Water flow texture
This commit is contained in:
@@ -233,3 +233,36 @@ Deno.test("the chunk worker draws water sloping down from a source, across a chu
|
||||
assert(!quads.some((corners) => corners.every(([x]) => x === 1)));
|
||||
assert(quads.some((corners) => corners.every(([x]) => x === 2)));
|
||||
});
|
||||
|
||||
Deno.test("with a flowing texture of its own, a sloping top flows downhill and the sides show part of it", () => {
|
||||
// level water stays still, whatever the flowing texture
|
||||
const lake: Record<string, Partial<LiquidCell>> = {};
|
||||
for (let dx = -1; dx <= 1; dx++) for (let dz = -1; dz <= 1; dz++) lake[`${dx},${dz}`] = liquid(1);
|
||||
assert(liquid_quads(cells(lake), OPEN, SOLID, 0.5).every((q) => q.still));
|
||||
|
||||
// a source to the -x side, so it flows towards +x
|
||||
const set = cells({ "0,0": liquid(liquid_height(1, 7)), "-1,0": liquid(1) });
|
||||
const quads = liquid_quads(set, OPEN, SOLID, 0.5);
|
||||
const top = quads.find((q) => q.face === 0)!;
|
||||
assertEquals(top.still, false);
|
||||
// the middle half of the texture, turned so v (down the texture) runs with x, downstream
|
||||
const uv_at = (x: number, z: number) => {
|
||||
const k = [0, 1, 2, 3].find((k) => top.positions[k * 3] === x && top.positions[k * 3 + 2] === z)!;
|
||||
return top.uvs.slice(k * 2, k * 2 + 2).map((n) => Math.round(n * 1000) / 1000);
|
||||
};
|
||||
assertEquals(uv_at(0, 0), [12, 4]);
|
||||
assertEquals(uv_at(1, 0), [12, 12]);
|
||||
assertEquals(uv_at(0, 1), [4, 4]);
|
||||
for (const n of top.uvs) assert(n >= 4 - 1e-9 && n <= 12 + 1e-9);
|
||||
|
||||
// the sides show the flowing texture's top left half
|
||||
for (const side of quads.filter((q) => q.face !== 0)) {
|
||||
assertEquals(side.still, false);
|
||||
for (const n of side.uvs) assert(n >= 0 && n <= 8);
|
||||
}
|
||||
|
||||
// with only one texture, the top stays still and the sides show all of it
|
||||
const plain = liquid_quads(set, OPEN, SOLID);
|
||||
assert(plain.find((q) => q.face === 0)!.still);
|
||||
assert(plain.some((q) => q.face !== 0 && q.uvs.some((n) => n > 8)));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user