Skip to content

Support simple soft body #897

@xiejiangzhi

Description

@xiejiangzhi

Joltc API for create a simple soft body.

https://github.com/xiejiangzhi/lovr/blob/mychange_v3/src/joltc_ext/ext.cpp#L109

Here, the parameters of the Lua interface are all written together
Then, I output the vertex point position and directly added an interface to the physics...

https://github.com/xiejiangzhi/lovr/blob/mychange_v3/src/myext/physics.c#L102
https://github.com/xiejiangzhi/lovr/blob/mychange_v3/src/myext/l_physics_world.c#L58
https://github.com/xiejiangzhi/lovr/blob/mychange_v3/src/myext/l_physics.c#L12

For data output, we only need to output the vertex positions; the face indices remain unchanged. I simply output a blob containing all the vertex positions, then
newMesh({ { 'VertexPosition', 'vec3' } }, out_vs_blob) and mesh:setVertices(out_vs_blob)
It basically works, but there's absolutely no design interface—it's purely functional.

Looking at Jolt's example code, the cube and sphere examples only require setting edge and volume constraints. I've added these to my code too, but I'm unsure what edge and volume data to input. So I haven't tested those yet, though the code itself isn't significantly different.

Compatibility issues: The soft body's shape is nil in lovr.
The if(!collider->shapes) check in collider:setTag needs to be removed.
In the callback, have to check collider->shapes if it is NULL.

 void luax_pushshape(lua_State* L, Shape* shape) {
+  if (!shape) {
+    lua_pushnil(L);
+    return;
+  }
+
 static Shape* subshapeToShape(Collider* collider, JPH_SubShapeID id, uint32_t* triangle) {
   Shape* shape = collider->shapes;
+  if (!shape) return NULL;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions