Mesh.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author alteredq / http://alteredqualia.com/
  4. * @author mikael emtinger / http://gomo.se/
  5. * @author jonobr1 / http://jonobr1.com/
  6. */
  7. THREE.Mesh = function ( geometry, material ) {
  8. THREE.Object3D.call( this );
  9. this.geometry = null;
  10. this.material = null;
  11. this.setGeometry( geometry );
  12. this.setMaterial( material );
  13. };
  14. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  15. THREE.Mesh.prototype.setGeometry = function ( geometry ) {
  16. if ( geometry !== undefined ) {
  17. this.geometry = geometry;
  18. if ( this.geometry.boundingSphere === null ) {
  19. this.geometry.computeBoundingSphere();
  20. }
  21. this.updateMorphTargets();
  22. }
  23. };
  24. THREE.Mesh.prototype.setMaterial = function ( material ) {
  25. if ( material !== undefined ) {
  26. this.material = material;
  27. } else {
  28. this.material = new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: true } );
  29. }
  30. };
  31. THREE.Mesh.prototype.updateMorphTargets = function () {
  32. if ( this.geometry.morphTargets.length > 0 ) {
  33. this.morphTargetBase = -1;
  34. this.morphTargetForcedOrder = [];
  35. this.morphTargetInfluences = [];
  36. this.morphTargetDictionary = {};
  37. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  38. this.morphTargetInfluences.push( 0 );
  39. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  40. }
  41. }
  42. };
  43. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  44. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  45. return this.morphTargetDictionary[ name ];
  46. }
  47. console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." );
  48. return 0;
  49. };
  50. THREE.Mesh.prototype.clone = function ( object ) {
  51. if ( object === undefined ) object = new THREE.Mesh( this.geometry, this.material );
  52. THREE.Object3D.prototype.clone.call( this, object );
  53. return object;
  54. };
粤ICP备19079148号