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 "NvCTypes.h"
00034
00035
00036 namespace Nv
00037 {
00038 namespace Blast
00039 {
00040
00041
00056 struct ExtStressSolverSettings
00057 {
00058 float hardness;
00059 float stressLinearFactor;
00060 float stressAngularFactor;
00061 uint32_t bondIterationsPerFrame;
00062 uint32_t graphReductionLevel;
00063
00064 ExtStressSolverSettings() :
00065 hardness(1000.0f),
00066 stressLinearFactor(0.25f),
00067 stressAngularFactor(0.75f),
00068 bondIterationsPerFrame(18000),
00069 graphReductionLevel(3)
00070 {}
00071 };
00072
00073
00079 struct ExtForceMode
00080 {
00081 enum Enum
00082 {
00083 IMPULSE,
00084 VELOCITY,
00085 };
00086 };
00087
00088
00104 class NV_DLL_EXPORT ExtStressSolver
00105 {
00106 public:
00108
00117 static ExtStressSolver* create(NvBlastFamily& family, ExtStressSolverSettings settings = ExtStressSolverSettings());
00118
00119
00121
00125 virtual void release() = 0;
00126
00138 virtual void setNodeInfo(uint32_t graphNodeIndex, float mass, float volume, NvcVec3 localPosition, bool isStatic) = 0;
00139
00147 virtual void setAllNodesInfoFromLL(float density = 1.0f) = 0;
00148
00156 virtual void setSettings(const ExtStressSolverSettings& settings) = 0;
00157
00163 virtual const ExtStressSolverSettings& getSettings() const = 0;
00164
00174 virtual bool notifyActorCreated(const NvBlastActor& actor) = 0;
00175
00183 virtual void notifyActorDestroyed(const NvBlastActor& actor) = 0;
00184
00195 virtual bool addForce(const NvBlastActor& actor, NvcVec3 localPosition, NvcVec3 localForce, ExtForceMode::Enum mode = ExtForceMode::IMPULSE) = 0;
00196
00204 virtual void addForce(uint32_t graphNodeIndex, NvcVec3 localForce, ExtForceMode::Enum mode = ExtForceMode::IMPULSE) = 0;
00205
00214 virtual bool addGravityForce(const NvBlastActor& actor, NvcVec3 localGravity) = 0;
00215
00225 virtual bool addAngularVelocity(const NvBlastActor& actor, NvcVec3 localCenterMass, NvcVec3 localAngularVelocity) = 0;
00226
00232 virtual void update() = 0;
00233
00241 virtual uint32_t getOverstressedBondCount() const = 0;
00242
00255 virtual void generateFractureCommands(const NvBlastActor& actor, NvBlastFractureBuffers& commands) = 0;
00256
00267 virtual void generateFractureCommands(NvBlastFractureBuffers& commands) = 0;
00268
00285 virtual uint32_t generateFractureCommandsPerActor(const NvBlastActor** actorBuffer, NvBlastFractureBuffers* commandsBuffer, uint32_t bufferSize) = 0;
00286
00293 virtual void reset() = 0;
00294
00300 virtual float getStressErrorLinear() const = 0;
00301
00307 virtual float getStressErrorAngular() const = 0;
00308
00314 virtual uint32_t getFrameCount() const = 0;
00315
00321 virtual uint32_t getBondCount() const = 0;
00322
00323
00327 enum DebugRenderMode
00328 {
00329 STRESS_GRAPH = 0,
00330 STRESS_GRAPH_NODES_IMPULSES = 1,
00331 STRESS_GRAPH_BONDS_IMPULSES = 2
00332 };
00333
00337 struct DebugLine
00338 {
00339 DebugLine(const NvcVec3& p0, const NvcVec3& p1, const uint32_t& c)
00340 : pos0(p0), color0(c), pos1(p1), color1(c) {}
00341
00342 NvcVec3 pos0;
00343 uint32_t color0;
00344 NvcVec3 pos1;
00345 uint32_t color1;
00346 };
00347
00351 struct DebugBuffer
00352 {
00353 const DebugLine* lines;
00354 uint32_t lineCount;
00355 };
00356
00369 virtual const DebugBuffer fillDebugRender(const uint32_t* nodes, uint32_t nodeCount, DebugRenderMode mode, float scale = 1.0f) = 0;
00370
00371
00373
00385 static uint32_t getIterationsPerFrame(const ExtStressSolverSettings& settings, uint32_t bondCount)
00386 {
00387 uint32_t perFrame = settings.bondIterationsPerFrame / (bondCount + 1);
00388 return perFrame > 0 ? perFrame : 1;
00389 }
00390
00398 uint32_t getIterationsPerFrame() const
00399 {
00400 return getIterationsPerFrame(getSettings(), getBondCount());
00401 }
00402
00403 };
00404
00405 }
00406 }
00407
00408
00409 #endif // ifndef NVBLASTEXTSTRESSSOLVER_H