Scale down mesh permanently

Started by
2 comments, last by leandro81 16 years, 9 months ago
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
<br/>GDNet journal: Endeavours On Managed Code Land
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;

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;        }
Thanks both of you guys,

I will try it out as soon as I get home :)
<br/>GDNet journal: Endeavours On Managed Code Land

This topic is closed to new replies.

Advertisement