@babylonjs/serializers 5.0.0-beta.8 → 5.0.0-beta.8-snapshot
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/package.json +20 -105
- package/OBJ/index.d.ts +0 -1
- package/OBJ/index.js +0 -2
- package/OBJ/index.js.map +0 -1
- package/OBJ/objSerializer.d.ts +0 -21
- package/OBJ/objSerializer.js +0 -160
- package/OBJ/objSerializer.js.map +0 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +0 -38
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +0 -174
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +0 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +0 -24
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +0 -91
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +0 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +0 -24
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +0 -74
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +0 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +0 -21
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +0 -52
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +0 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +0 -34
- package/glTF/2.0/Extensions/KHR_texture_transform.js +0 -137
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +0 -1
- package/glTF/2.0/Extensions/index.d.ts +0 -5
- package/glTF/2.0/Extensions/index.js +0 -6
- package/glTF/2.0/Extensions/index.js.map +0 -1
- package/glTF/2.0/glTFAnimation.d.ts +0 -200
- package/glTF/2.0/glTFAnimation.js +0 -840
- package/glTF/2.0/glTFAnimation.js.map +0 -1
- package/glTF/2.0/glTFData.d.ts +0 -19
- package/glTF/2.0/glTFData.js +0 -53
- package/glTF/2.0/glTFData.js.map +0 -1
- package/glTF/2.0/glTFExporter.d.ts +0 -445
- package/glTF/2.0/glTFExporter.js +0 -1943
- package/glTF/2.0/glTFExporter.js.map +0 -1
- package/glTF/2.0/glTFExporterExtension.d.ts +0 -74
- package/glTF/2.0/glTFExporterExtension.js +0 -3
- package/glTF/2.0/glTFExporterExtension.js.map +0 -1
- package/glTF/2.0/glTFMaterialExporter.d.ts +0 -230
- package/glTF/2.0/glTFMaterialExporter.js +0 -1143
- package/glTF/2.0/glTFMaterialExporter.js.map +0 -1
- package/glTF/2.0/glTFSerializer.d.ts +0 -60
- package/glTF/2.0/glTFSerializer.js +0 -63
- package/glTF/2.0/glTFSerializer.js.map +0 -1
- package/glTF/2.0/glTFUtilities.d.ts +0 -96
- package/glTF/2.0/glTFUtilities.js +0 -196
- package/glTF/2.0/glTFUtilities.js.map +0 -1
- package/glTF/2.0/index.d.ts +0 -8
- package/glTF/2.0/index.js +0 -9
- package/glTF/2.0/index.js.map +0 -1
- package/glTF/2.0/shaders/textureTransform.fragment.d.ts +0 -5
- package/glTF/2.0/shaders/textureTransform.fragment.js +0 -7
- package/glTF/2.0/shaders/textureTransform.fragment.js.map +0 -1
- package/glTF/glTFFileExporter.d.ts +0 -20
- package/glTF/glTFFileExporter.js +0 -3
- package/glTF/glTFFileExporter.js.map +0 -1
- package/glTF/index.d.ts +0 -2
- package/glTF/index.js +0 -3
- package/glTF/index.js.map +0 -1
- package/index.d.ts +0 -3
- package/index.js.map +0 -1
- package/legacy/legacy-glTF2Serializer.d.ts +0 -2
- package/legacy/legacy-glTF2Serializer.js +0 -44
- package/legacy/legacy-glTF2Serializer.js.map +0 -1
- package/legacy/legacy-objSerializer.d.ts +0 -1
- package/legacy/legacy-objSerializer.js +0 -13
- package/legacy/legacy-objSerializer.js.map +0 -1
- package/legacy/legacy-stlSerializer.d.ts +0 -1
- package/legacy/legacy-stlSerializer.js +0 -13
- package/legacy/legacy-stlSerializer.js.map +0 -1
- package/legacy/legacy.d.ts +0 -4
- package/legacy/legacy.js +0 -5
- package/legacy/legacy.js.map +0 -1
- package/readme.md +0 -29
- package/stl/index.d.ts +0 -1
- package/stl/index.js +0 -2
- package/stl/index.js.map +0 -1
- package/stl/stlSerializer.d.ts +0 -17
- package/stl/stlSerializer.js +0 -108
- package/stl/stlSerializer.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,114 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
"author": {
|
|
3
|
-
"name": "David CATUHE"
|
|
4
|
-
},
|
|
5
2
|
"name": "@babylonjs/serializers",
|
|
6
|
-
"
|
|
7
|
-
"version": "5.0.0-beta.8",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "https://github.com/BabylonJS/Babylon.js.git"
|
|
11
|
-
},
|
|
3
|
+
"version": "5.0.0-beta.8-snapshot",
|
|
12
4
|
"main": "index.js",
|
|
5
|
+
"module": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
13
7
|
"files": [
|
|
14
|
-
"
|
|
15
|
-
"glTF/2.0/Extensions/index.js",
|
|
16
|
-
"glTF/2.0/Extensions/index.js.map",
|
|
17
|
-
"glTF/2.0/Extensions/KHR_lights_punctual.d.ts",
|
|
18
|
-
"glTF/2.0/Extensions/KHR_lights_punctual.js",
|
|
19
|
-
"glTF/2.0/Extensions/KHR_lights_punctual.js.map",
|
|
20
|
-
"glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts",
|
|
21
|
-
"glTF/2.0/Extensions/KHR_materials_clearcoat.js",
|
|
22
|
-
"glTF/2.0/Extensions/KHR_materials_clearcoat.js.map",
|
|
23
|
-
"glTF/2.0/Extensions/KHR_materials_sheen.d.ts",
|
|
24
|
-
"glTF/2.0/Extensions/KHR_materials_sheen.js",
|
|
25
|
-
"glTF/2.0/Extensions/KHR_materials_sheen.js.map",
|
|
26
|
-
"glTF/2.0/Extensions/KHR_materials_unlit.d.ts",
|
|
27
|
-
"glTF/2.0/Extensions/KHR_materials_unlit.js",
|
|
28
|
-
"glTF/2.0/Extensions/KHR_materials_unlit.js.map",
|
|
29
|
-
"glTF/2.0/Extensions/KHR_texture_transform.d.ts",
|
|
30
|
-
"glTF/2.0/Extensions/KHR_texture_transform.js",
|
|
31
|
-
"glTF/2.0/Extensions/KHR_texture_transform.js.map",
|
|
32
|
-
"glTF/2.0/glTFAnimation.d.ts",
|
|
33
|
-
"glTF/2.0/glTFAnimation.js",
|
|
34
|
-
"glTF/2.0/glTFAnimation.js.map",
|
|
35
|
-
"glTF/2.0/glTFData.d.ts",
|
|
36
|
-
"glTF/2.0/glTFData.js",
|
|
37
|
-
"glTF/2.0/glTFData.js.map",
|
|
38
|
-
"glTF/2.0/glTFExporter.d.ts",
|
|
39
|
-
"glTF/2.0/glTFExporter.js",
|
|
40
|
-
"glTF/2.0/glTFExporter.js.map",
|
|
41
|
-
"glTF/2.0/glTFExporterExtension.d.ts",
|
|
42
|
-
"glTF/2.0/glTFExporterExtension.js",
|
|
43
|
-
"glTF/2.0/glTFExporterExtension.js.map",
|
|
44
|
-
"glTF/2.0/glTFMaterialExporter.d.ts",
|
|
45
|
-
"glTF/2.0/glTFMaterialExporter.js",
|
|
46
|
-
"glTF/2.0/glTFMaterialExporter.js.map",
|
|
47
|
-
"glTF/2.0/glTFSerializer.d.ts",
|
|
48
|
-
"glTF/2.0/glTFSerializer.js",
|
|
49
|
-
"glTF/2.0/glTFSerializer.js.map",
|
|
50
|
-
"glTF/2.0/glTFUtilities.d.ts",
|
|
51
|
-
"glTF/2.0/glTFUtilities.js",
|
|
52
|
-
"glTF/2.0/glTFUtilities.js.map",
|
|
53
|
-
"glTF/2.0/index.d.ts",
|
|
54
|
-
"glTF/2.0/index.js",
|
|
55
|
-
"glTF/2.0/index.js.map",
|
|
56
|
-
"glTF/2.0/shaders/textureTransform.fragment.d.ts",
|
|
57
|
-
"glTF/2.0/shaders/textureTransform.fragment.js",
|
|
58
|
-
"glTF/2.0/shaders/textureTransform.fragment.js.map",
|
|
59
|
-
"glTF/glTFFileExporter.d.ts",
|
|
60
|
-
"glTF/glTFFileExporter.js",
|
|
61
|
-
"glTF/glTFFileExporter.js.map",
|
|
62
|
-
"glTF/index.d.ts",
|
|
63
|
-
"glTF/index.js",
|
|
64
|
-
"glTF/index.js.map",
|
|
65
|
-
"index.d.ts",
|
|
66
|
-
"index.js",
|
|
67
|
-
"index.js.map",
|
|
68
|
-
"legacy/legacy-glTF2Serializer.d.ts",
|
|
69
|
-
"legacy/legacy-glTF2Serializer.js",
|
|
70
|
-
"legacy/legacy-glTF2Serializer.js.map",
|
|
71
|
-
"legacy/legacy-objSerializer.d.ts",
|
|
72
|
-
"legacy/legacy-objSerializer.js",
|
|
73
|
-
"legacy/legacy-objSerializer.js.map",
|
|
74
|
-
"legacy/legacy-stlSerializer.d.ts",
|
|
75
|
-
"legacy/legacy-stlSerializer.js",
|
|
76
|
-
"legacy/legacy-stlSerializer.js.map",
|
|
77
|
-
"legacy/legacy.d.ts",
|
|
78
|
-
"legacy/legacy.js",
|
|
79
|
-
"legacy/legacy.js.map",
|
|
80
|
-
"OBJ/index.d.ts",
|
|
81
|
-
"OBJ/index.js",
|
|
82
|
-
"OBJ/index.js.map",
|
|
83
|
-
"OBJ/objSerializer.d.ts",
|
|
84
|
-
"OBJ/objSerializer.js",
|
|
85
|
-
"OBJ/objSerializer.js.map",
|
|
86
|
-
"readme.md",
|
|
87
|
-
"stl/index.d.ts",
|
|
88
|
-
"stl/index.js",
|
|
89
|
-
"stl/index.js.map",
|
|
90
|
-
"stl/stlSerializer.d.ts",
|
|
91
|
-
"stl/stlSerializer.js",
|
|
92
|
-
"stl/stlSerializer.js.map"
|
|
8
|
+
"./"
|
|
93
9
|
],
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
|
|
101
|
-
],
|
|
102
|
-
"license": "Apache-2.0",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "npm run clean && npm run compile",
|
|
12
|
+
"clean": "rimraf dist && rimraf *.tsbuildinfo && rimraf \"./**/*.!(json|build.json)\"",
|
|
13
|
+
"compile": "tsc -b tsconfig.build.json",
|
|
14
|
+
"postcompile": "build-tools -c add-js-to-es6 --path ./dist/**/*.js",
|
|
15
|
+
"prepublishOnly": "build-tools -c prepare-es6-build"
|
|
16
|
+
},
|
|
103
17
|
"dependencies": {
|
|
104
|
-
"@babylonjs/core": "5.0.0-beta.8",
|
|
105
|
-
"babylonjs-gltf2interface": "5.0.0-beta.8",
|
|
18
|
+
"@babylonjs/core": "^5.0.0-beta.8-snapshot",
|
|
19
|
+
"babylonjs-gltf2interface": "^5.0.0-beta.8-snapshot",
|
|
106
20
|
"tslib": "^2.3.1"
|
|
107
21
|
},
|
|
108
|
-
"
|
|
109
|
-
"
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@dev/build-tools": "^5.0.0-beta.8-snapshot",
|
|
24
|
+
"@lts/serializers": "^5.0.0-beta.8-snapshot",
|
|
25
|
+
"rimraf": "^3.0.2",
|
|
26
|
+
"typescript": "^4.4.4"
|
|
110
27
|
},
|
|
111
|
-
"
|
|
112
|
-
|
|
113
|
-
"type": "module"
|
|
114
|
-
}
|
|
28
|
+
"sideEffects": true
|
|
29
|
+
}
|
package/OBJ/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./objSerializer";
|
package/OBJ/index.js
DELETED
package/OBJ/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../sourceES6/serializers/src/OBJ/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./objSerializer\";"]}
|
package/OBJ/objSerializer.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Mesh } from "@babylonjs/core/Meshes/mesh";
|
|
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
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
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 (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 (i = 0; i < trunkUV.length; i += 2) {
|
|
80
|
-
output.push("vt " + trunkUV[i] + " " + trunkUV[i + 1]);
|
|
81
|
-
currentTextureV++;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
for (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 " + facePositions[0] + "/" + faceUVs[0] + "/" + faceNormals[0] +
|
|
92
|
-
" " + facePositions[1] + "/" + faceUVs[1] + "/" + faceNormals[1] +
|
|
93
|
-
" " + facePositions[2] + "/" + faceUVs[2] + "/" + faceNormals[2]);
|
|
94
|
-
}
|
|
95
|
-
//back de previous matrix, to not change the original mesh in the scene
|
|
96
|
-
if (globalposition && inverseTransform) {
|
|
97
|
-
mesh[j].bakeTransformIntoVertices(inverseTransform);
|
|
98
|
-
}
|
|
99
|
-
v += currentV;
|
|
100
|
-
textureV += currentTextureV;
|
|
101
|
-
}
|
|
102
|
-
var text = output.join("\n");
|
|
103
|
-
return (text);
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Exports the material(s) of a mesh in .MTL file format (text)
|
|
107
|
-
* @param mesh defines the mesh to extract the material from
|
|
108
|
-
* @returns the mtl content
|
|
109
|
-
*/
|
|
110
|
-
//TODO: Export the materials of mesh array
|
|
111
|
-
OBJExport.MTL = function (mesh) {
|
|
112
|
-
var output = [];
|
|
113
|
-
var m = mesh.material;
|
|
114
|
-
output.push("newmtl mat1");
|
|
115
|
-
output.push(" Ns " + m.specularPower.toFixed(4));
|
|
116
|
-
output.push(" Ni 1.5000");
|
|
117
|
-
output.push(" d " + m.alpha.toFixed(4));
|
|
118
|
-
output.push(" Tr 0.0000");
|
|
119
|
-
output.push(" Tf 1.0000 1.0000 1.0000");
|
|
120
|
-
output.push(" illum 2");
|
|
121
|
-
output.push(" Ka " + m.ambientColor.r.toFixed(4) + " " + m.ambientColor.g.toFixed(4) + " " + m.ambientColor.b.toFixed(4));
|
|
122
|
-
output.push(" Kd " + m.diffuseColor.r.toFixed(4) + " " + m.diffuseColor.g.toFixed(4) + " " + m.diffuseColor.b.toFixed(4));
|
|
123
|
-
output.push(" Ks " + m.specularColor.r.toFixed(4) + " " + m.specularColor.g.toFixed(4) + " " + m.specularColor.b.toFixed(4));
|
|
124
|
-
output.push(" Ke " + m.emissiveColor.r.toFixed(4) + " " + m.emissiveColor.g.toFixed(4) + " " + m.emissiveColor.b.toFixed(4));
|
|
125
|
-
//TODO: uv scale, offset, wrap
|
|
126
|
-
//TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures?
|
|
127
|
-
var uvscale = "";
|
|
128
|
-
if (m.ambientTexture) {
|
|
129
|
-
output.push(" map_Ka " + uvscale + m.ambientTexture.name);
|
|
130
|
-
}
|
|
131
|
-
if (m.diffuseTexture) {
|
|
132
|
-
output.push(" map_Kd " + uvscale + m.diffuseTexture.name);
|
|
133
|
-
//TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d)
|
|
134
|
-
}
|
|
135
|
-
if (m.specularTexture) {
|
|
136
|
-
output.push(" map_Ks " + uvscale + m.specularTexture.name);
|
|
137
|
-
/* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???)
|
|
138
|
-
if (m.useGlossinessFromSpecularMapAlpha) {
|
|
139
|
-
output.push(" map_Ns "+uvscale + m.specularTexture.name);
|
|
140
|
-
}
|
|
141
|
-
*/
|
|
142
|
-
}
|
|
143
|
-
/* TODO: emissive texture not in .MAT format (???)
|
|
144
|
-
if (m.emissiveTexture) {
|
|
145
|
-
output.push(" map_d "+uvscale+m.emissiveTexture.name);
|
|
146
|
-
}
|
|
147
|
-
*/
|
|
148
|
-
if (m.bumpTexture) {
|
|
149
|
-
output.push(" map_bump -imfchan z " + uvscale + m.bumpTexture.name);
|
|
150
|
-
}
|
|
151
|
-
if (m.opacityTexture) {
|
|
152
|
-
output.push(" map_d " + uvscale + m.opacityTexture.name);
|
|
153
|
-
}
|
|
154
|
-
var text = output.join("\n");
|
|
155
|
-
return (text);
|
|
156
|
-
};
|
|
157
|
-
return OBJExport;
|
|
158
|
-
}());
|
|
159
|
-
export { OBJExport };
|
|
160
|
-
//# sourceMappingURL=objSerializer.js.map
|
package/OBJ/objSerializer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;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AAa,CAAC,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,IAAI,OAAO,GAAG,EAAE,CAAC;QAEjB,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,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,38 +0,0 @@
|
|
|
1
|
-
import { Nullable } from "@babylonjs/core/types";
|
|
2
|
-
import { Node } from "@babylonjs/core/node";
|
|
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
|
-
/** @hidden */
|
|
20
|
-
constructor(exporter: _Exporter);
|
|
21
|
-
/** @hidden */
|
|
22
|
-
dispose(): void;
|
|
23
|
-
/** @hidden */
|
|
24
|
-
get wasUsed(): boolean;
|
|
25
|
-
/** @hidden */
|
|
26
|
-
onExporting(): void;
|
|
27
|
-
/**
|
|
28
|
-
* Define this method to modify the default behavior when exporting a node
|
|
29
|
-
* @param context The context when exporting the node
|
|
30
|
-
* @param node glTF node
|
|
31
|
-
* @param babylonNode BabylonJS node
|
|
32
|
-
* @param nodeMap Node mapping of unique id to glTF node index
|
|
33
|
-
* @returns nullable INode promise
|
|
34
|
-
*/
|
|
35
|
-
postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
|
|
36
|
-
[key: number]: number;
|
|
37
|
-
}): Promise<Nullable<INode>>;
|
|
38
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
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
|
-
var NAME = "KHR_lights_punctual";
|
|
10
|
-
/**
|
|
11
|
-
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
|
|
12
|
-
*/
|
|
13
|
-
var KHR_lights_punctual = /** @class */ (function () {
|
|
14
|
-
/** @hidden */
|
|
15
|
-
function KHR_lights_punctual(exporter) {
|
|
16
|
-
/** The name of this extension. */
|
|
17
|
-
this.name = NAME;
|
|
18
|
-
/** Defines whether this extension is enabled. */
|
|
19
|
-
this.enabled = true;
|
|
20
|
-
/** Defines whether this extension is required */
|
|
21
|
-
this.required = false;
|
|
22
|
-
this._exporter = exporter;
|
|
23
|
-
}
|
|
24
|
-
/** @hidden */
|
|
25
|
-
KHR_lights_punctual.prototype.dispose = function () {
|
|
26
|
-
this._lights = null;
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(KHR_lights_punctual.prototype, "wasUsed", {
|
|
29
|
-
/** @hidden */
|
|
30
|
-
get: function () {
|
|
31
|
-
return !!this._lights;
|
|
32
|
-
},
|
|
33
|
-
enumerable: false,
|
|
34
|
-
configurable: true
|
|
35
|
-
});
|
|
36
|
-
/** @hidden */
|
|
37
|
-
KHR_lights_punctual.prototype.onExporting = function () {
|
|
38
|
-
this._exporter._glTF.extensions[NAME] = this._lights;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Define this method to modify the default behavior when exporting a node
|
|
42
|
-
* @param context The context when exporting the node
|
|
43
|
-
* @param node glTF node
|
|
44
|
-
* @param babylonNode BabylonJS node
|
|
45
|
-
* @param nodeMap Node mapping of unique id to glTF node index
|
|
46
|
-
* @returns nullable INode promise
|
|
47
|
-
*/
|
|
48
|
-
KHR_lights_punctual.prototype.postExportNodeAsync = function (context, node, babylonNode, nodeMap) {
|
|
49
|
-
var _this = this;
|
|
50
|
-
return new Promise(function (resolve, reject) {
|
|
51
|
-
if (node && babylonNode instanceof ShadowLight) {
|
|
52
|
-
var babylonLight = babylonNode;
|
|
53
|
-
var light = void 0;
|
|
54
|
-
var lightType = (babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT ? "point" /* POINT */ : (babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT ? "directional" /* DIRECTIONAL */ : (babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT ? "spot" /* SPOT */ : null)));
|
|
55
|
-
if (lightType == null) {
|
|
56
|
-
Logger.Warn("".concat(context, ": Light ").concat(babylonLight.name, " is not supported in ").concat(NAME));
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
var lightPosition = babylonLight.position.clone();
|
|
60
|
-
var convertToRightHandedSystem = _this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];
|
|
61
|
-
if (!lightPosition.equals(Vector3.Zero())) {
|
|
62
|
-
if (convertToRightHandedSystem) {
|
|
63
|
-
_GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);
|
|
64
|
-
}
|
|
65
|
-
node.translation = lightPosition.asArray();
|
|
66
|
-
}
|
|
67
|
-
if (lightType !== "point" /* POINT */) {
|
|
68
|
-
var localAxis = babylonLight.direction;
|
|
69
|
-
var yaw = -Math.atan2(localAxis.z * (_this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;
|
|
70
|
-
var len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
|
|
71
|
-
var pitch = -Math.atan2(localAxis.y, len);
|
|
72
|
-
var lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);
|
|
73
|
-
if (convertToRightHandedSystem) {
|
|
74
|
-
_GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);
|
|
75
|
-
}
|
|
76
|
-
if (!lightRotationQuaternion.equals(Quaternion.Identity())) {
|
|
77
|
-
node.rotation = lightRotationQuaternion.asArray();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (babylonLight.falloffType !== Light.FALLOFF_GLTF) {
|
|
81
|
-
Logger.Warn("".concat(context, ": Light falloff for ").concat(babylonLight.name, " does not match the ").concat(NAME, " specification!"));
|
|
82
|
-
}
|
|
83
|
-
light = {
|
|
84
|
-
type: lightType
|
|
85
|
-
};
|
|
86
|
-
if (!babylonLight.diffuse.equals(Color3.White())) {
|
|
87
|
-
light.color = babylonLight.diffuse.asArray();
|
|
88
|
-
}
|
|
89
|
-
if (babylonLight.intensity !== 1.0) {
|
|
90
|
-
light.intensity = babylonLight.intensity;
|
|
91
|
-
}
|
|
92
|
-
if (babylonLight.range !== Number.MAX_VALUE) {
|
|
93
|
-
light.range = babylonLight.range;
|
|
94
|
-
}
|
|
95
|
-
if (lightType === "spot" /* SPOT */) {
|
|
96
|
-
var babylonSpotLight = babylonLight;
|
|
97
|
-
if (babylonSpotLight.angle !== Math.PI / 2.0) {
|
|
98
|
-
if (light.spot == null) {
|
|
99
|
-
light.spot = {};
|
|
100
|
-
}
|
|
101
|
-
light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;
|
|
102
|
-
}
|
|
103
|
-
if (babylonSpotLight.innerAngle !== 0) {
|
|
104
|
-
if (light.spot == null) {
|
|
105
|
-
light.spot = {};
|
|
106
|
-
}
|
|
107
|
-
light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (_this._lights == null) {
|
|
111
|
-
_this._lights = {
|
|
112
|
-
lights: []
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
_this._lights.lights.push(light);
|
|
116
|
-
var lightReference = {
|
|
117
|
-
light: _this._lights.lights.length - 1
|
|
118
|
-
};
|
|
119
|
-
// Avoid duplicating the Light's parent node if possible.
|
|
120
|
-
var parentBabylonNode = babylonNode.parent;
|
|
121
|
-
if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {
|
|
122
|
-
var parentNode = _this._exporter._nodes[nodeMap[parentBabylonNode.uniqueId]];
|
|
123
|
-
if (parentNode) {
|
|
124
|
-
var parentNodeLocalMatrix = TmpVectors.Matrix[0];
|
|
125
|
-
var parentInvertNodeLocalMatrix = TmpVectors.Matrix[1];
|
|
126
|
-
var parentNodeLocalTranslation = parentNode.translation ? new Vector3(parentNode.translation[0], parentNode.translation[1], parentNode.translation[2]) : Vector3.Zero();
|
|
127
|
-
var parentNodeLocalRotation = parentNode.rotation ? new Quaternion(parentNode.rotation[0], parentNode.rotation[1], parentNode.rotation[2], parentNode.rotation[3]) : Quaternion.Identity();
|
|
128
|
-
var parentNodeLocalScale = parentNode.scale ? new Vector3(parentNode.scale[0], parentNode.scale[1], parentNode.scale[2]) : Vector3.One();
|
|
129
|
-
Matrix.ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);
|
|
130
|
-
parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);
|
|
131
|
-
// Convert light local matrix to local matrix relative to grandparent, facing -Z
|
|
132
|
-
var lightLocalMatrix = TmpVectors.Matrix[2];
|
|
133
|
-
var nodeLocalTranslation = node.translation ? new Vector3(node.translation[0], node.translation[1], node.translation[2]) : Vector3.Zero();
|
|
134
|
-
// Undo directional light positional offset
|
|
135
|
-
if (babylonLight instanceof DirectionalLight) {
|
|
136
|
-
nodeLocalTranslation.subtractInPlace(_this._exporter._babylonScene.useRightHandedSystem ? babylonLight.direction : _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction));
|
|
137
|
-
}
|
|
138
|
-
var nodeLocalRotation = _this._exporter._babylonScene.useRightHandedSystem ? Quaternion.Identity() : new Quaternion(0, 1, 0, 0);
|
|
139
|
-
if (node.rotation) {
|
|
140
|
-
nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));
|
|
141
|
-
}
|
|
142
|
-
var nodeLocalScale = node.scale ? new Vector3(node.scale[0], node.scale[1], node.scale[2]) : Vector3.One();
|
|
143
|
-
Matrix.ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);
|
|
144
|
-
lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);
|
|
145
|
-
var parentNewScale = TmpVectors.Vector3[0];
|
|
146
|
-
var parentNewRotationQuaternion = TmpVectors.Quaternion[0];
|
|
147
|
-
var parentNewTranslation = TmpVectors.Vector3[1];
|
|
148
|
-
lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);
|
|
149
|
-
parentNode.scale = parentNewScale.asArray();
|
|
150
|
-
parentNode.rotation = parentNewRotationQuaternion.asArray();
|
|
151
|
-
parentNode.translation = parentNewTranslation.asArray();
|
|
152
|
-
if (parentNode.extensions == null) {
|
|
153
|
-
parentNode.extensions = {};
|
|
154
|
-
}
|
|
155
|
-
parentNode.extensions[NAME] = lightReference;
|
|
156
|
-
// Do not export the original node
|
|
157
|
-
resolve(null);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (node.extensions == null) {
|
|
162
|
-
node.extensions = {};
|
|
163
|
-
}
|
|
164
|
-
node.extensions[NAME] = lightReference;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
resolve(node);
|
|
168
|
-
});
|
|
169
|
-
};
|
|
170
|
-
return KHR_lights_punctual;
|
|
171
|
-
}());
|
|
172
|
-
export { KHR_lights_punctual };
|
|
173
|
-
_Exporter.RegisterExtension(NAME, function (exporter) { return new KHR_lights_punctual(exporter); });
|
|
174
|
-
//# sourceMappingURL=KHR_lights_punctual.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,CAA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AAC,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));"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
}
|