Advertisement
Guest User

Untitled

a guest
Dec 12th, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function AssetLoader(isManaged, useDracoCompression, useKtxCompression) {
  2.     if (isManaged === true) {
  3.         this.manager = new nixps.cloudflow.visual.THREE.LoadingManager();
  4.     }
  5.  
  6.     if (useDracoCompression === true) {
  7.         this.dracoLoader = new nixps.cloudflow.visual.DRACOLoader()
  8.         this.dracoLoader.setDecoderPath('common/Render3D/draco/');
  9.         this.dracoLoader.preload();
  10.     }
  11.  
  12.     if (useKtxCompression === true) {
  13.         this.ktxLoader = new nixps.cloudflow.visual.KTX2Loader();
  14.         this.ktxLoader.setTranscoderPath('common/Render3D/basis');
  15.     }
  16. }
  17.  
  18. AssetLoader.prototype = {
  19.     constructor: AssetLoader,
  20.  
  21.     initialize: function(renderer) {
  22.         if (this.dracoLoader !== undefined) {
  23.             this._getGltfLoader().setDRACOLoader(this.dracoLoader);
  24.         }
  25.  
  26.         if(this.ktxLoader !== undefined) {
  27.             this._getGltfLoader().setKTX2Loader(this.ktxLoader.detectSupport(renderer.rendererInternal));
  28.         }
  29.     },
  30.  
  31.     loadGlb: function (filePath) {
  32.         return this._getGltfLoader().loadAsync(filePath);
  33.     },
  34.  
  35.     loadEnvironment: function (filePath) {
  36.         var that = this;
  37.         return $.Deferred(function (pDefer) {
  38.             that._getHDRLoader().load(filePath, function (tex) {
  39.                 tex.mapping = nixps.cloudflow.visual.THREE.EquirectangularReflectionMapping;
  40.                 pDefer.resolve(tex);
  41.             }, function () { }, pDefer.reject);
  42.         })
  43.     },
  44.  
  45.     loadTexture: function (filePath) {
  46.         var that = this;
  47.         return $.Deferred(function (pDefer) {
  48.             that._getTextureLoader().load(filePath, function (tex) {
  49.                 pDefer.resolve(tex);
  50.             }, function () { }, pDefer.reject);
  51.         })
  52.     },
  53.  
  54.     getManager: function () {
  55.         return this.manager;
  56.     },
  57.  
  58.     _getGltfLoader: function () {
  59.         return this.manager !== undefined ? new nixps.cloudflow.visual.GLTFLoader(this.manager) : new nixps.cloudflow.visual.GLTFLoader();
  60.     },
  61.  
  62.     _getHDRLoader: function () {
  63.         return this.manager !== undefined ? new nixps.cloudflow.visual.RGBELoader(this.manager) : new nixps.cloudflow.visual.RGBELoader();
  64.     },
  65.  
  66.     _getTextureLoader: function () {
  67.         return this.manager !== undefined ? new nixps.cloudflow.visual.TextureLoader(this.manager) : new nixps.cloudflow.visual.TextureLoader();
  68.     }
  69. }
  70.  
  71. module.exports = AssetLoader
  72.  
  73. \\\\\\\\\\\\\\
  74.             var assetLoader = new AssetLoader(true, true, true);
  75.             assetLoader.initialize(this.renderer);
  76.  
  77.             assetLoader.loadGlb(that.options.gltfPath).then(function (gltf) {
  78.                 that.scene.add(gltf.scene);
  79.  
  80.                 if (gltf.cameras && gltf.cameras.length !== 0) {
  81.                     that.activeCamera = gltf.cameras[0]
  82.                     that.cameras = gltf.cameras;
  83.                 } else if (gltf.cameras.length === 0) {
  84.                     throw new Error("No cameras were found in the scene.")
  85.                 }
  86.  
  87.                 if (that.options.responsive) {
  88.                     that._resize();
  89.                 }
  90.  
  91.                 that.controls = new nixps.cloudflow.visual.OrbitControls(that.activeCamera, that.renderer.getCanvas());
  92.  
  93.                 gltf.scene.traverse(function (node) {
  94.                     if (node instanceof THREE.Mesh) {
  95.                         if (node.material !== null) {
  96.                             node.material.envMap = that.scene.environment;
  97.                         }
  98.                     }
  99.                 })
  100.  
  101.                 //Start rendering loop
  102.                 that.renderer._update(that.scene, that.controls);
  103.  
  104.             }, function (progress) { },
  105.                 function (error) { console.error(error) })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement