From 7e1b96909d6470c06222a554e31b1c35a064eb68 Mon Sep 17 00:00:00 2001 From: stephengold Date: Fri, 17 Jan 2025 23:31:20 -0800 Subject: [PATCH] SoftBodySharedSettings: add the sCreateCube() method --- .../joltjni/SoftBodySharedSettings.java | 21 ++++++++++++++++++- .../native/glue/s/SoftBodySharedSettings.cpp | 15 +++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/stephengold/joltjni/SoftBodySharedSettings.java b/src/main/java/com/github/stephengold/joltjni/SoftBodySharedSettings.java index e911a349..5e6fc059 100644 --- a/src/main/java/com/github/stephengold/joltjni/SoftBodySharedSettings.java +++ b/src/main/java/com/github/stephengold/joltjni/SoftBodySharedSettings.java @@ -1,5 +1,5 @@ /* -Copyright (c) 2024 Stephen Gold +Copyright (c) 2024-2025 Stephen Gold Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -173,6 +173,22 @@ public void optimize() { optimize(settingsVa); } + /** + * Create a cube with edge constraints, volume constraints, and faces. + * + * @param gridSize the desired number of points on each axis (≥1) + * @param gridSpacing the distance between adjacent points + * @return a counted reference to new settings + */ + public static SoftBodySharedSettingsRef sCreateCube( + int gridSize, float gridSpacing) { + long refVa = sCreateCubeNative(gridSize, gridSpacing); + SoftBodySharedSettingsRef result + = new SoftBodySharedSettingsRef(refVa, true); + + return result; + } + /** * Replace the materials. (native attribute: mMaterials) * @@ -327,6 +343,9 @@ native static void createConstraints(long settingsVa, native private static void setEmbedded(long settingsVa); + native private static long sCreateCubeNative( + int gridSize, float gridSpacing); + 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 22200bed..3ffc10fa 100644 --- a/src/main/native/glue/s/SoftBodySharedSettings.cpp +++ b/src/main/native/glue/s/SoftBodySharedSettings.cpp @@ -267,6 +267,21 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodySharedSetting pSettings->SetEmbedded(); } +/* + * Class: com_github_stephengold_joltjni_SoftBodySharedSettings + * Method: sCreateCubeNative + * Signature: (IF)J + */ +JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_SoftBodySharedSettings_sCreateCubeNative + (JNIEnv *, jclass, jint gridSize, jfloat gridSpacing) { + Ref ref + = SoftBodySharedSettings::sCreateCube(gridSize, gridSpacing); + Ref * const pResult + = new Ref(ref); + TRACE_NEW("Ref", pResult) + return reinterpret_cast (pResult); +} + /* * Class: com_github_stephengold_joltjni_SoftBodySharedSettings * Method: setMaterialsSingle