@babylonjs/serializers 5.0.0-alpha.7 → 5.0.0-beta.2
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.js +1 -1
- package/OBJ/objSerializer.js +19 -12
- package/OBJ/objSerializer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +8 -8
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +24 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +91 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +6 -11
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +13 -37
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +3 -3
- package/glTF/2.0/Extensions/KHR_texture_transform.js +4 -4
- package/glTF/2.0/Extensions/index.d.ts +1 -0
- package/glTF/2.0/Extensions/index.js +5 -4
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/glTFAnimation.js +10 -9
- package/glTF/2.0/glTFAnimation.js.map +1 -1
- package/glTF/2.0/glTFData.js +1 -1
- package/glTF/2.0/glTFData.js.map +1 -1
- package/glTF/2.0/glTFExporter.d.ts +7 -0
- package/glTF/2.0/glTFExporter.js +133 -97
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFExporterExtension.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.d.ts +8 -6
- package/glTF/2.0/glTFMaterialExporter.js +67 -48
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/glTF/2.0/glTFSerializer.d.ts +4 -0
- package/glTF/2.0/glTFSerializer.js +1 -1
- package/glTF/2.0/glTFSerializer.js.map +1 -1
- package/glTF/2.0/glTFUtilities.d.ts +1 -2
- package/glTF/2.0/glTFUtilities.js +1 -5
- package/glTF/2.0/glTFUtilities.js.map +1 -1
- package/glTF/2.0/index.d.ts +1 -1
- package/glTF/2.0/index.js +8 -8
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/2.0/shaders/textureTransform.fragment.js +3 -3
- package/glTF/2.0/shaders/textureTransform.fragment.js.map +1 -1
- package/glTF/index.d.ts +1 -1
- package/glTF/index.js +2 -2
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF2Serializer.d.ts +1 -1
- package/legacy/legacy-glTF2Serializer.js +7 -7
- package/legacy/legacy-glTF2Serializer.js.map +1 -1
- package/legacy/legacy-objSerializer.d.ts +1 -1
- package/legacy/legacy-objSerializer.js +2 -2
- package/legacy/legacy-objSerializer.js.map +1 -1
- package/legacy/legacy-stlSerializer.d.ts +1 -1
- package/legacy/legacy-stlSerializer.js +2 -2
- package/legacy/legacy-stlSerializer.js.map +1 -1
- package/legacy/legacy.js +4 -4
- package/package.json +7 -4
- package/stl/index.js +1 -1
- package/stl/stlSerializer.js +2 -2
- package/stl/stlSerializer.js.map +1 -1
package/OBJ/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./objSerializer";
|
|
1
|
+
export * from "./objSerializer.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/OBJ/objSerializer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Matrix } from "@babylonjs/core/Maths/math.vector";
|
|
2
|
-
import { Tools } from "@babylonjs/core/Misc/tools";
|
|
1
|
+
import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
|
2
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
3
3
|
/**
|
|
4
4
|
* Class for generating OBJ data from a Babylon scene.
|
|
5
5
|
*/
|
|
@@ -17,6 +17,8 @@ var OBJExport = /** @class */ (function () {
|
|
|
17
17
|
OBJExport.OBJ = function (mesh, materials, matlibname, globalposition) {
|
|
18
18
|
var output = [];
|
|
19
19
|
var v = 1;
|
|
20
|
+
// keep track of uv index in case mixed meshes are passed in
|
|
21
|
+
var textureV = 1;
|
|
20
22
|
if (materials) {
|
|
21
23
|
if (!matlibname) {
|
|
22
24
|
matlibname = 'mat';
|
|
@@ -27,11 +29,12 @@ var OBJExport = /** @class */ (function () {
|
|
|
27
29
|
output.push("g object" + j);
|
|
28
30
|
output.push("o object_" + j);
|
|
29
31
|
//Uses the position of the item in the scene, to the file (this back to normal in the end)
|
|
30
|
-
var
|
|
32
|
+
var inverseTransform = null;
|
|
31
33
|
if (globalposition) {
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
var transform = mesh[j].computeWorldMatrix(true);
|
|
35
|
+
inverseTransform = new Matrix();
|
|
36
|
+
transform.invertToRef(inverseTransform);
|
|
37
|
+
mesh[j].bakeTransformIntoVertices(transform);
|
|
35
38
|
}
|
|
36
39
|
//TODO: submeshes (groups)
|
|
37
40
|
//TODO: smoothing groups (s 1, s off);
|
|
@@ -50,7 +53,8 @@ var OBJExport = /** @class */ (function () {
|
|
|
50
53
|
var trunkNormals = g.getVerticesData('normal');
|
|
51
54
|
var trunkUV = g.getVerticesData('uv');
|
|
52
55
|
var trunkFaces = g.getIndices();
|
|
53
|
-
var
|
|
56
|
+
var currentV = 0;
|
|
57
|
+
var currentTextureV = 0;
|
|
54
58
|
if (!trunkVerts || !trunkFaces) {
|
|
55
59
|
Tools.Warn("There are no position vertices or indices on the mesh!");
|
|
56
60
|
continue;
|
|
@@ -64,7 +68,7 @@ var OBJExport = /** @class */ (function () {
|
|
|
64
68
|
else {
|
|
65
69
|
output.push("v " + trunkVerts[i] + " " + trunkVerts[i + 1] + " " + -trunkVerts[i + 2]);
|
|
66
70
|
}
|
|
67
|
-
|
|
71
|
+
currentV++;
|
|
68
72
|
}
|
|
69
73
|
if (trunkNormals != null) {
|
|
70
74
|
for (i = 0; i < trunkNormals.length; i += 3) {
|
|
@@ -74,23 +78,26 @@ var OBJExport = /** @class */ (function () {
|
|
|
74
78
|
if (trunkUV != null) {
|
|
75
79
|
for (i = 0; i < trunkUV.length; i += 2) {
|
|
76
80
|
output.push("vt " + trunkUV[i] + " " + trunkUV[i + 1]);
|
|
81
|
+
currentTextureV++;
|
|
77
82
|
}
|
|
78
83
|
}
|
|
79
84
|
for (i = 0; i < trunkFaces.length; i += 3) {
|
|
80
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)];
|
|
81
87
|
var blanks = ["", "", ""];
|
|
82
88
|
var facePositions = indices;
|
|
83
|
-
var faceUVs = trunkUV != null ?
|
|
89
|
+
var faceUVs = trunkUV != null ? textureIndices : blanks;
|
|
84
90
|
var faceNormals = trunkNormals != null ? indices : blanks;
|
|
85
91
|
output.push("f " + facePositions[0] + "/" + faceUVs[0] + "/" + faceNormals[0] +
|
|
86
92
|
" " + facePositions[1] + "/" + faceUVs[1] + "/" + faceNormals[1] +
|
|
87
93
|
" " + facePositions[2] + "/" + faceUVs[2] + "/" + faceNormals[2]);
|
|
88
94
|
}
|
|
89
95
|
//back de previous matrix, to not change the original mesh in the scene
|
|
90
|
-
if (globalposition &&
|
|
91
|
-
mesh[j].bakeTransformIntoVertices(
|
|
96
|
+
if (globalposition && inverseTransform) {
|
|
97
|
+
mesh[j].bakeTransformIntoVertices(inverseTransform);
|
|
92
98
|
}
|
|
93
|
-
v +=
|
|
99
|
+
v += currentV;
|
|
100
|
+
textureV += currentTextureV;
|
|
94
101
|
}
|
|
95
102
|
var text = output.join("\n");
|
|
96
103
|
return (text);
|
package/OBJ/objSerializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objSerializer.js","sourceRoot":"","sources":["../../../sourceES6/serializers/src/OB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;AAAD,CAAC,AApKD,IAoKC","sourcesContent":["\nimport { Nullable } from \"@babylonjs/core/types\";\nimport { Matrix } from \"@babylonjs/core/Maths/math.vector\";\nimport { Tools } from \"@babylonjs/core/Misc/tools\";\nimport { StandardMaterial } from \"@babylonjs/core/Materials/standardMaterial\";\nimport { Geometry } from \"@babylonjs/core/Meshes/geometry\";\nimport { Mesh } from \"@babylonjs/core/Meshes/mesh\";\n\n/**\n * Class for generating OBJ data from a Babylon scene.\n */\nexport class OBJExport {\n /**\n * Exports the geometry of a Mesh array in .OBJ file format (text)\n * @param mesh defines the list of meshes to serialize\n * @param materials defines if materials should be exported\n * @param matlibname defines the name of the associated mtl file\n * @param globalposition defines if the exported positions are globals or local to the exported mesh\n * @returns the OBJ content\n */\n public static OBJ(mesh: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean): string {\n const output: string[] = [];\n let v = 1;\n if (materials) {\n if (!matlibname) {\n matlibname = 'mat';\n }\n output.push(\"mtllib \" + matlibname + \".mtl\");\n }\n for (let j = 0; j < mesh.length; j++) {\n output.push(\"g object\" + j);\n output.push(\"o object_\" + j);\n\n //Uses the position of the item in the scene, to the file (this back to normal in the end)\n let lastMatrix: Nullable<Matrix> = null;\n if (globalposition) {\n var newMatrix = Matrix.Translation(mesh[j].position.x, mesh[j].position.y, mesh[j].position.z);\n lastMatrix = Matrix.Translation(-(mesh[j].position.x), -(mesh[j].position.y), -(mesh[j].position.z));\n mesh[j].bakeTransformIntoVertices(newMatrix);\n }\n\n //TODO: submeshes (groups)\n //TODO: smoothing groups (s 1, s off);\n if (materials) {\n let mat = mesh[j].material;\n\n if (mat) {\n output.push(\"usemtl \" + mat.id);\n }\n }\n const g: Nullable<Geometry> = mesh[j].geometry;\n\n if (!g) {\n Tools.Warn(\"No geometry is present on the mesh\");\n continue;\n }\n\n const trunkVerts = g.getVerticesData('position');\n const trunkNormals = g.getVerticesData('normal');\n const trunkUV = g.getVerticesData('uv');\n const trunkFaces = g.getIndices();\n var curV = 0;\n\n if (!trunkVerts || !trunkFaces) {\n Tools.Warn(\"There are no position vertices or indices on the mesh!\");\n continue;\n }\n\n for (var i = 0; i < trunkVerts.length; i += 3) {\n // Babylon.js default is left handed, while OBJ default is right handed\n // Need to invert Z vertices unless Babylon is set to use a right handed system\n if (mesh[0].getScene().useRightHandedSystem) {\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + trunkVerts[i + 2]);\n } else {\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + -trunkVerts[i + 2]);\n }\n curV++;\n }\n\n if (trunkNormals != null) {\n for (i = 0; i < trunkNormals.length; i += 3) {\n output.push(\"vn \" + trunkNormals[i] + \" \" + trunkNormals[i + 1] + \" \" + trunkNormals[i + 2]);\n }\n }\n if (trunkUV != null) {\n\n for (i = 0; i < trunkUV.length; i += 2) {\n output.push(\"vt \" + trunkUV[i] + \" \" + trunkUV[i + 1]);\n }\n }\n\n for (i = 0; i < trunkFaces.length; i += 3) {\n const indices = [String(trunkFaces[i + 2] + v), String(trunkFaces[i + 1] + v), String(trunkFaces[i] + v)];\n const blanks: string[] = [\"\", \"\", \"\"];\n\n const facePositions = indices;\n const faceUVs = trunkUV != null ? indices : blanks;\n const faceNormals = trunkNormals != null ? indices : blanks;\n\n output.push(\n \"f \" + facePositions[0] + \"/\" + faceUVs[0] + \"/\" + faceNormals[0] +\n \" \" + facePositions[1] + \"/\" + faceUVs[1] + \"/\" + faceNormals[1] +\n \" \" + facePositions[2] + \"/\" + faceUVs[2] + \"/\" + faceNormals[2]\n );\n }\n //back de previous matrix, to not change the original mesh in the scene\n if (globalposition && lastMatrix) {\n mesh[j].bakeTransformIntoVertices(lastMatrix);\n }\n v += curV;\n }\n const text: string = output.join(\"\\n\");\n return (text);\n }\n\n /**\n * Exports the material(s) of a mesh in .MTL file format (text)\n * @param mesh defines the mesh to extract the material from\n * @returns the mtl content\n */\n //TODO: Export the materials of mesh array\n public static MTL(mesh: Mesh): string {\n var output = [];\n var m = <StandardMaterial>mesh.material;\n output.push(\"newmtl mat1\");\n output.push(\" Ns \" + m.specularPower.toFixed(4));\n output.push(\" Ni 1.5000\");\n output.push(\" d \" + m.alpha.toFixed(4));\n output.push(\" Tr 0.0000\");\n output.push(\" Tf 1.0000 1.0000 1.0000\");\n output.push(\" illum 2\");\n output.push(\" Ka \" + m.ambientColor.r.toFixed(4) + \" \" + m.ambientColor.g.toFixed(4) + \" \" + m.ambientColor.b.toFixed(4));\n output.push(\" Kd \" + m.diffuseColor.r.toFixed(4) + \" \" + m.diffuseColor.g.toFixed(4) + \" \" + m.diffuseColor.b.toFixed(4));\n output.push(\" Ks \" + m.specularColor.r.toFixed(4) + \" \" + m.specularColor.g.toFixed(4) + \" \" + m.specularColor.b.toFixed(4));\n output.push(\" Ke \" + m.emissiveColor.r.toFixed(4) + \" \" + m.emissiveColor.g.toFixed(4) + \" \" + m.emissiveColor.b.toFixed(4));\n\n //TODO: uv scale, offset, wrap\n //TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures?\n var uvscale = \"\";\n\n if (m.ambientTexture) {\n output.push(\" map_Ka \" + uvscale + m.ambientTexture.name);\n }\n\n if (m.diffuseTexture) {\n output.push(\" map_Kd \" + uvscale + m.diffuseTexture.name);\n //TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d)\n }\n\n if (m.specularTexture) {\n output.push(\" map_Ks \" + uvscale + m.specularTexture.name);\n /* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???)\n if (m.useGlossinessFromSpecularMapAlpha) {\n output.push(\" map_Ns \"+uvscale + m.specularTexture.name);\n }\n */\n }\n\n /* TODO: emissive texture not in .MAT format (???)\n if (m.emissiveTexture) {\n output.push(\" map_d \"+uvscale+m.emissiveTexture.name);\n }\n */\n\n if (m.bumpTexture) {\n output.push(\" map_bump -imfchan z \" + uvscale + m.bumpTexture.name);\n }\n\n if (m.opacityTexture) {\n output.push(\" map_d \" + uvscale + m.opacityTexture.name);\n }\n\n var text = output.join(\"\\n\");\n return (text);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"objSerializer.js","sourceRoot":"","sources":["../../../sourceES6/serializers/src/OBJ/objSerializer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAKnD;;GAEG;AACH;IAAA;IA6KA,CAAC;IA5KG;;;;;;;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,CAAC,CAAC,yBAAyB,CAAC,SAAS,C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AE;YAClB,MAAM,CAAC,IAAI,CAAC,UAAU,GAAG,OAAO,GAAG,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;SAC7D;QAED,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IACL,gBAAC;AAAD,CAAC,AA7KD,IA6KC","sourcesContent":["\nimport { Nullable } from \"@babylonjs/core/types\";\nimport { Matrix } from \"@babylonjs/core/Maths/math.vector\";\nimport { Tools } from \"@babylonjs/core/Misc/tools\";\nimport { StandardMaterial } from \"@babylonjs/core/Materials/standardMaterial\";\nimport { Geometry } from \"@babylonjs/core/Meshes/geometry\";\nimport { Mesh } from \"@babylonjs/core/Meshes/mesh\";\n\n/**\n * Class for generating OBJ data from a Babylon scene.\n */\nexport class OBJExport {\n /**\n * Exports the geometry of a Mesh array in .OBJ file format (text)\n * @param mesh defines the list of meshes to serialize\n * @param materials defines if materials should be exported\n * @param matlibname defines the name of the associated mtl file\n * @param globalposition defines if the exported positions are globals or local to the exported mesh\n * @returns the OBJ content\n */\n public static OBJ(mesh: Mesh[], materials?: boolean, matlibname?: string, globalposition?: boolean): string {\n const output: string[] = [];\n let v = 1;\n // keep track of uv index in case mixed meshes are passed in\n let textureV = 1;\n\n if (materials) {\n if (!matlibname) {\n matlibname = 'mat';\n }\n output.push(\"mtllib \" + matlibname + \".mtl\");\n }\n for (let j = 0; j < mesh.length; j++) {\n output.push(\"g object\" + j);\n output.push(\"o object_\" + j);\n\n //Uses the position of the item in the scene, to the file (this back to normal in the end)\n let inverseTransform: Nullable<Matrix> = null;\n if (globalposition) {\n const transform = mesh[j].computeWorldMatrix(true);\n inverseTransform = new Matrix();\n transform.invertToRef(inverseTransform);\n\n mesh[j].bakeTransformIntoVertices(transform);\n }\n\n //TODO: submeshes (groups)\n //TODO: smoothing groups (s 1, s off);\n if (materials) {\n let mat = mesh[j].material;\n\n if (mat) {\n output.push(\"usemtl \" + mat.id);\n }\n }\n const g: Nullable<Geometry> = mesh[j].geometry;\n\n if (!g) {\n Tools.Warn(\"No geometry is present on the mesh\");\n continue;\n }\n\n const trunkVerts = g.getVerticesData('position');\n const trunkNormals = g.getVerticesData('normal');\n const trunkUV = g.getVerticesData('uv');\n const trunkFaces = g.getIndices();\n let currentV = 0;\n let currentTextureV = 0;\n\n if (!trunkVerts || !trunkFaces) {\n Tools.Warn(\"There are no position vertices or indices on the mesh!\");\n continue;\n }\n\n for (var i = 0; i < trunkVerts.length; i += 3) {\n // Babylon.js default is left handed, while OBJ default is right handed\n // Need to invert Z vertices unless Babylon is set to use a right handed system\n if (mesh[0].getScene().useRightHandedSystem) {\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + trunkVerts[i + 2]);\n } else {\n output.push(\"v \" + trunkVerts[i] + \" \" + trunkVerts[i + 1] + \" \" + -trunkVerts[i + 2]);\n }\n currentV++;\n }\n\n if (trunkNormals != null) {\n for (i = 0; i < trunkNormals.length; i += 3) {\n output.push(\"vn \" + trunkNormals[i] + \" \" + trunkNormals[i + 1] + \" \" + trunkNormals[i + 2]);\n }\n }\n if (trunkUV != null) {\n\n for (i = 0; i < trunkUV.length; i += 2) {\n output.push(\"vt \" + trunkUV[i] + \" \" + trunkUV[i + 1]);\n currentTextureV++;\n }\n }\n\n for (i = 0; i < trunkFaces.length; i += 3) {\n const indices = [String(trunkFaces[i + 2] + v), String(trunkFaces[i + 1] + v), String(trunkFaces[i] + v)];\n const textureIndices = [String(trunkFaces[i + 2] + textureV), String(trunkFaces[i + 1] + textureV), String(trunkFaces[i] + textureV)];\n const blanks: string[] = [\"\", \"\", \"\"];\n\n const facePositions = indices;\n const faceUVs = trunkUV != null ? textureIndices : blanks;\n const faceNormals = trunkNormals != null ? indices : blanks;\n\n output.push(\n \"f \" + facePositions[0] + \"/\" + faceUVs[0] + \"/\" + faceNormals[0] +\n \" \" + facePositions[1] + \"/\" + faceUVs[1] + \"/\" + faceNormals[1] +\n \" \" + facePositions[2] + \"/\" + faceUVs[2] + \"/\" + faceNormals[2]\n );\n }\n //back de previous matrix, to not change the original mesh in the scene\n if (globalposition && inverseTransform) {\n mesh[j].bakeTransformIntoVertices(inverseTransform);\n }\n v += currentV;\n textureV += currentTextureV;\n }\n const text: string = output.join(\"\\n\");\n return (text);\n }\n\n /**\n * Exports the material(s) of a mesh in .MTL file format (text)\n * @param mesh defines the mesh to extract the material from\n * @returns the mtl content\n */\n //TODO: Export the materials of mesh array\n public static MTL(mesh: Mesh): string {\n var output = [];\n var m = <StandardMaterial>mesh.material;\n output.push(\"newmtl mat1\");\n output.push(\" Ns \" + m.specularPower.toFixed(4));\n output.push(\" Ni 1.5000\");\n output.push(\" d \" + m.alpha.toFixed(4));\n output.push(\" Tr 0.0000\");\n output.push(\" Tf 1.0000 1.0000 1.0000\");\n output.push(\" illum 2\");\n output.push(\" Ka \" + m.ambientColor.r.toFixed(4) + \" \" + m.ambientColor.g.toFixed(4) + \" \" + m.ambientColor.b.toFixed(4));\n output.push(\" Kd \" + m.diffuseColor.r.toFixed(4) + \" \" + m.diffuseColor.g.toFixed(4) + \" \" + m.diffuseColor.b.toFixed(4));\n output.push(\" Ks \" + m.specularColor.r.toFixed(4) + \" \" + m.specularColor.g.toFixed(4) + \" \" + m.specularColor.b.toFixed(4));\n output.push(\" Ke \" + m.emissiveColor.r.toFixed(4) + \" \" + m.emissiveColor.g.toFixed(4) + \" \" + m.emissiveColor.b.toFixed(4));\n\n //TODO: uv scale, offset, wrap\n //TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures?\n var uvscale = \"\";\n\n if (m.ambientTexture) {\n output.push(\" map_Ka \" + uvscale + m.ambientTexture.name);\n }\n\n if (m.diffuseTexture) {\n output.push(\" map_Kd \" + uvscale + m.diffuseTexture.name);\n //TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d)\n }\n\n if (m.specularTexture) {\n output.push(\" map_Ks \" + uvscale + m.specularTexture.name);\n /* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???)\n if (m.useGlossinessFromSpecularMapAlpha) {\n output.push(\" map_Ns \"+uvscale + m.specularTexture.name);\n }\n */\n }\n\n /* TODO: emissive texture not in .MAT format (???)\n if (m.emissiveTexture) {\n output.push(\" map_d \"+uvscale+m.emissiveTexture.name);\n }\n */\n\n if (m.bumpTexture) {\n output.push(\" map_bump -imfchan z \" + uvscale + m.bumpTexture.name);\n }\n\n if (m.opacityTexture) {\n output.push(\" map_d \" + uvscale + m.opacityTexture.name);\n }\n\n var text = output.join(\"\\n\");\n return (text);\n }\n}\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Vector3, Quaternion, TmpVectors, Matrix } from "@babylonjs/core/Maths/math.vector";
|
|
2
|
-
import { Color3 } from "@babylonjs/core/Maths/math.color";
|
|
3
|
-
import { Light } from "@babylonjs/core/Lights/light";
|
|
4
|
-
import { DirectionalLight } from "@babylonjs/core/Lights/directionalLight";
|
|
5
|
-
import { ShadowLight } from "@babylonjs/core/Lights/shadowLight";
|
|
6
|
-
import { _Exporter } from "../glTFExporter";
|
|
7
|
-
import { Logger } from "@babylonjs/core/Misc/logger";
|
|
8
|
-
import { _GLTFUtilities } from "../glTFUtilities";
|
|
1
|
+
import { Vector3, Quaternion, TmpVectors, Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
|
2
|
+
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
|
3
|
+
import { Light } from "@babylonjs/core/Lights/light.js";
|
|
4
|
+
import { DirectionalLight } from "@babylonjs/core/Lights/directionalLight.js";
|
|
5
|
+
import { ShadowLight } from "@babylonjs/core/Lights/shadowLight.js";
|
|
6
|
+
import { _Exporter } from "../glTFExporter.js";
|
|
7
|
+
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
8
|
+
import { _GLTFUtilities } from "../glTFUtilities.js";
|
|
9
9
|
var NAME = "KHR_lights_punctual";
|
|
10
10
|
/**
|
|
11
11
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../sourceES6/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAGjE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,IAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH;IAeI,cAAc;IACd,6BAAY,QAAmB;QAf/B,kCAAkC;QAClB,SAAI,GAAG,IAAI,CAAC;QAE5B,iDAAiD;QAC1C,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QASpB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,cAAc;IACP,qCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAGD,sBAAW,wCAAO;QADlB,cAAc;aACd;YACI,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QAC1B,CAAC;;;OAAA;IAED,cAAc;IACP,yCAAW,GAAlB;QACI,IAAI,CAAC,SAAU,CAAC,KAAK,CA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,CAAC,UAAU,GAAG,EAAE,CAAC;qBACxB;oBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;iBAC1C;aACJ;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;IACL,0BAAC;AAAD,CAAC,AAvLD,IAuLC;;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,QAAQ,IAAK,OAAA,IAAI,mBAAmB,CAAC,QAAQ,CAAC,EAAjC,CAAiC,CAAC,CAAC","sourcesContent":["import { SpotLight } from \"@babylonjs/core/Lights/spotLight\";\nimport { Nullable } from \"@babylonjs/core/types\";\nimport { Vector3, Quaternion, TmpVectors, Matrix } from \"@babylonjs/core/Maths/math.vector\";\nimport { Color3 } from \"@babylonjs/core/Maths/math.color\";\nimport { Light } from \"@babylonjs/core/Lights/light\";\nimport { DirectionalLight } from \"@babylonjs/core/Lights/directionalLight\";\nimport { Node } from \"@babylonjs/core/node\";\nimport { ShadowLight } from \"@babylonjs/core/Lights/shadowLight\";\nimport { INode } from \"babylonjs-gltf2interface\";\nimport { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\nimport { _Exporter } from \"../glTFExporter\";\nimport { Logger } from \"@babylonjs/core/Misc/logger\";\nimport { _GLTFUtilities } from \"../glTFUtilities\";\nimport { IKHRLightsPunctual_LightType, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\n\nconst NAME = \"KHR_lights_punctual\";\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\n */\nexport class KHR_lights_punctual implements IGLTFExporterExtensionV2 {\n /** The name of this extension. */\n public readonly name = NAME;\n\n /** Defines whether this extension is enabled. */\n public enabled = true;\n\n /** Defines whether this extension is required */\n public required = false;\n\n /** Reference to the glTF exporter */\n private _exporter: _Exporter;\n\n private _lights: IKHRLightsPunctual;\n\n /** @hidden */\n constructor(exporter: _Exporter) {\n this._exporter = exporter;\n }\n\n /** @hidden */\n public dispose() {\n (this._lights as any) = null;\n }\n\n /** @hidden */\n public get wasUsed() {\n return !!this._lights;\n }\n\n /** @hidden */\n public onExporting(): void {\n this._exporter!._glTF.extensions![NAME] = this._lights;\n }\n /**\n * Define this method to modify the default behavior when exporting a node\n * @param context The context when exporting the node\n * @param node glTF node\n * @param babylonNode BabylonJS node\n * @param nodeMap Node mapping of unique id to glTF node index\n * @returns nullable INode promise\n */\n public postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {[key: number]: number}): Promise<Nullable<INode>> {\n return new Promise((resolve, reject) => {\n if (node && babylonNode instanceof ShadowLight) {\n const babylonLight: ShadowLight = babylonNode;\n let light: IKHRLightsPunctual_Light;\n\n const lightType = (\n babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT ? IKHRLightsPunctual_LightType.POINT : (\n babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT ? IKHRLightsPunctual_LightType.DIRECTIONAL : (\n babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT ? IKHRLightsPunctual_LightType.SPOT : null\n )));\n if (lightType == null) {\n Logger.Warn(`${context}: Light ${babylonLight.name} is not supported in ${NAME}`);\n }\n else {\n const lightPosition = babylonLight.position.clone();\n let convertToRightHandedSystem = this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];\n if (!lightPosition.equals(Vector3.Zero())) {\n if (convertToRightHandedSystem) {\n _GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);\n }\n node.translation = lightPosition.asArray();\n }\n if (lightType !== IKHRLightsPunctual_LightType.POINT) {\n const localAxis = babylonLight.direction;\n const yaw = -Math.atan2(localAxis.z * (this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\n const pitch = -Math.atan2(localAxis.y, len);\n const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);\n if (convertToRightHandedSystem) {\n _GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);\n }\n if (!lightRotationQuaternion.equals(Quaternion.Identity())) {\n node.rotation = lightRotationQuaternion.asArray();\n }\n }\n\n if (babylonLight.falloffType !== Light.FALLOFF_GLTF) {\n Logger.Warn(`${context}: Light falloff for ${babylonLight.name} does not match the ${NAME} specification!`);\n }\n light = {\n type: lightType\n };\n if (!babylonLight.diffuse.equals(Color3.White())) {\n light.color = babylonLight.diffuse.asArray();\n }\n if (babylonLight.intensity !== 1.0) {\n light.intensity = babylonLight.intensity;\n }\n if (babylonLight.range !== Number.MAX_VALUE) {\n light.range = babylonLight.range;\n }\n\n if (lightType === IKHRLightsPunctual_LightType.SPOT) {\n const babylonSpotLight = babylonLight as SpotLight;\n if (babylonSpotLight.angle !== Math.PI / 2.0) {\n if (light.spot == null) {\n light.spot = {};\n }\n light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;\n }\n if (babylonSpotLight.innerAngle !== 0) {\n if (light.spot == null) {\n light.spot = {};\n }\n light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;\n }\n }\n\n if (this._lights == null) {\n this._lights = {\n lights: []\n };\n }\n\n this._lights.lights.push(light);\n\n const lightReference: IKHRLightsPunctual_LightReference = {\n light: this._lights.lights.length - 1\n };\n\n // Avoid duplicating the Light's parent node if possible.\n let parentBabylonNode = babylonNode.parent;\n if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {\n let parentNode = this._exporter._nodes[nodeMap![parentBabylonNode.uniqueId]];\n if (parentNode) {\n let parentNodeLocalMatrix = TmpVectors.Matrix[0];\n let parentInvertNodeLocalMatrix = TmpVectors.Matrix[1];\n let parentNodeLocalTranslation = parentNode.translation ? new Vector3(parentNode.translation[0], parentNode.translation[1], parentNode.translation[2]) : Vector3.Zero();\n let parentNodeLocalRotation = parentNode.rotation ? new Quaternion(parentNode.rotation[0], parentNode.rotation[1], parentNode.rotation[2], parentNode.rotation[3]) : Quaternion.Identity();\n let parentNodeLocalScale = parentNode.scale ? new Vector3(parentNode.scale[0], parentNode.scale[1], parentNode.scale[2]) : Vector3.One();\n\n Matrix.ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);\n parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);\n\n // Convert light local matrix to local matrix relative to grandparent, facing -Z\n let lightLocalMatrix = TmpVectors.Matrix[2];\n let nodeLocalTranslation = node.translation ? new Vector3(node.translation[0], node.translation[1], node.translation[2]) : Vector3.Zero();\n\n // Undo directional light positional offset\n if (babylonLight instanceof DirectionalLight) {\n nodeLocalTranslation.subtractInPlace(this._exporter._babylonScene.useRightHandedSystem ? babylonLight.direction : _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction));\n }\n let nodeLocalRotation = this._exporter._babylonScene.useRightHandedSystem ? Quaternion.Identity() : new Quaternion(0, 1, 0, 0);\n if (node.rotation) {\n nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));\n }\n let nodeLocalScale = node.scale ? new Vector3(node.scale[0], node.scale[1], node.scale[2]) : Vector3.One();\n\n Matrix.ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);\n lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);\n let parentNewScale = TmpVectors.Vector3[0];\n let parentNewRotationQuaternion = TmpVectors.Quaternion[0];\n let parentNewTranslation = TmpVectors.Vector3[1];\n\n lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);\n parentNode.scale = parentNewScale.asArray();\n parentNode.rotation = parentNewRotationQuaternion.asArray();\n parentNode.translation = parentNewTranslation.asArray();\n\n if (parentNode.extensions == null) {\n parentNode.extensions = {};\n }\n parentNode.extensions[NAME] = lightReference;\n\n // Do not export the original node\n resolve(null);\n return;\n }\n }\n\n if (node.extensions == null) {\n node.extensions = {};\n }\n\n node.extensions[NAME] = lightReference;\n }\n }\n resolve(node);\n });\n }\n}\n\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));"]}
|
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../sourceES6/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAGjE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,IAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH;IAeI,cAAc;IACd,6BAAY,QAAmB;QAf/B,kCAAkC;QAClB,SAAI,GAAG,IAAI,CAAC;QAE5B,iDAAiD;QAC1C,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QASpB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,cAAc;IACP,qCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAGD,sBAAW,wCAAO;QADlB,cAAc;aACd;YACI,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QAC1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BACd,OAAO;yBACV;qBACJ;oBAED,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;wBACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;qBACxB;oBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;iBAC1C;aACJ;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;IACL,0BAAC;AAAD,CAAC,AAvLD,IAuLC;;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,QAAQ,IAAK,OAAA,IAAI,mBAAmB,CAAC,QAAQ,CAAC,EAAjC,CAAiC,CAAC,CAAC","sourcesContent":["import { SpotLight } from \"@babylonjs/core/Lights/spotLight\";\nimport { Nullable } from \"@babylonjs/core/types\";\nimport { Vector3, Quaternion, TmpVectors, Matrix } from \"@babylonjs/core/Maths/math.vector\";\nimport { Color3 } from \"@babylonjs/core/Maths/math.color\";\nimport { Light } from \"@babylonjs/core/Lights/light\";\nimport { DirectionalLight } from \"@babylonjs/core/Lights/directionalLight\";\nimport { Node } from \"@babylonjs/core/node\";\nimport { ShadowLight } from \"@babylonjs/core/Lights/shadowLight\";\nimport { INode } from \"babylonjs-gltf2interface\";\nimport { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\nimport { _Exporter } from \"../glTFExporter\";\nimport { Logger } from \"@babylonjs/core/Misc/logger\";\nimport { _GLTFUtilities } from \"../glTFUtilities\";\nimport { IKHRLightsPunctual_LightType, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\n\nconst NAME = \"KHR_lights_punctual\";\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\n */\nexport class KHR_lights_punctual implements IGLTFExporterExtensionV2 {\n /** The name of this extension. */\n public readonly name = NAME;\n\n /** Defines whether this extension is enabled. */\n public enabled = true;\n\n /** Defines whether this extension is required */\n public required = false;\n\n /** Reference to the glTF exporter */\n private _exporter: _Exporter;\n\n private _lights: IKHRLightsPunctual;\n\n /** @hidden */\n constructor(exporter: _Exporter) {\n this._exporter = exporter;\n }\n\n /** @hidden */\n public dispose() {\n (this._lights as any) = null;\n }\n\n /** @hidden */\n public get wasUsed() {\n return !!this._lights;\n }\n\n /** @hidden */\n public onExporting(): void {\n this._exporter!._glTF.extensions![NAME] = this._lights;\n }\n /**\n * Define this method to modify the default behavior when exporting a node\n * @param context The context when exporting the node\n * @param node glTF node\n * @param babylonNode BabylonJS node\n * @param nodeMap Node mapping of unique id to glTF node index\n * @returns nullable INode promise\n */\n public postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: { [key: number]: number }): Promise<Nullable<INode>> {\n return new Promise((resolve, reject) => {\n if (node && babylonNode instanceof ShadowLight) {\n const babylonLight: ShadowLight = babylonNode;\n let light: IKHRLightsPunctual_Light;\n\n const lightType = (\n babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT ? IKHRLightsPunctual_LightType.POINT : (\n babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT ? IKHRLightsPunctual_LightType.DIRECTIONAL : (\n babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT ? IKHRLightsPunctual_LightType.SPOT : null\n )));\n if (lightType == null) {\n Logger.Warn(`${context}: Light ${babylonLight.name} is not supported in ${NAME}`);\n }\n else {\n const lightPosition = babylonLight.position.clone();\n let convertToRightHandedSystem = this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];\n if (!lightPosition.equals(Vector3.Zero())) {\n if (convertToRightHandedSystem) {\n _GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);\n }\n node.translation = lightPosition.asArray();\n }\n if (lightType !== IKHRLightsPunctual_LightType.POINT) {\n const localAxis = babylonLight.direction;\n const yaw = -Math.atan2(localAxis.z * (this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\n const pitch = -Math.atan2(localAxis.y, len);\n const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);\n if (convertToRightHandedSystem) {\n _GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);\n }\n if (!lightRotationQuaternion.equals(Quaternion.Identity())) {\n node.rotation = lightRotationQuaternion.asArray();\n }\n }\n\n if (babylonLight.falloffType !== Light.FALLOFF_GLTF) {\n Logger.Warn(`${context}: Light falloff for ${babylonLight.name} does not match the ${NAME} specification!`);\n }\n light = {\n type: lightType\n };\n if (!babylonLight.diffuse.equals(Color3.White())) {\n light.color = babylonLight.diffuse.asArray();\n }\n if (babylonLight.intensity !== 1.0) {\n light.intensity = babylonLight.intensity;\n }\n if (babylonLight.range !== Number.MAX_VALUE) {\n light.range = babylonLight.range;\n }\n\n if (lightType === IKHRLightsPunctual_LightType.SPOT) {\n const babylonSpotLight = babylonLight as SpotLight;\n if (babylonSpotLight.angle !== Math.PI / 2.0) {\n if (light.spot == null) {\n light.spot = {};\n }\n light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;\n }\n if (babylonSpotLight.innerAngle !== 0) {\n if (light.spot == null) {\n light.spot = {};\n }\n light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;\n }\n }\n\n if (this._lights == null) {\n this._lights = {\n lights: []\n };\n }\n\n this._lights.lights.push(light);\n\n const lightReference: IKHRLightsPunctual_LightReference = {\n light: this._lights.lights.length - 1\n };\n\n // Avoid duplicating the Light's parent node if possible.\n let parentBabylonNode = babylonNode.parent;\n if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {\n let parentNode = this._exporter._nodes[nodeMap![parentBabylonNode.uniqueId]];\n if (parentNode) {\n let parentNodeLocalMatrix = TmpVectors.Matrix[0];\n let parentInvertNodeLocalMatrix = TmpVectors.Matrix[1];\n let parentNodeLocalTranslation = parentNode.translation ? new Vector3(parentNode.translation[0], parentNode.translation[1], parentNode.translation[2]) : Vector3.Zero();\n let parentNodeLocalRotation = parentNode.rotation ? new Quaternion(parentNode.rotation[0], parentNode.rotation[1], parentNode.rotation[2], parentNode.rotation[3]) : Quaternion.Identity();\n let parentNodeLocalScale = parentNode.scale ? new Vector3(parentNode.scale[0], parentNode.scale[1], parentNode.scale[2]) : Vector3.One();\n\n Matrix.ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);\n parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);\n\n // Convert light local matrix to local matrix relative to grandparent, facing -Z\n let lightLocalMatrix = TmpVectors.Matrix[2];\n let nodeLocalTranslation = node.translation ? new Vector3(node.translation[0], node.translation[1], node.translation[2]) : Vector3.Zero();\n\n // Undo directional light positional offset\n if (babylonLight instanceof DirectionalLight) {\n nodeLocalTranslation.subtractInPlace(this._exporter._babylonScene.useRightHandedSystem ? babylonLight.direction : _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction));\n }\n let nodeLocalRotation = this._exporter._babylonScene.useRightHandedSystem ? Quaternion.Identity() : new Quaternion(0, 1, 0, 0);\n if (node.rotation) {\n nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));\n }\n let nodeLocalScale = node.scale ? new Vector3(node.scale[0], node.scale[1], node.scale[2]) : Vector3.One();\n\n Matrix.ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);\n lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);\n let parentNewScale = TmpVectors.Vector3[0];\n let parentNewRotationQuaternion = TmpVectors.Quaternion[0];\n let parentNewTranslation = TmpVectors.Vector3[1];\n\n lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);\n parentNode.scale = parentNewScale.asArray();\n parentNode.rotation = parentNewRotationQuaternion.asArray();\n parentNode.translation = parentNewTranslation.asArray();\n\n if (parentNode.extensions == null) {\n parentNode.extensions = {};\n }\n parentNode.extensions[NAME] = lightReference;\n\n // Do not export the original node\n resolve(null);\n return;\n }\n }\n\n if (node.extensions == null) {\n node.extensions = {};\n }\n\n node.extensions[NAME] = lightReference;\n }\n }\n resolve(node);\n });\n }\n}\n\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IMaterial } from "babylonjs-gltf2interface";
|
|
2
|
+
import { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
|
|
3
|
+
import { _Exporter } from "../glTFExporter";
|
|
4
|
+
import { Material } from "@babylonjs/core/Materials/material";
|
|
5
|
+
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture";
|
|
6
|
+
/**
|
|
7
|
+
* @hidden
|
|
8
|
+
*/
|
|
9
|
+
export declare class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 {
|
|
10
|
+
/** Name of this extension */
|
|
11
|
+
readonly name = "KHR_materials_clearcoat";
|
|
12
|
+
/** Defines whether this extension is enabled */
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
/** Defines whether this extension is required */
|
|
15
|
+
required: boolean;
|
|
16
|
+
private _exporter;
|
|
17
|
+
private _wasUsed;
|
|
18
|
+
constructor(exporter: _Exporter);
|
|
19
|
+
dispose(): void;
|
|
20
|
+
/** @hidden */
|
|
21
|
+
get wasUsed(): boolean;
|
|
22
|
+
postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
|
|
23
|
+
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { _Exporter } from "../glTFExporter.js";
|
|
2
|
+
import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
|
|
3
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
4
|
+
var NAME = "KHR_materials_clearcoat";
|
|
5
|
+
/**
|
|
6
|
+
* @hidden
|
|
7
|
+
*/
|
|
8
|
+
var KHR_materials_clearcoat = /** @class */ (function () {
|
|
9
|
+
function KHR_materials_clearcoat(exporter) {
|
|
10
|
+
/** Name of this extension */
|
|
11
|
+
this.name = NAME;
|
|
12
|
+
/** Defines whether this extension is enabled */
|
|
13
|
+
this.enabled = true;
|
|
14
|
+
/** Defines whether this extension is required */
|
|
15
|
+
this.required = false;
|
|
16
|
+
this._wasUsed = false;
|
|
17
|
+
this._exporter = exporter;
|
|
18
|
+
}
|
|
19
|
+
KHR_materials_clearcoat.prototype.dispose = function () {
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(KHR_materials_clearcoat.prototype, "wasUsed", {
|
|
22
|
+
/** @hidden */
|
|
23
|
+
get: function () {
|
|
24
|
+
return this._wasUsed;
|
|
25
|
+
},
|
|
26
|
+
enumerable: false,
|
|
27
|
+
configurable: true
|
|
28
|
+
});
|
|
29
|
+
KHR_materials_clearcoat.prototype.postExportMaterialAdditionalTextures = function (context, node, babylonMaterial) {
|
|
30
|
+
var additionalTextures = [];
|
|
31
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
32
|
+
if (babylonMaterial.clearCoat.isEnabled) {
|
|
33
|
+
if (babylonMaterial.clearCoat.texture) {
|
|
34
|
+
additionalTextures.push(babylonMaterial.clearCoat.texture);
|
|
35
|
+
}
|
|
36
|
+
if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {
|
|
37
|
+
additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);
|
|
38
|
+
}
|
|
39
|
+
if (babylonMaterial.clearCoat.bumpTexture) {
|
|
40
|
+
additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);
|
|
41
|
+
}
|
|
42
|
+
return additionalTextures;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return [];
|
|
46
|
+
};
|
|
47
|
+
KHR_materials_clearcoat.prototype.postExportMaterialAsync = function (context, node, babylonMaterial) {
|
|
48
|
+
var _this = this;
|
|
49
|
+
return new Promise(function (resolve, reject) {
|
|
50
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
51
|
+
if (!babylonMaterial.clearCoat.isEnabled) {
|
|
52
|
+
resolve(node);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
_this._wasUsed = true;
|
|
56
|
+
node.extensions = node.extensions || {};
|
|
57
|
+
var clearCoatTextureInfo = _this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture);
|
|
58
|
+
var clearCoatTextureRoughnessInfo = void 0;
|
|
59
|
+
if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {
|
|
60
|
+
clearCoatTextureRoughnessInfo = _this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
clearCoatTextureRoughnessInfo = _this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.textureRoughness);
|
|
64
|
+
}
|
|
65
|
+
if (babylonMaterial.clearCoat.isTintEnabled) {
|
|
66
|
+
Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: " + babylonMaterial.name);
|
|
67
|
+
}
|
|
68
|
+
if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {
|
|
69
|
+
Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: " + babylonMaterial.name);
|
|
70
|
+
}
|
|
71
|
+
var clearCoatNormalTextureInfo = _this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.bumpTexture);
|
|
72
|
+
var clearCoatInfo_1 = {
|
|
73
|
+
clearcoatFactor: babylonMaterial.clearCoat.intensity,
|
|
74
|
+
clearcoatTexture: clearCoatTextureInfo !== null && clearCoatTextureInfo !== void 0 ? clearCoatTextureInfo : undefined,
|
|
75
|
+
clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,
|
|
76
|
+
clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo !== null && clearCoatTextureRoughnessInfo !== void 0 ? clearCoatTextureRoughnessInfo : undefined,
|
|
77
|
+
clearcoatNormalTexture: clearCoatNormalTextureInfo !== null && clearCoatNormalTextureInfo !== void 0 ? clearCoatNormalTextureInfo : undefined,
|
|
78
|
+
hasTextures: function () {
|
|
79
|
+
return clearCoatInfo_1.clearcoatTexture !== null || clearCoatInfo_1.clearcoatRoughnessTexture !== null || clearCoatInfo_1.clearcoatRoughnessTexture !== null;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
node.extensions[NAME] = clearCoatInfo_1;
|
|
83
|
+
}
|
|
84
|
+
resolve(node);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
return KHR_materials_clearcoat;
|
|
88
|
+
}());
|
|
89
|
+
export { KHR_materials_clearcoat };
|
|
90
|
+
_Exporter.RegisterExtension(NAME, function (exporter) { return new KHR_materials_clearcoat(exporter); });
|
|
91
|
+
//# sourceMappingURL=KHR_materials_clearcoat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_materials_clearcoat.js","sourceRoot":"","sources":["../../../../../sourceES6/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAGhF,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD,IAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;GAEG;AACH;IAcI,iCAAY,QAAmB;QAb/B,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1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E,0BAA0B,aAA1B,0BAA0B,cAA1B,0BAA0B,GAAI,SAAS;oBAC/D,WAAW,EAAE;wBACT,OAAO,eAAa,CAAC,gBAAgB,KAAK,IAAI,IAAI,eAAa,CAAC,yBAAyB,KAAK,IAAI,IAAI,eAAa,CAAC,yBAAyB,KAAK,IAAI,CAAC;oBAC3J,CAAC;iBACJ,CAAC;gBAEF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,eAAa,CAAC;aACzC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;IACL,8BAAC;AAAD,CAAC,AA5FD,IA4FC;;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,QAAQ,IAAK,OAAA,IAAI,uBAAuB,CAAC,QAAQ,CAAC,EAArC,CAAqC,CAAC,CAAC","sourcesContent":["import { IMaterial } from \"babylonjs-gltf2interface\";\r\nimport { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport { Material } from \"@babylonjs/core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"@babylonjs/core/Materials/PBR/pbrBaseMaterial\";\r\nimport { BaseTexture } from \"@babylonjs/core/Materials/Textures/baseTexture\";\r\nimport { IKHRMaterialsClearcoat } from \"babylonjs-gltf2interface\";\r\nimport { Tools } from \"@babylonjs/core/Misc/tools\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat\";\r\n\r\n/**\r\n * @hidden\r\n */\r\nexport class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {\r\n }\r\n\r\n /** @hidden */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.clearCoat.isEnabled) {\r\n if (babylonMaterial.clearCoat.texture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.texture);\r\n }\r\n if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {\r\n additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n if (babylonMaterial.clearCoat.bumpTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve, reject) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.clearCoat.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const clearCoatTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture);\r\n let clearCoatTextureRoughnessInfo;\r\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\r\n clearCoatTextureRoughnessInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.texture);\r\n } else {\r\n clearCoatTextureRoughnessInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.isTintEnabled) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {\r\n Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.clearCoat.intensity,\r\n clearcoatTexture: clearCoatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,\r\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n hasTextures: () => {\r\n return clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null;\r\n }\r\n };\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter));\r\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IMaterial } from "babylonjs-gltf2interface";
|
|
2
2
|
import { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
|
|
3
3
|
import { _Exporter } from "../glTFExporter";
|
|
4
|
-
import { Material } from
|
|
5
|
-
import {
|
|
6
|
-
import { BaseTexture } from '@babylonjs/core/Materials/Textures/baseTexture';
|
|
4
|
+
import { Material } from "@babylonjs/core/Materials/material";
|
|
5
|
+
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture";
|
|
7
6
|
/**
|
|
8
7
|
* @hidden
|
|
9
8
|
*/
|
|
@@ -14,16 +13,12 @@ export declare class KHR_materials_sheen implements IGLTFExporterExtensionV2 {
|
|
|
14
13
|
enabled: boolean;
|
|
15
14
|
/** Defines whether this extension is required */
|
|
16
15
|
required: boolean;
|
|
17
|
-
/** Reference to the glTF exporter */
|
|
18
|
-
private _textureInfos;
|
|
19
|
-
private _exportedTextures;
|
|
20
16
|
private _wasUsed;
|
|
17
|
+
private _exporter;
|
|
21
18
|
constructor(exporter: _Exporter);
|
|
22
19
|
dispose(): void;
|
|
23
20
|
/** @hidden */
|
|
24
21
|
get wasUsed(): boolean;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
|
|
28
|
-
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
22
|
+
postExportMaterialAdditionalTextures(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
|
|
23
|
+
postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
29
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _Exporter } from "../glTFExporter";
|
|
2
|
-
import { PBRMaterial } from
|
|
1
|
+
import { _Exporter } from "../glTFExporter.js";
|
|
2
|
+
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
|
3
3
|
var NAME = "KHR_materials_sheen";
|
|
4
4
|
/**
|
|
5
5
|
* @hidden
|
|
@@ -12,14 +12,10 @@ var KHR_materials_sheen = /** @class */ (function () {
|
|
|
12
12
|
this.enabled = true;
|
|
13
13
|
/** Defines whether this extension is required */
|
|
14
14
|
this.required = false;
|
|
15
|
-
/** Reference to the glTF exporter */
|
|
16
|
-
this._textureInfos = [];
|
|
17
|
-
this._exportedTextures = [];
|
|
18
15
|
this._wasUsed = false;
|
|
16
|
+
this._exporter = exporter;
|
|
19
17
|
}
|
|
20
18
|
KHR_materials_sheen.prototype.dispose = function () {
|
|
21
|
-
this._textureInfos = [];
|
|
22
|
-
this._exportedTextures = [];
|
|
23
19
|
};
|
|
24
20
|
Object.defineProperty(KHR_materials_sheen.prototype, "wasUsed", {
|
|
25
21
|
/** @hidden */
|
|
@@ -29,23 +25,9 @@ var KHR_materials_sheen = /** @class */ (function () {
|
|
|
29
25
|
enumerable: false,
|
|
30
26
|
configurable: true
|
|
31
27
|
});
|
|
32
|
-
KHR_materials_sheen.prototype._getTextureIndex = function (babylonTexture) {
|
|
33
|
-
var textureIndex = this._exportedTextures.indexOf(babylonTexture);
|
|
34
|
-
if (textureIndex === -1 && babylonTexture.reservedDataStore) {
|
|
35
|
-
textureIndex = this._exportedTextures.indexOf(babylonTexture.reservedDataStore.source);
|
|
36
|
-
}
|
|
37
|
-
return textureIndex;
|
|
38
|
-
};
|
|
39
|
-
KHR_materials_sheen.prototype.postExportTexture = function (context, textureInfo, babylonTexture) {
|
|
40
|
-
var textureIndex = this._getTextureIndex(babylonTexture);
|
|
41
|
-
if (textureIndex > -1) {
|
|
42
|
-
this._textureInfos[textureIndex] = textureInfo;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
28
|
KHR_materials_sheen.prototype.postExportMaterialAdditionalTextures = function (context, node, babylonMaterial) {
|
|
46
29
|
if (babylonMaterial instanceof PBRMaterial) {
|
|
47
30
|
if (babylonMaterial.sheen.isEnabled && babylonMaterial.sheen.texture) {
|
|
48
|
-
this._exportedTextures.push(babylonMaterial.sheen.texture);
|
|
49
31
|
return [babylonMaterial.sheen.texture];
|
|
50
32
|
}
|
|
51
33
|
}
|
|
@@ -54,7 +36,7 @@ var KHR_materials_sheen = /** @class */ (function () {
|
|
|
54
36
|
KHR_materials_sheen.prototype.postExportMaterialAsync = function (context, node, babylonMaterial) {
|
|
55
37
|
var _this = this;
|
|
56
38
|
return new Promise(function (resolve, reject) {
|
|
57
|
-
var _a;
|
|
39
|
+
var _a, _b, _c, _d;
|
|
58
40
|
if (babylonMaterial instanceof PBRMaterial) {
|
|
59
41
|
if (!babylonMaterial.sheen.isEnabled) {
|
|
60
42
|
resolve(node);
|
|
@@ -64,29 +46,23 @@ var KHR_materials_sheen = /** @class */ (function () {
|
|
|
64
46
|
if (node.extensions == null) {
|
|
65
47
|
node.extensions = {};
|
|
66
48
|
}
|
|
67
|
-
var
|
|
49
|
+
var sheenInfo_1 = {
|
|
68
50
|
sheenColorFactor: babylonMaterial.sheen.color.asArray(),
|
|
69
|
-
sheenRoughnessFactor: (_a = babylonMaterial.sheen.roughness) !== null && _a !== void 0 ? _a : 0
|
|
51
|
+
sheenRoughnessFactor: (_a = babylonMaterial.sheen.roughness) !== null && _a !== void 0 ? _a : 0,
|
|
52
|
+
hasTextures: function () {
|
|
53
|
+
return sheenInfo_1.sheenColorTexture !== null || sheenInfo_1.sheenRoughnessTexture !== null;
|
|
54
|
+
}
|
|
70
55
|
};
|
|
71
56
|
if (babylonMaterial.sheen.texture) {
|
|
72
|
-
|
|
73
|
-
if (textureIndex > -1) {
|
|
74
|
-
sheenInfo.sheenColorTexture = _this._textureInfos[textureIndex];
|
|
75
|
-
}
|
|
57
|
+
sheenInfo_1.sheenColorTexture = (_b = _this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.texture)) !== null && _b !== void 0 ? _b : undefined;
|
|
76
58
|
}
|
|
77
59
|
if (babylonMaterial.sheen.textureRoughness && !babylonMaterial.sheen.useRoughnessFromMainTexture) {
|
|
78
|
-
|
|
79
|
-
if (textureIndex > -1) {
|
|
80
|
-
sheenInfo.sheenRoughnessTexture = _this._textureInfos[textureIndex];
|
|
81
|
-
}
|
|
60
|
+
sheenInfo_1.sheenRoughnessTexture = (_c = _this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.textureRoughness)) !== null && _c !== void 0 ? _c : undefined;
|
|
82
61
|
}
|
|
83
62
|
else if (babylonMaterial.sheen.texture && babylonMaterial.sheen.useRoughnessFromMainTexture) {
|
|
84
|
-
|
|
85
|
-
if (textureIndex > -1) {
|
|
86
|
-
sheenInfo.sheenRoughnessTexture = _this._textureInfos[textureIndex];
|
|
87
|
-
}
|
|
63
|
+
sheenInfo_1.sheenRoughnessTexture = (_d = _this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.texture)) !== null && _d !== void 0 ? _d : undefined;
|
|
88
64
|
}
|
|
89
|
-
node.extensions[NAME] =
|
|
65
|
+
node.extensions[NAME] = sheenInfo_1;
|
|
90
66
|
}
|
|
91
67
|
resolve(node);
|
|
92
68
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_materials_sheen.js","sourceRoot":"","sources":["../../../../../sourceES6/serializers/src/glTF/2.0/Extensions/KHR_materials_sheen.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"KHR_materials_sheen.js","sourceRoot":"","sources":["../../../../../sourceES6/serializers/src/glTF/2.0/Extensions/KHR_materials_sheen.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAIxE,IAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH;IAcI,6BAAY,QAAmB;QAb/B,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAEhB,aAAQ,GAAG,KAAK,CAAC;QAKrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAEM,qCAAO,GAAd;IACA,CAAC;IAGD,sBAAW,wCAAO;QADlB,cAAc;aACd;YACI,OAAO,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;;;OAAA;IAEM,kEAAoC,GAA3C,UAA4C,OAAe,EAAE,IAAe,EAAE,eAAyB;QACnG,IAAI,eAAe,YAAY,WAAW,EAAE;YACxC,IAAI,eAAe,CAAC,KAAK,CAAC,SAAS,IAAI,eAAe,CAAC,KAAK,CAAC,OAAO,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AAe,CAAC,KAAK,CAAC,gBAAgB,CAAC,mCAAI,SAAS,CAAC;iBAC/I;qBAAM,IAAI,eAAe,CAAC,KAAK,CAAC,OAAO,IAAI,eAAe,CAAC,KAAK,CAAC,2BAA2B,EAAE;oBAC3F,WAAS,CAAC,qBAAqB,GAAG,MAAA,KAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,eAAe,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,mCAAI,SAAS,CAAC;iBACtI;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,WAAS,CAAC;aACrC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;IACL,0BAAC;AAAD,CAAC,AAxED,IAwEC;;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,QAAQ,IAAK,OAAA,IAAI,mBAAmB,CAAC,QAAQ,CAAC,EAAjC,CAAiC,CAAC,CAAC","sourcesContent":["import { IMaterial } from \"babylonjs-gltf2interface\";\r\nimport { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport { Material } from \"@babylonjs/core/Materials/material\";\r\nimport { PBRMaterial } from \"@babylonjs/core/Materials/PBR/pbrMaterial\";\r\nimport { BaseTexture } from \"@babylonjs/core/Materials/Textures/baseTexture\";\r\nimport { IKHRMaterialsSheen } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_materials_sheen\";\r\n\r\n/**\r\n * @hidden\r\n */\r\nexport class KHR_materials_sheen implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _wasUsed = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {\r\n }\r\n\r\n /** @hidden */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (babylonMaterial.sheen.isEnabled && babylonMaterial.sheen.texture) {\r\n return [babylonMaterial.sheen.texture];\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve, reject) => {\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (!babylonMaterial.sheen.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n const sheenInfo: IKHRMaterialsSheen = {\r\n sheenColorFactor: babylonMaterial.sheen.color.asArray(),\r\n sheenRoughnessFactor: babylonMaterial.sheen.roughness ?? 0,\r\n hasTextures: () => {\r\n return sheenInfo.sheenColorTexture !== null || sheenInfo.sheenRoughnessTexture !== null;\r\n }\r\n };\r\n\r\n if (babylonMaterial.sheen.texture) {\r\n sheenInfo.sheenColorTexture = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.texture) ?? undefined;\r\n }\r\n\r\n if (babylonMaterial.sheen.textureRoughness && !babylonMaterial.sheen.useRoughnessFromMainTexture) {\r\n sheenInfo.sheenRoughnessTexture = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.textureRoughness) ?? undefined;\r\n } else if (babylonMaterial.sheen.texture && babylonMaterial.sheen.useRoughnessFromMainTexture) {\r\n sheenInfo.sheenRoughnessTexture = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.sheen.texture) ?? undefined;\r\n }\r\n\r\n node.extensions[NAME] = sheenInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_sheen(exporter));"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _Exporter } from "../glTFExporter";
|
|
2
|
-
import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';
|
|
3
|
-
import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
|
|
1
|
+
import { _Exporter } from "../glTFExporter.js";
|
|
2
|
+
import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial.js';
|
|
3
|
+
import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial.js';
|
|
4
4
|
var NAME = "KHR_materials_unlit";
|
|
5
5
|
/**
|
|
6
6
|
* @hidden
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Tools } from "@babylonjs/core/Misc/tools";
|
|
2
|
-
import { ProceduralTexture } from "@babylonjs/core/Materials/Textures/Procedurals/proceduralTexture";
|
|
3
|
-
import { _Exporter } from "../glTFExporter";
|
|
1
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
2
|
+
import { ProceduralTexture } from "@babylonjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
|
|
3
|
+
import { _Exporter } from "../glTFExporter.js";
|
|
4
4
|
var NAME = "KHR_texture_transform";
|
|
5
|
-
import "../shaders/textureTransform.fragment";
|
|
5
|
+
import "../shaders/textureTransform.fragment.js";
|
|
6
6
|
/**
|
|
7
7
|
* @hidden
|
|
8
8
|
*/
|