diff --git a/src/dice/Dice.js b/src/dice/Dice.js index 21dcbfa..23dee18 100644 --- a/src/dice/Dice.js +++ b/src/dice/Dice.js @@ -27,13 +27,15 @@ class Dice { const mesh = await this.loadMesh(source, material, scene); meshes[type] = mesh; }; - await addToMeshes("d4", d4Source); - await addToMeshes("d6", d6Source); - await addToMeshes("d8", d8Source); - await addToMeshes("d10", d10Source); - await addToMeshes("d12", d12Source); - await addToMeshes("d20", d20Source); - await addToMeshes("d100", d100Source); + await Promise.all([ + addToMeshes("d4", d4Source), + addToMeshes("d6", d6Source), + addToMeshes("d8", d8Source), + addToMeshes("d10", d10Source), + addToMeshes("d12", d12Source), + addToMeshes("d20", d20Source), + addToMeshes("d100", d100Source), + ]); return meshes; } @@ -51,9 +53,14 @@ class Dice { static async loadMaterial(materialName, textures, scene) { let pbr = new PBRMaterial(materialName, scene); - pbr.albedoTexture = await importTextureAsync(textures.albedo); - pbr.normalTexture = await importTextureAsync(textures.normal); - pbr.metallicTexture = await importTextureAsync(textures.metalRoughness); + let [albedo, normal, metalRoughness] = await Promise.all([ + importTextureAsync(textures.albedo), + importTextureAsync(textures.normal), + importTextureAsync(textures.metalRoughness), + ]); + pbr.albedoTexture = albedo; + pbr.normalTexture = normal; + pbr.metallicTexture = metalRoughness; pbr.useRoughnessFromMetallicTextureAlpha = false; pbr.useRoughnessFromMetallicTextureGreen = true; pbr.useMetallnessFromMetallicTextureBlue = true; diff --git a/src/dice/diceTray/DiceTray.js b/src/dice/diceTray/DiceTray.js index 72bd936..1e9ec71 100644 --- a/src/dice/diceTray/DiceTray.js +++ b/src/dice/diceTray/DiceTray.js @@ -117,17 +117,33 @@ class DiceTray { } async loadMeshes() { - this.singleMesh = ( - await SceneLoader.ImportMeshAsync("", singleMeshSource, "", this.scene) - ).meshes[1]; + let [ + singleMeshes, + doubleMeshes, + singleAlbedoTexture, + singleNormalTexture, + singleMetalRoughnessTexture, + doubleAlbedoTexture, + doubleNormalTexture, + doubleMetalRoughnessTexture, + ] = await Promise.all([ + SceneLoader.ImportMeshAsync("", singleMeshSource, "", this.scene), + SceneLoader.ImportMeshAsync("", doubleMeshSource, "", this.scene), + importTextureAsync(singleAlbedo), + importTextureAsync(singleNormal), + importTextureAsync(singleMetalRoughness), + importTextureAsync(doubleAlbedo), + importTextureAsync(doubleNormal), + importTextureAsync(doubleMetalRoughness), + ]); + + this.singleMesh = singleMeshes.meshes[1]; this.singleMesh.id = "dice_tray_single"; this.singleMesh.name = "dice_tray"; let singleMaterial = new PBRMaterial("dice_tray_mat_single", this.scene); - singleMaterial.albedoTexture = await importTextureAsync(singleAlbedo); - singleMaterial.normalTexture = await importTextureAsync(singleNormal); - singleMaterial.metallicTexture = await importTextureAsync( - singleMetalRoughness - ); + singleMaterial.albedoTexture = singleAlbedoTexture; + singleMaterial.normalTexture = singleNormalTexture; + singleMaterial.metallicTexture = singleMetalRoughnessTexture; singleMaterial.useRoughnessFromMetallicTextureAlpha = false; singleMaterial.useRoughnessFromMetallicTextureGreen = true; singleMaterial.useMetallnessFromMetallicTextureBlue = true; @@ -137,17 +153,13 @@ class DiceTray { this.shadowGenerator.addShadowCaster(this.singleMesh); this.singleMesh.isVisible = this.size === "single"; - this.doubleMesh = ( - await SceneLoader.ImportMeshAsync("", doubleMeshSource, "", this.scene) - ).meshes[1]; + this.doubleMesh = doubleMeshes.meshes[1]; this.doubleMesh.id = "dice_tray_double"; this.doubleMesh.name = "dice_tray"; let doubleMaterial = new PBRMaterial("dice_tray_mat_double", this.scene); - doubleMaterial.albedoTexture = await importTextureAsync(doubleAlbedo); - doubleMaterial.normalTexture = await importTextureAsync(doubleNormal); - doubleMaterial.metallicTexture = await importTextureAsync( - doubleMetalRoughness - ); + doubleMaterial.albedoTexture = doubleAlbedoTexture; + doubleMaterial.normalTexture = doubleNormalTexture; + doubleMaterial.metallicTexture = doubleMetalRoughnessTexture; doubleMaterial.useRoughnessFromMetallicTextureAlpha = false; doubleMaterial.useRoughnessFromMetallicTextureGreen = true; doubleMaterial.useMetallnessFromMetallicTextureBlue = true; diff --git a/src/dice/gemstone/GemstoneDice.js b/src/dice/gemstone/GemstoneDice.js index 1d2b0b3..4545912 100644 --- a/src/dice/gemstone/GemstoneDice.js +++ b/src/dice/gemstone/GemstoneDice.js @@ -20,9 +20,14 @@ class GemstoneDice extends Dice { static async loadMaterial(materialName, textures, scene) { let pbr = new PBRMaterial(materialName, scene); - pbr.albedoTexture = await importTextureAsync(textures.albedo); - pbr.normalTexture = await importTextureAsync(textures.normal); - pbr.metallicTexture = await importTextureAsync(textures.metalRoughness); + let [albedo, normal, metalRoughness] = await Promise.all([ + importTextureAsync(textures.albedo), + importTextureAsync(textures.normal), + importTextureAsync(textures.metalRoughness), + ]); + pbr.albedoTexture = albedo; + pbr.normalTexture = normal; + pbr.metallicTexture = metalRoughness; pbr.useRoughnessFromMetallicTextureAlpha = false; pbr.useRoughnessFromMetallicTextureGreen = true; pbr.useMetallnessFromMetallicTextureBlue = true; diff --git a/src/dice/glass/GlassDice.js b/src/dice/glass/GlassDice.js index 62a5693..ec063dc 100644 --- a/src/dice/glass/GlassDice.js +++ b/src/dice/glass/GlassDice.js @@ -20,8 +20,13 @@ class GlassDice extends Dice { static async loadMaterial(materialName, textures, scene) { let pbr = new PBRMaterial(materialName, scene); - pbr.albedoTexture = await importTextureAsync(textures.albedo); - pbr.normalTexture = await importTextureAsync(textures.normal); + let [albedo, normal, mask] = await Promise.all([ + importTextureAsync(textures.albedo), + importTextureAsync(textures.normal), + importTextureAsync(textures.mask), + ]); + pbr.albedoTexture = albedo; + pbr.normalTexture = normal; pbr.roughness = 0.25; pbr.metallic = 0; pbr.subSurface.isRefractionEnabled = true; @@ -32,7 +37,7 @@ class GlassDice extends Dice { pbr.subSurface.minimumThickness = 10; pbr.subSurface.maximumThickness = 10; pbr.subSurface.tintColor = new Color3(43 / 255, 1, 115 / 255); - pbr.subSurface.thicknessTexture = await importTextureAsync(textures.mask); + pbr.subSurface.thicknessTexture = mask; pbr.subSurface.useMaskFromThicknessTexture = true; return pbr;