Skip to content

Commit

Permalink
Multiple scenes picked randomly at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Lewin committed Aug 8, 2024
1 parent 889fd25 commit 6644a02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions scenes/manifest.json
Original file line number Diff line number Diff line change
@@ -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"}
]
2 changes: 1 addition & 1 deletion shaders/g2p2g.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
18 changes: 16 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ let g_pause = false;

let g_mouseRadius = 100;

let g_manifest;
let g_currentSceneName = 'No Scene Loaded'

init();

function init()
Expand All @@ -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.
Expand Down Expand Up @@ -475,4 +478,15 @@ async function pickLoadScene()
const [result] = await window.showOpenFilePicker();
const file = await result.getFile();
loadScene(JSON.parse(await file.text()));
}
}

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});
}

0 comments on commit 6644a02

Please sign in to comment.