Moved AnimationObject to separate source files.

This commit is contained in:
Andrzej Kapolka 2014-04-17 15:52:32 -07:00
parent 197127fbde
commit 15d4f59ceb
5 changed files with 84 additions and 49 deletions

View file

@ -10,7 +10,6 @@
//
#include <QRunnable>
#include <QScriptEngine>
#include <QThreadPool>
#include "AnimationCache.h"
@ -101,22 +100,3 @@ void Animation::downloadFinished(QNetworkReply* reply) {
QThreadPool::globalInstance()->start(new AnimationReader(_self, reply));
}
QStringList AnimationObject::getJointNames() const {
return qscriptvalue_cast<AnimationPointer>(thisObject())->getJointNames();
}
QVector<FBXAnimationFrame> AnimationObject::getFrames() const {
return qscriptvalue_cast<AnimationPointer>(thisObject())->getFrames();
}
QVector<glm::quat> AnimationFrameObject::getRotations() const {
return qscriptvalue_cast<FBXAnimationFrame>(thisObject()).rotations;
}
void registerAnimationTypes(QScriptEngine* engine) {
qScriptRegisterSequenceMetaType<QVector<FBXAnimationFrame> >(engine);
engine->setDefaultPrototype(qMetaTypeId<FBXAnimationFrame>(), engine->newQObject(
new AnimationFrameObject(), QScriptEngine::ScriptOwnership));
engine->setDefaultPrototype(qMetaTypeId<AnimationPointer>(), engine->newQObject(
new AnimationObject(), QScriptEngine::ScriptOwnership));
}

View file

@ -12,14 +12,10 @@
#ifndef hifi_AnimationCache_h
#define hifi_AnimationCache_h
#include <QScriptable>
#include <ResourceCache.h>
#include <FBXReader.h>
class QScriptEngine;
class Animation;
typedef QSharedPointer<Animation> AnimationPointer;
@ -69,29 +65,4 @@ private:
FBXGeometry _geometry;
};
/// Scriptable wrapper for animation pointers.
class AnimationObject : public QObject, protected QScriptable {
Q_OBJECT
Q_PROPERTY(QStringList jointNames READ getJointNames)
Q_PROPERTY(QVector<FBXAnimationFrame> frames READ getFrames)
public:
Q_INVOKABLE QStringList getJointNames() const;
Q_INVOKABLE QVector<FBXAnimationFrame> getFrames() const;
};
/// Scriptable wrapper for animation frames.
class AnimationFrameObject : public QObject, protected QScriptable {
Q_OBJECT
Q_PROPERTY(QVector<glm::quat> rotations READ getRotations)
public:
Q_INVOKABLE QVector<glm::quat> getRotations() const;
};
void registerAnimationTypes(QScriptEngine* engine);
#endif // hifi_AnimationCache_h

View file

@ -0,0 +1,36 @@
//
// AnimationObject.cpp
// libraries/script-engine/src/
//
// Created by Andrzej Kapolka on 4/17/14.
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QScriptEngine>
#include "AnimationCache.h"
#include "AnimationObject.h"
QStringList AnimationObject::getJointNames() const {
return qscriptvalue_cast<AnimationPointer>(thisObject())->getJointNames();
}
QVector<FBXAnimationFrame> AnimationObject::getFrames() const {
return qscriptvalue_cast<AnimationPointer>(thisObject())->getFrames();
}
QVector<glm::quat> AnimationFrameObject::getRotations() const {
return qscriptvalue_cast<FBXAnimationFrame>(thisObject()).rotations;
}
void registerAnimationTypes(QScriptEngine* engine) {
qScriptRegisterSequenceMetaType<QVector<FBXAnimationFrame> >(engine);
engine->setDefaultPrototype(qMetaTypeId<FBXAnimationFrame>(), engine->newQObject(
new AnimationFrameObject(), QScriptEngine::ScriptOwnership));
engine->setDefaultPrototype(qMetaTypeId<AnimationPointer>(), engine->newQObject(
new AnimationObject(), QScriptEngine::ScriptOwnership));
}

View file

@ -0,0 +1,47 @@
//
// AnimationObject.h
// libraries/script-engine/src/
//
// Created by Andrzej Kapolka on 4/17/14.
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_AnimationObject_h
#define hifi_AnimationObject_h
#include <QObject>
#include <QScriptable>
#include <FBXReader.h>
class QScriptEngine;
/// Scriptable wrapper for animation pointers.
class AnimationObject : public QObject, protected QScriptable {
Q_OBJECT
Q_PROPERTY(QStringList jointNames READ getJointNames)
Q_PROPERTY(QVector<FBXAnimationFrame> frames READ getFrames)
public:
Q_INVOKABLE QStringList getJointNames() const;
Q_INVOKABLE QVector<FBXAnimationFrame> getFrames() const;
};
/// Scriptable wrapper for animation frames.
class AnimationFrameObject : public QObject, protected QScriptable {
Q_OBJECT
Q_PROPERTY(QVector<glm::quat> rotations READ getRotations)
public:
Q_INVOKABLE QVector<glm::quat> getRotations() const;
};
void registerAnimationTypes(QScriptEngine* engine);
#endif // hifi_AnimationObject_h

View file

@ -28,6 +28,7 @@
#include <Sound.h>
#include "AnimationObject.h"
#include "MenuItemProperties.h"
#include "LocalVoxels.h"
#include "ScriptEngine.h"