@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/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.0
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.2.0"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "web"
|
|
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
|
|
|
@@ -1241,10 +1268,8 @@ function PortalSpatializedContainer(props) {
|
|
|
1241
1268
|
onSpatialDragStart,
|
|
1242
1269
|
onSpatialDrag,
|
|
1243
1270
|
onSpatialDragEnd,
|
|
1244
|
-
onSpatialRotateStart,
|
|
1245
1271
|
onSpatialRotate,
|
|
1246
1272
|
onSpatialRotateEnd,
|
|
1247
|
-
onSpatialMagnifyStart,
|
|
1248
1273
|
onSpatialMagnify,
|
|
1249
1274
|
onSpatialMagnifyEnd,
|
|
1250
1275
|
[SpatialID]: spatialId,
|
|
@@ -1318,16 +1343,6 @@ function PortalSpatializedContainer(props) {
|
|
|
1318
1343
|
spatializedElement.onSpatialDragStart = onSpatialDragStart;
|
|
1319
1344
|
}
|
|
1320
1345
|
}, [spatializedElement, onSpatialDragStart]);
|
|
1321
|
-
useEffect7(() => {
|
|
1322
|
-
if (spatializedElement) {
|
|
1323
|
-
spatializedElement.onSpatialRotateStart = onSpatialRotateStart;
|
|
1324
|
-
}
|
|
1325
|
-
}, [spatializedElement, onSpatialRotateStart]);
|
|
1326
|
-
useEffect7(() => {
|
|
1327
|
-
if (spatializedElement) {
|
|
1328
|
-
spatializedElement.onSpatialMagnifyStart = onSpatialMagnifyStart;
|
|
1329
|
-
}
|
|
1330
|
-
}, [spatializedElement, onSpatialMagnifyStart]);
|
|
1331
1346
|
return /* @__PURE__ */ jsxs(PortalInstanceContext.Provider, { value: portalInstanceObject, children: [
|
|
1332
1347
|
spatializedElement && portalInstanceObject.dom && /* @__PURE__ */ jsx3(Content, { spatializedElement, ...restProps }),
|
|
1333
1348
|
PlaceholderEl
|
|
@@ -1335,7 +1350,7 @@ function PortalSpatializedContainer(props) {
|
|
|
1335
1350
|
}
|
|
1336
1351
|
|
|
1337
1352
|
// src/spatialized-container/hooks/useSpatialEvents.ts
|
|
1338
|
-
function createEventProxy(event, currentTargetGetter) {
|
|
1353
|
+
function createEventProxy(event, currentTargetGetter, offsetXGetter, offsetYGetter, offsetZGetter) {
|
|
1339
1354
|
return new Proxy(event, {
|
|
1340
1355
|
get(target, prop) {
|
|
1341
1356
|
if (prop === "currentTarget") {
|
|
@@ -1344,20 +1359,41 @@ function createEventProxy(event, currentTargetGetter) {
|
|
|
1344
1359
|
if (prop === "isTrusted") {
|
|
1345
1360
|
return true;
|
|
1346
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
|
+
}
|
|
1347
1374
|
return Reflect.get(target, prop);
|
|
1348
1375
|
}
|
|
1349
1376
|
});
|
|
1350
1377
|
}
|
|
1351
|
-
function createEventHandler(handler, currentTargetGetter) {
|
|
1378
|
+
function createEventHandler(handler, currentTargetGetter, offsetXGetter, offsetYGetter, offsetZGetter) {
|
|
1352
1379
|
return handler ? (event) => {
|
|
1353
|
-
const proxyEvent = createEventProxy(
|
|
1380
|
+
const proxyEvent = createEventProxy(
|
|
1381
|
+
event,
|
|
1382
|
+
currentTargetGetter,
|
|
1383
|
+
offsetXGetter,
|
|
1384
|
+
offsetYGetter,
|
|
1385
|
+
offsetZGetter
|
|
1386
|
+
);
|
|
1354
1387
|
handler(proxyEvent);
|
|
1355
1388
|
} : void 0;
|
|
1356
1389
|
}
|
|
1357
1390
|
function useSpatialEventsBase(spatialEvents, currentTargetGetter) {
|
|
1358
1391
|
const onSpatialTap = createEventHandler(
|
|
1359
1392
|
spatialEvents.onSpatialTap,
|
|
1360
|
-
currentTargetGetter
|
|
1393
|
+
currentTargetGetter,
|
|
1394
|
+
(ev) => ev.detail?.location3D?.x,
|
|
1395
|
+
(ev) => ev.detail?.location3D?.y,
|
|
1396
|
+
(ev) => ev.detail?.location3D?.z
|
|
1361
1397
|
);
|
|
1362
1398
|
const onSpatialDrag = createEventHandler(
|
|
1363
1399
|
spatialEvents.onSpatialDrag,
|
|
@@ -1385,19 +1421,18 @@ function useSpatialEventsBase(spatialEvents, currentTargetGetter) {
|
|
|
1385
1421
|
);
|
|
1386
1422
|
const onSpatialDragStart = createEventHandler(
|
|
1387
1423
|
spatialEvents.onSpatialDragStart,
|
|
1388
|
-
currentTargetGetter
|
|
1424
|
+
currentTargetGetter,
|
|
1425
|
+
(ev) => ev.detail?.startLocation3D?.x,
|
|
1426
|
+
(ev) => ev.detail?.startLocation3D?.y,
|
|
1427
|
+
(ev) => ev.detail?.startLocation3D?.z
|
|
1389
1428
|
);
|
|
1390
|
-
const onSpatialRotateStart = createEventHandler(spatialEvents.onSpatialRotateStart, currentTargetGetter);
|
|
1391
|
-
const onSpatialMagnifyStart = createEventHandler(spatialEvents.onSpatialMagnifyStart, currentTargetGetter);
|
|
1392
1429
|
return {
|
|
1393
1430
|
onSpatialTap,
|
|
1394
1431
|
onSpatialDragStart,
|
|
1395
1432
|
onSpatialDrag,
|
|
1396
1433
|
onSpatialDragEnd,
|
|
1397
|
-
onSpatialRotateStart,
|
|
1398
1434
|
onSpatialRotate,
|
|
1399
1435
|
onSpatialRotateEnd,
|
|
1400
|
-
onSpatialMagnifyStart,
|
|
1401
1436
|
onSpatialMagnify,
|
|
1402
1437
|
onSpatialMagnifyEnd
|
|
1403
1438
|
};
|
|
@@ -1488,10 +1523,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1488
1523
|
onSpatialDragStart: onSpatialDragStart2,
|
|
1489
1524
|
onSpatialDrag: onSpatialDrag2,
|
|
1490
1525
|
onSpatialDragEnd: onSpatialDragEnd2,
|
|
1491
|
-
onSpatialRotateStart: onSpatialRotateStart2,
|
|
1492
1526
|
onSpatialRotate: onSpatialRotate2,
|
|
1493
1527
|
onSpatialRotateEnd: onSpatialRotateEnd2,
|
|
1494
|
-
onSpatialMagnifyStart: onSpatialMagnifyStart2,
|
|
1495
1528
|
onSpatialMagnify: onSpatialMagnify2,
|
|
1496
1529
|
onSpatialMagnifyEnd: onSpatialMagnifyEnd2,
|
|
1497
1530
|
extraRefProps: extraRefProps2,
|
|
@@ -1518,10 +1551,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1518
1551
|
onSpatialDragStart,
|
|
1519
1552
|
onSpatialDrag,
|
|
1520
1553
|
onSpatialDragEnd,
|
|
1521
|
-
onSpatialRotateStart,
|
|
1522
1554
|
onSpatialRotate,
|
|
1523
1555
|
onSpatialRotateEnd,
|
|
1524
|
-
onSpatialMagnifyStart,
|
|
1525
1556
|
onSpatialMagnify,
|
|
1526
1557
|
onSpatialMagnifyEnd,
|
|
1527
1558
|
extraRefProps,
|
|
@@ -1535,10 +1566,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1535
1566
|
onSpatialDragStart,
|
|
1536
1567
|
onSpatialDrag,
|
|
1537
1568
|
onSpatialDragEnd,
|
|
1538
|
-
onSpatialRotateStart,
|
|
1539
1569
|
onSpatialRotate,
|
|
1540
1570
|
onSpatialRotateEnd,
|
|
1541
|
-
onSpatialMagnifyStart,
|
|
1542
1571
|
onSpatialMagnify,
|
|
1543
1572
|
onSpatialMagnifyEnd
|
|
1544
1573
|
},
|
|
@@ -1604,10 +1633,8 @@ function SpatializedContainerBase(inprops, ref) {
|
|
|
1604
1633
|
onSpatialDragStart,
|
|
1605
1634
|
onSpatialDrag,
|
|
1606
1635
|
onSpatialDragEnd,
|
|
1607
|
-
onSpatialRotateStart,
|
|
1608
1636
|
onSpatialRotate,
|
|
1609
1637
|
onSpatialRotateEnd,
|
|
1610
|
-
onSpatialMagnifyStart,
|
|
1611
1638
|
onSpatialMagnify,
|
|
1612
1639
|
onSpatialMagnifyEnd
|
|
1613
1640
|
},
|
|
@@ -1836,10 +1863,11 @@ function getAbsoluteURL(url) {
|
|
|
1836
1863
|
if (!url) {
|
|
1837
1864
|
return "";
|
|
1838
1865
|
}
|
|
1839
|
-
|
|
1866
|
+
try {
|
|
1867
|
+
return new URL(url, document.baseURI).toString();
|
|
1868
|
+
} catch {
|
|
1840
1869
|
return url;
|
|
1841
1870
|
}
|
|
1842
|
-
return window.location.origin + url;
|
|
1843
1871
|
}
|
|
1844
1872
|
function createLoadEvent(type, targetGetter) {
|
|
1845
1873
|
const event = new CustomEvent(type, {
|
|
@@ -1908,37 +1936,12 @@ async function createSpatializedElement2() {
|
|
|
1908
1936
|
function SpatializedStatic3DElementContainerBase(props, ref) {
|
|
1909
1937
|
const extraRefProps = useCallback6(
|
|
1910
1938
|
(domProxy) => {
|
|
1911
|
-
|
|
1912
|
-
let needupdate = false;
|
|
1913
|
-
const triggerUpdate = () => {
|
|
1914
|
-
const spatializedElement = domProxy.__spatializedElement;
|
|
1915
|
-
spatializedElement.updateModelTransform(modelTransform);
|
|
1916
|
-
needupdate = false;
|
|
1917
|
-
};
|
|
1918
|
-
const domMatrixProxy = new Proxy(modelTransform, {
|
|
1919
|
-
get(target, prop, receiver) {
|
|
1920
|
-
const value = Reflect.get(target, prop, receiver);
|
|
1921
|
-
if (typeof value === "function") {
|
|
1922
|
-
return function(...args) {
|
|
1923
|
-
requestAnimationFrame(triggerUpdate);
|
|
1924
|
-
return value.apply(target, args);
|
|
1925
|
-
};
|
|
1926
|
-
} else {
|
|
1927
|
-
return value;
|
|
1928
|
-
}
|
|
1929
|
-
},
|
|
1930
|
-
set(target, prop, value) {
|
|
1931
|
-
const success = Reflect.set(target, prop, value);
|
|
1932
|
-
if (!needupdate) {
|
|
1933
|
-
needupdate = true;
|
|
1934
|
-
requestAnimationFrame(triggerUpdate);
|
|
1935
|
-
}
|
|
1936
|
-
return success;
|
|
1937
|
-
}
|
|
1938
|
-
});
|
|
1939
|
+
let modelTransform = new DOMMatrixReadOnly();
|
|
1939
1940
|
return {
|
|
1940
|
-
currentSrc
|
|
1941
|
-
|
|
1941
|
+
get currentSrc() {
|
|
1942
|
+
return getAbsoluteURL(props.src);
|
|
1943
|
+
},
|
|
1944
|
+
get ready() {
|
|
1942
1945
|
const spatializedElement = domProxy.__spatializedElement;
|
|
1943
1946
|
const promise = spatializedElement.ready.then((success) => {
|
|
1944
1947
|
if (success) {
|
|
@@ -1948,7 +1951,14 @@ function SpatializedStatic3DElementContainerBase(props, ref) {
|
|
|
1948
1951
|
});
|
|
1949
1952
|
return promise;
|
|
1950
1953
|
},
|
|
1951
|
-
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
|
+
}
|
|
1952
1962
|
};
|
|
1953
1963
|
},
|
|
1954
1964
|
[]
|
|
@@ -2113,6 +2123,9 @@ function withSpatialMonitor(El) {
|
|
|
2113
2123
|
}
|
|
2114
2124
|
|
|
2115
2125
|
// src/reality/components/Entity.tsx
|
|
2126
|
+
import { forwardRef as forwardRef11 } from "react";
|
|
2127
|
+
|
|
2128
|
+
// src/reality/components/BaseEntity.tsx
|
|
2116
2129
|
import { forwardRef as forwardRef10 } from "react";
|
|
2117
2130
|
|
|
2118
2131
|
// src/reality/context/RealityContext.tsx
|
|
@@ -2142,7 +2155,8 @@ var ResourceRegistry = class {
|
|
|
2142
2155
|
removeAndDestroy(id) {
|
|
2143
2156
|
const p = this.resources.get(id);
|
|
2144
2157
|
if (p) {
|
|
2145
|
-
p.then((spatialObj) => spatialObj.destroy())
|
|
2158
|
+
p.then((spatialObj) => spatialObj.destroy()).catch(() => {
|
|
2159
|
+
});
|
|
2146
2160
|
}
|
|
2147
2161
|
this.resources.delete(id);
|
|
2148
2162
|
}
|
|
@@ -2152,7 +2166,10 @@ var ResourceRegistry = class {
|
|
|
2152
2166
|
destroy() {
|
|
2153
2167
|
const pending = Array.from(this.resources.values());
|
|
2154
2168
|
this.resources.clear();
|
|
2155
|
-
pending.forEach(
|
|
2169
|
+
pending.forEach(
|
|
2170
|
+
(promise) => promise.then((spatialObj) => spatialObj.destroy()).catch(() => {
|
|
2171
|
+
})
|
|
2172
|
+
);
|
|
2156
2173
|
}
|
|
2157
2174
|
};
|
|
2158
2175
|
|
|
@@ -2223,7 +2240,7 @@ function useEntityTransform(entity, { position, rotation, scale }) {
|
|
|
2223
2240
|
}
|
|
2224
2241
|
|
|
2225
2242
|
// src/reality/hooks/useEntityEvent.tsx
|
|
2226
|
-
import { useEffect as
|
|
2243
|
+
import { useEffect as useEffect17, useRef as useRef7 } from "react";
|
|
2227
2244
|
|
|
2228
2245
|
// src/reality/type.ts
|
|
2229
2246
|
var eventMap = {
|
|
@@ -2243,42 +2260,161 @@ var eventMap = {
|
|
|
2243
2260
|
onSpatialMagnifyEnd: "spatialmagnifyend"
|
|
2244
2261
|
};
|
|
2245
2262
|
|
|
2263
|
+
// src/reality/hooks/useEntityRef.tsx
|
|
2264
|
+
import { useImperativeHandle } from "react";
|
|
2265
|
+
var useEntityRef = (ref, instance) => {
|
|
2266
|
+
useImperativeHandle(ref, () => instance);
|
|
2267
|
+
};
|
|
2268
|
+
var EntityRef = class {
|
|
2269
|
+
_entity;
|
|
2270
|
+
_ctx;
|
|
2271
|
+
constructor(entity = null, ctx = null) {
|
|
2272
|
+
this._entity = entity;
|
|
2273
|
+
this._ctx = ctx;
|
|
2274
|
+
}
|
|
2275
|
+
updateEntity(entity) {
|
|
2276
|
+
if (entity) this._entity = entity;
|
|
2277
|
+
}
|
|
2278
|
+
updateCtx(ctx) {
|
|
2279
|
+
if (ctx) this._ctx = ctx;
|
|
2280
|
+
}
|
|
2281
|
+
destroy() {
|
|
2282
|
+
this._entity?.destroy();
|
|
2283
|
+
}
|
|
2284
|
+
get entity() {
|
|
2285
|
+
return this._entity;
|
|
2286
|
+
}
|
|
2287
|
+
get id() {
|
|
2288
|
+
return this._entity?.userData?.id;
|
|
2289
|
+
}
|
|
2290
|
+
get name() {
|
|
2291
|
+
return this._entity?.userData?.name;
|
|
2292
|
+
}
|
|
2293
|
+
async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
|
|
2294
|
+
if (!this._entity) return position;
|
|
2295
|
+
try {
|
|
2296
|
+
const fromEnt = await this._ctx?.resourceRegistry.get(fromEntityId);
|
|
2297
|
+
const toEnt = await this._ctx?.resourceRegistry.get(toEntityId);
|
|
2298
|
+
if (!fromEnt || !toEnt) return position;
|
|
2299
|
+
const ret = await this._entity.convertFromEntityToEntity(
|
|
2300
|
+
fromEnt.id,
|
|
2301
|
+
toEnt.id,
|
|
2302
|
+
position
|
|
2303
|
+
);
|
|
2304
|
+
return ret?.data ?? position;
|
|
2305
|
+
} catch {
|
|
2306
|
+
return position;
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
async convertFromEntityToReality(entityId, position) {
|
|
2310
|
+
if (!this._entity) return position;
|
|
2311
|
+
try {
|
|
2312
|
+
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2313
|
+
if (!ent) return position;
|
|
2314
|
+
const ret = await this._entity.convertFromEntityToScene(ent.id, position);
|
|
2315
|
+
return ret?.data ?? position;
|
|
2316
|
+
} catch {
|
|
2317
|
+
return position;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
async convertFromRealityToEntity(entityId, position) {
|
|
2321
|
+
if (!this._entity) return position;
|
|
2322
|
+
try {
|
|
2323
|
+
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2324
|
+
if (!ent) return position;
|
|
2325
|
+
const ret = await this._entity.convertFromSceneToEntity(ent.id, position);
|
|
2326
|
+
return ret?.data ?? position;
|
|
2327
|
+
} catch {
|
|
2328
|
+
return position;
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
|
|
2246
2333
|
// src/reality/hooks/useEntityEvent.tsx
|
|
2247
2334
|
function createEventProxy2(ev, instance) {
|
|
2248
2335
|
return new Proxy(ev, {
|
|
2249
2336
|
get(target, prop) {
|
|
2250
|
-
if (prop === "
|
|
2337
|
+
if (prop === "currentTarget") {
|
|
2251
2338
|
return instance;
|
|
2252
2339
|
}
|
|
2340
|
+
if (prop === "target") {
|
|
2341
|
+
const origin = target.__origin;
|
|
2342
|
+
if (origin) {
|
|
2343
|
+
return new EntityRef(origin, null);
|
|
2344
|
+
}
|
|
2345
|
+
return instance;
|
|
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
|
+
}
|
|
2253
2380
|
const val = target[prop];
|
|
2254
2381
|
return typeof val === "function" ? val.bind(target) : val;
|
|
2255
2382
|
}
|
|
2256
2383
|
});
|
|
2257
2384
|
}
|
|
2258
2385
|
var useEntityEvent = ({ instance, ...handlers }) => {
|
|
2259
|
-
|
|
2386
|
+
const eventsSetRef = useRef7(/* @__PURE__ */ new Set());
|
|
2387
|
+
useEffect17(() => {
|
|
2260
2388
|
const entity = instance.entity;
|
|
2261
2389
|
if (!entity) return;
|
|
2262
|
-
const boundHandlers = [];
|
|
2263
2390
|
Object.entries(eventMap).forEach(([reactKey, spatialEvent]) => {
|
|
2264
2391
|
const handlerFn = handlers[reactKey];
|
|
2265
2392
|
if (!handlerFn) return;
|
|
2266
2393
|
const wrapped = (ev) => handlerFn(createEventProxy2(ev, instance));
|
|
2267
2394
|
entity.addEvent(spatialEvent, wrapped);
|
|
2268
|
-
|
|
2395
|
+
eventsSetRef.current.add(reactKey);
|
|
2269
2396
|
});
|
|
2270
2397
|
return () => {
|
|
2271
|
-
boundHandlers.forEach((unbind) => unbind());
|
|
2272
2398
|
};
|
|
2273
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]);
|
|
2274
2410
|
return null;
|
|
2275
2411
|
};
|
|
2276
2412
|
|
|
2277
2413
|
// src/reality/hooks/useEntityId.tsx
|
|
2278
|
-
import { useEffect as
|
|
2414
|
+
import { useEffect as useEffect18 } from "react";
|
|
2279
2415
|
var useEntityId = ({ id, entity }) => {
|
|
2280
2416
|
const ctx = useRealityContext();
|
|
2281
|
-
|
|
2417
|
+
useEffect18(() => {
|
|
2282
2418
|
if (!id || !entity || !ctx) return;
|
|
2283
2419
|
ctx.resourceRegistry.add(id, Promise.resolve(entity));
|
|
2284
2420
|
return () => {
|
|
@@ -2289,7 +2425,7 @@ var useEntityId = ({ id, entity }) => {
|
|
|
2289
2425
|
};
|
|
2290
2426
|
|
|
2291
2427
|
// src/reality/hooks/useEntity.tsx
|
|
2292
|
-
import { useEffect as
|
|
2428
|
+
import { useEffect as useEffect19, useRef as useRef8 } from "react";
|
|
2293
2429
|
var useEntity = ({
|
|
2294
2430
|
ref,
|
|
2295
2431
|
id,
|
|
@@ -2300,10 +2436,10 @@ var useEntity = ({
|
|
|
2300
2436
|
onSpatialDragStart,
|
|
2301
2437
|
onSpatialDrag,
|
|
2302
2438
|
onSpatialDragEnd,
|
|
2303
|
-
onSpatialRotateStart,
|
|
2439
|
+
// onSpatialRotateStart,
|
|
2304
2440
|
onSpatialRotate,
|
|
2305
2441
|
onSpatialRotateEnd,
|
|
2306
|
-
onSpatialMagnifyStart,
|
|
2442
|
+
// onSpatialMagnifyStart,
|
|
2307
2443
|
onSpatialMagnify,
|
|
2308
2444
|
onSpatialMagnifyEnd,
|
|
2309
2445
|
// TODO: add other event handlers
|
|
@@ -2311,9 +2447,9 @@ var useEntity = ({
|
|
|
2311
2447
|
}) => {
|
|
2312
2448
|
const ctx = useRealityContext();
|
|
2313
2449
|
const parent = useParentContext();
|
|
2314
|
-
const instanceRef =
|
|
2450
|
+
const instanceRef = useRef8(new EntityRef(null, ctx));
|
|
2315
2451
|
const forceUpdate = useForceUpdate2();
|
|
2316
|
-
|
|
2452
|
+
useEffect19(() => {
|
|
2317
2453
|
if (!ctx) return;
|
|
2318
2454
|
const controller = new AbortController();
|
|
2319
2455
|
const init = async () => {
|
|
@@ -2352,86 +2488,16 @@ var useEntity = ({
|
|
|
2352
2488
|
onSpatialDragStart,
|
|
2353
2489
|
onSpatialDrag,
|
|
2354
2490
|
onSpatialDragEnd,
|
|
2355
|
-
onSpatialRotateStart,
|
|
2491
|
+
// onSpatialRotateStart,
|
|
2356
2492
|
onSpatialRotate,
|
|
2357
2493
|
onSpatialRotateEnd,
|
|
2358
|
-
onSpatialMagnifyStart,
|
|
2494
|
+
// onSpatialMagnifyStart,
|
|
2359
2495
|
onSpatialMagnify,
|
|
2360
2496
|
onSpatialMagnifyEnd
|
|
2361
2497
|
});
|
|
2362
2498
|
return instanceRef.current.entity;
|
|
2363
2499
|
};
|
|
2364
2500
|
|
|
2365
|
-
// src/reality/hooks/useEntityRef.tsx
|
|
2366
|
-
import { useImperativeHandle } from "react";
|
|
2367
|
-
var useEntityRef = (ref, instance) => {
|
|
2368
|
-
useImperativeHandle(ref, () => instance);
|
|
2369
|
-
};
|
|
2370
|
-
var EntityRef = class {
|
|
2371
|
-
_entity;
|
|
2372
|
-
_ctx;
|
|
2373
|
-
constructor(entity = null, ctx = null) {
|
|
2374
|
-
this._entity = entity;
|
|
2375
|
-
this._ctx = ctx;
|
|
2376
|
-
}
|
|
2377
|
-
updateEntity(entity) {
|
|
2378
|
-
if (entity) this._entity = entity;
|
|
2379
|
-
}
|
|
2380
|
-
updateCtx(ctx) {
|
|
2381
|
-
if (ctx) this._ctx = ctx;
|
|
2382
|
-
}
|
|
2383
|
-
destroy() {
|
|
2384
|
-
this._entity?.destroy();
|
|
2385
|
-
}
|
|
2386
|
-
get entity() {
|
|
2387
|
-
return this._entity;
|
|
2388
|
-
}
|
|
2389
|
-
get id() {
|
|
2390
|
-
return this._entity?.userData?.id;
|
|
2391
|
-
}
|
|
2392
|
-
get name() {
|
|
2393
|
-
return this._entity?.userData?.name;
|
|
2394
|
-
}
|
|
2395
|
-
async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
|
|
2396
|
-
if (!this._entity) return position;
|
|
2397
|
-
try {
|
|
2398
|
-
const fromEnt = await this._ctx?.resourceRegistry.get(fromEntityId);
|
|
2399
|
-
const toEnt = await this._ctx?.resourceRegistry.get(toEntityId);
|
|
2400
|
-
if (!fromEnt || !toEnt) return position;
|
|
2401
|
-
const ret = await this._entity.convertFromEntityToEntity(
|
|
2402
|
-
fromEnt.id,
|
|
2403
|
-
toEnt.id,
|
|
2404
|
-
position
|
|
2405
|
-
);
|
|
2406
|
-
return ret?.data ?? position;
|
|
2407
|
-
} catch {
|
|
2408
|
-
return position;
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
async convertFromEntityToReality(entityId, position) {
|
|
2412
|
-
if (!this._entity) return position;
|
|
2413
|
-
try {
|
|
2414
|
-
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2415
|
-
if (!ent) return position;
|
|
2416
|
-
const ret = await this._entity.convertFromEntityToScene(ent.id, position);
|
|
2417
|
-
return ret?.data ?? position;
|
|
2418
|
-
} catch {
|
|
2419
|
-
return position;
|
|
2420
|
-
}
|
|
2421
|
-
}
|
|
2422
|
-
async convertFromRealityToEntity(entityId, position) {
|
|
2423
|
-
if (!this._entity) return position;
|
|
2424
|
-
try {
|
|
2425
|
-
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2426
|
-
if (!ent) return position;
|
|
2427
|
-
const ret = await this._entity.convertFromSceneToEntity(ent.id, position);
|
|
2428
|
-
return ret?.data ?? position;
|
|
2429
|
-
} catch {
|
|
2430
|
-
return position;
|
|
2431
|
-
}
|
|
2432
|
-
}
|
|
2433
|
-
};
|
|
2434
|
-
|
|
2435
2501
|
// src/reality/hooks/useForceUpdate.tsx
|
|
2436
2502
|
import { useCallback as useCallback7, useState as useState7 } from "react";
|
|
2437
2503
|
var useForceUpdate2 = () => {
|
|
@@ -2439,108 +2505,88 @@ var useForceUpdate2 = () => {
|
|
|
2439
2505
|
return useCallback7(() => setTick((tick) => tick + 1), []);
|
|
2440
2506
|
};
|
|
2441
2507
|
|
|
2442
|
-
// src/reality/components/
|
|
2508
|
+
// src/reality/components/BaseEntity.tsx
|
|
2443
2509
|
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
2444
|
-
var
|
|
2445
|
-
({
|
|
2510
|
+
var BaseEntity = forwardRef10(
|
|
2511
|
+
({ children, createEntity, ...rest }, ref) => {
|
|
2446
2512
|
const ctx = useRealityContext();
|
|
2447
2513
|
const entity = useEntity({
|
|
2514
|
+
...rest,
|
|
2448
2515
|
ref,
|
|
2449
|
-
|
|
2450
|
-
position,
|
|
2451
|
-
rotation,
|
|
2452
|
-
scale,
|
|
2453
|
-
onSpatialTap,
|
|
2454
|
-
createEntity: async () => ctx.session.createEntity({ id, name })
|
|
2516
|
+
createEntity: (signal) => createEntity(ctx, signal)
|
|
2455
2517
|
});
|
|
2456
2518
|
if (!entity) return null;
|
|
2457
2519
|
return /* @__PURE__ */ jsx12(ParentContext.Provider, { value: entity, children });
|
|
2458
2520
|
}
|
|
2459
2521
|
);
|
|
2460
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
|
+
|
|
2461
2539
|
// src/reality/components/BoxEntity.tsx
|
|
2462
|
-
import { forwardRef as
|
|
2540
|
+
import { forwardRef as forwardRef13 } from "react";
|
|
2463
2541
|
|
|
2464
2542
|
// src/reality/components/GeometryEntity.tsx
|
|
2465
|
-
import { forwardRef as
|
|
2466
|
-
import { jsx as
|
|
2467
|
-
var GeometryEntity =
|
|
2468
|
-
({
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
onSpatialRotateStart,
|
|
2502
|
-
onSpatialRotate,
|
|
2503
|
-
onSpatialRotateEnd,
|
|
2504
|
-
onSpatialMagnifyStart,
|
|
2505
|
-
onSpatialMagnify,
|
|
2506
|
-
onSpatialMagnifyEnd,
|
|
2507
|
-
createEntity: async (signal) => {
|
|
2508
|
-
const manager = new AbortResourceManager(signal);
|
|
2509
|
-
try {
|
|
2510
|
-
const ent = await manager.addResource(
|
|
2511
|
-
() => ctx.session.createEntity({ id, name })
|
|
2512
|
-
);
|
|
2513
|
-
const geometry = await manager.addResource(
|
|
2514
|
-
() => createGeometry(geometryOptions)
|
|
2515
|
-
);
|
|
2516
|
-
const materialList = await Promise.all(
|
|
2517
|
-
materials?.map((id2) => ctx.resourceRegistry.get(id2)).filter(Boolean) ?? []
|
|
2518
|
-
);
|
|
2519
|
-
const modelComponent = await manager.addResource(
|
|
2520
|
-
() => ctx.session.createModelComponent({
|
|
2521
|
-
mesh: geometry,
|
|
2522
|
-
materials: materialList
|
|
2523
|
-
})
|
|
2524
|
-
);
|
|
2525
|
-
await ent.addComponent(modelComponent);
|
|
2526
|
-
return ent;
|
|
2527
|
-
} catch (error) {
|
|
2528
|
-
await manager.dispose();
|
|
2529
|
-
return null;
|
|
2530
|
-
}
|
|
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
|
|
2531
2579
|
}
|
|
2532
|
-
|
|
2533
|
-
if (!entity) return null;
|
|
2534
|
-
return /* @__PURE__ */ jsx13(ParentContext.Provider, { value: entity, children });
|
|
2580
|
+
);
|
|
2535
2581
|
}
|
|
2536
2582
|
);
|
|
2537
2583
|
|
|
2538
2584
|
// src/reality/components/BoxEntity.tsx
|
|
2539
|
-
import { jsx as
|
|
2540
|
-
var BoxEntity =
|
|
2585
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
2586
|
+
var BoxEntity = forwardRef13(
|
|
2541
2587
|
({ children, ...props }, ref) => {
|
|
2542
2588
|
const ctx = useRealityContext();
|
|
2543
|
-
return /* @__PURE__ */
|
|
2589
|
+
return /* @__PURE__ */ jsx15(
|
|
2544
2590
|
GeometryEntity,
|
|
2545
2591
|
{
|
|
2546
2592
|
...props,
|
|
@@ -2560,10 +2606,10 @@ var BoxEntity = forwardRef12(
|
|
|
2560
2606
|
);
|
|
2561
2607
|
|
|
2562
2608
|
// src/reality/components/UnlitMaterial.tsx
|
|
2563
|
-
import { useEffect as useEffect20, useRef as
|
|
2609
|
+
import { useEffect as useEffect20, useRef as useRef9 } from "react";
|
|
2564
2610
|
var UnlitMaterial = ({ children, ...options }) => {
|
|
2565
2611
|
const ctx = useRealityContext();
|
|
2566
|
-
const materialRef =
|
|
2612
|
+
const materialRef = useRef9();
|
|
2567
2613
|
useEffect20(() => {
|
|
2568
2614
|
if (!ctx) return;
|
|
2569
2615
|
const { session, reality, resourceRegistry } = ctx;
|
|
@@ -2586,12 +2632,12 @@ var UnlitMaterial = ({ children, ...options }) => {
|
|
|
2586
2632
|
};
|
|
2587
2633
|
|
|
2588
2634
|
// src/reality/components/SphereEntity.tsx
|
|
2589
|
-
import { forwardRef as
|
|
2590
|
-
import { jsx as
|
|
2591
|
-
var SphereEntity =
|
|
2635
|
+
import { forwardRef as forwardRef14 } from "react";
|
|
2636
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
2637
|
+
var SphereEntity = forwardRef14(
|
|
2592
2638
|
({ children, ...props }, ref) => {
|
|
2593
2639
|
const ctx = useRealityContext();
|
|
2594
|
-
return /* @__PURE__ */
|
|
2640
|
+
return /* @__PURE__ */ jsx16(
|
|
2595
2641
|
GeometryEntity,
|
|
2596
2642
|
{
|
|
2597
2643
|
...props,
|
|
@@ -2607,12 +2653,12 @@ var SphereEntity = forwardRef13(
|
|
|
2607
2653
|
);
|
|
2608
2654
|
|
|
2609
2655
|
// src/reality/components/ConeEntity.tsx
|
|
2610
|
-
import { forwardRef as
|
|
2611
|
-
import { jsx as
|
|
2612
|
-
var ConeEntity =
|
|
2656
|
+
import { forwardRef as forwardRef15 } from "react";
|
|
2657
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
2658
|
+
var ConeEntity = forwardRef15(
|
|
2613
2659
|
({ children, ...props }, ref) => {
|
|
2614
2660
|
const ctx = useRealityContext();
|
|
2615
|
-
return /* @__PURE__ */
|
|
2661
|
+
return /* @__PURE__ */ jsx17(
|
|
2616
2662
|
GeometryEntity,
|
|
2617
2663
|
{
|
|
2618
2664
|
...props,
|
|
@@ -2629,12 +2675,12 @@ var ConeEntity = forwardRef14(
|
|
|
2629
2675
|
);
|
|
2630
2676
|
|
|
2631
2677
|
// src/reality/components/CylinderEntity.tsx
|
|
2632
|
-
import { forwardRef as
|
|
2633
|
-
import { jsx as
|
|
2634
|
-
var CylinderEntity =
|
|
2678
|
+
import { forwardRef as forwardRef16 } from "react";
|
|
2679
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
2680
|
+
var CylinderEntity = forwardRef16(
|
|
2635
2681
|
({ children, ...props }, ref) => {
|
|
2636
2682
|
const ctx = useRealityContext();
|
|
2637
|
-
return /* @__PURE__ */
|
|
2683
|
+
return /* @__PURE__ */ jsx18(
|
|
2638
2684
|
GeometryEntity,
|
|
2639
2685
|
{
|
|
2640
2686
|
...props,
|
|
@@ -2651,12 +2697,12 @@ var CylinderEntity = forwardRef15(
|
|
|
2651
2697
|
);
|
|
2652
2698
|
|
|
2653
2699
|
// src/reality/components/PlaneEntity.tsx
|
|
2654
|
-
import { forwardRef as
|
|
2655
|
-
import { jsx as
|
|
2656
|
-
var PlaneEntity =
|
|
2700
|
+
import { forwardRef as forwardRef17 } from "react";
|
|
2701
|
+
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
2702
|
+
var PlaneEntity = forwardRef17(
|
|
2657
2703
|
({ children, ...props }, ref) => {
|
|
2658
2704
|
const ctx = useRealityContext();
|
|
2659
|
-
return /* @__PURE__ */
|
|
2705
|
+
return /* @__PURE__ */ jsx19(
|
|
2660
2706
|
GeometryEntity,
|
|
2661
2707
|
{
|
|
2662
2708
|
...props,
|
|
@@ -2674,13 +2720,13 @@ var PlaneEntity = forwardRef16(
|
|
|
2674
2720
|
);
|
|
2675
2721
|
|
|
2676
2722
|
// src/reality/components/SceneGraph.tsx
|
|
2677
|
-
import { jsx as
|
|
2723
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
2678
2724
|
var SceneGraph = ({ children }) => {
|
|
2679
|
-
return /* @__PURE__ */
|
|
2725
|
+
return /* @__PURE__ */ jsx20(ParentContext.Provider, { value: null, children });
|
|
2680
2726
|
};
|
|
2681
2727
|
|
|
2682
2728
|
// src/reality/components/ModelAsset.tsx
|
|
2683
|
-
import { useEffect as useEffect21, useRef as
|
|
2729
|
+
import { useEffect as useEffect21, useRef as useRef10 } from "react";
|
|
2684
2730
|
var resolveAssetUrl = (url) => {
|
|
2685
2731
|
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
2686
2732
|
return url;
|
|
@@ -2689,16 +2735,16 @@ var resolveAssetUrl = (url) => {
|
|
|
2689
2735
|
};
|
|
2690
2736
|
var ModelAsset = ({ children, ...options }) => {
|
|
2691
2737
|
const ctx = useRealityContext();
|
|
2692
|
-
const materialRef =
|
|
2738
|
+
const materialRef = useRef10();
|
|
2693
2739
|
useEffect21(() => {
|
|
2694
2740
|
const controller = new AbortController();
|
|
2695
2741
|
if (!ctx) return;
|
|
2696
2742
|
const { session, reality, resourceRegistry } = ctx;
|
|
2697
2743
|
const init = async () => {
|
|
2698
|
-
const resolvedUrl = resolveAssetUrl(options.src);
|
|
2699
|
-
const modelAssetPromise = session.createModelAsset({ url: resolvedUrl });
|
|
2700
|
-
resourceRegistry.add(options.id, modelAssetPromise);
|
|
2701
2744
|
try {
|
|
2745
|
+
const resolvedUrl = resolveAssetUrl(options.src);
|
|
2746
|
+
const modelAssetPromise = session.createModelAsset({ url: resolvedUrl });
|
|
2747
|
+
resourceRegistry.add(options.id, modelAssetPromise);
|
|
2702
2748
|
const mat = await modelAssetPromise;
|
|
2703
2749
|
if (controller.signal.aborted) {
|
|
2704
2750
|
mat.destroy();
|
|
@@ -2720,57 +2766,63 @@ var ModelAsset = ({ children, ...options }) => {
|
|
|
2720
2766
|
};
|
|
2721
2767
|
|
|
2722
2768
|
// src/reality/components/ModelEntity.tsx
|
|
2723
|
-
import { forwardRef as
|
|
2724
|
-
import { jsx as
|
|
2725
|
-
var ModelEntity =
|
|
2726
|
-
({ id, model,
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
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) {
|
|
2741
2793
|
return null;
|
|
2742
2794
|
}
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
modelAssetId: modelAsset.id,
|
|
2746
|
-
name
|
|
2747
|
-
},
|
|
2748
|
-
{ id, name }
|
|
2749
|
-
);
|
|
2750
|
-
} catch (error) {
|
|
2751
|
-
console.error("ModelEntity error:", error);
|
|
2752
|
-
return null;
|
|
2753
|
-
}
|
|
2795
|
+
},
|
|
2796
|
+
children
|
|
2754
2797
|
}
|
|
2755
|
-
|
|
2756
|
-
if (!entity) return null;
|
|
2757
|
-
return /* @__PURE__ */ jsx20(ParentContext.Provider, { value: entity, children });
|
|
2798
|
+
);
|
|
2758
2799
|
}
|
|
2759
2800
|
);
|
|
2760
2801
|
|
|
2761
2802
|
// src/reality/components/Reality.tsx
|
|
2762
2803
|
import {
|
|
2763
|
-
forwardRef as
|
|
2804
|
+
forwardRef as forwardRef19,
|
|
2764
2805
|
useCallback as useCallback8,
|
|
2765
2806
|
useEffect as useEffect22,
|
|
2766
|
-
useRef as
|
|
2807
|
+
useRef as useRef11,
|
|
2767
2808
|
useState as useState8
|
|
2768
2809
|
} from "react";
|
|
2769
|
-
import { Fragment as Fragment3, jsx as
|
|
2770
|
-
var Reality =
|
|
2771
|
-
function RealityBase({ children, ...
|
|
2772
|
-
const
|
|
2773
|
-
|
|
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);
|
|
2774
2826
|
const [isReady, setIsReady] = useState8(false);
|
|
2775
2827
|
const cleanupReality = useCallback8(() => {
|
|
2776
2828
|
ctxRef.current?.resourceRegistry.destroy();
|
|
@@ -2817,9 +2869,9 @@ var Reality = forwardRef18(
|
|
|
2817
2869
|
return null;
|
|
2818
2870
|
}
|
|
2819
2871
|
}, [cleanupReality]);
|
|
2820
|
-
const content = useCallback8(() => /* @__PURE__ */
|
|
2872
|
+
const content = useCallback8(() => /* @__PURE__ */ jsx22(Fragment3, {}), []);
|
|
2821
2873
|
return /* @__PURE__ */ jsxs3(RealityContext.Provider, { value: ctxRef.current, children: [
|
|
2822
|
-
/* @__PURE__ */
|
|
2874
|
+
/* @__PURE__ */ jsx22(
|
|
2823
2875
|
SpatializedContainer,
|
|
2824
2876
|
{
|
|
2825
2877
|
component: "div",
|
|
@@ -2835,8 +2887,8 @@ var Reality = forwardRef18(
|
|
|
2835
2887
|
);
|
|
2836
2888
|
|
|
2837
2889
|
// src/Model.tsx
|
|
2838
|
-
import { forwardRef as
|
|
2839
|
-
import { jsx as
|
|
2890
|
+
import { forwardRef as forwardRef20 } from "react";
|
|
2891
|
+
import { jsx as jsx23 } from "react/jsx-runtime";
|
|
2840
2892
|
var spatial2 = new Spatial();
|
|
2841
2893
|
function ModelBase(props, ref) {
|
|
2842
2894
|
const { "enable-xr": enableXR, ...restProps } = props;
|
|
@@ -2846,23 +2898,21 @@ function ModelBase(props, ref) {
|
|
|
2846
2898
|
onSpatialDragStart,
|
|
2847
2899
|
onSpatialDrag,
|
|
2848
2900
|
onSpatialDragEnd,
|
|
2849
|
-
onSpatialRotateStart,
|
|
2850
2901
|
onSpatialRotate,
|
|
2851
2902
|
onSpatialRotateEnd,
|
|
2852
|
-
onSpatialMagnifyStart,
|
|
2853
2903
|
onSpatialMagnify,
|
|
2854
2904
|
onSpatialMagnifyEnd,
|
|
2855
2905
|
...modelProps
|
|
2856
2906
|
} = restProps;
|
|
2857
|
-
return /* @__PURE__ */
|
|
2907
|
+
return /* @__PURE__ */ jsx23("model", { ref, ...modelProps });
|
|
2858
2908
|
}
|
|
2859
|
-
return /* @__PURE__ */
|
|
2909
|
+
return /* @__PURE__ */ jsx23(SpatializedStatic3DElementContainer, { ref, ...restProps });
|
|
2860
2910
|
}
|
|
2861
|
-
var Model = withSSRSupported(
|
|
2911
|
+
var Model = withSSRSupported(forwardRef20(ModelBase));
|
|
2862
2912
|
Model.displayName = "Model";
|
|
2863
2913
|
|
|
2864
2914
|
// src/index.ts
|
|
2865
|
-
var version = "1.0
|
|
2915
|
+
var version = "1.2.0";
|
|
2866
2916
|
if (typeof window !== "undefined") {
|
|
2867
2917
|
initPolyfill();
|
|
2868
2918
|
}
|