Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- // Super simple/crappy MeshEditor by Alec Holowka http://infiniteammo.ca
- [CustomEditor (typeof(Transform))]
- public class EditMesh : Editor
- {
- public Mesh mesh;
- public Transform targetTransform;
- void OnEnable()
- {
- targetTransform = (Transform)target;
- MeshFilter meshFilter = targetTransform.GetComponent<MeshFilter>();
- if (meshFilter)
- {
- mesh = meshFilter.sharedMesh;
- }
- }
- void OnSceneGUI()
- {
- if (mesh)
- {
- bool meshChanged = false;
- int c = 0;
- foreach (Vector3 vertex in mesh.vertices)
- {
- Vector3 originalPosition = targetTransform.TransformPoint(vertex);
- //Vector3 newPosition = Handles.PositionHandle(originalPosition, Quaternion.identity);
- Vector3 newPosition = Handles.FreeMoveHandle(originalPosition, Quaternion.identity, 0.05f, Vector3.zero, Handles.CircleCap);
- if (newPosition != originalPosition)
- {
- Vector3[] vertices = mesh.vertices;
- vertices[c] = targetTransform.InverseTransformPoint(newPosition);
- mesh.vertices = vertices;
- meshChanged = true;
- break;
- }
- //Handles.CubeCap(c, targetTransform.TransformPoint(vertex), Quaternion.identity, 0.05f);
- c++;
- }
- if (meshChanged)
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement