{"id":1749,"date":"2013-03-27T18:30:45","date_gmt":"2013-03-27T15:30:45","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=1749"},"modified":"2013-03-30T02:43:19","modified_gmt":"2013-03-29T23:43:19","slug":"editor-mesh-helper-gizmos","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2013\/03\/27\/editor-mesh-helper-gizmos\/","title":{"rendered":"Editor Mesh Helper Gizmos"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1750\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/03\/27\/editor-mesh-helper-gizmos\/editor_mesh_helper_uv_vertex_normal_color_gizmo\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo.jpg?fit=680%2C650&amp;ssl=1\" data-orig-size=\"680,650\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"editor_mesh_helper_uv_vertex_normal_color_gizmo\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo.jpg?fit=680%2C650&amp;ssl=1\" class=\"alignnone size-full wp-image-1750\" alt=\"editor_mesh_helper_uv_vertex_normal_color_gizmo\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo.jpg?resize=680%2C650\" width=\"680\" height=\"650\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo.jpg?resize=300%2C286&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Started making a mesh helper editor script. Should be useful to see the mesh details easily..<\/p>\n<p><strong>Current features:<\/strong><br \/>\n&#8211; Display selected object details (<a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/DrawGizmo.DrawGizmo.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/DrawGizmo.DrawGizmo.html\" target=\"_blank\">DrawGizmo<\/a>)<br \/>\n&#8211; Draw green boxes on vertex locations (<a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Handles.DotCap.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Handles.DotCap.html\" target=\"_blank\">Handles.DotCap<\/a>)<br \/>\n&#8211; Display vertex number and UV info (<a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Handles.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Handles.html\" target=\"_blank\">Handles.Label<\/a>)<br \/>\n&#8211; Label position is affected by the normals (so that overlapping vertice labes go bit different directions)<br \/>\n&#8211; Draw triangles with blue lines (<a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Handles.DrawPolyLine.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Handles.DrawPolyLine.html\" target=\"_blank\">Handles.DrawPolyLine<\/a>)<br \/>\n&#8211; Line positions are multiplied by 1.005f, so that the default wireframe doesnt block them..<br \/>\n&#8211; Display face normals (numbers and visual line)<br \/>\n&#8211; Hide back facing details (if wanted), works kind of.. (Access to editor camera position\/rotation\/etc: <a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Camera-current.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Camera-current.html\" target=\"_blank\">Camera.current<\/a> , not sure if there is other ways..)<br \/>\n&#8211; Use CustomEditor, instead of trying to modify every selected object (see image#4)<br \/>\n&#8211; Snap to closest vertices (using <a title=\"http:\/\/unitycoder.com\/blog\/2013\/03\/26\/kdtree-find-nearest-object\/\" href=\"http:\/\/unitycoder.com\/blog\/2013\/03\/26\/kdtree-find-nearest-object\/\" target=\"_blank\">kdree<\/a>): Works, but positions in the tree are not yet updated after modifying vertices.. maybe it wouldnt need kdree at all.<br \/>\n&#8211; Vertex position editor : first version works, just need to add mesh update while dragging the vertices<\/p>\n<p><strong>TODO:<\/strong><br \/>\n&#8211; Draw handles with vertex colors (if exists)<br \/>\n&#8211; Vertex color editor<br \/>\n&#8211; Total vertex count<br \/>\n&#8211; Different color\/style for the label texts<br \/>\n&#8211; Pivot position editor<br \/>\n&#8211; Show original mesh outlines<br \/>\n&#8211; Undo functionality (i guess its done with this: <a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Undo.SetSnapshotTarget.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Undo.SetSnapshotTarget.html\" target=\"_blank\">Undo.SetSnapshotTarget<\/a>)<br \/>\n&#8211; UV value editor<br \/>\n&#8211; normal value editor<br \/>\n&#8211; Flip normals tool<br \/>\n&#8211; Export Tools: Export as script (like <a title=\"http:\/\/forum.unity3d.com\/threads\/100857-mMesh-%283ds-Max-mesh-to-unityscript-converter%29\" href=\"http:\/\/forum.unity3d.com\/threads\/100857-mMesh-%283ds-Max-mesh-to-unityscript-converter%29\" target=\"_blank\">mMesh<\/a>)<br \/>\n&#8211; Save modified mesh<br \/>\n&#8211; Button to &#8220;Reset mesh to original&#8221;<br \/>\n&#8211; Show vertex distance from startpoint when dragging<br \/>\n&#8211; Show vertex position (local and world) when dragging<br \/>\n&#8211; Flip \/ Mirror, flips all mesh vertices<br \/>\n&#8211; Maybe later: Removing \/ adding vertices?<br \/>\n&#8211; Maybe later: Optimize mesh? Smoothen\/relax vertices?<br \/>\n&#8211; DX11 stuff?<br \/>\n&#8211;<\/p>\n<p><strong><br \/>\nSNIPPETS:<\/strong><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ calculate triangle centroid (center of 3 points)\r\n\/\/ http:\/\/math.tutorvista.com\/geometry\/centroid.html\r\nVector3 centroid = (vertexpos1+vertexpos2+vertexpos3)\/3;\r\n\r\n\/\/ get mouse world position (without raycasting), inside void OnSceneGUI()..\r\n\/\/huh that took couple hours to get it working..unity docs &gt;&lt;, althought it doesnt work in most cases still..\r\nRay r = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);\r\nVector3 worldPos = r.GetPoint(Vector3.Distance(r.origin,targetObj.position));\r\n<\/pre>\n<p>&#8212;<\/p>\n<p><strong>Image#2:<\/strong> Back facing labels are hidden (kind of)<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1763\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/03\/27\/editor-mesh-helper-gizmos\/editor_mesh_helper_uv_vertex_normal_color_gizmo_2-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo_21.jpg?fit=680%2C519&amp;ssl=1\" data-orig-size=\"680,519\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"editor_mesh_helper_uv_vertex_normal_color_gizmo_2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo_21.jpg?fit=680%2C519&amp;ssl=1\" class=\"alignnone size-full wp-image-1763\" alt=\"editor_mesh_helper_uv_vertex_normal_color_gizmo_2\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo_21.jpg?resize=680%2C519\" width=\"680\" height=\"519\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo_21.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo_21.jpg?resize=300%2C228&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#3:<\/strong> Explosion.. Some problems with <a title=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Handles.PositionHandle.html\" href=\"http:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/Handles.PositionHandle.html\" target=\"_blank\">Handles.PositionHandle<\/a> and moving vertices.. Oh no, broke the default &#8220;cube&#8221; mesh completely, how to reset it? (*Restarting unity fixed it)<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1769\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/03\/27\/editor-mesh-helper-gizmos\/handles_positionhandle_problems_moving_vertices\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/Handles_PositionHandle_problems_moving_vertices.jpg?fit=680%2C309&amp;ssl=1\" data-orig-size=\"680,309\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Handles_PositionHandle_problems_moving_vertices\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/Handles_PositionHandle_problems_moving_vertices.jpg?fit=680%2C309&amp;ssl=1\" class=\"alignnone size-full wp-image-1769\" alt=\"Handles_PositionHandle_problems_moving_vertices\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/Handles_PositionHandle_problems_moving_vertices.jpg?resize=680%2C309\" width=\"680\" height=\"309\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/Handles_PositionHandle_problems_moving_vertices.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/Handles_PositionHandle_problems_moving_vertices.jpg?resize=300%2C136&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#4:<\/strong> Default transform compoment from the inspector went broke also.. local rotation is displayed like this:<br \/>\n*Solved: I had this code: [CustomEditor(typeof(Transform))], replaced it with: [CustomEditor(typeof(MyScriptNameHere))]<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1773\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2013\/03\/27\/editor-mesh-helper-gizmos\/transform_inspector_broken\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/transform_inspector_broken.jpg?fit=357%2C251&amp;ssl=1\" data-orig-size=\"357,251\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"transform_inspector_broken\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/transform_inspector_broken.jpg?fit=357%2C251&amp;ssl=1\" class=\"alignnone size-full wp-image-1773\" alt=\"transform_inspector_broken\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/transform_inspector_broken.jpg?resize=357%2C251\" width=\"357\" height=\"251\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/transform_inspector_broken.jpg?w=357&amp;ssl=1 357w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/transform_inspector_broken.jpg?resize=300%2C210&amp;ssl=1 300w\" sizes=\"auto, (max-width: 357px) 100vw, 357px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Started making a mesh helper editor script. Should be useful to see the mesh details easily.. Current features: &#8211; Display selected object details (DrawGizmo) &#8211; Draw green boxes on vertex locations (Handles.DotCap) &#8211; Display vertex number and UV info (Handles.Label) &#8211; Label position is affected [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1750,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[23,3],"tags":[454,453,358,449,450,448,5,455,451,189,452,102],"class_list":["post-1749","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-functions-unity3d","category-unity3d","tag-adjust","tag-colors","tag-editor","tag-gizmos","tag-handles","tag-helper","tag-mesh","tag-modify","tag-normals","tag-script","tag-uvs","tag-vertices"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2013\/03\/editor_mesh_helper_uv_vertex_normal_color_gizmo.jpg?fit=680%2C650&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-sd","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=1749"}],"version-history":[{"count":36,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1749\/revisions"}],"predecessor-version":[{"id":1755,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1749\/revisions\/1755"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/1750"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=1749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=1749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=1749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}