Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function AssetLoader(isManaged, useDracoCompression, useKtxCompression) {
- if (isManaged === true) {
- this.manager = new nixps.cloudflow.visual.THREE.LoadingManager();
- }
- if (useDracoCompression === true) {
- this.dracoLoader = new nixps.cloudflow.visual.DRACOLoader()
- this.dracoLoader.setDecoderPath('common/Render3D/draco/');
- this.dracoLoader.preload();
- }
- if (useKtxCompression === true) {
- this.ktxLoader = new nixps.cloudflow.visual.KTX2Loader();
- this.ktxLoader.setTranscoderPath('common/Render3D/basis');
- }
- }
- AssetLoader.prototype = {
- constructor: AssetLoader,
- initialize: function(renderer) {
- if (this.dracoLoader !== undefined) {
- this._getGltfLoader().setDRACOLoader(this.dracoLoader);
- }
- if(this.ktxLoader !== undefined) {
- this._getGltfLoader().setKTX2Loader(this.ktxLoader.detectSupport(renderer.rendererInternal));
- }
- },
- loadGlb: function (filePath) {
- return this._getGltfLoader().loadAsync(filePath);
- },
- loadEnvironment: function (filePath) {
- var that = this;
- return $.Deferred(function (pDefer) {
- that._getHDRLoader().load(filePath, function (tex) {
- tex.mapping = nixps.cloudflow.visual.THREE.EquirectangularReflectionMapping;
- pDefer.resolve(tex);
- }, function () { }, pDefer.reject);
- })
- },
- loadTexture: function (filePath) {
- var that = this;
- return $.Deferred(function (pDefer) {
- that._getTextureLoader().load(filePath, function (tex) {
- pDefer.resolve(tex);
- }, function () { }, pDefer.reject);
- })
- },
- getManager: function () {
- return this.manager;
- },
- _getGltfLoader: function () {
- return this.manager !== undefined ? new nixps.cloudflow.visual.GLTFLoader(this.manager) : new nixps.cloudflow.visual.GLTFLoader();
- },
- _getHDRLoader: function () {
- return this.manager !== undefined ? new nixps.cloudflow.visual.RGBELoader(this.manager) : new nixps.cloudflow.visual.RGBELoader();
- },
- _getTextureLoader: function () {
- return this.manager !== undefined ? new nixps.cloudflow.visual.TextureLoader(this.manager) : new nixps.cloudflow.visual.TextureLoader();
- }
- }
- module.exports = AssetLoader
- \\\\\\\\\\\\\\
- var assetLoader = new AssetLoader(true, true, true);
- assetLoader.initialize(this.renderer);
- assetLoader.loadGlb(that.options.gltfPath).then(function (gltf) {
- that.scene.add(gltf.scene);
- if (gltf.cameras && gltf.cameras.length !== 0) {
- that.activeCamera = gltf.cameras[0]
- that.cameras = gltf.cameras;
- } else if (gltf.cameras.length === 0) {
- throw new Error("No cameras were found in the scene.")
- }
- if (that.options.responsive) {
- that._resize();
- }
- that.controls = new nixps.cloudflow.visual.OrbitControls(that.activeCamera, that.renderer.getCanvas());
- gltf.scene.traverse(function (node) {
- if (node instanceof THREE.Mesh) {
- if (node.material !== null) {
- node.material.envMap = that.scene.environment;
- }
- }
- })
- //Start rendering loop
- that.renderer._update(that.scene, that.controls);
- }, function (progress) { },
- function (error) { console.error(error) })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement