Skip to content

Commit

Permalink
SoftBodySharedSettings: add the setMaterials() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 26, 2024
1 parent dece1dc commit b0a5144
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
}
16 changes: 16 additions & 0 deletions src/main/native/glue/s/SoftBodySharedSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SoftBodySharedSettings *> (settingsVa);
const PhysicsMaterial * const pMaterial
= reinterpret_cast<PhysicsMaterial *> (materialVa);
RefConst<PhysicsMaterial> ref = pMaterial;
pSettings->mMaterials.clear();
pSettings->mMaterials.push_back(ref);
}

/*
* Class: com_github_stephengold_joltjni_SoftBodySharedSettings
* Method: toRef
Expand Down

0 comments on commit b0a5144

Please sign in to comment.