I had a scene of three.js and a component of vue3. I wanna make the component insert into the scene by CSS2DObject or CSS3DObject, but they just support the HTMLElement type。
My component is dynamic because I need data from backend.
Can I use CSS2DObject or CSS3DObject to make a component of vue3 become an object supported by threejs?
You need to use the ref attribute to create a reference to the child component inside the parent’s template. Also to make sure the child component is mounted you need to call initScene inside the onMounted lifecycle hook.
CSS2DObject and CSS3DObject take an HTMLElement, in your code you are giving it the child component it self, to get the root HTMLElement of the child component use the $el property of the child ref like so componentRef.value!.$el. Always in the onMounted lifecycle hook.