Hi, everybody!
I have a problem…
In my project, I need to show the object convex hull in Unity running time, as shown in image 1.
But I just get the “normal” mesh, like in image 2. (These are figures from Editor Mode, as you can note. But this is what I see in Running Time Mode too).
This is my code:
public void OnRenderObject()
{
MeshFilter filter = null;
MeshCollider collider = null;
Mesh mesh = null;
if( Camera.current.cullingMask == ~(1 << LayerMask.NameToLayer("CameraSensorHiddenLayer")) )
return;
if (_renderOpt == option._MeshCollider)
{
collider = GetComponent<MeshCollider>();
if( collider == null )
return;
mesh = collider.sharedMesh;
}
else if(_renderOpt == option._FilterCollider)
{
filter = GetComponent<MeshFilter>();
if( filter == null )
return;
mesh = filter.sharedMesh;
}
if( mesh == null )
return;
Vector3[] vertices = mesh.vertices;
int[] triangles = mesh.triangles;
LineMaterial.SetPass(0);
GL.PushMatrix();
GL.MultMatrix(transform.localToWorldMatrix);
GL.Begin(GL.LINES);
GL.Color(LineColor);
for (int i = 0; i < triangles.Length/3; i++)
{
int j = i*3;
GL.Vertex( vertices[triangles[j]] );
GL.Vertex( vertices[triangles[j+1]] );
}
GL.End();
GL.PopMatrix();
}
I can’t figure out what I’m doing wrong.
Thanks and sorry for my bad english.