@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.
Files changed (151) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/needle-engine.js +44005 -36382
  3. package/dist/needle-engine.min.js +706 -513
  4. package/dist/needle-engine.umd.cjs +685 -492
  5. package/lib/engine/codegen/register_types.js +54 -4
  6. package/lib/engine/codegen/register_types.js.map +1 -1
  7. package/lib/engine/engine_addressables.d.ts +3 -3
  8. package/lib/engine/engine_addressables.js +30 -9
  9. package/lib/engine/engine_addressables.js.map +1 -1
  10. package/lib/engine/engine_element.js +1 -1
  11. package/lib/engine/engine_element.js.map +1 -1
  12. package/lib/engine/engine_gameobject.d.ts +2 -1
  13. package/lib/engine/engine_gameobject.js +19 -0
  14. package/lib/engine/engine_gameobject.js.map +1 -1
  15. package/lib/engine/engine_input.js +10 -0
  16. package/lib/engine/engine_input.js.map +1 -1
  17. package/lib/engine/engine_math.d.ts +4 -0
  18. package/lib/engine/engine_math.js +6 -0
  19. package/lib/engine/engine_math.js.map +1 -1
  20. package/lib/engine/engine_three_utils.js +2 -2
  21. package/lib/engine/engine_three_utils.js.map +1 -1
  22. package/lib/engine-components/Animation.js +4 -0
  23. package/lib/engine-components/Animation.js.map +1 -1
  24. package/lib/engine-components/AnimatorController.js +7 -2
  25. package/lib/engine-components/AnimatorController.js.map +1 -1
  26. package/lib/engine-components/OrbitControls.js +13 -4
  27. package/lib/engine-components/OrbitControls.js.map +1 -1
  28. package/lib/engine-components/TransformGizmo.d.ts +8 -4
  29. package/lib/engine-components/TransformGizmo.js +62 -63
  30. package/lib/engine-components/TransformGizmo.js.map +1 -1
  31. package/lib/engine-components/codegen/components.d.ts +27 -2
  32. package/lib/engine-components/codegen/components.js +27 -2
  33. package/lib/engine-components/codegen/components.js.map +1 -1
  34. package/lib/engine-components/export/usdz/Extension.d.ts +4 -4
  35. package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +86 -0
  36. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +830 -0
  37. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -0
  38. package/lib/engine-components/export/usdz/USDZExporter.d.ts +6 -3
  39. package/lib/engine-components/export/usdz/USDZExporter.js +34 -11
  40. package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
  41. package/lib/engine-components/export/usdz/extensions/Animation.d.ts +15 -15
  42. package/lib/engine-components/export/usdz/extensions/Animation.js +24 -29
  43. package/lib/engine-components/export/usdz/extensions/Animation.js.map +1 -1
  44. package/lib/engine-components/export/usdz/extensions/DocumentExtension.d.ts +5 -0
  45. package/lib/engine-components/export/usdz/extensions/DocumentExtension.js +7 -0
  46. package/lib/engine-components/export/usdz/extensions/DocumentExtension.js.map +1 -0
  47. package/lib/engine-components/export/usdz/extensions/USDZText.d.ts +47 -0
  48. package/lib/engine-components/export/usdz/extensions/USDZText.js +114 -0
  49. package/lib/engine-components/export/usdz/extensions/USDZText.js.map +1 -0
  50. package/lib/engine-components/export/usdz/extensions/behavior/Actions.d.ts +30 -0
  51. package/lib/engine-components/export/usdz/extensions/behavior/Actions.js +89 -0
  52. package/lib/engine-components/export/usdz/extensions/behavior/Actions.js.map +1 -0
  53. package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.d.ts +23 -0
  54. package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.js +114 -0
  55. package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.js.map +1 -0
  56. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +96 -0
  57. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js +421 -0
  58. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -0
  59. package/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.d.ts +111 -0
  60. package/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.js +409 -0
  61. package/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.js.map +1 -0
  62. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  63. package/lib/engine-components/ui/BaseUIComponent.d.ts +2 -0
  64. package/lib/engine-components/ui/BaseUIComponent.js +6 -0
  65. package/lib/engine-components/ui/BaseUIComponent.js.map +1 -1
  66. package/lib/engine-components/ui/Button.js +9 -5
  67. package/lib/engine-components/ui/Button.js.map +1 -1
  68. package/lib/engine-components/ui/Canvas.d.ts +23 -6
  69. package/lib/engine-components/ui/Canvas.js +167 -34
  70. package/lib/engine-components/ui/Canvas.js.map +1 -1
  71. package/lib/engine-components/ui/EventSystem.d.ts +6 -0
  72. package/lib/engine-components/ui/EventSystem.js +4 -4
  73. package/lib/engine-components/ui/EventSystem.js.map +1 -1
  74. package/lib/engine-components/ui/Graphic.d.ts +5 -2
  75. package/lib/engine-components/ui/Graphic.js +38 -7
  76. package/lib/engine-components/ui/Graphic.js.map +1 -1
  77. package/lib/engine-components/ui/Image.d.ts +1 -0
  78. package/lib/engine-components/ui/Image.js +14 -5
  79. package/lib/engine-components/ui/Image.js.map +1 -1
  80. package/lib/engine-components/ui/InputField.d.ts +1 -0
  81. package/lib/engine-components/ui/InputField.js +8 -0
  82. package/lib/engine-components/ui/InputField.js.map +1 -1
  83. package/lib/engine-components/ui/Interfaces.d.ts +19 -0
  84. package/lib/engine-components/ui/Interfaces.js +11 -0
  85. package/lib/engine-components/ui/Interfaces.js.map +1 -1
  86. package/lib/engine-components/ui/Layout.d.ts +65 -3
  87. package/lib/engine-components/ui/Layout.js +304 -3
  88. package/lib/engine-components/ui/Layout.js.map +1 -1
  89. package/lib/engine-components/ui/Outline.d.ts +7 -0
  90. package/lib/engine-components/ui/Outline.js +21 -0
  91. package/lib/engine-components/ui/Outline.js.map +1 -0
  92. package/lib/engine-components/ui/RectTransform.d.ts +32 -13
  93. package/lib/engine-components/ui/RectTransform.js +216 -56
  94. package/lib/engine-components/ui/RectTransform.js.map +1 -1
  95. package/lib/engine-components/ui/Text.d.ts +13 -10
  96. package/lib/engine-components/ui/Text.js +177 -246
  97. package/lib/engine-components/ui/Text.js.map +1 -1
  98. package/lib/engine-components/utils/LookAt.d.ts +13 -0
  99. package/lib/engine-components/utils/LookAt.js +66 -0
  100. package/lib/engine-components/utils/LookAt.js.map +1 -0
  101. package/lib/engine-components/webxr/WebXRImageTracking.d.ts +12 -3
  102. package/lib/engine-components/webxr/WebXRImageTracking.js +156 -24
  103. package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
  104. package/lib/tsconfig.tsbuildinfo +1 -1
  105. package/package.json +2 -2
  106. package/plugins/vite/reload.js +13 -2
  107. package/src/engine/codegen/register_types.js +56 -6
  108. package/src/engine/engine_addressables.ts +28 -10
  109. package/src/engine/engine_element.ts +1 -1
  110. package/src/engine/engine_gameobject.ts +19 -1
  111. package/src/engine/engine_input.ts +11 -0
  112. package/src/engine/engine_math.ts +10 -0
  113. package/src/engine/engine_three_utils.ts +2 -2
  114. package/src/engine-components/Animation.ts +4 -0
  115. package/src/engine-components/AnimatorController.ts +7 -1
  116. package/src/engine-components/OrbitControls.ts +14 -6
  117. package/src/engine-components/TransformGizmo.ts +64 -70
  118. package/src/engine-components/codegen/components.ts +27 -2
  119. package/src/engine-components/export/usdz/Extension.ts +4 -5
  120. package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +1280 -0
  121. package/src/engine-components/export/usdz/USDZExporter.ts +39 -17
  122. package/src/engine-components/export/usdz/extensions/Animation.ts +37 -45
  123. package/src/engine-components/export/usdz/extensions/DocumentExtension.ts +10 -0
  124. package/src/engine-components/export/usdz/extensions/USDZText.ts +142 -0
  125. package/src/engine-components/export/usdz/extensions/behavior/Actions.ts +99 -0
  126. package/src/engine-components/export/usdz/extensions/behavior/Behaviour.ts +181 -0
  127. package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +503 -0
  128. package/src/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.ts +459 -0
  129. package/src/engine-components/postprocessing/PostProcessingHandler.ts +1 -1
  130. package/src/engine-components/ui/BaseUIComponent.ts +7 -1
  131. package/src/engine-components/ui/Button.ts +14 -9
  132. package/src/engine-components/ui/Canvas.ts +178 -39
  133. package/src/engine-components/ui/EventSystem.ts +16 -9
  134. package/src/engine-components/ui/Graphic.ts +46 -8
  135. package/src/engine-components/ui/Image.ts +13 -4
  136. package/src/engine-components/ui/InputField.ts +9 -1
  137. package/src/engine-components/ui/Interfaces.ts +39 -3
  138. package/src/engine-components/ui/Layout.ts +303 -4
  139. package/src/engine-components/ui/Outline.ts +13 -0
  140. package/src/engine-components/ui/RectTransform.ts +236 -68
  141. package/src/engine-components/ui/Text.ts +284 -265
  142. package/src/engine-components/utils/LookAt.ts +74 -0
  143. package/src/engine-components/webxr/WebXRImageTracking.ts +179 -31
  144. package/lib/engine-components/export/usdz/types.d.ts +0 -34
  145. package/lib/engine-components/export/usdz/types.js +0 -2
  146. package/lib/engine-components/export/usdz/types.js.map +0 -1
  147. package/lib/engine-components/ui/Keyboard.d.ts +0 -31
  148. package/lib/engine-components/ui/Keyboard.js +0 -178
  149. package/lib/engine-components/ui/Keyboard.js.map +0 -1
  150. package/src/engine-components/export/usdz/types.ts +0 -39
  151. package/src/engine-components/ui/Keyboard.ts +0 -204
@@ -1,17 +1,316 @@
1
- import { Behaviour } from "../Component";
1
+ import { ILayoutGroup, IRectTransform, IRectTransformChangedReceiver } from "./Interfaces";
2
+ import { Behaviour, GameObject } from "../Component";
3
+ import { serializable } from "../../engine/engine_serialization";
4
+ import { Canvas } from "./Canvas";
5
+ import { RectTransform } from "./RectTransform";
6
+ import { getParam } from "../../engine/engine_utils";
2
7
 
3
- export class LayoutGroup extends Behaviour {
8
+ const debug = getParam("debuguilayout");
9
+
10
+ export class Padding {
11
+ @serializable()
12
+ left: number = 0;
13
+ @serializable()
14
+ right: number = 0;
15
+ @serializable()
16
+ top: number = 0;
17
+ @serializable()
18
+ bottom: number = 0;
19
+
20
+ get vertical() {
21
+ return this.top + this.bottom;
22
+ }
23
+ get horizontal() {
24
+ return this.left + this.right;
25
+ }
26
+ }
27
+
28
+ export enum TextAnchor {
29
+ UpperLeft = 0,
30
+ UpperCenter = 1,
31
+ UpperRight = 2,
32
+ MiddleLeft = 3,
33
+ MiddleCenter = 4,
34
+ MiddleRight = 5,
35
+ LowerLeft = 6,
36
+ LowerCenter = 7,
37
+ LowerRight = 8,
38
+ Custom = 9
39
+ }
40
+
41
+ enum Axis {
42
+ Horizontal = "x",
43
+ Vertical = "y"
44
+ }
45
+
46
+ export abstract class LayoutGroup extends Behaviour implements ILayoutGroup {
47
+
48
+ private _rectTransform: RectTransform | null = null;
49
+ private get rectTransform() {
50
+ return this._rectTransform;
51
+ }
52
+
53
+ onParentRectTransformChanged(_comp: IRectTransform): void {
54
+ this._needsUpdate = true;
55
+ }
56
+
57
+ private _needsUpdate: boolean = false;
58
+ get isDirty(): boolean {
59
+ return this._needsUpdate;
60
+ }
61
+
62
+ get isLayoutGroup(): boolean {
63
+ return true;
64
+ }
65
+
66
+ updateLayout() {
67
+ if (!this._rectTransform) return;
68
+ if (debug)
69
+ console.warn("Layout Update", this.context.time.frame, this.name);
70
+ this._needsUpdate = false;
71
+ this.onCalculateLayout(this._rectTransform);
72
+ }
73
+
74
+ // onBeforeRender(): void {
75
+ // this.updateLayout();
76
+ // }
77
+
78
+ @serializable()
79
+ childAlignment: TextAnchor = TextAnchor.UpperLeft;
80
+
81
+ @serializable()
4
82
  reverseArrangement: boolean = false;
83
+
84
+ @serializable()
85
+ spacing: number = 0;
86
+ @serializable(Padding)
87
+ padding!: Padding;
88
+
89
+ @serializable()
90
+ minWidth: number = 0;
91
+ @serializable()
92
+ minHeight: number = 0;
93
+
94
+ @serializable()
95
+ flexibleHeight: number = 0;
96
+ @serializable()
97
+ flexibleWidth: number = 0;
98
+
99
+ @serializable()
100
+ preferredHeight: number = 0;
101
+ @serializable()
102
+ preferredWidth: number = 0;
103
+
104
+ start() {
105
+ this._needsUpdate = true;
106
+ }
107
+
108
+ onEnable(): void {
109
+ if(debug) console.log(this.name, this);
110
+ this._rectTransform = this.gameObject.getComponent(RectTransform);
111
+ const canvas = this.gameObject.getComponentInParent(Canvas);
112
+ if (canvas) {
113
+ canvas.registerLayoutGroup(this);
114
+ }
115
+ this._needsUpdate = true;
116
+ }
117
+
118
+ onDisable(): void {
119
+ const canvas = this.gameObject.getComponentInParent(Canvas);
120
+ if (canvas) {
121
+ canvas.unregisterLayoutGroup(this);
122
+ }
123
+ }
124
+
125
+ protected abstract onCalculateLayout(rt: RectTransform);
126
+
127
+
128
+
129
+ // for animation:
130
+ private set m_Spacing(val) {
131
+ if (val === this.spacing) return;
132
+ this._needsUpdate = true;
133
+ this.spacing = val;
134
+ }
135
+ get m_Spacing() {
136
+ return this.spacing;
137
+ }
5
138
  }
6
139
 
7
- export class VerticalLayoutGroup extends LayoutGroup {
140
+ export abstract class HorizontalOrVerticalLayoutGroup extends LayoutGroup {
141
+
142
+ @serializable()
143
+ childControlHeight: boolean = true;
144
+ @serializable()
145
+ childControlWidth: boolean = true;
146
+ @serializable()
147
+ childForceExpandHeight: boolean = false;
148
+ @serializable()
149
+ childForceExpandWidth: boolean = false;
150
+ @serializable()
151
+ childScaleHeight: boolean = false;
152
+ @serializable()
153
+ childScaleWidth: boolean = false;
154
+
155
+ protected abstract get primaryAxis(): Axis;
156
+
157
+ protected onCalculateLayout(rect: RectTransform) {
158
+ const axis = this.primaryAxis;
159
+
160
+ const totalWidth = rect.width;
161
+ let actualWidth = totalWidth;
162
+ const totalHeight = rect.height;
163
+ let actualHeight = totalHeight;
164
+ actualWidth -= this.padding.horizontal;
165
+ actualHeight -= this.padding.vertical;
166
+
167
+ // console.log(rt.name, "width=" + totalWidth + ", height=" + totalHeight)
168
+
169
+ const paddingAxis = axis === Axis.Horizontal ? this.padding.horizontal : this.padding.vertical;
170
+ const isHorizontal = axis === Axis.Horizontal;
171
+ const isVertical = !isHorizontal;
172
+ const otherAxis = isHorizontal ? "y" : "x";
173
+ const controlSize = isHorizontal ? this.childControlWidth : this.childControlHeight;
174
+ const controlSizeOtherAxis = isHorizontal ? this.childControlHeight : this.childControlWidth;
175
+ const forceExpandSize = isHorizontal ? this.childForceExpandWidth : this.childForceExpandHeight;
176
+ const forceExpandSizeOtherAxis = isHorizontal ? this.childForceExpandHeight : this.childForceExpandWidth;
177
+ const actualExpandSize = isHorizontal ? actualHeight : actualWidth;
178
+ const totalSpace = isHorizontal ? totalWidth : totalHeight;
179
+ // 0 is left/top, 0.5 is middle, 1 is right/bottom
180
+ const alignmentOnAxis = 0.5 * (isHorizontal ? this.childAlignment % 3 : Math.floor(this.childAlignment / 3));
181
+
182
+ let start = 0;
183
+ if (isHorizontal) {
184
+ start += this.padding.left;
185
+ }
186
+ else
187
+ start += this.padding.top;
188
+
189
+
190
+ // Calculate total size of the elements
191
+ let totalChildSize = 0;
192
+ let actualRectTransformChildCount = 0;
193
+ for (let i = 0; i < this.gameObject.children.length; i++) {
194
+ const ch = this.gameObject.children[i];
195
+ const rt = GameObject.getComponent(ch, RectTransform);
196
+ if (rt?.activeAndEnabled) {
197
+ actualRectTransformChildCount += 1;
198
+ if (isHorizontal) {
199
+ totalChildSize += rt.width;
200
+ }
201
+ else {
202
+ totalChildSize += rt.height;
203
+ }
204
+ }
205
+ }
206
+
207
+ let sizePerChild = 0;
208
+ const totalSpacing = this.spacing * (actualRectTransformChildCount - 1)
209
+ if (forceExpandSize || controlSize) {
210
+ let size = 0;
211
+ if (isHorizontal) {
212
+ size = actualWidth -= totalSpacing;
213
+ }
214
+ else {
215
+ size = actualHeight -= totalSpacing;
216
+ }
217
+ if (actualRectTransformChildCount > 0)
218
+ sizePerChild = size / actualRectTransformChildCount;
219
+ }
220
+
221
+ let leftOffset = 0;
222
+ leftOffset += this.padding.left;
223
+ leftOffset -= this.padding.right;
224
+
225
+ if (alignmentOnAxis !== 0) {
226
+ start = totalSpace - totalChildSize;
227
+ start *= alignmentOnAxis;
228
+ start -= totalSpacing * alignmentOnAxis;
229
+ if (isHorizontal) {
230
+ start -= this.padding.right * alignmentOnAxis;
231
+ start += this.padding.left * (1 - alignmentOnAxis);
232
+ if (start < this.padding.left) {
233
+ start = this.padding.left;
234
+ }
235
+ }
236
+ else {
237
+ start -= this.padding.bottom * alignmentOnAxis;
238
+ start += this.padding.top * (1 - alignmentOnAxis);
239
+ if (start < this.padding.top) {
240
+ start = this.padding.top;
241
+ }
242
+ }
243
+ }
244
+
245
+ // Apply layout
246
+ let k = 0;
247
+ for (let i = 0; i < this.gameObject.children.length; i++) {
248
+ const ch = this.gameObject.children[i];
249
+ const rt = GameObject.getComponent(ch, RectTransform);
250
+ if (rt?.activeAndEnabled) {
251
+ rt.pivot?.set(.5, .5);
252
+ // Horizontal padding
253
+ const x = totalWidth * .5 + leftOffset * .5;
254
+ if (rt.anchoredPosition.x !== x)
255
+ rt.anchoredPosition.x = x;
256
+ const y = totalHeight * -.5
257
+ if (rt.anchoredPosition.y !== y)
258
+ rt.anchoredPosition.y = y;
259
+ // Set the size for the secondary axis (e.g. height for a horizontal layout group)
260
+ if (forceExpandSizeOtherAxis && controlSizeOtherAxis && rt.sizeDelta[otherAxis] !== actualExpandSize) {
261
+ rt.sizeDelta[otherAxis] = actualExpandSize;
262
+ }
263
+ // Set the size for the primary axis (e.g. width for a horizontal layout group)
264
+ if (forceExpandSize && controlSize && rt.sizeDelta[axis] !== sizePerChild) {
265
+ rt.sizeDelta[axis] = sizePerChild
266
+ }
267
+
268
+ const size = isHorizontal ? rt.width : rt.height;
269
+ let halfSize = size * .5;
270
+ start += halfSize;
271
+
272
+ if (forceExpandSize) {
273
+ let preferredStart = sizePerChild * (k + 1) - sizePerChild * .5;
274
+ if (preferredStart > start)
275
+ start = preferredStart;
276
+ }
277
+
278
+ let value = start;
279
+ if (axis === Axis.Vertical)
280
+ value = -value;
281
+ // Only set the position if it's not already the correct one to avoid triggering the rectTransform dirty event
282
+ if (rt.anchoredPosition[axis] !== value) {
283
+ rt.anchoredPosition[axis] = value
284
+ }
285
+
286
+ start += halfSize;
287
+ start += this.spacing;
288
+ k += 1;
289
+ }
290
+ }
291
+ }
292
+
293
+
294
+ }
295
+
296
+ export class VerticalLayoutGroup extends HorizontalOrVerticalLayoutGroup {
297
+
298
+ protected get primaryAxis() {
299
+ return Axis.Vertical;
300
+ }
8
301
 
9
302
  }
10
303
 
11
- export class HorizontalLayoutGroup extends LayoutGroup {
304
+ export class HorizontalLayoutGroup extends HorizontalOrVerticalLayoutGroup {
305
+
306
+ protected get primaryAxis() {
307
+ return Axis.Horizontal;
308
+ }
12
309
 
13
310
  }
14
311
 
15
312
  export class GridLayoutGroup extends LayoutGroup {
313
+ protected onCalculateLayout() {
314
+ }
16
315
 
17
316
  }
@@ -0,0 +1,13 @@
1
+ import { RGBAColor } from "../js-extensions";
2
+ import { serializable } from "../../engine/engine_serialization";
3
+ import { Behaviour } from "../Component";
4
+ import { Color, Vector2 } from "three"
5
+
6
+ export class Outline extends Behaviour {
7
+
8
+ @serializable(RGBAColor)
9
+ effectColor?: RGBAColor;
10
+
11
+ @serializable(Vector2)
12
+ effectDistance?: Vector2;
13
+ }