Unknown Node Loader

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Brainsaw
Posts: 1176
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Unknown Node Loader

Post by Brainsaw »

This is something that has proven to be handy: a loader for the unknown scene node. I use it in the BulletByte RoadCreator when a scene is loaded because the IrrOdeCar scene contains a lot of IrrOde scenenodes, and I didn't want to include those in the RoadCreator, so I made a snippet that claims to load these unknown nodes (but just creates an EmptySceneNode instead) so that I was able to see something in that scene. I hope this is of help for someone:

Code: Select all

 
class CUnknownNodeLoader : public scene::ISceneNodeFactory {
  protected:
    IrrlichtDevice *m_pDevice;
    scene::ISceneManager *m_pSmgr;
    core::array<core::stringc> m_aNodeNames;
 
  public:
    CUnknownNodeLoader(IrrlichtDevice *pDevice) {
      m_pDevice=pDevice;
      m_pSmgr=pDevice->getSceneManager();
    }
 
    virtual scene::ISceneNode *addSceneNode (const c8 *typeName, scene::ISceneNode *parent=0) {
      static bool s_bCreating=false;
 
      if (!s_bCreating) {
        s_bCreating=true;
        scene::ISceneNode *pRet=m_pSmgr->addSceneNode(typeName,parent!=NULL?parent:m_pSmgr->getRootSceneNode());
        s_bCreating=false;
 
        if (pRet==NULL) {
          pRet=m_pSmgr->addEmptySceneNode(parent!=NULL?parent:m_pSmgr->getRootSceneNode(),-1);
          pRet->setName(typeName);
 
          bool bAdd=true;
          for (u32 i=0; i<m_aNodeNames.size(); i++) {
            if (!strcmp(m_aNodeNames[i].c_str(),typeName)) bAdd=false;
          }
 
          if (bAdd) {
            printf("**** new type: \"%s\"\n",typeName);
            m_aNodeNames.push_back(typeName);
          }
          return pRet;
        }
      }
 
      return NULL;
    }
 
    virtual scene::ISceneNode *addSceneNode (scene::ESCENE_NODE_TYPE type, scene::ISceneNode *parent=0) {
      return addSceneNode("xxxxyyyyzzzz",parent);
    }
 
    virtual u32 getCreatableSceneNodeTypeCount () const {
      return m_aNodeNames.size();
    }
 
    virtual scene::ESCENE_NODE_TYPE getCreateableSceneNodeType (u32 idx) const {
      return scene::ESNT_UNKNOWN;
    }
 
    virtual const c8 *getCreateableSceneNodeTypeName (scene::ESCENE_NODE_TYPE type) const {
      static c8 s_sTemp[0xFF];
      sprintf(s_sTemp,"Node_%i",type);
      return s_sTemp;
    }
 
    virtual const c8 *getCreateableSceneNodeTypeName (u32 idx) const {
      return m_aNodeNames[idx].c_str();
    }
};
 
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Post Reply