Skip to content

Commit 6d80dbd

Browse files
Add quaternion animation support and animator update stub
Introduces QuatAnimationFrame for quaternion-based animation frames and updates the animation loading logic to handle rotation channels as quaternions. Also adds a stub for the GfxAnimator::update() method and corrects the animations vector naming in GfxModel.
1 parent bd4c0ea commit 6d80dbd

2 files changed

Lines changed: 69 additions & 8 deletions

File tree

include/borealis/gfx/model.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ namespace brl
126126
glm::vec3 value;
127127
};
128128

129+
struct QuatAnimationFrame : AnimationFrame {
130+
glm::quat value;
131+
};
132+
129133
struct Channel {
130134
int boneIndex;
131135
ChannelInterpolation interpolation;
@@ -136,7 +140,7 @@ namespace brl
136140

137141
std::string name;
138142

139-
143+
std::vector<Channel> channels;
140144

141145
};
142146

@@ -147,7 +151,7 @@ namespace brl
147151
std::vector<GfxMaterialDescription*> materialDescriptions;
148152
std::vector<GfxMaterial*> materials;
149153
std::vector<GfxSkin*> skins;
150-
std::vector<GfxAnimation*> animation;
154+
std::vector<GfxAnimation*> animations;
151155

152156
static GfxModel* loadModel(std::string path);
153157

@@ -251,6 +255,10 @@ namespace brl
251255

252256
GfxAnimation* animation;
253257

258+
GfxAnimator();
259+
260+
void update() override;
261+
254262
private:
255263
GfxModelEntity* model= nullptr;
256264
};

src/brl/gfx/model.cpp

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,15 +606,26 @@ brl::GfxModel::GfxModel(std::string path)
606606

607607
tinygltf::AnimationSampler sampler = anim.samplers[channel.sampler];
608608

609+
int targetSkin = -1;
609610
int targetBone = -1;
610611

611-
for (int i = 0; i <model.skins[0].joints.size(); i++) {
612-
if (model.skins[0].joints[i] == channel.target_node){
613-
targetBone = i;
612+
for (int j = 0; j < model.skins.size(); j++)
613+
{
614+
for (int i = 0; i <model.skins[j].joints.size(); i++) {
615+
if (model.skins[j].joints[i] == channel.target_node) {
616+
targetBone = i;
617+
targetSkin = j;
618+
break;
619+
}
620+
}
621+
622+
if (targetBone != -1) {
623+
break;
614624
}
615625
}
626+
616627

617-
if (targetBone == -1)
628+
if (targetBone == -1 || targetSkin == -1)
618629
continue;
619630

620631
if (sampler.interpolation == "LINEAR")
@@ -623,8 +634,42 @@ brl::GfxModel::GfxModel(std::string path)
623634
animChannel.interpolation = GfxAnimation::STEP;
624635
if (sampler.interpolation == "CUBICSPLINE")
625636
animChannel.interpolation = GfxAnimation::CUBICSPLINE;
626-
627-
637+
638+
const tinygltf::Accessor& inputAccessor = model.accessors[sampler.input];
639+
const tinygltf::Accessor& outputAccessor = model.accessors[sampler.output];
640+
641+
const tinygltf::BufferView& input_bufferView = model.bufferViews[inputAccessor.bufferView];
642+
const tinygltf::Buffer& input_buffer = model.buffers[input_bufferView.buffer];
643+
644+
const tinygltf::BufferView& output_bufferView = model.bufferViews[outputAccessor.bufferView];
645+
const tinygltf::Buffer& output_buffer = model.buffers[output_bufferView.buffer];
646+
647+
648+
auto times = reinterpret_cast<const float*>(&input_buffer.data[input_bufferView.byteOffset + inputAccessor.byteOffset]);
649+
int frameCount = inputAccessor.count;
650+
651+
auto values = reinterpret_cast<const float*>(&output_buffer.data[output_bufferView.byteOffset + outputAccessor.byteOffset]);
652+
653+
654+
if (animChannel.type == GfxAnimation::TRANSLATION || animChannel.type == GfxAnimation::SCALE) {
655+
656+
for (std::size_t i = 0; i < frameCount; ++i) {
657+
float frame = times[i];
658+
glm::vec3 value = {values[i * 3 + 0], values[i * 3 + 1], values[i * 3 + 2]};
659+
660+
animChannel.frames.push_back(GfxAnimation::Vec3AnimationFrame{frame,value});
661+
}
662+
} else if (animChannel.type == GfxAnimation::ROTATION)
663+
{
664+
for (std::size_t i = 0; i < frameCount; ++i) {
665+
float frame = times[i];
666+
glm::quat value = {values[i * 4 + 0], values[i * 4 + 1], values[i * 4 + 2], values[i*4+3]};
667+
668+
animChannel.frames.push_back(GfxAnimation::QuatAnimationFrame{frame,value});
669+
}
670+
}
671+
672+
animation->channels.push_back(animChannel);
628673
}
629674

630675
animations.push_back(animation);
@@ -824,3 +869,11 @@ void brl::GfxSkinnedMeshRenderer::lateUpdate()
824869
GfxEngine::instance->insertCall(materials[i], subMesh->buffer, calculateTransform(), overrides, instancingID);
825870
}
826871
}
872+
873+
void brl::GfxAnimator::update()
874+
{
875+
const auto& skeleton = model->skeletons[0];
876+
877+
878+
879+
}

0 commit comments

Comments
 (0)