Browse Source

Added import scale to fix importer
Fixed FBX importer so it generates import options of the proper type

Marko Pintera 10 years ago
parent
commit
401f7c96bf

+ 11 - 0
BansheeCore/Include/BsMeshImportOptions.h

@@ -82,6 +82,16 @@ namespace BansheeEngine
 		 */
 		bool getImportAnimation() const { return mImportAnimation; }
 
+		/**
+		 * @brief	Sets a value that will uniformly scale the imported mesh by the specified value.
+		 */
+		void setImportScale(float import) { mImportScale = import; }
+
+		/**
+		 * @brief	Retrieves a value that will uniformly scale the imported mesh by the specified value.
+		 */
+		float getImportScale() const { return mImportScale; }
+
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/
@@ -97,5 +107,6 @@ namespace BansheeEngine
 		bool mImportBlendShapes;
 		bool mImportSkin;
 		bool mImportAnimation;
+		float mImportScale;
 	};
 }

+ 4 - 0
BansheeCore/Include/BsMeshImportOptionsRTTI.h

@@ -27,6 +27,9 @@ namespace BansheeEngine
 		bool& getImportAnimation(MeshImportOptions* obj) { return obj->mImportAnimation; }
 		void setImportAnimation(MeshImportOptions* obj, bool& value) { obj->mImportAnimation = value; }
 
+		float& getImportScale(MeshImportOptions* obj) { return obj->mImportScale; }
+		void setImportScale(MeshImportOptions* obj, float& value) { obj->mImportScale = value; }
+
 	public:
 		MeshImportOptionsRTTI()
 		{
@@ -36,6 +39,7 @@ namespace BansheeEngine
 			addPlainField("mImportBlendShapes", 3, &MeshImportOptionsRTTI::getImportBlendShapes, &MeshImportOptionsRTTI::setImportBlendShapes);
 			addPlainField("mImportSkin", 4, &MeshImportOptionsRTTI::getImportSkin, &MeshImportOptionsRTTI::setImportSkin);
 			addPlainField("mImportAnimation", 5, &MeshImportOptionsRTTI::getImportAnimation, &MeshImportOptionsRTTI::setImportAnimation);
+			addPlainField("mImportScale", 6, &MeshImportOptionsRTTI::getImportScale, &MeshImportOptionsRTTI::setImportScale);
 		}
 
 		virtual const String& getRTTIName()

+ 2 - 1
BansheeCore/Source/BsMeshImportOptions.cpp

@@ -5,7 +5,8 @@ namespace BansheeEngine
 {
 	MeshImportOptions::MeshImportOptions()
 		:mCPUReadable(false), mImportNormals(false), mImportTangents(false), 
-		mImportBlendShapes(false), mImportSkin(false), mImportAnimation(false)
+		mImportBlendShapes(false), mImportSkin(false), mImportAnimation(false),
+		mImportScale(0.01f)
 	{ }
 
 	/************************************************************************/

+ 0 - 1
BansheeEditor/Source/BsEditorApplication.cpp

@@ -220,7 +220,6 @@ namespace BansheeEngine
 
 		HSceneObject clone = testModelGO->clone();
 		GameObjectHandle<DbgTestGameObjectRef> clonedDbgTestGameObjectRef = clone->getComponent<DbgTestGameObjectRef>();
-		clone->setScale(Vector3::ONE * 0.01f);
 
 		testModelGO->destroy();
 

+ 1 - 0
BansheeFBXImporter/Include/BsFBXImportData.h

@@ -19,6 +19,7 @@ namespace BansheeEngine
 		bool importBlendShapes = true;
 		bool importNormals = true;
 		bool importTangents = true;
+		float importScale = 0.01f;
 	};
 
 	/**

+ 9 - 4
BansheeFBXImporter/Include/BsFBXImporter.h

@@ -22,17 +22,22 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	SpecificImporter::isExtensionSupported
 		 */
-		virtual bool isExtensionSupported(const WString& ext) const;
+		virtual bool isExtensionSupported(const WString& ext) const override;
 
 		/**
 		 * @copydoc	SpecificImporter::isMagicNumberSupported
 		 */
-		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
+		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const override;
 
 		/**
 		 * @copydoc	SpecificImporter::import
 		 */
-		virtual ResourcePtr import(const Path& filePath, ConstImportOptionsPtr importOptions);
+		virtual ResourcePtr import(const Path& filePath, ConstImportOptionsPtr importOptions) override;
+
+		/**
+		 * @copydoc	SpecificImporter::createImportOptions
+		 */
+		ImportOptionsPtr createImportOptions() const override;
 	private:
 		/**
 		 * @brief	Starts up FBX SDK. Must be called before any other operations.
@@ -78,7 +83,7 @@ namespace BansheeEngine
 		 * @brief	Converts the mesh data from the imported FBX scene into mesh data that can be used
 		 *			for initializing a mesh.
 		 */
-		MeshDataPtr generateMeshData(const FBXImportScene& scene, Vector<SubMesh>& subMeshes);
+		MeshDataPtr generateMeshData(const FBXImportScene& scene, const FBXImportOptions& options, Vector<SubMesh>& subMeshes);
 
 		/**
 		 * @brief	Creates an internal representation of an FBX node from an FbxNode object.

+ 11 - 3
BansheeFBXImporter/Source/BsFBXImporter.cpp

@@ -90,6 +90,11 @@ namespace BansheeEngine
 		return true; // FBX files can be plain-text so I don't even check for magic number
 	}
 
+	ImportOptionsPtr FBXImporter::createImportOptions() const
+	{
+		return bs_shared_ptr<MeshImportOptions, PoolAlloc>();
+	}
+
 	ResourcePtr FBXImporter::import(const Path& filePath, ConstImportOptionsPtr importOptions)
 	{
 		FbxScene* fbxScene = nullptr;
@@ -107,13 +112,14 @@ namespace BansheeEngine
 		fbxImportOptions.importAnimation = meshImportOptions->getImportAnimation();
 		fbxImportOptions.importBlendShapes = meshImportOptions->getImportBlendShapes();
 		fbxImportOptions.importSkin = meshImportOptions->getImportSkin();
+		fbxImportOptions.importScale = meshImportOptions->getImportScale();
 
 		FBXImportScene importedScene;
 		parseScene(fbxScene, fbxImportOptions, importedScene);
 		splitMeshVertices(importedScene);
 		
 		Vector<SubMesh> subMeshes;
-		MeshDataPtr meshData = generateMeshData(importedScene, subMeshes);
+		MeshDataPtr meshData = generateMeshData(importedScene, fbxImportOptions, subMeshes);
 
 		// TODO - Later: Optimize mesh: Remove bad and degenerate polygons, optimize for vertex cache
 
@@ -314,8 +320,10 @@ namespace BansheeEngine
 		scene.meshes = splitMeshes;
 	}
 
-	MeshDataPtr FBXImporter::generateMeshData(const FBXImportScene& scene, Vector<SubMesh>& outputSubMeshes)
+	MeshDataPtr FBXImporter::generateMeshData(const FBXImportScene& scene, const FBXImportOptions& options, Vector<SubMesh>& outputSubMeshes)
 	{
+		Matrix4 importScale = Matrix4::scaling(options.importScale);
+
 		Vector<MeshDataPtr> allMeshData;
 		Vector<Vector<SubMesh>> allSubMeshes;
 
@@ -380,7 +388,7 @@ namespace BansheeEngine
 			UINT32 numIndices = (UINT32)mesh->indices.size();
 			for (auto& node : mesh->referencedBy)
 			{
-				Matrix4 worldTransform = node->worldTransform;
+				Matrix4 worldTransform = node->worldTransform * importScale;
 				Matrix4 worldTransformIT = worldTransform.transpose();
 				worldTransformIT = worldTransformIT.inverse();
 

+ 0 - 1
TODO.txt

@@ -27,7 +27,6 @@ Project window
 
 Dropping doesn't work. endDrag in DragAndDropManager gets called before cursorReleased()
 Destroying Renderable objects doesn't seem to properly clear them from the renderer
-Dragging the selection area past the scroll area borders will expand the scroll area
 Add mesh scale to FBX importer (and default it to 0.01 or whatever makes the dragon look normal sized)
 
 Later: