Mar
27
2013

Editor Mesh Helper Gizmos

editor_mesh_helper_uv_vertex_normal_color_gizmo

Started making a mesh helper editor script. Should be useful to see the mesh details easily..

Current features:
– Display selected object details (DrawGizmo)
– Draw green boxes on vertex locations (Handles.DotCap)
– Display vertex number and UV info (Handles.Label)
– Label position is affected by the normals (so that overlapping vertice labes go bit different directions)
– Draw triangles with blue lines (Handles.DrawPolyLine)
– Line positions are multiplied by 1.005f, so that the default wireframe doesnt block them..
– Display face normals (numbers and visual line)
– Hide back facing details (if wanted), works kind of.. (Access to editor camera position/rotation/etc: Camera.current , not sure if there is other ways..)
– Use CustomEditor, instead of trying to modify every selected object (see image#4)
– Snap to closest vertices (using kdree): Works, but positions in the tree are not yet updated after modifying vertices.. maybe it wouldnt need kdree at all.
– Vertex position editor : first version works, just need to add mesh update while dragging the vertices

TODO:
– Draw handles with vertex colors (if exists)
– Vertex color editor
– Total vertex count
– Different color/style for the label texts
– Pivot position editor
– Show original mesh outlines
– Undo functionality (i guess its done with this: Undo.SetSnapshotTarget)
– UV value editor
– normal value editor
– Flip normals tool
– Export Tools: Export as script (like mMesh)
– Save modified mesh
– Button to “Reset mesh to original”
– Show vertex distance from startpoint when dragging
– Show vertex position (local and world) when dragging
– Flip / Mirror, flips all mesh vertices
– Maybe later: Removing / adding vertices?
– Maybe later: Optimize mesh? Smoothen/relax vertices?
– DX11 stuff?


SNIPPETS:

// calculate triangle centroid (center of 3 points)
// http://math.tutorvista.com/geometry/centroid.html
Vector3 centroid = (vertexpos1+vertexpos2+vertexpos3)/3;

// get mouse world position (without raycasting), inside void OnSceneGUI()..
//huh that took couple hours to get it working..unity docs ><, althought it doesnt work in most cases still..
Ray r = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
Vector3 worldPos = r.GetPoint(Vector3.Distance(r.origin,targetObj.position));

Image#2: Back facing labels are hidden (kind of)

editor_mesh_helper_uv_vertex_normal_color_gizmo_2

Image#3: Explosion.. Some problems with Handles.PositionHandle and moving vertices.. Oh no, broke the default “cube” mesh completely, how to reset it? (*Restarting unity fixed it)

Handles_PositionHandle_problems_moving_vertices

Image#4: Default transform compoment from the inspector went broke also.. local rotation is displayed like this:
*Solved: I had this code: [CustomEditor(typeof(Transform))], replaced it with: [CustomEditor(typeof(MyScriptNameHere))]

transform_inspector_broken


3 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.