@@ -972,6 +972,8 @@ function textAlign( lines, ALIGNMENT, INNER_WIDTH ) {
972
972
973
973
}
974
974
975
+ line . x = offsetX ;
976
+
975
977
}
976
978
977
979
// last operations for justifications alignments
@@ -1109,54 +1111,41 @@ function InlineManager( Base ) {
1109
1111
1110
1112
// Compute lines
1111
1113
const lines = this . computeLines ( ) ;
1114
+ lines . interLine = INTERLINE ;
1112
1115
1113
1116
/////////////////////////////////////////////////////////////////
1114
1117
// Position lines according to justifyContent and contentAlign
1115
1118
/////////////////////////////////////////////////////////////////
1116
1119
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 ) ;
1136
1121
1137
1122
// Line vertical positioning
1138
1123
1139
1124
const justificationOffset = ( ( ) => {
1140
1125
switch ( JUSTIFICATION ) {
1141
1126
1142
1127
case 'start' :
1143
- return ( INNER_HEIGHT / 2 ) - lines [ 0 ] . lineHeight ;
1128
+ return ( INNER_HEIGHT / 2 ) ;
1129
+
1144
1130
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
+
1146
1133
case 'center' :
1147
- return ( textHeight / 2 ) - lines [ 0 ] . lineHeight ;
1134
+ return ( textHeight / 2 ) ;
1135
+
1148
1136
default :
1149
1137
console . warn ( `justifyContent: '${ JUSTIFICATION } ' is not valid` ) ;
1150
1138
1151
1139
}
1152
1140
} ) ( ) ;
1153
1141
1154
- // const justificationOffset = 0;
1155
1142
1156
1143
//
1157
1144
1158
1145
lines . forEach ( ( line ) => {
1159
1146
1147
+ line . y += justificationOffset ;
1148
+
1160
1149
line . forEach ( ( inline ) => {
1161
1150
1162
1151
inline . offsetY += justificationOffset ;
@@ -1345,6 +1334,10 @@ function InlineManager( Base ) {
1345
1334
// Will stock the characters of each line, so that we can
1346
1335
// correct lines position before to merge
1347
1336
const lines = [ [ ] ] ;
1337
+ lines . height = 0 ;
1338
+
1339
+ const INTERLINE = this . getInterLine ( ) ;
1340
+ console . warn ( INTERLINE ) ;
1348
1341
1349
1342
this . childrenInlines . reduce ( ( lastInlineOffset , inlineComponent ) => {
1350
1343
@@ -1409,7 +1402,8 @@ function InlineManager( Base ) {
1409
1402
1410
1403
// Compute lines dimensions
1411
1404
1412
- lines . forEach ( ( line ) => {
1405
+ let width = 0 , height = 0 , lineOffsetY = - INTERLINE / 2 ;
1406
+ lines . forEach ( ( line , i ) => {
1413
1407
1414
1408
//
1415
1409
@@ -1434,6 +1428,7 @@ function InlineManager( Base ) {
1434
1428
//
1435
1429
1436
1430
line . width = 0 ;
1431
+ line . height = line . lineHeight ;
1437
1432
const lineHasInlines = line [ 0 ] ;
1438
1433
1439
1434
if ( lineHasInlines ) {
@@ -1451,11 +1446,35 @@ function InlineManager( Base ) {
1451
1446
1452
1447
// compute its width: length from firstInline:LEFT to lastInline:RIGHT
1453
1448
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 ) ;
1454
1469
1455
1470
}
1456
1471
1457
1472
} ) ;
1458
1473
1474
+ lines . height = height ;
1475
+ lines . width = width ;
1476
+
1477
+
1459
1478
return lines ;
1460
1479
}
1461
1480
@@ -1472,16 +1491,7 @@ function InlineManager( Base ) {
1472
1491
} ) ;
1473
1492
1474
1493
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 ) ;
1485
1495
}
1486
1496
1487
1497
/**
@@ -3384,16 +3394,17 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
3384
3394
3385
3395
if ( attribute . normalized || attribute . isInterleavedBufferAttribute ) {
3386
3396
3397
+ const srcArray = attribute . isInterleavedBufferAttribute ? attribute . data . array : attribute . array ;
3387
3398
const dstArray = new Float32Array ( attribute . getCount ( ) * attribute . itemSize ) ;
3388
3399
3389
3400
for ( let i = 0 , j = 0 ; i < attribute . getCount ( ) ; i ++ ) {
3390
3401
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 ) ;
3393
3404
3394
3405
if ( attribute . itemSize > 2 ) {
3395
3406
3396
- dstArray [ j ++ ] = attribute . getZ ( i ) ;
3407
+ dstArray [ j ++ ] = MathUtils . denormalize ( attribute . getZ ( i ) , srcArray ) ;
3397
3408
3398
3409
}
3399
3410
@@ -3732,7 +3743,7 @@ function interleaveAttributes( attributes ) {
3732
3743
let arrayLength = 0 ;
3733
3744
let stride = 0 ;
3734
3745
3735
- // calculate the length and type of the interleavedBuffer
3746
+ // calculate the the length and type of the interleavedBuffer
3736
3747
for ( let i = 0 , l = attributes . length ; i < l ; ++ i ) {
3737
3748
3738
3749
const attribute = attributes [ i ] ;
@@ -3902,7 +3913,7 @@ function estimateBytesUsed( geometry ) {
3902
3913
/**
3903
3914
* @param {BufferGeometry } geometry
3904
3915
* @param {number } tolerance
3905
- * @return {BufferGeometry }
3916
+ * @return {BufferGeometry> }
3906
3917
*/
3907
3918
function mergeVertices ( geometry , tolerance = 1e-4 ) {
3908
3919
@@ -3920,33 +3931,22 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
3920
3931
3921
3932
// attributes and new attribute arrays
3922
3933
const attributeNames = Object . keys ( geometry . attributes ) ;
3923
- const tmpAttributes = { } ;
3924
- const tmpMorphAttributes = { } ;
3934
+ const attrArrays = { } ;
3935
+ const morphAttrsArrays = { } ;
3925
3936
const newIndices = [ ] ;
3926
3937
const getters = [ 'getX' , 'getY' , 'getZ' , 'getW' ] ;
3927
- const setters = [ 'setX' , 'setY' , 'setZ' , 'setW' ] ;
3928
3938
3929
- // Initialize the arrays, allocating space conservatively. Extra
3930
- // space will be trimmed in the last step.
3939
+ // initialize the arrays
3931
3940
for ( let i = 0 , l = attributeNames . length ; i < l ; i ++ ) {
3932
3941
3933
3942
const name = attributeNames [ i ] ;
3934
- const attr = geometry . attributes [ name ] ;
3935
3943
3936
- tmpAttributes [ name ] = new BufferAttribute (
3937
- new attr . array . constructor ( attr . count * attr . itemSize ) ,
3938
- attr . itemSize ,
3939
- attr . normalized
3940
- ) ;
3944
+ attrArrays [ name ] = [ ] ;
3941
3945
3942
3946
const morphAttr = geometry . morphAttributes [ name ] ;
3943
3947
if ( morphAttr ) {
3944
3948
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 ( ( ) => [ ] ) ;
3950
3950
3951
3951
}
3952
3952
@@ -3984,27 +3984,26 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
3984
3984
3985
3985
} else {
3986
3986
3987
- // copy data to the new index in the temporary attributes
3987
+ // copy data to the new index in the attribute arrays
3988
3988
for ( let j = 0 , l = attributeNames . length ; j < l ; j ++ ) {
3989
3989
3990
3990
const name = attributeNames [ j ] ;
3991
3991
const attribute = geometry . getAttribute ( name ) ;
3992
3992
const morphAttr = geometry . morphAttributes [ name ] ;
3993
3993
const itemSize = attribute . itemSize ;
3994
- const newarray = tmpAttributes [ name ] ;
3995
- const newMorphArrays = tmpMorphAttributes [ name ] ;
3994
+ const newarray = attrArrays [ name ] ;
3995
+ const newMorphArrays = morphAttrsArrays [ name ] ;
3996
3996
3997
3997
for ( let k = 0 ; k < itemSize ; k ++ ) {
3998
3998
3999
3999
const getterFunc = getters [ k ] ;
4000
- const setterFunc = setters [ k ] ;
4001
- newarray [ setterFunc ] ( nextIndex , attribute [ getterFunc ] ( index ) ) ;
4000
+ newarray . push ( attribute [ getterFunc ] ( index ) ) ;
4002
4001
4003
4002
if ( morphAttr ) {
4004
4003
4005
4004
for ( let m = 0 , ml = morphAttr . length ; m < ml ; m ++ ) {
4006
4005
4007
- newMorphArrays [ m ] [ setterFunc ] ( nextIndex , morphAttr [ m ] [ getterFunc ] ( index ) ) ;
4006
+ newMorphArrays [ m ] . push ( morphAttr [ m ] [ getterFunc ] ( index ) ) ;
4008
4007
4009
4008
}
4010
4009
@@ -4022,29 +4021,31 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
4022
4021
4023
4022
}
4024
4023
4025
- // generate result BufferGeometry
4024
+ // Generate typed arrays from new attribute arrays and update
4025
+ // the attributeBuffers
4026
4026
const result = geometry . clone ( ) ;
4027
- for ( const name in geometry . attributes ) {
4027
+ for ( let i = 0 , l = attributeNames . length ; i < l ; i ++ ) {
4028
4028
4029
- const tmpAttribute = tmpAttributes [ name ] ;
4029
+ const name = attributeNames [ i ] ;
4030
+ const oldAttribute = geometry . getAttribute ( name ) ;
4030
4031
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 ) ;
4036
4034
4037
- if ( ! ( name in tmpMorphAttributes ) ) continue ;
4035
+ result . setAttribute ( name , attribute ) ;
4038
4036
4039
- for ( let j = 0 ; j < tmpMorphAttributes [ name ] . length ; j ++ ) {
4037
+ // Update the attribute arrays
4038
+ if ( name in morphAttrsArrays ) {
4040
4039
4041
- const tmpMorphAttribute = tmpMorphAttributes [ name ] [ j ] ;
4040
+ for ( let j = 0 ; j < morphAttrsArrays [ name ] . length ; j ++ ) {
4042
4041
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
+ }
4048
4049
4049
4050
}
4050
4051
@@ -4061,7 +4062,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
4061
4062
/**
4062
4063
* @param {BufferGeometry } geometry
4063
4064
* @param {number } drawMode
4064
- * @return {BufferGeometry }
4065
+ * @return {BufferGeometry> }
4065
4066
*/
4066
4067
function toTrianglesDrawMode ( geometry , drawMode ) {
4067
4068
@@ -4574,7 +4575,8 @@ class MSDFGlyph extends external_THREE_namespaceObject.PlaneGeometry {
4574
4575
const char = inline . glyph ;
4575
4576
const fontSize = inline . fontSize ;
4576
4577
4577
- super ( fontSize , fontSize ) ;
4578
+ // super( fontSize, fontSize );
4579
+ super ( inline . width , inline . height ) ;
4578
4580
4579
4581
// Misc glyphs
4580
4582
if ( char . match ( / \s / g ) === null ) {
@@ -4583,7 +4585,7 @@ class MSDFGlyph extends external_THREE_namespaceObject.PlaneGeometry {
4583
4585
4584
4586
this . mapUVs ( font , char ) ;
4585
4587
4586
- this . transformGeometry ( font , fontSize , char , inline ) ;
4588
+ this . transformGeometry ( inline ) ;
4587
4589
4588
4590
// White spaces (we don't want our plane geometry to have a visual width nor a height)
4589
4591
} else {
@@ -4662,26 +4664,11 @@ class MSDFGlyph extends external_THREE_namespaceObject.PlaneGeometry {
4662
4664
}
4663
4665
4664
4666
/** 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 ) {
4681
4668
4682
4669
this . translate (
4683
4670
inline . width / 2 ,
4684
- ( inline . height / 2 ) - inline . anchor ,
4671
+ inline . height / 2 ,
4685
4672
0
4686
4673
) ;
4687
4674
@@ -4743,9 +4730,9 @@ function getGlyphDimensions( options ) {
4743
4730
const xoffset = charOBJ ? charOBJ . xoffset * SCALE_MULT : 0 ;
4744
4731
4745
4732
// 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;
4747
4734
4748
- // const lineHeight = FONT.common.lineHeight * SCALE_MULT;
4735
+ const anchor = charOBJ ? charOBJ . yoffset * SCALE_MULT : 0 ;
4749
4736
4750
4737
// console.log( lineHeight )
4751
4738
0 commit comments