Animators and coilhead animations

This commit is contained in:
2026-11-21 21:54:02 -03:00
parent 69ad4b80d0
commit 0c711b8163
21 changed files with 960 additions and 34 deletions
+14 -7
View File
@@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// entities mods define (entities/<name>.json), drawn with their entity model and a texture from the atlas. there are no
// animation files yet: the model turns to the entity's yaw, a bone named "head" to where it looks, and bones named
// like minecraft's humanoid ones (right_arm, left_arm, right_leg, left_leg) swing as it walks, the right arm when it
// attacks too. entities without a model are their texture facing the camera, like minecraft's fishing hook
// entities mods define (entities/<name>.json), drawn with their entity model and a texture from the atlas. the model
// turns to the entity's yaw, and its bones are posed by its type's animator from a mod (see entity_animators.ts). without
// one, a bone named "head" turns to where it looks, and bones named like minecraft's humanoid ones (right_arm, left_arm,
// right_leg, left_leg) swing as it walks, the right arm when it attacks too. entities without a model are their texture
// facing the camera, like minecraft's fishing hook
import { AssetManager } from "@/client/assets.ts";
import type { Camera } from "@/client/camera.ts";
import type { RemoteEntity } from "@/client/entity/remote_entity.ts";
@@ -14,7 +15,7 @@ import type { SpriteRegion } from "@/common/constants.ts";
import { EverythingRegistry } from "@/common/everything_registry.ts";
import type { EntityBoneJson, EntityJson, EntityModelJson } from "@/common/mod_data.ts";
import { HURT_TINT } from "./player_renderer.ts";
import { IDENTITY, model_pivot, multiply, rotation_around, type Vec3 } from "./model_math.ts";
import { bone_matrices, IDENTITY, model_pivot, multiply, rotation_around, type Vec3 } from "./model_math.ts";
import { push_model } from "./model_renderer.ts";
import { entity_tint } from "./entity_light.ts";
@@ -44,8 +45,15 @@ export function render_mod_entity(entity: RemoteEntity, camera: Camera, partial_
return [x + mx * yaw_cos + mz * yaw_sin, y + my, z - mx * yaw_sin + mz * yaw_cos];
};
const offsets = entity.animation?.pose(entity.age + partial_tick);
const pose = offsets ? () => IDENTITY : default_pose(entity, partial_tick);
push_model(model, bone_matrices(model, pose, offsets), atlas, region, to_world, tint);
}
// the head looking and the humanoid swing, for an entity without an animator
function default_pose(entity: RemoteEntity, partial_tick: number) {
const limbs = limb_angles(entity, partial_tick);
const pose = (bone: EntityBoneJson) => {
return (bone: EntityBoneJson) => {
let matrix = IDENTITY;
if (bone.name === "head") {
matrix = rotation_around(model_pivot(bone), entity.pitch, entity.head_yaw - entity.yaw, 0);
@@ -54,7 +62,6 @@ export function render_mod_entity(entity: RemoteEntity, camera: Camera, partial_
if (limb) matrix = multiply(rotation_around(model_pivot(bone), limb, 0, 0), matrix);
return matrix;
};
push_model(model, pose, atlas, region, to_world, tint);
}
// how far each humanoid limb turns forward (radians), like minecraft's HumanoidModel.setupAnim: arms and legs swing