summaryrefslogtreecommitdiff
path: root/src/scene.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/scene.h')
-rw-r--r--src/scene.h184
1 files changed, 184 insertions, 0 deletions
diff --git a/src/scene.h b/src/scene.h
new file mode 100644
index 0000000..dfcf635
--- /dev/null
+++ b/src/scene.h
@@ -0,0 +1,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