From 8d9016bb30d11c704024194d562c48983dc01b2e Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Sun, 30 Jun 2019 23:55:28 +0200 Subject: [PATCH] Added all standard player models to the model viewer. --- .../{plKcap00.nj => FOmarAccessory0.nj} | Bin .../{plKcap01.nj => FOmarAccessory1.nj} | Bin .../{plKcap02.nj => FOmarAccessory2.nj} | Bin .../{plKcap03.nj => FOmarAccessory3.nj} | Bin .../{plKcap04.nj => FOmarAccessory4.nj} | Bin .../{plKcap05.nj => FOmarAccessory5.nj} | Bin .../{plKcap06.nj => FOmarAccessory6.nj} | Bin .../{plKcap07.nj => FOmarAccessory7.nj} | Bin .../{plKcap08.nj => FOmarAccessory8.nj} | Bin .../{plKcap09.nj => FOmarAccessory9.nj} | Bin public/player/{plKbdy00.nj => FOmarBody.nj} | Bin public/player/{plKhai00.nj => FOmarHair0.nj} | Bin public/player/{plKhai01.nj => FOmarHair1.nj} | Bin public/player/{plKhai02.nj => FOmarHair2.nj} | Bin public/player/{plKhai03.nj => FOmarHair3.nj} | Bin public/player/{plKhai04.nj => FOmarHair4.nj} | Bin public/player/{plKhai05.nj => FOmarHair5.nj} | Bin public/player/{plKhai06.nj => FOmarHair6.nj} | Bin public/player/{plKhai07.nj => FOmarHair7.nj} | Bin public/player/{plKhai08.nj => FOmarHair8.nj} | Bin public/player/{plKhai09.nj => FOmarHair9.nj} | Bin public/player/{plKhed00.nj => FOmarHead0.nj} | Bin .../{plLcap00.nj => RAmarlAccessory0.nj} | Bin .../{plLcap01.nj => RAmarlAccessory1.nj} | Bin .../{plLcap02.nj => RAmarlAccessory2.nj} | Bin .../{plLcap03.nj => RAmarlAccessory3.nj} | Bin .../{plLcap04.nj => RAmarlAccessory4.nj} | Bin .../{plLcap05.nj => RAmarlAccessory5.nj} | Bin .../{plLcap06.nj => RAmarlAccessory6.nj} | Bin .../{plLcap07.nj => RAmarlAccessory7.nj} | Bin .../{plLcap08.nj => RAmarlAccessory8.nj} | Bin .../{plLcap09.nj => RAmarlAccessory9.nj} | Bin public/player/{plLbdy00.nj => RAmarlBody.nj} | Bin public/player/{plLhai00.nj => RAmarlHair0.nj} | Bin public/player/{plLhai01.nj => RAmarlHair1.nj} | Bin public/player/{plLhai02.nj => RAmarlHair2.nj} | Bin public/player/{plLhai03.nj => RAmarlHair3.nj} | Bin public/player/{plLhai04.nj => RAmarlHair4.nj} | Bin public/player/{plLhai05.nj => RAmarlHair5.nj} | Bin public/player/{plLhai06.nj => RAmarlHair6.nj} | Bin public/player/{plLhai07.nj => RAmarlHair7.nj} | Bin public/player/{plLhai08.nj => RAmarlHair8.nj} | Bin public/player/{plLhai09.nj => RAmarlHair9.nj} | Bin public/player/{plLhed00.nj => RAmarlHead0.nj} | Bin src/bin_data/loading/player.ts | 2 +- src/bin_data/parsing/ninja/index.ts | 12 ++++----- src/rendering/animation.ts | 25 ++++++++---------- src/rendering/models.ts | 14 +++++----- src/stores/ModelViewerStore.ts | 4 ++- 49 files changed, 29 insertions(+), 28 deletions(-) rename public/player/{plKcap00.nj => FOmarAccessory0.nj} (100%) rename public/player/{plKcap01.nj => FOmarAccessory1.nj} (100%) rename public/player/{plKcap02.nj => FOmarAccessory2.nj} (100%) rename public/player/{plKcap03.nj => FOmarAccessory3.nj} (100%) rename public/player/{plKcap04.nj => FOmarAccessory4.nj} (100%) rename public/player/{plKcap05.nj => FOmarAccessory5.nj} (100%) rename public/player/{plKcap06.nj => FOmarAccessory6.nj} (100%) rename public/player/{plKcap07.nj => FOmarAccessory7.nj} (100%) rename public/player/{plKcap08.nj => FOmarAccessory8.nj} (100%) rename public/player/{plKcap09.nj => FOmarAccessory9.nj} (100%) rename public/player/{plKbdy00.nj => FOmarBody.nj} (100%) rename public/player/{plKhai00.nj => FOmarHair0.nj} (100%) rename public/player/{plKhai01.nj => FOmarHair1.nj} (100%) rename public/player/{plKhai02.nj => FOmarHair2.nj} (100%) rename public/player/{plKhai03.nj => FOmarHair3.nj} (100%) rename public/player/{plKhai04.nj => FOmarHair4.nj} (100%) rename public/player/{plKhai05.nj => FOmarHair5.nj} (100%) rename public/player/{plKhai06.nj => FOmarHair6.nj} (100%) rename public/player/{plKhai07.nj => FOmarHair7.nj} (100%) rename public/player/{plKhai08.nj => FOmarHair8.nj} (100%) rename public/player/{plKhai09.nj => FOmarHair9.nj} (100%) rename public/player/{plKhed00.nj => FOmarHead0.nj} (100%) rename public/player/{plLcap00.nj => RAmarlAccessory0.nj} (100%) rename public/player/{plLcap01.nj => RAmarlAccessory1.nj} (100%) rename public/player/{plLcap02.nj => RAmarlAccessory2.nj} (100%) rename public/player/{plLcap03.nj => RAmarlAccessory3.nj} (100%) rename public/player/{plLcap04.nj => RAmarlAccessory4.nj} (100%) rename public/player/{plLcap05.nj => RAmarlAccessory5.nj} (100%) rename public/player/{plLcap06.nj => RAmarlAccessory6.nj} (100%) rename public/player/{plLcap07.nj => RAmarlAccessory7.nj} (100%) rename public/player/{plLcap08.nj => RAmarlAccessory8.nj} (100%) rename public/player/{plLcap09.nj => RAmarlAccessory9.nj} (100%) rename public/player/{plLbdy00.nj => RAmarlBody.nj} (100%) rename public/player/{plLhai00.nj => RAmarlHair0.nj} (100%) rename public/player/{plLhai01.nj => RAmarlHair1.nj} (100%) rename public/player/{plLhai02.nj => RAmarlHair2.nj} (100%) rename public/player/{plLhai03.nj => RAmarlHair3.nj} (100%) rename public/player/{plLhai04.nj => RAmarlHair4.nj} (100%) rename public/player/{plLhai05.nj => RAmarlHair5.nj} (100%) rename public/player/{plLhai06.nj => RAmarlHair6.nj} (100%) rename public/player/{plLhai07.nj => RAmarlHair7.nj} (100%) rename public/player/{plLhai08.nj => RAmarlHair8.nj} (100%) rename public/player/{plLhai09.nj => RAmarlHair9.nj} (100%) rename public/player/{plLhed00.nj => RAmarlHead0.nj} (100%) diff --git a/public/player/plKcap00.nj b/public/player/FOmarAccessory0.nj similarity index 100% rename from public/player/plKcap00.nj rename to public/player/FOmarAccessory0.nj diff --git a/public/player/plKcap01.nj b/public/player/FOmarAccessory1.nj similarity index 100% rename from public/player/plKcap01.nj rename to public/player/FOmarAccessory1.nj diff --git a/public/player/plKcap02.nj b/public/player/FOmarAccessory2.nj similarity index 100% rename from public/player/plKcap02.nj rename to public/player/FOmarAccessory2.nj diff --git a/public/player/plKcap03.nj b/public/player/FOmarAccessory3.nj similarity index 100% rename from public/player/plKcap03.nj rename to public/player/FOmarAccessory3.nj diff --git a/public/player/plKcap04.nj b/public/player/FOmarAccessory4.nj similarity index 100% rename from public/player/plKcap04.nj rename to public/player/FOmarAccessory4.nj diff --git a/public/player/plKcap05.nj b/public/player/FOmarAccessory5.nj similarity index 100% rename from public/player/plKcap05.nj rename to public/player/FOmarAccessory5.nj diff --git a/public/player/plKcap06.nj b/public/player/FOmarAccessory6.nj similarity index 100% rename from public/player/plKcap06.nj rename to public/player/FOmarAccessory6.nj diff --git a/public/player/plKcap07.nj b/public/player/FOmarAccessory7.nj similarity index 100% rename from public/player/plKcap07.nj rename to public/player/FOmarAccessory7.nj diff --git a/public/player/plKcap08.nj b/public/player/FOmarAccessory8.nj similarity index 100% rename from public/player/plKcap08.nj rename to public/player/FOmarAccessory8.nj diff --git a/public/player/plKcap09.nj b/public/player/FOmarAccessory9.nj similarity index 100% rename from public/player/plKcap09.nj rename to public/player/FOmarAccessory9.nj diff --git a/public/player/plKbdy00.nj b/public/player/FOmarBody.nj similarity index 100% rename from public/player/plKbdy00.nj rename to public/player/FOmarBody.nj diff --git a/public/player/plKhai00.nj b/public/player/FOmarHair0.nj similarity index 100% rename from public/player/plKhai00.nj rename to public/player/FOmarHair0.nj diff --git a/public/player/plKhai01.nj b/public/player/FOmarHair1.nj similarity index 100% rename from public/player/plKhai01.nj rename to public/player/FOmarHair1.nj diff --git a/public/player/plKhai02.nj b/public/player/FOmarHair2.nj similarity index 100% rename from public/player/plKhai02.nj rename to public/player/FOmarHair2.nj diff --git a/public/player/plKhai03.nj b/public/player/FOmarHair3.nj similarity index 100% rename from public/player/plKhai03.nj rename to public/player/FOmarHair3.nj diff --git a/public/player/plKhai04.nj b/public/player/FOmarHair4.nj similarity index 100% rename from public/player/plKhai04.nj rename to public/player/FOmarHair4.nj diff --git a/public/player/plKhai05.nj b/public/player/FOmarHair5.nj similarity index 100% rename from public/player/plKhai05.nj rename to public/player/FOmarHair5.nj diff --git a/public/player/plKhai06.nj b/public/player/FOmarHair6.nj similarity index 100% rename from public/player/plKhai06.nj rename to public/player/FOmarHair6.nj diff --git a/public/player/plKhai07.nj b/public/player/FOmarHair7.nj similarity index 100% rename from public/player/plKhai07.nj rename to public/player/FOmarHair7.nj diff --git a/public/player/plKhai08.nj b/public/player/FOmarHair8.nj similarity index 100% rename from public/player/plKhai08.nj rename to public/player/FOmarHair8.nj diff --git a/public/player/plKhai09.nj b/public/player/FOmarHair9.nj similarity index 100% rename from public/player/plKhai09.nj rename to public/player/FOmarHair9.nj diff --git a/public/player/plKhed00.nj b/public/player/FOmarHead0.nj similarity index 100% rename from public/player/plKhed00.nj rename to public/player/FOmarHead0.nj diff --git a/public/player/plLcap00.nj b/public/player/RAmarlAccessory0.nj similarity index 100% rename from public/player/plLcap00.nj rename to public/player/RAmarlAccessory0.nj diff --git a/public/player/plLcap01.nj b/public/player/RAmarlAccessory1.nj similarity index 100% rename from public/player/plLcap01.nj rename to public/player/RAmarlAccessory1.nj diff --git a/public/player/plLcap02.nj b/public/player/RAmarlAccessory2.nj similarity index 100% rename from public/player/plLcap02.nj rename to public/player/RAmarlAccessory2.nj diff --git a/public/player/plLcap03.nj b/public/player/RAmarlAccessory3.nj similarity index 100% rename from public/player/plLcap03.nj rename to public/player/RAmarlAccessory3.nj diff --git a/public/player/plLcap04.nj b/public/player/RAmarlAccessory4.nj similarity index 100% rename from public/player/plLcap04.nj rename to public/player/RAmarlAccessory4.nj diff --git a/public/player/plLcap05.nj b/public/player/RAmarlAccessory5.nj similarity index 100% rename from public/player/plLcap05.nj rename to public/player/RAmarlAccessory5.nj diff --git a/public/player/plLcap06.nj b/public/player/RAmarlAccessory6.nj similarity index 100% rename from public/player/plLcap06.nj rename to public/player/RAmarlAccessory6.nj diff --git a/public/player/plLcap07.nj b/public/player/RAmarlAccessory7.nj similarity index 100% rename from public/player/plLcap07.nj rename to public/player/RAmarlAccessory7.nj diff --git a/public/player/plLcap08.nj b/public/player/RAmarlAccessory8.nj similarity index 100% rename from public/player/plLcap08.nj rename to public/player/RAmarlAccessory8.nj diff --git a/public/player/plLcap09.nj b/public/player/RAmarlAccessory9.nj similarity index 100% rename from public/player/plLcap09.nj rename to public/player/RAmarlAccessory9.nj diff --git a/public/player/plLbdy00.nj b/public/player/RAmarlBody.nj similarity index 100% rename from public/player/plLbdy00.nj rename to public/player/RAmarlBody.nj diff --git a/public/player/plLhai00.nj b/public/player/RAmarlHair0.nj similarity index 100% rename from public/player/plLhai00.nj rename to public/player/RAmarlHair0.nj diff --git a/public/player/plLhai01.nj b/public/player/RAmarlHair1.nj similarity index 100% rename from public/player/plLhai01.nj rename to public/player/RAmarlHair1.nj diff --git a/public/player/plLhai02.nj b/public/player/RAmarlHair2.nj similarity index 100% rename from public/player/plLhai02.nj rename to public/player/RAmarlHair2.nj diff --git a/public/player/plLhai03.nj b/public/player/RAmarlHair3.nj similarity index 100% rename from public/player/plLhai03.nj rename to public/player/RAmarlHair3.nj diff --git a/public/player/plLhai04.nj b/public/player/RAmarlHair4.nj similarity index 100% rename from public/player/plLhai04.nj rename to public/player/RAmarlHair4.nj diff --git a/public/player/plLhai05.nj b/public/player/RAmarlHair5.nj similarity index 100% rename from public/player/plLhai05.nj rename to public/player/RAmarlHair5.nj diff --git a/public/player/plLhai06.nj b/public/player/RAmarlHair6.nj similarity index 100% rename from public/player/plLhai06.nj rename to public/player/RAmarlHair6.nj diff --git a/public/player/plLhai07.nj b/public/player/RAmarlHair7.nj similarity index 100% rename from public/player/plLhai07.nj rename to public/player/RAmarlHair7.nj diff --git a/public/player/plLhai08.nj b/public/player/RAmarlHair8.nj similarity index 100% rename from public/player/plLhai08.nj rename to public/player/RAmarlHair8.nj diff --git a/public/player/plLhai09.nj b/public/player/RAmarlHair9.nj similarity index 100% rename from public/player/plLhai09.nj rename to public/player/RAmarlHair9.nj diff --git a/public/player/plLhed00.nj b/public/player/RAmarlHead0.nj similarity index 100% rename from public/player/plLhed00.nj rename to public/player/RAmarlHead0.nj diff --git a/src/bin_data/loading/player.ts b/src/bin_data/loading/player.ts index b5c7d175..648fc4dd 100644 --- a/src/bin_data/loading/player.ts +++ b/src/bin_data/loading/player.ts @@ -59,7 +59,7 @@ function add_to_bone( bone_id: number, id_ref: [number] = [0] ) { - if (!object.evaluation_flags.eval_skip) { + if (!object.evaluation_flags.skip) { const id = id_ref[0]++; if (id === bone_id) { diff --git a/src/bin_data/parsing/ninja/index.ts b/src/bin_data/parsing/ninja/index.ts index 197176d4..e3177445 100644 --- a/src/bin_data/parsing/ninja/index.ts +++ b/src/bin_data/parsing/ninja/index.ts @@ -27,8 +27,8 @@ export type NinjaObject = { hidden: boolean, break_child_trace: boolean, zxy_rotation_order: boolean, - eval_skip: boolean, - eval_shape_skip: boolean, + skip: boolean, + shape_skip: boolean, }, model?: M, position: Vec3, @@ -80,8 +80,8 @@ function parse_sibling_objects( const hidden = (eval_flags & 0b1000) !== 0; const break_child_trace = (eval_flags & 0b10000) !== 0; const zxy_rotation_order = (eval_flags & 0b100000) !== 0; - const eval_skip = (eval_flags & 0b1000000) !== 0; - const eval_shape_skip = (eval_flags & 0b1000000) !== 0; + const skip = (eval_flags & 0b1000000) !== 0; + const shape_skip = (eval_flags & 0b10000000) !== 0; const model_offset = cursor.u32(); const pos_x = cursor.f32(); @@ -127,8 +127,8 @@ function parse_sibling_objects( hidden, break_child_trace, zxy_rotation_order, - eval_skip, - eval_shape_skip, + skip, + shape_skip, }, model, position: new Vec3(pos_x, pos_y, pos_z), diff --git a/src/rendering/animation.ts b/src/rendering/animation.ts index a7e3810b..21fff8d3 100644 --- a/src/rendering/animation.ts +++ b/src/rendering/animation.ts @@ -13,22 +13,15 @@ export function create_animation_clip(action: NjAction): AnimationClip { motion.motion_data.forEach((motion_data, bone_id) => { motion_data.tracks.forEach(({ type, keyframes }) => { - let name: string; const times: number[] = []; const values: number[] = []; for (const keyframe of keyframes) { times.push(keyframe.frame / PSO_FRAME_RATE); - if (type === NjKeyframeTrackType.Position) { - name = `.bones[${bone_id}].position`; - values.push(keyframe.value.x, keyframe.value.y, keyframe.value.z); - } else if (type === NjKeyframeTrackType.Scale) { - name = `.bones[${bone_id}].scale`; + if (type === NjKeyframeTrackType.Position || type === NjKeyframeTrackType.Scale) { values.push(keyframe.value.x, keyframe.value.y, keyframe.value.z); } else { - name = `.bones[${bone_id}].quaternion`; - const quat = new Quaternion().setFromEuler( new Euler(keyframe.value.x, keyframe.value.y, keyframe.value.z) ); @@ -38,13 +31,17 @@ export function create_animation_clip(action: NjAction): AnimationClip { } if (type === NjKeyframeTrackType.Rotation) { - tracks.push( - new QuaternionKeyframeTrack( - name!, times, values, interpolation - ) - ); + tracks.push(new QuaternionKeyframeTrack( + `.bones[${bone_id}].quaternion`, times, values, interpolation + )); } else { - tracks.push(new VectorKeyframeTrack(name, times, values, interpolation)); + const name = type === NjKeyframeTrackType.Position + ? `.bones[${bone_id}].position` + : `.bones[${bone_id}].scale`; + + tracks.push(new VectorKeyframeTrack( + name, times, values, interpolation + )); } }); }); diff --git a/src/rendering/models.ts b/src/rendering/models.ts index 9975151e..dddec1a2 100644 --- a/src/rendering/models.ts +++ b/src/rendering/models.ts @@ -14,6 +14,9 @@ const DEFAULT_SKINNED_MATERIAL = new MeshLambertMaterial({ side: DoubleSide }); const DEFAULT_NORMAL = new Vector3(0, 1, 0); +const NO_TRANSLATION = new Vector3(0, 0, 0); +const NO_ROTATION = new Quaternion(0, 0, 0, 1); +const NO_SCALE = new Vector3(1, 1, 1); export function ninja_object_to_buffer_geometry( object: NinjaObject, @@ -109,7 +112,7 @@ class Object3DCreator { parent_matrix: Matrix4 ) { const { - no_translate, no_rotate, no_scale, hidden, break_child_trace, zxy_rotation_order, eval_skip + no_translate, no_rotate, no_scale, hidden, break_child_trace, zxy_rotation_order, skip } = object.evaluation_flags; const { position, rotation, scale } = object; @@ -118,15 +121,15 @@ class Object3DCreator { ); const matrix = new Matrix4() .compose( - no_translate ? new Vector3() : vec3_to_threejs(position), - no_rotate ? new Quaternion(0, 0, 0, 1) : new Quaternion().setFromEuler(euler), - no_scale ? new Vector3(1, 1, 1) : vec3_to_threejs(scale) + no_translate ? NO_TRANSLATION : vec3_to_threejs(position), + no_rotate ? NO_ROTATION : new Quaternion().setFromEuler(euler), + no_scale ? NO_SCALE : vec3_to_threejs(scale) ) .premultiply(parent_matrix); let bone: Bone | undefined; - if (eval_skip) { + if (skip) { bone = parent_bone; } else { bone = new Bone(); @@ -162,7 +165,6 @@ class Object3DCreator { } } - // TODO: use indices and don't add duplicate positions/normals. private nj_model_to_geometry(model: NjModel, matrix: Matrix4) { const normal_matrix = new Matrix3().getNormalMatrix(matrix); diff --git a/src/stores/ModelViewerStore.ts b/src/stores/ModelViewerStore.ts index 2b97eedc..1a28c6b0 100644 --- a/src/stores/ModelViewerStore.ts +++ b/src/stores/ModelViewerStore.ts @@ -18,9 +18,11 @@ class ModelViewerStore { new PlayerModel('HUcast', 5, 0, new Set()), new PlayerModel('HUcaseal', 5, 0, new Set()), new PlayerModel('RAmar', 1, 10, new Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])), + new PlayerModel('RAmarl', 1, 10, new Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])), new PlayerModel('RAcast', 5, 0, new Set()), new PlayerModel('RAcaseal', 5, 0, new Set()), new PlayerModel('FOmarl', 1, 10, new Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])), + new PlayerModel('FOmar', 1, 10, new Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])), new PlayerModel('FOnewm', 1, 10, new Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])), new PlayerModel('FOnewearl', 1, 10, new Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])), ]; @@ -93,7 +95,7 @@ class ModelViewerStore { bone_id: number, id_ref: [number] ) { - if (!object.evaluation_flags.eval_skip) { + if (!object.evaluation_flags.skip) { const id = id_ref[0]++; if (id === bone_id) {