Skip to content

Commit 098cd97

Browse files
committed
6.5.2
1 parent ae9a3ef commit 098cd97

File tree

4 files changed

+95
-72
lines changed

4 files changed

+95
-72
lines changed

build/three-mesh-ui.js

+44-35
Original file line numberDiff line numberDiff line change
@@ -3384,17 +3384,16 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
33843384

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

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

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

3392-
dstArray[ j ++ ] = MathUtils.denormalize( attribute.getX( i ), srcArray );
3393-
dstArray[ j ++ ] = MathUtils.denormalize( attribute.getY( i ), srcArray );
3391+
dstArray[ j ++ ] = attribute.getX( i );
3392+
dstArray[ j ++ ] = attribute.getY( i );
33943393

33953394
if ( attribute.itemSize > 2 ) {
33963395

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

33993398
}
34003399

@@ -3733,7 +3732,7 @@ function interleaveAttributes( attributes ) {
37333732
let arrayLength = 0;
37343733
let stride = 0;
37353734

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

37393738
const attribute = attributes[ i ];
@@ -3903,7 +3902,7 @@ function estimateBytesUsed( geometry ) {
39033902
/**
39043903
* @param {BufferGeometry} geometry
39053904
* @param {number} tolerance
3906-
* @return {BufferGeometry>}
3905+
* @return {BufferGeometry}
39073906
*/
39083907
function mergeVertices( geometry, tolerance = 1e-4 ) {
39093908

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

39223921
// attributes and new attribute arrays
39233922
const attributeNames = Object.keys( geometry.attributes );
3924-
const attrArrays = {};
3925-
const morphAttrsArrays = {};
3923+
const tmpAttributes = {};
3924+
const tmpMorphAttributes = {};
39263925
const newIndices = [];
39273926
const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
3927+
const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
39283928

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

39323933
const name = attributeNames[ i ];
3934+
const attr = geometry.attributes[ name ];
39333935

3934-
attrArrays[ name ] = [];
3936+
tmpAttributes[ name ] = new BufferAttribute(
3937+
new attr.array.constructor( attr.count * attr.itemSize ),
3938+
attr.itemSize,
3939+
attr.normalized
3940+
);
39353941

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

3939-
morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
3945+
tmpMorphAttributes[ name ] = new BufferAttribute(
3946+
new morphAttr.array.constructor( morphAttr.count * morphAttr.itemSize ),
3947+
morphAttr.itemSize,
3948+
morphAttr.normalized
3949+
);
39403950

39413951
}
39423952

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

39753985
} else {
39763986

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

39803990
const name = attributeNames[ j ];
39813991
const attribute = geometry.getAttribute( name );
39823992
const morphAttr = geometry.morphAttributes[ name ];
39833993
const itemSize = attribute.itemSize;
3984-
const newarray = attrArrays[ name ];
3985-
const newMorphArrays = morphAttrsArrays[ name ];
3994+
const newarray = tmpAttributes[ name ];
3995+
const newMorphArrays = tmpMorphAttributes[ name ];
39863996

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

39893999
const getterFunc = getters[ k ];
3990-
newarray.push( attribute[ getterFunc ]( index ) );
4000+
const setterFunc = setters[ k ];
4001+
newarray[ setterFunc ]( nextIndex, attribute[ getterFunc ]( index ) );
39914002

39924003
if ( morphAttr ) {
39934004

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

3996-
newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
4007+
newMorphArrays[ m ][ setterFunc ]( nextIndex, morphAttr[ m ][ getterFunc ]( index ) );
39974008

39984009
}
39994010

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

40124023
}
40134024

4014-
// Generate typed arrays from new attribute arrays and update
4015-
// the attributeBuffers
4025+
// generate result BufferGeometry
40164026
const result = geometry.clone();
4017-
for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
4018-
4019-
const name = attributeNames[ i ];
4020-
const oldAttribute = geometry.getAttribute( name );
4021-
4022-
const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
4023-
const attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
4027+
for ( const name in geometry.attributes ) {
40244028

4025-
result.setAttribute( name, attribute );
4029+
const tmpAttribute = tmpAttributes[ name ];
40264030

4027-
// Update the attribute arrays
4028-
if ( name in morphAttrsArrays ) {
4031+
result.setAttribute( name, new BufferAttribute(
4032+
tmpAttribute.array.slice( 0, nextIndex * tmpAttribute.itemSize ),
4033+
tmpAttribute.itemSize,
4034+
tmpAttribute.normalized,
4035+
) );
40294036

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

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

4034-
const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
4035-
const morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
4036-
result.morphAttributes[ name ][ j ] = morphAttribute;
4041+
const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ];
40374042

4038-
}
4043+
result.morphAttributes[ name ][ j ] = new BufferAttribute(
4044+
tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ),
4045+
tmpMorphAttribute.itemSize,
4046+
tmpMorphAttribute.normalized,
4047+
);
40394048

40404049
}
40414050

@@ -4052,7 +4061,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
40524061
/**
40534062
* @param {BufferGeometry} geometry
40544063
* @param {number} drawMode
4055-
* @return {BufferGeometry>}
4064+
* @return {BufferGeometry}
40564065
*/
40574066
function toTrianglesDrawMode( geometry, drawMode ) {
40584067

build/three-mesh-ui.module.js

+44-35
Original file line numberDiff line numberDiff line change
@@ -3387,17 +3387,16 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
33873387

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

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

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

3395-
dstArray[ j ++ ] = MathUtils.denormalize( attribute.getX( i ), srcArray );
3396-
dstArray[ j ++ ] = MathUtils.denormalize( attribute.getY( i ), srcArray );
3394+
dstArray[ j ++ ] = attribute.getX( i );
3395+
dstArray[ j ++ ] = attribute.getY( i );
33973396

33983397
if ( attribute.itemSize > 2 ) {
33993398

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

34023401
}
34033402

@@ -3736,7 +3735,7 @@ function interleaveAttributes( attributes ) {
37363735
let arrayLength = 0;
37373736
let stride = 0;
37383737

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

37423741
const attribute = attributes[ i ];
@@ -3906,7 +3905,7 @@ function estimateBytesUsed( geometry ) {
39063905
/**
39073906
* @param {BufferGeometry} geometry
39083907
* @param {number} tolerance
3909-
* @return {BufferGeometry>}
3908+
* @return {BufferGeometry}
39103909
*/
39113910
function mergeVertices( geometry, tolerance = 1e-4 ) {
39123911

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

39253924
// attributes and new attribute arrays
39263925
const attributeNames = Object.keys( geometry.attributes );
3927-
const attrArrays = {};
3928-
const morphAttrsArrays = {};
3926+
const tmpAttributes = {};
3927+
const tmpMorphAttributes = {};
39293928
const newIndices = [];
39303929
const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
3930+
const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
39313931

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

39353936
const name = attributeNames[ i ];
3937+
const attr = geometry.attributes[ name ];
39363938

3937-
attrArrays[ name ] = [];
3939+
tmpAttributes[ name ] = new BufferAttribute(
3940+
new attr.array.constructor( attr.count * attr.itemSize ),
3941+
attr.itemSize,
3942+
attr.normalized
3943+
);
39383944

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

3942-
morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
3948+
tmpMorphAttributes[ name ] = new BufferAttribute(
3949+
new morphAttr.array.constructor( morphAttr.count * morphAttr.itemSize ),
3950+
morphAttr.itemSize,
3951+
morphAttr.normalized
3952+
);
39433953

39443954
}
39453955

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

39783988
} else {
39793989

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

39833993
const name = attributeNames[ j ];
39843994
const attribute = geometry.getAttribute( name );
39853995
const morphAttr = geometry.morphAttributes[ name ];
39863996
const itemSize = attribute.itemSize;
3987-
const newarray = attrArrays[ name ];
3988-
const newMorphArrays = morphAttrsArrays[ name ];
3997+
const newarray = tmpAttributes[ name ];
3998+
const newMorphArrays = tmpMorphAttributes[ name ];
39893999

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

39924002
const getterFunc = getters[ k ];
3993-
newarray.push( attribute[ getterFunc ]( index ) );
4003+
const setterFunc = setters[ k ];
4004+
newarray[ setterFunc ]( nextIndex, attribute[ getterFunc ]( index ) );
39944005

39954006
if ( morphAttr ) {
39964007

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

3999-
newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
4010+
newMorphArrays[ m ][ setterFunc ]( nextIndex, morphAttr[ m ][ getterFunc ]( index ) );
40004011

40014012
}
40024013

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

40154026
}
40164027

4017-
// Generate typed arrays from new attribute arrays and update
4018-
// the attributeBuffers
4028+
// generate result BufferGeometry
40194029
const result = geometry.clone();
4020-
for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
4021-
4022-
const name = attributeNames[ i ];
4023-
const oldAttribute = geometry.getAttribute( name );
4024-
4025-
const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
4026-
const attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
4030+
for ( const name in geometry.attributes ) {
40274031

4028-
result.setAttribute( name, attribute );
4032+
const tmpAttribute = tmpAttributes[ name ];
40294033

4030-
// Update the attribute arrays
4031-
if ( name in morphAttrsArrays ) {
4034+
result.setAttribute( name, new BufferAttribute(
4035+
tmpAttribute.array.slice( 0, nextIndex * tmpAttribute.itemSize ),
4036+
tmpAttribute.itemSize,
4037+
tmpAttribute.normalized,
4038+
) );
40324039

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

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

4037-
const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
4038-
const morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
4039-
result.morphAttributes[ name ][ j ] = morphAttribute;
4044+
const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ];
40404045

4041-
}
4046+
result.morphAttributes[ name ][ j ] = new BufferAttribute(
4047+
tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ),
4048+
tmpMorphAttribute.itemSize,
4049+
tmpMorphAttribute.normalized,
4050+
);
40424051

40434052
}
40444053

@@ -4055,7 +4064,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
40554064
/**
40564065
* @param {BufferGeometry} geometry
40574066
* @param {number} drawMode
4058-
* @return {BufferGeometry>}
4067+
* @return {BufferGeometry}
40594068
*/
40604069
function toTrianglesDrawMode( geometry, drawMode ) {
40614070

package-lock.json

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "three-mesh-ui",
3-
"version": "6.5.1",
3+
"version": "6.5.2",
44
"description": "a library on top of three.js to help in creating 3D user interfaces",
55
"engines": {
66
"node": "x.x.x"

0 commit comments

Comments
 (0)