let loader = new THREE.TextureLoader();
let texture = loader.load("/static/plane.jpg");
texture.wrapS = THREE.MirroredRepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat = new THREE.Vector2(1, 1);
let material = new THREE.MeshBasicMaterial({map: texture});
let cube = new THREE.Mesh(boxGeometry, material);
let texture = new THREE.Texture();
imageLoader.load('/static/wood.jpg', image => {
texture.image = image;
texture.needsUpdate = true;
});
objLoader.load("/static/model/Light.obj", object => {
object.traverse( function (child) {
if (child instanceof THREE.Mesh) {
child.material.map = texture;
}
});
scene.add(object);
});
document.addEventListener('mousemove', function (e) {
e.preventDefault();
console.log(mouse);
mouse.x = (e.clientX / window.innerWidth) * 2 - 1;
mouse.y = - (e.clientY / window.innerHeight) * 2 + 1;
}, false);
function render () {
ray.setFromCamera(mouse, camera);
let intersects = ray.intersectObjects(scene.children);
if (intersects.length > 0) {
if (INTERSECTED !== intersects[0].object) {
if (INTERSECTED)
INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
INTERSECTED = intersects[0].object;
INTERSECTED.currentHex = INTERSECTED.material.emissive.getHex();
INTERSECTED.material.emissive.setHex(0xFF0000);
}
} else {
if (INTERSECTED)
INTERSECTED.material.emissive.setHex(INTERSECTED.currentHex);
INTERSECTED = null;
}
}
function animate () {
requestAnimationFrame( animate );
render();
renderer.render(scene, camera);
}
animate();
本作品採用《CC 協議》,轉載必須註明作者和本文連結