|
@@ -18,48 +18,46 @@ const _m1 = new Matrix4();
|
|
|
const _obj = new Object3D();
|
|
|
const _offset = new Vector3();
|
|
|
|
|
|
-function Geometry() {
|
|
|
+class Geometry extends EventDispatcher {
|
|
|
|
|
|
- this.uuid = MathUtils.generateUUID();
|
|
|
-
|
|
|
- this.name = '';
|
|
|
- this.type = 'Geometry';
|
|
|
+ constructor() {
|
|
|
|
|
|
- this.vertices = [];
|
|
|
- this.colors = [];
|
|
|
- this.faces = [];
|
|
|
- this.faceVertexUvs = [[]];
|
|
|
+ super();
|
|
|
|
|
|
- this.morphTargets = [];
|
|
|
- this.morphNormals = [];
|
|
|
+ this.uuid = MathUtils.generateUUID();
|
|
|
|
|
|
- this.skinWeights = [];
|
|
|
- this.skinIndices = [];
|
|
|
+ this.name = '';
|
|
|
+ this.type = 'Geometry';
|
|
|
|
|
|
- this.lineDistances = [];
|
|
|
+ this.vertices = [];
|
|
|
+ this.colors = [];
|
|
|
+ this.faces = [];
|
|
|
+ this.faceVertexUvs = [[]];
|
|
|
|
|
|
- this.boundingBox = null;
|
|
|
- this.boundingSphere = null;
|
|
|
+ this.morphTargets = [];
|
|
|
+ this.morphNormals = [];
|
|
|
|
|
|
- // update flags
|
|
|
+ this.skinWeights = [];
|
|
|
+ this.skinIndices = [];
|
|
|
|
|
|
- this.elementsNeedUpdate = false;
|
|
|
- this.verticesNeedUpdate = false;
|
|
|
- this.uvsNeedUpdate = false;
|
|
|
- this.normalsNeedUpdate = false;
|
|
|
- this.colorsNeedUpdate = false;
|
|
|
- this.lineDistancesNeedUpdate = false;
|
|
|
- this.groupsNeedUpdate = false;
|
|
|
+ this.lineDistances = [];
|
|
|
|
|
|
-}
|
|
|
+ this.boundingBox = null;
|
|
|
+ this.boundingSphere = null;
|
|
|
|
|
|
-Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
|
|
|
+ // update flags
|
|
|
|
|
|
- constructor: Geometry,
|
|
|
+ this.elementsNeedUpdate = false;
|
|
|
+ this.verticesNeedUpdate = false;
|
|
|
+ this.uvsNeedUpdate = false;
|
|
|
+ this.normalsNeedUpdate = false;
|
|
|
+ this.colorsNeedUpdate = false;
|
|
|
+ this.lineDistancesNeedUpdate = false;
|
|
|
+ this.groupsNeedUpdate = false;
|
|
|
|
|
|
- isGeometry: true,
|
|
|
+ }
|
|
|
|
|
|
- applyMatrix4: function ( matrix ) {
|
|
|
+ applyMatrix4( matrix ) {
|
|
|
|
|
|
const normalMatrix = new Matrix3().getNormalMatrix( matrix );
|
|
|
|
|
@@ -100,9 +98,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- rotateX: function ( angle ) {
|
|
|
+ rotateX( angle ) {
|
|
|
|
|
|
// rotate geometry around world x-axis
|
|
|
|
|
@@ -112,9 +110,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- rotateY: function ( angle ) {
|
|
|
+ rotateY( angle ) {
|
|
|
|
|
|
// rotate geometry around world y-axis
|
|
|
|
|
@@ -124,9 +122,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- rotateZ: function ( angle ) {
|
|
|
+ rotateZ( angle ) {
|
|
|
|
|
|
// rotate geometry around world z-axis
|
|
|
|
|
@@ -136,9 +134,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- translate: function ( x, y, z ) {
|
|
|
+ translate( x, y, z ) {
|
|
|
|
|
|
// translate geometry
|
|
|
|
|
@@ -148,9 +146,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- scale: function ( x, y, z ) {
|
|
|
+ scale( x, y, z ) {
|
|
|
|
|
|
// scale geometry
|
|
|
|
|
@@ -160,9 +158,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- lookAt: function ( vector ) {
|
|
|
+ lookAt( vector ) {
|
|
|
|
|
|
_obj.lookAt( vector );
|
|
|
|
|
@@ -172,9 +170,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- fromBufferGeometry: function ( geometry ) {
|
|
|
+ fromBufferGeometry( geometry ) {
|
|
|
|
|
|
const scope = this;
|
|
|
|
|
@@ -313,9 +311,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- center: function () {
|
|
|
+ center() {
|
|
|
|
|
|
this.computeBoundingBox();
|
|
|
|
|
@@ -325,9 +323,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- normalize: function () {
|
|
|
+ normalize() {
|
|
|
|
|
|
this.computeBoundingSphere();
|
|
|
|
|
@@ -348,9 +346,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- computeFaceNormals: function () {
|
|
|
+ computeFaceNormals() {
|
|
|
|
|
|
const cb = new Vector3(), ab = new Vector3();
|
|
|
|
|
@@ -372,9 +370,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
}
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- computeVertexNormals: function ( areaWeighted = true ) {
|
|
|
+ computeVertexNormals( areaWeighted = true ) {
|
|
|
|
|
|
const vertices = new Array( this.vertices.length );
|
|
|
|
|
@@ -459,9 +457,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
}
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- computeFlatVertexNormals: function () {
|
|
|
+ computeFlatVertexNormals() {
|
|
|
|
|
|
this.computeFaceNormals();
|
|
|
|
|
@@ -493,9 +491,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
}
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- computeMorphNormals: function () {
|
|
|
+ computeMorphNormals() {
|
|
|
|
|
|
// save original normals
|
|
|
// - create temp variables on first access
|
|
@@ -604,9 +602,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
}
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- computeBoundingBox: function () {
|
|
|
+ computeBoundingBox() {
|
|
|
|
|
|
if ( this.boundingBox === null ) {
|
|
|
|
|
@@ -616,9 +614,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
this.boundingBox.setFromPoints( this.vertices );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- computeBoundingSphere: function () {
|
|
|
+ computeBoundingSphere() {
|
|
|
|
|
|
if ( this.boundingSphere === null ) {
|
|
|
|
|
@@ -628,9 +626,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
this.boundingSphere.setFromPoints( this.vertices );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- merge: function ( geometry, matrix, materialIndexOffset = 0 ) {
|
|
|
+ merge( geometry, matrix, materialIndexOffset = 0 ) {
|
|
|
|
|
|
if ( ! ( geometry && geometry.isGeometry ) ) {
|
|
|
|
|
@@ -747,9 +745,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
}
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- mergeMesh: function ( mesh ) {
|
|
|
+ mergeMesh( mesh ) {
|
|
|
|
|
|
if ( ! ( mesh && mesh.isMesh ) ) {
|
|
|
|
|
@@ -762,7 +760,7 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
this.merge( mesh.geometry, mesh.matrix );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
/*
|
|
|
* Checks for duplicate vertices with hashmap.
|
|
@@ -770,7 +768,7 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
* and faces' vertices are updated.
|
|
|
*/
|
|
|
|
|
|
- mergeVertices: function ( precisionPoints = 4 ) {
|
|
|
+ mergeVertices( precisionPoints = 4 ) {
|
|
|
|
|
|
const verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
|
|
|
const unique = [], changes = [];
|
|
@@ -847,9 +845,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
this.vertices = unique;
|
|
|
return diff;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setFromPoints: function ( points ) {
|
|
|
+ setFromPoints( points ) {
|
|
|
|
|
|
this.vertices = [];
|
|
|
|
|
@@ -862,9 +860,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- sortFacesByMaterialIndex: function () {
|
|
|
+ sortFacesByMaterialIndex() {
|
|
|
|
|
|
const faces = this.faces;
|
|
|
const length = faces.length;
|
|
@@ -909,9 +907,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
|
|
|
if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- toJSON: function () {
|
|
|
+ toJSON() {
|
|
|
|
|
|
const data = {
|
|
|
metadata: {
|
|
@@ -1102,9 +1100,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return data;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- clone: function () {
|
|
|
+ clone() {
|
|
|
|
|
|
/*
|
|
|
// Handle primitives
|
|
@@ -1132,9 +1130,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return new Geometry().copy( this );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copy: function ( source ) {
|
|
|
+ copy( source ) {
|
|
|
|
|
|
// reset
|
|
|
|
|
@@ -1364,9 +1362,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- toBufferGeometry: function () {
|
|
|
+ toBufferGeometry() {
|
|
|
|
|
|
const geometry = new DirectGeometry().fromGeometry( this );
|
|
|
|
|
@@ -1461,78 +1459,80 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
|
|
|
|
|
|
return buffergeometry;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- computeTangents: function () {
|
|
|
+ computeTangents() {
|
|
|
|
|
|
console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- computeLineDistances: function () {
|
|
|
+ computeLineDistances() {
|
|
|
|
|
|
console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- applyMatrix: function ( matrix ) {
|
|
|
+ applyMatrix( matrix ) {
|
|
|
|
|
|
console.warn( 'THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().' );
|
|
|
return this.applyMatrix4( matrix );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- dispose: function () {
|
|
|
+ dispose() {
|
|
|
|
|
|
this.dispatchEvent( { type: 'dispose' } );
|
|
|
|
|
|
}
|
|
|
|
|
|
-} );
|
|
|
+ static createBufferGeometryFromObject( object ) {
|
|
|
|
|
|
-Geometry.createBufferGeometryFromObject = function ( object ) {
|
|
|
+ let buffergeometry = new BufferGeometry();
|
|
|
|
|
|
- let buffergeometry = new BufferGeometry();
|
|
|
+ const geometry = object.geometry;
|
|
|
|
|
|
- const geometry = object.geometry;
|
|
|
+ if ( object.isPoints || object.isLine ) {
|
|
|
|
|
|
- if ( object.isPoints || object.isLine ) {
|
|
|
+ const positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
|
|
|
+ const colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
|
|
|
|
|
|
- const positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
|
|
|
- const colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
|
|
|
+ buffergeometry.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
|
|
|
+ buffergeometry.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
|
|
|
|
|
|
- buffergeometry.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
|
|
|
- buffergeometry.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
|
|
|
+ if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
|
|
|
|
|
|
- if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
|
|
|
+ const lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
|
|
|
|
|
|
- const lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
|
|
|
+ buffergeometry.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
|
|
|
|
|
|
- buffergeometry.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( geometry.boundingSphere !== null ) {
|
|
|
|
|
|
- if ( geometry.boundingSphere !== null ) {
|
|
|
+ buffergeometry.boundingSphere = geometry.boundingSphere.clone();
|
|
|
|
|
|
- buffergeometry.boundingSphere = geometry.boundingSphere.clone();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( geometry.boundingBox !== null ) {
|
|
|
|
|
|
- if ( geometry.boundingBox !== null ) {
|
|
|
+ buffergeometry.boundingBox = geometry.boundingBox.clone();
|
|
|
|
|
|
- buffergeometry.boundingBox = geometry.boundingBox.clone();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ } else if ( object.isMesh ) {
|
|
|
|
|
|
- } else if ( object.isMesh ) {
|
|
|
+ buffergeometry = geometry.toBufferGeometry();
|
|
|
|
|
|
- buffergeometry = geometry.toBufferGeometry();
|
|
|
+ }
|
|
|
+
|
|
|
+ return buffergeometry;
|
|
|
|
|
|
}
|
|
|
|
|
|
- return buffergeometry;
|
|
|
+}
|
|
|
|
|
|
-};
|
|
|
+Geometry.prototype.isGeometry = true;
|
|
|
|
|
|
class DirectGeometry {
|
|
|
|