1 /**
2 Copyright: Copyright (c) 2017-2018 Andrey Penechko.
3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
4 Authors: Andrey Penechko.
5 */
6 module voxelman.world.mesh.tables.slope;
7 
8 import voxelman.geometry;
9 import voxelman.world.block.shape;
10 
11 private alias SSM = ShapeSideMask;
12 BlockShape[12] metaToShapeTable = [
13 	//zneg        zpos        xpos        xneg        ypos       yneg
14 	{[SSM.full,   SSM.empty,  SSM.slope2, SSM.slope1, SSM.empty,  SSM.full  ], 0b_0011_1111, true, true}, // 0, yneg full
15 	{[SSM.slope1, SSM.slope2, SSM.full,   SSM.empty,  SSM.empty,  SSM.full  ], 0b_1010_1111, true, true}, // 1
16 	{[SSM.empty,  SSM.full,   SSM.slope1, SSM.slope2, SSM.empty,  SSM.full  ], 0b_1100_1111, true, true}, // 2
17 	{[SSM.slope2, SSM.slope1, SSM.empty,  SSM.full,   SSM.empty,  SSM.full  ], 0b_0101_1111, true, true}, // 3
18 
19 	// looking from ypos, use face corners for numbering | vertical sides full
20 	{[SSM.full,   SSM.empty,  SSM.empty,  SSM.full,   SSM.slope0, SSM.slope3], 0b_0111_0111, true, true}, // 0 zneg, xneg full
21 	{[SSM.empty,  SSM.full,   SSM.empty,  SSM.full,   SSM.slope1, SSM.slope2], 0b_1101_1101, true, true}, // 1 zpos, xneg full
22 	{[SSM.empty,  SSM.full,   SSM.full,   SSM.empty,  SSM.slope2, SSM.slope1], 0b_1110_1110, true, true}, // 2 zpos, xpos full
23 	{[SSM.full,   SSM.empty,  SSM.full,   SSM.empty,  SSM.slope3, SSM.slope0], 0b_1011_1011, true, true}, // 3 zneg, xpos full
24 
25 	{[SSM.full,   SSM.empty,  SSM.slope3, SSM.slope0, SSM.full,   SSM.empty ], 0b_1111_0011, true, true}, // 0, ypos full
26 	{[SSM.slope0, SSM.slope3, SSM.full,   SSM.empty,  SSM.full,   SSM.empty ], 0b_1111_1010, true, true}, // 1
27 	{[SSM.empty,  SSM.full,   SSM.slope0, SSM.slope3, SSM.full,   SSM.empty ], 0b_1111_1100, true, true}, // 2
28 	{[SSM.slope3, SSM.slope0, SSM.empty,  SSM.full,   SSM.full,   SSM.empty ], 0b_1111_0101, true, true}, // 3
29 ];
30 
31 // 0--3 occlusion side 1
32 // |  |
33 // 1--2 occlusion side 2
34 // metadata[12], side * corner index[4]
35 immutable ubyte[4][12] slopeInternalOcclusionIndicies = [
36 	[0,3,1,2],[3,2,1,2],[2,1,1,2],[1,0,1,2],
37 	[3,2,0,1],[3,2,0,1],[3,2,0,1],[3,2,0,1],
38 	[0,3,3,0],[0,3,0,1],[0,3,1,2],[0,3,2,3],
39 ];
40 
41 // internal geometry
42 immutable ubyte[4][12] slopeInternalIndicies = [
43 	[4,2,3,5],
44 	[5,0,2,7],
45 	[7,1,0,6],
46 	[6,3,1,4],
47 
48 	[5,6,2,1],
49 	[4,7,3,0],
50 	[6,5,1,2],
51 	[7,4,0,3],
52 
53 	[6,0,1,7],
54 	[4,1,3,6],
55 	[5,3,2,4],
56 	[7,2,0,5],
57 ];
58 
59 // corners are fetched from those sides via slopeInternalOcclusionIndicies
60 immutable CubeSide[2][12] slopeOcclusionSides = [
61 	[CubeSide.ypos, CubeSide.zpos],
62 	[CubeSide.ypos, CubeSide.xneg],
63 	[CubeSide.ypos, CubeSide.zneg],
64 	[CubeSide.ypos, CubeSide.xpos],
65 
66 	[CubeSide.xpos, CubeSide.zpos],
67 	[CubeSide.zneg, CubeSide.xpos],
68 	[CubeSide.xneg, CubeSide.zneg],
69 	[CubeSide.zpos, CubeSide.xneg],
70 
71 	[CubeSide.zpos, CubeSide.yneg],
72 	[CubeSide.xneg, CubeSide.yneg],
73 	[CubeSide.zneg, CubeSide.yneg],
74 	[CubeSide.xpos, CubeSide.yneg],
75 ];
76 
77 immutable ubyte[3][4] slopeColorIndicies = [ // from rotation
78 	[1,3,0], [1,2,0], [1,2,3], [0,2,3]];
79 
80 // 0--3 // corner numbering of face verticies
81 // |  |
82 // 1--2
83 // 2-1  2      2  0-2
84 // |/   |\    /|   \|
85 // 0    0-1  0-1    1
86 //
87 //  0    1    2    3  rotation
88 // CCW
89 // slopeFaceCornerIndicies[rotation,4][side,6][x/y/z,3]
90 immutable ubyte[3][6][4] slopeFaceIndicies = // from rotation and side
91 [	// zneg    zpos    xpos    xneg    ypos    yneg
92 	[[1,4,5],[2,7,6],[3,5,7],[0,6,4],[6,5,4],[3,0,1],], // rotation 0
93 	[[1,0,5],[2,3,6],[3,1,7],[0,2,4],[6,7,4],[3,2,1],], // rotation 1
94 	[[1,0,4],[2,3,7],[3,1,5],[0,2,6],[6,7,5],[3,2,0],], // rotation 2
95 	[[5,0,4],[6,3,7],[7,1,5],[4,2,6],[4,7,5],[1,2,0],], // rotation 3
96 ];
97 
98 // each side includes 4 rotations that have this side as full.
99 immutable ubyte[4][6] slopeSideRotations = [
100 	[ 0, 4, 8, 7], // zneg (yneg, xneg, ypos, xpos)
101 	[ 2, 6,10, 5], // zpos (yneg, xpos, ypos, xneg)
102 	[ 1, 7, 9, 6], // xpos (yneg, zneg, ypos, zpos)
103 	[ 3, 5,11, 4], // xneg (yneg, zpos, ypos, zneg)
104 	[10,11, 8, 9], // ypos (zpos, xneg, zneg, xpos)
105 	[ 2, 3, 0, 1], // yneg (zpos, xneg, zneg, xpos)
106 ];