+
+static csg_object *load_object(struct ts_node *node)
+{
+ float *apos, *arot, *ascale, *acolor;
+ float aroughness;
+ struct ts_node *c;
+ csg_object *o, *olist = 0, *otail = 0;
+ int num_subobj = 0;
+
+ c = node->child_list;
+ while(c) {
+ if((o = load_object(c))) {
+ if(olist) {
+ otail->ob.next = o;
+ otail = o;
+ } else {
+ olist = otail = o;
+ }
+ ++num_subobj;
+ }
+ c = c->next;
+ }
+
+ apos = ts_get_attr_vec(node, "position", 0);
+ arot = ts_get_attr_vec(node, "rotation", 0);
+ ascale = ts_get_attr_vec(node, "scaling", 0);
+ acolor = ts_get_attr_vec(node, "color", 0);
+ aroughness = ts_get_attr_num(node, "roughness", 0);
+
+ if(strcmp(node->name, "null") == 0) {
+ if(num_subobj) {
+ fprintf(stderr, "null can't have sub-objects\n");
+ goto err;
+ }
+ if(!(o = alloc_object(OB_NULL))) {
+ goto err;
+ }
+ return o;
+
+ } else if(strcmp(node->name, "sphere") == 0) {
+ if(num_subobj) {
+ fprintf(stderr, "sphere can't have sub-objects\n");
+ goto err;
+ }
+ if(!(o = alloc_object(OB_SPHERE))) {
+ goto err;
+ }
+ }
+
+err:
+ while(olist) {
+ o = olist;
+ olist = olist->ob.next;
+ csg_free_object(o);
+ }
+ return 0;
+}