ammo.js softbody demo on p5 editor cannon ball game Lv1 sample source linked
here is sample source https://editor.p5js.org/setapolo/sketches/e7xZ2cfjV https://preview.p5js.org/setapolo/present/e7xZ2cfjV
Visual impression: A jelly-like blob squashes on impact and quickly regains its shape, bouncing with a soft, lively feel.
Technique names: Ammo.js (Bullet Physics, wasm) btSoftBody with Three.js; mixed rigid/soft-body simulation; ray-cast projectile.
Explanation: The scene runs in a btSoftRigidDynamicsWorld with gravity, advanced each frame by stepSimulation. The soft object is built from a triangle mesh via CreateFromTriMesh and solved as a mass-spring network of nodes and links. Volume feel is sustained by set_kPR (internal pressure). Return speed and damping are tuned with set_kDP and surface friction with set_kDF. Material stiffness uses set_m_kLST / set_m_kAST. Soft–soft and soft–rigid contacts are enabled by set_collisions(0x11). For rendering, Three.js updates the mesh each frame by mapping geometry vertices to soft-body nodes (get_m_nodes) and writing back positions and normals; vertices are pre-merged with BufferGeometryUtils.mergeVertices so indexing matches. On click, a ray gives direction, a rigid ball is created (btSphereShape) and launched using setLinearVelocity. Camera and lights are standard Three.js, drawing every frame in sync with the physics step to show smooth deformation and recovery.
Comments
Post a Comment