Mesh.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 = geometry;
  10. this.material = ( material !== undefined ) ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: true } );
  11. if ( this.geometry ) {
  12. // calc bound radius
  13. if ( this.geometry.boundingSphere === null ) {
  14. this.geometry.computeBoundingSphere();
  15. }
  16. this.updateMorphTargets();
  17. }
  18. };
  19. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  20. THREE.Mesh.prototype.updateMorphTargets = function() {
  21. // setup morph targets
  22. var morphTargetAmount = this.geometry.morphTargets.length;
  23. if (!!morphTargetAmount) {
  24. // Initialize variables for morph targets if they don't exist.
  25. if ( !this.morphTargetInfluences ) {
  26. this.morphTargetBase = -1;
  27. this.morphTargetForcedOrder = [];
  28. this.morphTargetInfluences = [];
  29. this.morphTargetDictionary = {};
  30. }
  31. // Make sure that the influences amount is identical to geometry's
  32. // morph target amount.
  33. if ( this.morphTargetInfluences.length !== morphTargetAmount ) {
  34. this.morphTargetInfluences.length = morphTargetAmount;
  35. }
  36. for ( var m = 0; m < morphTargetAmount; m++ ) {
  37. this.morphTargetInfluences[ m ] = this.morphTargetInfluences[ m ] || 0;
  38. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  39. }
  40. }
  41. };
  42. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  43. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  44. return this.morphTargetDictionary[ name ];
  45. }
  46. console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning -1." );
  47. return -1; // Easier comparator similar to ecmascript 5 indexOf.
  48. };
  49. THREE.Mesh.prototype.clone = function ( object ) {
  50. if ( object === undefined ) object = new THREE.Mesh( this.geometry, this.material );
  51. THREE.Object3D.prototype.clone.call( this, object );
  52. return object;
  53. };
粤ICP备19079148号