Newer
Older
Import / projects / Gameloft / bne_lib / code / Utils / Attachments.cpp
#include "Attachments.h"

#include <Graphics/Object.h>
#include <Graphics/Model.h>

namespace bne {

  int32_t GetAttachmentPointIndex(CasualCore::Object* a_pObject, const char* a_attachPointName) {
    CasualCore::Renderable* renderable = a_pObject->GetRenderable();
    if (renderable != nullptr) {
      CasualCore::Model* model = renderable->GetModel();
      if ((model != nullptr) && (model->GetAnimationController() != nullptr)) {
        return model->GetAnimationController()->GetBoneIndex(a_attachPointName);
      }
    }
    return -1;
  }

  RKMatrix GetAttachmentPointLocalTransform(CasualCore::Object* a_pObject, int32_t a_attachIndex) {
    if (a_attachIndex >= 0) {
      CasualCore::Renderable* renderable = a_pObject->GetRenderable();
      if (renderable != nullptr) {
        CasualCore::Model* model = renderable->GetModel();
        if ((model != nullptr) && (model->GetAnimationController() != nullptr)) {
          return model->GetAnimationController()->GetBoneTransformLocal(a_attachIndex);
        }
      }
    }
    return RKMatrix::identity;
  }
} // namespace bne