mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 18:13:29 +02:00
Added some basic method to allow scripts to run/stop animations on the avatar.
This commit is contained in:
parent
1022f1bec4
commit
0dfd787034
4 changed files with 60 additions and 16 deletions
|
@ -436,6 +436,33 @@ void MyAvatar::removeAnimationHandle(const AnimationHandlePointer& handle) {
|
|||
_animationHandles.removeOne(handle);
|
||||
}
|
||||
|
||||
void MyAvatar::startAnimation(const QString& url, float fps, float priority, bool loop) {
|
||||
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));
|
||||
return;
|
||||
}
|
||||
AnimationHandlePointer handle = _skeletonModel.createAnimationHandle();
|
||||
handle->setURL(url);
|
||||
handle->setFPS(fps);
|
||||
handle->setPriority(priority);
|
||||
handle->setLoop(loop);
|
||||
handle->start();
|
||||
}
|
||||
|
||||
void MyAvatar::stopAnimation(const QString& url) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "stopAnimation", Q_ARG(const QString&, url));
|
||||
return;
|
||||
}
|
||||
foreach (const AnimationHandlePointer& handle, _skeletonModel.getRunningAnimations()) {
|
||||
if (handle->getURL() == url) {
|
||||
handle->stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MyAvatar::saveData(QSettings* settings) {
|
||||
settings->beginGroup("Avatar");
|
||||
|
||||
|
|
|
@ -66,6 +66,13 @@ public:
|
|||
AnimationHandlePointer addAnimationHandle();
|
||||
void removeAnimationHandle(const AnimationHandlePointer& handle);
|
||||
|
||||
/// Allows scripts to run animations.
|
||||
Q_INVOKABLE void startAnimation(const QString& url, float fps = 30.0f,
|
||||
float priority = 1.0f, bool loop = false);
|
||||
|
||||
/// Stops an animation as identified by a URL.
|
||||
Q_INVOKABLE void stopAnimation(const QString& url);
|
||||
|
||||
// get/set avatar data
|
||||
void saveData(QSettings* settings);
|
||||
void loadData(QSettings* settings);
|
||||
|
|
|
@ -1670,28 +1670,32 @@ static void insertSorted(QList<AnimationHandlePointer>& handles, const Animation
|
|||
void AnimationHandle::setPriority(float priority) {
|
||||
if (_priority != priority) {
|
||||
_priority = priority;
|
||||
if (_running) {
|
||||
_model->_runningAnimations.removeOne(_self);
|
||||
insertSorted(_model->_runningAnimations, _self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationHandle::setRunning(bool running) {
|
||||
if ((_running = running)) {
|
||||
if (!_model->_runningAnimations.contains(_self)) {
|
||||
insertSorted(_model->_runningAnimations, _self);
|
||||
}
|
||||
_frameIndex = 0.0f;
|
||||
|
||||
} else {
|
||||
_model->_runningAnimations.removeOne(_self);
|
||||
insertSorted(_model->_runningAnimations, _self);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationHandle::start() {
|
||||
if (!_model->_runningAnimations.contains(_self)) {
|
||||
insertSorted(_model->_runningAnimations, _self);
|
||||
}
|
||||
_frameIndex = 0.0f;
|
||||
}
|
||||
|
||||
void AnimationHandle::stop() {
|
||||
_model->_runningAnimations.removeOne(_self);
|
||||
}
|
||||
|
||||
AnimationHandle::AnimationHandle(Model* model) :
|
||||
QObject(model),
|
||||
_model(model),
|
||||
_fps(30.0f),
|
||||
_priority(1.0f),
|
||||
_loop(false) {
|
||||
_loop(false),
|
||||
_running(false) {
|
||||
}
|
||||
|
||||
void AnimationHandle::simulate(float deltaTime) {
|
||||
|
|
|
@ -194,6 +194,8 @@ public:
|
|||
|
||||
AnimationHandlePointer createAnimationHandle();
|
||||
|
||||
const QList<AnimationHandlePointer>& getRunningAnimations() const { return _runningAnimations; }
|
||||
|
||||
void clearShapes();
|
||||
void rebuildShapes();
|
||||
void resetShapePositions();
|
||||
|
@ -376,7 +378,7 @@ Q_DECLARE_METATYPE(QVector<glm::vec3>)
|
|||
/// Represents a handle to a model animation.
|
||||
class AnimationHandle : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
|
||||
void setURL(const QUrl& url);
|
||||
|
@ -391,8 +393,11 @@ public:
|
|||
void setLoop(bool loop) { _loop = loop; }
|
||||
bool getLoop() const { return _loop; }
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
void setRunning(bool running);
|
||||
bool isRunning() const { return _running; }
|
||||
|
||||
void start() { setRunning(true); }
|
||||
void stop() { setRunning(false); }
|
||||
|
||||
private:
|
||||
|
||||
|
@ -409,6 +414,7 @@ private:
|
|||
float _fps;
|
||||
float _priority;
|
||||
bool _loop;
|
||||
bool _running;
|
||||
QVector<int> _jointMappings;
|
||||
float _frameIndex;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue