16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 16:19:19 +02:00

scale matchtolerance, add VNT2 chunk type

This commit is contained in:
milek7
2020-10-19 16:47:25 +02:00
parent 6a48293a40
commit 181249b1e7
3 changed files with 28 additions and 12 deletions

View File

@@ -487,6 +487,7 @@ std::pair<int, int> TSubModel::Load( cParser &parser, bool dynamic )
// transformation matrix // transformation matrix
fMatrix = new float4x4(); fMatrix = new float4x4();
readMatrix(parser, *fMatrix); // wczytanie transform readMatrix(parser, *fMatrix); // wczytanie transform
float transformscale = 1.0f;
if( !fMatrix->IdentityIs() ) { if( !fMatrix->IdentityIs() ) {
iFlags |= 0x8000; // transform niejedynkowy - trzeba go przechować iFlags |= 0x8000; // transform niejedynkowy - trzeba go przechować
// check the scaling // check the scaling
@@ -504,6 +505,7 @@ std::pair<int, int> TSubModel::Load( cParser &parser, bool dynamic )
rescale : rescale :
normalize ); normalize );
} }
transformscale = (scale.x + scale.y + scale.z) / 3.0f;
} }
if (eType < TP_ROTATOR) if (eType < TP_ROTATOR)
{ // wczytywanie wierzchołków { // wczytywanie wierzchołków
@@ -685,7 +687,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 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 ); gfx::calculate_tangents( Vertices, Indices, GL_TRIANGLES );
// update values potentially changed by indexing // update values potentially changed by indexing
m_geometry.index_count = Indices.size(); m_geometry.index_count = Indices.size();
@@ -1706,9 +1708,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, MAKE_ID4( 'I', 'D', 'X', '0' + indexsize ) );
sn_utils::ls_uint32( s, 8 + m_indexcount * indexsize ); sn_utils::ls_uint32( s, 8 + m_indexcount * indexsize );
Root->serialize_indices( s, 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 ); if (!(Global.iConvertModels & 8)) {
Root->serialize_geometry( s, true, true ); 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 { else {
sn_utils::ls_uint32( s, MAKE_ID4( 'V', 'N', 'T', '0' ) ); sn_utils::ls_uint32( s, MAKE_ID4( 'V', 'N', 'T', '0' ) );
@@ -1850,16 +1860,22 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
auto const &submodelgeometry { submodel.m_geometry }; auto const &submodelgeometry { submodel.m_geometry };
submodel.Vertices.resize( submodelgeometry.vertex_count ); submodel.Vertices.resize( submodelgeometry.vertex_count );
m_vertexcount += submodelgeometry.vertex_count; m_vertexcount += submodelgeometry.vertex_count;
if( vertextype > 0 ) { if (vertextype == 1) {
// expanded chunk formats // expanded chunk formats
for( auto &vertex : submodel.Vertices ) { 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 // legacy vnt0 format
for( auto &vertex : submodel.Vertices ) { for( auto &vertex : submodel.Vertices ) {
vertex.deserialize( s, vertextype > 0 ); vertex.deserialize( s, false );
if( submodel.eType < TP_ROTATOR ) { if( submodel.eType < TP_ROTATOR ) {
// normal vectors debug routine // normal vectors debug routine
if( ( false == submodel.m_normalizenormals ) if( ( false == submodel.m_normalizenormals )

View File

@@ -183,14 +183,14 @@ void calculate_tangents(vertex_array &vertices, const index_array &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() ); Indices.resize( Vertices.size() );
std::iota( std::begin( Indices ), std::end( Indices ), 0 ); std::iota( std::begin( Indices ), std::end( Indices ), 0 );
// gather instances of used verices, replace the original vertex bank with it after you're done // gather instances of used verices, replace the original vertex bank with it after you're done
vertex_array indexedvertices; vertex_array indexedvertices;
indexedvertices.reserve( std::max<size_t>( 100, Vertices.size() / 3 ) ); // optimistic guesstimate, but should reduce re-allocation somewhat 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 ) { for( auto idx = 0; idx < Indices.size(); ++idx ) {
if( Indices[ idx ] < 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 // this index is pointing to a vertex out of linear order, i.e. it's an already processed duplicate we can skip

View File

@@ -52,8 +52,8 @@ using basic_index = std::uint32_t;
using vertex_array = std::vector<basic_vertex>; using vertex_array = std::vector<basic_vertex>;
using index_array = std::vector<basic_index>; using index_array = std::vector<basic_index>;
void calculate_tangents(vertex_array &vertices, const index_array &indices, int type ); void calculate_tangents(vertex_array &vertices, const index_array &indices, int 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 // generic geometry bank class, allows storage, update and drawing of geometry chunks