@babylonjs/loaders 6.40.0 → 6.41.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -30,14 +30,6 @@ export declare class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneL
|
|
30
30
|
* @returns if the data can be loaded directly
|
31
31
|
*/
|
32
32
|
canDirectLoad(): boolean;
|
33
|
-
/**
|
34
|
-
* Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license
|
35
|
-
* Loads a .ply from data array buffer
|
36
|
-
* if data array buffer is not ply, returns the original buffer
|
37
|
-
* @param data the data to load
|
38
|
-
* @returns the loaded buffer
|
39
|
-
*/
|
40
|
-
private _loadPLY;
|
41
33
|
/**
|
42
34
|
* Imports from the loaded gaussian splatting data and adds them to the scene
|
43
35
|
* @param _meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
package/SPLAT/splatFileLoader.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader.js";
|
2
|
-
import { Quaternion } from "@babylonjs/core/Maths/math.vector.js";
|
3
2
|
import { GaussianSplattingMesh } from "@babylonjs/core/Meshes/GaussianSplatting/gaussianSplattingMesh.js";
|
4
3
|
/**
|
5
4
|
* @experimental
|
@@ -41,137 +40,6 @@ export class SPLATFileLoader {
|
|
41
40
|
canDirectLoad() {
|
42
41
|
return false;
|
43
42
|
}
|
44
|
-
/**
|
45
|
-
* Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license
|
46
|
-
* Loads a .ply from data array buffer
|
47
|
-
* if data array buffer is not ply, returns the original buffer
|
48
|
-
* @param data the data to load
|
49
|
-
* @returns the loaded buffer
|
50
|
-
*/
|
51
|
-
_loadPLY(data) {
|
52
|
-
const ubuf = new Uint8Array(data);
|
53
|
-
const header = new TextDecoder().decode(ubuf.slice(0, 1024 * 10));
|
54
|
-
const headerEnd = "end_header\n";
|
55
|
-
const headerEndIndex = header.indexOf(headerEnd);
|
56
|
-
if (headerEndIndex < 0 || !header) {
|
57
|
-
return data;
|
58
|
-
}
|
59
|
-
const vertexCount = parseInt(/element vertex (\d+)\n/.exec(header)[1]);
|
60
|
-
let rowOffset = 0;
|
61
|
-
const offsets = {
|
62
|
-
double: 8,
|
63
|
-
int: 4,
|
64
|
-
uint: 4,
|
65
|
-
float: 4,
|
66
|
-
short: 2,
|
67
|
-
ushort: 2,
|
68
|
-
uchar: 1,
|
69
|
-
};
|
70
|
-
const properties = [];
|
71
|
-
const filtered = header
|
72
|
-
.slice(0, headerEndIndex)
|
73
|
-
.split("\n")
|
74
|
-
.filter((k) => k.startsWith("property "));
|
75
|
-
for (const prop of filtered) {
|
76
|
-
const [, type, name] = prop.split(" ");
|
77
|
-
properties.push({ name, type, offset: rowOffset });
|
78
|
-
if (!offsets[type])
|
79
|
-
throw new Error(`Unsupported property type: ${type}`);
|
80
|
-
rowOffset += offsets[type];
|
81
|
-
}
|
82
|
-
const rowLength = 3 * 4 + 3 * 4 + 4 + 4;
|
83
|
-
const SH_C0 = 0.28209479177387814;
|
84
|
-
const dataView = new DataView(data, headerEndIndex + headerEnd.length);
|
85
|
-
const buffer = new ArrayBuffer(rowLength * vertexCount);
|
86
|
-
const q = new Quaternion();
|
87
|
-
for (let i = 0; i < vertexCount; i++) {
|
88
|
-
const position = new Float32Array(buffer, i * rowLength, 3);
|
89
|
-
const scale = new Float32Array(buffer, i * rowLength + 12, 3);
|
90
|
-
const rgba = new Uint8ClampedArray(buffer, i * rowLength + 24, 4);
|
91
|
-
const rot = new Uint8ClampedArray(buffer, i * rowLength + 28, 4);
|
92
|
-
let r0 = 255;
|
93
|
-
let r1 = 0;
|
94
|
-
let r2 = 0;
|
95
|
-
let r3 = 0;
|
96
|
-
for (let propertyIndex = 0; propertyIndex < properties.length; propertyIndex++) {
|
97
|
-
const property = properties[propertyIndex];
|
98
|
-
let value;
|
99
|
-
switch (property.type) {
|
100
|
-
case "float":
|
101
|
-
value = dataView.getFloat32(property.offset + i * rowOffset, true);
|
102
|
-
break;
|
103
|
-
case "int":
|
104
|
-
value = dataView.getInt32(property.offset + i * rowOffset, true);
|
105
|
-
break;
|
106
|
-
default:
|
107
|
-
throw new Error(`Unsupported property type: ${property.type}`);
|
108
|
-
}
|
109
|
-
switch (property.name) {
|
110
|
-
case "x":
|
111
|
-
position[0] = value;
|
112
|
-
break;
|
113
|
-
case "y":
|
114
|
-
position[1] = value;
|
115
|
-
break;
|
116
|
-
case "z":
|
117
|
-
position[2] = value;
|
118
|
-
break;
|
119
|
-
case "scale_0":
|
120
|
-
scale[0] = Math.exp(value);
|
121
|
-
break;
|
122
|
-
case "scale_1":
|
123
|
-
scale[1] = Math.exp(value);
|
124
|
-
break;
|
125
|
-
case "scale_2":
|
126
|
-
scale[2] = Math.exp(value);
|
127
|
-
break;
|
128
|
-
case "red":
|
129
|
-
rgba[0] = value;
|
130
|
-
break;
|
131
|
-
case "green":
|
132
|
-
rgba[1] = value;
|
133
|
-
break;
|
134
|
-
case "blue":
|
135
|
-
rgba[2] = value;
|
136
|
-
break;
|
137
|
-
case "f_dc_0":
|
138
|
-
rgba[0] = (0.5 + SH_C0 * value) * 255;
|
139
|
-
break;
|
140
|
-
case "f_dc_1":
|
141
|
-
rgba[1] = (0.5 + SH_C0 * value) * 255;
|
142
|
-
break;
|
143
|
-
case "f_dc_2":
|
144
|
-
rgba[2] = (0.5 + SH_C0 * value) * 255;
|
145
|
-
break;
|
146
|
-
case "f_dc_3":
|
147
|
-
rgba[3] = (0.5 + SH_C0 * value) * 255;
|
148
|
-
break;
|
149
|
-
case "opacity":
|
150
|
-
rgba[3] = (1 / (1 + Math.exp(-value))) * 255;
|
151
|
-
break;
|
152
|
-
case "rot_0":
|
153
|
-
r0 = value;
|
154
|
-
break;
|
155
|
-
case "rot_1":
|
156
|
-
r1 = value;
|
157
|
-
break;
|
158
|
-
case "rot_2":
|
159
|
-
r2 = value;
|
160
|
-
break;
|
161
|
-
case "rot_3":
|
162
|
-
r3 = value;
|
163
|
-
break;
|
164
|
-
}
|
165
|
-
}
|
166
|
-
q.set(r1, r2, r3, r0);
|
167
|
-
q.normalize();
|
168
|
-
rot[0] = q.w * 128 + 128;
|
169
|
-
rot[1] = q.x * 128 + 128;
|
170
|
-
rot[2] = q.y * 128 + 128;
|
171
|
-
rot[3] = q.z * 128 + 128;
|
172
|
-
}
|
173
|
-
return buffer;
|
174
|
-
}
|
175
43
|
/**
|
176
44
|
* Imports from the loaded gaussian splatting data and adds them to the scene
|
177
45
|
* @param _meshesNames a string or array of strings of the mesh names that should be loaded from the file
|
@@ -202,7 +70,7 @@ export class SPLATFileLoader {
|
|
202
70
|
*/
|
203
71
|
loadAsync(scene, data, _rootUrl) {
|
204
72
|
const gaussianSplatting = new GaussianSplattingMesh("GaussianSplatting", null, scene);
|
205
|
-
return gaussianSplatting.loadDataAsync(
|
73
|
+
return gaussianSplatting.loadDataAsync(GaussianSplattingMesh.ConvertPLYToSplat(data));
|
206
74
|
}
|
207
75
|
// eslint-disable-next-line jsdoc/require-returns-check
|
208
76
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"splatFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/SPLAT/splatFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,UAAU,EAAE,6CAA+B;AACpD,OAAO,EAAE,qBAAqB,EAAE,0EAA4D;AAI5F;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAiBxB,+CAA+C;IAC/C;;OAEG;IACH;QApBA;;WAEG;QACI,SAAI,GAAG,OAAO,CAAC;QAEtB;;;WAGG;QACI,eAAU,GAAiC;YAC9C,gEAAgE;YAChE,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC5B,gEAAgE;YAChE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC7B,CAAC;IAMa,CAAC;IAEhB;;;OAGG;IACH,YAAY;QACR,OA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AAa,EAAE,KAAa,EAAE,QAAgB;QACzE,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;IAC9F,CAAC;CACJ;AAED,IAAI,WAAW,EAAE;IACb,0CAA0C;IAC1C,WAAW,CAAC,cAAc,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC;CACrD","sourcesContent":["import type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult, ISceneLoaderPluginExtensions } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { Quaternion } from \"core/Maths/math.vector\";\r\nimport { GaussianSplattingMesh } from \"core/Meshes/GaussianSplatting/gaussianSplattingMesh\";\r\nimport type { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\n/**\r\n * @experimental\r\n * SPLAT file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public name = \"splat\";\r\n\r\n /**\r\n * Defines the extensions the splat loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n */\r\n public extensions: ISceneLoaderPluginExtensions = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \".splat\": { isBinary: true },\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \".ply\": { isBinary: true },\r\n };\r\n\r\n //private _loadingOptions: SPLATLoadingOptions;\r\n /**\r\n * Creates loader for gaussian splatting files\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Instantiates a gaussian splatting file loader plugin.\r\n * @returns the created plugin\r\n */\r\n createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\r\n return new SPLATFileLoader();\r\n }\r\n\r\n /**\r\n * If the data string can be loaded directly.\r\n * @returns if the data can be loaded directly\r\n */\r\n public canDirectLoad(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license\r\n * Loads a .ply from data array buffer\r\n * if data array buffer is not ply, returns the original buffer\r\n * @param data the data to load\r\n * @returns the loaded buffer\r\n */\r\n private _loadPLY(data: any): ArrayBuffer {\r\n const ubuf = new Uint8Array(data);\r\n const header = new TextDecoder().decode(ubuf.slice(0, 1024 * 10));\r\n const headerEnd = \"end_header\\n\";\r\n const headerEndIndex = header.indexOf(headerEnd);\r\n if (headerEndIndex < 0 || !header) {\r\n return data;\r\n }\r\n const vertexCount = parseInt(/element vertex (\\d+)\\n/.exec(header)![1]);\r\n\r\n let rowOffset = 0;\r\n const offsets: Record<string, number> = {\r\n double: 8,\r\n int: 4,\r\n uint: 4,\r\n float: 4,\r\n short: 2,\r\n ushort: 2,\r\n uchar: 1,\r\n };\r\n\r\n type PlyProperty = {\r\n name: string;\r\n type: string;\r\n offset: number;\r\n };\r\n const properties: PlyProperty[] = [];\r\n const filtered = header\r\n .slice(0, headerEndIndex)\r\n .split(\"\\n\")\r\n .filter((k) => k.startsWith(\"property \"));\r\n for (const prop of filtered) {\r\n const [, type, name] = prop.split(\" \");\r\n properties.push({ name, type, offset: rowOffset });\r\n if (!offsets[type]) throw new Error(`Unsupported property type: ${type}`);\r\n rowOffset += offsets[type];\r\n }\r\n\r\n const rowLength = 3 * 4 + 3 * 4 + 4 + 4;\r\n const SH_C0 = 0.28209479177387814;\r\n\r\n const dataView = new DataView(data, headerEndIndex + headerEnd.length);\r\n const buffer = new ArrayBuffer(rowLength * vertexCount);\r\n const q = new Quaternion();\r\n\r\n for (let i = 0; i < vertexCount; i++) {\r\n const position = new Float32Array(buffer, i * rowLength, 3);\r\n const scale = new Float32Array(buffer, i * rowLength + 12, 3);\r\n const rgba = new Uint8ClampedArray(buffer, i * rowLength + 24, 4);\r\n const rot = new Uint8ClampedArray(buffer, i * rowLength + 28, 4);\r\n\r\n let r0: number = 255;\r\n let r1: number = 0;\r\n let r2: number = 0;\r\n let r3: number = 0;\r\n\r\n for (let propertyIndex = 0; propertyIndex < properties.length; propertyIndex++) {\r\n const property = properties[propertyIndex];\r\n let value;\r\n switch (property.type) {\r\n case \"float\":\r\n value = dataView.getFloat32(property.offset + i * rowOffset, true);\r\n break;\r\n case \"int\":\r\n value = dataView.getInt32(property.offset + i * rowOffset, true);\r\n break;\r\n default:\r\n throw new Error(`Unsupported property type: ${property.type}`);\r\n }\r\n\r\n switch (property.name) {\r\n case \"x\":\r\n position[0] = value;\r\n break;\r\n case \"y\":\r\n position[1] = value;\r\n break;\r\n case \"z\":\r\n position[2] = value;\r\n break;\r\n case \"scale_0\":\r\n scale[0] = Math.exp(value);\r\n break;\r\n case \"scale_1\":\r\n scale[1] = Math.exp(value);\r\n break;\r\n case \"scale_2\":\r\n scale[2] = Math.exp(value);\r\n break;\r\n case \"red\":\r\n rgba[0] = value;\r\n break;\r\n case \"green\":\r\n rgba[1] = value;\r\n break;\r\n case \"blue\":\r\n rgba[2] = value;\r\n break;\r\n case \"f_dc_0\":\r\n rgba[0] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"f_dc_1\":\r\n rgba[1] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"f_dc_2\":\r\n rgba[2] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"f_dc_3\":\r\n rgba[3] = (0.5 + SH_C0 * value) * 255;\r\n break;\r\n case \"opacity\":\r\n rgba[3] = (1 / (1 + Math.exp(-value))) * 255;\r\n break;\r\n case \"rot_0\":\r\n r0 = value;\r\n break;\r\n case \"rot_1\":\r\n r1 = value;\r\n break;\r\n case \"rot_2\":\r\n r2 = value;\r\n break;\r\n case \"rot_3\":\r\n r3 = value;\r\n break;\r\n }\r\n }\r\n\r\n q.set(r1, r2, r3, r0);\r\n q.normalize();\r\n rot[0] = q.w * 128 + 128;\r\n rot[1] = q.x * 128 + 128;\r\n rot[2] = q.y * 128 + 128;\r\n rot[3] = q.z * 128 + 128;\r\n }\r\n\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Imports from the loaded gaussian splatting data and adds them to the scene\r\n * @param _meshesNames a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene the scene the meshes should be added to\r\n * @param data the gaussian splatting data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n public async importMeshAsync(_meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult> {\r\n const gaussianSplatting = new GaussianSplattingMesh(\"GaussianSplatting\", null, scene);\r\n await gaussianSplatting.loadFileAsync(rootUrl);\r\n return {\r\n meshes: [gaussianSplatting],\r\n particleSystems: [],\r\n skeletons: [],\r\n animationGroups: [],\r\n transformNodes: [],\r\n geometries: [],\r\n lights: [],\r\n };\r\n }\r\n\r\n /**\r\n * Imports all objects from the loaded gaussian splatting data and adds them to the scene\r\n * @param scene the scene the objects should be added to\r\n * @param data the gaussian splatting data to load\r\n * @param _rootUrl root url to load from\r\n * @returns a promise which completes when objects have been loaded to the scene\r\n */\r\n public loadAsync(scene: Scene, data: any, _rootUrl: string): Promise<void> {\r\n const gaussianSplatting = new GaussianSplattingMesh(\"GaussianSplatting\", null, scene);\r\n return gaussianSplatting.loadDataAsync(this._loadPLY(data));\r\n }\r\n\r\n // eslint-disable-next-line jsdoc/require-returns-check\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 loadAssetContainerAsync(_scene: Scene, _data: string, _rootUrl: string): Promise<AssetContainer> {\r\n throw new Error(\"loadAssetContainerAsync not implemented for Gaussian Splatting loading\");\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n //Add this loader into the register plugin\r\n SceneLoader.RegisterPlugin(new SPLATFileLoader());\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"splatFileLoader.js","sourceRoot":"","sources":["../../../../dev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B,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,uDAAuD;IACvD;;;;;;OAMG;IACI,uBAAuB,CAAC,MAAa,EAAE,KAAa,EAAE,QAAgB;QACzE,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;IAC9F,CAAC;CACJ;AAED,IAAI,WAAW,EAAE;IACb,0CAA0C;IAC1C,WAAW,CAAC,cAAc,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC;CACrD","sourcesContent":["import type { ISceneLoaderPluginAsync, ISceneLoaderPluginFactory, ISceneLoaderPlugin, ISceneLoaderAsyncResult, ISceneLoaderPluginExtensions } from \"core/Loading/sceneLoader\";\r\nimport { SceneLoader } from \"core/Loading/sceneLoader\";\r\nimport { GaussianSplattingMesh } from \"core/Meshes/GaussianSplatting/gaussianSplattingMesh\";\r\nimport type { AssetContainer } from \"core/assetContainer\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\n/**\r\n * @experimental\r\n * SPLAT file type loader.\r\n * This is a babylon scene loader plugin.\r\n */\r\nexport class SPLATFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPluginFactory {\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public name = \"splat\";\r\n\r\n /**\r\n * Defines the extensions the splat loader is able to load.\r\n * force data to come in as an ArrayBuffer\r\n */\r\n public extensions: ISceneLoaderPluginExtensions = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \".splat\": { isBinary: true },\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n \".ply\": { isBinary: true },\r\n };\r\n\r\n //private _loadingOptions: SPLATLoadingOptions;\r\n /**\r\n * Creates loader for gaussian splatting files\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Instantiates a gaussian splatting file loader plugin.\r\n * @returns the created plugin\r\n */\r\n createPlugin(): ISceneLoaderPluginAsync | ISceneLoaderPlugin {\r\n return new SPLATFileLoader();\r\n }\r\n\r\n /**\r\n * If the data string can be loaded directly.\r\n * @returns if the data can be loaded directly\r\n */\r\n public canDirectLoad(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Imports from the loaded gaussian splatting data and adds them to the scene\r\n * @param _meshesNames a string or array of strings of the mesh names that should be loaded from the file\r\n * @param scene the scene the meshes should be added to\r\n * @param data the gaussian splatting data to load\r\n * @param rootUrl root url to load from\r\n * @returns a promise containing the loaded meshes, particles, skeletons and animations\r\n */\r\n public async importMeshAsync(_meshesNames: any, scene: Scene, data: any, rootUrl: string): Promise<ISceneLoaderAsyncResult> {\r\n const gaussianSplatting = new GaussianSplattingMesh(\"GaussianSplatting\", null, scene);\r\n await gaussianSplatting.loadFileAsync(rootUrl);\r\n return {\r\n meshes: [gaussianSplatting],\r\n particleSystems: [],\r\n skeletons: [],\r\n animationGroups: [],\r\n transformNodes: [],\r\n geometries: [],\r\n lights: [],\r\n };\r\n }\r\n\r\n /**\r\n * Imports all objects from the loaded gaussian splatting data and adds them to the scene\r\n * @param scene the scene the objects should be added to\r\n * @param data the gaussian splatting data to load\r\n * @param _rootUrl root url to load from\r\n * @returns a promise which completes when objects have been loaded to the scene\r\n */\r\n public loadAsync(scene: Scene, data: any, _rootUrl: string): Promise<void> {\r\n const gaussianSplatting = new GaussianSplattingMesh(\"GaussianSplatting\", null, scene);\r\n return gaussianSplatting.loadDataAsync(GaussianSplattingMesh.ConvertPLYToSplat(data));\r\n }\r\n\r\n // eslint-disable-next-line jsdoc/require-returns-check\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 loadAssetContainerAsync(_scene: Scene, _data: string, _rootUrl: string): Promise<AssetContainer> {\r\n throw new Error(\"loadAssetContainerAsync not implemented for Gaussian Splatting loading\");\r\n }\r\n}\r\n\r\nif (SceneLoader) {\r\n //Add this loader into the register plugin\r\n SceneLoader.RegisterPlugin(new SPLATFileLoader());\r\n}\r\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babylonjs/loaders",
|
3
|
-
"version": "6.
|
3
|
+
"version": "6.41.1",
|
4
4
|
"main": "index.js",
|
5
5
|
"module": "index.js",
|
6
6
|
"types": "index.d.ts",
|
@@ -18,10 +18,10 @@
|
|
18
18
|
"postcompile": "build-tools -c add-js-to-es6"
|
19
19
|
},
|
20
20
|
"devDependencies": {
|
21
|
-
"@babylonjs/core": "^6.
|
21
|
+
"@babylonjs/core": "^6.41.1",
|
22
22
|
"@dev/build-tools": "^1.0.0",
|
23
23
|
"@lts/loaders": "^1.0.0",
|
24
|
-
"babylonjs-gltf2interface": "^6.
|
24
|
+
"babylonjs-gltf2interface": "^6.41.1"
|
25
25
|
},
|
26
26
|
"peerDependencies": {
|
27
27
|
"@babylonjs/core": "^6.0.0",
|