+/*
+ * Set the colors of the triangles in the group as defined in a file.
+ */
+static int _model_set_colors(model_t* m, FILE* file)
+{
+ double a, r, g, b;
+ if (fscanf(file, " %lf %lf %lf %lf", &a, &r, &g, &b) != 4) {
+ fprintf(stderr, "Cannot read color values from scene.\n");
+ return -1;
+ }
+
+ for (const list_t* i = model_geometry(m); i; i = i->link) {
+ tri_t* t = (tri_t*)i->val;
+ t->a.c = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a);
+ t->b.c = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a);
+ t->c.c = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a);
+ }
+ return 0;
+}
+
+/*
+ * Concat a translation matrix to the transformation as defined in a file.
+ */
+static int _model_add_translate(model_t* m, FILE* file)
+{
+ double tx, ty, tz;
+ if (fscanf(file, " %lf %lf %lf", &tx, &ty, &tz) != 3) {
+ fprintf(stderr, "Cannot read translate coordinates from scene.\n");
+ return -1;
+ }
+ mat_t transform = MAT_TRANSLATE((scal_t)tx, (scal_t)ty, (scal_t)tz);
+ model_transform(m, &transform);
+ return 0;
+}
+
+/*
+ * Concat a rotation matrix to the transformation as defined in a file.
+ */
+static int _model_add_rotate(model_t* m, FILE* file)
+{
+ double theta, ax, ay, az;
+ if (fscanf(file, " %lf %lf %lf %lf", &theta, &ax, &ay, &az) != 4) {
+ fprintf(stderr, "Cannot read rotation angle from scene.\n");
+ return -1;
+ }
+ mat_t transform = MAT_ROTATE((scal_t)theta, (scal_t)ax, (scal_t)ay, (scal_t)az);
+ model_transform(m, &transform);
+ return 0;
+}
+
+/*
+ * Concat a scale matrix to the transformation as defined in a file.
+ */
+static int _model_add_scale(model_t* m, FILE* file)
+{
+ double sx, sy, sz;
+ if (fscanf(file, " %lf %lf %lf", &sx, &sy, &sz) != 3) {
+ fprintf(stderr, "Cannot read scale factors from scene.\n");
+ return -1;
+ }
+ mat_t transform = MAT_SCALE((scal_t)sx, (scal_t)sy, (scal_t)sz);
+ model_transform(m, &transform);
+ return 0;
+}
+
+/*
+ * Set the specular highlight and shininess factor for the group.
+ */
+static int _model_set_material(model_t* m, FILE* file)
+{
+ double sr, sg, sb, shininess;
+ if (fscanf(file, " %lf %lf %lf %lf", &sr, &sg, &sb, &shininess) != 4) {
+ fprintf(stderr, "Cannot read material information from scene.\n");
+ return -1;
+ }
+ model_material(m, color_new((scal_t)sr, (scal_t)sg, (scal_t)sb, S(1.0)), (scal_t)shininess);
+ return 0;
+}
+
+/*
+ * Add a light to the scene.
+ */
+static int _scene_add_light(scene_t* s, FILE* file)
+{
+ double lx, ly, lz, r, g, b;
+ if (fscanf(file, " %lf %lf %lf %lf %lf %lf",
+ &lx, &ly, &lz, &r, &g, &b) != 6) {
+ fprintf(stderr, "Cannot read light values from scene.\n");
+ return -1;
+ }
+ light_t* l = light_alloc(
+ vec_new(lx, ly, lz),
+ color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0)),
+ color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0))
+ );
+ list_push2(&s->lights, l, mem_free);
+ return 0;
+}
+
+