# Scale down mesh permanently

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

## 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 on other sites
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 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 on other sites
Thanks both of you guys,

I will try it out as soon as I get home :)

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 104
• 11
• ### Forum Statistics

• Total Topics
632978
• Total Posts
3009681
• ### Who's Online (See full list)

There are no registered users currently online

×