Skip to content

Commit

Permalink
Easier importer and resources interface
Browse files Browse the repository at this point in the history
Updated readme example with new interface
  • Loading branch information
BearishSun committed Jul 8, 2014
1 parent fdc6548 commit becb8d0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
9 changes: 9 additions & 0 deletions BansheeCore/Include/BsImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ namespace BansheeEngine
*/
HResource import(const Path& inputFilePath, ConstImportOptionsPtr importOptions = nullptr);

/**
* @copydoc import
*/
template <class T>
ResourceHandle<T> import(const Path& inputFilePath, ConstImportOptionsPtr importOptions = nullptr)
{
return static_resource_cast<T>(import(inputFilePath, importOptions));
}

/**
* @brief Imports a resource and replaces the contents of the provided existing resource with new imported data.
*
Expand Down
22 changes: 20 additions & 2 deletions BansheeCore/Include/BsResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ namespace BansheeEngine
*/
HResource load(const Path& filePath);

/**
* @copydoc load
*/
template <class T>
ResourceHandle<T> load(const Path& filePath)
{
return static_resource_cast<T>(load(filePath));
}

/**
* @brief Loads the resource asynchronously. Initially returned resource handle will be invalid
* until resource loading is done.
Expand All @@ -37,15 +46,24 @@ namespace BansheeEngine
*/
HResource loadAsync(const Path& filePath);

/**
* @copydoc loadAsync
*/
template <class T>
ResourceHandle<T> loadAsync(const Path& filePath)
{
return static_resource_cast<T>(loadAsync(filePath));
}

/**
* @brief Loads the resource with the given UUID. Returns an empty handle if resource can't be loaded.
* Resource is loaded synchronously.
*/
HResource loadFromUUID(const String& uuid);

/**
* @brief Loads the resource with the given UUID asynchronously. Initially returned resource handle will be invalid
* until resource loading is done.
* @brief Loads the resource with the given UUID asynchronously. Initially returned resource handle will be invalid
* until resource loading is done.
*
* @param uuid UUID of the resource to load.
*
Expand Down
8 changes: 4 additions & 4 deletions ExampleProject/Main/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace BansheeEngine
// so next time the application is ran you can just load them directly. This can be done with Resources::save/load.

// Import an FBX mesh.
exampleModel = static_resource_cast<Mesh>(Importer::instance().import(exampleModelPath));
exampleModel = Importer::instance().import<Mesh>(exampleModelPath);

// When importing you may specify optional import options that control how is the asset imported.
ImportOptionsPtr textureImportOptions = Importer::instance().createImportOptions(exampleTexturePath);
Expand All @@ -160,7 +160,7 @@ namespace BansheeEngine
}

// Import texture with specified import options
exampleTexture = static_resource_cast<Texture>(Importer::instance().import(exampleTexturePath, textureImportOptions));
exampleTexture = Importer::instance().import<Texture>(exampleTexturePath, textureImportOptions);

// Create import options for fragment GPU program
ImportOptionsPtr gpuProgImportOptions = Importer::instance().createImportOptions(exampleFragmentShaderPath);
Expand All @@ -182,7 +182,7 @@ namespace BansheeEngine
}

// Import fragment GPU program
exampleFragmentGPUProg = static_resource_cast<GpuProgram>(Importer::instance().import(exampleFragmentShaderPath, gpuProgImportOptions));
exampleFragmentGPUProg = Importer::instance().import<GpuProgram>(exampleFragmentShaderPath, gpuProgImportOptions);

// Create import options for vertex GPU program. Similar as above.
gpuProgImportOptions = Importer::instance().createImportOptions(exampleVertexShaderPath);
Expand All @@ -197,7 +197,7 @@ namespace BansheeEngine
}

// Import vertex GPU program
exampleVertexGPUProg = static_resource_cast<GpuProgram>(Importer::instance().import(exampleVertexShaderPath, gpuProgImportOptions));
exampleVertexGPUProg = Importer::instance().import<GpuProgram>(exampleVertexShaderPath, gpuProgImportOptions);

/************************************************************************/
/* CREATE SHADER */
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ Easiest way to get started with Banshee is to check out `ExampleProject` include

### Importing resources
```
HMesh dragonModel = static_resource_cast<Mesh>(Importer::instance().import("Dragon.fbx"));
HTexture dragonTexture = static_resource_cast<Texture>(Importer::instance().import("Dragon.psd"));
HMesh dragonModel = Importer::instance().import<Mesh>("Dragon.fbx");
HTexture dragonTexture = Importer::instance().import<Texture>("Dragon.psd");
```

### Adding and positioning a camera
Expand Down

0 comments on commit becb8d0

Please sign in to comment.