@@ -10,15 +10,17 @@ import { kCARTESIAN, kPOLAR, kCYLINDRICAL, kSPHERICAL, kRAPIDITY } from '../hist
10
10
import { buildHist2dContour , buildSurf3D } from '../hist2d/TH2Painter.mjs' ;
11
11
12
12
13
- function createLatexGeometry ( painter , lbl , size ) {
13
+ function createLatexGeometry ( painter , lbl , size , as_array ) {
14
14
const geom_args = { font : getHelveticaFont ( ) , size, height : 0 , curveSegments : 5 } ;
15
15
if ( THREE . REVISION > 162 )
16
16
geom_args . depth = 0 ;
17
17
else
18
18
geom_args . height = 0 ;
19
19
20
- if ( isPlainText ( lbl ) )
21
- return new THREE . TextGeometry ( translateLaTeX ( lbl ) , geom_args ) ;
20
+ if ( isPlainText ( lbl ) ) {
21
+ const res = new THREE . TextGeometry ( translateLaTeX ( lbl ) , geom_args ) ;
22
+ return as_array ? [ res ] : res ;
23
+ }
22
24
23
25
const font_size = size * 100 , geoms = [ ] ;
24
26
let stroke_width = 5 ;
@@ -92,6 +94,8 @@ function createLatexGeometry(painter, lbl, size) {
92
94
this . x += Number . parseInt ( value ) * 0.01 ;
93
95
else if ( ( name === 'y' ) && ( this . kind === 'text' ) )
94
96
this . y -= Number . parseInt ( value ) * 0.01 ;
97
+ else if ( ( name === 'fill' ) && ( this . kind === 'text' ) )
98
+ this . fill = value ;
95
99
else if ( ( name === 'd' ) && ( this . kind === 'path' ) ) {
96
100
if ( get ( ) !== 'M' )
97
101
return console . error ( 'Not starts with M' ) ;
@@ -122,6 +126,7 @@ function createLatexGeometry(painter, lbl, size) {
122
126
const pos = new Float32Array ( pnts ) ;
123
127
124
128
this . geom = new THREE . BufferGeometry ( ) ;
129
+ this . geom . _fill = this . fill ;
125
130
this . geom . setAttribute ( 'position' , new THREE . BufferAttribute ( pos , 3 ) ) ;
126
131
this . geom . scale ( 0.01 , - 0.01 , 0.01 ) ;
127
132
this . geom . computeVertexNormals ( ) ;
@@ -135,6 +140,7 @@ function createLatexGeometry(painter, lbl, size) {
135
140
if ( this . kind === 'text' ) {
136
141
geom_args . size = Math . round ( 0.01 * this . font_size ) ;
137
142
this . geom = new THREE . TextGeometry ( v , geom_args ) ;
143
+ this . geom . _fill = this . fill ;
138
144
geoms . push ( this . geom ) ;
139
145
}
140
146
}
@@ -148,11 +154,15 @@ function createLatexGeometry(painter, lbl, size) {
148
154
149
155
if ( ! geoms . length ) {
150
156
geom_args . size = size ;
151
- return new THREE . TextGeometry ( translateLaTeX ( lbl ) , geom_args ) ;
157
+ const res = new THREE . TextGeometry ( translateLaTeX ( lbl ) , geom_args ) ;
158
+ return as_array ? [ res ] : res ;
152
159
}
153
160
154
161
node . translate ( ) ; // apply translate attributes
155
162
163
+ if ( as_array )
164
+ return geoms ;
165
+
156
166
if ( geoms . length === 1 )
157
167
return geoms [ 0 ] ;
158
168
@@ -187,12 +197,17 @@ function build3dlatex(obj) {
187
197
handle = painter . createAttText ( { attr : obj } ) ,
188
198
valign = handle . align % 10 ,
189
199
halign = handle . align - valign ,
190
- text3d = createLatexGeometry ( painter , obj . fTitle , handle . getSize ( ) || 10 ) ;
200
+ arr3d = createLatexGeometry ( painter , obj . fTitle , handle . getSize ( ) || 10 , true ) ,
201
+ bb = new THREE . Box3 ( ) . makeEmpty ( ) ;
191
202
192
- text3d . computeBoundingBox ( ) ;
203
+ arr3d . forEach ( geom => {
204
+ geom . computeBoundingBox ( ) ;
205
+ bb . expandByPoint ( geom . boundingBox . max ) ;
206
+ bb . expandByPoint ( geom . boundingBox . min ) ;
207
+ } )
193
208
194
- let width = text3d . boundingBox . max . x - text3d . boundingBox . min . x ,
195
- height = text3d . boundingBox . max . y - text3d . boundingBox . min . y ;
209
+ let width = bb . max . x - bb . min . x ,
210
+ height = bb . max . y - bb . min . y ;
196
211
197
212
if ( halign === 1 )
198
213
width = 0 ;
@@ -204,11 +219,26 @@ function build3dlatex(obj) {
204
219
else if ( valign === 2 )
205
220
height *= 0.5 ;
206
221
207
- text3d . translate ( - width , - height , 0 ) ;
222
+ const materials = [ ] ,
223
+ getMaterial = color => {
224
+ if ( ! color )
225
+ color = 'black' ;
226
+ if ( ! materials [ color ] )
227
+ materials [ color ] = new THREE . MeshBasicMaterial ( getMaterialArgs ( color , { vertexColors : false } ) ) ;
228
+ return materials [ color ] ;
229
+ } ;
230
+
208
231
209
- const material = new THREE . MeshBasicMaterial ( getMaterialArgs ( handle . color || 'black' , { vertexColors : false } ) ) ;
232
+ const material0 = new THREE . MeshBasicMaterial ( getMaterialArgs ( handle . color || 'black' , { vertexColors : false } ) ) ;
233
+
234
+ const obj3d = new THREE . Object3D ( ) ;
235
+
236
+ arr3d . forEach ( geom => {
237
+ geom . translate ( - width , - height , 0 ) ;
238
+ obj3d . add ( new THREE . Mesh ( geom , getMaterial ( geom . _fill || handle . color ) ) ) ;
239
+ } ) ;
210
240
211
- return new THREE . Mesh ( text3d , material ) ;
241
+ return arr3d . length === 1 ? obj3d . children [ 0 ] : obj3d ;
212
242
}
213
243
214
244
/** @summary Text 3d axis visibility
0 commit comments