|
From: <axl...@us...> - 2008-12-30 14:52:19
|
Revision: 93
http://hgengine.svn.sourceforge.net/hgengine/?rev=93&view=rev
Author: axlecrusher
Date: 2008-12-30 14:52:16 +0000 (Tue, 30 Dec 2008)
Log Message:
-----------
Add models
Added Paths:
-----------
Mercury2/src/HGMDLMesh.cpp
Mercury2/src/HGMDLMesh.h
Mercury2/src/HGMDLModel.cpp
Mercury2/src/HGMDLModel.h
Added: Mercury2/src/HGMDLMesh.cpp
===================================================================
--- Mercury2/src/HGMDLMesh.cpp (rev 0)
+++ Mercury2/src/HGMDLMesh.cpp 2008-12-30 14:52:16 UTC (rev 93)
@@ -0,0 +1,65 @@
+#include <HGMDLMesh.h>
+
+void HGMDLMesh::LoadFromFile(FILE* hgmdl)
+{
+ uint32_t nameLength;
+ fread(&nameLength, sizeof(uint32_t), 1, hgmdl);
+
+ if (nameLength > 0)
+ {
+ char* name = new char[nameLength+1];
+ name[nameLength] = 0;
+ fread(name, nameLength, 1, hgmdl);
+ m_name = name;
+ }
+
+ fread(&m_cachable, sizeof(bool), 1, hgmdl);
+
+ uint32_t dataLength;
+ fread(&dataLength, sizeof(uint32_t), 1, hgmdl);
+ if (dataLength > 0)
+ {
+ m_vertexData.Allocate( dataLength/sizeof(float) ); //they are all floats
+ fread(m_vertexData.Buffer(), dataLength, 1, hgmdl);
+ }
+
+ uint16_t numIndices;
+ fread(&numIndices, sizeof(uint16_t), 1, hgmdl);
+ if (numIndices > 0)
+ {
+ m_indexData.Allocate( numIndices );
+ fread(m_indexData.Buffer(), numIndices*sizeof(uint16_t), 1, hgmdl);
+ }
+}
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Added: Mercury2/src/HGMDLMesh.h
===================================================================
--- Mercury2/src/HGMDLMesh.h (rev 0)
+++ Mercury2/src/HGMDLMesh.h 2008-12-30 14:52:16 UTC (rev 93)
@@ -0,0 +1,44 @@
+#include <MercuryVBO.h>
+
+class HGMDLMesh : public MercuryVBO
+{
+ public:
+ void LoadFromFile(FILE* hgmdl);
+ private:
+ string m_name;
+ bool m_cachable;
+};
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+
+
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Added: Mercury2/src/HGMDLModel.cpp
===================================================================
--- Mercury2/src/HGMDLModel.cpp (rev 0)
+++ Mercury2/src/HGMDLModel.cpp 2008-12-30 14:52:16 UTC (rev 93)
@@ -0,0 +1,91 @@
+#include <HGMDLModel.h>
+
+REGISTER_ASSET_TYPE(HGMDLModel);
+
+void HGMDLModel::LoadFromXML(const XMLNode& node)
+{
+ if ( !node.Attribute("file").empty() )
+ {
+ FILE* f = fopen( node.Attribute("file").c_str(), "rb" );
+ LoadModel( f );
+ fclose( f );
+ }
+}
+
+void HGMDLModel::LoadModel(FILE* hgmdl)
+{
+ char fingerPrint[5];
+ fingerPrint[5] = 0;
+ fread(fingerPrint, 4, 1, hgmdl);
+
+ string p(fingerPrint);
+ if (p != "MBMF")
+ {
+ printf("Not a HGMDL file.\n");
+ return;
+ }
+
+ uint32_t version;
+ fread(&version, 4, 1, hgmdl);
+
+ if (version != 200)
+ {
+ printf("Invalid HGMDL version %d\n", version);
+ return;
+ }
+
+ uint16_t numMeshes;
+ fread(&numMeshes, sizeof(uint16_t), 1, hgmdl);
+ for (uint16_t i = 0; i < numMeshes; ++i)
+ {
+ HGMDLMesh *mesh = new HGMDLMesh();
+ mesh->LoadFromFile( hgmdl );
+ m_meshes.push_back(mesh);
+ }
+}
+
+void HGMDLModel::Render(MercuryNode* node)
+{
+ list< HGMDLMesh* >::iterator i = m_meshes.begin();
+ for(;i != m_meshes.end(); ++i)
+ {
+ (*i)->Render(node);
+ }
+}
+
+HGMDLModel* HGMDLModel::Generate()
+{
+ return new HGMDLModel();
+}
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Added: Mercury2/src/HGMDLModel.h
===================================================================
--- Mercury2/src/HGMDLModel.h (rev 0)
+++ Mercury2/src/HGMDLModel.h 2008-12-30 14:52:16 UTC (rev 93)
@@ -0,0 +1,49 @@
+#include <MercuryAsset.h>
+#include <HGMDLMesh.h>
+
+class HGMDLModel : public MercuryAsset
+{
+ public:
+
+ virtual void LoadFromXML(const XMLNode& node);
+
+ void LoadModel(FILE* hgmdl);
+
+ static HGMDLModel* Generate();
+ virtual void Render(MercuryNode* node);
+
+ private:
+ std::list< HGMDLMesh* > m_meshes;
+};
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|