Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ben D'Angelo
committed
Apr 4, 2015
0 parents
commit 4cd98f5
Showing
23 changed files
with
868 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ipch | ||
Debug | ||
ffxiExporter/Debug | ||
ffxiMap.obj |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xiExporter", "xiExporter\xiExporter.vcxproj", "{A74CE523-8C9B-4887-A4A0-29BF13D55424}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Win32 = Debug|Win32 | ||
Release|Win32 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A74CE523-8C9B-4887-A4A0-29BF13D55424}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
{A74CE523-8C9B-4887-A4A0-29BF13D55424}.Debug|Win32.Build.0 = Debug|Win32 | ||
{A74CE523-8C9B-4887-A4A0-29BF13D55424}.Release|Win32.ActiveCfg = Release|Win32 | ||
{A74CE523-8C9B-4887-A4A0-29BF13D55424}.Release|Win32.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "Callback.h" | ||
using namespace std; | ||
|
||
|
||
Callback::Callback(void) | ||
{ | ||
count = 0; | ||
} | ||
|
||
|
||
Callback::~Callback(void) | ||
{ | ||
} | ||
|
||
bool Callback::HandleNewObject(char* ID, UINT NumIndexes, UINT NumVerteses, CONST void* pIndexData, CONST void* pVertexData) | ||
{ | ||
|
||
count++; | ||
// printf("Object %d (%s)\n", count, ID); | ||
if(count == 243){ | ||
printf("Handling new object (%s) Indexes %d, Verteses %d\n", ID, NumVerteses, NumVerteses); | ||
// std::string buf("objs\\"); | ||
// buf.append(ID); | ||
std::stringstream buf; | ||
buf << "obj" << count << ".obj"; | ||
const std::string tmp = buf.str(); | ||
|
||
ofstream objFile(tmp.c_str()); | ||
|
||
if(objFile.is_open()){ | ||
// output this object | ||
|
||
float* data = (float*)pVertexData; | ||
for(unsigned int i=0; i<NumVerteses*3; i+=3){ | ||
int offset = 0; | ||
printf("Vertex: x: %f y: %f z: %f\n", data[i + offset], data[i+1 + offset], data[i+2 + offset]); | ||
objFile << "v " << std::fixed << data[i] << " " << std::fixed << data[i+1] << " " << std::fixed << data[i+2] << "\n"; | ||
} | ||
|
||
objFile << "\n"; | ||
|
||
short* indexData = (short*)pIndexData; | ||
for(unsigned int i=0; i<NumIndexes; i+=4){ | ||
printf("Face: %u %u %u %u\n", indexData[i], indexData[i+1], indexData[i+2], indexData[i+3]); | ||
objFile << "f " << (indexData[i] + 1) << " " << (indexData[i+1] + 1) << " " << (indexData[i+2] + 1) << " " << (indexData[i+3] + 1) << "\n"; | ||
} | ||
|
||
printf("Wrote (%s) to file\n", ID); | ||
objFile.close(); | ||
} else { | ||
printf("Failed to open file (%s)\n", tmp.c_str()); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool Callback::HandleNewTexture(char* ID, char* pdata) | ||
{ | ||
|
||
return true; | ||
} | ||
|
||
void Callback::HandleProgress(const char* pStage, UINT Progress, UINT Total) | ||
{ | ||
printf("Progress of %s %d / %d \n", pStage, Progress, Total); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
#include <iostream> | ||
#include <fstream> | ||
#include <stdio.h> | ||
#include <sstream> | ||
#include "maplib.h" | ||
|
||
class Callback : | ||
public FFxiMapLib::ICallbackClass { | ||
public: | ||
Callback(void); | ||
~Callback(void); | ||
|
||
bool HandleNewObject(char* ID, UINT NumIndexes, UINT NumVerteses, CONST void* pIndexData, CONST void* pVertexData); | ||
bool HandleNewTexture(char* ID, char* pdata); | ||
void HandleProgress(const char* pStage, UINT Progress, UINT Total); | ||
private: | ||
int count; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#include "MapExporter.h" | ||
|
||
MapExporter::MapExporter(char* ffxiPath) : | ||
m_MapLib(NULL), m_ObjectBuffer(NULL), m_ObjectMap(NULL), m_ObjectMapCount(NULL), m_Loaded(false) | ||
{ | ||
m_MapLib = new FFxiMapLib::MapLib(); | ||
m_ZoneID = 0; | ||
m_MapLib->SetGamePath(ffxiPath); | ||
m_MapLib->AddCallback(this); | ||
} | ||
|
||
MapExporter::~MapExporter() | ||
{ | ||
m_Loaded = false; | ||
|
||
if( m_ObjectBuffer ) | ||
delete m_ObjectBuffer; | ||
m_ObjectBuffer = NULL; | ||
|
||
if( m_ObjectMap ) | ||
delete[] m_ObjectMap; | ||
m_ObjectMap = NULL; | ||
m_ObjectMapCount = 0; | ||
|
||
if( m_MapLib ) | ||
{ | ||
m_MapLib->FreeMap(); | ||
delete m_MapLib; | ||
m_MapLib = NULL; | ||
} | ||
} | ||
|
||
bool MapExporter::HandleNewObject(char* ID, UINT NumIndexes, UINT NumVerteses, CONST void* pIndexData, CONST void* pVertexData) | ||
{ | ||
//an object can have more than one sub object | ||
//so we have to check that the object hasn't already been added | ||
MapObject* Object = this->m_ObjectBuffer->GetMapObject(ID); | ||
if( Object == NULL ) | ||
Object = this->m_ObjectBuffer->NewMapObject(ID); | ||
|
||
Object->AddVertexBuffer(NumIndexes, NumVerteses, pIndexData, pVertexData); | ||
return true; | ||
} | ||
|
||
bool MapExporter::LoadMap(unsigned int ZoneID) | ||
{ | ||
m_ZoneID = ZoneID; | ||
//create a buffer to hold the objects | ||
this->m_ObjectBuffer = new ObjectBuffer(); | ||
|
||
//start loading the map | ||
if( !m_MapLib->LoadMap(ZoneID) ) | ||
return false; //something went wrong parsing the dat | ||
|
||
m_ObjectMapCount = m_MapLib->GetObjectMapCount(); | ||
//create the array to hold the object map | ||
m_ObjectMap = new ObjectMap[m_ObjectMapCount]; | ||
|
||
//copy the raw object info to our array. | ||
//find the object that goes with it and save a pointer to it. | ||
//pre transform a matrix for the object. | ||
for (unsigned int i = 0; i < m_ObjectMapCount; i++) | ||
{ | ||
FFxiMapLib::OBJINFO* RawObject = m_MapLib->GetObjectMap(i); | ||
ObjectMap* Map = &m_ObjectMap[i]; | ||
|
||
//copy the OBJINFO over | ||
memcpy(Map, RawObject, sizeof(FFxiMapLib::OBJINFO)); | ||
|
||
//find the object for this entry | ||
Map->Object = m_ObjectBuffer->GetMapObject(RawObject->id); | ||
|
||
//preprocess the objects matrix | ||
D3DXMATRIX matWorld; | ||
D3DXMATRIX matWorld2; | ||
D3DXMATRIX matWorld3; | ||
D3DXMATRIX matWorld4; | ||
D3DXMATRIX matWorldR4; | ||
D3DXMATRIX matWorldR5; | ||
D3DXMATRIX matWorldR6; | ||
ZeroMemory(&matWorld,sizeof(D3DXMATRIX)); | ||
|
||
D3DXMatrixScaling(&matWorld3, this->m_ObjectMap[i].ObjectInfo.fScaleX, this->m_ObjectMap[i].ObjectInfo.fScaleY, this->m_ObjectMap[i].ObjectInfo.fScaleZ); | ||
D3DXMatrixTranslation(&matWorld, this->m_ObjectMap[i].ObjectInfo.fTransX, this->m_ObjectMap[i].ObjectInfo.fTransY,this->m_ObjectMap[i].ObjectInfo.fTransZ); | ||
D3DXMatrixRotationX(&matWorldR4, this->m_ObjectMap[i].ObjectInfo.fRotX); | ||
D3DXMatrixRotationY(&matWorldR5, this->m_ObjectMap[i].ObjectInfo.fRotY); | ||
D3DXMatrixRotationZ(&matWorldR6, this->m_ObjectMap[i].ObjectInfo.fRotZ); | ||
matWorld2 = matWorldR4 * matWorldR5 * matWorldR6; | ||
matWorld=((matWorld3*matWorld2))*matWorld; | ||
Map->MatWorld = matWorld; | ||
|
||
if( this->m_ObjectMap[i].ObjectInfo.fScaleX * this->m_ObjectMap[i].ObjectInfo.fScaleY * this->m_ObjectMap[i].ObjectInfo.fScaleZ < 0.0f ) | ||
Map->CullMode = D3DCULL_CW; | ||
else | ||
Map->CullMode = D3DCULL_CCW; | ||
} | ||
|
||
m_Loaded = true; | ||
return true; | ||
} | ||
|
||
bool MapExporter::ExportMap() | ||
{ | ||
if( m_Loaded && m_ObjectBuffer && m_ObjectMap ) | ||
{ | ||
|
||
std::ofstream objFile("ffxiMap.obj"); | ||
|
||
if(!objFile.is_open()){ | ||
return false; | ||
} | ||
|
||
for (unsigned int i = 0; i < m_ObjectMapCount; i++) | ||
{ | ||
if( m_ObjectMap[i].Object ) | ||
{ | ||
std::string* out = ObjectMapToObj(i, &m_ObjectMap[i]); | ||
objFile << out->c_str(); | ||
objFile << "\n"; | ||
|
||
delete out; | ||
} | ||
} | ||
|
||
objFile.close(); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
std::string* MapExporter::ObjectMapToObj(unsigned int ID, ObjectMap* obj) | ||
{ | ||
return obj->Object->ToObj(ID, obj->MatWorld, obj->CullMode); | ||
// m_Renderer->SetTransform(D3DTS_WORLD, &m_ObjectMap[i].MatWorld); | ||
// m_Renderer->SetRenderState(D3DRS_CULLMODE, m_ObjectMap[i].CullMode); | ||
// m_ObjectMap[i].Object->RenderObject(); | ||
} | ||
|
||
unsigned int MapExporter::GetZoneID() | ||
{ | ||
return m_ZoneID; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
#include <d3d9.h> | ||
#include <d3dx9.h> | ||
#pragma comment(lib, "d3d9.lib") | ||
#pragma comment(lib, "d3dx9.lib") | ||
|
||
#include "ObjectBuffer.h" | ||
#include "MapLib.h" | ||
#include "MapObject.h" | ||
#include <fstream> | ||
#include <string> | ||
|
||
struct ObjectMap | ||
{ | ||
FFxiMapLib::OBJINFO ObjectInfo; | ||
MapObject* Object; | ||
D3DXMATRIX MatWorld; | ||
D3DCULL CullMode; | ||
ObjectMap() : Object(NULL) {} | ||
}; | ||
|
||
class MapExporter : public FFxiMapLib::ICallbackClass | ||
{ | ||
private: | ||
FFxiMapLib::MapLib* m_MapLib; | ||
ObjectBuffer* m_ObjectBuffer; | ||
ObjectMap* m_ObjectMap; | ||
unsigned int m_ObjectMapCount; | ||
bool m_Loaded; | ||
unsigned int m_ZoneID; | ||
|
||
std::string* ObjectMapToObj(unsigned int ID, ObjectMap* obj); | ||
protected: | ||
//callbacks | ||
virtual bool HandleNewObject(char* ID, UINT NumIndexes, UINT NumVerteses, CONST void* pIndexData, CONST void* pVertexData); | ||
virtual bool HandleNewTexture(char* ID, char* pdata) { return true; } | ||
virtual void HandleProgress(const char* pStage, UINT Progress, UINT Total) { } | ||
public: | ||
MapExporter(char* ffxiPath); | ||
virtual ~MapExporter(); | ||
|
||
bool LoadMap(unsigned int ZoneID); | ||
|
||
bool ExportMap(); | ||
unsigned int GetZoneID(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#pragma once | ||
#ifndef _MAPLIB_HEADER_ | ||
#define _MAPLIB_HEADER_ | ||
|
||
#ifndef CONST | ||
#define CONST const | ||
#endif | ||
typedef unsigned int UINT; | ||
|
||
#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(MAPLIB_STATIC) | ||
# ifdef MAPLIB_EXPORTS | ||
# define MAPLIBEXPORT __declspec(dllexport) | ||
# else | ||
# define MAPLIBEXPORT __declspec(dllimport) | ||
# pragma comment(lib, "FFxiMapLib.lib") | ||
# endif | ||
# define MAPLIBPRIVATE | ||
#else | ||
# define MAPLIBEXPORT | ||
# define MAPLIBPRIVATE | ||
#endif | ||
|
||
|
||
|
||
namespace FFxiMapLib | ||
{ | ||
class ICallbackClass | ||
{ | ||
public: | ||
virtual bool HandleNewObject(char* ID, UINT NumIndexes, UINT NumVerteses, CONST void* pIndexData, CONST void* pVertexData) = 0; | ||
virtual bool HandleNewTexture(char* ID, char* pdata) = 0; | ||
virtual void HandleProgress(const char* pStage, UINT Progress, UINT Total) = 0; | ||
}; | ||
|
||
#pragma pack(push,1) | ||
typedef struct | ||
{ | ||
char id[16]; | ||
float fTransX,fTransY,fTransZ; | ||
float fRotX,fRotY,fRotZ; | ||
float fScaleX,fScaleY,fScaleZ; | ||
float fa,fb,fc,fd; | ||
long fe,ff,fg,fh,fi,fj,fk,fl; | ||
} OBJINFO; | ||
#pragma pack(pop) | ||
|
||
class MAPLIBEXPORT MapLib | ||
{ | ||
private: | ||
ICallbackClass* m_CallBack; | ||
UINT m_MapID; | ||
|
||
char m_ffxiDir[1024]; | ||
|
||
char* m_pDatData; | ||
UINT m_datSize; | ||
|
||
OBJINFO* m_ObjectMap; | ||
UINT m_ObjectMapCount; | ||
|
||
private: | ||
bool ParseDat(); | ||
bool ParseObject(char* pObject); | ||
UINT GetFtableID(UINT Table, UINT ID); | ||
public: | ||
MapLib(); | ||
virtual ~MapLib(); | ||
|
||
bool SetGamePath(const char* Path); | ||
bool LoadMap(UINT ZoneID); | ||
bool LoadMap(const char* DatPath); | ||
void FreeMap(); | ||
|
||
OBJINFO* GetObjectMap(UINT Index); | ||
UINT GetObjectMapCount(); | ||
|
||
void AddCallback(ICallbackClass* T); | ||
|
||
}; | ||
}; | ||
#endif |
Oops, something went wrong.