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 #pragma once
00029
00030 #include "NvBlastExtDamageAcceleratorInternal.h"
00031 #include "NvBlast.h"
00032 #include "NvBlastArray.h"
00033
00034
00035 namespace Nv
00036 {
00037 namespace Blast
00038 {
00039
00040 class ExtDamageAcceleratorAABBTree final : public ExtDamageAcceleratorInternal
00041 {
00042 public:
00044
00045 ExtDamageAcceleratorAABBTree() :
00046 m_root(nullptr)
00047 {
00048 }
00049
00050 virtual ~ExtDamageAcceleratorAABBTree()
00051 {
00052 }
00053
00054 static ExtDamageAcceleratorAABBTree* create(const NvBlastAsset* asset);
00055
00056
00058
00059 virtual void release() override;
00060
00061 virtual void findBondCentroidsInBounds(const physx::PxBounds3& bounds, ResultCallback& resultCallback) const override
00062 {
00063 const_cast<ExtDamageAcceleratorAABBTree*>(this)->findInBounds(bounds, resultCallback, false);
00064 }
00065
00066 virtual void findBondSegmentsInBounds(const physx::PxBounds3& bounds, ResultCallback& resultCallback) const override
00067 {
00068 const_cast<ExtDamageAcceleratorAABBTree*>(this)->findInBounds(bounds, resultCallback, true);
00069
00070 }
00071
00072 virtual void findBondSegmentsPlaneIntersected(const physx::PxPlane& plane, ResultCallback& resultCallback) const override;
00073
00074 virtual Nv::Blast::DebugBuffer fillDebugRender(int depth, bool segments) override;
00075
00076 virtual void* getImmediateScratch(size_t size) override
00077 {
00078 m_scratch.resizeUninitialized(size);
00079 return m_scratch.begin();
00080 }
00081
00082
00083 private:
00084
00085 ExtDamageAcceleratorAABBTree(ExtDamageAcceleratorAABBTree&);
00086 ExtDamageAcceleratorAABBTree& operator=(const ExtDamageAcceleratorAABBTree& tree);
00087
00088
00089 struct Node
00090 {
00091 int child[2];
00092 uint32_t first;
00093 uint32_t last;
00094 physx::PxBounds3 pointsBound;
00095 physx::PxBounds3 segmentsBound;
00096 };
00097
00098
00099 void build(const NvBlastAsset* asset);
00100
00101 int createNode(uint32_t startIdx, uint32_t endIdx, uint32_t depth);
00102
00103 void pushResult(ResultCallback& callback, uint32_t pointIndex) const
00104 {
00105 callback.push(pointIndex, m_bonds[pointIndex].node0, m_bonds[pointIndex].node1);
00106 }
00107
00108 void findInBounds(const physx::PxBounds3& bounds, ResultCallback& callback, bool segments) const;
00109
00110 void findPointsInBounds(const Node& node, ResultCallback& callback, const physx::PxBounds3& bounds) const;
00111
00112 void findSegmentsInBounds(const Node& node, ResultCallback& callback, const physx::PxBounds3& bounds) const;
00113
00114 void findSegmentsPlaneIntersected(const Node& node, ResultCallback& callback, const physx::PxPlane& plane) const;
00115
00116 void fillDebugBuffer(const Node& node, int currentDepth, int depth, bool segments);
00117
00118
00120
00121 Node* m_root;
00122 Array<Node>::type m_nodes;
00123 Array<uint32_t>::type m_indices;
00124
00125 Array<physx::PxVec3>::type m_points;
00126
00127 struct Segment
00128 {
00129 physx::PxVec3 p0;
00130 physx::PxVec3 p1;
00131 };
00132 Array<Segment>::type m_segments;
00133
00134 struct BondData
00135 {
00136 uint32_t node0;
00137 uint32_t node1;
00138 };
00139 Array<BondData>::type m_bonds;
00140
00141 Array<Nv::Blast::DebugLine>::type m_debugLineBuffer;
00142
00143 Array<char>::type m_scratch;
00144 };
00145
00146
00147 }
00148 }