C++ Script II

  1. CreateVRMLFromString
  2. Reference Counter
This tutorial explains how to use the createVRMLFromString interface of the browser object. (sources: cppscript2.cpp, cppscript2.wrl. To view this example load the cppscript2.wrl file with the glutCyberle VRML-Browser. The script can be compiled as explained in the cppscript tutorial.

CreateVRMLFromString

This function is accessed through the browser object that is stored in the Params struture.
MFNode* erg = pParams->browser->CreateVrmlFromString(str.c_str());
This function returns an MFNode field, which is allocated by the browser. Therefore the browser also must deallocate it.
pParams->browser->Dealloc(erg);

Reference Counter

Important to notice is that if you want to store a node reference for later use, you have to inc the reference counter of the SFNode pointer.
//Save the node reference to be able to remove it later
const SFNode* node = erg->at(0);
pParams->browser->IncNodeRefCount(node);
DATA(nodes).push_back(node);
Similar, if you don't need the reference to the SFNode object anymore, dec the reference counter.
pParams->browser->DecNodeRefCount(DATA(nodes)[i]);