-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcubedeformer.cfg
More file actions
205 lines (179 loc) · 4.66 KB
/
cubedeformer.cfg
File metadata and controls
205 lines (179 loc) · 4.66 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Cube Deformer functions, by @Salatiel#5274
// version: 23/01/2022
// indexes: [+x, -x, +y, -y]
// [[movesel x, movesel y], [movesel dir, movesel dim]], camera yaw
.selfacesheet = [
[[1 1][-1 1] 90]
[[0 0][1 1] -90]
[[1 0][1 0] 180]
[[0 1][-1 0] 0]
]
// indexes: [+x, -x, +y, -y]
// [movesel dim, [[TL x, TL y, TL z], [TR x, TR y, TR z], [BL x, BL y, BL z], [BR x, BR y, BR z]]]
//
// _face 3_
// |TL TR|
// | |
// | |
// |BL____BR|< this is always the origin
//
.selcornersheet = [
[[1 1 1][1 0 1][1 1 0][1 0 0]]
[[0 0 1][0 1 1][0 0 0][0 1 0]]
[[0 1 1][1 1 1][0 1 0][1 1 0]]
[[1 0 1][0 0 1][1 0 0][0 0 0]]
]
// 0: +x, 1: -x, 2: +y, 3: -y
getlookatface = [
local dir
dir = (mod (round (divf (getcamyaw) 90)) 4)
result (substr [3021] (? (= $dir -1) 3 $dir) 1)
]
editinview 0; nompedit 0 // their default values prevent some commands from working properly
// gotoface <face 0..3> [command] <optional delay to fix gotoface callback (default: 500ms)>
gotoface = [
local selpos face
selpos = (getselpos)
if (|| (=s $arg1 "") (= $arg1 -1)) [arg1 = (getlookatface)]
face = (at $.selfacesheet $arg1)
if $editing [edittoggle]
edittoggle
sleep 0 [entdrop @entdrop]
entdrop 0
entcancel
newent teledest; entset teledest (at $face 2) -31349 0 0 -31349
newent teleport -31349 -1 31349 -1 -31349
edittoggle
sleep 0 [
edittoggle
entselect [|| (=s (entget) (
concat "teledest" @@(at $face 2) -31349 0 0 -31349
)) (=s (entget) (
concat "teleport" -31349 -1 31349 -1 -31349
))]
delent
setselpos @[selpos]
movesel @(at (at $face 0) 0) 1
movesel @(at (at $face 0) 1) 0
selpos = (getselpos)
gridpower (- $gridpower 1)
sleep 0 [
setselpos @[selpos]
movesel (at (at (at $.selfacesheet @@arg1) 1) 0) (at (at (at $.selfacesheet @@arg1) 1) 1)
movesel 1 2
gotosel
cancelsel
gridpower (+ $gridpower 1)
sleep 0 [
setselpos @@@[selpos]
reorient
if (!= (strstr [@@@@arg2] "gotoface") -1) [
sleep (? (< $numargs 3) @@@@arg3 500) [@@@@@arg2]
] [
sleep 0 [@@@@@arg2]
]
]
]
]
]
// gotoedge <edge 0..3> [command]
gotoedge = [
local face.index corner.index corner.xyz selpos
face.index = (getlookatface); corner.index = $arg1
corner.xyz = (at (at $.selcornersheet $face.index) $corner.index)
selsave
selpos = (getselpos)
gridpower (max (- $gridpower 1) 0)
sleep 0 [
setselpos @[selpos]
movesel @(at $corner.xyz 0) 0
movesel @(at $corner.xyz 1) 1
movesel @(at $corner.xyz 2) 2
gotoselcenter 0 [
if (!= @@arg3 1) [
gridpower (+ $gridpower 1)
setselpos @@[selpos]
selswap
]
sleep 0 [@@@arg2]
]
]
]
// shortcuts
// same as movesel, but executes a command every move.
// moveseldo x y z [command] <straight line 0/1>
moveseldo = [
local x y z
x = 0; y = 0; z = 0
loop s (+ (+ (abs $arg1) (abs $arg2)) (abs $arg3)) [
if (= $s 0) [arg4]
if (!= $x $arg1) [
movesel (? (< $arg1 0) -1 1) 0
x = (+ $x 1)
]
if (!= $y $arg2) [
movesel (? (< $arg2 0) -1 1) 1
y = (+ $y 1)
]
if (!= $z $arg3) [
movesel (? (< $arg3 0) -1 1) 2
z = (+ $z 1)
]
arg4
]
]
// shortcut for gotoedge and editface.
// pushedge <edge 0..3> <depth 0..8> [command]
pushedge = [
gotoedge $arg1 [
editface @arg2 2
@arg3
]
]
// shortcut for gotoface, gotoedge and editface which takes care of +Z(4) and -Z(5) faces automatically (by rotating the cube).
// editfaceedge <face 0..5> <edge 0..3> <depth 0..8> [command A] [command B]
// if face is 4 or 5, "command A" is executed during the process of rotating the cube to access them.
editfaceedge = [
if (<= $arg1 3) [
gotoface $arg1 [
gotoedge @arg2 [
editface @@arg3 2
sleep 0 [@@@arg4]
]
] 400
] [
.z.direction = (? (= $arg1 4) 1 -1)
gotoface 0 [
rotate $.z.direction
gotoface 3 [
gotoedge @@arg2 [
editface @@@arg3 2
@@@arg4
gotoface 0 [
rotate (* $.z.direction -1)
@@@@arg5
]
]
] 400
]
]
]
// similar to gotosel, but uses entautoview to go to the center of the selection.
// gotoselcenter <dist> [command]
gotoselcenter = [
entcancel
sleep 0 [entautoviewdist @entautoviewdist; entdrop @entdrop; @arg2]
entdrop 2
newent base -31349
entautoviewdist $arg1
entautoview
delent
]
// ¯\_(ツ)_/¯
gotoface_fixpitch = [
local face
face = (? (= $arg1 -1) (getlookatface) $arg1)
if $editing [edittoggle]
suicide
sleep 100 [respawn; sleep 100 [edittoggle; gotoface @@face [@@@arg2] @@arg3]]
]