mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 05:02:45 +01:00
feat(model): the channels of EU07M models move joints and scrub clips
A channel (CHNL component) is a named value of a model, kept within its range, which moves what it's bound to. The game now follows its bindings to joints and to clips. - A joint binding (a JOIN component of a node): the value of the target (channel * scale + offset) turns a hinge (radians) or a screw (turning and moving by its pitch), 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 (animation::joint_transform()). - A clip binding: 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. - Format, before the release: the target of a clip binding is the index of the clip in ACLP (clips aren't components); the validator checks the target by the kind of the binding (a joint has to be a JOIN component). - TAnimModel::set_channel(name, value); a channel not set has its initial value. RaPrepare() sets the nodes from the channels after the clips playing, so a channel overrides a clip on the same node. The nodes of the joints are flagged animated at load, which keeps the model out of the instancing. - New form of the animation event: "animation <delay> <model> channel <name> <value>"; a channel the model hasn't gets "Bad event: ... can't find channel ..." in the log. The current release doesn't read the new form. - The editor self-test gets "channel <node> <name> <value>". Checked in the game (Vulkan, a skinned tube with a hinge on its tip and a clip on its base): "bend 1" from the self-test and "bend -1" from an event turn the tip both ways, "phase 0.5" from an event turns the whole tube through the clip, an unknown channel logs the error. Unit tests 1204/1204, 4 new ones for the hinge, slider, screw and limits, the range of a channel and the targets of the bindings in the file. Not built with GCC here.
This commit is contained in:
@@ -759,6 +759,10 @@ void TAnimModel::RaPrepare()
|
||||
entry->PrepareModel();
|
||||
}
|
||||
apply_clips();
|
||||
// after the clips playing, as they may set the same nodes
|
||||
if( ( pModel != nullptr ) && ( false == pModel->channels().empty() ) ) {
|
||||
apply_channels();
|
||||
}
|
||||
}
|
||||
|
||||
// the state of the lit and the dark part of a numbered light, as RaPrepare() shows them
|
||||
@@ -817,6 +821,51 @@ void TAnimModel::stop_clips() {
|
||||
m_autoplaystarted = true;
|
||||
}
|
||||
|
||||
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 ) };
|
||||
if( found == channels.end() ) { return false; }
|
||||
if( m_channels.size() != channels.size() ) {
|
||||
m_channels.resize( channels.size() );
|
||||
std::ranges::transform( channels, m_channels.begin(), &animation::channel::initial );
|
||||
}
|
||||
auto const index { static_cast<std::size_t>( std::distance( channels.begin(), found ) ) };
|
||||
m_channels[ index ] = animation::channel_value( *found, Value );
|
||||
return true;
|
||||
}
|
||||
|
||||
void TAnimModel::apply_channels() {
|
||||
|
||||
auto const &channels { pModel->channels() };
|
||||
auto const &clips { pModel->clips() };
|
||||
auto *root { pModel->GetSMRoot() };
|
||||
auto const count { pModel->submodel_count() };
|
||||
for( std::size_t idx = 0; idx < channels.size(); ++idx ) {
|
||||
auto const &channel { channels[ idx ] };
|
||||
auto const value { idx < m_channels.size() ? m_channels[ idx ] : channel.initial };
|
||||
for( auto const &binding : channel.bindings ) {
|
||||
auto const target { value * binding.scale + binding.offset };
|
||||
if( binding.target == animation::binding_target::joint ) {
|
||||
if( ( binding.joint.node >= 0 ) && ( binding.joint.node < count ) ) {
|
||||
root[ binding.joint.node ].SetClipTransform( animation::joint_transform( binding.joint, target ) );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if( binding.clip >= clips.size() ) { continue; }
|
||||
// the share of the duration of the clip
|
||||
auto const &clip { clips[ binding.clip ] };
|
||||
auto const time { std::clamp( target, 0.f, 1.f ) * clip.duration };
|
||||
for( auto const &node : clip.nodes ) {
|
||||
if( ( node.node >= 0 ) && ( node.node < count ) ) {
|
||||
root[ node.node ].SetClipTransform( animation::local_transform( clip, node, time ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TAnimModel::apply_clips() {
|
||||
|
||||
if( ( pModel == nullptr ) || pModel->clips().empty() ) { return; }
|
||||
|
||||
Reference in New Issue
Block a user