NvCloth Cloth Simulation Library
repository·master·Indexed 43 days ago
https://github.com/nvidiagameworks/nvclothA high-performance, low-level cloth simulation library for real-time interactive applications and games. It provides robust simulation and collision response for animated characters with minimal integration overhead. Includes support for PhysX compatibility (NvCloth 1.1.6 with PhysX 4.0, or NvCloth 1.1.5 with PhysX 3.4) and Android cross-compilation via android-cmake.
What's inside NvCloth
- NvCloth is a low-level cloth solver library designed for real-time interactive applications, such as games. It provides fast and robust cloth simulation, collision detection, and response mechanisms optimized for animated characters. The library is designed with a low-level interface to ensure minimal overhead and easy integration into existing engines.
Optimize ImGui for large lists using clipping
masterWhile ImGui is highly performant, submitting thousands of items (e.g., 1000+) to the UI can incur overhead because ImGui must still calculate the size of every item even if it is not visible.
To maintain high performance when browsing very large datasets:
- Manual Clipping: Perform clipping in your own code so you only submit the items currently visible on screen to ImGui.
- ImGuiListClipper: Use the built-in
ImGuiListClipperhelper to assist with calculating which items should be rendered based on scroll position.
Ensure PhysX / PxShared compatibility
masterWhen integrating NvCloth with PhysX, ensure the versions of
PxSharedmatch the requirements of the NvCloth version being used:- For NvCloth 1.1.6: Use the version of
PxSharedshipped with PhysX 4.0. - For PhysX 3.4: You must use NvCloth 1.1.5 instead of 1.1.6.
- For NvCloth 1.1.6: Use the version of
Manage large font textures and memory
masterIf you have a very large number of glyphs or multiple fonts, you may hit graphics driver texture size limits. To mitigate this:
- Specify texture width: Set
io.Fonts.TexDesiredWidthto control the aspect ratio (minimizing height). - Reduce oversampling: Lower
config.OversampleHto 2 or 1. - Limit glyph ranges: Only bake the specific character ranges required for your application.
- Specify texture width: Set
Identify Android architecture and features in CMakeLists.txt
masterWhen writing
CMakeLists.txtfiles intended to be used withandroid-cmake, you can use theANDROIDvariable to trigger platform-specific logic. To detect specific architectures, check theCMAKE_SYSTEM_PROCESSORvariable:Value Architecture/ABI armv5tearmeabiarmv6armeabi-v6 with VFParmv7-aarmeabi-v7avariantsaarch64arm64-v8ai686x86x86_64x86_64mipsmipsmips64mips64Other useful variables:
NEON: Set if the target ABI supports Neon.ANDROID_NATIVE_API_LEVEL: The target API level.ANDROID_NDK_RELEASE: The NDK version.ANDROID_RTTI: Set if RTTI is enabled by the selected STL.ANDROID_EXCEPTIONS: Set if exceptions are enabled by the selected STL.
if (ANDROID) message(STATUS "Hello from Android build!") if (CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") # ARMv7 specific logic endif() endif()Handle UTF-8 encoding and codepoint remapping
masterImGui requires all strings to use UTF-8 encoding.
- Avoid local code pages: Using local code pages (like CP-923 or CP-1251) in source literals will not work.
- C++11 Solution: Use the
u8"string"syntax for UTF-8 literals. - Manual Conversion: Convert text data to UTF-8 before loading or use
font->AddRemapChar()to map local codepage characters to Unicode codepoints.
Build android-cmake on Windows
masterTo build
android-cmakenatively on Windows, do not usecygwinas it is not supported. It is highly recommended to use Ninja for fast, multithreaded native builds.Using Ninja:
- Ensure CMake version is newer than 2.8.9.
- Download the latest Ninja from GitHub.
- Add
ninja.exeto your systemPATH. - Run CMake with the
-GNinjagenerator flag.
Using GNU Make (Alternative): If you prefer using a Windows port of GNU Make (such as
make.exefrom the Android NDK ormingw-make):- Add the path to your
make.exeto your systemPATH. - Run CMake using the
-G"MinGW Makefiles"generator (note: useMinGW Makefileseven if your make is not MinGW's). - Pass
-DCMAKE_MAKE_PROGRAM="<full/path/to/make.exe>"to CMake. - Build using
make.exeorcmake --build ..
# Recommended: Using Ninja cmake -GNinja <other_args> # Alternative: Using MinGW Makefiles cmake -G"MinGW Makefiles" -DCMAKE_MAKE_PROGRAM="C:/path/to/make.exe" <other_args>Integrate dear imgui (ImGui) into your project
masterImGui is a bloat-free, renderer-agnostic C++ GUI library designed for fast iteration in real-time 3D applications, tools, and debuggers. It is self-contained and does not require a specific build process; you can simply add its source files directly to your project.
Core Files to Include
To integrate ImGui, copy the following files into your project:
imgui.cppimgui.himgui_demo.cppimgui_draw.cppimgui_internal.himconfig.h(user-editable configuration)stb_rect_pack.hstb_textedit.hstb_truetype.h
Integration Workflow
- Input Handling: Your application must pass mouse and keyboard inputs to ImGui.
- Rendering: ImGui outputs vertex buffers and simple command-lists. You are responsible for rendering these buffers using your application's existing 3D pipeline (e.g., OpenGL, DirectX, Vulkan).
- Execution: Because ImGui does not touch graphics state directly, you can call ImGui commands anywhere in your code, such as during an algorithm execution or within your own rendering loop.
Build a C/C++ project for Android using android-cmake
masterTo compile native code for Android using the
android-cmakescripts, use theandroid.toolchain.cmakefile with the CMake command line. You must specify the NDK path, the build type (eitherReleaseorDebug), and the target ABI.Requirements:
- Android NDK (>= r5)
- CMake (>= v2.6.3, v2.8.9 recommended)
NDK Discovery Order:
ANDROID_NDKCMake variableANDROID_NDKenvironment variable- Paths in
ANDROID_NDK_SEARCH_PATHSCMake variable - Platform-specific locations (e.g., home folder, Windows "Program Files")
# Configure the project cmake -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake \ -DANDROID_NDK=<ndk_path> \ -DCMAKE_BUILD_TYPE=Release \ -DANDROID_ABI="armeabi-v7a with NEON" \ <source_path> # Build the project cmake --build .Merge icon fonts into a main font
masterTo use icons (like FontAwesome) alongside your main text, use
MergeMode = truein anImFontConfig. This combines the icon glyphs into the existing font atlas.Important: The character ranges array passed to
AddFont*functions is used lazily and is not copied. You must ensure the ranges array remains in scope for the entire duration of the font usage.// Load a first font ImGuiIO& io = ImGui::GetIO(); io.Fonts->AddFontDefault(); // Define ranges (must stay in scope) static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; ImFontConfig config; config.MergeMode = true; // Add the icon font using MergeMode io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, &config, icons_ranges);Access NvCloth documentation and API reference
masterDetailed information for NvCloth is organized into several locations within the repository:
- Release Notes, API User Guide, and Compiling Instructions: Located at
./NvCloth/docs/documentation/index.html. - API Documentation (Doxygen): Located at
./NvCloth/docs/doxy/index.html. - Changes and Platform Support: See
./NvCloth/ReleaseNotes.txt.
- Release Notes, API User Guide, and Compiling Instructions: Located at
Correctly append compiler flags in Android builds
masterWhen adding custom flags to your C or C++ targets, always append them to the existing flags rather than overwriting them.
android-cmakeprepopulatesCMAKE_C_FLAGSandCMAKE_CXX_FLAGSwith critical Android-specific flags.set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_c_flags}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}")set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}")