@needle-tools/engine 5.0.0 → 5.1.0-experimental.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components.needle.json +1 -1
- package/dist/generateMeshBVH.worker-DT9A2Hrc.js +1 -0
- package/dist/gltf-progressive-3BwW4ETO.min.js +10 -0
- package/dist/gltf-progressive-ByD1UX0A.umd.cjs +10 -0
- package/dist/{gltf-progressive-Cl167Vjx.js → gltf-progressive-DwWaVr0o.js} +412 -394
- package/dist/gltf-progressive.worker-DpfUjn1n.js +3 -0
- package/dist/{materialx-qPScBWhj.min.js → materialx-9KHBidZa.min.js} +1 -1
- package/dist/{materialx-4ApD6Vz5.js → materialx-BBDu8W5P.js} +1 -1
- package/dist/{materialx-D0XUnhBY.umd.cjs → materialx-hLP3E8AA.umd.cjs} +2 -2
- package/dist/{needle-engine.bundle-CoEvMwYM.min.js → needle-engine.bundle-BiCxyTBE.min.js} +110 -110
- package/dist/{needle-engine.bundle-BAYLGumK.umd.cjs → needle-engine.bundle-CaHKqc30.umd.cjs} +123 -123
- package/dist/{needle-engine.bundle-BDIyvCV6.js → needle-engine.bundle-JZXX6OjM.js} +2143 -2088
- package/dist/needle-engine.d.ts +102 -44
- package/dist/needle-engine.js +480 -476
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-B_9sKVU7.min.js → postprocessing-BZfyAdCY.min.js} +1 -1
- package/dist/{postprocessing-WDc9WwI3.js → postprocessing-CXlA3QA6.js} +1 -1
- package/dist/{postprocessing-B2wb6pzI.umd.cjs → postprocessing-Dwy7Hz_T.umd.cjs} +38 -38
- package/dist/three-examples.js +4760 -3641
- package/dist/three-examples.min.js +17 -35
- package/dist/three-examples.umd.cjs +16 -34
- package/dist/three.js +48533 -28562
- package/dist/three.min.js +716 -502
- package/dist/three.umd.cjs +720 -506
- package/dist/vendor-Bf43L3CE.min.js +1116 -0
- package/dist/{vendor-CntUvmJu.umd.cjs → vendor-BlyEaMTL.umd.cjs} +31 -31
- package/dist/{vendor-vHLk8sXu.js → vendor-D-7l5gB0.js} +2562 -2556
- package/lib/engine/engine_animation.js +1 -1
- package/lib/engine/engine_animation.js.map +1 -1
- package/lib/engine/engine_audio.js.map +1 -1
- package/lib/engine/engine_context.js +3 -6
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_create_objects.js +0 -1
- package/lib/engine/engine_create_objects.js.map +1 -1
- package/lib/engine/engine_element.d.ts +113 -0
- package/lib/engine/engine_element.js +833 -0
- package/lib/engine/engine_element.js.map +1 -0
- package/lib/engine/engine_element_attributes.d.ts +72 -0
- package/lib/engine/engine_element_attributes.js +2 -0
- package/lib/engine/engine_element_attributes.js.map +1 -0
- package/lib/engine/engine_element_extras.d.ts +6 -0
- package/lib/engine/engine_element_extras.js +14 -0
- package/lib/engine/engine_element_extras.js.map +1 -0
- package/lib/engine/engine_element_loading.d.ts +44 -0
- package/lib/engine/engine_element_loading.js +350 -0
- package/lib/engine/engine_element_loading.js.map +1 -0
- package/lib/engine/engine_element_overlay.d.ts +21 -0
- package/lib/engine/engine_element_overlay.js +167 -0
- package/lib/engine/engine_element_overlay.js.map +1 -0
- package/lib/engine/engine_license.js.map +1 -1
- package/lib/engine/engine_pmrem.js +2 -2
- package/lib/engine/engine_pmrem.js.map +1 -1
- package/lib/engine/engine_scenetools.d.ts +62 -0
- package/lib/engine/engine_scenetools.js +337 -0
- package/lib/engine/engine_scenetools.js.map +1 -0
- package/lib/engine/engine_test_utils.d.ts +39 -0
- package/lib/engine/engine_test_utils.js +84 -0
- package/lib/engine/engine_test_utils.js.map +1 -0
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_time.js +4 -3
- package/lib/engine/engine_time.js.map +1 -1
- package/lib/engine/engine_ui.d.ts +25 -0
- package/lib/engine/engine_ui.dummy_canvas.d.ts +2 -0
- package/lib/engine/engine_ui.dummy_canvas.js +55 -0
- package/lib/engine/engine_ui.dummy_canvas.js.map +1 -0
- package/lib/engine/engine_ui.js +168 -0
- package/lib/engine/engine_ui.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_lightmaps.js +2 -2
- package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_pmrem.d.ts +1 -1
- package/lib/engine/webcomponents/icons.js +3 -2
- package/lib/engine/webcomponents/icons.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.attributes.d.ts +69 -0
- package/lib/engine/webcomponents/needle-engine.attributes.js +2 -0
- package/lib/engine/webcomponents/needle-engine.attributes.js.map +1 -0
- package/lib/engine-components/AudioSource.js +1 -1
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/Light.d.ts +3 -0
- package/lib/engine-components/Light.js +39 -31
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +2 -1
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/SpriteRenderer.d.ts +1 -1
- package/lib/engine-components/VideoPlayer.d.ts +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/Animation.js +1 -0
- package/lib/engine-components/export/usdz/extensions/Animation.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -1
- package/lib/engine-components/particlesystem/ParticleSystem.d.ts +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
- package/lib/engine-components/ui/BaseUIComponent_Uikit.d.ts +54 -0
- package/lib/engine-components/ui/BaseUIComponent_Uikit.js +114 -0
- package/lib/engine-components/ui/BaseUIComponent_Uikit.js.map +1 -0
- package/lib/engine-components/ui/BaseUikitComponent.d.ts +54 -0
- package/lib/engine-components/ui/BaseUikitComponent.js +114 -0
- package/lib/engine-components/ui/BaseUikitComponent.js.map +1 -0
- package/lib/engine-components/ui/Button.legacy.d.ts +68 -0
- package/lib/engine-components/ui/Button.legacy.js +320 -0
- package/lib/engine-components/ui/Button.legacy.js.map +1 -0
- package/lib/engine-components/ui/ButtonUikit.d.ts +51 -0
- package/lib/engine-components/ui/ButtonUikit.js +187 -0
- package/lib/engine-components/ui/ButtonUikit.js.map +1 -0
- package/lib/engine-components/ui/Canvas.js +2 -2
- package/lib/engine-components/ui/Canvas.js.map +1 -1
- package/lib/engine-components/ui/Canvas.legacy.d.ts +76 -0
- package/lib/engine-components/ui/Canvas.legacy.js +409 -0
- package/lib/engine-components/ui/Canvas.legacy.js.map +1 -0
- package/lib/engine-components/ui/CanvasUikit.d.ts +68 -0
- package/lib/engine-components/ui/CanvasUikit.js +289 -0
- package/lib/engine-components/ui/CanvasUikit.js.map +1 -0
- package/lib/engine-components/ui/Graphic.d.ts +3 -3
- package/lib/engine-components/ui/Graphic.js +6 -2
- package/lib/engine-components/ui/Graphic.js.map +1 -1
- package/lib/engine-components/ui/Graphic.legacy.d.ts +55 -0
- package/lib/engine-components/ui/Graphic.legacy.js +268 -0
- package/lib/engine-components/ui/Graphic.legacy.js.map +1 -0
- package/lib/engine-components/ui/GraphicUikit.d.ts +21 -0
- package/lib/engine-components/ui/GraphicUikit.js +65 -0
- package/lib/engine-components/ui/GraphicUikit.js.map +1 -0
- package/lib/engine-components/ui/Image.js.map +1 -1
- package/lib/engine-components/ui/Image.legacy.d.ts +39 -0
- package/lib/engine-components/ui/Image.legacy.js +121 -0
- package/lib/engine-components/ui/Image.legacy.js.map +1 -0
- package/lib/engine-components/ui/ImageUikit.d.ts +22 -0
- package/lib/engine-components/ui/ImageUikit.js +97 -0
- package/lib/engine-components/ui/ImageUikit.js.map +1 -0
- package/lib/engine-components/ui/RenderMode.d.ts +14 -0
- package/lib/engine-components/ui/RenderMode.js +16 -0
- package/lib/engine-components/ui/RenderMode.js.map +1 -0
- package/lib/engine-components/ui/Text.d.ts +64 -11
- package/lib/engine-components/ui/Text.js +154 -45
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components/ui/Text.legacy.d.ts +81 -0
- package/lib/engine-components/ui/Text.legacy.js +548 -0
- package/lib/engine-components/ui/Text.legacy.js.map +1 -0
- package/lib/engine-components/ui/TextUikit.d.ts +42 -0
- package/lib/engine-components/ui/TextUikit.js +164 -0
- package/lib/engine-components/ui/TextUikit.js.map +1 -0
- package/lib/engine-components/ui/index.d.ts +1 -0
- package/lib/engine-components/ui/index.js +1 -0
- package/lib/engine-components/ui/index.js.map +1 -1
- package/lib/engine-components/webxr/WebARCameraBackground.d.ts +1 -1
- package/lib/include/three/EXT_mesh_gpu_instancing_exporter.d.ts +6 -0
- package/lib/include/three/EXT_mesh_gpu_instancing_exporter.js +46 -0
- package/lib/include/three/EXT_mesh_gpu_instancing_exporter.js.map +1 -0
- package/package.json +5 -5
- package/plugins/common/buildinfo.d.ts +6 -0
- package/plugins/vite/ai.d.ts +7 -8
- package/plugins/vite/ai.js +95 -20
- package/plugins/vite/alias.js +6 -0
- package/plugins/vite/dependencies.js +7 -0
- package/src/engine/engine_animation.ts +1 -1
- package/src/engine/engine_audio.ts +1 -1
- package/src/engine/engine_context.ts +3 -6
- package/src/engine/engine_create_objects.ts +0 -1
- package/src/engine/engine_license.ts +0 -2
- package/src/engine/engine_pmrem.ts +3 -3
- package/src/engine/engine_three_utils.ts +2 -2
- package/src/engine/engine_time.ts +4 -3
- package/src/engine/extensions/NEEDLE_lightmaps.ts +3 -3
- package/src/engine/webcomponents/icons.ts +3 -2
- package/src/engine-components/AudioSource.ts +1 -1
- package/src/engine-components/Light.ts +39 -31
- package/src/engine-components/OrbitControls.ts +2 -2
- package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +2 -2
- package/src/engine-components/export/usdz/extensions/Animation.ts +6 -5
- package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +1 -1
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +3 -3
- package/src/engine-components/timeline/TimelineTracks.ts +2 -2
- package/src/engine-components/ui/Canvas.ts +2 -2
- package/src/engine-components/ui/Graphic.ts +7 -3
- package/src/engine-components/ui/Image.ts +1 -1
- package/src/engine-components/ui/Text.ts +170 -52
- package/src/engine-components/ui/index.ts +2 -1
- package/dist/generateMeshBVH.worker-DiCnZlf3.js +0 -21
- package/dist/gltf-progressive-BryRjllq.min.js +0 -10
- package/dist/gltf-progressive-DJBMx-zB.umd.cjs +0 -10
- package/dist/gltf-progressive.worker-BqODMeeW.js +0 -23
- package/dist/vendor-DPbfJJ4d.min.js +0 -1116
|
@@ -27,7 +27,7 @@ export enum VerticalWrapMode {
|
|
|
27
27
|
Truncate = 0,
|
|
28
28
|
Overflow = 1,
|
|
29
29
|
}
|
|
30
|
-
enum HorizontalWrapMode {
|
|
30
|
+
export enum HorizontalWrapMode {
|
|
31
31
|
Wrap = 0,
|
|
32
32
|
Overflow = 1,
|
|
33
33
|
}
|
|
@@ -70,33 +70,149 @@ export enum FontStyle {
|
|
|
70
70
|
*/
|
|
71
71
|
export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiver {
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The alignment of the text within its container. This determines how the text is anchored and positioned relative to its RectTransform. For example, `UpperLeft` will anchor the text to the upper left corner of the container, while `MiddleCenter` will center the text both horizontally and vertically. Changing this property will update the underlying three-mesh-ui options and mark the UI as dirty to trigger a re-render.
|
|
75
|
+
*/
|
|
73
76
|
@serializable()
|
|
74
|
-
alignment: TextAnchor
|
|
77
|
+
set alignment(val: TextAnchor) {
|
|
78
|
+
if (val !== this._alignment) {
|
|
79
|
+
this._alignment = val;
|
|
80
|
+
this.uiObject?.set(this.getTextOpts());
|
|
81
|
+
this.markDirty();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
get alignment(): TextAnchor {
|
|
85
|
+
return this._alignment;
|
|
86
|
+
}
|
|
87
|
+
private _alignment: TextAnchor = TextAnchor.UpperLeft;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Determines how text that exceeds the vertical bounds of the container is handled. If set to `Truncate`, any text that goes beyond the vertical limits of the container will be cut off and not visible. If set to `Overflow`, the text will continue to render outside the container bounds, which may result in it being partially or fully visible depending on the layout and parent containers.
|
|
91
|
+
* @default VerticalWrapMode.Truncate
|
|
92
|
+
*/
|
|
75
93
|
@serializable()
|
|
76
|
-
verticalOverflow: VerticalWrapMode
|
|
94
|
+
set verticalOverflow(val: VerticalWrapMode) {
|
|
95
|
+
if (val !== this._verticalOverflow) {
|
|
96
|
+
this._verticalOverflow = val;
|
|
97
|
+
this.uiObject?.set(this.getTextOpts());
|
|
98
|
+
this.markDirty();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
get verticalOverflow(): VerticalWrapMode {
|
|
102
|
+
return this._verticalOverflow;
|
|
103
|
+
}
|
|
104
|
+
private _verticalOverflow: VerticalWrapMode = VerticalWrapMode.Truncate;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Determines how text that exceeds the horizontal bounds of the container is handled. If set to `Wrap`, the text will automatically wrap to the next line when it reaches the edge of the container. If set to `Overflow`, the text will continue on a single line and may overflow outside the container bounds.
|
|
108
|
+
* @default HorizontalWrapMode.Wrap
|
|
109
|
+
*/
|
|
77
110
|
@serializable()
|
|
78
|
-
horizontalOverflow: HorizontalWrapMode
|
|
111
|
+
set horizontalOverflow(val: HorizontalWrapMode) {
|
|
112
|
+
if (val !== this._horizontalOverflow) {
|
|
113
|
+
this._horizontalOverflow = val;
|
|
114
|
+
this.uiObject?.set(this.getTextOpts());
|
|
115
|
+
this.markDirty();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
get horizontalOverflow(): HorizontalWrapMode {
|
|
119
|
+
return this._horizontalOverflow;
|
|
120
|
+
}
|
|
121
|
+
private _horizontalOverflow: HorizontalWrapMode = HorizontalWrapMode.Wrap;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The line spacing multiplier for the text. A value of 1 means normal spacing, 1.5 means 50% more spacing, and 0.5 means 50% less spacing.
|
|
125
|
+
* @default 1
|
|
126
|
+
*/
|
|
79
127
|
@serializable()
|
|
80
|
-
lineSpacing: number
|
|
128
|
+
set lineSpacing(val: number) {
|
|
129
|
+
if (val !== this._lineSpacing) {
|
|
130
|
+
this._lineSpacing = val;
|
|
131
|
+
this.uiObject?.set(this.getTextOpts());
|
|
132
|
+
this.markDirty();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
get lineSpacing(): number {
|
|
136
|
+
return this._lineSpacing;
|
|
137
|
+
}
|
|
138
|
+
private _lineSpacing: number = 1;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The style of the font, which can be normal, bold, italic, or bold and italic.
|
|
142
|
+
*
|
|
143
|
+
* This is used to determine the correct font variant to use based on the provided `font` property. For example, if you set `font` to "Arial" and `fontStyle` to `FontStyle.Bold`, it will look for a font variant named "Arial-Bold" (or "arial-bold") in the font library. If such a variant exists, it will be used to render the text with the specified style.
|
|
144
|
+
*
|
|
145
|
+
* @default FontStyle.Normal
|
|
146
|
+
*/
|
|
81
147
|
@serializable()
|
|
82
|
-
|
|
148
|
+
set fontStyle(val: FontStyle) {
|
|
149
|
+
if (val !== this._fontStyle) {
|
|
150
|
+
this._fontStyle = val;
|
|
151
|
+
this.uiObject?.set(this.getTextOpts());
|
|
152
|
+
this.markDirty();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
get fontStyle(): FontStyle {
|
|
156
|
+
return this._fontStyle;
|
|
157
|
+
}
|
|
158
|
+
private _fontStyle: FontStyle = FontStyle.Normal;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The font to use for the text, specified as a URL to a font file.
|
|
162
|
+
*
|
|
163
|
+
* The font file must be in MSDF format. You can generate MSDF fonts using tools like [msdf-bmfont-xml](https://github.com/Chlumsky/msdf-bmfont-xml) or by using Needle Engine for Unity where the Needle Engine integration automatically generates MSDF fonts for used font assets.
|
|
164
|
+
*
|
|
165
|
+
* @default "https://cdn.needle.tools/static/fonts/msdf/arial/arial"
|
|
166
|
+
*/
|
|
83
167
|
@serializable(URL)
|
|
84
|
-
font
|
|
168
|
+
set font(val: string | null) {
|
|
169
|
+
if (val !== this._font) {
|
|
170
|
+
this._font = val;
|
|
171
|
+
this.uiObject?.set(this.getTextOpts());
|
|
172
|
+
this.markDirty();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
get font(): string | null {
|
|
176
|
+
return this._font;
|
|
177
|
+
}
|
|
178
|
+
private _font: string | null = "https://cdn.needle.tools/static/fonts/msdf/arial/arial";
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Whether to support basic rich text tags in the `text` property. Supported tags include `<b>`, `<i>`, and `<color=hex>`. For example: `Hello <b>World</b>` or `Score: <color=#ff0000>100</color>`
|
|
183
|
+
* @default false
|
|
184
|
+
*/
|
|
85
185
|
@serializable()
|
|
86
|
-
|
|
186
|
+
set supportRichText(val: boolean) {
|
|
187
|
+
if (val !== this._supportRichText) {
|
|
188
|
+
this._supportRichText = val;
|
|
189
|
+
this.uiObject?.set(this.getTextOpts());
|
|
190
|
+
this.markDirty();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
get supportRichText(): boolean {
|
|
194
|
+
return this._supportRichText;
|
|
195
|
+
}
|
|
196
|
+
private _supportRichText: boolean = false;
|
|
197
|
+
|
|
87
198
|
|
|
88
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Set the alpha factor for the text, which multiplies with the color's alpha to determine overall transparency.
|
|
201
|
+
*/
|
|
89
202
|
setAlphaFactor(factor: number): void {
|
|
90
203
|
super.setAlphaFactor(factor);
|
|
91
204
|
this.uiObject?.set({ fontOpacity: this.color.alpha * this.alphaFactor });
|
|
92
205
|
this.markDirty();
|
|
93
206
|
}
|
|
94
207
|
|
|
208
|
+
/**
|
|
209
|
+
* The text content to display. Supports basic rich text tags like `<b>`, `<i>`, and `<color=hex>` if `supportRichText` is enabled.
|
|
210
|
+
* @default ""
|
|
211
|
+
*/
|
|
95
212
|
@serializable()
|
|
96
213
|
get text(): string {
|
|
97
214
|
return this._text;
|
|
98
215
|
}
|
|
99
|
-
|
|
100
216
|
set text(val: string) {
|
|
101
217
|
if (val !== this._text) {
|
|
102
218
|
this._text = val;
|
|
@@ -105,6 +221,7 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
105
221
|
this.context.accessibility.updateElement(this, { label: this.text });
|
|
106
222
|
}
|
|
107
223
|
}
|
|
224
|
+
private _text: string = "";
|
|
108
225
|
|
|
109
226
|
private set_text(val: string) {
|
|
110
227
|
this.text = val;
|
|
@@ -120,6 +237,7 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
120
237
|
this._fontSize = val;
|
|
121
238
|
this.uiObject?.set({ fontSize: val });
|
|
122
239
|
}
|
|
240
|
+
private _fontSize: number = 12;
|
|
123
241
|
|
|
124
242
|
private sRGBTextColor: Color = new Color(1, 0, 1);
|
|
125
243
|
protected onColorChanged(): void {
|
|
@@ -158,26 +276,6 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
158
276
|
protected onCreate(_opts: any): void {
|
|
159
277
|
if (debug) console.log(this);
|
|
160
278
|
|
|
161
|
-
if (this.horizontalOverflow == HorizontalWrapMode.Overflow) {
|
|
162
|
-
// Only line characters in the textContent (\n,\r\t) would be able to multiline the text
|
|
163
|
-
_opts.whiteSpace = 'pre';
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (this.verticalOverflow == VerticalWrapMode.Truncate) {
|
|
167
|
-
this.context.renderer.localClippingEnabled = true;
|
|
168
|
-
_opts.overflow = 'hidden';
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// @marwie : this combination is currently KO. See sample "Overflow Overview"
|
|
173
|
-
if (this.horizontalOverflow == HorizontalWrapMode.Overflow && this.verticalOverflow == VerticalWrapMode.Truncate) {
|
|
174
|
-
// This could fix this combination, but would require anchors updates to replace element
|
|
175
|
-
// _opts.width = 'auto';
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
_opts.lineHeight = this.lineSpacing;
|
|
180
|
-
|
|
181
279
|
// @marwie : Should be fixed. Currently _opts are always fed with :
|
|
182
280
|
// backgroundOpacity : color.opacity
|
|
183
281
|
// backgroundColor : color
|
|
@@ -190,8 +288,6 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
190
288
|
_opts.backgroundOpacity = 0.5;
|
|
191
289
|
}
|
|
192
290
|
|
|
193
|
-
const rt = this.rectTransform;
|
|
194
|
-
|
|
195
291
|
// Texts now support both options, block and inline, and inline has all default to inherit
|
|
196
292
|
_opts = { ..._opts, ...this.getTextOpts() };
|
|
197
293
|
|
|
@@ -202,6 +298,7 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
202
298
|
_opts.backgroundOpacity = 0.1;
|
|
203
299
|
}
|
|
204
300
|
|
|
301
|
+
const rt = this.rectTransform;
|
|
205
302
|
this.uiObject = rt.createNewText(_opts);
|
|
206
303
|
this.feedText(this.text, this.supportRichText);
|
|
207
304
|
|
|
@@ -212,8 +309,6 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
212
309
|
this.handleTextRenderOnTop();
|
|
213
310
|
}
|
|
214
311
|
|
|
215
|
-
private _text: string = "";
|
|
216
|
-
private _fontSize: number = 12;
|
|
217
312
|
|
|
218
313
|
private _textMeshUi: Array<ThreeMeshUI.Inline> | null = null;
|
|
219
314
|
|
|
@@ -224,14 +319,36 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
224
319
|
// fontSize /= this.canvas?.scaleFactor;
|
|
225
320
|
// }
|
|
226
321
|
|
|
227
|
-
|
|
228
|
-
|
|
322
|
+
const textOpts: {
|
|
323
|
+
color: Color,
|
|
324
|
+
fontOpacity: number,
|
|
325
|
+
fontSize: number,
|
|
326
|
+
fontKerning: string,
|
|
327
|
+
whiteSpace?: string,
|
|
328
|
+
overflow?: string,
|
|
329
|
+
lineHeight?: number
|
|
330
|
+
} = {
|
|
229
331
|
color: this.color,
|
|
230
332
|
fontOpacity: this.color.alpha,
|
|
231
333
|
fontSize: fontSize,
|
|
232
334
|
fontKerning: "normal",
|
|
233
|
-
|
|
234
335
|
};
|
|
336
|
+
|
|
337
|
+
if (this.horizontalOverflow == HorizontalWrapMode.Overflow) {
|
|
338
|
+
// Only line characters in the textContent (\n,\r\t) would be able to multiline the text
|
|
339
|
+
textOpts.whiteSpace = 'pre';
|
|
340
|
+
}
|
|
341
|
+
if (this.verticalOverflow == VerticalWrapMode.Truncate) {
|
|
342
|
+
this.context.renderer.localClippingEnabled = true;
|
|
343
|
+
textOpts.overflow = 'hidden';
|
|
344
|
+
}
|
|
345
|
+
// @marwie : this combination is currently KO. See sample "Overflow Overview"
|
|
346
|
+
if (this.horizontalOverflow == HorizontalWrapMode.Overflow && this.verticalOverflow == VerticalWrapMode.Truncate) {
|
|
347
|
+
// This could fix this combination, but would require anchors updates to replace element
|
|
348
|
+
// textOpts.width = 'auto';
|
|
349
|
+
}
|
|
350
|
+
textOpts.lineHeight = this.lineSpacing;
|
|
351
|
+
|
|
235
352
|
this.setFont(textOpts as ThreeMeshUIEveryOptions, this.fontStyle);
|
|
236
353
|
return textOpts;
|
|
237
354
|
}
|
|
@@ -486,15 +603,16 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
486
603
|
* @private
|
|
487
604
|
*/
|
|
488
605
|
private setFont(opts: ThreeMeshUIEveryOptions, fontStyle: FontStyle) {
|
|
606
|
+
|
|
607
|
+
if (!this.font) {
|
|
608
|
+
if(debug) console.warn("No font set for Text component, skipping font setup");
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
489
611
|
|
|
490
|
-
// @TODO : THH could be useful to uniformize font family name :
|
|
491
|
-
// This would ease possible html/vr matching
|
|
492
|
-
// - Arial instead of assets/arial
|
|
493
|
-
// - Arial should stay Arial instead of arial
|
|
494
|
-
if (!this.font) return;
|
|
495
612
|
const fontName = this.font;
|
|
496
613
|
const familyName = this.getFamilyNameWithCorrectSuffix(fontName, fontStyle);
|
|
497
|
-
|
|
614
|
+
|
|
615
|
+
if (debug) console.log("Selected font family:" + familyName, this.font);
|
|
498
616
|
|
|
499
617
|
// ensure a font family is register under this name
|
|
500
618
|
let fontFamily = ThreeMeshUI.FontLibrary.getFontFamily(familyName as string);
|
|
@@ -527,9 +645,7 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
527
645
|
opts.fontWeight = 400;
|
|
528
646
|
}
|
|
529
647
|
|
|
530
|
-
|
|
531
648
|
// Ensure a fontVariant is registered
|
|
532
|
-
//@TODO: @swingingtom add type for fontWeight
|
|
533
649
|
let fontVariant = fontFamily.getVariant(opts.fontWeight as any as string, opts.fontStyle);
|
|
534
650
|
if (!fontVariant) {
|
|
535
651
|
let jsonPath = familyName;
|
|
@@ -550,13 +666,7 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
550
666
|
|
|
551
667
|
private getFamilyNameWithCorrectSuffix(familyName: string, style: FontStyle): string {
|
|
552
668
|
|
|
553
|
-
|
|
554
|
-
// the URL decorator resolves the URL to absolute URLs - we need to remove the domain part since we're only interested in the path
|
|
555
|
-
if (familyName.startsWith("https:") || familyName.startsWith("http:")) {
|
|
556
|
-
const url = new URL(familyName);
|
|
557
|
-
familyName = url.pathname;
|
|
558
|
-
}
|
|
559
|
-
|
|
669
|
+
const isAbsolute = familyName.startsWith("https:") || familyName.startsWith("http:");
|
|
560
670
|
|
|
561
671
|
// we can only change the style for the family if the name has a suffix (e.g. Arial-Bold)
|
|
562
672
|
const styleSeparator = familyName.lastIndexOf('-');
|
|
@@ -580,8 +690,16 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
|
|
|
580
690
|
}
|
|
581
691
|
const isUpperCase = fontBaseName[0] === fontBaseName[0].toUpperCase();
|
|
582
692
|
const fontNameWithoutSuffix = familyName.substring(0, styleSeparator > pathSeparatorIndex ? styleSeparator : familyName.length);
|
|
693
|
+
|
|
583
694
|
if (debug) console.log("Select font: ", familyName, FontStyle[style], fontBaseName, isUpperCase, fontNameWithoutSuffix);
|
|
584
695
|
|
|
696
|
+
/**
|
|
697
|
+
* If a user provides a font with an absolute URL AND the font name does not end with "-msdf.json" or ".png" (e.g. "https://example.com/fonts/Arial-Bold"), we will assume that the user is providing the full path to the font files and we will not try to modify the font name based on the style. This allows users to have more control over the font files they are using, especially if they are hosting their own fonts or using a custom font provider that does not follow the same naming conventions as our default fonts.
|
|
698
|
+
*/
|
|
699
|
+
if (isAbsolute && (!familyName.endsWith("-msdf.json") || !familyName.endsWith(".png"))) {
|
|
700
|
+
return fontNameWithoutSuffix;
|
|
701
|
+
}
|
|
702
|
+
|
|
585
703
|
switch (style) {
|
|
586
704
|
case FontStyle.Normal:
|
|
587
705
|
if (isUpperCase) return fontNameWithoutSuffix + "-Regular";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./PointerEvents.js"
|
|
1
|
+
export * from "./PointerEvents.js";
|
|
2
|
+
export * from "./Text.js";
|