-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAxisReset.vsl
76 lines (60 loc) · 1.67 KB
/
AxisReset.vsl
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
////////////////////////
// Description : Edit by ghomist
extern bool ResetAsCenter;
extern bool ResetAsWorld;
extern bool IfKeepOrigin;
void main()
{
Vector pos;
Vector posNew;
Vector entPos;
Vector entPosNew;
Vector vMax(0,0,0);
Vector vMin(0,0,0);
Vector vCenter(0,0,0);
Vector z(0,0,1);
Vector up(0,1,0),right(1,0,0);
Matrix mat;
int count = ac.selection.Size();
for (int i=0; i<count; ++i) {
Entity3D ent = Entity3D.Cast(ac.selection[i]);
if (!ent) continue;
if (IfKeepOrigin) ent = Entity3D.Cast(ac.Copy(ent,false,true));
ent.GetPosition(entPos,null);
Mesh m = ent.GetCurrentMesh();
int vCount = m.GetVertexCount();
if (ResetAsCenter) {
m.GetVertexPosition(0,vMax);
m.GetVertexPosition(0,vMin);
for (int index=0; index<vCount; index++){
m.GetVertexPosition(index,pos);
if (pos.x > vMax.x) vMax.x = pos.x;
if (pos.y > vMax.y) vMax.y = pos.y;
if (pos.z > vMax.z) vMax.z = pos.z;
if (pos.x < vMin.x) vMin.x = pos.x;
if (pos.y < vMin.y) vMin.y = pos.y;
if (pos.z < vMin.z) vMin.z = pos.z;
}
vCenter = (vMax + vMin)/2;
for (int index=0; index<vCount; index++){
m.GetVertexPosition(index,pos);
posNew = pos - vCenter;
m.SetVertexPosition(index,posNew);
}
entPosNew = entPos + vCenter;
ent.SetPosition(entPosNew,null,false);
}
if (ResetAsWorld) {
mat = ent.GetLocalMatrix();
for (int index=0; index<vCount; index++){
m.GetVertexPosition(index,pos);
pos.Rotate(mat);
m.SetVertexPosition(index,pos);
m.GetVertexNormal(index,pos);
pos.Rotate(mat);
m.SetVertexNormal(index,pos);
}
ent.SetOrientation(z,up,right,null,false);
}
}
}