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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
#ifndef ANIMTOOL_SCENE_H_
#define ANIMTOOL_SCENE_H_
#include "util/container.h"
#include "util/str.h"
#include "expr.h"
#include "draw.h"
#include "resource.h"
struct bone
{
// mutable
float pos[3];
};
enum pos_type
{
POS_ABSOLUTE,
POS_ATTACHED,
};
struct pos
{
enum pos_type type;
union {
struct expr absolute[3];
struct loc_str attach_name;
struct bone *attach;
};
};
struct camera
{
bool roll;
struct pos target;
// mutable
float pos[3];
float up[3];
};
enum transform_op
{
TR_TRANSLATE,
TR_SCALE,
TR_ROTATE,
};
#define TRANSFORM_OPS_N 3
struct transform
{
bool has_op[TRANSFORM_OPS_N][3];
struct expr op[TRANSFORM_OPS_N][3];
array(struct node) children;
};
struct surface
{
option(struct texture) texture;
struct expr color;
};
struct object
{
struct surface surface;
struct mesh mesh;
};
enum node_type
{
NODE_TRANSFORM,
NODE_OBJECT,
NODE_CAMERA,
NODE_BONE,
NODE_LIGHT,
};
struct node
{
enum node_type type;
union {
struct transform transform;
struct camera camera;
struct object object;
struct bone bone;
};
};
enum seq_inst_type
{
SEQ_TIME,
SEQ_POV,
SEQ_REP,
};
#define SEQ_TIMES_INF ((unsigned int) -1)
struct seq_inst
{
enum seq_inst_type type;
union {
struct loc_str pov_name;
struct camera *pov;
struct {
unsigned int times;
array(struct seq_inst) children;
} rep;
double time;
};
};
enum projection_type
{
PROJ_PERSPECTIVE,
PROJ_ORTHO,
};
struct projection
{
enum projection_type type;
union {
struct {
// l r b t n f
float planes[6];
} ortho;
struct {
// n f
float planes[2];
struct expr fov;
} perspective;
};
};
struct scene
{
unsigned int fps;
unsigned int size[2];
str outfile;
array(struct seq_inst) seq;
struct camera *camera;
struct projection proj;
option(struct surface) bg;
option(double) live;
struct node root;
};
enum var_type
{
VAR_NUMBER,
VAR_STRING,
};
struct var
{
enum var_type type;
union {
str string;
double number;
};
};
struct registry
{
map(str) raw_vars;
map(struct var) vars;
map(struct camera *) cameras;
map(struct bone *) bones;
struct camera *default_camera;
};
void proj_default(struct projection *proj, enum projection_type type);
void proj_free(struct projection *proj);
void surface_init(struct surface *surf);
void surface_free(struct surface *surf);
void registry_free(struct registry *reg);
void scene_init(struct scene *scene);
void scene_free(struct scene *scene);
void scene_bind(struct scene *scene, struct source *src, struct registry *reg);
void scene_load(struct scene *scene, struct source *src, struct draw_backend *draw);
#endif
|