From 043ef610f24579c3cd127a1669bbeeb91c297207 Mon Sep 17 00:00:00 2001 From: milek7 Date: Sat, 12 Mar 2022 18:39:32 +0100 Subject: [PATCH] add vertex deduplication range to config, multiply tolerancescale through whole chain --- Globals.cpp | 5 +++++ Globals.h | 1 + Model3d.cpp | 15 ++++++++++----- Model3d.h | 1 + geometrybank.cpp | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Globals.cpp b/Globals.cpp index c3bddd01..1d18f452 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -488,6 +488,11 @@ global_settings::ConfigParse(cParser &Parser) { Parser.getTokens(1, false); Parser >> iConvertModels; } + else if (token == "convertindexrange") + { + Parser.getTokens(1, false); + Parser >> iConvertIndexRange; + } else if (token == "file.binary.terrain") { // binary terrain (de)serialization diff --git a/Globals.h b/Globals.h index 5431795c..672fa96a 100644 --- a/Globals.h +++ b/Globals.h @@ -70,6 +70,7 @@ struct global_settings { std::string SceneryFile; std::string local_start_vehicle{ "EU07-424" }; int iConvertModels{ 0 }; // tworzenie plików binarnych + int iConvertIndexRange{ 1000 }; // range of duplicate vertex scan bool file_binary_terrain{ true }; // enable binary terrain (de)serialization // logs int iWriteLogEnabled{ 3 }; // maska bitowa: 1-zapis do pliku, 2-okienko, 4-nazwy torów diff --git a/Model3d.cpp b/Model3d.cpp index 73571147..7d5c8b5c 100644 --- a/Model3d.cpp +++ b/Model3d.cpp @@ -455,7 +455,8 @@ std::pair TSubModel::Load( cParser &parser, bool dynamic ) // transformation matrix fMatrix = new float4x4(); readMatrix(parser, *fMatrix); // wczytanie transform - float transformscale = 1.0f; + if (Parent != nullptr) + transformscalestack = Parent->transformscalestack; if( !fMatrix->IdentityIs() ) { iFlags |= 0x8000; // transform niejedynkowy - trzeba go przechować // check the scaling @@ -473,7 +474,7 @@ std::pair TSubModel::Load( cParser &parser, bool dynamic ) rescale : normalize ); } - transformscale = (scale.x + scale.y + scale.z) / 3.0f; + transformscalestack *= (scale.x + scale.y + scale.z) / 3.0f; } if (eType < TP_ROTATOR) { // wczytywanie wierzchołków @@ -655,7 +656,7 @@ std::pair TSubModel::Load( cParser &parser, bool dynamic ) } } Vertices.resize( m_geometry.vertex_count ); // in case we had some degenerate triangles along the way - gfx::calculate_indices( Indices, Vertices, transformscale ); + gfx::calculate_indices( Indices, Vertices, transformscalestack ); gfx::calculate_tangents( Vertices, Indices, GL_TRIANGLES ); // update values potentially changed by indexing m_geometry.index_count = Indices.size(); @@ -2195,13 +2196,17 @@ void TModel3d::LoadFromTextFile(std::string const &FileName, bool dynamic) break; } SubModel = new TSubModel(); + SubModel->Parent = GetFromName(parent); + if (SubModel->Parent == nullptr && parent != "none") + ErrorLog("Bad model: parent for sub-model \"" + SubModel->pName +"\" doesn't exist or is located later in the model data", logtype::model); + { auto const result { SubModel->Load( parser, dynamic ) }; m_indexcount += result.first; m_vertexcount += result.second; } - // będzie potrzebne do wyliczenia pozycji, np. pantografu - SubModel->Parent = AddToNamed(parent.c_str(), SubModel); + + AddTo(SubModel->Parent, SubModel); parser.getTokens(); parser >> token; diff --git a/Model3d.h b/Model3d.h index d1fd83e7..256c583a 100644 --- a/Model3d.h +++ b/Model3d.h @@ -105,6 +105,7 @@ private: float4x4 *fMatrix = nullptr; // pojedyncza precyzja wystarcza int iMatrix; // w pliku binarnym jest numer matrycy }; + float transformscalestack { 1.0f }; // tolerancescale used in calculate_indices for whole matrix chain int iTexture { 0 }; // numer nazwy tekstury, -1 wymienna, 0 brak float fLight { -1.0f }; // próg jasności światła do zadziałania selfillum glm::vec4 diff --git a/geometrybank.cpp b/geometrybank.cpp index 00301c27..47dd316c 100644 --- a/geometrybank.cpp +++ b/geometrybank.cpp @@ -202,7 +202,7 @@ void calculate_indices( index_array &Indices, vertex_array &Vertices, float tole // if found, remap these to use our current vertex instead auto vertex { Vertices[ idx ] }; auto matchiter { std::cbegin( Vertices ) + idx }; - for( auto matchidx = idx + 1; matchidx < Indices.size() && matchidx < idx + 1000; ++matchidx ) { + for( auto matchidx = idx + 1; matchidx < Indices.size() && matchidx < idx + Global.iConvertIndexRange; ++matchidx ) { ++matchiter; if( ( glm::all( glm::epsilonEqual( vertex.position, matchiter->position, matchtolerance ) ) ) && ( glm::all( glm::epsilonEqual( vertex.normal, matchiter->normal, matchtolerance ) ) )