16 uint8_t
ao[4] = {3, 3, 3, 3};
24 float originZ,
int tilesPerRow = 16,
25 uint32_t aoWord = 0xFFu) {
27 const float ix = float(rect.
x());
28 const float iy = float(rect.
y());
29 const float iz = float(rect.
z());
30 const float w = float(rect.
width());
31 const float h = float(rect.
height());
36 for (
int i = 0; i < 4; ++i) out.
ao[i] = uint8_t((aoWord >> (2 * i)) & 3u);
38 const float corners2[4][2] = {{0.f, 0.f}, {1.f, 0.f}, {1.f, 1.f}, {0.f, 1.f}};
39 for (
int i = 0; i < 4; ++i) {
40 const float cu = corners2[i][0];
41 const float cv = corners2[i][1];
42 float x = ix,
y = iy,
z = iz;
43 float nx = 0.f,
ny = 0.f,
nz = 0.f;
54 z = iz + (1.f - cu) *
w;
66 z = iz + (1.f - cv) *
h;
70 x = ix + (1.f - cu) *
w;
90 const float tiles = float(tilesPerRow < 1 ? 1 : tilesPerRow);
91 const float tileU = 1.f /
tiles;
92 const float col = float(out.
tex % (tilesPerRow < 1 ? 1 : tilesPerRow));
93 const float row = float(out.
tex / (tilesPerRow < 1 ? 1 : tilesPerRow));
94 out.
uv[i][0] = (col + cu) * tileU;
95 out.
uv[i][1] = (row + cv) * tileU;
103 const float e1x =
q.
corners[2][0] -
q.corners[0][0];
104 const float e1y =
q.corners[2][1] -
q.corners[0][1];
105 const float e1z =
q.corners[2][2] -
q.corners[0][2];
106 const float e2x =
q.corners[1][0] -
q.corners[0][0];
107 const float e2y =
q.corners[1][1] -
q.corners[0][1];
108 const float e2z =
q.corners[1][2] -
q.corners[0][2];
109 const float cx = e1y * e2z - e1z * e2y;
110 const float cy = e1z * e2x - e1x * e2z;
111 const float cz = e1x * e2y - e1y * e2x;
112 return cx *
q.normal[0] +
cy *
q.normal[1] + cz *
q.normal[2] > 0.f;
117 const float e1x =
q.corners[3][0] -
q.corners[0][0];
118 const float e1y =
q.corners[3][1] -
q.corners[0][1];
119 const float e1z =
q.corners[3][2] -
q.corners[0][2];
120 const float e2x =
q.corners[2][0] -
q.corners[0][0];
121 const float e2y =
q.corners[2][1] -
q.corners[0][1];
122 const float e2z =
q.corners[2][2] -
q.corners[0][2];
123 const float cx = e1y * e2z - e1z * e2y;
124 const float cy = e1z * e2x - e1x * e2z;
125 const float cz = e1x * e2y - e1y * e2x;
126 return cx *
q.normal[0] +
cy *
q.normal[1] + cz *
q.normal[2] > 0.f;
std::array< double, 10 > q
std::vector< WfcTile > tiles
方块类型定义:名字、各面图集纹理、方向性、组合声明。 方向性方块在注册时按 orientation 绕 Y 轴展开成多个"具体类型"变体, 每个变体持有旋转后的各面纹理;渲染端只消费纹理 id,不接触 ...
bool decodedWindingMatchesNormal(const DecodedRect &q)
True when triangle (0,2,1) winding matches outward normal (matches GPU index order).
DecodedRect decodePackedRect(PackedRect rect, FaceDir dir, float originX, float originY, float originZ, int tilesPerRow=16, uint32_t aoWord=0xFFu)
CPU mirror of the instanced voxel vertex shader placement / UV logic. Used by unit tests to validate ...
bool decodedSecondTriangleMatchesNormal(const DecodedRect &q)
True when the second GPU triangle (0,3,2) also matches the outward normal.
FaceDir
Six axis-aligned face directions. Each chunk keeps a separate instance buffer per direction so camera...
One decoded face rectangle in world space (mirrors voxel_rect.vert).
Packed face-rectangle instance (exactly 32 bits): bits 0..4 : x (0..31) bits 5..9 : y (0....
int height() const
Height.