@webspatial/react-sdk 1.0.5 → 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 +366 -316
- 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 +366 -316
- package/dist/web/index.js.map +1 -1
- package/package.json +2 -2
package/dist/default/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.0
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.2.0"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "avp"
|
|
7
7
|
})()
|
|
8
8
|
|
|
@@ -186,19 +186,40 @@ var SpatialContainerRefProxy = class {
|
|
|
186
186
|
if (!self.styleProxy) {
|
|
187
187
|
self.styleProxy = new Proxy(target.style, {
|
|
188
188
|
get(target2, prop2) {
|
|
189
|
-
if (prop2 === "visibility") {
|
|
190
|
-
return self.transformVisibilityTaskContainerDom?.style.getPropertyValue(
|
|
191
|
-
"visibility"
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
if (prop2 === "transform") {
|
|
189
|
+
if (prop2 === "visibility" || prop2 === "transform") {
|
|
195
190
|
return self.transformVisibilityTaskContainerDom?.style.getPropertyValue(
|
|
196
|
-
|
|
191
|
+
prop2
|
|
197
192
|
);
|
|
198
193
|
}
|
|
199
194
|
const value2 = Reflect.get(target2, prop2);
|
|
200
195
|
if (typeof value2 === "function") {
|
|
201
|
-
|
|
196
|
+
if (prop2 === "setProperty" || prop2 === "removeProperty" || prop2 === "getPropertyValue") {
|
|
197
|
+
return function(...args) {
|
|
198
|
+
const validProperties = ["visibility", "transform"];
|
|
199
|
+
const [property] = args;
|
|
200
|
+
if (validProperties.includes(property)) {
|
|
201
|
+
if (prop2 === "setProperty") {
|
|
202
|
+
const [, kValue] = args;
|
|
203
|
+
self.transformVisibilityTaskContainerDom?.style.setProperty(
|
|
204
|
+
property,
|
|
205
|
+
kValue
|
|
206
|
+
);
|
|
207
|
+
} else if (prop2 === "removeProperty") {
|
|
208
|
+
self.transformVisibilityTaskContainerDom?.style.removeProperty(
|
|
209
|
+
property
|
|
210
|
+
);
|
|
211
|
+
} else if (prop2 === "getPropertyValue") {
|
|
212
|
+
return self.transformVisibilityTaskContainerDom?.style.getPropertyValue(
|
|
213
|
+
property
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
return value2.apply(this, args);
|
|
218
|
+
}
|
|
219
|
+
}.bind(target2);
|
|
220
|
+
} else {
|
|
221
|
+
return value2.bind(target2);
|
|
222
|
+
}
|
|
202
223
|
} else {
|
|
203
224
|
return value2;
|
|
204
225
|
}
|
|
@@ -279,7 +300,7 @@ var SpatialContainerRefProxy = class {
|
|
|
279
300
|
}
|
|
280
301
|
const extraProps = cacheExtraRefProps;
|
|
281
302
|
if (extraProps.hasOwnProperty(prop)) {
|
|
282
|
-
return extraProps[prop]
|
|
303
|
+
return extraProps[prop];
|
|
283
304
|
}
|
|
284
305
|
}
|
|
285
306
|
const value = Reflect.get(target, prop);
|
|
@@ -314,6 +335,12 @@ var SpatialContainerRefProxy = class {
|
|
|
314
335
|
self.transformVisibilityTaskContainerDom.className = value;
|
|
315
336
|
}
|
|
316
337
|
}
|
|
338
|
+
if (typeof prop === "string" && self.extraRefProps) {
|
|
339
|
+
if (!cacheExtraRefProps) {
|
|
340
|
+
cacheExtraRefProps = self.extraRefProps(domProxy);
|
|
341
|
+
}
|
|
342
|
+
cacheExtraRefProps[prop] = value;
|
|
343
|
+
}
|
|
317
344
|
return Reflect.set(target, prop, value);
|
|
318
345
|
}
|
|
319
346
|
}
|
|
@@ -659,7 +686,7 @@ var StandardSpatializedContainer = forwardRef(
|
|
|
659
686
|
function injectSpatialDefaultStyle() {
|
|
660
687
|
const styleElement = document.createElement("style");
|
|
661
688
|
styleElement.type = "text/css";
|
|
662
|
-
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; } ";
|
|
663
690
|
document.head.appendChild(styleElement);
|
|
664
691
|
}
|
|
665
692
|
|
|
@@ -1200,10 +1227,8 @@ function PortalSpatializedContainer(props) {
|
|
|
1200
1227
|
onSpatialDragStart,
|
|
1201
1228
|
onSpatialDrag,
|
|
1202
1229
|
onSpatialDragEnd,
|
|
1203
|
-
onSpatialRotateStart,
|
|
1204
1230
|
onSpatialRotate,
|
|
1205
1231
|
onSpatialRotateEnd,
|
|
1206
|
-
onSpatialMagnifyStart,
|
|
1207
1232
|
onSpatialMagnify,
|
|
1208
1233
|
onSpatialMagnifyEnd,
|
|
1209
1234
|
[SpatialID]: spatialId,
|
|
@@ -1277,16 +1302,6 @@ function PortalSpatializedContainer(props) {
|
|
|
1277
1302
|
spatializedElement.onSpatialDragStart = onSpatialDragStart;
|
|
1278
1303
|
}
|
|
1279
1304
|
}, [spatializedElement, onSpatialDragStart]);
|
|
1280
|
-
useEffect7(() => {
|
|
1281
|
-
if (spatializedElement) {
|
|
1282
|
-
spatializedElement.onSpatialRotateStart = onSpatialRotateStart;
|
|
1283
|
-
}
|
|
1284
|
-
}, [spatializedElement, onSpatialRotateStart]);
|
|
1285
|
-
useEffect7(() => {
|
|
1286
|
-
if (spatializedElement) {
|
|
1287
|
-
spatializedElement.onSpatialMagnifyStart = onSpatialMagnifyStart;
|
|
1288
|
-
}
|
|
1289
|
-
}, [spatializedElement, onSpatialMagnifyStart]);
|
|
1290
1305
|
return /* @__PURE__ */ jsxs(PortalInstanceContext.Provider, { value: portalInstanceObject, children: [
|
|
1291
1306
|
spatializedElement && portalInstanceObject.dom && /* @__PURE__ */ jsx3(Content, { spatializedElement, ...restProps }),
|
|
1292
1307
|
PlaceholderEl
|
|
@@ -1294,7 +1309,7 @@ function PortalSpatializedContainer(props) {
|
|
|
1294
1309
|
}
|
|
1295
1310
|
|
|
1296
1311
|
// src/spatialized-container/hooks/useSpatialEvents.ts
|
|
1297
|
-
function createEventProxy(event, currentTargetGetter) {
|
|
1312
|
+
function createEventProxy(event, currentTargetGetter, offsetXGetter, offsetYGetter, offsetZGetter) {
|
|
1298
1313
|
return new Proxy(event, {
|
|
1299
1314
|
get(target, prop) {
|
|
1300
1315
|
if (prop === "currentTarget") {
|
|
@@ -1303,20 +1318,41 @@ function createEventProxy(event, currentTargetGetter) {
|
|
|
1303
1318
|
if (prop === "isTrusted") {
|
|
1304
1319
|
return true;
|
|
1305
1320
|
}
|
|
1321
|
+
if (prop === "bubbles") {
|
|
1322
|
+
return false;
|
|
1323
|
+
}
|
|
1324
|
+
if (prop === "offsetX" && offsetXGetter) {
|
|
1325
|
+
return offsetXGetter(target) ?? 0;
|
|
1326
|
+
}
|
|
1327
|
+
if (prop === "offsetY" && offsetYGetter) {
|
|
1328
|
+
return offsetYGetter(target) ?? 0;
|
|
1329
|
+
}
|
|
1330
|
+
if (prop === "offsetZ" && offsetZGetter) {
|
|
1331
|
+
return offsetZGetter(target) ?? 0;
|
|
1332
|
+
}
|
|
1306
1333
|
return Reflect.get(target, prop);
|
|
1307
1334
|
}
|
|
1308
1335
|
});
|
|
1309
1336
|
}
|
|
1310
|
-
function createEventHandler(handler, currentTargetGetter) {
|
|
1337
|
+
function createEventHandler(handler, currentTargetGetter, offsetXGetter, offsetYGetter, offsetZGetter) {
|
|
1311
1338
|
return handler ? (event) => {
|
|
1312
|
-
const proxyEvent = createEventProxy(
|
|
1339
|
+
const proxyEvent = createEventProxy(
|
|
1340
|
+
event,
|
|
1341
|
+
currentTargetGetter,
|
|
1342
|
+
offsetXGetter,
|
|
1343
|
+
offsetYGetter,
|
|
1344
|
+
offsetZGetter
|
|
1345
|
+
);
|
|
1313
1346
|
handler(proxyEvent);
|
|
1314
1347
|
} : void 0;
|
|
1315
1348
|
}
|
|
1316
1349
|
function useSpatialEventsBase(spatialEvents, currentTargetGetter) {
|
|
1317
1350
|
const onSpatialTap = createEventHandler(
|
|
1318
1351
|
spatialEvents.onSpatialTap,
|
|
1319
|
-
currentTargetGetter
|
|
1352
|
+
currentTargetGetter,
|
|
1353
|
+
(ev) => ev.detail?.location3D?.x,
|
|
1354
|
+
(ev) => ev.detail?.location3D?.y,
|
|
1355
|
+
(ev) => ev.detail?.location3D?.z
|
|
1320
1356
|
);
|
|
1321
1357
|
const onSpatialDrag = createEventHandler(
|
|
1322
1358
|
spatialEvents.onSpatialDrag,
|
|
@@ -1344,19 +1380,18 @@ function useSpatialEventsBase(spatialEvents, currentTargetGetter) {
|
|
|
1344
1380
|
);
|
|
1345
1381
|
const onSpatialDragStart = createEventHandler(
|
|
1346
1382
|
spatialEvents.onSpatialDragStart,
|
|
1347
|
-
currentTargetGetter
|
|
1383
|
+
currentTargetGetter,
|
|
1384
|
+
(ev) => ev.detail?.startLocation3D?.x,
|
|
1385
|
+
(ev) => ev.detail?.startLocation3D?.y,
|
|
1386
|
+
(ev) => ev.detail?.startLocation3D?.z
|
|
1348
1387
|
);
|
|
1349
|
-
const onSpatialRotateStart = createEventHandler(spatialEvents.onSpatialRotateStart, currentTargetGetter);
|
|
1350
|
-
const onSpatialMagnifyStart = createEventHandler(spatialEvents.onSpatialMagnifyStart, currentTargetGetter);
|
|
1351
1388
|
return {
|
|
1352
1389
|
onSpatialTap,
|
|
1353
1390
|
onSpatialDragStart,
|
|
1354
1391
|
onSpatialDrag,
|
|
1355
1392
|
onSpatialDragEnd,
|
|
1356
|
-
onSpatialRotateStart,
|
|
1357
1393
|
onSpatialRotate,
|
|
1358
1394
|
onSpatialRotateEnd,
|
|
1359
|
-
onSpatialMagnifyStart,
|
|
1360
1395
|
onSpatialMagnify,
|
|
1361
1396
|
onSpatialMagnifyEnd
|
|
1362
1397
|
};
|
|
@@ -1447,10 +1482,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1447
1482
|
onSpatialDragStart: onSpatialDragStart2,
|
|
1448
1483
|
onSpatialDrag: onSpatialDrag2,
|
|
1449
1484
|
onSpatialDragEnd: onSpatialDragEnd2,
|
|
1450
|
-
onSpatialRotateStart: onSpatialRotateStart2,
|
|
1451
1485
|
onSpatialRotate: onSpatialRotate2,
|
|
1452
1486
|
onSpatialRotateEnd: onSpatialRotateEnd2,
|
|
1453
|
-
onSpatialMagnifyStart: onSpatialMagnifyStart2,
|
|
1454
1487
|
onSpatialMagnify: onSpatialMagnify2,
|
|
1455
1488
|
onSpatialMagnifyEnd: onSpatialMagnifyEnd2,
|
|
1456
1489
|
extraRefProps: extraRefProps2,
|
|
@@ -1477,10 +1510,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1477
1510
|
onSpatialDragStart,
|
|
1478
1511
|
onSpatialDrag,
|
|
1479
1512
|
onSpatialDragEnd,
|
|
1480
|
-
onSpatialRotateStart,
|
|
1481
1513
|
onSpatialRotate,
|
|
1482
1514
|
onSpatialRotateEnd,
|
|
1483
|
-
onSpatialMagnifyStart,
|
|
1484
1515
|
onSpatialMagnify,
|
|
1485
1516
|
onSpatialMagnifyEnd,
|
|
1486
1517
|
extraRefProps,
|
|
@@ -1494,10 +1525,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1494
1525
|
onSpatialDragStart,
|
|
1495
1526
|
onSpatialDrag,
|
|
1496
1527
|
onSpatialDragEnd,
|
|
1497
|
-
onSpatialRotateStart,
|
|
1498
1528
|
onSpatialRotate,
|
|
1499
1529
|
onSpatialRotateEnd,
|
|
1500
|
-
onSpatialMagnifyStart,
|
|
1501
1530
|
onSpatialMagnify,
|
|
1502
1531
|
onSpatialMagnifyEnd
|
|
1503
1532
|
},
|
|
@@ -1563,10 +1592,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1563
1592
|
onSpatialDragStart,
|
|
1564
1593
|
onSpatialDrag,
|
|
1565
1594
|
onSpatialDragEnd,
|
|
1566
|
-
onSpatialRotateStart,
|
|
1567
1595
|
onSpatialRotate,
|
|
1568
1596
|
onSpatialRotateEnd,
|
|
1569
|
-
onSpatialMagnifyStart,
|
|
1570
1597
|
onSpatialMagnify,
|
|
1571
1598
|
onSpatialMagnifyEnd
|
|
1572
1599
|
},
|
|
@@ -1795,10 +1822,11 @@ function getAbsoluteURL(url) {
|
|
|
1795
1822
|
if (!url) {
|
|
1796
1823
|
return "";
|
|
1797
1824
|
}
|
|
1798
|
-
|
|
1825
|
+
try {
|
|
1826
|
+
return new URL(url, document.baseURI).toString();
|
|
1827
|
+
} catch {
|
|
1799
1828
|
return url;
|
|
1800
1829
|
}
|
|
1801
|
-
return window.location.origin + url;
|
|
1802
1830
|
}
|
|
1803
1831
|
function createLoadEvent(type, targetGetter) {
|
|
1804
1832
|
const event = new CustomEvent(type, {
|
|
@@ -1867,37 +1895,12 @@ async function createSpatializedElement2() {
|
|
|
1867
1895
|
function SpatializedStatic3DElementContainerBase(props, ref) {
|
|
1868
1896
|
const extraRefProps = useCallback6(
|
|
1869
1897
|
(domProxy) => {
|
|
1870
|
-
|
|
1871
|
-
let needupdate = false;
|
|
1872
|
-
const triggerUpdate = () => {
|
|
1873
|
-
const spatializedElement = domProxy.__spatializedElement;
|
|
1874
|
-
spatializedElement.updateModelTransform(modelTransform);
|
|
1875
|
-
needupdate = false;
|
|
1876
|
-
};
|
|
1877
|
-
const domMatrixProxy = new Proxy(modelTransform, {
|
|
1878
|
-
get(target, prop, receiver) {
|
|
1879
|
-
const value = Reflect.get(target, prop, receiver);
|
|
1880
|
-
if (typeof value === "function") {
|
|
1881
|
-
return function(...args) {
|
|
1882
|
-
requestAnimationFrame(triggerUpdate);
|
|
1883
|
-
return value.apply(target, args);
|
|
1884
|
-
};
|
|
1885
|
-
} else {
|
|
1886
|
-
return value;
|
|
1887
|
-
}
|
|
1888
|
-
},
|
|
1889
|
-
set(target, prop, value) {
|
|
1890
|
-
const success = Reflect.set(target, prop, value);
|
|
1891
|
-
if (!needupdate) {
|
|
1892
|
-
needupdate = true;
|
|
1893
|
-
requestAnimationFrame(triggerUpdate);
|
|
1894
|
-
}
|
|
1895
|
-
return success;
|
|
1896
|
-
}
|
|
1897
|
-
});
|
|
1898
|
+
let modelTransform = new DOMMatrixReadOnly();
|
|
1898
1899
|
return {
|
|
1899
|
-
currentSrc
|
|
1900
|
-
|
|
1900
|
+
get currentSrc() {
|
|
1901
|
+
return getAbsoluteURL(props.src);
|
|
1902
|
+
},
|
|
1903
|
+
get ready() {
|
|
1901
1904
|
const spatializedElement = domProxy.__spatializedElement;
|
|
1902
1905
|
const promise = spatializedElement.ready.then((success) => {
|
|
1903
1906
|
if (success) {
|
|
@@ -1907,7 +1910,14 @@ function SpatializedStatic3DElementContainerBase(props, ref) {
|
|
|
1907
1910
|
});
|
|
1908
1911
|
return promise;
|
|
1909
1912
|
},
|
|
1910
|
-
entityTransform
|
|
1913
|
+
get entityTransform() {
|
|
1914
|
+
return modelTransform;
|
|
1915
|
+
},
|
|
1916
|
+
set entityTransform(value) {
|
|
1917
|
+
modelTransform = value;
|
|
1918
|
+
const spatializedElement = domProxy.__spatializedElement;
|
|
1919
|
+
spatializedElement.updateModelTransform(modelTransform);
|
|
1920
|
+
}
|
|
1911
1921
|
};
|
|
1912
1922
|
},
|
|
1913
1923
|
[]
|
|
@@ -2072,6 +2082,9 @@ function withSpatialMonitor(El) {
|
|
|
2072
2082
|
}
|
|
2073
2083
|
|
|
2074
2084
|
// src/reality/components/Entity.tsx
|
|
2085
|
+
import { forwardRef as forwardRef11 } from "react";
|
|
2086
|
+
|
|
2087
|
+
// src/reality/components/BaseEntity.tsx
|
|
2075
2088
|
import { forwardRef as forwardRef10 } from "react";
|
|
2076
2089
|
|
|
2077
2090
|
// src/reality/context/RealityContext.tsx
|
|
@@ -2101,7 +2114,8 @@ var ResourceRegistry = class {
|
|
|
2101
2114
|
removeAndDestroy(id) {
|
|
2102
2115
|
const p = this.resources.get(id);
|
|
2103
2116
|
if (p) {
|
|
2104
|
-
p.then((spatialObj) => spatialObj.destroy())
|
|
2117
|
+
p.then((spatialObj) => spatialObj.destroy()).catch(() => {
|
|
2118
|
+
});
|
|
2105
2119
|
}
|
|
2106
2120
|
this.resources.delete(id);
|
|
2107
2121
|
}
|
|
@@ -2111,7 +2125,10 @@ var ResourceRegistry = class {
|
|
|
2111
2125
|
destroy() {
|
|
2112
2126
|
const pending = Array.from(this.resources.values());
|
|
2113
2127
|
this.resources.clear();
|
|
2114
|
-
pending.forEach(
|
|
2128
|
+
pending.forEach(
|
|
2129
|
+
(promise) => promise.then((spatialObj) => spatialObj.destroy()).catch(() => {
|
|
2130
|
+
})
|
|
2131
|
+
);
|
|
2115
2132
|
}
|
|
2116
2133
|
};
|
|
2117
2134
|
|
|
@@ -2182,7 +2199,7 @@ function useEntityTransform(entity, { position, rotation, scale }) {
|
|
|
2182
2199
|
}
|
|
2183
2200
|
|
|
2184
2201
|
// src/reality/hooks/useEntityEvent.tsx
|
|
2185
|
-
import { useEffect as
|
|
2202
|
+
import { useEffect as useEffect17, useRef as useRef7 } from "react";
|
|
2186
2203
|
|
|
2187
2204
|
// src/reality/type.ts
|
|
2188
2205
|
var eventMap = {
|
|
@@ -2202,42 +2219,161 @@ var eventMap = {
|
|
|
2202
2219
|
onSpatialMagnifyEnd: "spatialmagnifyend"
|
|
2203
2220
|
};
|
|
2204
2221
|
|
|
2222
|
+
// src/reality/hooks/useEntityRef.tsx
|
|
2223
|
+
import { useImperativeHandle } from "react";
|
|
2224
|
+
var useEntityRef = (ref, instance) => {
|
|
2225
|
+
useImperativeHandle(ref, () => instance);
|
|
2226
|
+
};
|
|
2227
|
+
var EntityRef = class {
|
|
2228
|
+
_entity;
|
|
2229
|
+
_ctx;
|
|
2230
|
+
constructor(entity = null, ctx = null) {
|
|
2231
|
+
this._entity = entity;
|
|
2232
|
+
this._ctx = ctx;
|
|
2233
|
+
}
|
|
2234
|
+
updateEntity(entity) {
|
|
2235
|
+
if (entity) this._entity = entity;
|
|
2236
|
+
}
|
|
2237
|
+
updateCtx(ctx) {
|
|
2238
|
+
if (ctx) this._ctx = ctx;
|
|
2239
|
+
}
|
|
2240
|
+
destroy() {
|
|
2241
|
+
this._entity?.destroy();
|
|
2242
|
+
}
|
|
2243
|
+
get entity() {
|
|
2244
|
+
return this._entity;
|
|
2245
|
+
}
|
|
2246
|
+
get id() {
|
|
2247
|
+
return this._entity?.userData?.id;
|
|
2248
|
+
}
|
|
2249
|
+
get name() {
|
|
2250
|
+
return this._entity?.userData?.name;
|
|
2251
|
+
}
|
|
2252
|
+
async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
|
|
2253
|
+
if (!this._entity) return position;
|
|
2254
|
+
try {
|
|
2255
|
+
const fromEnt = await this._ctx?.resourceRegistry.get(fromEntityId);
|
|
2256
|
+
const toEnt = await this._ctx?.resourceRegistry.get(toEntityId);
|
|
2257
|
+
if (!fromEnt || !toEnt) return position;
|
|
2258
|
+
const ret = await this._entity.convertFromEntityToEntity(
|
|
2259
|
+
fromEnt.id,
|
|
2260
|
+
toEnt.id,
|
|
2261
|
+
position
|
|
2262
|
+
);
|
|
2263
|
+
return ret?.data ?? position;
|
|
2264
|
+
} catch {
|
|
2265
|
+
return position;
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
async convertFromEntityToReality(entityId, position) {
|
|
2269
|
+
if (!this._entity) return position;
|
|
2270
|
+
try {
|
|
2271
|
+
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2272
|
+
if (!ent) return position;
|
|
2273
|
+
const ret = await this._entity.convertFromEntityToScene(ent.id, position);
|
|
2274
|
+
return ret?.data ?? position;
|
|
2275
|
+
} catch {
|
|
2276
|
+
return position;
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
async convertFromRealityToEntity(entityId, position) {
|
|
2280
|
+
if (!this._entity) return position;
|
|
2281
|
+
try {
|
|
2282
|
+
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2283
|
+
if (!ent) return position;
|
|
2284
|
+
const ret = await this._entity.convertFromSceneToEntity(ent.id, position);
|
|
2285
|
+
return ret?.data ?? position;
|
|
2286
|
+
} catch {
|
|
2287
|
+
return position;
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
};
|
|
2291
|
+
|
|
2205
2292
|
// src/reality/hooks/useEntityEvent.tsx
|
|
2206
2293
|
function createEventProxy2(ev, instance) {
|
|
2207
2294
|
return new Proxy(ev, {
|
|
2208
2295
|
get(target, prop) {
|
|
2209
|
-
if (prop === "
|
|
2296
|
+
if (prop === "currentTarget") {
|
|
2210
2297
|
return instance;
|
|
2211
2298
|
}
|
|
2299
|
+
if (prop === "target") {
|
|
2300
|
+
const origin = target.__origin;
|
|
2301
|
+
if (origin) {
|
|
2302
|
+
return new EntityRef(origin, null);
|
|
2303
|
+
}
|
|
2304
|
+
return instance;
|
|
2305
|
+
}
|
|
2306
|
+
if (prop === "bubbles") {
|
|
2307
|
+
return true;
|
|
2308
|
+
}
|
|
2309
|
+
if (prop === "offsetX") {
|
|
2310
|
+
const type = target.type;
|
|
2311
|
+
if (type === "spatialtap") {
|
|
2312
|
+
return target.detail?.location3D?.x ?? 0;
|
|
2313
|
+
}
|
|
2314
|
+
if (type === "spatialdragstart") {
|
|
2315
|
+
return target.detail?.startLocation3D?.x ?? 0;
|
|
2316
|
+
}
|
|
2317
|
+
return void 0;
|
|
2318
|
+
}
|
|
2319
|
+
if (prop === "offsetY") {
|
|
2320
|
+
const type = target.type;
|
|
2321
|
+
if (type === "spatialtap") {
|
|
2322
|
+
return target.detail?.location3D?.y ?? 0;
|
|
2323
|
+
}
|
|
2324
|
+
if (type === "spatialdragstart") {
|
|
2325
|
+
return target.detail?.startLocation3D?.y ?? 0;
|
|
2326
|
+
}
|
|
2327
|
+
return void 0;
|
|
2328
|
+
}
|
|
2329
|
+
if (prop === "offsetZ") {
|
|
2330
|
+
const type = target.type;
|
|
2331
|
+
if (type === "spatialtap") {
|
|
2332
|
+
return target.detail?.location3D?.z ?? 0;
|
|
2333
|
+
}
|
|
2334
|
+
if (type === "spatialdragstart") {
|
|
2335
|
+
return target.detail?.startLocation3D?.z ?? 0;
|
|
2336
|
+
}
|
|
2337
|
+
return void 0;
|
|
2338
|
+
}
|
|
2212
2339
|
const val = target[prop];
|
|
2213
2340
|
return typeof val === "function" ? val.bind(target) : val;
|
|
2214
2341
|
}
|
|
2215
2342
|
});
|
|
2216
2343
|
}
|
|
2217
2344
|
var useEntityEvent = ({ instance, ...handlers }) => {
|
|
2218
|
-
|
|
2345
|
+
const eventsSetRef = useRef7(/* @__PURE__ */ new Set());
|
|
2346
|
+
useEffect17(() => {
|
|
2219
2347
|
const entity = instance.entity;
|
|
2220
2348
|
if (!entity) return;
|
|
2221
|
-
const boundHandlers = [];
|
|
2222
2349
|
Object.entries(eventMap).forEach(([reactKey, spatialEvent]) => {
|
|
2223
2350
|
const handlerFn = handlers[reactKey];
|
|
2224
2351
|
if (!handlerFn) return;
|
|
2225
2352
|
const wrapped = (ev) => handlerFn(createEventProxy2(ev, instance));
|
|
2226
2353
|
entity.addEvent(spatialEvent, wrapped);
|
|
2227
|
-
|
|
2354
|
+
eventsSetRef.current.add(reactKey);
|
|
2228
2355
|
});
|
|
2229
2356
|
return () => {
|
|
2230
|
-
boundHandlers.forEach((unbind) => unbind());
|
|
2231
2357
|
};
|
|
2232
2358
|
}, [instance.entity, ...Object.values(handlers)]);
|
|
2359
|
+
useEffect17(() => {
|
|
2360
|
+
const entity = instance.entity;
|
|
2361
|
+
if (!entity) return;
|
|
2362
|
+
return () => {
|
|
2363
|
+
for (let x of eventsSetRef.current) {
|
|
2364
|
+
entity.removeEvent(x);
|
|
2365
|
+
}
|
|
2366
|
+
eventsSetRef.current.clear();
|
|
2367
|
+
};
|
|
2368
|
+
}, [instance.entity]);
|
|
2233
2369
|
return null;
|
|
2234
2370
|
};
|
|
2235
2371
|
|
|
2236
2372
|
// src/reality/hooks/useEntityId.tsx
|
|
2237
|
-
import { useEffect as
|
|
2373
|
+
import { useEffect as useEffect18 } from "react";
|
|
2238
2374
|
var useEntityId = ({ id, entity }) => {
|
|
2239
2375
|
const ctx = useRealityContext();
|
|
2240
|
-
|
|
2376
|
+
useEffect18(() => {
|
|
2241
2377
|
if (!id || !entity || !ctx) return;
|
|
2242
2378
|
ctx.resourceRegistry.add(id, Promise.resolve(entity));
|
|
2243
2379
|
return () => {
|
|
@@ -2248,7 +2384,7 @@ var useEntityId = ({ id, entity }) => {
|
|
|
2248
2384
|
};
|
|
2249
2385
|
|
|
2250
2386
|
// src/reality/hooks/useEntity.tsx
|
|
2251
|
-
import { useEffect as
|
|
2387
|
+
import { useEffect as useEffect19, useRef as useRef8 } from "react";
|
|
2252
2388
|
var useEntity = ({
|
|
2253
2389
|
ref,
|
|
2254
2390
|
id,
|
|
@@ -2259,10 +2395,10 @@ var useEntity = ({
|
|
|
2259
2395
|
onSpatialDragStart,
|
|
2260
2396
|
onSpatialDrag,
|
|
2261
2397
|
onSpatialDragEnd,
|
|
2262
|
-
onSpatialRotateStart,
|
|
2398
|
+
// onSpatialRotateStart,
|
|
2263
2399
|
onSpatialRotate,
|
|
2264
2400
|
onSpatialRotateEnd,
|
|
2265
|
-
onSpatialMagnifyStart,
|
|
2401
|
+
// onSpatialMagnifyStart,
|
|
2266
2402
|
onSpatialMagnify,
|
|
2267
2403
|
onSpatialMagnifyEnd,
|
|
2268
2404
|
// TODO: add other event handlers
|
|
@@ -2270,9 +2406,9 @@ var useEntity = ({
|
|
|
2270
2406
|
}) => {
|
|
2271
2407
|
const ctx = useRealityContext();
|
|
2272
2408
|
const parent = useParentContext();
|
|
2273
|
-
const instanceRef =
|
|
2409
|
+
const instanceRef = useRef8(new EntityRef(null, ctx));
|
|
2274
2410
|
const forceUpdate = useForceUpdate2();
|
|
2275
|
-
|
|
2411
|
+
useEffect19(() => {
|
|
2276
2412
|
if (!ctx) return;
|
|
2277
2413
|
const controller = new AbortController();
|
|
2278
2414
|
const init = async () => {
|
|
@@ -2311,86 +2447,16 @@ var useEntity = ({
|
|
|
2311
2447
|
onSpatialDragStart,
|
|
2312
2448
|
onSpatialDrag,
|
|
2313
2449
|
onSpatialDragEnd,
|
|
2314
|
-
onSpatialRotateStart,
|
|
2450
|
+
// onSpatialRotateStart,
|
|
2315
2451
|
onSpatialRotate,
|
|
2316
2452
|
onSpatialRotateEnd,
|
|
2317
|
-
onSpatialMagnifyStart,
|
|
2453
|
+
// onSpatialMagnifyStart,
|
|
2318
2454
|
onSpatialMagnify,
|
|
2319
2455
|
onSpatialMagnifyEnd
|
|
2320
2456
|
});
|
|
2321
2457
|
return instanceRef.current.entity;
|
|
2322
2458
|
};
|
|
2323
2459
|
|
|
2324
|
-
// src/reality/hooks/useEntityRef.tsx
|
|
2325
|
-
import { useImperativeHandle } from "react";
|
|
2326
|
-
var useEntityRef = (ref, instance) => {
|
|
2327
|
-
useImperativeHandle(ref, () => instance);
|
|
2328
|
-
};
|
|
2329
|
-
var EntityRef = class {
|
|
2330
|
-
_entity;
|
|
2331
|
-
_ctx;
|
|
2332
|
-
constructor(entity = null, ctx = null) {
|
|
2333
|
-
this._entity = entity;
|
|
2334
|
-
this._ctx = ctx;
|
|
2335
|
-
}
|
|
2336
|
-
updateEntity(entity) {
|
|
2337
|
-
if (entity) this._entity = entity;
|
|
2338
|
-
}
|
|
2339
|
-
updateCtx(ctx) {
|
|
2340
|
-
if (ctx) this._ctx = ctx;
|
|
2341
|
-
}
|
|
2342
|
-
destroy() {
|
|
2343
|
-
this._entity?.destroy();
|
|
2344
|
-
}
|
|
2345
|
-
get entity() {
|
|
2346
|
-
return this._entity;
|
|
2347
|
-
}
|
|
2348
|
-
get id() {
|
|
2349
|
-
return this._entity?.userData?.id;
|
|
2350
|
-
}
|
|
2351
|
-
get name() {
|
|
2352
|
-
return this._entity?.userData?.name;
|
|
2353
|
-
}
|
|
2354
|
-
async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
|
|
2355
|
-
if (!this._entity) return position;
|
|
2356
|
-
try {
|
|
2357
|
-
const fromEnt = await this._ctx?.resourceRegistry.get(fromEntityId);
|
|
2358
|
-
const toEnt = await this._ctx?.resourceRegistry.get(toEntityId);
|
|
2359
|
-
if (!fromEnt || !toEnt) return position;
|
|
2360
|
-
const ret = await this._entity.convertFromEntityToEntity(
|
|
2361
|
-
fromEnt.id,
|
|
2362
|
-
toEnt.id,
|
|
2363
|
-
position
|
|
2364
|
-
);
|
|
2365
|
-
return ret?.data ?? position;
|
|
2366
|
-
} catch {
|
|
2367
|
-
return position;
|
|
2368
|
-
}
|
|
2369
|
-
}
|
|
2370
|
-
async convertFromEntityToReality(entityId, position) {
|
|
2371
|
-
if (!this._entity) return position;
|
|
2372
|
-
try {
|
|
2373
|
-
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2374
|
-
if (!ent) return position;
|
|
2375
|
-
const ret = await this._entity.convertFromEntityToScene(ent.id, position);
|
|
2376
|
-
return ret?.data ?? position;
|
|
2377
|
-
} catch {
|
|
2378
|
-
return position;
|
|
2379
|
-
}
|
|
2380
|
-
}
|
|
2381
|
-
async convertFromRealityToEntity(entityId, position) {
|
|
2382
|
-
if (!this._entity) return position;
|
|
2383
|
-
try {
|
|
2384
|
-
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2385
|
-
if (!ent) return position;
|
|
2386
|
-
const ret = await this._entity.convertFromSceneToEntity(ent.id, position);
|
|
2387
|
-
return ret?.data ?? position;
|
|
2388
|
-
} catch {
|
|
2389
|
-
return position;
|
|
2390
|
-
}
|
|
2391
|
-
}
|
|
2392
|
-
};
|
|
2393
|
-
|
|
2394
2460
|
// src/reality/hooks/useForceUpdate.tsx
|
|
2395
2461
|
import { useCallback as useCallback7, useState as useState7 } from "react";
|
|
2396
2462
|
var useForceUpdate2 = () => {
|
|
@@ -2398,108 +2464,88 @@ var useForceUpdate2 = () => {
|
|
|
2398
2464
|
return useCallback7(() => setTick((tick) => tick + 1), []);
|
|
2399
2465
|
};
|
|
2400
2466
|
|
|
2401
|
-
// src/reality/components/
|
|
2467
|
+
// src/reality/components/BaseEntity.tsx
|
|
2402
2468
|
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
2403
|
-
var
|
|
2404
|
-
({
|
|
2469
|
+
var BaseEntity = forwardRef10(
|
|
2470
|
+
({ children, createEntity, ...rest }, ref) => {
|
|
2405
2471
|
const ctx = useRealityContext();
|
|
2406
2472
|
const entity = useEntity({
|
|
2473
|
+
...rest,
|
|
2407
2474
|
ref,
|
|
2408
|
-
|
|
2409
|
-
position,
|
|
2410
|
-
rotation,
|
|
2411
|
-
scale,
|
|
2412
|
-
onSpatialTap,
|
|
2413
|
-
createEntity: async () => ctx.session.createEntity({ id, name })
|
|
2475
|
+
createEntity: (signal) => createEntity(ctx, signal)
|
|
2414
2476
|
});
|
|
2415
2477
|
if (!entity) return null;
|
|
2416
2478
|
return /* @__PURE__ */ jsx12(ParentContext.Provider, { value: entity, children });
|
|
2417
2479
|
}
|
|
2418
2480
|
);
|
|
2419
2481
|
|
|
2482
|
+
// src/reality/components/Entity.tsx
|
|
2483
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
2484
|
+
var Entity = forwardRef11((props, ref) => {
|
|
2485
|
+
const { id, name, children, ...rest } = props;
|
|
2486
|
+
return /* @__PURE__ */ jsx13(
|
|
2487
|
+
BaseEntity,
|
|
2488
|
+
{
|
|
2489
|
+
...rest,
|
|
2490
|
+
id,
|
|
2491
|
+
ref,
|
|
2492
|
+
createEntity: async (ctxVal) => ctxVal.session.createEntity({ id, name }),
|
|
2493
|
+
children
|
|
2494
|
+
}
|
|
2495
|
+
);
|
|
2496
|
+
});
|
|
2497
|
+
|
|
2420
2498
|
// src/reality/components/BoxEntity.tsx
|
|
2421
|
-
import { forwardRef as
|
|
2499
|
+
import { forwardRef as forwardRef13 } from "react";
|
|
2422
2500
|
|
|
2423
2501
|
// src/reality/components/GeometryEntity.tsx
|
|
2424
|
-
import { forwardRef as
|
|
2425
|
-
import { jsx as
|
|
2426
|
-
var GeometryEntity =
|
|
2427
|
-
({
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
onSpatialRotateStart,
|
|
2461
|
-
onSpatialRotate,
|
|
2462
|
-
onSpatialRotateEnd,
|
|
2463
|
-
onSpatialMagnifyStart,
|
|
2464
|
-
onSpatialMagnify,
|
|
2465
|
-
onSpatialMagnifyEnd,
|
|
2466
|
-
createEntity: async (signal) => {
|
|
2467
|
-
const manager = new AbortResourceManager(signal);
|
|
2468
|
-
try {
|
|
2469
|
-
const ent = await manager.addResource(
|
|
2470
|
-
() => ctx.session.createEntity({ id, name })
|
|
2471
|
-
);
|
|
2472
|
-
const geometry = await manager.addResource(
|
|
2473
|
-
() => createGeometry(geometryOptions)
|
|
2474
|
-
);
|
|
2475
|
-
const materialList = await Promise.all(
|
|
2476
|
-
materials?.map((id2) => ctx.resourceRegistry.get(id2)).filter(Boolean) ?? []
|
|
2477
|
-
);
|
|
2478
|
-
const modelComponent = await manager.addResource(
|
|
2479
|
-
() => ctx.session.createModelComponent({
|
|
2480
|
-
mesh: geometry,
|
|
2481
|
-
materials: materialList
|
|
2482
|
-
})
|
|
2483
|
-
);
|
|
2484
|
-
await ent.addComponent(modelComponent);
|
|
2485
|
-
return ent;
|
|
2486
|
-
} catch (error) {
|
|
2487
|
-
await manager.dispose();
|
|
2488
|
-
return null;
|
|
2489
|
-
}
|
|
2502
|
+
import { forwardRef as forwardRef12 } from "react";
|
|
2503
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
2504
|
+
var GeometryEntity = forwardRef12(
|
|
2505
|
+
({ id, children, name, materials, geometryOptions, createGeometry, ...rest }, ref) => {
|
|
2506
|
+
return /* @__PURE__ */ jsx14(
|
|
2507
|
+
BaseEntity,
|
|
2508
|
+
{
|
|
2509
|
+
...rest,
|
|
2510
|
+
id,
|
|
2511
|
+
ref,
|
|
2512
|
+
createEntity: async (ctx, signal) => {
|
|
2513
|
+
const manager = new AbortResourceManager(signal);
|
|
2514
|
+
try {
|
|
2515
|
+
const ent = await manager.addResource(
|
|
2516
|
+
() => ctx.session.createEntity({ id, name })
|
|
2517
|
+
);
|
|
2518
|
+
const geometry = await manager.addResource(
|
|
2519
|
+
() => createGeometry(geometryOptions)
|
|
2520
|
+
);
|
|
2521
|
+
const materialList = await Promise.all(
|
|
2522
|
+
materials?.map((id2) => ctx.resourceRegistry.get(id2)).filter(Boolean) ?? []
|
|
2523
|
+
);
|
|
2524
|
+
const modelComponent = await manager.addResource(
|
|
2525
|
+
() => ctx.session.createModelComponent({
|
|
2526
|
+
mesh: geometry,
|
|
2527
|
+
materials: materialList
|
|
2528
|
+
})
|
|
2529
|
+
);
|
|
2530
|
+
await ent.addComponent(modelComponent);
|
|
2531
|
+
return ent;
|
|
2532
|
+
} catch (error) {
|
|
2533
|
+
await manager.dispose();
|
|
2534
|
+
return null;
|
|
2535
|
+
}
|
|
2536
|
+
},
|
|
2537
|
+
children
|
|
2490
2538
|
}
|
|
2491
|
-
|
|
2492
|
-
if (!entity) return null;
|
|
2493
|
-
return /* @__PURE__ */ jsx13(ParentContext.Provider, { value: entity, children });
|
|
2539
|
+
);
|
|
2494
2540
|
}
|
|
2495
2541
|
);
|
|
2496
2542
|
|
|
2497
2543
|
// src/reality/components/BoxEntity.tsx
|
|
2498
|
-
import { jsx as
|
|
2499
|
-
var BoxEntity =
|
|
2544
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
2545
|
+
var BoxEntity = forwardRef13(
|
|
2500
2546
|
({ children, ...props }, ref) => {
|
|
2501
2547
|
const ctx = useRealityContext();
|
|
2502
|
-
return /* @__PURE__ */
|
|
2548
|
+
return /* @__PURE__ */ jsx15(
|
|
2503
2549
|
GeometryEntity,
|
|
2504
2550
|
{
|
|
2505
2551
|
...props,
|
|
@@ -2519,10 +2565,10 @@ var BoxEntity = forwardRef12(
|
|
|
2519
2565
|
);
|
|
2520
2566
|
|
|
2521
2567
|
// src/reality/components/UnlitMaterial.tsx
|
|
2522
|
-
import { useEffect as useEffect20, useRef as
|
|
2568
|
+
import { useEffect as useEffect20, useRef as useRef9 } from "react";
|
|
2523
2569
|
var UnlitMaterial = ({ children, ...options }) => {
|
|
2524
2570
|
const ctx = useRealityContext();
|
|
2525
|
-
const materialRef =
|
|
2571
|
+
const materialRef = useRef9();
|
|
2526
2572
|
useEffect20(() => {
|
|
2527
2573
|
if (!ctx) return;
|
|
2528
2574
|
const { session, reality, resourceRegistry } = ctx;
|
|
@@ -2545,12 +2591,12 @@ var UnlitMaterial = ({ children, ...options }) => {
|
|
|
2545
2591
|
};
|
|
2546
2592
|
|
|
2547
2593
|
// src/reality/components/SphereEntity.tsx
|
|
2548
|
-
import { forwardRef as
|
|
2549
|
-
import { jsx as
|
|
2550
|
-
var SphereEntity =
|
|
2594
|
+
import { forwardRef as forwardRef14 } from "react";
|
|
2595
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
2596
|
+
var SphereEntity = forwardRef14(
|
|
2551
2597
|
({ children, ...props }, ref) => {
|
|
2552
2598
|
const ctx = useRealityContext();
|
|
2553
|
-
return /* @__PURE__ */
|
|
2599
|
+
return /* @__PURE__ */ jsx16(
|
|
2554
2600
|
GeometryEntity,
|
|
2555
2601
|
{
|
|
2556
2602
|
...props,
|
|
@@ -2566,12 +2612,12 @@ var SphereEntity = forwardRef13(
|
|
|
2566
2612
|
);
|
|
2567
2613
|
|
|
2568
2614
|
// src/reality/components/ConeEntity.tsx
|
|
2569
|
-
import { forwardRef as
|
|
2570
|
-
import { jsx as
|
|
2571
|
-
var ConeEntity =
|
|
2615
|
+
import { forwardRef as forwardRef15 } from "react";
|
|
2616
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
2617
|
+
var ConeEntity = forwardRef15(
|
|
2572
2618
|
({ children, ...props }, ref) => {
|
|
2573
2619
|
const ctx = useRealityContext();
|
|
2574
|
-
return /* @__PURE__ */
|
|
2620
|
+
return /* @__PURE__ */ jsx17(
|
|
2575
2621
|
GeometryEntity,
|
|
2576
2622
|
{
|
|
2577
2623
|
...props,
|
|
@@ -2588,12 +2634,12 @@ var ConeEntity = forwardRef14(
|
|
|
2588
2634
|
);
|
|
2589
2635
|
|
|
2590
2636
|
// src/reality/components/CylinderEntity.tsx
|
|
2591
|
-
import { forwardRef as
|
|
2592
|
-
import { jsx as
|
|
2593
|
-
var CylinderEntity =
|
|
2637
|
+
import { forwardRef as forwardRef16 } from "react";
|
|
2638
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
2639
|
+
var CylinderEntity = forwardRef16(
|
|
2594
2640
|
({ children, ...props }, ref) => {
|
|
2595
2641
|
const ctx = useRealityContext();
|
|
2596
|
-
return /* @__PURE__ */
|
|
2642
|
+
return /* @__PURE__ */ jsx18(
|
|
2597
2643
|
GeometryEntity,
|
|
2598
2644
|
{
|
|
2599
2645
|
...props,
|
|
@@ -2610,12 +2656,12 @@ var CylinderEntity = forwardRef15(
|
|
|
2610
2656
|
);
|
|
2611
2657
|
|
|
2612
2658
|
// src/reality/components/PlaneEntity.tsx
|
|
2613
|
-
import { forwardRef as
|
|
2614
|
-
import { jsx as
|
|
2615
|
-
var PlaneEntity =
|
|
2659
|
+
import { forwardRef as forwardRef17 } from "react";
|
|
2660
|
+
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
2661
|
+
var PlaneEntity = forwardRef17(
|
|
2616
2662
|
({ children, ...props }, ref) => {
|
|
2617
2663
|
const ctx = useRealityContext();
|
|
2618
|
-
return /* @__PURE__ */
|
|
2664
|
+
return /* @__PURE__ */ jsx19(
|
|
2619
2665
|
GeometryEntity,
|
|
2620
2666
|
{
|
|
2621
2667
|
...props,
|
|
@@ -2633,13 +2679,13 @@ var PlaneEntity = forwardRef16(
|
|
|
2633
2679
|
);
|
|
2634
2680
|
|
|
2635
2681
|
// src/reality/components/SceneGraph.tsx
|
|
2636
|
-
import { jsx as
|
|
2682
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
2637
2683
|
var SceneGraph = ({ children }) => {
|
|
2638
|
-
return /* @__PURE__ */
|
|
2684
|
+
return /* @__PURE__ */ jsx20(ParentContext.Provider, { value: null, children });
|
|
2639
2685
|
};
|
|
2640
2686
|
|
|
2641
2687
|
// src/reality/components/ModelAsset.tsx
|
|
2642
|
-
import { useEffect as useEffect21, useRef as
|
|
2688
|
+
import { useEffect as useEffect21, useRef as useRef10 } from "react";
|
|
2643
2689
|
var resolveAssetUrl = (url) => {
|
|
2644
2690
|
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
2645
2691
|
return url;
|
|
@@ -2648,16 +2694,16 @@ var resolveAssetUrl = (url) => {
|
|
|
2648
2694
|
};
|
|
2649
2695
|
var ModelAsset = ({ children, ...options }) => {
|
|
2650
2696
|
const ctx = useRealityContext();
|
|
2651
|
-
const materialRef =
|
|
2697
|
+
const materialRef = useRef10();
|
|
2652
2698
|
useEffect21(() => {
|
|
2653
2699
|
const controller = new AbortController();
|
|
2654
2700
|
if (!ctx) return;
|
|
2655
2701
|
const { session, reality, resourceRegistry } = ctx;
|
|
2656
2702
|
const init = async () => {
|
|
2657
|
-
const resolvedUrl = resolveAssetUrl(options.src);
|
|
2658
|
-
const modelAssetPromise = session.createModelAsset({ url: resolvedUrl });
|
|
2659
|
-
resourceRegistry.add(options.id, modelAssetPromise);
|
|
2660
2703
|
try {
|
|
2704
|
+
const resolvedUrl = resolveAssetUrl(options.src);
|
|
2705
|
+
const modelAssetPromise = session.createModelAsset({ url: resolvedUrl });
|
|
2706
|
+
resourceRegistry.add(options.id, modelAssetPromise);
|
|
2661
2707
|
const mat = await modelAssetPromise;
|
|
2662
2708
|
if (controller.signal.aborted) {
|
|
2663
2709
|
mat.destroy();
|
|
@@ -2679,57 +2725,63 @@ var ModelAsset = ({ children, ...options }) => {
|
|
|
2679
2725
|
};
|
|
2680
2726
|
|
|
2681
2727
|
// src/reality/components/ModelEntity.tsx
|
|
2682
|
-
import { forwardRef as
|
|
2683
|
-
import { jsx as
|
|
2684
|
-
var ModelEntity =
|
|
2685
|
-
({ id, model,
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2728
|
+
import { forwardRef as forwardRef18 } from "react";
|
|
2729
|
+
import { jsx as jsx21 } from "react/jsx-runtime";
|
|
2730
|
+
var ModelEntity = forwardRef18(
|
|
2731
|
+
({ id, model, children, name, ...rest }, ref) => {
|
|
2732
|
+
return /* @__PURE__ */ jsx21(
|
|
2733
|
+
BaseEntity,
|
|
2734
|
+
{
|
|
2735
|
+
...rest,
|
|
2736
|
+
id,
|
|
2737
|
+
ref,
|
|
2738
|
+
createEntity: async (ctx, signal) => {
|
|
2739
|
+
try {
|
|
2740
|
+
const modelAsset = await ctx.resourceRegistry.get(model);
|
|
2741
|
+
if (!modelAsset)
|
|
2742
|
+
throw new Error(`ModelEntity: model not found ${model}`);
|
|
2743
|
+
if (signal.aborted) return null;
|
|
2744
|
+
return ctx.session.createSpatialModelEntity(
|
|
2745
|
+
{
|
|
2746
|
+
modelAssetId: modelAsset.id,
|
|
2747
|
+
name
|
|
2748
|
+
},
|
|
2749
|
+
{ id, name }
|
|
2750
|
+
);
|
|
2751
|
+
} catch (error) {
|
|
2700
2752
|
return null;
|
|
2701
2753
|
}
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
modelAssetId: modelAsset.id,
|
|
2705
|
-
name
|
|
2706
|
-
},
|
|
2707
|
-
{ id, name }
|
|
2708
|
-
);
|
|
2709
|
-
} catch (error) {
|
|
2710
|
-
console.error("ModelEntity error:", error);
|
|
2711
|
-
return null;
|
|
2712
|
-
}
|
|
2754
|
+
},
|
|
2755
|
+
children
|
|
2713
2756
|
}
|
|
2714
|
-
|
|
2715
|
-
if (!entity) return null;
|
|
2716
|
-
return /* @__PURE__ */ jsx20(ParentContext.Provider, { value: entity, children });
|
|
2757
|
+
);
|
|
2717
2758
|
}
|
|
2718
2759
|
);
|
|
2719
2760
|
|
|
2720
2761
|
// src/reality/components/Reality.tsx
|
|
2721
2762
|
import {
|
|
2722
|
-
forwardRef as
|
|
2763
|
+
forwardRef as forwardRef19,
|
|
2723
2764
|
useCallback as useCallback8,
|
|
2724
2765
|
useEffect as useEffect22,
|
|
2725
|
-
useRef as
|
|
2766
|
+
useRef as useRef11,
|
|
2726
2767
|
useState as useState8
|
|
2727
2768
|
} from "react";
|
|
2728
|
-
import { Fragment as Fragment3, jsx as
|
|
2729
|
-
var Reality =
|
|
2730
|
-
function RealityBase({ children, ...
|
|
2731
|
-
const
|
|
2732
|
-
|
|
2769
|
+
import { Fragment as Fragment3, jsx as jsx22, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2770
|
+
var Reality = forwardRef19(
|
|
2771
|
+
function RealityBase({ children, ...inProps }, ref) {
|
|
2772
|
+
const {
|
|
2773
|
+
onSpatialTap,
|
|
2774
|
+
onSpatialDragStart,
|
|
2775
|
+
onSpatialDrag,
|
|
2776
|
+
onSpatialDragEnd,
|
|
2777
|
+
onSpatialRotate,
|
|
2778
|
+
onSpatialRotateEnd,
|
|
2779
|
+
onSpatialMagnify,
|
|
2780
|
+
onSpatialMagnifyEnd,
|
|
2781
|
+
...props
|
|
2782
|
+
} = inProps;
|
|
2783
|
+
const ctxRef = useRef11(null);
|
|
2784
|
+
const creationId = useRef11(0);
|
|
2733
2785
|
const [isReady, setIsReady] = useState8(false);
|
|
2734
2786
|
const cleanupReality = useCallback8(() => {
|
|
2735
2787
|
ctxRef.current?.resourceRegistry.destroy();
|
|
@@ -2776,9 +2828,9 @@ var Reality = forwardRef18(
|
|
|
2776
2828
|
return null;
|
|
2777
2829
|
}
|
|
2778
2830
|
}, [cleanupReality]);
|
|
2779
|
-
const content = useCallback8(() => /* @__PURE__ */
|
|
2831
|
+
const content = useCallback8(() => /* @__PURE__ */ jsx22(Fragment3, {}), []);
|
|
2780
2832
|
return /* @__PURE__ */ jsxs3(RealityContext.Provider, { value: ctxRef.current, children: [
|
|
2781
|
-
/* @__PURE__ */
|
|
2833
|
+
/* @__PURE__ */ jsx22(
|
|
2782
2834
|
SpatializedContainer,
|
|
2783
2835
|
{
|
|
2784
2836
|
component: "div",
|
|
@@ -2794,9 +2846,9 @@ var Reality = forwardRef18(
|
|
|
2794
2846
|
);
|
|
2795
2847
|
|
|
2796
2848
|
// src/Model.tsx
|
|
2797
|
-
import { forwardRef as
|
|
2849
|
+
import { forwardRef as forwardRef20 } from "react";
|
|
2798
2850
|
import { Spatial as Spatial2 } from "@webspatial/core-sdk";
|
|
2799
|
-
import { jsx as
|
|
2851
|
+
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
2800
2852
|
var spatial2 = new Spatial2();
|
|
2801
2853
|
function ModelBase(props, ref) {
|
|
2802
2854
|
const { "enable-xr": enableXR, ...restProps } = props;
|
|
@@ -2806,23 +2858,21 @@ function ModelBase(props, ref) {
|
|
|
2806
2858
|
onSpatialDragStart,
|
|
2807
2859
|
onSpatialDrag,
|
|
2808
2860
|
onSpatialDragEnd,
|
|
2809
|
-
onSpatialRotateStart,
|
|
2810
2861
|
onSpatialRotate,
|
|
2811
2862
|
onSpatialRotateEnd,
|
|
2812
|
-
onSpatialMagnifyStart,
|
|
2813
2863
|
onSpatialMagnify,
|
|
2814
2864
|
onSpatialMagnifyEnd,
|
|
2815
2865
|
...modelProps
|
|
2816
2866
|
} = restProps;
|
|
2817
|
-
return /* @__PURE__ */
|
|
2867
|
+
return /* @__PURE__ */ jsx23("model", { ref, ...modelProps });
|
|
2818
2868
|
}
|
|
2819
|
-
return /* @__PURE__ */
|
|
2869
|
+
return /* @__PURE__ */ jsx23(SpatializedStatic3DElementContainer, { ref, ...restProps });
|
|
2820
2870
|
}
|
|
2821
|
-
var Model = withSSRSupported(
|
|
2871
|
+
var Model = withSSRSupported(forwardRef20(ModelBase));
|
|
2822
2872
|
Model.displayName = "Model";
|
|
2823
2873
|
|
|
2824
2874
|
// src/index.ts
|
|
2825
|
-
var version = "1.0
|
|
2875
|
+
var version = "1.2.0";
|
|
2826
2876
|
if (typeof window !== "undefined") {
|
|
2827
2877
|
initPolyfill();
|
|
2828
2878
|
}
|