C#. Inappropriate mesh vertex coordinates returned by another class
Hi all,
I have made two scripts, one which retrieves geometrical information from an object, such as mesh vertex position, and another script which prints out this information to an XML.
Problem:
When I print out the information and instantiate spheres for debug purpose based on information that I am retrieving directly via button from geometry information script, everything is correct as it should be.
When I reference the geometry information script from my XML print script, the outputted coordinates of vertices are as if the object was positioned on X=Y=Z=0 with scale of 1
I suspect this has something to do with what kind of information has been passed into the Geometrical Information script when it's triggered via XML print script.
Script which prints and processes geometrical data retreived from Geometry script. This gives me data as if the relevant game object was on X-Y-Z=0
I read your code from the early editings, idk why you delete it.
maybe you already solved it as you probably already know mesh.getvertices return on local space
I think you knew that, because you used transform.TransformPoint on the bulid of the mesh from the xml, I think to the script that is handling the building from xml,haven't the same pos and scale than the first...
both possible solutions are, both storing on the xml the scale and pos of the original transform
if you want to have the same exact object, build the mesh again on an cleared object, and apply scale and position on the transform after build the mesh, then will be scaled properly
if you want to apply the scale and pos to the vertex, without modify the transform, you can do some like:
//retreive info of scale and pos on oldScale and oldPosition vars
for (int a = 0; a < vertexPositions.Count; a++)
{
Vector3 worldPt = transform.TransformPoint(vertexPositions[a]);
worldPt = (worldPt*oldScale)+oldPosition;
//apply to vertex array
...
this is to modify the mesh directly without touch the new transform