Item rendering
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
Texture,
|
||||
use_texture,
|
||||
} from "$/client/renderer/mod.ts";
|
||||
import { item_block, push_item } from "./item_renderer.ts";
|
||||
import { display_transform, drawn_as_model, item_model_of, push_item } from "./item_renderer.ts";
|
||||
import { push_cube, type Vec3 } from "./player_renderer.ts";
|
||||
import { right_arm } from "./player_model.ts";
|
||||
import { render_worn_arm } from "./worn_renderer.ts";
|
||||
@@ -66,7 +66,11 @@ export class HandRenderer {
|
||||
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)), tint);
|
||||
const display = item_model_of(item)?.display.firstperson_righthand;
|
||||
const transform = display
|
||||
? display_transform(held_pose(1 - equip, swing_progress), display)
|
||||
: pose(item, (1 - equip) * 0.6, Math.sin(swing_progress * Math.PI));
|
||||
push_item(atlas, item, transform, tint);
|
||||
} else {
|
||||
const skin = player.skin ?? AssetManager.instance.get<Texture>("bworld:skin");
|
||||
const arm = right_arm(player.slim);
|
||||
@@ -119,9 +123,30 @@ export function arm_pose(pivot: Vec3, lower: number, attack: number) {
|
||||
};
|
||||
}
|
||||
|
||||
// from the item's model to in front of the camera. lower drops it out of sight, swing tips it forward and in
|
||||
// where a held model's firstperson_righthand transform starts from: low on the right in front of the camera, dropped
|
||||
// out of sight by lower and swung by attack like arm_pose. it's where the display format's transforms are made from, so
|
||||
// ones made for it elsewhere look the same here
|
||||
export function held_pose(lower: number, attack: number) {
|
||||
const degrees = Math.PI / 180;
|
||||
const sqrt_attack = Math.sqrt(attack);
|
||||
const matrix = mat4.create();
|
||||
mat4.translate(matrix, matrix, [
|
||||
-0.4 * Math.sin(sqrt_attack * Math.PI) + 0.56,
|
||||
0.2 * Math.sin(sqrt_attack * Math.PI * 2) - 0.52 - lower * 0.6,
|
||||
-0.2 * Math.sin(attack * Math.PI) - 0.72,
|
||||
]);
|
||||
const swing = Math.sin(sqrt_attack * Math.PI);
|
||||
mat4.rotateY(matrix, matrix, (45 - Math.sin(attack * attack * Math.PI) * 20) * degrees);
|
||||
mat4.rotateZ(matrix, matrix, swing * -20 * degrees);
|
||||
mat4.rotateX(matrix, matrix, swing * -80 * degrees);
|
||||
mat4.rotateY(matrix, matrix, -45 * degrees);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
// from the item's model to in front of the camera, for one without a display transform for it. lower drops it out of
|
||||
// sight, swing tips it forward and in
|
||||
function pose(item: ItemStack, lower: number, swing: number) {
|
||||
const p = item_block(item) ? BLOCK_POSE : ITEM_POSE;
|
||||
const p = drawn_as_model(item) ? BLOCK_POSE : ITEM_POSE;
|
||||
const matrix = mat4.create();
|
||||
mat4.translate(matrix, matrix, [p.x - swing * 0.25, p.y - lower + swing * 0.1, p.z - swing * 0.2]);
|
||||
mat4.rotateX(matrix, matrix, p.pitch - swing * SWING_ANGLE);
|
||||
|
||||
Reference in New Issue
Block a user