فهرست منبع

Easier importer and resources interface
Updated readme example with new interface

Marko Pintera 11 سال پیش
والد
کامیت
becb8d0082
4فایلهای تغییر یافته به همراه35 افزوده شده و 8 حذف شده
  1. 9 0
      BansheeCore/Include/BsImporter.h
  2. 20 2
      BansheeCore/Include/BsResources.h
  3. 4 4
      ExampleProject/Main/Main.cpp
  4. 2 2
      README.md

+ 9 - 0
BansheeCore/Include/BsImporter.h

@@ -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.
 		 *

+ 20 - 2
BansheeCore/Include/BsResources.h

@@ -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.
@@ -37,6 +46,15 @@ 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.
@@ -44,8 +62,8 @@ namespace BansheeEngine
 		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. 
 		 *

+ 4 - 4
ExampleProject/Main/Main.cpp

@@ -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);
@@ -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);
@@ -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);
@@ -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	                      		*/

+ 2 - 2
README.md

@@ -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