Allow static to be modfied by a transform

This commit is contained in:
James Lambert 2022-12-30 21:58:05 -07:00
parent 226057dd61
commit be1f6dd243
20 changed files with 134 additions and 35 deletions

View file

@ -210,6 +210,8 @@ build/src/player/player.o: build/assets/models/player/chell.h build/assets/mater
build/assets/models/player/chell.h: assets/materials/chell.skm.yaml
ANIM_TEST_CHAMBERS = build/assets/test_chambers/test_chamber_03/test_chamber_03_anim.o
build/anims.ld: $(ANIM_LIST) $(ANIM_TEST_CHAMBERS) tools/generate_animation_ld.js
@mkdir -p $(@D)
node tools/generate_animation_ld.js $@ $(ANIM_LIST) $(ANIM_TEST_CHAMBERS)
@ -223,8 +225,6 @@ TEST_CHAMBERS = assets/test_chambers/test_chamber_00/test_chamber_00.blend \
assets/test_chambers/test_chamber_02/test_chamber_02.blend \
assets/test_chambers/test_chamber_03/test_chamber_03.blend
ANIM_TEST_CHAMBERS = build/assets/test_chambers/test_chamber_03/test_chamber_03_anim.o
TEST_CHAMBER_HEADERS = $(TEST_CHAMBERS:%.blend=build/%.h)
TEST_CHAMBER_OBJECTS = $(TEST_CHAMBERS:%.blend=build/%_geo.o)

View file

@ -275,7 +275,7 @@ local function build_armature_data(armature, gfx_reference_or_nil, name_hint, fi
return {
displayList = gfx_reference_or_nil or sk_definition_writer.null_value,
boneTransforms = sk_definition_writer.reference_to(transforms, 1),
pose = sk_definition_writer.reference_to(transforms, 1),
numberOfBones = #armature.nodes,
numberOfAttachments = 0,
boneParentIndex = sk_definition_writer.reference_to(parent_mapping, 1),

View file

@ -59,11 +59,23 @@ double extractStaticUVScale(const std::string& nodeName) {
return result;
}
aiMatrix4x4 buildTransformForRenderChunk(aiNode* node) {
aiMatrix4x4 result;
// this is setup to intentionally skip the root node
while (node->mParent) {
result = node->mTransformation * result;
node = node->mParent;
}
return result;
}
void MeshDefinitionGenerator::AppendRenderChunks(const aiScene* scene, aiNode* node, CFileDefinition& fileDefinition, const DisplayListSettings& settings, std::vector<RenderChunk>& renderChunks) {
for (unsigned meshIndex = 0; meshIndex < node->mNumMeshes; ++meshIndex) {
std::shared_ptr<ExtendedMesh> mesh = fileDefinition.GetExtendedMesh(scene->mMeshes[node->mMeshes[meshIndex]]);
mesh = mesh->Transform(node->mTransformation);
mesh = mesh->Transform(buildTransformForRenderChunk(node));
std::string materialName = ExtendedMesh::GetMaterialName(scene->mMaterials[mesh->mMesh->mMaterialIndex], settings.mForceMaterialName);

View file

@ -23,10 +23,6 @@ struct BoundingSphere {
short radius;
};
enum TriggerCutsceneIndex {
TRIGGER_START,
};
enum CutsceneStepType {
CutsceneStepTypeNoop,
CutsceneStepTypePlaySound,
@ -173,7 +169,7 @@ struct BoxDropperDefinition {
};
struct AnimationInfo {
struct SKArmature armature;
struct SKArmatureDefinition armature;
struct SKAnimationClip* clips;
short clipCount;
};

View file

@ -83,6 +83,14 @@ struct LevelDefinition* levelFixPointers(struct LevelDefinition* from, int point
result->signage = ADJUST_POINTER_POS(result->signage, pointerOffset);
result->boxDroppers = ADJUST_POINTER_POS(result->boxDroppers, pointerOffset);
result->animations = ADJUST_POINTER_POS(result->animations, pointerOffset);
for (int i = 0; i < result->animationInfoCount; ++i) {
result->animations[i].clips = ADJUST_POINTER_POS(result->animations[i].clips, pointerOffset);
result->animations[i].armature.boneParentIndex = ADJUST_POINTER_POS(result->animations[i].armature.boneParentIndex, pointerOffset);
result->animations[i].armature.pose = ADJUST_POINTER_POS(result->animations[i].armature.pose, pointerOffset);
}
return result;
}

View file

@ -6,7 +6,7 @@
#include "../graphics/render_scene.h"
#include "../math/mathf.h"
void staticRenderPopulateRooms(struct FrustrumCullingInformation* cullingInfo, struct RenderScene* renderScene) {
void staticRenderPopulateRooms(struct FrustrumCullingInformation* cullingInfo, Mtx* staticTransforms, struct RenderScene* renderScene) {
int currentRoom = 0;
u64 visibleRooms = renderScene->visibleRooms;
@ -27,7 +27,13 @@ void staticRenderPopulateRooms(struct FrustrumCullingInformation* cullingInfo, s
boxCenter.y = (float)(box->minY + box->maxY) * (0.5f / SCENE_SCALE);
boxCenter.z = (float)(box->minZ + box->maxZ) * (0.5f / SCENE_SCALE);
renderSceneAdd(renderScene, gCurrentLevel->staticContent[i].displayList, NULL, gCurrentLevel->staticContent[i].materialIndex, &boxCenter, NULL);
Mtx* matrix = NULL;
if (gCurrentLevel->staticContent[i].transformIndex != NO_TRANSFORM_INDEX) {
matrix = &staticTransforms[gCurrentLevel->staticContent[i].transformIndex];
}
renderSceneAdd(renderScene, gCurrentLevel->staticContent[i].displayList, matrix, gCurrentLevel->staticContent[i].materialIndex, &boxCenter, NULL);
}
}
@ -75,14 +81,14 @@ int staticRenderIsRoomVisible(u64 visibleRooms, u16 roomIndex) {
return (visibleRooms & (1LL << roomIndex)) != 0;
}
void staticRender(struct Transform* cameraTransform, struct FrustrumCullingInformation* cullingInfo, u64 visibleRooms, struct DynamicRenderDataList* dynamicList, int stageIndex, struct RenderState* renderState) {
void staticRender(struct Transform* cameraTransform, struct FrustrumCullingInformation* cullingInfo, u64 visibleRooms, struct DynamicRenderDataList* dynamicList, int stageIndex, Mtx* staticTransforms, struct RenderState* renderState) {
if (!gCurrentLevel) {
return;
}
struct RenderScene* renderScene = renderSceneNew(cameraTransform, renderState, MAX_RENDER_COUNT, visibleRooms);
staticRenderPopulateRooms(cullingInfo, renderScene);
staticRenderPopulateRooms(cullingInfo, staticTransforms, renderScene);
dynamicRenderPopulateRenderScene(dynamicList, stageIndex, renderScene);

View file

@ -8,6 +8,6 @@
void staticRenderDetermineVisibleRooms(struct FrustrumCullingInformation* cullingInfo, u16 currentRoom, u64* visitedRooms);
int staticRenderIsRoomVisible(u64 visibleRooms, u16 roomIndex);
void staticRender(struct Transform* cameraTransform, struct FrustrumCullingInformation* cullingInfo, u64 visibleRooms, struct DynamicRenderDataList* dynamicList, int stageIndex, struct RenderState* renderState);
void staticRender(struct Transform* cameraTransform, struct FrustrumCullingInformation* cullingInfo, u64 visibleRooms, struct DynamicRenderDataList* dynamicList, int stageIndex, Mtx* staticTransforms, struct RenderState* renderState);
#endif

View file

@ -158,7 +158,7 @@ static void gameProc(void* arg) {
dynamicSceneInit();
contactSolverInit(&gContactSolver);
portalSurfaceCleanupQueueInit();
levelLoad(0);
levelLoad(3);
cutsceneRunnerReset();
controllersInit();
initAudio(fps);

View file

@ -341,7 +341,7 @@ void playerUpdate(struct Player* player, struct Transform* cameraTransform) {
struct Vector3 forward;
struct Vector3 right;
skBlenderUpdate(&player->animator, player->armature.boneTransforms, FIXED_DELTA_TIME);
skBlenderUpdate(&player->animator, player->armature.pose, FIXED_DELTA_TIME);
int doorwayMask = worldCheckDoorwaySides(&gCurrentLevel->world, &player->lookTransform.position, player->body.currentRoom);
playerGetMoveBasis(&player->lookTransform, &forward, &right);

View file

@ -109,7 +109,7 @@ void boxDropperInit(struct BoxDropper* dropper, struct BoxDropperDefinition* def
}
void boxDropperUpdate(struct BoxDropper* dropper) {
skAnimatorUpdate(&dropper->animator, dropper->armature.boneTransforms, FIXED_DELTA_TIME);
skAnimatorUpdate(&dropper->animator, dropper->armature.pose, FIXED_DELTA_TIME);
if (dropper->reloadTimer > 0.0f) {
dropper->reloadTimer -= FIXED_DELTA_TIME;

View file

@ -82,7 +82,7 @@ void pedestalDetermineHolderAngle(struct Pedestal* pedestal, struct Vector2* out
}
void pedestalUpdate(struct Pedestal* pedestal) {
skAnimatorUpdate(&pedestal->animator, pedestal->armature.boneTransforms, FIXED_DELTA_TIME);
skAnimatorUpdate(&pedestal->animator, pedestal->armature.pose, FIXED_DELTA_TIME);
if (pedestal->flags & PedestalFlagsIsPointing) {
struct Vector2 target;
@ -93,7 +93,7 @@ void pedestalUpdate(struct Pedestal* pedestal) {
}
}
quatAxisComplex(&gUp, &pedestal->currentRotation, &pedestal->armature.boneTransforms[PEDESTAL_HOLDER_BONE].rotation);
quatAxisComplex(&gUp, &pedestal->currentRotation, &pedestal->armature.pose[PEDESTAL_HOLDER_BONE].rotation);
}
void pedestalHide(struct Pedestal* pedestal) {

View file

@ -408,7 +408,7 @@ void renderPlanBuild(struct RenderPlan* renderPlan, struct Scene* scene, struct
renderPlanAdjustViewportDepth(renderPlan);
}
void renderPlanExecute(struct RenderPlan* renderPlan, struct Scene* scene, struct RenderState* renderState) {
void renderPlanExecute(struct RenderPlan* renderPlan, struct Scene* scene, Mtx* staticTransforms, struct RenderState* renderState) {
struct DynamicRenderDataList* dynamicList = dynamicRenderListNew(MAX_DYNAMIC_SCENE_OBJECTS);
dynamicRenderListPopulate(dynamicList, renderPlan->stageProps, renderPlan->stageCount, renderState);
@ -474,7 +474,7 @@ void renderPlanExecute(struct RenderPlan* renderPlan, struct Scene* scene, struc
portalIndex = 1 - portalIndex;
}
staticRender(&current->camera.transform, &current->cameraMatrixInfo.cullingInformation, current->visiblerooms, dynamicList, stageIndex, renderState);
staticRender(&current->camera.transform, &current->cameraMatrixInfo.cullingInformation, current->visiblerooms, dynamicList, stageIndex, staticTransforms, renderState);
}
dynamicRenderListFree(dynamicList);

View file

@ -47,6 +47,6 @@ struct RenderPlan {
void renderPlanBuild(struct RenderPlan* renderPlan, struct Scene* scene, struct RenderState* renderState);
void renderPlanExecute(struct RenderPlan* renderPlan, struct Scene* scene, struct RenderState* renderState);
void renderPlanExecute(struct RenderPlan* renderPlan, struct Scene* scene, Mtx* staticTransforms, struct RenderState* renderState);
#endif

View file

@ -118,6 +118,8 @@ void sceneInit(struct Scene* scene) {
}
scene->freeCameraOffset = gZeroVec;
sceneAnimatorInit(&scene->animator, gCurrentLevel->animations, gCurrentLevel->animationInfoCount);
}
#define SOLID_COLOR 0, 0, 0, ENVIRONMENT, 0, 0, 0, ENVIRONMENT
@ -175,8 +177,10 @@ void sceneRender(struct Scene* scene, struct RenderState* renderState, struct Gr
struct RenderPlan renderPlan;
Mtx* staticMatrices = sceneAnimatorBuildTransforms(&scene->animator, renderState);
renderPlanBuild(&renderPlan, scene, renderState);
renderPlanExecute(&renderPlan, scene, renderState);
renderPlanExecute(&renderPlan, scene, staticMatrices, renderState);
sceneRenderPortalGun(scene, renderState);
@ -334,6 +338,7 @@ void sceneUpdate(struct Scene* scene) {
collisionSceneUpdateDynamics();
sceneAnimatorUpdate(&scene->animator);
levelCheckTriggers(&scene->player.lookTransform.position);
cutscenesUpdate();

View file

@ -16,6 +16,7 @@
#include "pedestal.h"
#include "signage.h"
#include "box_dropper.h"
#include "scene_animator.h"
struct Scene {
struct Camera camera;
@ -30,6 +31,7 @@ struct Scene {
struct Signage* signage;
struct BoxDropper* boxDroppers;
struct Vector3 freeCameraOffset;
struct SceneAnimator animator;
OSTime cpuTime;
OSTime lastFrameStart;
OSTime lastFrameTime;

View file

@ -0,0 +1,41 @@
#include "scene_animator.h"
#include "../util/memory.h"
#include "../util/time.h"
void sceneAnimatorInit(struct SceneAnimator* sceneAnimator, struct AnimationInfo* animationInfo, int animatorCount) {
sceneAnimator->armatures = malloc(sizeof(struct SKArmature) * animatorCount);
sceneAnimator->animators = malloc(sizeof(struct SKAnimator) * animatorCount);
sceneAnimator->animationInfo = animationInfo;
sceneAnimator->animatorCount = animatorCount;
sceneAnimator->boneCount = 0;
for (int i = 0; i < animatorCount; ++i) {
skArmatureInit(&sceneAnimator->armatures[i], &animationInfo[i].armature);
skAnimatorInit(&sceneAnimator->animators[i], animationInfo[i].armature.numberOfBones);
sceneAnimator->boneCount += animationInfo[i].armature.numberOfBones;
}
}
void sceneAnimatorUpdate(struct SceneAnimator* sceneAnimator) {
for (int i = 0; i < sceneAnimator->animatorCount; ++i) {
skAnimatorUpdate(&sceneAnimator->animators[i], sceneAnimator->armatures[i].pose, FIXED_DELTA_TIME);
}
}
Mtx* sceneAnimatorBuildTransforms(struct SceneAnimator* sceneAnimator, struct RenderState* renderState) {
Mtx* result = renderStateRequestMatrices(renderState, sceneAnimator->boneCount);
Mtx* curr = result;
for (int i = 0; i < sceneAnimator->animatorCount; ++i) {
skCalculateTransforms(&sceneAnimator->armatures[i], curr);
curr += sceneAnimator->armatures[i].numberOfBones;
}
return result;
}

View file

@ -0,0 +1,25 @@
#ifndef __SCENE_ANIMATOR_H__
#define __SCENE_ANIMATOR_H__
#include "../levels/level_definition.h"
#include "../sk64/skelatool_armature.h"
#include "../sk64/skelatool_animator.h"
#include "../graphics/renderstate.h"
struct SceneAnimator {
struct SKArmature* armatures;
struct SKAnimator* animators;
struct AnimationInfo* animationInfo;
short animatorCount;
short boneCount;
};
void sceneAnimatorInit(struct SceneAnimator* sceneAnimator, struct AnimationInfo* animationInfo, int animatorCount);
void sceneAnimatorUpdate(struct SceneAnimator* sceneAnimator);
Mtx* sceneAnimatorBuildTransforms(struct SceneAnimator* sceneAnimator, struct RenderState* renderState);
#endif

View file

@ -11,20 +11,20 @@ void skArmatureInit(struct SKArmature* object, struct SKArmatureDefinition* defi
unsigned transformSize = sizeof(Mtx) * definition->numberOfBones;
object->boneTransforms = malloc(transformSize);
if (definition->initialPose) {
if (IS_KSEG0(definition->initialPose)) {
memCopy(object->boneTransforms, definition->initialPose, transformSize);
object->pose = malloc(transformSize);
if (definition->pose) {
if (IS_KSEG0(definition->pose)) {
memCopy(object->pose, definition->pose, transformSize);
} else {
romCopy((void*)definition->initialPose, (void*)object->boneTransforms, transformSize);
romCopy((void*)definition->pose, (void*)object->pose, transformSize);
}
}
object->boneParentIndex = definition->boneParentIndex;
}
void skCleanupObject(struct SKArmature* object) {
free(object->boneTransforms);
object->boneTransforms = 0;
free(object->pose);
object->pose = 0;
object->numberOfBones = 0;
}
@ -79,7 +79,7 @@ void skRenderObject(struct SKArmature* object, Gfx** attachements, struct Render
void skCalculateTransforms(struct SKArmature* object, Mtx* into) {
for (int i = 0; i < object->numberOfBones; ++i) {
transformToMatrixL(&object->boneTransforms[i], &into[i], 1.0f);
transformToMatrixL(&object->pose[i], &into[i], 1.0f);
}
}
@ -90,7 +90,7 @@ void skCalculateBonePosition(struct SKArmature* object, unsigned short boneIndex
*out = *bonePosition;
while (boneIndex < object->numberOfBones) {
transformPoint(&object->boneTransforms[boneIndex], out, out);
transformPoint(&object->pose[boneIndex], out, out);
boneIndex = object->boneParentIndex[boneIndex];
}
}

View file

@ -9,7 +9,7 @@
struct SKArmatureDefinition {
Gfx* displayList;
struct Transform* initialPose;
struct Transform* pose;
unsigned short* boneParentIndex;
u16 numberOfBones;
u16 numberOfAttachments;
@ -17,10 +17,10 @@ struct SKArmatureDefinition {
struct SKArmature {
Gfx* displayList;
struct Transform* boneTransforms;
struct Transform* pose;
unsigned short* boneParentIndex;
u16 numberOfBones;
u16 numberOfAttachments;
unsigned short* boneParentIndex;
};
void skArmatureInit(struct SKArmature* object, struct SKArmatureDefinition* definition);

View file

@ -28,6 +28,10 @@ local function proccessStaticNodes(nodes)
mesh_bb.max.x = math.floor(mesh_bb.max.x + 0.5)
mesh_bb.max.y = math.floor(mesh_bb.max.y + 0.5)
mesh_bb.max.z = math.floor(mesh_bb.max.z + 0.5)
if v.node.name == '@static floor.005' then
print(mesh_bb)
end
table.insert(result, {
node = v.node,