scale matchtolerance, add VNT2 chunk type

This commit is contained in:
milek7
2020-10-19 16:47:25 +02:00
committed by tmj-fstate
parent f9a8c1fbb3
commit b0d46b9ddc
3 changed files with 27 additions and 11 deletions

View File

@@ -480,6 +480,7 @@ std::pair<int, int> 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<int, int> 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<int, int> 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 )

View File

@@ -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<size_t>( 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

View File

@@ -53,7 +53,7 @@ using vertex_array = std::vector<basic_vertex>;
using index_array = std::vector<basic_index>;
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