### NvCloth Cross-Thread Profiling Start Macro (C++) Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/_callbacks_8h-source.html Defines the NV_CLOTH_PROFILE_START_CROSSTHREAD macro for starting a profiling zone across threads. It checks if the NvCloth profiler is available and, if so, calls its zoneStart method. This macro is intended for use with C++ code. ```cpp #define NV_CLOTH_PROFILE_START_CROSSTHREAD(x, y) \ (GetNvClothProfiler()!=nullptr? \ GetNvClothProfiler()->zoneStart(x, true, y):nullptr) ``` -------------------------------- ### GET /dxContext/releaseContext Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/functions_0x72.html Releases the DirectX context manager callback. ```APIDOC ## GET /dxContext/releaseContext ### Description Releases the resources associated with the DxContextManagerCallback. ### Method GET ### Endpoint /nv::cloth::DxContextManagerCallback/releaseContext ### Response #### Success Response (200) - **message** (string) - Context released successfully. #### Response Example { "message": "context_released" } ``` -------------------------------- ### GET /solver/state Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/functions_func_0x67.html Retrieves the current state and configuration of the cloth solver, including inter-collision settings. ```APIDOC ## GET /solver/state ### Description Fetches global solver settings, including the list of active cloths and inter-collision parameters. ### Method GET ### Endpoint /nv::cloth::Solver ### Parameters #### Query Parameters - **metric** (string) - Required - The solver metric to retrieve (e.g., 'InterCollisionStiffness', 'NumCloths') ### Request Example { "metric": "getNumCloths" } ### Response #### Success Response (200) - **count** (integer) - The number of cloths currently managed by the solver. #### Response Example { "count": 10 } ``` -------------------------------- ### Collision Setup API Source: https://context7.com/nvidiagameworks/nvcloth/llms.txt Configures collision with spheres, capsules, planes, and triangles, and enables continuous collision detection. ```APIDOC ## Collision Setup NvCloth supports collision with spheres, capsules (sphere pairs), convex shapes (plane combinations), and triangles. Collision shapes can be animated between frames. ### Setup Sphere Collision ```cpp // Setup sphere collision (PxVec4: x, y, z, radius) physx::PxVec4 spheres[] = { physx::PxVec4(0.0f, 5.0f, 0.0f, 1.5f), // Sphere at (0,5,0) with radius 1.5 physx::PxVec4(2.0f, 5.0f, 0.0f, 1.0f) // Sphere at (2,5,0) with radius 1.0 }; // Set spheres (start and target positions for interpolation) cloth->setSpheres( nv::cloth::Range(spheres, spheres + 2), nv::cloth::Range(spheres, spheres + 2) ); ``` ### Setup Capsule Collision ```cpp // Setup capsules (connect spheres by index pairs) uint32_t capsuleIndices[] = {0, 1}; // Capsule from sphere 0 to sphere 1 cloth->setCapsules( nv::cloth::Range(capsuleIndices, capsuleIndices + 2), 0, // first capsule index 1 // last capsule index (exclusive, so this sets 1 capsule) ); ``` ### Setup Plane Collision and Convex Shapes ```cpp // Setup plane collision (PxVec4: normal.x, normal.y, normal.z, distance) physx::PxVec4 planes[] = { physx::PxVec4(0.0f, 1.0f, 0.0f, 0.0f), // Ground plane (y=0) physx::PxVec4(1.0f, 0.0f, 0.0f, -5.0f) // Wall plane (x=-5) }; cloth->setPlanes( nv::cloth::Range(planes, planes + 2), 0, cloth->getNumPlanes() ); // Enable planes as convex shapes (bitmask of plane indices) uint32_t convexMasks[] = { (1 << 0), // Convex 0: just the ground plane (1 << 0) | (1 << 1) // Convex 1: intersection of ground and wall }; cloth->setConvexes( nv::cloth::Range(convexMasks, convexMasks + 2), 0, cloth->getNumConvexes() ); ``` ### Setup Triangle Collision ```cpp // Setup triangle collision (3 vertices per triangle) physx::PxVec3 triVertices[] = { physx::PxVec3(-2.0f, 3.0f, -2.0f), physx::PxVec3( 2.0f, 3.0f, -2.0f), physx::PxVec3( 0.0f, 3.0f, 2.0f) }; cloth->setTriangles( nv::cloth::Range(triVertices, triVertices + 3), 0, 1 // triangle range [0, 1) ); ``` ### Enable Continuous Collision and Set Friction/Mass Scale ```cpp // Enable continuous collision detection for fast-moving objects cloth->enableContinuousCollision(true); // Set collision friction cloth->setFriction(0.5f); // Set collision mass scale (affects collision response) cloth->setCollisionMassScale(1.0f); ``` ``` -------------------------------- ### Retrieve Cloth Simulation Parameters Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth-members.html Examples of getter methods used to retrieve physical properties and simulation coefficients from the Cloth object. ```cpp float getLiftCoefficient() const = 0; float getLinearDrag() const = 0; float getLinearInertia() const = 0; float getMotionConstraintBias() const = 0; float getMotionConstraintScale() const = 0; float getMotionConstraintStiffness() const = 0; ``` -------------------------------- ### Load Default ImGui Font Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/samples/external/imgui/1.49/extra_fonts/README.txt Loads the default ImGui font. This is the simplest way to get a font active in your application. ```cpp ImGuiIO& io = ImGui::GetIO(); io.Fonts->AddFontDefault(); ``` -------------------------------- ### Initialize NvCloth Factory for CPU Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/documentation/UserGuide/Index.html Demonstrates the creation and cleanup of a CPU-based factory using the NvCloth library. ```cpp #include nv::cloth::Factory* factory = NvClothCreateFactoryCPU(); if(factory==nullptr) { //error } //At cleanup: NvClothDestroyFactory(factory); ``` -------------------------------- ### POST /solver/beginSimulation Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_solver.html Begins a simulation frame with a specified time step. ```APIDOC ## POST /solver/beginSimulation ### Description Initializes the simulation frame for the current time step. ### Method POST ### Endpoint /solver/beginSimulation ### Parameters #### Query Parameters - **dt** (float) - Required - The time step for the simulation frame. ### Request Example { "dt": 0.016 } ### Response #### Success Response (200) - **result** (boolean) - Returns true if the simulation frame started successfully. ``` -------------------------------- ### POST /solver/simulation/begin Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_solver.html Begins a simulation frame with a specified delta time. ```APIDOC ## POST /solver/simulation/begin ### Description Initializes a new simulation frame. Returns false if there is no pending work to simulate. ### Method POST ### Endpoint /solver/simulation/begin ### Parameters #### Query Parameters - **dt** (float) - Required - The delta time for the current simulation frame. ### Response #### Success Response (200) - **canSimulate** (boolean) - Returns true if simulation should proceed, false otherwise. ``` -------------------------------- ### GET /solver/numCloths Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_solver.html Retrieves the total number of cloth objects currently managed by the solver. ```APIDOC ## GET /solver/numCloths ### Description Returns the count of cloth objects added to the solver. ### Method GET ### Endpoint /solver/numCloths ### Response #### Success Response (200) - **count** (int) - The number of cloths. #### Response Example { "count": 5 } ``` -------------------------------- ### Simulation Execution API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/_solver_8h-source.html Methods for controlling the simulation lifecycle, specifically starting a simulation frame. ```APIDOC ## Simulation Execution ### Description This method triggers the beginning of a simulation frame for all cloths managed by the solver. ### Method - **beginSimulation(float dt)** ### Parameters #### Query Parameters - **dt** (float) - Required - The time step (delta time) for the simulation frame. ### Response #### Success Response (200) - **status** (bool) - Returns true if the simulation frame was successfully initialized. ``` -------------------------------- ### Initialize NvCloth Factory for DX11 Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/documentation/UserGuide/Index.html Demonstrates the creation of a DX11-based factory, requiring a device context manager. ```cpp #include #include ID3D11Device* DXDevice; ID3D11DeviceContext* DXDeviceContext; nv::cloth::DxContextManagerCallback* GraphicsContextManager; D3D_FEATURE_LEVEL featureLevels[] = {D3D_FEATURE_LEVEL_11_0}; D3D_FEATURE_LEVEL featureLevelResult; HRESULT result = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, featureLevels, 1, D3D11_SDK_VERSION, &DXDevice, &featureLevelResult, &DXDeviceContext); ASSERT(result == S_OK); GraphicsContextManager = new DxContextManagerCallbackImpl(DXDevice); nv::cloth::Factory* factory = NvClothCreateFactoryDX11(GraphicsContextManager); ``` -------------------------------- ### Initialize NvCloth and Create Simulation Factory Source: https://context7.com/nvidiagameworks/nvcloth/llms.txt This snippet demonstrates how to define custom callbacks for memory management, error handling, and assertions, then initialize the NvCloth library. It also shows how to instantiate a factory for CPU-based simulations and provides commented examples for CUDA and DirectX 11 factory creation. ```cpp #include #include class CustomAllocator : public physx::PxAllocatorCallback { public: void* allocate(size_t size, const char*, const char*, int) override { return _aligned_malloc(size, 16); } void deallocate(void* ptr) override { _aligned_free(ptr); } }; class CustomErrorCallback : public physx::PxErrorCallback { public: void reportError(physx::PxErrorCode::Enum code, const char* message, const char* file, int line) override { printf("NvCloth Error [%d]: %s at %s:%d\n", code, message, file, line); } }; class CustomAssertHandler : public nv::cloth::PxAssertHandler { public: void operator()(const char* exp, const char* file, int line, bool& ignore) override { printf("NvCloth Assert: %s at %s:%d\n", exp, file, line); } }; CustomAllocator allocator; CustomErrorCallback errorCallback; CustomAssertHandler assertHandler; nv::cloth::InitializeNvCloth(&allocator, &errorCallback, &assertHandler, nullptr); nv::cloth::Factory* factory = NvClothCreateFactoryCPU(); bool hasCuda = NvClothCompiledWithCudaSupport(); bool hasDx11 = NvClothCompiledWithDxSupport(); NvClothDestroyFactory(factory); ``` -------------------------------- ### Managing Cloth Simulation with Solver Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_solver.html This snippet demonstrates the typical workflow for using the Solver class, including adding a cloth object, beginning a simulation frame, and performing the heavy computation. ```cpp nv::cloth::Solver* solver = ...; // Obtained from factory nv::cloth::Cloth* cloth = ...; // Add cloth to solver solver->addCloth(cloth); // Start simulation frame with time step dt if (solver->beginSimulation(0.016f)) { // Perform simulation chunks int numChunks = solver->getSimulationChunkCount(); for (int i = 0; i < numChunks; ++i) { solver->simulateChunk(i); } // Finalize simulation solver->endSimulation(); } ``` -------------------------------- ### GET /cloth/properties Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/functions_func_0x67.html Retrieves various physical properties and state information for a specific Cloth object. ```APIDOC ## GET /cloth/properties ### Description Retrieves physical attributes such as drag, inertia, damping, and particle data from a cloth simulation instance. ### Method GET ### Endpoint /nv::cloth::Cloth ### Parameters #### Query Parameters - **property** (string) - Required - The specific property to retrieve (e.g., 'Damping', 'Gravity', 'DragCoefficient') ### Request Example { "property": "getDamping" } ### Response #### Success Response (200) - **value** (float/object) - The requested property value or state data. #### Response Example { "value": 0.5 } ``` -------------------------------- ### Create and Configure Cloth Instance (C++) Source: https://context7.com/nvidiagameworks/nvcloth/llms.txt Creates a cloth object from particles and a fabric, then configures its simulation properties such as gravity, damping, inertia, solver frequency, and phase configurations. It also demonstrates setting tether constraints and user data. Dependencies include NvCloth headers. ```cpp #include #include // Prepare particle data (position + inverse mass as PxVec4) std::vector particles; for (size_t i = 0; i < vertices.size(); i++) { particles.push_back(physx::PxVec4(vertices[i], invMasses[i])); } // Create cloth from particles and fabric nv::cloth::Cloth* cloth = factory->createCloth( nv::cloth::Range(particles.data(), particles.data() + particles.size()), *fabric ); // Configure gravity cloth->setGravity(physx::PxVec3(0.0f, -9.8f, 0.0f)); // Configure damping (0 = no damping, 1 = full damping) cloth->setDamping(physx::PxVec3(0.1f, 0.1f, 0.1f)); // Configure inertia settings for local-to-world motion cloth->setLinearInertia(physx::PxVec3(1.0f, 1.0f, 1.0f)); cloth->setAngularInertia(physx::PxVec3(1.0f, 1.0f, 1.0f)); cloth->setCentrifugalInertia(physx::PxVec3(1.0f, 1.0f, 1.0f)); // Configure solver frequency (iterations per second) cloth->setSolverFrequency(120.0f); // Configure drag for more natural cloth behavior cloth->setLinearDrag(physx::PxVec3(0.1f, 0.1f, 0.1f)); cloth->setAngularDrag(physx::PxVec3(0.1f, 0.1f, 0.1f)); // Setup phase configurations for constraint stiffness std::vector phases(fabric->getNumPhases()); for (int i = 0; i < phases.size(); i++) { phases[i].mPhaseIndex = i; phases[i].mStiffness = 1.0f; // Constraint stiffness (0-1) phases[i].mStiffnessMultiplier = 1.0f; // Additional multiplier phases[i].mCompressionLimit = 1.0f; // Allow compression up to this ratio phases[i].mStretchLimit = 1.0f; // Allow stretch up to this ratio } cloth->setPhaseConfig(nv::cloth::Range( phases.data(), phases.data() + phases.size())); // Configure tether constraints (prevents excessive stretching) cloth->setTetherConstraintScale(1.0f); cloth->setTetherConstraintStiffness(1.0f); // Store custom user data cloth->setUserData(myCustomDataPointer); // Delete cloth when done delete cloth; ``` -------------------------------- ### GET /nv/cloth/Fabric/properties Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_fabric.html Retrieve structural information about the cloth fabric, such as the number of particles, indices, and constraints. ```APIDOC ## GET /nv/cloth/Fabric/properties ### Description Retrieves metadata and structural counts for a specific Fabric instance. ### Method GET ### Endpoint /nv/cloth/Fabric/properties ### Parameters #### Path Parameters - **fabricId** (string) - Required - The unique identifier of the Fabric instance. ### Request Example { "fabricId": "fabric_001" } ### Response #### Success Response (200) - **numParticles** (uint32_t) - Total number of particles in the fabric. - **numIndices** (uint32_t) - Total number of indices stored. - **numTriangles** (uint32_t) - Number of triangles in the mesh. #### Response Example { "numParticles": 1024, "numIndices": 3072, "numTriangles": 1024 } ``` -------------------------------- ### Initialize PhaseConfig Structure Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/structnv_1_1cloth_1_1_phase_config.html Demonstrates the constructor for the PhaseConfig struct, which allows setting an initial phase index. This is typically used when defining constraints for specific cloth simulation phases. ```cpp namespace nv { namespace cloth { struct PhaseConfig { PhaseConfig(uint16_t index = uint16_t(-1)) : mPhaseIndex(index) {} float mCompressionLimit; uint16_t mPadding; uint16_t mPhaseIndex; float mStiffness; float mStiffnessMultiplier; float mStretchLimit; }; } } ``` -------------------------------- ### Simulation Control Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/_solver_8h-source.html Methods for controlling the simulation process, including starting, simulating chunks, and ending the simulation. ```APIDOC ## POST /nvcloth/solver/simulateChunk ### Description Executes a portion of the cloth simulation. ### Method POST ### Endpoint /nvcloth/solver/simulateChunk ### Parameters #### Path Parameters - **idx** (int) - Required - The index of the simulation chunk to process. ### Request Example ```json { "idx": 0 } ``` ### Response #### Success Response (200) Indicates successful execution of the simulation chunk. #### Response Example ```json { "status": "success" } ``` ## POST /nvcloth/solver/endSimulation ### Description Finalizes the cloth simulation process. ### Method POST ### Endpoint /nvcloth/solver/endSimulation ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) Indicates successful completion of the simulation. #### Response Example ```json { "status": "success" } ``` ## GET /nvcloth/solver/getSimulationChunkCount ### Description Retrieves the total number of simulation chunks that need to be processed for the current frame. ### Method GET ### Endpoint /nvcloth/solver/getSimulationChunkCount ### Parameters None ### Response #### Success Response (200) - **chunkCount** (int) - The number of simulation chunks. #### Response Example ```json { "chunkCount": 10 } ``` ``` -------------------------------- ### Create Simulation Objects via Factory Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/_factory_8h-source.html Methods for initializing core simulation components including Fabric, Cloth, and Solver objects. These methods serve as the primary entry point for setting up a cloth simulation environment. ```cpp virtual Fabric* createFabric(uint32_t numParticles, Range phaseIndices, Range sets, Range restvalues, Range stiffnessValues, Range indices, Range anchors, Range tetherLengths, Range triangles) = 0; virtual Cloth* createCloth(Range particles, Fabric& fabric) = 0; virtual Solver* createSolver() = 0; virtual Cloth* clone(const Cloth& cloth) = 0; ``` -------------------------------- ### Get Particle Accelerations - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Retrieves a range of particle accelerations. This is a pure virtual function. ```cpp virtual Range nv::cloth::Cloth::getParticleAccelerations() ``` -------------------------------- ### Implement Wind and Aerodynamics Source: https://context7.com/nvidiagameworks/nvcloth/llms.txt Shows how to set global wind velocity, drag, lift, and fluid density. Includes an example function for animating wind over time using trigonometric functions. ```cpp cloth->setWindVelocity(physx::PxVec3(10.0f, 0.0f, 5.0f)); cloth->setDragCoefficient(0.4f); cloth->setLiftCoefficient(0.25f); cloth->setFluidDensity(1.0f); void updateWind(nv::cloth::Cloth* cloth, float time) { float windStrength = 20.0f + 10.0f * sinf(time * 0.5f); float windAngle = time * 0.3f; physx::PxVec3 wind( windStrength * cosf(windAngle), sinf(time * 2.0f) * 2.0f, windStrength * sinf(windAngle) ); cloth->setWindVelocity(wind); } ``` -------------------------------- ### Get Linear Drag - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Retrieves the linear drag vector. This is a pure virtual function. ```cpp virtual physx::PxVec3 nv::cloth::Cloth::getLinearDrag() const ``` -------------------------------- ### GET /cloth/simulation/state Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Retrieves the current state of the cloth simulation, including particle positions, rotation, and translation. ```APIDOC ## GET /cloth/simulation/state ### Description Retrieves the current spatial state of the cloth, including rotation, translation, and previous frame particle data. ### Method GET ### Endpoint /cloth/simulation/state ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **rotation** (PxQuat) - The current rotation of the local space simulation. - **translation** (PxVec3) - The current translation of the local space simulation. - **previousParticles** (MappedRange) - The simulation particles of the previous frame. #### Response Example { "rotation": {"x": 0, "y": 0, "z": 0, "w": 1}, "translation": {"x": 0, "y": 0, "z": 0} } ``` -------------------------------- ### Manage NvCloth Solver Lifecycle Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/documentation/UserGuide/Index.html Demonstrates how to create, destroy, and manage cloths within an NvCloth solver instance. ```cpp nv::cloth::Solver* solver = factory->createSolver(); solver->addCloth(cloth); solver->removeCloth(cloth); NV_CLOTH_DELETE(solver); ``` -------------------------------- ### GET /cloth/simulation/properties Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Retrieves various simulation properties including collision distances, stiffness, and solver frequencies. ```APIDOC ## GET /cloth/simulation/properties ### Description Retrieves the current configuration settings for the cloth simulation, including self-collision parameters, tether constraints, and solver frequency. ### Method GET ### Endpoint /cloth/simulation/properties ### Parameters None ### Request Example {} ### Response #### Success Response (200) - **selfCollisionDistance** (float) - The distance particles need to be separated. - **selfCollisionStiffness** (float) - The constraint stiffness for self-collision. - **tetherConstraintScale** (float) - The scale factor for tether constraints. - **tetherConstraintStiffness** (float) - The stiffness factor for tether constraints. - **solverFrequency** (float) - The frequency of the cloth solver. #### Response Example { "selfCollisionDistance": 0.05, "selfCollisionStiffness": 1.0, "tetherConstraintScale": 1.0, "tetherConstraintStiffness": 1.0, "solverFrequency": 60.0 } ``` -------------------------------- ### Creating Simulation Components Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_factory.html Methods for instantiating core simulation objects including cloth, fabric, and solvers. ```cpp virtual Cloth* createCloth(Range< const physx::PxVec4 > particles, Fabric &fabric) = 0; virtual Fabric* createFabric(uint32_t numParticles, Range< const uint32_t > phaseIndices, Range< const uint32_t > sets, Range< const float > restvalues, Range< const float > stiffnessValues, Range< const uint32_t > indices, Range< const uint32_t > anchors, Range< const float > tetherLengths, Range< const uint32_t > triangles) = 0; virtual Solver* createSolver() = 0; virtual Cloth* clone(const Cloth &cloth) = 0; ``` -------------------------------- ### GET /nv::cloth::StridedData/at Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/functions_func.html Accesses data at a specific index within a strided data structure. ```APIDOC ## GET /nv::cloth::StridedData/at ### Description Retrieves the data element located at the specified index within the strided data buffer. ### Method GET ### Endpoint nv::cloth::StridedData::at(index) ### Parameters #### Query Parameters - **index** (int) - Required - The zero-based index of the element to retrieve. ### Request Example { "index": 0 } ### Response #### Success Response (200) - **data** (object) - The requested data element. #### Response Example { "data": "value_at_index" } ``` -------------------------------- ### Initialize NvCloth Factory for CUDA Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/documentation/UserGuide/Index.html Demonstrates the creation of a CUDA-based factory, requiring a valid CUDA context. ```cpp #include #include CUcontext cudaContext; int deviceCount = 0; CUresult result = cuDeviceGetCount(&deviceCount); ASSERT(CUDA_SUCCESS == result); ASSERT(deviceCount >= 1); result = cuCtxCreate(&cudaContext, 0, 0); ASSERT(CUDA_SUCCESS == result); nv::cloth::Factory* factory = NvClothCreateFactoryCUDA(cudaContext); ``` -------------------------------- ### Initialize Documentation Configuration Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/documentation/Cooking/Index.html Defines the global configuration object for the documentation site, including versioning and file path settings. This is used by the documentation engine to manage navigation and search functionality. ```javascript var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '1.1.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; ``` -------------------------------- ### Inter-Collision Parameters Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/_solver_8h-source.html Methods for setting and getting parameters related to inter-collision behavior within the cloth simulation. ```APIDOC ## POST /nvcloth/solver/setInterCollisionDistance ### Description Sets the distance threshold for inter-collision detection between cloth elements. ### Method POST ### Endpoint /nvcloth/solver/setInterCollisionDistance ### Parameters #### Request Body - **distance** (float) - Required - The distance threshold for inter-collision. ### Request Example ```json { "distance": 0.1 } ``` ### Response #### Success Response (200) Indicates the inter-collision distance was set successfully. #### Response Example ```json { "status": "success" } ``` ## GET /nvcloth/solver/getInterCollisionDistance ### Description Retrieves the current distance threshold for inter-collision detection. ### Method GET ### Endpoint /nvcloth/solver/getInterCollisionDistance ### Parameters None ### Response #### Success Response (200) - **distance** (float) - The current inter-collision distance threshold. #### Response Example ```json { "distance": 0.1 } ``` ## POST /nvcloth/solver/setInterCollisionStiffness ### Description Sets the stiffness of the inter-collision response. ### Method POST ### Endpoint /nvcloth/solver/setInterCollisionStiffness ### Parameters #### Request Body - **stiffness** (float) - Required - The stiffness value for inter-collision. ### Request Example ```json { "stiffness": 100.0 } ``` ### Response #### Success Response (200) Indicates the inter-collision stiffness was set successfully. #### Response Example ```json { "status": "success" } ``` ## GET /nvcloth/solver/getInterCollisionStiffness ### Description Retrieves the current stiffness of the inter-collision response. ### Method GET ### Endpoint /nvcloth/solver/getInterCollisionStiffness ### Parameters None ### Response #### Success Response (200) - **stiffness** (float) - The current inter-collision stiffness. #### Response Example ```json { "stiffness": 100.0 } ``` ## POST /nvcloth/solver/setInterCollisionNbIterations ### Description Sets the number of iterations for the inter-collision solver. ### Method POST ### Endpoint /nvcloth/solver/setInterCollisionNbIterations ### Parameters #### Request Body - **nbIterations** (uint32_t) - Required - The number of iterations for the inter-collision solver. ### Request Example ```json { "nbIterations": 5 } ``` ### Response #### Success Response (200) Indicates the number of inter-collision iterations was set successfully. #### Response Example ```json { "status": "success" } ``` ## GET /nvcloth/solver/getInterCollisionNbIterations ### Description Retrieves the current number of iterations for the inter-collision solver. ### Method GET ### Endpoint /nvcloth/solver/getInterCollisionNbIterations ### Parameters None ### Response #### Success Response (200) - **nbIterations** (uint32_t) - The current number of inter-collision iterations. #### Response Example ```json { "nbIterations": 5 } ``` ## POST /nvcloth/solver/setInterCollisionFilter ### Description Sets a filter for inter-collision detection. ### Method POST ### Endpoint /nvcloth/solver/setInterCollisionFilter ### Parameters #### Request Body - **filter** (InterCollisionFilter) - Required - The inter-collision filter configuration. ### Request Example ```json { "filter": { /* ... filter configuration ... */ } } ``` ### Response #### Success Response (200) Indicates the inter-collision filter was set successfully. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Get Rotation - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Retrieves the current rotation as a constant reference to a PxQuat. This is a pure virtual function. ```cpp virtual const physx::PxQuat& nv::cloth::Cloth::getRotation() const ``` -------------------------------- ### Configure Cloth Phase Settings with NvCloth (C++) Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/documentation/UserGuide/Index.html This snippet shows how to set up phase configurations for a cloth object. It involves creating an array of nv::cloth::PhaseConfig, iterating through the number of phases provided by the fabric, and assigning properties like stiffness and limits. The phase configurations control constraint solving order and properties. ```cpp nv::cloth::PhaseConfig* phases = new nv::cloth::PhaseConfig[fabric->getNumPhases()]; for(int i = 0; i < fabric->getNumPhases(); i++) { phases[i].mPhaseIndex = i; // Set index to the corresponding set (constraint group) //Give phases different configs depending on type switch(phaseTypeInfo[i]) { case nv::cloth::ClothFabricPhaseType::eINVALID: //ERROR break; case nv::cloth::ClothFabricPhaseType::eVERTICAL: break; case nv::cloth::ClothFabricPhaseType::eHORIZONTAL: break; case nv::cloth::ClothFabricPhaseType::eBENDING: break; case nv::cloth::ClothFabricPhaseType::eSHEARING: break; } //For this example we give very phase the same config phases[i].mStiffness = 1.0f; phases[i].mStiffnessMultiplier = 1.0f; phases[i].mCompressionLimit = 1.0f; phases[i].mStretchLimit = 1.0f; } cloth->setPhaseConfig(nv::cloth::Range(phases, phases + fabric->getNumPhases())); delete [] phases; ``` -------------------------------- ### Get Number of Virtual Particles - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the number of virtual particles. This is a pure virtual function. ```cpp virtual uint32_t nv::cloth::Cloth::getNumVirtualParticles() const ``` -------------------------------- ### Initialize Search Interface Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/documentation/Cooking/Index.html Uses jQuery to display the search box element on the documentation page. This ensures the search functionality is visible to the user upon page load. ```javascript $('#searchbox').show(0); ``` -------------------------------- ### Configure Sleep and Performance Optimization Source: https://context7.com/nvidiagameworks/nvcloth/llms.txt Shows how to set sleep thresholds and intervals to reduce CPU/GPU load when cloth is inactive. It also demonstrates how to dynamically adjust the solver frequency based on distance to the camera for LOD optimization. ```cpp cloth->setSleepThreshold(0.01f); cloth->setSleepTestInterval(100); cloth->setSleepAfterCount(3); if (cloth->isAsleep()) { printf("Cloth is sleeping (pass count: %u)\n", cloth->getSleepPassCount()); } cloth->wakeUp(); cloth->putToSleep(); float distanceToCamera = computeDistance(cloth, camera); if (distanceToCamera > 50.0f) { cloth->setSolverFrequency(60.0f); } else { cloth->setSolverFrequency(120.0f); } ``` -------------------------------- ### Get Number of Triangles - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the number of triangles currently set. This is a pure virtual function. ```cpp virtual uint32_t nv::cloth::Cloth::getNumTriangles() const ``` -------------------------------- ### Get Number of Spheres - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the number of spheres currently set. This is a pure virtual function. ```cpp virtual uint32_t nv::cloth::Cloth::getNumSpheres() const ``` -------------------------------- ### Cloning a Cloth Instance Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Demonstrates how to create a duplicate of an existing Cloth instance using the associated Factory. ```cpp nv::cloth::Cloth* clone(nv::cloth::Factory& factory) const; // Usage: // clothInstance->getFactory().clone(*this); ``` -------------------------------- ### Get Number of Separation Constraints - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the number of separation constraints. This is a pure virtual function. ```cpp virtual uint32_t nv::cloth::Cloth::getNumSeparationConstraints() const ``` -------------------------------- ### Get Number of Rest Positions - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the number of rest positions. This is a pure virtual function. ```cpp virtual uint32_t nv::cloth::Cloth::getNumRestPositions() const ``` -------------------------------- ### Direct Fabric Cooking with ClothFabricCooker in C++ Source: https://context7.com/nvidiagameworks/nvcloth/llms.txt This C++ snippet demonstrates how to use the ClothFabricCooker directly for advanced control over fabric creation. It covers initializing the cooker, cooking mesh data into fabric, retrieving cooked data and descriptors, and finally creating a fabric object using the cooked data. Error handling for the cooking process is included. ```cpp #include // Create fabric cooker virtual nv::cloth::ClothFabricCooker* NvClothCreateFabricCooker() = 0; // Cook mesh to fabric data bool success = cooker->cook(meshDesc, gravity, true if (success) { // Get cooked data for custom processing nv::cloth::CookedData cookedData = cooker->getCookedData(); printf("Cooked %u particles, %u phases\n", cookedData.mNumParticles, cookedData.mPhaseIndices.size()); // Get fabric descriptor nv::cloth::ClothFabricDesc desc = cooker->getDescriptor(); // Create fabric from cooked data nv::cloth::Fabric* fabric = factory->createFabric( cookedData.mNumParticles, cookedData.mPhaseIndices, cookedData.mSets, cookedData.mRestvalues, cookedData.mStiffnessValues, cookedData.mIndices, cookedData.mAnchors, cookedData.mTetherLengths, cookedData.mTriangles ); } delete cooker; ``` -------------------------------- ### Initialize and Validate ClothFabricDesc Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/_cloth_fabric_cooker_8h-source.html This snippet demonstrates the constructor, the setToDefault method for memory initialization, and the isValid method for verifying the integrity of the fabric descriptor. ```cpp PX_INLINE ClothFabricDesc::ClothFabricDesc() { setToDefault(); } PX_INLINE void ClothFabricDesc::setToDefault() { memset(this, 0, sizeof(ClothFabricDesc)); } PX_INLINE bool ClothFabricDesc::isValid() const { return nbParticles && nbPhases && phases && restvalues && nbSets; } ``` -------------------------------- ### Get Number of Planes - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the number of planes currently set. This is a pure virtual function. ```cpp virtual uint32_t nv::cloth::Cloth::getNumPlanes() const ``` -------------------------------- ### Create Cloth Instance with NvCloth (C++) Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/documentation/UserGuide/Index.html This code illustrates the creation of a cloth instance from a previously cooked fabric object. It requires initial particle positions, where the w component of PxVec4 represents inverse mass (0 for static particles). After creation, the cloth instance can be configured with phase settings. ```cpp physx::PxVec4* particlePositions = ...; // The w component is the inverse mass of the particle // and can be to 0 to lock the particle / make it static. v::cloth::Cloth* cloth = factory->createCloth(nv::cloth::Range(particlePositions, particlePositions + particleCount), *fabric); // particlePositions can be freed here. ... NV_CLOTH_DELETE(cloth); ``` -------------------------------- ### Get Number of Particles - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the number of particles simulated by this fabric. This is a pure virtual function. ```cpp virtual uint32_t nv::cloth::Cloth::getNumParticles() const ``` -------------------------------- ### POST /nv::cloth::Cloth/wakeUp Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/functions_func_0x77.html The wakeUp method is used to transition a cloth object from a sleeping state to an active state within the simulation. ```APIDOC ## POST /nv::cloth::Cloth/wakeUp ### Description Transitions the specified cloth instance from a sleeping state to an active state, ensuring it is processed by the simulation engine. ### Method POST ### Endpoint /nv::cloth::Cloth/wakeUp ### Parameters #### Path Parameters - **clothId** (string) - Required - The unique identifier for the cloth instance to wake up. ### Request Example { "clothId": "cloth_instance_001" } ### Response #### Success Response (200) - **status** (string) - Indicates the cloth has been successfully woken up. #### Response Example { "status": "success", "message": "Cloth instance 001 is now active." } ``` -------------------------------- ### Get Number of Particle Accelerations - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the number of particle accelerations. This is a pure virtual function. ```cpp virtual uint32_t nv::cloth::Cloth::getNumParticleAccelerations() const ``` -------------------------------- ### Get Tether Constraint Stiffness - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the stiffness value for tether constraints, as configured by setTetherConstraintStiffness(). ```cpp virtual float getTetherConstraintStiffness() const = 0; Returns value set with setTetherConstraintStiffness(). ``` -------------------------------- ### Configure Cloth Simulation Settings Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Methods to enable continuous collision detection and retrieve physical properties like damping, drag, and bounding box information. ```cpp virtual void enableContinuousCollision(bool) = 0; virtual physx::PxVec3 getDamping() const = 0; virtual float getDragCoefficient() const = 0; virtual const physx::PxVec3& getBoundingBoxCenter() const = 0; ``` -------------------------------- ### Get Tether Constraint Scale - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the scale factor for tether constraints, as set by setTetherConstraintScale(). ```cpp virtual float getTetherConstraintScale() const = 0; Returns value set with setTetherConstraintScale(). ``` -------------------------------- ### Get Self Collision Stiffness - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the stiffness value for self-collision constraints, as configured by setSelfCollisionStiffness(). ```cpp virtual float getSelfCollisionStiffness() const = 0; Returns value set with setSelfCollisionStiffness(). ``` -------------------------------- ### Create Simple Tether Cooker (C++) Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/_cloth_tether_cooker_8h.html This function creates a simple tether cooker for NVIDIA NvCloth. It requires the NvCloth API and is used for tethering cloth simulations. The function returns a pointer to the created ClothTetherCooker object. ```cpp #include "NvCloth/ClothTetherCooker.h" NV_CLOTH_API nv::cloth::ClothTetherCooker* NvClothCreateSimpleTetherCooker(); ``` -------------------------------- ### Initialize NvCloth Library Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/documentation/UserGuide/Index.html Initializes the NvCloth library by providing necessary callbacks for memory management, error reporting, and profiling. ```APIDOC ## InitializeNvCloth ### Description Registers user-defined callbacks for memory allocation, error reporting, and assert handling. This must be called before any other NvCloth library functions. ### Method Function Call ### Parameters - **callbacks** (object) - Required - Implementation of physx::PxAllocatorCallback, physx::PxErrorCallback, and physx::PxAssertHandler. ### Request Example ```cpp nv::cloth::InitializeNvCloth(myAllocator, myErrorCallback, myAssertHandler); ``` ``` -------------------------------- ### Get Self Collision Distance - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the distance threshold for self-collision detection, as set by setSelfCollisionDistance(). ```cpp virtual float getSelfCollisionDistance() const = 0; Returns value set with setSelfCollisionDistance(). ``` -------------------------------- ### Include Sample Base CMake Configuration Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/samples/compiler/cmake/windows/CMakeLists.txt This command includes a common CMake configuration file named SampleBase.cmake. This file likely contains shared settings and definitions used across various sample projects within the NvCloth repository. ```cmake INCLUDE(${PROJECT_CMAKE_FILES_DIR}/SampleBase.cmake) ``` -------------------------------- ### Get Number of Motion Constraints - NvCloth Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the total count of active motion constraints applied to the cloth. ```cpp virtual uint32_t getNumMotionConstraints() const = 0 ``` -------------------------------- ### Build Android Project with CMake Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/Externals/CMakeModules/android/README.md Commands to configure and build a C/C++ project for Android using the provided toolchain file. Requires the Android NDK path and target ABI specification. ```bash cmake -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake \ -DANDROID_NDK= \ -DCMAKE_BUILD_TYPE=Release \ -DANDROID_ABI="armeabi-v7a with NEON" \ cmake --build . ``` ```bash cmake -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake -DANDROID_NDK= -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI="armeabi-v7a with NEON" && cmake --build . ``` -------------------------------- ### Get Previous Particles - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns a mapped range of the simulation particles from the previous frame. Similar to getCurrentParticles(). ```cpp virtual MappedRange nv::cloth::Cloth::getPreviousParticles() ``` -------------------------------- ### Cloth Physics and Solver Configuration Methods Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/_cloth_8h-source.html A collection of virtual methods for managing cloth dynamics, including inertia, gravity, drag, and solver frequency settings. These methods are part of the nv::cloth::Cloth interface. ```cpp virtual const physx::PxQuat& getRotation() const = 0; virtual void clearInertia() = 0; virtual void teleport(const physx::PxVec3& delta) = 0; virtual float getPreviousIterationDt() const = 0; virtual void setGravity(const physx::PxVec3&) = 0; virtual physx::PxVec3 getGravity() const = 0; virtual void setDamping(const physx::PxVec3&) = 0; virtual physx::PxVec3 getDamping() const = 0; virtual void setLinearDrag(const physx::PxVec3&) = 0; virtual physx::PxVec3 getLinearDrag() const = 0; virtual void setAngularDrag(const physx::PxVec3&) = 0; virtual physx::PxVec3 getAngularDrag() const = 0; virtual void setLinearInertia(const physx::PxVec3&) = 0; virtual physx::PxVec3 getLinearInertia() const = 0; virtual void setAngularInertia(const physx::PxVec3&) = 0; virtual physx::PxVec3 getAngularInertia() const = 0; virtual void setCentrifugalInertia(const physx::PxVec3&) = 0; virtual physx::PxVec3 getCentrifugalInertia() const = 0; virtual void setSolverFrequency(float) = 0; virtual float getSolverFrequency() const = 0; virtual void setStiffnessFrequency(float) = 0; virtual float getStiffnessFrequency() const = 0; virtual void setAcceleationFilterWidth(uint32_t) = 0; virtual uint32_t getAccelerationFilterWidth() const = 0; virtual void setPhaseConfig(Range configs) = 0; ``` -------------------------------- ### Get Number of Motion Constraints - NvCloth API Source: https://github.com/nvidiagameworks/nvcloth/blob/master/NvCloth/docs/doxy/files/classnv_1_1cloth_1_1_cloth.html Returns the total number of motion constraints. This is a pure virtual function. ```cpp virtual uint32_t nv::cloth::Cloth::getNumMotionConstraints() const ```