00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTEXTSTRESSSOLVER_H
00030 #define NVBLASTEXTSTRESSSOLVER_H
00031
00032 #include "NvBlastTypes.h"
00033 #include "PxVec3.h"
00034 #include <vector>
00035
00036
00037 namespace Nv
00038 {
00039 namespace Blast
00040 {
00041
00042
00057 struct ExtStressSolverSettings
00058 {
00059 float hardness;
00060 float stressLinearFactor;
00061 float stressAngularFactor;
00062 uint32_t bondIterationsPerFrame;
00063 uint32_t graphReductionLevel;
00064
00065 ExtStressSolverSettings() :
00066 hardness(1000.0f),
00067 stressLinearFactor(0.25f),
00068 stressAngularFactor(0.75f),
00069 bondIterationsPerFrame(18000),
00070 graphReductionLevel(3)
00071 {}
00072 };
00073
00074
00080 struct ExtForceMode
00081 {
00082 enum Enum
00083 {
00084 IMPULSE,
00085 VELOCITY,
00086 };
00087 };
00088
00089
00105 class NV_DLL_EXPORT ExtStressSolver
00106 {
00107 public:
00109
00118 static ExtStressSolver* create(NvBlastFamily& family, ExtStressSolverSettings settings = ExtStressSolverSettings());
00119
00120
00122
00126 virtual void release() = 0;
00127
00139 virtual void setNodeInfo(uint32_t graphNodeIndex, float mass, float volume, physx::PxVec3 localPosition, bool isStatic) = 0;
00140
00148 virtual void setAllNodesInfoFromLL(float density = 1.0f) = 0;
00149
00157 virtual void setSettings(const ExtStressSolverSettings& settings) = 0;
00158
00164 virtual const ExtStressSolverSettings& getSettings() const = 0;
00165
00175 virtual bool notifyActorCreated(const NvBlastActor& actor) = 0;
00176
00184 virtual void notifyActorDestroyed(const NvBlastActor& actor) = 0;
00185
00196 virtual bool addForce(const NvBlastActor& actor, physx::PxVec3 localPosition, physx::PxVec3 localForce, ExtForceMode::Enum mode = ExtForceMode::IMPULSE) = 0;
00197
00205 virtual void addForce(uint32_t graphNodeIndex, physx::PxVec3 localForce, ExtForceMode::Enum mode = ExtForceMode::IMPULSE) = 0;
00206
00215 virtual bool addGravityForce(const NvBlastActor& actor, physx::PxVec3 localGravity) = 0;
00216
00226 virtual bool addAngularVelocity(const NvBlastActor& actor, physx::PxVec3 localCenterMass, physx::PxVec3 localAngularVelocity) = 0;
00227
00233 virtual void update() = 0;
00234
00242 virtual uint32_t getOverstressedBondCount() const = 0;
00243
00256 virtual void generateFractureCommands(const NvBlastActor& actor, NvBlastFractureBuffers& commands) = 0;
00257
00268 virtual void generateFractureCommands(NvBlastFractureBuffers& commands) = 0;
00269
00286 virtual uint32_t generateFractureCommandsPerActor(const NvBlastActor** actorBuffer, NvBlastFractureBuffers* commandsBuffer, uint32_t bufferSize) = 0;
00287
00294 virtual void reset() = 0;
00295
00301 virtual float getStressErrorLinear() const = 0;
00302
00308 virtual float getStressErrorAngular() const = 0;
00309
00315 virtual uint32_t getFrameCount() const = 0;
00316
00322 virtual uint32_t getBondCount() const = 0;
00323
00324
00328 enum DebugRenderMode
00329 {
00330 STRESS_GRAPH = 0,
00331 STRESS_GRAPH_NODES_IMPULSES = 1,
00332 STRESS_GRAPH_BONDS_IMPULSES = 2
00333 };
00334
00338 struct DebugLine
00339 {
00340 DebugLine(const physx::PxVec3& p0, const physx::PxVec3& p1, const uint32_t& c)
00341 : pos0(p0), color0(c), pos1(p1), color1(c) {}
00342
00343 physx::PxVec3 pos0;
00344 uint32_t color0;
00345 physx::PxVec3 pos1;
00346 uint32_t color1;
00347 };
00348
00352 struct DebugBuffer
00353 {
00354 const DebugLine* lines;
00355 uint32_t lineCount;
00356 };
00357
00370 virtual const DebugBuffer fillDebugRender(const uint32_t* nodes, uint32_t nodeCount, DebugRenderMode mode, float scale = 1.0f) = 0;
00371
00372
00374
00386 static uint32_t getIterationsPerFrame(const ExtStressSolverSettings& settings, uint32_t bondCount)
00387 {
00388 uint32_t perFrame = settings.bondIterationsPerFrame / (bondCount + 1);
00389 return perFrame > 0 ? perFrame : 1;
00390 }
00391
00399 uint32_t getIterationsPerFrame() const
00400 {
00401 return getIterationsPerFrame(getSettings(), getBondCount());
00402 }
00403
00404 };
00405
00406 }
00407 }
00408
00409
00410 #endif // ifndef NVBLASTEXTSTRESSSOLVER_H