mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
Merge remote-tracking branch 'tmj/master' into sim
This commit is contained in:
55
Model3d.cpp
55
Model3d.cpp
@@ -1813,6 +1813,7 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::streampos end = s.tellg() + (std::streampos)size;
|
std::streampos end = s.tellg() + (std::streampos)size;
|
||||||
|
bool hastangents { false };
|
||||||
|
|
||||||
while (s.tellg() < end)
|
while (s.tellg() < end)
|
||||||
{
|
{
|
||||||
@@ -1856,35 +1857,44 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
|||||||
return (Left.first) < (Right.first); } );
|
return (Left.first) < (Right.first); } );
|
||||||
// once sorted we can grab geometry as it comes, and assign it to the chunks it belongs to
|
// once sorted we can grab geometry as it comes, and assign it to the chunks it belongs to
|
||||||
size_t const vertextype { ( ( ( type & 0xFF000000 ) >> 24 ) - '0' ) };
|
size_t const vertextype { ( ( ( type & 0xFF000000 ) >> 24 ) - '0' ) };
|
||||||
|
hastangents = ( vertextype > 0 );
|
||||||
for( auto const &submodeloffset : submodeloffsets ) {
|
for( auto const &submodeloffset : submodeloffsets ) {
|
||||||
auto &submodel { Root[ submodeloffset.second ] };
|
auto &submodel { Root[ submodeloffset.second ] };
|
||||||
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 == 1) {
|
switch( vertextype ) {
|
||||||
// expanded chunk formats
|
case 0: {
|
||||||
for( auto &vertex : submodel.Vertices ) {
|
|
||||||
vertex.deserialize_packed( s, true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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, false );
|
vertex.deserialize( s, hastangents );
|
||||||
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 )
|
||||||
&& ( std::abs( glm::length2( vertex.normal ) - 1.0f ) > 0.01f ) ) {
|
&& ( std::abs( glm::length2( vertex.normal ) - 1.0f ) > 0.01f ) ) {
|
||||||
submodel.m_normalizenormals = TSubModel::normalize; // we don't know if uniform scaling would suffice
|
submodel.m_normalizenormals = TSubModel::normalize; // we don't know if uniform scaling would suffice
|
||||||
WriteLog( "Bad model: non-unit normal vector(s) encountered during sub-model geometry deserialization", logtype::model );
|
WriteLog( "Bad model: non-unit normal vector(s) encountered during sub-model geometry deserialization", logtype::model );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
// expanded chunk formats
|
||||||
|
for( auto &vertex : submodel.Vertices ) {
|
||||||
|
vertex.deserialize_packed( s, hastangents );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
// expanded chunk formats
|
||||||
|
for( auto &vertex : submodel.Vertices ) {
|
||||||
|
vertex.deserialize( s, hastangents );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2006,6 +2016,9 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( false == hastangents ) {
|
||||||
|
gfx::calculate_tangents( Root[i].Vertices, Root[i].Indices, type );
|
||||||
|
}
|
||||||
Root[i].m_geometry.handle = GfxRenderer->Insert( Root[i].Indices, Root[i].Vertices, m_geometrybank, type );
|
Root[i].m_geometry.handle = GfxRenderer->Insert( Root[i].Indices, Root[i].Vertices, m_geometrybank, type );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user