123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- THREE.DirectGeometry = function () {
- Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
- this.uuid = THREE.Math.generateUUID();
- this.name = '';
- this.type = 'DirectGeometry';
- this.vertices = [];
- this.colors = [];
- this.normals = [];
- this.colors = [];
- this.uvs = [];
- this.uvs2 = [];
- this.morphTargets = [];
- this.morphColors = [];
- this.morphNormals = [];
- this.skinWeights = [];
- this.skinIndices = [];
- // this.lineDistances = [];
- this.boundingBox = null;
- this.boundingSphere = null;
- // update flags
- this.verticesNeedUpdate = false;
- this.normalsNeedUpdate = false;
- this.colorsNeedUpdate = false;
- this.uvsNeedUpdate = false;
- };
- THREE.DirectGeometry.prototype = {
- constructor: THREE.DirectGeometry,
- computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
- computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
- computeFaceNormals: function () {
- console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
- return this;
- },
- computeVertexNormals: function () {
- console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
- return this;
- },
- fromGeometry: function ( geometry, material ) {
- material = material || { 'vertexColors': THREE.NoColors };
- var faces = geometry.faces;
- var vertices = geometry.vertices;
- var faceVertexUvs = geometry.faceVertexUvs;
- var materialVertexColors = material.vertexColors;
- var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
- var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
- // morphs
- var morphTargets = geometry.morphTargets;
- var morphTargetsLength = morphTargets.length;
- for ( var i = 0; i < morphTargetsLength; i ++ ) {
- this.morphTargets[ i ] = [];
- }
- var morphNormals = geometry.morphNormals;
- var morphNormalsLength = morphNormals.length;
- for ( var i = 0; i < morphNormalsLength; i ++ ) {
- this.morphNormals[ i ] = [];
- }
- var morphColors = geometry.morphColors;
- var morphColorsLength = morphColors.length;
- for ( var i = 0; i < morphColorsLength; i ++ ) {
- this.morphColors[ i ] = [];
- }
- // skins
- var skinIndices = geometry.skinIndices;
- var skinWeights = geometry.skinWeights;
- var hasSkinIndices = skinIndices.length === vertices.length;
- var hasSkinWeights = skinWeights.length === vertices.length;
- //
- for ( var i = 0; i < faces.length; i ++ ) {
- var face = faces[ i ];
- this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
- var vertexNormals = face.vertexNormals;
- if ( vertexNormals.length === 3 ) {
- this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
- } else {
- var normal = face.normal;
- this.normals.push( normal, normal, normal );
- }
- var vertexColors = face.vertexColors;
- if ( materialVertexColors === THREE.VertexColors ) {
- this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
- } else if ( materialVertexColors === THREE.FaceColors ) {
- var color = face.color;
- this.colors.push( color, color, color );
- }
- if ( hasFaceVertexUv === true ) {
- var vertexUvs = faceVertexUvs[ 0 ][ i ];
- if ( vertexUvs !== undefined ) {
- this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
- } else {
- console.warn( 'THREE.BufferGeometry.fromGeometry(): Undefined vertexUv', i );
- this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
- }
- }
- if ( hasFaceVertexUv2 === true ) {
- var vertexUvs = faceVertexUvs[ 1 ][ i ];
- if ( vertexUvs !== undefined ) {
- this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
- } else {
- console.warn( 'THREE.BufferGeometry.fromGeometry(): Undefined vertexUv2', i );
- this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
- }
- }
- // morphs
- for ( var j = 0; j < morphTargetsLength; j ++ ) {
- var morphTarget = morphTargets[ j ].vertices;
- this.morphTargets[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
- }
- for ( var j = 0; j < morphNormalsLength; j ++ ) {
- var morphNormal = morphNormals[ j ].normals;
- this.morphNormals[ j ].push( morphNormal[ face.a ], morphNormal[ face.b ], morphNormal[ face.c ] );
- }
- for ( var j = 0; j < morphColorsLength; j ++ ) {
- var morphColor = morphColors[ j ].colors;
- this.morphColors[ j ].push( morphColor[ face.a ], morphColor[ face.b ], morphColor[ face.c ] );
- }
- // skins
- if ( hasSkinIndices ) {
- this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
- }
- if ( hasSkinWeights ) {
- this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
- }
- }
- this.verticesNeedUpdate = geometry.verticesNeedUpdate;
- this.normalsNeedUpdate = geometry.normalsNeedUpdate;
- this.colorsNeedUpdate = geometry.colorsNeedUpdate;
- this.uvsNeedUpdate = geometry.uvsNeedUpdate;
- return this;
- },
- dispose: function () {
- this.dispatchEvent( { type: 'dispose' } );
- }
- };
- THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
|