Lighting for entities

This commit is contained in:
2026-09-30 16:56:55 -03:00
parent 93382d3c97
commit cbc9edfd60
11 changed files with 163 additions and 18 deletions
+7 -4
View File
@@ -8,6 +8,7 @@ import type { LocalPlayer } from "$/client/entity/local_player.ts";
import { begin_view_model, end_mode_3d, flush_batch, set_current_texture, Texture } from "$/client/renderer/mod.ts";
import { item_block, push_item } from "./item_renderer.ts";
import { push_cube, right_arm, type Vec3 } from "./player_renderer.ts";
import { entity_tint } from "./entity_light.ts";
// wider than the world's field of view, like minecraft's fixed 70 degrees for the hand
const FOV = 70 * Math.PI / 180;
@@ -34,7 +35,7 @@ export class HandRenderer {
}
}
render(player: LocalPlayer) {
render(player: LocalPlayer, partial_tick: number) {
const inventories = player.inventories;
const item = inventories.inventory.get_item(inventories.hotbar_selected);
const held = item ? `${inventories.hotbar_selected} ${item.type_id}` : "";
@@ -47,18 +48,20 @@ export class HandRenderer {
const equip = Math.min(1, (now - this.#equipped_at) / EQUIP_MS);
const swing_progress = Math.min(1, (now - this.#swung_at) / SWING_MS);
// the light where the player's eyes are, like every other entity
const tint = entity_tint(player, partial_tick);
begin_view_model(FOV);
if (item) {
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
set_current_texture(atlas.tex);
push_item(atlas, item, pose(item, (1 - equip) * 0.6, Math.sin(swing_progress * Math.PI)));
push_item(atlas, item, pose(item, (1 - equip) * 0.6, Math.sin(swing_progress * Math.PI)), tint);
} else {
const skin = player.skin ?? AssetManager.instance.get<Texture>("bworld:skin");
const arm = right_arm(player.slim);
const transform = arm_pose(arm.pivot, 1 - equip, swing_progress);
set_current_texture(skin.tex);
push_cube(skin, arm, arm.texture, 0, transform);
push_cube(skin, arm, arm.overlay, arm.inflate, transform);
push_cube(skin, arm, arm.texture, 0, transform, tint);
push_cube(skin, arm, arm.overlay, arm.inflate, transform, tint);
}
flush_batch();
end_mode_3d();