aboutsummaryrefslogtreecommitdiff
path: root/sdk/extensions/authoringCommon
diff options
context:
space:
mode:
authorBryan Galdrikian <[email protected]>2019-09-17 09:16:55 -0700
committerBryan Galdrikian <[email protected]>2019-09-17 09:16:55 -0700
commit9f4fc41dc5d857e3c7c3500fc71953e54d780a39 (patch)
tree20a548f0eda0ff2f0510ef57f6d038e480dd8611 /sdk/extensions/authoringCommon
parentFixing chunk hierarchy optimization/merge bugs (diff)
downloadblast-1.1.5_release.tar.xz
blast-1.1.5_release.zip
* NvBlastAsset::testForValidChunkOrder (used when creating an NvBlastAsset) is now more strict, requiring parent chunk descriptors to come before their children. It is still less strict than the order created by NvBlastBuildAssetDescChunkReorderMap.v1.1.5_releasev1.1.5_rc1v1.1.5_pre5dev
* Added FractureTool::setApproximateBonding function. Signals the tool to create bonds by proximity instead of just using cut plane data. * Chunks which have been merged using the uniteChunks function may be merged again * Restored chunk volume calculation * NvBlastBuildAssetDescChunkReorderMap failure cases fixed.
Diffstat (limited to 'sdk/extensions/authoringCommon')
-rw-r--r--sdk/extensions/authoringCommon/source/NvBlastExtAuthoringInternalCommon.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringInternalCommon.h b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringInternalCommon.h
index 4a0fbd0..79bbe3a 100644
--- a/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringInternalCommon.h
+++ b/sdk/extensions/authoringCommon/source/NvBlastExtAuthoringInternalCommon.h
@@ -29,6 +29,7 @@
#ifndef NVBLASTINTERNALCOMMON_H
#define NVBLASTINTERNALCOMMON_H
#include "NvBlastExtAuthoringTypes.h"
+#include "NvBlastPxSharedHelpers.h"
#include <PxVec2.h>
#include <PxVec3.h>
#include <PxPlane.h>
@@ -275,6 +276,47 @@ struct VrtPositionComparator
};
};
+
+NV_INLINE float calculateCollisionHullVolume(const CollisionHull& hull)
+{
+ if (hull.pointsCount == 0)
+ {
+ return 0.0f;
+ }
+
+ // Find an approximate centroid for a more accurate calculation
+ NvcVec3 centroid = { 0.0f, 0.0f, 0.0f };
+ for (uint32_t i = 0; i < hull.pointsCount; ++i)
+ {
+ centroid = centroid + hull.points[i];
+ }
+ centroid = centroid / hull.pointsCount;
+
+ float volume = 0.0f;
+
+ for (uint32_t i = 0; i < hull.polygonDataCount; ++i)
+ {
+ const HullPolygon& poly = hull.polygonData[i];
+ if (poly.vertexCount < 3)
+ {
+ continue;
+ }
+ const uint32_t i0 = hull.indices[poly.indexBase];
+ uint32_t i1 = hull.indices[poly.indexBase + 1];
+ for (uint32_t j = 2; j < poly.vertexCount; ++j)
+ {
+ const uint32_t i2 = hull.indices[poly.indexBase + j];
+ const NvcVec3 a = hull.points[i0] - centroid;
+ const NvcVec3 b = hull.points[i1] - centroid;
+ const NvcVec3 c = hull.points[i2] - centroid;
+ volume +=
+ (a.x * b.y * c.z - a.x * b.z * c.y - a.y * b.x * c.z + a.y * b.z * c.x + a.z * b.x * c.y - a.z * b.y * c.x);
+ i1 = i2;
+ }
+ }
+ return (1.0f / 6.0f) * std::abs(volume);
+}
+
} // namespace Blast
} // namespace Nv