1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Remove all traces of Skeleton

This commit is contained in:
Daniel Evans 2017-01-08 19:46:00 +00:00
parent 94456aa732
commit d84b492412
24 changed files with 14 additions and 274 deletions

View File

@ -41,8 +41,6 @@ set(RWENGINE_SOURCES
src/data/PathData.hpp
src/data/PedData.cpp
src/data/PedData.hpp
src/data/Skeleton.cpp
src/data/Skeleton.hpp
src/data/WeaponData.hpp
src/data/ZoneData.hpp
src/dynamics/CollisionInstance.cpp

View File

@ -1,100 +0,0 @@
#include <data/Clump.hpp>
#include <data/Skeleton.hpp>
#include <glm/gtc/matrix_transform.hpp>
Skeleton::FrameTransform Skeleton::IdentityTransform = {glm::vec3(0.f),
glm::quat()};
Skeleton::FrameData Skeleton::IdentityData = {
Skeleton::IdentityTransform, Skeleton::IdentityTransform, true};
Skeleton::Skeleton() {
}
void Skeleton::setAllData(const Skeleton::FramesData& data) {
framedata = data;
}
const Skeleton::FrameData& Skeleton::getData(unsigned int frameIdx) const {
auto fdit = framedata.find(frameIdx);
if (fdit == framedata.end()) {
return Skeleton::IdentityData;
}
return fdit->second;
}
void Skeleton::setData(unsigned int frameIdx, const Skeleton::FrameData& data) {
framedata[frameIdx] = data;
}
void Skeleton::setEnabled(ModelFrame* frame, bool enabled) {
auto fdit = framedata.find(frame->getIndex());
if (fdit != framedata.end()) {
fdit->second.enabled = enabled;
} else {
FrameTransform tf{frame->getDefaultTranslation(),
glm::quat_cast(frame->getDefaultRotation())};
framedata.insert({frame->getIndex(), {tf, tf, enabled}});
}
}
void Skeleton::setEnabled(unsigned int frameIdx, bool enabled) {
auto fdit = framedata.find(frameIdx);
if (fdit == framedata.end()) {
framedata.insert({frameIdx,
{Skeleton::IdentityTransform,
Skeleton::IdentityTransform, enabled}});
} else {
fdit->second.enabled = enabled;
}
}
const Skeleton::FrameTransform& Skeleton::getInterpolated(
unsigned int frameIdx) const {
auto itit = interpolateddata.find(frameIdx);
if (itit == interpolateddata.end()) {
return Skeleton::IdentityTransform;
}
return itit->second;
}
void Skeleton::interpolate(float alpha) {
interpolateddata.clear();
for (auto i = framedata.begin(); i != framedata.end(); ++i) {
auto& t2 = i->second.a.translation;
auto& t1 = i->second.b.translation;
auto& r2 = i->second.a.rotation;
auto& r1 = i->second.b.rotation;
interpolateddata.insert(
{i->first, {glm::mix(t1, t2, alpha), glm::slerp(r1, r2, alpha)}});
}
}
glm::mat4 Skeleton::getMatrix(unsigned int frameIdx) const {
const FrameTransform& ft = getInterpolated(frameIdx);
glm::mat4 m;
m = glm::translate(m, ft.translation);
m = m * glm::mat4_cast(ft.rotation);
return m;
}
glm::mat4 Skeleton::getMatrix(ModelFrame* frame) const {
auto itit = interpolateddata.find(frame->getIndex());
if (itit != interpolateddata.end()) {
glm::mat4 m;
m = glm::translate(m, itit->second.translation);
m = m * glm::mat4_cast(itit->second.rotation);
return m;
}
return frame->getTransform();
}

View File

@ -1,59 +0,0 @@
#ifndef _SKELETON_HPP_
#define _SKELETON_HPP_
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <map>
#include <vector>
class ModelFrame;
/**
* Data class for additional frame transformation and meta data.
*
* Provides interfaces to modify and query the visibility of model frames,
* as well as their transformation. Modified by Animator to animate models.
*/
class Skeleton {
public:
struct FrameTransform {
glm::vec3 translation;
glm::quat rotation;
};
static FrameTransform IdentityTransform;
struct FrameData {
FrameTransform a;
FrameTransform b;
bool enabled;
};
static FrameData IdentityData;
typedef std::map<unsigned int, FrameData> FramesData;
typedef std::map<unsigned int, FrameTransform> TransformData;
Skeleton();
void setAllData(const FramesData& data);
const FrameData& getData(unsigned int frameIdx) const;
void setData(unsigned int frameIdx, const FrameData& data);
void setEnabled(ModelFrame* frame, bool enabled);
void setEnabled(unsigned int frameIdx, bool enabled);
const FrameTransform& getInterpolated(unsigned int frameIdx) const;
glm::mat4 getMatrix(unsigned int frameIdx) const;
glm::mat4 getMatrix(ModelFrame* frame) const;
void interpolate(float alpha);
private:
FramesData framedata;
TransformData interpolateddata;
};
#endif

View File

@ -1,5 +1,4 @@
#include <data/Clump.hpp>
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <loaders/LoaderDFF.hpp>

View File

@ -1,4 +1,3 @@
#include <data/Skeleton.hpp>
#include <engine/GameWorld.hpp>
#include <items/Weapon.hpp>
#include <objects/ProjectileObject.hpp>

View File

@ -1,5 +1,4 @@
#include <ai/CharacterController.hpp>
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>

View File

@ -1,4 +1,3 @@
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <objects/CutsceneObject.hpp>

View File

@ -1,4 +1,3 @@
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <glm/gtc/quaternion.hpp>
#include <loaders/LoaderDFF.hpp>
@ -9,9 +8,6 @@ GameObject::~GameObject() {
if (animator) {
delete animator;
}
if (skeleton) {
delete skeleton;
}
if (modelinfo_) {
modelinfo_->removeReference();

View File

@ -11,7 +11,6 @@
#include <objects/ObjectTypes.hpp>
#include <rw/types.hpp>
class Skeleton;
class CharacterController;
class Animator;
class GameWorld;
@ -46,7 +45,6 @@ public:
GameWorld* engine;
Animator* animator; /// Object's animator.
Skeleton* skeleton;
bool inWater;
@ -71,7 +69,6 @@ public:
, rotation(rot)
, engine(engine)
, animator(nullptr)
, skeleton(nullptr)
, inWater(false)
, _lastHeight(std::numeric_limits<float>::max())
, visible(true)

View File

@ -1,7 +1,6 @@
#include <BulletDynamics/Vehicle/btRaycastVehicle.h>
#include <data/Clump.hpp>
#include <data/CollisionModel.hpp>
#include <data/Skeleton.hpp>
#include <dynamics/CollisionInstance.hpp>
#include <dynamics/RaycastCallbacks.hpp>
#include <engine/Animator.hpp>

View File

@ -14,7 +14,6 @@
#include <data/ModelData.hpp>
#include <data/CutsceneData.hpp>
#include <data/Skeleton.hpp>
#include <objects/CutsceneObject.hpp>
#include <render/ObjectRenderer.hpp>

View File

@ -1,6 +1,5 @@
#include <data/Clump.hpp>
#include <data/CutsceneData.hpp>
#include <data/Skeleton.hpp>
#include <engine/GameData.hpp>
#include <engine/GameState.hpp>
#include <glm/gtc/type_ptr.hpp>

View File

@ -6,7 +6,6 @@
#include <engine/GameState.hpp>
#include <engine/GameData.hpp>
#include <engine/Animator.hpp>
#include <data/Skeleton.hpp>
#include <core/Logger.hpp>
#include <ai/PlayerController.hpp>
#include <data/CutsceneData.hpp>

View File

@ -3,7 +3,6 @@
#include <QMouseEvent>
#include <algorithm>
#include <data/Clump.hpp>
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <objects/CharacterObject.hpp>
@ -81,9 +80,8 @@ void ViewerWidget::paintGL() {
r.setViewport(width(), height());
if (dummyObject && dummyObject->animator && dummyObject->skeleton) {
if (dummyObject && dummyObject->animator) {
dummyObject->animator->tick(1.f / 60.f);
dummyObject->skeleton->interpolate(1.f);
}
r.getRenderer()->invalidate();

View File

@ -1,10 +1,9 @@
#include "DFFFramesTreeModel.hpp"
#include <data/Clump.hpp>
#include <data/Skeleton.hpp>
DFFFramesTreeModel::DFFFramesTreeModel(Clump* m, Skeleton* skel,
DFFFramesTreeModel::DFFFramesTreeModel(Clump* m,
QObject* parent)
: QAbstractItemModel(parent), model(m), skeleton(skel) {
: QAbstractItemModel(parent), model(m) {
}
int DFFFramesTreeModel::columnCount(const QModelIndex& parent) const {
@ -59,10 +58,7 @@ QVariant DFFFramesTreeModel::data(const QModelIndex& index, int role) const {
}
} else if (role == Qt::CheckStateRole) {
if (index.column() == 0) {
if (skeleton) {
return skeleton->getData(f->getIndex()).enabled ? Qt::Checked
: Qt::Unchecked;
}
return true;
}
}
return QVariant();
@ -77,11 +73,10 @@ bool DFFFramesTreeModel::setData(const QModelIndex& index,
ModelFrame* f = static_cast<ModelFrame*>(index.internalPointer());
if (role == Qt::CheckStateRole) {
if (index.column() == 0 && skeleton) {
if (index.column() == 0) {
if ((Qt::CheckState)value.toInt() == Qt::Checked) {
skeleton->setEnabled(f, true);
RW_UNIMPLEMENTED("Hiding Frames");
} else {
skeleton->setEnabled(f, false);
}
return true;
}
@ -97,7 +92,7 @@ Qt::ItemFlags DFFFramesTreeModel::flags(const QModelIndex& index) const {
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (index.column() == 0 && skeleton) {
if (index.column() == 0) {
flags |= Qt::ItemIsUserCheckable;
}

View File

@ -5,14 +5,12 @@
#include <rw/types.hpp>
class Clump;
class Skeleton;
class DFFFramesTreeModel : public QAbstractItemModel {
Clump* model;
Skeleton* skeleton;
public:
explicit DFFFramesTreeModel(Clump* m, Skeleton* skel, QObject* parent = 0);
explicit DFFFramesTreeModel(Clump* m, QObject* parent = 0);
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;

View File

@ -1,6 +1,5 @@
#include "ModelViewer.hpp"
#include <QDebug>
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <fstream>
#include <objects/GameObject.hpp>
@ -9,7 +8,7 @@
ModelViewer::ModelViewer(ViewerWidget* viewer, QWidget* parent,
Qt::WindowFlags f)
: ViewerInterface(parent, f), viewing(nullptr), skeleton(nullptr) {
: ViewerInterface(parent, f), viewing(nullptr) {
mainSplit = new QSplitter;
mainLayout = new QVBoxLayout;
@ -42,19 +41,14 @@ void ModelViewer::setViewerWidget(ViewerWidget* widget) {
void ModelViewer::showModel(Clump* model) {
viewing = model;
if (skeleton) {
delete skeleton;
}
skeleton = new Skeleton();
viewerWidget->showModel(model);
frames->setModel(model, nullptr);
frames->setModel(model);
}
void ModelViewer::showObject(uint16_t object) {
viewerWidget->showObject(object);
viewing = viewerWidget->currentModel();
skeleton = viewerWidget->currentObject()->skeleton;
frames->setModel(viewing, skeleton);
frames->setModel(viewing);
}
void ModelViewer::loadAnimations(const QString& file) {

View File

@ -15,7 +15,6 @@
class ViewerWidget;
class Clump;
class Skeleton;
class ModelFramesWidget;
class Animation;
@ -23,7 +22,6 @@ class ModelViewer : public ViewerInterface {
Q_OBJECT
Clump* viewing;
Skeleton* skeleton;
QSplitter* mainSplit;
QVBoxLayout* mainLayout;

View File

@ -33,7 +33,7 @@ ModelFramesWidget::ModelFramesWidget(QWidget* parent, Qt::WindowFlags flags)
setLayout(_layout);
}
void ModelFramesWidget::setModel(Clump* model, Skeleton* skeleton) {
void ModelFramesWidget::setModel(Clump* model) {
if (framemodel) {
delete framemodel;
framemodel = nullptr;
@ -41,7 +41,7 @@ void ModelFramesWidget::setModel(Clump* model, Skeleton* skeleton) {
}
gmodel = model;
if (model != nullptr) {
framemodel = new DFFFramesTreeModel(model, skeleton, this);
framemodel = new DFFFramesTreeModel(model, this);
tree->setModel(framemodel);
tree->setDisabled(false);
connect(tree->selectionModel(),

View File

@ -30,7 +30,7 @@ public:
public slots:
void setModel(Clump* model, Skeleton* skeleton);
void setModel(Clump* model);
signals:

View File

@ -38,7 +38,6 @@ set(TEST_SOURCES
"test_rwbstream.cpp"
"test_SaveGame.cpp"
"test_scriptmachine.cpp"
"test_skeleton.cpp"
"test_state.cpp"
"test_text.cpp"
"test_trafficdirector.cpp"

View File

@ -1,6 +1,5 @@
#include <boost/test/unit_test.hpp>
#include <data/Clump.hpp>
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <glm/gtx/string_cast.hpp>
#include "test_globals.hpp"
@ -10,7 +9,6 @@ BOOST_AUTO_TEST_SUITE(AnimationTests)
#if RW_TEST_WITH_DATA
BOOST_AUTO_TEST_CASE(test_matrix) {
{
Skeleton skeleton;
Animation animation;
/** Models are currently needed to relate animation bones <=> model

View File

@ -1,63 +0,0 @@
#include <boost/test/unit_test.hpp>
#include <data/Skeleton.hpp>
#include <glm/glm.hpp>
BOOST_AUTO_TEST_SUITE(SkeletonTests)
BOOST_AUTO_TEST_CASE(test_methods) {
Skeleton::FrameTransform t1{glm::vec3(0.f, 0.f, 0.f),
glm::quat(0.f, 0.f, 0.f, 0.f)};
Skeleton::FrameTransform t2{glm::vec3(1.f, 0.f, 0.f),
glm::quat(0.f, 0.f, 1.f, 0.f)};
Skeleton skeleton;
skeleton.setAllData({{0, {t1, t2, true}}});
BOOST_CHECK(skeleton.getData(0).a.translation == t1.translation);
BOOST_CHECK(skeleton.getData(0).a.rotation == t1.rotation);
BOOST_CHECK(skeleton.getData(0).b.translation == t2.translation);
BOOST_CHECK(skeleton.getData(0).b.rotation == t2.rotation);
BOOST_CHECK(skeleton.getData(0).enabled);
skeleton.setData(0, {t2, t1, false});
BOOST_CHECK(skeleton.getData(0).a.translation == t2.translation);
BOOST_CHECK(skeleton.getData(0).a.rotation == t2.rotation);
BOOST_CHECK(skeleton.getData(0).b.translation == t1.translation);
BOOST_CHECK(skeleton.getData(0).b.rotation == t1.rotation);
BOOST_CHECK(!skeleton.getData(0).enabled);
}
BOOST_AUTO_TEST_CASE(test_interpolate) {
Skeleton::FrameTransform t1{glm::vec3(0.f, 0.f, 0.f),
glm::quat(0.f, 0.f, 0.f, 0.f)};
Skeleton::FrameTransform t2{glm::vec3(1.f, 0.f, 0.f),
glm::quat(0.f, 0.f, 1.f, 0.f)};
Skeleton skeleton;
skeleton.setAllData({{0, {t2, t1, true}}});
/** Without calling Skeleton::interpolate(alpha) the result is identity */
BOOST_CHECK(skeleton.getInterpolated(0).translation ==
Skeleton::IdentityTransform.translation);
BOOST_CHECK(skeleton.getInterpolated(0).rotation ==
Skeleton::IdentityTransform.rotation);
skeleton.interpolate(0.f);
BOOST_CHECK(skeleton.getInterpolated(0).translation == t1.translation);
BOOST_CHECK(skeleton.getInterpolated(0).rotation == t1.rotation);
skeleton.interpolate(1.f);
BOOST_CHECK(skeleton.getInterpolated(0).translation == t2.translation);
BOOST_CHECK(skeleton.getInterpolated(0).rotation == t2.rotation);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -1,6 +1,5 @@
#include <boost/test/unit_test.hpp>
#include <data/Clump.hpp>
#include <data/Skeleton.hpp>
#include <objects/VehicleObject.hpp>
#include "test_globals.hpp"