| 133 | #endif |
| 134 | |
| 135 | bool CollisionData::GetModelTriangle(uint32 faceIndex, MeshBase*& mesh, uint32& meshTriangleIndex) const |
| 136 | { |
| 137 | mesh = nullptr; |
| 138 | meshTriangleIndex = MAX_uint32; |
| 139 | if (!IsLoaded()) |
| 140 | return false; |
| 141 | PROFILE_CPU(); |
| 142 | ScopeLock lock(Locker); |
| 143 | if (_triangleMesh) |
| 144 | { |
| 145 | uint32 trianglesCount; |
| 146 | const uint32* remap = PhysicsBackend::GetTriangleMeshRemap(_triangleMesh, trianglesCount); |
| 147 | if (remap && faceIndex < trianglesCount) |
| 148 | { |
| 149 | // Get source triangle index from the triangle mesh |
| 150 | meshTriangleIndex = remap[faceIndex]; |
| 151 | |
| 152 | // Check if model was used when cooking |
| 153 | AssetReference<ModelBase> model; |
| 154 | model = _options.Model; |
| 155 | if (!model) |
| 156 | return true; |
| 157 | |
| 158 | // Follow code-path similar to CollisionCooking.cpp to pick a mesh that contains this triangle (collision is cooked from merged all source meshes from the model) |
| 159 | if (model->WaitForLoaded()) |
| 160 | return false; |
| 161 | const int32 lodIndex = Math::Clamp(_options.ModelLodIndex, 0, model->GetLODsCount()); |
| 162 | Array<MeshBase*> meshes; |
| 163 | model->GetMeshes(meshes, lodIndex); |
| 164 | uint32 triangleCounter = 0; |
| 165 | for (int32 meshIndex = 0; meshIndex < meshes.Count(); meshIndex++) |
| 166 | { |
| 167 | MeshBase* m = meshes[meshIndex]; |
| 168 | if ((_options.MaterialSlotsMask & (1 << m->GetMaterialSlotIndex())) == 0) |
| 169 | continue; |
| 170 | const uint32 count = m->GetTriangleCount(); |
| 171 | if (meshTriangleIndex - triangleCounter <= count) |
| 172 | { |
| 173 | mesh = m; |
| 174 | meshTriangleIndex -= triangleCounter; |
| 175 | return true; |
| 176 | } |
| 177 | triangleCounter += count; |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | void CollisionData::ExtractGeometry(Array<Float3>& vertexBuffer, Array<int32>& indexBuffer) const |
| 186 | { |
nothing calls this directly
no test coverage detected