Skip to content

Commit

Permalink
UI|Model Renderer: Play animations manually via the model asset editor
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 3, 2016
1 parent 6b79c8d commit 0120360
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doomsday/apps/client/include/render/stateanimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class StateAnimator : public de::ModelDrawable::Animator,

void triggerDamage(int points, struct mobj_s const *inflictor);

void startSequence(int animationId, int priority, bool looping,
de::String const &node = "");

void advanceTime(de::TimeDelta const &elapsed) override;

de::ddouble currentTime(int index) const override;
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/client/include/ui/editors/modelasseteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ModelAssetEditor : public SidebarWidget
protected slots:
void setSelectedAsset(uint pos);
void setSelectedInstance(uint pos);
void playAnimation();

private:
DENG2_PRIVATE(d)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/ui/editors/variablegroupeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class VariableGroupEditor : public de::FoldPanelWidget
de::VariableSliderWidget *addSlider(de::Variable &var, de::Ranged const &range, double step, int precision);
de::VariableLineEditWidget *addLineEdit(de::Variable &var);

void addWidget(GuiWidget *widget);

/**
* Commit all added widgets to the group. This finalizes the layout of the
* added widgets.
Expand Down
8 changes: 8 additions & 0 deletions doomsday/apps/client/src/render/stateanimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,14 @@ void StateAnimator::triggerDamage(int points, struct mobj_s const *inflictor)
}
}

void StateAnimator::startSequence(int animationId, int priority, bool looping,
String const &node)
{
using Seq = Instance::Sequence;
d->start(Seq(animationId, node, looping? Seq::Looping : Seq::NotLooping,
priority));
}

void StateAnimator::advanceTime(TimeDelta const &elapsed)
{
ModelDrawable::Animator::advanceTime(elapsed);
Expand Down
64 changes: 60 additions & 4 deletions doomsday/apps/client/src/ui/editors/modelasseteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
using namespace de;
using namespace de::ui;

struct PlayData
{
int mobjId;
int animationId;

PlayData(int mobj = 0, int seq = 0) : mobjId(mobj), animationId(seq) {}
};
Q_DECLARE_METATYPE(PlayData)

DENG_GUI_PIMPL(ModelAssetEditor)
, DENG2_OBSERVES(PackageLoader, Activity)
, DENG2_OBSERVES(PanelWidget, AboutToOpen)
Expand All @@ -53,6 +62,7 @@ DENG_GUI_PIMPL(ModelAssetEditor)
LabelWidget *instLabel;
ChoiceWidget *instChoice;
QList<Group *> groups; ///< Generated based on asset subrecords.
SafeWidgetPtr<ChoiceWidget> animChoice;

Instance(Public *i) : Base(i)
{
Expand Down Expand Up @@ -97,6 +107,10 @@ DENG_GUI_PIMPL(ModelAssetEditor)
return count != 1? suffix : "";
}

/**
* Sets the currently active model asset.
* @param id Asset identifier.
*/
void setAsset(String id)
{
assetId = id;
Expand Down Expand Up @@ -199,7 +213,25 @@ DENG_GUI_PIMPL(ModelAssetEditor)
DENG2_ASSERT(anim);
Record &ns = anim->objectNamespace();

Group *g = makeGroup(*anim, ns, tr("Variables"));
// Manual animation controls.
Group *g = new Group(this, "", tr("Animations"));
groups << g;
g->addLabel(tr("Play:"));
animChoice.reset(new ChoiceWidget);
render::Model const &model = anim->model();
for(int i = 0; i < model.animationCount(); ++i)
{
QVariant var;
var.setValue(PlayData(mobjId, i));
animChoice->items() << new ChoiceItem(model.animationName(i), var);
}
g->addWidget(animChoice);
QObject::connect(animChoice.get(), SIGNAL(selectionChangedByUser(uint)),
thisPublic, SLOT(playAnimation()));
g->commit();

// Animator variables.
g = makeGroup(*anim, ns, tr("Variables"));
g->open();
groups << g;

Expand Down Expand Up @@ -324,7 +356,8 @@ DENG_GUI_PIMPL(ModelAssetEditor)
.shaderDefinition(*pass.program);

// Check the variable declarations.
auto vars = ScriptedInfo::subrecordsOfType(QStringLiteral("variable"), shaderDef).keys();
auto vars = ScriptedInfo::subrecordsOfType(QStringLiteral("variable"),
shaderDef).keys();
qSort(vars);
QStringList names;
for(String const &n : vars)
Expand Down Expand Up @@ -365,7 +398,6 @@ DENG_GUI_PIMPL(ModelAssetEditor)
{
layout << g->title() << *g;
}

self.updateSidebarLayout(assetLabel->rule().width() +
assetChoice->rule().width(),
assetChoice->rule().height());
Expand All @@ -392,7 +424,6 @@ DENG_GUI_PIMPL(ModelAssetEditor)
}
return LoopContinue;
});

sortInstancesByDistance(false);
}

Expand Down Expand Up @@ -439,6 +470,26 @@ DENG_GUI_PIMPL(ModelAssetEditor)
}
}
}

void playSelectedAnimation()
{
if(!animChoice || !animChoice->isValidSelection())
return;

PlayData const data = animChoice->selectedItem().data().value<PlayData>();

if(mobj_t const *mo = Mobj_ById(data.mobjId))
{
if(auto *thinker = THINKER_DATA_MAYBE(mo->thinker, ClientMobjThinkerData))
{
if(render::StateAnimator *animator = thinker->animator())
{
qDebug() << "starting" << data.animationId << "on" << data.mobjId;
animator->startSequence(data.animationId, 10, false);
}
}
}
}
};

ModelAssetEditor::ModelAssetEditor()
Expand Down Expand Up @@ -477,3 +528,8 @@ void ModelAssetEditor::setSelectedInstance(uint /*pos*/)
d->makeGroups();
d->redoLayout();
}

void ModelAssetEditor::playAnimation()
{
d->playSelectedAnimation();
}
6 changes: 6 additions & 0 deletions doomsday/apps/client/src/ui/editors/variablegroupeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ VariableLineEditWidget *VariableGroupEditor::addLineEdit(Variable &var)
return w;
}

void VariableGroupEditor::addWidget(GuiWidget *widget)
{
d->content->add(widget);
d->layout << *widget;
}

void VariableGroupEditor::commit()
{
d->content->rule().setSize(d->layout.width(), d->layout.height() +
Expand Down

0 comments on commit 0120360

Please sign in to comment.