Scene.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * @author mr.doob / http://mrdoob.com/
  3. */
  4. THREE.Scene = function () {
  5. THREE.Object3D.call( this );
  6. this.fog = null;
  7. this.overrideMaterial = null;
  8. this.matrixAutoUpdate = false;
  9. this.__objects = [];
  10. this.__lights = [];
  11. this.__objectsAdded = [];
  12. this.__objectsRemoved = [];
  13. };
  14. THREE.Scene.prototype = new THREE.Object3D();
  15. THREE.Scene.prototype.constructor = THREE.Scene;
  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. } else if ( !( object instanceof THREE.Camera ) ) {
  46. var i = this.__objects.indexOf( object );
  47. if( i !== -1 ) {
  48. this.__objects.splice( i, 1 );
  49. this.__objectsRemoved.push( object );
  50. // check if previously added
  51. var ai = this.__objectsAdded.indexOf( object );
  52. if ( ai !== -1 ) {
  53. this.__objectsAdded.splice( ai, 1 );
  54. }
  55. }
  56. }
  57. for ( var c = 0; c < object.children.length; c ++ ) {
  58. this.removeObject( object.children[ c ] );
  59. }
  60. };
粤ICP备19079148号