Moved dice asset loading to be parallel
This commit is contained in:
parent
2330709e62
commit
a5d14c0fa4
@ -27,13 +27,15 @@ class Dice {
|
|||||||
const mesh = await this.loadMesh(source, material, scene);
|
const mesh = await this.loadMesh(source, material, scene);
|
||||||
meshes[type] = mesh;
|
meshes[type] = mesh;
|
||||||
};
|
};
|
||||||
await addToMeshes("d4", d4Source);
|
await Promise.all([
|
||||||
await addToMeshes("d6", d6Source);
|
addToMeshes("d4", d4Source),
|
||||||
await addToMeshes("d8", d8Source);
|
addToMeshes("d6", d6Source),
|
||||||
await addToMeshes("d10", d10Source);
|
addToMeshes("d8", d8Source),
|
||||||
await addToMeshes("d12", d12Source);
|
addToMeshes("d10", d10Source),
|
||||||
await addToMeshes("d20", d20Source);
|
addToMeshes("d12", d12Source),
|
||||||
await addToMeshes("d100", d100Source);
|
addToMeshes("d20", d20Source),
|
||||||
|
addToMeshes("d100", d100Source),
|
||||||
|
]);
|
||||||
return meshes;
|
return meshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,9 +53,14 @@ class Dice {
|
|||||||
|
|
||||||
static async loadMaterial(materialName, textures, scene) {
|
static async loadMaterial(materialName, textures, scene) {
|
||||||
let pbr = new PBRMaterial(materialName, scene);
|
let pbr = new PBRMaterial(materialName, scene);
|
||||||
pbr.albedoTexture = await importTextureAsync(textures.albedo);
|
let [albedo, normal, metalRoughness] = await Promise.all([
|
||||||
pbr.normalTexture = await importTextureAsync(textures.normal);
|
importTextureAsync(textures.albedo),
|
||||||
pbr.metallicTexture = await importTextureAsync(textures.metalRoughness);
|
importTextureAsync(textures.normal),
|
||||||
|
importTextureAsync(textures.metalRoughness),
|
||||||
|
]);
|
||||||
|
pbr.albedoTexture = albedo;
|
||||||
|
pbr.normalTexture = normal;
|
||||||
|
pbr.metallicTexture = metalRoughness;
|
||||||
pbr.useRoughnessFromMetallicTextureAlpha = false;
|
pbr.useRoughnessFromMetallicTextureAlpha = false;
|
||||||
pbr.useRoughnessFromMetallicTextureGreen = true;
|
pbr.useRoughnessFromMetallicTextureGreen = true;
|
||||||
pbr.useMetallnessFromMetallicTextureBlue = true;
|
pbr.useMetallnessFromMetallicTextureBlue = true;
|
||||||
|
@ -117,17 +117,33 @@ class DiceTray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadMeshes() {
|
async loadMeshes() {
|
||||||
this.singleMesh = (
|
let [
|
||||||
await SceneLoader.ImportMeshAsync("", singleMeshSource, "", this.scene)
|
singleMeshes,
|
||||||
).meshes[1];
|
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.id = "dice_tray_single";
|
||||||
this.singleMesh.name = "dice_tray";
|
this.singleMesh.name = "dice_tray";
|
||||||
let singleMaterial = new PBRMaterial("dice_tray_mat_single", this.scene);
|
let singleMaterial = new PBRMaterial("dice_tray_mat_single", this.scene);
|
||||||
singleMaterial.albedoTexture = await importTextureAsync(singleAlbedo);
|
singleMaterial.albedoTexture = singleAlbedoTexture;
|
||||||
singleMaterial.normalTexture = await importTextureAsync(singleNormal);
|
singleMaterial.normalTexture = singleNormalTexture;
|
||||||
singleMaterial.metallicTexture = await importTextureAsync(
|
singleMaterial.metallicTexture = singleMetalRoughnessTexture;
|
||||||
singleMetalRoughness
|
|
||||||
);
|
|
||||||
singleMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
singleMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
||||||
singleMaterial.useRoughnessFromMetallicTextureGreen = true;
|
singleMaterial.useRoughnessFromMetallicTextureGreen = true;
|
||||||
singleMaterial.useMetallnessFromMetallicTextureBlue = true;
|
singleMaterial.useMetallnessFromMetallicTextureBlue = true;
|
||||||
@ -137,17 +153,13 @@ class DiceTray {
|
|||||||
this.shadowGenerator.addShadowCaster(this.singleMesh);
|
this.shadowGenerator.addShadowCaster(this.singleMesh);
|
||||||
this.singleMesh.isVisible = this.size === "single";
|
this.singleMesh.isVisible = this.size === "single";
|
||||||
|
|
||||||
this.doubleMesh = (
|
this.doubleMesh = doubleMeshes.meshes[1];
|
||||||
await SceneLoader.ImportMeshAsync("", doubleMeshSource, "", this.scene)
|
|
||||||
).meshes[1];
|
|
||||||
this.doubleMesh.id = "dice_tray_double";
|
this.doubleMesh.id = "dice_tray_double";
|
||||||
this.doubleMesh.name = "dice_tray";
|
this.doubleMesh.name = "dice_tray";
|
||||||
let doubleMaterial = new PBRMaterial("dice_tray_mat_double", this.scene);
|
let doubleMaterial = new PBRMaterial("dice_tray_mat_double", this.scene);
|
||||||
doubleMaterial.albedoTexture = await importTextureAsync(doubleAlbedo);
|
doubleMaterial.albedoTexture = doubleAlbedoTexture;
|
||||||
doubleMaterial.normalTexture = await importTextureAsync(doubleNormal);
|
doubleMaterial.normalTexture = doubleNormalTexture;
|
||||||
doubleMaterial.metallicTexture = await importTextureAsync(
|
doubleMaterial.metallicTexture = doubleMetalRoughnessTexture;
|
||||||
doubleMetalRoughness
|
|
||||||
);
|
|
||||||
doubleMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
doubleMaterial.useRoughnessFromMetallicTextureAlpha = false;
|
||||||
doubleMaterial.useRoughnessFromMetallicTextureGreen = true;
|
doubleMaterial.useRoughnessFromMetallicTextureGreen = true;
|
||||||
doubleMaterial.useMetallnessFromMetallicTextureBlue = true;
|
doubleMaterial.useMetallnessFromMetallicTextureBlue = true;
|
||||||
|
@ -20,9 +20,14 @@ class GemstoneDice extends Dice {
|
|||||||
|
|
||||||
static async loadMaterial(materialName, textures, scene) {
|
static async loadMaterial(materialName, textures, scene) {
|
||||||
let pbr = new PBRMaterial(materialName, scene);
|
let pbr = new PBRMaterial(materialName, scene);
|
||||||
pbr.albedoTexture = await importTextureAsync(textures.albedo);
|
let [albedo, normal, metalRoughness] = await Promise.all([
|
||||||
pbr.normalTexture = await importTextureAsync(textures.normal);
|
importTextureAsync(textures.albedo),
|
||||||
pbr.metallicTexture = await importTextureAsync(textures.metalRoughness);
|
importTextureAsync(textures.normal),
|
||||||
|
importTextureAsync(textures.metalRoughness),
|
||||||
|
]);
|
||||||
|
pbr.albedoTexture = albedo;
|
||||||
|
pbr.normalTexture = normal;
|
||||||
|
pbr.metallicTexture = metalRoughness;
|
||||||
pbr.useRoughnessFromMetallicTextureAlpha = false;
|
pbr.useRoughnessFromMetallicTextureAlpha = false;
|
||||||
pbr.useRoughnessFromMetallicTextureGreen = true;
|
pbr.useRoughnessFromMetallicTextureGreen = true;
|
||||||
pbr.useMetallnessFromMetallicTextureBlue = true;
|
pbr.useMetallnessFromMetallicTextureBlue = true;
|
||||||
|
@ -20,8 +20,13 @@ class GlassDice extends Dice {
|
|||||||
|
|
||||||
static async loadMaterial(materialName, textures, scene) {
|
static async loadMaterial(materialName, textures, scene) {
|
||||||
let pbr = new PBRMaterial(materialName, scene);
|
let pbr = new PBRMaterial(materialName, scene);
|
||||||
pbr.albedoTexture = await importTextureAsync(textures.albedo);
|
let [albedo, normal, mask] = await Promise.all([
|
||||||
pbr.normalTexture = await importTextureAsync(textures.normal);
|
importTextureAsync(textures.albedo),
|
||||||
|
importTextureAsync(textures.normal),
|
||||||
|
importTextureAsync(textures.mask),
|
||||||
|
]);
|
||||||
|
pbr.albedoTexture = albedo;
|
||||||
|
pbr.normalTexture = normal;
|
||||||
pbr.roughness = 0.25;
|
pbr.roughness = 0.25;
|
||||||
pbr.metallic = 0;
|
pbr.metallic = 0;
|
||||||
pbr.subSurface.isRefractionEnabled = true;
|
pbr.subSurface.isRefractionEnabled = true;
|
||||||
@ -32,7 +37,7 @@ class GlassDice extends Dice {
|
|||||||
pbr.subSurface.minimumThickness = 10;
|
pbr.subSurface.minimumThickness = 10;
|
||||||
pbr.subSurface.maximumThickness = 10;
|
pbr.subSurface.maximumThickness = 10;
|
||||||
pbr.subSurface.tintColor = new Color3(43 / 255, 1, 115 / 255);
|
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;
|
pbr.subSurface.useMaskFromThicknessTexture = true;
|
||||||
|
|
||||||
return pbr;
|
return pbr;
|
||||||
|
Loading…
Reference in New Issue
Block a user