Three. js source code annotation (33) Scenes/Scene. js

Source: Internet
Author: User

Three. js source code annotation (33) Scenes/Scene. js

 

Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.


I also just started learning. Sorry for the errors in many places.

The following code is a comment on the Scenes/Scene. JS file in the THREE. js source code file.

More updates in: https://github.com/omni360/three.js.sourcecode


/*** @ Author mrdoob/http://mrdoob.com/* // Scene is the Scene object. All objects, lights, animations, bones, and so on need to be placed in the Scene. the function functions of the Scene object are implemented by defining the constructed function prototype object. *////SceneTHREE. scene = function () {THREE. object3D. call (this); // call the call method of the Object3D object and hand over the method originally belonging to Object3D to the current object Scene for use. this. fog = null; // The fog effect attribute of the scenario. this. overrideMaterial = null; // specifies the material attribute of the scenario. The default value is null. If this attribute is set, all objects in the scenario are rendered as the material. this. autoUpdate = true; // checked by the renderer // the default value is true, indicating that each frame of the renderer checks whether the matrix of objects in the scenario and scenario is updated. If it is false, objects in the scenario will not be automatically updated. /********************** the new version has been deleted ************ * ******************** this. matrixAutoUpd Ate = false; // The default value is false. determines whether the matrix in the scenario is automatically updated. This attribute has been deleted in the new version. **************************************** * *****************************/this. _ lights = []; // All lights in the scenario are stored in the _ lights attribute array, this attribute/**************************** has been deleted in the new version ****** * ************************** this. _ objectsAdded = []; // All cameras and bones added in the scenario are stored in the _ objectsAdded attribute array. this attribute has been deleted in the new version. _ objectsRemoved = []; // All cameras and bones deleted in the scenario are stored in the _ objectsRemoved attribute array. This attribute has been deleted in the new version. // TODO: What do attributes mean? Is it new? Should the added camera be in the children array? We should put the camera and skeleton in this attribute array to improve efficiency. **************************************** ******************************/}; /*************************************** * ************ the method attribute definition of the Scene object is as follows, inherited from Object3D ************************************* * ************/THREE. scene. prototype = Object. create (THREE. object3D. prototype); // Scene object from THREE. the Objec3D prototype inherits all attribute methods /******************************** **************************** * ************ // _ addObject is used to add a light object to the _ lights attribute array of the scene, _ objectsAdded // NOTE: This method has been deleted in the new version /////_ AddObject///Light, Carmera, Bone, can contain sub-objects ///
 
  
Returns a new Scene object.
 THREE. scene. prototype. _ addObject = function (object) {if (object instanceof THREE. light) {// if it is a Light, if (this. _ lights. indexOf (object) ===- 1) {this. _ lights. push (object); // Add to _ lights attribute array} if (object.tar get & object.tar get. parent = undefined) {this. add (object.tar get) ;}} else if (! (Object instanceof THREE. camera | object instanceof THREE. bone) {// if it is a skeleton or camera this. _ objectsAdded. push (object); // Add it to the _ objectsAdded attribute array // check if previusly removed // check whether the object has been deleted var I = this. _ objectsRemoved. indexOf (object); // if the object is deleted, if (I! =-1) {this. _ objectsRemoved. splice (I, 1); // delete from the _ objectsRemoved array .}} this. dispatchEvent ({type: 'objectadded', object: object}); // schedule the event object. dispatchEvent ({type: 'addidtoscene ', scene: this}); // scheduling event for (var c = 0; c <object. children. length; c ++) {// if the object has a sub-object this. _ addObject (object. children [c]); // Add the child object to the _ objectsAdded attribute array }}; /// // _ removeObject is used to delete the light object from the _ lights attribute array of the scene, and add the camera and skeleton from the _ objectsRemoved // NOTE: this method has been deleted in the new version /////_ RemoveObject///Light, Carmera, Bone, can contain sub-objects ///
 
  
Returns a new Scene object.
 THREE. scene. prototype. _ removeObject = function (object) {if (object instanceof THREE. light) {var I = this. _ lights. indexOf (object); if (I! =-1) {this. _ lights. splice (I, 1);} if (object. shadowCascadeArray) {for (var x = 0; x <object. shadowCascadeArray. length; x ++) {this. _ removeObject (object. shadowCascadeArray [x]) ;}} else if (! (Object instanceof THREE. camera) {this. _ objectsRemoved. push (object); // check if previusly added // check whether the object has been added. var I = this. _ objectsAdded. indexOf (object); if (I! =-1) {this. _ objectsAdded. splice (I, 1) ;}} this. dispatchEvent ({type: 'objectremoved', object: object}); object. dispatchEvent ({type: 'removedfromscene ', scene: this}); for (var c = 0; c <object. children. length; c ++) {this. _ removeObject (object. children [c]) ;}}; **************************************** ********************************** // The clone method/ // clone a Scene object, copy the attribute array separately. *////Clone///
 
  
Returns the cloned Scene object.
 THREE. scene. prototype. clone = function (object) {if (object = undefined) object = new THREE. scene (); THREE. object3D. prototype. clone. call (this, object); if (this. fog! = Null) object. fog = this. fog. clone (); if (this. overrideMaterial! = Null) object. overrideMaterial = this. overrideMaterial. clone (); object. autoUpdate = this. autoUpdate; /********************** the new version has been deleted ************ * ******************** object. matrixAutoUpdate = this. matrixAutoUpdate; // ************************************ has been deleted in the new version ********************************** * **********************************/return object; // returns the cloned Scene object };


Wuji (http://blog.csdn.net/omni360)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.


The following code is a comment on the Scenes/Scene. JS file in the THREE. js source code file.

More updates in: https://github.com/omni360/three.js.sourcecode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.