Optimize model loading 2
authorLanius Trolling <lanius@laniustrolling.dev>
Fri, 24 Feb 2023 17:30:43 +0000 (12:30 -0500)
committerLanius Trolling <lanius@laniustrolling.dev>
Fri, 24 Feb 2023 17:30:43 +0000 (12:30 -0500)
src/main/resources/static/init.js

index c4bfeffca22379dc79a49e7db1e0b0b26c98fe2b..b6d8673a4cf41693f77219e993d4b24ad0893bbd 100644 (file)
        });
 
        window.addEventListener("load", function () {
+               const mtlLoader = (new THREE.MTLLoader()).setPath("/assets/meshes/").setResourcePath("/assets/meshes/");
+               const objLoader = (new THREE.OBJLoader()).setPath("/assets/meshes/").setResourcePath("/assets/meshes/");
+
                async function loadObj(modelName) {
-                       const mtlLib = await (new THREE.MTLLoader()).setPath("/assets/meshes/").setResourcePath("/assets/meshes/").loadAsync(modelName + ".mtl");
+                       const mtlLib = await mtlLoader.loadAsync(modelName + ".mtl");
                        mtlLib.preload();
-                       return await (new THREE.OBJLoader()).setPath("/assets/meshes/").setResourcePath("/assets/meshes/").setMaterials(mtlLib).loadAsync(modelName + ".obj");
+                       return await objLoader.setMaterials(mtlLib).loadAsync(modelName + ".obj");
                }
 
                // Mesh viewing