Time for action—loading a model at runtime

We are going to demonstrate the loading of a model file by using the osg::ProxyNode. The proxy will record the filename of the original model, and defer loading it until the viewer is running and sending corresponding requests.

  1. Include the necessary headers:
    #include <osg/ProxyNode>
    #include <osgViewer/Viewer>
    
  2. Instead of just loading model files as child nodes, we will set a filename to the specified index of children. This is similar to the insertChild() method, which puts a node into the specified position of the children list, but the list will not be filled until the dynamic loading process has finished.
    osg::ref_ptr<osg::ProxyNode> root = new osg::ProxyNode;
    root->setFileName( 0, "cow.osg" );
    
  3. Start ...

Get OpenSceneGraph 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.