| 221 | } |
| 222 | |
| 223 | void Collider::UpdateGeometry() |
| 224 | { |
| 225 | if (_shape == nullptr) |
| 226 | return; |
| 227 | |
| 228 | // Setup shape geometry |
| 229 | _cachedScale = GetScale().GetAbsolute().MaxValue(); |
| 230 | CollisionShape shape; |
| 231 | GetGeometry(shape); |
| 232 | |
| 233 | // Recreate shape if geometry has different type |
| 234 | if (PhysicsBackend::GetShapeType(_shape) != shape.Type) |
| 235 | { |
| 236 | // Detach from the actor |
| 237 | void* actor = PhysicsBackend::GetShapeActor(_shape); |
| 238 | if (actor) |
| 239 | PhysicsBackend::DetachShape(_shape, actor); |
| 240 | |
| 241 | // Release shape |
| 242 | PhysicsBackend::RemoveCollider(this); |
| 243 | PhysicsBackend::DestroyShape(_shape); |
| 244 | _shape = nullptr; |
| 245 | |
| 246 | // Recreate shape |
| 247 | CreateShape(); |
| 248 | |
| 249 | // Reattach again (only if can, see CanAttach function) |
| 250 | if (actor) |
| 251 | { |
| 252 | const auto rigidBody = dynamic_cast<RigidBody*>(GetParent()); |
| 253 | if (rigidBody && CanAttach(rigidBody)) |
| 254 | { |
| 255 | Attach(rigidBody); |
| 256 | } |
| 257 | else if (_staticActor != nullptr) |
| 258 | { |
| 259 | PhysicsBackend::AttachShape(_shape, actor); |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | // Be static triangle mesh |
| 264 | CreateStaticActor(); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | // Update shape |
| 272 | PhysicsBackend::SetShapeGeometry(_shape, shape); |
| 273 | } |
| 274 | |
| 275 | void Collider::CreateStaticActor() |
| 276 | { |
nothing calls this directly
no test coverage detected