| 119 | } |
| 120 | |
| 121 | bool BVHStructureBuilder::loadFromDesc(const PxBVHStructureDesc& desc) |
| 122 | { |
| 123 | PX_ASSERT(desc.isValid()); |
| 124 | |
| 125 | const PxU32 numPrimitives = desc.bounds.count; |
| 126 | |
| 127 | // allocate one more for safe SIMD vec4 load |
| 128 | mBounds = reinterpret_cast<PxBounds3*>(PX_ALLOC((numPrimitives + 1) * sizeof(PxBounds3), "PxBounds3")); |
| 129 | |
| 130 | const PxU8* sB = reinterpret_cast<const PxU8*>(desc.bounds.data); |
| 131 | |
| 132 | for(PxU32 i = 0; i < numPrimitives; i++) |
| 133 | { |
| 134 | inflateBounds(mBounds[i], *reinterpret_cast<const PxBounds3*>(sB)); |
| 135 | |
| 136 | sB += desc.bounds.stride; |
| 137 | } |
| 138 | mNumVolumes = numPrimitives; |
| 139 | |
| 140 | // build the BVH |
| 141 | AABBTreeBuildParams params; |
| 142 | params.mNbPrimitives = desc.bounds.count; |
| 143 | params.mAABBArray = mBounds; |
| 144 | params.mLimit = NB_OBJECTS_PER_NODE; |
| 145 | BuildStats stats; |
| 146 | NodeAllocator nodeAllocator; |
| 147 | |
| 148 | const bool buildStatus = buildAABBTree(params, nodeAllocator, stats, mIndices); |
| 149 | PX_UNUSED(buildStatus); |
| 150 | PX_ASSERT(buildStatus); |
| 151 | |
| 152 | // store the computed hierarchy |
| 153 | mNumNodes = stats.getCount(); |
| 154 | mNodes = reinterpret_cast<BVHNode*>(PX_ALLOC(sizeof(BVHNode)*mNumNodes, "AABB tree nodes")); |
| 155 | PX_ASSERT(mNumNodes==nodeAllocator.mTotalNbNodes); |
| 156 | |
| 157 | // store the results into BVHNode list |
| 158 | flatten(nodeAllocator, mNodes); |
| 159 | nodeAllocator.release(); |
| 160 | |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | // A.B. move to load code |
| 165 | #define PX_BVH_STRUCTURE_VERSION 1 |
no test coverage detected