- Home /
How to resize mesh to fbx model gameobject?
Hi, I'm using the mesh filter and renderer to get a hold of the vertices of the mesh and assign spheres to the mesh, but I'm using an fbx model which has a skinned mesh renderer by default. I've managed to assign spheres to each vertex but the mesh itself doesn't match the size or the rotation of the actual model.
I want to assign the spheres to the textured fbx model like in the image but i can't get the vertex information from it. I read on other posts about SkinRenderer.BakeMesh(), but I have no idea how to use it because the document is really ambiguous on how to use it. I have an array of vertices which I get from mesh.vertices. I tried changing the size and rotation in the blend file that it was made in but no difference. I also tried to putting the mesh in an empty gameobject and resizing it that way but the result is the same. Thanks!
Answer by HarshadK · Aug 03, 2017 at 05:08 AM
The mesh.vertices array gives the local position of the vertices which is relative to the center of the object. And seems like you are trying to assign your spheres at those positions and the position you are passing is world position which is why they are not at correct positions. Use Transform.TransformPoint to convert local position of your vertices to world position and pass that position to your spheres.
Considering the script is assigned to your model itself below is an untested code but should give you the idea.
for(int i = 0; i < mesh.vertices.Length; i++) {
// Here the position is transformed based on which object the script is attached to.
sphere.transform.position = transform.TransformPoint(mesh.vertices[i]);
}
The spheres no longer attach to the vertices using this code they just fly of in another direction. This is the code
for(int i = 0; i < particleSetUp.vertices.Length; i++)
{
//myTransform.position = myTransform.parent.position + particleSetUp.vertices[Random.Range(0, i)];
myTransform.position = myTransform.TransformPoint( particleSetUp.vertices[Random.Range(0, i)]);
}
I'm using Random.Range cause I want the spheres to attach to a random point on the mesh. This class is attached to each individual spheres created.
Thanks I got it to work in the end, I just needed to change "transform.Transformpoint" to "transform.parent.TransformPoint" the spheres were the child of the textured model. Now I need the spheres to move around with the mesh while animating. Thanks for your help!
Your answer
Follow this Question
Related Questions
Android performance problem on model joints(Rig). 1 Answer
Simple mesh deformation : Mesh.vertices or vertex shader with displacement texture ? 1 Answer
Mesh vertex count differs on Mac/Windows 1 Answer
horseshoe game - convex mesh colliders with interior spaces 1 Answer
iOS hardware limitations. 1 Answer