MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / DrawPhysicsDebug

Method DrawPhysicsDebug

Source/Engine/Physics/Actors/Cloth.cpp:344–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342#if USE_EDITOR
343
344void Cloth::DrawPhysicsDebug(RenderView& view)
345{
346#if WITH_CLOTH && COMPILE_WITH_DEBUG_DRAW
347 if (_cloth)
348 {
349 PROFILE_CPU();
350 const ModelInstanceActor::MeshReference meshRef = GetMesh();
351 if (meshRef.Actor == nullptr)
352 return;
353 MeshAccessor accessor;
354 MeshBufferType bufferTypes[1] = { MeshBufferType::Index };
355 if (accessor.LoadMesh(meshRef.Get(), false, ToSpan(bufferTypes, 1)))
356 return;
357 auto indices = accessor.Index();
358 auto indicesData = indices.GetData();
359 PhysicsBackend::LockClothParticles(_cloth);
360 const Span<const Float4> particles = PhysicsBackend::GetClothParticles(_cloth);
361 const Transform transform = GetTransform();
362 const bool indices16bit = indices.GetFormat() == PixelFormat::R16_UInt;
363 const int32 trianglesCount = indices.GetCount() / 3;
364 for (int32 triangleIndex = 0; triangleIndex < trianglesCount; triangleIndex++)
365 {
366 const int32 index = triangleIndex * 3;
367 int32 i0, i1, i2;
368 if (indices16bit)
369 {
370 i0 = indicesData.Get<uint16>()[index];
371 i1 = indicesData.Get<uint16>()[index + 1];
372 i2 = indicesData.Get<uint16>()[index + 2];
373 }
374 else
375 {
376 i0 = indicesData.Get<uint32>()[index];
377 i1 = indicesData.Get<uint32>()[index + 1];
378 i2 = indicesData.Get<uint32>()[index + 2];
379 }
380 if (_paint.Count() == particles.Length())
381 {
382 if (Math::Max(_paint[i0], _paint[i1], _paint[i2]) < ZeroTolerance)
383 continue;
384 }
385 const Vector3 v0 = transform.LocalToWorld(Vector3(particles[i0]));
386 const Vector3 v1 = transform.LocalToWorld(Vector3(particles[i1]));
387 const Vector3 v2 = transform.LocalToWorld(Vector3(particles[i2]));
388 DEBUG_DRAW_TRIANGLE(v0, v1, v2, Color::Pink, 0, true);
389 }
390 PhysicsBackend::UnlockClothParticles(_cloth);
391 }
392#endif
393}
394
395void Cloth::OnDebugDrawSelected()
396{

Callers

nothing calls this directly

Calls 13

GetMeshFunction · 0.85
ToSpanFunction · 0.50
MaxFunction · 0.50
Vector3Class · 0.50
LoadMeshMethod · 0.45
GetMethod · 0.45
IndexMethod · 0.45
GetDataMethod · 0.45
GetFormatMethod · 0.45
GetCountMethod · 0.45
CountMethod · 0.45
LengthMethod · 0.45

Tested by

no test coverage detected