From 728e7e405dd56afb4da03fd63df378d5f984ed73 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 20 Oct 2012 18:40:24 +0200 Subject: Transparent plant textures --- src/graphics/engine/modelfile.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/graphics/engine/modelfile.cpp') diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index c0d04a0..3b0343a 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -608,9 +608,6 @@ bool CModelFile::ReadModel(std::istream& stream) triangle.state = t.state; triangle.variableTex2 = t.texNum2 == 1; - if (triangle.tex1Name == "plant.png") - triangle.state |= ENG_RSTATE_ALPHA; - if (!triangle.variableTex2 && t.texNum2 != 0) { if (t.texNum2 >= 1 && t.texNum2 <= 10) @@ -637,6 +634,10 @@ bool CModelFile::ReadModel(std::istream& stream) m_triangles[i].tex2Name = StrUtils::Replace(m_triangles[i].tex2Name, "bmp", "png"); m_triangles[i].tex2Name = StrUtils::Replace(m_triangles[i].tex2Name, "tga", "png"); + // TODO: fix this in model files + if (m_triangles[i].tex1Name == "plant.png") + m_triangles[i].state |= ENG_RSTATE_ALPHA; + GetLogger()->Trace("ModelTriangle %d\n", i+1); std::string s1 = m_triangles[i].p1.ToString(); GetLogger()->Trace(" p1: %s\n", s1.c_str()); -- cgit v1.2.3-1-g7c22 From 4811defca2eeea69e40346be6b1647f276db8c76 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 14 Dec 2012 21:30:35 +0100 Subject: Static objects using OpenGL VBOs and display lists --- src/graphics/engine/modelfile.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/graphics/engine/modelfile.cpp') diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index 3b0343a..a9972fe 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -1157,18 +1157,24 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) #ifndef MODELFILE_NO_ENGINE + +/** + * TODO: move the function to CEngine or new class (CModelManager?) + * and make models shared static objects. + */ + bool CModelFile::CreateEngineObject(int objRank) { std::vector vs(3, VertexTex2()); + m_engine->SetObjectStatic(objRank, true); // TODO: make optional in the future + float limit[2]; limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config limit[1] = m_engine->GetLimitLOD(1); // frontier BC as config for (int i = 0; i < static_cast( m_triangles.size() ); i++) { - // TODO move this to CEngine - float min = m_triangles[i].min; float max = m_triangles[i].max; -- cgit v1.2.3-1-g7c22 From 5574eccebd16ae38a2a21ed202d1f9d1ba8f67a4 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 26 Dec 2012 20:58:02 +0100 Subject: Engine optimization - rewritten model management - new class CModelManager - rewritten engine object structure in CEngine - created shared model data instead of separate objects per each model instance - minor refactoring --- src/graphics/engine/modelfile.cpp | 136 +------------------------------------- 1 file changed, 1 insertion(+), 135 deletions(-) (limited to 'src/graphics/engine/modelfile.cpp') diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index a9972fe..a942b08 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -34,22 +34,10 @@ #include -/* - * NOTE: #ifndef checking for MODELFILE_NO_ENGINE - * is provided in this module to conditionally - * disable dependence on CEngine. - */ - - // Graphics module namespace namespace Gfx { -//! How big the triangle vector is by default -const int TRIANGLE_PREALLOCATE_COUNT = 2000; - - - bool ReadBinaryVertex(std::istream& stream, Vertex& vertex) { vertex.coord.x = IOUtils::ReadBinaryFloat(stream); @@ -322,15 +310,8 @@ bool ReadLineString(std::istream& stream, const std::string& prefix, std::string } -CModelFile::CModelFile(CInstanceManager* iMan) +CModelFile::CModelFile() { - m_iMan = iMan; - -#ifndef MODELFILE_NO_ENGINE - m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); -#endif - - m_triangles.reserve(TRIANGLE_PREALLOCATE_COUNT); } CModelFile::~CModelFile() @@ -1155,99 +1136,6 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) Other stuff *******************************************************/ -#ifndef MODELFILE_NO_ENGINE - - -/** - * TODO: move the function to CEngine or new class (CModelManager?) - * and make models shared static objects. - */ - -bool CModelFile::CreateEngineObject(int objRank) -{ - std::vector vs(3, VertexTex2()); - - m_engine->SetObjectStatic(objRank, true); // TODO: make optional in the future - - float limit[2]; - limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config - limit[1] = m_engine->GetLimitLOD(1); // frontier BC as config - - for (int i = 0; i < static_cast( m_triangles.size() ); i++) - { - float min = m_triangles[i].min; - float max = m_triangles[i].max; - - // Standard frontiers -> config - if (min == 0.0f && max == 100.0f) // resolution A ? - { - max = limit[0]; - } - else if (min == 100.0f && max == 200.0f) // resolution B ? - { - min = limit[0]; - max = limit[1]; - } - else if (min == 200.0f && max == 1000000.0f) // resolution C ? - { - min = limit[1]; - } - - int state = m_triangles[i].state; - std::string tex2Name = m_triangles[i].tex2Name; - - if (m_triangles[i].variableTex2) - { - int texNum = m_engine->GetSecondTexture(); - - if (texNum >= 1 && texNum <= 10) - state |= ENG_RSTATE_DUAL_BLACK; - - if (texNum >= 11 && texNum <= 20) - state |= ENG_RSTATE_DUAL_WHITE; - - char name[20] = { 0 }; - sprintf(name, "dirty%.2d.png", texNum); - tex2Name = name; - } - - vs[0] = m_triangles[i].p1; - vs[1] = m_triangles[i].p2; - vs[2] = m_triangles[i].p3; - - bool ok = m_engine->AddTriangles(objRank, vs, - m_triangles[i].material, - state, - m_triangles[i].tex1Name, - tex2Name, - min, max, false); - if (!ok) - return false; - } - - return true; -} - -#endif - -void CModelFile::Mirror() -{ - for (int i = 0; i < static_cast( m_triangles.size() ); i++) - { - VertexTex2 t = m_triangles[i].p1; - m_triangles[i].p1 = m_triangles[i].p2; - m_triangles[i].p2 = t; - - m_triangles[i].p1.coord.z = -m_triangles[i].p1.coord.z; - m_triangles[i].p2.coord.z = -m_triangles[i].p2.coord.z; - m_triangles[i].p3.coord.z = -m_triangles[i].p3.coord.z; - - m_triangles[i].p1.normal.z = -m_triangles[i].p1.normal.z; - m_triangles[i].p2.normal.z = -m_triangles[i].p2.normal.z; - m_triangles[i].p3.normal.z = -m_triangles[i].p3.normal.z; - } -} - const std::vector& CModelFile::GetTriangles() { return m_triangles; @@ -1258,28 +1146,6 @@ int CModelFile::GetTriangleCount() return m_triangles.size(); } -float CModelFile::GetHeight(Math::Vector pos) -{ - float limit = 5.0f; - - for (int i = 0; i < static_cast( m_triangles.size() ); i++) - { - if ( fabs(pos.x - m_triangles[i].p1.coord.x) < limit && - fabs(pos.z - m_triangles[i].p1.coord.z) < limit ) - return m_triangles[i].p1.coord.y; - - if ( fabs(pos.x - m_triangles[i].p2.coord.x) < limit && - fabs(pos.z - m_triangles[i].p2.coord.z) < limit ) - return m_triangles[i].p2.coord.y; - - if ( fabs(pos.x - m_triangles[i].p3.coord.x) < limit && - fabs(pos.z - m_triangles[i].p3.coord.z) < limit ) - return m_triangles[i].p3.coord.y; - } - - return 0.0f; -} - void CModelFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max) { ModelTriangle triangle; -- cgit v1.2.3-1-g7c22 From a937a7b6ec081ab546505e5ab1fcd9b3723a6f4b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 27 Jan 2013 11:43:53 +0100 Subject: Changed model min/max to LOD levels --- src/graphics/engine/modelfile.cpp | 146 +++++++++++++++++++++++--------------- 1 file changed, 90 insertions(+), 56 deletions(-) (limited to 'src/graphics/engine/modelfile.cpp') diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index a942b08..c9d41f3 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -495,8 +495,7 @@ bool CModelFile::ReadModel(std::istream& stream) triangle.material = t.material; triangle.tex1Name = std::string(t.texName); - triangle.min = t.min; - triangle.max = t.max; + triangle.lodLevel = MinMaxToLodLevel(t.min, t.max); m_triangles.push_back(triangle); } @@ -539,8 +538,7 @@ bool CModelFile::ReadModel(std::istream& stream) triangle.material = t.material; triangle.tex1Name = std::string(t.texName); - triangle.min = t.min; - triangle.max = t.max; + triangle.lodLevel = MinMaxToLodLevel(t.min, t.max); triangle.state = t.state; m_triangles.push_back(triangle); @@ -584,8 +582,7 @@ bool CModelFile::ReadModel(std::istream& stream) triangle.material = t.material; triangle.tex1Name = std::string(t.texName); - triangle.min = t.min; - triangle.max = t.max; + triangle.lodLevel = MinMaxToLodLevel(t.min, t.max); triangle.state = t.state; triangle.variableTex2 = t.texNum2 == 1; @@ -634,7 +631,7 @@ bool CModelFile::ReadModel(std::istream& stream) GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), m_triangles[i].variableTex2 ? "(variable)" : m_triangles[i].tex2Name.c_str()); - GetLogger()->Trace(" min: %.2f max: %.2f\n", m_triangles[i].min, m_triangles[i].max); + GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); } @@ -685,8 +682,7 @@ bool CModelFile::WriteModel(std::ostream& stream) t.material = m_triangles[i].material; strncpy(t.texName, m_triangles[i].tex1Name.c_str(), 20); - t.min = m_triangles[i].min; - t.max = m_triangles[i].max; + LODLevelToMinMax(m_triangles[i].lodLevel, t.min, t.max); t.state = m_triangles[i].state; int no = 0; @@ -722,6 +718,46 @@ bool CModelFile::WriteModel(std::ostream& stream) return true; } +LODLevel CModelFile::MinMaxToLodLevel(float min, float max) +{ + if (min == 0.0f && max == 100.0f) + return LOD_High; + else if (min == 100.0f && max == 200.0f) + return LOD_Medium; + else if (min == 200.0f && max == 1000000.0f) + return LOD_Low; + else if (min == 0.0f && max == 1000000.0f) + return LOD_Constant; + + return LOD_Constant; +} + +void CModelFile::LODLevelToMinMax(LODLevel lodLevel, float& min, float& max) +{ + switch (lodLevel) + { + case LOD_High: + min = 0.0f; + max = 100.0f; + break; + + case LOD_Medium: + min = 100.0f; + max = 200.0f; + break; + + case LOD_Low: + min = 200.0f; + max = 1000000.0f; + break; + + case LOD_Constant: + min = 0.0f; + max = 1000000.0f; + break; + } +} + /******************************************************* New formats @@ -768,17 +804,15 @@ struct NewModelTriangle1 std::string tex2Name; //! If true, 2nd texture will be taken from current engine setting bool variableTex2; - //! Min LOD threshold - float min; - //! Max LOD threshold - float max; + //! LOD level + int lodLevel; //! Rendering state to be set int state; NewModelTriangle1() { variableTex2 = true; - min = max = 0.0f; + lodLevel = 0; state = 0; } }; @@ -834,8 +868,7 @@ bool CModelFile::ReadTextModel(std::istream& stream) ReadLineValue(stream, "tex1", t.tex1Name) && ReadLineValue(stream, "tex2", t.tex2Name) && ReadLineValue(stream, "var_tex2", varTex2Ch) && - ReadLineValue(stream, "min", t.min) && - ReadLineValue(stream, "max", t.max) && + ReadLineValue(stream, "lod_level", t.lodLevel) && ReadLineValue(stream, "state", t.state); if (!triOk || stream.fail()) @@ -855,10 +888,17 @@ bool CModelFile::ReadTextModel(std::istream& stream) triangle.tex1Name = t.tex1Name; triangle.tex2Name = t.tex2Name; triangle.variableTex2 = t.variableTex2; - triangle.min = t.min; - triangle.max = t.max; triangle.state = t.state; + switch (t.lodLevel) + { + case 0: triangle.lodLevel = LOD_Constant; break; + case 1: triangle.lodLevel = LOD_Low; break; + case 2: triangle.lodLevel = LOD_Medium; break; + case 3: triangle.lodLevel = LOD_High; break; + default: break; + } + m_triangles.push_back(triangle); continue; @@ -886,7 +926,7 @@ bool CModelFile::ReadTextModel(std::istream& stream) GetLogger()->Trace(" mat: d: %s a: %s s: %s\n", d.c_str(), a.c_str(), s.c_str()); GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), m_triangles[i].tex2Name.c_str()); - GetLogger()->Trace(" min: %.2f max: %.2f\n", m_triangles[i].min, m_triangles[i].max); + GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); } @@ -938,10 +978,16 @@ bool CModelFile::WriteTextModel(std::ostream& stream) t.tex1Name = m_triangles[i].tex1Name; t.tex2Name = m_triangles[i].tex2Name; t.variableTex2 = m_triangles[i].variableTex2; - t.min = m_triangles[i].min; - t.max = m_triangles[i].max; t.state = m_triangles[i].state; + switch (m_triangles[i].lodLevel) + { + case LOD_Constant: t.lodLevel = 0; break; + case LOD_Low: t.lodLevel = 1; break; + case LOD_Medium: t.lodLevel = 2; break; + case LOD_High: t.lodLevel = 3; break; + } + stream << "p1 "; WriteTextVertexTex2(t.p1, stream); stream << "p2 "; @@ -954,8 +1000,7 @@ bool CModelFile::WriteTextModel(std::ostream& stream) stream << "tex1 " << t.tex1Name << std::endl; stream << "tex2 " << t.tex2Name << std::endl; stream << "var_tex2 " << (t.variableTex2 ? 'Y' : 'N') << std::endl; - stream << "min " << t.min << std::endl; - stream << "max " << t.max << std::endl; + stream << "lod_level " << t.lodLevel << std::endl; stream << "state " << t.state << std::endl; stream << std::endl; @@ -1012,9 +1057,8 @@ bool CModelFile::ReadBinaryModel(std::istream& stream) t.tex1Name = IOUtils::ReadBinaryString<1>(stream); t.tex2Name = IOUtils::ReadBinaryString<1>(stream); t.variableTex2 = IOUtils::ReadBinaryBool(stream); - t.min = IOUtils::ReadBinaryFloat(stream); - t.max = IOUtils::ReadBinaryFloat(stream); - t.state = IOUtils::ReadBinary<4, unsigned int>(stream); + t.lodLevel = IOUtils::ReadBinary<4, int>(stream); + t.state = IOUtils::ReadBinary<4, int>(stream); if (stream.fail()) { @@ -1030,10 +1074,17 @@ bool CModelFile::ReadBinaryModel(std::istream& stream) triangle.tex1Name = t.tex1Name; triangle.tex2Name = t.tex2Name; triangle.variableTex2 = t.variableTex2; - triangle.min = t.min; - triangle.max = t.max; triangle.state = t.state; + switch (t.lodLevel) + { + case 0: triangle.lodLevel = LOD_Constant; break; + case 1: triangle.lodLevel = LOD_Low; break; + case 2: triangle.lodLevel = LOD_Medium; break; + case 3: triangle.lodLevel = LOD_High; break; + default: break; + } + m_triangles.push_back(triangle); } } @@ -1059,7 +1110,7 @@ bool CModelFile::ReadBinaryModel(std::istream& stream) GetLogger()->Trace(" mat: d: %s a: %s s: %s\n", d.c_str(), a.c_str(), s.c_str()); GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), m_triangles[i].tex2Name.c_str()); - GetLogger()->Trace(" min: %.2f max: %.2f\n", m_triangles[i].min, m_triangles[i].max); + GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); } @@ -1106,10 +1157,16 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) t.tex1Name = m_triangles[i].tex1Name; t.tex2Name = m_triangles[i].tex2Name; t.variableTex2 = m_triangles[i].variableTex2; - t.min = m_triangles[i].min; - t.max = m_triangles[i].max; t.state = m_triangles[i].state; + switch (m_triangles[i].lodLevel) + { + case LOD_Constant: t.lodLevel = 0; break; + case LOD_Low: t.lodLevel = 1; break; + case LOD_Medium: t.lodLevel = 2; break; + case LOD_High: t.lodLevel = 3; break; + } + WriteBinaryVertexTex2(t.p1, stream); WriteBinaryVertexTex2(t.p2, stream); WriteBinaryVertexTex2(t.p3, stream); @@ -1117,9 +1174,8 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) IOUtils::WriteBinaryString<1>(t.tex1Name, stream); IOUtils::WriteBinaryString<1>(t.tex2Name, stream); IOUtils::WriteBinaryBool(t.variableTex2, stream); - IOUtils::WriteBinaryFloat(t.min, stream); - IOUtils::WriteBinaryFloat(t.max, stream); - IOUtils::WriteBinary<4, unsigned int>(t.state, stream); + IOUtils::WriteBinary<4, int>(t.lodLevel, stream); + IOUtils::WriteBinary<4, int>(t.state, stream); if (stream.fail()) { @@ -1132,10 +1188,6 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream) } -/******************************************************* - Other stuff - *******************************************************/ - const std::vector& CModelFile::GetTriangles() { return m_triangles; @@ -1146,23 +1198,5 @@ int CModelFile::GetTriangleCount() return m_triangles.size(); } -void CModelFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max) -{ - ModelTriangle triangle; - - Math::Vector n = Math::NormalToPlane(p3, p2, p1); - triangle.p1 = VertexTex2(p1, n); - triangle.p2 = VertexTex2(p2, n); - triangle.p3 = VertexTex2(p3, n); - - triangle.material.diffuse = Color(1.0f, 1.0f, 1.0f, 0.0f); - triangle.material.ambient = Color(0.5f, 0.5f, 0.5f, 0.0f); - - triangle.min = min; - triangle.max = max; - - m_triangles.push_back(triangle); -} - } // namespace Gfx -- cgit v1.2.3-1-g7c22 From 001d37b257b126dd6ef1dced70f94ff3d2806d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Dziwi=C5=84ski?= Date: Sat, 16 Feb 2013 22:37:43 +0100 Subject: CInstanceManager refactoring * removed classes managed by CInstanceManager except for CObject, CPyro, CBrain and CPhysics because of dependencies * refactored instance searching to use existing singleton instances of CApplication, CEngine and CRobotMain and calling their getter functions --- src/graphics/engine/modelfile.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/graphics/engine/modelfile.cpp') diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index c9d41f3..f6d7a7b 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -18,7 +18,6 @@ #include "graphics/engine/modelfile.h" -#include "common/iman.h" #include "common/ioutils.h" #include "common/logger.h" #include "common/stringutils.h" -- cgit v1.2.3-1-g7c22