@@ -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