Hi there guys. I got the script below from a forum post that I (unfortunetally) cant remember where, but thanks to the author. I converted it to C# and it works fine, just attach it to a gameObject that has a MeshFilter. My question is this: This script draws all the lines including the diagonal lines to create triangles in stead of four-sided polys and that is what I need - think about the typical way 3DS Max would draw an editable poly. Can someone see a way to mod this code to avoid it from drawing the diagonal lines? Any help will be appreciated! Here is the C# version, feel free to use it! Code (csharp): using UnityEngine; using System.Collections; using System.Collections.Generic; public class wire_frame : MonoBehaviour { Vector3 P0 ; Vector3 P1 ; Vector3 P2 ; List<Vector3> wires = new List<Vector3>(); Color lineColor ; public GameObject myMesh; static Material lineMaterial; void Start () { CreateLineMaterial(); MeshFilter filter = myMesh.GetComponent<MeshFilter>(); var mesh = filter.mesh; var vertices = mesh.vertices; var triangles = mesh.triangles; print(vertices.Length); for (int k = 0; k < triangles.Length / 3; k++) { wires.Add (vertices[triangles[k * 3]]); wires.Add (vertices[triangles[k * 3 + 1]]); wires.Add (vertices[triangles[k * 3 + 2]]); } wires.Add (vertices[triangles[triangles.Length - 2]]); wires.Add (vertices[triangles[triangles.Length - 1]]); } void OnPostRender() { lineMaterial.SetPass(0); GL.Begin(GL.LINES); GL.Color(lineColor); for (int i = 0; i < wires.Count / 3; i++) { P0 = myMesh.transform.TransformPoint (wires[i * 3]); P1 = myMesh.transform.TransformPoint (wires[i * 3 + 1]); P2 = myMesh.transform.TransformPoint (wires[i * 3 + 2]); GL.Vertex3(P0.x, P0.y, P0.z); GL.Vertex3(P1.x, P1.y, P1.z); GL.Vertex3(P2.x, P2.y, P2.z); GL.Vertex3(P0.x, P0.y, P0.z); } GL.End(); } static void CreateLineMaterial() { if( !lineMaterial ) { lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" + "SubShader { Pass { " + " Blend SrcAlpha OneMinusSrcAlpha " + " ZWrite Off Cull Front Fog { Mode Off } " + "} } }" ); lineMaterial.hideFlags = HideFlags.HideAndDontSave; lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave; } } }
There isn't really a way, aside from creating the quads manually or parsing a format where the mesh is stored as quads instead of triangles. --Eric
Thanks eric. Im still curious though how an app like 3ds max display these "square" lines in the top, left and right viewports for example, and you have to convert the mesh away from a poly to see the triangles
They're storing the mesh as quads (or other polygons) internally, so they can display lines that way. Once something has been converted to triangles, it's fairly hard to convert back to quads. --Eric
Attach the script to main camera and drag your gameobject into the variable field. Sorry my first explanation was wrong!