DynamicGeometry.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. THREE.DynamicGeometry = function () {
  5. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6. this.uuid = THREE.Math.generateUUID();
  7. this.name = '';
  8. this.type = 'DynamicGeometry';
  9. this.vertices = [];
  10. this.colors = [];
  11. this.normals = [];
  12. this.colors = [];
  13. this.uvs = [];
  14. this.faces = [];
  15. // this.lineDistances = [];
  16. this.boundingBox = null;
  17. this.boundingSphere = null;
  18. // update flags
  19. this.verticesNeedUpdate = false;
  20. this.normalsNeedUpdate = false;
  21. this.colorsNeedUpdate = false;
  22. this.uvsNeedUpdate = false;
  23. };
  24. THREE.DynamicGeometry.prototype = {
  25. constructor: THREE.DynamicGeometry,
  26. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  27. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  28. computeFaceNormals: function () {
  29. console.warn( 'THREE.DynamicGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  30. return this;
  31. },
  32. computeVertexNormals: function () {
  33. console.warn( 'THREE.DynamicGeometry: computeVertexNormals () is not a method of this type of geometry.' );
  34. return this;
  35. },
  36. fromGeometry: function ( geometry ) {
  37. this.vertices = geometry.vertices;
  38. this.faces = geometry.faces;
  39. var faces = geometry.faces;
  40. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  41. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  42. var face = faces[ i ];
  43. var indices = [ face.a, face.b, face.c ];
  44. var vertexNormals = face.vertexNormals;
  45. var vertexColors = face.vertexColors;
  46. var vertexUvs = faceVertexUvs[ i ];
  47. for ( var j = 0, jl = vertexNormals.length; j < jl; j ++ ) {
  48. this.normals[ indices[ j ] ] = vertexNormals[ j ];
  49. }
  50. for ( var j = 0, jl = vertexColors.length; j < jl; j ++ ) {
  51. this.colors[ indices[ j ] ] = vertexColors[ j ];
  52. }
  53. for ( var j = 0, jl = vertexUvs.length; j < jl; j ++ ) {
  54. this.uvs[ indices[ j ] ] = vertexUvs[ j ];
  55. }
  56. }
  57. if ( geometry.morphTargets ) this.morphTargets = geometry.morphTargets.slice( 0 );
  58. if ( geometry.morphColors ) this.morphColors = geometry.morphColors.slice( 0 );
  59. if ( geometry.morphNormals ) this.morphNormals = geometry.morphNormals.slice( 0 );
  60. if ( geometry.skinIndices ) this.skinIndices = geometry.skinIndices.slice( 0 );
  61. if ( geometry.skinWeights ) this.skinWeights = geometry.skinWeights.slice( 0 );
  62. return this;
  63. },
  64. dispose: function () {
  65. this.dispatchEvent( { type: 'dispose' } );
  66. }
  67. };
  68. THREE.EventDispatcher.prototype.apply( THREE.DynamicGeometry.prototype );
粤ICP备19079148号