Skip to content

Commit

Permalink
fixed compound returnning zero volume
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJerez committed Oct 22, 2024
1 parent 3293eeb commit 79c5feb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,14 @@ void ndShapeCompound::DebugShape(const ndMatrix& matrix, ndShapeDebugNotify& deb

ndFloat32 ndShapeCompound::GetVolume() const
{
ndAssert(0);
return ndFloat32(0.0f);
ndFloat32 volume = ndFloat32 (0.0f);
ndTreeArray::Iterator iter(m_array);
for (iter.Begin(); iter; iter++)
{
const ndShapeInstance* const collision = iter.GetNode()->GetInfo()->GetShape();
volume += collision->GetVolume();
}
return volume;
}

ndFloat32 ndShapeCompound::GetBoxMinRadius() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,28 @@ long long UNewtonCollisionConvexApproximate::CalculateStaticMeshHash() const
const UStaticMesh* const staticMesh = staticComponent->GetStaticMesh().Get();
check(staticMesh);
const FStaticMeshRenderData* const renderData = staticMesh->GetRenderData();
check(renderData);
const FStaticMeshLODResourcesArray& renderResource = renderData->LODResources;
if (renderData)
{
const FStaticMeshLODResourcesArray& renderResource = renderData->LODResources;

//const FVector uScale(GetComponentTransform().GetScale3D());
//const ndVector scale(ndFloat32(uScale.X), ndFloat32(uScale.Y), ndFloat32(uScale.Z), ndFloat32(0.0f));
//const ndVector bakedScale(scale.Scale(UNREAL_INV_UNIT_SYSTEM));
//const FVector uScale(GetComponentTransform().GetScale3D());
//const ndVector scale(ndFloat32(uScale.X), ndFloat32(uScale.Y), ndFloat32(uScale.Z), ndFloat32(0.0f));
//const ndVector bakedScale(scale.Scale(UNREAL_INV_UNIT_SYSTEM));

const FStaticMeshLODResources& renderLOD = renderResource[0];
const FStaticMeshVertexBuffers& staticMeshVertexBuffer = renderLOD.VertexBuffers;;
const FPositionVertexBuffer& positBuffer = staticMeshVertexBuffer.PositionVertexBuffer;
for (ndInt32 i = 0; i < ndInt32(positBuffer.GetNumVertices()); ++i)
{
const FVector3f p(positBuffer.VertexPosition(i));
hash = ndCRC64(&p, sizeof(FVector3f), hash);
}
const FRawStaticIndexBuffer& indexBuffer = renderLOD.IndexBuffer;
for (ndInt32 i = 0; i < ndInt32(indexBuffer.GetNumIndices()); i += 3)
{
ndInt32 j = indexBuffer.GetIndex(i);
hash = ndCRC64(&j, sizeof(ndInt32), hash);
const FStaticMeshLODResources& renderLOD = renderResource[0];
const FStaticMeshVertexBuffers& staticMeshVertexBuffer = renderLOD.VertexBuffers;;
const FPositionVertexBuffer& positBuffer = staticMeshVertexBuffer.PositionVertexBuffer;
for (ndInt32 i = 0; i < ndInt32(positBuffer.GetNumVertices()); ++i)
{
const FVector3f p(positBuffer.VertexPosition(i));
hash = ndCRC64(&p, sizeof(FVector3f), hash);
}
const FRawStaticIndexBuffer& indexBuffer = renderLOD.IndexBuffer;
for (ndInt32 i = 0; i < ndInt32(indexBuffer.GetNumIndices()); i += 3)
{
ndInt32 j = indexBuffer.GetIndex(i);
hash = ndCRC64(&j, sizeof(ndInt32), hash);
}
}
}
return hash;
Expand Down
10 changes: 8 additions & 2 deletions newton-4.00/sdk/dCollision/ndShapeCompound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,14 @@ void ndShapeCompound::DebugShape(const ndMatrix& matrix, ndShapeDebugNotify& deb

ndFloat32 ndShapeCompound::GetVolume() const
{
ndAssert(0);
return ndFloat32(0.0f);
ndFloat32 volume = ndFloat32(0.0f);
ndTreeArray::Iterator iter(m_array);
for (iter.Begin(); iter; iter++)
{
const ndShapeInstance* const collision = iter.GetNode()->GetInfo()->GetShape();
volume += collision->GetVolume();
}
return volume;
}

ndFloat32 ndShapeCompound::GetBoxMinRadius() const
Expand Down

0 comments on commit 79c5feb

Please sign in to comment.