# elongate or scale limbs of a model in XNA

I'd like to create one model that I import into an XNA game.

I'd like to be able to copy this model and make programmatic modifications to it during execution (with the intent of using the same model to represent multiple characters in the game). For example, I'd like to make the legs slightly longer or shorter, or the waist slightly fatter or thinner, or the head slightly smaller or larger.

I know how to use transforms to modify a mesh, but it seems that what I need here is to apply a transform to only a subset of vertices in that mesh. I have no idea how to do this in XNA, or if it's even supported.

Two questions: 1) is functionality like this supported in XNA? 2) if so, what kind of methods are used to obtain the desired result?

(note, this was crossposted from stackoverflow, this forum was recommended as a better place for my question)

it can be done modifying the bone transform of your model.

You don't need submeshes, each vertex in a model should have a bone weight property that quantify how that vertex is affected by the bone transform.

In this image each color defines the bone that is applied to each vertex.

You will have a bone hierarchy tree that seems to this skeleton, that way if you change athe forearm bone, scaling it, it will affect to the hand bone.

Xna offers you a Model class that let you access to the Bones, but you have to recalcultate the bone transform by yourself. And of course the model have to be created with the skeleton that you need.

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.model_members(v=xnagamestudio.40).aspx

You should have to do something similiar to:

// Save the original bone transforms that are relative to its parents.
Model.CopyBoneTransformsTo ( Backup );

// I have not done this ever, but I would test this:
Model.Bones.Item["Hand"].Transform = Matrix.CreateScale(1,1,1.5f) * Model.Bones.Item["Hand"].Transform;
or
Model.Bones.Item["Hand"].Transform = Model.Bones.Item["Hand"].Transform * Matrix.CreateScale(1,1,1.5f);


Remember that order in matrix multiplication is very important.

It depends somewhat on the format of the model you are attempting to perform these transformations on. Some models are implemented as a single monolithic mesh, and it in this case it may be difficult to isolate the vertices which make up the arms, or legs for example. Although other commenters may know a way to work with such a model.

Many models are implemented as a hierarchy of sub-meshes, and this can be defined by the modeller when the asset is created. If you have created the model yourself or an artist has created it for you, you the arms could be made a separate sub-mesh. You could then identify these in code and perform your transformation on only this sub-mesh.

Personally, I am a programmer and not a modeller myself, so I am unsure as to the specifics of this process in the modelling software, but it is certainly possible.

Also, you may want to bear in mind that transforming vertices might have an effect on any skinned animations provided with the model, although I'm unsure about the specifics of this.

Another approach that might give more plausible results would be to a have an animation with keyframes that range between really thin and really fat, and then 'tweening' between these frames via interpolation before copying the vertices to give your new base model. Simple programmatic manipulation of the vertex data via something like linear interpolation might result in some strange and artificial looking results.

EDIT: Taking into account other suggestions and approaches I had not considered such as other reply on bone weighting