Browse Source

Exporter refactoring

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
2fd81579b5
4 changed files with 96 additions and 3 deletions
  1. 2 2
      testapp/Main.cpp
  2. 1 1
      tools/scene/CMakeLists.txt
  3. 8 0
      tools/scene/Exporter.cpp
  4. 85 0
      tools/scene/Exporter.h

+ 2 - 2
testapp/Main.cpp

@@ -219,7 +219,7 @@ Error init()
 	}
 #endif
 
-#if 1
+#if 0
 	// horse
 	err = scene.newSceneNode<ModelNode>("horse", horse, 
 		"models/horse/horse.ankimdl");
@@ -253,7 +253,7 @@ Error init()
 		move->setLocalOrigin(Vec4(0.0, 1.4, 0.6, 0.0));
 	}
 
-#if 0
+#if 1
 	{
 		ScriptResourcePointer script;
 

+ 1 - 1
tools/scene/CMakeLists.txt

@@ -3,5 +3,5 @@ include_directories("../../thirdparty/assimp/include")
 add_definitions("-fexceptions")
 
 add_executable(ankisceneimp Main.cpp Model.cpp Animation.cpp Light.cpp 
-	Common.cpp)
+	Common.cpp Exporter.cpp)
 target_link_libraries(ankisceneimp ankiassimp) 

+ 8 - 0
tools/scene/Exporter.cpp

@@ -0,0 +1,8 @@
+// Copyright (C) 2014, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include "Exporter.h"
+
+

+ 85 - 0
tools/scene/Exporter.h

@@ -0,0 +1,85 @@
+// Copyright (C) 2014, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#ifndef ANKI_TOOLS_SCENE_EXPORTER_H
+#define ANKI_TOOLS_SCENE_EXPORTER_H
+
+#include <string>
+#include <array>
+#include <cstdint>
+#include <fstream>
+#include <vector>
+
+#include <assimp/Importer.hpp>
+#include <assimp/scene.h>
+#include <assimp/postprocess.h>
+
+const uint32_t INVALID_INDEX = 0xFFFFFFFF;
+
+/// Thin mesh wrapper
+struct Model
+{
+	uint32_t m_meshIndex = INVALID_INDEX; ///< Mesh index in the scene
+	uint32_t m_materialIndex = INVALID_INDEX;
+	bool m_instanced = false;
+};
+
+/// Scene node.
+struct Node
+{
+	uint32_t m_modelIndex; ///< Index inside Exporter::m_models
+	std::vector<aiMatrix4x4> m_transforms;
+};
+
+const uint32_t MAX_BONES_PER_VERTEX = 4;
+
+/// Bone/weight info for a single vertex
+struct VertexWeight
+{
+	std::array<uint32_t, MAX_BONES_PER_VERTEX> m_boneIndices;
+	std::array<float, MAX_BONES_PER_VERTEX> m_weigths;
+	uint32_t m_bonesCount;
+};
+
+/// AnKi exporter.
+class Exporter
+{
+public:
+	std::string m_inputFilename;
+	std::string m_outputDirectory;
+	std::string m_rpath;
+	std::string m_texrpath;
+	
+	bool m_flipyz = false;
+
+	const aiScene* m_scene = nullptr;
+	Assimp::Importer m_importer;
+
+	std::vector<Model> m_models;
+	std::vector<Node> m_nodes;
+
+	std::ofstream m_sceneFile;
+
+	/// Load the scene.
+	void load();
+
+	/// Export.
+	void exportAll();
+
+private:
+	/// Convert one 4x4 matrix to AnKi friendly matrix.
+	aiMatrix4x4 toAnkiMatrix(const aiMatrix4x4& in) const;
+
+	/// Convert one 3x3 matrix to AnKi friendly matrix.
+	aiMatrix3x3 toAnkiMatrix(const aiMatrix3x3& in) const;
+
+	/// Write transformation of a node
+	void writeNodeTransform(
+		const std::string& node, 
+		const aiMatrix4x4& mat) const;
+};
+
+#endif
+