mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-23 00:29:19 +02:00
binary model vertex tangent calculation fix
This commit is contained in:
41
Model3d.cpp
41
Model3d.cpp
@@ -1795,6 +1795,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)
|
||||||
{
|
{
|
||||||
@@ -1838,27 +1839,17 @@ 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 )
|
||||||
@@ -1868,6 +1859,25 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1984,6 +1994,9 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( ( false == hastangents ) && ( type >= GL_TRIANGLES ) && ( type <= GL_TRIANGLE_FAN ) ) {
|
||||||
|
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