-
Notifications
You must be signed in to change notification settings - Fork 18
/
text.go
718 lines (547 loc) · 22.1 KB
/
text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
package tetra3d
import (
"fmt"
"image/color"
"math"
"strings"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text"
"golang.org/x/image/font"
"golang.org/x/image/font/basicfont"
_ "embed"
)
type TextHorizontalAlignment int
type TextVerticalAlignment int
const (
TextAlignHorizontalLeft TextHorizontalAlignment = iota // Left aligned text. The text hugs the left side of the texture.
TextAlignHorizontalCenter // Center aligned text. All text lines are centered horizontally in the texture's width.
TextAlignHorizontalRight // Right aligned text. The text hugs the right side of the texture.
TextAlignVerticalTop TextVerticalAlignment = iota // Top aligned text. The text hugs the top side of the texture.
TextAlignVerticalCenter // Center aligned text. All text lines are centered horizontally in the texture's width.
TextAlignVerticalBottom // Bottom aligned text. The text hugs the bottom side of the texture.
)
type TextStyle struct {
Font font.Face // The font face to use for rendering the text. The size is customizeable, but the DPI should be 72.
Cursor string // A cursor string sequence is drawn at the end while typewriter-ing; defaults to a blank string ("").
LineHeightMultiplier float64 // The multiplier for line height changes.
AlignmentHorizontal TextHorizontalAlignment // How the text should be horizontally aligned in the Text texture.
AlignmentVertical TextVerticalAlignment
BGColor Color // The Background color for the text. Defaults to black (0, 0, 0, 1).
FGColor Color // The Foreground color for the text. Defaults to white (1, 1, 1, 1).
ShadowDirection Vector // A vector indicating direction of the shadow's heading. Defaults to down-right ( {1, 1, 0}, normalized ).
ShadowLength int // The length of the shadow in pixels. Defaults to 0 (no shadow).
ShadowColorNear Color // The color of the shadow near the letters. Defaults to black (0, 0, 0, 1).
ShadowColorFar Color // The color of the shadow towards the end of the letters. Defaults to black (0, 0, 0, 1).
OutlineThickness int // Overall thickness of the outline in pixels. Defaults to 0 (no outline).
OutlineRounded bool // If the outline is rounded or not. Defaults to false (square outlines).
OutlineColor Color // Color of the outline. Defaults to black (0, 0, 0, 1).
// Margin (in pixels) of space to leave around the frame of the texture (left or right, depending on HorizontalAlignment, and from the top). Defaults to 0.
MarginHorizontal, MarginVertical int
// Manual offsets to positioning
OffsetX, OffsetY int
}
func NewDefaultTextStyle() TextStyle {
return TextStyle{
Font: basicfont.Face7x13,
LineHeightMultiplier: 1,
BGColor: NewColor(0, 0, 0, 1),
FGColor: NewColor(1, 1, 1, 1),
OutlineColor: NewColor(0, 0, 0, 1),
ShadowDirection: Vector{1, 1, 0, 0}.Unit(),
ShadowColorNear: NewColor(0, 0, 0, 1),
ShadowColorFar: NewColor(0, 0, 0, 1),
}
}
// Text represents a helper object that writes text for display as a texture on a Model's MeshPart.
// Text objects use a pre-made shader to render.
type Text struct {
meshPart *MeshPart // The MeshPart that the Text is operating on
Texture *ebiten.Image // The texture used to render text
style TextStyle
setText string
parsedText []string
typewriterIndex int
typewriterOn bool
textureSize int
}
//go:embed shaders/text.kage
var textShaderSrc []byte
// NewText creates a new Text rendering surface for typing out text and assigns the MeshPart provided to use that surface as a texture.
// If the MeshPart has no Material, then a new one will be created with sane default settings.
// NewText sets the transparency mode of the material to be transparent, as clip alpha doesn't work properly.
// textureWidth is how wide (in pixels) the backing texture should be for displaying the text; the height is determined by the
// aspect ratio of the dimensions of the meshpart given.
// Text objects update the mesh's material to point to an internal texture, and use a shader as well. If you want to tweak the rendering further,
// do so on the provided MeshPart after calling NewText().
// All changes to the Text require that the Text object updates its texture, which can be costly as this means redrawing the text as
// necessary; this is handled automatically.
// Note that for this to work ideally, the mesh cannot be rotated (i.e. the mesh's faces should not be at an angle).
// The function will return an error if the UV values for the vertices don't cover a large enough range (i.e. if the plane doesn't cover
// the entire text texture, from 0,0 to 1,1). This isn't necessarily a problem, but can indicate an issue that would make text not render.
func NewText(meshPart *MeshPart, textureWidth int) (*Text, error) {
text := &Text{
meshPart: meshPart,
textureSize: textureWidth,
}
// Calculate the width and height of the dimensions based off of the
// meshpart's vertex positions; this determines our texture's aspect ratio.
w, h := meshPart.primaryDimensions()
asr := float64(h) / float64(w)
text.Texture = ebiten.NewImage(textureWidth, int(float64(textureWidth)*asr))
if meshPart.Material == nil {
// If no material is present, then we can create a new one with sane defaults
meshPart.Material = NewMaterial("text material")
meshPart.Material.BackfaceCulling = true
meshPart.Material.Shadeless = true
} else {
// We have to clone the material to ensure that unique objects that share the same material can both
// have their own Text textures.
meshPart.Material = meshPart.Material.Clone()
}
meshPart.Material.FragmentShaderOn = true
meshPart.Material.Texture = text.Texture
// We set this because Alpha Clip doesn't work with shadows / outlines, as just the text itself writes depth values
meshPart.Material.TransparencyMode = TransparencyModeTransparent
// shader, err := ebiten.NewShader(textShaderSrc)
shader, err := ExtendBase3DShader(string(textShaderSrc))
if err != nil {
panic(err)
}
meshPart.Material.SetShader(shader)
// We set the default text here so that something appears, and we
// apply a style using the function because otherwise, the text would be invisible.
text.setText = "Default text"
text.parsedText = []string{"Default text"}
text.SetStyle(NewDefaultTextStyle()) // The texture will update when we apply the style.
uvMin := Vector{math.MaxFloat64, math.MaxFloat64, 0, 0}
uvMax := Vector{-math.MaxFloat64, -math.MaxFloat64, 0, 0}
meshPart.ForEachVertexIndex(func(vertIndex int) {
uv := meshPart.Mesh.VertexUVs[vertIndex]
if uv.X < uvMin.X {
uvMin.X = uv.X
}
if uv.Y < uvMin.Y {
uvMin.Y = uv.Y
}
if uv.X > uvMax.X {
uvMax.X = uv.X
}
if uv.Y > uvMax.Y {
uvMax.Y = uv.Y
}
}, false)
err = nil
if uvMax.X-uvMin.X < 0.99 || uvMax.Y-uvMin.Y < 0.99 {
err = fmt.Errorf("warning: uv values for text mesh part bounds have a small or unusual bounds of: %s : %s", uvMin, uvMax)
}
return text, err
}
// NewTextAutoSize creates a new Text rendering surface for typing out text,
// with the backing texture's size calculated from an orthographic Camera's render scale.
// This is generally useful for UI Text objects.
// Note that for this to work ideally, the mesh cannot be rotated (i.e. the mesh's faces should not be at an angle).
// All changes to the Text require that the Text object updates its texture, which can be costly as this means redrawing the text as
// necessary; this is handled automatically.
// The function will return an error if the UV values for the vertices don't cover a large enough range (i.e. if the plane doesn't cover
// the entire text texture, from 0,0 to 1,1). This isn't necessarily a problem, but can indicate an issue that would make text not render.
func NewTextAutoSize(meshPart *MeshPart, camera *Camera) (*Text, error) {
w, _ := camera.Size()
meshPartDimWidth, _ := meshPart.primaryDimensions()
texWidth := math.Round(meshPartDimWidth / camera.OrthoScale() * float64(w))
return NewText(meshPart, int(texWidth))
}
// Clone clones the Text object.
func (text *Text) Clone() *Text {
newText, _ := NewText(text.meshPart, text.textureSize)
newText.typewriterIndex = text.typewriterIndex
newText.typewriterOn = text.typewriterOn
newText.setText = text.setText
newText.parsedText = append([]string{}, text.parsedText...)
newText.Texture = ebiten.NewImageFromImage(text.Texture)
newText.textureSize = text.textureSize
newText.style = text.style
return newText
}
// Text returns the current text that is being displayed for the Text object.
func (text *Text) Text() string {
return text.setText
}
func splitWithSeparator(str string, seps string) []string {
output := []string{}
start := 0
index := strings.IndexAny(str, seps)
if index < 0 {
return []string{str}
}
for index >= 0 {
end := start + index + 1
if end > len(str) {
end = len(str)
}
output = append(output, str[start:end])
start += index + 1
index = strings.IndexAny(str[start:], seps)
if index < 0 {
output = append(output, str[start:])
}
}
return output
}
// SetText sets the text to be displayed for the Text object.
// arguments can be variables to be displayed in the text string, formatted using fmt.Sprintf()'s formatting rules.
// Text objects handle automatically splitting newlines based on length to the owning plane mesh's size.
// Setting the text to be blank clears the text, though Text.ClearText() also exists, and is just syntactic sugar for this purpose.
// SetText accounts for the margin set in the Text object's active TextStyle, but if it is applied prior to calling SetText().
func (textObj *Text) SetText(txt string, arguments ...any) *Text {
if len(arguments) > 0 {
txt = fmt.Sprintf(txt, arguments...)
}
if textObj.setText != txt {
textObj.setText = txt
textureWidth := textObj.Texture.Bounds().Dx()
// If a word gets too close to the texture's right side, we loop
safetyMargin := int(float64(textureWidth)*0.1) + textObj.style.MarginHorizontal
parsedText := []string{}
for _, line := range strings.Split(txt, "\n") {
split := splitWithSeparator(line, " -")
runningMeasure := 0
wordIndex := 0
// Some fonts have space characters that are basically empty somehow...?
spaceAdd := 0
if measureText(" ", textObj.style.Font).Dx() <= 0 {
spaceAdd = measureText("M", textObj.style.Font).Dx()
}
for i, word := range split {
wordSpace := measureText(word, textObj.style.Font).Dx()
runningMeasure += wordSpace + spaceAdd
if runningMeasure >= textureWidth-safetyMargin {
t := strings.Join(split[wordIndex:i], "")
parsedText = append(parsedText, t)
runningMeasure = wordSpace
wordIndex = i
// if i == len(split)-1 {
// parsedText = append(parsedText, strings.Join(split[wordIndex:], ""))
// }
}
}
t := strings.Join(split[wordIndex:], "")
parsedText = append(parsedText, t)
}
textObj.parsedText = parsedText
if textObj.typewriterIndex >= 0 {
textObj.typewriterIndex = 0
}
textObj.UpdateTexture()
}
return textObj
}
// ClearText clears the text displaying in the Text Object.
func (textObj *Text) ClearText() *Text {
return textObj.SetText("")
}
// UpdateTexture will update the Text's backing texture, clearing and/or redrawing the texture as necessary.
// This won't do anything if the texture is nil (has been disposed).
func (textObj *Text) UpdateTexture() {
if textObj.Texture == nil {
return
}
typewriterIndex := textObj.typewriterIndex
if !textObj.typewriterOn {
typewriterIndex = len(textObj.parsedText) - 1
}
textLineMargin := 2
lineHeight := int(float64(textObj.style.Font.Metrics().Height.Ceil() + textLineMargin))
multipliedLineHeight := int(float64(lineHeight) * textObj.style.LineHeightMultiplier)
ascent := textObj.style.Font.Metrics().Ascent.Ceil()
typing := true
// if textObj.style.BGColor != nil {
// textObj.Texture.Fill(textObj.style.BGColor.ToRGBA64())
// } else {
textObj.Texture.Clear()
// }
textureWidth := textObj.Texture.Bounds().Dx()
textureHeight := textObj.Texture.Bounds().Dy()
blockHeight := max(len(textObj.parsedText)*multipliedLineHeight, lineHeight)
for lineIndex, line := range textObj.parsedText {
measure := measureText(line, textObj.style.Font)
if textObj.typewriterOn && typewriterIndex >= 0 {
if !typing {
break
}
if typewriterIndex > len(line) {
typewriterIndex -= len(line)
} else if typing {
line = line[:typewriterIndex]
typing = false
}
}
x := -measure.Min.X
y := -measure.Min.Y + (lineIndex * multipliedLineHeight)
if textObj.style.AlignmentHorizontal == TextAlignHorizontalCenter {
x = textureWidth/2 - measure.Dx()/2
} else if textObj.style.AlignmentHorizontal == TextAlignHorizontalRight {
x = textureWidth - measure.Dx()
x -= textObj.style.MarginHorizontal
} else {
x += textObj.style.MarginHorizontal
}
if textObj.style.AlignmentVertical == TextAlignVerticalCenter {
// We add the minimum because the height shouldn't probably include parts of text
// that drop below the baseline (e.g. measure.Dy())
y += textureHeight/2 - blockHeight/2 + ascent/2
} else if textObj.style.AlignmentVertical == TextAlignVerticalBottom {
y += textureHeight - blockHeight
y -= textObj.style.MarginVertical
} else {
y += textObj.style.MarginVertical
}
x += textObj.style.OffsetX
y += textObj.style.OffsetY
if textObj.typewriterOn && (len(line) < len(textObj.parsedText[lineIndex]) || lineIndex == len(textObj.parsedText)-1) {
line += textObj.style.Cursor
}
text.Draw(textObj.Texture, line, textObj.style.Font, x, y, color.RGBA{255, 255, 255, 255})
// text.Draw(textObj.Texture, line, textObj.style.Font, x, y, textObj.style.FGColor.ToRGBA64())
}
}
func (text *Text) Style() TextStyle {
return text.style
}
func (text *Text) SetStyle(style TextStyle) {
if text.style != style {
oldStyle := text.style
text.style = style
rounded := float32(0)
if style.OutlineRounded {
rounded = 1
}
shadowVec := style.ShadowDirection.Unit().Invert()
uniformMap := map[string]any{
"OutlineThickness": float32(style.OutlineThickness),
"OutlineRounded": rounded,
"ShadowVector": [2]float32{float32(shadowVec.X), float32(shadowVec.Y)},
"ShadowLength": float32(style.ShadowLength),
"BGColor": style.BGColor.ToFloat32Array(),
"FGColor": style.FGColor.ToFloat32Array(),
"OutlineColor": style.OutlineColor.ToFloat32Array(),
"ShadowColorNear": style.ShadowColorNear.ToFloat32Array(),
"ShadowColorFar": style.ShadowColorFar.ToFloat32Array(),
}
if !style.ShadowColorFar.IsZero() {
uniformMap["ShadowColorFarSet"] = 1.0
}
text.meshPart.Material.FragmentShaderOptions = &ebiten.DrawTrianglesShaderOptions{
Images: [4]*ebiten.Image{
text.Texture,
},
Uniforms: uniformMap,
}
// If the font changes, we have to set the text again to ensure the text wraps properly.
if style.Font != oldStyle.Font {
setText := text.setText
text.setText = ""
text.SetText(setText)
}
text.UpdateTexture()
}
}
// TypewriterIndex returns the typewriter index of the Text object.
func (text *Text) TypewriterIndex() int {
return text.typewriterIndex
}
// SetTypewriterIndex sets the typewriter scroll of the text to the value given.
func (text *Text) SetTypewriterIndex(typewriterIndex int) {
oldIndex := text.typewriterIndex
text.typewriterIndex = typewriterIndex
if text.typewriterIndex >= len(text.setText) {
text.typewriterIndex = len(text.setText)
}
if text.typewriterIndex < 0 {
text.typewriterIndex = 0
}
if text.typewriterOn && oldIndex != text.typewriterIndex {
text.UpdateTexture()
}
}
// FinishTypewriter finishes the typewriter effect, so that the entire message is visible.
func (text *Text) FinishTypewriter() {
text.SetTypewriterIndex(len(text.setText))
}
// AdvanceTypewriterIndex advances the scroll of the text by the number of characters given.
// AdvanceTypewriterIndex will return a boolean value indicating if the Text advanced to the end
// or not.
func (text *Text) AdvanceTypewriterIndex(advanceBy int) bool {
oldIndex := text.typewriterIndex
adv := text.typewriterIndex + advanceBy
if text.typewriterIndex == math.MaxInt {
adv = 0
}
text.SetTypewriterIndex(adv)
if advanceBy > 0 {
return oldIndex >= len(text.setText)
} else if advanceBy < 0 {
return oldIndex <= 0
}
return false
}
// TypewriterFinished returns if the typewriter effect is finished.
func (text *Text) TypewriterFinished() bool {
return text.typewriterIndex >= len(text.setText)
}
// SetTypewriterOn sets the typewriter effect on the Text object.
func (text *Text) SetTypewriterOn(on bool) {
if text.typewriterOn != on {
text.UpdateTexture()
}
text.typewriterOn = on
}
// TypewriterOn returns if the typewriter effect is enabled on the Text object.
func (text *Text) TypewriterOn() bool {
return text.typewriterOn
}
// Dispose disposes of the text object's backing texture; this needs to be called to free VRAM, and should be called
// whenever the owning Model and Mesh are no longer is going to be used.
// This also will set the texture of the MeshPart this Text object is tied to, to nil.
func (text *Text) Dispose() {
if text.Texture != nil {
text.Texture.Dispose()
text.Texture = nil
text.meshPart.Material.Texture = nil
}
}
// type Text struct {
// *Node
// textModel *Model
// font font.Face
// setText string
// typewriterIndex int
// texture *ebiten.Image
// lineHeight float64
// }
// func NewText(name string, lineHeight float64) *Text {
// text := &Text{
// Node: NewNode(name),
// textModel: NewModel(NewSubdividedPlaneMesh(4, 4), "text model"),
// font: basicfont.Face7x13,
// typewriterIndex: -1,
// lineHeight: lineHeight,
// }
// // text.textModel.Mesh.SelectVertices().SelectAll().ApplyMatrix(NewMatrix4Scale(0.5, 0.5, 0.5))
// mat := text.textModel.Mesh.Materials()[0]
// mat.BackfaceCulling = true
// mat.TransparencyMode = TransparencyModeTransparent
// text.AddChildren(text.textModel)
// return text
// }
// func (text *Text) Clone() INode {
// newText := NewText(text.name, text.lineHeight)
// newText.textModel = text.textModel.Clone().(*Model)
// newText.typewriterIndex = text.typewriterIndex
// newText.setText = text.setText
// newText.font = text.font
// return newText
// }
// func (text *Text) Font() font.Face {
// return text.font
// }
// func (text *Text) SetFont(font font.Face) {
// if text.font != font {
// text.font = font
// text.updateTexture()
// }
// }
// func (text *Text) Text() string {
// return text.setText
// }
// func (text *Text) SetText(txt string) {
// if text.setText != txt {
// text.setText = txt
// text.updateTexture()
// }
// }
// func (textObj *Text) updateTexture() {
// if textObj.setText == "" {
// return
// }
// measure := text.BoundString(textObj.font, textObj.Text())
// asr := float64(measure.Dx()) / float64(measure.Dy())
// if textObj.texture == nil || measure.Dx() > textObj.texture.Bounds().Dx() || measure.Dy() > textObj.texture.Bounds().Dy() {
// if textObj.texture != nil {
// textObj.texture.Dispose()
// }
// newWidth := int(closestPowerOfTwo(float64(measure.Dx())) * 1.5)
// newHeight := int(closestPowerOfTwo(float64(measure.Dy())) * 1.5)
// textObj.texture = ebiten.NewImage(newWidth, newHeight)
// textObj.textModel.Mesh.Materials()[0].Texture = textObj.texture
// }
// textObj.texture.Clear()
// txt := ""
// if textObj.typewriterIndex >= 0 {
// txt = textObj.Text()[:textObj.typewriterIndex]
// } else {
// txt = textObj.Text()
// }
// lineCount := float64(strings.Count(textObj.Text(), "\n")) + 1
// text.Draw(textObj.texture, txt, textObj.font, -measure.Min.X, -measure.Min.Y, color.White)
// fmt.Println("text:", txt)
// // targetDimensions := textObj.dimensions.Mult(textObj.WorldScale())
// // textObj.textModel.SetLocalScaleVec(targetDimensions)
// // textObj.textModel.SetLocalScale(asr, 1, 1)
// lh := textObj.lineHeight * lineCount
// fmt.Println(textObj.lineHeight, lh, lineCount)
// textObj.textModel.SetLocalScale(lh*asr, lh, 1)
// fmt.Println("text set?")
// // Left align
// textObj.textModel.SetLocalPosition(textObj.textModel.LocalScale().X/2, 0, 0)
// }
// func (text *Text) TypewriterIndex() int {
// return text.typewriterIndex
// }
// // SetTypewriterIndex advances the scroll of the text by the number of characters given.
// // SetTypewriterIndex will return a boolean value indicating if the Text is at the end
// // of the scroll or not.
// func (text *Text) SetTypewriterIndex(typewriterIndex int) bool {
// oldIndex := text.typewriterIndex
// text.typewriterIndex += typewriterIndex
// if oldIndex != text.typewriterIndex {
// text.updateTexture()
// }
// if text.typewriterIndex >= len(text.setText) {
// text.typewriterIndex = len(text.setText)
// }
// return text.typewriterIndex >= len(text.setText)
// }
// // AddChildren parents the provided children Nodes to the passed parent Node, inheriting its transformations and being under it in the scenegraph
// // hierarchy. If the children are already parented to other Nodes, they are unparented before doing so.
// func (text *Text) AddChildren(children ...INode) {
// text.addChildren(text, children...)
// }
// // Unparent unparents the AmbientLight from its parent, removing it from the scenegraph.
// func (text *Text) Unparent() {
// if text.parent != nil {
// text.parent.RemoveChildren(text)
// }
// }
// // Type returns the NodeType for this object.
// func (text *Text) Type() NodeType {
// return NodeTypeText
// }
// // Index returns the index of the Node in its parent's children list.
// // If the node doesn't have a parent, its index will be -1.
// func (text *Text) Index() int {
// if text.parent != nil {
// for i, c := range text.parent.Children() {
// if c == text {
// return i
// }
// }
// }
// return -1
// }
// func (text *Text) String() string {
// if ReadableReferences {
// return "<" + text.Path() + "> : " + text.Text()
// } else {
// return fmt.Sprintf("%p", text)
// }
// }