@needle-tools/engine 3.3.0-alpha → 3.5.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 (149) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/needle-engine.js +62620 -61118
  3. package/dist/needle-engine.min.js +434 -410
  4. package/dist/needle-engine.umd.cjs +435 -411
  5. package/lib/engine/api.d.ts +1 -0
  6. package/lib/engine/api.js +1 -0
  7. package/lib/engine/api.js.map +1 -1
  8. package/lib/engine/codegen/register_types.js +50 -2
  9. package/lib/engine/codegen/register_types.js.map +1 -1
  10. package/lib/engine/engine_context.d.ts +1 -1
  11. package/lib/engine/engine_context.js +21 -15
  12. package/lib/engine/engine_context.js.map +1 -1
  13. package/lib/engine/engine_context_registry.d.ts +5 -3
  14. package/lib/engine/engine_context_registry.js +10 -2
  15. package/lib/engine/engine_context_registry.js.map +1 -1
  16. package/lib/engine/engine_element.js.map +1 -1
  17. package/lib/engine/engine_element_loading.js +2 -3
  18. package/lib/engine/engine_element_loading.js.map +1 -1
  19. package/lib/engine/engine_gameobject.d.ts +1 -1
  20. package/lib/engine/engine_gameobject.js +4 -2
  21. package/lib/engine/engine_gameobject.js.map +1 -1
  22. package/lib/engine/engine_input.d.ts +2 -2
  23. package/lib/engine/engine_physics.d.ts +20 -93
  24. package/lib/engine/engine_physics.js +20 -892
  25. package/lib/engine/engine_physics.js.map +1 -1
  26. package/lib/engine/engine_physics.types.js.map +1 -1
  27. package/lib/engine/engine_physics_rapier.d.ts +103 -0
  28. package/lib/engine/engine_physics_rapier.js +1003 -0
  29. package/lib/engine/engine_physics_rapier.js.map +1 -0
  30. package/lib/engine/engine_three_utils.js +2 -2
  31. package/lib/engine/engine_three_utils.js.map +1 -1
  32. package/lib/engine/engine_types.d.ts +50 -1
  33. package/lib/engine/engine_types.js +8 -0
  34. package/lib/engine/engine_types.js.map +1 -1
  35. package/lib/engine-components/Animation.js +4 -0
  36. package/lib/engine-components/Animation.js.map +1 -1
  37. package/lib/engine-components/Collider.js +6 -6
  38. package/lib/engine-components/Collider.js.map +1 -1
  39. package/lib/engine-components/Joints.js +2 -2
  40. package/lib/engine-components/Joints.js.map +1 -1
  41. package/lib/engine-components/RigidBody.d.ts +0 -1
  42. package/lib/engine-components/RigidBody.js +24 -30
  43. package/lib/engine-components/RigidBody.js.map +1 -1
  44. package/lib/engine-components/codegen/components.d.ts +25 -1
  45. package/lib/engine-components/codegen/components.js +25 -1
  46. package/lib/engine-components/codegen/components.js.map +1 -1
  47. package/lib/engine-components/export/usdz/Extension.d.ts +4 -4
  48. package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +86 -0
  49. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +858 -0
  50. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -0
  51. package/lib/engine-components/export/usdz/USDZExporter.d.ts +6 -3
  52. package/lib/engine-components/export/usdz/USDZExporter.js +34 -11
  53. package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
  54. package/lib/engine-components/export/usdz/extensions/Animation.d.ts +15 -15
  55. package/lib/engine-components/export/usdz/extensions/Animation.js +24 -29
  56. package/lib/engine-components/export/usdz/extensions/Animation.js.map +1 -1
  57. package/lib/engine-components/export/usdz/extensions/DocumentExtension.d.ts +5 -0
  58. package/lib/engine-components/export/usdz/extensions/DocumentExtension.js +7 -0
  59. package/lib/engine-components/export/usdz/extensions/DocumentExtension.js.map +1 -0
  60. package/lib/engine-components/export/usdz/extensions/USDZText.d.ts +47 -0
  61. package/lib/engine-components/export/usdz/extensions/USDZText.js +114 -0
  62. package/lib/engine-components/export/usdz/extensions/USDZText.js.map +1 -0
  63. package/lib/engine-components/export/usdz/extensions/behavior/Actions.d.ts +30 -0
  64. package/lib/engine-components/export/usdz/extensions/behavior/Actions.js +89 -0
  65. package/lib/engine-components/export/usdz/extensions/behavior/Actions.js.map +1 -0
  66. package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.d.ts +23 -0
  67. package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.js +114 -0
  68. package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.js.map +1 -0
  69. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +102 -0
  70. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js +458 -0
  71. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -0
  72. package/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.d.ts +111 -0
  73. package/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.js +409 -0
  74. package/lib/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.js.map +1 -0
  75. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  76. package/lib/engine-components/ui/BaseUIComponent.d.ts +2 -0
  77. package/lib/engine-components/ui/BaseUIComponent.js +6 -0
  78. package/lib/engine-components/ui/BaseUIComponent.js.map +1 -1
  79. package/lib/engine-components/ui/Canvas.d.ts +11 -1
  80. package/lib/engine-components/ui/Canvas.js +72 -3
  81. package/lib/engine-components/ui/Canvas.js.map +1 -1
  82. package/lib/engine-components/ui/Graphic.js.map +1 -1
  83. package/lib/engine-components/ui/Image.js +4 -4
  84. package/lib/engine-components/ui/Image.js.map +1 -1
  85. package/lib/engine-components/ui/Interfaces.d.ts +11 -0
  86. package/lib/engine-components/ui/Interfaces.js +11 -0
  87. package/lib/engine-components/ui/Interfaces.js.map +1 -1
  88. package/lib/engine-components/ui/Layout.d.ts +65 -3
  89. package/lib/engine-components/ui/Layout.js +304 -3
  90. package/lib/engine-components/ui/Layout.js.map +1 -1
  91. package/lib/engine-components/ui/RectTransform.d.ts +8 -7
  92. package/lib/engine-components/ui/RectTransform.js +66 -36
  93. package/lib/engine-components/ui/RectTransform.js.map +1 -1
  94. package/lib/engine-components/utils/LookAt.d.ts +7 -1
  95. package/lib/engine-components/utils/LookAt.js +43 -6
  96. package/lib/engine-components/utils/LookAt.js.map +1 -1
  97. package/lib/engine-components/webxr/WebXRImageTracking.d.ts +4 -3
  98. package/lib/engine-components/webxr/WebXRImageTracking.js +81 -25
  99. package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
  100. package/lib/tsconfig.tsbuildinfo +1 -1
  101. package/package.json +1 -1
  102. package/plugins/vite/config.js +2 -1
  103. package/plugins/vite/defines.js +30 -0
  104. package/plugins/vite/dependency-watcher.js +173 -0
  105. package/plugins/vite/editor-connection.js +37 -39
  106. package/plugins/vite/index.js +5 -1
  107. package/plugins/vite/reload.js +16 -3
  108. package/src/engine/api.ts +1 -0
  109. package/src/engine/codegen/register_types.js +50 -2
  110. package/src/engine/engine_context.ts +32 -23
  111. package/src/engine/engine_context_registry.ts +13 -6
  112. package/src/engine/engine_element.ts +2 -1
  113. package/src/engine/engine_element_loading.ts +2 -3
  114. package/src/engine/engine_gameobject.ts +3 -2
  115. package/src/engine/engine_input.ts +2 -2
  116. package/src/engine/engine_physics.ts +25 -1020
  117. package/src/engine/engine_physics.types.ts +1 -3
  118. package/src/engine/engine_physics_rapier.ts +1127 -0
  119. package/src/engine/engine_three_utils.ts +2 -2
  120. package/src/engine/engine_types.ts +66 -4
  121. package/src/engine-components/Animation.ts +4 -0
  122. package/src/engine-components/Collider.ts +6 -6
  123. package/src/engine-components/Joints.ts +2 -2
  124. package/src/engine-components/RigidBody.ts +24 -31
  125. package/src/engine-components/codegen/components.ts +25 -1
  126. package/src/engine-components/export/usdz/Extension.ts +4 -5
  127. package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +1312 -0
  128. package/src/engine-components/export/usdz/USDZExporter.ts +39 -17
  129. package/src/engine-components/export/usdz/extensions/Animation.ts +37 -45
  130. package/src/engine-components/export/usdz/extensions/DocumentExtension.ts +10 -0
  131. package/src/engine-components/export/usdz/extensions/USDZText.ts +142 -0
  132. package/src/engine-components/export/usdz/extensions/behavior/Actions.ts +99 -0
  133. package/src/engine-components/export/usdz/extensions/behavior/Behaviour.ts +181 -0
  134. package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +545 -0
  135. package/src/engine-components/export/usdz/extensions/behavior/BehavioursBuilder.ts +459 -0
  136. package/src/engine-components/postprocessing/PostProcessingHandler.ts +1 -1
  137. package/src/engine-components/ui/BaseUIComponent.ts +7 -1
  138. package/src/engine-components/ui/Canvas.ts +80 -5
  139. package/src/engine-components/ui/Graphic.ts +2 -0
  140. package/src/engine-components/ui/Image.ts +3 -3
  141. package/src/engine-components/ui/Interfaces.ts +30 -6
  142. package/src/engine-components/ui/Layout.ts +303 -4
  143. package/src/engine-components/ui/RectTransform.ts +67 -41
  144. package/src/engine-components/utils/LookAt.ts +60 -7
  145. package/src/engine-components/webxr/WebXRImageTracking.ts +100 -27
  146. package/lib/engine-components/export/usdz/types.d.ts +0 -34
  147. package/lib/engine-components/export/usdz/types.js +0 -2
  148. package/lib/engine-components/export/usdz/types.js.map +0 -1
  149. package/src/engine-components/export/usdz/types.ts +0 -39
@@ -1,15 +1,15 @@
1
1
  import { delay, getParam, isiOS, isMobileDevice, isSafari } from "../../../engine/engine_utils";
2
- import { Object3D, Color, Mesh, Matrix4 } from "three";
3
- import { USDZExporter as ThreeUSDZExporter } from "three/examples/jsm/exporters/USDZExporter";
2
+ import { Object3D, Mesh, Matrix4 } from "three";
3
+ import { USDZExporter as ThreeUSDZExporter } from "./ThreeUSDZExporter";
4
4
  import { AnimationExtension } from "./extensions/Animation"
5
5
  import { ensureQuicklookLinkIsCreated } from "./utils/quicklook";
6
6
  import { getFormattedDate } from "./utils/timeutils";
7
7
  import { registerAnimatorsImplictly } from "./utils/animationutils";
8
- import { IUSDZExporterExtension } from "./Extension";
8
+ import { IUSDExporterExtension } from "./Extension";
9
9
  import { Behaviour, GameObject } from "../../Component";
10
10
  import { WebXR } from "../../webxr/WebXR"
11
11
  import { serializable } from "../../../engine/engine_serialization";
12
- import { isDevEnvironment, showBalloonMessage, showBalloonWarning } from "../../../engine/debug/debug";
12
+ import { showBalloonMessage, showBalloonWarning } from "../../../engine/debug/debug";
13
13
  import { Context } from "../../../engine/engine_setup";
14
14
  import { WebARSessionRoot } from "../../webxr/WebARSessionRoot";
15
15
  import { hasProLicense } from "../../../engine/engine_license";
@@ -32,7 +32,7 @@ export class QuickLookOverlay {
32
32
  export class USDZExporter extends Behaviour {
33
33
 
34
34
  @serializable(Object3D)
35
- objectToExport?: THREE.Object3D;
35
+ objectToExport?: Object3D;
36
36
 
37
37
  @serializable()
38
38
  autoExportAnimations: boolean = false;
@@ -43,13 +43,20 @@ export class USDZExporter extends Behaviour {
43
43
  @serializable(QuickLookOverlay)
44
44
  overlay?: QuickLookOverlay;
45
45
 
46
- extensions: IUSDZExporterExtension[] = [];
46
+ // Currently not exposed to integrations - not fully tested. Set from code (e.g. image tracking)
47
+ @serializable()
48
+ anchoringType: "plane" | "image" | "face" | "none" = "plane";
49
+
50
+ // Currently not exposed to integrations - not fully tested. Set from code (e.g. image tracking)
51
+ @serializable()
52
+ planeAnchoringAlignment: "horizontal" | "vertical" | "any" = "horizontal";
53
+
54
+ extensions: IUSDExporterExtension[] = [];
47
55
 
48
56
  private link!: HTMLAnchorElement;
49
57
  private webxr?: WebXR;
50
58
  private webARSessionRoot: WebARSessionRoot | undefined;
51
59
 
52
-
53
60
  start() {
54
61
  if (debug) {
55
62
  console.log(this);
@@ -72,13 +79,11 @@ export class USDZExporter extends Behaviour {
72
79
  this.exportAsync();
73
80
  });
74
81
 
75
- if (!this.objectToExport) this.objectToExport = this.gameObject;
76
-
77
-
78
- if (isDevEnvironment() && (!this.objectToExport?.children?.length && !(this.objectToExport as Mesh)?.isMesh)) {
79
- showBalloonWarning("USDZ Exporter has nothing to export");
80
- console.warn("USDZExporter has no objects to export assigned:", this)
81
- }
82
+ // fall back to this object or to the scene if it's empty and doesn't have a mesh
83
+ if (!this.objectToExport)
84
+ this.objectToExport = this.gameObject;
85
+ if (!this.objectToExport?.children?.length && !(this.objectToExport as Mesh)?.isMesh)
86
+ this.objectToExport = this.context.scene;
82
87
  }
83
88
 
84
89
 
@@ -135,13 +140,30 @@ export class USDZExporter extends Behaviour {
135
140
  this.dispatchEvent(new CustomEvent("before-export", { detail: eventArgs }))
136
141
 
137
142
  let name = this.exportFileName ?? this.objectToExport?.name ?? this.name;
138
- if (debug) name += "-" + getFormattedDate();
139
- else if (!hasProLicense()) name = name + " - Made with Needle";
143
+ if (!hasProLicense()) name += "-MadeWithNeedle";
144
+ name += "-" + getFormattedDate(); // seems iOS caches the file in some cases, this ensures we always have a fresh file
140
145
 
141
146
  //@ts-ignore
142
147
  exporter.debug = debug;
148
+
149
+ // sanitize anchoring types
150
+ if (this.anchoringType !== "plane" && this.anchoringType !== "none" && this.anchoringType !== "image" && this.anchoringType !== "face")
151
+ this.anchoringType = "plane";
152
+ if (this.planeAnchoringAlignment !== "horizontal" && this.planeAnchoringAlignment !== "vertical" && this.planeAnchoringAlignment !== "any")
153
+ this.planeAnchoringAlignment = "horizontal";
154
+
143
155
  //@ts-ignore
144
- const arraybuffer = await exporter.parse(this.objectToExport, extensions);
156
+ const arraybuffer = await exporter.parse(this.objectToExport, {
157
+ ar: {
158
+ anchoring: {
159
+ type: this.anchoringType,
160
+ }
161
+ },
162
+ planeAnchoring: {
163
+ alignment: this.planeAnchoringAlignment,
164
+ },
165
+ extensions: extensions
166
+ });
145
167
  const blob = new Blob([arraybuffer], { type: 'application/octet-stream' });
146
168
 
147
169
  this.dispatchEvent(new CustomEvent("after-export", { detail: eventArgs }))
@@ -1,17 +1,18 @@
1
1
  import { GameObject } from "../../../Component";
2
2
  import { getParam } from "../../../../engine/engine_utils";
3
- import { Object3D, Color, Matrix4, MeshStandardMaterial, Vector3, Quaternion, Interpolant } from "three";
4
- //@ts-ignore
5
- import { USDZObject, buildMatrix } from "three/examples/jsm/exporters/USDZExporter"
6
- import { IUSDZExporterExtension } from "../Extension";
3
+
4
+ import { USDObject, buildMatrix } from "../ThreeUSDZExporter";
5
+ import { IUSDExporterExtension } from "../Extension";
6
+
7
+ import { Object3D, Matrix4, Vector3, Quaternion, Interpolant, AnimationClip, KeyframeTrack } from "three";
7
8
 
8
9
  const debug = getParam("debugusdzanimation");
9
10
 
10
11
  export interface UsdzAnimation {
11
- createAnimation(ext: AnimationExtension, model: USDZObject, context);
12
+ createAnimation(ext: AnimationExtension, model: USDObject, context);
12
13
  }
13
14
 
14
- export type AnimationClipCollection = Array<{ root: Object3D, clips: Array<THREE.AnimationClip> }>;
15
+ export type AnimationClipCollection = Array<{ root: Object3D, clips: Array<AnimationClip> }>;
15
16
 
16
17
  export class RegisteredAnimationInfo {
17
18
 
@@ -20,9 +21,9 @@ export class RegisteredAnimationInfo {
20
21
 
21
22
  private ext: AnimationExtension;
22
23
  private root: Object3D;
23
- private clip: THREE.AnimationClip;
24
+ private clip: AnimationClip;
24
25
 
25
- constructor(ext: AnimationExtension, root: THREE.Object3D, clip: THREE.AnimationClip) {
26
+ constructor(ext: AnimationExtension, root: Object3D, clip: AnimationClip) {
26
27
  this.ext = ext;
27
28
  this.root = root;
28
29
  this.clip = clip;
@@ -30,17 +31,17 @@ export class RegisteredAnimationInfo {
30
31
  }
31
32
 
32
33
  export class TransformData {
33
- clip: THREE.AnimationClip;
34
- pos?: THREE.KeyframeTrack;
35
- rot?: THREE.KeyframeTrack;
36
- scale?: THREE.KeyframeTrack;
34
+ clip: AnimationClip;
35
+ pos?: KeyframeTrack;
36
+ rot?: KeyframeTrack;
37
+ scale?: KeyframeTrack;
37
38
  get frameRate(): number { return 60; }
38
39
 
39
40
  private ext: AnimationExtension;
40
41
  private root: Object3D;
41
42
  private target: Object3D;
42
43
 
43
- constructor(ext: AnimationExtension, root: Object3D, target: Object3D, clip: THREE.AnimationClip) {
44
+ constructor(ext: AnimationExtension, root: Object3D, target: Object3D, clip: AnimationClip) {
44
45
  this.ext = ext;
45
46
  this.root = root;
46
47
  this.target = target;
@@ -78,14 +79,14 @@ export class TransformData {
78
79
 
79
80
  declare type AnimationDict = Map<Object3D, Array<TransformData>>;
80
81
 
81
- export class AnimationExtension implements IUSDZExporterExtension {
82
+ export class AnimationExtension implements IUSDExporterExtension {
82
83
 
83
84
  get extensionName(): string { return "animation" }
84
85
  private dict: AnimationDict = new Map();
85
86
  // private rootTargetMap: Map<Object3D, Object3D[]> = new Map();
86
87
  private rootTargetMap: Map<Object3D, Object3D[]> = new Map();
87
88
 
88
- getStartTime01(root: Object3D, clip: THREE.AnimationClip) {
89
+ getStartTime01(root: Object3D, clip: AnimationClip) {
89
90
  const targets = this.rootTargetMap.get(root);
90
91
  if (!targets) return Infinity;
91
92
  let longestStartTime: number = -1;
@@ -108,7 +109,7 @@ export class AnimationExtension implements IUSDZExporterExtension {
108
109
  return longestStartTime;
109
110
  }
110
111
 
111
- registerAnimation(root: Object3D, clip: THREE.AnimationClip): RegisteredAnimationInfo | null {
112
+ registerAnimation(root: Object3D, clip: AnimationClip): RegisteredAnimationInfo | null {
112
113
  if (!clip || !root) return null;
113
114
  if (!this.rootTargetMap.has(root)) this.rootTargetMap.set(root, []);
114
115
  // this.rootTargetMap.get(root)?.push(clip);
@@ -165,7 +166,7 @@ export class AnimationExtension implements IUSDZExporterExtension {
165
166
  }
166
167
  }
167
168
 
168
- onExportObject(object, model: USDZObject, _context) {
169
+ onExportObject(object, model: USDObject, _context) {
169
170
 
170
171
  GameObject.foreachComponent(object, (comp) => {
171
172
  const c = comp as unknown as UsdzAnimation;
@@ -187,7 +188,7 @@ class SerializeAnimation {
187
188
 
188
189
  object: Object3D;
189
190
  dict: AnimationDict;
190
- model: USDZObject;
191
+ model: USDObject | undefined = undefined;
191
192
 
192
193
  private callback?: Function;
193
194
 
@@ -196,7 +197,7 @@ class SerializeAnimation {
196
197
  this.dict = dict;
197
198
  }
198
199
 
199
- registerCallback(model: USDZObject) {
200
+ registerCallback(model: USDObject) {
200
201
  if (this.model && this.callback) {
201
202
  this.model.removeEventListener("serialize", this.callback);
202
203
  }
@@ -209,6 +210,7 @@ class SerializeAnimation {
209
210
  }
210
211
 
211
212
  onSerialize(writer, _context) {
213
+ if (!this.model) return;
212
214
  if (debug)
213
215
  console.log("SERIALIZE", this.model.name, this.object.type);
214
216
  // do we have a track for this?
@@ -228,22 +230,24 @@ class SerializeAnimation {
228
230
  const rotation = new Quaternion();
229
231
  const scale = new Vector3(1, 1, 1);
230
232
 
231
- // TODO doesn't support individual time arrays right now
232
- // could use these in case we don't have time values that are identical
233
- /*
234
- const translationInterpolant = o.pos?.createInterpolant() as THREE.Interpolant;
235
- const rotationInterpolant = o.rot?.createInterpolant() as THREE.Interpolant;
236
- const scaleInterpolant = o.scale?.createInterpolant() as THREE.Interpolant;
237
- */
238
-
239
233
  writer.appendLine("matrix4d xformOp:transform.timeSamples = {");
240
234
  writer.indent++;
241
235
 
242
236
  for (const transformData of arr) {
243
- let timesArray = transformData.pos?.times;
244
- if (!timesArray || transformData.rot && transformData.rot.times?.length > timesArray?.length) timesArray = transformData.rot?.times;
245
- if (!timesArray || transformData.scale && transformData.scale.times?.length > timesArray?.length) timesArray = transformData.scale?.times;
246
- if (!timesArray) {
237
+ let posTimesArray = transformData.pos?.times;
238
+ let rotTimesArray = transformData.rot?.times;
239
+ let scaleTimesArray = transformData.scale?.times;
240
+
241
+ // timesArray is the sorted union of all time values
242
+ let timesArray: number[] = [];
243
+ if (posTimesArray) for (const t of posTimesArray) timesArray.push(t);
244
+ if (rotTimesArray) for (const t of rotTimesArray) timesArray.push(t);
245
+ if (scaleTimesArray) for (const t of scaleTimesArray) timesArray.push(t);
246
+ // sort
247
+ timesArray.sort((a, b) => a - b);
248
+ timesArray = [...new Set(timesArray)];
249
+
250
+ if (!timesArray || timesArray.length === 0) {
247
251
  console.error("got an animated object but no time values??", object, transformData);
248
252
  continue;
249
253
  }
@@ -276,8 +280,8 @@ class SerializeAnimation {
276
280
  rotation.set(quat[0], quat[1], quat[2], quat[3]);
277
281
  }
278
282
  if (scaleInterpolant) {
279
- const scale = scaleInterpolant.evaluate(time);
280
- scale.set(scale[0], scale[1], scale[2]);
283
+ const scaleVal = scaleInterpolant.evaluate(time);
284
+ scale.set(scaleVal[0], scaleVal[1], scaleVal[2]);
281
285
  }
282
286
 
283
287
  composedTransform.compose(translation, rotation, scale);
@@ -290,17 +294,5 @@ class SerializeAnimation {
290
294
  }
291
295
  writer.indent--;
292
296
  writer.appendLine("}");
293
-
294
- /*
295
- let transform3 = new Matrix4();
296
- transform3.compose(0.2,0,0);
297
- const transform = buildMatrix(model.matrix);
298
- const transform2 = buildMatrix(transform3.multiply(model.matrix));
299
-
300
- writer.appendLine(`matrix4d xformOp:transform.timeSamples = {
301
- 0: ${transform},
302
- 30: ${transform2}
303
- }`);
304
- */
305
297
  }
306
298
  }
@@ -0,0 +1,10 @@
1
+ import { IUSDExporterExtension } from "../Extension";
2
+
3
+ export class DocumentExtension implements IUSDExporterExtension {
4
+
5
+ get extensionName(): string {
6
+ return "DocumentExtension";
7
+ }
8
+
9
+ onAfterBuildDocument(_context: any) { }
10
+ }
@@ -0,0 +1,142 @@
1
+ import { IBehaviorElement } from "../extensions/behavior/BehavioursBuilder";
2
+ import { USDDocument, USDWriter } from "../ThreeUSDZExporter";
3
+
4
+
5
+ export enum TextWrapMode {
6
+ singleLine = "singleLine",
7
+ hardBreaks = "hardBreaks",
8
+ flowing = "flowing",
9
+ }
10
+
11
+ export enum HorizontalAlignment {
12
+ left = "left",
13
+ center = "center",
14
+ right = "right",
15
+ justified = "justified"
16
+ }
17
+
18
+ export enum VerticalAlignment {
19
+ top = "top",
20
+ middle = "middle",
21
+ lowerMiddle = "lowerMiddle",
22
+ baseline = "baseline",
23
+ bottom = "bottom"
24
+ }
25
+
26
+ export class USDZText implements IBehaviorElement {
27
+
28
+ static global_id: number = 0;
29
+ static getId(): number {
30
+ return this.global_id++;
31
+ }
32
+
33
+ id: string;
34
+ content: string = "";
35
+ font?: string[] = [];
36
+ pointSize: number = 144;
37
+ width?: number;
38
+ height?: number;
39
+ depth?: number;
40
+ wrapMode?: TextWrapMode;
41
+ horizontalAlignment?: HorizontalAlignment;
42
+ verticalAlignment?: VerticalAlignment;
43
+
44
+ setDepth(depth: number): USDZText {
45
+ this.depth = depth;
46
+ return this;
47
+ }
48
+
49
+ setPointSize(pointSize: number): USDZText {
50
+ this.pointSize = pointSize;
51
+ return this;
52
+ }
53
+
54
+ setHorizontalAlignment(align: HorizontalAlignment) {
55
+ this.horizontalAlignment = align;
56
+ return this;
57
+ }
58
+
59
+ setVerticalAlignment(align: VerticalAlignment) {
60
+ this.verticalAlignment = align;
61
+ return this;
62
+ }
63
+
64
+ constructor(id: string) {
65
+ this.id = id;
66
+ }
67
+
68
+ writeTo(_document: USDDocument | undefined, writer: USDWriter) {
69
+
70
+
71
+ writer.beginBlock(`def Preliminary_Text "${this.id}"`);
72
+
73
+ if (this.content)
74
+ writer.appendLine(`string content = "${this.content}"`);
75
+
76
+ if (!this.font || this.font.length <= 0) {
77
+ this.font ||= [];
78
+ this.font?.push("sans-serif");
79
+ }
80
+ const str = this.font.map(s => `"${s}"`).join(", ");
81
+ writer.appendLine(`string[] font = [ ${str} ]`);
82
+
83
+ writer.appendLine(`double pointSize = ${this.pointSize}`);
84
+ if (typeof this.width === "number")
85
+ writer.appendLine(`double width = ${this.width}`);
86
+ if (typeof this.height === "number")
87
+ writer.appendLine(`double height = ${this.height}`);
88
+ if (typeof this.depth === "number")
89
+ writer.appendLine(`double depth = ${this.depth}`);
90
+ if (this.wrapMode)
91
+ writer.appendLine(`token wrapMode = "${this.wrapMode}"`);
92
+ if (this.horizontalAlignment)
93
+ writer.appendLine(`token horizontalAlignment = "${this.horizontalAlignment}"`);
94
+ if (this.verticalAlignment)
95
+ writer.appendLine(`token verticalAlignment = "${this.verticalAlignment}"`);
96
+
97
+ writer.closeBlock();
98
+
99
+ }
100
+
101
+ }
102
+
103
+
104
+ export class TextBuilder {
105
+ static singleLine(str: string, pointSize?: number, depth?: number): USDZText {
106
+
107
+ const text = new USDZText("text_" + USDZText.getId());
108
+ text.content = str;
109
+ if (pointSize)
110
+ text.pointSize = pointSize;
111
+ if (depth)
112
+ text.depth = depth;
113
+ return text;
114
+ }
115
+
116
+ static multiLine(str: string, width: number, height: number, horizontal: HorizontalAlignment, vertical: VerticalAlignment, wrapMode?: TextWrapMode) {
117
+ const text = new USDZText("text_" + USDZText.getId());
118
+ text.content = str;
119
+ text.width = width;
120
+ text.height = height;
121
+ text.horizontalAlignment = horizontal;
122
+ text.verticalAlignment = vertical;
123
+ if (wrapMode)
124
+ text.wrapMode = wrapMode;
125
+ return text;
126
+ }
127
+ }
128
+
129
+
130
+ export class TextExtension {
131
+ onExportObject(_object, model, _context) {
132
+ model.addEventListener("serialize", (writer, _context) => {
133
+ const text = TextBuilder.multiLine("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
134
+ 1, 1, HorizontalAlignment.justified, VerticalAlignment.top);
135
+ text.pointSize = 300;
136
+ text.depth = .01;
137
+ text.writeTo(undefined, writer);
138
+ });
139
+ }
140
+ }
141
+
142
+
@@ -0,0 +1,99 @@
1
+ import { Object3D, Matrix4, Material, BufferGeometry } from "three";
2
+ import { ActionBuilder, ActionModel } from "./BehavioursBuilder";
3
+ import { USDObject, USDDocument } from "../../ThreeUSDZExporter";
4
+
5
+ export abstract class DocumentAction {
6
+
7
+ get id(): string { return this.object.uuid; }
8
+
9
+ protected object: Object3D;
10
+ protected model?: USDObject;
11
+
12
+ constructor(obj: Object3D) {
13
+ this.object = obj;
14
+ }
15
+
16
+ apply(document: USDDocument) {
17
+ if (!this.model) {
18
+ this.model = document.findById(this.object.uuid);
19
+ if (!this.model) {
20
+ console.error("could not find model with id " + this.object.uuid);
21
+ return;
22
+ }
23
+ }
24
+ this.onApply(document);
25
+ }
26
+
27
+ protected abstract onApply(document: USDDocument);
28
+ }
29
+
30
+ export class VariantAction extends DocumentAction {
31
+ constructor(obj: Object3D, matrix?: Matrix4, material?: Material, geometry?: BufferGeometry) {
32
+ super(obj);
33
+ this.matrix = matrix;
34
+ this.material = material;
35
+ this.geometry = geometry;
36
+ }
37
+
38
+ private matrix: Matrix4 | undefined;
39
+ private material: Material | undefined;
40
+ private geometry: BufferGeometry | undefined;
41
+
42
+ protected onApply(_: USDDocument) {
43
+ const model = this.model;
44
+ if (!model) return;
45
+ if (!model.parent?.isDynamic) {
46
+ USDObject.createEmptyParent(model);
47
+ }
48
+ const clone = model.clone();
49
+ if (this.matrix) clone.matrix = this.matrix;
50
+ if (this.material) clone.material = this.material;
51
+ if (this.geometry) clone.geometry = this.geometry;
52
+ model.parent?.add(clone);
53
+ }
54
+
55
+ private _enableAction?: ActionModel;
56
+ private _disableAction?: ActionModel;
57
+
58
+ enable(): ActionModel {
59
+ if (this._enableAction) return this._enableAction;
60
+ this._enableAction = ActionBuilder.fadeAction(this.object, 0, true);;
61
+ return this._enableAction;
62
+ }
63
+
64
+ disable(): ActionModel {
65
+ if (this._disableAction) return this._disableAction;
66
+ this._disableAction = ActionBuilder.fadeAction(this.object, 0, false);;
67
+ return this._disableAction;
68
+ }
69
+ }
70
+
71
+ export class ActionCollection {
72
+
73
+ private actions: DocumentAction[];
74
+ private sortedActions?: { [key: string]: DocumentAction[] };
75
+
76
+ constructor(actions: DocumentAction[]) {
77
+ this.actions = [...actions]
78
+ }
79
+
80
+ // organize is called once when getting an action for the first time
81
+ // the sorted actions are baked then and adding new actions will not be added anymore
82
+ private organize() {
83
+ this.sortedActions = {};
84
+ for (const action of this.actions) {
85
+ const id = action.id;
86
+ if (!this.sortedActions[id]) {
87
+ this.sortedActions[id] = [];
88
+ }
89
+ this.sortedActions[id].push(action);
90
+ }
91
+ }
92
+
93
+ /** returns all document actions affecting the object passed in */
94
+ getActions(obj: Object3D): DocumentAction[] | null {
95
+ if (!this.sortedActions) this.organize();
96
+ return this.sortedActions![obj.uuid];
97
+ }
98
+
99
+ }