Morphing a skinned mesh

Hi,

I mailed to Joachim about a problem accessing the vertices of a skinned mesh.
There Joachim told me the script hereunder should work

function Start ()
{
mesh = Instantiate(GetComponent(SkinnedMeshRenderer).sharedMesh);
GetComponent(SkinnedMeshRenderer).sharedMesh = mesh;
}

function Update ()
{
var vertices : Vector3[ ] = mesh.vertices;
for(var i=0;i<vertices.Length;i++)
{
vertices*.y=1.0;*
}
// for(var vertex : Vector3 in vertices)
// {
// vertex.y=1.0;
// }
mesh.vertices = vertices;
}
AND IT DOES WORK.
But if I try the exact same script on a static mesh without skin, then it returns a null reference or something and doesn’t want to run.
Is there a difference in getting access to vertices between a RIGGED/SKINNED and a NORMAL mesh ?
I was thinking about loading a skinnet mesh and save its vertex data in an array, then load in some morph poses as static meshes and save their vertices also in arrays. Then I could lerp between the poses by applying the vertex arrays of the poses to the skinned/rigged vertex array.
But therefore I need to be able to access both types of vertex arrays.
Hopefully somebody can help me a little.
Tns in advance

If your mesh does not have a SkinnedMeshRenderer then you GetComponent() will return nothing, so your mesh variable will be null. Did you try using MeshRenderer instead of SkinnedMeshRenderer when the script is attached to a static mesh?

I can’t believe I ever did this in an old engine I used (3drad). Someone else wrote a morph handler and I did the following:

I rewrote it to make a mesh reader that created an array of points in the base model this was done once at runtime in both the builder project and the game project.

Then I rewrote it to create delta (difference) arrays for each morph target. I saved these out to files (maybe one file, I can’t remember now).

Then I rewrote it to handle all of these at runtime through user input.

In the end it was probably four scripts and a bit of trouble to set up, but once it was done, it was easy to implement. Sort of a home grown pipeline. The resulting game only used the code to read the initial model and then the handler, so I had a separate project for building the arrays.

I would be willing to contribute to a team effort where we make some kind of solution like this. The Morpher on the Wiki is a great place to start. Any takers?