mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Update tsMeshFit.cpp
fix addSphere fix addCapsule now spheres and capsules scale correctly.... hopefully....
This commit is contained in:
parent
399844f7f1
commit
8cf2b1d0ef
1 changed files with 40 additions and 9 deletions
|
|
@ -443,12 +443,27 @@ void MeshFit::addSphere( F32 radius, const Point3F& center )
|
||||||
if ( !mesh )
|
if ( !mesh )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for ( S32 i = 0; i < mesh->mVertexData.size(); i++ )
|
if (mesh->mVerts.size() > 0)
|
||||||
{
|
{
|
||||||
TSMesh::__TSMeshVertexBase &vdata = mesh->mVertexData.getBase(i);
|
for (S32 i = 0; i < mesh->mVerts.size(); i++)
|
||||||
Point3F v = vdata.vert();
|
{
|
||||||
vdata.vert( v * radius );
|
Point3F v = mesh->mVerts[i];
|
||||||
|
mesh->mVerts[i] = v * radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh->mVertexData.setReady(false);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (S32 i = 0; i < mesh->mVertexData.size(); i++)
|
||||||
|
{
|
||||||
|
TSMesh::__TSMeshVertexBase& vdata = mesh->mVertexData.getBase(i);
|
||||||
|
Point3F v = vdata.vert();
|
||||||
|
vdata.vert(v * radius);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
mesh->computeBounds();
|
mesh->computeBounds();
|
||||||
|
|
||||||
mMeshes.increment();
|
mMeshes.increment();
|
||||||
|
|
@ -477,12 +492,28 @@ void MeshFit::addCapsule( F32 radius, F32 height, const MatrixF& mat )
|
||||||
// Translate and scale the mesh verts
|
// Translate and scale the mesh verts
|
||||||
height = mMax( 0, height );
|
height = mMax( 0, height );
|
||||||
F32 offset = ( height / ( 2 * radius ) ) - 0.5f;
|
F32 offset = ( height / ( 2 * radius ) ) - 0.5f;
|
||||||
for ( S32 i = 0; i < mesh->mVertexData.size(); i++ )
|
if (mesh->mVerts.size() > 0)
|
||||||
{
|
{
|
||||||
Point3F v = mesh->mVertexData.getBase(i).vert();
|
for (S32 i = 0; i < mesh->mVerts.size(); i++)
|
||||||
v.y += ( ( v.y > 0 ) ? offset : -offset );
|
{
|
||||||
mesh->mVertexData.getBase(i).vert( v * radius );
|
Point3F v = mesh->mVerts[i];
|
||||||
|
v.y += ((v.y > 0) ? offset : -offset);
|
||||||
|
mesh->mVerts[i] = v * radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh->mVertexData.setReady(false);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (S32 i = 0; i < mesh->mVertexData.size(); i++)
|
||||||
|
{
|
||||||
|
TSMesh::__TSMeshVertexBase& vdata = mesh->mVertexData.getBase(i);
|
||||||
|
Point3F v = vdata.vert();
|
||||||
|
v.y += ((v.y > 0) ? offset : -offset);
|
||||||
|
vdata.vert(v * radius);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mesh->computeBounds();
|
mesh->computeBounds();
|
||||||
|
|
||||||
mMeshes.increment();
|
mMeshes.increment();
|
||||||
|
|
@ -722,7 +753,7 @@ void MeshFit::fitConvexHulls( U32 depth, F32 mergeThreshold, F32 concavityThresh
|
||||||
if ( sphereMaxError > 0 )
|
if ( sphereMaxError > 0 )
|
||||||
{
|
{
|
||||||
primFitter.fitSphere(ch.m_points.size(), points);
|
primFitter.fitSphere(ch.m_points.size(), points);
|
||||||
sphereError = 100.0f * ( 1.0f - ( meshVolume / primFitter.getSphereVolume() ) );
|
sphereError = 100.0f * ( 1.0f - ( meshVolume / primFitter.getSphereVolume()));
|
||||||
}
|
}
|
||||||
if ( capsuleMaxError > 0 )
|
if ( capsuleMaxError > 0 )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue