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

submodel location calculation fix for t3d files

This commit is contained in:
tmj-fstate
2018-01-02 20:35:02 +01:00
parent fdb99eedc6
commit ba26ad1918
2 changed files with 36 additions and 37 deletions

View File

@@ -653,13 +653,14 @@ void TSubModel::InitialRotate(bool doit)
if (fMatrix->IdentityIs()) if (fMatrix->IdentityIs())
iFlags &= ~0x8000; // jednak jednostkowa po obróceniu iFlags &= ~0x8000; // jednak jednostkowa po obróceniu
} }
if (Child) if( Child ) {
Child->InitialRotate(false); // potomnych nie obracamy już, tylko // potomnych nie obracamy już, tylko ewentualnie optymalizujemy
// ewentualnie optymalizujemy Child->InitialRotate( false );
else if (Global::iConvertModels & 2) // optymalizacja jest opcjonalna }
else if (Global::iConvertModels & 2) {
// optymalizacja jest opcjonalna
if ((iFlags & 0xC000) == 0x8000) // o ile nie ma animacji if ((iFlags & 0xC000) == 0x8000) // o ile nie ma animacji
{ // jak nie ma potomnych, można wymnożyć przez transform i wyjedynkować { // jak nie ma potomnych, można wymnożyć przez transform i wyjedynkować go
// go
float4x4 *mat = GetMatrix(); // transform submodelu float4x4 *mat = GetMatrix(); // transform submodelu
if( false == Vertices.empty() ) { if( false == Vertices.empty() ) {
for( auto &vertex : Vertices ) { for( auto &vertex : Vertices ) {
@@ -681,6 +682,7 @@ void TSubModel::InitialRotate(bool doit)
iFlags &= ~0x8000; // transform jedynkowy iFlags &= ~0x8000; // transform jedynkowy
} }
} }
}
else // jak jest jednostkowy i nie ma animacji else // jak jest jednostkowy i nie ma animacji
if (doit) if (doit)
{ // jeśli jest jednostkowy transform, to przeliczamy { // jeśli jest jednostkowy transform, to przeliczamy
@@ -1169,7 +1171,7 @@ TSubModel::offset( float const Geometrytestoffsetthreshold ) const {
// for such cases we resort to an estimate from submodel geometry // for such cases we resort to an estimate from submodel geometry
// TODO: do proper bounding area calculation for submodel when loading mesh and grab the centre point from it here // TODO: do proper bounding area calculation for submodel when loading mesh and grab the centre point from it here
if( m_geometry != null_handle ) { if( m_geometry != null_handle ) {
auto const &vertices{ GfxRenderer.Vertices( m_geometry ) }; auto const &vertices { GfxRenderer.Vertices( m_geometry ) };
if( false == vertices.empty() ) { if( false == vertices.empty() ) {
// transformation matrix for the submodel can still contain rotation and/or scaling, // transformation matrix for the submodel can still contain rotation and/or scaling,
// so we pass the vertex positions through it rather than just grab them directly // so we pass the vertex positions through it rather than just grab them directly
@@ -1183,6 +1185,16 @@ TSubModel::offset( float const Geometrytestoffsetthreshold ) const {
} }
} }
if( true == TestFlag( iFlags, 0x0200 ) ) {
// flip coordinates for t3d file which wasn't yet initialized
if( std::abs( offset.y ) > offset.z ) {
// NOTE, HACK: results require flipping if the model wasn't yet initialized, so we're using crude method to detect possible cases
// TODO: sort out this mess, either unify offset lookups to take place before (or after) initialization,
// or provide way to determine on submodel level whether the initialization took place
offset = { -offset.x, offset.z, offset.y };
}
}
return offset; return offset;
} }

View File

@@ -5690,14 +5690,12 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
*parser >> token; *parser >> token;
if (token != "none") if (token != "none")
{ {
// bieżąca sciezka do tekstur to dynamic/...
Global::asCurrentTexturePath = Global::asCurrentTexturePath = DynamicObject->asBaseDir;
DynamicObject->asBaseDir; // bieżąca sciezka do tekstur to dynamic/... // szukaj kabinę jako oddzielny model
TModel3d *kabina = TModel3d *kabina = TModelsManager::GetModel(DynamicObject->asBaseDir + token, true);
TModelsManager::GetModel(DynamicObject->asBaseDir + token, // z powrotem defaultowa sciezka do tekstur
true); // szukaj kabinę jako oddzielny model Global::asCurrentTexturePath = szTexturePath;
Global::asCurrentTexturePath =
szTexturePath; // z powrotem defaultowa sciezka do tekstur
// if (DynamicObject->mdKabina!=k) // if (DynamicObject->mdKabina!=k)
if (kabina != nullptr) if (kabina != nullptr)
{ {
@@ -5708,16 +5706,11 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
// else // else
// break; //wyjście z pętli, bo model zostaje bez zmian // break; //wyjście z pętli, bo model zostaje bez zmian
} }
else if (cabindex == 1) else if (cabindex == 1) {
{
// model tylko, gdy nie ma kabiny 1 // model tylko, gdy nie ma kabiny 1
DynamicObject->mdKabina = // McZapkie-170103: szukaj elementy kabiny w glownym modelu
DynamicObject DynamicObject->mdKabina = DynamicObject->mdModel;
->mdModel; // McZapkie-170103: szukaj elementy kabiny w glownym modelu
} }
/*
Universal4Active = false;
*/
clear_cab_controls(); clear_cab_controls();
} }
if (nullptr == DynamicObject->mdKabina) if (nullptr == DynamicObject->mdKabina)
@@ -5737,8 +5730,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
} }
else if (token == "pyscreen:") else if (token == "pyscreen:")
{ {
pyScreens.init(*parser, DynamicObject->mdKabina, DynamicObject->name(), pyScreens.init(*parser, DynamicObject->mdKabina, DynamicObject->name(), NewCabNo);
NewCabNo);
} }
// btLampkaUnknown.Init("unknown",mdKabina,false); // btLampkaUnknown.Init("unknown",mdKabina,false);
} while (token != ""); } while (token != "");
@@ -5750,9 +5742,6 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
pyScreens.start(); pyScreens.start();
if (DynamicObject->mdKabina) if (DynamicObject->mdKabina)
{ {
DynamicObject->mdKabina->Init(); // obrócenie modelu oraz optymalizacja, również zapisanie binarnego
set_cab_controls();
// configure placement of sound emitters which aren't bound with any device model, and weren't placed manually // configure placement of sound emitters which aren't bound with any device model, and weren't placed manually
// try first to bind sounds to location of possible devices // try first to bind sounds to location of possible devices
if( dsbReverserKey.offset() == nullvector ) { if( dsbReverserKey.offset() == nullvector ) {
@@ -5800,12 +5789,10 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
sound->offset( caboffset ); sound->offset( caboffset );
} }
} }
/*
// HACK: for some reason simulation at the start is slow until a sound is played DynamicObject->mdKabina->Init(); // obrócenie modelu oraz optymalizacja, również zapisanie binarnego
// until we do a proper fix, try to play a 'silent' sound when cab is entered set_cab_controls();
// TBD: it could be instead a legit sound of door closing
play_sound( dsbSwitch, DSBVOLUME_MIN );
*/
return true; return true;
} }
return (token == "none"); return (token == "none");