Difference between revisions of "Threejs"

From Wasya Wiki
Jump to: navigation, search
(destroy scene)
Line 17: Line 17:
  
 
== destroy scene ==
 
== destroy scene ==
 +
<pre>
 
     cancelAnimationFrame(this.id);// Stop the animation
 
     cancelAnimationFrame(this.id);// Stop the animation
 
     this.renderer.domElement.addEventListener('dblclick', null, false); //remove listener to render
 
     this.renderer.domElement.addEventListener('dblclick', null, false); //remove listener to render
Line 24: Line 25:
 
     this.controls = null;
 
     this.controls = null;
 
     empty(this.modelContainer);
 
     empty(this.modelContainer);
 +
</pre>
  
 +
<pre>
 
   function removeObject3D(object3D) {
 
   function removeObject3D(object3D) {
 
     if (!(object3D instanceof THREE.Object3D)) return false;
 
     if (!(object3D instanceof THREE.Object3D)) return false;
Line 43: Line 46:
 
     return true;
 
     return true;
 
   }
 
   }
 +
</pre>

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;
  }