18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-18 02:26:00 +01:00

Merge pull request #293 from MaSzyna-EU07/fix/door-inner-faces-lowpoly-lighting

Door wings: let the low poly interior have its own, moving inside of the doors (eu07/maszyna#512)
This commit is contained in:
2026-11-09 12:47:58 +00:00
committed by GitHub
4 changed files with 192 additions and 57 deletions

View File

@@ -0,0 +1,54 @@
#include "stdafx.h"
#include "doctest.h"
#include "vehicle/doorwings.h"
// the poses of the animated door wings (eu07/maszyna#512): a wing of the main model and its namesake in the low
// poly interior get the same pose, worked out once from the door position of the mover
TEST_CASE("door wings: only the door animations move wings") {
CHECK(door_wings::is_wing(0x010)); // TAnim::TypeSet for the doors
CHECK_FALSE(door_wings::is_wing(0x000)); // axles
CHECK_FALSE(door_wings::is_wing(0x055)); // pantographs, five submodels
CHECK_FALSE(door_wings::is_wing(0x070)); // doorsteps
CHECK_FALSE(door_wings::is_wing(0x080)); // mirrors
CHECK(door_wings::is_wing(0x210)); // the parameter count in the upper bits doesn't matter
}
TEST_CASE("door wings: odd wings are on the left, even ones on the right") {
CHECK_FALSE(door_wings::on_right_side(1));
CHECK(door_wings::on_right_side(2));
CHECK_FALSE(door_wings::on_right_side(3));
CHECK(door_wings::on_right_side(4));
}
TEST_CASE("door wings: a sliding wing shifts along the vehicle by the door position") {
CHECK(door_wings::slide(0.f) == glm::vec3(0.f, 0.f, 0.f));
CHECK(door_wings::slide(0.65f) == glm::vec3(0.f, 0.f, 0.65f));
}
TEST_CASE("door wings: a plug wing goes out first, then slides") {
auto const rangeout{0.1f};
// closed
CHECK(door_wings::plug(0.f, rangeout) == glm::vec3(0.f, 0.f, 0.f));
// still going out, and not sliding yet
auto const out{door_wings::plug(0.02f, rangeout)};
CHECK(out.x == doctest::Approx(0.04f));
CHECK(out.z == 0.f);
// out as far as it goes, sliding by what the position has beyond half of the way out
auto const open{door_wings::plug(0.7f, rangeout)};
CHECK(open.x == rangeout);
CHECK(open.y == 0.f);
CHECK(open.z == doctest::Approx(0.65f));
}
TEST_CASE("door wings: a folding wing turns one way and its larger wing twice as far the other way") {
auto const angles{door_wings::fold(40.f)};
CHECK(angles.smaller == 40.f);
CHECK(angles.larger == -80.f);
CHECK(angles.step == 40.f);
auto const closed{door_wings::fold(0.f)};
CHECK(closed.smaller == 0.f);
CHECK(closed.larger == 0.f);
CHECK(closed.step == 0.f);
}

View File

@@ -29,6 +29,7 @@ http://mozilla.org/MPL/2.0/.
#include "audio/sound.h"
#include "model/MdlMngr.h"
#include "model/Model3d.h"
#include "vehicle/doorwings.h"
#include "rendering/renderer.h"
#include "application/uitranscripts.h"
#include "input/messaging.h"
@@ -584,20 +585,52 @@ void TDynamicObject::update_slottedlevers() {
}
}
namespace {
// the position of the door the animated wing belongs to: its shift or angle from closed
float door_position( TMoverParameters const &Mover, TAnim const *Animation ) {
return Mover.Doors.instances[ (
door_wings::on_right_side( Animation->iNumber ) ?
side::right :
side::left ) ].position;
}
// the wing in the main model, and its namesake in the low poly interior; either can be missing
std::array<TSubModel *, 2> wing_parts( TAnim const *Animation ) {
return { Animation->smAnimated, Animation->smInterior };
}
// folding door: the smaller wing turns, the larger wing (its child) the other way, the step (child of that) under it
void fold_wing( TSubModel *Wing, door_wings::fold_angles const &Angles ) {
if( Wing == nullptr ) { return; }
// skrzydło mniejsze
Wing->SetRotate( float3( 0, 0, 1 ), Angles.smaller );
// skrzydło większe
auto *larger { Wing->ChildGet() };
if( larger == nullptr ) { return; }
larger->SetRotate( float3( 0, 0, 1 ), Angles.larger );
// podnóżek?
auto *step { larger->ChildGet() };
if( step == nullptr ) { return; }
step->SetRotate( float3( 0, 1, 0 ), Angles.step );
}
} // namespace
// animacja drzwi - przesuw
void TDynamicObject::UpdateDoorTranslate(TAnim *pAnim) {
if( pAnim->smAnimated == nullptr ) { return; }
auto const &door { MoverParameters->Doors.instances[ (
( pAnim->iNumber & 1 ) == 0 ?
side::right :
side::left ) ] };
pAnim->smAnimated->SetTranslate(
glm::vec3{
0.0,
0.0,
door.position } );
auto const shift { door_wings::slide( door_position( *MoverParameters, pAnim ) ) };
for( auto *wing : wing_parts( pAnim ) ) {
if( wing != nullptr ) {
wing->SetTranslate( shift );
}
}
};
// animacja drzwi - obrót
@@ -605,14 +638,12 @@ void TDynamicObject::UpdateDoorRotate(TAnim *pAnim) {
if( pAnim->smAnimated == nullptr ) { return; }
auto const &door { MoverParameters->Doors.instances[ (
( pAnim->iNumber & 1 ) == 0 ?
side::right :
side::left ) ] };
pAnim->smAnimated->SetRotate(
float3(1, 0, 0),
door.position );
auto const angle { door_position( *MoverParameters, pAnim ) };
for( auto *wing : wing_parts( pAnim ) ) {
if( wing != nullptr ) {
wing->SetRotate( float3( 1, 0, 0 ), angle );
}
}
};
// animacja drzwi - obrót
@@ -620,31 +651,10 @@ void TDynamicObject::UpdateDoorFold(TAnim *pAnim) {
if( pAnim->smAnimated == nullptr ) { return; }
auto const &door { MoverParameters->Doors.instances[ (
( pAnim->iNumber & 1 ) == 0 ?
side::right :
side::left ) ] };
// skrzydło mniejsze
pAnim->smAnimated->SetRotate(
float3(0, 0, 1),
door.position);
// skrzydło większe
auto *sm = pAnim->smAnimated->ChildGet();
if( sm == nullptr ) { return; }
sm->SetRotate(
float3(0, 0, 1),
-door.position - door.position);
// podnóżek?
sm = sm->ChildGet();
if( sm == nullptr ) { return; }
sm->SetRotate(
float3(0, 1, 0),
door.position);
auto const angles { door_wings::fold( door_position( *MoverParameters, pAnim ) ) };
for( auto *wing : wing_parts( pAnim ) ) {
fold_wing( wing, angles );
}
};
// animacja drzwi - odskokprzesuw
@@ -652,20 +662,12 @@ void TDynamicObject::UpdateDoorPlug(TAnim *pAnim) {
if( pAnim->smAnimated == nullptr ) { return; }
auto const &door { MoverParameters->Doors.instances[ (
( pAnim->iNumber & 1 ) == 0 ?
side::right :
side::left ) ] };
pAnim->smAnimated->SetTranslate(
glm::vec3{
std::min(
door.position * 2.f,
MoverParameters->Doors.range_out ),
0.0,
std::max(
0.f,
door.position - MoverParameters->Doors.range_out * 0.5f ) } );
auto const shift { door_wings::plug( door_position( *MoverParameters, pAnim ), MoverParameters->Doors.range_out ) };
for( auto *wing : wing_parts( pAnim ) ) {
if( wing != nullptr ) {
wing->SetTranslate( shift );
}
}
}
void TDynamicObject::UpdatePant(TAnim *pAnim)
@@ -2445,6 +2447,8 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
for( auto const &nameprefix : nameprefixes ) {
init_sections( mdLowPolyInt, nameprefix, MoverParameters->CompartmentLights.start_type == start_t::manual );
}
// the inside of the door wings, if the interior has them
init_interior_doors();
}
// destination sign
if( mdModel ) {
@@ -2589,6 +2593,26 @@ TDynamicObject::init_sections( TModel3d const *Model, std::string const &Namepre
return sectioncount;
}
// a door wing of the main model is seen from the outside, lit as the exterior. its namesake in the low poly interior,
// if the model has one, follows its moves and is lit with the interior, by its compartment section if it's in one
void
TDynamicObject::init_interior_doors() {
if( mdLowPolyInt == nullptr ) { return; }
for( auto &animation : pAnimations ) {
// the door animation is only set up for a wing found in the main model
if( false == door_wings::is_wing( animation.iFlags ) ) { continue; }
if( ( animation.yUpdate == nullptr ) || ( animation.smAnimated == nullptr ) ) { continue; }
auto *interiorwing { mdLowPolyInt->GetFromName( animation.smAnimated->pName ) };
if( ( interiorwing == nullptr ) || ( interiorwing == animation.smAnimated ) ) { continue; }
interiorwing->WillBeAnimated();
animation.smInterior = interiorwing;
}
}
bool
TDynamicObject::init_destination( TModel3d *Model ) {

View File

@@ -157,6 +157,9 @@ public:
float fMaxDist; // do jakiej odległości wykonywana jest animacja NOTE: square of actual distance
float fSpeed; // parametr szybkości animacji
int iNumber; // numer kolejny obiektu
// door wings only: the submodel of the same name in the low poly interior, if it has one, posed along with
// smAnimated, so the inside of the door can be part of the interior and lit with it
TSubModel *smInterior { nullptr };
TUpdate yUpdate; // metoda TDynamicObject aktualizująca animację
/*
@@ -704,6 +707,8 @@ private:
float Load, std::string LoadType, bool Reversed, std::string);
int init_sections( TModel3d const *Model, std::string const &Nameprefix, bool const Overrideselfillum );
bool init_destination( TModel3d *Model );
// pairs the animated door wings with their namesakes in the low poly interior
void init_interior_doors();
void create_controller( std::string const Type, bool const Trainset );
void AttachNext(TDynamicObject *Object, int iType = 1);
bool UpdateForce(double dt);

52
vehicle/doorwings.h Normal file
View File

@@ -0,0 +1,52 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <algorithm>
#include <glm/vec3.hpp>
// the poses of the animated door wings of a vehicle, for the door position of the mover. a wing is posed alike
// in the main model and, when the low poly interior has a submodel of the same name, in the interior as well
namespace door_wings {
// whether the animation with the given flags (TAnim::iFlags, the kind of animation in bits 4-7) moves a door wing
inline bool is_wing(int const Flags) {
return (Flags & 0xF0) == 0x10;
}
// odd numbered wings (door1, door3...) are on the left side of the vehicle, even numbered on the right
inline bool on_right_side(int const Number) {
return (Number & 1) == 0;
}
// sliding door (type 1): shifted along the vehicle
inline glm::vec3 slide(float const Position) {
return {0.f, 0.f, Position};
}
// plug door (type 4): pushed out first, up to Rangeout, then slid along the vehicle
inline glm::vec3 plug(float const Position, float const Rangeout) {
return {std::min(Position * 2.f, Rangeout), 0.f, std::max(0.f, Position - Rangeout * 0.5f)};
}
// folding door (type 3): the angles of the smaller wing, of the larger wing (its child) and of the step (the
// child of the larger wing)
struct fold_angles {
float smaller;
float larger;
float step;
};
inline fold_angles fold(float const Position) {
return {Position, -Position - Position, Position};
}
} // namespace door_wings