Scene.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.Scene = function () {
  5. THREE.Object3D.call( this );
  6. this.fog = null;
  7. this.overrideMaterial = null;
  8. this.autoUpdate = true; // checked by the renderer
  9. this.matrixAutoUpdate = false;
  10. this.__objects = [];
  11. this.__lights = [];
  12. this.__objectsAdded = [];
  13. this.__objectsRemoved = [];
  14. };
  15. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  16. THREE.Scene.prototype.__addObject = function ( object ) {
  17. if ( object instanceof THREE.Light ) {
  18. if ( this.__lights.indexOf( object ) === - 1 ) {
  19. this.__lights.push( object );
  20. }
  21. if ( object.target && object.target.parent === undefined ) {
  22. this.add( object.target );
  23. }
  24. } else if ( !( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) {
  25. if ( this.__objects.indexOf( object ) === - 1 ) {
  26. this.__objects.push( object );
  27. this.__objectsAdded.push( object );
  28. // check if previously removed
  29. var i = this.__objectsRemoved.indexOf( object );
  30. if ( i !== -1 ) {
  31. this.__objectsRemoved.splice( i, 1 );
  32. }
  33. }
  34. }
  35. for ( var c = 0; c < object.children.length; c ++ ) {
  36. this.__addObject( object.children[ c ] );
  37. }
  38. };
  39. THREE.Scene.prototype.__removeObject = function ( object ) {
  40. if ( object instanceof THREE.Light ) {
  41. var i = this.__lights.indexOf( object );
  42. if ( i !== -1 ) {
  43. this.__lights.splice( i, 1 );
  44. }
  45. if ( object.shadowCascadeArray ) {
  46. for ( var x = 0; x < object.shadowCascadeArray.length; x++ ) {
  47. this.__removeObject( object.shadowCascadeArray[ x ] );
  48. }
  49. }
  50. } else if ( !( object instanceof THREE.Camera ) ) {
  51. var i = this.__objects.indexOf( object );
  52. if( i !== -1 ) {
  53. this.__objects.splice( i, 1 );
  54. this.__objectsRemoved.push( object );
  55. // check if previously added
  56. var ai = this.__objectsAdded.indexOf( object );
  57. if ( ai !== -1 ) {
  58. this.__objectsAdded.splice( ai, 1 );
  59. }
  60. }
  61. }
  62. for ( var c = 0; c < object.children.length; c ++ ) {
  63. this.__removeObject( object.children[ c ] );
  64. }
  65. };
  66. THREE.Scene.prototype.clone = function ( object ) {
  67. if ( object === undefined ) object = new THREE.Scene();
  68. THREE.Object3D.prototype.clone.call(this, object);
  69. if ( this.fog !== null ) object.fog = this.fog.clone();
  70. if ( this.overrideMaterial !== null ) object.overrideMaterial = this.overrideMaterial.clone();
  71. object.autoUpdate = this.autoUpdate;
  72. object.matrixAutoUpdate = this.matrixAutoUpdate;
  73. return object;
  74. };
粤ICP备19079148号