Skip to content

Commit

Permalink
use ofxGML
Browse files Browse the repository at this point in the history
  • Loading branch information
underdoeg committed Jun 27, 2014
1 parent 493ed60 commit ee072cb
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 23 deletions.
1 change: 1 addition & 0 deletions example/addons.make
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ofxBlender
ofxGLM
Binary file modified example/bin/data/test.blend
Binary file not shown.
266 changes: 266 additions & 0 deletions example/codelite/example.project

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions example/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ void ofApp::setup() {
file.exportStructure();
scene = file.getScene(0);
scene->setDebug(true);
scene->timeline.setEndless(true);
//scene->timeline.setLoop(true);
//scene->timeline.setEndless(true);

scene->getActiveCamera()->addConstraint(new LookAtConstraint(scene->getMesh(0)));
//scene->getActiveCamera()->addConstraint(new LookAtConstraint(scene->getMesh(0)));
}

void ofApp::update() {
Expand Down
10 changes: 6 additions & 4 deletions src/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void Timeline::step() {
void Timeline::setTime(unsigned long long t) {
if(!isPlaying)
return;

t = t - timeOffset;

if(isPaused) {
Expand All @@ -40,9 +40,9 @@ void Timeline::setTime(unsigned long long t) {
//timeOld = time;
return;
}
cout << t << endl;


Timeline* _this = this;
ofNotifyEvent(preFrame, _this);

if(isLoop && !isEndless) {
time = t % duration;
Expand Down Expand Up @@ -72,6 +72,8 @@ void Timeline::setTime(unsigned long long t) {
for(Timeline* child: children) {
child->setTime(time);
}

ofNotifyEvent(postFrame, _this);
timeOld = time;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,11 @@ class Timeline {
unsigned long long getTime();
unsigned long long getDuration();


ofEvent<Timeline*> started;
ofEvent<Timeline*> ended;
ofEvent<Timeline*> preFrame;
ofEvent<Timeline*> postFrame;
ofEvent<std::string> markerTriggered;

private:
Expand Down
45 changes: 29 additions & 16 deletions src/Object.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Object.h"
#include "Layer.h"
#include "Scene.h"
#include "gtx/euler_angles.hpp"

namespace ofx {

Expand All @@ -14,10 +15,16 @@ Object::Object() {
layer = NULL;
lookAtTarget = NULL;
lookAtUp.set(0, 1, 0);

animIsEuler = false;

timeline.setDefaultHandler<float>(std::bind(&Object::onAnimationDataFloat, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
timeline.setDefaultHandler<bool>(std::bind(&Object::onAnimationDataBool, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
timeline.setDefaultHandler<ofVec3f>(std::bind(&Object::onAnimationDataVec3f, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
timeline.setDefaultHandler<ofQuaternion>(std::bind(&Object::onAnimationDataQuat, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

ofAddListener(timeline.preFrame, this, &Object::onTimelinePreFrame);
ofAddListener(timeline.postFrame, this, &Object::onTimelinePostFrame);
}

Object::~Object() {
Expand Down Expand Up @@ -130,6 +137,24 @@ void Object::onScaleChanged() {

/////////////////////////////////////////////////////////////////////////////////

void Object::onTimelinePreFrame(Timeline*&) {
animIsEuler = false;

//TODO: only trigger when there is an euler animation
glm::quat quat = toGlm(getOrientationQuat());
eulerRot = glm::eulerAngles(quat);
}

void Object::onTimelinePostFrame(Timeline*&) {

if(animIsEuler) {
ofQuaternion QuatAroundX = ofQuaternion( eulerRot.x, ofVec3f(1.0,0.0,0.0) );
ofQuaternion QuatAroundY = ofQuaternion( eulerRot.y, ofVec3f(0.0,1.0,0.0) );
ofQuaternion QuatAroundZ = ofQuaternion( eulerRot.z, ofVec3f(0.0,0.0,1.0) );
setOrientation(QuatAroundX * QuatAroundY * QuatAroundZ);
}
}

void Object::onAnimationDataFloat(float value, string address, int channel) {
//cout << channel << ":" << address << endl;
//cout << "MY VALUES : " << value << endl;
Expand All @@ -154,27 +179,15 @@ void Object::onAnimationDataFloat(float value, string address, int channel) {
}
setScale(scale);
} else if(address == "rotation_euler") {
ofVec3f rot = getOrientationEuler();
//ofQuaternion quat = getOrientationQuat();
//ofVec3f axis;

value = ofRadToDeg(value);
if(channel == 0) {
//tilt(value);
rot.x = value;
//axis = getXAxis();
eulerRot.x = value;
} else if(channel == 1) {
rot.y = value;
//pan(value);
//axis = getYAxis();
eulerRot.y = value;
} else if(channel == 2) {
rot.z = value;
//roll(value);
//axis = getZAxis();
eulerRot.z = value;
}
//quat.set(axis.x, axis.y, axis.z, value);
///setOrientation(quat);
setOrientation(rot);
animIsEuler = true;
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ofMain.h"
#include "Animation.h"
#include "Constraint.h"
#include "ofxGLM.h"

namespace ofx {
namespace blender {
Expand Down Expand Up @@ -66,14 +67,22 @@ class Object: public ofNode {
void onOrientationChanged();
void onPositionChanged();
void onScaleChanged();


void onTimelinePreFrame(Timeline*&);
void onTimelinePostFrame(Timeline*&);

private:
Object* lookAtTarget;
ofVec3f lookAtUp;
bool visible;
Object* parent;
std::vector<Object*> children;
std::vector<Constraint*> constraints;

//helpers for euler rotation
bool animIsEuler;
//ofVec3f eulerRot;
glm::vec3 eulerRot;
};

}
Expand Down

0 comments on commit ee072cb

Please # to comment.