mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 05:57:08 +01:00
Merge branch 'feat/eu07m-gref' of https://github.com/MaSzyna-EU07/maszyna into feat/eu07m-model-inspector
# Conflicts: # model/AnimModel.h
This commit is contained in:
+31
-8
@@ -15,6 +15,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "stdafx.h"
|
||||
#include "model/AnimModel.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
#include "rendering/renderer.h"
|
||||
#include "model/MdlMngr.h"
|
||||
#include "simulation/simulation.h"
|
||||
@@ -569,6 +572,9 @@ void TAnimModel::update_instanceable_flag() {
|
||||
// gfx.instancedlights: the lights go with the matrix of each instance (instance_light_bits()), and the instanced walk
|
||||
// animates each instance (RaAnimate) and prepares the model with all the parts of the lights shown (RaPrepareInstanced)
|
||||
if( ( iNumLights != 0 ) && ( false == Global.gfx_instancedlights ) ) { ++s_rejected_lights; return; }
|
||||
// light colours of its own (lightcolors of the node) go onto the shared submodels as the instance is prepared (RaPrepare),
|
||||
// which the instances of a bucket don't each get: such an instance is drawn on its own
|
||||
if( std::ranges::any_of( m_lightcolors, []( glm::vec3 const &Colour ) { return Colour.r >= 0.f; } ) ) { ++s_rejected_lights; return; }
|
||||
if( !m_animlist.empty() ) { ++s_rejected_animlist; return; }
|
||||
if( submodel_tree_blocks_instancing( pModel->Root ) ) { ++s_rejected_animated_submodel; return; }
|
||||
m_instanceable = true;
|
||||
@@ -755,14 +761,15 @@ void TAnimModel::RaPrepare()
|
||||
TSubModel::iVariantSeed = 0;
|
||||
TSubModel::pasText = &asText; // przekazanie tekstu do wyświetlacza (!!!! do przemyślenia)
|
||||
|
||||
for (auto entry : m_animlist) {
|
||||
entry->PrepareModel();
|
||||
}
|
||||
// the clips first, then the channels, as they may set the same nodes; an animation event of the scenery on a node (rotate,
|
||||
// translate...) takes over from both, a clip which ended or was stopped included, as the later one set on the submodel counts
|
||||
apply_clips();
|
||||
// after the clips playing, as they may set the same nodes
|
||||
if( ( pModel != nullptr ) && ( false == pModel->channels().empty() ) ) {
|
||||
apply_channels();
|
||||
}
|
||||
for (auto entry : m_animlist) {
|
||||
entry->PrepareModel();
|
||||
}
|
||||
}
|
||||
|
||||
// the state of the lit and the dark part of a numbered light, as RaPrepare() shows them
|
||||
@@ -806,7 +813,11 @@ bool TAnimModel::play_clip( std::string_view const Name, float const Speed, floa
|
||||
|
||||
if( pModel == nullptr ) { return false; }
|
||||
auto const &clips { pModel->clips() };
|
||||
auto const found { std::ranges::find( clips, Name, &animation::clip::name ) };
|
||||
// the name regardless of case, as the submodels are found by theirs
|
||||
auto const same { [ Name ]( animation::clip const &Clip ) {
|
||||
return std::ranges::equal( Clip.name, Name, []( char const Left, char const Right ) {
|
||||
return std::tolower( static_cast<unsigned char>( Left ) ) == std::tolower( static_cast<unsigned char>( Right ) ); } ); } };
|
||||
auto const found { std::ranges::find_if( clips, same ) };
|
||||
if( found == clips.end() ) { return false; }
|
||||
auto const index { static_cast<std::size_t>( std::distance( clips.begin(), found ) ) };
|
||||
std::erase_if( m_clips, [ index ]( clip_playing const &Playing ) { return Playing.clip == index; } );
|
||||
@@ -819,7 +830,15 @@ bool TAnimModel::play_clip( std::string_view const Name, float const Speed, floa
|
||||
|
||||
void TAnimModel::stop_clips() {
|
||||
|
||||
m_clips.clear();
|
||||
// the clips are held where they are, not dropped: the pose lives in the submodels the instances of the model share, so the
|
||||
// nodes of this instance are set again for each of its draws (apply_clips()), or another instance playing a clip would leave
|
||||
// them at rest
|
||||
auto const now { Timer::GetTime() };
|
||||
for( auto &playing : m_clips ) {
|
||||
if( false == playing.held.has_value() ) {
|
||||
playing.held = ( now - playing.start ) * playing.speed;
|
||||
}
|
||||
}
|
||||
m_autoplaystarted = true;
|
||||
}
|
||||
|
||||
@@ -827,7 +846,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<unsigned char>( Left ) ) == std::tolower( static_cast<unsigned char>( 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() );
|
||||
@@ -886,7 +909,7 @@ void TAnimModel::apply_clips() {
|
||||
auto const count { pModel->submodel_count() };
|
||||
for( auto const &playing : m_clips ) {
|
||||
auto const &clip { clips[ playing.clip ] };
|
||||
auto const time { animation::clip_time( clip, ( now - playing.start ) * playing.speed ) };
|
||||
auto const time { animation::clip_time( clip, playing.held.value_or( ( now - playing.start ) * playing.speed ) ) };
|
||||
for( auto const &node : clip.nodes ) {
|
||||
if( ( node.node < 0 ) || ( node.node >= count ) ) { continue; }
|
||||
root[ node.node ].SetClipTransform( animation::local_transform( clip, node, time ) );
|
||||
|
||||
Reference in New Issue
Block a user