@babylonjs/loaders 5.0.0-rc.7 → 5.0.0-rc.9
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/index.d.ts +4 -4
- package/OBJ/index.js +4 -4
- package/OBJ/mtlFileLoader.d.ts +41 -41
- package/OBJ/mtlFileLoader.js +232 -232
- package/OBJ/objFileLoader.d.ts +126 -126
- package/OBJ/objFileLoader.js +296 -296
- package/OBJ/objLoadingOptions.d.ts +43 -43
- package/OBJ/objLoadingOptions.js +1 -1
- package/OBJ/solidParser.d.ts +154 -154
- package/OBJ/solidParser.js +693 -693
- package/STL/index.d.ts +1 -1
- package/STL/index.js +1 -1
- package/STL/stlFileLoader.d.ts +64 -64
- package/STL/stlFileLoader.js +233 -233
- package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
- package/glTF/1.0/glTFBinaryExtension.js +60 -60
- package/glTF/1.0/glTFLoader.d.ts +136 -136
- package/glTF/1.0/glTFLoader.js +1815 -1815
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
- package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
- package/glTF/1.0/glTFLoaderUtils.d.ts +62 -62
- package/glTF/1.0/glTFLoaderUtils.js +250 -250
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
- package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -129
- package/glTF/1.0/index.d.ts +5 -5
- package/glTF/1.0/index.js +5 -5
- package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -43
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -117
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -36
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -88
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -34
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -49
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -29
- package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -40
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -50
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -73
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -112
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -36
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -89
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -94
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -53
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -42
- package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -62
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -80
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -84
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -74
- package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -83
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -288
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -73
- package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -87
- package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -254
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -85
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -22
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -23
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -29
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -40
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -33
- package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -61
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -32
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -49
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -54
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -240
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -109
- package/glTF/2.0/Extensions/MSFT_lod.js +369 -369
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
- package/glTF/2.0/Extensions/index.d.ts +26 -26
- package/glTF/2.0/Extensions/index.js +26 -26
- package/glTF/2.0/glTFLoader.d.ts +405 -405
- package/glTF/2.0/glTFLoader.js +2366 -2366
- package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
- package/glTF/2.0/glTFLoaderExtension.js +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -211
- package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
- package/glTF/2.0/index.d.ts +4 -4
- package/glTF/2.0/index.js +4 -4
- package/glTF/glTFFileLoader.d.ts +433 -433
- package/glTF/glTFFileLoader.js +927 -927
- package/glTF/glTFValidation.d.ts +29 -29
- package/glTF/glTFValidation.js +123 -123
- package/glTF/index.d.ts +5 -5
- package/glTF/index.js +5 -5
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/legacy/legacy-glTF.d.ts +2 -2
- package/legacy/legacy-glTF.js +18 -18
- package/legacy/legacy-glTF1.d.ts +2 -2
- package/legacy/legacy-glTF1.js +14 -14
- package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF1FileLoader.js +3 -3
- package/legacy/legacy-glTF2.d.ts +2 -2
- package/legacy/legacy-glTF2.js +32 -32
- package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF2FileLoader.js +3 -3
- package/legacy/legacy-glTFFileLoader.d.ts +3 -3
- package/legacy/legacy-glTFFileLoader.js +4 -4
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +12 -12
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +12 -12
- package/legacy/legacy.d.ts +6 -6
- package/legacy/legacy.js +7 -7
- package/package.json +3 -3
package/STL/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from "./stlFileLoader";
|
1
|
+
export * from "./stlFileLoader";
|
package/STL/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from "./stlFileLoader
|
1
|
+
export * from "./stlFileLoader";
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/STL/stlFileLoader.d.ts
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
import { Nullable } from "@babylonjs/core/types.js";
|
2
|
-
import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh.js";
|
3
|
-
import { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from "@babylonjs/core/Loading/sceneLoader.js";
|
4
|
-
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
5
|
-
import { Scene } from "@babylonjs/core/scene.js";
|
6
|
-
/**
|
7
|
-
* STL file type loader.
|
8
|
-
* This is a babylon scene loader plugin.
|
9
|
-
*/
|
10
|
-
export declare class STLFileLoader implements ISceneLoaderPlugin {
|
11
|
-
/** @hidden */
|
12
|
-
solidPattern: RegExp;
|
13
|
-
/** @hidden */
|
14
|
-
facetsPattern: RegExp;
|
15
|
-
/** @hidden */
|
16
|
-
normalPattern: RegExp;
|
17
|
-
/** @hidden */
|
18
|
-
vertexPattern: RegExp;
|
19
|
-
/**
|
20
|
-
* Defines the name of the plugin.
|
21
|
-
*/
|
22
|
-
name: string;
|
23
|
-
/**
|
24
|
-
* Defines the extensions the stl loader is able to load.
|
25
|
-
* force data to come in as an ArrayBuffer
|
26
|
-
* we'll convert to string if it looks like it's an ASCII .stl
|
27
|
-
*/
|
28
|
-
extensions: ISceneLoaderPluginExtensions;
|
29
|
-
/**
|
30
|
-
* Defines if Y and Z axes are swapped or not when loading an STL file.
|
31
|
-
* The default is false to maintain backward compatibility. When set to
|
32
|
-
* true, coordinates from the STL file are used without change.
|
33
|
-
*/
|
34
|
-
static DO_NOT_ALTER_FILE_COORDINATES: boolean;
|
35
|
-
/**
|
36
|
-
* Import meshes into a scene.
|
37
|
-
* @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
|
38
|
-
* @param scene The scene to import into
|
39
|
-
* @param data The data to import
|
40
|
-
* @param rootUrl The root url for scene and resources
|
41
|
-
* @param meshes The meshes array to import into
|
42
|
-
* @returns True if successful or false otherwise
|
43
|
-
*/
|
44
|
-
importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>): boolean;
|
45
|
-
/**
|
46
|
-
* Load into a scene.
|
47
|
-
* @param scene The scene to load into
|
48
|
-
* @param data The data to import
|
49
|
-
* @param rootUrl The root url for scene and resources
|
50
|
-
* @returns true if successful or false otherwise
|
51
|
-
*/
|
52
|
-
load(scene: Scene, data: any, rootUrl: string): boolean;
|
53
|
-
/**
|
54
|
-
* Load into an asset container.
|
55
|
-
* @param scene The scene to load into
|
56
|
-
* @param data The data to import
|
57
|
-
* @param rootUrl The root url for scene and resources
|
58
|
-
* @returns The loaded asset container
|
59
|
-
*/
|
60
|
-
loadAssetContainer(scene: Scene, data: string, rootUrl: string): AssetContainer;
|
61
|
-
private _isBinary;
|
62
|
-
private _parseBinary;
|
63
|
-
private _parseASCII;
|
64
|
-
}
|
1
|
+
import { Nullable } from "@babylonjs/core/types.js";
|
2
|
+
import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh.js";
|
3
|
+
import { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from "@babylonjs/core/Loading/sceneLoader.js";
|
4
|
+
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
5
|
+
import { Scene } from "@babylonjs/core/scene.js";
|
6
|
+
/**
|
7
|
+
* STL file type loader.
|
8
|
+
* This is a babylon scene loader plugin.
|
9
|
+
*/
|
10
|
+
export declare class STLFileLoader implements ISceneLoaderPlugin {
|
11
|
+
/** @hidden */
|
12
|
+
solidPattern: RegExp;
|
13
|
+
/** @hidden */
|
14
|
+
facetsPattern: RegExp;
|
15
|
+
/** @hidden */
|
16
|
+
normalPattern: RegExp;
|
17
|
+
/** @hidden */
|
18
|
+
vertexPattern: RegExp;
|
19
|
+
/**
|
20
|
+
* Defines the name of the plugin.
|
21
|
+
*/
|
22
|
+
name: string;
|
23
|
+
/**
|
24
|
+
* Defines the extensions the stl loader is able to load.
|
25
|
+
* force data to come in as an ArrayBuffer
|
26
|
+
* we'll convert to string if it looks like it's an ASCII .stl
|
27
|
+
*/
|
28
|
+
extensions: ISceneLoaderPluginExtensions;
|
29
|
+
/**
|
30
|
+
* Defines if Y and Z axes are swapped or not when loading an STL file.
|
31
|
+
* The default is false to maintain backward compatibility. When set to
|
32
|
+
* true, coordinates from the STL file are used without change.
|
33
|
+
*/
|
34
|
+
static DO_NOT_ALTER_FILE_COORDINATES: boolean;
|
35
|
+
/**
|
36
|
+
* Import meshes into a scene.
|
37
|
+
* @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
|
38
|
+
* @param scene The scene to import into
|
39
|
+
* @param data The data to import
|
40
|
+
* @param rootUrl The root url for scene and resources
|
41
|
+
* @param meshes The meshes array to import into
|
42
|
+
* @returns True if successful or false otherwise
|
43
|
+
*/
|
44
|
+
importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>): boolean;
|
45
|
+
/**
|
46
|
+
* Load into a scene.
|
47
|
+
* @param scene The scene to load into
|
48
|
+
* @param data The data to import
|
49
|
+
* @param rootUrl The root url for scene and resources
|
50
|
+
* @returns true if successful or false otherwise
|
51
|
+
*/
|
52
|
+
load(scene: Scene, data: any, rootUrl: string): boolean;
|
53
|
+
/**
|
54
|
+
* Load into an asset container.
|
55
|
+
* @param scene The scene to load into
|
56
|
+
* @param data The data to import
|
57
|
+
* @param rootUrl The root url for scene and resources
|
58
|
+
* @returns The loaded asset container
|
59
|
+
*/
|
60
|
+
loadAssetContainer(scene: Scene, data: string, rootUrl: string): AssetContainer;
|
61
|
+
private _isBinary;
|
62
|
+
private _parseBinary;
|
63
|
+
private _parseASCII;
|
64
|
+
}
|
package/STL/stlFileLoader.js
CHANGED
@@ -1,234 +1,234 @@
|
|
1
|
-
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
2
|
-
import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
3
|
-
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
4
|
-
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
5
|
-
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
6
|
-
/**
|
7
|
-
* STL file type loader.
|
8
|
-
* This is a babylon scene loader plugin.
|
9
|
-
*/
|
10
|
-
var STLFileLoader = /** @class */ (function () {
|
11
|
-
function STLFileLoader() {
|
12
|
-
/** @hidden */
|
13
|
-
this.solidPattern = /solid (\S*)([\S\s]*?)endsolid[ ]*(\S*)/g;
|
14
|
-
/** @hidden */
|
15
|
-
this.facetsPattern = /facet([\s\S]*?)endfacet/g;
|
16
|
-
/** @hidden */
|
17
|
-
this.normalPattern = /normal[\s]+([-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;
|
18
|
-
/** @hidden */
|
19
|
-
this.vertexPattern = /vertex[\s]+([-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;
|
20
|
-
/**
|
21
|
-
* Defines the name of the plugin.
|
22
|
-
*/
|
23
|
-
this.name = "stl";
|
24
|
-
/**
|
25
|
-
* Defines the extensions the stl loader is able to load.
|
26
|
-
* force data to come in as an ArrayBuffer
|
27
|
-
* we'll convert to string if it looks like it's an ASCII .stl
|
28
|
-
*/
|
29
|
-
this.extensions = {
|
30
|
-
".stl": { isBinary: true },
|
31
|
-
};
|
32
|
-
}
|
33
|
-
/**
|
34
|
-
* Import meshes into a scene.
|
35
|
-
* @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
|
36
|
-
* @param scene The scene to import into
|
37
|
-
* @param data The data to import
|
38
|
-
* @param rootUrl The root url for scene and resources
|
39
|
-
* @param meshes The meshes array to import into
|
40
|
-
* @returns True if successful or false otherwise
|
41
|
-
*/
|
42
|
-
STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes) {
|
43
|
-
var matches;
|
44
|
-
if (typeof data !== "string") {
|
45
|
-
if (this._isBinary(data)) {
|
46
|
-
// binary .stl
|
47
|
-
var babylonMesh = new Mesh("stlmesh", scene);
|
48
|
-
this._parseBinary(babylonMesh, data);
|
49
|
-
if (meshes) {
|
50
|
-
meshes.push(babylonMesh);
|
51
|
-
}
|
52
|
-
return true;
|
53
|
-
}
|
54
|
-
// ASCII .stl
|
55
|
-
// convert to string
|
56
|
-
var array_buffer = new Uint8Array(data);
|
57
|
-
var str = "";
|
58
|
-
for (var i = 0; i < data.byteLength; i++) {
|
59
|
-
str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
|
60
|
-
}
|
61
|
-
data = str;
|
62
|
-
}
|
63
|
-
//if arrived here, data is a string, containing the STLA data.
|
64
|
-
while ((matches = this.solidPattern.exec(data))) {
|
65
|
-
var meshName = matches[1];
|
66
|
-
var meshNameFromEnd = matches[3];
|
67
|
-
if (meshName != meshNameFromEnd) {
|
68
|
-
Tools.Error("Error in STL, solid name != endsolid name");
|
69
|
-
return false;
|
70
|
-
}
|
71
|
-
// check meshesNames
|
72
|
-
if (meshesNames && meshName) {
|
73
|
-
if (meshesNames instanceof Array) {
|
74
|
-
if (!meshesNames.indexOf(meshName)) {
|
75
|
-
continue;
|
76
|
-
}
|
77
|
-
}
|
78
|
-
else {
|
79
|
-
if (meshName !== meshesNames) {
|
80
|
-
continue;
|
81
|
-
}
|
82
|
-
}
|
83
|
-
}
|
84
|
-
// stl mesh name can be empty as well
|
85
|
-
meshName = meshName || "stlmesh";
|
86
|
-
var babylonMesh = new Mesh(meshName, scene);
|
87
|
-
this._parseASCII(babylonMesh, matches[2]);
|
88
|
-
if (meshes) {
|
89
|
-
meshes.push(babylonMesh);
|
90
|
-
}
|
91
|
-
}
|
92
|
-
return true;
|
93
|
-
};
|
94
|
-
/**
|
95
|
-
* Load into a scene.
|
96
|
-
* @param scene The scene to load into
|
97
|
-
* @param data The data to import
|
98
|
-
* @param rootUrl The root url for scene and resources
|
99
|
-
* @returns true if successful or false otherwise
|
100
|
-
*/
|
101
|
-
STLFileLoader.prototype.load = function (scene, data, rootUrl) {
|
102
|
-
var result = this.importMesh(null, scene, data, rootUrl, null);
|
103
|
-
return result;
|
104
|
-
};
|
105
|
-
/**
|
106
|
-
* Load into an asset container.
|
107
|
-
* @param scene The scene to load into
|
108
|
-
* @param data The data to import
|
109
|
-
* @param rootUrl The root url for scene and resources
|
110
|
-
* @returns The loaded asset container
|
111
|
-
*/
|
112
|
-
STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl) {
|
113
|
-
var container = new AssetContainer(scene);
|
114
|
-
scene._blockEntityCollection = true;
|
115
|
-
this.importMesh(null, scene, data, rootUrl, container.meshes);
|
116
|
-
scene._blockEntityCollection = false;
|
117
|
-
return container;
|
118
|
-
};
|
119
|
-
STLFileLoader.prototype._isBinary = function (data) {
|
120
|
-
// check if file size is correct for binary stl
|
121
|
-
var reader = new DataView(data);
|
122
|
-
// A Binary STL header is 80 bytes, if the data size is not great than
|
123
|
-
// that then it's not a binary STL.
|
124
|
-
if (reader.byteLength <= 80) {
|
125
|
-
return false;
|
126
|
-
}
|
127
|
-
var faceSize = (32 / 8) * 3 + (32 / 8) * 3 * 3 + 16 / 8;
|
128
|
-
var nFaces = reader.getUint32(80, true);
|
129
|
-
if (80 + 32 / 8 + nFaces * faceSize === reader.byteLength) {
|
130
|
-
return true;
|
131
|
-
}
|
132
|
-
// check characters higher than ASCII to confirm binary
|
133
|
-
var fileLength = reader.byteLength;
|
134
|
-
for (var index = 0; index < fileLength; index++) {
|
135
|
-
if (reader.getUint8(index) > 127) {
|
136
|
-
return true;
|
137
|
-
}
|
138
|
-
}
|
139
|
-
return false;
|
140
|
-
};
|
141
|
-
STLFileLoader.prototype._parseBinary = function (mesh, data) {
|
142
|
-
var reader = new DataView(data);
|
143
|
-
var faces = reader.getUint32(80, true);
|
144
|
-
var dataOffset = 84;
|
145
|
-
var faceLength = 12 * 4 + 2;
|
146
|
-
var offset = 0;
|
147
|
-
var positions = new Float32Array(faces * 3 * 3);
|
148
|
-
var normals = new Float32Array(faces * 3 * 3);
|
149
|
-
var indices = new Uint32Array(faces * 3);
|
150
|
-
var indicesCount = 0;
|
151
|
-
for (var face = 0; face < faces; face++) {
|
152
|
-
var start = dataOffset + face * faceLength;
|
153
|
-
var normalX = reader.getFloat32(start, true);
|
154
|
-
var normalY = reader.getFloat32(start + 4, true);
|
155
|
-
var normalZ = reader.getFloat32(start + 8, true);
|
156
|
-
for (var i = 1; i <= 3; i++) {
|
157
|
-
var vertexstart = start + i * 12;
|
158
|
-
// ordering is intentional to match ascii import
|
159
|
-
positions[offset] = reader.getFloat32(vertexstart, true);
|
160
|
-
normals[offset] = normalX;
|
161
|
-
if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {
|
162
|
-
positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
|
163
|
-
positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
|
164
|
-
normals[offset + 2] = normalY;
|
165
|
-
normals[offset + 1] = normalZ;
|
166
|
-
}
|
167
|
-
else {
|
168
|
-
positions[offset + 1] = reader.getFloat32(vertexstart + 4, true);
|
169
|
-
positions[offset + 2] = reader.getFloat32(vertexstart + 8, true);
|
170
|
-
normals[offset + 1] = normalY;
|
171
|
-
normals[offset + 2] = normalZ;
|
172
|
-
}
|
173
|
-
offset += 3;
|
174
|
-
}
|
175
|
-
indices[indicesCount] = indicesCount++;
|
176
|
-
indices[indicesCount] = indicesCount++;
|
177
|
-
indices[indicesCount] = indicesCount++;
|
178
|
-
}
|
179
|
-
mesh.setVerticesData(VertexBuffer.PositionKind, positions);
|
180
|
-
mesh.setVerticesData(VertexBuffer.NormalKind, normals);
|
181
|
-
mesh.setIndices(indices);
|
182
|
-
mesh.computeWorldMatrix(true);
|
183
|
-
};
|
184
|
-
STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
|
185
|
-
var positions = [];
|
186
|
-
var normals = [];
|
187
|
-
var indices = [];
|
188
|
-
var indicesCount = 0;
|
189
|
-
//load facets, ignoring loop as the standard doesn't define it can contain more than vertices
|
190
|
-
var matches;
|
191
|
-
while ((matches = this.facetsPattern.exec(solidData))) {
|
192
|
-
var facet = matches[1];
|
193
|
-
//one normal per face
|
194
|
-
var normalMatches = this.normalPattern.exec(facet);
|
195
|
-
this.normalPattern.lastIndex = 0;
|
196
|
-
if (!normalMatches) {
|
197
|
-
continue;
|
198
|
-
}
|
199
|
-
var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
|
200
|
-
var vertexMatch = void 0;
|
201
|
-
while ((vertexMatch = this.vertexPattern.exec(facet))) {
|
202
|
-
if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {
|
203
|
-
positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
|
204
|
-
normals.push(normal[0], normal[1], normal[2]);
|
205
|
-
}
|
206
|
-
else {
|
207
|
-
positions.push(Number(vertexMatch[1]), Number(vertexMatch[3]), Number(vertexMatch[5]));
|
208
|
-
// Flipping the second and third component because inverted
|
209
|
-
// when normal was declared.
|
210
|
-
normals.push(normal[0], normal[2], normal[1]);
|
211
|
-
}
|
212
|
-
}
|
213
|
-
indices.push(indicesCount++, indicesCount++, indicesCount++);
|
214
|
-
this.vertexPattern.lastIndex = 0;
|
215
|
-
}
|
216
|
-
this.facetsPattern.lastIndex = 0;
|
217
|
-
mesh.setVerticesData(VertexBuffer.PositionKind, positions);
|
218
|
-
mesh.setVerticesData(VertexBuffer.NormalKind, normals);
|
219
|
-
mesh.setIndices(indices);
|
220
|
-
mesh.computeWorldMatrix(true);
|
221
|
-
};
|
222
|
-
/**
|
223
|
-
* Defines if Y and Z axes are swapped or not when loading an STL file.
|
224
|
-
* The default is false to maintain backward compatibility. When set to
|
225
|
-
* true, coordinates from the STL file are used without change.
|
226
|
-
*/
|
227
|
-
STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES = false;
|
228
|
-
return STLFileLoader;
|
229
|
-
}());
|
230
|
-
export { STLFileLoader };
|
231
|
-
if (SceneLoader) {
|
232
|
-
SceneLoader.RegisterPlugin(new STLFileLoader());
|
233
|
-
}
|
1
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
2
|
+
import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
3
|
+
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
4
|
+
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
5
|
+
import { AssetContainer } from "@babylonjs/core/assetContainer.js";
|
6
|
+
/**
|
7
|
+
* STL file type loader.
|
8
|
+
* This is a babylon scene loader plugin.
|
9
|
+
*/
|
10
|
+
var STLFileLoader = /** @class */ (function () {
|
11
|
+
function STLFileLoader() {
|
12
|
+
/** @hidden */
|
13
|
+
this.solidPattern = /solid (\S*)([\S\s]*?)endsolid[ ]*(\S*)/g;
|
14
|
+
/** @hidden */
|
15
|
+
this.facetsPattern = /facet([\s\S]*?)endfacet/g;
|
16
|
+
/** @hidden */
|
17
|
+
this.normalPattern = /normal[\s]+([-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;
|
18
|
+
/** @hidden */
|
19
|
+
this.vertexPattern = /vertex[\s]+([-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+/g;
|
20
|
+
/**
|
21
|
+
* Defines the name of the plugin.
|
22
|
+
*/
|
23
|
+
this.name = "stl";
|
24
|
+
/**
|
25
|
+
* Defines the extensions the stl loader is able to load.
|
26
|
+
* force data to come in as an ArrayBuffer
|
27
|
+
* we'll convert to string if it looks like it's an ASCII .stl
|
28
|
+
*/
|
29
|
+
this.extensions = {
|
30
|
+
".stl": { isBinary: true },
|
31
|
+
};
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Import meshes into a scene.
|
35
|
+
* @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
|
36
|
+
* @param scene The scene to import into
|
37
|
+
* @param data The data to import
|
38
|
+
* @param rootUrl The root url for scene and resources
|
39
|
+
* @param meshes The meshes array to import into
|
40
|
+
* @returns True if successful or false otherwise
|
41
|
+
*/
|
42
|
+
STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes) {
|
43
|
+
var matches;
|
44
|
+
if (typeof data !== "string") {
|
45
|
+
if (this._isBinary(data)) {
|
46
|
+
// binary .stl
|
47
|
+
var babylonMesh = new Mesh("stlmesh", scene);
|
48
|
+
this._parseBinary(babylonMesh, data);
|
49
|
+
if (meshes) {
|
50
|
+
meshes.push(babylonMesh);
|
51
|
+
}
|
52
|
+
return true;
|
53
|
+
}
|
54
|
+
// ASCII .stl
|
55
|
+
// convert to string
|
56
|
+
var array_buffer = new Uint8Array(data);
|
57
|
+
var str = "";
|
58
|
+
for (var i = 0; i < data.byteLength; i++) {
|
59
|
+
str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
|
60
|
+
}
|
61
|
+
data = str;
|
62
|
+
}
|
63
|
+
//if arrived here, data is a string, containing the STLA data.
|
64
|
+
while ((matches = this.solidPattern.exec(data))) {
|
65
|
+
var meshName = matches[1];
|
66
|
+
var meshNameFromEnd = matches[3];
|
67
|
+
if (meshName != meshNameFromEnd) {
|
68
|
+
Tools.Error("Error in STL, solid name != endsolid name");
|
69
|
+
return false;
|
70
|
+
}
|
71
|
+
// check meshesNames
|
72
|
+
if (meshesNames && meshName) {
|
73
|
+
if (meshesNames instanceof Array) {
|
74
|
+
if (!meshesNames.indexOf(meshName)) {
|
75
|
+
continue;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
if (meshName !== meshesNames) {
|
80
|
+
continue;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
// stl mesh name can be empty as well
|
85
|
+
meshName = meshName || "stlmesh";
|
86
|
+
var babylonMesh = new Mesh(meshName, scene);
|
87
|
+
this._parseASCII(babylonMesh, matches[2]);
|
88
|
+
if (meshes) {
|
89
|
+
meshes.push(babylonMesh);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
return true;
|
93
|
+
};
|
94
|
+
/**
|
95
|
+
* Load into a scene.
|
96
|
+
* @param scene The scene to load into
|
97
|
+
* @param data The data to import
|
98
|
+
* @param rootUrl The root url for scene and resources
|
99
|
+
* @returns true if successful or false otherwise
|
100
|
+
*/
|
101
|
+
STLFileLoader.prototype.load = function (scene, data, rootUrl) {
|
102
|
+
var result = this.importMesh(null, scene, data, rootUrl, null);
|
103
|
+
return result;
|
104
|
+
};
|
105
|
+
/**
|
106
|
+
* Load into an asset container.
|
107
|
+
* @param scene The scene to load into
|
108
|
+
* @param data The data to import
|
109
|
+
* @param rootUrl The root url for scene and resources
|
110
|
+
* @returns The loaded asset container
|
111
|
+
*/
|
112
|
+
STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl) {
|
113
|
+
var container = new AssetContainer(scene);
|
114
|
+
scene._blockEntityCollection = true;
|
115
|
+
this.importMesh(null, scene, data, rootUrl, container.meshes);
|
116
|
+
scene._blockEntityCollection = false;
|
117
|
+
return container;
|
118
|
+
};
|
119
|
+
STLFileLoader.prototype._isBinary = function (data) {
|
120
|
+
// check if file size is correct for binary stl
|
121
|
+
var reader = new DataView(data);
|
122
|
+
// A Binary STL header is 80 bytes, if the data size is not great than
|
123
|
+
// that then it's not a binary STL.
|
124
|
+
if (reader.byteLength <= 80) {
|
125
|
+
return false;
|
126
|
+
}
|
127
|
+
var faceSize = (32 / 8) * 3 + (32 / 8) * 3 * 3 + 16 / 8;
|
128
|
+
var nFaces = reader.getUint32(80, true);
|
129
|
+
if (80 + 32 / 8 + nFaces * faceSize === reader.byteLength) {
|
130
|
+
return true;
|
131
|
+
}
|
132
|
+
// check characters higher than ASCII to confirm binary
|
133
|
+
var fileLength = reader.byteLength;
|
134
|
+
for (var index = 0; index < fileLength; index++) {
|
135
|
+
if (reader.getUint8(index) > 127) {
|
136
|
+
return true;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
return false;
|
140
|
+
};
|
141
|
+
STLFileLoader.prototype._parseBinary = function (mesh, data) {
|
142
|
+
var reader = new DataView(data);
|
143
|
+
var faces = reader.getUint32(80, true);
|
144
|
+
var dataOffset = 84;
|
145
|
+
var faceLength = 12 * 4 + 2;
|
146
|
+
var offset = 0;
|
147
|
+
var positions = new Float32Array(faces * 3 * 3);
|
148
|
+
var normals = new Float32Array(faces * 3 * 3);
|
149
|
+
var indices = new Uint32Array(faces * 3);
|
150
|
+
var indicesCount = 0;
|
151
|
+
for (var face = 0; face < faces; face++) {
|
152
|
+
var start = dataOffset + face * faceLength;
|
153
|
+
var normalX = reader.getFloat32(start, true);
|
154
|
+
var normalY = reader.getFloat32(start + 4, true);
|
155
|
+
var normalZ = reader.getFloat32(start + 8, true);
|
156
|
+
for (var i = 1; i <= 3; i++) {
|
157
|
+
var vertexstart = start + i * 12;
|
158
|
+
// ordering is intentional to match ascii import
|
159
|
+
positions[offset] = reader.getFloat32(vertexstart, true);
|
160
|
+
normals[offset] = normalX;
|
161
|
+
if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {
|
162
|
+
positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
|
163
|
+
positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
|
164
|
+
normals[offset + 2] = normalY;
|
165
|
+
normals[offset + 1] = normalZ;
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
positions[offset + 1] = reader.getFloat32(vertexstart + 4, true);
|
169
|
+
positions[offset + 2] = reader.getFloat32(vertexstart + 8, true);
|
170
|
+
normals[offset + 1] = normalY;
|
171
|
+
normals[offset + 2] = normalZ;
|
172
|
+
}
|
173
|
+
offset += 3;
|
174
|
+
}
|
175
|
+
indices[indicesCount] = indicesCount++;
|
176
|
+
indices[indicesCount] = indicesCount++;
|
177
|
+
indices[indicesCount] = indicesCount++;
|
178
|
+
}
|
179
|
+
mesh.setVerticesData(VertexBuffer.PositionKind, positions);
|
180
|
+
mesh.setVerticesData(VertexBuffer.NormalKind, normals);
|
181
|
+
mesh.setIndices(indices);
|
182
|
+
mesh.computeWorldMatrix(true);
|
183
|
+
};
|
184
|
+
STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
|
185
|
+
var positions = [];
|
186
|
+
var normals = [];
|
187
|
+
var indices = [];
|
188
|
+
var indicesCount = 0;
|
189
|
+
//load facets, ignoring loop as the standard doesn't define it can contain more than vertices
|
190
|
+
var matches;
|
191
|
+
while ((matches = this.facetsPattern.exec(solidData))) {
|
192
|
+
var facet = matches[1];
|
193
|
+
//one normal per face
|
194
|
+
var normalMatches = this.normalPattern.exec(facet);
|
195
|
+
this.normalPattern.lastIndex = 0;
|
196
|
+
if (!normalMatches) {
|
197
|
+
continue;
|
198
|
+
}
|
199
|
+
var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
|
200
|
+
var vertexMatch = void 0;
|
201
|
+
while ((vertexMatch = this.vertexPattern.exec(facet))) {
|
202
|
+
if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {
|
203
|
+
positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
|
204
|
+
normals.push(normal[0], normal[1], normal[2]);
|
205
|
+
}
|
206
|
+
else {
|
207
|
+
positions.push(Number(vertexMatch[1]), Number(vertexMatch[3]), Number(vertexMatch[5]));
|
208
|
+
// Flipping the second and third component because inverted
|
209
|
+
// when normal was declared.
|
210
|
+
normals.push(normal[0], normal[2], normal[1]);
|
211
|
+
}
|
212
|
+
}
|
213
|
+
indices.push(indicesCount++, indicesCount++, indicesCount++);
|
214
|
+
this.vertexPattern.lastIndex = 0;
|
215
|
+
}
|
216
|
+
this.facetsPattern.lastIndex = 0;
|
217
|
+
mesh.setVerticesData(VertexBuffer.PositionKind, positions);
|
218
|
+
mesh.setVerticesData(VertexBuffer.NormalKind, normals);
|
219
|
+
mesh.setIndices(indices);
|
220
|
+
mesh.computeWorldMatrix(true);
|
221
|
+
};
|
222
|
+
/**
|
223
|
+
* Defines if Y and Z axes are swapped or not when loading an STL file.
|
224
|
+
* The default is false to maintain backward compatibility. When set to
|
225
|
+
* true, coordinates from the STL file are used without change.
|
226
|
+
*/
|
227
|
+
STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES = false;
|
228
|
+
return STLFileLoader;
|
229
|
+
}());
|
230
|
+
export { STLFileLoader };
|
231
|
+
if (SceneLoader) {
|
232
|
+
SceneLoader.RegisterPlugin(new STLFileLoader());
|
233
|
+
}
|
234
234
|
//# sourceMappingURL=stlFileLoader.js.map
|
@@ -1,13 +1,13 @@
|
|
1
|
-
import { GLTFLoaderExtension } from "./glTFLoader";
|
2
|
-
import { Scene } from "@babylonjs/core/scene.js";
|
3
|
-
import { IGLTFLoaderData } from "../glTFFileLoader";
|
4
|
-
import { IGLTFRuntime } from "./glTFLoaderInterfaces";
|
5
|
-
/** @hidden */
|
6
|
-
export declare class GLTFBinaryExtension extends GLTFLoaderExtension {
|
7
|
-
private _bin;
|
8
|
-
constructor();
|
9
|
-
loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void): boolean;
|
10
|
-
loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
|
11
|
-
loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void): boolean;
|
12
|
-
loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void): boolean;
|
13
|
-
}
|
1
|
+
import { GLTFLoaderExtension } from "./glTFLoader";
|
2
|
+
import { Scene } from "@babylonjs/core/scene.js";
|
3
|
+
import { IGLTFLoaderData } from "../glTFFileLoader";
|
4
|
+
import { IGLTFRuntime } from "./glTFLoaderInterfaces";
|
5
|
+
/** @hidden */
|
6
|
+
export declare class GLTFBinaryExtension extends GLTFLoaderExtension {
|
7
|
+
private _bin;
|
8
|
+
constructor();
|
9
|
+
loadRuntimeAsync(scene: Scene, data: IGLTFLoaderData, rootUrl: string, onSuccess: (gltfRuntime: IGLTFRuntime) => void): boolean;
|
10
|
+
loadBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void, onError: (message: string) => void): boolean;
|
11
|
+
loadTextureBufferAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (buffer: ArrayBufferView) => void): boolean;
|
12
|
+
loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void): boolean;
|
13
|
+
}
|