- Home /
modify a mesh that is from an fbx import
So, i have an animated humanoid model that was from an fbx import. The model is made a few meshes (head, arms, legs body) and bones for animation. I have the animations all chopped up etc etc. and works as is.
So, the issue is trying to modify a mesh of a specific body part. I have made some code to modify a mesh in C# that works well when using it on a cube or some other primitive shape, but it does not work at all on the model (or its body parts) i imported.
For example, if i attach the script to the model's head, it will change the texture, angle, and material of the head, but the vertices of the mesh does NOT change...and thats the most important part. However, attach this same script to a cube or something, it it works as intended.
So, I can only guess that the skinned mesh within my model is making things difficult? I have no idea why its not updating/changing. Does anybody have any clues to why i cant change the verts at run time? I do some stuff at Start() and Update(), even tho i wont need to update anything if this works as intended (its a one time/loading change)
If you want to see code, check this out, the code is more or less the same. http://unity3d.com/support/documentation/ScriptReference/Mesh.html
thanks for your help
can you post more details about your code? The link only provides the general idea of what you're after; it may be the specifics that are throwing things off.
Answer by kablammyman · Jun 07, 2011 at 05:33 PM
the code is literally the code from the examples, but I foudn out what to do.
Changing the mesh for a skinned mesh object does nothing. What you have to do is change the "sharedMesh" instead. The problem is that if your model is a prefab, any changes you make will permanently change the prefab (without saving, quitting, or anything like that)!
WTF??? This is not good, and makes no sense.
the docs tell me what I just found out the hard way. In case anyone is interested, check it out:
I will make a copy of the mesh first before editing. The trouble will be a trying to "undo" the changes at shutdown, or when the editor stops, or whatever.
OnDisable () will at as a destructor for me...problem solved.
now i need to figure out why the changes i make to the shared mesh dont look the same as they would to a normal mesh
figured it out. you need to give the sharmedmesh the list of triangles before giving the verts. I didnt have this problem with a normal mesh.
Answer by Tasarran · Dec 09, 2011 at 05:40 PM
Here's a snippet of code that I know works. You should be able to apply this to any object, and it will randomly tweak all the verts. If this doesn't work, I would guess it is a conflict with the bones.
// load the vertices
var mesh : Mesh = gameObject.GetComponent(MeshFilter).mesh;
var vertices : Vector3[] = mesh.vertices;
// step through and multiply the coordinates of each point, in effect scaling that point a random amount from the origin
for(i=0 ; i<vertices.length ; i++)
{
vertices[i] *= Random.Range(0.9, 1.1);
}
// apply the vertex changes back to the mesh, recalc normals & bounds
mesh.vertices = vertices;
if (recalculateNormals)
mesh.RecalculateNormals();
mesh.RecalculateBounds();
Your answer
Follow this Question
Related Questions
My meshes arent loading properly. 1 Answer
Im reading a .obj file and converting it to a mesh (doesnt work) 0 Answers
Modifying SkinnedMeshRenderer.sharedMesh.uv Doesnt Reset after Stopping game. 1 Answer
Add a ''valid mesh renderer'' (Can't use my own trees) 0 Answers
White line in a mesh level 0 Answers