diff --git a/src/main/java/com/github/stephengold/joltjni/BodyInterface.java b/src/main/java/com/github/stephengold/joltjni/BodyInterface.java index 93810c97..9216d166 100644 --- a/src/main/java/com/github/stephengold/joltjni/BodyInterface.java +++ b/src/main/java/com/github/stephengold/joltjni/BodyInterface.java @@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal import com.github.stephengold.joltjni.enumerate.EMotionType; import com.github.stephengold.joltjni.readonly.ConstBodyCreationSettings; import com.github.stephengold.joltjni.readonly.ConstBodyId; +import com.github.stephengold.joltjni.readonly.ConstSoftBodyCreationSettings; import com.github.stephengold.joltjni.readonly.QuatArg; import com.github.stephengold.joltjni.readonly.RVec3Arg; import com.github.stephengold.joltjni.readonly.Vec3Arg; @@ -188,6 +189,22 @@ public BodyId createAndAddBody( return result; } + /** + * Create a soft body and add it to the physics system. + * + * @param settings the settings to use (not null, unaffected) + * @param activationMode whether to activate the body (not null) + * @return the ID of the created body, or an invalid ID when out of bodies + */ + public BodyId createAndAddSoftBody(ConstSoftBodyCreationSettings settings, + EActivation activationMode) { + Body body = createSoftBody(settings); + BodyId result = body.getId(); + addBody(result, activationMode); + + return result; + } + /** * Create a rigid body using the specified settings. * @@ -229,6 +246,24 @@ public TwoBodyConstraint createConstraint( return result; } + /** + * Create a soft body using the specified settings. + * + * @param settings the settings to use (not null, unaffected) + * @return the new body + */ + public Body createSoftBody(ConstSoftBodyCreationSettings settings) { + long bodyInterfaceVa = va(); + long settingsVa = settings.va(); + long bodyVa = createSoftBody(bodyInterfaceVa, settingsVa); + if (bodyVa == 0L) { + throw new IllegalStateException("ran out of bodies"); + } + Body result = new Body(bodyVa); + + return result; + } + /** * Deactivate the specified body. * @@ -679,6 +714,9 @@ native private static long createBody( native private static long createConstraint(long bodyInterfaceVa, long settingsVa, long body1IdVa, long body2IdVa); + native private static long createSoftBody( + long bodyInterfaceVa, long settingsVa); + native private static void deactivateBody( long bodyInterfaceVa, long bodyIdVa); diff --git a/src/main/native/glue/bo/BodyInterface.cpp b/src/main/native/glue/bo/BodyInterface.cpp index 37a06d6a..1759c66a 100644 --- a/src/main/native/glue/bo/BodyInterface.cpp +++ b/src/main/native/glue/bo/BodyInterface.cpp @@ -166,6 +166,21 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_BodyInterface_create return reinterpret_cast (pResult); } +/* + * Class: com_github_stephengold_joltjni_BodyInterface + * Method: createSoftBody + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_BodyInterface_createSoftBody + (JNIEnv *, jclass, jlong bodyInterfaceVa, jlong settingsVa) { + BodyInterface * const pInterface + = reinterpret_cast (bodyInterfaceVa); + const SoftBodyCreationSettings * const pSettings + = reinterpret_cast (settingsVa); + const Body * const pResult = pInterface->CreateSoftBody(*pSettings); + return reinterpret_cast (pResult); +} + /* * Class: com_github_stephengold_joltjni_BodyInterface * Method: deactivateBody