I am passing the name of the 3d model add and texture name in a function and the result is the 3d model is rendered in a scene. All what am in stuck is ,I just want to remove only the 3d objects from the scene
when i use scene.children to get the objects it contains the light and camera too i just want to remove only the Meshes in the scene
I am passing the name of the 3d model add and texture name in a function and the result is the 3d model is rendered in a scene. All what am in stuck is ,I just want to remove only the 3d objects from the scene
when i use scene.children to get the objects it contains the light and camera too i just want to remove only the Meshes in the scene
Share Improve this question edited Jan 28, 2016 at 14:08 micnil 4,8152 gold badges32 silver badges41 bronze badges asked Jan 28, 2016 at 11:55 ArUnArUn 1,3372 gold badges23 silver badges40 bronze badges2 Answers
Reset to default 5Maybe this solves your problem,
for (let i = scene.children.length - 1; i >= 0; i--) {
if(scene.children[i].type === "Mesh")
scene.remove(scene.children[i]);
}
Note that it is a reverse for loop. This is because we are removing items from the array that we are iterating, and we need to preserve the indices.
Just removing THREE objects from your scene is not enough to delete them from memory. You have to call the dispose() methods on the objects' geometries, materials and textures.
https://github./mrdoob/three.js/issues/5175
After you call your dispose and remove methods, do a diagnostic like this (where this.renderer is your THREE.Renderer):
if (this.renderer && (this.renderer.info.memory.geometries || this.renderer.info.memory.programs || this.renderer.info.memory.textures)) {
loge("geometries=" + this.renderer.info.memory.geometries + " programs=" + this.renderer.info.memory.programs + " textures=" + this.renderer.info.memory.textures);
}
If the number of programs, geometries and textures isn't stable, you are inviting performance issues and a memory leak.