From b0a5144672013b97851fa52cbc8d7f07c0457cf1 Mon Sep 17 00:00:00 2001 From: stephengold Date: Tue, 26 Nov 2024 10:10:48 -0800 Subject: [PATCH] SoftBodySharedSettings: add the setMaterials() method --- .../joltjni/SoftBodySharedSettings.java | 13 +++++++++++++ .../native/glue/s/SoftBodySharedSettings.cpp | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/main/java/com/github/stephengold/joltjni/SoftBodySharedSettings.java b/src/main/java/com/github/stephengold/joltjni/SoftBodySharedSettings.java index c1334fb2..24c60460 100644 --- a/src/main/java/com/github/stephengold/joltjni/SoftBodySharedSettings.java +++ b/src/main/java/com/github/stephengold/joltjni/SoftBodySharedSettings.java @@ -172,6 +172,17 @@ public void optimize() { long settingsVa = va(); optimize(settingsVa); } + + /** + * Alter the materials. (native attribute: mMaterials) + * + * @param material the desired material, or {@code null} + */ + public void setMaterials(PhysicsMaterial material) { + long settingsVa = va(); + long materialVa = (material == null) ? 0L : material.va(); + setMaterialsSingle(settingsVa, materialVa); + } // ************************************************************************* // ConstSoftBodySharedSettings methods @@ -318,5 +329,7 @@ native private static void createConstraints(long settingsVa, native private static void setEmbedded(long settingsVa); + native static void setMaterialsSingle(long settingsVa, long materialVa); + native private static long toRef(long settingsVa); } diff --git a/src/main/native/glue/s/SoftBodySharedSettings.cpp b/src/main/native/glue/s/SoftBodySharedSettings.cpp index 14125d02..5ed5a125 100644 --- a/src/main/native/glue/s/SoftBodySharedSettings.cpp +++ b/src/main/native/glue/s/SoftBodySharedSettings.cpp @@ -267,6 +267,22 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodySharedSetting pSettings->SetEmbedded(); } +/* + * Class: com_github_stephengold_joltjni_SoftBodySharedSettings + * Method: setMaterialsSingle + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodySharedSettings_setMaterialsSingle + (JNIEnv *, jclass, jlong settingsVa, jlong materialVa) { + SoftBodySharedSettings * const pSettings + = reinterpret_cast (settingsVa); + const PhysicsMaterial * const pMaterial + = reinterpret_cast (materialVa); + RefConst ref = pMaterial; + pSettings->mMaterials.clear(); + pSettings->mMaterials.push_back(ref); +} + /* * Class: com_github_stephengold_joltjni_SoftBodySharedSettings * Method: toRef