
This file was automatically generated from diguyOsgExtGraphicsFile.cpp. Do not edit this file directly; the changes will be lost.
| Introduction |
Files are the high-level representation of loaded geometry files. The geometry files contain parts of visible geometry that will be attached to shapes.
The class diguyOsgExtGraphicsFile is an example of a diguyGraphicsFile subclass for a retained mode renderer using an external loader. The example subclass shows how to use the accessors of the diguyGraphicsFile class and which virtual functions should be overridden for a retained mode renderer such as Open Scene Graph.
| Header files and forward declarations |
#include "diguyOsgExtGraphicsFile.h" #include <string> #include <stdlib.h> #include <string.h> #include <libbdilog.h> #include <osg/Geode> #include <osg/Notify> #include <osg/ShapeDrawable> #include <osgDB/ReadFile> #include <osgDB/Registry> int diguyOsgExtGraphicsFile::s_osgdb_path_modified = 0;
| Constructor |
Initialize data members of the class to a known state.
Base class data will not be fully initialized until the Build Stage is done, so base class accessors should not be called here.
diguyOsgExtGraphicsFile::diguyOsgExtGraphicsFile(void* internal_data) : diguyGraphicsFile(internal_data) { /* * Add some DI-Guy directories to the list of directories OSG will * search for files. */ if (!s_osgdb_path_modified) { char* diguy_env_var = getenv("DIGUY"); char* bdigeometry_env_var = getenv("BDIGEOMETRY"); char* diguy_geometry_env_var = getenv("DIGUY_GEOMETRY"); char sprintf_temp[1024]; /* * Get the current data file path. */ osgDB::FilePathList list = osgDB::Registry::instance()->getDataFilePathList(); /* * Add to it. */ sprintf(sprintf_temp, "%s", diguy_geometry_env_var); list.push_back(std::string(sprintf_temp)); sprintf(sprintf_temp, "%s/flt", diguy_geometry_env_var); list.push_back(std::string(sprintf_temp)); sprintf(sprintf_temp, "%s", bdigeometry_env_var); list.push_back(std::string(sprintf_temp)); sprintf(sprintf_temp, "%s/flt", bdigeometry_env_var); list.push_back(std::string(sprintf_temp)); sprintf(sprintf_temp, "%s/geometry", diguy_env_var); list.push_back(std::string(sprintf_temp)); sprintf(sprintf_temp, "%s/geometry/flt", diguy_env_var); list.push_back(std::string(sprintf_temp)); osgDB::Registry::instance()->setDataFilePathList(list); s_osgdb_path_modified = 1; } }
| load |
Build Stage
Description:
Override of diguyGraphicsFile::load().
The load() function should load the specified file, and be ready to provide pointers to parts from the file.
This implementation uses an OSG plugin to load .flt files.
int diguyOsgExtGraphicsFile::load(const char* filename, const char* extension) { /* * Don't try to load anything but a ".flt" file. */ if (strcmp(extension, "flt")) return -1; /* * Read the flt file. */ osg::NotifySeverity original_notify_level = osg::getNotifyLevel(); osg::setNotifyLevel(osg::WARN); { m_file_root = osgDB::readNodeFile(filename); } osg::setNotifyLevel(original_notify_level); if (!m_file_root) { bdi_log_printf(BDI_LOG_WARN, "WARNING: Failed to load geometry file '%s'.\n", filename); return -1; } bdi_log_printf(BDI_LOG_INFO, "INFO: Loaded geometry file '%s'.\n", filename); return 0; }
| unload |
Unbuild Stage
Description:
Override of diguyGraphicsFile::load().
The unload() function should undo the actions of the load() function. Whatever objects were created in load() should be deleted here.
This implementation dereferences the root node of the loaded file, potentially deleting it.
int diguyOsgExtGraphicsFile::unload() { m_file_root = NULL; return 0; }
| find_part |
Build Stage
Description:
Override of diguyGraphicsFile::find_part().
The find_part() function should find and return a geometry part from this file. This part will be attached to a shape.
This implementation looks for a sub-node with the given name in the hierarchy returned by the load() function.
void* diguyOsgExtGraphicsFile::find_part(const char* part_name) { if (!m_file_root) return NULL; osg::Node* part = NULL; if (strlen(part_name) == 0) { /* * Empty part name? Return entire hierarchy. */ part = m_file_root; if (!part) { bdi_log_printf(BDI_LOG_DEBUG, "DEBUG: Root-node part not found in geometry file '%s'.\n", get_filename()); } } else { /* * Use the utility function recursive_find_part() to find a node * in the hierarchy with the given name. */ part = recursive_find_part(part_name, m_file_root); if (!part) { bdi_log_printf(BDI_LOG_DEBUG, "DEBUG: Part '%s' not found in geometry file '%s'.\n", part_name, get_filename()); } } return (void *) part; }
| recursive_find_part |
Protected utility function for finding a sub-node with the given name.
So far I haven't found an OSG function that recursively searches the hierarchy for a node with a particular name, so I've written my own version here.
osg::Node* diguyOsgExtGraphicsFile::recursive_find_part(const char* part_name, osg::Node* parent) { /* * See if parent itself is the desired part. */ std::string parent_name = parent->getName(); if (parent_name == part_name) return parent; /* * Check to see if parent is a group. If not, part not found. */ osg::Group* parent_as_group = parent->asGroup(); if (!parent_as_group) return NULL; /* * Recursively check group children. */ unsigned int child_index; for (child_index=0; child_index<parent_as_group->getNumChildren(); child_index++) { osg::Node* child = parent_as_group->getChild(child_index); if (child) { osg::Node* part = recursive_find_part(part_name, child); if (part) return part; } } return NULL; }
| Create function definition |
Create and return an object of a subclass of diguyGraphicsFile. This function will be called whenever DI-Guy requires a file object.
diguyGraphicsFile* diguyOsgExtGraphicsFile_create_func(void* internal_data) { return new diguyOsgExtGraphicsFile(internal_data); }
ALL RIGHTS RESERVED.
These coded instructions, statements, and computer programs contain unpublished proprietary information of Boston Dynamics and are protected by Copyright Laws of the United States. They may not be used, duplicated, or disclosed in any form, in whole or in part, without the prior written consent from Boston Dynamics.
RESTRICTED RIGHTS LEGEND
Use, duplication, or disclosure by the government is subject to restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Sofware clause at DFARS 252.227-7013 and/or in similar or successor clauses in the FAR, or the DOD or NASA FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19, as applicable. Unpublished-rights reserved under the Copyright Laws of the United States.
Contractor/Manufacturer is:
Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.