aboutsummaryrefslogtreecommitdiff
path: root/sdk
diff options
context:
space:
mode:
authorbgaldrikian <[email protected]>2018-10-25 00:12:07 -0700
committerbgaldrikian <[email protected]>2018-10-25 00:12:07 -0700
commita3f92a1c7a1cc1553bd9581845ef2542d55ee58f (patch)
tree65d7b052c81faca989db10cf2681f4209fe6dc76 /sdk
parentMerge pull request #14 from neithy/master (diff)
downloadblast-a3f92a1c7a1cc1553bd9581845ef2542d55ee58f.tar.xz
blast-a3f92a1c7a1cc1553bd9581845ef2542d55ee58f.zip
Fix for crash bug during ESS authoringv1.1.4_releasev1.1.4_rc2
Doc updates for AuthoringTool and ApexImporter Updated release notes
Diffstat (limited to 'sdk')
-rwxr-xr-xsdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.cpp96
-rwxr-xr-xsdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.h5
2 files changed, 90 insertions, 11 deletions
diff --git a/sdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.cpp b/sdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.cpp
index 2f87c67..1952e0f 100755
--- a/sdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.cpp
+++ b/sdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.cpp
@@ -194,8 +194,63 @@ namespace Nv
}
+ inline bool pointInsidePoly(const PxVec3& pt, const uint8_t *indices, uint16_t indexCount, const PxVec3 *verts, const PxVec3& n)
+ {
+ int s = 0;
+ for (uint16_t i = 0; i < indexCount; ++i)
+ {
+ const PxVec3 r0 = verts[indices[i]] - pt;
+ const PxVec3 r1 = verts[indices[(i + 1) % indexCount]] - pt;
+ const float cn = r0.cross(r1).dot(n);
+ const int cns = cn >= 0 ? 1 : -1;
+ if (!s)
+ {
+ s = cns;
+ }
+ if (cns*s < 0)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ void AddPpAnchorPoints(
+ const uint8_t* indicesA, uint16_t indexCountA, const PxVec3* vertsA, const float planeA[4],
+ const uint8_t* indicesB, uint16_t indexCountB, const PxVec3* vertsB, const float planeB[4],
+ std::vector<PxVec3>& points)
+ {
+ PxPlane pla(planeA[0], planeA[1], planeA[2], planeA[3]);
+ PxPlane plb(planeB[0], planeB[1], planeB[2], planeB[3]);
+
+ for (uint16_t iA = 0; iA < indexCountA; ++iA)
+ {
+ PxVec3 pt;
+ if (getPlaneSegmentIntersection(plb, vertsA[indicesA[iA]], vertsA[indicesA[(iA + 1) % indexCountA]], pt))
+ {
+ if (pointInsidePoly(pt, indicesB, indexCountB, vertsB, plb.n))
+ {
+ points.push_back(pt);
+ }
+ }
+ }
+
+ for (uint16_t iB = 0; iB < indexCountA; ++iB)
+ {
+ PxVec3 pt;
+ if (getPlaneSegmentIntersection(pla, vertsB[indicesB[iB]], vertsB[indicesA[(iB + 1) % indexCountB]], pt))
+ {
+ if (pointInsidePoly(pt, indicesA, indexCountA, vertsA, pla.n))
+ {
+ points.push_back(pt);
+ }
+ }
+ }
+ }
+
+
float BlastBondGeneratorImpl::processWithMidplanes(TriangleProcessor* trProcessor, const Triangle* mA, uint32_t mavc, const Triangle* mB, uint32_t mbvc,
- const std::vector<PxVec3>& hull1p, const std::vector<PxVec3>& hull2p, PxVec3& normal, PxVec3& centroid, float maxSeparation)
+ const CollisionHull* hull1, const CollisionHull* hull2, const std::vector<PxVec3>& hull1p, const std::vector<PxVec3>& hull2p, PxVec3& normal, PxVec3& centroid, float maxSeparation)
{
PxBounds3 bounds;
PxBounds3 aBounds;
@@ -238,7 +293,9 @@ namespace Nv
return 0.0;
}
- if (separation.getDistance() > 0) // If chunks don't intersect then use midplane to produce bond, otherwise midplane can be wrong
+ const bool have_geometry = (mA != nullptr && mB != nullptr) || (hull1 != nullptr && hull2 != nullptr);
+
+ if (separation.getDistance() > 0 || !have_geometry) // If chunks don't intersect then use midplane to produce bond, otherwise midplane can be wrong (only if we have geometry)
{
// Build first plane interface
PxPlane midplane = separation.plane;
@@ -299,14 +356,31 @@ namespace Nv
std::vector<PxVec3> intersectionAnchors;
-
- for (uint32_t i = 0; i < mavc; ++i)
- {
- for (uint32_t j = 0; j < mbvc; ++j)
+ if (mA != nullptr && mB != nullptr) // Use triangles
+ {
+ for (uint32_t i = 0; i < mavc; ++i)
{
- AddTtAnchorPoints(mA + i, mB + j, intersectionAnchors);
+ for (uint32_t j = 0; j < mbvc; ++j)
+ {
+ AddTtAnchorPoints(mA + i, mB + j, intersectionAnchors);
+ }
}
}
+ else // Use hulls
+ {
+ for (uint32_t i1 = 0; i1 < hull1->polygonDataCount; ++i1)
+ {
+ CollisionHull::HullPolygon& poly1 = hull1->polygonData[i1];
+ for (uint32_t i2 = 0; i2 < hull2->polygonDataCount; ++i2)
+ {
+ CollisionHull::HullPolygon& poly2 = hull2->polygonData[i2];
+ AddPpAnchorPoints(
+ reinterpret_cast<uint8_t*>(hull1->indices) + poly1.mIndexBase, poly1.mNbVerts, hull1->points, poly1.mPlane,
+ reinterpret_cast<uint8_t*>(hull2->indices) + poly2.mIndexBase, poly2.mNbVerts, hull2->points, poly2.mPlane,
+ intersectionAnchors);
+ }
+ }
+ }
PxVec3 lcoid(0, 0, 0);
for (uint32_t i = 0; i < intersectionAnchors.size(); ++i)
@@ -513,8 +587,12 @@ namespace Nv
PxVec3 normal;
PxVec3 centroid;
- float area = processWithMidplanes(&trProcessor, geometry + geometryOffset[i], geometryOffset[i + 1] - geometryOffset[i],
- geometry + geometryOffset[j], geometryOffset[j + 1] - geometryOffset[j], hullPoints[i][ihull], hullPoints[j][jhull], normal, centroid, conf.maxSeparation);
+ float area = processWithMidplanes(&trProcessor,
+ geometry ? geometry + geometryOffset[i] : nullptr, geometryOffset[i + 1] - geometryOffset[i],
+ geometry ? geometry + geometryOffset[j] : nullptr, geometryOffset[j + 1] - geometryOffset[j],
+ geometry ? nullptr : chunkHulls[geometryOffset[i] + ihull],
+ geometry ? nullptr : chunkHulls[geometryOffset[j] + jhull],
+ hullPoints[i][ihull], hullPoints[j][jhull], normal, centroid, conf.maxSeparation);
if (area > 0)
{
diff --git a/sdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.h b/sdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.h
index bef3668..222d22b 100755
--- a/sdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.h
+++ b/sdk/extensions/authoring/source/NvBlastExtAuthoringBondGeneratorImpl.h
@@ -75,8 +75,9 @@ public:
private:
- float processWithMidplanes(TriangleProcessor* trProcessor, const Triangle* mA, uint32_t mavc, const Triangle* mB, uint32_t mbvc,
- const std::vector<physx::PxVec3>& hull1p, const std::vector<physx::PxVec3>& hull2p, physx::PxVec3& normal, physx::PxVec3& centroid, float maxSeparation);
+ float processWithMidplanes(TriangleProcessor* trProcessor, const Triangle* mA, uint32_t mavc, const Triangle* mB, uint32_t mbvc, const CollisionHull* hull1, const CollisionHull* hull2,
+ const std::vector<physx::PxVec3>& hull1p, const std::vector<physx::PxVec3>& hull2p,
+ physx::PxVec3& normal, physx::PxVec3& centroid, float maxSeparation);
int32_t createFullBondListAveraged( uint32_t meshCount, const uint32_t* geometryOffset, const Triangle* geometry, const CollisionHull** chunkHulls,
const bool* supportFlags, const uint32_t* meshGroups, NvBlastBondDesc*& resultBondDescs, BondGenerationConfig conf, std::set<std::pair<uint32_t, uint32_t> >* pairNotToTest = nullptr);