Fix mesh collision proxy setup for meshes using packed positions format
#3791
This commit is contained in:
@@ -248,6 +248,19 @@ public:
|
||||
explicit Half4(const Color& c);
|
||||
explicit Half4(const Rectangle& rect);
|
||||
|
||||
operator Float2() const
|
||||
{
|
||||
return ToFloat2();
|
||||
}
|
||||
operator Float3() const
|
||||
{
|
||||
return ToFloat3();
|
||||
}
|
||||
operator Float4() const
|
||||
{
|
||||
return ToFloat4();
|
||||
}
|
||||
|
||||
public:
|
||||
Float2 ToFloat2() const;
|
||||
Float3 ToFloat3() const;
|
||||
|
||||
@@ -41,16 +41,6 @@ FloatR10G10B10A2::FloatR10G10B10A2(const float* values)
|
||||
{
|
||||
}
|
||||
|
||||
FloatR10G10B10A2::operator Float3() const
|
||||
{
|
||||
return ToFloat3();
|
||||
}
|
||||
|
||||
FloatR10G10B10A2::operator Float4() const
|
||||
{
|
||||
return ToFloat4();
|
||||
}
|
||||
|
||||
Float3 FloatR10G10B10A2::ToFloat3() const
|
||||
{
|
||||
Float3 vectorOut;
|
||||
|
||||
@@ -40,9 +40,14 @@ struct FLAXENGINE_API FloatR10G10B10A2
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
operator Float3() const;
|
||||
operator Float4() const;
|
||||
operator Float3() const
|
||||
{
|
||||
return ToFloat3();
|
||||
}
|
||||
operator Float4() const
|
||||
{
|
||||
return ToFloat4();
|
||||
}
|
||||
|
||||
FloatR10G10B10A2& operator=(const FloatR10G10B10A2& other)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include "Engine/Core/Math/Transform.h"
|
||||
#include "Engine/Core/Math/Ray.h"
|
||||
#include "Engine/Core/Math/CollisionsHelper.h"
|
||||
#include "Engine/Core/Math/Packed.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
#include "Engine/Graphics/PixelFormat.h"
|
||||
|
||||
/// <summary>
|
||||
/// Helper container used for detailed triangle mesh intersections tests.
|
||||
@@ -31,23 +33,38 @@ public:
|
||||
}
|
||||
|
||||
template<typename IndexType>
|
||||
void Init(uint32 vertices, uint32 triangles, const Float3* positions, const IndexType* indices, uint32 positionsStride = sizeof(Float3))
|
||||
void Init(uint32 vertices, uint32 triangles, const Float3* positions, const IndexType* indices, uint32 positionsStride = sizeof(Float3), PixelFormat positionsFormat = PixelFormat::R32G32B32_Float)
|
||||
{
|
||||
Triangles.Clear();
|
||||
Triangles.EnsureCapacity(triangles, false);
|
||||
const IndexType* it = indices;
|
||||
for (uint32 i = 0; i < triangles; i++)
|
||||
#define LOOP_BEGIN() \
|
||||
for (uint32 i = 0; i < triangles; i++) \
|
||||
{ \
|
||||
const IndexType i0 = *(it++); \
|
||||
const IndexType i1 = *(it++); \
|
||||
const IndexType i2 = *(it++); \
|
||||
if (i0 < vertices && i1 < vertices && i2 < vertices) \
|
||||
{
|
||||
const IndexType i0 = *(it++);
|
||||
const IndexType i1 = *(it++);
|
||||
const IndexType i2 = *(it++);
|
||||
if (i0 < vertices && i1 < vertices && i2 < vertices)
|
||||
{
|
||||
#define LOOP_END() } }
|
||||
if (positionsFormat == PixelFormat::R32G32B32_Float)
|
||||
{
|
||||
LOOP_BEGIN()
|
||||
#define GET_POS(idx) *(const Float3*)((const byte*)positions + positionsStride * idx)
|
||||
Triangles.Add({ GET_POS(i0), GET_POS(i1), GET_POS(i2) });
|
||||
#undef GET_POS
|
||||
}
|
||||
LOOP_END()
|
||||
}
|
||||
else if (positionsFormat == PixelFormat::R16G16B16A16_Float)
|
||||
{
|
||||
LOOP_BEGIN()
|
||||
#define GET_POS(idx) (Float3)*(const Half4*)((const byte*)positions + positionsStride * idx)
|
||||
Triangles.Add({ GET_POS(i0), GET_POS(i1), GET_POS(i2) });
|
||||
#undef GET_POS
|
||||
LOOP_END()
|
||||
}
|
||||
#undef LOOP_BEGIN
|
||||
#undef LOOP_END
|
||||
}
|
||||
|
||||
void Clear()
|
||||
|
||||
@@ -470,10 +470,11 @@ bool MeshBase::Init(uint32 vertices, uint32 triangles, const Array<const void*,
|
||||
|
||||
// Init collision proxy
|
||||
#if MODEL_USE_PRECISE_MESH_INTERSECTS
|
||||
VertexElement positionsElement = vbLayout[0]->FindElement(VertexElement::Types::Position);
|
||||
if (use16BitIndexBuffer)
|
||||
_collisionProxy.Init<uint16>(vertices, triangles, (const Float3*)vbData[0], (const uint16*)ibData);
|
||||
_collisionProxy.Init<uint16>(vertices, triangles, (const Float3*)vbData[0], (const uint16*)ibData, vertexBuffer0->GetStride(), positionsElement.Format);
|
||||
else
|
||||
_collisionProxy.Init<uint32>(vertices, triangles, (const Float3*)vbData[0], (const uint32*)ibData);
|
||||
_collisionProxy.Init<uint32>(vertices, triangles, (const Float3*)vbData[0], (const uint32*)ibData, vertexBuffer0->GetStride(), positionsElement.Format);
|
||||
#endif
|
||||
|
||||
// Free old buffers
|
||||
|
||||
Reference in New Issue
Block a user