|
@@ -10,40 +10,40 @@ import {
|
|
Vector3
|
|
Vector3
|
|
} from '../../../build/three.module.js';
|
|
} from '../../../build/three.module.js';
|
|
|
|
|
|
-var BufferGeometryUtils = {
|
|
|
|
|
|
+class BufferGeometryUtils {
|
|
|
|
|
|
- computeTangents: function ( geometry ) {
|
|
|
|
|
|
+ static computeTangents( geometry ) {
|
|
|
|
|
|
geometry.computeTangents();
|
|
geometry.computeTangents();
|
|
console.warn( 'THREE.BufferGeometryUtils: .computeTangents() has been removed. Use BufferGeometry.computeTangents() instead.' );
|
|
console.warn( 'THREE.BufferGeometryUtils: .computeTangents() has been removed. Use BufferGeometry.computeTangents() instead.' );
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {Array<BufferGeometry>} geometries
|
|
* @param {Array<BufferGeometry>} geometries
|
|
* @param {Boolean} useGroups
|
|
* @param {Boolean} useGroups
|
|
* @return {BufferGeometry}
|
|
* @return {BufferGeometry}
|
|
*/
|
|
*/
|
|
- mergeBufferGeometries: function ( geometries, useGroups ) {
|
|
|
|
|
|
+ static mergeBufferGeometries( geometries, useGroups = false ) {
|
|
|
|
|
|
- var isIndexed = geometries[ 0 ].index !== null;
|
|
|
|
|
|
+ const isIndexed = geometries[ 0 ].index !== null;
|
|
|
|
|
|
- var attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
|
|
|
|
- var morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
|
|
|
|
|
|
+ const attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
|
|
|
|
+ const morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
|
|
|
|
|
|
- var attributes = {};
|
|
|
|
- var morphAttributes = {};
|
|
|
|
|
|
+ const attributes = {};
|
|
|
|
+ const morphAttributes = {};
|
|
|
|
|
|
- var morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
|
|
|
|
|
|
+ const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
|
|
|
|
|
|
- var mergedGeometry = new BufferGeometry();
|
|
|
|
|
|
+ const mergedGeometry = new BufferGeometry();
|
|
|
|
|
|
- var offset = 0;
|
|
|
|
|
|
+ let offset = 0;
|
|
|
|
|
|
- for ( var i = 0; i < geometries.length; ++ i ) {
|
|
|
|
|
|
+ for ( let i = 0; i < geometries.length; ++ i ) {
|
|
|
|
|
|
- var geometry = geometries[ i ];
|
|
|
|
- var attributesCount = 0;
|
|
|
|
|
|
+ const geometry = geometries[ i ];
|
|
|
|
+ let attributesCount = 0;
|
|
|
|
|
|
// ensure that all geometries are indexed, or none
|
|
// ensure that all geometries are indexed, or none
|
|
|
|
|
|
@@ -56,7 +56,7 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
// gather attributes, exit early if they're different
|
|
// gather attributes, exit early if they're different
|
|
|
|
|
|
- for ( var name in geometry.attributes ) {
|
|
|
|
|
|
+ for ( const name in geometry.attributes ) {
|
|
|
|
|
|
if ( ! attributesUsed.has( name ) ) {
|
|
if ( ! attributesUsed.has( name ) ) {
|
|
|
|
|
|
@@ -91,7 +91,7 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- for ( var name in geometry.morphAttributes ) {
|
|
|
|
|
|
+ for ( const name in geometry.morphAttributes ) {
|
|
|
|
|
|
if ( ! morphAttributesUsed.has( name ) ) {
|
|
if ( ! morphAttributesUsed.has( name ) ) {
|
|
|
|
|
|
@@ -113,7 +113,7 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
if ( useGroups ) {
|
|
if ( useGroups ) {
|
|
|
|
|
|
- var count;
|
|
|
|
|
|
+ let count;
|
|
|
|
|
|
if ( isIndexed ) {
|
|
if ( isIndexed ) {
|
|
|
|
|
|
@@ -142,14 +142,14 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
if ( isIndexed ) {
|
|
if ( isIndexed ) {
|
|
|
|
|
|
- var indexOffset = 0;
|
|
|
|
- var mergedIndex = [];
|
|
|
|
|
|
+ let indexOffset = 0;
|
|
|
|
+ const mergedIndex = [];
|
|
|
|
|
|
- for ( var i = 0; i < geometries.length; ++ i ) {
|
|
|
|
|
|
+ for ( let i = 0; i < geometries.length; ++ i ) {
|
|
|
|
|
|
- var index = geometries[ i ].index;
|
|
|
|
|
|
+ const index = geometries[ i ].index;
|
|
|
|
|
|
- for ( var j = 0; j < index.count; ++ j ) {
|
|
|
|
|
|
+ for ( let j = 0; j < index.count; ++ j ) {
|
|
|
|
|
|
mergedIndex.push( index.getX( j ) + indexOffset );
|
|
mergedIndex.push( index.getX( j ) + indexOffset );
|
|
|
|
|
|
@@ -165,9 +165,9 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
// merge attributes
|
|
// merge attributes
|
|
|
|
|
|
- for ( var name in attributes ) {
|
|
|
|
|
|
+ for ( const name in attributes ) {
|
|
|
|
|
|
- var mergedAttribute = this.mergeBufferAttributes( attributes[ name ] );
|
|
|
|
|
|
+ const mergedAttribute = this.mergeBufferAttributes( attributes[ name ] );
|
|
|
|
|
|
if ( ! mergedAttribute ) {
|
|
if ( ! mergedAttribute ) {
|
|
|
|
|
|
@@ -182,26 +182,26 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
// merge morph attributes
|
|
// merge morph attributes
|
|
|
|
|
|
- for ( var name in morphAttributes ) {
|
|
|
|
|
|
+ for ( const name in morphAttributes ) {
|
|
|
|
|
|
- var numMorphTargets = morphAttributes[ name ][ 0 ].length;
|
|
|
|
|
|
+ const numMorphTargets = morphAttributes[ name ][ 0 ].length;
|
|
|
|
|
|
if ( numMorphTargets === 0 ) break;
|
|
if ( numMorphTargets === 0 ) break;
|
|
|
|
|
|
mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
|
|
mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
|
|
mergedGeometry.morphAttributes[ name ] = [];
|
|
mergedGeometry.morphAttributes[ name ] = [];
|
|
|
|
|
|
- for ( var i = 0; i < numMorphTargets; ++ i ) {
|
|
|
|
|
|
+ for ( let i = 0; i < numMorphTargets; ++ i ) {
|
|
|
|
|
|
- var morphAttributesToMerge = [];
|
|
|
|
|
|
+ const morphAttributesToMerge = [];
|
|
|
|
|
|
- for ( var j = 0; j < morphAttributes[ name ].length; ++ j ) {
|
|
|
|
|
|
+ for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) {
|
|
|
|
|
|
morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
|
|
morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var mergedMorphAttribute = this.mergeBufferAttributes( morphAttributesToMerge );
|
|
|
|
|
|
+ const mergedMorphAttribute = this.mergeBufferAttributes( morphAttributesToMerge );
|
|
|
|
|
|
if ( ! mergedMorphAttribute ) {
|
|
if ( ! mergedMorphAttribute ) {
|
|
|
|
|
|
@@ -218,22 +218,22 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
return mergedGeometry;
|
|
return mergedGeometry;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {Array<BufferAttribute>} attributes
|
|
* @param {Array<BufferAttribute>} attributes
|
|
* @return {BufferAttribute}
|
|
* @return {BufferAttribute}
|
|
*/
|
|
*/
|
|
- mergeBufferAttributes: function ( attributes ) {
|
|
|
|
|
|
+ static mergeBufferAttributes( attributes ) {
|
|
|
|
|
|
- var TypedArray;
|
|
|
|
- var itemSize;
|
|
|
|
- var normalized;
|
|
|
|
- var arrayLength = 0;
|
|
|
|
|
|
+ let TypedArray;
|
|
|
|
+ let itemSize;
|
|
|
|
+ let normalized;
|
|
|
|
+ let arrayLength = 0;
|
|
|
|
|
|
- for ( var i = 0; i < attributes.length; ++ i ) {
|
|
|
|
|
|
+ for ( let i = 0; i < attributes.length; ++ i ) {
|
|
|
|
|
|
- var attribute = attributes[ i ];
|
|
|
|
|
|
+ const attribute = attributes[ i ];
|
|
|
|
|
|
if ( attribute.isInterleavedBufferAttribute ) {
|
|
if ( attribute.isInterleavedBufferAttribute ) {
|
|
|
|
|
|
@@ -270,10 +270,10 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var array = new TypedArray( arrayLength );
|
|
|
|
- var offset = 0;
|
|
|
|
|
|
+ const array = new TypedArray( arrayLength );
|
|
|
|
+ let offset = 0;
|
|
|
|
|
|
- for ( var i = 0; i < attributes.length; ++ i ) {
|
|
|
|
|
|
+ for ( let i = 0; i < attributes.length; ++ i ) {
|
|
|
|
|
|
array.set( attributes[ i ].array, offset );
|
|
array.set( attributes[ i ].array, offset );
|
|
|
|
|
|
@@ -283,24 +283,24 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
return new BufferAttribute( array, itemSize, normalized );
|
|
return new BufferAttribute( array, itemSize, normalized );
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {Array<BufferAttribute>} attributes
|
|
* @param {Array<BufferAttribute>} attributes
|
|
* @return {Array<InterleavedBufferAttribute>}
|
|
* @return {Array<InterleavedBufferAttribute>}
|
|
*/
|
|
*/
|
|
- interleaveAttributes: function ( attributes ) {
|
|
|
|
|
|
+ static interleaveAttributes( attributes ) {
|
|
|
|
|
|
// Interleaves the provided attributes into an InterleavedBuffer and returns
|
|
// Interleaves the provided attributes into an InterleavedBuffer and returns
|
|
// a set of InterleavedBufferAttributes for each attribute
|
|
// a set of InterleavedBufferAttributes for each attribute
|
|
- var TypedArray;
|
|
|
|
- var arrayLength = 0;
|
|
|
|
- var stride = 0;
|
|
|
|
|
|
+ let TypedArray;
|
|
|
|
+ let arrayLength = 0;
|
|
|
|
+ let stride = 0;
|
|
|
|
|
|
// calculate the the length and type of the interleavedBuffer
|
|
// calculate the the length and type of the interleavedBuffer
|
|
- for ( var i = 0, l = attributes.length; i < l; ++ i ) {
|
|
|
|
|
|
+ for ( let i = 0, l = attributes.length; i < l; ++ i ) {
|
|
|
|
|
|
- var attribute = attributes[ i ];
|
|
|
|
|
|
+ const attribute = attributes[ i ];
|
|
|
|
|
|
if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
|
|
if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
|
|
if ( TypedArray !== attribute.array.constructor ) {
|
|
if ( TypedArray !== attribute.array.constructor ) {
|
|
@@ -316,27 +316,27 @@ var BufferGeometryUtils = {
|
|
}
|
|
}
|
|
|
|
|
|
// Create the set of buffer attributes
|
|
// Create the set of buffer attributes
|
|
- var interleavedBuffer = new InterleavedBuffer( new TypedArray( arrayLength ), stride );
|
|
|
|
- var offset = 0;
|
|
|
|
- var res = [];
|
|
|
|
- var getters = [ 'getX', 'getY', 'getZ', 'getW' ];
|
|
|
|
- var setters = [ 'setX', 'setY', 'setZ', 'setW' ];
|
|
|
|
-
|
|
|
|
- for ( var j = 0, l = attributes.length; j < l; j ++ ) {
|
|
|
|
-
|
|
|
|
- var attribute = attributes[ j ];
|
|
|
|
- var itemSize = attribute.itemSize;
|
|
|
|
- var count = attribute.count;
|
|
|
|
- var iba = new InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, attribute.normalized );
|
|
|
|
|
|
+ const interleavedBuffer = new InterleavedBuffer( new TypedArray( arrayLength ), stride );
|
|
|
|
+ let offset = 0;
|
|
|
|
+ const res = [];
|
|
|
|
+ const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
|
|
|
|
+ const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
|
|
|
|
+
|
|
|
|
+ for ( let j = 0, l = attributes.length; j < l; j ++ ) {
|
|
|
|
+
|
|
|
|
+ const attribute = attributes[ j ];
|
|
|
|
+ const itemSize = attribute.itemSize;
|
|
|
|
+ const count = attribute.count;
|
|
|
|
+ const iba = new InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, attribute.normalized );
|
|
res.push( iba );
|
|
res.push( iba );
|
|
|
|
|
|
offset += itemSize;
|
|
offset += itemSize;
|
|
|
|
|
|
// Move the data for each attribute into the new interleavedBuffer
|
|
// Move the data for each attribute into the new interleavedBuffer
|
|
// at the appropriate offset
|
|
// at the appropriate offset
|
|
- for ( var c = 0; c < count; c ++ ) {
|
|
|
|
|
|
+ for ( let c = 0; c < count; c ++ ) {
|
|
|
|
|
|
- for ( var k = 0; k < itemSize; k ++ ) {
|
|
|
|
|
|
+ for ( let k = 0; k < itemSize; k ++ ) {
|
|
|
|
|
|
iba[ setters[ k ] ]( c, attribute[ getters[ k ] ]( c ) );
|
|
iba[ setters[ k ] ]( c, attribute[ getters[ k ] ]( c ) );
|
|
|
|
|
|
@@ -348,65 +348,65 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
return res;
|
|
return res;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {Array<BufferGeometry>} geometry
|
|
* @param {Array<BufferGeometry>} geometry
|
|
* @return {number}
|
|
* @return {number}
|
|
*/
|
|
*/
|
|
- estimateBytesUsed: function ( geometry ) {
|
|
|
|
|
|
+ static estimateBytesUsed( geometry ) {
|
|
|
|
|
|
// Return the estimated memory used by this geometry in bytes
|
|
// Return the estimated memory used by this geometry in bytes
|
|
// Calculate using itemSize, count, and BYTES_PER_ELEMENT to account
|
|
// Calculate using itemSize, count, and BYTES_PER_ELEMENT to account
|
|
// for InterleavedBufferAttributes.
|
|
// for InterleavedBufferAttributes.
|
|
- var mem = 0;
|
|
|
|
- for ( var name in geometry.attributes ) {
|
|
|
|
|
|
+ let mem = 0;
|
|
|
|
+ for ( const name in geometry.attributes ) {
|
|
|
|
|
|
- var attr = geometry.getAttribute( name );
|
|
|
|
|
|
+ const attr = geometry.getAttribute( name );
|
|
mem += attr.count * attr.itemSize * attr.array.BYTES_PER_ELEMENT;
|
|
mem += attr.count * attr.itemSize * attr.array.BYTES_PER_ELEMENT;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var indices = geometry.getIndex();
|
|
|
|
|
|
+ const indices = geometry.getIndex();
|
|
mem += indices ? indices.count * indices.itemSize * indices.array.BYTES_PER_ELEMENT : 0;
|
|
mem += indices ? indices.count * indices.itemSize * indices.array.BYTES_PER_ELEMENT : 0;
|
|
return mem;
|
|
return mem;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {BufferGeometry} geometry
|
|
* @param {BufferGeometry} geometry
|
|
* @param {number} tolerance
|
|
* @param {number} tolerance
|
|
* @return {BufferGeometry>}
|
|
* @return {BufferGeometry>}
|
|
*/
|
|
*/
|
|
- mergeVertices: function ( geometry, tolerance = 1e-4 ) {
|
|
|
|
|
|
+ static mergeVertices( geometry, tolerance = 1e-4 ) {
|
|
|
|
|
|
tolerance = Math.max( tolerance, Number.EPSILON );
|
|
tolerance = Math.max( tolerance, Number.EPSILON );
|
|
|
|
|
|
// Generate an index buffer if the geometry doesn't have one, or optimize it
|
|
// Generate an index buffer if the geometry doesn't have one, or optimize it
|
|
// if it's already available.
|
|
// if it's already available.
|
|
- var hashToIndex = {};
|
|
|
|
- var indices = geometry.getIndex();
|
|
|
|
- var positions = geometry.getAttribute( 'position' );
|
|
|
|
- var vertexCount = indices ? indices.count : positions.count;
|
|
|
|
|
|
+ const hashToIndex = {};
|
|
|
|
+ const indices = geometry.getIndex();
|
|
|
|
+ const positions = geometry.getAttribute( 'position' );
|
|
|
|
+ const vertexCount = indices ? indices.count : positions.count;
|
|
|
|
|
|
// next value for triangle indices
|
|
// next value for triangle indices
|
|
- var nextIndex = 0;
|
|
|
|
|
|
+ let nextIndex = 0;
|
|
|
|
|
|
// attributes and new attribute arrays
|
|
// attributes and new attribute arrays
|
|
- var attributeNames = Object.keys( geometry.attributes );
|
|
|
|
- var attrArrays = {};
|
|
|
|
- var morphAttrsArrays = {};
|
|
|
|
- var newIndices = [];
|
|
|
|
- var getters = [ 'getX', 'getY', 'getZ', 'getW' ];
|
|
|
|
|
|
+ const attributeNames = Object.keys( geometry.attributes );
|
|
|
|
+ const attrArrays = {};
|
|
|
|
+ const morphAttrsArrays = {};
|
|
|
|
+ const newIndices = [];
|
|
|
|
+ const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
|
|
|
|
|
|
// initialize the arrays
|
|
// initialize the arrays
|
|
- for ( var i = 0, l = attributeNames.length; i < l; i ++ ) {
|
|
|
|
|
|
+ for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
|
|
|
|
|
|
- var name = attributeNames[ i ];
|
|
|
|
|
|
+ const name = attributeNames[ i ];
|
|
|
|
|
|
attrArrays[ name ] = [];
|
|
attrArrays[ name ] = [];
|
|
|
|
|
|
- var morphAttr = geometry.morphAttributes[ name ];
|
|
|
|
|
|
+ const morphAttr = geometry.morphAttributes[ name ];
|
|
if ( morphAttr ) {
|
|
if ( morphAttr ) {
|
|
|
|
|
|
morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
|
|
morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
|
|
@@ -416,21 +416,21 @@ var BufferGeometryUtils = {
|
|
}
|
|
}
|
|
|
|
|
|
// convert the error tolerance to an amount of decimal places to truncate to
|
|
// convert the error tolerance to an amount of decimal places to truncate to
|
|
- var decimalShift = Math.log10( 1 / tolerance );
|
|
|
|
- var shiftMultiplier = Math.pow( 10, decimalShift );
|
|
|
|
- for ( var i = 0; i < vertexCount; i ++ ) {
|
|
|
|
|
|
+ const decimalShift = Math.log10( 1 / tolerance );
|
|
|
|
+ const shiftMultiplier = Math.pow( 10, decimalShift );
|
|
|
|
+ for ( let i = 0; i < vertexCount; i ++ ) {
|
|
|
|
|
|
- var index = indices ? indices.getX( i ) : i;
|
|
|
|
|
|
+ const index = indices ? indices.getX( i ) : i;
|
|
|
|
|
|
// Generate a hash for the vertex attributes at the current index 'i'
|
|
// Generate a hash for the vertex attributes at the current index 'i'
|
|
- var hash = '';
|
|
|
|
- for ( var j = 0, l = attributeNames.length; j < l; j ++ ) {
|
|
|
|
|
|
+ let hash = '';
|
|
|
|
+ for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
|
|
|
|
|
|
- var name = attributeNames[ j ];
|
|
|
|
- var attribute = geometry.getAttribute( name );
|
|
|
|
- var itemSize = attribute.itemSize;
|
|
|
|
|
|
+ const name = attributeNames[ j ];
|
|
|
|
+ const attribute = geometry.getAttribute( name );
|
|
|
|
+ const itemSize = attribute.itemSize;
|
|
|
|
|
|
- for ( var k = 0; k < itemSize; k ++ ) {
|
|
|
|
|
|
+ for ( let k = 0; k < itemSize; k ++ ) {
|
|
|
|
|
|
// double tilde truncates the decimal value
|
|
// double tilde truncates the decimal value
|
|
hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * shiftMultiplier ) },`;
|
|
hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * shiftMultiplier ) },`;
|
|
@@ -448,23 +448,23 @@ var BufferGeometryUtils = {
|
|
} else {
|
|
} else {
|
|
|
|
|
|
// copy data to the new index in the attribute arrays
|
|
// copy data to the new index in the attribute arrays
|
|
- for ( var j = 0, l = attributeNames.length; j < l; j ++ ) {
|
|
|
|
|
|
+ for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
|
|
|
|
|
|
- var name = attributeNames[ j ];
|
|
|
|
- var attribute = geometry.getAttribute( name );
|
|
|
|
- var morphAttr = geometry.morphAttributes[ name ];
|
|
|
|
- var itemSize = attribute.itemSize;
|
|
|
|
- var newarray = attrArrays[ name ];
|
|
|
|
- var newMorphArrays = morphAttrsArrays[ name ];
|
|
|
|
|
|
+ const name = attributeNames[ j ];
|
|
|
|
+ const attribute = geometry.getAttribute( name );
|
|
|
|
+ const morphAttr = geometry.morphAttributes[ name ];
|
|
|
|
+ const itemSize = attribute.itemSize;
|
|
|
|
+ const newarray = attrArrays[ name ];
|
|
|
|
+ const newMorphArrays = morphAttrsArrays[ name ];
|
|
|
|
|
|
- for ( var k = 0; k < itemSize; k ++ ) {
|
|
|
|
|
|
+ for ( let k = 0; k < itemSize; k ++ ) {
|
|
|
|
|
|
- var getterFunc = getters[ k ];
|
|
|
|
|
|
+ const getterFunc = getters[ k ];
|
|
newarray.push( attribute[ getterFunc ]( index ) );
|
|
newarray.push( attribute[ getterFunc ]( index ) );
|
|
|
|
|
|
if ( morphAttr ) {
|
|
if ( morphAttr ) {
|
|
|
|
|
|
- for ( var m = 0, ml = morphAttr.length; m < ml; m ++ ) {
|
|
|
|
|
|
+ for ( let m = 0, ml = morphAttr.length; m < ml; m ++ ) {
|
|
|
|
|
|
newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
|
|
newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
|
|
|
|
|
|
@@ -487,25 +487,25 @@ var BufferGeometryUtils = {
|
|
// Generate typed arrays from new attribute arrays and update
|
|
// Generate typed arrays from new attribute arrays and update
|
|
// the attributeBuffers
|
|
// the attributeBuffers
|
|
const result = geometry.clone();
|
|
const result = geometry.clone();
|
|
- for ( var i = 0, l = attributeNames.length; i < l; i ++ ) {
|
|
|
|
|
|
+ for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
|
|
|
|
|
|
- var name = attributeNames[ i ];
|
|
|
|
- var oldAttribute = geometry.getAttribute( name );
|
|
|
|
|
|
+ const name = attributeNames[ i ];
|
|
|
|
+ const oldAttribute = geometry.getAttribute( name );
|
|
|
|
|
|
- var buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
|
|
|
|
- var attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
|
|
|
|
|
|
+ const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
|
|
|
|
+ const attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
|
|
|
|
|
|
result.setAttribute( name, attribute );
|
|
result.setAttribute( name, attribute );
|
|
|
|
|
|
// Update the attribute arrays
|
|
// Update the attribute arrays
|
|
if ( name in morphAttrsArrays ) {
|
|
if ( name in morphAttrsArrays ) {
|
|
|
|
|
|
- for ( var j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
|
|
|
|
|
|
+ for ( let j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
|
|
|
|
|
|
- var oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
|
|
|
|
|
|
+ const oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
|
|
|
|
|
|
- var buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
|
|
|
|
- var morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
|
|
|
|
|
|
+ const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
|
|
|
|
+ const morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
|
|
result.morphAttributes[ name ][ j ] = morphAttribute;
|
|
result.morphAttributes[ name ][ j ] = morphAttribute;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -520,14 +520,14 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
return result;
|
|
return result;
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {BufferGeometry} geometry
|
|
* @param {BufferGeometry} geometry
|
|
* @param {number} drawMode
|
|
* @param {number} drawMode
|
|
* @return {BufferGeometry>}
|
|
* @return {BufferGeometry>}
|
|
*/
|
|
*/
|
|
- toTrianglesDrawMode: function ( geometry, drawMode ) {
|
|
|
|
|
|
+ static toTrianglesDrawMode( geometry, drawMode ) {
|
|
|
|
|
|
if ( drawMode === TrianglesDrawMode ) {
|
|
if ( drawMode === TrianglesDrawMode ) {
|
|
|
|
|
|
@@ -538,19 +538,19 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
if ( drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode ) {
|
|
if ( drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode ) {
|
|
|
|
|
|
- var index = geometry.getIndex();
|
|
|
|
|
|
+ let index = geometry.getIndex();
|
|
|
|
|
|
// generate index if not present
|
|
// generate index if not present
|
|
|
|
|
|
if ( index === null ) {
|
|
if ( index === null ) {
|
|
|
|
|
|
- var indices = [];
|
|
|
|
|
|
+ const indices = [];
|
|
|
|
|
|
- var position = geometry.getAttribute( 'position' );
|
|
|
|
|
|
+ const position = geometry.getAttribute( 'position' );
|
|
|
|
|
|
if ( position !== undefined ) {
|
|
if ( position !== undefined ) {
|
|
|
|
|
|
- for ( var i = 0; i < position.count; i ++ ) {
|
|
|
|
|
|
+ for ( let i = 0; i < position.count; i ++ ) {
|
|
|
|
|
|
indices.push( i );
|
|
indices.push( i );
|
|
|
|
|
|
@@ -570,14 +570,14 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
//
|
|
//
|
|
|
|
|
|
- var numberOfTriangles = index.count - 2;
|
|
|
|
- var newIndices = [];
|
|
|
|
|
|
+ const numberOfTriangles = index.count - 2;
|
|
|
|
+ const newIndices = [];
|
|
|
|
|
|
if ( drawMode === TriangleFanDrawMode ) {
|
|
if ( drawMode === TriangleFanDrawMode ) {
|
|
|
|
|
|
// gl.TRIANGLE_FAN
|
|
// gl.TRIANGLE_FAN
|
|
|
|
|
|
- for ( var i = 1; i <= numberOfTriangles; i ++ ) {
|
|
|
|
|
|
+ for ( let i = 1; i <= numberOfTriangles; i ++ ) {
|
|
|
|
|
|
newIndices.push( index.getX( 0 ) );
|
|
newIndices.push( index.getX( 0 ) );
|
|
newIndices.push( index.getX( i ) );
|
|
newIndices.push( index.getX( i ) );
|
|
@@ -589,7 +589,7 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
// gl.TRIANGLE_STRIP
|
|
// gl.TRIANGLE_STRIP
|
|
|
|
|
|
- for ( var i = 0; i < numberOfTriangles; i ++ ) {
|
|
|
|
|
|
+ for ( let i = 0; i < numberOfTriangles; i ++ ) {
|
|
|
|
|
|
if ( i % 2 === 0 ) {
|
|
if ( i % 2 === 0 ) {
|
|
|
|
|
|
@@ -617,7 +617,7 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
// build final geometry
|
|
// build final geometry
|
|
|
|
|
|
- var newGeometry = geometry.clone();
|
|
|
|
|
|
+ const newGeometry = geometry.clone();
|
|
newGeometry.setIndex( newIndices );
|
|
newGeometry.setIndex( newIndices );
|
|
newGeometry.clearGroups();
|
|
newGeometry.clearGroups();
|
|
|
|
|
|
@@ -630,7 +630,7 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Calculates the morphed attributes of a morphed/skinned BufferGeometry.
|
|
* Calculates the morphed attributes of a morphed/skinned BufferGeometry.
|
|
@@ -638,7 +638,7 @@ var BufferGeometryUtils = {
|
|
* @param {Mesh | Line | Points} object An instance of Mesh, Line or Points.
|
|
* @param {Mesh | Line | Points} object An instance of Mesh, Line or Points.
|
|
* @return {Object} An Object with original position/normal attributes and morphed ones.
|
|
* @return {Object} An Object with original position/normal attributes and morphed ones.
|
|
*/
|
|
*/
|
|
- computeMorphedAttributes: function ( object ) {
|
|
|
|
|
|
+ static computeMorphedAttributes( object ) {
|
|
|
|
|
|
if ( object.geometry.isBufferGeometry !== true ) {
|
|
if ( object.geometry.isBufferGeometry !== true ) {
|
|
|
|
|
|
@@ -647,17 +647,17 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var _vA = new Vector3();
|
|
|
|
- var _vB = new Vector3();
|
|
|
|
- var _vC = new Vector3();
|
|
|
|
|
|
+ const _vA = new Vector3();
|
|
|
|
+ const _vB = new Vector3();
|
|
|
|
+ const _vC = new Vector3();
|
|
|
|
|
|
- var _tempA = new Vector3();
|
|
|
|
- var _tempB = new Vector3();
|
|
|
|
- var _tempC = new Vector3();
|
|
|
|
|
|
+ const _tempA = new Vector3();
|
|
|
|
+ const _tempB = new Vector3();
|
|
|
|
+ const _tempC = new Vector3();
|
|
|
|
|
|
- var _morphA = new Vector3();
|
|
|
|
- var _morphB = new Vector3();
|
|
|
|
- var _morphC = new Vector3();
|
|
|
|
|
|
+ const _morphA = new Vector3();
|
|
|
|
+ const _morphB = new Vector3();
|
|
|
|
+ const _morphC = new Vector3();
|
|
|
|
|
|
function _calculateMorphedAttributeData(
|
|
function _calculateMorphedAttributeData(
|
|
object,
|
|
object,
|
|
@@ -675,7 +675,7 @@ var BufferGeometryUtils = {
|
|
_vB.fromBufferAttribute( attribute, b );
|
|
_vB.fromBufferAttribute( attribute, b );
|
|
_vC.fromBufferAttribute( attribute, c );
|
|
_vC.fromBufferAttribute( attribute, c );
|
|
|
|
|
|
- var morphInfluences = object.morphTargetInfluences;
|
|
|
|
|
|
+ const morphInfluences = object.morphTargetInfluences;
|
|
|
|
|
|
if ( material.morphTargets && morphAttribute && morphInfluences ) {
|
|
if ( material.morphTargets && morphAttribute && morphInfluences ) {
|
|
|
|
|
|
@@ -683,10 +683,10 @@ var BufferGeometryUtils = {
|
|
_morphB.set( 0, 0, 0 );
|
|
_morphB.set( 0, 0, 0 );
|
|
_morphC.set( 0, 0, 0 );
|
|
_morphC.set( 0, 0, 0 );
|
|
|
|
|
|
- for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
|
|
|
|
|
|
+ for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
|
|
|
|
|
|
- var influence = morphInfluences[ i ];
|
|
|
|
- var morph = morphAttribute[ i ];
|
|
|
|
|
|
+ const influence = morphInfluences[ i ];
|
|
|
|
+ const morph = morphAttribute[ i ];
|
|
|
|
|
|
if ( influence === 0 ) continue;
|
|
if ( influence === 0 ) continue;
|
|
|
|
|
|
@@ -736,25 +736,25 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var geometry = object.geometry;
|
|
|
|
- var material = object.material;
|
|
|
|
|
|
+ const geometry = object.geometry;
|
|
|
|
+ const material = object.material;
|
|
|
|
|
|
- var a, b, c;
|
|
|
|
- var index = geometry.index;
|
|
|
|
- var positionAttribute = geometry.attributes.position;
|
|
|
|
- var morphPosition = geometry.morphAttributes.position;
|
|
|
|
- var morphTargetsRelative = geometry.morphTargetsRelative;
|
|
|
|
- var normalAttribute = geometry.attributes.normal;
|
|
|
|
- var morphNormal = geometry.morphAttributes.position;
|
|
|
|
|
|
+ let a, b, c;
|
|
|
|
+ const index = geometry.index;
|
|
|
|
+ const positionAttribute = geometry.attributes.position;
|
|
|
|
+ const morphPosition = geometry.morphAttributes.position;
|
|
|
|
+ const morphTargetsRelative = geometry.morphTargetsRelative;
|
|
|
|
+ const normalAttribute = geometry.attributes.normal;
|
|
|
|
+ const morphNormal = geometry.morphAttributes.position;
|
|
|
|
|
|
- var groups = geometry.groups;
|
|
|
|
- var drawRange = geometry.drawRange;
|
|
|
|
- var i, j, il, jl;
|
|
|
|
- var group, groupMaterial;
|
|
|
|
- var start, end;
|
|
|
|
|
|
+ const groups = geometry.groups;
|
|
|
|
+ const drawRange = geometry.drawRange;
|
|
|
|
+ let i, j, il, jl;
|
|
|
|
+ let group, groupMaterial;
|
|
|
|
+ let start, end;
|
|
|
|
|
|
- var modifiedPosition = new Float32Array( positionAttribute.count * positionAttribute.itemSize );
|
|
|
|
- var modifiedNormal = new Float32Array( normalAttribute.count * normalAttribute.itemSize );
|
|
|
|
|
|
+ const modifiedPosition = new Float32Array( positionAttribute.count * positionAttribute.itemSize );
|
|
|
|
+ const modifiedNormal = new Float32Array( normalAttribute.count * normalAttribute.itemSize );
|
|
|
|
|
|
if ( index !== null ) {
|
|
if ( index !== null ) {
|
|
|
|
|
|
@@ -916,8 +916,8 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var morphedPositionAttribute = new Float32BufferAttribute( modifiedPosition, 3 );
|
|
|
|
- var morphedNormalAttribute = new Float32BufferAttribute( modifiedNormal, 3 );
|
|
|
|
|
|
+ const morphedPositionAttribute = new Float32BufferAttribute( modifiedPosition, 3 );
|
|
|
|
+ const morphedNormalAttribute = new Float32BufferAttribute( modifiedNormal, 3 );
|
|
|
|
|
|
return {
|
|
return {
|
|
|
|
|
|
@@ -930,6 +930,6 @@ var BufferGeometryUtils = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-};
|
|
|
|
|
|
+}
|
|
|
|
|
|
export { BufferGeometryUtils };
|
|
export { BufferGeometryUtils };
|