diff --git a/Makefile b/Makefile index 2ab0b43..c6cccf8 100644 --- a/Makefile +++ b/Makefile @@ -171,28 +171,17 @@ build/src/scene/elevator.o: build/assets/models/props/round_elevator_collision.h MODEL_LIST = assets/models/player/chell.blend \ assets/models/portal_gun/v_portalgun.blend \ assets/models/portal_gun/w_portalgun.blend \ - assets/models/props/button.blend \ - assets/models/props/door_01.blend \ - assets/models/props/door_02.blend \ - assets/models/props/combine_ball_catcher.blend \ - assets/models/props/combine_ball_launcher.blend \ - assets/models/props/portal_cleanser.blend \ assets/models/props/round_elevator.blend \ assets/models/props/round_elevator_interior.blend \ assets/models/props/round_elevator_collision.blend \ - assets/models/props/security_camera.blend \ assets/models/props/signage.blend \ assets/models/props/signage_off.blend \ - assets/models/props/switch001.blend \ - assets/models/props/box_dropper.blend \ - assets/models/props/box_dropper_glass.blend \ assets/models/portal/portal_blue.blend \ assets/models/portal/portal_blue_filled.blend \ assets/models/portal/portal_blue_face.blend \ assets/models/portal/portal_orange.blend \ assets/models/portal/portal_orange_filled.blend \ assets/models/portal/portal_orange_face.blend \ - assets/models/pedestal.blend \ assets/models/grav_flare.blend \ assets/models/fleck_ash2.blend @@ -201,16 +190,27 @@ DYNAMIC_MODEL_LIST = assets/models/cube/cube.blend \ assets/models/props/cylinder_test.blend \ assets/models/props/radio.blend \ assets/models/signage/clock_digits.blend \ - assets/models/signage/clock.blend - + assets/models/signage/clock.blend \ + assets/models/props/box_dropper_glass.blend \ + assets/models/props/portal_cleanser.blend + +DYNAMIC_ANIMATED_MODEL_LIST = assets/models/pedestal.blend \ + assets/models/props/box_dropper.blend \ + assets/models/props/button.blend \ + assets/models/props/combine_ball_catcher.blend \ + assets/models/props/combine_ball_launcher.blend \ + assets/models/props/door_01.blend \ + assets/models/props/door_02.blend \ + assets/models/props/security_camera.blend \ + assets/models/props/switch001.blend ANIM_LIST = build/assets/models/pedestal_anim.o \ + build/assets/models/player/chell_anim.o \ build/assets/models/props/box_dropper_anim.o \ build/assets/models/props/combine_ball_catcher_anim.o \ build/assets/models/props/combine_ball_launcher_anim.o \ build/assets/models/props/door_01_anim.o \ build/assets/models/props/door_02_anim.o \ - build/assets/models/player/chell_anim.o \ build/assets/models/props/switch001_anim.o MODEL_HEADERS = $(MODEL_LIST:%.blend=build/%.h) @@ -219,70 +219,44 @@ MODEL_OBJECTS = $(MODEL_LIST:%.blend=build/%_geo.o) DYNAMIC_MODEL_HEADERS = $(DYNAMIC_MODEL_LIST:%.blend=build/%.h) DYNAMIC_MODEL_OBJECTS = $(DYNAMIC_MODEL_LIST:%.blend=build/%_geo.o) +DYNAMIC_ANIMATED_MODEL_HEADERS = $(DYNAMIC_ANIMATED_MODEL_LIST:%.blend=build/%.h) +DYNAMIC_ANIMATED_MODEL_OBJECTS = $(DYNAMIC_ANIMATED_MODEL_LIST:%.blend=build/%_geo.o) + build/assets/models/%.h build/assets/models/%_geo.c build/assets/models/%_anim.c: build/assets/models/%.fbx assets/models/%.flags assets/materials/elevator.skm.yaml assets/materials/objects.skm.yaml assets/materials/static.skm.yaml $(TEXTURE_IMAGES) $(SKELATOOL64) $(SKELATOOL64) --fixed-point-scale 256 --model-scale 0.01 --name $(<:build/assets/models/%.fbx=%) $(shell cat $(<:build/assets/models/%.fbx=assets/models/%.flags)) -o $(<:%.fbx=%.h) $< -build/src/models/models.o: $(MODEL_HEADERS) - -build/src/decor/decor_object_list.o: build/assets/models/dynamic_model_list.h build/assets/materials/static.h - -build/src/scene/portal.o: $(MODEL_HEADERS) - -build/src/scene/signage.o: $(MODEL_HEADERS) - -build/src/scene/box_dropper.o: $(MODEL_HEADERS) build/assets/models/dynamic_model_list.h - -build/src/scene/pedestal.o: $(MODEL_HEADERS) - -build/src/scene/render_plan.o: $(MODEL_HEADERS) - -build/src/scene/portal_render.o: $(MODEL_HEADERS) - -build/src/scene/clock.o: build/assets/models/dynamic_model_list.h - -build/src/scene/fizzler.o: $(MODEL_HEADERS) - -build/src/scene/security_camera.o: build/src/audio/clips.h $(MODEL_HEADERS) - -build/src/scene/switch.o: build/assets/models/props/switch001.h build/assets/materials/static.h - -build/src/player/player.o: build/assets/models/player/chell.h build/assets/materials/static.h - -build/src/scene/ball.o: build/assets/models/grav_flare.h build/assets/models/fleck_ash2.h build/assets/materials/static.h - -build/src/scene/ball_launcher.o: build/assets/models/props/combine_ball_launcher.h build/assets/materials/static.h - -build/src/scene/ball_catcher.o: build/assets/models/props/combine_ball_catcher.h build/assets/materials/static.h - -build/src/scene/door.o: build/assets/models/props/door_01.h build/assets/models/props/door_02.h - -build/src/menu/game_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h - -build/src/menu/main_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h - -build/src/menu/new_game_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h - -build/src/menu/load_game.o: build/assets/materials/ui.h build/src/audio/clips.h - -build/src/menu/save_game_menu.o: build/src/audio/clips.h - -build/src/menu/savefile_list.o: build/assets/materials/ui.h build/src/audio/clips.h - -build/src/menu/landing_menu.o: build/assets/materials/ui.h build/src/audio/clips.h - -build/src/menu/options_menu.o: build/assets/materials/ui.h - -build/src/menu/joystick_options.o: build/assets/materials/ui.h build/src/audio/clips.h - -build/src/menu/controls.o: build/assets/materials/ui.h build/src/audio/clips.h - -build/src/util/dynamic_asset_data.o: build/assets/models/dynamic_model_list_data.h - build/assets/models/player/chell.h: assets/materials/chell.skm.yaml - build/assets/models/props/combine_ball_catcher.h: assets/materials/ball_catcher.skm.yaml - build/assets/models/props/combine_ball_launcher.h: assets/materials/ball_catcher.skm.yaml +build/src/decor/decor_object_list.o: build/assets/models/dynamic_model_list.h build/assets/materials/static.h +build/src/menu/controls.o: build/assets/materials/ui.h build/src/audio/clips.h +build/src/menu/game_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h +build/src/menu/joystick_options.o: build/assets/materials/ui.h build/src/audio/clips.h +build/src/menu/landing_menu.o: build/assets/materials/ui.h build/src/audio/clips.h +build/src/menu/load_game.o: build/assets/materials/ui.h build/src/audio/clips.h +build/src/menu/main_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h +build/src/menu/new_game_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h +build/src/menu/options_menu.o: build/assets/materials/ui.h +build/src/menu/save_game_menu.o: build/src/audio/clips.h +build/src/menu/savefile_list.o: build/assets/materials/ui.h build/src/audio/clips.h +build/src/player/player.o: build/assets/models/player/chell.h build/assets/materials/static.h +build/src/scene/ball_catcher.o: build/assets/models/props/combine_ball_catcher.h build/assets/materials/static.h build/assets/models/dynamic_animated_model_list.h +build/src/scene/ball_launcher.o: build/assets/models/props/combine_ball_launcher.h build/assets/materials/static.h build/assets/models/dynamic_animated_model_list.h +build/src/scene/ball.o: build/assets/models/grav_flare.h build/assets/models/fleck_ash2.h build/assets/materials/static.h +build/src/scene/box_dropper.o: build/assets/materials/static.h build/assets/models/props/box_dropper.h build/assets/models/dynamic_model_list.h build/assets/models/dynamic_animated_model_list.h +build/src/scene/button.o: build/assets/materials/static.h build/assets/models/props/button.h build/assets/models/dynamic_animated_model_list.h +build/src/scene/clock.o: build/assets/models/dynamic_model_list.h +build/src/scene/door.o: build/assets/materials/static.h build/assets/models/props/door_01.h build/assets/models/props/door_02.h build/assets/models/dynamic_animated_model_list.h +build/src/scene/fizzler.o: build/assets/models/dynamic_model_list.h +build/src/scene/pedestal.o: build/assets/materials/static.h build/assets/models/pedestal.h build/assets/models/dynamic_animated_model_list.h build/assets/models/portal_gun/w_portalgun.h +build/src/scene/portal_gun.o: $(MODEL_HEADERS) +build/src/scene/portal_render.o: $(MODEL_HEADERS) +build/src/scene/portal.o: $(MODEL_HEADERS) +build/src/scene/render_plan.o: $(MODEL_HEADERS) +build/src/scene/security_camera.o: build/src/audio/clips.h build/assets/models/props/security_camera.h build/assets/models/dynamic_animated_model_list.h +build/src/scene/signage.o: $(MODEL_HEADERS) +build/src/scene/switch.o: build/assets/models/props/switch001.h build/assets/materials/static.h build/assets/models/dynamic_animated_model_list.h +build/src/util/dynamic_asset_data.o: build/assets/models/dynamic_model_list_data.h ANIM_TEST_CHAMBERS = build/assets/test_chambers/test_chamber_00/test_chamber_00_anim.o \ @@ -341,13 +315,17 @@ build/assets/models/dynamic_model_list.h build/assets/models/dynamic_model_list_ @mkdir -p $(@D) node tools/generate_dynamic_model_list.js build/assets/models/dynamic_model_list.h build/assets/models/dynamic_model_list_data.h $(DYNAMIC_MODEL_HEADERS) +build/assets/models/dynamic_animated_model_list.h build/assets/models/dynamic_animated_model_list_data.h: $(DYNAMIC_ANIMATED_MODEL_HEADERS) tools/generate_dynamic_animated_model_list.js + @mkdir -p $(@D) + node tools/generate_dynamic_animated_model_list.js build/assets/models/dynamic_animated_model_list.h build/assets/models/dynamic_animated_model_list_data.h $(DYNAMIC_ANIMATED_MODEL_HEADERS) + build/levels.ld: $(TEST_CHAMBER_OBJECTS) tools/generate_level_ld.js @mkdir -p $(@D) node tools/generate_level_ld.js $@ 0x02000000 $(TEST_CHAMBER_OBJECTS) -build/dynamic_models.ld: $(DYNAMIC_MODEL_OBJECTS) tools/generate_level_ld.js +build/dynamic_models.ld: $(DYNAMIC_MODEL_OBJECTS) $(DYNAMIC_ANIMATED_MODEL_OBJECTS) tools/generate_level_ld.js @mkdir -p $(@D) - node tools/generate_level_ld.js $@ 0x03000000 $(DYNAMIC_MODEL_OBJECTS) + node tools/generate_level_ld.js $@ 0x03000000 $(DYNAMIC_MODEL_OBJECTS) $(DYNAMIC_ANIMATED_MODEL_OBJECTS) build/src/levels/levels.o: build/assets/test_chambers/level_list.h build/assets/materials/static.h diff --git a/skelatool64/src/definition_generator/AnimationGenerator.cpp b/skelatool64/src/definition_generator/AnimationGenerator.cpp index f8d953f..fe3178c 100644 --- a/skelatool64/src/definition_generator/AnimationGenerator.cpp +++ b/skelatool64/src/definition_generator/AnimationGenerator.cpp @@ -155,7 +155,7 @@ aiQuaternion evaluateQuaternionAt(const aiQuatKey* keys, unsigned keyCount, doub return output; } -void generateanimationV2(const aiAnimation& animation, BoneHierarchy& bones, CFileDefinition& fileDef, const DisplayListSettings& settings) { +std::string generateanimationV2(const aiAnimation& animation, int index, BoneHierarchy& bones, CFileDefinition& fileDef, const DisplayListSettings& settings) { int nFrames = ceil(animation.mDuration * settings.mTicksPerSecond / animation.mTicksPerSecond) + 1; std::vector> allFrameData(nFrames); @@ -235,13 +235,28 @@ void generateanimationV2(const aiAnimation& animation, BoneHierarchy& bones, CFi clip->AddPrimitive(bones.GetBoneCount()); clip->AddPrimitive(framesName); clip->AddPrimitive(settings.mTicksPerSecond); - fileDef.AddDataDefinition(std::string(animation.mName.C_Str()) + "_clip", "struct SKAnimationClip", false, "_geo", std::move(clip)); + std::string result = fileDef.AddDataDefinition(std::string(animation.mName.C_Str()) + "_clip", "struct SKAnimationClip", false, "_geo", std::move(clip)); + + std::string animationMacroName = fileDef.GetUniqueName(std::string(animation.mName.C_Str()) + "_clip_index"); + std::transform(animationMacroName.begin(), animationMacroName.end(), animationMacroName.begin(), ::toupper); + fileDef.AddMacro(animationMacroName, std::to_string(index)); + + return result; } void generateAnimationDataV2(const aiScene* scene, BoneHierarchy& bones, CFileDefinition& fileDef, const DisplayListSettings& settings) { + std::unique_ptr clipArray(new StructureDataChunk()); + for (unsigned animationIndex = 0; animationIndex < scene->mNumAnimations; ++animationIndex) { - generateanimationV2(*scene->mAnimations[animationIndex], bones, fileDef, settings); + std::string clipName = generateanimationV2(*scene->mAnimations[animationIndex], animationIndex, bones, fileDef, settings); + clipArray->AddPrimitive("&" + clipName); } + + fileDef.AddDataDefinition("clips", "struct SKAnimationClip*", true, "_geo", std::move(clipArray)); + + std::string clipCountMacroName = fileDef.GetUniqueName("CLIP_COUNT"); + std::transform(clipCountMacroName.begin(), clipCountMacroName.end(), clipCountMacroName.begin(), ::toupper); + fileDef.AddMacro(clipCountMacroName, std::to_string(scene->mNumAnimations)); } AnimationResults generateAnimationForScene(const aiScene* scene, CFileDefinition &fileDefinition, DisplayListSettings& settings) { diff --git a/src/models/models.c b/src/models/models.c deleted file mode 100644 index 9ba13ed..0000000 --- a/src/models/models.c +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include "sk64/skelatool_animator.h" - -#include "../../build/assets/models/portal_gun/v_portalgun.h" -#include "../../build/assets/models/portal_gun/w_portalgun.h" -#include "../../build/assets/materials/static.h" -#include "../../build/assets/models/props/button.h" -#include "../../build/assets/models/props/door_01.h" -#include "../../build/assets/models/props/cylinder_test.h" -#include "../../build/assets/models/props/box_dropper.h" -#include "../../build/assets/models/props/box_dropper_glass.h" - -Gfx* v_portal_gun_gfx = &portal_gun_v_portalgun_model_gfx[0]; - -Gfx* w_portal_gun_gfx = &portal_gun_w_portalgun_model_gfx[0]; - -Gfx* button_gfx = &props_button_model_gfx[0]; -short button_material_index = BUTTON_INDEX; - -Gfx* cylinder_gfx = &props_cylinder_test_model_gfx[0]; -short cylinder_material_index = PLASTIC_PLASTICWALL001A_INDEX; - -short fizzler_material_index = PORTAL_CLEANSER_INDEX; - -Gfx* box_dropper_gfx = props_box_dropper_model_gfx; -Gfx* box_dropper_glass_gfx = props_box_dropper_glass_model_gfx; -short box_dropper_material_index = DEFAULT_INDEX; -short box_dropper_glass_material_index = GLASSWINDOW_FROSTED_002_INDEX; \ No newline at end of file diff --git a/src/models/models.h b/src/models/models.h deleted file mode 100644 index d22aade..0000000 --- a/src/models/models.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __MODELS_H__ -#define __MODELS_H__ - -extern Gfx* v_portal_gun_gfx; - -extern Gfx* w_portal_gun_gfx; - -extern Gfx* button_gfx; -extern short button_material_index; - -extern Gfx* cylinder_gfx; -extern short cylinder_material_index; - -extern short fizzler_material_index; - -extern Gfx* box_dropper_gfx; -extern Gfx* box_dropper_glass_gfx; -extern short box_dropper_material_index; -extern short box_dropper_glass_material_index; - - -#endif \ No newline at end of file diff --git a/src/scene/ball.c b/src/scene/ball.c index 9ccf422..cc5803e 100644 --- a/src/scene/ball.c +++ b/src/scene/ball.c @@ -10,7 +10,6 @@ #include "../build/assets/models/grav_flare.h" #include "../build/assets/models/fleck_ash2.h" -#include "../build/assets/models/cube/cube.h" #include "../build/assets/materials/static.h" #include "../audio/soundplayer.h" diff --git a/src/scene/ball_catcher.c b/src/scene/ball_catcher.c index 6e179fc..ed2a251 100644 --- a/src/scene/ball_catcher.c +++ b/src/scene/ball_catcher.c @@ -6,9 +6,11 @@ #include "../physics/collision_scene.h" #include "dynamic_scene.h" #include "signals.h" +#include "../util/dynamic_asset_loader.h" #include "../build/assets/models/props/combine_ball_catcher.h" #include "../build/assets/materials/static.h" +#include "../../build/assets/models/dynamic_animated_model_list.h" struct CollisionBox gBallCatcherBox = { {0.5f, 0.5f, 0.5f}, @@ -47,7 +49,7 @@ void ballCatcherRender(void* data, struct DynamicRenderDataList* renderList, str dynamicRenderListAddData( renderList, - props_combine_ball_catcher_model_gfx, + catcher->armature.displayList, matrix, BALL_CATCHER_INDEX, &catcher->rigidBody.transform.position, @@ -56,8 +58,10 @@ void ballCatcherRender(void* data, struct DynamicRenderDataList* renderList, str } void ballCatcherInit(struct BallCatcher* catcher, struct BallCatcherDefinition* definition) { + struct SKArmatureWithAnimations* armature = dynamicAssetAnimatedModel(PROPS_COMBINE_BALL_CATCHER_DYNAMIC_ANIMATED_MODEL); + collisionObjectInit(&catcher->collisionObject, &gBallCatcherCollider, &catcher->rigidBody, 1.0f, COLLISION_LAYERS_TANGIBLE); - rigidBodyMarkKinematic(&catcher->rigidBody); + rigidBodyMarkKinematic(&catcher->rigidBody); collisionSceneAddDynamicObject(&catcher->collisionObject); catcher->rigidBody.transform.position = definition->position; @@ -76,7 +80,7 @@ void ballCatcherInit(struct BallCatcher* catcher, struct BallCatcherDefinition* dynamicSceneSetRoomFlags(catcher->dynamicId, ROOM_FLAG_FROM_INDEX(catcher->rigidBody.currentRoom)); skAnimatorInit(&catcher->animator, PROPS_COMBINE_BALL_CATCHER_DEFAULT_BONES_COUNT); - skArmatureInit(&catcher->armature, &props_combine_ball_catcher_armature); + skArmatureInit(&catcher->armature, armature->armature); } void ballCatcherCheckBalls(struct BallCatcher* catcher, struct BallLauncher* ballLaunchers, int ballLauncherCount) { @@ -105,7 +109,7 @@ void ballCatcherCheckBalls(struct BallCatcher* catcher, struct BallLauncher* bal catcher->caughtBall = &launcher->currentBall; soundPlayerPlay(soundsBallCatcher, 5.0f, 1.0f, &catcher->rigidBody.transform.position, &catcher->rigidBody.velocity); ballMarkCaught(catcher->caughtBall); - skAnimatorRunClip(&catcher->animator, &props_combine_ball_catcher_Armature_catch_clip, 0.0f, 0); + skAnimatorRunClip(&catcher->animator, dynamicAssetClip(PROPS_COMBINE_BALL_CATCHER_DYNAMIC_ANIMATED_MODEL, PROPS_COMBINE_BALL_CATCHER_ARMATURE_CATCH_CLIP_INDEX), 0.0f, 0); } } diff --git a/src/scene/ball_launcher.c b/src/scene/ball_launcher.c index e3945e8..fc35796 100644 --- a/src/scene/ball_launcher.c +++ b/src/scene/ball_launcher.c @@ -8,10 +8,11 @@ #include "signals.h" #include "../audio/clips.h" #include "../audio/soundplayer.h" +#include "../util/dynamic_asset_loader.h" #include "../build/assets/models/props/combine_ball_launcher.h" #include "../build/assets/materials/static.h" - +#include "../../build/assets/models/dynamic_animated_model_list.h" struct CollisionBox gBallLauncherBox = { {0.5f, 0.5f, 0.5f}, @@ -46,7 +47,7 @@ void ballLauncherRender(void* data, struct DynamicRenderDataList* renderList, st dynamicRenderListAddData( renderList, - props_combine_ball_launcher_model_gfx, + launcher->armature.displayList, matrix, BALL_CATCHER_INDEX, &launcher->rigidBody.transform.position, @@ -55,6 +56,8 @@ void ballLauncherRender(void* data, struct DynamicRenderDataList* renderList, st } void ballLauncherInit(struct BallLauncher* launcher, struct BallLauncherDefinition* definition) { + struct SKArmatureWithAnimations* armature = dynamicAssetAnimatedModel(PROPS_COMBINE_BALL_LAUNCHER_DYNAMIC_ANIMATED_MODEL); + collisionObjectInit(&launcher->collisionObject, &gBallLauncherCollider, &launcher->rigidBody, 1.0f, COLLISION_LAYERS_TANGIBLE | COLLISION_LAYERS_BLOCK_BALL); rigidBodyMarkKinematic(&launcher->rigidBody); collisionSceneAddDynamicObject(&launcher->collisionObject); @@ -74,7 +77,7 @@ void ballLauncherInit(struct BallLauncher* launcher, struct BallLauncherDefiniti dynamicSceneSetRoomFlags(launcher->dynamicId, ROOM_FLAG_FROM_INDEX(launcher->rigidBody.currentRoom)); skAnimatorInit(&launcher->animator, PROPS_COMBINE_BALL_LAUNCHER_DEFAULT_BONES_COUNT); - skArmatureInit(&launcher->armature, &props_combine_ball_launcher_armature); + skArmatureInit(&launcher->armature, armature->armature); ballInitInactive(&launcher->currentBall); } @@ -94,7 +97,7 @@ void ballLauncherUpdate(struct BallLauncher* launcher) { vector3Scale(&initialVelocity, &initialVelocity, BALL_VELOCITY); ballInit(&launcher->currentBall, &launcher->rigidBody.transform.position, &initialVelocity, launcher->rigidBody.currentRoom, launcher->ballLifetime); - skAnimatorRunClip(&launcher->animator, &props_combine_ball_launcher_Armature_launch_clip, 0.0f, 0); + skAnimatorRunClip(&launcher->animator, dynamicAssetClip(PROPS_COMBINE_BALL_LAUNCHER_DYNAMIC_ANIMATED_MODEL, PROPS_COMBINE_BALL_LAUNCHER_ARMATURE_LAUNCH_CLIP_INDEX), 0.0f, 0); soundPlayerPlay(soundsBallLaunch, 1.0f, 1.0f, &launcher->rigidBody.transform.position, &gZeroVec); } diff --git a/src/scene/box_dropper.c b/src/scene/box_dropper.c index 8bdd636..fa4249c 100644 --- a/src/scene/box_dropper.c +++ b/src/scene/box_dropper.c @@ -1,7 +1,6 @@ #include "box_dropper.h" #include "../scene/dynamic_scene.h" -#include "../models/models.h" #include "../defs.h" #include "../physics/config.h" #include "../util/time.h" @@ -12,6 +11,7 @@ #include "../../build/assets/materials/static.h" #include "../../build/assets/models/props/box_dropper.h" #include "../../build/assets/models/dynamic_model_list.h" +#include "../../build/assets/models/dynamic_animated_model_list.h" #define DROOPER_RELOAD_TIME 2.0f #define DROPPER_DROP_TIME 0.5f @@ -50,18 +50,18 @@ void boxDropperRender(void* data, struct DynamicRenderDataList* renderList, stru dynamicRenderListAddData( renderList, - props_box_dropper_model_gfx, + dropper->armature.displayList, matrix, - box_dropper_material_index, + DEFAULT_INDEX, &dropper->transform.position, armature ); dynamicRenderListAddData( renderList, - box_dropper_glass_gfx, + dynamicAssetModel(PROPS_BOX_DROPPER_GLASS_DYNAMIC_MODEL), matrix, - box_dropper_glass_material_index, + GLASSWINDOW_FROSTED_002_INDEX, &dropper->transform.position, NULL ); @@ -90,6 +90,8 @@ void boxDropperRender(void* data, struct DynamicRenderDataList* renderList, stru } void boxDropperInit(struct BoxDropper* dropper, struct BoxDropperDefinition* definition) { + struct SKArmatureWithAnimations* armature = dynamicAssetAnimatedModel(PROPS_BOX_DROPPER_DYNAMIC_ANIMATED_MODEL); + dropper->dynamicId = dynamicSceneAdd(dropper, boxDropperRender, &dropper->transform.position, 1.5f); dropper->transform.position = definition->position; @@ -99,7 +101,7 @@ void boxDropperInit(struct BoxDropper* dropper, struct BoxDropperDefinition* def dropper->roomIndex = definition->roomIndex; dropper->signalIndex = definition->signalIndex; - skArmatureInit(&dropper->armature, &props_box_dropper_armature); + skArmatureInit(&dropper->armature, armature->armature); skAnimatorInit(&dropper->animator, PROPS_BOX_DROPPER_DEFAULT_BONES_COUNT); @@ -109,6 +111,7 @@ void boxDropperInit(struct BoxDropper* dropper, struct BoxDropperDefinition* def dynamicSceneSetRoomFlags(dropper->dynamicId, ROOM_FLAG_FROM_INDEX(dropper->roomIndex)); dynamicAssetModelPreload(CUBE_CUBE_DYNAMIC_MODEL); + dynamicAssetModelPreload(PROPS_BOX_DROPPER_GLASS_DYNAMIC_MODEL); } void boxDropperUpdate(struct BoxDropper* dropper) { @@ -146,7 +149,7 @@ void boxDropperUpdate(struct BoxDropper* dropper) { boxDropperFakePos(dropper, &pendingCubePos); decorObjectInit(&dropper->activeCube, decorObjectDefinitionForId(DECOR_TYPE_CUBE_UNIMPORTANT), &pendingCubePos, dropper->roomIndex); - skAnimatorRunClip(&dropper->animator, &props_box_dropper_Armature_DropCube_clip, 0.0f, 0); + skAnimatorRunClip(&dropper->animator, dynamicAssetClip(PROPS_BOX_DROPPER_DYNAMIC_ANIMATED_MODEL, PROPS_BOX_DROPPER_ARMATURE_DROPCUBE_CLIP_INDEX), 0.0f, 0); soundPlayerPlay(soundsReleaseCube, 5.0f, 0.5f, &dropper->activeCube.rigidBody.transform.position, &gZeroVec); dropper->flags &= ~BoxDropperFlagsCubeRequested; diff --git a/src/scene/button.c b/src/scene/button.c index fe6a5ea..e609eae 100644 --- a/src/scene/button.c +++ b/src/scene/button.c @@ -1,15 +1,17 @@ #include "button.h" #include "defs.h" -#include "../models/models.h" #include "../graphics/renderstate.h" #include "dynamic_scene.h" #include "../physics/collision_cylinder.h" #include "../physics/collision_scene.h" #include "../physics/contact_solver.h" #include "../util/time.h" +#include "../util/dynamic_asset_loader.h" -#include "../build/assets/models/props/button.h" +#include "../../build/assets/models/dynamic_animated_model_list.h" +#include "../build/assets/materials/static.h" +#include "../../build/assets/models/props/button.h" struct Vector2 gButtonCylinderEdgeVectors[] = { {0.0f, 1.0f}, @@ -59,16 +61,20 @@ void buttonRender(void* data, struct DynamicRenderDataList* renderList, struct R return; } - transformToMatrixL(&props_button_default_bones[PROPS_BUTTON_BUTTONBASE_BONE], &armature[PROPS_BUTTON_BUTTONBASE_BONE], 1.0f); + struct SKArmatureWithAnimations* armatureDef = dynamicAssetAnimatedModel(PROPS_BUTTON_DYNAMIC_ANIMATED_MODEL); + + transformToMatrixL(&armatureDef->armature->pose[PROPS_BUTTON_BUTTONBASE_BONE], &armature[PROPS_BUTTON_BUTTONBASE_BONE], 1.0f); // reusing global memory - props_button_default_bones[PROPS_BUTTON_BUTTONPAD_BONE].position.y = (button->rigidBody.transform.position.y - button->originalPos.y) * SCENE_SCALE; - transformToMatrixL(&props_button_default_bones[PROPS_BUTTON_BUTTONPAD_BONE], &armature[PROPS_BUTTON_BUTTONPAD_BONE], 1.0f); + armatureDef->armature->pose[PROPS_BUTTON_BUTTONPAD_BONE].position.y = (button->rigidBody.transform.position.y - button->originalPos.y) * SCENE_SCALE; + transformToMatrixL(&armatureDef->armature->pose[PROPS_BUTTON_BUTTONPAD_BONE], &armature[PROPS_BUTTON_BUTTONPAD_BONE], 1.0f); - dynamicRenderListAddData(renderList, button_gfx, matrix, button_material_index, &button->rigidBody.transform.position, armature); + dynamicRenderListAddData(renderList, armatureDef->armature->displayList, matrix, BUTTON_INDEX, &button->rigidBody.transform.position, armature); } void buttonInit(struct Button* button, struct ButtonDefinition* definition) { + dynamicAssetAnimatedModel(PROPS_BUTTON_DYNAMIC_ANIMATED_MODEL); + collisionObjectInit(&button->collisionObject, &gButtonCollider, &button->rigidBody, 1.0f, COLLISION_LAYERS_TANGIBLE); rigidBodyMarkKinematic(&button->rigidBody); collisionSceneAddDynamicObject(&button->collisionObject); diff --git a/src/scene/door.c b/src/scene/door.c index fb4af58..447cd66 100644 --- a/src/scene/door.c +++ b/src/scene/door.c @@ -2,15 +2,16 @@ #include "../graphics/render_scene.h" #include "defs.h" -#include "../models/models.h" #include "../scene/dynamic_scene.h" #include "signals.h" #include "../math/mathf.h" #include "../util/time.h" #include "../physics/collision_box.h" #include "../physics/collision_scene.h" +#include "../util/dynamic_asset_loader.h" #include "../build/assets/materials/static.h" +#include "../../build/assets/models/dynamic_animated_model_list.h" #include "../build/assets/models/props/door_01.h" #include "../build/assets/models/props/door_02.h" @@ -33,22 +34,20 @@ struct ColliderTypeData gDoorCollider = { struct DoorTypeDefinition gDoorTypeDefinitions[] = { [DoorType01] = { - &props_door_01_armature, - &props_door_01_model_gfx[0], - &props_door_01_Armature_open_clip, - &props_door_01_Armature_close_clip, - &props_door_01_Armature_opened_clip, + PROPS_DOOR_01_DYNAMIC_ANIMATED_MODEL, + PROPS_DOOR_01_ARMATURE_OPEN_CLIP_INDEX, + PROPS_DOOR_01_ARMATURE_CLOSE_CLIP_INDEX, + PROPS_DOOR_01_ARMATURE_OPENED_CLIP_INDEX, DOOR_01_INDEX, -1, 1.0f, {0.0f, 0.0f, 0.0f, 1.0f}, }, [DoorType02] = { - &props_door_02_armature, - &props_door_02_model_gfx[0], - &props_door_02_Armature_open_clip, - &props_door_02_Armature_close_clip, - &props_door_02_Armature_opened_clip, + PROPS_DOOR_02_DYNAMIC_ANIMATED_MODEL, + PROPS_DOOR_02_ARMATURE_OPEN_CLIP_INDEX, + PROPS_DOOR_02_ARMATURE_CLOSE_CLIP_INDEX, + PROPS_DOOR_02_ARMATURE_OPENED_CLIP_INDEX, DOOR_02_INDEX, PROPS_DOOR_02_DOOR_BONE, 3.0f, @@ -80,7 +79,7 @@ void doorRender(void* data, struct DynamicRenderDataList* renderList, struct Ren skCalculateTransforms(&door->armature, armature); - dynamicRenderListAddData(renderList, typeDefinition->model, matrix, typeDefinition->materialIndex, &door->rigidBody.transform.position, armature); + dynamicRenderListAddData(renderList, door->armature.displayList, matrix, typeDefinition->materialIndex, &door->rigidBody.transform.position, armature); } void doorInit(struct Door* door, struct DoorDefinition* doorDefinition, struct World* world) { @@ -89,9 +88,10 @@ void doorInit(struct Door* door, struct DoorDefinition* doorDefinition, struct W collisionSceneAddDynamicObject(&door->collisionObject); struct DoorTypeDefinition* typeDefinition = &gDoorTypeDefinitions[doorDefinition->doorType]; + struct SKArmatureWithAnimations* armature = dynamicAssetAnimatedModel(typeDefinition->armatureIndex); - skArmatureInit(&door->armature, typeDefinition->armature); - skAnimatorInit(&door->animator, typeDefinition->armature->numberOfBones); + skArmatureInit(&door->armature, armature->armature); + skAnimatorInit(&door->animator, armature->armature->numberOfBones); door->rigidBody.transform.position = doorDefinition->location; door->rigidBody.transform.position.y += 1.0f; @@ -126,9 +126,9 @@ void doorUpdate(struct Door* door) { if (isOpen != signal) { if (signal) { - skAnimatorRunClip(&door->animator, typeDefinition->openClip, 0.0f, 0); + skAnimatorRunClip(&door->animator, dynamicAssetClip(typeDefinition->armatureIndex, typeDefinition->openClipIndex), 0.0f, 0); } else { - skAnimatorRunClip(&door->animator, typeDefinition->closeClip, 0.0f, 0); + skAnimatorRunClip(&door->animator, dynamicAssetClip(typeDefinition->armatureIndex, typeDefinition->closeClipIndex), 0.0f, 0); } soundPlayerPlay(soundsDoor, 3.0f, 0.5f, &door->rigidBody.transform.position, &gZeroVec); @@ -168,6 +168,6 @@ void doorCheckForOpenState(struct Door* door) { int signal = signalsRead(door->signalIndex); if (signal) { - skAnimatorRunClip(&door->animator, typeDefinition->openedClip, 0.0f, 0); + skAnimatorRunClip(&door->animator, dynamicAssetClip(typeDefinition->armatureIndex, typeDefinition->openedClipIndex), 0.0f, 0); } } \ No newline at end of file diff --git a/src/scene/door.h b/src/scene/door.h index 530233a..ba9bcd7 100644 --- a/src/scene/door.h +++ b/src/scene/door.h @@ -13,11 +13,10 @@ enum DoorFlags { }; struct DoorTypeDefinition { - struct SKArmatureDefinition* armature; - Gfx* model; - struct SKAnimationClip* openClip; - struct SKAnimationClip* closeClip; - struct SKAnimationClip* openedClip; + short armatureIndex; + short openClipIndex; + short closeClipIndex; + short openedClipIndex; short materialIndex; short colliderBoneIndex; float closeSpeed; diff --git a/src/scene/fizzler.c b/src/scene/fizzler.c index 548cf39..a6b84ff 100644 --- a/src/scene/fizzler.c +++ b/src/scene/fizzler.c @@ -4,9 +4,10 @@ #include "../graphics/render_scene.h" #include "../scene/dynamic_scene.h" #include "../physics/collision_scene.h" -#include "../models/models.h" +#include "../util/dynamic_asset_loader.h" + +#include "../../build/assets/models/dynamic_model_list.h" -#include "../build/assets/models/props/portal_cleanser.h" #include "../build/assets/materials/static.h" #define GFX_PER_PARTICLE(particleCount) ((particleCount) + (((particleCount) + 7) >> 3) + 1) @@ -40,7 +41,7 @@ void fizzlerRender(void* data, struct DynamicRenderDataList* renderList, struct transformToMatrixL(&fizzler->rigidBody.transform, matrix, SCENE_SCALE); - dynamicRenderListAddData(renderList, fizzler->modelGraphics, matrix, fizzler_material_index, &fizzler->rigidBody.transform.position, NULL); + dynamicRenderListAddData(renderList, fizzler->modelGraphics, matrix, PORTAL_CLEANSER_INDEX, &fizzler->rigidBody.transform.position, NULL); Mtx* sideMatrices = renderStateRequestMatrices(renderState, 2); @@ -52,12 +53,12 @@ void fizzlerRender(void* data, struct DynamicRenderDataList* renderList, struct gRelativeLeft.position.x = fizzler->collisionBox.sideLength.x; transformConcat(&fizzler->rigidBody.transform, &gRelativeLeft, &combinedTransform); transformToMatrixL(&combinedTransform, &sideMatrices[0], SCENE_SCALE); - dynamicRenderListAddData(renderList, props_portal_cleanser_model_gfx, &sideMatrices[0], PORTAL_CLEANSER_WALL_INDEX, &fizzler->rigidBody.transform.position, NULL); + dynamicRenderListAddData(renderList, dynamicAssetModel(PROPS_PORTAL_CLEANSER_DYNAMIC_MODEL), &sideMatrices[0], PORTAL_CLEANSER_WALL_INDEX, &fizzler->rigidBody.transform.position, NULL); gRelativeRight.position.x = -fizzler->collisionBox.sideLength.x; transformConcat(&fizzler->rigidBody.transform, &gRelativeRight, &combinedTransform); transformToMatrixL(&combinedTransform, &sideMatrices[1], SCENE_SCALE); - dynamicRenderListAddData(renderList, props_portal_cleanser_model_gfx, &sideMatrices[1], PORTAL_CLEANSER_WALL_INDEX, &fizzler->rigidBody.transform.position, NULL); + dynamicRenderListAddData(renderList, dynamicAssetModel(PROPS_PORTAL_CLEANSER_DYNAMIC_MODEL), &sideMatrices[1], PORTAL_CLEANSER_WALL_INDEX, &fizzler->rigidBody.transform.position, NULL); } void fizzlerSpawnParticle(struct Fizzler* fizzler, int particleIndex) { @@ -187,6 +188,8 @@ void fizzlerInit(struct Fizzler* fizzler, struct Transform* transform, float wid fizzler->dynamicId = dynamicSceneAdd(fizzler, fizzlerRender, &fizzler->rigidBody.transform.position, sqrtf(width * width + height * height) * 0.5f); dynamicSceneSetRoomFlags(fizzler->dynamicId, ROOM_FLAG_FROM_INDEX(room)); + + dynamicAssetModelPreload(PROPS_PORTAL_CLEANSER_DYNAMIC_MODEL); } void fizzlerUpdate(struct Fizzler* fizzler) { diff --git a/src/scene/pedestal.c b/src/scene/pedestal.c index 6e549d4..7990d21 100644 --- a/src/scene/pedestal.c +++ b/src/scene/pedestal.c @@ -2,11 +2,13 @@ #include "../scene/dynamic_scene.h" #include "../defs.h" -#include "../models/models.h" #include "../util/time.h" +#include "../util/dynamic_asset_loader.h" #include "../build/assets/materials/static.h" #include "../build/assets/models/pedestal.h" +#include "../../build/assets/models/dynamic_animated_model_list.h" +#include "../../build/assets/models/portal_gun/w_portalgun.h" struct Vector2 gMaxPedistalRotation; #define MAX_PEDISTAL_ROTATION_DEGREES_PER_SEC (M_PI / 3.0f) @@ -30,7 +32,8 @@ void pedestalRender(void* data, struct DynamicRenderDataList* renderList, struct skCalculateTransforms(&pedestal->armature, armature); - Gfx* attachments = skBuildAttachments(&pedestal->armature, (pedestal->flags & PedestalFlagsDown) ? NULL : &w_portal_gun_gfx, renderState); + Gfx* gunAttachment = portal_gun_w_portalgun_model_gfx; + Gfx* attachments = skBuildAttachments(&pedestal->armature, (pedestal->flags & PedestalFlagsDown) ? NULL : &gunAttachment, renderState); Gfx* objectRender = renderStateAllocateDLChunk(renderState, 4); Gfx* dl = objectRender; @@ -39,7 +42,7 @@ void pedestalRender(void* data, struct DynamicRenderDataList* renderList, struct gSPSegment(dl++, BONE_ATTACHMENT_SEGMENT, osVirtualToPhysical(attachments)); } gSPSegment(dl++, MATRIX_TRANSFORM_SEGMENT, osVirtualToPhysical(armature)); - gSPDisplayList(dl++, pedestal_model_gfx); + gSPDisplayList(dl++, pedestal->armature.displayList); gSPEndDisplayList(dl++); dynamicRenderListAddData( @@ -53,12 +56,14 @@ void pedestalRender(void* data, struct DynamicRenderDataList* renderList, struct } void pedestalInit(struct Pedestal* pedestal, struct PedestalDefinition* definition) { + struct SKArmatureWithAnimations* armature = dynamicAssetAnimatedModel(PEDESTAL_DYNAMIC_ANIMATED_MODEL); + transformInitIdentity(&pedestal->transform); pedestal->transform.position = definition->position; pedestal->roomIndex = definition->roomIndex; - skArmatureInit(&pedestal->armature, &pedestal_armature); + skArmatureInit(&pedestal->armature, armature->armature); skAnimatorInit(&pedestal->animator, PEDESTAL_DEFAULT_BONES_COUNT); @@ -112,7 +117,7 @@ void pedestalUpdate(struct Pedestal* pedestal) { void pedestalHide(struct Pedestal* pedestal) { soundPlayerPlay(soundsReleaseCube, 3.0f, 0.5f, &pedestal->transform.position, &gZeroVec); pedestal->flags |= PedestalFlagsDown; - skAnimatorRunClip(&pedestal->animator, &pedestal_Armature_Hide_clip, 0.0f, 0); + skAnimatorRunClip(&pedestal->animator, dynamicAssetClip(PEDESTAL_DYNAMIC_ANIMATED_MODEL, PEDESTAL_ARMATURE_HIDE_CLIP_INDEX), 0.0f, 0); } void pedestalPointAt(struct Pedestal* pedestal, struct Vector3* target) { @@ -121,5 +126,5 @@ void pedestalPointAt(struct Pedestal* pedestal, struct Vector3* target) { } void pedestalSetDown(struct Pedestal* pedestal) { - skAnimatorRunClip(&pedestal->animator, &pedestal_Armature_Hidden_clip, 0.0f, 0); + skAnimatorRunClip(&pedestal->animator, dynamicAssetClip(PEDESTAL_DYNAMIC_ANIMATED_MODEL, PEDESTAL_ARMATURE_HIDDEN_CLIP_INDEX), 0.0f, 0); } \ No newline at end of file diff --git a/src/scene/portal.c b/src/scene/portal.c index 06dbc70..3a3fb1c 100644 --- a/src/scene/portal.c +++ b/src/scene/portal.c @@ -1,6 +1,5 @@ #include "portal.h" -#include "models/models.h" #include "../graphics/screen_clipper.h" #include "../graphics/graphics.h" #include "../defs.h" diff --git a/src/scene/portal_gun.c b/src/scene/portal_gun.c index 04c0f79..973ca51 100644 --- a/src/scene/portal_gun.c +++ b/src/scene/portal_gun.c @@ -2,7 +2,8 @@ #include "../physics/collision_scene.h" #include "../physics/collision_cylinder.h" -#include "models/models.h" + +#include "../../build/assets/models/portal_gun/v_portalgun.h" #define PORTAL_GUN_RECOIL_TIME (0.18f) @@ -55,7 +56,7 @@ void portalGunRenderReal(struct PortalGun* portalGun, struct RenderState* render transformToMatrixL(&portalGun->rigidBody.transform, matrix, SCENE_SCALE); gSPMatrix(renderState->dl++, matrix, G_MTX_MODELVIEW | G_MTX_PUSH | G_MTX_MUL); - gSPDisplayList(renderState->dl++, v_portal_gun_gfx); + gSPDisplayList(renderState->dl++, portal_gun_v_portalgun_model_gfx); gSPPopMatrix(renderState->dl++, G_MTX_MODELVIEW); } } diff --git a/src/scene/scene.c b/src/scene/scene.c index 8705142..0733fd0 100644 --- a/src/scene/scene.c +++ b/src/scene/scene.c @@ -3,7 +3,6 @@ #include "defs.h" #include "graphics/graphics.h" -#include "models/models.h" #include "materials/shadow_caster.h" #include "materials/subject.h" #include "materials/light.h" diff --git a/src/scene/security_camera.c b/src/scene/security_camera.c index 2f4f0a3..8d55630 100644 --- a/src/scene/security_camera.c +++ b/src/scene/security_camera.c @@ -8,10 +8,12 @@ #include "../util/time.h" #include "../levels/cutscene_runner.h" #include "../decor/decor_object.h" +#include "../util/dynamic_asset_loader.h" -#include "../build/assets/models/props/security_camera.h" #include "../build/assets/materials/static.h" #include "../build/src/audio/clips.h" +#include "../../build/assets/models/dynamic_animated_model_list.h" +#include "../../build/assets/models/props/security_camera.h" struct CollisionBox gSecurityCameraCollisionBox = { {0.15, 0.3f, 0.35f} @@ -100,7 +102,7 @@ void securityCameraRender(void* data, struct DynamicRenderDataList* renderList, dynamicRenderListAddData( renderList, - decorBuildFizzleGfx(props_security_camera_model_gfx, securityCamera->fizzleTime, renderState), + decorBuildFizzleGfx(securityCamera->armature.displayList, securityCamera->fizzleTime, renderState), matrix, securityCamera->fizzleTime > 0.0f ? SECURITY_CAMERA_FIZZLED_INDEX : SECURITY_CAMERA_INDEX, &securityCamera->rigidBody.transform.position, @@ -109,11 +111,13 @@ void securityCameraRender(void* data, struct DynamicRenderDataList* renderList, } void securityCameraInit(struct SecurityCamera* securityCamera, struct SecurityCameraDefinition* definition) { + struct SKArmatureWithAnimations* armature = dynamicAssetAnimatedModel(PROPS_SECURITY_CAMERA_DYNAMIC_ANIMATED_MODEL); + collisionObjectInit(&securityCamera->collisionObject, &gSecurityCameraCollider, &securityCamera->rigidBody, 1.0f, COLLISION_LAYERS_TANGIBLE | COLLISION_LAYERS_FIZZLER); rigidBodyMarkKinematic(&securityCamera->rigidBody); collisionSceneAddDynamicObject(&securityCamera->collisionObject); - skArmatureInit(&securityCamera->armature, &props_security_camera_armature); + skArmatureInit(&securityCamera->armature, armature->armature); securityCamera->rigidBody.transform.position = definition->position; securityCamera->rigidBody.transform.rotation = definition->rotation; diff --git a/src/scene/switch.c b/src/scene/switch.c index 9605714..b30ef80 100644 --- a/src/scene/switch.c +++ b/src/scene/switch.c @@ -4,9 +4,11 @@ #include "../physics/collision_scene.h" #include "dynamic_scene.h" #include "signals.h" +#include "../util/dynamic_asset_loader.h" #include "../build/assets/models/props/switch001.h" #include "../build/assets/materials/static.h" +#include "../../build/assets/models/dynamic_animated_model_list.h" #include "../util/time.h" @@ -62,7 +64,7 @@ void switchRender(void* data, struct DynamicRenderDataList* renderList, struct R dynamicRenderListAddData( renderList, - props_switch001_model_gfx, + switchObj->armature.displayList, matrix, BUTTON_INDEX, &switchObj->rigidBody.transform.position, @@ -71,6 +73,8 @@ void switchRender(void* data, struct DynamicRenderDataList* renderList, struct R } void switchInit(struct Switch* switchObj, struct SwitchDefinition* definition) { + struct SKArmatureWithAnimations* armature = dynamicAssetAnimatedModel(PROPS_SWITCH001_DYNAMIC_ANIMATED_MODEL); + collisionObjectInit(&switchObj->collisionObject, &gSwitchCollider, &switchObj->rigidBody, 1.0f, COLLISION_LAYERS_TANGIBLE); rigidBodyMarkKinematic(&switchObj->rigidBody); collisionSceneAddDynamicObject(&switchObj->collisionObject); @@ -88,7 +92,7 @@ void switchInit(struct Switch* switchObj, struct SwitchDefinition* definition) { dynamicSceneSetRoomFlags(switchObj->dynamicId, ROOM_FLAG_FROM_INDEX(switchObj->rigidBody.currentRoom)); skAnimatorInit(&switchObj->animator, PROPS_SWITCH001_DEFAULT_BONES_COUNT); - skArmatureInit(&switchObj->armature, &props_switch001_armature); + skArmatureInit(&switchObj->armature, armature->armature); switchObj->duration = definition->duration; switchObj->flags = 0; @@ -105,7 +109,7 @@ void switchActivate(struct Switch* switchObj) { switchObj->flags |= SwitchFlagsDepressed; switchObj->timeLeft = switchObj->duration; signalsSend(switchObj->signalIndex); - skAnimatorRunClip(&switchObj->animator, &props_switch001_Armature_down_clip, 0.0f, 0); + skAnimatorRunClip(&switchObj->animator, dynamicAssetClip(PROPS_SWITCH001_DYNAMIC_ANIMATED_MODEL, PROPS_SWITCH001_ARMATURE_DOWN_CLIP_INDEX), 0.0f, 0); } void switchUpdate(struct Switch* switchObj) { @@ -120,7 +124,7 @@ void switchUpdate(struct Switch* switchObj) { if ((switchObj->flags & SwitchFlagsDepressed) != 0 && !skAnimatorIsRunning(&switchObj->animator)) { switchObj->flags &= ~SwitchFlagsDepressed; - skAnimatorRunClip(&switchObj->animator, &props_switch001_Armature_up_clip, 0.0f, 0); + skAnimatorRunClip(&switchObj->animator, dynamicAssetClip(PROPS_SWITCH001_DYNAMIC_ANIMATED_MODEL, PROPS_SWITCH001_ARMATURE_UP_CLIP_INDEX), 0.0f, 0); } return; diff --git a/src/util/dynamic_animated_asset_data.c b/src/util/dynamic_animated_asset_data.c new file mode 100644 index 0000000..5b73ba2 --- /dev/null +++ b/src/util/dynamic_animated_asset_data.c @@ -0,0 +1,2 @@ + +#include "../build/assets/models/dynamic_animated_model_list_data.h" \ No newline at end of file diff --git a/src/util/dynamic_asset_loader.c b/src/util/dynamic_asset_loader.c index 906ff78..ffd1341 100644 --- a/src/util/dynamic_asset_loader.c +++ b/src/util/dynamic_asset_loader.c @@ -3,24 +3,51 @@ #include "rom.h" #include "../build/assets/models/dynamic_model_list.h" +#include "../build/assets/models/dynamic_animated_model_list.h" extern struct DynamicAssetModel gDynamicModels[]; +extern struct DynamicAnimatedAssetModel gDynamicAnimatedModels[]; + Gfx* gLoadedModels[DYNAMIC_MODEL_COUNT]; u32 gModelPointerOffset[DYNAMIC_MODEL_COUNT]; +struct SKArmatureWithAnimations gLoadedAnimatedModels[DYNAMIC_ANIMATED_MODEL_COUNT]; + Gfx gBlankGfx[] = { gsSPEndDisplayList(), }; +struct SKArmatureDefinition gBlankArmature = { + gBlankGfx, + NULL, + NULL, + 0, + 0, +}; + +struct SKArmatureWithAnimations gBlankArmatureWithAnimations = { + &gBlankArmature, + NULL, + 0, +}; + +struct SKAnimationClip gBlankClip = { + 0, + 0, + NULL, + 0, +}; + void dynamicAssetsReset() { zeroMemory(gLoadedModels, sizeof(gLoadedModels)); + zeroMemory(gLoadedAnimatedModels, sizeof(gLoadedAnimatedModels)); } #define ADJUST_POINTER_POS(ptr, offset) (void*)((ptr) ? (char*)(ptr) + (offset) : 0) -Gfx* dynamicAssetFixModelPointers(Gfx* gfx, u32 pointerOffset, u32 segmentStart, u32 segmentLength) { +Gfx* dynamicAssetFixModelPointers(Gfx* gfx, u32 pointerOffset, u32 segmentStart, u32 segmentEnd) { // only adjust pointers that land within the segment - if ((u32)gfx < segmentStart || (u32)gfx >= segmentStart + segmentLength) { + if ((u32)gfx < segmentStart || (u32)gfx >= segmentEnd) { return gfx; } @@ -28,9 +55,8 @@ Gfx* dynamicAssetFixModelPointers(Gfx* gfx, u32 pointerOffset, u32 segmentStart, Gfx* result = gfx; - // prevent an infinite loop, although this G_ENDL - // isn't reached this will be bad anyway - Gfx* maxGfx = gfx + (segmentLength >> 3); + // prevent an infinite loop if G_ENDL isn't found + Gfx* maxGfx = ADJUST_POINTER_POS(segmentEnd, pointerOffset); while (gfx < maxGfx) { int commandType = _SHIFTR(gfx->words.w0, 24, 8); @@ -41,7 +67,7 @@ Gfx* dynamicAssetFixModelPointers(Gfx* gfx, u32 pointerOffset, u32 segmentStart, if (gfx->dma.par == G_DL_NOPUSH) { break; } - gfx->dma.addr = (u32)dynamicAssetFixModelPointers((Gfx*)gfx->dma.addr, pointerOffset, segmentStart, segmentLength); + gfx->dma.addr = (u32)dynamicAssetFixModelPointers((Gfx*)gfx->dma.addr, pointerOffset, segmentStart, segmentEnd); break; case G_VTX: gfx->dma.addr = (u32)ADJUST_POINTER_POS(gfx->dma.addr, pointerOffset); @@ -59,7 +85,35 @@ Gfx* dynamicAssetLoadModel(struct DynamicAssetModel* model, u32* pointerOffset) void* assetMemoryChunk = malloc(length); romCopy(model->addressStart, assetMemoryChunk, length); *pointerOffset = (u32)assetMemoryChunk - (u32)model->segmentStart; - return dynamicAssetFixModelPointers(model->model, *pointerOffset, (u32)model->segmentStart, length); + Gfx* result = dynamicAssetFixModelPointers(model->model, *pointerOffset, (u32)model->segmentStart, (u32)model->segmentStart + length); + + if (!result) { + free(assetMemoryChunk); + *pointerOffset = 0; + } + + return result; +} + +void dynamicAssetLoadAnimatedModel(struct DynamicAnimatedAssetModel* model, struct SKArmatureWithAnimations* result) { + u32 length = (u32)model->addressEnd - (u32)model->addressStart; + void* assetMemoryChunk = malloc(length); + romCopy(model->addressStart, assetMemoryChunk, length); + u32 pointerOffset = (u32)assetMemoryChunk - (u32)model->segmentStart; + + result->armature = ADJUST_POINTER_POS(model->armature, pointerOffset); + + result->armature->displayList = dynamicAssetFixModelPointers(result->armature->displayList, pointerOffset, (u32)model->segmentStart, (u32)model->segmentStart + length); + result->armature->pose = ADJUST_POINTER_POS(result->armature->pose, pointerOffset); + result->armature->boneParentIndex = ADJUST_POINTER_POS(result->armature->boneParentIndex, pointerOffset); + + result->clips = ADJUST_POINTER_POS(model->clips, pointerOffset); + + for (int i = 0; i < model->clipCount; i++) { + result->clips[i] = ADJUST_POINTER_POS(result->clips[i], pointerOffset); + } + + result->clipCount = model->clipCount; } void dynamicAssetModelPreload(int index) { @@ -84,4 +138,30 @@ void* dynamicAssetFixPointer(int index, void* ptr) { } return (void*)ADJUST_POINTER_POS(ptr, gModelPointerOffset[index]); +} + +struct SKArmatureWithAnimations* dynamicAssetAnimatedModel(int index) { + if (index < 0 || index >= DYNAMIC_ANIMATED_MODEL_COUNT) { + return &gBlankArmatureWithAnimations; + } + + if (!gLoadedAnimatedModels[index].armature) { + dynamicAssetLoadAnimatedModel(&gDynamicAnimatedModels[index], &gLoadedAnimatedModels[index]); + } + + if (!gLoadedAnimatedModels[index].armature) { + return &gBlankArmatureWithAnimations; + } + + return &gLoadedAnimatedModels[index]; +} + +struct SKAnimationClip* dynamicAssetClip(int index, int clipIndex) { + struct SKArmatureWithAnimations* armature = dynamicAssetAnimatedModel(index); + + if (clipIndex < 0 || clipIndex >= armature->clipCount) { + return &gBlankClip; + } + + return armature->clips[clipIndex]; } \ No newline at end of file diff --git a/src/util/dynamic_asset_loader.h b/src/util/dynamic_asset_loader.h index d529a0d..9cc10c8 100644 --- a/src/util/dynamic_asset_loader.h +++ b/src/util/dynamic_asset_loader.h @@ -3,6 +3,9 @@ #include +#include "../sk64/skelatool_armature.h" +#include "../sk64/skelatool_clip.h" + struct DynamicAssetModel { void* addressStart; void* addressEnd; @@ -10,6 +13,21 @@ struct DynamicAssetModel { Gfx* model; }; +struct DynamicAnimatedAssetModel { + void* addressStart; + void* addressEnd; + void* segmentStart; + struct SKArmatureDefinition* armature; + struct SKAnimationClip** clips; + short clipCount; +}; + +struct SKArmatureWithAnimations { + struct SKArmatureDefinition* armature; + struct SKAnimationClip** clips; + short clipCount; +}; + void dynamicAssetsReset(); void dynamicAssetModelPreload(int index); @@ -17,4 +35,7 @@ Gfx* dynamicAssetModel(int index); void* dynamicAssetFixPointer(int index, void* ptr); +struct SKArmatureWithAnimations* dynamicAssetAnimatedModel(int index); +struct SKAnimationClip* dynamicAssetClip(int index, int clipIndex); + #endif \ No newline at end of file diff --git a/tools/generate_dynamic_animated_model_list.js b/tools/generate_dynamic_animated_model_list.js new file mode 100644 index 0000000..5ab54da --- /dev/null +++ b/tools/generate_dynamic_animated_model_list.js @@ -0,0 +1,103 @@ +const fs = require('fs'); +const path = require('path'); + +function generateInclude(outputLocation, headerLocation) { + return `#include "${path.relative(path.dirname(outputLocation), headerLocation)}"` +} + +const InvalidTokenCharacter = /[^A-Za-z0-9_]/gim; + +function getSegmentName(headerLocation) { + const levelName = path.basename(headerLocation); + const noExtension = levelName.slice(0, levelName.length - path.extname(levelName).length); + + return noExtension.replace(InvalidTokenCharacter, '_'); +} + +function generateArmatureName(outputLocation, headerLocation) { + const relative = path.relative(path.dirname(outputLocation), headerLocation).slice(0, -2); + return relative.replace(InvalidTokenCharacter, '_') + '_armature'; +} + +function generateClipsName(outputLocation, headerLocation) { + const relative = path.relative(path.dirname(outputLocation), headerLocation).slice(0, -2); + return relative.replace(InvalidTokenCharacter, '_') + '_clips'; +} + +function generateClipCountName(outputLocation, headerLocation) { + const relative = path.relative(path.dirname(outputLocation), headerLocation).slice(0, -2); + return relative.replace(InvalidTokenCharacter, '_').toUpperCase() + '_CLIP_COUNT'; +} + +function generateDynamicModelName(outputLocation, headerLocation, index) { + const relative = path.relative(path.dirname(outputLocation), headerLocation).slice(0, -2); + return relative.replace(InvalidTokenCharacter, '_') + '_DYNAMIC_ANIMATED_MODEL'; +} + +function generateMetadata(outputLocation, headerLocation) { + const segmentName = getSegmentName(headerLocation); + return ` { + _${segmentName}_geoSegmentRomStart, + _${segmentName}_geoSegmentRomEnd, + _${segmentName}_geoSegmentStart, + &${generateArmatureName(outputLocation, headerLocation)}, + ${generateClipsName(outputLocation, headerLocation)}, + ${generateClipCountName(outputLocation, headerLocation)}, + },`; +} + +function generateExterns(headerLocation) { + const segmentName = getSegmentName(headerLocation); + return ` +extern char _${segmentName}_geoSegmentRomStart[]; +extern char _${segmentName}_geoSegmentRomEnd[]; +extern char _${segmentName}_geoSegmentStart[]; +`; + +} + +function generateModelList(outputLocation, headerLocations) { + return `struct DynamicAnimatedAssetModel gDynamicAnimatedModels[] = { +${headerLocations.map(headerLocation => generateMetadata(outputLocation, headerLocation)).join('\n')} +};` +} + +function generateMetadataDeclaration(outputLocation, headerLocation, index) { + const segmentName = getSegmentName(headerLocation); + return `#define ${generateDynamicModelName(outputLocation, headerLocation).toUpperCase()} ${index}`; +} + +function generateModelHeaderList(outputLocation, headerLocations) { + return headerLocations.map((headerLocation, index) => generateMetadataDeclaration(outputLocation, headerLocation, index)).join('\n'); +} + +function generateData(outputLocation, headerLocations) { + return `#ifndef __DYNAMIC_ANIMATED_MODEL_LIST_DATA_H__ +#define __DYNAMIC_ANIMATED_MODEL_LIST_DATA_H__ + +#include "util/dynamic_asset_loader.h" + +${headerLocations.map(headerLocation => generateInclude(outputLocation, headerLocation)).join('\n')} + +${headerLocations.map(generateExterns).join('\n')} + +${generateModelList(outputLocation, headerLocations)} + +#endif +`; +} + +function generateHeader(outputLocation, headerLocations) { + return `#ifndef __DYNAMIC_ANIMATED_MODEL_LIST_DEFINITION_H__ +#define __DYNAMIC_ANIMATED_MODEL_LIST_DEFINITION_H__ + +#define DYNAMIC_ANIMATED_MODEL_COUNT ${headerLocations.length} + +${generateModelHeaderList(outputLocation, headerLocations)} + +#endif +`; +} + +fs.writeFileSync(process.argv[2], generateHeader(process.argv[2], process.argv.slice(4))); +fs.writeFileSync(process.argv[3], generateData(process.argv[3], process.argv.slice(4))); \ No newline at end of file