From 548150f33ebf07b6ec2cb9455df4560a1e28d830 Mon Sep 17 00:00:00 2001
From: Anakin <Battlefrontler@t-online.de>
Date: Tue, 11 Oct 2016 13:41:24 +0200
Subject: [PATCH] evaluate most of MODL chunk, missing GEOM chunk,

---
 MshViewer/Header/Object.h   | 35 ++++++++++++++-
 MshViewer/Source/Object.cpp | 89 +++++++++++++++++++++++++++++++++++--
 MshViewer/main.cpp          |  5 +++
 3 files changed, 124 insertions(+), 5 deletions(-)

diff --git a/MshViewer/Header/Object.h b/MshViewer/Header/Object.h
index 2b3a2c3..c710558 100644
--- a/MshViewer/Header/Object.h
+++ b/MshViewer/Header/Object.h
@@ -2,7 +2,16 @@
 #include <vector>
 #include <list>
 #include <fstream>
-//#include <windows.h>
+#include <string>
+
+enum mtyp {
+	null,
+	dynamicMesh,
+	cloth,
+	bone,
+	staticMesh,
+	shadowMesh = 6
+};
 
 struct chunkHeader {
 	char name[5];
@@ -10,6 +19,28 @@ struct chunkHeader {
 	std::streampos position;
 };
 
+struct modl {
+	std::string name;
+	std::uint32_t size;
+	std::streampos position;
+	std::string parent;
+	mtyp type;
+	std::uint32_t zeroBaseIndex;
+	std::uint32_t renderFlags;
+	struct {
+		float scale[3];
+		float rotation[4];
+		float translation[3];
+	} tran;
+	struct {
+		std::uint32_t type;
+		float data1;
+		float data2;
+		float data3;
+	} swci;
+};
+
+
 class Object
 {
 public:
@@ -19,7 +50,7 @@ public:
 private:
 
 	std::list<chunkHeader*> lChunkMsh2;
-	std::list<std::list<chunkHeader*>*> lChunkModls;
+	std::list<modl*> lModls;
 	std::fstream fsMesh;
 
 
diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp
index 216d9fe..c0bc51c 100644
--- a/MshViewer/Source/Object.cpp
+++ b/MshViewer/Source/Object.cpp
@@ -33,9 +33,92 @@ Object::Object(const char* path)
 	{
 		if (!strcmp("MODL", (*it)->name))
 		{
-			std::list<chunkHeader*>* tempModlList = new std::list<chunkHeader*>;
-			loadChunks(*tempModlList, (*it)->position, (*it)->size);
-			lChunkModls.push_back(tempModlList);
+			modl* tempModl = new modl;
+			tempModl->size = (*it)->size;
+			tempModl->position = (*it)->position;
+
+			std::list<chunkHeader*> tempChunks;
+
+			loadChunks(tempChunks, (*it)->position, (*it)->size);
+			
+			// evaluate MODL subchunks
+			for (std::list<chunkHeader*>::iterator it = tempChunks.begin(); it != tempChunks.end(); it++)
+			{
+				if (!strcmp("MTYP", (*it)->name))
+				{
+					fsMesh.seekg((*it)->position);
+					std::uint32_t tempType;
+					fsMesh.read(reinterpret_cast<char*>(&tempType), sizeof(tempType));
+					tempModl->type = (mtyp)tempType;
+				}
+
+				if (!strcmp("MNDX", (*it)->name))
+				{
+					fsMesh.seekg((*it)->position);
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->zeroBaseIndex), sizeof(tempModl->zeroBaseIndex));
+				}
+
+				if (!strcmp("PRNT", (*it)->name))
+				{
+					fsMesh.seekg((*it)->position);
+					char tempName[33] = { 0 };
+					fsMesh.read(reinterpret_cast<char*>(&tempName[0]), (*it)->size > 32 ? 32 : (*it)->size);
+					tempModl->parent = tempName;
+				}
+
+				if (!strcmp("NAME", (*it)->name))
+				{
+					fsMesh.seekg((*it)->position);
+					char tempName[33] = { 0 };
+					fsMesh.read(reinterpret_cast<char*>(&tempName[0]), (*it)->size > 32 ? 32 : (*it)->size);
+					tempModl->name = tempName;
+				}
+
+				if (!strcmp("FLGS", (*it)->name))
+				{
+					fsMesh.seekg((*it)->position);
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->renderFlags), sizeof(tempModl->renderFlags));
+				}
+
+				if (!strcmp("TRAN", (*it)->name))
+				{
+					fsMesh.seekg((*it)->position);
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.scale[0]), sizeof(float));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.scale[1]), sizeof(float));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.scale[2]), sizeof(float));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.rotation[0]), sizeof(float));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.rotation[1]), sizeof(float));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.rotation[2]), sizeof(float));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.rotation[3]), sizeof(float));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.translation[0]), sizeof(float));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.translation[1]), sizeof(float));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.translation[2]), sizeof(float));
+				}
+
+				if (!strcmp("GEOM", (*it)->name))
+				{
+
+				}
+
+				if (!strcmp("SWCI", (*it)->name))
+				{
+					fsMesh.seekg((*it)->position);
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->swci.type), sizeof(tempModl->swci.type));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->swci.data1), sizeof(tempModl->swci.data1));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->swci.data2), sizeof(tempModl->swci.data2));
+					fsMesh.read(reinterpret_cast<char*>(&tempModl->swci.data3), sizeof(tempModl->swci.data3));
+				}
+			}
+			
+			lModls.push_back(tempModl);
+
+			//clean up
+			while (!tempChunks.empty())
+			{
+				chunkHeader* tempCursor = tempChunks.front();
+				tempChunks.pop_front();
+				delete tempCursor;
+			}
 		}
 	}
 
diff --git a/MshViewer/main.cpp b/MshViewer/main.cpp
index c2a1eca..e7d920d 100644
--- a/MshViewer/main.cpp
+++ b/MshViewer/main.cpp
@@ -9,6 +9,8 @@
 
 int main(int argc, char** argv)
 {
+	//goto openGL;
+
 	try {
 		Object obj("..\\Release\\Msh\\cube.msh");
 	}
@@ -21,6 +23,9 @@ int main(int argc, char** argv)
 
 
 	return 0;
+
+openGL:
+
 	OpenGLController *scene = OpenGLController::getInstance();
 
 	scene->loadMsh("test.msh");
-- 
GitLab