From ce40e11b9421725420c7bba278faa42d4ab1cffd Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Sun, 29 Nov 2026 18:20:09 +0100 Subject: [PATCH] fix(model): EU07M review of #543: channel names keep their case, the joint moves from its rest value - The channel event reads the name of the channel as written (getTokens lowercased it), and set_channel() finds it regardless of case: a channel named doorLeft couldn't be set from a scenery. - JOIN.rest is read: the node is modelled at the rest value of its joint, which moves it by the value less rest (the limits stay values of the joint). A part modelled half open no longer jumps when its channel is set. Files without it (rest 0) move as before. - The spec says so, and that no vehicle sets channels yet. Test: a slider modelled half out. --- docs/eu07m-format.md | 7 +++++-- model/AnimModel.cpp | 9 ++++++++- model/clip.cpp | 2 ++ model/clip.h | 1 + model/eu07m/eu07m_load.cpp | 1 + tests/unit/test_clip.cpp | 5 +++++ world/Event.cpp | 4 ++-- 7 files changed, 24 insertions(+), 5 deletions(-) diff --git a/docs/eu07m-format.md b/docs/eu07m-format.md index 3614ea493..dcda7226e 100644 --- a/docs/eu07m-format.md +++ b/docs/eu07m-format.md @@ -286,10 +286,13 @@ the code of a vehicle, later Lua or a gauge in the cab) doesn't matter. - **Bindings the game follows.** A joint (`JOIN` of a node): the value of the target turns a hinge (radians) or a screw, or moves a slider (metres) along the axis of the joint, from the transform of the node, within the limits of the joint when it has them; a - fixed or a ball joint leaves the node at rest. A clip (its index in `ACLP`): the value of the target is the share of the duration + fixed or a ball joint leaves the node at rest. The node is modelled at the `rest` value of the joint: the joint moves it by the + value less `rest` (the limits are values of the joint, as `rest` is). A clip (its index in `ACLP`): the value of the target is the share of the duration of the clip, 0 to 1, so the channel scrubs the clip without playing it. Bindings to variants and light slots are read but not followed yet. -- **In the game.** `TAnimModel::set_channel(name, value)` sets a channel (the self-test command `channel `). +- **In the game.** `TAnimModel::set_channel(name, value)` sets a channel (the self-test command `channel `), + the name regardless of case. Only scenery events and the self-test set channels so far; a vehicle (`TDynamicObject`: its cab + controls, its state) has no hook to them yet. Each time the instance is drawn, `RaPrepare()` sets the nodes from the channels, after the clips playing, so a channel overrides a clip on the same node. A channel not set yet has its initial value. The nodes of the joints are flagged animated at load. - **Scenery event.** `event animation channel endevent` sets the channel. A channel the diff --git a/model/AnimModel.cpp b/model/AnimModel.cpp index 22fa34c39..55b4ac9a1 100644 --- a/model/AnimModel.cpp +++ b/model/AnimModel.cpp @@ -15,6 +15,9 @@ http://mozilla.org/MPL/2.0/. #include "stdafx.h" #include "model/AnimModel.h" +#include +#include + #include "rendering/renderer.h" #include "model/MdlMngr.h" #include "simulation/simulation.h" @@ -825,7 +828,11 @@ bool TAnimModel::set_channel( std::string_view const Name, float const Value ) { if( pModel == nullptr ) { return false; } auto const &channels { pModel->channels() }; - auto const found { std::ranges::find( channels, Name, &animation::channel::name ) }; + // the name regardless of case, as the submodels are found by theirs + auto const same { [ Name ]( animation::channel const &Channel ) { + return std::ranges::equal( Channel.name, Name, []( char const Left, char const Right ) { + return std::tolower( static_cast( Left ) ) == std::tolower( static_cast( Right ) ); } ); } }; + auto const found { std::ranges::find_if( channels, same ) }; if( found == channels.end() ) { return false; } if( m_channels.size() != channels.size() ) { m_channels.resize( channels.size() ); diff --git a/model/clip.cpp b/model/clip.cpp index 2013227f7..ae3e51e80 100644 --- a/model/clip.cpp +++ b/model/clip.cpp @@ -140,6 +140,8 @@ glm::mat4 joint_transform(joint_binding const &Joint, float const Value) { value = std::clamp(value, std::min(Joint.minimum, Joint.maximum), std::max(Joint.minimum, Joint.maximum)); } + // the node is modelled at the rest value of the joint: at that value it stays as modelled + value -= Joint.rest_value; auto const length{glm::length(Joint.axis)}; if (length <= 0.f) { diff --git a/model/clip.h b/model/clip.h index e6fe7f9fd..6b699ac2e 100644 --- a/model/clip.h +++ b/model/clip.h @@ -97,6 +97,7 @@ struct joint_binding float maximum{0.f}; float pitch{0.f}; // metres for each turn of a screw glm::mat4 rest{1.f}; // the transform of the node within its parent, which the joint moves from + float rest_value{0.f}; // the value of the joint the node is modelled at (JOIN.rest): the joint moves by the value less it }; enum class binding_target : std::uint8_t diff --git a/model/eu07m/eu07m_load.cpp b/model/eu07m/eu07m_load.cpp index db361131d..9080d637f 100644 --- a/model/eu07m/eu07m_load.cpp +++ b/model/eu07m/eu07m_load.cpp @@ -439,6 +439,7 @@ std::optional make_joint(eu07m::model const &Model, st result.maximum = joint.maximum; result.pitch = joint.pitch; result.rest = Locals[record.target]; + result.rest_value = joint.rest; return result; } diff --git a/tests/unit/test_clip.cpp b/tests/unit/test_clip.cpp index 43aeaf788..ba22b4f9e 100644 --- a/tests/unit/test_clip.cpp +++ b/tests/unit/test_clip.cpp @@ -181,6 +181,11 @@ TEST_CASE("clip: a joint turns or moves its node from the rest, within its limit slider.type = animation::joint_type::slider; slider.axis = {0.f, 1.f, 0.f}; CHECK(animation::joint_transform(slider, 0.25f)[3].y == doctest::Approx(0.25f)); + // a part modelled half out (JOIN.rest 0.1): there at the value 0.1, at its modelled place at 0 + slider.rest_value = 0.1f; + CHECK(animation::joint_transform(slider, 0.1f)[3].y == doctest::Approx(0.f)); + CHECK(animation::joint_transform(slider, 0.f)[3].y == doctest::Approx(-0.1f)); + slider.rest_value = 0.f; // a screw of 0.012 m a turn moves 0.006 m in half a turn animation::joint_binding screw; diff --git a/world/Event.cpp b/world/Event.cpp index 613c6e2b7..24ab6d4c3 100644 --- a/world/Event.cpp +++ b/world/Event.cpp @@ -1670,8 +1670,8 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) Input >> m_animationparams[ 0 ]; } else if( token == "channel" ) { - // a channel of the model (EU07M): its name and value - Input.getTokens(); + // a channel of the model (EU07M): its name, as written (the parser would lowercase it), and value + Input.getTokens( 1, false ); Input >> m_animationsubmodel; m_animationtype = channel_animation; Input.getTokens( 1 );