Fix animation of flowing liquids not matching direction
This commit is contained in:
parent
402e477f76
commit
3057f16d13
|
@ -2709,18 +2709,64 @@ void meshgen_liquid(MeshMakeData *data, v3s16 p, MapNode &n, SelectedNode &selec
|
|||
|
||||
if (top_is_same_liquid == false) {
|
||||
video::S3DVertex vertices[4] = {
|
||||
video::S3DVertex(-0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y1()),
|
||||
video::S3DVertex( 0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y1()),
|
||||
video::S3DVertex( 0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y0()),
|
||||
video::S3DVertex(-0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y0())
|
||||
video::S3DVertex(-0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y1()),
|
||||
video::S3DVertex( 0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y1()),
|
||||
video::S3DVertex( 0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y0()),
|
||||
video::S3DVertex(-0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y0())
|
||||
};
|
||||
|
||||
// This fixes a strange bug
|
||||
// To get backface culling right, the vertices need to go
|
||||
// clockwise around the front of the face. And we happened to
|
||||
// calculate corner levels in exact reverse order.
|
||||
s32 corner_resolve[4] = {3,2,1,0};
|
||||
|
||||
for (s32 i=0; i<4; i++) {
|
||||
s32 j = corner_resolve[i];
|
||||
vertices[i].Pos.Y += corner_levels[j];
|
||||
vertices[i].Pos += pos;
|
||||
}
|
||||
|
||||
// Default downwards-flowing texture animation goes from
|
||||
// -Z towards +Z, thus the direction is +Z.
|
||||
// Rotate texture to make animation go in flow direction
|
||||
// Positive if liquid moves towards +Z
|
||||
int dz = (corner_levels[side_corners[2][0]] +
|
||||
corner_levels[side_corners[2][1]] <
|
||||
corner_levels[side_corners[3][0]] +
|
||||
corner_levels[side_corners[3][1]]);
|
||||
// Positive if liquid moves towards +X
|
||||
int dx = (corner_levels[side_corners[0][0]] +
|
||||
corner_levels[side_corners[0][1]] <
|
||||
corner_levels[side_corners[1][0]] +
|
||||
corner_levels[side_corners[1][1]]);
|
||||
// -X
|
||||
if (-dx >= abs(dz)) {
|
||||
v2f t = vertices[0].TCoords;
|
||||
vertices[0].TCoords = vertices[1].TCoords;
|
||||
vertices[1].TCoords = vertices[2].TCoords;
|
||||
vertices[2].TCoords = vertices[3].TCoords;
|
||||
vertices[3].TCoords = t;
|
||||
}
|
||||
// +X
|
||||
if (dx >= abs(dz)) {
|
||||
v2f t = vertices[0].TCoords;
|
||||
vertices[0].TCoords = vertices[3].TCoords;
|
||||
vertices[3].TCoords = vertices[2].TCoords;
|
||||
vertices[2].TCoords = vertices[1].TCoords;
|
||||
vertices[1].TCoords = t;
|
||||
}
|
||||
// -Z
|
||||
if (-dz >= abs(dx)) {
|
||||
v2f t = vertices[0].TCoords;
|
||||
vertices[0].TCoords = vertices[3].TCoords;
|
||||
vertices[3].TCoords = vertices[2].TCoords;
|
||||
vertices[2].TCoords = vertices[1].TCoords;
|
||||
vertices[1].TCoords = t;
|
||||
t = vertices[0].TCoords;
|
||||
vertices[0].TCoords = vertices[3].TCoords;
|
||||
vertices[3].TCoords = vertices[2].TCoords;
|
||||
vertices[2].TCoords = vertices[1].TCoords;
|
||||
vertices[1].TCoords = t;
|
||||
}
|
||||
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
|
@ -2731,10 +2777,6 @@ void meshgen_liquid(MeshMakeData *data, v3s16 p, MapNode &n, SelectedNode &selec
|
|||
meshgen_lights(data,n,p,colours,f->vertex_alpha,v3s16(0,1,0),4,vertices);
|
||||
}
|
||||
|
||||
for (s32 j=0; j<4; j++) {
|
||||
vertices[j].Pos += pos;
|
||||
}
|
||||
|
||||
data->append(tiles[0], vertices, 4, indices, 6, colours);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue