I'm trying to read the vertices from a mesh that I've imported into my scene from an fbx file.
Something like this:
public MeshFilter MyMesh;
for (int i=0; i<MyMesh.sharedMesh.vertices.Length; i++)
Debug.Log("Vertex #"+i + " "+MyMesh.sharedMesh.vertices*);*
*<p>The mesh renders fine in the scene, and I print the correct number of vertices, but they always come out as (0,0,0).</p>*
*<p>Any ideas what I'm doing wrong?</p>*
OK, I'm an idiot...great first post :) The sizes were smaller than the precision of the Vector3 string printing. Doesn't solve my real problem, but gets me past this false alarm. nothing to see here...
In the interest of making up for my stupid question I'll post what ended up being the real problem, and the solution I found for it (although I'm still not sure why the solution was necessary).
I was trying to create a SkinnedMeshRenderer from a mesh template imported from an fbx file. I have hundreds of these in my scene, and to try and improve performance I wanted to procedurally generate a skinned mesh with one bone for each instance of the template I wanted in the scene.
I was following the example here:
But when I tried to do the following:
Mesh mesh = new Mesh();
mesh.vertices = new Vector3[TileMesh.sharedMesh.vertices.Length];
for (int i=0; i<TileMesh.sharedMesh.vertices.Length; i++)
mesh.vertices _= TileMesh.sharedMesh.vertices*;*_
_*<p>The values in mesh.vertices remained (0,0,0).</p>*_
_*<p>For whatever reason this (below) ended up working and fixing my problem. Perhaps it's because mesh.vertices is a read only property, I don't know. If that was the case I would have expected a compile error...but it's working now so I'm happy.</p>*_
_*Mesh mesh = new Mesh();*_
_*Vector3  vertices = new Vector3[TileMesh.sharedMesh.vertices.Length];*_
_*for (int i=0; i<TileMesh.sharedMesh.vertices.Length; i++)*_
<em><em>vertices _= TileMesh.sharedMesh.vertices*;*_</em></em>
<em><em>_*mesh.vertices = vertices;*_</em></em>
<em><em>_*<p>Still curious why I had to do this, but maybe this will help someone else in the future.</p>*_</em></em>