Пример #1
0
EntityWrapper EntityManagerWrapper::createEntityF(const std::string& entity_name)
{
    luabridge::LuaRef handle = global.scriptManager.getGlobal(entity_name);
    EntityWrapper entity = createEntity();
    entity.setProperty("tableName", entity_name);
    entity.setProperty("type", handle["type"]);

    if (handle["GraphicsComponent"])
        m_addGraphicsComponent(entity.getEntity(), handle["GraphicsComponent"]);

    if (handle["PhysicsComponent"])
        m_addPhysicsComponent(entity.getEntity(), handle["PhysicsComponent"]);

    if (handle["AnimationComponent"])
        m_addAnimationComponent(entity.getEntity(), handle["AnimationComponent"]);

    return entity;
}
Пример #2
0
  bool AnimationGroup::initialize(const DataProxy& dict, Ogre::SceneManager* sceneManager)
  {
    for(auto& pair : dict)
    {
      std::string fullId = pair.second.as<std::string>();

      std::vector<std::string> id = split(fullId, '.');

      std::string entityID;
      mAnimations[pair.first] = Animation();
      if(id.size() < 2) {
        LOG(TRACE) << "Added empty animation to group " << pair.first;
        continue;
      }

      SceneNodeWrapper* containerNode = mRenderComponent->getRoot();
      int i;
      for(i = 0; i < id.size() - 2; i++) {
        containerNode = containerNode->getChildOfType<SceneNodeWrapper>(id[i]);
        if(containerNode == 0) {
          break;
        }
      }

      if(containerNode == 0) {
        LOG(TRACE) << "Failed to find node with name " << id[i];
        continue;
      }

      EntityWrapper* w = containerNode->getChildOfType<EntityWrapper>(id[i]);

      OgreV1::Entity* e = w->getEntity();

      // no entity was found with such id
      if(e == 0)
      {
        LOG(ERROR) << "Failed to add animation: entity with id \"" << id[0] << "\" not found in scene manager";
        return false;
      }

      // no such state
      if(!e->hasAnimationState(id[1]))
      {
        LOG(ERROR) << "Failed to add animation: animation state with id \"" << id[1] << "\" not found in entity";
        return false;
      }

      LOG(TRACE) << "Adding animation " << fullId << " to group " << pair.first;
      mAnimations[pair.first].initialize(e->getAnimationState(id[1]));
    }
    return true;
  }