mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 03:52:52 +01:00
feat(events): the animation event starts and stops the clips of EU07M models
A clip of stage 8 played on its own (autoplay) or from the code; a scenery event can start it now. - New form of the animation event: "animation <delay> <model> clip <name> <pace>". A pace above 0 starts the clip from its beginning at that pace (a clip playing starts over), 0 stops the clips of the model, its nodes left where the clips put them. A clip the model hasn't gets "Bad event: ... can't find clip ..." in the log. The event is written back in the same form. The forms before it (rotate, translate, digital, .vmd) read and run as they did. The current release doesn't read the new form. - The editor self-test gets "eventrun <name>", which finds the targets of the event and runs it at once, since the editor runs no events. Checked in the game (Vulkan): after "clip bend 0" the tube stands still (no pixel differs between three shots), after "clip bend 2" it moves, "clip nosuchclip 1" logs the error (time let run in the editor for the test only). No unit test: the unit tests don't link world/Event.cpp. Unit tests 1200/1200. Not built with GCC here.
This commit is contained in:
@@ -99,6 +99,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c
|
||||
// key <S|W|CTRL|RMB> <press|release> [ctrl] a key or right button event, as the window gives it
|
||||
// lineside <vehicle|hekto|fouling|parallel> the tab of the objects along the track in the track window
|
||||
// event <name> queues the event
|
||||
// eventrun <name> runs the event at once, its targets found first, as the simulation does (the editor runs none)
|
||||
// clip <node> <name> [speed] starts an animation clip of the model of the instance (EU07M), by the simulation time
|
||||
// animate <node> <submodel> <x> <y> <z> turns a submodel of a model instance to the angles, as an animation event does (the
|
||||
// editor doesn't run the events); the animation goes by the simulation time
|
||||
|
||||
@@ -573,6 +573,19 @@ editor_mode::selftest_result editor_mode::selftest_scene(std::string const &comm
|
||||
WriteLog("SELFTEST event " + name + (event != nullptr ? " queued" : ": no such event"));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (command == "eventrun")
|
||||
{
|
||||
std::string name;
|
||||
words >> name;
|
||||
auto *event{simulation::Events.FindEvent(name)};
|
||||
if (event != nullptr)
|
||||
{
|
||||
event->init();
|
||||
event->run();
|
||||
}
|
||||
WriteLog("SELFTEST eventrun " + name + (event != nullptr ? " run" : ": no such event"));
|
||||
return selftest_result::handled;
|
||||
}
|
||||
if (command == "clip")
|
||||
{
|
||||
std::string node;
|
||||
|
||||
@@ -262,8 +262,13 @@ Części węzła bez ścieżki zostają takie, jak w jego TRS.
|
||||
ustawia transformy węzłów (`TSubModel::SetClipTransform()`, animacja `at_Clip`), tak jak inne animacje egzemplarza.
|
||||
Węzły, które klipy przesuwają, są przy wczytaniu oznaczane jako animowane, więc model z klipami nie jest
|
||||
instancjonowany. Klip ruszający jointami skóry zgina skinowane części (sekcja „Skinning”).
|
||||
- **Jeszcze nie:** event scenerii, który startuje klip, oraz powiązanie kanałów `CHNL` z czasem klipu. Obecne wydanie
|
||||
nie czyta tych sekcji, a plik bez nich wczytuje się jak dotąd.
|
||||
- **Event scenerii.** `event <nazwa> animation <opóźnienie> <model> clip <klip> <tempo> endevent` startuje klip od
|
||||
początku w podanym tempie (klip już grający zaczyna od nowa), a tempo 0 zatrzymuje klipy modelu; węzły zostają tam,
|
||||
gdzie klip je zostawił. Klip, którego model nie ma, daje w logu `Bad event: ... can't find clip`. To nowa forma
|
||||
eventu `animation`, której obecne wydanie nie czyta; dotychczasowe formy (`rotate`, `translate`, `digital`, `.vmd`)
|
||||
czytają się jak dotąd.
|
||||
- **Jeszcze nie:** powiązanie kanałów `CHNL` z czasem klipu. Obecne wydanie nie czyta sekcji klipów, a plik bez nich
|
||||
wczytuje się jak dotąd.
|
||||
|
||||
### Skinning
|
||||
|
||||
|
||||
@@ -1576,6 +1576,10 @@ animation_event::init() {
|
||||
// animacja modelu
|
||||
init_targets( simulation::Instances, "model instance" );
|
||||
// custom target initialization code
|
||||
if( m_animationtype == clip_animation ) {
|
||||
// clips go by the model, not by its submodels
|
||||
return;
|
||||
}
|
||||
if( m_animationtype == 4 ) {
|
||||
// vmd animations target whole model
|
||||
return;
|
||||
@@ -1657,6 +1661,14 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
|
||||
>> m_animationparams[ 2 ]
|
||||
>> m_animationparams[ 3 ];
|
||||
}
|
||||
else if( token == "clip" ) {
|
||||
// an animation clip of the model (EU07M): its name and pace; a pace of 0 stops the clips playing
|
||||
Input.getTokens();
|
||||
Input >> m_animationsubmodel;
|
||||
m_animationtype = clip_animation;
|
||||
Input.getTokens( 1 );
|
||||
Input >> m_animationparams[ 0 ];
|
||||
}
|
||||
else if( token.ends_with(".vmd") ) // na razie tu, może będzie inaczej
|
||||
{ // animacja z pliku VMD
|
||||
{
|
||||
@@ -1692,6 +1704,10 @@ void
|
||||
animation_event::run_() {
|
||||
|
||||
WriteLog( "Type: Animation" );
|
||||
if( m_animationtype == clip_animation ) {
|
||||
run_clips();
|
||||
return;
|
||||
}
|
||||
// animation modes target specific submodels
|
||||
m_animationcontainers.remove_if([this](std::weak_ptr<TAnimContainer> ptr)
|
||||
{
|
||||
@@ -1721,6 +1737,21 @@ animation_event::run_() {
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
animation_event::run_clips() const {
|
||||
|
||||
for( auto const &target : m_targets ) {
|
||||
auto *model { static_cast<TAnimModel *>( std::get<scene::basic_node *>( target ) ) };
|
||||
if( model == nullptr ) { continue; }
|
||||
if( m_animationparams[ 0 ] <= 0.0 ) {
|
||||
model->stop_clips();
|
||||
}
|
||||
else if( false == model->play_clip( m_animationsubmodel, static_cast<float>( m_animationparams[ 0 ] ) ) ) {
|
||||
ErrorLog( "Bad event: \"" + m_name + "\" (type: " + type() + ") can't find clip " + m_animationsubmodel + " in model instance \"" + model->name() + "\"" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
animation_event::finish() const {
|
||||
|
||||
@@ -1735,6 +1766,10 @@ animation_event::finish() const {
|
||||
void
|
||||
animation_event::export_as_text_( std::ostream &Output ) const {
|
||||
|
||||
if( m_animationtype == clip_animation ) {
|
||||
Output << "clip " << m_animationsubmodel << ' ' << m_animationparams[ 0 ] << ' ';
|
||||
return;
|
||||
}
|
||||
// animation type
|
||||
Output << (
|
||||
m_animationtype == 1 ? "rotate" :
|
||||
|
||||
@@ -439,6 +439,8 @@ public:
|
||||
void init() override;
|
||||
// the animation it set brought to its end at once, for the editor which shows it with the time stopped
|
||||
void finish() const;
|
||||
// the form "clip <name> <pace>": an animation clip of the model (EU07M) started, or the clips stopped with a pace of 0
|
||||
static constexpr int clip_animation{ 16 };
|
||||
|
||||
private:
|
||||
// methods
|
||||
@@ -448,6 +450,7 @@ private:
|
||||
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
|
||||
// run() subclass details
|
||||
void run_() override;
|
||||
void run_clips() const;
|
||||
// export_as_text() subclass details
|
||||
void export_as_text_( std::ostream &Output ) const override;
|
||||
// members
|
||||
|
||||
Reference in New Issue
Block a user