Block visuals
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
draw_terrain,
|
||||
flush_batch,
|
||||
get_current_texture,
|
||||
light_color,
|
||||
push_vertex,
|
||||
set_current_texture,
|
||||
Texture,
|
||||
@@ -37,6 +38,7 @@ import type { BlockHitResult } from "$/client/level/client_level.ts";
|
||||
import { FACE_GROUPS, UNALIGNED_GROUP } from "$/client/workers/chunk_messages.ts";
|
||||
import { FACE_AXIS, FACE_NORMALS } from "$/client/workers/translucent_sort.ts";
|
||||
import { Frustum } from "./frustum.ts";
|
||||
import { draw_instance } from "./visuals.ts";
|
||||
|
||||
// draws the level, like minecraft's LevelRenderer: terrain in layers, block breaking and entities
|
||||
export class LevelRenderer {
|
||||
@@ -44,7 +46,7 @@ export class LevelRenderer {
|
||||
// chunks in view this frame, worked out once for all the layers
|
||||
#visible: Chunk[] = [];
|
||||
// what to draw, switched off in the f3 performance window to see what each costs
|
||||
draw = { solid: true, cutout: true, translucent: true, entities: true };
|
||||
draw = { solid: true, cutout: true, translucent: true, entities: true, visuals: true };
|
||||
|
||||
get visible_chunks() {
|
||||
return this.#visible.length;
|
||||
@@ -75,7 +77,8 @@ export class LevelRenderer {
|
||||
this.frustum.update(view_projection());
|
||||
this.#visible.length = 0;
|
||||
for (const chunk of level.chunks.values()) {
|
||||
if (Object.keys(chunk.meshes).length > 0 && this.#in_view(chunk)) {
|
||||
const drawn = Object.keys(chunk.meshes).length > 0 || level.visuals.has(chunk.x, chunk.z);
|
||||
if (drawn && this.#in_view(chunk)) {
|
||||
this.#visible.push(chunk);
|
||||
}
|
||||
}
|
||||
@@ -146,6 +149,18 @@ export class LevelRenderer {
|
||||
flush_batch();
|
||||
}
|
||||
|
||||
// blocks drawn with code, in the chunks in view, see client/rendering/visuals.ts
|
||||
render_visuals(level: ClientLevel, partial_tick: number) {
|
||||
if (!this.draw.visuals) return;
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
set_current_texture(level.image.tex);
|
||||
const time = level.ticks + partial_tick;
|
||||
level.visuals.render(this.#visible, time, (instance, x, y, z) => {
|
||||
draw_instance(atlas, instance, x, y, z, time, light_color(level.get_light(x, y, z)));
|
||||
});
|
||||
flush_batch();
|
||||
}
|
||||
|
||||
// the cracks on the block being broken, drawn over its model's faces like minecraft's crumbling overlay, so a slab
|
||||
// or a plant cracks where it is and not on a whole cube around it
|
||||
render_destroy_progress(level: ClientLevel, game_mode: MultiPlayerGameMode) {
|
||||
|
||||
Reference in New Issue
Block a user