Clone element trough scripting

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
QuantumLeap
Posts: 38
Joined: Mon Sep 25, 2006 6:31 pm
Location: San Francisco, California

Clone element trough scripting

Post by QuantumLeap »

I need to replicate a certain node many times (maybe hundreds) and place it on the scene in positions and rotations determined by a function.

It would be great to have a scripting function like

Code: Select all

cloneNodeFromName("NodeName")  
for that effect.

Is there another way to do it at this moment?
It's easier to curse a candle than light the darkness
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Not that I know of. You should be able to do it yourself in C++. You could load you .irr file, run a little bit of code on it and then write out a new .irr file with the changes. You could then load it up in irrEdit to make sure it turned out like you wanted. The following _might_ work.

Code: Select all

ISceneNode*
ISceneNode_clone(ISceneNode* node, ISceneNode* parent, IrrlichtDevice* device)
{
  // smgr needed to access node factory
  ISceneManager* smgr = device->getSceneManager();

  // file system needed to create new attributes
  IFileSystem* fs = device->getFileSystem();

  // video driver needed to load textures
  IVideoDriver* driver = device->getVideoDriver();

  if (!parent)
    parent = smgr->getRootSceneNode();

  // create a new node instance of the correct type
  s32 f;
  for (f = 0; f < smgr->getRegisteredSceneNodeFactoryCount(); ++f)
  {
    ISceneNodeFactory* factory = smgr->getSceneNodeFactory(f);
    if (!factory)
      continue; // just in case
  
    ISceneNode* clone = factory->addSceneNode(node->getType(), parent);
    if (clone)
    {
      io::IAttributes* attribs = fs->createEmptyAttributes(driver);

      // serialize attributes from existing node
      node->serializeAttributes(attribs);

      // and use them to fill our current node
      clone->deserializeAttributes(attribs);

      // clean up our attribs
      attribs->drop();

      // return cloned node
      return clone;
    }
  }

  return 0;
}
Travis
QuantumLeap
Posts: 38
Joined: Mon Sep 25, 2006 6:31 pm
Location: San Francisco, California

Post by QuantumLeap »

You could load you .irr file, run a little bit of code on it and then write out a new .irr file with the changes
OK, I'm perfectly capable of reproducing a node within irrlicht and have it displayed. but how to save a .irr file from there?
It's easier to curse a candle than light the darkness
QuantumLeap
Posts: 38
Joined: Mon Sep 25, 2006 6:31 pm
Location: San Francisco, California

Post by QuantumLeap »

Vitek, please ignore my last post. I just had a look at http://irrlicht.sourceforge.net/docu/cl ... r.html#a64

Many thanks, problem (kind of) solved!
It's easier to curse a candle than light the darkness
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You may have no problems trying to figure out how to copy a scene node of arbitrary type, but a lot of guys aren't quite as sharp. Someone else will want to know how to do it, and hopefully they'll find the code above to be useful...

I'm glad you got it working. To bad that IrrEdit doesn't support extension by plug-ins.

Travis
Post Reply