Skip to content

Commit f70d77d

Browse files
committed
6.5.3
1 parent 24fd2b7 commit f70d77d

6 files changed

+176
-202
lines changed

build/three-mesh-ui.js

+86-99
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,8 @@ function textAlign( lines, ALIGNMENT, INNER_WIDTH ) {
972972

973973
}
974974

975+
line.x = offsetX;
976+
975977
}
976978

977979
// last operations for justifications alignments
@@ -1109,54 +1111,41 @@ function InlineManager( Base ) {
11091111

11101112
// Compute lines
11111113
const lines = this.computeLines();
1114+
lines.interLine = INTERLINE;
11121115

11131116
/////////////////////////////////////////////////////////////////
11141117
// Position lines according to justifyContent and contentAlign
11151118
/////////////////////////////////////////////////////////////////
11161119

1117-
// individual vertical offset
1118-
1119-
let textHeight = lines.reduce( ( offsetY, line, i, arr ) => {
1120-
1121-
const charAlignement = line.lineHeight - line.lineBase;
1122-
1123-
line.forEach( ( inline ) => {
1124-
1125-
inline.offsetY = offsetY - line.lineHeight + charAlignement + arr[ 0 ].lineHeight;
1126-
1127-
} );
1128-
1129-
return offsetY - line.lineHeight - INTERLINE;
1130-
1131-
}, 0 ) + INTERLINE;
1132-
1133-
//
1134-
1135-
textHeight = Math.abs( textHeight );
1120+
const textHeight = Math.abs( lines.height );
11361121

11371122
// Line vertical positioning
11381123

11391124
const justificationOffset = ( () => {
11401125
switch ( JUSTIFICATION ) {
11411126

11421127
case 'start':
1143-
return ( INNER_HEIGHT / 2 ) - lines[ 0 ].lineHeight;
1128+
return (INNER_HEIGHT/2);
1129+
11441130
case 'end':
1145-
return textHeight - lines[ 0 ].lineHeight - ( INNER_HEIGHT / 2 ) + ( lines[ lines.length - 1 ].lineHeight - lines[ lines.length - 1 ].lineHeight );
1131+
return textHeight - ( INNER_HEIGHT / 2 );
1132+
11461133
case 'center':
1147-
return ( textHeight / 2 ) - lines[ 0 ].lineHeight;
1134+
return ( textHeight / 2 );
1135+
11481136
default:
11491137
console.warn( `justifyContent: '${JUSTIFICATION}' is not valid` );
11501138

11511139
}
11521140
} )();
11531141

1154-
// const justificationOffset = 0;
11551142

11561143
//
11571144

11581145
lines.forEach( ( line ) => {
11591146

1147+
line.y += justificationOffset;
1148+
11601149
line.forEach( ( inline ) => {
11611150

11621151
inline.offsetY += justificationOffset;
@@ -1345,6 +1334,10 @@ function InlineManager( Base ) {
13451334
// Will stock the characters of each line, so that we can
13461335
// correct lines position before to merge
13471336
const lines = [ [] ];
1337+
lines.height = 0;
1338+
1339+
const INTERLINE = this.getInterLine();
1340+
console.warn(INTERLINE);
13481341

13491342
this.childrenInlines.reduce( ( lastInlineOffset, inlineComponent ) => {
13501343

@@ -1409,7 +1402,8 @@ function InlineManager( Base ) {
14091402

14101403
// Compute lines dimensions
14111404

1412-
lines.forEach( ( line ) => {
1405+
let width = 0, height =0, lineOffsetY = -INTERLINE/2;
1406+
lines.forEach( ( line, i ) => {
14131407

14141408
//
14151409

@@ -1434,6 +1428,7 @@ function InlineManager( Base ) {
14341428
//
14351429

14361430
line.width = 0;
1431+
line.height = line.lineHeight;
14371432
const lineHasInlines = line[ 0 ];
14381433

14391434
if ( lineHasInlines ) {
@@ -1451,11 +1446,35 @@ function InlineManager( Base ) {
14511446

14521447
// compute its width: length from firstInline:LEFT to lastInline:RIGHT
14531448
line.width = this.computeLineWidth( line );
1449+
if( line.width > width ){
1450+
width = line.width;
1451+
}
1452+
1453+
line.forEach( ( inline ) => {
1454+
1455+
inline.offsetY = (lineOffsetY - inline.height) - inline.anchor;
1456+
1457+
if( inline.lineHeight < line.lineHeight ){
1458+
inline.offsetY -= line.lineBase- inline.lineBase;
1459+
}
1460+
1461+
} );
1462+
1463+
line.y = lineOffsetY;
1464+
// line.x will be set by textAlign
1465+
1466+
height += ( line.lineHeight + INTERLINE );
1467+
1468+
lineOffsetY = lineOffsetY - (line.lineHeight + INTERLINE );
14541469

14551470
}
14561471

14571472
} );
14581473

1474+
lines.height = height;
1475+
lines.width = width;
1476+
1477+
14591478
return lines;
14601479
}
14611480

@@ -1472,16 +1491,7 @@ function InlineManager( Base ) {
14721491
} );
14731492

14741493
const lines = this.computeLines();
1475-
1476-
const INTERLINE = this.getInterLine();
1477-
1478-
const textHeight = lines.reduce( ( offsetY, line ) => {
1479-
1480-
return offsetY - line.lineHeight - INTERLINE;
1481-
1482-
}, 0 ) + INTERLINE;
1483-
1484-
return Math.abs( textHeight );
1494+
return Math.abs( lines.height );
14851495
}
14861496

14871497
/**
@@ -3384,16 +3394,17 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
33843394

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

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

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

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

33943405
if ( attribute.itemSize > 2 ) {
33953406

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

33983409
}
33993410

@@ -3732,7 +3743,7 @@ function interleaveAttributes( attributes ) {
37323743
let arrayLength = 0;
37333744
let stride = 0;
37343745

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

37383749
const attribute = attributes[ i ];
@@ -3902,7 +3913,7 @@ function estimateBytesUsed( geometry ) {
39023913
/**
39033914
* @param {BufferGeometry} geometry
39043915
* @param {number} tolerance
3905-
* @return {BufferGeometry}
3916+
* @return {BufferGeometry>}
39063917
*/
39073918
function mergeVertices( geometry, tolerance = 1e-4 ) {
39083919

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

39213932
// attributes and new attribute arrays
39223933
const attributeNames = Object.keys( geometry.attributes );
3923-
const tmpAttributes = {};
3924-
const tmpMorphAttributes = {};
3934+
const attrArrays = {};
3935+
const morphAttrsArrays = {};
39253936
const newIndices = [];
39263937
const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
3927-
const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
39283938

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

39333942
const name = attributeNames[ i ];
3934-
const attr = geometry.attributes[ name ];
39353943

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

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

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

39513951
}
39523952

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

39853985
} else {
39863986

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

39903990
const name = attributeNames[ j ];
39913991
const attribute = geometry.getAttribute( name );
39923992
const morphAttr = geometry.morphAttributes[ name ];
39933993
const itemSize = attribute.itemSize;
3994-
const newarray = tmpAttributes[ name ];
3995-
const newMorphArrays = tmpMorphAttributes[ name ];
3994+
const newarray = attrArrays[ name ];
3995+
const newMorphArrays = morphAttrsArrays[ name ];
39963996

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

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

40034002
if ( morphAttr ) {
40044003

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

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

40094008
}
40104009

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

40234022
}
40244023

4025-
// generate result BufferGeometry
4024+
// Generate typed arrays from new attribute arrays and update
4025+
// the attributeBuffers
40264026
const result = geometry.clone();
4027-
for ( const name in geometry.attributes ) {
4027+
for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
40284028

4029-
const tmpAttribute = tmpAttributes[ name ];
4029+
const name = attributeNames[ i ];
4030+
const oldAttribute = geometry.getAttribute( name );
40304031

4031-
result.setAttribute( name, new BufferAttribute(
4032-
tmpAttribute.array.slice( 0, nextIndex * tmpAttribute.itemSize ),
4033-
tmpAttribute.itemSize,
4034-
tmpAttribute.normalized,
4035-
) );
4032+
const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
4033+
const attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
40364034

4037-
if ( ! ( name in tmpMorphAttributes ) ) continue;
4035+
result.setAttribute( name, attribute );
40384036

4039-
for ( let j = 0; j < tmpMorphAttributes[ name ].length; j ++ ) {
4037+
// Update the attribute arrays
4038+
if ( name in morphAttrsArrays ) {
40404039

4041-
const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ];
4040+
for ( let j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
40424041

4043-
result.morphAttributes[ name ][ j ] = new BufferAttribute(
4044-
tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ),
4045-
tmpMorphAttribute.itemSize,
4046-
tmpMorphAttribute.normalized,
4047-
);
4042+
const oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
4043+
4044+
const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
4045+
const morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
4046+
result.morphAttributes[ name ][ j ] = morphAttribute;
4047+
4048+
}
40484049

40494050
}
40504051

@@ -4061,7 +4062,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
40614062
/**
40624063
* @param {BufferGeometry} geometry
40634064
* @param {number} drawMode
4064-
* @return {BufferGeometry}
4065+
* @return {BufferGeometry>}
40654066
*/
40664067
function toTrianglesDrawMode( geometry, drawMode ) {
40674068

@@ -4574,7 +4575,8 @@ class MSDFGlyph extends external_THREE_namespaceObject.PlaneGeometry {
45744575
const char = inline.glyph;
45754576
const fontSize = inline.fontSize;
45764577

4577-
super( fontSize, fontSize );
4578+
// super( fontSize, fontSize );
4579+
super( inline.width, inline.height );
45784580

45794581
// Misc glyphs
45804582
if ( char.match( /\s/g ) === null ) {
@@ -4583,7 +4585,7 @@ class MSDFGlyph extends external_THREE_namespaceObject.PlaneGeometry {
45834585

45844586
this.mapUVs( font, char );
45854587

4586-
this.transformGeometry( font, fontSize, char, inline );
4588+
this.transformGeometry( inline );
45874589

45884590
// White spaces (we don't want our plane geometry to have a visual width nor a height)
45894591
} else {
@@ -4662,26 +4664,11 @@ class MSDFGlyph extends external_THREE_namespaceObject.PlaneGeometry {
46624664
}
46634665

46644666
/** Gives the previously computed scale and offset to the geometry */
4665-
transformGeometry( font, fontSize, char, inline ) {
4666-
4667-
const charOBJ = font.chars.find( charOBJ => charOBJ.char === char );
4668-
4669-
const common = font.common;
4670-
4671-
const newHeight = charOBJ.height / common.lineHeight;
4672-
const newWidth = ( charOBJ.width * newHeight ) / charOBJ.height;
4673-
4674-
this.scale(
4675-
newWidth,
4676-
newHeight,
4677-
1
4678-
);
4679-
4680-
//
4667+
transformGeometry( inline ) {
46814668

46824669
this.translate(
46834670
inline.width / 2,
4684-
( inline.height / 2 ) - inline.anchor,
4671+
inline.height / 2,
46854672
0
46864673
);
46874674

@@ -4743,9 +4730,9 @@ function getGlyphDimensions( options ) {
47434730
const xoffset = charOBJ ? charOBJ.xoffset * SCALE_MULT : 0;
47444731

47454732
// world-space length between lowest point and the text cursor position
4746-
const anchor = charOBJ ? ( ( charOBJ.yoffset + charOBJ.height - FONT.common.base ) * FONT_SIZE ) / FONT.common.lineHeight : 0;
4733+
// const anchor = charOBJ ? ( ( charOBJ.yoffset + charOBJ.height - FONT.common.base ) * FONT_SIZE ) / FONT.common.lineHeight : 0;
47474734

4748-
// const lineHeight = FONT.common.lineHeight * SCALE_MULT;
4735+
const anchor = charOBJ ? charOBJ.yoffset * SCALE_MULT : 0;
47494736

47504737
// console.log( lineHeight )
47514738

build/three-mesh-ui.min.js

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

0 commit comments

Comments
 (0)