Closed JPhilipp closed 7 months ago
If I remember correctly, your props were attached to the 'Head' bone. If that is the case, you could try hiding only the top-level meshes of the armature.
head.armature.children.forEach( x => {
if ( x.isMesh ) {
x.visible = false;
}
});
To show them again, set visible
to true.
Thank you, I will give this a try in a few hours!
On that note, what would be the proper way to unload everything, destroy the threejs and release all memory, if I wanted to completely hide things and also not show any prop anymore? Could I just null the head and set the avatar div innerHTML to empty?
As far as I know, all modern browsers use the 'mark-and-sweep' algorithm, in which garbage collection automatically collects all non-reachable objects. So, in principle, if you make the object unreachable, it will be collected, and its allocated memory reclaimed.
Unfortunately, when using the three.js
library, there are some objects that are not released this way and have to be disposed explicitly by calling the Three.js method dispose
. For this purpose, the TalkingHead class has a method clearThree(obj)
, which is called on the scene every time a new avatar is loaded.
Typically, there is no need to delete the TalkingHead instance as it can be reused. You can also just head.stop()
and hide the div. When you need the avatar again, show the div and call head.start()
.
If, for some reason, you would want to delete the instance, you can do the following:
head.stop();
head.clearThree(head.scene);
head.resizeobserver.disconnect();
head = null;
document.getElementById('div-id').innerHTML = '';
NOTE: I just added the resizeobserver
property, so it is only available in the latest version of the class. If the observer is not disconnected, it will retain the reference to the class instance and prevent garbage collection.
Thank you!
Is there a way to hide the avatar, but keep everything else in the scene (like props I added)?
For a special feature, I want to temporarily show an actual webcam-filmed speaking robot head instead of an avatar, but they should still be overlaid by props I added.
Cheers!