Mesh.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @author mr.doob / http://mrdoob.com/
  3. * @author alteredq / http://alteredqualia.com/
  4. * @author mikael emtinger / http://gomo.se/
  5. */
  6. THREE.Mesh = function( geometry, materials ) {
  7. THREE.Object3D.call( this );
  8. this.geometry = geometry;
  9. this.materials = materials && materials.length ? materials : [ materials ];
  10. this.normalMatrix = THREE.Matrix4.makeInvert3x3( this.globalMatrix ).transpose();
  11. this.flipSided = false;
  12. this.doubleSided = false;
  13. this.overdraw = false; // TODO: Move to material?
  14. // calc bound radius
  15. if( this.geometry ) {
  16. if( !this.geometry.boundingSphere )
  17. this.geometry.computeBoundingSphere();
  18. this.boundRadius = geometry.boundingSphere.radius;
  19. }
  20. }
  21. THREE.Mesh.prototype = new THREE.Object3D();
  22. THREE.Mesh.prototype.constructor = THREE.Mesh;
  23. THREE.Mesh.prototype.supr = THREE.Object3D.prototype;
  24. /*
  25. * Update
  26. */
  27. THREE.Mesh.prototype.update = function( parentGlobalMatrix, forceUpdate, camera, renderer ) {
  28. // visible?
  29. if( this.visible ) {
  30. // update local
  31. if( this.autoUpdateMatrix )
  32. forceUpdate |= this.updateMatrix();
  33. // update global
  34. if( forceUpdate || this.matrixNeedsToUpdate ) {
  35. if( parentGlobalMatrix )
  36. this.globalMatrix.multiply( parentGlobalMatrix, this.localMatrix );
  37. else
  38. this.globalMatrix.copy( this.localMatrix );
  39. this.matrixNeedsToUpdate = false;
  40. forceUpdate = true;
  41. // update normal
  42. this.normalMatrix = THREE.Matrix4.makeInvert3x3( this.globalMatrix ).transpose();
  43. }
  44. // update children
  45. for( var i = 0; i < this.children.length; i++ )
  46. this.children[ i ].update( this.globalMatrix, forceUpdate, camera, renderer );
  47. // check camera frustum and add to render list
  48. if( renderer && camera ) {
  49. if( camera.frustumContains( this ))
  50. renderer.addToRenderList( this );
  51. else
  52. renderer.removeFromRenderList( this );
  53. }
  54. } else {
  55. renderer.removeFromRenderList( this );
  56. }
  57. }
粤ICP备19079148号