Merge pull request #2892 from ey6es/animenu

Allow setting masked joints for each animation.  Fixed a couple compile warnings.
This commit is contained in:
Brad Hefta-Gaub 2014-05-21 15:14:37 -07:00
commit 5e31489fd6
8 changed files with 56 additions and 6 deletions

View file

@ -441,10 +441,10 @@ void MyAvatar::removeAnimationHandle(const AnimationHandlePointer& handle) {
_animationHandles.removeOne(handle);
}
void MyAvatar::startAnimation(const QString& url, float fps, float priority, bool loop) {
void MyAvatar::startAnimation(const QString& url, float fps, float priority, bool loop, const QStringList& maskedJoints) {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "startAnimation", Q_ARG(const QString&, url),
Q_ARG(float, fps), Q_ARG(float, priority), Q_ARG(bool, loop));
Q_ARG(float, fps), Q_ARG(float, priority), Q_ARG(bool, loop), Q_ARG(const QStringList&, maskedJoints));
return;
}
AnimationHandlePointer handle = _skeletonModel.createAnimationHandle();
@ -452,6 +452,7 @@ void MyAvatar::startAnimation(const QString& url, float fps, float priority, boo
handle->setFPS(fps);
handle->setPriority(priority);
handle->setLoop(loop);
handle->setMaskedJoints(maskedJoints);
handle->start();
}
@ -513,6 +514,7 @@ void MyAvatar::saveData(QSettings* settings) {
settings->setValue("url", pointer->getURL());
settings->setValue("fps", pointer->getFPS());
settings->setValue("priority", pointer->getPriority());
settings->setValue("maskedJoints", pointer->getMaskedJoints());
}
settings->endArray();
@ -579,6 +581,7 @@ void MyAvatar::loadData(QSettings* settings) {
handle->setURL(settings->value("url").toUrl());
handle->setFPS(loadSetting(settings, "fps", 30.0f));
handle->setPriority(loadSetting(settings, "priority", 1.0f));
handle->setMaskedJoints(settings->value("maskedJoints").toStringList());
}
settings->endArray();

View file

@ -68,7 +68,7 @@ public:
/// Allows scripts to run animations.
Q_INVOKABLE void startAnimation(const QString& url, float fps = 30.0f,
float priority = 1.0f, bool loop = false);
float priority = 1.0f, bool loop = false, const QStringList& maskedJoints = QStringList());
/// Stops an animation as identified by a URL.
Q_INVOKABLE void stopAnimation(const QString& url);

View file

@ -1684,6 +1684,11 @@ void AnimationHandle::setPriority(float priority) {
}
}
void AnimationHandle::setMaskedJoints(const QStringList& maskedJoints) {
_maskedJoints = maskedJoints;
_jointMappings.clear();
}
void AnimationHandle::setRunning(bool running) {
if ((_running = running)) {
if (!_model->_runningAnimations.contains(_self)) {
@ -1716,6 +1721,15 @@ void AnimationHandle::simulate(float deltaTime) {
if (_jointMappings.isEmpty()) {
return;
}
if (!_maskedJoints.isEmpty()) {
const FBXGeometry& geometry = _model->getGeometry()->getFBXGeometry();
for (int i = 0; i < _jointMappings.size(); i++) {
int& mapping = _jointMappings[i];
if (mapping != -1 && _maskedJoints.contains(geometry.joints.at(mapping).name)) {
mapping = -1;
}
}
}
}
const FBXGeometry& animationGeometry = _animation->getGeometry();

View file

@ -393,6 +393,9 @@ public:
void setLoop(bool loop) { _loop = loop; }
bool getLoop() const { return _loop; }
void setMaskedJoints(const QStringList& maskedJoints);
const QStringList& getMaskedJoints() const { return _maskedJoints; }
void setRunning(bool running);
bool isRunning() const { return _running; }
@ -414,6 +417,7 @@ private:
float _fps;
float _priority;
bool _loop;
QStringList _maskedJoints;
bool _running;
QVector<int> _jointMappings;
float _frameIndex;

View file

@ -100,6 +100,13 @@ AnimationPanel::AnimationPanel(AnimationsDialog* dialog, const AnimationHandlePo
_priority->setValue(handle->getPriority());
connect(_priority, SIGNAL(valueChanged(double)), SLOT(updateHandle()));
QHBoxLayout* maskedJointBox = new QHBoxLayout();
layout->addRow("Masked Joints:", maskedJointBox);
maskedJointBox->addWidget(_maskedJoints = new QLineEdit(handle->getMaskedJoints().join(", ")), 1);
connect(_maskedJoints, SIGNAL(returnPressed()), SLOT(updateHandle()));
maskedJointBox->addWidget(_chooseMaskedJoints = new QPushButton("Choose"));
connect(_chooseMaskedJoints, SIGNAL(clicked(bool)), SLOT(chooseMaskedJoints()));
QPushButton* remove = new QPushButton("Delete");
layout->addRow(remove);
connect(remove, SIGNAL(clicked(bool)), SLOT(removeHandle()));
@ -118,10 +125,31 @@ void AnimationPanel::chooseURL() {
emit _url->returnPressed();
}
void AnimationPanel::chooseMaskedJoints() {
QMenu menu;
QStringList maskedJoints = _handle->getMaskedJoints();
foreach (const QString& jointName, Application::getInstance()->getAvatar()->getJointNames()) {
QAction* action = menu.addAction(jointName);
action->setCheckable(true);
action->setChecked(maskedJoints.contains(jointName));
}
QAction* action = menu.exec(_chooseMaskedJoints->mapToGlobal(QPoint(0, 0)));
if (action) {
if (action->isChecked()) {
maskedJoints.append(action->text());
} else {
maskedJoints.removeOne(action->text());
}
_handle->setMaskedJoints(maskedJoints);
_maskedJoints->setText(maskedJoints.join(", "));
}
}
void AnimationPanel::updateHandle() {
_handle->setURL(_url->text());
_handle->setFPS(_fps->value());
_handle->setPriority(_priority->value());
_handle->setMaskedJoints(_maskedJoints->text().split(QRegExp("\\s*,\\s*")));
}
void AnimationPanel::removeHandle() {

View file

@ -53,6 +53,7 @@ public:
private slots:
void chooseURL();
void chooseMaskedJoints();
void updateHandle();
void removeHandle();
@ -63,6 +64,8 @@ private:
QLineEdit* _url;
QDoubleSpinBox* _fps;
QDoubleSpinBox* _priority;
QLineEdit* _maskedJoints;
QPushButton* _chooseMaskedJoints;
bool _applying;
};

View file

@ -133,7 +133,6 @@ void NodeBounds::draw() {
glTranslatef(selectedCenter.x, selectedCenter.y, selectedCenter.z);
glScalef(selectedScale, selectedScale, selectedScale);
NodeType_t selectedNodeType = selectedNode->getType();
float red, green, blue;
getColorForNodeType(selectedNode->getType(), red, green, blue);
@ -225,7 +224,6 @@ void NodeBounds::drawOverlay() {
const int FONT = 2;
const int PADDING = 10;
const int MOUSE_OFFSET = 10;
const int BACKGROUND_OFFSET_Y = -20;
const int BACKGROUND_BEVEL = 3;
int mouseX = application->getMouseX(),

View file

@ -1442,7 +1442,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
}
// figure the number of animation frames from the curves
int frameCount = 0;
int frameCount = 1;
foreach (const AnimationCurve& curve, animationCurves) {
frameCount = qMax(frameCount, curve.values.size());
}