Advertisement
infinite_ammo

EditMesh.cs

Apr 8th, 2012
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4.  
  5. // Super simple/crappy MeshEditor by Alec Holowka http://infiniteammo.ca
  6.  
  7. [CustomEditor (typeof(Transform))]
  8. public class EditMesh : Editor
  9. {
  10.     public Mesh mesh;
  11.     public Transform targetTransform;
  12.  
  13.     void OnEnable()
  14.     {
  15.         targetTransform = (Transform)target;
  16.         MeshFilter meshFilter = targetTransform.GetComponent<MeshFilter>();
  17.         if (meshFilter)
  18.         {
  19.             mesh = meshFilter.sharedMesh;
  20.         }
  21.     }
  22.  
  23.     void OnSceneGUI()
  24.     {
  25.         if (mesh)
  26.         {
  27.             bool meshChanged = false;
  28.             int c = 0;
  29.             foreach (Vector3 vertex in mesh.vertices)
  30.             {
  31.                 Vector3 originalPosition = targetTransform.TransformPoint(vertex);
  32.                 //Vector3 newPosition = Handles.PositionHandle(originalPosition, Quaternion.identity);
  33.                 Vector3 newPosition = Handles.FreeMoveHandle(originalPosition, Quaternion.identity, 0.05f, Vector3.zero, Handles.CircleCap);
  34.                 if (newPosition != originalPosition)
  35.                 {
  36.                     Vector3[] vertices = mesh.vertices;
  37.                     vertices[c] = targetTransform.InverseTransformPoint(newPosition);
  38.                     mesh.vertices = vertices;
  39.                     meshChanged = true;
  40.                     break;
  41.                 }
  42.                 //Handles.CubeCap(c, targetTransform.TransformPoint(vertex), Quaternion.identity, 0.05f);
  43.                 c++;
  44.             }
  45.  
  46.             if (meshChanged)
  47.             {
  48.  
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement