Difference between revisions of "Threejs"
From Wasya Wiki
| Line 24: | Line 24: | ||
this.controls = null; | this.controls = null; | ||
empty(this.modelContainer); | empty(this.modelContainer); | ||
| + | |||
| + | function removeObject3D(object3D) { | ||
| + | if (!(object3D instanceof THREE.Object3D)) return false; | ||
| + | |||
| + | // for better memory management and performance | ||
| + | if (object3D.geometry) object3D.geometry.dispose(); | ||
| + | |||
| + | if (object3D.material) { | ||
| + | if (object3D.material instanceof Array) { | ||
| + | // for better memory management and performance | ||
| + | object3D.material.forEach(material => material.dispose()); | ||
| + | } else { | ||
| + | // for better memory management and performance | ||
| + | object3D.material.dispose(); | ||
| + | } | ||
| + | } | ||
| + | object3D.removeFromParent(); // the parent might be the scene or another Object3D, but it is sure to be removed this way | ||
| + | return true; | ||
| + | } | ||
Revision as of 02:07, 15 October 2022
Develop
Perspective Camera
/**
* PerspectiveCamera( fov : Number, aspect : Number, near : Number, far : Number )
*
* fov — Camera frustum vertical field of view.
* aspect — Camera frustum aspect ratio.
* near — Camera frustum near plane.
* far — Camera frustum far plane.
*/
Picking
destroy scene
cancelAnimationFrame(this.id);// Stop the animation
this.renderer.domElement.addEventListener('dblclick', null, false); //remove listener to render
this.scene = null;
this.projector = null;
this.camera = null;
this.controls = null;
empty(this.modelContainer);
function removeObject3D(object3D) {
if (!(object3D instanceof THREE.Object3D)) return false;
// for better memory management and performance if (object3D.geometry) object3D.geometry.dispose();
if (object3D.material) {
if (object3D.material instanceof Array) {
// for better memory management and performance
object3D.material.forEach(material => material.dispose());
} else {
// for better memory management and performance
object3D.material.dispose();
}
}
object3D.removeFromParent(); // the parent might be the scene or another Object3D, but it is sure to be removed this way
return true;
}