• Advertisement
Sign in to follow this  

Scale down mesh permanently

This topic is 3840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi again, I have a mesh and would like to have several versions of it, each with a different size. But, instead of resizing it on the main loop, before drawing it, I would like to do the job as part of the game initialization, since i need to create separate geometries to input the Newton Physics library (since newton doesn't support model scaling). How could I achieve that? (Oh, and I'm using C#) Thanks in advance, Leandro

Share this post


Link to post
Share on other sites
Advertisement
Given that the center of the scaling operation is at 0,0,0, you can simply loop through all the vertices in the mesh and multiply their xyz coordinates by some factor

for each vertex
x*=factor;
y*=factor;
z*=factor;


Share this post


Link to post
Share on other sites
tell me if it works:


public static Mesh ScaleMesh(Mesh mesh, float scalingFactor)
{
Mesh clonedMesh = mesh.Clone(mesh.Options.Value, mesh.VertexFormat, mesh.Device);

using (VertexBuffer vb = clonedMesh.VertexBuffer)
{
CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])vb.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.None, clonedMesh.NumberVertices);
try
{
for (int i = 0; i < verts.Length; i++)
{
verts[i].Position = Vector3.Scale(verts[i].Position, scalingFactor);
}
}
finally
{
vb.Unlock();
}
}
return clonedMesh;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement