in Unity3D how to convert / compare vertices positions in mesh to world coordinates

Viewed 397

In unity3D i use quadsmesh to render massives and larges starfields like novas and galaxies at high FPS using only one gameobject with a near fade effect on the quads using shaders.

While building the mesh I store each stars (vertices) positions and some parameters in an array and spawn gameobjects for each items inside a specified range, and want to destroy those who are to far away to keep GameObjects instances as low as possible.

When the mesh and all it's parents object have their transforms positions set like bellow it's working very well :

position x:0 y:0 z:0 rotation x:0 y:0 z:0 scale x:1 y:1 z:1

When I apply a transform (position rotation or scale) to the mesh object or any parent, I lose the synchronisation between spawned objects positions and starfield rendered positions

Already tried this with limited success

public Vector3 GetVertexWorldPosition(Vector3 vertex, Transform owner)
{
    return owner.localToWorldMatrix.MultiplyPoint3x4(vertex);
}

I'm able to workaround for Vector3Positioppn using

star.position = GetVertexWorldPosition(vertex, starfield.transform) + starfield.tranform.position;

Is there a standard method to convert the position of a vertice in a mesh (whatever the transforms position rotation and scale of the mesh) to the scene world position ?

0 Answers
Related