xxxxxxxxxx
105
let scene, camera, renderer, controls, stats;
function preload() {
// Load the STL file
loader = new THREE.STLLoader();
loader.load(
'https://threejs.org/examples/models/stl/ascii/slotted_disk.stl',
function (geometry) {
const material = new THREE.MeshPhongMaterial({
color: 0x555555,
specular: 0x111111,
shininess: 200,
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0, 0, 0);
mesh.rotation.set(-Math.PI / 2, 0, 0);
mesh.scale.set(0.5, 0.5, 0.5);
scene.add(mesh);
},
function (xhr) {
console.log((xhr.loaded / xhr.total) * 100 + '% loaded');
},
function (error) {
console.log(error);
}
);
}
function setup() {
createCanvas(400, 400);
/*
// Create the scene
scene = new THREE.Scene();
scene.add(new THREE.AxesHelper(5));
// Create the camera
camera = new THREE.PerspectiveCamera(
75,
windowWidth / windowHeight,
0.1,
1000
);
camera.position.z = 5;
// Create the renderer
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(windowWidth, windowHeight);
document.body.appendChild(renderer.domElement);
// Add controls to the camera
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
// Add lights to the scene
const light1 = new THREE.DirectionalLight(0xffffff, 0.5);
light1.position.set(1, 1, 1);
scene.add(light1);
const light2 = new THREE.DirectionalLight(0xffffff, 0.5);
light2.position.set(-1, -1, 1);
scene.add(light2);
const light3 = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(light3);
// Add stats to the page
stats = new Stats();
document.body.appendChild(stats.dom);
// Add window resize listener
window.addEventListener('resize', onWindowResize, false);
*/
}
function draw() {
background(220);
/*
// Render the scene
renderer.render(scene, camera);
// Update controls and stats
controls.update();
stats.update();
*/
}
/*
function onWindowResize() {
// Resize the canvas and update the camera aspect ratio
camera.aspect = windowWidth / windowHeight;
camera.updateProjectionMatrix();
renderer.setSize(windowWidth, windowHeight);
}
*/