Bump engine submodule and move texlevels from instance params to texcoords.

This commit is contained in:
Roz K 2022-12-05 05:53:23 +01:00
parent a145a4bea3
commit e361a68b7c
Signed by: roz
GPG Key ID: 51FBF4E483E1C822
9 changed files with 360 additions and 246 deletions

Binary file not shown.

View File

@ -1,5 +0,0 @@
water = _water mesh grass
sand = _sand mesh grass
rock = _rock mesh grass
mud = _mud mesh grass
lava = _lava mesh grass

View File

@ -1,10 +1,8 @@
# Blender 3.2.2 MTL File: 'tiles.blend'
# Blender 3.3.1 MTL File: 'tiles.blend'
# www.blender.org
newmtl forest
Ns 10.000005
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.100000 0.100000 0.100000
Ke 0.000000 0.000000 0.000000
Ni 0.000000
@ -16,7 +14,6 @@ map_Ns forest_r.png
newmtl grass
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.100000 0.100000 0.100000
Ke 0.000000 0.000000 0.000000
Ni 0.000000
@ -27,8 +24,7 @@ map_Kd grass.png
newmtl lava
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.200000 0.200000 0.200000
Ks 0.100000 0.100000 0.100000
Ke 0.000000 0.000000 0.000000
Ni 0.000000
d 1.000000
@ -38,7 +34,6 @@ map_Kd lava.png
newmtl mud
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.100000 0.100000 0.100000
Ke 0.000000 0.000000 0.000000
Ni 0.000000
@ -49,7 +44,6 @@ map_Kd mud.png
newmtl rock
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.100000 0.100000 0.100000
Ke 0.000000 0.000000 0.000000
Ni 0.000000
@ -60,7 +54,6 @@ map_Kd rock.png
newmtl sand
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.100000 0.100000 0.100000
Ke 0.000000 0.000000 0.000000
Ni 0.000000
@ -69,10 +62,9 @@ illum 2
map_Kd sand.png
newmtl water
Ns 62.500000
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 1.000000 1.000000 1.000000
Ks 0.100000 0.100000 0.100000
Ke 0.000000 0.000000 0.000000
Ni 0.000000
d 1.000000

View File

@ -1,4 +1,4 @@
# Blender 3.2.2
# Blender 3.3.1
# www.blender.org
mtllib tiles.mtl
o grass
@ -47,76 +47,6 @@ f 7/7/1 4/4/1 12/12/1
f 6/6/1 9/9/1 13/13/1
f 9/9/1 8/8/1 13/13/1
f 8/8/1 5/5/1 13/13/1
o _water
v 4.000000 4.000000 0.000000
v -4.000000 4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 -4.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
s 0
usemtl water
f 16/16/2 14/14/2 15/15/2
f 16/16/2 15/15/2 17/17/2
o _sand
v 4.000000 4.000000 0.000000
v -4.000000 4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 -4.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
s 0
usemtl sand
f 20/20/3 18/18/3 19/19/3
f 20/20/3 19/19/3 21/21/3
o _rock
v 4.000000 4.000000 0.000000
v -4.000000 4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 -4.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
s 0
usemtl rock
f 24/24/4 22/22/4 23/23/4
f 24/24/4 23/23/4 25/25/4
o _mud
v 4.000000 4.000000 0.000000
v -4.000000 4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 -4.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
s 0
usemtl mud
f 28/28/5 26/26/5 27/27/5
f 28/28/5 27/27/5 29/29/5
o _lava
v -4.000000 -4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 4.000000 0.000000
v 4.000000 4.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
s 0
usemtl lava
f 31/31/6 32/32/6 30/30/6
f 31/31/6 33/33/6 32/32/6
o forest
v -4.000000 -4.000000 0.000000
v 0.000000 -4.000000 0.000000
@ -308,88 +238,318 @@ vt 0.664062 0.664062
vt 0.710938 0.695312
s 0
usemtl forest
f 35/35/7 36/36/7 47/51/8
f 34/34/7 35/35/7 45/47/9
f 37/37/10 34/34/7 45/47/11
f 36/36/7 38/38/12 47/51/13
f 40/40/14 39/39/7 48/52/15
f 39/39/7 37/37/16 48/52/17
f 38/38/18 41/41/7 44/46/19
f 41/41/7 40/40/20 44/46/21
f 15/15/2 16/16/2 27/31/3
f 14/14/2 15/15/2 25/27/4
f 17/17/5 14/14/2 25/27/6
f 16/16/2 18/18/7 27/31/8
f 20/20/9 19/19/2 28/32/10
f 19/19/2 17/17/11 28/32/12
f 18/18/13 21/21/2 24/26/14
f 21/21/2 20/20/15 24/26/16
s 1
f 50/56/22 42/42/23 46/48/24
f 51/57/25 43/44/26 49/53/27
f 52/58/28 74/88/29 73/85/30
f 53/59/31 74/88/29 52/58/28
f 53/59/31 76/93/32 75/90/33
f 50/56/22 46/48/24 43/44/26
f 51/57/25 50/56/22 43/44/26
f 51/57/25 49/53/27 76/93/32
f 53/59/31 51/57/25 76/93/32
f 53/59/31 75/90/33 74/88/29
f 52/58/28 73/85/30 42/42/23
f 52/58/28 42/42/23 50/56/22
f 51/57/25 55/61/34 50/56/22
f 30/36/17 22/22/18 26/28/19
f 31/37/20 23/24/21 29/33/22
f 32/38/23 54/68/24 53/65/25
f 33/39/26 54/68/24 32/38/23
f 33/39/26 56/73/27 55/70/28
f 30/36/17 26/28/19 23/24/21
f 31/37/20 30/36/17 23/24/21
f 31/37/20 29/33/22 56/73/27
f 33/39/26 31/37/20 56/73/27
f 33/39/26 55/70/28 54/68/24
f 32/38/23 53/65/25 22/22/18
f 32/38/23 22/22/18 30/36/17
f 31/37/20 35/41/29 30/36/17
s 0
f 45/47/35 46/49/7 42/43/7
f 45/47/36 73/86/7 37/37/37
f 47/51/38 46/50/7 35/35/7
f 47/51/39 49/54/7 43/45/7
f 48/52/40 73/87/7 74/89/7
f 48/52/41 75/91/7 40/40/42
f 44/46/43 49/55/7 38/38/44
f 44/46/45 75/92/7 76/94/7
f 25/27/30 26/29/2 22/23/2
f 25/27/31 53/66/2 17/17/32
f 27/31/33 26/30/2 15/15/2
f 27/31/34 29/34/2 23/25/2
f 28/32/35 53/67/2 54/69/2
f 28/32/36 55/71/2 20/20/37
f 24/26/38 29/35/2 18/18/39
f 24/26/40 55/72/2 56/74/2
s 1
f 56/62/46 57/63/47 71/82/48
f 53/59/31 54/60/49 51/57/25
f 52/58/28 56/62/46 53/59/31
f 50/56/22 57/63/47 52/58/28
f 60/68/50 61/70/51 67/77/52
f 57/63/47 55/61/34 72/84/53
f 58/64/54 60/68/50 68/78/55
f 59/67/56 58/64/54 69/79/57
f 63/73/58 62/72/59 70/80/60
f 36/42/41 37/43/42 51/62/43
f 33/39/26 34/40/44 31/37/20
f 32/38/23 36/42/41 33/39/26
f 30/36/17 37/43/42 32/38/23
f 40/48/45 41/50/46 47/57/47
f 37/43/42 35/41/29 52/64/48
f 38/44/49 40/48/45 48/58/50
f 39/47/51 38/44/49 49/59/52
f 43/53/53 42/52/54 50/60/55
s 0
f 45/47/61 35/35/7 46/49/7
f 45/47/62 42/43/7 73/86/7
f 47/51/63 43/45/7 46/50/7
f 47/51/64 38/38/65 49/54/7
f 48/52/66 37/37/67 73/87/7
f 48/52/68 74/89/7 75/91/7
f 44/46/69 76/94/7 49/55/7
f 44/46/70 40/40/71 75/92/7
f 25/27/56 15/15/2 26/29/2
f 25/27/57 22/23/2 53/66/2
f 27/31/58 23/25/2 26/30/2
f 27/31/59 18/18/60 29/34/2
f 28/32/61 17/17/62 53/67/2
f 28/32/63 54/69/2 55/71/2
f 24/26/64 56/74/2 29/35/2
f 24/26/65 20/20/66 55/72/2
s 1
f 61/70/51 59/67/56 66/76/72
f 59/67/56 63/73/58 66/76/72
f 63/73/58 65/75/73 66/76/72
f 65/75/73 61/70/51 66/76/72
f 61/70/51 65/75/73 67/77/52
f 65/75/73 64/74/74 67/77/52
f 64/74/74 60/68/50 67/77/52
f 60/68/50 64/74/74 68/78/55
f 64/74/74 62/72/59 68/78/55
f 62/72/59 58/64/54 68/78/55
f 58/64/54 62/72/59 69/79/57
f 62/72/59 63/73/58 69/79/57
f 63/73/58 59/67/56 69/79/57
f 62/72/59 64/74/74 70/80/60
f 64/74/74 65/75/73 70/80/60
f 65/75/73 63/73/58 70/80/60
f 55/61/34 54/60/49 77/96/75
f 54/60/49 58/65/76 77/96/75
f 58/64/54 59/67/56 77/95/77
f 59/66/78 55/61/34 77/96/75
f 54/60/49 56/62/46 78/98/79
f 56/62/46 60/69/80 78/98/79
f 60/68/50 58/64/54 78/97/81
f 58/65/76 54/60/49 78/98/79
f 57/63/47 61/71/82 71/82/48
f 61/70/51 60/68/50 71/81/83
f 60/69/80 56/62/46 71/82/48
f 55/61/34 59/66/78 72/84/53
f 59/67/56 61/70/51 72/83/84
f 61/71/82 57/63/47 72/84/53
f 51/57/25 54/60/49 55/61/34
f 53/59/31 56/62/46 54/60/49
f 52/58/28 57/63/47 56/62/46
f 50/56/22 55/61/34 57/63/47
f 41/50/46 39/47/51 46/56/67
f 39/47/51 43/53/53 46/56/67
f 43/53/53 45/55/68 46/56/67
f 45/55/68 41/50/46 46/56/67
f 41/50/46 45/55/68 47/57/47
f 45/55/68 44/54/69 47/57/47
f 44/54/69 40/48/45 47/57/47
f 40/48/45 44/54/69 48/58/50
f 44/54/69 42/52/54 48/58/50
f 42/52/54 38/44/49 48/58/50
f 38/44/49 42/52/54 49/59/52
f 42/52/54 43/53/53 49/59/52
f 43/53/53 39/47/51 49/59/52
f 42/52/54 44/54/69 50/60/55
f 44/54/69 45/55/68 50/60/55
f 45/55/68 43/53/53 50/60/55
f 35/41/29 34/40/44 57/76/70
f 34/40/44 38/45/71 57/76/70
f 38/44/49 39/47/51 57/75/72
f 39/46/73 35/41/29 57/76/70
f 34/40/44 36/42/41 58/78/74
f 36/42/41 40/49/75 58/78/74
f 40/48/45 38/44/49 58/77/76
f 38/45/71 34/40/44 58/78/74
f 37/43/42 41/51/77 51/62/43
f 41/50/46 40/48/45 51/61/78
f 40/49/75 36/42/41 51/62/43
f 35/41/29 39/46/73 52/64/48
f 39/47/51 41/50/46 52/63/79
f 41/51/77 37/43/42 52/64/48
f 31/37/20 34/40/44 35/41/29
f 33/39/26 36/42/41 34/40/44
f 32/38/23 37/43/42 36/42/41
f 30/36/17 35/41/29 37/43/42
o lava
v -4.000000 -4.000000 0.000000
v 0.000000 -4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 0.000000 0.000000
v 0.000000 0.000000 0.000000
v 4.000000 0.000000 0.000000
v -4.000000 4.000000 0.000000
v 0.000000 4.000000 0.000000
v 4.000000 4.000000 0.000000
v -2.000000 -2.000000 0.000000
v 2.000000 -2.000000 0.000000
v -2.000000 2.000000 0.000000
v 2.000000 2.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 0.000000 0.000000
vt 0.500000 0.000000
vt 1.000000 0.000000
vt 0.000000 0.500000
vt 0.500000 0.500000
vt 1.000000 0.500000
vt 0.000000 1.000000
vt 0.500000 1.000000
vt 1.000000 1.000000
vt 0.250000 0.250000
vt 0.750000 0.250000
vt 0.250000 0.750000
vt 0.750000 0.750000
s 0
usemtl lava
f 60/80/80 61/81/80 69/89/80
f 62/82/80 63/83/80 70/90/80
f 63/83/80 64/84/80 71/91/80
f 59/79/80 60/80/80 68/88/80
f 60/80/80 63/83/80 68/88/80
f 63/83/80 62/82/80 68/88/80
f 62/82/80 59/79/80 68/88/80
f 61/81/80 64/84/80 69/89/80
f 64/84/80 63/83/80 69/89/80
f 63/83/80 60/80/80 69/89/80
f 63/83/80 66/86/80 70/90/80
f 66/86/80 65/85/80 70/90/80
f 65/85/80 62/82/80 70/90/80
f 64/84/80 67/87/80 71/91/80
f 67/87/80 66/86/80 71/91/80
f 66/86/80 63/83/80 71/91/80
o mud
v -4.000000 -4.000000 0.000000
v 0.000000 -4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 0.000000 0.000000
v 0.000000 0.000000 0.000000
v 4.000000 0.000000 0.000000
v -4.000000 4.000000 0.000000
v 0.000000 4.000000 0.000000
v 4.000000 4.000000 0.000000
v -2.000000 -2.000000 0.000000
v 2.000000 -2.000000 0.000000
v -2.000000 2.000000 0.000000
v 2.000000 2.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 0.000000 0.000000
vt 0.500000 0.000000
vt 1.000000 0.000000
vt 0.000000 0.500000
vt 0.500000 0.500000
vt 1.000000 0.500000
vt 0.000000 1.000000
vt 0.500000 1.000000
vt 1.000000 1.000000
vt 0.250000 0.250000
vt 0.750000 0.250000
vt 0.250000 0.750000
vt 0.750000 0.750000
s 0
usemtl mud
f 73/93/81 74/94/81 82/102/81
f 75/95/81 76/96/81 83/103/81
f 76/96/81 77/97/81 84/104/81
f 72/92/81 73/93/81 81/101/81
f 73/93/81 76/96/81 81/101/81
f 76/96/81 75/95/81 81/101/81
f 75/95/81 72/92/81 81/101/81
f 74/94/81 77/97/81 82/102/81
f 77/97/81 76/96/81 82/102/81
f 76/96/81 73/93/81 82/102/81
f 76/96/81 79/99/81 83/103/81
f 79/99/81 78/98/81 83/103/81
f 78/98/81 75/95/81 83/103/81
f 77/97/81 80/100/81 84/104/81
f 80/100/81 79/99/81 84/104/81
f 79/99/81 76/96/81 84/104/81
o rock
v -4.000000 -4.000000 0.000000
v 0.000000 -4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 0.000000 0.000000
v 0.000000 0.000000 0.000000
v 4.000000 0.000000 0.000000
v -4.000000 4.000000 0.000000
v 0.000000 4.000000 0.000000
v 4.000000 4.000000 0.000000
v -2.000000 -2.000000 0.000000
v 2.000000 -2.000000 0.000000
v -2.000000 2.000000 0.000000
v 2.000000 2.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 0.000000 0.000000
vt 0.500000 0.000000
vt 1.000000 0.000000
vt 0.000000 0.500000
vt 0.500000 0.500000
vt 1.000000 0.500000
vt 0.000000 1.000000
vt 0.500000 1.000000
vt 1.000000 1.000000
vt 0.250000 0.250000
vt 0.750000 0.250000
vt 0.250000 0.750000
vt 0.750000 0.750000
s 0
usemtl rock
f 86/106/82 87/107/82 95/115/82
f 88/108/82 89/109/82 96/116/82
f 89/109/82 90/110/82 97/117/82
f 85/105/82 86/106/82 94/114/82
f 86/106/82 89/109/82 94/114/82
f 89/109/82 88/108/82 94/114/82
f 88/108/82 85/105/82 94/114/82
f 87/107/82 90/110/82 95/115/82
f 90/110/82 89/109/82 95/115/82
f 89/109/82 86/106/82 95/115/82
f 89/109/82 92/112/82 96/116/82
f 92/112/82 91/111/82 96/116/82
f 91/111/82 88/108/82 96/116/82
f 90/110/82 93/113/82 97/117/82
f 93/113/82 92/112/82 97/117/82
f 92/112/82 89/109/82 97/117/82
o sand
v -4.000000 -4.000000 0.000000
v 0.000000 -4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 0.000000 0.000000
v 0.000000 0.000000 0.000000
v 4.000000 0.000000 0.000000
v -4.000000 4.000000 0.000000
v 0.000000 4.000000 0.000000
v 4.000000 4.000000 0.000000
v -2.000000 -2.000000 0.000000
v 2.000000 -2.000000 0.000000
v -2.000000 2.000000 0.000000
v 2.000000 2.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 0.000000 0.000000
vt 0.500000 0.000000
vt 1.000000 0.000000
vt 0.000000 0.500000
vt 0.500000 0.500000
vt 1.000000 0.500000
vt 0.000000 1.000000
vt 0.500000 1.000000
vt 1.000000 1.000000
vt 0.250000 0.250000
vt 0.750000 0.250000
vt 0.250000 0.750000
vt 0.750000 0.750000
s 0
usemtl sand
f 99/119/83 100/120/83 108/128/83
f 101/121/83 102/122/83 109/129/83
f 102/122/83 103/123/83 110/130/83
f 98/118/83 99/119/83 107/127/83
f 99/119/83 102/122/83 107/127/83
f 102/122/83 101/121/83 107/127/83
f 101/121/83 98/118/83 107/127/83
f 100/120/83 103/123/83 108/128/83
f 103/123/83 102/122/83 108/128/83
f 102/122/83 99/119/83 108/128/83
f 102/122/83 105/125/83 109/129/83
f 105/125/83 104/124/83 109/129/83
f 104/124/83 101/121/83 109/129/83
f 103/123/83 106/126/83 110/130/83
f 106/126/83 105/125/83 110/130/83
f 105/125/83 102/122/83 110/130/83
o water
v -4.000000 -4.000000 0.000000
v 0.000000 -4.000000 0.000000
v 4.000000 -4.000000 0.000000
v -4.000000 0.000000 0.000000
v 0.000000 0.000000 0.000000
v 4.000000 0.000000 0.000000
v -4.000000 4.000000 0.000000
v 0.000000 4.000000 0.000000
v 4.000000 4.000000 0.000000
v -2.000000 -2.000000 0.000000
v 2.000000 -2.000000 0.000000
v -2.000000 2.000000 0.000000
v 2.000000 2.000000 0.000000
vn -0.0000 -0.0000 1.0000
vt 0.000000 0.000000
vt 0.500000 0.000000
vt 1.000000 0.000000
vt 0.000000 0.500000
vt 0.500000 0.500000
vt 1.000000 0.500000
vt 0.000000 1.000000
vt 0.500000 1.000000
vt 1.000000 1.000000
vt 0.250000 0.250000
vt 0.750000 0.250000
vt 0.250000 0.750000
vt 0.750000 0.750000
s 0
usemtl water
f 112/132/84 113/133/84 121/141/84
f 114/134/84 115/135/84 122/142/84
f 115/135/84 116/136/84 123/143/84
f 111/131/84 112/132/84 120/140/84
f 112/132/84 115/135/84 120/140/84
f 115/135/84 114/134/84 120/140/84
f 114/134/84 111/131/84 120/140/84
f 113/133/84 116/136/84 121/141/84
f 116/136/84 115/135/84 121/141/84
f 115/135/84 112/132/84 121/141/84
f 115/135/84 118/138/84 122/142/84
f 118/138/84 117/137/84 122/142/84
f 117/137/84 114/134/84 122/142/84
f 116/136/84 119/139/84 123/143/84
f 119/139/84 118/138/84 123/143/84
f 118/138/84 115/135/84 123/143/84

2
engine

@ -1 +1 @@
Subproject commit af25548752d7ae7004a937307e06bd4810e46cc7
Subproject commit 8f3612bed26d4bdb9f6c62541bf6068285f760b3

View File

@ -19,14 +19,13 @@ from engine import (
INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, BATCH_ORIENTATION_FORMAT_NONE, create_batch, draw_batch, destroy_batch)
class Batch:
__slots__ = '_batch', 'max_size', 'flags', 'texlevels', 'meshes', 'translations', 'orientations'
__slots__ = '_batch', 'max_size', 'flags', 'meshes', 'translations', 'orientations'
def __init__(self, max_size, translation_format, orientation_format):
assert max_size <= BATCH_MAX_SIZE
self._batch = create_batch(max_size, translation_format, orientation_format)
self.max_size = max_size
self.flags = array('B')
self.texlevels = array('H')
self.meshes = array('I')
self.translations = array('f')
if orientation_format != BATCH_ORIENTATION_FORMAT_NONE:
@ -37,13 +36,12 @@ class Batch:
def __del__(self):
destroy_batch(self._batch)
def append(self, flags, texlevel, mesh, translation, orientation):
def append(self, flags, mesh, translation, orientation):
assert len(translation) == 3
assert orientation is None or len(orientation) == 3
index = len(self.flags)
assert index < self.max_size
self.flags.append(flags | INSTANCE_FLAG_SPAWNED)
self.texlevels.append(texlevel)
self.meshes.append(mesh)
self.translations.extend(translation)
if self.orientations is not None:
@ -57,4 +55,4 @@ class Batch:
self.orientations[index * 3 : index * 3 + 3] = orientation
def draw(self):
draw_batch(self._batch, self.flags, self.texlevels, self.meshes, self.translations, self.orientations)
draw_batch(self._batch, self.flags, self.meshes, self.translations, self.orientations)

View File

@ -30,23 +30,6 @@ class ObjArchive(Archive):
def __init__(self):
super().__init__()
def import_hacks(self, path):
print("Importing hacks", path)
hacks = {}
for line in open(path):
data = line.split()
if not data:
continue
name = data.pop(0)
if name == '#':
continue
assert len(data) == 4 and data[0] == '=' and data[2] == 'mesh'
alias = data[1]
mesh = data[3]
assert name not in hacks.keys()
hacks[name] = (alias, mesh)
return hacks
def import_mtl(self, mtlpath):
def load_value(x):
x = round(float(x), 6)
@ -178,12 +161,10 @@ class ObjArchive(Archive):
elif code == 'o':
if name:
assert mesh
objects[name] = (texlevel, mesh)
objects[name] = mesh
name = data[0]
print("Importing object", name)
mesh = []
elif code == 'usemtl':
texlevel = texlevels[data[0]]
elif code == 'v':
position = tuple(map(load_coord, data))
assert len(position) == 3
@ -196,66 +177,57 @@ class ObjArchive(Archive):
texcoord = tuple(map(load_coord, data))
assert len(texcoord) == 2
texcoords.append((texcoord[0], 1.0 - texcoord[1]))
elif code == 'usemtl':
texlevel = texlevels[data[0]]
elif code == 'f':
indices = tuple(map(lambda x: tuple(map(load_index, x.split('/'))), data))
assert len(indices) == 3
assert len(indices[0]) == 3
assert len(indices[1]) == 3
assert len(indices[2]) == 3
triangle = tuple(map(lambda x: positions[x[0]] + normals[x[2]] + texcoords[x[1]], indices))
triangle = tuple(map(
lambda x: positions[x[0]] + normals[x[2]] + texcoords[x[1]] + (texlevel,), indices))
assert len(triangle) == 3 and len(set(triangle)) == 3
mesh.append(triangle)
if name:
assert mesh
objects[name] = (texlevel, mesh)
objects[name] = mesh
vertices = set()
for _, mesh in objects.values():
for mesh in objects.values():
vertices |= frozenset(chain.from_iterable(mesh))
vertices = tuple(vertices)
indices = []
models = {}
for name, (texlevel, mesh) in sorted(objects.items()):
if name[0] == '_':
print(name, ": texlevel =", texlevel)
models[name] = (texlevel, -1, -1)
else:
offset = len(indices)
assert offset < 65536
indices.extend(map(vertices.index, chain.from_iterable(mesh)))
count = len(indices) - offset
assert count % 3 == 0
count //= 3
assert count < 65536
print(name, ": texlevel =", texlevel, "offset =", offset, "count =", count)
models[name] = (texlevel, offset, count)
for name, mesh in sorted(objects.items()):
offset = len(indices)
assert offset < 65536
indices.extend(map(vertices.index, chain.from_iterable(mesh)))
count = len(indices) - offset
assert count % 3 == 0
count //= 3
assert count < 65536
print(name, ": offset =", offset, "triangles =", count)
models[name] = (offset, count)
name = str(objpath.stem)
assert name not in self.vertices_db.keys()
#TODO: move to math
def pack_10(_x):
return round(_x * (512.0 if _x < 0.0 else 511.0)) & 1023
def pack_vertex(_px, _py, _pz, _nx, _ny, _nz, _s, _t):
n = (pack_10(_nx) << 20) | (pack_10(_ny) << 10) | (pack_10(_nz) << 0)
s = max(0, min(65535, round(_s * 65535.0)))
t = max(0, min(65535, round(_t * 65535.0)))
return struct.pack('fffIHH', _px, _py, _pz, n, s, t)
def pack_u10(_x):
return round(_x * 1023.0) & 1023
def pack_vertex(_px, _py, _pz, _nx, _ny, _nz, _s, _t, _tl):
n = (pack_10(_nz) << 20) | (pack_10(_ny) << 10) | pack_10(_nx)
t = ((_tl & 1023) << 20) | (pack_u10(_t) << 10) | pack_u10(_s)
return struct.pack('fffII', _px, _py, _pz, n, t)
self.vertices_db[name] = VerticesData(name,
array('B', b''.join(starmap(pack_vertex, vertices))),
array('H', indices))
path = objpath.parent / (objpath.stem + '.hacks')
if path.exists():
hacks = self.import_hacks(path)
for name, (alias, mesh) in hacks.items():
print("Hacking", name, "from", alias, "with mesh", mesh)
assert name not in models.keys() and alias in models.keys() and mesh in models.keys()
texlevel, _, _ = models[alias]
_, offset, count = models[mesh]
models[name] = (texlevel, offset, count)
for name, (texlevel, offset, count) in sorted(models.items()):
for name, (offset, count) in sorted(models.items()):
if name[0] != '_':
print("Storing", name)
assert name not in self.models_db.keys()
self.models_db[name] = ModelData(
name, INSTANCE_FLAG_VISIBLE, texlevel, offset | count << 16)
name, INSTANCE_FLAG_VISIBLE, offset | count << 16)
if __name__ == '__main__':
if len(sys.argv) < 3:

View File

@ -23,9 +23,9 @@ import engine
VERTEX_SIZE = 20
VERTEX_FORMAT = engine.vertex_format(
engine.VERTEX_FORMAT_VEC3_FLOAT,
engine.VERTEX_FORMAT_VEC3_INT10,
engine.VERTEX_FORMAT_VEC2_USHORT)
engine.VERTEX_FORMAT_VEC3_FLOAT, # position
engine.VERTEX_FORMAT_VEC3_INT10 | engine.VERTEX_FORMAT_NORMALIZE, # normal
engine.VERTEX_FORMAT_VEC3_UINT10) # texcoords
def load_png(path):
width, height, data, _ = png.Reader(filename = path).read_flat()
@ -166,39 +166,37 @@ def create_vertices(data):
return engine.create_vertices(VERTEX_FORMAT, len(data.vertices) // VERTEX_SIZE, data.vertices, data.indices)
class ModelData:
__slots__ = 'name', 'flags', 'texlevel', 'mesh'
__slots__ = 'name', 'flags', 'mesh'
def __init__(self, name, flags, texlevel, mesh):
def __init__(self, name, flags, mesh):
self.name = name
self.flags = flags
self.texlevel = texlevel
self.mesh = mesh
@classmethod
def from_archive(cls, file):
_read_magic(file, b'MD')
name = _read_string(file)
flags, texlevel, mesh = _read_struct(file, 'BHI')
return ModelData(name, flags, texlevel, mesh)
flags, mesh = _read_struct(file, 'II')
return ModelData(name, flags, mesh)
def to_archive(self, file):
_write_magic(file, b'MD')
_write_string(file, self.name)
_write_struct(file, 'BHI', (self.flags, self.texlevel, self.mesh))
_write_struct(file, 'II', (self.flags, self.mesh))
class Model:
__slots__ = 'flags', 'texlevel', 'mesh'
__slots__ = 'flags', 'mesh'
def __init__(self, flags, texlevel, mesh):
def __init__(self, flags, mesh):
self.flags = flags
self.texlevel = texlevel
self.mesh = mesh
def spawn(self, batch, translation = engine.vec3_zero, orientation = engine.vec3_forward):
return batch.append(self.flags, self.texlevel, self.mesh, translation, orientation)
return batch.append(self.flags, self.mesh, translation, orientation)
def create_model(data):
return Model(data.flags, data.texlevel, data.mesh)
return Model(data.flags, data.mesh)
class Archive:
__slots__ = 'textures_db', 'vertices_db', 'models_db'

View File

@ -18,13 +18,11 @@ precision highp float;
layout(location = 0) in vec3 a_position; // model space
layout(location = 1) in vec3 a_normal; // model space
layout(location = 2) in vec2 a_texcoord; // texture space
layout(location = 2) in vec3 a_texcoord; // texture space
layout(location = 3) in vec4 i_translation; // per mesh, model space -> world space (x, y, z, texlevel)
layout(location = 3) in vec3 i_translation; // per mesh, model space -> world space
layout(location = 4) in vec3 i_orientation; // per mesh, model space -> world space
#define i_texlevel i_translation.w
uniform mat4 u_view; // world space -> view space
uniform mat4 u_projection; // view space -> screen space
@ -33,6 +31,7 @@ uniform highp sampler2D u_normal_sampler;
const vec3 c_normal_scale = vec3(2.0, 2.0, 1.0);
const vec3 c_normal_shift = vec3(-1.0, -1.0, 0.0);
const vec2 c_st_scale = vec2(1.0 / 1023.0, 1.0 / 1023.0);
const vec2 c_terrain_scale = vec2(1.0 / 2048.0, -1.0 / 2048.0);
const vec2 c_terrain_shift = vec2(0.5, 0.5);
const float c_weight_scale = 1.0 / 64.f;
@ -58,6 +57,6 @@ void main(void) {
v_position = view_position.xyz;
v_normal = (u_view * vec4(world_normal, 0.0)).xyz;
v_terrain_normal = vec4((u_view * vec4(terrain_normal, 0.0)).xyz, weight);
v_texcoord = vec4(a_texcoord, i_texlevel, i_texlevel + 1.0);
v_texcoord = vec4(a_texcoord.st * c_st_scale, a_texcoord.p, a_texcoord.p + 1.0);
gl_Position = u_projection * view_position;
}