No, you are asking about something that is as elusive as the lockness monster, debated as much as as Area 51 and a club to bash the gopher heads of anyone who asks for years.
I’ve heard that people have done it… I’ve seen blurry shaky video… is it a hubcap or a skinned morph??? Experts have argued for years!
This seems as one of those tightly held secrets for the “people in the know”, I’m convinced that it would be easier to find the Arc Of The Covenant than to find this, as one person put it, “only 20 lines of code”
My travels led me to an ancient Abby in Utrecht Holland where deep in the Catacombs I unearthed a stone carvings in an ancient Dutch dialect, when it was translated it foretold that support for animated vertices withing Unity3d would be released Dec 21, 2012.
He doesn’t at the moment Hippo hes stopped selling it according to his signature. Been waiting to see if it comes back to life but it’s been a while now.
var targetMesh : Mesh; // Mesh we want to edit. Should be the mesh of the model this is applied to.
var targetMesh_base : Mesh; // Copy of that mesh, this is our base mesh, which the morphs will be applied to.
var targetMesh_morph1 : Mesh; // Morph map poses...
var targetMesh_morph2 : Mesh; // ...
private var targetVerts_base : Vector3[]; // Vertex positions of our base mesh.
private var targetVerts_morph1 : Vector3[]; // Vertex positions of our morph meshes...
private var targetVerts_morph2 : Vector3[]; // ...
private var tempVerts : Vector3[]; // Temporary holder for the vertex positions in the current morph state.
private var iDefault : float; // Length of while(i--) loop.
function Start() {
// Load up the vertices.
targetVerts_base = targetMesh_base.vertices;
targetVerts_morph1 = targetMesh_morph1.vertices;
targetVerts_morph2 = targetMesh_morph2.vertices;
// Initialise the temporary holder and while() loop to be the correct length.
tempVerts = new Vector3[targetMesh.vertices.Length];
iDefault = targetMesh.vertices.Length;
// Pre-subtract the default vertex positions from the morph vertex positions. Saves a calculation in the LateUpdate loop.
// I've run it the i-- way as it's *far* faster than any other method and it isn't important that we do the vertices in numerical order.
var i = iDefault;
while (i--) {
targetVerts_morph1[i] = targetVerts_morph1[i] - targetVerts_base[i];
targetVerts_morph2[i] = targetVerts_morph2[i] - targetVerts_base[i];
}
}
function LateUpdate() {
// Depending on how many morph targets you have, this bit could be optimised to only calculate the non-zero morph strengths. As there's only two at the moment it hardly seems worth it.
morph1Strength = Mathf.Sin(Time.time);
morph2Strength = Mathf.Cos(Time.time);
// Again, i-- method. This is where it really shines, as it's being called each frame and this method will give you a lot of FPS back.
var i = iDefault;
while (i--) {
tempVerts[i] = targetVerts_base[i] - (targetVerts_morph1[i] * morph1Strength) - (targetVerts_morph2[i] * morph2Strength);
}
targetMesh.vertices = tempVerts;
}
This is the one I wrote for testing morphs on a skinned mesh - should work with non-skinned.
Note that you’ll need two copies of the mesh you want to modify.
One (the target mesh - the one applied to your model in-game) actually gets physically modified - this is a permanent change to the model until you re-import it manually. i.e. Any morphs applied will stay there even after you exit Play mode. This is why we have two base meshes.
The other (the base target mesh - identical in every respect, but doesn’t get modified, only copied from) is used as the reference to work out the original vertex positions of your target mesh.