@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,15 +1,15 @@
|
|
|
1
1
|
import { delay, getParam, isiOS, isMobileDevice, isSafari } from "../../../engine/engine_utils";
|
|
2
|
-
import { Object3D,
|
|
3
|
-
import { USDZExporter as ThreeUSDZExporter } from "
|
|
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 {
|
|
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 {
|
|
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?:
|
|
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
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
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 (
|
|
139
|
-
|
|
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,
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
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:
|
|
12
|
+
createAnimation(ext: AnimationExtension, model: USDObject, context);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export type AnimationClipCollection = Array<{ root: Object3D, clips: Array<
|
|
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:
|
|
24
|
+
private clip: AnimationClip;
|
|
24
25
|
|
|
25
|
-
constructor(ext: AnimationExtension, root:
|
|
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:
|
|
34
|
-
pos?:
|
|
35
|
-
rot?:
|
|
36
|
-
scale?:
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
|
280
|
-
scale.set(
|
|
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,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
|
+
}
|