@needle-tools/engine 3.2.15-alpha → 3.4.0-alpha
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/CHANGELOG.md +23 -0
- package/dist/needle-engine.js +44005 -36382
- package/dist/needle-engine.min.js +706 -513
- package/dist/needle-engine.umd.cjs +685 -492
- package/lib/engine/codegen/register_types.js +54 -4
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/engine_addressables.d.ts +3 -3
- package/lib/engine/engine_addressables.js +30 -9
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_element.js +1 -1
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_gameobject.d.ts +2 -1
- package/lib/engine/engine_gameobject.js +19 -0
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_input.js +10 -0
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_math.d.ts +4 -0
- package/lib/engine/engine_math.js +6 -0
- package/lib/engine/engine_math.js.map +1 -1
- package/lib/engine/engine_three_utils.js +2 -2
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine-components/Animation.js +4 -0
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/AnimatorController.js +7 -2
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +13 -4
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/TransformGizmo.d.ts +8 -4
- package/lib/engine-components/TransformGizmo.js +62 -63
- package/lib/engine-components/TransformGizmo.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +27 -2
- package/lib/engine-components/codegen/components.js +27 -2
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/export/usdz/Extension.d.ts +4 -4
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +86 -0
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +830 -0
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -0
- package/lib/engine-components/export/usdz/USDZExporter.d.ts +6 -3
- package/lib/engine-components/export/usdz/USDZExporter.js +34 -11
- package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/Animation.d.ts +15 -15
- package/lib/engine-components/export/usdz/extensions/Animation.js +24 -29
- package/lib/engine-components/export/usdz/extensions/Animation.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/DocumentExtension.d.ts +5 -0
- package/lib/engine-components/export/usdz/extensions/DocumentExtension.js +7 -0
- package/lib/engine-components/export/usdz/extensions/DocumentExtension.js.map +1 -0
- package/lib/engine-components/export/usdz/extensions/USDZText.d.ts +47 -0
- package/lib/engine-components/export/usdz/extensions/USDZText.js +114 -0
- package/lib/engine-components/export/usdz/extensions/USDZText.js.map +1 -0
- package/lib/engine-components/export/usdz/extensions/behavior/Actions.d.ts +30 -0
- package/lib/engine-components/export/usdz/extensions/behavior/Actions.js +89 -0
- package/lib/engine-components/export/usdz/extensions/behavior/Actions.js.map +1 -0
- package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.d.ts +23 -0
- package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.js +114 -0
- package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.js.map +1 -0
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +96 -0
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js +421 -0
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -0
- package/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.d.ts +111 -0
- package/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.js +409 -0
- package/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/ui/BaseUIComponent.d.ts +2 -0
- package/lib/engine-components/ui/BaseUIComponent.js +6 -0
- package/lib/engine-components/ui/BaseUIComponent.js.map +1 -1
- package/lib/engine-components/ui/Button.js +9 -5
- package/lib/engine-components/ui/Button.js.map +1 -1
- package/lib/engine-components/ui/Canvas.d.ts +23 -6
- package/lib/engine-components/ui/Canvas.js +167 -34
- package/lib/engine-components/ui/Canvas.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.d.ts +6 -0
- package/lib/engine-components/ui/EventSystem.js +4 -4
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/lib/engine-components/ui/Graphic.d.ts +5 -2
- package/lib/engine-components/ui/Graphic.js +38 -7
- package/lib/engine-components/ui/Graphic.js.map +1 -1
- package/lib/engine-components/ui/Image.d.ts +1 -0
- package/lib/engine-components/ui/Image.js +14 -5
- package/lib/engine-components/ui/Image.js.map +1 -1
- package/lib/engine-components/ui/InputField.d.ts +1 -0
- package/lib/engine-components/ui/InputField.js +8 -0
- package/lib/engine-components/ui/InputField.js.map +1 -1
- package/lib/engine-components/ui/Interfaces.d.ts +19 -0
- package/lib/engine-components/ui/Interfaces.js +11 -0
- package/lib/engine-components/ui/Interfaces.js.map +1 -1
- package/lib/engine-components/ui/Layout.d.ts +65 -3
- package/lib/engine-components/ui/Layout.js +304 -3
- package/lib/engine-components/ui/Layout.js.map +1 -1
- package/lib/engine-components/ui/Outline.d.ts +7 -0
- package/lib/engine-components/ui/Outline.js +21 -0
- package/lib/engine-components/ui/Outline.js.map +1 -0
- package/lib/engine-components/ui/RectTransform.d.ts +32 -13
- package/lib/engine-components/ui/RectTransform.js +216 -56
- package/lib/engine-components/ui/RectTransform.js.map +1 -1
- package/lib/engine-components/ui/Text.d.ts +13 -10
- package/lib/engine-components/ui/Text.js +177 -246
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components/utils/LookAt.d.ts +13 -0
- package/lib/engine-components/utils/LookAt.js +66 -0
- package/lib/engine-components/utils/LookAt.js.map +1 -0
- package/lib/engine-components/webxr/WebXRImageTracking.d.ts +12 -3
- package/lib/engine-components/webxr/WebXRImageTracking.js +156 -24
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/plugins/vite/reload.js +13 -2
- package/src/engine/codegen/register_types.js +56 -6
- package/src/engine/engine_addressables.ts +28 -10
- package/src/engine/engine_element.ts +1 -1
- package/src/engine/engine_gameobject.ts +19 -1
- package/src/engine/engine_input.ts +11 -0
- package/src/engine/engine_math.ts +10 -0
- package/src/engine/engine_three_utils.ts +2 -2
- package/src/engine-components/Animation.ts +4 -0
- package/src/engine-components/AnimatorController.ts +7 -1
- package/src/engine-components/OrbitControls.ts +14 -6
- package/src/engine-components/TransformGizmo.ts +64 -70
- package/src/engine-components/codegen/components.ts +27 -2
- package/src/engine-components/export/usdz/Extension.ts +4 -5
- package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +1280 -0
- package/src/engine-components/export/usdz/USDZExporter.ts +39 -17
- package/src/engine-components/export/usdz/extensions/Animation.ts +37 -45
- package/src/engine-components/export/usdz/extensions/DocumentExtension.ts +10 -0
- package/src/engine-components/export/usdz/extensions/USDZText.ts +142 -0
- package/src/engine-components/export/usdz/extensions/behavior/Actions.ts +99 -0
- package/src/engine-components/export/usdz/extensions/behavior/Behaviour.ts +181 -0
- package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +503 -0
- package/src/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.ts +459 -0
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +1 -1
- package/src/engine-components/ui/BaseUIComponent.ts +7 -1
- package/src/engine-components/ui/Button.ts +14 -9
- package/src/engine-components/ui/Canvas.ts +178 -39
- package/src/engine-components/ui/EventSystem.ts +16 -9
- package/src/engine-components/ui/Graphic.ts +46 -8
- package/src/engine-components/ui/Image.ts +13 -4
- package/src/engine-components/ui/InputField.ts +9 -1
- package/src/engine-components/ui/Interfaces.ts +39 -3
- package/src/engine-components/ui/Layout.ts +303 -4
- package/src/engine-components/ui/Outline.ts +13 -0
- package/src/engine-components/ui/RectTransform.ts +236 -68
- package/src/engine-components/ui/Text.ts +284 -265
- package/src/engine-components/utils/LookAt.ts +74 -0
- package/src/engine-components/webxr/WebXRImageTracking.ts +179 -31
- package/lib/engine-components/export/usdz/types.d.ts +0 -34
- package/lib/engine-components/export/usdz/types.js +0 -2
- package/lib/engine-components/export/usdz/types.js.map +0 -1
- package/lib/engine-components/ui/Keyboard.d.ts +0 -31
- package/lib/engine-components/ui/Keyboard.js +0 -178
- package/lib/engine-components/ui/Keyboard.js.map +0 -1
- package/src/engine-components/export/usdz/types.ts +0 -39
- package/src/engine-components/ui/Keyboard.ts +0 -204
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { Behaviour } from "../Component";
|
|
2
1
|
import * as ThreeMeshUI from 'three-mesh-ui'
|
|
3
2
|
import { BaseUIComponent } from "./BaseUIComponent";
|
|
3
|
+
import { DocumentedOptions as ThreeMeshUIEveryOptions } from "three-mesh-ui/build/types/core/elements/MeshUIBaseElement";
|
|
4
4
|
import { serializable } from "../../engine/engine_serialization_decorator";
|
|
5
|
-
import { Color, Matrix4, Object3D, Vector2, Vector3 } from "three";
|
|
5
|
+
import { Color, Matrix4, Object3D, Quaternion, Vector2, Vector3 } from "three";
|
|
6
6
|
import { EventSystem } from "./EventSystem";
|
|
7
7
|
import { getParam } from "../../engine/engine_utils";
|
|
8
8
|
import { onChange } from "./Utils";
|
|
9
|
+
import { foreachComponentEnumerator } from "../../engine/engine_gameobject";
|
|
10
|
+
import { ICanvas, IRectTransform, IRectTransformChangedReceiver, ILayoutGroup } from "./Interfaces";
|
|
11
|
+
import { GameObject } from '../Component';
|
|
9
12
|
|
|
10
13
|
const debug = getParam("debugui");
|
|
14
|
+
const debugLayout = getParam("debuguilayout");
|
|
11
15
|
|
|
12
16
|
export class Size {
|
|
13
17
|
width!: number;
|
|
@@ -21,32 +25,77 @@ export class Rect {
|
|
|
21
25
|
height!: number;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
const tempVec = new Vector3();
|
|
29
|
+
const tempMatrix = new Matrix4();
|
|
30
|
+
const tempQuaternion = new Quaternion();
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
export class RectTransform extends BaseUIComponent implements IRectTransform, IRectTransformChangedReceiver {
|
|
33
|
+
|
|
34
|
+
offset: number = 0.1;
|
|
27
35
|
|
|
28
36
|
// @serializable(Object3D)
|
|
29
37
|
// root? : Object3D;
|
|
30
38
|
|
|
31
39
|
get translation() { return this.gameObject.position; }
|
|
32
40
|
get rotation() { return this.gameObject.quaternion; }
|
|
33
|
-
get scale():
|
|
41
|
+
get scale(): Vector3 { return this.gameObject.scale; }
|
|
34
42
|
|
|
35
43
|
private _anchoredPosition!: Vector3;
|
|
36
|
-
|
|
44
|
+
|
|
45
|
+
@serializable(Vector3)
|
|
46
|
+
get anchoredPosition() {
|
|
37
47
|
if (!this._anchoredPosition) this._anchoredPosition = new Vector3();
|
|
38
48
|
return this._anchoredPosition;
|
|
39
49
|
}
|
|
50
|
+
private set anchoredPosition(value: Vector3) {
|
|
51
|
+
this._anchoredPosition = value;
|
|
52
|
+
}
|
|
40
53
|
|
|
41
54
|
@serializable(Rect)
|
|
42
|
-
rect?: Rect;
|
|
55
|
+
private rect?: Rect; // TODO: should we use the rect or sizeDelta?
|
|
56
|
+
|
|
43
57
|
@serializable(Vector2)
|
|
44
|
-
sizeDelta!:
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
sizeDelta!: Vector2;
|
|
59
|
+
|
|
60
|
+
@serializable(Vector2)
|
|
61
|
+
pivot?: Vector2;
|
|
62
|
+
|
|
63
|
+
@serializable(Vector2)
|
|
64
|
+
anchorMin!: Vector2;
|
|
65
|
+
@serializable(Vector2)
|
|
66
|
+
anchorMax!: Vector2;
|
|
67
|
+
|
|
47
68
|
@serializable(Vector2)
|
|
48
|
-
|
|
69
|
+
offsetMin!: Vector2;
|
|
70
|
+
@serializable(Vector2)
|
|
71
|
+
offsetMax!: Vector2;
|
|
72
|
+
|
|
73
|
+
get width() {
|
|
74
|
+
if (this.anchorMin.x !== this.anchorMax.x) {
|
|
75
|
+
if (this._parentRectTransform) {
|
|
76
|
+
const parentWidth = this._parentRectTransform.width;
|
|
77
|
+
const anchorWidth = this.anchorMax.x - this.anchorMin.x;
|
|
78
|
+
let width = parentWidth * anchorWidth;
|
|
79
|
+
width += this.sizeDelta.x;
|
|
80
|
+
return width;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return this.sizeDelta.x;
|
|
84
|
+
}
|
|
85
|
+
get height() {
|
|
86
|
+
if (this.anchorMin.y !== this.anchorMax.y) {
|
|
87
|
+
if (this._parentRectTransform) {
|
|
88
|
+
const parentHeight = this._parentRectTransform.height;
|
|
89
|
+
const anchorHeight = this.anchorMax.y - this.anchorMin.y;
|
|
90
|
+
let height = parentHeight * anchorHeight;
|
|
91
|
+
height += this.sizeDelta.y;
|
|
92
|
+
return height
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return this.sizeDelta.y;
|
|
96
|
+
}
|
|
49
97
|
|
|
98
|
+
// private lastMatrixWorld!: Matrix4;
|
|
50
99
|
private lastMatrix!: Matrix4;
|
|
51
100
|
private rectBlock!: Object3D;
|
|
52
101
|
private _transformNeedsUpdate: boolean = false;
|
|
@@ -60,89 +109,192 @@ export class RectTransform extends BaseUIComponent {
|
|
|
60
109
|
|
|
61
110
|
// this is required if an animator animated the transform anchoring
|
|
62
111
|
if (!this._anchoredPosition) this._anchoredPosition = new Vector3();
|
|
63
|
-
|
|
112
|
+
|
|
113
|
+
// TODO: we need to replace this with the watch that e.g. Rigibody is using (or the one in utils?)
|
|
114
|
+
// perhaps we can also just manually check the few properties in the update loops?
|
|
115
|
+
// TODO: check if value actually changed, this is called on assignment
|
|
116
|
+
onChange(this, "_anchoredPosition", () => { this.markDirty(); });
|
|
117
|
+
onChange(this, "sizeDelta", () => { this.markDirty(); });
|
|
118
|
+
onChange(this, "pivot", () => { this.markDirty(); });
|
|
119
|
+
|
|
120
|
+
// When exported with an anchored position offset we remove it here
|
|
121
|
+
// because it would otherwise be applied twice when the anchoring is animated
|
|
122
|
+
// Maybe we can get rid of this workaround if we just set the mesh ui position from the
|
|
123
|
+
// anchored position value but then we would have to make sure if a user/the engine updates
|
|
124
|
+
// "position" the change would also land in anchoredPosition
|
|
125
|
+
// Another solution would perhaps be to get rid of the extra "anchoredPosition" vector3
|
|
126
|
+
// and instead use the same vector3 instance on both "position" and "anchoredPosition"
|
|
127
|
+
// But I'm also not sure if this will not cause issues elsewhere later / be confusing?
|
|
128
|
+
// (that being said we can make anchoredPosition hidden)
|
|
129
|
+
if (!this.isRoot()) {
|
|
130
|
+
this.gameObject.position.x += this.anchoredPosition.x;
|
|
131
|
+
this.gameObject.position.y -= this.anchoredPosition.y;
|
|
132
|
+
}
|
|
64
133
|
}
|
|
65
134
|
|
|
66
135
|
onEnable() {
|
|
67
136
|
super.onEnable();
|
|
68
137
|
this.addShadowComponent(this.rectBlock);
|
|
69
138
|
this._transformNeedsUpdate = true;
|
|
139
|
+
this.Canvas?.registerTransform(this);
|
|
70
140
|
}
|
|
71
141
|
|
|
72
142
|
onDisable() {
|
|
73
143
|
super.onDisable();
|
|
74
144
|
this.removeShadowComponent();
|
|
145
|
+
this.Canvas?.unregisterTransform(this);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
onParentRectTransformChanged(comp: IRectTransform) {
|
|
149
|
+
if (this._transformNeedsUpdate) return;
|
|
150
|
+
// When the parent rect transform changes we have to to recalculate our transform
|
|
151
|
+
this.onApplyTransform(debugLayout ? `${comp.name} changed` : undefined);
|
|
75
152
|
}
|
|
76
153
|
|
|
77
|
-
|
|
154
|
+
get isDirty() {
|
|
155
|
+
if(!this._transformNeedsUpdate) this._transformNeedsUpdate = !this.lastMatrix.equals(this.gameObject.matrix);
|
|
156
|
+
return this._transformNeedsUpdate;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// private _copyMatrixAfterRender: boolean = false;
|
|
160
|
+
|
|
161
|
+
markDirty() {
|
|
162
|
+
if (this._transformNeedsUpdate) return;
|
|
163
|
+
if (debugLayout) console.warn("RectTransform markDirty()", this.name)
|
|
164
|
+
this._transformNeedsUpdate = true;
|
|
165
|
+
// If mark dirty is called explictly we want to allow updating the transform again when updateTransform is called
|
|
166
|
+
// if we dont reset it here we get delayed layout updates
|
|
167
|
+
this._lastUpdateFrame = -1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
/** Will update the transforms if it changed or is dirty */
|
|
172
|
+
updateTransform() {
|
|
173
|
+
// TODO: instead of checking matrix again it would perhaps be better to test if position, rotation or scale have changed individually?
|
|
174
|
+
const transformChanged = this._transformNeedsUpdate || !this.lastMatrix.equals(this.gameObject.matrix);// || !this.lastMatrixWorld.equals(this.gameObject.matrixWorld);
|
|
175
|
+
if (transformChanged && this.canUpdate()) {
|
|
176
|
+
this.onApplyTransform(this._transformNeedsUpdate ? "Marked dirty" : "Matrix changed");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private _parentRectTransform?: RectTransform;
|
|
181
|
+
private _lastUpdateFrame: number = -1;
|
|
182
|
+
|
|
183
|
+
private canUpdate() {
|
|
184
|
+
return this._transformNeedsUpdate && this.activeAndEnabled && this._lastUpdateFrame !== this.context.time.frame;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private onApplyTransform(reason?: string) {
|
|
188
|
+
// TODO: need to improve the update logic, with this UI updates have some frame delay but dont happen exponentially per hierarchy
|
|
189
|
+
if (this.context.time.frameCount === this._lastUpdateFrame) return;
|
|
190
|
+
this._lastUpdateFrame = this.context.time.frameCount;
|
|
191
|
+
|
|
78
192
|
const uiobject = this.shadowComponent;
|
|
79
193
|
if (!uiobject) return;
|
|
194
|
+
this._parentRectTransform = GameObject.getComponentInParent(this.gameObject.parent!, RectTransform) as RectTransform;
|
|
195
|
+
|
|
80
196
|
this._transformNeedsUpdate = false;
|
|
197
|
+
this.lastMatrix.copy(this.gameObject.matrix);
|
|
198
|
+
|
|
199
|
+
if (debugLayout) console.warn("RectTransform → ApplyTransform", this.name + " because " + reason);
|
|
81
200
|
|
|
82
201
|
if (!this.isRoot()) {
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
uiobject.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
uiobject.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
202
|
+
// Reset temp matrix
|
|
203
|
+
uiobject.matrix.identity();
|
|
204
|
+
uiobject.matrixAutoUpdate = false;
|
|
205
|
+
// calc pivot and apply
|
|
206
|
+
tempVec.set(0, 0, 0);
|
|
207
|
+
this.applyPivot(tempVec);
|
|
208
|
+
uiobject.matrix.setPosition(tempVec.x, tempVec.y, 0);
|
|
209
|
+
// calc rotation matrix and apply (we can skip this if it's not rotated)
|
|
210
|
+
if (this.gameObject.quaternion.x || this.gameObject.quaternion.y || this.gameObject.quaternion.z) {
|
|
211
|
+
tempQuaternion.copy(this.gameObject.quaternion);
|
|
212
|
+
tempQuaternion.x *= -1;
|
|
213
|
+
tempQuaternion.z *= -1;
|
|
214
|
+
tempMatrix.makeRotationFromQuaternion(tempQuaternion);
|
|
215
|
+
uiobject.matrix.premultiply(tempMatrix);
|
|
216
|
+
}
|
|
217
|
+
// calc anchors and offset and apply
|
|
218
|
+
tempVec.set(0, 0, 0);
|
|
219
|
+
this.applyAnchoring(tempVec);
|
|
220
|
+
tempVec.z += this.offset;
|
|
221
|
+
tempVec.z -= this.gameObject.position.z;
|
|
222
|
+
tempMatrix.identity();
|
|
223
|
+
tempMatrix.setPosition(tempVec.x, tempVec.y, tempVec.z);
|
|
224
|
+
uiobject.matrix.premultiply(tempMatrix);
|
|
225
|
+
// apply scale if necessary
|
|
226
|
+
uiobject.matrix.scale(this.gameObject.scale);
|
|
97
227
|
}
|
|
98
228
|
else {
|
|
99
|
-
|
|
229
|
+
// We have to rotate the canvas when it's in worldspace
|
|
230
|
+
const canvas = this.Root as any as ICanvas;
|
|
231
|
+
if (!canvas.screenspace) uiobject.rotation.y = Math.PI;
|
|
100
232
|
}
|
|
101
233
|
|
|
102
|
-
this
|
|
103
|
-
|
|
104
|
-
|
|
234
|
+
// iterate other components on this object that might need to know about the transform change
|
|
235
|
+
// e.g. Graphic components should update their width and height
|
|
236
|
+
const includeChildren = true;
|
|
237
|
+
for (const comp of foreachComponentEnumerator(this.gameObject, BaseUIComponent, includeChildren, 1)) {
|
|
238
|
+
if (comp === this) continue;
|
|
239
|
+
if (!comp.activeAndEnabled) continue;
|
|
240
|
+
const callback = comp as any as IRectTransformChangedReceiver;
|
|
241
|
+
if (callback.onParentRectTransformChanged) {
|
|
242
|
+
// if (debugLayout) console.log(`RectTransform ${this.name} → call`, comp.name + "/" + comp.constructor.name)
|
|
243
|
+
callback.onParentRectTransformChanged(this);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
105
246
|
|
|
106
|
-
|
|
107
|
-
this._transformNeedsUpdate = true;
|
|
247
|
+
// const layout = GameObject.getComponentInParent(this.gameObject, ILayoutGroup);
|
|
108
248
|
}
|
|
109
249
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
250
|
+
// onAfterRender() {
|
|
251
|
+
// if (this._copyMatrixAfterRender) {
|
|
252
|
+
// // can we only have this event when the transform changed in this frame? Otherwise all RectTransforms will be iterated. Not sure what is better
|
|
253
|
+
// this.lastMatrixWorld.copy(this.gameObject.matrixWorld);
|
|
254
|
+
// }
|
|
255
|
+
// }
|
|
256
|
+
|
|
257
|
+
/** applies the position offset to the passed in vector */
|
|
258
|
+
private applyAnchoring(pos: Vector3) {
|
|
259
|
+
pos.x += this.anchoredPosition.x;
|
|
260
|
+
pos.y += this.anchoredPosition.y;
|
|
261
|
+
|
|
262
|
+
const parent = this._parentRectTransform;
|
|
263
|
+
if (parent) {
|
|
264
|
+
// Calculate vertical offset
|
|
265
|
+
let oy = 0;
|
|
266
|
+
const vert = 1 - this.anchorMax.y - this.anchorMin.y;
|
|
267
|
+
oy -= (parent.height * .5) * vert;
|
|
268
|
+
pos.y += oy;
|
|
269
|
+
|
|
270
|
+
// calculate horizontal offset
|
|
271
|
+
let ox = 0;
|
|
272
|
+
const horz = 1 - this.anchorMax.x - this.anchorMin.x;
|
|
273
|
+
ox -= (parent.width * .5) * horz;
|
|
274
|
+
pos.x += ox;
|
|
121
275
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
ty -= this.anchoredPosition.y;// * .05;
|
|
132
|
-
const offx = tx;
|
|
133
|
-
const offy = ty;
|
|
134
|
-
// console.log(this.name, this.pivot, tx, ty, "offset", offx, offy);
|
|
135
|
-
pos.x -= offx;
|
|
136
|
-
pos.y -= offy;
|
|
137
|
-
|
|
138
|
-
// TODO update size from anchoring, width, height, sizeDelta
|
|
139
|
-
if (this.shadowComponent)
|
|
140
|
-
// console.log(this.shadowComponent)
|
|
141
|
-
this.set({ width: this.sizeDelta.x, height: this.sizeDelta.y });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** applies the pivot offset to the passed in vector */
|
|
279
|
+
private applyPivot(vec: Vector3) {
|
|
280
|
+
if (this.pivot && !this.isRoot()) {
|
|
281
|
+
const pv = this.pivot.x - .5;
|
|
282
|
+
vec.x -= pv * this.sizeDelta.x * this.gameObject.scale.x;
|
|
283
|
+
const ph = this.pivot.y - .5;
|
|
284
|
+
vec.y -= ph * this.sizeDelta.y * this.gameObject.scale.y;
|
|
142
285
|
}
|
|
143
286
|
}
|
|
144
287
|
|
|
145
|
-
getBasicOptions():
|
|
288
|
+
getBasicOptions(): ThreeMeshUIEveryOptions {
|
|
289
|
+
|
|
290
|
+
// @TODO : instead of getBasicOptions for each component we could use once needleEngine initialized
|
|
291
|
+
// ThreeMeshUI.DefaultValues.set({
|
|
292
|
+
// backgroundOpacity: 1,
|
|
293
|
+
// borderWidth: 0, // if we dont specify width here a border will automatically propagated to child blocks
|
|
294
|
+
// borderRadius: 0,
|
|
295
|
+
// borderOpacity: 0,
|
|
296
|
+
// })
|
|
297
|
+
|
|
146
298
|
const opts = {
|
|
147
299
|
width: this.rect!.width,
|
|
148
300
|
height: this.rect!.height,// * this.context.mainCameraComponent!.aspect,
|
|
@@ -151,6 +303,7 @@ export class RectTransform extends BaseUIComponent {
|
|
|
151
303
|
borderWidth: 0, // if we dont specify width here a border will automatically propagated to child blocks
|
|
152
304
|
borderRadius: 0,
|
|
153
305
|
borderOpacity: 0,
|
|
306
|
+
letterSpacing: -0.03,
|
|
154
307
|
// justifyContent: 'center',
|
|
155
308
|
// alignItems: 'center',
|
|
156
309
|
// alignContent: 'center',
|
|
@@ -169,17 +322,32 @@ export class RectTransform extends BaseUIComponent {
|
|
|
169
322
|
return opts;
|
|
170
323
|
}
|
|
171
324
|
|
|
172
|
-
private _createdBlocks
|
|
325
|
+
private _createdBlocks: ThreeMeshUI.Block[] = [];
|
|
326
|
+
private _createdTextBlocks: ThreeMeshUI.Text[] = [];
|
|
173
327
|
|
|
174
|
-
createNewBlock(opts?:
|
|
328
|
+
createNewBlock(opts?: ThreeMeshUIEveryOptions | object): ThreeMeshUI.Block {
|
|
175
329
|
opts = {
|
|
176
330
|
...this.getBasicOptions(),
|
|
177
331
|
...opts
|
|
178
332
|
};
|
|
179
333
|
if (debug)
|
|
180
334
|
console.log(this.name, opts);
|
|
181
|
-
const block = new ThreeMeshUI.Block(opts as
|
|
335
|
+
const block = new ThreeMeshUI.Block(opts as ThreeMeshUIEveryOptions);
|
|
182
336
|
this._createdBlocks.push(block);
|
|
183
337
|
return block;
|
|
184
338
|
}
|
|
339
|
+
|
|
340
|
+
createNewText(opts?: ThreeMeshUIEveryOptions | object): ThreeMeshUI.Block {
|
|
341
|
+
if (debug)
|
|
342
|
+
console.log(opts)
|
|
343
|
+
opts = {
|
|
344
|
+
...this.getBasicOptions(),
|
|
345
|
+
...opts,
|
|
346
|
+
};
|
|
347
|
+
if (debug)
|
|
348
|
+
console.log(this.name, opts);
|
|
349
|
+
const block = new ThreeMeshUI.Text(opts as ThreeMeshUIEveryOptions);
|
|
350
|
+
this._createdTextBlocks.push(block);
|
|
351
|
+
return block;
|
|
352
|
+
}
|
|
185
353
|
}
|