|
From: <axl...@us...> - 2009-03-01 16:19:13
|
Revision: 151
http://hgengine.svn.sourceforge.net/hgengine/?rev=151&view=rev
Author: axlecrusher
Date: 2009-03-01 16:19:05 +0000 (Sun, 01 Mar 2009)
Log Message:
-----------
Update HGMDL with oriented bounding box as an extra data element for
meshes
Modified Paths:
--------------
Mercury2/beerhall.hgmdl
Mercury2/docs/MercuryBinaryModelFormat.odt
Mercury2/mercury2.kdevelop
Mercury2/scenegraph.xml
Mercury2/src/HGMDLMesh.cpp
Mercury2/src/HGMDLMesh.h
Mercury2/tools/obj2hgmdl/obj2hgmdl.cpp
Modified: Mercury2/beerhall.hgmdl
===================================================================
(Binary files differ)
Modified: Mercury2/docs/MercuryBinaryModelFormat.odt
===================================================================
(Binary files differ)
Modified: Mercury2/mercury2.kdevelop
===================================================================
--- Mercury2/mercury2.kdevelop 2009-01-22 16:28:56 UTC (rev 150)
+++ Mercury2/mercury2.kdevelop 2009-03-01 16:19:05 UTC (rev 151)
@@ -2,7 +2,7 @@
<kdevelop>
<general>
<author>Joshua Allen</author>
- <email></email>
+ <email/>
<version>2.0</version>
<projectmanagement>KDevAutoProject</projectmanagement>
<primarylanguage>C++</primarylanguage>
@@ -14,8 +14,8 @@
<projectname>Mercury2</projectname>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
- <description></description>
- <defaultencoding></defaultencoding>
+ <description/>
+ <defaultencoding/>
<versioncontrol/>
</general>
<kdevautoproject>
@@ -26,8 +26,8 @@
<run>
<mainprogram>/home/josh/Mercury2/debug/src/mercury2</mainprogram>
<terminal>false</terminal>
- <programargs></programargs>
- <globaldebugarguments></globaldebugarguments>
+ <programargs/>
+ <globaldebugarguments/>
<globalcwd>/home/josh/Mercury2</globalcwd>
<useglobalprogram>true</useglobalprogram>
<autocompile>false</autocompile>
@@ -43,15 +43,15 @@
<f77compiler>kdevg77options</f77compiler>
<cxxflags>-O2 -g -Wall</cxxflags>
<envvars/>
- <configargs></configargs>
- <topsourcedir></topsourcedir>
+ <configargs/>
+ <topsourcedir/>
<cppflags>-Isrc/ -I/usr/include/libxml2/ -DHGENGINE -DRUN_FROM_START_FOLDER -DUSE_SSE</cppflags>
<ldflags>-lpthread -lX11 -lGL -lxml2 -lpng</ldflags>
- <ccompilerbinary></ccompilerbinary>
- <cxxcompilerbinary></cxxcompilerbinary>
- <f77compilerbinary></f77compilerbinary>
+ <ccompilerbinary/>
+ <cxxcompilerbinary/>
+ <f77compilerbinary/>
<cflags>-O2 -g -Wall</cflags>
- <f77flags></f77flags>
+ <f77flags/>
</optimized>
<debug>
<configargs>--enable-debug=full</configargs>
@@ -61,14 +61,14 @@
<f77compiler>kdevg77options</f77compiler>
<cxxflags>-O2 -g -Wall</cxxflags>
<envvars/>
- <topsourcedir></topsourcedir>
+ <topsourcedir/>
<cppflags>-Isrc/ -I/usr/include/libxml2/ -DHGENGINE -DRUN_FROM_START_FOLDER -DUSE_SSE</cppflags>
<ldflags>-lpthread -lX11 -lGL -lxml2 -lpng</ldflags>
- <ccompilerbinary></ccompilerbinary>
- <cxxcompilerbinary></cxxcompilerbinary>
- <f77compilerbinary></f77compilerbinary>
+ <ccompilerbinary/>
+ <cxxcompilerbinary/>
+ <f77compilerbinary/>
<cflags>-O2 -g -Wall</cflags>
- <f77flags></f77flags>
+ <f77flags/>
</debug>
<default>
<envvars/>
@@ -222,7 +222,7 @@
<includePaths>.;</includePaths>
</codecompletion>
<creategettersetter>
- <prefixGet></prefixGet>
+ <prefixGet/>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
@@ -243,11 +243,11 @@
</cppsupportpart>
<kdevdebugger>
<general>
- <gdbpath></gdbpath>
+ <gdbpath/>
<dbgshell>libtool</dbgshell>
- <configGdbScript></configGdbScript>
- <runShellScript></runShellScript>
- <runGdbScript></runGdbScript>
+ <configGdbScript/>
+ <runShellScript/>
+ <runGdbScript/>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
Modified: Mercury2/scenegraph.xml
===================================================================
--- Mercury2/scenegraph.xml 2009-01-22 16:28:56 UTC (rev 150)
+++ Mercury2/scenegraph.xml 2009-03-01 16:19:05 UTC (rev 151)
@@ -20,13 +20,13 @@
<asset type="quad"/>
</node>
</node>
- <node type="rotatornode" movz="-2" scalex="0.05" scaley="0.05" scalez="0.05" >
+ <node type="rotatornode" movz="-2" scalex="0.25" scaley="0.25" scalez="0.25" >
<node type="renderablenode">
<asset type="texture" file="test.bmp"/>
<asset type="hgmdlmodel" file="beerhall.hgmdl"/>
</node>
</node>
- <node type="rotatornode" movz="-2" movx="2" scalex="0.05" scaley="0.05" scalez="0.05" >
+ <node type="rotatornode" movz="-2" movx="2" scalex="0.25" scaley="0.25" scalez="0.25" >
<node type="renderablenode">
<asset type="texture" file="test.bmp"/>
<asset type="hgmdlmodel" file="beerhall.hgmdl"/>
Modified: Mercury2/src/HGMDLMesh.cpp
===================================================================
--- Mercury2/src/HGMDLMesh.cpp 2009-01-22 16:28:56 UTC (rev 150)
+++ Mercury2/src/HGMDLMesh.cpp 2009-03-01 16:19:05 UTC (rev 151)
@@ -38,8 +38,28 @@
//fread(m_indexData.Buffer(), numIndices*sizeof(uint16_t), 1, hgmdl);
hgmdl->Read( m_indexData.Buffer(), numIndices*sizeof(uint16_t) );
}
+
+ uint32_t extraDataCount;
+ hgmdl->Read( &extraDataCount, sizeof( uint32_t ) );
+ printf("has %d extras\n", extraDataCount);
+ for (uint32_t i = 0; i < extraDataCount; ++i)
+ {
+ ReadExtraData(hgmdl);
+ }
}
+void HGMDLMesh::ReadExtraData(MercuryFile* hgmdl)
+{
+ uint32_t type, length;
+ char* data = NULL;
+ hgmdl->Read( &type, sizeof(char)*4 );
+ hgmdl->Read( &length, sizeof(uint32_t) );
+
+ data = new char[length];
+ hgmdl->Read( data, length );
+ delete data;
+}
+
/****************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/HGMDLMesh.h
===================================================================
--- Mercury2/src/HGMDLMesh.h 2009-01-22 16:28:56 UTC (rev 150)
+++ Mercury2/src/HGMDLMesh.h 2009-03-01 16:19:05 UTC (rev 151)
@@ -8,6 +8,7 @@
{
public:
void LoadFromFile(MercuryFile* hgmdl);
+ void ReadExtraData(MercuryFile* hgmdl);
private:
MString m_name;
bool m_cachable;
Modified: Mercury2/tools/obj2hgmdl/obj2hgmdl.cpp
===================================================================
--- Mercury2/tools/obj2hgmdl/obj2hgmdl.cpp 2009-01-22 16:28:56 UTC (rev 150)
+++ Mercury2/tools/obj2hgmdl/obj2hgmdl.cpp 2009-03-01 16:19:05 UTC (rev 151)
@@ -4,13 +4,19 @@
#include <stdint.h>
#include <MercuryPoint.h>
#include <map>
+#include <math.h>
using namespace std;
+float min(float x, float y) { return x<y?x:y; }
+float max(float x, float y) { return x>y?x:y; }
+
vector< MercuryPoint > v;
vector< MercuryPoint > vt;
vector< MercuryPoint > vn;
+float minX, maxX, minY, maxY, minZ, maxZ;
+
struct Vertex
{
MercuryPoint uv;
@@ -25,25 +31,7 @@
vector< Vertex > vertice;
vector< uint16_t > indice;
-/*
-struct Mesh
-{
- uint32_t nameLength;
- char* name;
- bool bCache;
-
- //Mercury2 imposes a limit of 65535 vertice in one VBO mesh
- uint32_t vertexDataLength; //in bytes
- char* vertexData;
-
- //Mercury2 imposes a limit of 65535 indices in one VBO mesh
- uint16_t numberOfIndices;
- uint16_t* indices;
-};
-
-Mesh currentMesh;
-*/
void LineParser(const string &line)
{
if (line.empty()) return;
@@ -53,6 +41,14 @@
MercuryPoint tv;
sscanf(line.c_str(), "v %f %f %f", &tv.x, &tv.y, &tv.z);
v.push_back(tv);
+
+ minX = min(minX, tv.x);
+ minY = min(minY, tv.y);
+ minZ = min(minZ, tv.z);
+
+ maxX = max(maxX, tv.x);
+ maxY = max(maxY, tv.y);
+ maxZ = max(maxZ, tv.z);
}
else if (token == "vt")
{
@@ -110,6 +106,27 @@
}
}
+void WriteOBB(FILE *mbmf)
+{
+ char type[] = "OBB ";
+ fwrite(type, sizeof(char)*4, 1, mbmf);
+
+ uint32_t tmp32 = sizeof(float)*6; fwrite(&tmp32, sizeof(uint32_t), 1, mbmf);
+ float tmp[3];
+
+ //center
+ tmp[0] = (maxX-minX)/2.0f;
+ tmp[1] = (maxY-minY)/2.0f;
+ tmp[2] = (maxZ-minZ)/2.0f;
+ fwrite(tmp, sizeof(float)*3, 1, mbmf);
+
+ //extends
+ tmp[0] = fabs(tmp[0]);
+ tmp[1] = fabs(tmp[1]);
+ tmp[2] = fabs(tmp[2]);
+ fwrite(tmp, sizeof(float)*3, 1, mbmf);
+}
+
void WriteMBMF( FILE *mbmf )
{
uint32_t tmp32;
@@ -140,6 +157,9 @@
tmp16 = indice.size(); fwrite(&tmp16, sizeof(uint16_t), 1, mbmf);
for (uint16_t i = 0; i < indice.size(); ++i)
fwrite(&indice[i], sizeof(uint16_t), 1, mbmf);
+
+ tmp32 = 1; fwrite(&tmp32, sizeof(uint32_t), 1, mbmf);
+ WriteOBB(mbmf);
}
tmp32 = 0;
@@ -159,13 +179,19 @@
mbmf = fopen(argv[2], "wb");
string line;
+
+ minX = minY = minZ = 1000000.0f;
+ maxX = maxY = maxZ = -1000000.0f;
-
while ( getline(obj, line) )
{
if (line.length() > 0) LineParser(line);
}
+ printf("%f %f %f\n", minX, maxX, (maxX-minX)/2.0f );
+ printf("%f %f %f\n", minY, maxY, (maxY-minY)/2.0f );
+ printf("%f %f %f\n", minZ, maxZ, (maxZ-minZ)/2.0f );
+
WriteMBMF( mbmf );
fclose( mbmf );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|