Jump to content
  • Advertisement
Sign in to follow this  
leandro81

Scale down mesh permanently

This topic is 4023 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.Position = Vector3.Scale(verts.Position, scalingFactor);
}
}
finally
{
vb.Unlock();
}
}
return clonedMesh;
}

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!