From 6644a02022ee434f9cd2914816ce4093b83ac2c7 Mon Sep 17 00:00:00 2001 From: Chris Lewin Date: Thu, 8 Aug 2024 22:41:32 +0100 Subject: [PATCH] Multiple scenes picked randomly at startup --- scenes/manifest.json | 7 +++++++ shaders/g2p2g.wgsl | 2 +- src/main.js | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 scenes/manifest.json diff --git a/scenes/manifest.json b/scenes/manifest.json new file mode 100644 index 0000000..2354c89 --- /dev/null +++ b/scenes/manifest.json @@ -0,0 +1,7 @@ +[ + { "scene": "./scenes/damBreak.json", "name": "Dam Break" }, + { "scene": "./scenes/4Materials.json", "name": "Four Materials"}, + { "scene": "./scenes/plasticPress.json", "name": "Plastic Press"}, + { "scene": "./scenes/pyramid.json", "name": "Pyramid"}, + { "scene": "./scenes/sandPile.json", "name": "SandPile"} +] \ No newline at end of file diff --git a/shaders/g2p2g.wgsl b/shaders/g2p2g.wgsl index aae7f20..7ab0ba5 100644 --- a/shaders/g2p2g.wgsl +++ b/shaders/g2p2g.wgsl @@ -312,7 +312,7 @@ fn csMain( @builtin(local_invocation_index) indexInGroup: u32, @builtin(workgrou } else if(g_simConstants.mouseFunction == MouseFunctionGrab) { - particle.displacement = 0.7*g_simConstants.mouseVelocity*g_simConstants.deltaTime; + particle.displacement = g_simConstants.mouseVelocity*g_simConstants.deltaTime; } } } diff --git a/src/main.js b/src/main.js index 23c7b9d..2b845e7 100644 --- a/src/main.js +++ b/src/main.js @@ -19,6 +19,9 @@ let g_pause = false; let g_mouseRadius = 100; +let g_manifest; +let g_currentSceneName = 'No Scene Loaded' + init(); function init() @@ -31,7 +34,7 @@ function init() // Setup the UI sidebar ui.init(() => {g_reset = true;}, () => {g_pause = !g_pause;}); - loadSceneFromUrl('./scenes/damBreak.json'); + loadScenes() // Setup sim. // Sim will add to the list of insert handlers. @@ -475,4 +478,15 @@ async function pickLoadScene() const [result] = await window.showOpenFilePicker(); const file = await result.getFile(); loadScene(JSON.parse(await file.text())); -} \ No newline at end of file +} + +async function loadScenes() +{ + g_manifest = await (await fetch('./scenes/manifest.json')).json(); + + let sceneCount = g_manifest.length; + + let randomIndex = Math.floor(Math.random()*sceneCount); + + await loadSceneFromUrl(g_manifest[randomIndex].scene).then(() => {g_currentSceneName = g_manifest[randomIndex].name}); +} \ No newline at end of file