diff --git a/src/dice/galaxy/preview.png b/src/dice/galaxy/preview.png index d62962d..d03da88 100644 Binary files a/src/dice/galaxy/preview.png and b/src/dice/galaxy/preview.png differ diff --git a/src/dice/gemstone/GemstoneDice.js b/src/dice/gemstone/GemstoneDice.js new file mode 100644 index 0000000..2ad1c07 --- /dev/null +++ b/src/dice/gemstone/GemstoneDice.js @@ -0,0 +1,62 @@ +import * as BABYLON from "babylonjs"; + +import Dice from "../Dice"; + +import albedo from "./albedo.jpg"; +import metalRoughness from "./metalRoughness.jpg"; +import normal from "./normal.jpg"; + +class GemstoneDice extends Dice { + static meshes; + static material; + + static getDicePhysicalProperties(diceType) { + let properties = super.getDicePhysicalProperties(diceType); + return { mass: properties.mass * 1.5, friction: properties.friction }; + } + + static loadMaterial(materialName, textures, scene) { + let pbr = new BABYLON.PBRMaterial(materialName, scene); + pbr.albedoTexture = new BABYLON.Texture(textures.albedo); + pbr.normalTexture = new BABYLON.Texture(textures.normal); + pbr.metallicTexture = new BABYLON.Texture(textures.metalRoughness); + pbr.useRoughnessFromMetallicTextureAlpha = false; + pbr.useRoughnessFromMetallicTextureGreen = true; + pbr.useMetallnessFromMetallicTextureBlue = true; + + pbr.subSurface.isTranslucencyEnabled = true; + pbr.subSurface.translucencyIntensity = 1.0; + pbr.subSurface.minimumThickness = 5; + pbr.subSurface.maximumThickness = 10; + pbr.subSurface.tintColor = new BABYLON.Color3(190 / 255, 0, 220 / 255); + + return pbr; + } + + static async load(scene) { + if (!this.material) { + this.material = this.loadMaterial( + "gemstone_pbr", + { albedo, metalRoughness, normal }, + scene + ); + } + if (!this.meshes) { + this.meshes = await this.loadMeshes(this.material, scene); + } + } + + static async createInstance(diceType, scene) { + if (!this.material || !this.meshes) { + throw Error("Dice not loaded, call load before creating an instance"); + } + + return Dice.createInstance( + this.meshes[diceType], + this.getDicePhysicalProperties(diceType), + scene + ); + } +} + +export default GemstoneDice; diff --git a/src/dice/gemstone/albedo.jpg b/src/dice/gemstone/albedo.jpg new file mode 100755 index 0000000..bd507af Binary files /dev/null and b/src/dice/gemstone/albedo.jpg differ diff --git a/src/dice/gemstone/metalRoughness.jpg b/src/dice/gemstone/metalRoughness.jpg new file mode 100755 index 0000000..e5107c9 Binary files /dev/null and b/src/dice/gemstone/metalRoughness.jpg differ diff --git a/src/dice/gemstone/normal.jpg b/src/dice/gemstone/normal.jpg new file mode 100755 index 0000000..4739fa6 Binary files /dev/null and b/src/dice/gemstone/normal.jpg differ diff --git a/src/dice/gemstone/preview.png b/src/dice/gemstone/preview.png new file mode 100644 index 0000000..b5f0502 Binary files /dev/null and b/src/dice/gemstone/preview.png differ diff --git a/src/dice/glass/GlassDice.js b/src/dice/glass/GlassDice.js new file mode 100644 index 0000000..8714d0e --- /dev/null +++ b/src/dice/glass/GlassDice.js @@ -0,0 +1,64 @@ +import * as BABYLON from "babylonjs"; + +import Dice from "../Dice"; + +import albedo from "./albedo.jpg"; +import mask from "./mask.png"; +import normal from "./normal.jpg"; + +class GlassDice extends Dice { + static meshes; + static material; + + static getDicePhysicalProperties(diceType) { + let properties = super.getDicePhysicalProperties(diceType); + return { mass: properties.mass * 1.5, friction: properties.friction }; + } + + static loadMaterial(materialName, textures, scene) { + let pbr = new BABYLON.PBRMaterial(materialName, scene); + pbr.albedoTexture = new BABYLON.Texture(textures.albedo); + pbr.normalTexture = new BABYLON.Texture(textures.normal); + pbr.roughness = 0.25; + pbr.metallic = 0; + pbr.subSurface.isRefractionEnabled = true; + pbr.subSurface.indexOfRefraction = 2.0; + pbr.subSurface.refractionIntensity = 1.2; + pbr.subSurface.isTranslucencyEnabled = true; + pbr.subSurface.translucencyIntensity = 2.5; + pbr.subSurface.minimumThickness = 10; + pbr.subSurface.maximumThickness = 10; + pbr.subSurface.tintColor = new BABYLON.Color3(43 / 255, 1, 115 / 255); + pbr.subSurface.thicknessTexture = new BABYLON.Texture(textures.mask); + pbr.subSurface.useMaskFromThicknessTexture = true; + + return pbr; + } + + static async load(scene) { + if (!this.material) { + this.material = this.loadMaterial( + "glass_pbr", + { albedo, mask, normal }, + scene + ); + } + if (!this.meshes) { + this.meshes = await this.loadMeshes(this.material, scene); + } + } + + static async createInstance(diceType, scene) { + if (!this.material || !this.meshes) { + throw Error("Dice not loaded, call load before creating an instance"); + } + + return Dice.createInstance( + this.meshes[diceType], + this.getDicePhysicalProperties(diceType), + scene + ); + } +} + +export default GlassDice; diff --git a/src/dice/glass/albedo.jpg b/src/dice/glass/albedo.jpg new file mode 100755 index 0000000..7aa1702 Binary files /dev/null and b/src/dice/glass/albedo.jpg differ diff --git a/src/dice/glass/mask.png b/src/dice/glass/mask.png new file mode 100644 index 0000000..20e8e81 Binary files /dev/null and b/src/dice/glass/mask.png differ diff --git a/src/dice/glass/normal.jpg b/src/dice/glass/normal.jpg new file mode 100755 index 0000000..de3f0e7 Binary files /dev/null and b/src/dice/glass/normal.jpg differ diff --git a/src/dice/glass/preview.png b/src/dice/glass/preview.png new file mode 100644 index 0000000..f612ec2 Binary files /dev/null and b/src/dice/glass/preview.png differ diff --git a/src/dice/index.js b/src/dice/index.js index 1f6315e..62e22b9 100644 --- a/src/dice/index.js +++ b/src/dice/index.js @@ -6,6 +6,8 @@ import NebulaDice from "./nebula/NebulaDice"; import SunriseDice from "./sunrise/SunriseDice"; import SunsetDice from "./sunset/SunsetDice"; import WalnutDice from "./walnut/WalnutDice"; +import GlassDice from "./glass/GlassDice"; +import GemstoneDice from "./gemstone/GemstoneDice"; import GalaxyPreview from "./galaxy/preview.png"; import IronPreview from "./iron/preview.png"; @@ -13,6 +15,8 @@ import NebulaPreview from "./nebula/preview.png"; import SunrisePreview from "./sunrise/preview.png"; import SunsetPreview from "./sunset/preview.png"; import WalnutPreview from "./walnut/preview.png"; +import GlassPreview from "./glass/preview.png"; +import GemstonePreview from "./gemstone/preview.png"; export const diceClasses = { galaxy: GalaxyDice, @@ -21,6 +25,8 @@ export const diceClasses = { sunset: SunsetDice, iron: IronDice, walnut: WalnutDice, + glass: GlassDice, + gemstone: GemstoneDice, }; export const dicePreviews = { @@ -30,6 +36,8 @@ export const dicePreviews = { sunset: SunsetPreview, iron: IronPreview, walnut: WalnutPreview, + glass: GlassPreview, + gemstone: GemstonePreview, }; export const dice = Object.keys(diceClasses).map((key) => ({ diff --git a/src/dice/iron/preview.png b/src/dice/iron/preview.png index 9d07c22..ddc5885 100644 Binary files a/src/dice/iron/preview.png and b/src/dice/iron/preview.png differ diff --git a/src/dice/nebula/preview.png b/src/dice/nebula/preview.png index c884c2b..992a1a4 100644 Binary files a/src/dice/nebula/preview.png and b/src/dice/nebula/preview.png differ diff --git a/src/dice/sunrise/preview.png b/src/dice/sunrise/preview.png index ebd1f5e..afe95bb 100644 Binary files a/src/dice/sunrise/preview.png and b/src/dice/sunrise/preview.png differ diff --git a/src/dice/sunset/preview.png b/src/dice/sunset/preview.png index 9a220ae..64eb54c 100644 Binary files a/src/dice/sunset/preview.png and b/src/dice/sunset/preview.png differ diff --git a/src/dice/walnut/preview.png b/src/dice/walnut/preview.png index b7c409f..a6dc0c4 100644 Binary files a/src/dice/walnut/preview.png and b/src/dice/walnut/preview.png differ