-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertexEditing
113 lines (90 loc) · 4.5 KB
/
vertexEditing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.ProBuilder;
public class EdgeEditingMain : MonoBehaviour
{
HashSet<EdgeLookup> edgeLookups;
Dictionary<ProBuilderMesh, HashSet<Edge>> probuilderEdgePair;
Dictionary<int, int> sharedVertexEdgeSelect;
[SerializeField] VertexEditingMain vertexEditingMain;
[SerializeField] float distanceToCameraEdge;
[SerializeField] int commonVertEdgeA;
[SerializeField] int commonVertEdgeB;
[SerializeField] Vector3 commonVertEdgeAPos;
[SerializeField] Vector3 commonVertEdgeBPos;
int localVertEdgeA;
int localVertEdgeB;
int commonEdgeA;
int commonEdgeB;
Dictionary<int, int> sharedVertexEdge;
HashSet<int> listVertsEdge;
Dictionary<int, int> sharedVertexDic;
bool hasSelectedEdge;
void Start()
{
sharedVertexEdge = new Dictionary<int, int>();
sharedVertexEdgeSelect = new Dictionary<int, int>();
edgeLookups = new HashSet<EdgeLookup>();
listVertsEdge = new HashSet<int>();
sharedVertexDic = new Dictionary<int, int>();
}
void Update()
{
}
public void SelectAndEditEdge()
{
if (Input.GetMouseButtonUp(0))
{
probuilderEdgePair = SelectionPicker.PickEdgesInRect(Camera.main, vertexEditingMain.rect, vertexEditingMain.proBuilderMeshList, PickerOptions.Default, 1);
vertexEditingMain.hasSelected = !vertexEditingMain.hasSelected;
hasSelectedEdge = false;
}
if (probuilderEdgePair != null)
{
foreach (KeyValuePair<ProBuilderMesh, HashSet<Edge>> meshAndEdge in probuilderEdgePair)
{
foreach (Edge edges in meshAndEdge.Value)
{
commonEdgeA = edges.a;
commonEdgeB = edges.b;
listVertsEdge.Add(commonEdgeA);
listVertsEdge.Add(commonEdgeB);
}
IList<SharedVertex> sharedVertices = vertexEditingMain.proBuilderMeshList[0].sharedVertices;
SharedVertex.GetSharedVertexLookup(sharedVertices, sharedVertexDic);
edgeLookups = EdgeLookup.GetEdgeLookupHashSet(meshAndEdge.Value, sharedVertexDic);
foreach (EdgeLookup edgeLookupList in edgeLookups)
{
commonVertEdgeA = edgeLookupList.common.a;
commonVertEdgeB = edgeLookupList.common.b;
localVertEdgeA = edgeLookupList.local.a;
localVertEdgeB = edgeLookupList.local.b;
}
commonVertEdgeAPos = vertexEditingMain.proBuilderMeshList[0].positions[localVertEdgeA];
commonVertEdgeBPos = vertexEditingMain.proBuilderMeshList[0].positions[localVertEdgeB];
Vector3 cameraPosition = Camera.main.transform.position;
Vector3 midPointEdge = (commonVertEdgeAPos + commonVertEdgeBPos) / 2;
if (!hasSelectedEdge)
{
distanceToCameraEdge = Vector3.Distance(midPointEdge, cameraPosition);
hasSelectedEdge = true;
}
vertexEditingMain.worldMousePosition = Camera.main.ScreenToWorldPoint(new Vector3(vertexEditingMain.endPositionRec.x, vertexEditingMain.endPositionRec.y, distanceToCameraEdge));
Vector3 positionDifference = vertexEditingMain.worldMousePosition - midPointEdge;
VertexPositioning.TranslateVertices(vertexEditingMain.proBuilderMeshList[0],meshAndEdge.Value,positionDifference);
sharedVertexEdgeSelect.Clear();
edgeLookups.Clear();
vertexEditingMain.sharedVertexList.Clear();
}
}
}
}
// IList<SharedVertex> sharedVertexAll = vertexEditingMain.proBuilderMeshList[0].sharedVertices;
//vertexEditingMain.sharedVertexList.Add(sharedVertexAll[commonVertEdgeA]);
//vertexEditingMain.sharedVertexList.Add(sharedVertexAll[commonVertEdgeB]);
// SharedVertex.GetSharedVertexLookup(vertexEditingMain.sharedVertexList, vertexEditingMain.dicLocalAndCommon);
// VertexPositioning.SetSharedVertexPosition(vertexEditingMain.proBuilderMeshList[0], commonVertEdgeA,
// vertexEditingMain.worldMousePosition + new Vector3(-0.5f,0,0));
// VertexPositioning.SetSharedVertexPosition(vertexEditingMain.proBuilderMeshList[0], commonVertEdgeB,
// vertexEditingMain.worldMousePosition + new Vector3(0.5f,0,0));