@babylonjs/serializers 5.0.0-rc.6 → 5.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.
- package/OBJ/index.d.ts +1 -1
- package/OBJ/index.js +1 -1
- package/OBJ/objSerializer.d.ts +21 -21
- package/OBJ/objSerializer.js +174 -174
- package/OBJ/objSerializer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +41 -41
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +189 -189
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +24 -24
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +90 -90
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +24 -24
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +73 -73
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +20 -20
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +51 -51
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +30 -30
- package/glTF/2.0/Extensions/KHR_texture_transform.js +137 -137
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/index.d.ts +5 -5
- package/glTF/2.0/Extensions/index.js +5 -5
- package/glTF/2.0/glTFAnimation.d.ts +206 -205
- package/glTF/2.0/glTFAnimation.js +852 -852
- package/glTF/2.0/glTFAnimation.js.map +1 -1
- package/glTF/2.0/glTFData.d.ts +19 -19
- package/glTF/2.0/glTFData.js +52 -52
- package/glTF/2.0/glTFExporter.d.ts +456 -455
- package/glTF/2.0/glTFExporter.js +1975 -1972
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFExporterExtension.d.ts +74 -74
- package/glTF/2.0/glTFExporterExtension.js +3 -3
- package/glTF/2.0/glTFExporterExtension.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.d.ts +208 -207
- package/glTF/2.0/glTFMaterialExporter.js +1114 -1110
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/glTF/2.0/glTFSerializer.d.ts +60 -60
- package/glTF/2.0/glTFSerializer.js +62 -62
- package/glTF/2.0/glTFSerializer.js.map +1 -1
- package/glTF/2.0/glTFUtilities.d.ts +99 -97
- package/glTF/2.0/glTFUtilities.js +196 -196
- package/glTF/2.0/glTFUtilities.js.map +1 -1
- package/glTF/2.0/index.d.ts +8 -8
- package/glTF/2.0/index.js +9 -8
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/2.0/shaders/textureTransform.fragment.d.ts +5 -5
- package/glTF/2.0/shaders/textureTransform.fragment.js +8 -8
- package/glTF/glTFFileExporter.d.ts +20 -20
- package/glTF/glTFFileExporter.js +3 -3
- package/glTF/index.d.ts +2 -2
- package/glTF/index.js +3 -2
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +4 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF2Serializer.d.ts +2 -2
- package/legacy/legacy-glTF2Serializer.js +44 -43
- package/legacy/legacy-glTF2Serializer.js.map +1 -1
- package/legacy/legacy-objSerializer.d.ts +1 -1
- package/legacy/legacy-objSerializer.js +13 -12
- package/legacy/legacy-objSerializer.js.map +1 -1
- package/legacy/legacy-stlSerializer.d.ts +1 -1
- package/legacy/legacy-stlSerializer.js +13 -12
- package/legacy/legacy-stlSerializer.js.map +1 -1
- package/legacy/legacy.d.ts +4 -4
- package/legacy/legacy.js +6 -5
- package/legacy/legacy.js.map +1 -1
- package/license.md +71 -0
- package/package.json +25 -6
- package/stl/index.d.ts +1 -1
- package/stl/index.js +1 -1
- package/stl/stlSerializer.d.ts +17 -17
- package/stl/stlSerializer.js +107 -107
- package/stl/stlSerializer.js.map +1 -1
package/OBJ/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./objSerializer";
|
|
1
|
+
export * from "./objSerializer";
|
package/OBJ/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./objSerializer.js";
|
|
1
|
+
export * from "./objSerializer.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/OBJ/objSerializer.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { 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 mesh 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(mesh: 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
|
-
}
|
|
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 mesh 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(mesh: 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
|
+
}
|
package/OBJ/objSerializer.js
CHANGED
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
|
2
|
-
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
3
|
-
/**
|
|
4
|
-
* Class for generating OBJ data from a Babylon scene.
|
|
5
|
-
*/
|
|
6
|
-
var OBJExport = /** @class */ (function () {
|
|
7
|
-
function OBJExport() {
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Exports the geometry of a Mesh array in .OBJ file format (text)
|
|
11
|
-
* @param mesh defines the list of meshes to serialize
|
|
12
|
-
* @param materials defines if materials should be exported
|
|
13
|
-
* @param matlibname defines the name of the associated mtl file
|
|
14
|
-
* @param globalposition defines if the exported positions are globals or local to the exported mesh
|
|
15
|
-
* @returns the OBJ content
|
|
16
|
-
*/
|
|
17
|
-
OBJExport.OBJ = function (mesh, materials, matlibname, globalposition) {
|
|
18
|
-
var output = [];
|
|
19
|
-
var v = 1;
|
|
20
|
-
// keep track of uv index in case mixed meshes are passed in
|
|
21
|
-
var textureV = 1;
|
|
22
|
-
if (materials) {
|
|
23
|
-
if (!matlibname) {
|
|
24
|
-
matlibname = "mat";
|
|
25
|
-
}
|
|
26
|
-
output.push("mtllib " + matlibname + ".mtl");
|
|
27
|
-
}
|
|
28
|
-
for (var j = 0; j < mesh.length; j++) {
|
|
29
|
-
output.push("g object" + j);
|
|
30
|
-
output.push("o object_" + j);
|
|
31
|
-
//Uses the position of the item in the scene, to the file (this back to normal in the end)
|
|
32
|
-
var inverseTransform = null;
|
|
33
|
-
if (globalposition) {
|
|
34
|
-
var transform = mesh[j].computeWorldMatrix(true);
|
|
35
|
-
inverseTransform = new Matrix();
|
|
36
|
-
transform.invertToRef(inverseTransform);
|
|
37
|
-
mesh[j].bakeTransformIntoVertices(transform);
|
|
38
|
-
}
|
|
39
|
-
//TODO: submeshes (groups)
|
|
40
|
-
//TODO: smoothing groups (s 1, s off);
|
|
41
|
-
if (materials) {
|
|
42
|
-
var mat = mesh[j].material;
|
|
43
|
-
if (mat) {
|
|
44
|
-
output.push("usemtl " + mat.id);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
var g = mesh[j].geometry;
|
|
48
|
-
if (!g) {
|
|
49
|
-
Tools.Warn("No geometry is present on the mesh");
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
var trunkVerts = g.getVerticesData("position");
|
|
53
|
-
var trunkNormals = g.getVerticesData("normal");
|
|
54
|
-
var trunkUV = g.getVerticesData("uv");
|
|
55
|
-
var trunkFaces = g.getIndices();
|
|
56
|
-
var currentV = 0;
|
|
57
|
-
var currentTextureV = 0;
|
|
58
|
-
if (!trunkVerts || !trunkFaces) {
|
|
59
|
-
Tools.Warn("There are no position vertices or indices on the mesh!");
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
for (var i = 0; i < trunkVerts.length; i += 3) {
|
|
63
|
-
// Babylon.js default is left handed, while OBJ default is right handed
|
|
64
|
-
// Need to invert Z vertices unless Babylon is set to use a right handed system
|
|
65
|
-
if (mesh[0].getScene().useRightHandedSystem) {
|
|
66
|
-
output.push("v " + trunkVerts[i] + " " + trunkVerts[i + 1] + " " + trunkVerts[i + 2]);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
output.push("v " + trunkVerts[i] + " " + trunkVerts[i + 1] + " " + -trunkVerts[i + 2]);
|
|
70
|
-
}
|
|
71
|
-
currentV++;
|
|
72
|
-
}
|
|
73
|
-
if (trunkNormals != null) {
|
|
74
|
-
for (var i = 0; i < trunkNormals.length; i += 3) {
|
|
75
|
-
output.push("vn " + trunkNormals[i] + " " + trunkNormals[i + 1] + " " + trunkNormals[i + 2]);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (trunkUV != null) {
|
|
79
|
-
for (var i = 0; i < trunkUV.length; i += 2) {
|
|
80
|
-
output.push("vt " + trunkUV[i] + " " + trunkUV[i + 1]);
|
|
81
|
-
currentTextureV++;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
for (var i = 0; i < trunkFaces.length; i += 3) {
|
|
85
|
-
var indices = [String(trunkFaces[i + 2] + v), String(trunkFaces[i + 1] + v), String(trunkFaces[i] + v)];
|
|
86
|
-
var textureIndices = [String(trunkFaces[i + 2] + textureV), String(trunkFaces[i + 1] + textureV), String(trunkFaces[i] + textureV)];
|
|
87
|
-
var blanks = ["", "", ""];
|
|
88
|
-
var facePositions = indices;
|
|
89
|
-
var faceUVs = trunkUV != null ? textureIndices : blanks;
|
|
90
|
-
var faceNormals = trunkNormals != null ? indices : blanks;
|
|
91
|
-
output.push("f " +
|
|
92
|
-
facePositions[0] +
|
|
93
|
-
"/" +
|
|
94
|
-
faceUVs[0] +
|
|
95
|
-
"/" +
|
|
96
|
-
faceNormals[0] +
|
|
97
|
-
" " +
|
|
98
|
-
facePositions[1] +
|
|
99
|
-
"/" +
|
|
100
|
-
faceUVs[1] +
|
|
101
|
-
"/" +
|
|
102
|
-
faceNormals[1] +
|
|
103
|
-
" " +
|
|
104
|
-
facePositions[2] +
|
|
105
|
-
"/" +
|
|
106
|
-
faceUVs[2] +
|
|
107
|
-
"/" +
|
|
108
|
-
faceNormals[2]);
|
|
109
|
-
}
|
|
110
|
-
//back de previous matrix, to not change the original mesh in the scene
|
|
111
|
-
if (globalposition && inverseTransform) {
|
|
112
|
-
mesh[j].bakeTransformIntoVertices(inverseTransform);
|
|
113
|
-
}
|
|
114
|
-
v += currentV;
|
|
115
|
-
textureV += currentTextureV;
|
|
116
|
-
}
|
|
117
|
-
var text = output.join("\n");
|
|
118
|
-
return text;
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Exports the material(s) of a mesh in .MTL file format (text)
|
|
122
|
-
* @param mesh defines the mesh to extract the material from
|
|
123
|
-
* @returns the mtl content
|
|
124
|
-
*/
|
|
125
|
-
//TODO: Export the materials of mesh array
|
|
126
|
-
OBJExport.MTL = function (mesh) {
|
|
127
|
-
var output = [];
|
|
128
|
-
var m = mesh.material;
|
|
129
|
-
output.push("newmtl mat1");
|
|
130
|
-
output.push(" Ns " + m.specularPower.toFixed(4));
|
|
131
|
-
output.push(" Ni 1.5000");
|
|
132
|
-
output.push(" d " + m.alpha.toFixed(4));
|
|
133
|
-
output.push(" Tr 0.0000");
|
|
134
|
-
output.push(" Tf 1.0000 1.0000 1.0000");
|
|
135
|
-
output.push(" illum 2");
|
|
136
|
-
output.push(" Ka " + m.ambientColor.r.toFixed(4) + " " + m.ambientColor.g.toFixed(4) + " " + m.ambientColor.b.toFixed(4));
|
|
137
|
-
output.push(" Kd " + m.diffuseColor.r.toFixed(4) + " " + m.diffuseColor.g.toFixed(4) + " " + m.diffuseColor.b.toFixed(4));
|
|
138
|
-
output.push(" Ks " + m.specularColor.r.toFixed(4) + " " + m.specularColor.g.toFixed(4) + " " + m.specularColor.b.toFixed(4));
|
|
139
|
-
output.push(" Ke " + m.emissiveColor.r.toFixed(4) + " " + m.emissiveColor.g.toFixed(4) + " " + m.emissiveColor.b.toFixed(4));
|
|
140
|
-
//TODO: uv scale, offset, wrap
|
|
141
|
-
//TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures?
|
|
142
|
-
var uvscale = "";
|
|
143
|
-
if (m.ambientTexture) {
|
|
144
|
-
output.push(" map_Ka " + uvscale + m.ambientTexture.name);
|
|
145
|
-
}
|
|
146
|
-
if (m.diffuseTexture) {
|
|
147
|
-
output.push(" map_Kd " + uvscale + m.diffuseTexture.name);
|
|
148
|
-
//TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d)
|
|
149
|
-
}
|
|
150
|
-
if (m.specularTexture) {
|
|
151
|
-
output.push(" map_Ks " + uvscale + m.specularTexture.name);
|
|
152
|
-
/* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???)
|
|
153
|
-
if (m.useGlossinessFromSpecularMapAlpha) {
|
|
154
|
-
output.push(" map_Ns "+uvscale + m.specularTexture.name);
|
|
155
|
-
}
|
|
156
|
-
*/
|
|
157
|
-
}
|
|
158
|
-
/* TODO: emissive texture not in .MAT format (???)
|
|
159
|
-
if (m.emissiveTexture) {
|
|
160
|
-
output.push(" map_d "+uvscale+m.emissiveTexture.name);
|
|
161
|
-
}
|
|
162
|
-
*/
|
|
163
|
-
if (m.bumpTexture) {
|
|
164
|
-
output.push(" map_bump -imfchan z " + uvscale + m.bumpTexture.name);
|
|
165
|
-
}
|
|
166
|
-
if (m.opacityTexture) {
|
|
167
|
-
output.push(" map_d " + uvscale + m.opacityTexture.name);
|
|
168
|
-
}
|
|
169
|
-
var text = output.join("\n");
|
|
170
|
-
return text;
|
|
171
|
-
};
|
|
172
|
-
return OBJExport;
|
|
173
|
-
}());
|
|
174
|
-
export { OBJExport };
|
|
1
|
+
import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
|
2
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
3
|
+
/**
|
|
4
|
+
* Class for generating OBJ data from a Babylon scene.
|
|
5
|
+
*/
|
|
6
|
+
var OBJExport = /** @class */ (function () {
|
|
7
|
+
function OBJExport() {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Exports the geometry of a Mesh array in .OBJ file format (text)
|
|
11
|
+
* @param mesh defines the list of meshes to serialize
|
|
12
|
+
* @param materials defines if materials should be exported
|
|
13
|
+
* @param matlibname defines the name of the associated mtl file
|
|
14
|
+
* @param globalposition defines if the exported positions are globals or local to the exported mesh
|
|
15
|
+
* @returns the OBJ content
|
|
16
|
+
*/
|
|
17
|
+
OBJExport.OBJ = function (mesh, materials, matlibname, globalposition) {
|
|
18
|
+
var output = [];
|
|
19
|
+
var v = 1;
|
|
20
|
+
// keep track of uv index in case mixed meshes are passed in
|
|
21
|
+
var textureV = 1;
|
|
22
|
+
if (materials) {
|
|
23
|
+
if (!matlibname) {
|
|
24
|
+
matlibname = "mat";
|
|
25
|
+
}
|
|
26
|
+
output.push("mtllib " + matlibname + ".mtl");
|
|
27
|
+
}
|
|
28
|
+
for (var j = 0; j < mesh.length; j++) {
|
|
29
|
+
output.push("g object" + j);
|
|
30
|
+
output.push("o object_" + j);
|
|
31
|
+
//Uses the position of the item in the scene, to the file (this back to normal in the end)
|
|
32
|
+
var inverseTransform = null;
|
|
33
|
+
if (globalposition) {
|
|
34
|
+
var transform = mesh[j].computeWorldMatrix(true);
|
|
35
|
+
inverseTransform = new Matrix();
|
|
36
|
+
transform.invertToRef(inverseTransform);
|
|
37
|
+
mesh[j].bakeTransformIntoVertices(transform);
|
|
38
|
+
}
|
|
39
|
+
//TODO: submeshes (groups)
|
|
40
|
+
//TODO: smoothing groups (s 1, s off);
|
|
41
|
+
if (materials) {
|
|
42
|
+
var mat = mesh[j].material;
|
|
43
|
+
if (mat) {
|
|
44
|
+
output.push("usemtl " + mat.id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
var g = mesh[j].geometry;
|
|
48
|
+
if (!g) {
|
|
49
|
+
Tools.Warn("No geometry is present on the mesh");
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
var trunkVerts = g.getVerticesData("position");
|
|
53
|
+
var trunkNormals = g.getVerticesData("normal");
|
|
54
|
+
var trunkUV = g.getVerticesData("uv");
|
|
55
|
+
var trunkFaces = g.getIndices();
|
|
56
|
+
var currentV = 0;
|
|
57
|
+
var currentTextureV = 0;
|
|
58
|
+
if (!trunkVerts || !trunkFaces) {
|
|
59
|
+
Tools.Warn("There are no position vertices or indices on the mesh!");
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
for (var i = 0; i < trunkVerts.length; i += 3) {
|
|
63
|
+
// Babylon.js default is left handed, while OBJ default is right handed
|
|
64
|
+
// Need to invert Z vertices unless Babylon is set to use a right handed system
|
|
65
|
+
if (mesh[0].getScene().useRightHandedSystem) {
|
|
66
|
+
output.push("v " + trunkVerts[i] + " " + trunkVerts[i + 1] + " " + trunkVerts[i + 2]);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
output.push("v " + trunkVerts[i] + " " + trunkVerts[i + 1] + " " + -trunkVerts[i + 2]);
|
|
70
|
+
}
|
|
71
|
+
currentV++;
|
|
72
|
+
}
|
|
73
|
+
if (trunkNormals != null) {
|
|
74
|
+
for (var i = 0; i < trunkNormals.length; i += 3) {
|
|
75
|
+
output.push("vn " + trunkNormals[i] + " " + trunkNormals[i + 1] + " " + trunkNormals[i + 2]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (trunkUV != null) {
|
|
79
|
+
for (var i = 0; i < trunkUV.length; i += 2) {
|
|
80
|
+
output.push("vt " + trunkUV[i] + " " + trunkUV[i + 1]);
|
|
81
|
+
currentTextureV++;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (var i = 0; i < trunkFaces.length; i += 3) {
|
|
85
|
+
var indices = [String(trunkFaces[i + 2] + v), String(trunkFaces[i + 1] + v), String(trunkFaces[i] + v)];
|
|
86
|
+
var textureIndices = [String(trunkFaces[i + 2] + textureV), String(trunkFaces[i + 1] + textureV), String(trunkFaces[i] + textureV)];
|
|
87
|
+
var blanks = ["", "", ""];
|
|
88
|
+
var facePositions = indices;
|
|
89
|
+
var faceUVs = trunkUV != null ? textureIndices : blanks;
|
|
90
|
+
var faceNormals = trunkNormals != null ? indices : blanks;
|
|
91
|
+
output.push("f " +
|
|
92
|
+
facePositions[0] +
|
|
93
|
+
"/" +
|
|
94
|
+
faceUVs[0] +
|
|
95
|
+
"/" +
|
|
96
|
+
faceNormals[0] +
|
|
97
|
+
" " +
|
|
98
|
+
facePositions[1] +
|
|
99
|
+
"/" +
|
|
100
|
+
faceUVs[1] +
|
|
101
|
+
"/" +
|
|
102
|
+
faceNormals[1] +
|
|
103
|
+
" " +
|
|
104
|
+
facePositions[2] +
|
|
105
|
+
"/" +
|
|
106
|
+
faceUVs[2] +
|
|
107
|
+
"/" +
|
|
108
|
+
faceNormals[2]);
|
|
109
|
+
}
|
|
110
|
+
//back de previous matrix, to not change the original mesh in the scene
|
|
111
|
+
if (globalposition && inverseTransform) {
|
|
112
|
+
mesh[j].bakeTransformIntoVertices(inverseTransform);
|
|
113
|
+
}
|
|
114
|
+
v += currentV;
|
|
115
|
+
textureV += currentTextureV;
|
|
116
|
+
}
|
|
117
|
+
var text = output.join("\n");
|
|
118
|
+
return text;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Exports the material(s) of a mesh in .MTL file format (text)
|
|
122
|
+
* @param mesh defines the mesh to extract the material from
|
|
123
|
+
* @returns the mtl content
|
|
124
|
+
*/
|
|
125
|
+
//TODO: Export the materials of mesh array
|
|
126
|
+
OBJExport.MTL = function (mesh) {
|
|
127
|
+
var output = [];
|
|
128
|
+
var m = mesh.material;
|
|
129
|
+
output.push("newmtl mat1");
|
|
130
|
+
output.push(" Ns " + m.specularPower.toFixed(4));
|
|
131
|
+
output.push(" Ni 1.5000");
|
|
132
|
+
output.push(" d " + m.alpha.toFixed(4));
|
|
133
|
+
output.push(" Tr 0.0000");
|
|
134
|
+
output.push(" Tf 1.0000 1.0000 1.0000");
|
|
135
|
+
output.push(" illum 2");
|
|
136
|
+
output.push(" Ka " + m.ambientColor.r.toFixed(4) + " " + m.ambientColor.g.toFixed(4) + " " + m.ambientColor.b.toFixed(4));
|
|
137
|
+
output.push(" Kd " + m.diffuseColor.r.toFixed(4) + " " + m.diffuseColor.g.toFixed(4) + " " + m.diffuseColor.b.toFixed(4));
|
|
138
|
+
output.push(" Ks " + m.specularColor.r.toFixed(4) + " " + m.specularColor.g.toFixed(4) + " " + m.specularColor.b.toFixed(4));
|
|
139
|
+
output.push(" Ke " + m.emissiveColor.r.toFixed(4) + " " + m.emissiveColor.g.toFixed(4) + " " + m.emissiveColor.b.toFixed(4));
|
|
140
|
+
//TODO: uv scale, offset, wrap
|
|
141
|
+
//TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures?
|
|
142
|
+
var uvscale = "";
|
|
143
|
+
if (m.ambientTexture) {
|
|
144
|
+
output.push(" map_Ka " + uvscale + m.ambientTexture.name);
|
|
145
|
+
}
|
|
146
|
+
if (m.diffuseTexture) {
|
|
147
|
+
output.push(" map_Kd " + uvscale + m.diffuseTexture.name);
|
|
148
|
+
//TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d)
|
|
149
|
+
}
|
|
150
|
+
if (m.specularTexture) {
|
|
151
|
+
output.push(" map_Ks " + uvscale + m.specularTexture.name);
|
|
152
|
+
/* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???)
|
|
153
|
+
if (m.useGlossinessFromSpecularMapAlpha) {
|
|
154
|
+
output.push(" map_Ns "+uvscale + m.specularTexture.name);
|
|
155
|
+
}
|
|
156
|
+
*/
|
|
157
|
+
}
|
|
158
|
+
/* TODO: emissive texture not in .MAT format (???)
|
|
159
|
+
if (m.emissiveTexture) {
|
|
160
|
+
output.push(" map_d "+uvscale+m.emissiveTexture.name);
|
|
161
|
+
}
|
|
162
|
+
*/
|
|
163
|
+
if (m.bumpTexture) {
|
|
164
|
+
output.push(" map_bump -imfchan z " + uvscale + m.bumpTexture.name);
|
|
165
|
+
}
|
|
166
|
+
if (m.opacityTexture) {
|
|
167
|
+
output.push(" map_d " + uvscale + m.opacityTexture.name);
|
|
168
|
+
}
|
|
169
|
+
var text = output.join("\n");
|
|
170
|
+
return text;
|
|
171
|
+
};
|
|
172
|
+
return OBJExport;
|
|
173
|
+
}());
|
|
174
|
+
export { OBJExport };
|
|
175
175
|
//# sourceMappingURL=objSerializer.js.map
|
package/OBJ/objSerializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objSerializer.js","sourceRoot":"","sources":["../../../../../lts/serializers/generated/OBJ/objSerializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAChD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAKxC;;GAEG;AACH;IAAA;IA2LA,CAAC;IA1LG;;;;;;;OAOG;IACW,aAAG,GAAjB,UAAkB,IAAY,EAAE,SAAmB,EAAE,UAAmB,EAAE,cAAwB;QAC9F,IAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,4DAA4D;QAC5D,IAAI,QAAQ,GAAG,CAAC,CAAC;QAEjB,IAAI,SAAS,EAAE;YACX,IAAI,CAAC,UAAU,EAAE;gBACb,UAAU,GAAG,KAAK,CAAC;aACtB;YACD,MAAM,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;SAChD;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAClC,MAAM,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;YAC5B,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;YAE7B,0FAA0F;YAC1F,IAAI,gBAAgB,GAAqB,IAAI,CAAC;YAC9C,IAAI,cAAc,EAAE;gBAChB,IAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;gBACnD,gBAAgB,GAAG,IAAI,MAAM,EAAE,CAAC;gBAChC,SAAS,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;gBAExC,IAAI,CAAC,CAAC,C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AAC;SACxE;QAED,IAAI,CAAC,CAAC,cAAc,EAAE;YAClB,MAAM,CAAC,IAAI,CAAC,UAAU,GAAG,OAAO,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;SAC7D;QAED,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IAChB,CAAC;IACL,gBAAC;AAAD,CAAC,AA3LD,IA2LC","sourcesContent":["import { Nullable } from \"core/types\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport { Geometry } from \"core/Meshes/geometry\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\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 mesh 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(mesh: 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 < mesh.length; j++) {\r\n output.push(\"g object\" + j);\r\n output.push(\"o object_\" + j);\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[j].computeWorldMatrix(true);\r\n inverseTransform = new Matrix();\r\n transform.invertToRef(inverseTransform);\r\n\r\n mesh[j].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[j].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[j].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 for (let i = 0; i < trunkVerts.length; i += 3) {\r\n // Babylon.js default is left handed, while OBJ default is right handed\r\n // Need to invert Z vertices unless Babylon is set to use a right handed system\r\n if (mesh[0].getScene().useRightHandedSystem) {\r\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + trunkVerts[i + 2]);\r\n } else {\r\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + -trunkVerts[i + 2]);\r\n }\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] + \" \" + 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 for (let i = 0; i < trunkFaces.length; i += 3) {\r\n const indices = [String(trunkFaces[i + 2] + v), String(trunkFaces[i + 1] + v), String(trunkFaces[i] + v)];\r\n const textureIndices = [String(trunkFaces[i + 2] + textureV), String(trunkFaces[i + 1] + textureV), String(trunkFaces[i] + textureV)];\r\n const blanks: string[] = [\"\", \"\", \"\"];\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[j].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"]}
|
|
1
|
+
{"version":3,"file":"objSerializer.js","sourceRoot":"","sources":["../../../../../lts/serializers/generated/OBJ/objSerializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAChD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAKxC;;GAEG;AACH;IAAA;IA2LA,CAAC;IA1LG;;;;;;;OAOG;IACW,aAAG,GAAjB,UAAkB,IAAY,EAAE,SAAmB,EAAE,UAAmB,EAAE,cAAwB;QAC9F,IAAM,MA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AAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAE9H,8BAA8B;QAC9B,iFAAiF;QACjF,IAAM,OAAO,GAAG,EAAE,CAAC;QAEnB,IAAI,CAAC,CAAC,cAAc,EAAE;YAClB,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,OAAO,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;SAC9D;QAED,IAAI,CAAC,CAAC,cAAc,EAAE;YAClB,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,OAAO,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC3D,kGAAkG;SACrG;QAED,IAAI,CAAC,CAAC,eAAe,EAAE;YACnB,MAAM,CAAC,IAAI,CAAC,WAAW,GAAG,OAAO,GAAG,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC5D;;;;cAIE;SACL;QAED;;;;UAIE;QAEF,IAAI,CAAC,CAAC,WAAW,EAAE;YACf,MAAM,CAAC,IAAI,CAAC,wBAAwB,GAAG,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SACxE;QAED,IAAI,CAAC,CAAC,cAAc,EAAE;YAClB,MAAM,CAAC,IAAI,CAAC,UAAU,GAAG,OAAO,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;SAC7D;QAED,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IAChB,CAAC;IACL,gBAAC;AAAD,CAAC,AA3LD,IA2LC","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\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 mesh 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(mesh: 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 < mesh.length; j++) {\r\n output.push(\"g object\" + j);\r\n output.push(\"o object_\" + j);\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[j].computeWorldMatrix(true);\r\n inverseTransform = new Matrix();\r\n transform.invertToRef(inverseTransform);\r\n\r\n mesh[j].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[j].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[j].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 for (let i = 0; i < trunkVerts.length; i += 3) {\r\n // Babylon.js default is left handed, while OBJ default is right handed\r\n // Need to invert Z vertices unless Babylon is set to use a right handed system\r\n if (mesh[0].getScene().useRightHandedSystem) {\r\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + trunkVerts[i + 2]);\r\n } else {\r\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + -trunkVerts[i + 2]);\r\n }\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] + \" \" + 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 for (let i = 0; i < trunkFaces.length; i += 3) {\r\n const indices = [String(trunkFaces[i + 2] + v), String(trunkFaces[i + 1] + v), String(trunkFaces[i] + v)];\r\n const textureIndices = [String(trunkFaces[i + 2] + textureV), String(trunkFaces[i + 1] + textureV), String(trunkFaces[i] + textureV)];\r\n const blanks: string[] = [\"\", \"\", \"\"];\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[j].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"]}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { Nullable } from "@babylonjs/core/types.js";
|
|
2
|
-
import { Node } from "@babylonjs/core/node.js";
|
|
3
|
-
import { INode } from "babylonjs-gltf2interface";
|
|
4
|
-
import { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
|
|
5
|
-
import { _Exporter } from "../glTFExporter";
|
|
6
|
-
/**
|
|
7
|
-
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
|
|
8
|
-
*/
|
|
9
|
-
export declare class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
|
|
10
|
-
/** The name of this extension. */
|
|
11
|
-
readonly name = "KHR_lights_punctual";
|
|
12
|
-
/** Defines whether this extension is enabled. */
|
|
13
|
-
enabled: boolean;
|
|
14
|
-
/** Defines whether this extension is required */
|
|
15
|
-
required: boolean;
|
|
16
|
-
/** Reference to the glTF exporter */
|
|
17
|
-
private _exporter;
|
|
18
|
-
private _lights;
|
|
19
|
-
/**
|
|
20
|
-
* @param exporter
|
|
21
|
-
* @hidden
|
|
22
|
-
*/
|
|
23
|
-
constructor(exporter: _Exporter);
|
|
24
|
-
/** @hidden */
|
|
25
|
-
dispose(): void;
|
|
26
|
-
/** @hidden */
|
|
27
|
-
get wasUsed(): boolean;
|
|
28
|
-
/** @hidden */
|
|
29
|
-
onExporting(): void;
|
|
30
|
-
/**
|
|
31
|
-
* Define this method to modify the default behavior when exporting a node
|
|
32
|
-
* @param context The context when exporting the node
|
|
33
|
-
* @param node glTF node
|
|
34
|
-
* @param babylonNode BabylonJS node
|
|
35
|
-
* @param nodeMap Node mapping of unique id to glTF node index
|
|
36
|
-
* @returns nullable INode promise
|
|
37
|
-
*/
|
|
38
|
-
postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
|
|
39
|
-
[key: number]: number;
|
|
40
|
-
}): Promise<Nullable<INode>>;
|
|
41
|
-
}
|
|
1
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
|
2
|
+
import type { Node } from "@babylonjs/core/node.js";
|
|
3
|
+
import type { INode } from "babylonjs-gltf2interface";
|
|
4
|
+
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
|
|
5
|
+
import { _Exporter } from "../glTFExporter";
|
|
6
|
+
/**
|
|
7
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
|
|
8
|
+
*/
|
|
9
|
+
export declare class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
|
|
10
|
+
/** The name of this extension. */
|
|
11
|
+
readonly name = "KHR_lights_punctual";
|
|
12
|
+
/** Defines whether this extension is enabled. */
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
/** Defines whether this extension is required */
|
|
15
|
+
required: boolean;
|
|
16
|
+
/** Reference to the glTF exporter */
|
|
17
|
+
private _exporter;
|
|
18
|
+
private _lights;
|
|
19
|
+
/**
|
|
20
|
+
* @param exporter
|
|
21
|
+
* @hidden
|
|
22
|
+
*/
|
|
23
|
+
constructor(exporter: _Exporter);
|
|
24
|
+
/** @hidden */
|
|
25
|
+
dispose(): void;
|
|
26
|
+
/** @hidden */
|
|
27
|
+
get wasUsed(): boolean;
|
|
28
|
+
/** @hidden */
|
|
29
|
+
onExporting(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Define this method to modify the default behavior when exporting a node
|
|
32
|
+
* @param context The context when exporting the node
|
|
33
|
+
* @param node glTF node
|
|
34
|
+
* @param babylonNode BabylonJS node
|
|
35
|
+
* @param nodeMap Node mapping of unique id to glTF node index
|
|
36
|
+
* @returns nullable INode promise
|
|
37
|
+
*/
|
|
38
|
+
postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
|
|
39
|
+
[key: number]: number;
|
|
40
|
+
}): Promise<Nullable<INode>>;
|
|
41
|
+
}
|