Skip to content

Commit

Permalink
6.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
swingingtom committed Oct 13, 2022
1 parent ae9a3ef commit 098cd97
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 72 deletions.
79 changes: 44 additions & 35 deletions build/three-mesh-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3384,17 +3384,16 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {

if ( attribute.normalized || attribute.isInterleavedBufferAttribute ) {

const srcArray = attribute.isInterleavedBufferAttribute ? attribute.data.array : attribute.array;
const dstArray = new Float32Array( attribute.getCount() * attribute.itemSize );

for ( let i = 0, j = 0; i < attribute.getCount(); i ++ ) {

dstArray[ j ++ ] = MathUtils.denormalize( attribute.getX( i ), srcArray );
dstArray[ j ++ ] = MathUtils.denormalize( attribute.getY( i ), srcArray );
dstArray[ j ++ ] = attribute.getX( i );
dstArray[ j ++ ] = attribute.getY( i );

if ( attribute.itemSize > 2 ) {

dstArray[ j ++ ] = MathUtils.denormalize( attribute.getZ( i ), srcArray );
dstArray[ j ++ ] = attribute.getZ( i );

}

Expand Down Expand Up @@ -3733,7 +3732,7 @@ function interleaveAttributes( attributes ) {
let arrayLength = 0;
let stride = 0;

// calculate the the length and type of the interleavedBuffer
// calculate the length and type of the interleavedBuffer
for ( let i = 0, l = attributes.length; i < l; ++ i ) {

const attribute = attributes[ i ];
Expand Down Expand Up @@ -3903,7 +3902,7 @@ function estimateBytesUsed( geometry ) {
/**
* @param {BufferGeometry} geometry
* @param {number} tolerance
* @return {BufferGeometry>}
* @return {BufferGeometry}
*/
function mergeVertices( geometry, tolerance = 1e-4 ) {

Expand All @@ -3921,22 +3920,33 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {

// attributes and new attribute arrays
const attributeNames = Object.keys( geometry.attributes );
const attrArrays = {};
const morphAttrsArrays = {};
const tmpAttributes = {};
const tmpMorphAttributes = {};
const newIndices = [];
const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
const setters = [ 'setX', 'setY', 'setZ', 'setW' ];

// initialize the arrays
// Initialize the arrays, allocating space conservatively. Extra
// space will be trimmed in the last step.
for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {

const name = attributeNames[ i ];
const attr = geometry.attributes[ name ];

attrArrays[ name ] = [];
tmpAttributes[ name ] = new BufferAttribute(
new attr.array.constructor( attr.count * attr.itemSize ),
attr.itemSize,
attr.normalized
);

const morphAttr = geometry.morphAttributes[ name ];
if ( morphAttr ) {

morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
tmpMorphAttributes[ name ] = new BufferAttribute(
new morphAttr.array.constructor( morphAttr.count * morphAttr.itemSize ),
morphAttr.itemSize,
morphAttr.normalized
);

}

Expand Down Expand Up @@ -3974,26 +3984,27 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {

} else {

// copy data to the new index in the attribute arrays
// copy data to the new index in the temporary attributes
for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {

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 ];
const newarray = tmpAttributes[ name ];
const newMorphArrays = tmpMorphAttributes[ name ];

for ( let k = 0; k < itemSize; k ++ ) {

const getterFunc = getters[ k ];
newarray.push( attribute[ getterFunc ]( index ) );
const setterFunc = setters[ k ];
newarray[ setterFunc ]( nextIndex, attribute[ getterFunc ]( index ) );

if ( morphAttr ) {

for ( let m = 0, ml = morphAttr.length; m < ml; m ++ ) {

newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
newMorphArrays[ m ][ setterFunc ]( nextIndex, morphAttr[ m ][ getterFunc ]( index ) );

}

Expand All @@ -4011,31 +4022,29 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {

}

// Generate typed arrays from new attribute arrays and update
// the attributeBuffers
// generate result BufferGeometry
const result = geometry.clone();
for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {

const name = attributeNames[ i ];
const oldAttribute = geometry.getAttribute( name );

const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
const attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
for ( const name in geometry.attributes ) {

result.setAttribute( name, attribute );
const tmpAttribute = tmpAttributes[ name ];

// Update the attribute arrays
if ( name in morphAttrsArrays ) {
result.setAttribute( name, new BufferAttribute(
tmpAttribute.array.slice( 0, nextIndex * tmpAttribute.itemSize ),
tmpAttribute.itemSize,
tmpAttribute.normalized,
) );

for ( let j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
if ( ! ( name in tmpMorphAttributes ) ) continue;

const oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
for ( let j = 0; j < tmpMorphAttributes[ name ].length; j ++ ) {

const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
const morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
result.morphAttributes[ name ][ j ] = morphAttribute;
const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ];

}
result.morphAttributes[ name ][ j ] = new BufferAttribute(
tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ),
tmpMorphAttribute.itemSize,
tmpMorphAttribute.normalized,
);

}

Expand All @@ -4052,7 +4061,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
/**
* @param {BufferGeometry} geometry
* @param {number} drawMode
* @return {BufferGeometry>}
* @return {BufferGeometry}
*/
function toTrianglesDrawMode( geometry, drawMode ) {

Expand Down
79 changes: 44 additions & 35 deletions build/three-mesh-ui.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3387,17 +3387,16 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {

if ( attribute.normalized || attribute.isInterleavedBufferAttribute ) {

const srcArray = attribute.isInterleavedBufferAttribute ? attribute.data.array : attribute.array;
const dstArray = new Float32Array( attribute.getCount() * attribute.itemSize );

for ( let i = 0, j = 0; i < attribute.getCount(); i ++ ) {

dstArray[ j ++ ] = MathUtils.denormalize( attribute.getX( i ), srcArray );
dstArray[ j ++ ] = MathUtils.denormalize( attribute.getY( i ), srcArray );
dstArray[ j ++ ] = attribute.getX( i );
dstArray[ j ++ ] = attribute.getY( i );

if ( attribute.itemSize > 2 ) {

dstArray[ j ++ ] = MathUtils.denormalize( attribute.getZ( i ), srcArray );
dstArray[ j ++ ] = attribute.getZ( i );

}

Expand Down Expand Up @@ -3736,7 +3735,7 @@ function interleaveAttributes( attributes ) {
let arrayLength = 0;
let stride = 0;

// calculate the the length and type of the interleavedBuffer
// calculate the length and type of the interleavedBuffer
for ( let i = 0, l = attributes.length; i < l; ++ i ) {

const attribute = attributes[ i ];
Expand Down Expand Up @@ -3906,7 +3905,7 @@ function estimateBytesUsed( geometry ) {
/**
* @param {BufferGeometry} geometry
* @param {number} tolerance
* @return {BufferGeometry>}
* @return {BufferGeometry}
*/
function mergeVertices( geometry, tolerance = 1e-4 ) {

Expand All @@ -3924,22 +3923,33 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {

// attributes and new attribute arrays
const attributeNames = Object.keys( geometry.attributes );
const attrArrays = {};
const morphAttrsArrays = {};
const tmpAttributes = {};
const tmpMorphAttributes = {};
const newIndices = [];
const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
const setters = [ 'setX', 'setY', 'setZ', 'setW' ];

// initialize the arrays
// Initialize the arrays, allocating space conservatively. Extra
// space will be trimmed in the last step.
for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {

const name = attributeNames[ i ];
const attr = geometry.attributes[ name ];

attrArrays[ name ] = [];
tmpAttributes[ name ] = new BufferAttribute(
new attr.array.constructor( attr.count * attr.itemSize ),
attr.itemSize,
attr.normalized
);

const morphAttr = geometry.morphAttributes[ name ];
if ( morphAttr ) {

morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
tmpMorphAttributes[ name ] = new BufferAttribute(
new morphAttr.array.constructor( morphAttr.count * morphAttr.itemSize ),
morphAttr.itemSize,
morphAttr.normalized
);

}

Expand Down Expand Up @@ -3977,26 +3987,27 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {

} else {

// copy data to the new index in the attribute arrays
// copy data to the new index in the temporary attributes
for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {

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 ];
const newarray = tmpAttributes[ name ];
const newMorphArrays = tmpMorphAttributes[ name ];

for ( let k = 0; k < itemSize; k ++ ) {

const getterFunc = getters[ k ];
newarray.push( attribute[ getterFunc ]( index ) );
const setterFunc = setters[ k ];
newarray[ setterFunc ]( nextIndex, attribute[ getterFunc ]( index ) );

if ( morphAttr ) {

for ( let m = 0, ml = morphAttr.length; m < ml; m ++ ) {

newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
newMorphArrays[ m ][ setterFunc ]( nextIndex, morphAttr[ m ][ getterFunc ]( index ) );

}

Expand All @@ -4014,31 +4025,29 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {

}

// Generate typed arrays from new attribute arrays and update
// the attributeBuffers
// generate result BufferGeometry
const result = geometry.clone();
for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {

const name = attributeNames[ i ];
const oldAttribute = geometry.getAttribute( name );

const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
const attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
for ( const name in geometry.attributes ) {

result.setAttribute( name, attribute );
const tmpAttribute = tmpAttributes[ name ];

// Update the attribute arrays
if ( name in morphAttrsArrays ) {
result.setAttribute( name, new BufferAttribute(
tmpAttribute.array.slice( 0, nextIndex * tmpAttribute.itemSize ),
tmpAttribute.itemSize,
tmpAttribute.normalized,
) );

for ( let j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
if ( ! ( name in tmpMorphAttributes ) ) continue;

const oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
for ( let j = 0; j < tmpMorphAttributes[ name ].length; j ++ ) {

const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
const morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
result.morphAttributes[ name ][ j ] = morphAttribute;
const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ];

}
result.morphAttributes[ name ][ j ] = new BufferAttribute(
tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ),
tmpMorphAttribute.itemSize,
tmpMorphAttribute.normalized,
);

}

Expand All @@ -4055,7 +4064,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
/**
* @param {BufferGeometry} geometry
* @param {number} drawMode
* @return {BufferGeometry>}
* @return {BufferGeometry}
*/
function toTrianglesDrawMode( geometry, drawMode ) {

Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "three-mesh-ui",
"version": "6.5.1",
"version": "6.5.2",
"description": "a library on top of three.js to help in creating 3D user interfaces",
"engines": {
"node": "x.x.x"
Expand Down

0 comments on commit 098cd97

Please sign in to comment.