@holoscript/core 6.0.3 → 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 (244) hide show
  1. package/README.md +40 -40
  2. package/dist/codebase/index.d.ts +25 -0
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +4 -0
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/entries/interop.d.ts +9 -0
  7. package/dist/entries/scripting.d.ts +7 -0
  8. package/dist/index.d.ts +520 -19
  9. package/dist/paper-0c-spike/index.d.ts +29 -0
  10. package/dist/reconstruction/index.d.ts +78 -0
  11. package/dist/self-improvement/index.d.ts +0 -48
  12. package/dist/storage/index.d.ts +24 -0
  13. package/dist/tools/index.d.ts +33 -0
  14. package/dist/traitDocs/traitDocs.d.ts +69 -0
  15. package/dist/traits/index.d.ts +61 -0
  16. package/package.json +102 -19
  17. package/dist/GLTFPipeline-3KLWWUQO.cjs +0 -34
  18. package/dist/GLTFPipeline-LYII2ZVQ.js +0 -13
  19. package/dist/HoloScriptPlusParser-BZR5DELQ.js +0 -692
  20. package/dist/HoloScriptPlusParser-SBMYDNXO.cjs +0 -697
  21. package/dist/USDZExporter-MHEHXZB4.cjs +0 -709
  22. package/dist/USDZExporter-YA55ZS35.js +0 -707
  23. package/dist/chunk-26TLYBFD.js +0 -309
  24. package/dist/chunk-27LWW5FU.cjs +0 -410
  25. package/dist/chunk-2UX5LRAP.cjs +0 -833
  26. package/dist/chunk-32TWR3HE.js +0 -70
  27. package/dist/chunk-3FXV5S25.cjs +0 -633
  28. package/dist/chunk-3FYZOR7S.cjs +0 -69
  29. package/dist/chunk-3KEU5QYY.cjs +0 -175
  30. package/dist/chunk-4FCZDTD5.js +0 -610
  31. package/dist/chunk-4KJ2R7VP.cjs +0 -507
  32. package/dist/chunk-4SMUJFHL.js +0 -1213
  33. package/dist/chunk-54FHG2MX.js +0 -655
  34. package/dist/chunk-56IF4NTA.js +0 -56
  35. package/dist/chunk-5GLCTO44.js +0 -161
  36. package/dist/chunk-5TOFIR6L.js +0 -407
  37. package/dist/chunk-65RFOWZI.js +0 -765
  38. package/dist/chunk-6OQBLABR.js +0 -5240
  39. package/dist/chunk-6WNCRE6F.js +0 -126
  40. package/dist/chunk-74YCHHTE.js +0 -1872
  41. package/dist/chunk-7H5UNJZD.cjs +0 -1973
  42. package/dist/chunk-7KPI4EKH.cjs +0 -701
  43. package/dist/chunk-7LCYLPW2.cjs +0 -663
  44. package/dist/chunk-7N3JIJMT.js +0 -1395
  45. package/dist/chunk-7X2IEJIE.cjs +0 -2526
  46. package/dist/chunk-A6GO3DPZ.cjs +0 -1002
  47. package/dist/chunk-AC4BSHFV.js +0 -765
  48. package/dist/chunk-AIUXRS74.cjs +0 -3681
  49. package/dist/chunk-ARNKA274.cjs +0 -130
  50. package/dist/chunk-AW7WAELW.js +0 -975
  51. package/dist/chunk-BKIGPPVM.js +0 -629
  52. package/dist/chunk-BO2OKHIY.js +0 -6055
  53. package/dist/chunk-BU5ZAFMC.js +0 -115
  54. package/dist/chunk-BY3B7ZYV.cjs +0 -457
  55. package/dist/chunk-C2QHVHZF.js +0 -4066
  56. package/dist/chunk-C7BNX4XJ.js +0 -1043
  57. package/dist/chunk-CLYEIWA5.cjs +0 -408
  58. package/dist/chunk-CMYAWUX3.js +0 -4455
  59. package/dist/chunk-CN4NOESF.cjs +0 -416
  60. package/dist/chunk-CNVM7J3M.js +0 -883
  61. package/dist/chunk-CO2VM2DK.js +0 -1965
  62. package/dist/chunk-CQDOF3G7.cjs +0 -1404
  63. package/dist/chunk-DH5G2JUA.cjs +0 -614
  64. package/dist/chunk-DIEDKX5B.cjs +0 -660
  65. package/dist/chunk-DN7UFU63.cjs +0 -172
  66. package/dist/chunk-DXVCEFZB.js +0 -2027
  67. package/dist/chunk-EGIZHYJP.cjs +0 -85
  68. package/dist/chunk-EJA7G2C4.cjs +0 -428
  69. package/dist/chunk-ELLQPFAF.js +0 -830
  70. package/dist/chunk-EMO7HAKJ.cjs +0 -1875
  71. package/dist/chunk-ENV7K6XA.js +0 -282
  72. package/dist/chunk-EPWRXL6S.js +0 -2522
  73. package/dist/chunk-EUFLX2PI.js +0 -56956
  74. package/dist/chunk-F5LVGHNT.js +0 -449
  75. package/dist/chunk-FEFHPUEM.cjs +0 -6122
  76. package/dist/chunk-FF3Q7ADR.js +0 -380
  77. package/dist/chunk-GC3YU46J.js +0 -762
  78. package/dist/chunk-H6WMMLQK.cjs +0 -4492
  79. package/dist/chunk-H7XMORZI.js +0 -2731
  80. package/dist/chunk-HAN4V3PF.cjs +0 -2037
  81. package/dist/chunk-HBZYCASG.js +0 -4208
  82. package/dist/chunk-HF4OFY25.cjs +0 -4097
  83. package/dist/chunk-HHS6FMOU.cjs +0 -3813
  84. package/dist/chunk-HJJLD366.js +0 -1169
  85. package/dist/chunk-HKCVM6OK.cjs +0 -2237
  86. package/dist/chunk-HUFNKFA6.js +0 -698
  87. package/dist/chunk-I3XGTIHM.cjs +0 -1505
  88. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  89. package/dist/chunk-IHOUYQIA.js +0 -406
  90. package/dist/chunk-ILRBGFVD.cjs +0 -72
  91. package/dist/chunk-KDB6BUMB.js +0 -3666
  92. package/dist/chunk-KUJRR4FJ.js +0 -657
  93. package/dist/chunk-KYM4XRFG.js +0 -421
  94. package/dist/chunk-L3Z2HIWJ.cjs +0 -793
  95. package/dist/chunk-LBPEZQAF.js +0 -2232
  96. package/dist/chunk-LER4WXW5.cjs +0 -286
  97. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  98. package/dist/chunk-M6FU6S22.js +0 -2911
  99. package/dist/chunk-MWEFR6YQ.js +0 -1857
  100. package/dist/chunk-N5FTS757.cjs +0 -415
  101. package/dist/chunk-NCUHGRTZ.js +0 -752
  102. package/dist/chunk-NKRKT6V2.js +0 -69
  103. package/dist/chunk-NLPSZT4C.js +0 -630
  104. package/dist/chunk-NRUB55IT.cjs +0 -771
  105. package/dist/chunk-NTMZSDXM.cjs +0 -633
  106. package/dist/chunk-ODGMVILH.js +0 -9662
  107. package/dist/chunk-PBA6NXCT.cjs +0 -1216
  108. package/dist/chunk-PHENW4MQ.js +0 -65
  109. package/dist/chunk-PJMOXFPR.cjs +0 -1861
  110. package/dist/chunk-PLMYCCA4.js +0 -504
  111. package/dist/chunk-PPULB4GG.cjs +0 -9728
  112. package/dist/chunk-PQLGZKMC.cjs +0 -755
  113. package/dist/chunk-Q56TT7IL.js +0 -483
  114. package/dist/chunk-QHVVVN47.cjs +0 -2033
  115. package/dist/chunk-QWKUKVRE.js +0 -2026
  116. package/dist/chunk-RE3OKSYF.cjs +0 -424
  117. package/dist/chunk-RT7LJRSF.cjs +0 -57378
  118. package/dist/chunk-SPDELRRV.cjs +0 -319
  119. package/dist/chunk-SUCBB66F.js +0 -229
  120. package/dist/chunk-TSWTWZ42.cjs +0 -4214
  121. package/dist/chunk-UITWA6DV.cjs +0 -2829
  122. package/dist/chunk-UQW6SLM5.js +0 -172
  123. package/dist/chunk-V2ILLPHK.cjs +0 -237
  124. package/dist/chunk-V42NTCFH.js +0 -3645
  125. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  126. package/dist/chunk-VJVCD5T5.cjs +0 -769
  127. package/dist/chunk-VK5AXKO3.js +0 -746
  128. package/dist/chunk-VSXOIUCF.cjs +0 -473
  129. package/dist/chunk-VZNKJZTT.cjs +0 -749
  130. package/dist/chunk-W76ETJTI.js +0 -678
  131. package/dist/chunk-WFJIDI2N.cjs +0 -424
  132. package/dist/chunk-WN3YF33G.cjs +0 -118
  133. package/dist/chunk-WUXIRGZP.cjs +0 -2915
  134. package/dist/chunk-WYH4GVZ5.js +0 -1488
  135. package/dist/chunk-X4YVN7H3.cjs +0 -888
  136. package/dist/chunk-X67XRI2T.js +0 -410
  137. package/dist/chunk-XDXZM3ZP.cjs +0 -1046
  138. package/dist/chunk-XH7SE4HH.cjs +0 -72
  139. package/dist/chunk-XNMEH2BI.js +0 -126
  140. package/dist/chunk-XSF76QRU.js +0 -468
  141. package/dist/chunk-XSUZMPVQ.cjs +0 -682
  142. package/dist/chunk-XUILI4KB.cjs +0 -430
  143. package/dist/chunk-Y5MUAYTO.js +0 -167
  144. package/dist/chunk-Y7VK5TH3.cjs +0 -129
  145. package/dist/chunk-YCMQQQ5U.cjs +0 -5244
  146. package/dist/chunk-YYXH45E2.js +0 -426
  147. package/dist/chunk-ZGTGVSTZ.js +0 -422
  148. package/dist/chunk-ZL6VJ6SN.js +0 -421
  149. package/dist/cli/holoscript-runner.cjs +0 -2258
  150. package/dist/cli/holoscript-runner.js +0 -2233
  151. package/dist/codebase/index.cjs +0 -336
  152. package/dist/codebase/index.js +0 -331
  153. package/dist/compiler/agent-inference.cjs +0 -29
  154. package/dist/compiler/agent-inference.js +0 -6
  155. package/dist/compiler/android-xr.cjs +0 -20
  156. package/dist/compiler/android-xr.js +0 -10
  157. package/dist/compiler/android.cjs +0 -21
  158. package/dist/compiler/android.js +0 -11
  159. package/dist/compiler/ar.cjs +0 -21
  160. package/dist/compiler/ar.js +0 -9
  161. package/dist/compiler/babylon.cjs +0 -18
  162. package/dist/compiler/babylon.js +0 -12
  163. package/dist/compiler/coco.cjs +0 -27
  164. package/dist/compiler/coco.js +0 -4
  165. package/dist/compiler/domain-block-utils.cjs +0 -595
  166. package/dist/compiler/domain-block-utils.js +0 -9
  167. package/dist/compiler/dtdl.cjs +0 -25
  168. package/dist/compiler/dtdl.js +0 -9
  169. package/dist/compiler/gltf-pipeline.cjs +0 -39
  170. package/dist/compiler/gltf-pipeline.js +0 -4
  171. package/dist/compiler/godot.cjs +0 -16
  172. package/dist/compiler/godot.js +0 -10
  173. package/dist/compiler/incremental.cjs +0 -30
  174. package/dist/compiler/incremental.js +0 -5
  175. package/dist/compiler/index.cjs +0 -1522
  176. package/dist/compiler/index.js +0 -1321
  177. package/dist/compiler/ios.cjs +0 -21
  178. package/dist/compiler/ios.js +0 -11
  179. package/dist/compiler/multi-layer.cjs +0 -27
  180. package/dist/compiler/multi-layer.js +0 -12
  181. package/dist/compiler/nodetoy.cjs +0 -23
  182. package/dist/compiler/nodetoy.js +0 -4
  183. package/dist/compiler/openxr.cjs +0 -16
  184. package/dist/compiler/openxr.js +0 -10
  185. package/dist/compiler/playcanvas.cjs +0 -17
  186. package/dist/compiler/playcanvas.js +0 -11
  187. package/dist/compiler/r3f.cjs +0 -35
  188. package/dist/compiler/r3f.js +0 -13
  189. package/dist/compiler/remotion.cjs +0 -23
  190. package/dist/compiler/remotion.js +0 -4
  191. package/dist/compiler/reproducibility.cjs +0 -39
  192. package/dist/compiler/reproducibility.js +0 -4
  193. package/dist/compiler/sdf.cjs +0 -22
  194. package/dist/compiler/sdf.js +0 -10
  195. package/dist/compiler/semantic-scene.cjs +0 -31
  196. package/dist/compiler/semantic-scene.js +0 -4
  197. package/dist/compiler/state.cjs +0 -18
  198. package/dist/compiler/state.js +0 -8
  199. package/dist/compiler/trait-composition.cjs +0 -27
  200. package/dist/compiler/trait-composition.js +0 -6
  201. package/dist/compiler/unity.cjs +0 -16
  202. package/dist/compiler/unity.js +0 -10
  203. package/dist/compiler/unreal.cjs +0 -20
  204. package/dist/compiler/unreal.js +0 -10
  205. package/dist/compiler/urdf.cjs +0 -46
  206. package/dist/compiler/urdf.js +0 -10
  207. package/dist/compiler/usd-physics.cjs +0 -24
  208. package/dist/compiler/usd-physics.js +0 -7
  209. package/dist/compiler/visionos.cjs +0 -16
  210. package/dist/compiler/visionos.js +0 -10
  211. package/dist/compiler/vrchat.cjs +0 -20
  212. package/dist/compiler/vrchat.js +0 -10
  213. package/dist/compiler/vrr.cjs +0 -22
  214. package/dist/compiler/vrr.js +0 -10
  215. package/dist/compiler/wasm.cjs +0 -34
  216. package/dist/compiler/wasm.js +0 -10
  217. package/dist/compiler/webgpu.cjs +0 -16
  218. package/dist/compiler/webgpu.js +0 -10
  219. package/dist/debugger.cjs +0 -21
  220. package/dist/debugger.js +0 -8
  221. package/dist/entries/interop.cjs +0 -62
  222. package/dist/entries/interop.js +0 -5
  223. package/dist/entries/scripting.cjs +0 -67
  224. package/dist/entries/scripting.js +0 -10
  225. package/dist/index.cjs +0 -61703
  226. package/dist/index.js +0 -58652
  227. package/dist/math/vec3.cjs +0 -57
  228. package/dist/math/vec3.js +0 -4
  229. package/dist/parser.cjs +0 -26
  230. package/dist/parser.js +0 -9
  231. package/dist/playwright-7DTEQCBD.cjs +0 -98673
  232. package/dist/playwright-BIZXMLD2.js +0 -98660
  233. package/dist/post-quantum-JTTAAGO3.cjs +0 -6
  234. package/dist/post-quantum-RVPVDEPI.js +0 -4
  235. package/dist/runtime.cjs +0 -16
  236. package/dist/runtime.js +0 -7
  237. package/dist/storage/index.cjs +0 -37
  238. package/dist/storage/index.js +0 -4
  239. package/dist/traits/index.cjs +0 -14331
  240. package/dist/traits/index.js +0 -12126
  241. package/dist/type-checker.cjs +0 -18
  242. package/dist/type-checker.js +0 -5
  243. package/dist/wot/index.cjs +0 -29
  244. package/dist/wot/index.js +0 -4
@@ -1,709 +0,0 @@
1
- 'use strict';
2
-
3
- require('./chunk-EGIZHYJP.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-MHEHXZB4.cjs.map
709
- //# sourceMappingURL=USDZExporter-MHEHXZB4.cjs.map