Animators and coilhead animations
This commit is contained in:
@@ -5,15 +5,15 @@
|
||||
import type { Texture } from "@/client/renderer/mod.ts";
|
||||
import type { SpriteRegion } from "@/common/constants.ts";
|
||||
import type { EntityBoneJson, EntityModelJson } from "@/common/mod_data.ts";
|
||||
import { apply, bone_matrices, type Matrix, multiply, own_matrix, type Vec3 } from "./model_math.ts";
|
||||
import { apply, type Matrix, multiply, own_matrix, type Vec3 } from "./model_math.ts";
|
||||
import { push_box, type VertexSink } from "./player_renderer.ts";
|
||||
|
||||
// pose is each bone's turn before its parent's, like a head looking or a limb swinging. to_world takes the model's
|
||||
// pixels, after the bones are turned, to the world. the texture is region of the atlas, stretched to the model's
|
||||
// texture size. only picks the bones drawn, all of them when not given. emit gets the vertices, the batch by default
|
||||
// bones is each bone's matrix, see bone_matrices. to_world takes the model's pixels, after the bones are turned, to the
|
||||
// world. the texture is region of the atlas, stretched to the model's texture size. only picks the bones drawn, all of
|
||||
// them when not given. emit gets the vertices, the batch by default
|
||||
export function push_model(
|
||||
model: EntityModelJson,
|
||||
pose: (bone: EntityBoneJson) => Matrix,
|
||||
bones: Map<string, Matrix>,
|
||||
atlas: Texture,
|
||||
region: SpriteRegion,
|
||||
to_world: (x: number, y: number, z: number) => Vec3,
|
||||
@@ -25,11 +25,10 @@ export function push_model(
|
||||
(region.x + u * region.width / model.texture_width) / atlas.width,
|
||||
(region.y + v * region.height / model.texture_height) / atlas.height,
|
||||
];
|
||||
const matrices = bone_matrices(model, pose);
|
||||
for (const bone of model.bones) {
|
||||
if (only && !only(bone)) continue;
|
||||
for (const cube of bone.cubes) {
|
||||
const matrix = multiply(matrices.get(bone.name)!, own_matrix(cube));
|
||||
const matrix = multiply(bones.get(bone.name)!, own_matrix(cube));
|
||||
const transform = (px: number, py: number, pz: number) => to_world(...apply(matrix, px, py, pz));
|
||||
const inflate = cube.inflate ?? 0;
|
||||
const [ox, oy, oz] = cube.origin;
|
||||
|
||||
Reference in New Issue
Block a user