@babylonjs/loaders 5.0.0-rc.0 → 5.0.0-rc.11
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/index.js.map +1 -1
- package/OBJ/mtlFileLoader.d.ts +41 -40
- package/OBJ/mtlFileLoader.js +232 -231
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.d.ts +126 -133
- package/OBJ/objFileLoader.js +296 -300
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +43 -43
- package/OBJ/objLoadingOptions.js +1 -1
- package/OBJ/objLoadingOptions.js.map +1 -1
- package/OBJ/solidParser.d.ts +154 -153
- package/OBJ/solidParser.js +693 -699
- package/OBJ/solidParser.js.map +1 -1
- package/STL/index.d.ts +1 -1
- package/STL/index.js +1 -1
- package/STL/index.js.map +1 -1
- package/STL/stlFileLoader.d.ts +64 -71
- package/STL/stlFileLoader.js +233 -239
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
- package/glTF/1.0/glTFBinaryExtension.js +60 -61
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.d.ts +136 -106
- package/glTF/1.0/glTFLoader.js +1814 -1696
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
- package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
- package/glTF/1.0/glTFLoaderUtils.js +250 -232
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
- package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -127
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- package/glTF/1.0/index.d.ts +5 -5
- package/glTF/1.0/index.js +5 -5
- package/glTF/1.0/index.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -36
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -110
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -28
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -80
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -27
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -42
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -21
- package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -32
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -32
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -55
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -101
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -28
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -81
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -86
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -45
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -34
- package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -54
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -72
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -76
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -66
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -76
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -277
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -30
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -65
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -76
- package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -243
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -31
- package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -78
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -19
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -21
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -21
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -32
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -25
- package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -53
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -29
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -46
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -38
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -216
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -75
- package/glTF/2.0/Extensions/MSFT_lod.js +369 -333
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- 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_minecraftMesh.js.map +1 -1
- 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/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/Extensions/index.d.ts +26 -26
- package/glTF/2.0/Extensions/index.js +26 -26
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +406 -357
- package/glTF/2.0/glTFLoader.js +2366 -2266
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
- package/glTF/2.0/glTFLoaderExtension.js +1 -1
- package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -209
- package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/2.0/index.d.ts +4 -4
- package/glTF/2.0/index.js +5 -4
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +433 -373
- package/glTF/glTFFileLoader.js +927 -870
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.d.ts +29 -29
- package/glTF/glTFValidation.js +123 -121
- package/glTF/glTFValidation.js.map +1 -1
- package/glTF/index.d.ts +5 -5
- package/glTF/index.js +6 -5
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +4 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF.d.ts +2 -2
- package/legacy/legacy-glTF.js +18 -18
- package/legacy/legacy-glTF.js.map +1 -1
- package/legacy/legacy-glTF1.d.ts +2 -2
- package/legacy/legacy-glTF1.js +15 -14
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF1FileLoader.js +3 -2
- package/legacy/legacy-glTF1FileLoader.js.map +1 -1
- package/legacy/legacy-glTF2.d.ts +2 -2
- package/legacy/legacy-glTF2.js +33 -32
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF2FileLoader.js +3 -2
- package/legacy/legacy-glTF2FileLoader.js.map +1 -1
- package/legacy/legacy-glTFFileLoader.d.ts +3 -3
- package/legacy/legacy-glTFFileLoader.js +4 -3
- package/legacy/legacy-glTFFileLoader.js.map +1 -1
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +13 -12
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +13 -12
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/legacy/legacy.d.ts +6 -6
- package/legacy/legacy.js +8 -6
- package/legacy/legacy.js.map +1 -1
- package/package.json +23 -198
- package/readme.md +2 -2
package/STL/stlFileLoader.js
CHANGED
@@ -1,240 +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]+([
|
18
|
-
/** @hidden */
|
19
|
-
this.vertexPattern = /vertex[\s]+([
|
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
|
-
* @
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
*
|
99
|
-
* @
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
*
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
var
|
149
|
-
var
|
150
|
-
var
|
151
|
-
var
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
positions[offset +
|
169
|
-
positions[offset +
|
170
|
-
normals[offset +
|
171
|
-
normals[offset +
|
172
|
-
}
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
var
|
201
|
-
this.
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
normals.push(normal[0], normal[
|
211
|
-
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
return STLFileLoader;
|
235
|
-
}());
|
236
|
-
export { STLFileLoader };
|
237
|
-
if (SceneLoader) {
|
238
|
-
SceneLoader.RegisterPlugin(new STLFileLoader());
|
239
|
-
}
|
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
|
+
}
|
240
234
|
//# sourceMappingURL=stlFileLoader.js.map
|
package/STL/stlFileLoader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stlFileLoader.js","sourceRoot":"","sources":["../../../sourceES6/loaders/src/STL/stlFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAI9D,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,OAAO,EAAE,WAAW,EAAoD,MAAM,qCAAqC,CAAC;AACpH,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE;;;GAGG;AACH;IAAA;QAEI,cAAc;QACP,iBAAY,GAAG,yCAAyC,CAAC;QAEhE,cAAc;QACP,kBAAa,GAAG,0BAA0B,CAAC;QAClD,cAAc;QACP,kBAAa,GAAG,yJAAyJ,CAAC;QACjL,cAAc;QACP,kBAAa,GAAG,yJAAyJ,CAAC;QAEjL;;WAEG;QACI,SAAI,GAAG,KAAK,CAAC;QAEpB;;;;WAIG;QACI,eAAU,GAAiC;YAC9C,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC7B,CAAC;IAyPN,CAAC;IAhPG;;;;;;;;;;;OAWG;IACI,kCAAU,GAAjB,UAAkB,WAAgB,EAAE,KAAY,EAAE,IAAS,EAAE,OAAe,EAAE,MAAgC,EAAE,eAA4C,EAAE,SAA+B;QACzL,IAAI,OAAO,CAAC;QAEZ,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAE1B,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;gBACtB,cAAc;gBACd,IAAI,WAAW,GAAG,IAAI,IAAI,CAAC,SAA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CAAC;QACjC,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAtPD;;;;OAIG;IACW,2CAA6B,GAAG,KAAK,CAAC;IAkPxD,oBAAC;CAAA,AAjRD,IAiRC;SAjRY,aAAa;AAmR1B,IAAI,WAAW,EAAE;IACb,WAAW,CAAC,cAAc,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;CACnD","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\nimport { Tools } from \"@babylonjs/core/Misc/tools\";\nimport { VertexBuffer } from \"@babylonjs/core/Buffers/buffer\";\nimport { Skeleton } from \"@babylonjs/core/Bones/skeleton\";\nimport { IParticleSystem } from \"@babylonjs/core/Particles/IParticleSystem\";\nimport { AbstractMesh } from \"@babylonjs/core/Meshes/abstractMesh\";\nimport { Mesh } from \"@babylonjs/core/Meshes/mesh\";\nimport { SceneLoader, ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from \"@babylonjs/core/Loading/sceneLoader\";\nimport { AssetContainer } from \"@babylonjs/core/assetContainer\";\nimport { Scene } from \"@babylonjs/core/scene\";\n\n/**\n * STL file type loader.\n * This is a babylon scene loader plugin.\n */\nexport class STLFileLoader implements ISceneLoaderPlugin {\n\n /** @hidden */\n public solidPattern = /solid (\\S*)([\\S\\s]*?)endsolid[ ]*(\\S*)/g;\n\n /** @hidden */\n public facetsPattern = /facet([\\s\\S]*?)endfacet/g;\n /** @hidden */\n public 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;\n /** @hidden */\n public 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;\n\n /**\n * Defines the name of the plugin.\n */\n public name = \"stl\";\n\n /**\n * Defines the extensions the stl loader is able to load.\n * force data to come in as an ArrayBuffer\n * we'll convert to string if it looks like it's an ASCII .stl\n */\n public extensions: ISceneLoaderPluginExtensions = {\n \".stl\": { isBinary: true },\n };\n\n /**\n * Defines if Y and Z axes are swapped or not when loading an STL file.\n * The default is false to maintain backward compatibility. When set to\n * true, coordinates from the STL file are used without change.\n */\n public static DO_NOT_ALTER_FILE_COORDINATES = false;\n\n /**\n * Import meshes into a scene.\n * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\n * @param scene The scene to import into\n * @param data The data to import\n * @param rootUrl The root url for scene and resources\n * @param meshes The meshes array to import into\n * @param particleSystems The particle systems array to import into\n * @param skeletons The skeletons array to import into\n * @param onError The callback when import fails\n * @returns True if successful or false otherwise\n */\n public importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>, particleSystems: Nullable<IParticleSystem[]>, skeletons: Nullable<Skeleton[]>): boolean {\n var matches;\n\n if (typeof data !== \"string\") {\n\n if (this._isBinary(data)) {\n // binary .stl\n var babylonMesh = new Mesh(\"stlmesh\", scene);\n this._parseBinary(babylonMesh, data);\n if (meshes) {\n meshes.push(babylonMesh);\n }\n return true;\n }\n\n // ASCII .stl\n\n // convert to string\n var array_buffer = new Uint8Array(data);\n var str = '';\n for (var i = 0; i < data.byteLength; i++) {\n str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian\n }\n data = str;\n }\n\n //if arrived here, data is a string, containing the STLA data.\n\n while (matches = this.solidPattern.exec(data)) {\n var meshName = matches[1];\n var meshNameFromEnd = matches[3];\n if (meshName != meshNameFromEnd) {\n Tools.Error(\"Error in STL, solid name != endsolid name\");\n return false;\n }\n\n // check meshesNames\n if (meshesNames && meshName) {\n if (meshesNames instanceof Array) {\n if (!meshesNames.indexOf(meshName)) {\n continue;\n }\n } else {\n if (meshName !== meshesNames) {\n continue;\n }\n }\n }\n\n // stl mesh name can be empty as well\n meshName = meshName || \"stlmesh\";\n\n var babylonMesh = new Mesh(meshName, scene);\n this._parseASCII(babylonMesh, matches[2]);\n if (meshes) {\n meshes.push(babylonMesh);\n }\n }\n\n return true;\n\n }\n\n /**\n * Load into a scene.\n * @param scene The scene to load into\n * @param data The data to import\n * @param rootUrl The root url for scene and resources\n * @param onError The callback when import fails\n * @returns true if successful or false otherwise\n */\n public load(scene: Scene, data: any, rootUrl: string): boolean {\n var result = this.importMesh(null, scene, data, rootUrl, null, null, null);\n return result;\n }\n\n /**\n * Load into an asset container.\n * @param scene The scene to load into\n * @param data The data to import\n * @param rootUrl The root url for scene and resources\n * @param onError The callback when import fails\n * @returns The loaded asset container\n */\n public loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer {\n var container = new AssetContainer(scene);\n scene._blockEntityCollection = true;\n this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);\n scene._blockEntityCollection = false;\n return container;\n }\n\n private _isBinary(data: any) {\n\n // check if file size is correct for binary stl\n var faceSize, nFaces, reader;\n reader = new DataView(data);\n\n // A Binary STL header is 80 bytes, if the data size is not great than\n // that then it's not a binary STL.\n if (reader.byteLength <= 80) {\n return false;\n }\n\n faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);\n nFaces = reader.getUint32(80, true);\n\n if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {\n return true;\n }\n\n // check characters higher than ASCII to confirm binary\n var fileLength = reader.byteLength;\n for (var index = 0; index < fileLength; index++) {\n if (reader.getUint8(index) > 127) {\n return true;\n }\n }\n\n return false;\n }\n\n private _parseBinary(mesh: Mesh, data: ArrayBuffer) {\n\n var reader = new DataView(data);\n var faces = reader.getUint32(80, true);\n\n var dataOffset = 84;\n var faceLength = 12 * 4 + 2;\n\n var offset = 0;\n\n var positions = new Float32Array(faces * 3 * 3);\n var normals = new Float32Array(faces * 3 * 3);\n var indices = new Uint32Array(faces * 3);\n var indicesCount = 0;\n\n for (var face = 0; face < faces; face++) {\n\n var start = dataOffset + face * faceLength;\n var normalX = reader.getFloat32(start, true);\n var normalY = reader.getFloat32(start + 4, true);\n var normalZ = reader.getFloat32(start + 8, true);\n\n for (var i = 1; i <= 3; i++) {\n\n var vertexstart = start + i * 12;\n\n // ordering is intentional to match ascii import\n positions[offset] = reader.getFloat32(vertexstart, true);\n normals[offset] = normalX;\n\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\n\n positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);\n positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);\n\n normals[offset + 2] = normalY;\n normals[offset + 1] = normalZ;\n }\n else {\n\n positions[offset + 1] = reader.getFloat32(vertexstart + 4, true);\n positions[offset + 2] = reader.getFloat32(vertexstart + 8, true);\n\n normals[offset + 1] = normalY;\n normals[offset + 2] = normalZ;\n }\n\n offset += 3;\n }\n indices[indicesCount] = indicesCount++;\n indices[indicesCount] = indicesCount++;\n indices[indicesCount] = indicesCount++;\n }\n\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\n mesh.setIndices(indices);\n mesh.computeWorldMatrix(true);\n }\n\n private _parseASCII(mesh: Mesh, solidData: string) {\n\n var positions = [];\n var normals = [];\n var indices = [];\n var indicesCount = 0;\n\n //load facets, ignoring loop as the standard doesn't define it can contain more than vertices\n var matches;\n while (matches = this.facetsPattern.exec(solidData)) {\n var facet = matches[1];\n //one normal per face\n var normalMatches = this.normalPattern.exec(facet);\n this.normalPattern.lastIndex = 0;\n if (!normalMatches) {\n continue;\n }\n var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];\n\n var vertexMatch;\n while (vertexMatch = this.vertexPattern.exec(facet)) {\n\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\n\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));\n normals.push(normal[0], normal[1], normal[2]);\n }\n else {\n\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[3]), Number(vertexMatch[5]));\n\n // Flipping the second and third component because inverted\n // when normal was declared.\n normals.push(normal[0], normal[2], normal[1]);\n }\n }\n indices.push(indicesCount++, indicesCount++, indicesCount++);\n this.vertexPattern.lastIndex = 0;\n }\n\n this.facetsPattern.lastIndex = 0;\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\n mesh.setIndices(indices);\n mesh.computeWorldMatrix(true);\n }\n}\n\nif (SceneLoader) {\n SceneLoader.RegisterPlugin(new STLFileLoader());\n}"]}
|
1
|
+
{"version":3,"file":"stlFileLoader.js","sourceRoot":"","sources":["../../../../../lts/loaders/generated/STL/stlFileLoader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,YAAY,EAAE,0CAA4B;AAEnD,OAAO,EAAE,IAAI,EAAE,uCAAyB;AAExC,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,cAAc,EAAE,0CAA4B;AAGrD;;;GAGG;AACH;IAAA;QACI,cAAc;QACP,iBAAY,GAAG,yCAAyC,CAAC;QAEhE,cAAc;QACP,kBAAa,GAAG,0BAA0B,CAAC;QAClD,cAAc;QACP,kBAAa,GAAG,mJAAmJ,CAAC;QAC3K,cAAc;QACP,kBAAa,GAAG,mJAAmJ,CAAC;QAE3K;;WAEG;QACI,SAAI,GAAG,KA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M,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;iBACjD;aACJ;YACD,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;YAC7D,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,CAAC,CAAC;SACpC;QAED,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAlOD;;;;OAIG;IACW,2CAA6B,GAAG,KAAK,CAAC;IA8NxD,oBAAC;CAAA,AA5PD,IA4PC;SA5PY,aAAa;AA8P1B,IAAI,WAAW,EAAE;IACb,WAAW,CAAC,cAAc,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;CACnD","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { ISceneLoaderPlugin, ISceneLoaderPluginExtensions } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\n/**\r\n * STL file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class STLFileLoader implements ISceneLoaderPlugin {\r\n /** @hidden */\r\n public solidPattern = /solid (\\S*)([\\S\\s]*?)endsolid[ ]*(\\S*)/g;\r\n\r\n /** @hidden */\r\n public facetsPattern = /facet([\\s\\S]*?)endfacet/g;\r\n /** @hidden */\r\n public 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;\r\n /** @hidden */\r\n public 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;\r\n\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public name = \"stl\";\r\n\r\n /**\r\n * Defines the extensions the stl loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n * we'll convert to string if it looks like it's an ASCII .stl\r\n */\r\n public extensions: ISceneLoaderPluginExtensions = {\r\n \".stl\": { isBinary: true },\r\n };\r\n\r\n /**\r\n * Defines if Y and Z axes are swapped or not when loading an STL file.\r\n * The default is false to maintain backward compatibility. When set to\r\n * true, coordinates from the STL file are used without change.\r\n */\r\n public static DO_NOT_ALTER_FILE_COORDINATES = false;\r\n\r\n /**\r\n * Import meshes into a scene.\r\n * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported\r\n * @param scene The scene to import into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @param meshes The meshes array to import into\r\n * @returns True if successful or false otherwise\r\n */\r\n public importMesh(meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: Nullable<AbstractMesh[]>): boolean {\r\n let matches;\r\n\r\n if (typeof data !== \"string\") {\r\n if (this._isBinary(data)) {\r\n // binary .stl\r\n const babylonMesh = new Mesh(\"stlmesh\", scene);\r\n this._parseBinary(babylonMesh, data);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n return true;\r\n }\r\n\r\n // ASCII .stl\r\n\r\n // convert to string\r\n const array_buffer = new Uint8Array(data);\r\n let str = \"\";\r\n for (let i = 0; i < data.byteLength; i++) {\r\n str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian\r\n }\r\n data = str;\r\n }\r\n\r\n //if arrived here, data is a string, containing the STLA data.\r\n\r\n while ((matches = this.solidPattern.exec(data))) {\r\n let meshName = matches[1];\r\n const meshNameFromEnd = matches[3];\r\n if (meshName != meshNameFromEnd) {\r\n Tools.Error(\"Error in STL, solid name != endsolid name\");\r\n return false;\r\n }\r\n\r\n // check meshesNames\r\n if (meshesNames && meshName) {\r\n if (meshesNames instanceof Array) {\r\n if (!meshesNames.indexOf(meshName)) {\r\n continue;\r\n }\r\n } else {\r\n if (meshName !== meshesNames) {\r\n continue;\r\n }\r\n }\r\n }\r\n\r\n // stl mesh name can be empty as well\r\n meshName = meshName || \"stlmesh\";\r\n\r\n const babylonMesh = new Mesh(meshName, scene);\r\n this._parseASCII(babylonMesh, matches[2]);\r\n if (meshes) {\r\n meshes.push(babylonMesh);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Load into a scene.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns true if successful or false otherwise\r\n */\r\n public load(scene: Scene, data: any, rootUrl: string): boolean {\r\n const result = this.importMesh(null, scene, data, rootUrl, null);\r\n return result;\r\n }\r\n\r\n /**\r\n * Load into an asset container.\r\n * @param scene The scene to load into\r\n * @param data The data to import\r\n * @param rootUrl The root url for scene and resources\r\n * @returns The loaded asset container\r\n */\r\n public loadAssetContainer(scene: Scene, data: string, rootUrl: string): AssetContainer {\r\n const container = new AssetContainer(scene);\r\n scene._blockEntityCollection = true;\r\n this.importMesh(null, scene, data, rootUrl, container.meshes);\r\n scene._blockEntityCollection = false;\r\n return container;\r\n }\r\n\r\n private _isBinary(data: any) {\r\n // check if file size is correct for binary stl\r\n const reader = new DataView(data);\r\n\r\n // A Binary STL header is 80 bytes, if the data size is not great than\r\n // that then it's not a binary STL.\r\n if (reader.byteLength <= 80) {\r\n return false;\r\n }\r\n\r\n const faceSize = (32 / 8) * 3 + (32 / 8) * 3 * 3 + 16 / 8;\r\n const nFaces = reader.getUint32(80, true);\r\n\r\n if (80 + 32 / 8 + nFaces * faceSize === reader.byteLength) {\r\n return true;\r\n }\r\n\r\n // check characters higher than ASCII to confirm binary\r\n const fileLength = reader.byteLength;\r\n for (let index = 0; index < fileLength; index++) {\r\n if (reader.getUint8(index) > 127) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _parseBinary(mesh: Mesh, data: ArrayBuffer) {\r\n const reader = new DataView(data);\r\n const faces = reader.getUint32(80, true);\r\n\r\n const dataOffset = 84;\r\n const faceLength = 12 * 4 + 2;\r\n\r\n let offset = 0;\r\n\r\n const positions = new Float32Array(faces * 3 * 3);\r\n const normals = new Float32Array(faces * 3 * 3);\r\n const indices = new Uint32Array(faces * 3);\r\n let indicesCount = 0;\r\n\r\n for (let face = 0; face < faces; face++) {\r\n const start = dataOffset + face * faceLength;\r\n const normalX = reader.getFloat32(start, true);\r\n const normalY = reader.getFloat32(start + 4, true);\r\n const normalZ = reader.getFloat32(start + 8, true);\r\n\r\n for (let i = 1; i <= 3; i++) {\r\n const vertexstart = start + i * 12;\r\n\r\n // ordering is intentional to match ascii import\r\n positions[offset] = reader.getFloat32(vertexstart, true);\r\n normals[offset] = normalX;\r\n\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 2] = normalY;\r\n normals[offset + 1] = normalZ;\r\n } else {\r\n positions[offset + 1] = reader.getFloat32(vertexstart + 4, true);\r\n positions[offset + 2] = reader.getFloat32(vertexstart + 8, true);\r\n\r\n normals[offset + 1] = normalY;\r\n normals[offset + 2] = normalZ;\r\n }\r\n\r\n offset += 3;\r\n }\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n indices[indicesCount] = indicesCount++;\r\n }\r\n\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n\r\n private _parseASCII(mesh: Mesh, solidData: string) {\r\n const positions = [];\r\n const normals = [];\r\n const indices = [];\r\n let indicesCount = 0;\r\n\r\n //load facets, ignoring loop as the standard doesn't define it can contain more than vertices\r\n let matches;\r\n while ((matches = this.facetsPattern.exec(solidData))) {\r\n const facet = matches[1];\r\n //one normal per face\r\n const normalMatches = this.normalPattern.exec(facet);\r\n this.normalPattern.lastIndex = 0;\r\n if (!normalMatches) {\r\n continue;\r\n }\r\n const normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];\r\n\r\n let vertexMatch;\r\n while ((vertexMatch = this.vertexPattern.exec(facet))) {\r\n if (!STLFileLoader.DO_NOT_ALTER_FILE_COORDINATES) {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));\r\n normals.push(normal[0], normal[1], normal[2]);\r\n } else {\r\n positions.push(Number(vertexMatch[1]), Number(vertexMatch[3]), Number(vertexMatch[5]));\r\n\r\n // Flipping the second and third component because inverted\r\n // when normal was declared.\r\n normals.push(normal[0], normal[2], normal[1]);\r\n }\r\n }\r\n indices.push(indicesCount++, indicesCount++, indicesCount++);\r\n this.vertexPattern.lastIndex = 0;\r\n }\r\n\r\n this.facetsPattern.lastIndex = 0;\r\n mesh.setVerticesData(VertexBuffer.PositionKind, positions);\r\n mesh.setVerticesData(VertexBuffer.NormalKind, normals);\r\n mesh.setIndices(indices);\r\n mesh.computeWorldMatrix(true);\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n SceneLoader.RegisterPlugin(new STLFileLoader());\r\n}\r\n"]}
|
@@ -1,13 +1,13 @@
|
|
1
|
-
import { GLTFLoaderExtension } from "./glTFLoader";
|
2
|
-
import { Scene } from "@babylonjs/core/scene";
|
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
|
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
|
12
|
-
loadShaderStringAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (shaderString: string) => void
|
13
|
-
}
|
1
|
+
import { GLTFLoaderExtension } from "./glTFLoader";
|
2
|
+
import type { Scene } from "@babylonjs/core/scene.js";
|
3
|
+
import type { IGLTFLoaderData } from "../glTFFileLoader";
|
4
|
+
import type { 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
|
+
}
|