https://github.com/flan8er/leptos_verlet

https://github.com/flan8er/leptos_verlet

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.4%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: Flan8er
  • License: mit
  • Language: Rust
  • Default Branch: main
  • Size: 52.1 MB
Statistics
  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 8
Created about 1 year ago · Last pushed 11 months ago
Metadata Files
Readme License

README.md

crates.io docs.rs

Leptos Verlet

An engine that allows the addition of interactive verlet simulations into any leptos app.

  • Spawned objects are interactive through container bounds allowing for a uniquely interactive component.
  • A host of prebuilt objects using an agnostic "builder" layer that allows the developer to define and spawn custom objects into the simulation.

Check out my other projects here!

Cloth Pendulum Rope

Implementation

Using

```rust use leptos_verlet::prelude::*;

[component]

pub fn App() -> impl IntoView { let simulation_container = NodeRef::

::new();

let active_modifier: RwSignal<ModificationTarget> = RwSignal::new(ModificationTarget::None);

view! {
    <VerletConfigProvider/>

    <main class="w-screen h-screen flex items-center justify-center overflow-hidden relative">
        <ElementPane active_modifier/>
        <InfoModal active_modifier/>

        <div
            node_ref=simulation_container
            class="w-full h-full relative"
        >
            <VerletCanvas parent_element=simulation_container/>

            <MouseMonitor active_modifier/>
        </div>

        <ControlPane active_modifier/>
    </main>
}

} ```

Custom Meshes

In the ^1.2 update, a new function is exposed to allow custom meshes to be imported and attached to a simulation Point. The mesh will track, follow, and reorient relative to whatever Point it's attached to.

```rust // Imports and spawns the mesh into the simulation // Must be ran inside a reactive context model_loader("/static/monkey.glb", "monkey.glb", 0);

// To attach the mesh to a SpawnNode: SpawnNode { attachment: Some(String::from("monkey.glb")), ..default() } ```

The SpawnNode type also takes in an extra argument: "attachment". This is an optional String where the value is the same modelname used in the modelloader function ("monkey.glb" in the above code). This essentially tells the mesh to follow whatever point it is attached to.

Screenshot 2025-07-01 at 8 50 10 AM

Custom Shapes

Any shape can be created, simulated, and styled using the built in spawner that reads from a Vec of SpawnNode.

```rust pub struct SpawnNode { /// The point to spawn. pub point: Point, /// A list of connections this point should share with other points. pub connection: Option>, /// The material of the point. Note, any 'locked' point will be displayed as red. pub pointmaterial: MaterialType, /// A specified material for each connection. pub connectionmaterial: Option>, /// The mesh of the point. pub pointmesh: MeshType, /// A specified mesh for each connection. pub connectionmesh: Option>, /// The diameter of the point. pub pointsize: f32, /// The thickness of the connection. pub connectionsize: Option>, /// The model_name for any imported model to be attached to this point. pub attachment: Option, }

pub struct SpawnRequest { pub mesh_network: Vec, } ```

Shown below is a verbose use case for spawning a square to be used to visualize the mesh network system. As much as feasible, a system should be created for programmatically generating these structures.

The desired vertices of the shape are constructed (below the initial velocity is set to zero by giving the point the same "current position" as "previous position"), and then added to a SpawnNode with the desired connection vertices and mesh/material styling. A mesh_network is then constructed and sent as a spawn request.

```rust use leptos_verlet::prelude::*;

let spawnrequest = expectcontext::();

let squaresize = 0.45; let pointsize = 0.025; let sticksize = 0.01; let pointmesh = MeshType::Sphere; let stickmesh = MeshType::Cuboid; let pointmaterial = MaterialType::Color([1., 1., 1., 1.]); // The spawned points will be pure white let stick_material = MaterialType::Color([1., 1., 1., 0.75]); // The spawned connections will be opaque white

let bottomleft = Vec3::new(-squaresize / 2., 0., 0.); let bottomright = Vec3::new(squaresize / 2., 0., 0.); let topright = Vec3::new(squaresize / 2., squaresize, 0.); let topleft = Vec3::new(-squaresize / 2., squaresize, 0.);

let bottomleftnode = SpawnNode { point: Point::new(bottomleft, bottomleft, false), connection: Some(vec![topleft, bottomright]), pointmaterial: pointmaterial.clone(), connectionmaterial: Some(vec![stickmaterial.clone(), stickmaterial.clone()]), pointmesh: pointmesh.clone(), connectionmesh: Some(vec![stickmesh.clone(), stickmesh.clone()]), pointsize: pointsize, connectionsize: Some(vec![sticksize, sticksize]), ..default() }; let bottomrightnode = SpawnNode { point: Point::new(bottomright, bottomright + 0.5, false), connection: Some(vec![bottomleft, topright, topleft]), pointmaterial: pointmaterial.clone(), connectionmaterial: Some(vec![ stickmaterial.clone(), stickmaterial.clone(), stickmaterial.clone(), ]), pointmesh: pointmesh.clone(), connectionmesh: Some(vec![ stickmesh.clone(), stickmesh.clone(), stickmesh.clone(), ]), pointsize: pointsize, connectionsize: Some(vec![sticksize, sticksize, sticksize]), ..default() }; let toprightnode = SpawnNode { point: Point::new(topright, topright, false), connection: Some(vec![bottomright, topleft]), pointmaterial: pointmaterial.clone(), connectionmaterial: Some(vec![stickmaterial.clone(), stickmaterial.clone()]), pointmesh: pointmesh.clone(), connectionmesh: Some(vec![stickmesh.clone(), stickmesh.clone()]), pointsize: pointsize, connectionsize: Some(vec![sticksize, sticksize]), ..default() }; let topleftnode = SpawnNode { point: Point::new(topleft, topleft, false), connection: Some(vec![bottomleft, topright, bottomright]), pointmaterial: pointmaterial.clone(), connectionmaterial: Some(vec![ stickmaterial.clone(), stickmaterial.clone(), stickmaterial.clone(), ]), pointmesh: pointmesh.clone(), connectionmesh: Some(vec![ stickmesh.clone(), stickmesh.clone(), stickmesh.clone(), ]), pointsize: pointsize, connectionsize: Some(vec![sticksize, sticksize, sticksize]), ..default() }; let meshnetwork = vec![ bottomleftnode, bottomrightnode, toprightnode, topleft_node, ];

let spawncustom = { let spawnrequest = spawnrequest.clone(); let meshnetwork = meshnetwork.clone(); move || { spawnrequest .send(SpawnRequest::new(meshnetwork.clone())) .ok(); } }; ```

Future Changes

  • Ideal gas law: soft bodies with constant (relatively) volumes

Compatibility

| Crate version | Compatible Leptos version | | ------------- | ------------------------- | | 1.0 | 0.7 | | 2.0 | 0.8 |

Owner

  • Login: Flan8er
  • Kind: user

GitHub Events

Total
  • Release event: 5
  • Watch event: 1
  • Push event: 14
  • Public event: 1
  • Create event: 5
Last Year
  • Release event: 5
  • Watch event: 1
  • Push event: 14
  • Public event: 1
  • Create event: 5

Issues and Pull Requests

Last synced: 10 months ago

Packages

  • Total packages: 1
  • Total downloads:
    • cargo 3,016 total
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 10
  • Total maintainers: 1
crates.io: leptos_verlet

An engine to perform Verlet simulations in Leptos apps.

  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 3,016 Total
Rankings
Dependent repos count: 21.2%
Dependent packages count: 28.1%
Average: 48.0%
Downloads: 94.8%
Maintainers (1)
Last synced: 10 months ago

Dependencies

Cargo.lock cargo
  • 631 dependencies
Cargo.toml cargo
example/Cargo.toml cargo
leptos_verlet/Cargo.toml cargo
example/package-lock.json npm
  • tailwindcss 4.1.10
  • tailwindcss-animate 1.0.7
example/package.json npm
  • tailwindcss ^4.1.8 development
  • tailwindcss-animate ^1.0.7