31. Locating files with agxIO::Environment

All resources (images, models, scripts) and runtime libraries (.dll/.so) are located using the singleton class agxIO::Environment. Currently there are two separate types of files:
  • Runtime files: .dll (WIN32), .so (Unix), .dylib (OSX)

  • Resource files: (.png, .obj, .png, .cfg, .agxPy, .agxScene, .schema, .agxKernel)

The path where these files can be found can be either controlled using environment variables as specified in Section 46, or programmatically using the agxIO::Environment class. This should be done before creating any other AGX object where file reading will be involved.

// Get a file path container to where runtime files are searched
agx::FilePathContainer& runtime_path =
  agxIO::Environment::instance()->getFilePath(
      agxIO::Environment::RUNTIME_PATH );

runtime_path.clear(); // Remove all previous settings
runtime_path.pushbackPath( "MyPath/plugins" );

// Try to find a file in the specified path
std::string filename = runtime_path.find( "plugin.dll" );

Same procedure can be done for RESOURCE_PATH to specify in what directories images, models, scripts and other non-runtime resources should be searched for.

// Get a file path container to where resource files are searched
agx::FilePathContainer& resource_path =
  agxIO::Environment::instance()->getFilePath(
      agxIO::Environment::RESOURCE_PATH );

resource_path.clear(); // Remove all previous settings
resource_path.pushbackPath( "MyPath/data/images;MyPath/data/models;" );
resource_path.pushbackPath( "MyPath/data/textures" );

// Try to find a file in the specified path
std::string filename = resource_path.find( "heightfield.png" );

In the windows version ‘;’ should be used to separate paths, and under UNIX the ‘:’ letter is used. Paths can be absolute or relative.