|
@@ -20,6 +20,7 @@ import { GLTFValidation } from './glTFValidation';
|
|
|
import { Light } from 'babylonjs/Lights/light';
|
|
|
import { TransformNode } from 'babylonjs/Meshes/transformNode';
|
|
|
import { RequestFileError } from 'babylonjs/Misc/fileTools';
|
|
|
+import { StringTools } from 'babylonjs/Misc/stringTools';
|
|
|
|
|
|
interface IFileRequestInfo extends IFileRequest {
|
|
|
_lengthComputable?: boolean;
|
|
@@ -456,6 +457,8 @@ export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISc
|
|
|
private _progressCallback?: (event: ISceneLoaderProgressEvent) => void;
|
|
|
private _requests = new Array<IFileRequestInfo>();
|
|
|
|
|
|
+ private static magicBase64Encoded = "Z2xURg"; // "glTF" base64 encoded (without the quotes!)
|
|
|
+
|
|
|
/**
|
|
|
* Name of the loader ("gltf")
|
|
|
*/
|
|
@@ -634,13 +637,28 @@ export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISc
|
|
|
|
|
|
/** @hidden */
|
|
|
public canDirectLoad(data: string): boolean {
|
|
|
- return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
|
|
|
+ return (data.indexOf("asset") !== -1 && data.indexOf("version") !== -1)
|
|
|
+ || StringTools.StartsWith(data, "data:base64," + GLTFFileLoader.magicBase64Encoded)
|
|
|
+ || StringTools.StartsWith(data, "data:application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded)
|
|
|
+ || StringTools.StartsWith(data, "data:model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded);
|
|
|
}
|
|
|
|
|
|
/** @hidden */
|
|
|
- public directLoad(scene: Scene, data: string): any {
|
|
|
+ public directLoad(scene: Scene, data: string): Promise<any> {
|
|
|
+ if (StringTools.StartsWith(data, "base64," + GLTFFileLoader.magicBase64Encoded) ||
|
|
|
+ StringTools.StartsWith(data, "application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded) ||
|
|
|
+ StringTools.StartsWith(data, "model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded)) {
|
|
|
+ const arrayBuffer = Tools.DecodeBase64(data);
|
|
|
+
|
|
|
+ this._validate(scene, arrayBuffer);
|
|
|
+ return this._unpackBinaryAsync(new DataReader({
|
|
|
+ readAsync: (byteOffset, byteLength) => Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)),
|
|
|
+ byteLength: arrayBuffer.byteLength
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
this._validate(scene, data);
|
|
|
- return { json: this._parseJson(data) };
|
|
|
+ return Promise.resolve({ json: this._parseJson(data) });
|
|
|
}
|
|
|
|
|
|
/**
|