Change branches so that the textures can be rotated (#1183)
* add pipes, which are like branches but you can have different textures on each mode * fix formatting * remove testing block * fix more formatting issues * fix more formatting issues * simplify fromRelPos * fix fromRelPos and give pipe same properties as branch * fix flashing dots caused by floating point inaccuracies * remove debug object * fix formatting issues * fix a couple things * remove debug textures * fix formatting and also make dir an enum * fix more formatting issues * remove branches * rename pipe to branch * remove floating point fix * remove branch model * Add back branches and add temporary textures * add back the branches * fix some stuff * small changes * fix compiler error --------- Co-authored-by: Carrie <carriecapp9@gmail.com>
@ -6,8 +6,15 @@
|
||||
},
|
||||
.absorbedLight = 0x202830,
|
||||
.rotation = .branch,
|
||||
.model = "cubyz:branch",
|
||||
.texture = "cubyz:baobab_log",
|
||||
.model = .{
|
||||
.radius = 4,
|
||||
},
|
||||
.texture_top = "cubyz:branch/baobab/dot",
|
||||
.texture_bottom = "cubyz:branch/baobab/half_line",
|
||||
.texture_right = "cubyz:branch/baobab/line",
|
||||
.texture_left = "cubyz:branch/baobab/bend",
|
||||
.texture_front = "cubyz:branch/baobab/intersection",
|
||||
.texture_back = "cubyz:branch/baobab/cross",
|
||||
.item = .{
|
||||
.material = .{
|
||||
.density = 0.2,
|
||||
|
@ -6,8 +6,15 @@
|
||||
},
|
||||
.absorbedLight = 0x202830,
|
||||
.rotation = .branch,
|
||||
.model = "cubyz:branch",
|
||||
.texture = "cubyz:birch_log",
|
||||
.model = .{
|
||||
.radius = 4,
|
||||
},
|
||||
.texture_top = "cubyz:branch/birch/dot",
|
||||
.texture_bottom = "cubyz:branch/birch/half_line",
|
||||
.texture_right = "cubyz:branch/birch/line",
|
||||
.texture_left = "cubyz:branch/birch/bend",
|
||||
.texture_front = "cubyz:branch/birch/intersection",
|
||||
.texture_back = "cubyz:branch/birch/cross",
|
||||
.item = .{
|
||||
.material = .{
|
||||
.density = 0.3,
|
||||
|
@ -6,8 +6,15 @@
|
||||
},
|
||||
.absorbedLight = 0x202830,
|
||||
.rotation = .branch,
|
||||
.model = "cubyz:branch",
|
||||
.texture = "cubyz:cactus",
|
||||
.model = .{
|
||||
.radius = 4,
|
||||
},
|
||||
.texture_top = "cubyz:branch/cactus/dot",
|
||||
.texture_bottom = "cubyz:branch/cactus/half_line",
|
||||
.texture_right = "cubyz:branch/cactus/line",
|
||||
.texture_left = "cubyz:branch/cactus/bend",
|
||||
.texture_front = "cubyz:branch/cactus/intersection",
|
||||
.texture_back = "cubyz:branch/cactus/cross",
|
||||
.item = .{
|
||||
.material = .{
|
||||
.density = 0.8,
|
||||
|
@ -6,8 +6,15 @@
|
||||
},
|
||||
.absorbedLight = 0x202830,
|
||||
.rotation = .branch,
|
||||
.model = "cubyz:branch",
|
||||
.texture = "cubyz:mahogany_log",
|
||||
.model = .{
|
||||
.radius = 4,
|
||||
},
|
||||
.texture_top = "cubyz:branch/mahogany/dot",
|
||||
.texture_bottom = "cubyz:branch/mahogany/half_line",
|
||||
.texture_right = "cubyz:branch/mahogany/line",
|
||||
.texture_left = "cubyz:branch/mahogany/bend",
|
||||
.texture_front = "cubyz:branch/mahogany/intersection",
|
||||
.texture_back = "cubyz:branch/mahogany/cross",
|
||||
.item = .{
|
||||
.material = .{
|
||||
.density = 0.5,
|
||||
|
@ -6,8 +6,15 @@
|
||||
},
|
||||
.absorbedLight = 0x202830,
|
||||
.rotation = .branch,
|
||||
.model = "cubyz:branch",
|
||||
.texture = "cubyz:oak_log",
|
||||
.model = .{
|
||||
.radius = 4,
|
||||
},
|
||||
.texture_top = "cubyz:branch/oak/dot",
|
||||
.texture_bottom = "cubyz:branch/oak/half_line",
|
||||
.texture_right = "cubyz:branch/oak/line",
|
||||
.texture_left = "cubyz:branch/oak/bend",
|
||||
.texture_front = "cubyz:branch/oak/intersection",
|
||||
.texture_back = "cubyz:branch/oak/cross",
|
||||
.item = .{
|
||||
.material = .{
|
||||
.density = 0.25,
|
||||
|
@ -6,8 +6,15 @@
|
||||
},
|
||||
.absorbedLight = 0x202830,
|
||||
.rotation = .branch,
|
||||
.model = "cubyz:branch",
|
||||
.texture = "cubyz:pine_log",
|
||||
.model = .{
|
||||
.radius = 4,
|
||||
},
|
||||
.texture_top = "cubyz:branch/pine/dot",
|
||||
.texture_bottom = "cubyz:branch/pine/half_line",
|
||||
.texture_right = "cubyz:branch/pine/line",
|
||||
.texture_left = "cubyz:branch/pine/bend",
|
||||
.texture_front = "cubyz:branch/pine/intersection",
|
||||
.texture_back = "cubyz:branch/pine/cross",
|
||||
.item = .{
|
||||
.material = .{
|
||||
.density = 0.25,
|
||||
|
BIN
assets/cubyz/blocks/textures/branch/baobab/bend.png
Normal file
After Width: | Height: | Size: 331 B |
BIN
assets/cubyz/blocks/textures/branch/baobab/cross.png
Normal file
After Width: | Height: | Size: 407 B |
BIN
assets/cubyz/blocks/textures/branch/baobab/dot.png
Normal file
After Width: | Height: | Size: 226 B |
BIN
assets/cubyz/blocks/textures/branch/baobab/half_line.png
Normal file
After Width: | Height: | Size: 280 B |
BIN
assets/cubyz/blocks/textures/branch/baobab/intersection.png
Normal file
After Width: | Height: | Size: 360 B |
BIN
assets/cubyz/blocks/textures/branch/baobab/line.png
Normal file
After Width: | Height: | Size: 327 B |
BIN
assets/cubyz/blocks/textures/branch/birch/bend.png
Normal file
After Width: | Height: | Size: 341 B |
BIN
assets/cubyz/blocks/textures/branch/birch/cross.png
Normal file
After Width: | Height: | Size: 420 B |
BIN
assets/cubyz/blocks/textures/branch/birch/dot.png
Normal file
After Width: | Height: | Size: 248 B |
BIN
assets/cubyz/blocks/textures/branch/birch/half_line.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
assets/cubyz/blocks/textures/branch/birch/intersection.png
Normal file
After Width: | Height: | Size: 377 B |
BIN
assets/cubyz/blocks/textures/branch/birch/line.png
Normal file
After Width: | Height: | Size: 351 B |
BIN
assets/cubyz/blocks/textures/branch/cactus/bend.png
Normal file
After Width: | Height: | Size: 322 B |
BIN
assets/cubyz/blocks/textures/branch/cactus/cross.png
Normal file
After Width: | Height: | Size: 385 B |
BIN
assets/cubyz/blocks/textures/branch/cactus/dot.png
Normal file
After Width: | Height: | Size: 220 B |
BIN
assets/cubyz/blocks/textures/branch/cactus/half_line.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
assets/cubyz/blocks/textures/branch/cactus/intersection.png
Normal file
After Width: | Height: | Size: 345 B |
BIN
assets/cubyz/blocks/textures/branch/cactus/line.png
Normal file
After Width: | Height: | Size: 299 B |
BIN
assets/cubyz/blocks/textures/branch/mahogany/bend.png
Normal file
After Width: | Height: | Size: 372 B |
BIN
assets/cubyz/blocks/textures/branch/mahogany/cross.png
Normal file
After Width: | Height: | Size: 459 B |
BIN
assets/cubyz/blocks/textures/branch/mahogany/dot.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
assets/cubyz/blocks/textures/branch/mahogany/half_line.png
Normal file
After Width: | Height: | Size: 303 B |
BIN
assets/cubyz/blocks/textures/branch/mahogany/intersection.png
Normal file
After Width: | Height: | Size: 385 B |
BIN
assets/cubyz/blocks/textures/branch/mahogany/line.png
Normal file
After Width: | Height: | Size: 354 B |
BIN
assets/cubyz/blocks/textures/branch/oak/bend.png
Normal file
After Width: | Height: | Size: 357 B |
BIN
assets/cubyz/blocks/textures/branch/oak/cross.png
Normal file
After Width: | Height: | Size: 430 B |
BIN
assets/cubyz/blocks/textures/branch/oak/dot.png
Normal file
After Width: | Height: | Size: 223 B |
BIN
assets/cubyz/blocks/textures/branch/oak/half_line.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
assets/cubyz/blocks/textures/branch/oak/intersection.png
Normal file
After Width: | Height: | Size: 373 B |
BIN
assets/cubyz/blocks/textures/branch/oak/line.png
Normal file
After Width: | Height: | Size: 327 B |
BIN
assets/cubyz/blocks/textures/branch/pine/bend.png
Normal file
After Width: | Height: | Size: 318 B |
BIN
assets/cubyz/blocks/textures/branch/pine/cross.png
Normal file
After Width: | Height: | Size: 405 B |
BIN
assets/cubyz/blocks/textures/branch/pine/dot.png
Normal file
After Width: | Height: | Size: 226 B |
BIN
assets/cubyz/blocks/textures/branch/pine/half_line.png
Normal file
After Width: | Height: | Size: 273 B |
BIN
assets/cubyz/blocks/textures/branch/pine/intersection.png
Normal file
After Width: | Height: | Size: 355 B |
BIN
assets/cubyz/blocks/textures/branch/pine/line.png
Normal file
After Width: | Height: | Size: 316 B |
BIN
assets/cubyz/blocks/textures/branch/willow/bend.png
Normal file
After Width: | Height: | Size: 301 B |
BIN
assets/cubyz/blocks/textures/branch/willow/cross.png
Normal file
After Width: | Height: | Size: 368 B |
BIN
assets/cubyz/blocks/textures/branch/willow/dot.png
Normal file
After Width: | Height: | Size: 203 B |
BIN
assets/cubyz/blocks/textures/branch/willow/half_line.png
Normal file
After Width: | Height: | Size: 244 B |
BIN
assets/cubyz/blocks/textures/branch/willow/intersection.png
Normal file
After Width: | Height: | Size: 317 B |
BIN
assets/cubyz/blocks/textures/branch/willow/line.png
Normal file
After Width: | Height: | Size: 287 B |
@ -6,8 +6,15 @@
|
||||
},
|
||||
.absorbedLight = 0x202830,
|
||||
.rotation = .branch,
|
||||
.model = "cubyz:branch",
|
||||
.texture = "cubyz:willow_log",
|
||||
.model = .{
|
||||
.radius = 4,
|
||||
},
|
||||
.texture_top = "cubyz:branch/willow/dot",
|
||||
.texture_bottom = "cubyz:branch/willow/half_line",
|
||||
.texture_right = "cubyz:branch/willow/line",
|
||||
.texture_left = "cubyz:branch/willow/bend",
|
||||
.texture_front = "cubyz:branch/willow/intersection",
|
||||
.texture_back = "cubyz:branch/willow/cross",
|
||||
.item = .{
|
||||
.material = .{
|
||||
.density = 0.5,
|
||||
|
@ -1,237 +0,0 @@
|
||||
o unknown
|
||||
v 0.25 0.75 0.75
|
||||
v 0.25 0.75 0.25
|
||||
v 0.25 0.25 0.25
|
||||
v 0.25 0.25 0.75
|
||||
v 0.75 0.25 0.75
|
||||
v 0.75 0.25 0.25
|
||||
v 0.75 0.75 0.25
|
||||
v 0.75 0.75 0.75
|
||||
v 0.75 0.25 0.75
|
||||
v 0.75 0.25 0.25
|
||||
v 1 0.25 0.25
|
||||
v 1 0.25 0.75
|
||||
v 1 0.75 0.75
|
||||
v 1 0.75 0.25
|
||||
v 0.75 0.75 0.25
|
||||
v 0.75 0.75 0.75
|
||||
v 0.75 0 0.75
|
||||
v 0.75 0.25 0.75
|
||||
v 0.25 0.25 0.75
|
||||
v 0.25 0 0.75
|
||||
v 0.75 0 0.25
|
||||
v 0.75 0.25 0.25
|
||||
v 0.25 0.25 0.25
|
||||
v 0.25 0 0.25
|
||||
v 0.75 0.25 0.25
|
||||
v 0.25 0.25 0.25
|
||||
v 0.25 0.25 0
|
||||
v 0.75 0.25 0
|
||||
v 0.75 0.75 0
|
||||
v 0.25 0.75 0
|
||||
v 0.25 0.75 0.25
|
||||
v 0.75 0.75 0.25
|
||||
v 0.75 0.25 1
|
||||
v 0.25 0.25 1
|
||||
v 0.25 0.25 0.75
|
||||
v 0.75 0.25 0.75
|
||||
v 0.75 0.75 0.75
|
||||
v 0.25 0.75 0.75
|
||||
v 0.25 0.75 1
|
||||
v 0.75 0.75 1
|
||||
v 0.25 1 0.75
|
||||
v 0.25 1 0.25
|
||||
v 0.25 0.75 0.25
|
||||
v 0.25 0.75 0.75
|
||||
v 0.75 0.75 0.75
|
||||
v 0.75 0.75 0.25
|
||||
v 0.75 1 0.25
|
||||
v 0.75 1 0.75
|
||||
v 0 0.25 0.75
|
||||
v 0 0.25 0.25
|
||||
v 0.25 0.25 0.25
|
||||
v 0.25 0.25 0.75
|
||||
v 0.25 0.75 0.75
|
||||
v 0.25 0.75 0.25
|
||||
v 0 0.75 0.25
|
||||
v 0 0.75 0.75
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0.0625 0.1875
|
||||
vt 0 0.1875
|
||||
vt 0 0.0625
|
||||
vt 0 0.1875
|
||||
vt 0 0.0625
|
||||
vt 0.0625 0.0625
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0 0.0625
|
||||
vt 0 0.1875
|
||||
vt 0.25 0.0625
|
||||
vt 0.25 0.1875
|
||||
vt 0.1875 0.1875
|
||||
vt 0.1875 0.0625
|
||||
vt 0.0625 0
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0
|
||||
vt 0 0.1875
|
||||
vt 0 0.0625
|
||||
vt 0.06249999999999999 0.0625
|
||||
vt 0.0625 0.1875
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.25 0.1875
|
||||
vt 0.25 0.0625
|
||||
vt 0.0625 0
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.0625 0.0625
|
||||
vt 0.0625 0
|
||||
vt 0.1875 0
|
||||
vt 0.0625 0
|
||||
vt 0.1875 0
|
||||
vt 0.1875 0.0625
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.0625 0.0625
|
||||
vt 0.0625 0
|
||||
vt 0.1875 0
|
||||
vt 0.0625 0
|
||||
vt 0.1875 0
|
||||
vt 0.1875 0.0625
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.25
|
||||
vt 0.0625 0.25
|
||||
vt 0.0625 0.1875
|
||||
vt 0.1875 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.1875 0.1875
|
||||
vt 0.1875 0.25
|
||||
vt 0.0625 0.25
|
||||
vt 0.1875 0.25
|
||||
vt 0.0625 0.25
|
||||
vt 0.0625 0.1875
|
||||
vt 0.1875 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.1875 0.1875
|
||||
vt 0.1875 0.25
|
||||
vt 0.0625 0.25
|
||||
vt 0 0.0625
|
||||
vt 0 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.1875 0.0625
|
||||
vt 0.25 0.0625
|
||||
vt 0.25 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.25
|
||||
vt 0.1875 0.25
|
||||
vt 0.1875 0.1875
|
||||
vt 0.0625 0.1875
|
||||
vt 0.0625 0.25
|
||||
vt 0.1875 0.25
|
||||
vt 0.1875 0.1875
|
||||
vt 0.25 0.0625
|
||||
vt 0.25 0.1875
|
||||
vt 0.1875 0.1875
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.1875 0.0625
|
||||
vt 0.25 0.0625
|
||||
vt 0.25 0.1875
|
||||
vt 0.25 0.1875
|
||||
vt 0.25 0.0625
|
||||
vt 0.1875 0.0625
|
||||
vt 0.1875 0.1875
|
||||
vt 0.0625 0.0625
|
||||
vt 0.0625 0.1875
|
||||
vt 0 0.1875
|
||||
vt 0 0.0625
|
||||
vn -1 0 0
|
||||
vn 1 0 0
|
||||
vn 0 -1 0
|
||||
vn 0 1 0
|
||||
vn 0 -1 0
|
||||
vn 0 1 0
|
||||
vn 0 0 -1
|
||||
vn 0 0 1
|
||||
vn 0 0 1
|
||||
vn 1 0 0
|
||||
vn -1 0 0
|
||||
vn 0 0 -1
|
||||
vn 0 0 1
|
||||
vn 0 0 -1
|
||||
vn 0 -1 0
|
||||
vn 0 1 0
|
||||
vn -1 0 0
|
||||
vn 1 0 0
|
||||
vn 0 -1 0
|
||||
vn 0 1 0
|
||||
vn -1 0 0
|
||||
vn 1 0 0
|
||||
vn -1 0 0
|
||||
vn 1 0 0
|
||||
vn 0 0 -1
|
||||
vn 0 0 1
|
||||
vn 0 -1 0
|
||||
vn 0 1 0
|
||||
vn 0 0 -1
|
||||
vn 0 0 1
|
||||
f 1/1/1 2/2/1 3/3/1 4/4/1
|
||||
f 5/5/2 6/6/2 7/7/2 8/8/2
|
||||
f 4/9/3 3/10/3 6/11/3 5/12/3
|
||||
f 8/13/4 7/14/4 2/15/4 1/16/4
|
||||
f 9/17/5 10/18/5 11/19/5 12/20/5
|
||||
f 13/21/6 14/22/6 15/23/6 16/24/6
|
||||
f 10/25/7 15/26/7 14/27/7 11/28/7
|
||||
f 12/29/8 13/30/8 16/31/8 9/32/8
|
||||
f 17/33/9 18/34/9 19/35/9 20/36/9
|
||||
f 17/37/10 21/38/10 22/39/10 18/40/10
|
||||
f 19/41/11 23/42/11 24/43/11 20/44/11
|
||||
f 24/45/12 23/46/12 22/47/12 21/48/12
|
||||
f 5/49/13 8/50/13 1/51/13 4/52/13
|
||||
f 3/53/14 2/54/14 7/55/14 6/56/14
|
||||
f 25/57/15 26/58/15 27/59/15 28/60/15
|
||||
f 29/61/16 30/62/16 31/63/16 32/64/16
|
||||
f 26/65/17 31/66/17 30/67/17 27/68/17
|
||||
f 28/69/18 29/70/18 32/71/18 25/72/18
|
||||
f 33/73/19 34/74/19 35/75/19 36/76/19
|
||||
f 37/77/20 38/78/20 39/79/20 40/80/20
|
||||
f 34/81/21 39/82/21 38/83/21 35/84/21
|
||||
f 36/85/22 37/86/22 40/87/22 33/88/22
|
||||
f 41/89/23 42/90/23 43/91/23 44/92/23
|
||||
f 45/93/24 46/94/24 47/95/24 48/96/24
|
||||
f 43/97/25 42/98/25 47/99/25 46/100/25
|
||||
f 45/101/26 48/102/26 41/103/26 44/104/26
|
||||
f 49/105/27 50/106/27 51/107/27 52/108/27
|
||||
f 53/109/28 54/110/28 55/111/28 56/112/28
|
||||
f 50/113/29 55/114/29 54/115/29 51/116/29
|
||||
f 52/117/30 53/118/30 56/119/30 49/120/30
|
@ -47,6 +47,26 @@ pub const Neighbor = enum(u3) { // MARK: Neighbor
|
||||
pub fn relPos(self: Neighbor) Vec3i {
|
||||
return .{self.relX(), self.relY(), self.relZ()};
|
||||
}
|
||||
|
||||
pub fn fromRelPos(pos: Vec3i) ?Neighbor {
|
||||
if(@reduce(.Add, @abs(pos)) != 1) {
|
||||
return null;
|
||||
}
|
||||
return switch(pos[0]) {
|
||||
1 => return .dirPosX,
|
||||
-1 => return .dirNegX,
|
||||
else => switch(pos[1]) {
|
||||
1 => return .dirPosY,
|
||||
-1 => return .dirNegY,
|
||||
else => switch(pos[2]) {
|
||||
1 => return .dirUp,
|
||||
-1 => return .dirDown,
|
||||
else => return null,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/// Index to bitMask for bitmap direction data
|
||||
pub inline fn bitMask(self: Neighbor) u6 {
|
||||
return @as(u6, 1) << @intFromEnum(self);
|
||||
|
240
src/rotation.zig
@ -341,7 +341,7 @@ pub const RotationModes = struct {
|
||||
pub const Branch = struct { // MARK: Branch
|
||||
pub const id: []const u8 = "branch";
|
||||
pub const dependsOnNeighbors = true;
|
||||
var branchModels: std.StringHashMap(u16) = undefined;
|
||||
var branchModels: std.AutoHashMap(u32, u16) = undefined;
|
||||
const BranchData = packed struct(u6) {
|
||||
enabledConnections: u6,
|
||||
|
||||
@ -374,35 +374,233 @@ pub const RotationModes = struct {
|
||||
branchModels.clearRetainingCapacity();
|
||||
}
|
||||
|
||||
fn branchTransform(quad: *main.models.QuadInfo, data: BranchData) void {
|
||||
for(&quad.corners) |*corner| {
|
||||
if((!data.isConnected(Neighbor.dirNegX) and corner[0] == 0) or
|
||||
(!data.isConnected(Neighbor.dirPosX) and corner[0] == 1) or
|
||||
(!data.isConnected(Neighbor.dirNegY) and corner[1] == 0) or
|
||||
(!data.isConnected(Neighbor.dirPosY) and corner[1] == 1) or
|
||||
(!data.isConnected(Neighbor.dirDown) and corner[2] == 0) or
|
||||
(!data.isConnected(Neighbor.dirUp) and corner[2] == 1)) return degenerateQuad(quad);
|
||||
const Direction = enum(u2) {
|
||||
negYDir = 0,
|
||||
posXDir = 1,
|
||||
posYDir = 2,
|
||||
negXDir = 3,
|
||||
};
|
||||
|
||||
const Pattern = union(enum) {
|
||||
dot: void,
|
||||
halfLine: struct {
|
||||
dir: Direction,
|
||||
},
|
||||
line: struct {
|
||||
dir: Direction,
|
||||
},
|
||||
bend: struct {
|
||||
dir: Direction,
|
||||
},
|
||||
intersection: struct {
|
||||
dir: Direction,
|
||||
},
|
||||
cross: void,
|
||||
};
|
||||
|
||||
fn rotateQuad(originalCorners: [4]Vec2f, pattern: Pattern, min: f32, max: f32, side: Neighbor) main.models.QuadInfo {
|
||||
var corners: [4]Vec2f = originalCorners;
|
||||
|
||||
switch(pattern) {
|
||||
.dot, .cross => {},
|
||||
inline else => |typ| {
|
||||
const angle: f32 = @as(f32, @floatFromInt(@intFromEnum(typ.dir)))*std.math.pi/2.0;
|
||||
corners = .{
|
||||
vec.rotate2d(originalCorners[0], angle, @splat(0.5)),
|
||||
vec.rotate2d(originalCorners[1], angle, @splat(0.5)),
|
||||
vec.rotate2d(originalCorners[2], angle, @splat(0.5)),
|
||||
vec.rotate2d(originalCorners[3], angle, @splat(0.5)),
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
const offX: f32 = @floatFromInt(@intFromBool(@reduce(.Add, side.textureX()) < 0));
|
||||
const offY: f32 = @floatFromInt(@intFromBool(@reduce(.Add, side.textureY()) < 0));
|
||||
|
||||
const corners3d = .{
|
||||
@as(Vec3f, @floatFromInt(side.textureX()))*@as(Vec3f, @splat(corners[0][0] - offX)) + @as(Vec3f, @floatFromInt(side.textureY()))*@as(Vec3f, @splat(corners[0][1] - offY)),
|
||||
@as(Vec3f, @floatFromInt(side.textureX()))*@as(Vec3f, @splat(corners[1][0] - offX)) + @as(Vec3f, @floatFromInt(side.textureY()))*@as(Vec3f, @splat(corners[1][1] - offY)),
|
||||
@as(Vec3f, @floatFromInt(side.textureX()))*@as(Vec3f, @splat(corners[2][0] - offX)) + @as(Vec3f, @floatFromInt(side.textureY()))*@as(Vec3f, @splat(corners[2][1] - offY)),
|
||||
@as(Vec3f, @floatFromInt(side.textureX()))*@as(Vec3f, @splat(corners[3][0] - offX)) + @as(Vec3f, @floatFromInt(side.textureY()))*@as(Vec3f, @splat(corners[3][1] - offY)),
|
||||
};
|
||||
|
||||
var offset: Vec3f = .{0.0, 0.0, 0.0};
|
||||
offset[@intFromEnum(side.vectorComponent())] = if(side.isPositive()) max else min;
|
||||
|
||||
const res: main.models.QuadInfo = .{
|
||||
.corners = .{
|
||||
corners3d[0] + offset,
|
||||
corners3d[1] + offset,
|
||||
corners3d[2] + offset,
|
||||
corners3d[3] + offset,
|
||||
},
|
||||
.cornerUV = originalCorners,
|
||||
.normal = @floatFromInt(side.relPos()),
|
||||
.textureSlot = @intFromEnum(pattern),
|
||||
};
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
fn addQuads(pattern: Pattern, side: Neighbor, radius: f32, out: *main.List(main.models.QuadInfo)) void {
|
||||
const min: f32 = (8.0 - radius)/16.0;
|
||||
const max: f32 = (8.0 + radius)/16.0;
|
||||
switch(pattern) {
|
||||
.dot => {
|
||||
out.append(rotateQuad(.{
|
||||
.{min, min},
|
||||
.{min, max},
|
||||
.{max, min},
|
||||
.{max, max},
|
||||
}, pattern, min, max, side));
|
||||
},
|
||||
.halfLine => {
|
||||
out.append(rotateQuad(.{
|
||||
.{min, 0.0},
|
||||
.{min, max},
|
||||
.{max, 0.0},
|
||||
.{max, max},
|
||||
}, pattern, min, max, side));
|
||||
},
|
||||
.line => {
|
||||
out.append(rotateQuad(.{
|
||||
.{min, 0.0},
|
||||
.{min, 1.0},
|
||||
.{max, 0.0},
|
||||
.{max, 1.0},
|
||||
}, pattern, min, max, side));
|
||||
},
|
||||
.bend => {
|
||||
out.append(rotateQuad(.{
|
||||
.{0.0, 0.0},
|
||||
.{0.0, max},
|
||||
.{max, 0.0},
|
||||
.{max, max},
|
||||
}, pattern, min, max, side));
|
||||
},
|
||||
.intersection => {
|
||||
out.append(rotateQuad(.{
|
||||
.{0.0, 0.0},
|
||||
.{0.0, max},
|
||||
.{1.0, 0.0},
|
||||
.{1.0, max},
|
||||
}, pattern, min, max, side));
|
||||
},
|
||||
.cross => {
|
||||
out.append(rotateQuad(.{
|
||||
.{0.0, 0.0},
|
||||
.{0.0, 1.0},
|
||||
.{1.0, 0.0},
|
||||
.{1.0, 1.0},
|
||||
}, pattern, min, max, side));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn degenerateQuad(quad: *main.models.QuadInfo) void {
|
||||
for(&quad.corners) |*corner| {
|
||||
corner.* = @splat(0.5);
|
||||
}
|
||||
fn getPattern(data: BranchData, side: Neighbor) ?Pattern {
|
||||
const posX = Neighbor.fromRelPos(side.textureX()).?;
|
||||
const negX = Neighbor.fromRelPos(side.textureX()).?.reverse();
|
||||
const posY = Neighbor.fromRelPos(side.textureY()).?;
|
||||
const negY = Neighbor.fromRelPos(side.textureY()).?.reverse();
|
||||
|
||||
const connectedPosX = data.isConnected(posX);
|
||||
const connectedNegX = data.isConnected(negX);
|
||||
const connectedPosY = data.isConnected(posY);
|
||||
const connectedNegY = data.isConnected(negY);
|
||||
|
||||
const count: u6 = @as(u6, @intFromBool(connectedPosX)) + @as(u6, @intFromBool(connectedNegX)) + @as(u6, @intFromBool(connectedPosY)) + @as(u6, @intFromBool(connectedNegY));
|
||||
|
||||
return switch(count) {
|
||||
0 => {
|
||||
if(data.isConnected(side)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return .dot;
|
||||
},
|
||||
1 => {
|
||||
var dir: Direction = .negXDir;
|
||||
if(connectedNegY) {
|
||||
dir = .negYDir;
|
||||
} else if(connectedPosX) {
|
||||
dir = .posXDir;
|
||||
} else if(connectedPosY) {
|
||||
dir = .posYDir;
|
||||
}
|
||||
return .{.halfLine = .{.dir = dir}};
|
||||
},
|
||||
2 => {
|
||||
if((connectedPosX and connectedNegX) or (connectedPosY and connectedNegY)) {
|
||||
var dir: Direction = .negYDir;
|
||||
if(connectedPosX and connectedNegX) {
|
||||
dir = .posXDir;
|
||||
}
|
||||
|
||||
return .{.line = .{.dir = dir}};
|
||||
}
|
||||
|
||||
var dir: Direction = .negXDir;
|
||||
|
||||
if(connectedNegY) {
|
||||
dir = .negYDir;
|
||||
if(connectedPosX) {
|
||||
dir = .posXDir;
|
||||
}
|
||||
} else if(connectedPosX) {
|
||||
dir = .posXDir;
|
||||
if(connectedPosY) {
|
||||
dir = .posYDir;
|
||||
}
|
||||
} else if(connectedPosY) {
|
||||
dir = .posYDir;
|
||||
if(connectedNegX) {
|
||||
dir = .negXDir;
|
||||
}
|
||||
}
|
||||
|
||||
return .{.bend = .{.dir = dir}};
|
||||
},
|
||||
3 => {
|
||||
var dir: Direction = undefined;
|
||||
if(!connectedPosY) dir = .negYDir;
|
||||
if(!connectedNegX) dir = .posXDir;
|
||||
if(!connectedNegY) dir = .posYDir;
|
||||
if(!connectedPosX) dir = .negXDir;
|
||||
|
||||
return .{.intersection = .{.dir = dir}};
|
||||
},
|
||||
4 => {
|
||||
return .cross;
|
||||
},
|
||||
else => undefined,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn createBlockModel(zon: ZonElement) u16 {
|
||||
const modelId = zon.as([]const u8, "cubyz:cube");
|
||||
if(branchModels.get(modelId)) |modelIndex| return modelIndex;
|
||||
const radius = zon.get(f32, "radius", 4);
|
||||
if(branchModels.get(@bitCast(radius))) |modelIndex| return modelIndex;
|
||||
|
||||
const baseModelIndex = main.models.getModelIndex(modelId);
|
||||
const baseModel = main.models.models.items[baseModelIndex];
|
||||
var modelIndex: u16 = undefined;
|
||||
for(0..64) |i| {
|
||||
var quads = main.List(main.models.QuadInfo).init(main.stackAllocator);
|
||||
defer quads.deinit();
|
||||
|
||||
const modelIndex: u16 = baseModel.transformModel(branchTransform, .{BranchData.init(0)});
|
||||
for(1..64) |branchData| {
|
||||
_ = baseModel.transformModel(branchTransform, .{BranchData.init(@truncate(branchData))});
|
||||
for(Neighbor.iterable) |neighbor| {
|
||||
const pattern = getPattern(BranchData.init(@intCast(i)), neighbor);
|
||||
|
||||
if(pattern) |pat| {
|
||||
addQuads(pat, neighbor, radius, &quads);
|
||||
}
|
||||
}
|
||||
|
||||
const index = main.models.Model.init(quads.items);
|
||||
if(i == 0) {
|
||||
modelIndex = index;
|
||||
}
|
||||
}
|
||||
branchModels.put(modelId, modelIndex) catch unreachable;
|
||||
|
||||
branchModels.put(@bitCast(radius), modelIndex) catch unreachable;
|
||||
|
||||
return modelIndex;
|
||||
}
|
||||
|
||||
|
13
src/vec.zig
@ -80,6 +80,19 @@ pub fn rotateZ(self: anytype, angle: @typeInfo(@TypeOf(self)).vector.child) @Typ
|
||||
};
|
||||
}
|
||||
|
||||
pub fn rotate2d(self: anytype, angle: @typeInfo(@TypeOf(self)).vector.child, center: @TypeOf(self)) @TypeOf(self) {
|
||||
if(@typeInfo(@TypeOf(self)).vector.len != 2) @compileError("Only available for vectors of length 2.");
|
||||
|
||||
const sin = @sin(angle);
|
||||
const cos = @cos(angle);
|
||||
const pos = self - center;
|
||||
|
||||
return @TypeOf(self){
|
||||
cos*pos[0] - sin*pos[1],
|
||||
sin*pos[0] + cos*pos[1],
|
||||
} + center;
|
||||
}
|
||||
|
||||
pub const Mat4f = struct { // MARK: Mat4f
|
||||
rows: [4]Vec4f,
|
||||
pub fn identity() Mat4f {
|
||||
|