@needle-tools/engine 4.8.7 → 4.8.8-next.857d744
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 +14 -0
- package/components.needle.json +1 -1
- package/dist/{needle-engine.bundle-B0qaChJt.js → needle-engine.bundle-BATGweff.js} +6505 -6452
- package/dist/{needle-engine.bundle-CZBThBDy.min.js → needle-engine.bundle-C0MpXHGe.min.js} +137 -137
- package/dist/{needle-engine.bundle-lBmpWgFp.umd.cjs → needle-engine.bundle-gnU2UVys.umd.cjs} +138 -138
- package/dist/needle-engine.js +2 -2
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/engine_addressables.d.ts +12 -12
- package/lib/engine/engine_addressables.js +30 -23
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_animation.d.ts +1 -3
- package/lib/engine/engine_animation.js +15 -9
- package/lib/engine/engine_animation.js.map +1 -1
- package/lib/engine/engine_camera.d.ts +8 -1
- package/lib/engine/engine_camera.js +25 -0
- package/lib/engine/engine_camera.js.map +1 -1
- package/lib/engine/engine_context.d.ts +9 -0
- package/lib/engine/engine_context.js +15 -0
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_loaders.js +15 -11
- package/lib/engine/engine_loaders.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.attributes.d.ts +1 -0
- package/lib/engine/webcomponents/needle-engine.js +11 -6
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine-components/Animation.js +2 -1
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/AnimationUtilsAutoplay.js +1 -6
- package/lib/engine-components/AnimationUtilsAutoplay.js.map +1 -1
- package/lib/engine-components/DropListener.d.ts +17 -12
- package/lib/engine-components/DropListener.js +34 -31
- package/lib/engine-components/DropListener.js.map +1 -1
- package/lib/engine-components/LookAtConstraint.d.ts +5 -1
- package/lib/engine-components/LookAtConstraint.js +8 -0
- package/lib/engine-components/LookAtConstraint.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +5 -7
- package/lib/engine-components/OrbitControls.js +12 -11
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/export/usdz/Extension.d.ts +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
- package/lib/engine-components/export/usdz/USDZExporter.d.ts +7 -0
- package/lib/engine-components/export/usdz/USDZExporter.js +8 -1
- package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.d.ts +4 -2
- package/lib/engine-components/webxr/WebXRImageTracking.js +117 -81
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/package.json +3 -3
- package/plugins/vite/alias.js +45 -23
- package/src/engine/engine_addressables.ts +44 -33
- package/src/engine/engine_animation.ts +17 -9
- package/src/engine/engine_camera.ts +40 -1
- package/src/engine/engine_context.ts +21 -1
- package/src/engine/engine_loaders.ts +18 -13
- package/src/engine/webcomponents/needle-engine.attributes.ts +2 -0
- package/src/engine/webcomponents/needle-engine.ts +13 -6
- package/src/engine-components/Animation.ts +1 -1
- package/src/engine-components/AnimationUtilsAutoplay.ts +1 -6
- package/src/engine-components/DropListener.ts +40 -31
- package/src/engine-components/LookAtConstraint.ts +9 -1
- package/src/engine-components/OrbitControls.ts +19 -16
- package/src/engine-components/export/usdz/Extension.ts +1 -1
- package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +1 -1
- package/src/engine-components/export/usdz/USDZExporter.ts +21 -12
- package/src/engine-components/webxr/WebXRImageTracking.ts +138 -90
|
@@ -8,7 +8,7 @@ import { BlobStorage } from "./engine_networking_blob.js";
|
|
|
8
8
|
import { registerPrefabProvider, syncInstantiate, SyncInstantiateOptions } from "./engine_networking_instantiate.js";
|
|
9
9
|
import { SerializationContext, TypeSerializer } from "./engine_serialization_core.js";
|
|
10
10
|
import { Context } from "./engine_setup.js";
|
|
11
|
-
import type { GLTF, IComponent, IGameObject, SourceIdentifier } from "./engine_types.js";
|
|
11
|
+
import type { GLTF, IComponent, IGameObject, Model, SourceIdentifier } from "./engine_types.js";
|
|
12
12
|
|
|
13
13
|
const debug = getParam("debugaddressables");
|
|
14
14
|
|
|
@@ -138,21 +138,35 @@ export class AssetReference {
|
|
|
138
138
|
return ref;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
private static currentlyInstantiating: Map<string, number> = new Map<string, number>();
|
|
142
141
|
|
|
143
|
-
/** @returns true if this is an AssetReference instance */
|
|
144
|
-
get isAssetReference() { return true; }
|
|
145
142
|
|
|
146
|
-
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
readonly isAssetReference = true;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* This is the loaded asset root object. If the asset is a glb/gltf file this will be the {@link three#Scene} object.
|
|
150
|
+
*/
|
|
151
|
+
get rawAsset(): any { return this._rawAsset; }
|
|
152
|
+
|
|
153
|
+
/** The loaded asset root
|
|
154
|
+
*/
|
|
147
155
|
get asset(): Object3D | null {
|
|
148
|
-
return this._glbRoot ?? this.
|
|
156
|
+
return this._glbRoot ?? (this._rawAsset?.scene || null);
|
|
149
157
|
}
|
|
150
158
|
|
|
151
|
-
protected set asset(val:
|
|
152
|
-
|
|
159
|
+
protected set asset(val: Object3D | null) {
|
|
160
|
+
if (val) {
|
|
161
|
+
this._rawAsset = {
|
|
162
|
+
animations: val.animations,
|
|
163
|
+
scene: val,
|
|
164
|
+
scenes: [val],
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else this._rawAsset = null;
|
|
153
168
|
}
|
|
154
169
|
|
|
155
|
-
private _loading?: PromiseLike<any>;
|
|
156
170
|
|
|
157
171
|
/** The url of the loaded asset (or the asset to be loaded)
|
|
158
172
|
* @deprecated use url */
|
|
@@ -177,12 +191,7 @@ export class AssetReference {
|
|
|
177
191
|
(this._url.startsWith("http") || this._url.startsWith("blob:") || this._url.startsWith("www.") || this._url.includes("/"));
|
|
178
192
|
}
|
|
179
193
|
|
|
180
|
-
|
|
181
|
-
* This is the loaded asset root object. If the asset is a glb/gltf file this will be the {@link three#Scene} object.
|
|
182
|
-
*/
|
|
183
|
-
get rawAsset(): any { return this._asset; }
|
|
184
|
-
|
|
185
|
-
private _asset: any;
|
|
194
|
+
private _rawAsset: Model | null = null;
|
|
186
195
|
private _glbRoot?: Object3D | null;
|
|
187
196
|
private _url: string;
|
|
188
197
|
private _urlName: string;
|
|
@@ -207,7 +216,7 @@ export class AssetReference {
|
|
|
207
216
|
else {
|
|
208
217
|
this._urlName = uri;
|
|
209
218
|
}
|
|
210
|
-
|
|
219
|
+
|
|
211
220
|
if (asset !== null) this.asset = asset;
|
|
212
221
|
registerPrefabProvider(this._url, this.onResolvePrefab.bind(this));
|
|
213
222
|
}
|
|
@@ -226,6 +235,8 @@ export class AssetReference {
|
|
|
226
235
|
return !this.asset || (this.asset as any).__destroyed === true || isDestroyed(this.asset) === true;
|
|
227
236
|
}
|
|
228
237
|
|
|
238
|
+
private _loadingPromise: Promise<Model | null | undefined> | null = null;
|
|
239
|
+
|
|
229
240
|
/**
|
|
230
241
|
* @returns `true` if the asset has been loaded (via preload) or if it exists already (assigned to `asset`) */
|
|
231
242
|
isLoaded() { return this._rawBinary || this.asset !== undefined }
|
|
@@ -242,7 +253,7 @@ export class AssetReference {
|
|
|
242
253
|
this.asset = null;
|
|
243
254
|
this._rawBinary = undefined;
|
|
244
255
|
this._glbRoot = null;
|
|
245
|
-
this.
|
|
256
|
+
this._loadingPromise = null;
|
|
246
257
|
if (Context.Current) {
|
|
247
258
|
Context.Current.addressables.unregisterAssetReference(this);
|
|
248
259
|
}
|
|
@@ -267,16 +278,14 @@ export class AssetReference {
|
|
|
267
278
|
/** Loads the asset and creates one instance (assigned to `asset`)
|
|
268
279
|
* @returns the loaded asset
|
|
269
280
|
*/
|
|
270
|
-
async loadAssetAsync(prog?: ProgressCallback | null) {
|
|
271
|
-
if (debug)
|
|
272
|
-
console.log("loadAssetAsync", this.url);
|
|
281
|
+
async loadAssetAsync(prog?: ProgressCallback | null): Promise<Object3D | null> {
|
|
282
|
+
if (debug) console.log("[AssetReference] loadAssetAsync", this.url);
|
|
273
283
|
if (!this.mustLoad) return this.asset;
|
|
274
284
|
|
|
275
285
|
if (prog) this._progressListeners.push(prog);
|
|
276
|
-
|
|
277
|
-
if (this.
|
|
278
|
-
|
|
279
|
-
return this._loading.then(_ => this.asset);
|
|
286
|
+
|
|
287
|
+
if (this._loadingPromise !== null) {
|
|
288
|
+
return this._loadingPromise.then(_ => this.asset);
|
|
280
289
|
}
|
|
281
290
|
const context = Context.Current;
|
|
282
291
|
// TODO: technically we shouldnt call awake only when the object is added to a scene
|
|
@@ -285,31 +294,30 @@ export class AssetReference {
|
|
|
285
294
|
// console.log("START LOADING");
|
|
286
295
|
if (this._rawBinary) {
|
|
287
296
|
if (!(this._rawBinary instanceof ArrayBuffer)) {
|
|
288
|
-
console.error("Failed loading
|
|
297
|
+
console.error("[AssetReference] Failed loading – Invalid data. Must be of type ArrayBuffer. " + (typeof this._rawBinary));
|
|
289
298
|
return null;
|
|
290
299
|
}
|
|
291
|
-
this.
|
|
300
|
+
this._loadingPromise = getLoader().parseSync(context, this._rawBinary, this.url, null);
|
|
292
301
|
this.raiseProgressEvent(new ProgressEvent("progress", { loaded: this._rawBinary.byteLength, total: this._rawBinary.byteLength }));
|
|
293
302
|
}
|
|
294
303
|
else {
|
|
295
304
|
if (debug) console.log("Load async", this.url);
|
|
296
|
-
this.
|
|
305
|
+
this._loadingPromise = getLoader().loadSync(context, this.url, this.url, null, prog => {
|
|
297
306
|
this.raiseProgressEvent(prog);
|
|
298
307
|
});
|
|
299
308
|
}
|
|
300
|
-
|
|
309
|
+
this._loadingPromise.finally(() => this._loadingPromise = null);
|
|
310
|
+
const res = await this._loadingPromise;
|
|
301
311
|
// clear all progress listeners after download has finished
|
|
302
312
|
this._progressListeners.length = 0;
|
|
303
313
|
this._glbRoot = this.tryGetActualGameObjectRoot(res);
|
|
304
|
-
this._loading = undefined;
|
|
305
314
|
if (res) {
|
|
306
315
|
// Make sure the loaded roots all have a reference to this AssetReference
|
|
307
316
|
// that was originally loading it.
|
|
308
317
|
// We need this when the loaded asset is being disposed
|
|
309
318
|
// TODO: we have to prevent disposing resources that are still in use
|
|
310
319
|
res[$assetReference] = this;
|
|
311
|
-
if (this._glbRoot)
|
|
312
|
-
this._glbRoot[$assetReference] = this;
|
|
320
|
+
if (this._glbRoot) this._glbRoot[$assetReference] = this;
|
|
313
321
|
if (this.asset) this.asset[$assetReference] = this;
|
|
314
322
|
|
|
315
323
|
// we need to handle the pre_setup callsbacks before instantiating
|
|
@@ -317,7 +325,7 @@ export class AssetReference {
|
|
|
317
325
|
processNewScripts(context);
|
|
318
326
|
|
|
319
327
|
if (res.scene !== undefined) {
|
|
320
|
-
this.
|
|
328
|
+
this._rawAsset = res;
|
|
321
329
|
}
|
|
322
330
|
return this.asset;
|
|
323
331
|
}
|
|
@@ -352,6 +360,9 @@ export class AssetReference {
|
|
|
352
360
|
}
|
|
353
361
|
}
|
|
354
362
|
|
|
363
|
+
|
|
364
|
+
private static readonly currentlyInstantiating: Map<string, number> = new Map<string, number>();
|
|
365
|
+
|
|
355
366
|
private async onInstantiate(opts?: Object3D | IInstantiateOptions | SyncInstantiateOptions | null, networked: boolean = false, saveOnServer?: boolean): Promise<Object3D | null> {
|
|
356
367
|
const context = Context.Current;
|
|
357
368
|
|
|
@@ -544,7 +555,7 @@ export class ImageReference {
|
|
|
544
555
|
console.error("Can not load texture without url");
|
|
545
556
|
return failedTexturePromise;
|
|
546
557
|
}
|
|
547
|
-
|
|
558
|
+
|
|
548
559
|
if (!this.loader) this.loader = new TextureLoader();
|
|
549
560
|
this.loader.setCrossOrigin("anonymous");
|
|
550
561
|
return this.loader.loadAsync(this.url).then(res => {
|
|
@@ -2,6 +2,7 @@ import { AnimationAction, AnimationClip, AnimationMixer, Object3D, PropertyBindi
|
|
|
2
2
|
|
|
3
3
|
import type { Context } from "./engine_context.js";
|
|
4
4
|
import { GLTF, IAnimationComponent, Model } from "./engine_types.js";
|
|
5
|
+
import { TypeStore } from "./engine_typestore.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Registry for animation related data. Use {@link registerAnimationMixer} to register an animation mixer instance.
|
|
@@ -88,12 +89,15 @@ export class AnimationUtils {
|
|
|
88
89
|
* This method will look for objects in the scene that have animations and assign them to the correct objects.
|
|
89
90
|
* @param file The GLTF file to assign the animations from
|
|
90
91
|
*/
|
|
91
|
-
static
|
|
92
|
+
static autoplayAnimations(file: Object3D | Pick<Model, "animations" | "scene">): Array<IAnimationComponent> | null {
|
|
92
93
|
if (!file || !file.animations) {
|
|
93
94
|
console.debug("No animations found in file");
|
|
94
|
-
return;
|
|
95
|
+
return null;
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
const scene = "scene" in file ? file.scene : file as Object3D;
|
|
99
|
+
const animationComponents = new Array<IAnimationComponent>();
|
|
100
|
+
|
|
97
101
|
for (let i = 0; i < file.animations.length; i++) {
|
|
98
102
|
const animation = file.animations[i];
|
|
99
103
|
if (!animation.tracks || animation.tracks.length <= 0) {
|
|
@@ -103,12 +107,12 @@ export class AnimationUtils {
|
|
|
103
107
|
for (const t in animation.tracks) {
|
|
104
108
|
const track = animation.tracks[t];
|
|
105
109
|
const parsedPath = PropertyBinding.parseTrackName(track.name);
|
|
106
|
-
let obj = PropertyBinding.findNode(
|
|
110
|
+
let obj = PropertyBinding.findNode(scene, parsedPath.nodeName);
|
|
107
111
|
if (!obj) {
|
|
108
112
|
const objectName = track["__objectName"] ?? track.name.substring(0, track.name.indexOf("."));
|
|
109
113
|
// let obj = gltf.scene.getObjectByName(objectName);
|
|
110
114
|
// this finds unnamed objects that still have tracks targeting them
|
|
111
|
-
obj =
|
|
115
|
+
obj = scene.getObjectByProperty('uuid', objectName);
|
|
112
116
|
|
|
113
117
|
if (!obj) {
|
|
114
118
|
// console.warn("could not find " + objectName, animation, gltf.scene);
|
|
@@ -116,19 +120,23 @@ export class AnimationUtils {
|
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
122
|
|
|
119
|
-
let animationComponent = findAnimationGameObjectInParent(obj);
|
|
123
|
+
let animationComponent = findAnimationGameObjectInParent(obj) || findAnimationGameObjectInParent(scene);
|
|
120
124
|
if (!animationComponent) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
const anim = TypeStore.get("Animation");
|
|
126
|
+
animationComponent = scene.addComponent(anim);
|
|
127
|
+
if (!animationComponent) {
|
|
128
|
+
console.error("Failed creating Animation component: No 'Animation' component found in TypeStore");
|
|
129
|
+
break;
|
|
124
130
|
}
|
|
125
|
-
animationComponent = opts.createAnimationComponent(file.scene, animation)
|
|
126
131
|
}
|
|
132
|
+
animationComponents.push(animationComponent);
|
|
127
133
|
if (animationComponent.addClip) {
|
|
128
134
|
animationComponent.addClip(animation);
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
137
|
}
|
|
138
|
+
return animationComponents;
|
|
139
|
+
|
|
132
140
|
function findAnimationGameObjectInParent(obj): IAnimationComponent | null {
|
|
133
141
|
if (!obj) return null;
|
|
134
142
|
const components = obj.userData?.components;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Camera, Object3D } from "three";
|
|
1
|
+
import { Camera, HemisphereLightHelper, Object3D, PerspectiveCamera, Vector2, WebGLRenderer } from "three";
|
|
2
|
+
import { Mathf } from "./engine_math.js";
|
|
2
3
|
|
|
3
4
|
import type { ICameraController } from "./engine_types.js";
|
|
4
5
|
|
|
@@ -37,4 +38,42 @@ export function useForAutoFit(obj: Object3D): boolean {
|
|
|
37
38
|
*/
|
|
38
39
|
export function setAutoFitEnabled(obj: Object3D, enabled: boolean): void {
|
|
39
40
|
obj[autofit] = enabled;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
export type FocusRect = DOMRect | Element | { x: number, y: number, width: number, height: number };
|
|
47
|
+
|
|
48
|
+
let rendererRect: DOMRect | undefined = undefined;
|
|
49
|
+
let overlapRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
50
|
+
|
|
51
|
+
export function updateCameraFocusRect(focusRect: FocusRect, dt: number, camera: PerspectiveCamera, renderer: WebGLRenderer) {
|
|
52
|
+
|
|
53
|
+
if (focusRect instanceof Element) {
|
|
54
|
+
focusRect = focusRect.getBoundingClientRect();
|
|
55
|
+
}
|
|
56
|
+
rendererRect = renderer.domElement.getBoundingClientRect();
|
|
57
|
+
|
|
58
|
+
const rect = overlapRect;
|
|
59
|
+
rect.x = focusRect.x;
|
|
60
|
+
rect.y = focusRect.y;
|
|
61
|
+
rect.width = focusRect.width;
|
|
62
|
+
rect.height = focusRect.height;
|
|
63
|
+
|
|
64
|
+
rect.x -= rendererRect.x;
|
|
65
|
+
rect.y -= rendererRect.y;
|
|
66
|
+
|
|
67
|
+
let targetX = rect.width / -2 - (rect.x - (rendererRect.width / 2));
|
|
68
|
+
let targetY = rect.height / -2 - (rect.y - (rendererRect.height / 2));
|
|
69
|
+
|
|
70
|
+
const view = camera.view;
|
|
71
|
+
|
|
72
|
+
let offsetX = view?.offsetX || 0;
|
|
73
|
+
let offsetY = view?.offsetY || 0;
|
|
74
|
+
offsetX = Mathf.lerp(offsetX, targetX, dt);
|
|
75
|
+
offsetY = Mathf.lerp(offsetY, targetY, dt);
|
|
76
|
+
|
|
77
|
+
camera.setViewOffset(rendererRect.width, rendererRect.height, offsetX, offsetY, rendererRect.width, rendererRect.height);
|
|
78
|
+
camera.updateProjectionMatrix();
|
|
40
79
|
}
|
|
@@ -41,6 +41,7 @@ import { deepClone, delay, DeviceUtilities, getParam } from './engine_utils.js';
|
|
|
41
41
|
import type { INeedleXRSessionEventReceiver, NeedleXRSession } from './engine_xr.js';
|
|
42
42
|
import { NeedleMenu } from './webcomponents/needle menu/needle-menu.js';
|
|
43
43
|
import type { NeedleEngineWebComponent } from './webcomponents/needle-engine.js';
|
|
44
|
+
import { FocusRect, updateCameraFocusRect } from './engine_camera.js';
|
|
44
45
|
|
|
45
46
|
const debug = getParam("debugcontext");
|
|
46
47
|
const stats = getParam("stats");
|
|
@@ -1371,6 +1372,20 @@ export class Context implements IContext {
|
|
|
1371
1372
|
this.internalUpdatePhysics(steps);
|
|
1372
1373
|
}
|
|
1373
1374
|
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
/**
|
|
1378
|
+
* Set a rect or dom element. The camera center will be moved to the center of the rect.
|
|
1379
|
+
* This is useful if you have Needle Engine embedded in a HTML layout and while you want the webgl background to fill e.g. the whole screen you want to move the camera center to free space.
|
|
1380
|
+
* For that you can simply pass in the rect or HMTL div that you want the camera to center on.
|
|
1381
|
+
*/
|
|
1382
|
+
public setCameraFocusRect(rect: FocusRect | null) {
|
|
1383
|
+
this._focusRect = rect;
|
|
1384
|
+
}
|
|
1385
|
+
get focusRect() { return this._focusRect; }
|
|
1386
|
+
private _focusRect: FocusRect | null = null;
|
|
1387
|
+
|
|
1388
|
+
|
|
1374
1389
|
private _lastTimestamp = 0;
|
|
1375
1390
|
private _accumulatedTime = 0;
|
|
1376
1391
|
private _dispatchReadyAfterFrame = false;
|
|
@@ -1421,7 +1436,7 @@ export class Context implements IContext {
|
|
|
1421
1436
|
|
|
1422
1437
|
Context.Current = this;
|
|
1423
1438
|
this.time.update();
|
|
1424
|
-
|
|
1439
|
+
|
|
1425
1440
|
if (debugframerate) console.log("FPS", (this.time.smoothedFps).toFixed(0));
|
|
1426
1441
|
|
|
1427
1442
|
|
|
@@ -1498,6 +1513,11 @@ export class Context implements IContext {
|
|
|
1498
1513
|
|
|
1499
1514
|
if (this.isVisibleToUser || this.runInBackground) {
|
|
1500
1515
|
|
|
1516
|
+
if (this._focusRect) {
|
|
1517
|
+
if (this.mainCamera instanceof PerspectiveCamera)
|
|
1518
|
+
updateCameraFocusRect(this._focusRect, this.time.deltaTime / .05, this.mainCamera, this.renderer);
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1501
1521
|
this._currentFrameEvent = FrameEvent.OnBeforeRender;
|
|
1502
1522
|
|
|
1503
1523
|
// should we move these callbacks in the regular three onBeforeRender events?
|
|
@@ -61,7 +61,7 @@ export async function onCreateLoader(url: string, context: Context): Promise<Cus
|
|
|
61
61
|
switch (type) {
|
|
62
62
|
case "unsupported":
|
|
63
63
|
return null;
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
default:
|
|
66
66
|
case "unknown":
|
|
67
67
|
{
|
|
@@ -287,15 +287,6 @@ async function onAfterLoaded(loader: Loader | CustomLoader, context: Context, gl
|
|
|
287
287
|
gltfId = gltfId.split("?")[0];
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
// assign animations of loaded glTF to all scenes
|
|
291
|
-
if ("scenes" in model) {
|
|
292
|
-
for (const scene of model.scenes) {
|
|
293
|
-
if (scene && !scene.animations?.length) {
|
|
294
|
-
scene.animations = [...model.animations];
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
290
|
// E.g. fbx material cleanup
|
|
300
291
|
postprocessLoadedFile(loader, model);
|
|
301
292
|
|
|
@@ -357,13 +348,27 @@ function checkIfUserAttemptedToLoadALocalFile(url: string) {
|
|
|
357
348
|
/**
|
|
358
349
|
* Postprocess the loaded file. This is used to apply any custom postprocessing to the loaded file.
|
|
359
350
|
*/
|
|
360
|
-
function postprocessLoadedFile(loader: object,
|
|
351
|
+
function postprocessLoadedFile(loader: object, model: Model) {
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
// assign animations of loaded glTF to all scenes
|
|
355
|
+
if ("scenes" in model) {
|
|
356
|
+
for (const scene of model.scenes) {
|
|
357
|
+
if (scene && !scene.animations?.length) {
|
|
358
|
+
for (const anim of model.animations) {
|
|
359
|
+
if (!scene.animations.includes(anim)) {
|
|
360
|
+
scene.animations.push(anim);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
361
366
|
|
|
362
367
|
if (loader instanceof FBXLoader || loader instanceof OBJLoader) {
|
|
363
368
|
|
|
364
|
-
let obj: Object3D | Model =
|
|
369
|
+
let obj: Object3D | Model = model;
|
|
365
370
|
if (!(obj instanceof Object3D)) {
|
|
366
|
-
obj = (
|
|
371
|
+
obj = (model as GLTF).scene || model.scenes.find(s => s);
|
|
367
372
|
}
|
|
368
373
|
|
|
369
374
|
obj.traverse((child) => {
|
|
@@ -60,6 +60,8 @@ type SkyboxAttributes = {
|
|
|
60
60
|
"background-color"?: string,
|
|
61
61
|
/** URL to .exr, .hdr, .png, .jpg to be used for lighting */
|
|
62
62
|
"environment-image"?: string,
|
|
63
|
+
|
|
64
|
+
"environment-intensity"?: number,
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
export type TonemappingAttributeOptions = "none" | "linear" | "neutral" | "agx";
|
|
@@ -45,6 +45,7 @@ const observedAttributes = [
|
|
|
45
45
|
"tone-mapping-exposure",
|
|
46
46
|
"background-blurriness",
|
|
47
47
|
"background-color",
|
|
48
|
+
"environment-intensity",
|
|
48
49
|
]
|
|
49
50
|
|
|
50
51
|
// https://developers.google.com/web/fundamentals/web-components/customelements
|
|
@@ -325,6 +326,8 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
|
|
|
325
326
|
if (debug) console.log("ktx2DecoderPath", newValue);
|
|
326
327
|
setKtx2TranscoderPath(newValue);
|
|
327
328
|
break;
|
|
329
|
+
|
|
330
|
+
case "tonemapping":
|
|
328
331
|
case "tone-mapping": {
|
|
329
332
|
this.applyAttributes();
|
|
330
333
|
break;
|
|
@@ -334,13 +337,10 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
|
|
|
334
337
|
break;
|
|
335
338
|
}
|
|
336
339
|
case "background-blurriness": {
|
|
337
|
-
|
|
338
|
-
if (value != undefined && this._context) {
|
|
339
|
-
this._context.scene.backgroundBlurriness = value;
|
|
340
|
-
}
|
|
340
|
+
this.applyAttributes();
|
|
341
341
|
break;
|
|
342
342
|
}
|
|
343
|
-
case "
|
|
343
|
+
case "environment-intensity": {
|
|
344
344
|
this.applyAttributes();
|
|
345
345
|
break;
|
|
346
346
|
}
|
|
@@ -552,11 +552,18 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
|
|
|
552
552
|
const backgroundBlurriness = this.getAttribute("background-blurriness");
|
|
553
553
|
if (backgroundBlurriness !== null && backgroundBlurriness !== undefined) {
|
|
554
554
|
const value = parseFloat(backgroundBlurriness);
|
|
555
|
-
if (value
|
|
555
|
+
if (!isNaN(value) && this._context) {
|
|
556
556
|
this._context.scene.backgroundBlurriness = value;
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
559
|
|
|
560
|
+
const environmentIntensity = this.getAttribute("environment-intensity");
|
|
561
|
+
if (environmentIntensity != undefined && this._context) {
|
|
562
|
+
const value = parseFloat(environmentIntensity);
|
|
563
|
+
if (!isNaN(value) && this._context)
|
|
564
|
+
this._context.scene.environmentIntensity = value;
|
|
565
|
+
}
|
|
566
|
+
|
|
560
567
|
const backgroundColor = this.getAttribute("background-color");
|
|
561
568
|
if (this._context?.renderer) {
|
|
562
569
|
if (typeof backgroundColor === "string" && backgroundColor.length > 0) {
|
|
@@ -67,7 +67,7 @@ export class Animation extends Behaviour implements IAnimationComponent {
|
|
|
67
67
|
get isAnimationComponent(): boolean { return true; }
|
|
68
68
|
addClip(clip: AnimationClip) {
|
|
69
69
|
if (!this.animations) this.animations = [];
|
|
70
|
-
this.animations.push(clip);
|
|
70
|
+
if (!this.animations.includes(clip)) this.animations.push(clip);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { GLTF } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
2
2
|
|
|
3
3
|
import { AnimationUtils } from "../engine/engine_animation.js";
|
|
4
|
-
import { addComponent } from "../engine/engine_components.js";
|
|
5
4
|
import { ContextEvent, ContextRegistry } from "../engine/engine_context_registry.js";
|
|
6
5
|
import { Animation } from "./Animation.js";
|
|
7
6
|
import { Animator } from "./Animator.js";
|
|
@@ -29,11 +28,7 @@ ContextRegistry.registerCallback(ContextEvent.ContextCreated, args => {
|
|
|
29
28
|
return undefined;
|
|
30
29
|
}, true);
|
|
31
30
|
if (hasAnimation !== true) {
|
|
32
|
-
AnimationUtils.
|
|
33
|
-
createAnimationComponent: (obj, _clip) => {
|
|
34
|
-
return addComponent(obj, Animation);
|
|
35
|
-
},
|
|
36
|
-
});
|
|
31
|
+
AnimationUtils.autoplayAnimations(file.file as GLTF);
|
|
37
32
|
}
|
|
38
33
|
}
|
|
39
34
|
}
|
|
@@ -143,13 +143,6 @@ const blobKeyName = "blob";
|
|
|
143
143
|
*/
|
|
144
144
|
export class DropListener extends Behaviour {
|
|
145
145
|
|
|
146
|
-
/**
|
|
147
|
-
* When enabled, the DropListener will automatically synchronize dropped files to other connected clients.
|
|
148
|
-
* When a file is dropped locally, it will be uploaded to blob storage and the URL will be shared with other clients.
|
|
149
|
-
*/
|
|
150
|
-
@serializable()
|
|
151
|
-
useNetworking: boolean = true;
|
|
152
|
-
|
|
153
146
|
/**
|
|
154
147
|
* When assigned, the DropListener will only accept files that are dropped on this specific object.
|
|
155
148
|
* This allows creating designated drop zones in your scene.
|
|
@@ -159,7 +152,10 @@ export class DropListener extends Behaviour {
|
|
|
159
152
|
|
|
160
153
|
/**
|
|
161
154
|
* When enabled, dropped objects will be automatically scaled to fit within the volume defined by fitVolumeSize.
|
|
162
|
-
* Useful for ensuring dropped models appear at an appropriate scale.
|
|
155
|
+
* Useful for ensuring dropped models appear at an appropriate scale.
|
|
156
|
+
*
|
|
157
|
+
* **Tip**: Use the handy `fitObjectIntoVolume` function (`import { fitObjectIntoVolume } from "@needle-tools/engine"`) for custom fitting needs.
|
|
158
|
+
*
|
|
163
159
|
* @default false
|
|
164
160
|
*/
|
|
165
161
|
@serializable()
|
|
@@ -180,6 +176,14 @@ export class DropListener extends Behaviour {
|
|
|
180
176
|
@serializable()
|
|
181
177
|
placeAtHitPosition: boolean = true;
|
|
182
178
|
|
|
179
|
+
/**
|
|
180
|
+
* When enabled, the DropListener will automatically synchronize dropped files to other connected clients.
|
|
181
|
+
* When a file is dropped locally, it will be uploaded to blob storage and the URL will be shared with other clients.
|
|
182
|
+
* @default false
|
|
183
|
+
*/
|
|
184
|
+
@serializable()
|
|
185
|
+
useNetworking: boolean = false;
|
|
186
|
+
|
|
183
187
|
/**
|
|
184
188
|
* Event list that gets invoked after a file has been successfully added to the scene.
|
|
185
189
|
* Receives {@link DropListenerOnDropArguments} containing the added object and related information.
|
|
@@ -193,6 +197,27 @@ export class DropListener extends Behaviour {
|
|
|
193
197
|
@serializable(EventList)
|
|
194
198
|
onDropped: EventList<DropListenerOnDropArguments> = new EventList();
|
|
195
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Loads a file from the given URL and adds it to the scene.
|
|
202
|
+
* @returns A promise that resolves to the loaded object or null if loading failed.
|
|
203
|
+
*/
|
|
204
|
+
loadFromURL(url: string, data?: { point?: Vec3, size?: Vec3 }): Promise<Object3D | null> {
|
|
205
|
+
return this.addFromUrl(url, { screenposition: new Vector2(), point: data?.point, size: data?.size, }, false);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Forgets all previously added objects.
|
|
210
|
+
* The droplistener will then not be able to remove previously added objects.
|
|
211
|
+
*/
|
|
212
|
+
forgetObjects() {
|
|
213
|
+
this.removePreviouslyAddedObjects(false);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
// #region internals
|
|
220
|
+
|
|
196
221
|
/** @internal */
|
|
197
222
|
onEnable(): void {
|
|
198
223
|
this.context.renderer.domElement.addEventListener("dragover", this.onDrag);
|
|
@@ -208,21 +233,6 @@ export class DropListener extends Behaviour {
|
|
|
208
233
|
this.context.connection.stopListen("droplistener", this.onNetworkEvent);
|
|
209
234
|
}
|
|
210
235
|
|
|
211
|
-
/**
|
|
212
|
-
* Loads a file from the given URL and adds it to the scene.
|
|
213
|
-
*/
|
|
214
|
-
loadFromURL(url: string, data?: { point?: Vec3, size?: Vec3 }) {
|
|
215
|
-
this.addFromUrl(url, { screenposition: new Vector2(), point: data?.point, size: data?.size, }, true);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Forgets all previously added objects.
|
|
220
|
-
* The droplistener will then not be able to remove previously added objects.
|
|
221
|
-
*/
|
|
222
|
-
forgetObjects() {
|
|
223
|
-
this.removePreviouslyAddedObjects(false);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
236
|
/**
|
|
227
237
|
* Handles network events received from other clients containing information about dropped objects
|
|
228
238
|
* @param evt Network event data containing object information, position, and content URL
|
|
@@ -326,7 +336,7 @@ export class DropListener extends Behaviour {
|
|
|
326
336
|
}
|
|
327
337
|
}
|
|
328
338
|
if (files.length > 0) {
|
|
329
|
-
await this.
|
|
339
|
+
await this.addFromFiles(files, ctx);
|
|
330
340
|
}
|
|
331
341
|
}
|
|
332
342
|
|
|
@@ -359,6 +369,7 @@ export class DropListener extends Behaviour {
|
|
|
359
369
|
// Ignore dropped images
|
|
360
370
|
const lowercaseUrl = url.toLowerCase();
|
|
361
371
|
if (lowercaseUrl.endsWith(".hdr") || lowercaseUrl.endsWith(".hdri") || lowercaseUrl.endsWith(".exr") || lowercaseUrl.endsWith(".png") || lowercaseUrl.endsWith(".jpg") || lowercaseUrl.endsWith(".jpeg")) {
|
|
372
|
+
console.warn(`Fileformat is not supported: ${lowercaseUrl}`);
|
|
362
373
|
return null;
|
|
363
374
|
}
|
|
364
375
|
|
|
@@ -374,7 +385,7 @@ export class DropListener extends Behaviour {
|
|
|
374
385
|
});
|
|
375
386
|
if (res && this._addedObjects.length <= 0) {
|
|
376
387
|
ctx.url = url;
|
|
377
|
-
const obj = this.
|
|
388
|
+
const obj = this.onObjectLoaded(res, ctx, isRemote);
|
|
378
389
|
return obj;
|
|
379
390
|
}
|
|
380
391
|
}
|
|
@@ -393,7 +404,7 @@ export class DropListener extends Behaviour {
|
|
|
393
404
|
* @param fileList Array of dropped files
|
|
394
405
|
* @param ctx Context information about where the drop occurred
|
|
395
406
|
*/
|
|
396
|
-
private async
|
|
407
|
+
private async addFromFiles(fileList: Array<File>, ctx: DropContext) {
|
|
397
408
|
if (debug) console.log("Add files", fileList)
|
|
398
409
|
if (!Array.isArray(fileList)) return;
|
|
399
410
|
if (!fileList.length) return;
|
|
@@ -427,7 +438,7 @@ export class DropListener extends Behaviour {
|
|
|
427
438
|
if (res) {
|
|
428
439
|
this.dispatchEvent(new CustomEvent(DropListenerEvents.FileDropped, { detail: file }));
|
|
429
440
|
ctx.file = file;
|
|
430
|
-
const obj = this.
|
|
441
|
+
const obj = this.onObjectLoaded(res, ctx, false);
|
|
431
442
|
|
|
432
443
|
// handle uploading the dropped object and networking the event
|
|
433
444
|
if (obj && this.context.connection.isConnected && this.useNetworking) {
|
|
@@ -478,7 +489,7 @@ export class DropListener extends Behaviour {
|
|
|
478
489
|
* @param isRemote Whether this object was shared from a remote client
|
|
479
490
|
* @returns The added object or null if adding failed
|
|
480
491
|
*/
|
|
481
|
-
private
|
|
492
|
+
private onObjectLoaded(data: { model: Model, contentMD5: string }, ctx: DropContext, isRemote: boolean): Object3D | null {
|
|
482
493
|
|
|
483
494
|
const { model, contentMD5 } = data;
|
|
484
495
|
|
|
@@ -522,9 +533,7 @@ export class DropListener extends Behaviour {
|
|
|
522
533
|
}
|
|
523
534
|
}
|
|
524
535
|
|
|
525
|
-
AnimationUtils.
|
|
526
|
-
createAnimationComponent: obj => addComponent(obj, Animation)
|
|
527
|
-
});
|
|
536
|
+
AnimationUtils.autoplayAnimations(model);
|
|
528
537
|
|
|
529
538
|
const evt = new DropListenerAddedEvent({
|
|
530
539
|
sender: this,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Object3D } from "three";
|
|
1
|
+
import { Object3D, Vector3 } from "three";
|
|
2
2
|
|
|
3
3
|
import { serializable } from "../engine/engine_serialization_decorator.js";
|
|
4
4
|
import { Behaviour } from "./Component.js";
|
|
@@ -23,4 +23,12 @@ export class LookAtConstraint extends Behaviour {
|
|
|
23
23
|
*/
|
|
24
24
|
@serializable(Object3D)
|
|
25
25
|
sources: Object3D[] = [];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Set the position of the constraint.
|
|
29
|
+
*/
|
|
30
|
+
setConstraintPosition(worldPosition: Vector3) {
|
|
31
|
+
const source = this.sources[0];
|
|
32
|
+
if (source) source.worldPosition = worldPosition;
|
|
33
|
+
}
|
|
26
34
|
}
|