@webspatial/react-sdk 1.1.0 → 1.2.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 +41 -24
- package/dist/default/index.js +255 -234
- package/dist/default/index.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.d.ts +1 -3
- 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 +41 -24
- package/dist/web/index.js +255 -234
- package/dist/web/index.js.map +1 -1
- package/package.json +2 -2
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.2.0"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "web"
|
|
7
7
|
})()
|
|
8
8
|
|
|
@@ -300,7 +300,7 @@ var SpatialContainerRefProxy = class {
|
|
|
300
300
|
}
|
|
301
301
|
const extraProps = cacheExtraRefProps;
|
|
302
302
|
if (extraProps.hasOwnProperty(prop)) {
|
|
303
|
-
return extraProps[prop]
|
|
303
|
+
return extraProps[prop];
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
const value = Reflect.get(target, prop);
|
|
@@ -335,6 +335,12 @@ var SpatialContainerRefProxy = class {
|
|
|
335
335
|
self.transformVisibilityTaskContainerDom.className = value;
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
|
+
if (typeof prop === "string" && self.extraRefProps) {
|
|
339
|
+
if (!cacheExtraRefProps) {
|
|
340
|
+
cacheExtraRefProps = self.extraRefProps(domProxy);
|
|
341
|
+
}
|
|
342
|
+
cacheExtraRefProps[prop] = value;
|
|
343
|
+
}
|
|
338
344
|
return Reflect.set(target, prop, value);
|
|
339
345
|
}
|
|
340
346
|
}
|
|
@@ -680,7 +686,7 @@ var StandardSpatializedContainer = forwardRef(
|
|
|
680
686
|
function injectSpatialDefaultStyle() {
|
|
681
687
|
const styleElement = document.createElement("style");
|
|
682
688
|
styleElement.type = "text/css";
|
|
683
|
-
styleElement.innerHTML = " .xr-spatial-default { --xr-back: 0; --xr-depth: 0; --xr-z-index: 0; --xr-background-material: none; } ";
|
|
689
|
+
styleElement.innerHTML = " :where(.xr-spatial-default) { --xr-back: 0; --xr-depth: 0; --xr-z-index: 0; --xr-background-material: none; } ";
|
|
684
690
|
document.head.appendChild(styleElement);
|
|
685
691
|
}
|
|
686
692
|
|
|
@@ -1262,10 +1268,8 @@ function PortalSpatializedContainer(props) {
|
|
|
1262
1268
|
onSpatialDragStart,
|
|
1263
1269
|
onSpatialDrag,
|
|
1264
1270
|
onSpatialDragEnd,
|
|
1265
|
-
onSpatialRotateStart,
|
|
1266
1271
|
onSpatialRotate,
|
|
1267
1272
|
onSpatialRotateEnd,
|
|
1268
|
-
onSpatialMagnifyStart,
|
|
1269
1273
|
onSpatialMagnify,
|
|
1270
1274
|
onSpatialMagnifyEnd,
|
|
1271
1275
|
[SpatialID]: spatialId,
|
|
@@ -1339,16 +1343,6 @@ function PortalSpatializedContainer(props) {
|
|
|
1339
1343
|
spatializedElement.onSpatialDragStart = onSpatialDragStart;
|
|
1340
1344
|
}
|
|
1341
1345
|
}, [spatializedElement, onSpatialDragStart]);
|
|
1342
|
-
useEffect7(() => {
|
|
1343
|
-
if (spatializedElement) {
|
|
1344
|
-
spatializedElement.onSpatialRotateStart = onSpatialRotateStart;
|
|
1345
|
-
}
|
|
1346
|
-
}, [spatializedElement, onSpatialRotateStart]);
|
|
1347
|
-
useEffect7(() => {
|
|
1348
|
-
if (spatializedElement) {
|
|
1349
|
-
spatializedElement.onSpatialMagnifyStart = onSpatialMagnifyStart;
|
|
1350
|
-
}
|
|
1351
|
-
}, [spatializedElement, onSpatialMagnifyStart]);
|
|
1352
1346
|
return /* @__PURE__ */ jsxs(PortalInstanceContext.Provider, { value: portalInstanceObject, children: [
|
|
1353
1347
|
spatializedElement && portalInstanceObject.dom && /* @__PURE__ */ jsx3(Content, { spatializedElement, ...restProps }),
|
|
1354
1348
|
PlaceholderEl
|
|
@@ -1356,7 +1350,7 @@ function PortalSpatializedContainer(props) {
|
|
|
1356
1350
|
}
|
|
1357
1351
|
|
|
1358
1352
|
// src/spatialized-container/hooks/useSpatialEvents.ts
|
|
1359
|
-
function createEventProxy(event, currentTargetGetter) {
|
|
1353
|
+
function createEventProxy(event, currentTargetGetter, offsetXGetter, offsetYGetter, offsetZGetter) {
|
|
1360
1354
|
return new Proxy(event, {
|
|
1361
1355
|
get(target, prop) {
|
|
1362
1356
|
if (prop === "currentTarget") {
|
|
@@ -1365,20 +1359,41 @@ function createEventProxy(event, currentTargetGetter) {
|
|
|
1365
1359
|
if (prop === "isTrusted") {
|
|
1366
1360
|
return true;
|
|
1367
1361
|
}
|
|
1362
|
+
if (prop === "bubbles") {
|
|
1363
|
+
return false;
|
|
1364
|
+
}
|
|
1365
|
+
if (prop === "offsetX" && offsetXGetter) {
|
|
1366
|
+
return offsetXGetter(target) ?? 0;
|
|
1367
|
+
}
|
|
1368
|
+
if (prop === "offsetY" && offsetYGetter) {
|
|
1369
|
+
return offsetYGetter(target) ?? 0;
|
|
1370
|
+
}
|
|
1371
|
+
if (prop === "offsetZ" && offsetZGetter) {
|
|
1372
|
+
return offsetZGetter(target) ?? 0;
|
|
1373
|
+
}
|
|
1368
1374
|
return Reflect.get(target, prop);
|
|
1369
1375
|
}
|
|
1370
1376
|
});
|
|
1371
1377
|
}
|
|
1372
|
-
function createEventHandler(handler, currentTargetGetter) {
|
|
1378
|
+
function createEventHandler(handler, currentTargetGetter, offsetXGetter, offsetYGetter, offsetZGetter) {
|
|
1373
1379
|
return handler ? (event) => {
|
|
1374
|
-
const proxyEvent = createEventProxy(
|
|
1380
|
+
const proxyEvent = createEventProxy(
|
|
1381
|
+
event,
|
|
1382
|
+
currentTargetGetter,
|
|
1383
|
+
offsetXGetter,
|
|
1384
|
+
offsetYGetter,
|
|
1385
|
+
offsetZGetter
|
|
1386
|
+
);
|
|
1375
1387
|
handler(proxyEvent);
|
|
1376
1388
|
} : void 0;
|
|
1377
1389
|
}
|
|
1378
1390
|
function useSpatialEventsBase(spatialEvents, currentTargetGetter) {
|
|
1379
1391
|
const onSpatialTap = createEventHandler(
|
|
1380
1392
|
spatialEvents.onSpatialTap,
|
|
1381
|
-
currentTargetGetter
|
|
1393
|
+
currentTargetGetter,
|
|
1394
|
+
(ev) => ev.detail?.location3D?.x,
|
|
1395
|
+
(ev) => ev.detail?.location3D?.y,
|
|
1396
|
+
(ev) => ev.detail?.location3D?.z
|
|
1382
1397
|
);
|
|
1383
1398
|
const onSpatialDrag = createEventHandler(
|
|
1384
1399
|
spatialEvents.onSpatialDrag,
|
|
@@ -1406,19 +1421,18 @@ function useSpatialEventsBase(spatialEvents, currentTargetGetter) {
|
|
|
1406
1421
|
);
|
|
1407
1422
|
const onSpatialDragStart = createEventHandler(
|
|
1408
1423
|
spatialEvents.onSpatialDragStart,
|
|
1409
|
-
currentTargetGetter
|
|
1424
|
+
currentTargetGetter,
|
|
1425
|
+
(ev) => ev.detail?.startLocation3D?.x,
|
|
1426
|
+
(ev) => ev.detail?.startLocation3D?.y,
|
|
1427
|
+
(ev) => ev.detail?.startLocation3D?.z
|
|
1410
1428
|
);
|
|
1411
|
-
const onSpatialRotateStart = createEventHandler(spatialEvents.onSpatialRotateStart, currentTargetGetter);
|
|
1412
|
-
const onSpatialMagnifyStart = createEventHandler(spatialEvents.onSpatialMagnifyStart, currentTargetGetter);
|
|
1413
1429
|
return {
|
|
1414
1430
|
onSpatialTap,
|
|
1415
1431
|
onSpatialDragStart,
|
|
1416
1432
|
onSpatialDrag,
|
|
1417
1433
|
onSpatialDragEnd,
|
|
1418
|
-
onSpatialRotateStart,
|
|
1419
1434
|
onSpatialRotate,
|
|
1420
1435
|
onSpatialRotateEnd,
|
|
1421
|
-
onSpatialMagnifyStart,
|
|
1422
1436
|
onSpatialMagnify,
|
|
1423
1437
|
onSpatialMagnifyEnd
|
|
1424
1438
|
};
|
|
@@ -1509,10 +1523,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1509
1523
|
onSpatialDragStart: onSpatialDragStart2,
|
|
1510
1524
|
onSpatialDrag: onSpatialDrag2,
|
|
1511
1525
|
onSpatialDragEnd: onSpatialDragEnd2,
|
|
1512
|
-
onSpatialRotateStart: onSpatialRotateStart2,
|
|
1513
1526
|
onSpatialRotate: onSpatialRotate2,
|
|
1514
1527
|
onSpatialRotateEnd: onSpatialRotateEnd2,
|
|
1515
|
-
onSpatialMagnifyStart: onSpatialMagnifyStart2,
|
|
1516
1528
|
onSpatialMagnify: onSpatialMagnify2,
|
|
1517
1529
|
onSpatialMagnifyEnd: onSpatialMagnifyEnd2,
|
|
1518
1530
|
extraRefProps: extraRefProps2,
|
|
@@ -1539,10 +1551,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1539
1551
|
onSpatialDragStart,
|
|
1540
1552
|
onSpatialDrag,
|
|
1541
1553
|
onSpatialDragEnd,
|
|
1542
|
-
onSpatialRotateStart,
|
|
1543
1554
|
onSpatialRotate,
|
|
1544
1555
|
onSpatialRotateEnd,
|
|
1545
|
-
onSpatialMagnifyStart,
|
|
1546
1556
|
onSpatialMagnify,
|
|
1547
1557
|
onSpatialMagnifyEnd,
|
|
1548
1558
|
extraRefProps,
|
|
@@ -1556,10 +1566,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1556
1566
|
onSpatialDragStart,
|
|
1557
1567
|
onSpatialDrag,
|
|
1558
1568
|
onSpatialDragEnd,
|
|
1559
|
-
onSpatialRotateStart,
|
|
1560
1569
|
onSpatialRotate,
|
|
1561
1570
|
onSpatialRotateEnd,
|
|
1562
|
-
onSpatialMagnifyStart,
|
|
1563
1571
|
onSpatialMagnify,
|
|
1564
1572
|
onSpatialMagnifyEnd
|
|
1565
1573
|
},
|
|
@@ -1625,10 +1633,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1625
1633
|
onSpatialDragStart,
|
|
1626
1634
|
onSpatialDrag,
|
|
1627
1635
|
onSpatialDragEnd,
|
|
1628
|
-
onSpatialRotateStart,
|
|
1629
1636
|
onSpatialRotate,
|
|
1630
1637
|
onSpatialRotateEnd,
|
|
1631
|
-
onSpatialMagnifyStart,
|
|
1632
1638
|
onSpatialMagnify,
|
|
1633
1639
|
onSpatialMagnifyEnd
|
|
1634
1640
|
},
|
|
@@ -1857,10 +1863,11 @@ function getAbsoluteURL(url) {
|
|
|
1857
1863
|
if (!url) {
|
|
1858
1864
|
return "";
|
|
1859
1865
|
}
|
|
1860
|
-
|
|
1866
|
+
try {
|
|
1867
|
+
return new URL(url, document.baseURI).toString();
|
|
1868
|
+
} catch {
|
|
1861
1869
|
return url;
|
|
1862
1870
|
}
|
|
1863
|
-
return window.location.origin + url;
|
|
1864
1871
|
}
|
|
1865
1872
|
function createLoadEvent(type, targetGetter) {
|
|
1866
1873
|
const event = new CustomEvent(type, {
|
|
@@ -1929,37 +1936,12 @@ async function createSpatializedElement2() {
|
|
|
1929
1936
|
function SpatializedStatic3DElementContainerBase(props, ref) {
|
|
1930
1937
|
const extraRefProps = useCallback6(
|
|
1931
1938
|
(domProxy) => {
|
|
1932
|
-
|
|
1933
|
-
let needupdate = false;
|
|
1934
|
-
const triggerUpdate = () => {
|
|
1935
|
-
const spatializedElement = domProxy.__spatializedElement;
|
|
1936
|
-
spatializedElement.updateModelTransform(modelTransform);
|
|
1937
|
-
needupdate = false;
|
|
1938
|
-
};
|
|
1939
|
-
const domMatrixProxy = new Proxy(modelTransform, {
|
|
1940
|
-
get(target, prop, receiver) {
|
|
1941
|
-
const value = Reflect.get(target, prop, receiver);
|
|
1942
|
-
if (typeof value === "function") {
|
|
1943
|
-
return function(...args) {
|
|
1944
|
-
requestAnimationFrame(triggerUpdate);
|
|
1945
|
-
return value.apply(target, args);
|
|
1946
|
-
};
|
|
1947
|
-
} else {
|
|
1948
|
-
return value;
|
|
1949
|
-
}
|
|
1950
|
-
},
|
|
1951
|
-
set(target, prop, value) {
|
|
1952
|
-
const success = Reflect.set(target, prop, value);
|
|
1953
|
-
if (!needupdate) {
|
|
1954
|
-
needupdate = true;
|
|
1955
|
-
requestAnimationFrame(triggerUpdate);
|
|
1956
|
-
}
|
|
1957
|
-
return success;
|
|
1958
|
-
}
|
|
1959
|
-
});
|
|
1939
|
+
let modelTransform = new DOMMatrixReadOnly();
|
|
1960
1940
|
return {
|
|
1961
|
-
currentSrc
|
|
1962
|
-
|
|
1941
|
+
get currentSrc() {
|
|
1942
|
+
return getAbsoluteURL(props.src);
|
|
1943
|
+
},
|
|
1944
|
+
get ready() {
|
|
1963
1945
|
const spatializedElement = domProxy.__spatializedElement;
|
|
1964
1946
|
const promise = spatializedElement.ready.then((success) => {
|
|
1965
1947
|
if (success) {
|
|
@@ -1969,7 +1951,14 @@ function SpatializedStatic3DElementContainerBase(props, ref) {
|
|
|
1969
1951
|
});
|
|
1970
1952
|
return promise;
|
|
1971
1953
|
},
|
|
1972
|
-
entityTransform
|
|
1954
|
+
get entityTransform() {
|
|
1955
|
+
return modelTransform;
|
|
1956
|
+
},
|
|
1957
|
+
set entityTransform(value) {
|
|
1958
|
+
modelTransform = value;
|
|
1959
|
+
const spatializedElement = domProxy.__spatializedElement;
|
|
1960
|
+
spatializedElement.updateModelTransform(modelTransform);
|
|
1961
|
+
}
|
|
1973
1962
|
};
|
|
1974
1963
|
},
|
|
1975
1964
|
[]
|
|
@@ -2134,6 +2123,9 @@ function withSpatialMonitor(El) {
|
|
|
2134
2123
|
}
|
|
2135
2124
|
|
|
2136
2125
|
// src/reality/components/Entity.tsx
|
|
2126
|
+
import { forwardRef as forwardRef11 } from "react";
|
|
2127
|
+
|
|
2128
|
+
// src/reality/components/BaseEntity.tsx
|
|
2137
2129
|
import { forwardRef as forwardRef10 } from "react";
|
|
2138
2130
|
|
|
2139
2131
|
// src/reality/context/RealityContext.tsx
|
|
@@ -2163,7 +2155,8 @@ var ResourceRegistry = class {
|
|
|
2163
2155
|
removeAndDestroy(id) {
|
|
2164
2156
|
const p = this.resources.get(id);
|
|
2165
2157
|
if (p) {
|
|
2166
|
-
p.then((spatialObj) => spatialObj.destroy())
|
|
2158
|
+
p.then((spatialObj) => spatialObj.destroy()).catch(() => {
|
|
2159
|
+
});
|
|
2167
2160
|
}
|
|
2168
2161
|
this.resources.delete(id);
|
|
2169
2162
|
}
|
|
@@ -2173,7 +2166,10 @@ var ResourceRegistry = class {
|
|
|
2173
2166
|
destroy() {
|
|
2174
2167
|
const pending = Array.from(this.resources.values());
|
|
2175
2168
|
this.resources.clear();
|
|
2176
|
-
pending.forEach(
|
|
2169
|
+
pending.forEach(
|
|
2170
|
+
(promise) => promise.then((spatialObj) => spatialObj.destroy()).catch(() => {
|
|
2171
|
+
})
|
|
2172
|
+
);
|
|
2177
2173
|
}
|
|
2178
2174
|
};
|
|
2179
2175
|
|
|
@@ -2244,7 +2240,7 @@ function useEntityTransform(entity, { position, rotation, scale }) {
|
|
|
2244
2240
|
}
|
|
2245
2241
|
|
|
2246
2242
|
// src/reality/hooks/useEntityEvent.tsx
|
|
2247
|
-
import { useEffect as useEffect17 } from "react";
|
|
2243
|
+
import { useEffect as useEffect17, useRef as useRef7 } from "react";
|
|
2248
2244
|
|
|
2249
2245
|
// src/reality/type.ts
|
|
2250
2246
|
var eventMap = {
|
|
@@ -2348,27 +2344,69 @@ function createEventProxy2(ev, instance) {
|
|
|
2348
2344
|
}
|
|
2349
2345
|
return instance;
|
|
2350
2346
|
}
|
|
2347
|
+
if (prop === "bubbles") {
|
|
2348
|
+
return true;
|
|
2349
|
+
}
|
|
2350
|
+
if (prop === "offsetX") {
|
|
2351
|
+
const type = target.type;
|
|
2352
|
+
if (type === "spatialtap") {
|
|
2353
|
+
return target.detail?.location3D?.x ?? 0;
|
|
2354
|
+
}
|
|
2355
|
+
if (type === "spatialdragstart") {
|
|
2356
|
+
return target.detail?.startLocation3D?.x ?? 0;
|
|
2357
|
+
}
|
|
2358
|
+
return void 0;
|
|
2359
|
+
}
|
|
2360
|
+
if (prop === "offsetY") {
|
|
2361
|
+
const type = target.type;
|
|
2362
|
+
if (type === "spatialtap") {
|
|
2363
|
+
return target.detail?.location3D?.y ?? 0;
|
|
2364
|
+
}
|
|
2365
|
+
if (type === "spatialdragstart") {
|
|
2366
|
+
return target.detail?.startLocation3D?.y ?? 0;
|
|
2367
|
+
}
|
|
2368
|
+
return void 0;
|
|
2369
|
+
}
|
|
2370
|
+
if (prop === "offsetZ") {
|
|
2371
|
+
const type = target.type;
|
|
2372
|
+
if (type === "spatialtap") {
|
|
2373
|
+
return target.detail?.location3D?.z ?? 0;
|
|
2374
|
+
}
|
|
2375
|
+
if (type === "spatialdragstart") {
|
|
2376
|
+
return target.detail?.startLocation3D?.z ?? 0;
|
|
2377
|
+
}
|
|
2378
|
+
return void 0;
|
|
2379
|
+
}
|
|
2351
2380
|
const val = target[prop];
|
|
2352
2381
|
return typeof val === "function" ? val.bind(target) : val;
|
|
2353
2382
|
}
|
|
2354
2383
|
});
|
|
2355
2384
|
}
|
|
2356
2385
|
var useEntityEvent = ({ instance, ...handlers }) => {
|
|
2386
|
+
const eventsSetRef = useRef7(/* @__PURE__ */ new Set());
|
|
2357
2387
|
useEffect17(() => {
|
|
2358
2388
|
const entity = instance.entity;
|
|
2359
2389
|
if (!entity) return;
|
|
2360
|
-
const boundHandlers = [];
|
|
2361
2390
|
Object.entries(eventMap).forEach(([reactKey, spatialEvent]) => {
|
|
2362
2391
|
const handlerFn = handlers[reactKey];
|
|
2363
2392
|
if (!handlerFn) return;
|
|
2364
2393
|
const wrapped = (ev) => handlerFn(createEventProxy2(ev, instance));
|
|
2365
2394
|
entity.addEvent(spatialEvent, wrapped);
|
|
2366
|
-
|
|
2395
|
+
eventsSetRef.current.add(reactKey);
|
|
2367
2396
|
});
|
|
2368
2397
|
return () => {
|
|
2369
|
-
boundHandlers.forEach((unbind) => unbind());
|
|
2370
2398
|
};
|
|
2371
2399
|
}, [instance.entity, ...Object.values(handlers)]);
|
|
2400
|
+
useEffect17(() => {
|
|
2401
|
+
const entity = instance.entity;
|
|
2402
|
+
if (!entity) return;
|
|
2403
|
+
return () => {
|
|
2404
|
+
for (let x of eventsSetRef.current) {
|
|
2405
|
+
entity.removeEvent(x);
|
|
2406
|
+
}
|
|
2407
|
+
eventsSetRef.current.clear();
|
|
2408
|
+
};
|
|
2409
|
+
}, [instance.entity]);
|
|
2372
2410
|
return null;
|
|
2373
2411
|
};
|
|
2374
2412
|
|
|
@@ -2387,7 +2425,7 @@ var useEntityId = ({ id, entity }) => {
|
|
|
2387
2425
|
};
|
|
2388
2426
|
|
|
2389
2427
|
// src/reality/hooks/useEntity.tsx
|
|
2390
|
-
import { useEffect as useEffect19, useRef as
|
|
2428
|
+
import { useEffect as useEffect19, useRef as useRef8 } from "react";
|
|
2391
2429
|
var useEntity = ({
|
|
2392
2430
|
ref,
|
|
2393
2431
|
id,
|
|
@@ -2398,10 +2436,10 @@ var useEntity = ({
|
|
|
2398
2436
|
onSpatialDragStart,
|
|
2399
2437
|
onSpatialDrag,
|
|
2400
2438
|
onSpatialDragEnd,
|
|
2401
|
-
onSpatialRotateStart,
|
|
2439
|
+
// onSpatialRotateStart,
|
|
2402
2440
|
onSpatialRotate,
|
|
2403
2441
|
onSpatialRotateEnd,
|
|
2404
|
-
onSpatialMagnifyStart,
|
|
2442
|
+
// onSpatialMagnifyStart,
|
|
2405
2443
|
onSpatialMagnify,
|
|
2406
2444
|
onSpatialMagnifyEnd,
|
|
2407
2445
|
// TODO: add other event handlers
|
|
@@ -2409,7 +2447,7 @@ var useEntity = ({
|
|
|
2409
2447
|
}) => {
|
|
2410
2448
|
const ctx = useRealityContext();
|
|
2411
2449
|
const parent = useParentContext();
|
|
2412
|
-
const instanceRef =
|
|
2450
|
+
const instanceRef = useRef8(new EntityRef(null, ctx));
|
|
2413
2451
|
const forceUpdate = useForceUpdate2();
|
|
2414
2452
|
useEffect19(() => {
|
|
2415
2453
|
if (!ctx) return;
|
|
@@ -2450,10 +2488,10 @@ var useEntity = ({
|
|
|
2450
2488
|
onSpatialDragStart,
|
|
2451
2489
|
onSpatialDrag,
|
|
2452
2490
|
onSpatialDragEnd,
|
|
2453
|
-
onSpatialRotateStart,
|
|
2491
|
+
// onSpatialRotateStart,
|
|
2454
2492
|
onSpatialRotate,
|
|
2455
2493
|
onSpatialRotateEnd,
|
|
2456
|
-
onSpatialMagnifyStart,
|
|
2494
|
+
// onSpatialMagnifyStart,
|
|
2457
2495
|
onSpatialMagnify,
|
|
2458
2496
|
onSpatialMagnifyEnd
|
|
2459
2497
|
});
|
|
@@ -2467,109 +2505,88 @@ var useForceUpdate2 = () => {
|
|
|
2467
2505
|
return useCallback7(() => setTick((tick) => tick + 1), []);
|
|
2468
2506
|
};
|
|
2469
2507
|
|
|
2470
|
-
// src/reality/components/
|
|
2508
|
+
// src/reality/components/BaseEntity.tsx
|
|
2471
2509
|
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
2472
|
-
var
|
|
2473
|
-
({
|
|
2510
|
+
var BaseEntity = forwardRef10(
|
|
2511
|
+
({ children, createEntity, ...rest }, ref) => {
|
|
2474
2512
|
const ctx = useRealityContext();
|
|
2475
2513
|
const entity = useEntity({
|
|
2514
|
+
...rest,
|
|
2476
2515
|
ref,
|
|
2477
|
-
|
|
2478
|
-
position,
|
|
2479
|
-
rotation,
|
|
2480
|
-
scale,
|
|
2481
|
-
onSpatialTap,
|
|
2482
|
-
createEntity: async () => ctx.session.createEntity({ id, name })
|
|
2516
|
+
createEntity: (signal) => createEntity(ctx, signal)
|
|
2483
2517
|
});
|
|
2484
2518
|
if (!entity) return null;
|
|
2485
2519
|
return /* @__PURE__ */ jsx12(ParentContext.Provider, { value: entity, children });
|
|
2486
2520
|
}
|
|
2487
2521
|
);
|
|
2488
2522
|
|
|
2523
|
+
// src/reality/components/Entity.tsx
|
|
2524
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
2525
|
+
var Entity = forwardRef11((props, ref) => {
|
|
2526
|
+
const { id, name, children, ...rest } = props;
|
|
2527
|
+
return /* @__PURE__ */ jsx13(
|
|
2528
|
+
BaseEntity,
|
|
2529
|
+
{
|
|
2530
|
+
...rest,
|
|
2531
|
+
id,
|
|
2532
|
+
ref,
|
|
2533
|
+
createEntity: async (ctxVal) => ctxVal.session.createEntity({ id, name }),
|
|
2534
|
+
children
|
|
2535
|
+
}
|
|
2536
|
+
);
|
|
2537
|
+
});
|
|
2538
|
+
|
|
2489
2539
|
// src/reality/components/BoxEntity.tsx
|
|
2490
|
-
import { forwardRef as
|
|
2540
|
+
import { forwardRef as forwardRef13 } from "react";
|
|
2491
2541
|
|
|
2492
2542
|
// src/reality/components/GeometryEntity.tsx
|
|
2493
|
-
import { forwardRef as
|
|
2494
|
-
import { jsx as
|
|
2495
|
-
var GeometryEntity =
|
|
2496
|
-
({
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
onSpatialRotateStart,
|
|
2530
|
-
onSpatialRotate,
|
|
2531
|
-
onSpatialRotateEnd,
|
|
2532
|
-
onSpatialMagnifyStart,
|
|
2533
|
-
onSpatialMagnify,
|
|
2534
|
-
onSpatialMagnifyEnd,
|
|
2535
|
-
createEntity: async (signal) => {
|
|
2536
|
-
const manager = new AbortResourceManager(signal);
|
|
2537
|
-
try {
|
|
2538
|
-
const ent = await manager.addResource(
|
|
2539
|
-
() => ctx.session.createEntity({ id, name })
|
|
2540
|
-
);
|
|
2541
|
-
const geometry = await manager.addResource(
|
|
2542
|
-
() => createGeometry(geometryOptions)
|
|
2543
|
-
);
|
|
2544
|
-
const materialList = await Promise.all(
|
|
2545
|
-
materials?.map((id2) => ctx.resourceRegistry.get(id2)).filter(Boolean) ?? []
|
|
2546
|
-
);
|
|
2547
|
-
const modelComponent = await manager.addResource(
|
|
2548
|
-
() => ctx.session.createModelComponent({
|
|
2549
|
-
mesh: geometry,
|
|
2550
|
-
materials: materialList
|
|
2551
|
-
})
|
|
2552
|
-
);
|
|
2553
|
-
await ent.addComponent(modelComponent);
|
|
2554
|
-
return ent;
|
|
2555
|
-
} catch (error) {
|
|
2556
|
-
console.error(error);
|
|
2557
|
-
await manager.dispose();
|
|
2558
|
-
return null;
|
|
2559
|
-
}
|
|
2543
|
+
import { forwardRef as forwardRef12 } from "react";
|
|
2544
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
2545
|
+
var GeometryEntity = forwardRef12(
|
|
2546
|
+
({ id, children, name, materials, geometryOptions, createGeometry, ...rest }, ref) => {
|
|
2547
|
+
return /* @__PURE__ */ jsx14(
|
|
2548
|
+
BaseEntity,
|
|
2549
|
+
{
|
|
2550
|
+
...rest,
|
|
2551
|
+
id,
|
|
2552
|
+
ref,
|
|
2553
|
+
createEntity: async (ctx, signal) => {
|
|
2554
|
+
const manager = new AbortResourceManager(signal);
|
|
2555
|
+
try {
|
|
2556
|
+
const ent = await manager.addResource(
|
|
2557
|
+
() => ctx.session.createEntity({ id, name })
|
|
2558
|
+
);
|
|
2559
|
+
const geometry = await manager.addResource(
|
|
2560
|
+
() => createGeometry(geometryOptions)
|
|
2561
|
+
);
|
|
2562
|
+
const materialList = await Promise.all(
|
|
2563
|
+
materials?.map((id2) => ctx.resourceRegistry.get(id2)).filter(Boolean) ?? []
|
|
2564
|
+
);
|
|
2565
|
+
const modelComponent = await manager.addResource(
|
|
2566
|
+
() => ctx.session.createModelComponent({
|
|
2567
|
+
mesh: geometry,
|
|
2568
|
+
materials: materialList
|
|
2569
|
+
})
|
|
2570
|
+
);
|
|
2571
|
+
await ent.addComponent(modelComponent);
|
|
2572
|
+
return ent;
|
|
2573
|
+
} catch (error) {
|
|
2574
|
+
await manager.dispose();
|
|
2575
|
+
return null;
|
|
2576
|
+
}
|
|
2577
|
+
},
|
|
2578
|
+
children
|
|
2560
2579
|
}
|
|
2561
|
-
|
|
2562
|
-
if (!entity) return null;
|
|
2563
|
-
return /* @__PURE__ */ jsx13(ParentContext.Provider, { value: entity, children });
|
|
2580
|
+
);
|
|
2564
2581
|
}
|
|
2565
2582
|
);
|
|
2566
2583
|
|
|
2567
2584
|
// src/reality/components/BoxEntity.tsx
|
|
2568
|
-
import { jsx as
|
|
2569
|
-
var BoxEntity =
|
|
2585
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
2586
|
+
var BoxEntity = forwardRef13(
|
|
2570
2587
|
({ children, ...props }, ref) => {
|
|
2571
2588
|
const ctx = useRealityContext();
|
|
2572
|
-
return /* @__PURE__ */
|
|
2589
|
+
return /* @__PURE__ */ jsx15(
|
|
2573
2590
|
GeometryEntity,
|
|
2574
2591
|
{
|
|
2575
2592
|
...props,
|
|
@@ -2589,10 +2606,10 @@ var BoxEntity = forwardRef12(
|
|
|
2589
2606
|
);
|
|
2590
2607
|
|
|
2591
2608
|
// src/reality/components/UnlitMaterial.tsx
|
|
2592
|
-
import { useEffect as useEffect20, useRef as
|
|
2609
|
+
import { useEffect as useEffect20, useRef as useRef9 } from "react";
|
|
2593
2610
|
var UnlitMaterial = ({ children, ...options }) => {
|
|
2594
2611
|
const ctx = useRealityContext();
|
|
2595
|
-
const materialRef =
|
|
2612
|
+
const materialRef = useRef9();
|
|
2596
2613
|
useEffect20(() => {
|
|
2597
2614
|
if (!ctx) return;
|
|
2598
2615
|
const { session, reality, resourceRegistry } = ctx;
|
|
@@ -2615,12 +2632,12 @@ var UnlitMaterial = ({ children, ...options }) => {
|
|
|
2615
2632
|
};
|
|
2616
2633
|
|
|
2617
2634
|
// src/reality/components/SphereEntity.tsx
|
|
2618
|
-
import { forwardRef as
|
|
2619
|
-
import { jsx as
|
|
2620
|
-
var SphereEntity =
|
|
2635
|
+
import { forwardRef as forwardRef14 } from "react";
|
|
2636
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
2637
|
+
var SphereEntity = forwardRef14(
|
|
2621
2638
|
({ children, ...props }, ref) => {
|
|
2622
2639
|
const ctx = useRealityContext();
|
|
2623
|
-
return /* @__PURE__ */
|
|
2640
|
+
return /* @__PURE__ */ jsx16(
|
|
2624
2641
|
GeometryEntity,
|
|
2625
2642
|
{
|
|
2626
2643
|
...props,
|
|
@@ -2636,12 +2653,12 @@ var SphereEntity = forwardRef13(
|
|
|
2636
2653
|
);
|
|
2637
2654
|
|
|
2638
2655
|
// src/reality/components/ConeEntity.tsx
|
|
2639
|
-
import { forwardRef as
|
|
2640
|
-
import { jsx as
|
|
2641
|
-
var ConeEntity =
|
|
2656
|
+
import { forwardRef as forwardRef15 } from "react";
|
|
2657
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
2658
|
+
var ConeEntity = forwardRef15(
|
|
2642
2659
|
({ children, ...props }, ref) => {
|
|
2643
2660
|
const ctx = useRealityContext();
|
|
2644
|
-
return /* @__PURE__ */
|
|
2661
|
+
return /* @__PURE__ */ jsx17(
|
|
2645
2662
|
GeometryEntity,
|
|
2646
2663
|
{
|
|
2647
2664
|
...props,
|
|
@@ -2658,12 +2675,12 @@ var ConeEntity = forwardRef14(
|
|
|
2658
2675
|
);
|
|
2659
2676
|
|
|
2660
2677
|
// src/reality/components/CylinderEntity.tsx
|
|
2661
|
-
import { forwardRef as
|
|
2662
|
-
import { jsx as
|
|
2663
|
-
var CylinderEntity =
|
|
2678
|
+
import { forwardRef as forwardRef16 } from "react";
|
|
2679
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
2680
|
+
var CylinderEntity = forwardRef16(
|
|
2664
2681
|
({ children, ...props }, ref) => {
|
|
2665
2682
|
const ctx = useRealityContext();
|
|
2666
|
-
return /* @__PURE__ */
|
|
2683
|
+
return /* @__PURE__ */ jsx18(
|
|
2667
2684
|
GeometryEntity,
|
|
2668
2685
|
{
|
|
2669
2686
|
...props,
|
|
@@ -2680,12 +2697,12 @@ var CylinderEntity = forwardRef15(
|
|
|
2680
2697
|
);
|
|
2681
2698
|
|
|
2682
2699
|
// src/reality/components/PlaneEntity.tsx
|
|
2683
|
-
import { forwardRef as
|
|
2684
|
-
import { jsx as
|
|
2685
|
-
var PlaneEntity =
|
|
2700
|
+
import { forwardRef as forwardRef17 } from "react";
|
|
2701
|
+
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
2702
|
+
var PlaneEntity = forwardRef17(
|
|
2686
2703
|
({ children, ...props }, ref) => {
|
|
2687
2704
|
const ctx = useRealityContext();
|
|
2688
|
-
return /* @__PURE__ */
|
|
2705
|
+
return /* @__PURE__ */ jsx19(
|
|
2689
2706
|
GeometryEntity,
|
|
2690
2707
|
{
|
|
2691
2708
|
...props,
|
|
@@ -2703,13 +2720,13 @@ var PlaneEntity = forwardRef16(
|
|
|
2703
2720
|
);
|
|
2704
2721
|
|
|
2705
2722
|
// src/reality/components/SceneGraph.tsx
|
|
2706
|
-
import { jsx as
|
|
2723
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
2707
2724
|
var SceneGraph = ({ children }) => {
|
|
2708
|
-
return /* @__PURE__ */
|
|
2725
|
+
return /* @__PURE__ */ jsx20(ParentContext.Provider, { value: null, children });
|
|
2709
2726
|
};
|
|
2710
2727
|
|
|
2711
2728
|
// src/reality/components/ModelAsset.tsx
|
|
2712
|
-
import { useEffect as useEffect21, useRef as
|
|
2729
|
+
import { useEffect as useEffect21, useRef as useRef10 } from "react";
|
|
2713
2730
|
var resolveAssetUrl = (url) => {
|
|
2714
2731
|
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
2715
2732
|
return url;
|
|
@@ -2718,16 +2735,16 @@ var resolveAssetUrl = (url) => {
|
|
|
2718
2735
|
};
|
|
2719
2736
|
var ModelAsset = ({ children, ...options }) => {
|
|
2720
2737
|
const ctx = useRealityContext();
|
|
2721
|
-
const materialRef =
|
|
2738
|
+
const materialRef = useRef10();
|
|
2722
2739
|
useEffect21(() => {
|
|
2723
2740
|
const controller = new AbortController();
|
|
2724
2741
|
if (!ctx) return;
|
|
2725
2742
|
const { session, reality, resourceRegistry } = ctx;
|
|
2726
2743
|
const init = async () => {
|
|
2727
|
-
const resolvedUrl = resolveAssetUrl(options.src);
|
|
2728
|
-
const modelAssetPromise = session.createModelAsset({ url: resolvedUrl });
|
|
2729
|
-
resourceRegistry.add(options.id, modelAssetPromise);
|
|
2730
2744
|
try {
|
|
2745
|
+
const resolvedUrl = resolveAssetUrl(options.src);
|
|
2746
|
+
const modelAssetPromise = session.createModelAsset({ url: resolvedUrl });
|
|
2747
|
+
resourceRegistry.add(options.id, modelAssetPromise);
|
|
2731
2748
|
const mat = await modelAssetPromise;
|
|
2732
2749
|
if (controller.signal.aborted) {
|
|
2733
2750
|
mat.destroy();
|
|
@@ -2749,57 +2766,63 @@ var ModelAsset = ({ children, ...options }) => {
|
|
|
2749
2766
|
};
|
|
2750
2767
|
|
|
2751
2768
|
// src/reality/components/ModelEntity.tsx
|
|
2752
|
-
import { forwardRef as
|
|
2753
|
-
import { jsx as
|
|
2754
|
-
var ModelEntity =
|
|
2755
|
-
({ id, model,
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2769
|
+
import { forwardRef as forwardRef18 } from "react";
|
|
2770
|
+
import { jsx as jsx21 } from "react/jsx-runtime";
|
|
2771
|
+
var ModelEntity = forwardRef18(
|
|
2772
|
+
({ id, model, children, name, ...rest }, ref) => {
|
|
2773
|
+
return /* @__PURE__ */ jsx21(
|
|
2774
|
+
BaseEntity,
|
|
2775
|
+
{
|
|
2776
|
+
...rest,
|
|
2777
|
+
id,
|
|
2778
|
+
ref,
|
|
2779
|
+
createEntity: async (ctx, signal) => {
|
|
2780
|
+
try {
|
|
2781
|
+
const modelAsset = await ctx.resourceRegistry.get(model);
|
|
2782
|
+
if (!modelAsset)
|
|
2783
|
+
throw new Error(`ModelEntity: model not found ${model}`);
|
|
2784
|
+
if (signal.aborted) return null;
|
|
2785
|
+
return ctx.session.createSpatialModelEntity(
|
|
2786
|
+
{
|
|
2787
|
+
modelAssetId: modelAsset.id,
|
|
2788
|
+
name
|
|
2789
|
+
},
|
|
2790
|
+
{ id, name }
|
|
2791
|
+
);
|
|
2792
|
+
} catch (error) {
|
|
2770
2793
|
return null;
|
|
2771
2794
|
}
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
modelAssetId: modelAsset.id,
|
|
2775
|
-
name
|
|
2776
|
-
},
|
|
2777
|
-
{ id, name }
|
|
2778
|
-
);
|
|
2779
|
-
} catch (error) {
|
|
2780
|
-
console.error("ModelEntity error:", error);
|
|
2781
|
-
return null;
|
|
2782
|
-
}
|
|
2795
|
+
},
|
|
2796
|
+
children
|
|
2783
2797
|
}
|
|
2784
|
-
|
|
2785
|
-
if (!entity) return null;
|
|
2786
|
-
return /* @__PURE__ */ jsx20(ParentContext.Provider, { value: entity, children });
|
|
2798
|
+
);
|
|
2787
2799
|
}
|
|
2788
2800
|
);
|
|
2789
2801
|
|
|
2790
2802
|
// src/reality/components/Reality.tsx
|
|
2791
2803
|
import {
|
|
2792
|
-
forwardRef as
|
|
2804
|
+
forwardRef as forwardRef19,
|
|
2793
2805
|
useCallback as useCallback8,
|
|
2794
2806
|
useEffect as useEffect22,
|
|
2795
|
-
useRef as
|
|
2807
|
+
useRef as useRef11,
|
|
2796
2808
|
useState as useState8
|
|
2797
2809
|
} from "react";
|
|
2798
|
-
import { Fragment as Fragment3, jsx as
|
|
2799
|
-
var Reality =
|
|
2800
|
-
function RealityBase({ children, ...
|
|
2801
|
-
const
|
|
2802
|
-
|
|
2810
|
+
import { Fragment as Fragment3, jsx as jsx22, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2811
|
+
var Reality = forwardRef19(
|
|
2812
|
+
function RealityBase({ children, ...inProps }, ref) {
|
|
2813
|
+
const {
|
|
2814
|
+
onSpatialTap,
|
|
2815
|
+
onSpatialDragStart,
|
|
2816
|
+
onSpatialDrag,
|
|
2817
|
+
onSpatialDragEnd,
|
|
2818
|
+
onSpatialRotate,
|
|
2819
|
+
onSpatialRotateEnd,
|
|
2820
|
+
onSpatialMagnify,
|
|
2821
|
+
onSpatialMagnifyEnd,
|
|
2822
|
+
...props
|
|
2823
|
+
} = inProps;
|
|
2824
|
+
const ctxRef = useRef11(null);
|
|
2825
|
+
const creationId = useRef11(0);
|
|
2803
2826
|
const [isReady, setIsReady] = useState8(false);
|
|
2804
2827
|
const cleanupReality = useCallback8(() => {
|
|
2805
2828
|
ctxRef.current?.resourceRegistry.destroy();
|
|
@@ -2846,9 +2869,9 @@ var Reality = forwardRef18(
|
|
|
2846
2869
|
return null;
|
|
2847
2870
|
}
|
|
2848
2871
|
}, [cleanupReality]);
|
|
2849
|
-
const content = useCallback8(() => /* @__PURE__ */
|
|
2872
|
+
const content = useCallback8(() => /* @__PURE__ */ jsx22(Fragment3, {}), []);
|
|
2850
2873
|
return /* @__PURE__ */ jsxs3(RealityContext.Provider, { value: ctxRef.current, children: [
|
|
2851
|
-
/* @__PURE__ */
|
|
2874
|
+
/* @__PURE__ */ jsx22(
|
|
2852
2875
|
SpatializedContainer,
|
|
2853
2876
|
{
|
|
2854
2877
|
component: "div",
|
|
@@ -2864,8 +2887,8 @@ var Reality = forwardRef18(
|
|
|
2864
2887
|
);
|
|
2865
2888
|
|
|
2866
2889
|
// src/Model.tsx
|
|
2867
|
-
import { forwardRef as
|
|
2868
|
-
import { jsx as
|
|
2890
|
+
import { forwardRef as forwardRef20 } from "react";
|
|
2891
|
+
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
2869
2892
|
var spatial2 = new Spatial();
|
|
2870
2893
|
function ModelBase(props, ref) {
|
|
2871
2894
|
const { "enable-xr": enableXR, ...restProps } = props;
|
|
@@ -2875,23 +2898,21 @@ function ModelBase(props, ref) {
|
|
|
2875
2898
|
onSpatialDragStart,
|
|
2876
2899
|
onSpatialDrag,
|
|
2877
2900
|
onSpatialDragEnd,
|
|
2878
|
-
onSpatialRotateStart,
|
|
2879
2901
|
onSpatialRotate,
|
|
2880
2902
|
onSpatialRotateEnd,
|
|
2881
|
-
onSpatialMagnifyStart,
|
|
2882
2903
|
onSpatialMagnify,
|
|
2883
2904
|
onSpatialMagnifyEnd,
|
|
2884
2905
|
...modelProps
|
|
2885
2906
|
} = restProps;
|
|
2886
|
-
return /* @__PURE__ */
|
|
2907
|
+
return /* @__PURE__ */ jsx23("model", { ref, ...modelProps });
|
|
2887
2908
|
}
|
|
2888
|
-
return /* @__PURE__ */
|
|
2909
|
+
return /* @__PURE__ */ jsx23(SpatializedStatic3DElementContainer, { ref, ...restProps });
|
|
2889
2910
|
}
|
|
2890
|
-
var Model = withSSRSupported(
|
|
2911
|
+
var Model = withSSRSupported(forwardRef20(ModelBase));
|
|
2891
2912
|
Model.displayName = "Model";
|
|
2892
2913
|
|
|
2893
2914
|
// src/index.ts
|
|
2894
|
-
var version = "1.
|
|
2915
|
+
var version = "1.2.0";
|
|
2895
2916
|
if (typeof window !== "undefined") {
|
|
2896
2917
|
initPolyfill();
|
|
2897
2918
|
}
|