diff --git a/Model3d.cpp b/Model3d.cpp index f0ba3e02..7aa88410 100644 --- a/Model3d.cpp +++ b/Model3d.cpp @@ -480,6 +480,7 @@ std::pair TSubModel::Load( cParser &parser, bool dynamic ) // transformation matrix fMatrix = new float4x4(); readMatrix(parser, *fMatrix); // wczytanie transform + float transformscale = 1.0f; if( !fMatrix->IdentityIs() ) { iFlags |= 0x8000; // transform niejedynkowy - trzeba go przechować // check the scaling @@ -497,6 +498,7 @@ std::pair TSubModel::Load( cParser &parser, bool dynamic ) rescale : normalize ); } + transformscale = (scale.x + scale.y + scale.z) / 3.0f; } if (eType < TP_ROTATOR) { // wczytywanie wierzchołków @@ -678,7 +680,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 ); + gfx::calculate_indices( Indices, Vertices, transformscale ); gfx::calculate_tangents( Vertices, Indices, GL_TRIANGLES ); // update values potentially changed by indexing m_geometry.index_count = Indices.size(); @@ -1689,9 +1691,17 @@ void TModel3d::SaveToBinFile(std::string const &FileName) sn_utils::ls_uint32( s, MAKE_ID4( 'I', 'D', 'X', '0' + indexsize ) ); sn_utils::ls_uint32( s, 8 + m_indexcount * indexsize ); Root->serialize_indices( s, indexsize ); - sn_utils::ls_uint32( s, MAKE_ID4( 'V', 'N', 'T', '1' ) ); - sn_utils::ls_uint32( s, 8 + m_vertexcount * 20 ); - Root->serialize_geometry( s, true, true ); + + if (!(Global.iConvertModels & 8)) { + sn_utils::ls_uint32( s, MAKE_ID4( 'V', 'N', 'T', '1' ) ); + sn_utils::ls_uint32( s, 8 + m_vertexcount * 20 ); + Root->serialize_geometry( s, true, true ); + } + else { + sn_utils::ls_uint32( s, MAKE_ID4( 'V', 'N', 'T', '2' ) ); + sn_utils::ls_uint32( s, 8 + m_vertexcount * 48 ); + Root->serialize_geometry( s, false, true ); + } } else { sn_utils::ls_uint32( s, MAKE_ID4( 'V', 'N', 'T', '0' ) ); @@ -1833,16 +1843,22 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic) auto const &submodelgeometry { submodel.m_geometry }; submodel.Vertices.resize( submodelgeometry.vertex_count ); m_vertexcount += submodelgeometry.vertex_count; - if( vertextype > 0 ) { + if (vertextype == 1) { // expanded chunk formats for( auto &vertex : submodel.Vertices ) { - vertex.deserialize_packed( s, vertextype > 0 ); + vertex.deserialize_packed( s, true ); } } - else { + else if (vertextype == 2) { + // expanded chunk formats + for( auto &vertex : submodel.Vertices ) { + vertex.deserialize( s, true ); + } + } + else if (vertextype == 0) { // legacy vnt0 format for( auto &vertex : submodel.Vertices ) { - vertex.deserialize( s, vertextype > 0 ); + vertex.deserialize( s, false ); if( submodel.eType < TP_ROTATOR ) { // normal vectors debug routine if( ( false == submodel.m_normalizenormals ) diff --git a/geometrybank.cpp b/geometrybank.cpp index 07c61fb6..2ed930d9 100644 --- a/geometrybank.cpp +++ b/geometrybank.cpp @@ -185,14 +185,14 @@ void calculate_tangents(vertex_array &vertices, index_array const &indices, int } } -void calculate_indices( index_array &Indices, vertex_array &Vertices ) { +void calculate_indices( index_array &Indices, vertex_array &Vertices, float tolerancescale ) { Indices.resize( Vertices.size() ); std::iota( std::begin( Indices ), std::end( Indices ), 0 ); // gather instances of used vertices, replace the original vertex bank with it after you're done vertex_array indexedvertices; indexedvertices.reserve( std::max( 100, Vertices.size() / 3 ) ); // optimistic guesstimate, but should reduce re-allocation somewhat - auto const matchtolerance { 1e-5f }; + auto const matchtolerance { 1e-5f * tolerancescale }; for( auto idx = 0; idx < Indices.size(); ++idx ) { if( Indices[ idx ] < idx ) { // this index is pointing to a vertex out of linear order, i.e. it's an already processed duplicate we can skip diff --git a/geometrybank.h b/geometrybank.h index 0d2a9b08..0c0ec075 100644 --- a/geometrybank.h +++ b/geometrybank.h @@ -53,7 +53,7 @@ using vertex_array = std::vector; using index_array = std::vector; void calculate_tangents( vertex_array &vertices, index_array const &indices, int const type ); -void calculate_indices( index_array &Indices, vertex_array &Vertices ); +void calculate_indices( index_array &Indices, vertex_array &Vertices, float tolerancescale = 1.0f ); // generic geometry bank class, allows storage, update and drawing of geometry chunks