@holoscript/core 7.0.0 → 8.0.1
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/README.md +4 -4
- package/bin/holoscript.cjs +3 -0
- package/dist/GLTFPipeline-N6B6PJ6G.cjs +38 -0
- package/dist/GLTFPipeline-P3WMNYCN.js +17 -0
- package/dist/HoloScriptPlusParser-7FBIFUFC.js +693 -0
- package/dist/HoloScriptPlusParser-A2W7OCN2.cjs +698 -0
- package/dist/HoloScriptPlusParser-F2Z56FJR.js +10 -0
- package/dist/HoloScriptPlusParser-WKHRIH6T.cjs +27 -0
- package/dist/HoloScriptRuntime-CBYJX3LZ.js +10 -0
- package/dist/HoloScriptRuntime-VJ374RER.cjs +19 -0
- package/dist/USDZExporter-3FWJ25JI.cjs +1037 -0
- package/dist/USDZExporter-D2HQLQYK.js +1035 -0
- package/dist/agents/index.cjs +19 -0
- package/dist/agents/index.d.ts +100 -0
- package/dist/agents/index.js +17 -0
- package/dist/chunk-2BSMSUCE.js +1941 -0
- package/dist/chunk-2IWC4FP7.cjs +1189 -0
- package/dist/chunk-2M2DPHKB.js +762 -0
- package/dist/chunk-2X7NGX3M.js +2426 -0
- package/dist/chunk-2YSNA2F2.cjs +1274 -0
- package/dist/chunk-3FOKASKO.cjs +348 -0
- package/dist/chunk-3WZEJHUQ.cjs +116 -0
- package/dist/chunk-4C57PR42.js +468 -0
- package/dist/chunk-4GU5GCIY.js +1384 -0
- package/dist/chunk-4N4SXXWF.js +769 -0
- package/dist/chunk-4PDEPEQW.cjs +41 -0
- package/dist/chunk-4R6SBXDB.js +45 -0
- package/dist/chunk-4SDKXQ4C.js +811 -0
- package/dist/chunk-4V2E7U7Q.cjs +2015 -0
- package/dist/chunk-5FSKKMR7.cjs +2092 -0
- package/dist/chunk-5GLCTO44.js +161 -0
- package/dist/chunk-5H2G27PK.cjs +627 -0
- package/dist/chunk-5JEU52DW.js +382 -0
- package/dist/chunk-5NWINHR5.cjs +689 -0
- package/dist/chunk-5S7RKFGR.cjs +446 -0
- package/dist/chunk-5WUNN6ZN.cjs +428 -0
- package/dist/chunk-6CTRH7HT.cjs +1985 -0
- package/dist/chunk-6EX3I5P4.cjs +130 -0
- package/dist/chunk-6Q7RC2MK.cjs +1418 -0
- package/dist/chunk-7H33U5SM.cjs +413 -0
- package/dist/chunk-7M3PNU2M.cjs +672 -0
- package/dist/chunk-7T25IEZ2.js +449 -0
- package/dist/chunk-7V4JI5TB.cjs +6947 -0
- package/dist/chunk-A6KINLZJ.js +236 -0
- package/dist/chunk-ADADVMXY.js +404 -0
- package/dist/chunk-AIA52I7T.cjs +543 -0
- package/dist/chunk-ALC6K7GL.cjs +4402 -0
- package/dist/chunk-ANXZFVY2.js +113 -0
- package/dist/chunk-AOVGZ25K.cjs +56583 -0
- package/dist/chunk-AVJHHUC5.cjs +718 -0
- package/dist/chunk-BGY3SDG3.js +4396 -0
- package/dist/chunk-BOVPWH4H.js +3857 -0
- package/dist/chunk-BRQJKJGT.cjs +20 -0
- package/dist/chunk-C37BHB7N.cjs +636 -0
- package/dist/chunk-CBJY23VL.js +126 -0
- package/dist/chunk-CCATWPXM.js +778 -0
- package/dist/chunk-CIWWXYHZ.cjs +50 -0
- package/dist/chunk-CMT5NMMS.js +669 -0
- package/dist/chunk-CR4FMIWL.cjs +1049 -0
- package/dist/chunk-CR7XRXRN.cjs +639 -0
- package/dist/chunk-CSD27UNQ.js +2176 -0
- package/dist/chunk-D3STJ56J.js +714 -0
- package/dist/chunk-DAJXW4KX.js +725 -0
- package/dist/chunk-DHO2YRIM.js +756 -0
- package/dist/chunk-DTGBOSEM.cjs +319 -0
- package/dist/chunk-E6XXE66V.js +2252 -0
- package/dist/chunk-E7JP3BS3.cjs +61 -0
- package/dist/chunk-EKBKLK7P.js +1169 -0
- package/dist/chunk-EKYL4PE3.cjs +404 -0
- package/dist/chunk-EXKSFGSX.cjs +274 -0
- package/dist/chunk-EXUP2BUM.cjs +1173 -0
- package/dist/chunk-FDSGHPAK.js +130 -0
- package/dist/chunk-FEWUHQNM.cjs +144 -0
- package/dist/chunk-FFAOS5HQ.js +70 -0
- package/dist/chunk-FGGJQRLZ.js +270 -0
- package/dist/chunk-FHP6LXJS.js +415 -0
- package/dist/chunk-FJPADH77.cjs +666 -0
- package/dist/chunk-FL33V6U7.js +421 -0
- package/dist/chunk-FYSPZT4V.cjs +169 -0
- package/dist/chunk-GIOYPNTH.js +5575 -0
- package/dist/chunk-GJNCFRJU.cjs +125 -0
- package/dist/chunk-GMP623FG.cjs +1508 -0
- package/dist/chunk-GQHQOPXZ.cjs +5580 -0
- package/dist/chunk-GTU2Z2WW.cjs +262 -0
- package/dist/chunk-GYZE55MO.js +2007 -0
- package/dist/chunk-GZG4KA4E.js +529 -0
- package/dist/chunk-H652NHX5.js +600 -0
- package/dist/chunk-HCCQLAA4.cjs +74 -0
- package/dist/chunk-HKEXJUWS.cjs +4007 -0
- package/dist/chunk-HNDK4IQU.cjs +5737 -0
- package/dist/chunk-HR2OSYVQ.js +56165 -0
- package/dist/chunk-HYNTS5CP.js +422 -0
- package/dist/chunk-I6XZ5DZF.cjs +488 -0
- package/dist/chunk-ILRBGFVD.cjs +72 -0
- package/dist/chunk-IUDGEUDO.cjs +1409 -0
- package/dist/chunk-IUTY5WQ2.cjs +424 -0
- package/dist/chunk-IVY74O6C.js +247 -0
- package/dist/chunk-IWC5DM2M.cjs +611 -0
- package/dist/chunk-J32ZJZJH.js +554 -0
- package/dist/chunk-J52VSAQ7.js +6884 -0
- package/dist/chunk-J6M4FPK5.js +421 -0
- package/dist/chunk-J7XZV333.js +844 -0
- package/dist/chunk-JBNDTXXV.cjs +2433 -0
- package/dist/chunk-JC5YBPSF.cjs +984 -0
- package/dist/chunk-JD7CIZ33.js +1949 -0
- package/dist/chunk-JIBL5LRK.js +4287 -0
- package/dist/chunk-JIYN45TV.cjs +2525 -0
- package/dist/chunk-K574J76X.cjs +457 -0
- package/dist/chunk-KHDZJE5D.cjs +2196 -0
- package/dist/chunk-KKFZ3B6J.cjs +557 -0
- package/dist/chunk-KKP7JKN4.cjs +6002 -0
- package/dist/chunk-KPJL34Y7.cjs +186 -0
- package/dist/chunk-KQCN6AKJ.cjs +3042 -0
- package/dist/chunk-L5LKKENW.cjs +424 -0
- package/dist/chunk-LHAXPADA.js +882 -0
- package/dist/chunk-LM2VU56C.cjs +37 -0
- package/dist/chunk-M56JSP4A.js +400 -0
- package/dist/chunk-MBOOR7X4.js +18 -0
- package/dist/chunk-MQWAT42R.cjs +4310 -0
- package/dist/chunk-MXFUTKCO.js +56 -0
- package/dist/chunk-MYY4PMWX.cjs +264 -0
- package/dist/chunk-N75IH2HY.js +258 -0
- package/dist/chunk-NCWCUZNS.cjs +72 -0
- package/dist/chunk-NG77ATEW.cjs +778 -0
- package/dist/chunk-NW5G5FBQ.js +215 -0
- package/dist/chunk-OBIYPYYS.cjs +1993 -0
- package/dist/chunk-OH2FAIVU.js +608 -0
- package/dist/chunk-OIQYIIO3.cjs +473 -0
- package/dist/chunk-OL46QLBJ.js +61 -0
- package/dist/chunk-OMXII44L.js +5386 -0
- package/dist/chunk-OSYNRVOV.cjs +243 -0
- package/dist/chunk-PGANYCAG.cjs +220 -0
- package/dist/chunk-PHENW4MQ.js +65 -0
- package/dist/chunk-PY37LNDP.js +686 -0
- package/dist/chunk-Q56TT7IL.js +483 -0
- package/dist/chunk-QD32ADK6.js +1046 -0
- package/dist/chunk-QPOQ7VPI.js +1491 -0
- package/dist/chunk-QPSKHBJP.js +5963 -0
- package/dist/chunk-QXH7QDSZ.js +1989 -0
- package/dist/chunk-R24NNAEG.js +1399 -0
- package/dist/chunk-R75BSDH7.cjs +50 -0
- package/dist/chunk-RARB3MBR.js +207 -0
- package/dist/chunk-ROHLEP2W.cjs +847 -0
- package/dist/chunk-S3MDHNKB.cjs +490 -0
- package/dist/chunk-S6YWHCKV.cjs +410 -0
- package/dist/chunk-SIEXCILW.js +229 -0
- package/dist/chunk-SLU6UPJI.cjs +410 -0
- package/dist/chunk-SMIWS6DE.cjs +212 -0
- package/dist/chunk-T5J7ZKP3.cjs +4885 -0
- package/dist/chunk-TDCNJHWO.js +341 -0
- package/dist/chunk-TG7O4WBC.js +406 -0
- package/dist/chunk-THCK6ECW.js +2085 -0
- package/dist/chunk-TJHVSBP2.js +439 -0
- package/dist/chunk-TVHSPJ4N.cjs +606 -0
- package/dist/chunk-TWUXUCEW.cjs +781 -0
- package/dist/chunk-U44IKGG7.cjs +5390 -0
- package/dist/chunk-UFZZ7TSN.cjs +886 -0
- package/dist/chunk-UJXISJBN.js +487 -0
- package/dist/chunk-UOIGFQXC.cjs +9750 -0
- package/dist/chunk-URG2SJLK.js +2521 -0
- package/dist/chunk-UWJHCOH2.js +623 -0
- package/dist/chunk-V6MKC2FZ.js +979 -0
- package/dist/chunk-VJ3L7CHT.cjs +169 -0
- package/dist/chunk-VMLKSV26.js +1216 -0
- package/dist/chunk-VVKVQZI6.js +55 -0
- package/dist/chunk-W6RW64BB.cjs +1219 -0
- package/dist/chunk-WKX5AMOY.js +309 -0
- package/dist/chunk-WNNE3PO3.js +34 -0
- package/dist/chunk-WRKUDAZJ.js +3038 -0
- package/dist/chunk-WRLUBRKS.cjs +1943 -0
- package/dist/chunk-WRNEH5MO.js +3169 -0
- package/dist/chunk-WRWEX5ZF.js +658 -0
- package/dist/chunk-X3GJPRVK.cjs +3246 -0
- package/dist/chunk-X3UVCWNL.cjs +2257 -0
- package/dist/chunk-XB274MW5.cjs +814 -0
- package/dist/chunk-XHIV6326.cjs +793 -0
- package/dist/chunk-XIVIE43A.cjs +729 -0
- package/dist/chunk-XJAN7CZG.cjs +432 -0
- package/dist/chunk-XKTPFXGA.js +164 -0
- package/dist/chunk-XL6INWKT.js +121 -0
- package/dist/chunk-XSFNHP2E.js +632 -0
- package/dist/chunk-XT6JY5W5.js +9684 -0
- package/dist/chunk-XUILI4KB.cjs +430 -0
- package/dist/chunk-YF2I3MV3.js +46 -0
- package/dist/chunk-YIMN575O.js +4847 -0
- package/dist/chunk-YIVFJNYV.js +176 -0
- package/dist/chunk-YKGPCZEE.cjs +237 -0
- package/dist/chunk-YN2YWTXW.js +5731 -0
- package/dist/chunk-YN6V7R3L.cjs +327 -0
- package/dist/chunk-YQELFNJV.js +39 -0
- package/dist/chunk-YVD3CSO3.js +1183 -0
- package/dist/chunk-YVOAF4ML.js +623 -0
- package/dist/chunk-YWOBW2PV.cjs +759 -0
- package/dist/chunk-YYXH45E2.js +426 -0
- package/dist/chunk-ZDSYWBIE.cjs +69 -0
- package/dist/chunk-ZU7NIRT6.js +325 -0
- package/dist/chunk-ZZ7RO2UQ.js +1243 -0
- package/dist/cli/holoscript-runner.cjs +2255 -0
- package/dist/cli/holoscript-runner.js +2230 -0
- package/dist/codebase/index.cjs +336 -0
- package/dist/codebase/index.js +331 -0
- package/dist/compiler/agent-inference.cjs +31 -0
- package/dist/compiler/agent-inference.js +8 -0
- package/dist/compiler/android-xr.cjs +24 -0
- package/dist/compiler/android-xr.js +14 -0
- package/dist/compiler/android.cjs +24 -0
- package/dist/compiler/android.js +14 -0
- package/dist/compiler/ar.cjs +23 -0
- package/dist/compiler/ar.js +11 -0
- package/dist/compiler/babylon.cjs +21 -0
- package/dist/compiler/babylon.js +15 -0
- package/dist/compiler/business-quest.cjs +43 -0
- package/dist/compiler/business-quest.js +4 -0
- package/dist/compiler/coco.cjs +27 -0
- package/dist/compiler/coco.js +4 -0
- package/dist/compiler/context.cjs +25 -0
- package/dist/compiler/context.d.ts +28 -0
- package/dist/compiler/context.js +8 -0
- package/dist/compiler/domain-block-utils.cjs +609 -0
- package/dist/compiler/domain-block-utils.js +11 -0
- package/dist/compiler/dtdl.cjs +27 -0
- package/dist/compiler/dtdl.js +11 -0
- package/dist/compiler/gltf-pipeline.cjs +39 -0
- package/dist/compiler/gltf-pipeline.js +4 -0
- package/dist/compiler/godot.cjs +18 -0
- package/dist/compiler/godot.js +12 -0
- package/dist/compiler/incremental.cjs +34 -0
- package/dist/compiler/incremental.js +9 -0
- package/dist/compiler/index.cjs +5408 -0
- package/dist/compiler/index.d.ts +334 -21
- package/dist/compiler/index.js +5069 -0
- package/dist/compiler/ios.cjs +23 -0
- package/dist/compiler/ios.js +13 -0
- package/dist/compiler/llm-provider-capabilities.cjs +25 -0
- package/dist/compiler/llm-provider-capabilities.d.ts +43 -0
- package/dist/compiler/llm-provider-capabilities.js +8 -0
- package/dist/compiler/multi-layer.cjs +24 -0
- package/dist/compiler/multi-layer.js +15 -0
- package/dist/compiler/nodetoy.cjs +23 -0
- package/dist/compiler/nodetoy.d.ts +69 -0
- package/dist/compiler/nodetoy.js +4 -0
- package/dist/compiler/openxr.cjs +19 -0
- package/dist/compiler/openxr.js +13 -0
- package/dist/compiler/playcanvas.cjs +19 -0
- package/dist/compiler/playcanvas.js +13 -0
- package/dist/compiler/r3f.cjs +39 -0
- package/dist/compiler/r3f.d.ts +22 -0
- package/dist/compiler/r3f.js +17 -0
- package/dist/compiler/remotion.cjs +23 -0
- package/dist/compiler/remotion.js +4 -0
- package/dist/compiler/reproducibility.cjs +39 -0
- package/dist/compiler/reproducibility.js +4 -0
- package/dist/compiler/sdf.cjs +24 -0
- package/dist/compiler/sdf.js +12 -0
- package/dist/compiler/semantic-scene.cjs +31 -0
- package/dist/compiler/semantic-scene.js +4 -0
- package/dist/compiler/state.cjs +21 -0
- package/dist/compiler/state.js +11 -0
- package/dist/compiler/trait-composition.cjs +30 -0
- package/dist/compiler/trait-composition.js +9 -0
- package/dist/compiler/unity.cjs +19 -0
- package/dist/compiler/unity.js +13 -0
- package/dist/compiler/unreal.cjs +23 -0
- package/dist/compiler/unreal.js +13 -0
- package/dist/compiler/urdf.cjs +52 -0
- package/dist/compiler/urdf.js +12 -0
- package/dist/compiler/usd-physics.cjs +26 -0
- package/dist/compiler/usd-physics.js +9 -0
- package/dist/compiler/visionos.cjs +19 -0
- package/dist/compiler/visionos.js +13 -0
- package/dist/compiler/vrchat.cjs +22 -0
- package/dist/compiler/vrchat.js +12 -0
- package/dist/compiler/vrr.cjs +24 -0
- package/dist/compiler/vrr.js +12 -0
- package/dist/compiler/wasm.cjs +36 -0
- package/dist/compiler/wasm.js +12 -0
- package/dist/compiler/webgpu.cjs +18 -0
- package/dist/compiler/webgpu.js +12 -0
- package/dist/coordinators/index.cjs +1266 -0
- package/dist/coordinators/index.d.ts +72 -1
- package/dist/coordinators/index.js +1259 -0
- package/dist/debugger.cjs +24 -0
- package/dist/debugger.js +11 -0
- package/dist/dist-ACXG6IH5.cjs +3113 -0
- package/dist/dist-VD4L6V7Q.js +3076 -0
- package/dist/entries/interop.cjs +64 -0
- package/dist/entries/interop.js +7 -0
- package/dist/entries/scripting.cjs +55 -0
- package/dist/entries/scripting.js +10 -0
- package/dist/hololand/index.cjs +146 -0
- package/dist/hololand/index.d.ts +70 -0
- package/dist/hololand/index.js +5 -0
- package/dist/index.cjs +44660 -0
- package/dist/index.d.ts +978 -21
- package/dist/index.js +41422 -0
- package/dist/math/tropical-spmv.cjs +45 -0
- package/dist/math/tropical-spmv.js +4 -0
- package/dist/math/vec3.cjs +57 -0
- package/dist/math/vec3.js +4 -0
- package/dist/ml-dsa-FSKBTE3W.cjs +1265 -0
- package/dist/ml-dsa-Z7JDKW4L.js +1265 -0
- package/dist/paper-0c-spike/index.cjs +150 -0
- package/dist/paper-0c-spike/index.js +141 -0
- package/dist/parser.cjs +61 -0
- package/dist/parser.d.ts +11 -0
- package/dist/parser.js +12 -0
- package/dist/playwright-3AT3AKTV.cjs +98673 -0
- package/dist/playwright-VZPDVUEQ.js +98660 -0
- package/dist/reconstruction/index.cjs +153 -0
- package/dist/reconstruction/index.d.ts +29 -2
- package/dist/reconstruction/index.js +8 -0
- package/dist/runtime.cjs +316 -0
- package/dist/runtime.d.ts +61 -0
- package/dist/runtime.js +31 -0
- package/dist/self-improvement/index.cjs +563 -0
- package/dist/self-improvement/index.js +545 -0
- package/dist/src-4ROC227P.cjs +2094 -0
- package/dist/src-HCCCSYP7.js +2073 -0
- package/dist/storage/index.cjs +38 -0
- package/dist/storage/index.js +5 -0
- package/dist/testing.cjs +25 -0
- package/dist/testing.d.ts +70 -0
- package/dist/testing.js +4 -0
- package/dist/traitDocs/traitDocs.cjs +33 -0
- package/dist/traitDocs/traitDocs.js +7 -0
- package/dist/traits/botanical-lotus.cjs +177 -0
- package/dist/traits/botanical-lotus.d.ts +502 -0
- package/dist/traits/botanical-lotus.js +7 -0
- package/dist/traits/engines/index.cjs +520 -0
- package/dist/traits/engines/index.js +380 -0
- package/dist/traits/index.cjs +24548 -0
- package/dist/traits/index.d.ts +171 -35
- package/dist/traits/index.js +21638 -0
- package/dist/traits/simulation-solver-factory.cjs +13 -0
- package/dist/traits/simulation-solver-factory.d.ts +23 -0
- package/dist/traits/simulation-solver-factory.js +4 -0
- package/dist/traits/webcam-gaze.cjs +35 -0
- package/dist/traits/webcam-gaze.d.ts +17 -0
- package/dist/traits/webcam-gaze.js +4 -0
- package/dist/type-checker.cjs +19 -0
- package/dist/type-checker.js +6 -0
- package/dist/world/index.cjs +947 -0
- package/dist/world/index.d.ts +147 -0
- package/dist/world/index.js +939 -0
- package/dist/world-model/index.cjs +1446 -0
- package/dist/world-model/index.d.ts +119 -0
- package/dist/world-model/index.js +1414 -0
- package/dist/wot/index.cjs +29 -0
- package/dist/wot/index.js +4 -0
- package/package.json +93 -49
|
@@ -0,0 +1,1037 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('./chunk-HCCQLAA4.cjs');
|
|
4
|
+
|
|
5
|
+
// src/export/usdz/USDTypes.ts
|
|
6
|
+
function createUSDXform(name, path) {
|
|
7
|
+
return {
|
|
8
|
+
path,
|
|
9
|
+
type: "Xform",
|
|
10
|
+
name,
|
|
11
|
+
attributes: [],
|
|
12
|
+
children: []
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function createUSDPreviewSurfaceMaterial(name, path, inputs) {
|
|
16
|
+
const shaderPath = `${path}/PreviewSurface`;
|
|
17
|
+
const shaderInputs = [];
|
|
18
|
+
if (inputs.diffuseColor) {
|
|
19
|
+
shaderInputs.push({
|
|
20
|
+
name: "diffuseColor",
|
|
21
|
+
type: "color3f",
|
|
22
|
+
value: inputs.diffuseColor
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (inputs.metallic !== void 0) {
|
|
26
|
+
shaderInputs.push({
|
|
27
|
+
name: "metallic",
|
|
28
|
+
type: "float",
|
|
29
|
+
value: inputs.metallic
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (inputs.roughness !== void 0) {
|
|
33
|
+
shaderInputs.push({
|
|
34
|
+
name: "roughness",
|
|
35
|
+
type: "float",
|
|
36
|
+
value: inputs.roughness
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (inputs.emissiveColor) {
|
|
40
|
+
shaderInputs.push({
|
|
41
|
+
name: "emissiveColor",
|
|
42
|
+
type: "color3f",
|
|
43
|
+
value: inputs.emissiveColor
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const material = {
|
|
47
|
+
path,
|
|
48
|
+
type: "Material",
|
|
49
|
+
name,
|
|
50
|
+
attributes: [],
|
|
51
|
+
surfaceShader: shaderPath,
|
|
52
|
+
children: [
|
|
53
|
+
{
|
|
54
|
+
path: shaderPath,
|
|
55
|
+
type: "Shader",
|
|
56
|
+
name: "PreviewSurface",
|
|
57
|
+
attributes: [
|
|
58
|
+
{
|
|
59
|
+
name: "info:id",
|
|
60
|
+
type: "token",
|
|
61
|
+
value: "UsdPreviewSurface"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
};
|
|
67
|
+
const shaderPrim = material.children[0];
|
|
68
|
+
shaderPrim.inputs = shaderInputs;
|
|
69
|
+
return material;
|
|
70
|
+
}
|
|
71
|
+
function quaternionToEuler(quat) {
|
|
72
|
+
const [x, y, z, w] = quat;
|
|
73
|
+
const sinr_cosp = 2 * (w * x + y * z);
|
|
74
|
+
const cosr_cosp = 1 - 2 * (x * x + y * y);
|
|
75
|
+
const roll = Math.atan2(sinr_cosp, cosr_cosp);
|
|
76
|
+
const sinp = 2 * (w * y - z * x);
|
|
77
|
+
const pitch = Math.abs(sinp) >= 1 ? Math.sign(sinp) * Math.PI / 2 : Math.asin(sinp);
|
|
78
|
+
const siny_cosp = 2 * (w * z + x * y);
|
|
79
|
+
const cosy_cosp = 1 - 2 * (y * y + z * z);
|
|
80
|
+
const yaw = Math.atan2(siny_cosp, cosy_cosp);
|
|
81
|
+
return [roll * 180 / Math.PI, pitch * 180 / Math.PI, yaw * 180 / Math.PI];
|
|
82
|
+
}
|
|
83
|
+
function sanitizeUSDName(name) {
|
|
84
|
+
return name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/export/usdz/USDZExporter.ts
|
|
88
|
+
var _USDZExporter = class _USDZExporter {
|
|
89
|
+
constructor(options = {}) {
|
|
90
|
+
this.primCounter = 0;
|
|
91
|
+
this.materialMap = /* @__PURE__ */ new Map();
|
|
92
|
+
// materialId -> USD path
|
|
93
|
+
this.meshMap = /* @__PURE__ */ new Map();
|
|
94
|
+
// meshId -> USD path
|
|
95
|
+
this.nodePrimMap = /* @__PURE__ */ new Map();
|
|
96
|
+
// nodeId -> USD prim
|
|
97
|
+
this.sceneGraphAccessorData = /* @__PURE__ */ new Map();
|
|
98
|
+
// accessorIndex -> flat data
|
|
99
|
+
this.textureFiles = [];
|
|
100
|
+
this.options = { ..._USDZExporter.DEFAULT_OPTIONS, ...options };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Export scene graph to USDZ format
|
|
104
|
+
* Returns ArrayBuffer containing .usdz package
|
|
105
|
+
*/
|
|
106
|
+
async export(sceneGraph) {
|
|
107
|
+
const startTime = performance.now();
|
|
108
|
+
this.reset();
|
|
109
|
+
this.stage = this.createStage(sceneGraph);
|
|
110
|
+
await this.convertSceneGraph(sceneGraph);
|
|
111
|
+
if (this.options.lookAtCamera || this.options.placementMode) {
|
|
112
|
+
this.addARMetadata();
|
|
113
|
+
}
|
|
114
|
+
const usdzBuffer = await this.packageUSDZ();
|
|
115
|
+
const endTime = performance.now();
|
|
116
|
+
const stats = this.calculateStats(usdzBuffer.byteLength, endTime - startTime);
|
|
117
|
+
return {
|
|
118
|
+
usdz: usdzBuffer,
|
|
119
|
+
stage: this.stage,
|
|
120
|
+
stats
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Convert from GLTF intermediate representation
|
|
125
|
+
*/
|
|
126
|
+
async convertFromGLTF(gltfResult) {
|
|
127
|
+
const sceneGraph = this.gltfToSceneGraph(gltfResult);
|
|
128
|
+
const result = await this.export(sceneGraph);
|
|
129
|
+
return result.usdz;
|
|
130
|
+
}
|
|
131
|
+
// ========================================================================
|
|
132
|
+
// Private Methods - GLTF Bridge
|
|
133
|
+
// ========================================================================
|
|
134
|
+
gltfToSceneGraph(gltfResult) {
|
|
135
|
+
const doc = gltfResult.document;
|
|
136
|
+
const buffers = this.extractGLTFBuffers(gltfResult);
|
|
137
|
+
const sgBuffers = buffers.map((data, i) => ({
|
|
138
|
+
id: `buf_${i}`,
|
|
139
|
+
byteLength: data.byteLength,
|
|
140
|
+
data
|
|
141
|
+
}));
|
|
142
|
+
const sgBufferViews = (doc.bufferViews || []).map((bv, i) => ({
|
|
143
|
+
id: `bv_${i}`,
|
|
144
|
+
bufferIndex: bv.buffer,
|
|
145
|
+
byteOffset: bv.byteOffset || 0,
|
|
146
|
+
byteLength: bv.byteLength,
|
|
147
|
+
byteStride: bv.byteStride,
|
|
148
|
+
target: bv.target === 34962 ? "arrayBuffer" : bv.target === 34963 ? "elementArrayBuffer" : void 0
|
|
149
|
+
}));
|
|
150
|
+
const componentTypeMap = {
|
|
151
|
+
5120: "byte",
|
|
152
|
+
5121: "ubyte",
|
|
153
|
+
5122: "short",
|
|
154
|
+
5123: "ushort",
|
|
155
|
+
5125: "uint",
|
|
156
|
+
5126: "float"
|
|
157
|
+
};
|
|
158
|
+
const accessorTypeMap = {
|
|
159
|
+
SCALAR: "scalar",
|
|
160
|
+
VEC2: "vec2",
|
|
161
|
+
VEC3: "vec3",
|
|
162
|
+
VEC4: "vec4",
|
|
163
|
+
MAT2: "mat2",
|
|
164
|
+
MAT3: "mat3",
|
|
165
|
+
MAT4: "mat4"
|
|
166
|
+
};
|
|
167
|
+
const sgAccessors = (doc.accessors || []).map((acc, i) => ({
|
|
168
|
+
id: `acc_${i}`,
|
|
169
|
+
bufferViewIndex: acc.bufferView !== void 0 ? acc.bufferView : 0,
|
|
170
|
+
byteOffset: acc.byteOffset || 0,
|
|
171
|
+
componentType: componentTypeMap[acc.componentType] || "float",
|
|
172
|
+
type: accessorTypeMap[acc.type] || "scalar",
|
|
173
|
+
count: acc.count,
|
|
174
|
+
normalized: acc.normalized || false,
|
|
175
|
+
min: acc.min,
|
|
176
|
+
max: acc.max
|
|
177
|
+
}));
|
|
178
|
+
const sgMeshes = (doc.meshes || []).map((mesh, i) => ({
|
|
179
|
+
id: `mesh_${i}`,
|
|
180
|
+
name: mesh.name || `Mesh_${i}`,
|
|
181
|
+
primitives: mesh.primitives.map((prim) => ({
|
|
182
|
+
attributes: { ...prim.attributes },
|
|
183
|
+
indices: prim.indices,
|
|
184
|
+
mode: this.mapGLTFPrimitiveMode(prim.mode),
|
|
185
|
+
materialRef: prim.material !== void 0 ? `mat_${prim.material}` : void 0
|
|
186
|
+
})),
|
|
187
|
+
bounds: { min: [0, 0, 0], max: [1, 1, 1] }
|
|
188
|
+
}));
|
|
189
|
+
const sgMaterials = (doc.materials || []).map((mat, i) => {
|
|
190
|
+
const pbr = mat.pbrMetallicRoughness;
|
|
191
|
+
return {
|
|
192
|
+
id: `mat_${i}`,
|
|
193
|
+
name: mat.name || `Material_${i}`,
|
|
194
|
+
type: "pbr",
|
|
195
|
+
doubleSided: mat.doubleSided || false,
|
|
196
|
+
alphaMode: mat.alphaMode?.toLowerCase() || "opaque",
|
|
197
|
+
alphaCutoff: mat.alphaCutoff ?? 0.5,
|
|
198
|
+
baseColor: pbr?.baseColorFactor || [1, 1, 1, 1],
|
|
199
|
+
metallic: pbr?.metallicFactor ?? 0,
|
|
200
|
+
roughness: pbr?.roughnessFactor ?? 0.5,
|
|
201
|
+
emissiveColor: mat.emissiveFactor || [0, 0, 0],
|
|
202
|
+
emissiveIntensity: 1,
|
|
203
|
+
normalScale: mat.normalTexture?.scale ?? 1,
|
|
204
|
+
occlusionStrength: mat.occlusionTexture?.strength ?? 1,
|
|
205
|
+
baseColorTexture: pbr?.baseColorTexture ? this.mapGLTFTextureRef(pbr.baseColorTexture.index, pbr.baseColorTexture.texCoord || 0) : void 0,
|
|
206
|
+
normalTexture: mat.normalTexture ? this.mapGLTFTextureRef(mat.normalTexture.index, mat.normalTexture.texCoord || 0) : void 0,
|
|
207
|
+
occlusionTexture: mat.occlusionTexture ? this.mapGLTFTextureRef(mat.occlusionTexture.index, mat.occlusionTexture.texCoord || 0) : void 0,
|
|
208
|
+
emissiveTexture: mat.emissiveTexture ? this.mapGLTFTextureRef(mat.emissiveTexture.index, mat.emissiveTexture.texCoord || 0) : void 0,
|
|
209
|
+
metallicRoughnessTexture: pbr?.metallicRoughnessTexture ? this.mapGLTFTextureRef(pbr.metallicRoughnessTexture.index, pbr.metallicRoughnessTexture.texCoord || 0) : void 0
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
const nodeIdMap = /* @__PURE__ */ new Map();
|
|
213
|
+
const buildNode = (gltfNode, index) => {
|
|
214
|
+
const id = `node_${index}`;
|
|
215
|
+
nodeIdMap.set(index, id);
|
|
216
|
+
const children = (gltfNode.children || []).map(
|
|
217
|
+
(ci) => buildNode(doc.nodes[ci], ci)
|
|
218
|
+
);
|
|
219
|
+
const components = [];
|
|
220
|
+
if (gltfNode.mesh !== void 0) {
|
|
221
|
+
components.push({
|
|
222
|
+
type: "mesh",
|
|
223
|
+
meshRef: `mesh_${gltfNode.mesh}`,
|
|
224
|
+
materialRefs: [],
|
|
225
|
+
castShadows: true,
|
|
226
|
+
receiveShadows: true,
|
|
227
|
+
enabled: true,
|
|
228
|
+
properties: {}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
id,
|
|
233
|
+
name: gltfNode.name || `Node_${index}`,
|
|
234
|
+
type: "object",
|
|
235
|
+
transform: {
|
|
236
|
+
position: gltfNode.translation || [0, 0, 0],
|
|
237
|
+
rotation: gltfNode.rotation ? {
|
|
238
|
+
x: gltfNode.rotation[0],
|
|
239
|
+
y: gltfNode.rotation[1],
|
|
240
|
+
z: gltfNode.rotation[2],
|
|
241
|
+
w: gltfNode.rotation[3]
|
|
242
|
+
} : { x: 0, y: 0, z: 0, w: 1 },
|
|
243
|
+
scale: gltfNode.scale || [1, 1, 1]
|
|
244
|
+
},
|
|
245
|
+
children,
|
|
246
|
+
components,
|
|
247
|
+
active: true,
|
|
248
|
+
layers: 1,
|
|
249
|
+
tags: [],
|
|
250
|
+
metadata: {}
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
const scene = doc.scenes?.[doc.scene ?? 0];
|
|
254
|
+
const rootChildren = (scene?.nodes || []).map((ni) => buildNode(doc.nodes[ni], ni));
|
|
255
|
+
const root = {
|
|
256
|
+
id: "root",
|
|
257
|
+
name: "Root",
|
|
258
|
+
type: "group",
|
|
259
|
+
transform: {
|
|
260
|
+
position: [0, 0, 0],
|
|
261
|
+
rotation: { x: 0, y: 0, z: 0, w: 1 },
|
|
262
|
+
scale: [1, 1, 1]
|
|
263
|
+
},
|
|
264
|
+
children: rootChildren,
|
|
265
|
+
components: [],
|
|
266
|
+
active: true,
|
|
267
|
+
layers: 1,
|
|
268
|
+
tags: [],
|
|
269
|
+
metadata: {}
|
|
270
|
+
};
|
|
271
|
+
const sgAnimations = (doc.animations || []).map((anim, i) => {
|
|
272
|
+
const channels = anim.channels.map((ch) => ({
|
|
273
|
+
targetNode: nodeIdMap.get(ch.target.node) || `node_${ch.target.node}`,
|
|
274
|
+
targetPath: ch.target.path,
|
|
275
|
+
samplerIndex: ch.sampler
|
|
276
|
+
}));
|
|
277
|
+
const samplers = anim.samplers.map((s) => ({
|
|
278
|
+
inputBufferView: s.input,
|
|
279
|
+
outputBufferView: s.output,
|
|
280
|
+
interpolation: s.interpolation?.toLowerCase() || "linear"
|
|
281
|
+
}));
|
|
282
|
+
return {
|
|
283
|
+
id: `anim_${i}`,
|
|
284
|
+
name: anim.name || `Animation_${i}`,
|
|
285
|
+
duration: 0,
|
|
286
|
+
channels,
|
|
287
|
+
samplers
|
|
288
|
+
};
|
|
289
|
+
});
|
|
290
|
+
return {
|
|
291
|
+
version: "3.3.0",
|
|
292
|
+
generator: "HoloScript USDZExporter (GLTF bridge)",
|
|
293
|
+
metadata: {
|
|
294
|
+
name: "GLTFImport",
|
|
295
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
296
|
+
modifiedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
297
|
+
tags: [],
|
|
298
|
+
properties: {}
|
|
299
|
+
},
|
|
300
|
+
root,
|
|
301
|
+
materials: sgMaterials,
|
|
302
|
+
textures: [],
|
|
303
|
+
meshes: sgMeshes,
|
|
304
|
+
buffers: sgBuffers,
|
|
305
|
+
bufferViews: sgBufferViews,
|
|
306
|
+
accessors: sgAccessors,
|
|
307
|
+
animations: sgAnimations,
|
|
308
|
+
skins: [],
|
|
309
|
+
extensions: {},
|
|
310
|
+
extras: {}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
extractGLTFBuffers(gltfResult) {
|
|
314
|
+
const doc = gltfResult.document;
|
|
315
|
+
if (gltfResult.glb) {
|
|
316
|
+
const binChunk = this.extractGLBBinChunk(gltfResult.glb);
|
|
317
|
+
if (binChunk) return [binChunk];
|
|
318
|
+
}
|
|
319
|
+
const buffers = [];
|
|
320
|
+
for (const buffer of doc.buffers || []) {
|
|
321
|
+
if (buffer.uri) {
|
|
322
|
+
const resource = gltfResult.resources.get(buffer.uri);
|
|
323
|
+
if (resource) {
|
|
324
|
+
buffers.push(resource);
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
buffers.push(new ArrayBuffer(buffer.byteLength));
|
|
329
|
+
}
|
|
330
|
+
return buffers;
|
|
331
|
+
}
|
|
332
|
+
extractGLBBinChunk(glb) {
|
|
333
|
+
const view = new DataView(glb);
|
|
334
|
+
const magic = view.getUint32(0, true);
|
|
335
|
+
if (magic !== 1179937895) return void 0;
|
|
336
|
+
const version = view.getUint32(4, true);
|
|
337
|
+
if (version !== 2) return void 0;
|
|
338
|
+
const length = view.getUint32(8, true);
|
|
339
|
+
let offset = 12;
|
|
340
|
+
while (offset < length) {
|
|
341
|
+
const chunkLength = view.getUint32(offset, true);
|
|
342
|
+
const chunkType = view.getUint32(offset + 4, true);
|
|
343
|
+
offset += 8;
|
|
344
|
+
if (chunkType === 5130562) {
|
|
345
|
+
return glb.slice(offset, offset + chunkLength);
|
|
346
|
+
}
|
|
347
|
+
offset += chunkLength;
|
|
348
|
+
}
|
|
349
|
+
return void 0;
|
|
350
|
+
}
|
|
351
|
+
mapGLTFPrimitiveMode(mode) {
|
|
352
|
+
const modes = ["points", "lines", "lineLoop", "lineStrip", "triangles", "triangleStrip", "triangleFan"];
|
|
353
|
+
return modes[mode ?? 4] || "triangles";
|
|
354
|
+
}
|
|
355
|
+
mapGLTFTextureRef(index, uvChannel) {
|
|
356
|
+
return {
|
|
357
|
+
id: `tex_${index}`,
|
|
358
|
+
uvChannel,
|
|
359
|
+
offset: { u: 0, v: 0 },
|
|
360
|
+
scale: { u: 1, v: 1 },
|
|
361
|
+
rotation: 0
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
// ========================================================================
|
|
365
|
+
// Private Methods - Stage Creation
|
|
366
|
+
// ========================================================================
|
|
367
|
+
createStage(sceneGraph) {
|
|
368
|
+
return {
|
|
369
|
+
metadata: {
|
|
370
|
+
version: "0.10.0",
|
|
371
|
+
upAxis: this.options.upAxis,
|
|
372
|
+
metersPerUnit: this.options.metersPerUnit,
|
|
373
|
+
comment: `Generated by ${sceneGraph.generator || "HoloScript USDZExporter"}`
|
|
374
|
+
},
|
|
375
|
+
defaultPrim: "Root",
|
|
376
|
+
prims: [],
|
|
377
|
+
customLayerData: {
|
|
378
|
+
creator: sceneGraph.generator,
|
|
379
|
+
holoscriptVersion: sceneGraph.version
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
async convertSceneGraph(sceneGraph) {
|
|
384
|
+
this.cacheAccessorData(sceneGraph);
|
|
385
|
+
const rootPrim = createUSDXform("Root", "/Root");
|
|
386
|
+
this.stage.prims.push(rootPrim);
|
|
387
|
+
await this.convertMaterials(sceneGraph.materials || []);
|
|
388
|
+
await this.convertMeshes(sceneGraph.meshes || [], sceneGraph);
|
|
389
|
+
this.convertNode(sceneGraph.root, rootPrim, sceneGraph);
|
|
390
|
+
if (this.options.includeAnimations && sceneGraph.animations?.length) {
|
|
391
|
+
this.convertAnimations(sceneGraph.animations);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
cacheAccessorData(sceneGraph) {
|
|
395
|
+
for (let i = 0; i < (sceneGraph.accessors || []).length; i++) {
|
|
396
|
+
const data = this.extractAccessorData(i, sceneGraph);
|
|
397
|
+
this.sceneGraphAccessorData.set(i, data);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
// ========================================================================
|
|
401
|
+
// Private Methods - Node Conversion
|
|
402
|
+
// ========================================================================
|
|
403
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Deep nested scene graph node access
|
|
404
|
+
convertNode(node, parentPrim, sceneGraph, depth = 0) {
|
|
405
|
+
if (!node || depth > 100) return;
|
|
406
|
+
const nodeName = sanitizeUSDName(node.name || `Node_${this.primCounter++}`);
|
|
407
|
+
const nodePath = `${parentPrim.path}/${nodeName}`;
|
|
408
|
+
const xformPrim = createUSDXform(nodeName, nodePath);
|
|
409
|
+
if (node.id) {
|
|
410
|
+
this.nodePrimMap.set(node.id, xformPrim);
|
|
411
|
+
}
|
|
412
|
+
if (node.transform) {
|
|
413
|
+
this.addTransform(xformPrim, node.transform);
|
|
414
|
+
}
|
|
415
|
+
if (!parentPrim.children) parentPrim.children = [];
|
|
416
|
+
parentPrim.children.push(xformPrim);
|
|
417
|
+
const meshComp = node.components?.find((c) => c.type === "mesh");
|
|
418
|
+
if (meshComp?.meshRef) {
|
|
419
|
+
const meshPath = this.meshMap.get(meshComp.meshRef);
|
|
420
|
+
if (meshPath) {
|
|
421
|
+
xformPrim.relationships = [
|
|
422
|
+
{
|
|
423
|
+
name: "mesh",
|
|
424
|
+
targets: [meshPath]
|
|
425
|
+
}
|
|
426
|
+
];
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (node.children?.length) {
|
|
430
|
+
for (const child of node.children) {
|
|
431
|
+
this.convertNode(child, xformPrim, sceneGraph, depth + 1);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Deep nested transform object access (position[0]/y/z, rotation[0]/y/z/w, scale[0]/y/z)
|
|
436
|
+
addTransform(prim, transform) {
|
|
437
|
+
const ops = [];
|
|
438
|
+
if (transform.position) {
|
|
439
|
+
ops.push({
|
|
440
|
+
type: "translate",
|
|
441
|
+
value: [transform.position[0], transform.position[1], transform.position[2]]
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
if (transform.rotation) {
|
|
445
|
+
const euler = quaternionToEuler([
|
|
446
|
+
transform.rotation[0],
|
|
447
|
+
transform.rotation[1],
|
|
448
|
+
transform.rotation[2],
|
|
449
|
+
transform.rotation[3]
|
|
450
|
+
]);
|
|
451
|
+
ops.push({
|
|
452
|
+
type: "rotateXYZ",
|
|
453
|
+
value: euler
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
if (transform.scale) {
|
|
457
|
+
ops.push({
|
|
458
|
+
type: "scale",
|
|
459
|
+
value: [transform.scale[0], transform.scale[1], transform.scale[2]]
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
if (ops.length > 0) {
|
|
463
|
+
prim.attributes.push({
|
|
464
|
+
name: "xformOpOrder",
|
|
465
|
+
type: "token[]",
|
|
466
|
+
value: ops.map((op) => `xformOp:${op.type}`)
|
|
467
|
+
});
|
|
468
|
+
for (const op of ops) {
|
|
469
|
+
prim.attributes.push({
|
|
470
|
+
name: `xformOp:${op.type}`,
|
|
471
|
+
type: this.getXformOpType(op.type),
|
|
472
|
+
value: op.value
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
getXformOpType(opType) {
|
|
478
|
+
switch (opType) {
|
|
479
|
+
case "translate":
|
|
480
|
+
return "float3";
|
|
481
|
+
case "rotateXYZ":
|
|
482
|
+
return "float3";
|
|
483
|
+
case "rotateX":
|
|
484
|
+
case "rotateY":
|
|
485
|
+
case "rotateZ":
|
|
486
|
+
return "float";
|
|
487
|
+
case "scale":
|
|
488
|
+
return "float3";
|
|
489
|
+
case "transform":
|
|
490
|
+
return "matrix4d";
|
|
491
|
+
default:
|
|
492
|
+
return "float3";
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// ========================================================================
|
|
496
|
+
// Private Methods - Material Conversion
|
|
497
|
+
// ========================================================================
|
|
498
|
+
async convertMaterials(materials) {
|
|
499
|
+
for (const material of materials) {
|
|
500
|
+
await this.convertMaterial(material);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
async convertMaterial(material) {
|
|
504
|
+
const matName = sanitizeUSDName(material.name || `Material_${this.primCounter++}`);
|
|
505
|
+
const matPath = `/Root/Materials/${matName}`;
|
|
506
|
+
const mapping = this.createMaterialMapping(material);
|
|
507
|
+
const inputs = {
|
|
508
|
+
diffuseColor: mapping.baseColor.slice(0, 3),
|
|
509
|
+
// RGB only
|
|
510
|
+
metallic: mapping.metallic,
|
|
511
|
+
roughness: mapping.roughness,
|
|
512
|
+
emissiveColor: mapping.emissive
|
|
513
|
+
};
|
|
514
|
+
if (material.alphaMode === "blend" || material.alphaMode === "mask") {
|
|
515
|
+
inputs.opacity = mapping.baseColor[3];
|
|
516
|
+
if (material.alphaMode === "mask") {
|
|
517
|
+
inputs.opacityThreshold = mapping.alphaCutoff || 0.5;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const usdMaterial = createUSDPreviewSurfaceMaterial(matName, matPath, inputs);
|
|
521
|
+
if (mapping.baseColorTexture) {
|
|
522
|
+
await this.addTextureToMaterial(usdMaterial, "diffuseColor", mapping.baseColorTexture);
|
|
523
|
+
}
|
|
524
|
+
if (mapping.normalTexture) {
|
|
525
|
+
await this.addTextureToMaterial(usdMaterial, "normal", mapping.normalTexture);
|
|
526
|
+
}
|
|
527
|
+
if (mapping.occlusionTexture) {
|
|
528
|
+
await this.addTextureToMaterial(usdMaterial, "occlusion", mapping.occlusionTexture);
|
|
529
|
+
}
|
|
530
|
+
if (!this.stage.prims[0].children) this.stage.prims[0].children = [];
|
|
531
|
+
let materialsScope = this.stage.prims[0].children.find((p) => p.name === "Materials");
|
|
532
|
+
if (!materialsScope) {
|
|
533
|
+
materialsScope = {
|
|
534
|
+
path: "/Root/Materials",
|
|
535
|
+
type: "Scope",
|
|
536
|
+
name: "Materials",
|
|
537
|
+
attributes: [],
|
|
538
|
+
children: []
|
|
539
|
+
};
|
|
540
|
+
this.stage.prims[0].children.push(materialsScope);
|
|
541
|
+
}
|
|
542
|
+
materialsScope.children.push(usdMaterial);
|
|
543
|
+
this.materialMap.set(material.id, matPath);
|
|
544
|
+
}
|
|
545
|
+
createMaterialMapping(material) {
|
|
546
|
+
return {
|
|
547
|
+
baseColor: material.baseColor || [1, 1, 1, 1],
|
|
548
|
+
metallic: material.metallic ?? 0,
|
|
549
|
+
roughness: material.roughness ?? 0.5,
|
|
550
|
+
emissive: material.emissiveColor || [0, 0, 0],
|
|
551
|
+
alphaMode: material.alphaMode,
|
|
552
|
+
alphaCutoff: material.alphaCutoff
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
async addTextureToMaterial(material, inputName, textureRef) {
|
|
556
|
+
const shader = material.children?.[0];
|
|
557
|
+
if (shader?.inputs) {
|
|
558
|
+
shader.inputs.push({
|
|
559
|
+
name: inputName,
|
|
560
|
+
type: "asset",
|
|
561
|
+
value: { path: textureRef }
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
// ========================================================================
|
|
566
|
+
// Private Methods - Mesh Conversion
|
|
567
|
+
// ========================================================================
|
|
568
|
+
async convertMeshes(meshes, sceneGraph) {
|
|
569
|
+
for (const mesh of meshes) {
|
|
570
|
+
await this.convertMesh(mesh, sceneGraph);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
async convertMesh(mesh, sceneGraph) {
|
|
574
|
+
const meshName = sanitizeUSDName(mesh.name || `Mesh_${this.primCounter++}`);
|
|
575
|
+
const meshPath = `/Root/Geometry/${meshName}`;
|
|
576
|
+
let geometryScope = this.stage.prims[0].children?.find((p) => p.name === "Geometry");
|
|
577
|
+
if (!geometryScope) {
|
|
578
|
+
geometryScope = {
|
|
579
|
+
path: "/Root/Geometry",
|
|
580
|
+
type: "Scope",
|
|
581
|
+
name: "Geometry",
|
|
582
|
+
attributes: [],
|
|
583
|
+
children: []
|
|
584
|
+
};
|
|
585
|
+
if (!this.stage.prims[0].children) this.stage.prims[0].children = [];
|
|
586
|
+
this.stage.prims[0].children.push(geometryScope);
|
|
587
|
+
}
|
|
588
|
+
for (let i = 0; i < mesh.primitives.length; i++) {
|
|
589
|
+
const primitive = mesh.primitives[i];
|
|
590
|
+
const primName = mesh.primitives.length > 1 ? `${meshName}_${i}` : meshName;
|
|
591
|
+
const primPath = mesh.primitives.length > 1 ? `${meshPath}_${i}` : meshPath;
|
|
592
|
+
const usdMesh = await this.convertMeshPrimitive(primitive, primName, primPath, sceneGraph);
|
|
593
|
+
geometryScope.children.push(usdMesh);
|
|
594
|
+
this.meshMap.set(mesh.id, primPath);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
async convertMeshPrimitive(primitive, name, path, sceneGraph) {
|
|
598
|
+
const positions = this.extractAccessorData(primitive.attributes.POSITION, sceneGraph);
|
|
599
|
+
const normals = primitive.attributes.NORMAL ? this.extractAccessorData(primitive.attributes.NORMAL, sceneGraph) : void 0;
|
|
600
|
+
const uvs = primitive.attributes.TEXCOORD_0 ? this.extractAccessorData(primitive.attributes.TEXCOORD_0, sceneGraph) : void 0;
|
|
601
|
+
const indices = primitive.indices !== void 0 ? this.extractAccessorData(primitive.indices, sceneGraph) : void 0;
|
|
602
|
+
const { faceVertexCounts, faceVertexIndices } = this.buildFaceData(
|
|
603
|
+
indices,
|
|
604
|
+
positions.length / 3
|
|
605
|
+
);
|
|
606
|
+
const usdMesh = {
|
|
607
|
+
path,
|
|
608
|
+
type: "Mesh",
|
|
609
|
+
name,
|
|
610
|
+
attributes: [],
|
|
611
|
+
faceVertexCounts,
|
|
612
|
+
faceVertexIndices,
|
|
613
|
+
points: positions
|
|
614
|
+
};
|
|
615
|
+
if (normals) {
|
|
616
|
+
usdMesh.normals = normals;
|
|
617
|
+
usdMesh.attributes.push({
|
|
618
|
+
name: "primvars:normals",
|
|
619
|
+
type: "normal3f[]",
|
|
620
|
+
value: normals
|
|
621
|
+
});
|
|
622
|
+
usdMesh.attributes.push({
|
|
623
|
+
name: "primvars:normals:interpolation",
|
|
624
|
+
type: "token",
|
|
625
|
+
value: "vertex"
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
if (uvs) {
|
|
629
|
+
usdMesh.primvars = [
|
|
630
|
+
{
|
|
631
|
+
name: "st",
|
|
632
|
+
type: "texCoord2f[]",
|
|
633
|
+
interpolation: "vertex",
|
|
634
|
+
values: uvs
|
|
635
|
+
}
|
|
636
|
+
];
|
|
637
|
+
}
|
|
638
|
+
if (primitive.materialRef) {
|
|
639
|
+
const matPath = this.materialMap.get(primitive.materialRef);
|
|
640
|
+
if (matPath) {
|
|
641
|
+
usdMesh.relationships = [
|
|
642
|
+
{
|
|
643
|
+
name: "material:binding",
|
|
644
|
+
targets: [matPath]
|
|
645
|
+
}
|
|
646
|
+
];
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return usdMesh;
|
|
650
|
+
}
|
|
651
|
+
extractAccessorData(accessorIndex, sceneGraph) {
|
|
652
|
+
const accessor = sceneGraph.accessors[accessorIndex];
|
|
653
|
+
if (!accessor) return [];
|
|
654
|
+
const bufferView = sceneGraph.bufferViews[accessor.bufferViewIndex];
|
|
655
|
+
const buffer = sceneGraph.buffers[bufferView.bufferIndex];
|
|
656
|
+
if (!buffer.data) return [];
|
|
657
|
+
const arrayView = this.getTypedArray(
|
|
658
|
+
buffer.data,
|
|
659
|
+
bufferView.byteOffset + accessor.byteOffset,
|
|
660
|
+
accessor.count * this.getComponentCount(accessor.type),
|
|
661
|
+
accessor.componentType
|
|
662
|
+
);
|
|
663
|
+
return Array.from(arrayView);
|
|
664
|
+
}
|
|
665
|
+
getTypedArray(buffer, offset, length, componentType) {
|
|
666
|
+
switch (componentType) {
|
|
667
|
+
case "float":
|
|
668
|
+
return new Float32Array(buffer, offset, length);
|
|
669
|
+
case "ushort":
|
|
670
|
+
return new Uint16Array(buffer, offset, length);
|
|
671
|
+
case "uint":
|
|
672
|
+
return new Uint32Array(buffer, offset, length);
|
|
673
|
+
default:
|
|
674
|
+
return new Float32Array(buffer, offset, length);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
getComponentCount(type) {
|
|
678
|
+
switch (type.toLowerCase()) {
|
|
679
|
+
case "scalar":
|
|
680
|
+
return 1;
|
|
681
|
+
case "vec2":
|
|
682
|
+
return 2;
|
|
683
|
+
case "vec3":
|
|
684
|
+
return 3;
|
|
685
|
+
case "vec4":
|
|
686
|
+
return 4;
|
|
687
|
+
case "mat2":
|
|
688
|
+
return 4;
|
|
689
|
+
case "mat3":
|
|
690
|
+
return 9;
|
|
691
|
+
case "mat4":
|
|
692
|
+
return 16;
|
|
693
|
+
default:
|
|
694
|
+
return 1;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
buildFaceData(indices, vertexCount) {
|
|
698
|
+
if (indices && indices.length > 0) {
|
|
699
|
+
const faceCount = Math.floor(indices.length / 3);
|
|
700
|
+
return {
|
|
701
|
+
faceVertexCounts: new Array(faceCount).fill(3),
|
|
702
|
+
faceVertexIndices: indices
|
|
703
|
+
};
|
|
704
|
+
} else if (vertexCount > 0) {
|
|
705
|
+
const faceCount = Math.floor(vertexCount / 3);
|
|
706
|
+
return {
|
|
707
|
+
faceVertexCounts: new Array(faceCount).fill(3),
|
|
708
|
+
faceVertexIndices: Array.from({ length: vertexCount }, (_, i) => i)
|
|
709
|
+
};
|
|
710
|
+
} else {
|
|
711
|
+
return {
|
|
712
|
+
faceVertexCounts: [],
|
|
713
|
+
faceVertexIndices: []
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
// ========================================================================
|
|
718
|
+
// Private Methods - Animation Conversion
|
|
719
|
+
// ========================================================================
|
|
720
|
+
convertAnimations(animations) {
|
|
721
|
+
for (const animation of animations) {
|
|
722
|
+
this.convertAnimation(animation);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
convertAnimation(animation) {
|
|
726
|
+
const channelsByNode = /* @__PURE__ */ new Map();
|
|
727
|
+
for (const channel of animation.channels) {
|
|
728
|
+
const list = channelsByNode.get(channel.targetNode) || [];
|
|
729
|
+
list.push(channel);
|
|
730
|
+
channelsByNode.set(channel.targetNode, list);
|
|
731
|
+
}
|
|
732
|
+
for (const [nodeId, channels] of Array.from(channelsByNode.entries())) {
|
|
733
|
+
const prim = this.nodePrimMap.get(nodeId);
|
|
734
|
+
if (!prim) continue;
|
|
735
|
+
for (const channel of channels) {
|
|
736
|
+
this.applyAnimationChannel(prim, channel, animation.samplers);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
applyAnimationChannel(prim, channel, samplers) {
|
|
741
|
+
const sampler = samplers[channel.samplerIndex];
|
|
742
|
+
if (!sampler) return;
|
|
743
|
+
const times = this.extractAccessorDataFlat(sampler.inputBufferView);
|
|
744
|
+
const values = this.extractAccessorDataFlat(sampler.outputBufferView);
|
|
745
|
+
if (times.length === 0 || values.length === 0) return;
|
|
746
|
+
const timeSamples = /* @__PURE__ */ new Map();
|
|
747
|
+
switch (channel.targetPath) {
|
|
748
|
+
case "translation": {
|
|
749
|
+
for (let i = 0; i < times.length; i++) {
|
|
750
|
+
timeSamples.set(times[i], [values[i * 3], values[i * 3 + 1], values[i * 3 + 2]]);
|
|
751
|
+
}
|
|
752
|
+
this.setXformOpTimeSamples(prim, "xformOp:translate", "float3", timeSamples);
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
case "rotation": {
|
|
756
|
+
for (let i = 0; i < times.length; i++) {
|
|
757
|
+
const qx = values[i * 4];
|
|
758
|
+
const qy = values[i * 4 + 1];
|
|
759
|
+
const qz = values[i * 4 + 2];
|
|
760
|
+
const qw = values[i * 4 + 3];
|
|
761
|
+
const euler = quaternionToEuler([qx, qy, qz, qw]);
|
|
762
|
+
timeSamples.set(times[i], euler);
|
|
763
|
+
}
|
|
764
|
+
this.setXformOpTimeSamples(prim, "xformOp:rotateXYZ", "float3", timeSamples);
|
|
765
|
+
break;
|
|
766
|
+
}
|
|
767
|
+
case "scale": {
|
|
768
|
+
for (let i = 0; i < times.length; i++) {
|
|
769
|
+
timeSamples.set(times[i], [values[i * 3], values[i * 3 + 1], values[i * 3 + 2]]);
|
|
770
|
+
}
|
|
771
|
+
this.setXformOpTimeSamples(prim, "xformOp:scale", "float3", timeSamples);
|
|
772
|
+
break;
|
|
773
|
+
}
|
|
774
|
+
case "weights": {
|
|
775
|
+
console.warn(`Morph target animation not yet supported for ${prim.name}`);
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
extractAccessorDataFlat(accessorIndex) {
|
|
781
|
+
return this.sceneGraphAccessorData.get(accessorIndex) || [];
|
|
782
|
+
}
|
|
783
|
+
setXformOpTimeSamples(prim, opName, type, timeSamples) {
|
|
784
|
+
let attr = prim.attributes.find((a) => a.name === opName);
|
|
785
|
+
if (!attr) {
|
|
786
|
+
attr = { name: opName, type, value: timeSamples.values().next().value || [] };
|
|
787
|
+
prim.attributes.push(attr);
|
|
788
|
+
}
|
|
789
|
+
attr.timeSamples = timeSamples;
|
|
790
|
+
}
|
|
791
|
+
// ========================================================================
|
|
792
|
+
// Private Methods - AR Metadata
|
|
793
|
+
// ========================================================================
|
|
794
|
+
addARMetadata() {
|
|
795
|
+
const metadata = {
|
|
796
|
+
arBehaviors: {
|
|
797
|
+
allowsContentScaling: this.options.allowContentScaling,
|
|
798
|
+
hasLookAtCamera: this.options.lookAtCamera,
|
|
799
|
+
initialPlacementMode: this.options.placementMode,
|
|
800
|
+
enableOcclusion: this.options.enableOcclusion
|
|
801
|
+
},
|
|
802
|
+
canonicalCameraDistance: this.options.canonicalCameraDistance
|
|
803
|
+
};
|
|
804
|
+
if (!this.stage.customLayerData) this.stage.customLayerData = {};
|
|
805
|
+
this.stage.customLayerData.arQuickLook = metadata;
|
|
806
|
+
if (this.stage.prims[0]) {
|
|
807
|
+
if (!this.stage.prims[0].metadata) this.stage.prims[0].metadata = {};
|
|
808
|
+
this.stage.prims[0].metadata.arQuickLook = metadata;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
// ========================================================================
|
|
812
|
+
// Private Methods - USDZ Packaging
|
|
813
|
+
// ========================================================================
|
|
814
|
+
async packageUSDZ() {
|
|
815
|
+
const usdContent = this.serializeUSD(this.stage);
|
|
816
|
+
const mainFile = {
|
|
817
|
+
path: "scene.usda",
|
|
818
|
+
data: new TextEncoder().encode(usdContent).buffer,
|
|
819
|
+
mimeType: "text/plain"
|
|
820
|
+
};
|
|
821
|
+
const package_ = {
|
|
822
|
+
mainFile,
|
|
823
|
+
files: this.textureFiles
|
|
824
|
+
};
|
|
825
|
+
return this.createZipArchive(package_);
|
|
826
|
+
}
|
|
827
|
+
serializeUSD(stage) {
|
|
828
|
+
const lines = [];
|
|
829
|
+
lines.push("#usda 1.0");
|
|
830
|
+
lines.push("(");
|
|
831
|
+
if (stage.defaultPrim) {
|
|
832
|
+
lines.push(` defaultPrim = "${stage.defaultPrim}"`);
|
|
833
|
+
}
|
|
834
|
+
if (stage.metadata.upAxis) {
|
|
835
|
+
lines.push(` upAxis = "${stage.metadata.upAxis}"`);
|
|
836
|
+
}
|
|
837
|
+
if (stage.metadata.metersPerUnit) {
|
|
838
|
+
lines.push(` metersPerUnit = ${stage.metadata.metersPerUnit}`);
|
|
839
|
+
}
|
|
840
|
+
lines.push(")");
|
|
841
|
+
lines.push("");
|
|
842
|
+
for (const prim of stage.prims) {
|
|
843
|
+
this.serializePrim(prim, lines, 0);
|
|
844
|
+
}
|
|
845
|
+
return lines.join("\n");
|
|
846
|
+
}
|
|
847
|
+
serializePrim(prim, lines, indent) {
|
|
848
|
+
const ind = " ".repeat(indent);
|
|
849
|
+
lines.push(`${ind}def ${prim.type} "${prim.name}"`);
|
|
850
|
+
lines.push(`${ind}{`);
|
|
851
|
+
for (const attr of prim.attributes) {
|
|
852
|
+
this.serializeAttribute(attr, lines, indent + 1);
|
|
853
|
+
}
|
|
854
|
+
if (prim.relationships) {
|
|
855
|
+
for (const rel of prim.relationships) {
|
|
856
|
+
const relInd = " ".repeat(indent + 1);
|
|
857
|
+
const targets = rel.targets.map((t) => `<${t}>`).join(", ");
|
|
858
|
+
lines.push(`${relInd}rel ${rel.name} = [${targets}]`);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if (prim.children) {
|
|
862
|
+
for (const child of prim.children) {
|
|
863
|
+
lines.push("");
|
|
864
|
+
this.serializePrim(child, lines, indent + 1);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
lines.push(`${ind}}`);
|
|
868
|
+
}
|
|
869
|
+
serializeAttribute(attr, lines, indent) {
|
|
870
|
+
const ind = " ".repeat(indent);
|
|
871
|
+
if (attr.timeSamples && attr.timeSamples.size > 0) {
|
|
872
|
+
lines.push(`${ind}${attr.type} ${attr.name}.timeSamples = {`);
|
|
873
|
+
for (const [time, sample] of Array.from(attr.timeSamples.entries())) {
|
|
874
|
+
const serializedSample = this.serializeValue(sample, attr.type);
|
|
875
|
+
lines.push(`${ind} ${time}: ${serializedSample},`);
|
|
876
|
+
}
|
|
877
|
+
lines.push(`${ind}}`);
|
|
878
|
+
} else {
|
|
879
|
+
const value = this.serializeValue(attr.value, attr.type);
|
|
880
|
+
lines.push(`${ind}${attr.type} ${attr.name} = ${value}`);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
serializeValue(value, type) {
|
|
884
|
+
if (Array.isArray(value)) {
|
|
885
|
+
if (type.includes("[]")) {
|
|
886
|
+
return `[${value.map((v) => this.serializeScalar(v, type.replace("[]", ""))).join(", ")}]`;
|
|
887
|
+
} else {
|
|
888
|
+
return `(${value.join(", ")})`;
|
|
889
|
+
}
|
|
890
|
+
} else if (typeof value === "string") {
|
|
891
|
+
return `"${value}"`;
|
|
892
|
+
} else if (typeof value === "object" && value !== null && "path" in value) {
|
|
893
|
+
return `@${value.path}@`;
|
|
894
|
+
} else {
|
|
895
|
+
return String(value);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
serializeScalar(value, _type) {
|
|
899
|
+
if (typeof value === "string") {
|
|
900
|
+
return `"${value}"`;
|
|
901
|
+
}
|
|
902
|
+
return String(value);
|
|
903
|
+
}
|
|
904
|
+
async createZipArchive(package_) {
|
|
905
|
+
const files = [package_.mainFile, ...package_.files];
|
|
906
|
+
let totalSize = 0;
|
|
907
|
+
const fileEntries = [];
|
|
908
|
+
const localHeaderSize = 30;
|
|
909
|
+
const centralHeaderSize = 46;
|
|
910
|
+
const endCentralSize = 22;
|
|
911
|
+
for (const file of files) {
|
|
912
|
+
const nameBytes = new TextEncoder().encode(file.path);
|
|
913
|
+
fileEntries.push({
|
|
914
|
+
name: file.path,
|
|
915
|
+
data: file.data,
|
|
916
|
+
offset: totalSize
|
|
917
|
+
});
|
|
918
|
+
totalSize += localHeaderSize + nameBytes.length + file.data.byteLength;
|
|
919
|
+
}
|
|
920
|
+
const centralDirOffset = totalSize;
|
|
921
|
+
let centralDirSize = 0;
|
|
922
|
+
for (const entry of fileEntries) {
|
|
923
|
+
const nameBytes = new TextEncoder().encode(entry.name);
|
|
924
|
+
centralDirSize += centralHeaderSize + nameBytes.length;
|
|
925
|
+
}
|
|
926
|
+
totalSize += centralDirSize + endCentralSize;
|
|
927
|
+
const buffer = new ArrayBuffer(totalSize);
|
|
928
|
+
const view = new DataView(buffer);
|
|
929
|
+
const bytes = new Uint8Array(buffer);
|
|
930
|
+
let offset = 0;
|
|
931
|
+
for (const entry of fileEntries) {
|
|
932
|
+
const nameBytes = new TextEncoder().encode(entry.name);
|
|
933
|
+
view.setUint32(offset, 67324752, true);
|
|
934
|
+
view.setUint16(offset + 4, 20, true);
|
|
935
|
+
view.setUint16(offset + 6, 0, true);
|
|
936
|
+
view.setUint16(offset + 8, 0, true);
|
|
937
|
+
view.setUint16(offset + 10, 0, true);
|
|
938
|
+
view.setUint16(offset + 12, 0, true);
|
|
939
|
+
view.setUint32(offset + 14, 0, true);
|
|
940
|
+
view.setUint32(offset + 18, entry.data.byteLength, true);
|
|
941
|
+
view.setUint32(offset + 22, entry.data.byteLength, true);
|
|
942
|
+
view.setUint16(offset + 26, nameBytes.length, true);
|
|
943
|
+
view.setUint16(offset + 28, 0, true);
|
|
944
|
+
offset += 30;
|
|
945
|
+
bytes.set(nameBytes, offset);
|
|
946
|
+
offset += nameBytes.length;
|
|
947
|
+
bytes.set(new Uint8Array(entry.data), offset);
|
|
948
|
+
offset += entry.data.byteLength;
|
|
949
|
+
}
|
|
950
|
+
for (const entry of fileEntries) {
|
|
951
|
+
const nameBytes = new TextEncoder().encode(entry.name);
|
|
952
|
+
view.setUint32(offset, 33639248, true);
|
|
953
|
+
view.setUint16(offset + 4, 20, true);
|
|
954
|
+
view.setUint16(offset + 6, 20, true);
|
|
955
|
+
view.setUint16(offset + 8, 0, true);
|
|
956
|
+
view.setUint16(offset + 10, 0, true);
|
|
957
|
+
view.setUint16(offset + 12, 0, true);
|
|
958
|
+
view.setUint16(offset + 14, 0, true);
|
|
959
|
+
view.setUint32(offset + 16, 0, true);
|
|
960
|
+
view.setUint32(offset + 20, entry.data.byteLength, true);
|
|
961
|
+
view.setUint32(offset + 24, entry.data.byteLength, true);
|
|
962
|
+
view.setUint16(offset + 28, nameBytes.length, true);
|
|
963
|
+
view.setUint16(offset + 30, 0, true);
|
|
964
|
+
view.setUint16(offset + 32, 0, true);
|
|
965
|
+
view.setUint16(offset + 34, 0, true);
|
|
966
|
+
view.setUint16(offset + 36, 0, true);
|
|
967
|
+
view.setUint32(offset + 38, 0, true);
|
|
968
|
+
view.setUint32(offset + 42, entry.offset, true);
|
|
969
|
+
offset += 46;
|
|
970
|
+
bytes.set(nameBytes, offset);
|
|
971
|
+
offset += nameBytes.length;
|
|
972
|
+
}
|
|
973
|
+
view.setUint32(offset, 101010256, true);
|
|
974
|
+
view.setUint16(offset + 4, 0, true);
|
|
975
|
+
view.setUint16(offset + 6, 0, true);
|
|
976
|
+
view.setUint16(offset + 8, fileEntries.length, true);
|
|
977
|
+
view.setUint16(offset + 10, fileEntries.length, true);
|
|
978
|
+
view.setUint32(offset + 12, centralDirSize, true);
|
|
979
|
+
view.setUint32(offset + 16, centralDirOffset, true);
|
|
980
|
+
view.setUint16(offset + 20, 0, true);
|
|
981
|
+
return buffer;
|
|
982
|
+
}
|
|
983
|
+
// ========================================================================
|
|
984
|
+
// Private Methods - Utilities
|
|
985
|
+
// ========================================================================
|
|
986
|
+
reset() {
|
|
987
|
+
this.primCounter = 0;
|
|
988
|
+
this.materialMap.clear();
|
|
989
|
+
this.meshMap.clear();
|
|
990
|
+
this.nodePrimMap.clear();
|
|
991
|
+
this.sceneGraphAccessorData.clear();
|
|
992
|
+
this.textureFiles = [];
|
|
993
|
+
}
|
|
994
|
+
calculateStats(usdzSize, exportTime) {
|
|
995
|
+
let primCount = 0;
|
|
996
|
+
let meshCount = 0;
|
|
997
|
+
let materialCount = 0;
|
|
998
|
+
const countPrims = (prim) => {
|
|
999
|
+
primCount++;
|
|
1000
|
+
if (prim.type === "Mesh") meshCount++;
|
|
1001
|
+
if (prim.type === "Material") materialCount++;
|
|
1002
|
+
if (prim.children) {
|
|
1003
|
+
for (const child of prim.children) countPrims(child);
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
for (const prim of this.stage.prims) {
|
|
1007
|
+
countPrims(prim);
|
|
1008
|
+
}
|
|
1009
|
+
return {
|
|
1010
|
+
primCount,
|
|
1011
|
+
meshCount,
|
|
1012
|
+
materialCount,
|
|
1013
|
+
textureCount: this.textureFiles.length,
|
|
1014
|
+
fileCount: 1 + this.textureFiles.length,
|
|
1015
|
+
usdzSize,
|
|
1016
|
+
exportTime
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
_USDZExporter.DEFAULT_OPTIONS = {
|
|
1021
|
+
includeAudio: false,
|
|
1022
|
+
lookAtCamera: false,
|
|
1023
|
+
placementMode: "floor",
|
|
1024
|
+
materialQuality: "standard",
|
|
1025
|
+
includeAnimations: true,
|
|
1026
|
+
realityComposerMode: false,
|
|
1027
|
+
metersPerUnit: 1,
|
|
1028
|
+
upAxis: "Y",
|
|
1029
|
+
enableOcclusion: true,
|
|
1030
|
+
allowContentScaling: true,
|
|
1031
|
+
canonicalCameraDistance: 2.5
|
|
1032
|
+
};
|
|
1033
|
+
var USDZExporter = _USDZExporter;
|
|
1034
|
+
|
|
1035
|
+
exports.USDZExporter = USDZExporter;
|
|
1036
|
+
//# sourceMappingURL=USDZExporter-3FWJ25JI.cjs.map
|
|
1037
|
+
//# sourceMappingURL=USDZExporter-3FWJ25JI.cjs.map
|