Work on portal gun pedestal

This commit is contained in:
James Lambert 2022-08-07 18:57:12 -06:00
parent 18a879d7fa
commit 0a9071805b
14 changed files with 76 additions and 15 deletions

View file

@ -134,6 +134,17 @@ materials:
gDPSetCombineMode:
color: ["0", "0", "0", "PRIMITIVE"]
solid_white_two_sided:
gDPSetPrimColor:
r: 255
g: 255
b: 255
gSPGeometryMode:
set: [G_LIGHTING, G_SHADE]
clear: [G_CULL_BACK]
gDPSetCombineMode:
color: ["PRIMITIVE", "0", "SHADE", "0"]
solid_black_two_sided:
gDPSetPrimColor:
r: 32

Binary file not shown.

View file

@ -131,7 +131,7 @@ bool keyframeSortFn(const SKBoneKeyframeChain& a, const SKBoneKeyframeChain& b)
return (a.keyframe.usedAttributes & 0x7) < (b.keyframe.usedAttributes & 0x7);
}
void populateKeyframes(const aiAnimation& input, BoneHierarchy& bones, float modelScale, float timeScalar, std::vector<SKBoneKeyframeChain>& output, aiQuaternion rotation) {
void populateKeyframes(const aiAnimation& input, BoneHierarchy& bones, float fixedPointScale, float modelScale, const aiQuaternion& rotation, float timeScalar, std::vector<SKBoneKeyframeChain>& output) {
for (unsigned i = 0; i < input.mNumChannels; ++i) {
aiNodeAnim* node = input.mChannels[i];
@ -154,12 +154,12 @@ void populateKeyframes(const aiAnimation& input, BoneHierarchy& bones, float mod
aiVector3D origin = vectorKey->mValue;
if (!targetBone->GetParent()) {
origin = rotation.Rotate(origin);
origin = rotation.Rotate(origin) * modelScale;
}
keyframe.keyframe.attributeData.push_back((short)(origin.x * modelScale));
keyframe.keyframe.attributeData.push_back((short)(origin.y * modelScale));
keyframe.keyframe.attributeData.push_back((short)(origin.z * modelScale));
keyframe.keyframe.attributeData.push_back((short)(origin.x * fixedPointScale));
keyframe.keyframe.attributeData.push_back((short)(origin.y * fixedPointScale));
keyframe.keyframe.attributeData.push_back((short)(origin.z * fixedPointScale));
output.push_back(keyframe);
}
@ -364,11 +364,11 @@ void buildInitialState(std::map<unsigned short, SKBoneKeyframeChain*>& firstKeyF
combineChunk(keyframes, output);
}
bool translateAnimationToSK(const aiAnimation& input, struct SKAnimation& output, BoneHierarchy& bones, float modelScale, unsigned short targetTicksPerSecond, aiQuaternion rotation) {
bool translateAnimationToSK(const aiAnimation& input, struct SKAnimation& output, BoneHierarchy& bones, float fixedPointScale, float modelScale, const aiQuaternion& rotation, unsigned short targetTicksPerSecond) {
float timeScalar = (float)targetTicksPerSecond / (float)1000.0f;
std::vector<SKBoneKeyframeChain> keyframes;
populateKeyframes(input, bones, modelScale, timeScalar, keyframes, rotation);
populateKeyframes(input, bones, fixedPointScale, modelScale, rotation, timeScalar, keyframes);
if (keyframes.size() == 0) {
return false;

View file

@ -5,6 +5,6 @@
#include "Animation.h"
#include "BoneHierarchy.h"
bool translateAnimationToSK(const aiAnimation& input, struct SKAnimation& output, BoneHierarchy& bones, float modelScale, unsigned short targetTicksPerSecond, aiQuaternion rotate);
bool translateAnimationToSK(const aiAnimation& input, struct SKAnimation& output, BoneHierarchy& bones, float fixedPointScale, float modelScale, const aiQuaternion& rotation, unsigned short targetTicksPerSecond);
#endif

View file

@ -72,12 +72,12 @@ std::shared_ptr<NodeAnimationInfo> findNodesForWithAnimation(const aiScene* scen
return result;
}
std::vector<SKAnimationHeader> generateAnimationData(const aiScene* scene, BoneHierarchy& bones, CFileDefinition& fileDef, float modelScale, unsigned short targetTicksPerSecond, aiQuaternion rotate) {
std::vector<SKAnimationHeader> generateAnimationData(const aiScene* scene, BoneHierarchy& bones, CFileDefinition& fileDef, float fixedPointScale, float modelScale, const aiQuaternion& rotation, unsigned short targetTicksPerSecond) {
std::vector<SKAnimationHeader> animations;
for (unsigned i = 0; i < scene->mNumAnimations; ++i) {
SKAnimation animation;
if (translateAnimationToSK(*scene->mAnimations[i], animation, bones, modelScale, targetTicksPerSecond, rotate)) {
if (translateAnimationToSK(*scene->mAnimations[i], animation, bones, fixedPointScale, modelScale, rotation, targetTicksPerSecond)) {
std::string animationName = fileDef.GetUniqueName(scene->mAnimations[i]->mName.C_Str());
unsigned short firstChunkSize = formatAnimationChunks(animationName, animation.chunks, fileDef);
@ -104,8 +104,14 @@ void generateAnimationForScene(const aiScene* scene, CFileDefinition &fileDefini
std::transform(boneCountName.begin(), boneCountName.end(), boneCountName.begin(), ::toupper);
fileDefinition.AddMacro(boneCountName, std::to_string(bones.GetBoneCount()));
aiMatrix4x4 baseTransform(
aiVector3D(settings.mModelScale, settings.mModelScale, settings.mModelScale),
settings.mRotateModel,
aiVector3D(0, 0, 0)
);
std::string animationsName = fileDefinition.GetUniqueName("animations");
auto animations = generateAnimationData(scene, bones, fileDefinition, settings.mFixedPointScale * settings.mModelScale, settings.mTicksPerSecond, settings.mRotateModel);
auto animations = generateAnimationData(scene, bones, fileDefinition, settings.mFixedPointScale, settings.mModelScale, settings.mRotateModel, settings.mTicksPerSecond);
std::unique_ptr<StructureDataChunk> animationNameData(new StructureDataChunk());

View file

@ -11,7 +11,7 @@
std::shared_ptr<NodeAnimationInfo> findNodesForWithAnimation(const aiScene* scene, const std::vector<aiNode*>& usedNodes, float modelScale);
std::vector<SKAnimationHeader> generateAnimationData(const aiScene* scene, BoneHierarchy& bones, CFileDefinition& fileDef, float modelScale, unsigned short targetTicksPerSecond, aiQuaternion rotate);
std::vector<SKAnimationHeader> generateAnimationData(const aiScene* scene, BoneHierarchy& bones, CFileDefinition& fileDef, float fixedPointScale, float modelScale, const aiQuaternion& rotation, unsigned short targetTicksPerSecond);
void generateAnimationForScene(const aiScene* scene, CFileDefinition &fileDefinition, DisplayListSettings& settings);
#endif

View file

@ -163,6 +163,9 @@ std::unique_ptr<StructureDataChunk> generateCutsceneStep(CutsceneStep& step, int
return result;
}
} else if (step.command == "hide_pedestal") {
result->AddPrimitive<const char*>("CutsceneStepTypeHidePedestal");
return result;
}
result->AddPrimitive<const char*>("CutsceneStepTypeNoop");

View file

@ -95,6 +95,11 @@ void cutsceneRunnerStartStep(struct CutsceneRunner* runner) {
case CutsceneStepTypeStopCutscene:
cutsceneStop(&gCurrentLevel->cutscenes[step->cutscene.cutsceneIndex]);
break;
case CutsceneStepTypeHidePedestal:
for (unsigned i = 0; i < gScene.pedestalCount; ++i) {
pedestalHide(&gScene.pedestals[i]);
}
break;
default:
}
}

View file

@ -36,6 +36,7 @@ enum CutsceneStepType {
CutsceneStepTypeStartCutscene,
CutsceneStepTypeStopCutscene,
CutsceneStepTypeWaitForCutscene,
CutsceneStepTypeHidePedestal,
};
struct CutsceneStep {

View file

@ -14,6 +14,7 @@
#include "audio/soundplayer.h"
#include "audio/audio.h"
#include "scene/portal_surface.h"
#include "sk64/skelatool_defs.h"
#include "levels/levels.h"
@ -91,6 +92,8 @@ extern OSMesgQueue dmaMessageQ;
extern char _heapStart[];
extern char _animation_segmentSegmentRomStart[];
static void gameProc(void* arg) {
u8 schedulerMode = OS_VI_NTSC_LPF1;
@ -154,6 +157,8 @@ static void gameProc(void* arg) {
initAudio();
soundPlayerInit();
sceneInit(&gScene);
skSetSegmentLocation(CHARACTER_ANIMATION_SEGMENT, (unsigned)_animation_segmentSegmentRomStart);
skInitDataPool(gPiHandle);
while (1) {
OSScMsg *msg = NULL;
@ -187,6 +192,7 @@ static void gameProc(void* arg) {
}
controllersTriggerRead();
skReadMessages();
if (inputIgnore) {
--inputIgnore;
} else {

View file

@ -11,8 +11,6 @@
void pedestalRender(void* data, struct RenderScene* renderScene) {
struct Pedestal* pedestal = (struct Pedestal*)data;
quatAxisAngle(&gUp, gTimePassed, &pedestal->armature.boneTransforms[PEDESTAL_HOLDER_BONE].rotation);
Mtx* matrix = renderStateRequestMatrices(renderScene->renderState, 1);
transformToMatrixL(&pedestal->transform, matrix, SCENE_SCALE);
@ -20,7 +18,7 @@ void pedestalRender(void* data, struct RenderScene* renderScene) {
skCalculateTransforms(&pedestal->armature, armature);
Gfx* attachments = skBuildAttachments(&pedestal->armature, &w_portal_gun_gfx, renderScene->renderState);
Gfx* attachments = skBuildAttachments(&pedestal->armature, (pedestal->flags & PedstalFlagsDown) ? NULL : &w_portal_gun_gfx, renderScene->renderState);
Gfx* objectRender = renderStateAllocateDLChunk(renderScene->renderState, 4);
Gfx* dl = objectRender;
@ -57,5 +55,21 @@ void pedestalInit(struct Pedestal* pedestal, struct PedestalDefinition* definiti
PEDESTAL_ATTACHMENT_COUNT
);
skAnimatorInit(&pedestal->animator, PEDESTAL_DEFAULT_BONES_COUNT, NULL, NULL);
pedestal->dynamicId = dynamicSceneAdd(pedestal, pedestalRender, &pedestal->transform, 0.8f);
pedestal->flags = 0;
}
void pedestalUpdate(struct Pedestal* pedestal) {
skAnimatorUpdate(&pedestal->animator, pedestal->armature.boneTransforms, FIXED_DELTA_TIME);
quatAxisAngle(&gUp, gTimePassed, &pedestal->armature.boneTransforms[PEDESTAL_HOLDER_BONE].rotation);
}
void pedestalHide(struct Pedestal* pedestal) {
pedestal->flags |= PedstalFlagsDown;
skAnimatorRunClip(&pedestal->animator, &pedestal_animations[0], 0);
}

View file

@ -2,16 +2,27 @@
#define __SCENE_PEDESTAL_H__
#include "../sk64/skelatool_armature.h"
#include "../sk64/skelatool_animator.h"
#include "../levels/level_definition.h"
enum PedstalFlags {
PedstalFlagsDown = (1 << 0),
};
struct Pedestal {
struct Transform transform;
struct SKArmature armature;
struct SKAnimator animator;
short dynamicId;
short roomIndex;
short flags;
};
void pedestalInit(struct Pedestal* pedestal, struct PedestalDefinition* definition);
void pedestalUpdate(struct Pedestal* pedestal);
void pedestalHide(struct Pedestal* pedestal);
#endif

View file

@ -288,6 +288,10 @@ void sceneUpdate(struct Scene* scene) {
for (int i = 0; i < scene->elevatorCount; ++i) {
elevatorUpdate(&scene->elevators[i], &scene->player);
}
for (int i = 0; i < scene->pedestalCount; ++i) {
pedestalUpdate(&scene->pedestals[i]);
}
collisionSceneUpdateDynamics();