This project is read-only.

How can I scale a TriangleMeshObject object?

Nov 6, 2008 at 3:29 PM
Hello, this is my question, How can I scale a TriangleMeshObject object?.
I read the: JigLibX sample is missing some code? discussion, but I'm not able to scale, only to position the TriangleMeshObject.
A little example code will be great.

Thanks in advance for your reply.

Nov 10, 2008 at 7:43 AM
I respond myself:

I some of you need to scale a mesh , use this TriangleMeshObject class constructor, obviously the last parameter will be the scale to use:

        public TriangleMeshObject(Game game, Model model, Matrix orientation, Vector3 position,Vector3 scale)
            : base(game, model)
        {
            this.scale = scale;
            body = new Body();
            //
            body.Position = orientation.Translation;
            //
            collision = new CollisionSkin(body);

            triangleMesh = new TriangleMesh();

            Dictionary<string, object> tagData = model.Tag as Dictionary<string, object>;
            Vector3[] vertices = tagData["Vertices"] as Vector3[];
            int[] indices = tagData["Indices"] as int[];

            List<Vector3> vertexList = new List<Vector3>();
            List<TriangleVertexIndices> indexList = new List<TriangleVertexIndices>();

            for (int i = 0; i < indices.Length / 3; i++)
            {
                indexList.Add(new TriangleVertexIndices(indices[i * 3 + 2], indices[i * 3 + 1], indices[i * 3 + 0]));
            }

            for (int i = 0; i < vertices.Length; i++)
            {
                //vertexList.Add(vertices[i]);
                Vector3 vd = Vector3.Multiply(vertices[i],scale);
                Vector3 vc =  Vector3.Transform(vd, orientation);
                
                vertexList.Add(vc);
                //vertexList.Add(Vector3.Transform(vertices[i], orientation));

            }
            //boxS.ApplyLocalTransform(new Transform(new Vector3 (-1,-1,-1), Matrix.Identity));
            triangleMesh.CreateMesh(vertexList, indexList, 4, 1.0f);
            collision.AddPrimitive(triangleMesh, 1, new MaterialProperties(0.1f, 0.7f, 0.6f));

            
            body.CollisionSkin = collision;
            
            body.Mass = 100;
            body.Immovable = true;
            body.EnableBody();
            PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision);
        }