@onerjs/serializers 8.23.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.
Files changed (135) hide show
  1. package/OBJ/index.d.ts +1 -0
  2. package/OBJ/index.js +2 -0
  3. package/OBJ/index.js.map +1 -0
  4. package/OBJ/objSerializer.d.ts +21 -0
  5. package/OBJ/objSerializer.js +171 -0
  6. package/OBJ/objSerializer.js.map +1 -0
  7. package/USDZ/index.d.ts +1 -0
  8. package/USDZ/index.js +3 -0
  9. package/USDZ/index.js.map +1 -0
  10. package/USDZ/usdzExporter.d.ts +50 -0
  11. package/USDZ/usdzExporter.js +589 -0
  12. package/USDZ/usdzExporter.js.map +1 -0
  13. package/exportUtils.d.ts +12 -0
  14. package/exportUtils.js +37 -0
  15. package/exportUtils.js.map +1 -0
  16. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.d.ts +24 -0
  17. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js +61 -0
  18. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js.map +1 -0
  19. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -0
  20. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +109 -0
  21. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -0
  22. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +32 -0
  23. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +135 -0
  24. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -0
  25. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +39 -0
  26. package/glTF/2.0/Extensions/KHR_lights_punctual.js +145 -0
  27. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -0
  28. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +24 -0
  29. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +62 -0
  30. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -0
  31. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +24 -0
  32. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +85 -0
  33. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -0
  34. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +40 -0
  35. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +118 -0
  36. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -0
  37. package/glTF/2.0/Extensions/KHR_materials_dispersion.d.ts +31 -0
  38. package/glTF/2.0/Extensions/KHR_materials_dispersion.js +63 -0
  39. package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -0
  40. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +27 -0
  41. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +54 -0
  42. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -0
  43. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +29 -0
  44. package/glTF/2.0/Extensions/KHR_materials_ior.js +55 -0
  45. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -0
  46. package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +24 -0
  47. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +69 -0
  48. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -0
  49. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +24 -0
  50. package/glTF/2.0/Extensions/KHR_materials_sheen.js +66 -0
  51. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -0
  52. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +41 -0
  53. package/glTF/2.0/Extensions/KHR_materials_specular.js +94 -0
  54. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -0
  55. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +41 -0
  56. package/glTF/2.0/Extensions/KHR_materials_transmission.js +92 -0
  57. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -0
  58. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +20 -0
  59. package/glTF/2.0/Extensions/KHR_materials_unlit.js +46 -0
  60. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -0
  61. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +40 -0
  62. package/glTF/2.0/Extensions/KHR_materials_volume.js +96 -0
  63. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
  64. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +21 -0
  65. package/glTF/2.0/Extensions/KHR_texture_transform.js +93 -0
  66. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -0
  67. package/glTF/2.0/Extensions/index.d.ts +17 -0
  68. package/glTF/2.0/Extensions/index.js +18 -0
  69. package/glTF/2.0/Extensions/index.js.map +1 -0
  70. package/glTF/2.0/bufferManager.d.ts +68 -0
  71. package/glTF/2.0/bufferManager.js +154 -0
  72. package/glTF/2.0/bufferManager.js.map +1 -0
  73. package/glTF/2.0/dataWriter.d.ts +20 -0
  74. package/glTF/2.0/dataWriter.js +83 -0
  75. package/glTF/2.0/dataWriter.js.map +1 -0
  76. package/glTF/2.0/glTFAnimation.d.ts +191 -0
  77. package/glTF/2.0/glTFAnimation.js +786 -0
  78. package/glTF/2.0/glTFAnimation.js.map +1 -0
  79. package/glTF/2.0/glTFData.d.ts +21 -0
  80. package/glTF/2.0/glTFData.js +30 -0
  81. package/glTF/2.0/glTFData.js.map +1 -0
  82. package/glTF/2.0/glTFExporter.d.ts +109 -0
  83. package/glTF/2.0/glTFExporter.js +1166 -0
  84. package/glTF/2.0/glTFExporter.js.map +1 -0
  85. package/glTF/2.0/glTFExporterExtension.d.ts +77 -0
  86. package/glTF/2.0/glTFExporterExtension.js +4 -0
  87. package/glTF/2.0/glTFExporterExtension.js.map +1 -0
  88. package/glTF/2.0/glTFMaterialExporter.d.ts +99 -0
  89. package/glTF/2.0/glTFMaterialExporter.js +778 -0
  90. package/glTF/2.0/glTFMaterialExporter.js.map +1 -0
  91. package/glTF/2.0/glTFMorphTargetsUtilities.d.ts +14 -0
  92. package/glTF/2.0/glTFMorphTargetsUtilities.js +149 -0
  93. package/glTF/2.0/glTFMorphTargetsUtilities.js.map +1 -0
  94. package/glTF/2.0/glTFSerializer.d.ts +78 -0
  95. package/glTF/2.0/glTFSerializer.js +39 -0
  96. package/glTF/2.0/glTFSerializer.js.map +1 -0
  97. package/glTF/2.0/glTFUtilities.d.ts +89 -0
  98. package/glTF/2.0/glTFUtilities.js +349 -0
  99. package/glTF/2.0/glTFUtilities.js.map +1 -0
  100. package/glTF/2.0/index.d.ts +4 -0
  101. package/glTF/2.0/index.js +6 -0
  102. package/glTF/2.0/index.js.map +1 -0
  103. package/glTF/glTFFileExporter.d.ts +20 -0
  104. package/glTF/glTFFileExporter.js +4 -0
  105. package/glTF/glTFFileExporter.js.map +1 -0
  106. package/glTF/index.d.ts +2 -0
  107. package/glTF/index.js +4 -0
  108. package/glTF/index.js.map +1 -0
  109. package/index.d.ts +4 -0
  110. package/index.js +6 -0
  111. package/index.js.map +1 -0
  112. package/legacy/legacy-glTF2Serializer.d.ts +2 -0
  113. package/legacy/legacy-glTF2Serializer.js +45 -0
  114. package/legacy/legacy-glTF2Serializer.js.map +1 -0
  115. package/legacy/legacy-objSerializer.d.ts +1 -0
  116. package/legacy/legacy-objSerializer.js +14 -0
  117. package/legacy/legacy-objSerializer.js.map +1 -0
  118. package/legacy/legacy-stlSerializer.d.ts +1 -0
  119. package/legacy/legacy-stlSerializer.js +14 -0
  120. package/legacy/legacy-stlSerializer.js.map +1 -0
  121. package/legacy/legacy-usdzSerializer.d.ts +1 -0
  122. package/legacy/legacy-usdzSerializer.js +14 -0
  123. package/legacy/legacy-usdzSerializer.js.map +1 -0
  124. package/legacy/legacy.d.ts +5 -0
  125. package/legacy/legacy.js +8 -0
  126. package/legacy/legacy.js.map +1 -0
  127. package/license.md +71 -0
  128. package/package.json +49 -0
  129. package/readme.md +29 -0
  130. package/stl/index.d.ts +1 -0
  131. package/stl/index.js +2 -0
  132. package/stl/index.js.map +1 -0
  133. package/stl/stlSerializer.d.ts +20 -0
  134. package/stl/stlSerializer.js +135 -0
  135. package/stl/stlSerializer.js.map +1 -0
package/OBJ/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./objSerializer.js";
package/OBJ/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./objSerializer.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/serializers/src/OBJ/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./objSerializer\";\r\n"]}
@@ -0,0 +1,21 @@
1
+ import type { Mesh } from "@babylonjs/core/Meshes/mesh.js";
2
+ /**
3
+ * Class for generating OBJ data from a Babylon scene.
4
+ */
5
+ export declare class OBJExport {
6
+ /**
7
+ * Exports the geometry of a Mesh array in .OBJ file format (text)
8
+ * @param meshes defines the list of meshes to serialize
9
+ * @param materials defines if materials should be exported
10
+ * @param matlibname defines the name of the associated mtl file
11
+ * @param globalposition defines if the exported positions are globals or local to the exported mesh
12
+ * @returns the OBJ content
13
+ */
14
+ static OBJ(meshes: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean): string;
15
+ /**
16
+ * Exports the material(s) of a mesh in .MTL file format (text)
17
+ * @param mesh defines the mesh to extract the material from
18
+ * @returns the mtl content
19
+ */
20
+ static MTL(mesh: Mesh): string;
21
+ }
@@ -0,0 +1,171 @@
1
+ import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
2
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
3
+ import { Material } from "@babylonjs/core/Materials/material.js";
4
+ /**
5
+ * Class for generating OBJ data from a Babylon scene.
6
+ */
7
+ export class OBJExport {
8
+ /**
9
+ * Exports the geometry of a Mesh array in .OBJ file format (text)
10
+ * @param meshes defines the list of meshes to serialize
11
+ * @param materials defines if materials should be exported
12
+ * @param matlibname defines the name of the associated mtl file
13
+ * @param globalposition defines if the exported positions are globals or local to the exported mesh
14
+ * @returns the OBJ content
15
+ */
16
+ static OBJ(meshes, materials, matlibname, globalposition) {
17
+ const output = [];
18
+ let v = 1;
19
+ // keep track of uv index in case mixed meshes are passed in
20
+ let textureV = 1;
21
+ if (materials) {
22
+ if (!matlibname) {
23
+ matlibname = "mat";
24
+ }
25
+ output.push("mtllib " + matlibname + ".mtl");
26
+ }
27
+ for (let j = 0; j < meshes.length; j++) {
28
+ const mesh = meshes[j];
29
+ const objectName = mesh.name || `mesh${j}}`;
30
+ output.push(`o ${objectName}`);
31
+ //Uses the position of the item in the scene, to the file (this back to normal in the end)
32
+ let inverseTransform = null;
33
+ if (globalposition) {
34
+ const transform = mesh.computeWorldMatrix(true);
35
+ inverseTransform = new Matrix();
36
+ transform.invertToRef(inverseTransform);
37
+ mesh.bakeTransformIntoVertices(transform);
38
+ }
39
+ //TODO: submeshes (groups)
40
+ //TODO: smoothing groups (s 1, s off);
41
+ if (materials) {
42
+ const mat = mesh.material;
43
+ if (mat) {
44
+ output.push("usemtl " + mat.id);
45
+ }
46
+ }
47
+ const g = mesh.geometry;
48
+ if (!g) {
49
+ Tools.Warn("No geometry is present on the mesh");
50
+ continue;
51
+ }
52
+ const trunkVerts = g.getVerticesData("position");
53
+ const trunkNormals = g.getVerticesData("normal");
54
+ const trunkUV = g.getVerticesData("uv");
55
+ const trunkFaces = g.getIndices();
56
+ let currentV = 0;
57
+ let currentTextureV = 0;
58
+ if (!trunkVerts || !trunkFaces) {
59
+ Tools.Warn("There are no position vertices or indices on the mesh!");
60
+ continue;
61
+ }
62
+ const useRightHandedSystem = meshes[0].getScene().useRightHandedSystem;
63
+ const handednessSign = useRightHandedSystem ? 1 : -1;
64
+ for (let i = 0; i < trunkVerts.length; i += 3) {
65
+ output.push("v " + trunkVerts[i] * handednessSign + " " + trunkVerts[i + 1] + " " + trunkVerts[i + 2]);
66
+ currentV++;
67
+ }
68
+ if (trunkNormals != null) {
69
+ for (let i = 0; i < trunkNormals.length; i += 3) {
70
+ output.push("vn " + trunkNormals[i] * handednessSign + " " + trunkNormals[i + 1] + " " + trunkNormals[i + 2]);
71
+ }
72
+ }
73
+ if (trunkUV != null) {
74
+ for (let i = 0; i < trunkUV.length; i += 2) {
75
+ output.push("vt " + trunkUV[i] + " " + trunkUV[i + 1]);
76
+ currentTextureV++;
77
+ }
78
+ }
79
+ const blanks = ["", "", ""];
80
+ const material = mesh.material || mesh.getScene().defaultMaterial;
81
+ const sideOrientation = material._getEffectiveOrientation(mesh);
82
+ const [offset1, offset2] = sideOrientation === Material.ClockWiseSideOrientation ? [2, 1] : [1, 2];
83
+ for (let i = 0; i < trunkFaces.length; i += 3) {
84
+ const indices = [String(trunkFaces[i] + v), String(trunkFaces[i + offset1] + v), String(trunkFaces[i + offset2] + v)];
85
+ const textureIndices = [String(trunkFaces[i] + textureV), String(trunkFaces[i + offset1] + textureV), String(trunkFaces[i + offset2] + textureV)];
86
+ const facePositions = indices;
87
+ const faceUVs = trunkUV != null ? textureIndices : blanks;
88
+ const faceNormals = trunkNormals != null ? indices : blanks;
89
+ output.push("f " +
90
+ facePositions[0] +
91
+ "/" +
92
+ faceUVs[0] +
93
+ "/" +
94
+ faceNormals[0] +
95
+ " " +
96
+ facePositions[1] +
97
+ "/" +
98
+ faceUVs[1] +
99
+ "/" +
100
+ faceNormals[1] +
101
+ " " +
102
+ facePositions[2] +
103
+ "/" +
104
+ faceUVs[2] +
105
+ "/" +
106
+ faceNormals[2]);
107
+ }
108
+ //back de previous matrix, to not change the original mesh in the scene
109
+ if (globalposition && inverseTransform) {
110
+ mesh.bakeTransformIntoVertices(inverseTransform);
111
+ }
112
+ v += currentV;
113
+ textureV += currentTextureV;
114
+ }
115
+ const text = output.join("\n");
116
+ return text;
117
+ }
118
+ /**
119
+ * Exports the material(s) of a mesh in .MTL file format (text)
120
+ * @param mesh defines the mesh to extract the material from
121
+ * @returns the mtl content
122
+ */
123
+ //TODO: Export the materials of mesh array
124
+ static MTL(mesh) {
125
+ const output = [];
126
+ const m = mesh.material;
127
+ output.push("newmtl mat1");
128
+ output.push(" Ns " + m.specularPower.toFixed(4));
129
+ output.push(" Ni 1.5000");
130
+ output.push(" d " + m.alpha.toFixed(4));
131
+ output.push(" Tr 0.0000");
132
+ output.push(" Tf 1.0000 1.0000 1.0000");
133
+ output.push(" illum 2");
134
+ output.push(" Ka " + m.ambientColor.r.toFixed(4) + " " + m.ambientColor.g.toFixed(4) + " " + m.ambientColor.b.toFixed(4));
135
+ output.push(" Kd " + m.diffuseColor.r.toFixed(4) + " " + m.diffuseColor.g.toFixed(4) + " " + m.diffuseColor.b.toFixed(4));
136
+ output.push(" Ks " + m.specularColor.r.toFixed(4) + " " + m.specularColor.g.toFixed(4) + " " + m.specularColor.b.toFixed(4));
137
+ output.push(" Ke " + m.emissiveColor.r.toFixed(4) + " " + m.emissiveColor.g.toFixed(4) + " " + m.emissiveColor.b.toFixed(4));
138
+ //TODO: uv scale, offset, wrap
139
+ //TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures?
140
+ const uvscale = "";
141
+ if (m.ambientTexture) {
142
+ output.push(" map_Ka " + uvscale + m.ambientTexture.name);
143
+ }
144
+ if (m.diffuseTexture) {
145
+ output.push(" map_Kd " + uvscale + m.diffuseTexture.name);
146
+ //TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d)
147
+ }
148
+ if (m.specularTexture) {
149
+ output.push(" map_Ks " + uvscale + m.specularTexture.name);
150
+ /* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???)
151
+ if (m.useGlossinessFromSpecularMapAlpha) {
152
+ output.push(" map_Ns "+uvscale + m.specularTexture.name);
153
+ }
154
+ */
155
+ }
156
+ /* TODO: emissive texture not in .MAT format (???)
157
+ if (m.emissiveTexture) {
158
+ output.push(" map_d "+uvscale+m.emissiveTexture.name);
159
+ }
160
+ */
161
+ if (m.bumpTexture) {
162
+ output.push(" map_bump -imfchan z " + uvscale + m.bumpTexture.name);
163
+ }
164
+ if (m.opacityTexture) {
165
+ output.push(" map_d " + uvscale + m.opacityTexture.name);
166
+ }
167
+ const text = output.join("\n");
168
+ return text;
169
+ }
170
+ }
171
+ //# sourceMappingURL=objSerializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objSerializer.js","sourceRoot":"","sources":["../../../../dev/serializers/src/OBJ/objSerializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAChD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAIxC,OAAO,EAAE,QAAQ,EAAE,8CAAgC;AAEnD;;GAEG;AACH,MAAM,OAAO,SAAS;IAClB;;;;;;;OAOG;IACI,MAAM,CAAC,GAAG,CAAC,MAAc,EAAE,SAAmB,EAAE,UAAmB,EAAE,cAAwB;QAChG,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,4DAA4D;QAC5D,IAAI,QAAQ,GAAG,CAAC,CAAC;QAEjB,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,UAAU,EAAE,CAAC;gBACd,UAAU,GAAG,KAAK,CAAC;YACvB,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;QACjD,CAAC;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACvB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;YAC5C,MAAM,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC,CAAC;YAE/B,0FAA0F;YAC1F,IAAI,gBAAgB,G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,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,OAAO,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;YACnB,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,OAAO,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC3D,kGAAkG;QACtG,CAAC;QAED,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,OAAO,GAAG,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC5D;;;;cAIE;QACN,CAAC;QAED;;;;UAIE;QAEF,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,wBAAwB,GAAG,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACzE,CAAC;QAED,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;YACnB,MAAM,CAAC,IAAI,CAAC,UAAU,GAAG,OAAO,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC9D,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport type { Geometry } from \"core/Meshes/geometry\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { Material } from \"core/Materials/material\";\r\n\r\n/**\r\n * Class for generating OBJ data from a Babylon scene.\r\n */\r\nexport class OBJExport {\r\n /**\r\n * Exports the geometry of a Mesh array in .OBJ file format (text)\r\n * @param meshes defines the list of meshes to serialize\r\n * @param materials defines if materials should be exported\r\n * @param matlibname defines the name of the associated mtl file\r\n * @param globalposition defines if the exported positions are globals or local to the exported mesh\r\n * @returns the OBJ content\r\n */\r\n public static OBJ(meshes: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean): string {\r\n const output: string[] = [];\r\n let v = 1;\r\n // keep track of uv index in case mixed meshes are passed in\r\n let textureV = 1;\r\n\r\n if (materials) {\r\n if (!matlibname) {\r\n matlibname = \"mat\";\r\n }\r\n output.push(\"mtllib \" + matlibname + \".mtl\");\r\n }\r\n for (let j = 0; j < meshes.length; j++) {\r\n const mesh = meshes[j];\r\n const objectName = mesh.name || `mesh${j}}`;\r\n output.push(`o ${objectName}`);\r\n\r\n //Uses the position of the item in the scene, to the file (this back to normal in the end)\r\n let inverseTransform: Nullable<Matrix> = null;\r\n if (globalposition) {\r\n const transform = mesh.computeWorldMatrix(true);\r\n inverseTransform = new Matrix();\r\n transform.invertToRef(inverseTransform);\r\n\r\n mesh.bakeTransformIntoVertices(transform);\r\n }\r\n\r\n //TODO: submeshes (groups)\r\n //TODO: smoothing groups (s 1, s off);\r\n if (materials) {\r\n const mat = mesh.material;\r\n\r\n if (mat) {\r\n output.push(\"usemtl \" + mat.id);\r\n }\r\n }\r\n const g: Nullable<Geometry> = mesh.geometry;\r\n\r\n if (!g) {\r\n Tools.Warn(\"No geometry is present on the mesh\");\r\n continue;\r\n }\r\n\r\n const trunkVerts = g.getVerticesData(\"position\");\r\n const trunkNormals = g.getVerticesData(\"normal\");\r\n const trunkUV = g.getVerticesData(\"uv\");\r\n const trunkFaces = g.getIndices();\r\n let currentV = 0;\r\n let currentTextureV = 0;\r\n\r\n if (!trunkVerts || !trunkFaces) {\r\n Tools.Warn(\"There are no position vertices or indices on the mesh!\");\r\n continue;\r\n }\r\n\r\n const useRightHandedSystem = meshes[0].getScene().useRightHandedSystem;\r\n const handednessSign = useRightHandedSystem ? 1 : -1;\r\n\r\n for (let i = 0; i < trunkVerts.length; i += 3) {\r\n output.push(\"v \" + trunkVerts[i] * handednessSign + \" \" + trunkVerts[i + 1] + \" \" + trunkVerts[i + 2]);\r\n currentV++;\r\n }\r\n\r\n if (trunkNormals != null) {\r\n for (let i = 0; i < trunkNormals.length; i += 3) {\r\n output.push(\"vn \" + trunkNormals[i] * handednessSign + \" \" + trunkNormals[i + 1] + \" \" + trunkNormals[i + 2]);\r\n }\r\n }\r\n if (trunkUV != null) {\r\n for (let i = 0; i < trunkUV.length; i += 2) {\r\n output.push(\"vt \" + trunkUV[i] + \" \" + trunkUV[i + 1]);\r\n currentTextureV++;\r\n }\r\n }\r\n\r\n const blanks: string[] = [\"\", \"\", \"\"];\r\n const material = mesh.material || mesh.getScene().defaultMaterial;\r\n\r\n const sideOrientation = material._getEffectiveOrientation(mesh);\r\n const [offset1, offset2] = sideOrientation === Material.ClockWiseSideOrientation ? [2, 1] : [1, 2];\r\n\r\n for (let i = 0; i < trunkFaces.length; i += 3) {\r\n const indices = [String(trunkFaces[i] + v), String(trunkFaces[i + offset1] + v), String(trunkFaces[i + offset2] + v)];\r\n const textureIndices = [String(trunkFaces[i] + textureV), String(trunkFaces[i + offset1] + textureV), String(trunkFaces[i + offset2] + textureV)];\r\n\r\n const facePositions = indices;\r\n const faceUVs = trunkUV != null ? textureIndices : blanks;\r\n const faceNormals = trunkNormals != null ? indices : blanks;\r\n\r\n output.push(\r\n \"f \" +\r\n facePositions[0] +\r\n \"/\" +\r\n faceUVs[0] +\r\n \"/\" +\r\n faceNormals[0] +\r\n \" \" +\r\n facePositions[1] +\r\n \"/\" +\r\n faceUVs[1] +\r\n \"/\" +\r\n faceNormals[1] +\r\n \" \" +\r\n facePositions[2] +\r\n \"/\" +\r\n faceUVs[2] +\r\n \"/\" +\r\n faceNormals[2]\r\n );\r\n }\r\n //back de previous matrix, to not change the original mesh in the scene\r\n if (globalposition && inverseTransform) {\r\n mesh.bakeTransformIntoVertices(inverseTransform);\r\n }\r\n v += currentV;\r\n textureV += currentTextureV;\r\n }\r\n const text: string = output.join(\"\\n\");\r\n return text;\r\n }\r\n\r\n /**\r\n * Exports the material(s) of a mesh in .MTL file format (text)\r\n * @param mesh defines the mesh to extract the material from\r\n * @returns the mtl content\r\n */\r\n //TODO: Export the materials of mesh array\r\n public static MTL(mesh: Mesh): string {\r\n const output = [];\r\n const m = <StandardMaterial>mesh.material;\r\n output.push(\"newmtl mat1\");\r\n output.push(\" Ns \" + m.specularPower.toFixed(4));\r\n output.push(\" Ni 1.5000\");\r\n output.push(\" d \" + m.alpha.toFixed(4));\r\n output.push(\" Tr 0.0000\");\r\n output.push(\" Tf 1.0000 1.0000 1.0000\");\r\n output.push(\" illum 2\");\r\n output.push(\" Ka \" + m.ambientColor.r.toFixed(4) + \" \" + m.ambientColor.g.toFixed(4) + \" \" + m.ambientColor.b.toFixed(4));\r\n output.push(\" Kd \" + m.diffuseColor.r.toFixed(4) + \" \" + m.diffuseColor.g.toFixed(4) + \" \" + m.diffuseColor.b.toFixed(4));\r\n output.push(\" Ks \" + m.specularColor.r.toFixed(4) + \" \" + m.specularColor.g.toFixed(4) + \" \" + m.specularColor.b.toFixed(4));\r\n output.push(\" Ke \" + m.emissiveColor.r.toFixed(4) + \" \" + m.emissiveColor.g.toFixed(4) + \" \" + m.emissiveColor.b.toFixed(4));\r\n\r\n //TODO: uv scale, offset, wrap\r\n //TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures?\r\n const uvscale = \"\";\r\n\r\n if (m.ambientTexture) {\r\n output.push(\" map_Ka \" + uvscale + m.ambientTexture.name);\r\n }\r\n\r\n if (m.diffuseTexture) {\r\n output.push(\" map_Kd \" + uvscale + m.diffuseTexture.name);\r\n //TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d)\r\n }\r\n\r\n if (m.specularTexture) {\r\n output.push(\" map_Ks \" + uvscale + m.specularTexture.name);\r\n /* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???)\r\n if (m.useGlossinessFromSpecularMapAlpha) {\r\n output.push(\" map_Ns \"+uvscale + m.specularTexture.name);\r\n }\r\n */\r\n }\r\n\r\n /* TODO: emissive texture not in .MAT format (???)\r\n if (m.emissiveTexture) {\r\n output.push(\" map_d \"+uvscale+m.emissiveTexture.name);\r\n }\r\n */\r\n\r\n if (m.bumpTexture) {\r\n output.push(\" map_bump -imfchan z \" + uvscale + m.bumpTexture.name);\r\n }\r\n\r\n if (m.opacityTexture) {\r\n output.push(\" map_d \" + uvscale + m.opacityTexture.name);\r\n }\r\n\r\n const text = output.join(\"\\n\");\r\n return text;\r\n }\r\n}\r\n"]}
@@ -0,0 +1 @@
1
+ export * from "./usdzExporter.js";
package/USDZ/index.js ADDED
@@ -0,0 +1,3 @@
1
+ /* eslint-disable @typescript-eslint/no-restricted-imports */
2
+ export * from "./usdzExporter.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/serializers/src/USDZ/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,gBAAgB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./usdzExporter\";\r\n"]}
@@ -0,0 +1,50 @@
1
+ import type { Mesh } from "@babylonjs/core/Meshes/mesh.js";
2
+ import type { Scene } from "@babylonjs/core/scene.js";
3
+ /**
4
+ * Options for the USDZ export
5
+ */
6
+ export interface IUSDZExportOptions {
7
+ /**
8
+ * URL to load the fflate library from
9
+ */
10
+ fflateUrl?: string;
11
+ /**
12
+ * Include anchoring properties in the USDZ file
13
+ */
14
+ includeAnchoringProperties?: boolean;
15
+ /**
16
+ * Anchoring type (plane by default)
17
+ */
18
+ anchoringType?: string;
19
+ /**
20
+ * Plane anchoring alignment (horizontal by default)
21
+ */
22
+ planeAnchoringAlignment?: string;
23
+ /**
24
+ * Model file name (model.usda by default)
25
+ */
26
+ modelFileName?: string;
27
+ /**
28
+ * Precision to use for number (5 by default)
29
+ */
30
+ precision?: number;
31
+ /**
32
+ * Export the camera (false by default)
33
+ */
34
+ exportCamera?: boolean;
35
+ /**
36
+ * Camera sensor width (35 by default)
37
+ */
38
+ cameraSensorWidth?: number;
39
+ }
40
+ /**
41
+ *
42
+ * @param scene scene to export
43
+ * @param options options to configure the export
44
+ * @param meshPredicate predicate to filter the meshes to export
45
+ * @returns a uint8 array containing the USDZ file
46
+ * @see [Simple sphere](https://playground.babylonjs.com/#H2G5XW#6)
47
+ * @see [Red sphere](https://playground.babylonjs.com/#H2G5XW#7)
48
+ * @see [Boombox](https://playground.babylonjs.com/#5N3RWK#5)
49
+ */
50
+ export declare function USDZExportAsync(scene: Scene, options: Partial<IUSDZExportOptions>, meshPredicate?: (m: Mesh) => boolean): Promise<Uint8Array>;