Hi.
I am importing a glb module from Blender into ThreeJS, which consists of a bunch of children meshes and groups. I want to detect when 5 specific elements are hovered (to change their opacity), and then call an action when they are clicked.
I have been browsing the internet but with no luck. This is what I could set up from tutorials, but it just creates an white screen.
import * as THREE from 'three';
import Sizes from "./Utils/sizes.js"
import Time from "./Utils/time.js"
import Resources from "./Utils/resources.js"
import assets from "./Utils/assets.js"
import Camera from "./camera.js"
import Renderer from "./renderer.js"
import World from "./World/world.js"
export default class Experience {
static instance
constructor(canvas) {
if (Experience.instance) {
return Experience.instance
}
Experience.instance = this;
this.canvas = canvas;
this.scene = new THREE.Scene() //I set up my scene here
this.time = new Time() //I set up time here for animations
this.sizes = new Sizes() //I set up sizes here
this.camera = new Camera() //I set up the camera here
this.renderer = new Renderer() //I set up my renderer here
this.recources = new Resources(assets) //I get the blender file from here
this.world = new World() //I set the view here, where I load the blender file
this.sizes.on("resize", ()=> {
this.resize();
})
this.time.on("update", ()=> {
this.update();
})
}
resize() {
this.camera.resize()
this.renderer.resize()
}
update() {
this.camera.update()
this.renderer.update()
}
}
//Raycasting
const raycaster = new THREE.Raycaster()
const moveMouse = new THREE.Vector2()
const experience = new Experience()
window.addEventListener('mousedown', event => {
moveMouse.x = ( event.clientX / window.innerHeight ) * 2 - 1
moveMouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1
raycaster.setFromCamera( moveMouse, experience.camera.perspectiveCamera)
const found = raycaster.intersectObjects( experience.world.room.actualRoom.children )
console.log(found)
}) //The white screen gets created from this.
Maybe there is a video or tutorial that I haven’t seen that would help me out, if you know one please let me know. I’m new to ThreeJs, so I’m still learning a lot.