src/engine.cpp
/* ********************************* O B J E C T ********************************* */
O B J E C T
O B J E C T
bool workshop::object_handle::resource_set(engine* e)
{
  assert(resource_ == nullptr);
  assert(e);
  workshop::engine::irr_runtime* r = e->runtime();
  assert(r->smgr);
  assert(r->driver);
  switch (type_) {
    case type_faerie: {
      irr::scene::IAnimatedMesh* mesh = r->smgr->getMesh((e->irrlicht_path() + "/media/faerie.md2").c_str());
      if (!mesh)
        return false;
      resource_ = r->smgr->addAnimatedMeshSceneNode(mesh, 0, id_flag_is_pickable | id_flag_is_highlightable);
      resource_->setScale(irr::core::vector3df(1.6f));
      resource_->setMD2Animation(irr::scene::EMAT_POINT);
      resource_->setAnimationSpeed(20.f);
      irr::video::ITexture* tex = r->driver->getTexture((e->irrlicht_path() + "/media/faerie2.bmp").c_str());
      if (!tex) {
        resource_ = nullptr;
        return false;
      }
      irr::video::SMaterial material;
      material.setTexture(0, tex);
      material.Lighting = true;
      material.NormalizeNormals = true;
      resource_->getMaterial(0) = material;
      resource_->setName(name_->c_str());
    } break;
    case type_ninja: {
      irr::scene::IAnimatedMesh* mesh = r->smgr->getMesh((e->irrlicht_path() + "/media/ninja.b3d").c_str());
      if (!mesh)
        return false;
      resource_ = r->smgr->addAnimatedMeshSceneNode(mesh, 0, id_flag_is_pickable | id_flag_is_highlightable);
      resource_->setScale(irr::core::vector3df(10));
      resource_->setAnimationSpeed(8.f);
      resource_->getMaterial(0).NormalizeNormals = true;
      resource_->getMaterial(0).Lighting = true;
      resource_->setName(name_->c_str());
    } break;
    case type_dwarf: {
      irr::scene::IAnimatedMesh* mesh = r->smgr->getMesh((e->irrlicht_path() + "/media/dwarf.x").c_str());
      if (!mesh)
        return false;
      resource_ = r->smgr->addAnimatedMeshSceneNode(mesh, 0, id_flag_is_pickable | id_flag_is_highlightable);
      resource_->setAnimationSpeed(20.f);
      resource_->getMaterial(0).Lighting = true;
      resource_->setName(name_->c_str());
    } break;
    case type_yodan: {
      irr::scene::IAnimatedMesh* mesh = r->smgr->getMesh((e->irrlicht_path() + "/media/yodan.mdl").c_str());
      if (!mesh)
        return false;
      resource_ = r->smgr->addAnimatedMeshSceneNode(mesh, 0, id_flag_is_pickable | id_flag_is_highlightable);
      resource_->setScale(irr::core::vector3df(0.8f));
      resource_->getMaterial(0).Lighting = true;
      resource_->setAnimationSpeed(20.f);
      resource_->setName(name_->c_str());
    } break;
    case type_unknown:
      break;
    default:
      assert(0);
  }
  return true;
}
bool workshop :: object_handle :: resource_set ( engine * e ) { assert ( resource_ == nullptr ) ; assert ( e ) ; workshop :: engine :: irr_runtime * r = e -> runtime ( ) ; assert ( r -> smgr ) ; assert ( r -> driver ) ; switch ( type_ ) { case type_faerie : { irr :: scene :: IAnimatedMesh * mesh = r -> smgr -> getMesh ( ( e -> irrlicht_path ( ) + " " ) . c_str ( ) ) ; if ( ! mesh ) return false ; resource_ = r -> smgr -> addAnimatedMeshSceneNode ( mesh , 0 , id_flag_is_pickable | id_flag_is_highlightable ) ; resource_ -> setScale ( irr :: core :: vector3df ( 1.6f ) ) ; resource_ -> setMD2Animation ( irr :: scene :: EMAT_POINT ) ; resource_ -> setAnimationSpeed ( 20.f ) ; irr :: video :: ITexture * tex = r -> driver -> getTexture ( ( e -> irrlicht_path ( ) + " " ) . c_str ( ) ) ; if ( ! tex ) { resource_ = nullptr ; return false ; } irr :: video :: SMaterial material ; material . setTexture ( 0 , tex ) ; material . Lighting = true ; material . NormalizeNormals = true ; resource_ -> getMaterial ( 0 ) = material ; resource_ -> setName ( name_ -> c_str ( ) ) ; } break ; case type_ninja : { irr :: scene :: IAnimatedMesh * mesh = r -> smgr -> getMesh ( ( e -> irrlicht_path ( ) + " " ) . c_str ( ) ) ; if ( ! mesh ) return false ; resource_ = r -> smgr -> addAnimatedMeshSceneNode ( mesh , 0 , id_flag_is_pickable | id_flag_is_highlightable ) ; resource_ -> setScale ( irr :: core :: vector3df ( 10 ) ) ; resource_ -> setAnimationSpeed ( 8.f ) ; resource_ -> getMaterial ( 0 ) . NormalizeNormals = true ; resource_ -> getMaterial ( 0 ) . Lighting = true ; resource_ -> setName ( name_ -> c_str ( ) ) ; } break ; case type_dwarf : { irr :: scene :: IAnimatedMesh * mesh = r -> smgr -> getMesh ( ( e -> irrlicht_path ( ) + " " ) . c_str ( ) ) ; if ( ! mesh ) return false ; resource_ = r -> smgr -> addAnimatedMeshSceneNode ( mesh , 0 , id_flag_is_pickable | id_flag_is_highlightable ) ; resource_ -> setAnimationSpeed ( 20.f ) ; resource_ -> getMaterial ( 0 ) . Lighting = true ; resource_ -> setName ( name_ -> c_str ( ) ) ; } break ; case type_yodan : { irr :: scene :: IAnimatedMesh * mesh = r -> smgr -> getMesh ( ( e -> irrlicht_path ( ) + " " ) . c_str ( ) ) ; if ( ! mesh ) return false ; resource_ = r -> smgr -> addAnimatedMeshSceneNode ( mesh , 0 , id_flag_is_pickable | id_flag_is_highlightable ) ; resource_ -> setScale ( irr :: core :: vector3df ( 0.8f ) ) ; resource_ -> getMaterial ( 0 ) . Lighting = true ; resource_ -> setAnimationSpeed ( 20.f ) ; resource_ -> setName ( name_ -> c_str ( ) ) ; } break ; case type_unknown : break ; default : assert ( 0 ) ; } return true ; }
O B J E C T
O B J E C T
// add an MD2 node, which uses vertex-based animation // this B3D file uses skinned skeletal animation // this X file uses skeletal animation, but without skinning // this mdl file uses skinned skeletal animation // nothing to do