Repository navigation
Add save/load of full particle state (2D & 3D) - #4
Open
wiesenthal wants to merge 1 commit into
Open
wiesenthal wants to merge 1 commit into
wiesenthal wants to merge 1 commit into
Conversation
Adds the ability to snapshot the entire live simulation — the position, velocity and type of every particle — to a file and restore it later, for both the 2D and 3D WebGPU engines. - New `useStateManager` composable: compact binary container (magic + version + JSON header + raw Float32 particle data) with download/parse helpers. - New `StatePanel` component: Save State / Load State buttons, wired into the left sidebar of both engines under a "Save / Load State" section. - 2D/3D engines: `saveState` reads the GPU particle buffer back via the existing `readBufferFromGPU` helper; `loadState` rebuilds the sim from the file, injecting the saved matrices/colors/particles instead of regenerating randomly (guarded by a `pendingLoadedState` seam in `initLife`). Engine mismatch (2D file in 3D, or vice versa) is rejected with a toast. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the ability to save and load the full state of a simulation — the position, velocity and type of every particle — for both the 2D and 3D WebGPU engines. This complements the existing preset system (which only stores rules/radii/colors/settings) by capturing the exact live snapshot, so you can freeze a run and resume it later pixel-for-pixel.
How it works
composables/useStateManager.ts— serializes a snapshot to a compact binary container and parses it back:JSON would balloon for millions of particles, so the particle data stays as raw little-endian floats. Includes
downloadState()andreadStateFile()helpers with toast feedback.components/particle-life/StatePanel.vue— a small Save State / Load State panel (hidden file input for load), added to the left sidebar of both engines under a new "Save / Load State" collapse section.ParticleLifeGpu.vue/ParticleLifeGpu3D.vue:saveState()reads the live GPU particle buffer back via the existingreadBufferFromGPUhelper (afteronSubmittedWorkDone()so the snapshot is current) and downloads it.loadState(file)parses the file, applies the saved particle/species counts and world size, then rebuilds the simulation — injecting the saved matrices, colors and particle buffer instead of regenerating randomly. This reuses the existinginitLife()rebuild path through a smallpendingLoadedStateseam, so buffer/pipeline recreation stays in one place.Buffer layouts handled: 2D = 5 floats/particle
[x, y, vx, vy, type], 3D = 7 floats/particle[x, y, z, vx, vy, vz, type].Testing
<script>block withoxc-parserto confirm no syntax/TS errors.🤖 Generated with Claude Code