UNPKG

@babylonjs/loaders

Version:

The Babylon.js file loaders library is an extension you can use to load different 3D file types into a Babylon scene.

62 lines 2.92 kB
import * as tslib_1 from "tslib"; import { GLTFLoaderExtension } from "./glTFLoader"; import { GLTFUtils } from "./glTFLoaderUtils"; import { EComponentType } from "./glTFLoaderInterfaces"; import { GLTFLoader, GLTFLoaderBase } from "./glTFLoader"; var BinaryExtensionBufferName = "binary_glTF"; /** @hidden */ var GLTFBinaryExtension = /** @class */ (function (_super) { tslib_1.__extends(GLTFBinaryExtension, _super); function GLTFBinaryExtension() { return _super.call(this, "KHR_binary_glTF") || this; } GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) { var extensionsUsed = data.json.extensionsUsed; if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) { return false; } this._bin = data.bin; onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl)); return true; }; GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) { if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) { return false; } if (id !== BinaryExtensionBufferName) { return false; } onSuccess(this._bin); return true; }; GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) { var texture = gltfRuntime.textures[id]; var source = gltfRuntime.images[texture.source]; if (!source.extensions || !(this.name in source.extensions)) { return false; } var sourceExt = source.extensions[this.name]; var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView]; var buffer = GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, EComponentType.UNSIGNED_BYTE); onSuccess(buffer); return true; }; GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) { var shader = gltfRuntime.shaders[id]; if (!shader.extensions || !(this.name in shader.extensions)) { return false; } var binaryExtensionShader = shader.extensions[this.name]; var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView]; var shaderBytes = GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, EComponentType.UNSIGNED_BYTE); setTimeout(function () { var shaderString = GLTFUtils.DecodeBufferToText(shaderBytes); onSuccess(shaderString); }); return true; }; return GLTFBinaryExtension; }(GLTFLoaderExtension)); export { GLTFBinaryExtension }; GLTFLoader.RegisterExtension(new GLTFBinaryExtension()); //# sourceMappingURL=glTFBinaryExtension.js.map