blob: 18463a8c8ed32606310571a6881a1f4f8bf33644 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#ifndef MORPHMESH_H
#define MORPHMESH_H
#include <iostream>
#include <iterator>
#include <ofMesh.h>
#include <ofxXmlSettings.h>
/*
Tim Redfern, March 2012
Loads meshes in Oak3D XML format
Draws blended morph targets
Multiple meshes are loaded as morph targets
Coords are absolute
--managing movement sequences
--cycles can refer to targets by name
--high level controller objects can refer to animation sequences by name
--this makes it impossible for a re-odering to banjax everything
cycles have a start time, and they either loop or act as a transition
Working out the morphs is a question of:
-working out which cycles are active based on behaviours
-adding their morph targets into the current vector of targets
behaviours are triggered by things like spotting people or avoiding the wall.
These could be parameterised on top of the rest?
*/
struct morphWeight
{
string name;
float weight;
};
struct key
{
key(float _val,float _time) {value=_val;time=_time;}
float value;
float time;
};
class track
{
//a single morph channel. keys a single morph target within a single sequence
public:
track();
string target;
multimap<float,float> keys;
float evaluate(float time);
};
class sequence
{
//tracks a morph sequence: an animation cycle or transition
//targets are named keys
//animation consists of time,value pairs for any number of named tracks
//the sequence knows the time (absolute seconds) it was started
//sequencer keeps track of playback time and start/stop of sequences
//tracks is a map of time,value pairs - built in interpolation via multimap
public:
sequence();
map<string,track> tracks;
vector<morphWeight> evaluate();
private:
float length;
float startTime;
float fadeinTime;
float fadeoutTime;
bool loop,active;
};
class morphmesh : public ofMesh
{
public:
morphmesh();
morphmesh(string filename);
bool loadMesh(string filename);
bool loadSeqs(string filename);
bool isLoaded();
void draw();
void draw(int target);
void draw(string target);
void draw(const vector<string>& targets, const vector<float>& weights);
void drawAnimated(); //evaluates all active sequences via iterator and builds a collection of targets and weights for above
int getNumTargets();
map< string,sequence > sequences; //public for direct access
protected:
private:
map< string,vector<ofVec3f> > morphs;
bool loaded;
};
#endif // MORPHMESH_H
|