Player rendering in the inventory

This commit is contained in:
2026-10-12 00:11:40 -03:00
parent fbef1d96d2
commit e1f3fda692
7 changed files with 242 additions and 13 deletions
+19 -3
View File
@@ -3,26 +3,42 @@
// TransformCopyingHumanoidModel. see docs/modding/items/index.md
import { AssetManager } from "$/client/assets.ts";
import type { Player } from "$/client/entity/player.ts";
import type { ItemStack } from "$/common/inventory.ts";
import type { Texture } from "$/client/renderer/mod.ts";
import { get_sprite_region } from "$/client/sprites.ts";
import { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
import type { EntityBoneJson, EntityModelJson } from "$/common/mod_data.ts";
import { IDENTITY, type Vec3 } from "./model_math.ts";
import { push_model } from "./model_renderer.ts";
import type { VertexSink } from "./player_renderer.ts";
import { on_part, type PlayerPose, pose_to_world, right_arm, worn_bone_pose, worn_look } from "./player_model.ts";
// the atlas has to be the current texture. tint is the player's, for light and flashing red
export function render_worn(player: Player, pose: PlayerPose, tint?: Vec3) {
if (player.worn.length === 0) return;
push_worn(player.worn, pose, tint);
}
// what's worn on a player in that pose, its vertices to emit, the batch by default, like the player in the inventory
export function push_worn(worn_items: ItemStack[], pose: PlayerPose, tint?: Vec3, emit?: VertexSink) {
if (worn_items.length === 0) return;
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
const to_world = pose_to_world(pose);
for (const stack of player.worn) {
for (const stack of worn_items) {
const worn = EverythingRegistry.get<ItemRegistry>("items", stack.type_id)?.worn;
if (!worn) continue;
const look = worn_look(worn, pose.slim);
const model = EverythingRegistry.get<EntityModelJson>("entity_models", look.model);
if (!model) continue;
push_model(model, worn_bone_pose(pose), atlas, get_sprite_region(look.texture), to_world, tint);
push_model(
model,
worn_bone_pose(pose),
atlas,
get_sprite_region(look.texture),
to_world,
tint,
undefined,
emit,
);
}
}