@webspatial/react-sdk 1.4.0 → 1.5.0
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/dist/default/index.d.ts +2 -1
- package/dist/default/index.js +344 -44
- package/dist/default/index.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.js +1 -1
- package/dist/jsx/jsx-dev-runtime.web.js +1 -1
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/jsx/jsx-runtime.web.js +1 -1
- package/dist/web/index.d.ts +2 -1
- package/dist/web/index.js +344 -44
- package/dist/web/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['react-sdk-version'] = "1.
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.5.0"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "avp"
|
|
7
7
|
})()
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['react-sdk-version'] = "1.
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.5.0"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "web"
|
|
7
7
|
})()
|
|
8
8
|
|
package/dist/jsx/jsx-runtime.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['react-sdk-version'] = "1.
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.5.0"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "avp"
|
|
7
7
|
})()
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['react-sdk-version'] = "1.
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.5.0"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "web"
|
|
7
7
|
})()
|
|
8
8
|
|
package/dist/web/index.d.ts
CHANGED
|
@@ -313,7 +313,8 @@ declare const ModelAsset: React__default.FC<Props>;
|
|
|
313
313
|
|
|
314
314
|
declare const ModelEntity: React__default.ForwardRefExoticComponent<EntityProps & {
|
|
315
315
|
model: string;
|
|
316
|
-
|
|
316
|
+
materials?: string[];
|
|
317
|
+
} & EntityEventHandler & {
|
|
317
318
|
children?: React__default.ReactNode;
|
|
318
319
|
} & React__default.RefAttributes<EntityRefShape>>;
|
|
319
320
|
|
package/dist/web/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['react-sdk-version'] = "1.
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.5.0"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "web"
|
|
7
7
|
})()
|
|
8
8
|
|
|
@@ -2404,6 +2404,20 @@ function shallowEqualRotation(a, b) {
|
|
|
2404
2404
|
if (!a || !b) return false;
|
|
2405
2405
|
return a.x === b.x && a.y === b.y && a.z === b.z && ("w" in a ? a.w === b.w : true);
|
|
2406
2406
|
}
|
|
2407
|
+
function shallowEqualObject(a, b) {
|
|
2408
|
+
if (a === b) return true;
|
|
2409
|
+
if (!a || !b) return false;
|
|
2410
|
+
const keysA = Object.keys(a);
|
|
2411
|
+
const keysB = Object.keys(b);
|
|
2412
|
+
if (keysA.length !== keysB.length) return false;
|
|
2413
|
+
return keysA.every((key) => a[key] === b[key]);
|
|
2414
|
+
}
|
|
2415
|
+
function shallowEqualArray(a, b) {
|
|
2416
|
+
if (a === b) return true;
|
|
2417
|
+
if (!a || !b) return false;
|
|
2418
|
+
if (a.length !== b.length) return false;
|
|
2419
|
+
return a.every((val, i) => val === b[i]);
|
|
2420
|
+
}
|
|
2407
2421
|
|
|
2408
2422
|
// src/reality/utils/AbortResourceManager.ts
|
|
2409
2423
|
var AbortResourceManager = class {
|
|
@@ -2548,9 +2562,150 @@ var EntityRef = class {
|
|
|
2548
2562
|
}
|
|
2549
2563
|
};
|
|
2550
2564
|
|
|
2565
|
+
// src/reality/hooks/useEntityEvent.tsx
|
|
2566
|
+
function createEventProxy2(ev, instance) {
|
|
2567
|
+
return new Proxy(ev, {
|
|
2568
|
+
get(target, prop) {
|
|
2569
|
+
if (prop === "currentTarget") {
|
|
2570
|
+
return instance;
|
|
2571
|
+
}
|
|
2572
|
+
if (prop === "target") {
|
|
2573
|
+
const origin = target.__origin;
|
|
2574
|
+
if (origin) {
|
|
2575
|
+
return new EntityRef(origin, null);
|
|
2576
|
+
}
|
|
2577
|
+
return instance;
|
|
2578
|
+
}
|
|
2579
|
+
if (prop === "bubbles") {
|
|
2580
|
+
return true;
|
|
2581
|
+
}
|
|
2582
|
+
if (prop === "offsetX") {
|
|
2583
|
+
const type = target.type;
|
|
2584
|
+
if (type === "spatialtap") {
|
|
2585
|
+
return target.detail?.location3D?.x ?? 0;
|
|
2586
|
+
}
|
|
2587
|
+
if (type === "spatialdragstart") {
|
|
2588
|
+
return target.detail?.startLocation3D?.x ?? 0;
|
|
2589
|
+
}
|
|
2590
|
+
return void 0;
|
|
2591
|
+
}
|
|
2592
|
+
if (prop === "offsetY") {
|
|
2593
|
+
const type = target.type;
|
|
2594
|
+
if (type === "spatialtap") {
|
|
2595
|
+
return target.detail?.location3D?.y ?? 0;
|
|
2596
|
+
}
|
|
2597
|
+
if (type === "spatialdragstart") {
|
|
2598
|
+
return target.detail?.startLocation3D?.y ?? 0;
|
|
2599
|
+
}
|
|
2600
|
+
return void 0;
|
|
2601
|
+
}
|
|
2602
|
+
if (prop === "offsetZ") {
|
|
2603
|
+
const type = target.type;
|
|
2604
|
+
if (type === "spatialtap") {
|
|
2605
|
+
return target.detail?.location3D?.z ?? 0;
|
|
2606
|
+
}
|
|
2607
|
+
if (type === "spatialdragstart") {
|
|
2608
|
+
return target.detail?.startLocation3D?.z ?? 0;
|
|
2609
|
+
}
|
|
2610
|
+
return void 0;
|
|
2611
|
+
}
|
|
2612
|
+
if (prop === "translationX") {
|
|
2613
|
+
const type = target.type;
|
|
2614
|
+
if (type === "spatialdrag") {
|
|
2615
|
+
return target.detail?.translation3D?.x ?? 0;
|
|
2616
|
+
}
|
|
2617
|
+
return void 0;
|
|
2618
|
+
}
|
|
2619
|
+
if (prop === "translationY") {
|
|
2620
|
+
const type = target.type;
|
|
2621
|
+
if (type === "spatialdrag") {
|
|
2622
|
+
return target.detail?.translation3D?.y ?? 0;
|
|
2623
|
+
}
|
|
2624
|
+
return void 0;
|
|
2625
|
+
}
|
|
2626
|
+
if (prop === "translationZ") {
|
|
2627
|
+
const type = target.type;
|
|
2628
|
+
if (type === "spatialdrag") {
|
|
2629
|
+
return target.detail?.translation3D?.z ?? 0;
|
|
2630
|
+
}
|
|
2631
|
+
return void 0;
|
|
2632
|
+
}
|
|
2633
|
+
if (prop === "quaternion") {
|
|
2634
|
+
const type = target.type;
|
|
2635
|
+
if (type === "spatialrotate") {
|
|
2636
|
+
return target.detail?.quaternion ?? {
|
|
2637
|
+
x: 0,
|
|
2638
|
+
y: 0,
|
|
2639
|
+
z: 0,
|
|
2640
|
+
w: 1
|
|
2641
|
+
};
|
|
2642
|
+
}
|
|
2643
|
+
return void 0;
|
|
2644
|
+
}
|
|
2645
|
+
if (prop === "magnification") {
|
|
2646
|
+
const type = target.type;
|
|
2647
|
+
if (type === "spatialmagnify") {
|
|
2648
|
+
return target.detail?.magnification ?? 1;
|
|
2649
|
+
}
|
|
2650
|
+
return void 0;
|
|
2651
|
+
}
|
|
2652
|
+
if (prop === "clientX") {
|
|
2653
|
+
const type = target.type;
|
|
2654
|
+
if (type === "spatialtap" || type === "spatialdragstart") {
|
|
2655
|
+
return target.detail?.globalLocation3D?.x ?? 0;
|
|
2656
|
+
}
|
|
2657
|
+
return void 0;
|
|
2658
|
+
}
|
|
2659
|
+
if (prop === "clientY") {
|
|
2660
|
+
const type = target.type;
|
|
2661
|
+
if (type === "spatialtap" || type === "spatialdragstart") {
|
|
2662
|
+
return target.detail?.globalLocation3D?.y ?? 0;
|
|
2663
|
+
}
|
|
2664
|
+
return void 0;
|
|
2665
|
+
}
|
|
2666
|
+
if (prop === "clientZ") {
|
|
2667
|
+
const type = target.type;
|
|
2668
|
+
if (type === "spatialtap" || type === "spatialdragstart") {
|
|
2669
|
+
return target.detail?.globalLocation3D?.z ?? 0;
|
|
2670
|
+
}
|
|
2671
|
+
return void 0;
|
|
2672
|
+
}
|
|
2673
|
+
const val = target[prop];
|
|
2674
|
+
return typeof val === "function" ? val.bind(target) : val;
|
|
2675
|
+
}
|
|
2676
|
+
});
|
|
2677
|
+
}
|
|
2678
|
+
var useEntityEvent = ({ instance, ...handlers }) => {
|
|
2679
|
+
const eventsSetRef = useRef9(/* @__PURE__ */ new Set());
|
|
2680
|
+
useEffect18(() => {
|
|
2681
|
+
const entity = instance.entity;
|
|
2682
|
+
if (!entity) return;
|
|
2683
|
+
Object.entries(eventMap).forEach(([reactKey, spatialEvent]) => {
|
|
2684
|
+
const handlerFn = handlers[reactKey];
|
|
2685
|
+
if (!handlerFn) return;
|
|
2686
|
+
const wrapped = (ev) => handlerFn(createEventProxy2(ev, instance));
|
|
2687
|
+
entity.addEvent(spatialEvent, wrapped);
|
|
2688
|
+
eventsSetRef.current.add(reactKey);
|
|
2689
|
+
});
|
|
2690
|
+
return () => {
|
|
2691
|
+
};
|
|
2692
|
+
}, [instance.entity, ...Object.values(handlers)]);
|
|
2693
|
+
useEffect18(() => {
|
|
2694
|
+
const entity = instance.entity;
|
|
2695
|
+
if (!entity) return;
|
|
2696
|
+
return () => {
|
|
2697
|
+
for (let x of eventsSetRef.current) {
|
|
2698
|
+
entity.removeEvent(x);
|
|
2699
|
+
}
|
|
2700
|
+
eventsSetRef.current.clear();
|
|
2701
|
+
};
|
|
2702
|
+
}, [instance.entity]);
|
|
2703
|
+
return null;
|
|
2704
|
+
};
|
|
2705
|
+
|
|
2551
2706
|
// src/reality/hooks/useRealityEvents.tsx
|
|
2552
2707
|
import { useEffect as useEffect19, useRef as useRef10 } from "react";
|
|
2553
|
-
function
|
|
2708
|
+
function createEventProxy3(ev, instance) {
|
|
2554
2709
|
return new Proxy(ev, {
|
|
2555
2710
|
get(target, prop) {
|
|
2556
2711
|
if (prop === "currentTarget") {
|
|
@@ -2669,7 +2824,7 @@ var useRealityEvents = ({ instance, ...handlers }) => {
|
|
|
2669
2824
|
Object.entries(eventMap).forEach(([reactKey, spatialEvent]) => {
|
|
2670
2825
|
const handlerFn = handlers[reactKey];
|
|
2671
2826
|
if (!handlerFn) return;
|
|
2672
|
-
const wrapped = (ev) => handlerFn(
|
|
2827
|
+
const wrapped = (ev) => handlerFn(createEventProxy3(ev, instance));
|
|
2673
2828
|
instance.addEvent(spatialEvent, wrapped);
|
|
2674
2829
|
eventsSetRef.current.add(spatialEvent);
|
|
2675
2830
|
});
|
|
@@ -2707,7 +2862,16 @@ var useEntity = ({
|
|
|
2707
2862
|
rotation,
|
|
2708
2863
|
scale,
|
|
2709
2864
|
enableInput,
|
|
2710
|
-
|
|
2865
|
+
onSpatialTap,
|
|
2866
|
+
onSpatialDragStart,
|
|
2867
|
+
onSpatialDrag,
|
|
2868
|
+
onSpatialDragEnd,
|
|
2869
|
+
onSpatialRotate,
|
|
2870
|
+
onSpatialRotateEnd,
|
|
2871
|
+
onSpatialMagnify,
|
|
2872
|
+
onSpatialMagnifyEnd,
|
|
2873
|
+
createEntity,
|
|
2874
|
+
recreateKey
|
|
2711
2875
|
}) => {
|
|
2712
2876
|
const ctx = useRealityContext();
|
|
2713
2877
|
const parent = useParentContext();
|
|
@@ -2724,6 +2888,11 @@ var useEntity = ({
|
|
|
2724
2888
|
ent.destroy();
|
|
2725
2889
|
return;
|
|
2726
2890
|
}
|
|
2891
|
+
await ent.updateTransform({ position, rotation, scale });
|
|
2892
|
+
if (controller.signal.aborted) {
|
|
2893
|
+
ent.destroy();
|
|
2894
|
+
return;
|
|
2895
|
+
}
|
|
2727
2896
|
if (parent) {
|
|
2728
2897
|
const result = await parent.addEntity(ent);
|
|
2729
2898
|
if (!result.success) throw new Error("parent.addEntity failed");
|
|
@@ -2742,10 +2911,21 @@ var useEntity = ({
|
|
|
2742
2911
|
controller.abort();
|
|
2743
2912
|
instanceRef.current?.destroy();
|
|
2744
2913
|
};
|
|
2745
|
-
}, [ctx, parent]);
|
|
2914
|
+
}, [ctx, parent, recreateKey]);
|
|
2746
2915
|
useEntityId({ id, entity: instanceRef.current.entity });
|
|
2747
2916
|
useEntityTransform(instanceRef.current.entity, { position, rotation, scale });
|
|
2748
2917
|
useEntityRef(ref, instanceRef.current);
|
|
2918
|
+
useEntityEvent({
|
|
2919
|
+
instance: instanceRef.current,
|
|
2920
|
+
onSpatialTap,
|
|
2921
|
+
onSpatialDragStart,
|
|
2922
|
+
onSpatialDrag,
|
|
2923
|
+
onSpatialDragEnd,
|
|
2924
|
+
onSpatialRotate,
|
|
2925
|
+
onSpatialRotateEnd,
|
|
2926
|
+
onSpatialMagnify,
|
|
2927
|
+
onSpatialMagnifyEnd
|
|
2928
|
+
});
|
|
2749
2929
|
useEffect21(() => {
|
|
2750
2930
|
const ent = instanceRef.current.entity;
|
|
2751
2931
|
if (!ent) return;
|
|
@@ -2757,20 +2937,21 @@ var useEntity = ({
|
|
|
2757
2937
|
};
|
|
2758
2938
|
|
|
2759
2939
|
// src/reality/hooks/useForceUpdate.tsx
|
|
2760
|
-
import { useCallback as useCallback7, useState as
|
|
2940
|
+
import { useCallback as useCallback7, useState as useState6 } from "react";
|
|
2761
2941
|
var useForceUpdate2 = () => {
|
|
2762
|
-
const [, setTick] =
|
|
2942
|
+
const [, setTick] = useState6(0);
|
|
2763
2943
|
return useCallback7(() => setTick((tick) => tick + 1), []);
|
|
2764
2944
|
};
|
|
2765
2945
|
|
|
2766
2946
|
// src/reality/components/BaseEntity.tsx
|
|
2767
2947
|
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
2768
2948
|
var BaseEntity = forwardRef10(
|
|
2769
|
-
({ children, createEntity, ...rest }, ref) => {
|
|
2949
|
+
({ children, createEntity, recreateKey, ...rest }, ref) => {
|
|
2770
2950
|
const ctx = useRealityContext();
|
|
2771
2951
|
const entity = useEntity({
|
|
2772
2952
|
...rest,
|
|
2773
2953
|
ref,
|
|
2954
|
+
recreateKey,
|
|
2774
2955
|
createEntity: (signal) => createEntity(ctx, signal)
|
|
2775
2956
|
});
|
|
2776
2957
|
if (!entity) return null;
|
|
@@ -2798,35 +2979,102 @@ var Entity = forwardRef11((props, ref) => {
|
|
|
2798
2979
|
import { forwardRef as forwardRef13 } from "react";
|
|
2799
2980
|
|
|
2800
2981
|
// src/reality/components/GeometryEntity.tsx
|
|
2801
|
-
import { forwardRef as forwardRef12 } from "react";
|
|
2982
|
+
import { forwardRef as forwardRef12, useEffect as useEffect22, useRef as useRef12 } from "react";
|
|
2802
2983
|
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
2803
2984
|
var GeometryEntity = forwardRef12(
|
|
2804
2985
|
({ id, children, name, materials, geometryOptions, createGeometry, ...rest }, ref) => {
|
|
2986
|
+
const ctx = useRealityContext();
|
|
2987
|
+
const entityRef = useRef12(null);
|
|
2988
|
+
const componentRef = useRef12(null);
|
|
2989
|
+
const mutableRef = useRef12({
|
|
2990
|
+
lastSnapshot: null,
|
|
2991
|
+
rebuildGen: 0
|
|
2992
|
+
});
|
|
2993
|
+
useEffect22(() => {
|
|
2994
|
+
const { lastSnapshot } = mutableRef.current;
|
|
2995
|
+
if (!ctx || !entityRef.current || lastSnapshot === null) return;
|
|
2996
|
+
const geometryChanged = !shallowEqualObject(
|
|
2997
|
+
lastSnapshot.geometryOptions,
|
|
2998
|
+
geometryOptions
|
|
2999
|
+
);
|
|
3000
|
+
const materialsChanged = !shallowEqualArray(
|
|
3001
|
+
lastSnapshot.materials,
|
|
3002
|
+
materials
|
|
3003
|
+
);
|
|
3004
|
+
if (!geometryChanged && !materialsChanged) return;
|
|
3005
|
+
mutableRef.current.lastSnapshot = { geometryOptions, materials };
|
|
3006
|
+
mutableRef.current.rebuildGen += 1;
|
|
3007
|
+
const gen = mutableRef.current.rebuildGen;
|
|
3008
|
+
const rebuild = async () => {
|
|
3009
|
+
const entity = entityRef.current;
|
|
3010
|
+
if (!entity) return;
|
|
3011
|
+
try {
|
|
3012
|
+
const oldComponent = componentRef.current;
|
|
3013
|
+
if (oldComponent) {
|
|
3014
|
+
await entity.removeComponent(oldComponent);
|
|
3015
|
+
await oldComponent.destroy();
|
|
3016
|
+
componentRef.current = null;
|
|
3017
|
+
if (gen !== mutableRef.current.rebuildGen) return;
|
|
3018
|
+
}
|
|
3019
|
+
const geometry = await createGeometry(geometryOptions);
|
|
3020
|
+
if (gen !== mutableRef.current.rebuildGen) {
|
|
3021
|
+
await geometry.destroy();
|
|
3022
|
+
return;
|
|
3023
|
+
}
|
|
3024
|
+
const materialList = await Promise.all(
|
|
3025
|
+
materials?.map((mid) => ctx.resourceRegistry.get(mid)).filter(Boolean) ?? []
|
|
3026
|
+
);
|
|
3027
|
+
if (gen !== mutableRef.current.rebuildGen) {
|
|
3028
|
+
await geometry.destroy();
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3031
|
+
const modelComponent = await ctx.session.createModelComponent({
|
|
3032
|
+
mesh: geometry,
|
|
3033
|
+
materials: materialList
|
|
3034
|
+
});
|
|
3035
|
+
if (gen !== mutableRef.current.rebuildGen) {
|
|
3036
|
+
await modelComponent.destroy();
|
|
3037
|
+
await geometry.destroy();
|
|
3038
|
+
return;
|
|
3039
|
+
}
|
|
3040
|
+
await entity.addComponent(modelComponent);
|
|
3041
|
+
componentRef.current = modelComponent;
|
|
3042
|
+
} catch (error) {
|
|
3043
|
+
if (gen === mutableRef.current.rebuildGen) {
|
|
3044
|
+
console.error("GeometryEntity: rebuild failed", error);
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
rebuild();
|
|
3049
|
+
}, [ctx, geometryOptions, materials, createGeometry]);
|
|
2805
3050
|
return /* @__PURE__ */ jsx14(
|
|
2806
3051
|
BaseEntity,
|
|
2807
3052
|
{
|
|
2808
3053
|
...rest,
|
|
2809
3054
|
id,
|
|
2810
3055
|
ref,
|
|
2811
|
-
createEntity: async (
|
|
3056
|
+
createEntity: async (ctx2, signal) => {
|
|
2812
3057
|
const manager = new AbortResourceManager(signal);
|
|
2813
3058
|
try {
|
|
2814
3059
|
const ent = await manager.addResource(
|
|
2815
|
-
() =>
|
|
3060
|
+
() => ctx2.session.createEntity({ id, name })
|
|
2816
3061
|
);
|
|
2817
3062
|
const geometry = await manager.addResource(
|
|
2818
3063
|
() => createGeometry(geometryOptions)
|
|
2819
3064
|
);
|
|
2820
3065
|
const materialList = await Promise.all(
|
|
2821
|
-
materials?.map((id2) =>
|
|
3066
|
+
materials?.map((id2) => ctx2.resourceRegistry.get(id2)).filter(Boolean) ?? []
|
|
2822
3067
|
);
|
|
2823
3068
|
const modelComponent = await manager.addResource(
|
|
2824
|
-
() =>
|
|
3069
|
+
() => ctx2.session.createModelComponent({
|
|
2825
3070
|
mesh: geometry,
|
|
2826
3071
|
materials: materialList
|
|
2827
3072
|
})
|
|
2828
3073
|
);
|
|
2829
3074
|
await ent.addComponent(modelComponent);
|
|
3075
|
+
entityRef.current = ent;
|
|
3076
|
+
componentRef.current = modelComponent;
|
|
3077
|
+
mutableRef.current.lastSnapshot = { geometryOptions, materials };
|
|
2830
3078
|
return ent;
|
|
2831
3079
|
} catch (error) {
|
|
2832
3080
|
await manager.dispose();
|
|
@@ -2864,14 +3112,15 @@ var BoxEntity = forwardRef13(
|
|
|
2864
3112
|
);
|
|
2865
3113
|
|
|
2866
3114
|
// src/reality/components/UnlitMaterial.tsx
|
|
2867
|
-
import { useEffect as
|
|
3115
|
+
import { useEffect as useEffect23, useRef as useRef13 } from "react";
|
|
2868
3116
|
var UnlitMaterial = ({
|
|
2869
3117
|
children,
|
|
2870
3118
|
...options
|
|
2871
3119
|
}) => {
|
|
2872
3120
|
const ctx = useRealityContext();
|
|
2873
|
-
const materialRef =
|
|
2874
|
-
|
|
3121
|
+
const materialRef = useRef13();
|
|
3122
|
+
const isInitializedRef = useRef13(false);
|
|
3123
|
+
useEffect23(() => {
|
|
2875
3124
|
if (!ctx) return;
|
|
2876
3125
|
const { session, reality, resourceRegistry } = ctx;
|
|
2877
3126
|
const init = async () => {
|
|
@@ -2880,6 +3129,7 @@ var UnlitMaterial = ({
|
|
|
2880
3129
|
try {
|
|
2881
3130
|
const mat = await materialPromise;
|
|
2882
3131
|
materialRef.current = mat;
|
|
3132
|
+
isInitializedRef.current = true;
|
|
2883
3133
|
} catch (error) {
|
|
2884
3134
|
console.error(" ~ UnlitMaterial ~ error:", error);
|
|
2885
3135
|
}
|
|
@@ -2887,8 +3137,21 @@ var UnlitMaterial = ({
|
|
|
2887
3137
|
init();
|
|
2888
3138
|
return () => {
|
|
2889
3139
|
resourceRegistry.removeAndDestroy(options.id);
|
|
3140
|
+
materialRef.current = void 0;
|
|
3141
|
+
isInitializedRef.current = false;
|
|
2890
3142
|
};
|
|
2891
3143
|
}, [ctx]);
|
|
3144
|
+
useEffect23(() => {
|
|
3145
|
+
if (!isInitializedRef.current || !materialRef.current) return;
|
|
3146
|
+
const updates = {};
|
|
3147
|
+
if (options.color !== void 0) updates.color = options.color;
|
|
3148
|
+
if (options.transparent !== void 0)
|
|
3149
|
+
updates.transparent = options.transparent;
|
|
3150
|
+
if (options.opacity !== void 0) updates.opacity = options.opacity;
|
|
3151
|
+
if (Object.keys(updates).length > 0) {
|
|
3152
|
+
materialRef.current.updateProperties(updates);
|
|
3153
|
+
}
|
|
3154
|
+
}, [options.color, options.transparent, options.opacity]);
|
|
2892
3155
|
return null;
|
|
2893
3156
|
};
|
|
2894
3157
|
|
|
@@ -2987,7 +3250,7 @@ var SceneGraph = ({ children }) => {
|
|
|
2987
3250
|
};
|
|
2988
3251
|
|
|
2989
3252
|
// src/reality/components/ModelAsset.tsx
|
|
2990
|
-
import { useEffect as
|
|
3253
|
+
import { useEffect as useEffect24, useRef as useRef14 } from "react";
|
|
2991
3254
|
var resolveAssetUrl = (url) => {
|
|
2992
3255
|
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
2993
3256
|
return url;
|
|
@@ -2996,8 +3259,8 @@ var resolveAssetUrl = (url) => {
|
|
|
2996
3259
|
};
|
|
2997
3260
|
var ModelAsset = ({ children, ...options }) => {
|
|
2998
3261
|
const ctx = useRealityContext();
|
|
2999
|
-
const materialRef =
|
|
3000
|
-
|
|
3262
|
+
const materialRef = useRef14();
|
|
3263
|
+
useEffect24(() => {
|
|
3001
3264
|
const controller = new AbortController();
|
|
3002
3265
|
if (!ctx) return;
|
|
3003
3266
|
const { session, reality, resourceRegistry } = ctx;
|
|
@@ -3027,29 +3290,66 @@ var ModelAsset = ({ children, ...options }) => {
|
|
|
3027
3290
|
};
|
|
3028
3291
|
|
|
3029
3292
|
// src/reality/components/ModelEntity.tsx
|
|
3030
|
-
import { forwardRef as forwardRef18 } from "react";
|
|
3293
|
+
import { forwardRef as forwardRef18, useEffect as useEffect25, useRef as useRef15 } from "react";
|
|
3031
3294
|
import { jsx as jsx21 } from "react/jsx-runtime";
|
|
3032
3295
|
var ModelEntity = forwardRef18(
|
|
3033
|
-
({ id, model, children, name, ...rest }, ref) => {
|
|
3296
|
+
({ id, model, children, name, materials, ...rest }, ref) => {
|
|
3297
|
+
const ctx = useRealityContext();
|
|
3298
|
+
const entityRef = useRef15(null);
|
|
3299
|
+
const lastMaterialsRef = useRef15(void 0);
|
|
3300
|
+
useEffect25(() => {
|
|
3301
|
+
if (!ctx || !entityRef.current) return;
|
|
3302
|
+
const next = materials ?? [];
|
|
3303
|
+
const prev = lastMaterialsRef.current ?? [];
|
|
3304
|
+
if (shallowEqualArray(prev, next)) return;
|
|
3305
|
+
lastMaterialsRef.current = next;
|
|
3306
|
+
const apply = async () => {
|
|
3307
|
+
try {
|
|
3308
|
+
const materialList = (await Promise.all(
|
|
3309
|
+
next.map((mid) => ctx.resourceRegistry.get(mid))
|
|
3310
|
+
)).filter(Boolean);
|
|
3311
|
+
if (entityRef.current) {
|
|
3312
|
+
await entityRef.current.setMaterials(materialList);
|
|
3313
|
+
}
|
|
3314
|
+
} catch (error) {
|
|
3315
|
+
console.error("ModelEntity: failed to set materials", error);
|
|
3316
|
+
}
|
|
3317
|
+
};
|
|
3318
|
+
apply();
|
|
3319
|
+
}, [ctx, materials]);
|
|
3034
3320
|
return /* @__PURE__ */ jsx21(
|
|
3035
3321
|
BaseEntity,
|
|
3036
3322
|
{
|
|
3037
3323
|
...rest,
|
|
3038
3324
|
id,
|
|
3039
3325
|
ref,
|
|
3040
|
-
|
|
3326
|
+
recreateKey: model,
|
|
3327
|
+
createEntity: async (ctx2, signal) => {
|
|
3041
3328
|
try {
|
|
3042
|
-
const modelAsset = await
|
|
3329
|
+
const modelAsset = await ctx2.resourceRegistry.get(model);
|
|
3043
3330
|
if (!modelAsset)
|
|
3044
3331
|
throw new Error(`ModelEntity: model not found ${model}`);
|
|
3045
3332
|
if (signal.aborted) return null;
|
|
3046
|
-
|
|
3333
|
+
const ent = await ctx2.session.createSpatialModelEntity(
|
|
3047
3334
|
{
|
|
3048
3335
|
modelAssetId: modelAsset.id,
|
|
3049
3336
|
name
|
|
3050
3337
|
},
|
|
3051
3338
|
{ id, name }
|
|
3052
3339
|
);
|
|
3340
|
+
entityRef.current = ent;
|
|
3341
|
+
if (materials && materials.length > 0) {
|
|
3342
|
+
const materialList = (await Promise.all(
|
|
3343
|
+
materials.map(
|
|
3344
|
+
(mid) => ctx2.resourceRegistry.get(mid)
|
|
3345
|
+
)
|
|
3346
|
+
)).filter(Boolean);
|
|
3347
|
+
if (materialList.length > 0 && !signal.aborted) {
|
|
3348
|
+
await ent.setMaterials(materialList);
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
lastMaterialsRef.current = materials ?? [];
|
|
3352
|
+
return ent;
|
|
3053
3353
|
} catch (error) {
|
|
3054
3354
|
return null;
|
|
3055
3355
|
}
|
|
@@ -3064,9 +3364,9 @@ var ModelEntity = forwardRef18(
|
|
|
3064
3364
|
import {
|
|
3065
3365
|
forwardRef as forwardRef19,
|
|
3066
3366
|
useCallback as useCallback8,
|
|
3067
|
-
useEffect as
|
|
3068
|
-
useRef as
|
|
3069
|
-
useState as
|
|
3367
|
+
useEffect as useEffect26,
|
|
3368
|
+
useRef as useRef16,
|
|
3369
|
+
useState as useState7
|
|
3070
3370
|
} from "react";
|
|
3071
3371
|
import { Fragment as Fragment3, jsx as jsx22, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
3072
3372
|
var Reality = forwardRef19(
|
|
@@ -3089,9 +3389,9 @@ var Reality = forwardRef19(
|
|
|
3089
3389
|
onSpatialMagnifyEnd,
|
|
3090
3390
|
...props
|
|
3091
3391
|
} = inProps;
|
|
3092
|
-
const ctxRef =
|
|
3093
|
-
const creationId =
|
|
3094
|
-
const [isReady, setIsReady] =
|
|
3392
|
+
const ctxRef = useRef16(null);
|
|
3393
|
+
const creationId = useRef16(0);
|
|
3394
|
+
const [isReady, setIsReady] = useState7(false);
|
|
3095
3395
|
const cleanupReality = useCallback8(() => {
|
|
3096
3396
|
ctxRef.current?.attachmentRegistry.destroy();
|
|
3097
3397
|
ctxRef.current?.resourceRegistry.destroy();
|
|
@@ -3099,7 +3399,7 @@ var Reality = forwardRef19(
|
|
|
3099
3399
|
ctxRef.current = null;
|
|
3100
3400
|
setIsReady(false);
|
|
3101
3401
|
}, []);
|
|
3102
|
-
|
|
3402
|
+
useEffect26(() => {
|
|
3103
3403
|
return () => {
|
|
3104
3404
|
creationId.current++;
|
|
3105
3405
|
cleanupReality();
|
|
@@ -3177,7 +3477,7 @@ var Reality = forwardRef19(
|
|
|
3177
3477
|
);
|
|
3178
3478
|
|
|
3179
3479
|
// src/reality/components/AttachmentAsset.tsx
|
|
3180
|
-
import { useEffect as
|
|
3480
|
+
import { useEffect as useEffect27, useState as useState8 } from "react";
|
|
3181
3481
|
import { createPortal as createPortal3 } from "react-dom";
|
|
3182
3482
|
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
3183
3483
|
var AttachmentAsset = ({
|
|
@@ -3185,8 +3485,8 @@ var AttachmentAsset = ({
|
|
|
3185
3485
|
children
|
|
3186
3486
|
}) => {
|
|
3187
3487
|
const ctx = useRealityContext();
|
|
3188
|
-
const [containers, setContainers] =
|
|
3189
|
-
|
|
3488
|
+
const [containers, setContainers] = useState8([]);
|
|
3489
|
+
useEffect27(() => {
|
|
3190
3490
|
if (!ctx) return;
|
|
3191
3491
|
return ctx.attachmentRegistry.onContainersChange(name, setContainers);
|
|
3192
3492
|
}, [ctx, name]);
|
|
@@ -3197,7 +3497,7 @@ var AttachmentAsset = ({
|
|
|
3197
3497
|
};
|
|
3198
3498
|
|
|
3199
3499
|
// src/reality/components/AttachmentEntity.tsx
|
|
3200
|
-
import { useEffect as
|
|
3500
|
+
import { useEffect as useEffect28, useRef as useRef17, useState as useState9 } from "react";
|
|
3201
3501
|
var instanceCounter = 0;
|
|
3202
3502
|
var AttachmentEntity = ({
|
|
3203
3503
|
attachment: attachmentName,
|
|
@@ -3206,12 +3506,12 @@ var AttachmentEntity = ({
|
|
|
3206
3506
|
}) => {
|
|
3207
3507
|
const ctx = useRealityContext();
|
|
3208
3508
|
const parent = useParentContext();
|
|
3209
|
-
const attachmentRef =
|
|
3210
|
-
const parentIdRef =
|
|
3211
|
-
const instanceIdRef =
|
|
3212
|
-
const attachmentNameRef =
|
|
3213
|
-
const [childWindow, setChildWindow] =
|
|
3214
|
-
|
|
3509
|
+
const attachmentRef = useRef17(null);
|
|
3510
|
+
const parentIdRef = useRef17(null);
|
|
3511
|
+
const instanceIdRef = useRef17(`att_${++instanceCounter}`);
|
|
3512
|
+
const attachmentNameRef = useRef17(attachmentName);
|
|
3513
|
+
const [childWindow, setChildWindow] = useState9(null);
|
|
3514
|
+
useEffect28(() => {
|
|
3215
3515
|
if (!ctx || !parent) return;
|
|
3216
3516
|
if (attachmentRef.current) return;
|
|
3217
3517
|
const parentId = parent.id;
|
|
@@ -3273,7 +3573,7 @@ var AttachmentEntity = ({
|
|
|
3273
3573
|
}
|
|
3274
3574
|
};
|
|
3275
3575
|
}, [ctx, parent]);
|
|
3276
|
-
|
|
3576
|
+
useEffect28(() => {
|
|
3277
3577
|
if (!ctx) return;
|
|
3278
3578
|
const att = attachmentRef.current;
|
|
3279
3579
|
const prevName = attachmentNameRef.current;
|
|
@@ -3290,7 +3590,7 @@ var AttachmentEntity = ({
|
|
|
3290
3590
|
}
|
|
3291
3591
|
}, [ctx, attachmentName]);
|
|
3292
3592
|
useSyncHeadStyles(childWindow, { subtree: false });
|
|
3293
|
-
|
|
3593
|
+
useEffect28(() => {
|
|
3294
3594
|
if (!attachmentRef.current) return;
|
|
3295
3595
|
attachmentRef.current.update({ position, size });
|
|
3296
3596
|
}, [position?.[0], position?.[1], position?.[2], size?.width, size?.height]);
|
|
@@ -3424,7 +3724,7 @@ async function convertCoordinate(position, { from, to }) {
|
|
|
3424
3724
|
}
|
|
3425
3725
|
|
|
3426
3726
|
// src/index.ts
|
|
3427
|
-
var version = "1.
|
|
3727
|
+
var version = "1.5.0";
|
|
3428
3728
|
if (typeof window !== "undefined") {
|
|
3429
3729
|
initPolyfill();
|
|
3430
3730
|
}
|