@holoscript/core 6.0.4 → 7.0.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.
Files changed (236) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +3 -2
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/index.d.ts +501 -19
  7. package/dist/paper-0c-spike/index.d.ts +29 -0
  8. package/dist/reconstruction/index.d.ts +78 -0
  9. package/dist/tools/index.d.ts +22 -1
  10. package/dist/traitDocs/traitDocs.d.ts +69 -0
  11. package/dist/traits/index.d.ts +61 -0
  12. package/package.json +105 -57
  13. package/dist/GLTFPipeline-DEN36VNK.js +0 -12
  14. package/dist/GLTFPipeline-YPCAK236.cjs +0 -33
  15. package/dist/HoloScriptPlusParser-BN6KVRCM.js +0 -692
  16. package/dist/HoloScriptPlusParser-NC5FE6AL.cjs +0 -697
  17. package/dist/USDZExporter-NTMBNTDB.js +0 -707
  18. package/dist/USDZExporter-UWGWNMMD.cjs +0 -709
  19. package/dist/chunk-27LWW5FU.cjs +0 -410
  20. package/dist/chunk-2CWOLHTE.js +0 -69
  21. package/dist/chunk-33LSUQDD.cjs +0 -835
  22. package/dist/chunk-3FJCK5XA.js +0 -2232
  23. package/dist/chunk-3FXV5S25.cjs +0 -633
  24. package/dist/chunk-3FYZOR7S.cjs +0 -69
  25. package/dist/chunk-3SAK5KFL.cjs +0 -83
  26. package/dist/chunk-4XSNJCLC.cjs +0 -1859
  27. package/dist/chunk-54FHG2MX.js +0 -655
  28. package/dist/chunk-56IF4NTA.js +0 -56
  29. package/dist/chunk-5BGSECRJ.cjs +0 -2237
  30. package/dist/chunk-5GLCTO44.js +0 -161
  31. package/dist/chunk-5O6TQC6M.cjs +0 -1871
  32. package/dist/chunk-5OEOHAAW.cjs +0 -682
  33. package/dist/chunk-5TOFIR6L.js +0 -407
  34. package/dist/chunk-5WUNN6ZN.cjs +0 -428
  35. package/dist/chunk-6TZPZCOJ.cjs +0 -1404
  36. package/dist/chunk-6UEHYZ7V.cjs +0 -773
  37. package/dist/chunk-6XSERL6L.js +0 -5678
  38. package/dist/chunk-72EQECGT.cjs +0 -908
  39. package/dist/chunk-7AGYRWKW.cjs +0 -507
  40. package/dist/chunk-7LCYLPW2.cjs +0 -663
  41. package/dist/chunk-A7PIMZGU.js +0 -263
  42. package/dist/chunk-ATSKSYVE.cjs +0 -51683
  43. package/dist/chunk-B5TCIAPQ.cjs +0 -117
  44. package/dist/chunk-BF2235SI.cjs +0 -5714
  45. package/dist/chunk-BKIGPPVM.js +0 -629
  46. package/dist/chunk-BND3ST2K.cjs +0 -662
  47. package/dist/chunk-BU7VWW2K.js +0 -2522
  48. package/dist/chunk-BWFJEM5A.js +0 -5419
  49. package/dist/chunk-CAUCGUEA.cjs +0 -130
  50. package/dist/chunk-CBJSLA2E.cjs +0 -5423
  51. package/dist/chunk-CDPGV4DN.js +0 -114
  52. package/dist/chunk-CLYEIWA5.cjs +0 -408
  53. package/dist/chunk-CS2EMTGF.js +0 -1966
  54. package/dist/chunk-DMG7C4H2.js +0 -975
  55. package/dist/chunk-DXJQDCFL.js +0 -468
  56. package/dist/chunk-E3FWRT3Z.js +0 -608
  57. package/dist/chunk-E3UALNFA.js +0 -421
  58. package/dist/chunk-EONILVMF.js +0 -762
  59. package/dist/chunk-EQV4R3EV.cjs +0 -769
  60. package/dist/chunk-F3HH56EB.cjs +0 -5538
  61. package/dist/chunk-F4IULT7N.js +0 -1488
  62. package/dist/chunk-FF3Q7ADR.js +0 -380
  63. package/dist/chunk-FFKU7BTK.cjs +0 -1046
  64. package/dist/chunk-FHQVYCH2.js +0 -70
  65. package/dist/chunk-FSF7EQVA.cjs +0 -1974
  66. package/dist/chunk-G4VZTCIB.js +0 -659
  67. package/dist/chunk-G7CT3EMP.cjs +0 -1002
  68. package/dist/chunk-GGHSW2NN.js +0 -51334
  69. package/dist/chunk-GVUR45UF.cjs +0 -777
  70. package/dist/chunk-H5Z7NASB.js +0 -9662
  71. package/dist/chunk-HE7ULERA.cjs +0 -697
  72. package/dist/chunk-HJJLD366.js +0 -1169
  73. package/dist/chunk-HPS76H7Q.js +0 -309
  74. package/dist/chunk-HQUEA5R6.cjs +0 -424
  75. package/dist/chunk-HYNTS5CP.js +0 -422
  76. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  77. package/dist/chunk-IBDG74G2.cjs +0 -1219
  78. package/dist/chunk-IFNQFCTM.js +0 -3098
  79. package/dist/chunk-IHOUYQIA.js +0 -406
  80. package/dist/chunk-ILRBGFVD.cjs +0 -72
  81. package/dist/chunk-IWI6J7FX.js +0 -421
  82. package/dist/chunk-K3JDKWGI.cjs +0 -270
  83. package/dist/chunk-K6EKD26I.js +0 -630
  84. package/dist/chunk-KCQ5NDYC.cjs +0 -3172
  85. package/dist/chunk-KED34ILP.js +0 -832
  86. package/dist/chunk-KSGXLT74.cjs +0 -457
  87. package/dist/chunk-L4G4RLXX.js +0 -767
  88. package/dist/chunk-LDP5OK6G.js +0 -1216
  89. package/dist/chunk-LGGRPKTV.cjs +0 -735
  90. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  91. package/dist/chunk-LSW7P7ML.js +0 -3675
  92. package/dist/chunk-LXJ4667L.cjs +0 -3874
  93. package/dist/chunk-LZ266PCM.cjs +0 -4499
  94. package/dist/chunk-MD6KDHVE.cjs +0 -237
  95. package/dist/chunk-MEASWI2Y.js +0 -126
  96. package/dist/chunk-MPXBVFHQ.js +0 -768
  97. package/dist/chunk-N5FTS757.cjs +0 -415
  98. package/dist/chunk-NCUKG4SK.cjs +0 -3075
  99. package/dist/chunk-NDQNIJEH.js +0 -1715
  100. package/dist/chunk-NOZZ46QU.js +0 -168
  101. package/dist/chunk-OFKWH2IP.js +0 -449
  102. package/dist/chunk-PHENW4MQ.js +0 -65
  103. package/dist/chunk-PMGODDJA.cjs +0 -319
  104. package/dist/chunk-Q4QX3AET.cjs +0 -1505
  105. package/dist/chunk-Q56TT7IL.js +0 -483
  106. package/dist/chunk-Q5JT3YML.cjs +0 -129
  107. package/dist/chunk-Q5SJOGHQ.cjs +0 -4256
  108. package/dist/chunk-QGKNANZ3.js +0 -3071
  109. package/dist/chunk-QLEAOI3Q.cjs +0 -424
  110. package/dist/chunk-R7MA7QWV.js +0 -732
  111. package/dist/chunk-RVYPEYPX.js +0 -678
  112. package/dist/chunk-S2N5TNMA.js +0 -1855
  113. package/dist/chunk-S565K7NK.js +0 -752
  114. package/dist/chunk-SDAMZIRE.js +0 -765
  115. package/dist/chunk-T36DDXSF.js +0 -4250
  116. package/dist/chunk-T4NKMBDL.js +0 -5474
  117. package/dist/chunk-T7LEXZUZ.cjs +0 -2526
  118. package/dist/chunk-TEWCN33Y.js +0 -694
  119. package/dist/chunk-TQSZUOW5.cjs +0 -793
  120. package/dist/chunk-TSH3MSQU.cjs +0 -129
  121. package/dist/chunk-UERJ3YJV.js +0 -504
  122. package/dist/chunk-UPJBDCVF.js +0 -1395
  123. package/dist/chunk-V3NN3HPP.js +0 -4462
  124. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  125. package/dist/chunk-WB4Z63GG.js +0 -229
  126. package/dist/chunk-WDW67DZB.cjs +0 -9728
  127. package/dist/chunk-WGMEAYBG.js +0 -126
  128. package/dist/chunk-X4ZF6CNE.cjs +0 -473
  129. package/dist/chunk-X6SEAXAX.cjs +0 -3681
  130. package/dist/chunk-XCWFGZAA.js +0 -1043
  131. package/dist/chunk-XD6IYDUX.js +0 -903
  132. package/dist/chunk-XG23EUQX.cjs +0 -1717
  133. package/dist/chunk-XRKWN5PL.cjs +0 -173
  134. package/dist/chunk-XUILI4KB.cjs +0 -430
  135. package/dist/chunk-XUTX5CBW.js +0 -126
  136. package/dist/chunk-XWPNTWDN.cjs +0 -755
  137. package/dist/chunk-XXINBTZK.cjs +0 -633
  138. package/dist/chunk-YCXFCXDS.js +0 -1868
  139. package/dist/chunk-YQK5JNFK.js +0 -3725
  140. package/dist/chunk-YYXH45E2.js +0 -426
  141. package/dist/chunk-Z34RLXRA.cjs +0 -612
  142. package/dist/chunk-ZP4D3CSX.cjs +0 -72
  143. package/dist/cli/holoscript-runner.cjs +0 -2259
  144. package/dist/cli/holoscript-runner.js +0 -2234
  145. package/dist/codebase/index.cjs +0 -336
  146. package/dist/codebase/index.js +0 -331
  147. package/dist/compiler/agent-inference.cjs +0 -28
  148. package/dist/compiler/agent-inference.js +0 -5
  149. package/dist/compiler/android-xr.cjs +0 -19
  150. package/dist/compiler/android-xr.js +0 -9
  151. package/dist/compiler/android.cjs +0 -20
  152. package/dist/compiler/android.js +0 -10
  153. package/dist/compiler/ar.cjs +0 -20
  154. package/dist/compiler/ar.js +0 -8
  155. package/dist/compiler/babylon.cjs +0 -17
  156. package/dist/compiler/babylon.js +0 -11
  157. package/dist/compiler/coco.cjs +0 -27
  158. package/dist/compiler/coco.js +0 -4
  159. package/dist/compiler/domain-block-utils.cjs +0 -602
  160. package/dist/compiler/domain-block-utils.js +0 -8
  161. package/dist/compiler/dtdl.cjs +0 -24
  162. package/dist/compiler/dtdl.js +0 -8
  163. package/dist/compiler/gltf-pipeline.cjs +0 -39
  164. package/dist/compiler/gltf-pipeline.js +0 -4
  165. package/dist/compiler/godot.cjs +0 -15
  166. package/dist/compiler/godot.js +0 -9
  167. package/dist/compiler/incremental.cjs +0 -29
  168. package/dist/compiler/incremental.js +0 -4
  169. package/dist/compiler/index.cjs +0 -2578
  170. package/dist/compiler/index.js +0 -2383
  171. package/dist/compiler/ios.cjs +0 -20
  172. package/dist/compiler/ios.js +0 -10
  173. package/dist/compiler/multi-layer.cjs +0 -20
  174. package/dist/compiler/multi-layer.js +0 -11
  175. package/dist/compiler/nodetoy.cjs +0 -23
  176. package/dist/compiler/nodetoy.js +0 -4
  177. package/dist/compiler/openxr.cjs +0 -15
  178. package/dist/compiler/openxr.js +0 -9
  179. package/dist/compiler/playcanvas.cjs +0 -16
  180. package/dist/compiler/playcanvas.js +0 -10
  181. package/dist/compiler/r3f.cjs +0 -34
  182. package/dist/compiler/r3f.js +0 -12
  183. package/dist/compiler/remotion.cjs +0 -23
  184. package/dist/compiler/remotion.js +0 -4
  185. package/dist/compiler/reproducibility.cjs +0 -39
  186. package/dist/compiler/reproducibility.js +0 -4
  187. package/dist/compiler/sdf.cjs +0 -21
  188. package/dist/compiler/sdf.js +0 -9
  189. package/dist/compiler/semantic-scene.cjs +0 -31
  190. package/dist/compiler/semantic-scene.js +0 -4
  191. package/dist/compiler/state.cjs +0 -17
  192. package/dist/compiler/state.js +0 -7
  193. package/dist/compiler/trait-composition.cjs +0 -26
  194. package/dist/compiler/trait-composition.js +0 -5
  195. package/dist/compiler/unity.cjs +0 -15
  196. package/dist/compiler/unity.js +0 -9
  197. package/dist/compiler/unreal.cjs +0 -19
  198. package/dist/compiler/unreal.js +0 -9
  199. package/dist/compiler/urdf.cjs +0 -45
  200. package/dist/compiler/urdf.js +0 -9
  201. package/dist/compiler/usd-physics.cjs +0 -23
  202. package/dist/compiler/usd-physics.js +0 -6
  203. package/dist/compiler/visionos.cjs +0 -15
  204. package/dist/compiler/visionos.js +0 -9
  205. package/dist/compiler/vrchat.cjs +0 -19
  206. package/dist/compiler/vrchat.js +0 -9
  207. package/dist/compiler/vrr.cjs +0 -21
  208. package/dist/compiler/vrr.js +0 -9
  209. package/dist/compiler/wasm.cjs +0 -33
  210. package/dist/compiler/wasm.js +0 -9
  211. package/dist/compiler/webgpu.cjs +0 -15
  212. package/dist/compiler/webgpu.js +0 -9
  213. package/dist/debugger.cjs +0 -21
  214. package/dist/debugger.js +0 -8
  215. package/dist/entries/interop.cjs +0 -62
  216. package/dist/entries/interop.js +0 -5
  217. package/dist/entries/scripting.cjs +0 -68
  218. package/dist/entries/scripting.js +0 -11
  219. package/dist/index.cjs +0 -40921
  220. package/dist/index.js +0 -37763
  221. package/dist/math/vec3.cjs +0 -57
  222. package/dist/math/vec3.js +0 -4
  223. package/dist/ml-dsa-PHCWUBPX.cjs +0 -1178
  224. package/dist/ml-dsa-WYLJHJO6.js +0 -1178
  225. package/dist/parser.cjs +0 -27
  226. package/dist/parser.js +0 -10
  227. package/dist/playwright-5OSAPTNH.js +0 -98660
  228. package/dist/playwright-RL6GY4F7.cjs +0 -98673
  229. package/dist/runtime.cjs +0 -16
  230. package/dist/runtime.js +0 -7
  231. package/dist/storage/index.cjs +0 -37
  232. package/dist/storage/index.js +0 -4
  233. package/dist/traits/index.cjs +0 -14649
  234. package/dist/traits/index.js +0 -12243
  235. package/dist/type-checker.cjs +0 -18
  236. package/dist/type-checker.js +0 -5
@@ -1,709 +0,0 @@
1
- 'use strict';
2
-
3
- require('./chunk-3SAK5KFL.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.textureFiles = [];
96
- this.options = { ..._USDZExporter.DEFAULT_OPTIONS, ...options };
97
- }
98
- /**
99
- * Export scene graph to USDZ format
100
- * Returns ArrayBuffer containing .usdz package
101
- */
102
- async export(sceneGraph) {
103
- const startTime = performance.now();
104
- this.reset();
105
- this.stage = this.createStage(sceneGraph);
106
- await this.convertSceneGraph(sceneGraph);
107
- if (this.options.lookAtCamera || this.options.placementMode) {
108
- this.addARMetadata();
109
- }
110
- const usdzBuffer = await this.packageUSDZ();
111
- const endTime = performance.now();
112
- const stats = this.calculateStats(usdzBuffer.byteLength, endTime - startTime);
113
- return {
114
- usdz: usdzBuffer,
115
- stage: this.stage,
116
- stats
117
- };
118
- }
119
- /**
120
- * Convert from GLTF intermediate representation
121
- */
122
- async convertFromGLTF(_gltfResult) {
123
- throw new Error("Direct GLTF conversion not yet implemented. Use export() with scene graph.");
124
- }
125
- // ========================================================================
126
- // Private Methods - Stage Creation
127
- // ========================================================================
128
- createStage(sceneGraph) {
129
- return {
130
- metadata: {
131
- version: "0.10.0",
132
- upAxis: this.options.upAxis,
133
- metersPerUnit: this.options.metersPerUnit,
134
- comment: `Generated by ${sceneGraph.generator || "HoloScript USDZExporter"}`
135
- },
136
- defaultPrim: "Root",
137
- prims: [],
138
- customLayerData: {
139
- creator: sceneGraph.generator,
140
- holoscriptVersion: sceneGraph.version
141
- }
142
- };
143
- }
144
- async convertSceneGraph(sceneGraph) {
145
- const rootPrim = createUSDXform("Root", "/Root");
146
- this.stage.prims.push(rootPrim);
147
- await this.convertMaterials(sceneGraph.materials || []);
148
- await this.convertMeshes(sceneGraph.meshes || [], sceneGraph);
149
- this.convertNode(sceneGraph.root, rootPrim, sceneGraph);
150
- if (this.options.includeAnimations && sceneGraph.animations?.length) {
151
- this.convertAnimations(sceneGraph.animations);
152
- }
153
- }
154
- // ========================================================================
155
- // Private Methods - Node Conversion
156
- // ========================================================================
157
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Deep nested scene graph node access
158
- convertNode(node, parentPrim, sceneGraph, depth = 0) {
159
- if (!node || depth > 100) return;
160
- const nodeName = sanitizeUSDName(node.name || `Node_${this.primCounter++}`);
161
- const nodePath = `${parentPrim.path}/${nodeName}`;
162
- const xformPrim = createUSDXform(nodeName, nodePath);
163
- if (node.transform) {
164
- this.addTransform(xformPrim, node.transform);
165
- }
166
- if (!parentPrim.children) parentPrim.children = [];
167
- parentPrim.children.push(xformPrim);
168
- const meshComp = node.components?.find((c) => c.type === "mesh");
169
- if (meshComp?.meshRef) {
170
- const meshPath = this.meshMap.get(meshComp.meshRef);
171
- if (meshPath) {
172
- xformPrim.relationships = [
173
- {
174
- name: "mesh",
175
- targets: [meshPath]
176
- }
177
- ];
178
- }
179
- }
180
- if (node.children?.length) {
181
- for (const child of node.children) {
182
- this.convertNode(child, xformPrim, sceneGraph, depth + 1);
183
- }
184
- }
185
- }
186
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Deep nested transform object access (position.x/y/z, rotation.x/y/z/w, scale.x/y/z)
187
- addTransform(prim, transform) {
188
- const ops = [];
189
- if (transform.position) {
190
- ops.push({
191
- type: "translate",
192
- value: [transform.position.x, transform.position.y, transform.position.z]
193
- });
194
- }
195
- if (transform.rotation) {
196
- const euler = quaternionToEuler([
197
- transform.rotation.x,
198
- transform.rotation.y,
199
- transform.rotation.z,
200
- transform.rotation.w
201
- ]);
202
- ops.push({
203
- type: "rotateXYZ",
204
- value: euler
205
- });
206
- }
207
- if (transform.scale) {
208
- ops.push({
209
- type: "scale",
210
- value: [transform.scale.x, transform.scale.y, transform.scale.z]
211
- });
212
- }
213
- if (ops.length > 0) {
214
- prim.attributes.push({
215
- name: "xformOpOrder",
216
- type: "token[]",
217
- value: ops.map((op) => `xformOp:${op.type}`)
218
- });
219
- for (const op of ops) {
220
- prim.attributes.push({
221
- name: `xformOp:${op.type}`,
222
- type: this.getXformOpType(op.type),
223
- value: op.value
224
- });
225
- }
226
- }
227
- }
228
- getXformOpType(opType) {
229
- switch (opType) {
230
- case "translate":
231
- return "float3";
232
- case "rotateXYZ":
233
- return "float3";
234
- case "rotateX":
235
- case "rotateY":
236
- case "rotateZ":
237
- return "float";
238
- case "scale":
239
- return "float3";
240
- case "transform":
241
- return "matrix4d";
242
- default:
243
- return "float3";
244
- }
245
- }
246
- // ========================================================================
247
- // Private Methods - Material Conversion
248
- // ========================================================================
249
- async convertMaterials(materials) {
250
- for (const material of materials) {
251
- await this.convertMaterial(material);
252
- }
253
- }
254
- async convertMaterial(material) {
255
- const matName = sanitizeUSDName(material.name || `Material_${this.primCounter++}`);
256
- const matPath = `/Root/Materials/${matName}`;
257
- const mapping = this.createMaterialMapping(material);
258
- const inputs = {
259
- diffuseColor: mapping.baseColor.slice(0, 3),
260
- // RGB only
261
- metallic: mapping.metallic,
262
- roughness: mapping.roughness,
263
- emissiveColor: mapping.emissive
264
- };
265
- if (material.alphaMode === "blend" || material.alphaMode === "mask") {
266
- inputs.opacity = mapping.baseColor[3];
267
- if (material.alphaMode === "mask") {
268
- inputs.opacityThreshold = mapping.alphaCutoff || 0.5;
269
- }
270
- }
271
- const usdMaterial = createUSDPreviewSurfaceMaterial(matName, matPath, inputs);
272
- if (mapping.baseColorTexture) {
273
- await this.addTextureToMaterial(usdMaterial, "diffuseColor", mapping.baseColorTexture);
274
- }
275
- if (mapping.normalTexture) {
276
- await this.addTextureToMaterial(usdMaterial, "normal", mapping.normalTexture);
277
- }
278
- if (mapping.occlusionTexture) {
279
- await this.addTextureToMaterial(usdMaterial, "occlusion", mapping.occlusionTexture);
280
- }
281
- if (!this.stage.prims[0].children) this.stage.prims[0].children = [];
282
- let materialsScope = this.stage.prims[0].children.find((p) => p.name === "Materials");
283
- if (!materialsScope) {
284
- materialsScope = {
285
- path: "/Root/Materials",
286
- type: "Scope",
287
- name: "Materials",
288
- attributes: [],
289
- children: []
290
- };
291
- this.stage.prims[0].children.push(materialsScope);
292
- }
293
- materialsScope.children.push(usdMaterial);
294
- this.materialMap.set(material.id, matPath);
295
- }
296
- createMaterialMapping(material) {
297
- return {
298
- baseColor: material.baseColor || [1, 1, 1, 1],
299
- metallic: material.metallic ?? 0,
300
- roughness: material.roughness ?? 0.5,
301
- emissive: material.emissiveColor || [0, 0, 0],
302
- alphaMode: material.alphaMode,
303
- alphaCutoff: material.alphaCutoff
304
- };
305
- }
306
- async addTextureToMaterial(material, inputName, textureRef) {
307
- const shader = material.children?.[0];
308
- if (shader?.inputs) {
309
- shader.inputs.push({
310
- name: inputName,
311
- type: "asset",
312
- value: { path: textureRef }
313
- });
314
- }
315
- }
316
- // ========================================================================
317
- // Private Methods - Mesh Conversion
318
- // ========================================================================
319
- async convertMeshes(meshes, sceneGraph) {
320
- for (const mesh of meshes) {
321
- await this.convertMesh(mesh, sceneGraph);
322
- }
323
- }
324
- async convertMesh(mesh, sceneGraph) {
325
- const meshName = sanitizeUSDName(mesh.name || `Mesh_${this.primCounter++}`);
326
- const meshPath = `/Root/Geometry/${meshName}`;
327
- let geometryScope = this.stage.prims[0].children?.find((p) => p.name === "Geometry");
328
- if (!geometryScope) {
329
- geometryScope = {
330
- path: "/Root/Geometry",
331
- type: "Scope",
332
- name: "Geometry",
333
- attributes: [],
334
- children: []
335
- };
336
- if (!this.stage.prims[0].children) this.stage.prims[0].children = [];
337
- this.stage.prims[0].children.push(geometryScope);
338
- }
339
- for (let i = 0; i < mesh.primitives.length; i++) {
340
- const primitive = mesh.primitives[i];
341
- const primName = mesh.primitives.length > 1 ? `${meshName}_${i}` : meshName;
342
- const primPath = mesh.primitives.length > 1 ? `${meshPath}_${i}` : meshPath;
343
- const usdMesh = await this.convertMeshPrimitive(primitive, primName, primPath, sceneGraph);
344
- geometryScope.children.push(usdMesh);
345
- this.meshMap.set(mesh.id, primPath);
346
- }
347
- }
348
- async convertMeshPrimitive(primitive, name, path, sceneGraph) {
349
- const positions = this.extractAccessorData(primitive.attributes.POSITION, sceneGraph);
350
- const normals = primitive.attributes.NORMAL ? this.extractAccessorData(primitive.attributes.NORMAL, sceneGraph) : void 0;
351
- const uvs = primitive.attributes.TEXCOORD_0 ? this.extractAccessorData(primitive.attributes.TEXCOORD_0, sceneGraph) : void 0;
352
- const indices = primitive.indices !== void 0 ? this.extractAccessorData(primitive.indices, sceneGraph) : void 0;
353
- const { faceVertexCounts, faceVertexIndices } = this.buildFaceData(
354
- indices,
355
- positions.length / 3
356
- );
357
- const usdMesh = {
358
- path,
359
- type: "Mesh",
360
- name,
361
- attributes: [],
362
- faceVertexCounts,
363
- faceVertexIndices,
364
- points: positions
365
- };
366
- if (normals) {
367
- usdMesh.normals = normals;
368
- usdMesh.attributes.push({
369
- name: "primvars:normals",
370
- type: "normal3f[]",
371
- value: normals
372
- });
373
- usdMesh.attributes.push({
374
- name: "primvars:normals:interpolation",
375
- type: "token",
376
- value: "vertex"
377
- });
378
- }
379
- if (uvs) {
380
- usdMesh.primvars = [
381
- {
382
- name: "st",
383
- type: "texCoord2f[]",
384
- interpolation: "vertex",
385
- values: uvs
386
- }
387
- ];
388
- }
389
- if (primitive.materialRef) {
390
- const matPath = this.materialMap.get(primitive.materialRef);
391
- if (matPath) {
392
- usdMesh.relationships = [
393
- {
394
- name: "material:binding",
395
- targets: [matPath]
396
- }
397
- ];
398
- }
399
- }
400
- return usdMesh;
401
- }
402
- extractAccessorData(accessorIndex, sceneGraph) {
403
- const accessor = sceneGraph.accessors[accessorIndex];
404
- if (!accessor) return [];
405
- const bufferView = sceneGraph.bufferViews[accessor.bufferViewIndex];
406
- const buffer = sceneGraph.buffers[bufferView.bufferIndex];
407
- if (!buffer.data) return [];
408
- const arrayView = this.getTypedArray(
409
- buffer.data,
410
- bufferView.byteOffset + accessor.byteOffset,
411
- accessor.count * this.getComponentCount(accessor.type),
412
- accessor.componentType
413
- );
414
- return Array.from(arrayView);
415
- }
416
- getTypedArray(buffer, offset, length, componentType) {
417
- switch (componentType) {
418
- case "float":
419
- return new Float32Array(buffer, offset, length);
420
- case "ushort":
421
- return new Uint16Array(buffer, offset, length);
422
- case "uint":
423
- return new Uint32Array(buffer, offset, length);
424
- default:
425
- return new Float32Array(buffer, offset, length);
426
- }
427
- }
428
- getComponentCount(type) {
429
- switch (type.toLowerCase()) {
430
- case "scalar":
431
- return 1;
432
- case "vec2":
433
- return 2;
434
- case "vec3":
435
- return 3;
436
- case "vec4":
437
- return 4;
438
- case "mat2":
439
- return 4;
440
- case "mat3":
441
- return 9;
442
- case "mat4":
443
- return 16;
444
- default:
445
- return 1;
446
- }
447
- }
448
- buildFaceData(indices, vertexCount) {
449
- if (indices && indices.length > 0) {
450
- const faceCount = Math.floor(indices.length / 3);
451
- return {
452
- faceVertexCounts: new Array(faceCount).fill(3),
453
- faceVertexIndices: indices
454
- };
455
- } else if (vertexCount > 0) {
456
- const faceCount = Math.floor(vertexCount / 3);
457
- return {
458
- faceVertexCounts: new Array(faceCount).fill(3),
459
- faceVertexIndices: Array.from({ length: vertexCount }, (_, i) => i)
460
- };
461
- } else {
462
- return {
463
- faceVertexCounts: [],
464
- faceVertexIndices: []
465
- };
466
- }
467
- }
468
- // ========================================================================
469
- // Private Methods - Animation Conversion
470
- // ========================================================================
471
- convertAnimations(_animations) {
472
- console.warn("Animation export not yet implemented");
473
- }
474
- // ========================================================================
475
- // Private Methods - AR Metadata
476
- // ========================================================================
477
- addARMetadata() {
478
- const metadata = {
479
- arBehaviors: {
480
- allowsContentScaling: this.options.allowContentScaling,
481
- hasLookAtCamera: this.options.lookAtCamera,
482
- initialPlacementMode: this.options.placementMode,
483
- enableOcclusion: this.options.enableOcclusion
484
- },
485
- canonicalCameraDistance: this.options.canonicalCameraDistance
486
- };
487
- if (!this.stage.customLayerData) this.stage.customLayerData = {};
488
- this.stage.customLayerData.arQuickLook = metadata;
489
- if (this.stage.prims[0]) {
490
- if (!this.stage.prims[0].metadata) this.stage.prims[0].metadata = {};
491
- this.stage.prims[0].metadata.arQuickLook = metadata;
492
- }
493
- }
494
- // ========================================================================
495
- // Private Methods - USDZ Packaging
496
- // ========================================================================
497
- async packageUSDZ() {
498
- const usdContent = this.serializeUSD(this.stage);
499
- const mainFile = {
500
- path: "scene.usda",
501
- data: new TextEncoder().encode(usdContent).buffer,
502
- mimeType: "text/plain"
503
- };
504
- const package_ = {
505
- mainFile,
506
- files: this.textureFiles
507
- };
508
- return this.createZipArchive(package_);
509
- }
510
- serializeUSD(stage) {
511
- const lines = [];
512
- lines.push("#usda 1.0");
513
- lines.push("(");
514
- if (stage.defaultPrim) {
515
- lines.push(` defaultPrim = "${stage.defaultPrim}"`);
516
- }
517
- if (stage.metadata.upAxis) {
518
- lines.push(` upAxis = "${stage.metadata.upAxis}"`);
519
- }
520
- if (stage.metadata.metersPerUnit) {
521
- lines.push(` metersPerUnit = ${stage.metadata.metersPerUnit}`);
522
- }
523
- lines.push(")");
524
- lines.push("");
525
- for (const prim of stage.prims) {
526
- this.serializePrim(prim, lines, 0);
527
- }
528
- return lines.join("\n");
529
- }
530
- serializePrim(prim, lines, indent) {
531
- const ind = " ".repeat(indent);
532
- lines.push(`${ind}def ${prim.type} "${prim.name}"`);
533
- lines.push(`${ind}{`);
534
- for (const attr of prim.attributes) {
535
- this.serializeAttribute(attr, lines, indent + 1);
536
- }
537
- if (prim.relationships) {
538
- for (const rel of prim.relationships) {
539
- const relInd = " ".repeat(indent + 1);
540
- const targets = rel.targets.map((t) => `<${t}>`).join(", ");
541
- lines.push(`${relInd}rel ${rel.name} = [${targets}]`);
542
- }
543
- }
544
- if (prim.children) {
545
- for (const child of prim.children) {
546
- lines.push("");
547
- this.serializePrim(child, lines, indent + 1);
548
- }
549
- }
550
- lines.push(`${ind}}`);
551
- }
552
- serializeAttribute(attr, lines, indent) {
553
- const ind = " ".repeat(indent);
554
- const value = this.serializeValue(attr.value, attr.type);
555
- lines.push(`${ind}${attr.type} ${attr.name} = ${value}`);
556
- }
557
- serializeValue(value, type) {
558
- if (Array.isArray(value)) {
559
- if (type.includes("[]")) {
560
- return `[${value.map((v) => this.serializeScalar(v, type.replace("[]", ""))).join(", ")}]`;
561
- } else {
562
- return `(${value.join(", ")})`;
563
- }
564
- } else if (typeof value === "string") {
565
- return `"${value}"`;
566
- } else if (typeof value === "object" && value !== null && "path" in value) {
567
- return `@${value.path}@`;
568
- } else {
569
- return String(value);
570
- }
571
- }
572
- serializeScalar(value, _type) {
573
- if (typeof value === "string") {
574
- return `"${value}"`;
575
- }
576
- return String(value);
577
- }
578
- async createZipArchive(package_) {
579
- const files = [package_.mainFile, ...package_.files];
580
- let totalSize = 0;
581
- const fileEntries = [];
582
- const localHeaderSize = 30;
583
- const centralHeaderSize = 46;
584
- const endCentralSize = 22;
585
- for (const file of files) {
586
- const nameBytes = new TextEncoder().encode(file.path);
587
- fileEntries.push({
588
- name: file.path,
589
- data: file.data,
590
- offset: totalSize
591
- });
592
- totalSize += localHeaderSize + nameBytes.length + file.data.byteLength;
593
- }
594
- const centralDirOffset = totalSize;
595
- let centralDirSize = 0;
596
- for (const entry of fileEntries) {
597
- const nameBytes = new TextEncoder().encode(entry.name);
598
- centralDirSize += centralHeaderSize + nameBytes.length;
599
- }
600
- totalSize += centralDirSize + endCentralSize;
601
- const buffer = new ArrayBuffer(totalSize);
602
- const view = new DataView(buffer);
603
- const bytes = new Uint8Array(buffer);
604
- let offset = 0;
605
- for (const entry of fileEntries) {
606
- const nameBytes = new TextEncoder().encode(entry.name);
607
- view.setUint32(offset, 67324752, true);
608
- view.setUint16(offset + 4, 20, true);
609
- view.setUint16(offset + 6, 0, true);
610
- view.setUint16(offset + 8, 0, true);
611
- view.setUint16(offset + 10, 0, true);
612
- view.setUint16(offset + 12, 0, true);
613
- view.setUint32(offset + 14, 0, true);
614
- view.setUint32(offset + 18, entry.data.byteLength, true);
615
- view.setUint32(offset + 22, entry.data.byteLength, true);
616
- view.setUint16(offset + 26, nameBytes.length, true);
617
- view.setUint16(offset + 28, 0, true);
618
- offset += 30;
619
- bytes.set(nameBytes, offset);
620
- offset += nameBytes.length;
621
- bytes.set(new Uint8Array(entry.data), offset);
622
- offset += entry.data.byteLength;
623
- }
624
- for (const entry of fileEntries) {
625
- const nameBytes = new TextEncoder().encode(entry.name);
626
- view.setUint32(offset, 33639248, true);
627
- view.setUint16(offset + 4, 20, true);
628
- view.setUint16(offset + 6, 20, true);
629
- view.setUint16(offset + 8, 0, true);
630
- view.setUint16(offset + 10, 0, true);
631
- view.setUint16(offset + 12, 0, true);
632
- view.setUint16(offset + 14, 0, true);
633
- view.setUint32(offset + 16, 0, true);
634
- view.setUint32(offset + 20, entry.data.byteLength, true);
635
- view.setUint32(offset + 24, entry.data.byteLength, true);
636
- view.setUint16(offset + 28, nameBytes.length, true);
637
- view.setUint16(offset + 30, 0, true);
638
- view.setUint16(offset + 32, 0, true);
639
- view.setUint16(offset + 34, 0, true);
640
- view.setUint16(offset + 36, 0, true);
641
- view.setUint32(offset + 38, 0, true);
642
- view.setUint32(offset + 42, entry.offset, true);
643
- offset += 46;
644
- bytes.set(nameBytes, offset);
645
- offset += nameBytes.length;
646
- }
647
- view.setUint32(offset, 101010256, true);
648
- view.setUint16(offset + 4, 0, true);
649
- view.setUint16(offset + 6, 0, true);
650
- view.setUint16(offset + 8, fileEntries.length, true);
651
- view.setUint16(offset + 10, fileEntries.length, true);
652
- view.setUint32(offset + 12, centralDirSize, true);
653
- view.setUint32(offset + 16, centralDirOffset, true);
654
- view.setUint16(offset + 20, 0, true);
655
- return buffer;
656
- }
657
- // ========================================================================
658
- // Private Methods - Utilities
659
- // ========================================================================
660
- reset() {
661
- this.primCounter = 0;
662
- this.materialMap.clear();
663
- this.meshMap.clear();
664
- this.textureFiles = [];
665
- }
666
- calculateStats(usdzSize, exportTime) {
667
- let primCount = 0;
668
- let meshCount = 0;
669
- let materialCount = 0;
670
- const countPrims = (prim) => {
671
- primCount++;
672
- if (prim.type === "Mesh") meshCount++;
673
- if (prim.type === "Material") materialCount++;
674
- if (prim.children) {
675
- for (const child of prim.children) countPrims(child);
676
- }
677
- };
678
- for (const prim of this.stage.prims) {
679
- countPrims(prim);
680
- }
681
- return {
682
- primCount,
683
- meshCount,
684
- materialCount,
685
- textureCount: this.textureFiles.length,
686
- fileCount: 1 + this.textureFiles.length,
687
- usdzSize,
688
- exportTime
689
- };
690
- }
691
- };
692
- _USDZExporter.DEFAULT_OPTIONS = {
693
- includeAudio: false,
694
- lookAtCamera: false,
695
- placementMode: "floor",
696
- materialQuality: "standard",
697
- includeAnimations: true,
698
- realityComposerMode: false,
699
- metersPerUnit: 1,
700
- upAxis: "Y",
701
- enableOcclusion: true,
702
- allowContentScaling: true,
703
- canonicalCameraDistance: 2.5
704
- };
705
- var USDZExporter = _USDZExporter;
706
-
707
- exports.USDZExporter = USDZExporter;
708
- //# sourceMappingURL=USDZExporter-UWGWNMMD.cjs.map
709
- //# sourceMappingURL=USDZExporter-UWGWNMMD.cjs.map