nuclear@14: #include nuclear@14: #include "goat3d_impl.h" nuclear@17: #include "log.h" nuclear@14: nuclear@14: static bool write_material(const Scene *scn, goat3d_io *io, const Material *mat, int level); nuclear@14: static bool write_mesh(const Scene *scn, goat3d_io *io, const Mesh *mesh, int idx, int level); nuclear@14: static bool write_light(const Scene *scn, goat3d_io *io, const Light *light, int level); nuclear@14: static bool write_camera(const Scene *scn, goat3d_io *io, const Camera *cam, int level); nuclear@14: static bool write_node(const Scene *scn, goat3d_io *io, const Node *node, int level); nuclear@14: static void xmlout(goat3d_io *io, int level, const char *fmt, ...); nuclear@14: nuclear@14: bool Scene::savexml(goat3d_io *io) const nuclear@14: { nuclear@14: xmlout(io, 0, "\n"); nuclear@14: nuclear@14: // write environment stuff nuclear@14: xmlout(io, 1, "\n"); nuclear@18: xmlout(io, 2, "\n", ambient.x, ambient.y, ambient.z); nuclear@18: xmlout(io, 1, "\n\n"); nuclear@14: nuclear@14: for(size_t i=0; i\n"); nuclear@14: return true; nuclear@14: } nuclear@14: nuclear@14: static bool write_material(const Scene *scn, goat3d_io *io, const Material *mat, int level) nuclear@14: { nuclear@14: xmlout(io, level, "\n"); nuclear@14: xmlout(io, level + 1, "\n", mat->name.c_str()); nuclear@14: nuclear@14: for(int i=0; iget_attrib_count(); i++) { nuclear@14: xmlout(io, level + 1, "\n"); nuclear@14: xmlout(io, level + 2, "\n", mat->get_attrib_name(i)); nuclear@14: nuclear@14: const MaterialAttrib &attr = (*mat)[i]; nuclear@18: xmlout(io, level + 2, "\n", attr.value.x, nuclear@14: attr.value.y, attr.value.z, attr.value.w); nuclear@14: if(!attr.map.empty()) { nuclear@14: xmlout(io, level + 2, "\n", attr.map.c_str()); nuclear@14: } nuclear@14: xmlout(io, level + 1, "\n"); nuclear@14: } nuclear@18: xmlout(io, level, "\n\n"); nuclear@14: return true; nuclear@14: } nuclear@14: nuclear@14: static bool write_mesh(const Scene *scn, goat3d_io *io, const Mesh *mesh, int idx, int level) nuclear@14: { nuclear@14: // first write the external (openctm) mesh file nuclear@14: const char *prefix = scn->get_name(); nuclear@14: if(!prefix) { nuclear@14: prefix = "goat"; nuclear@14: } nuclear@14: nuclear@14: char *mesh_filename = (char*)alloca(strlen(prefix) + 32); nuclear@14: sprintf(mesh_filename, "%s-mesh%04d.ctm", prefix, idx); nuclear@14: nuclear@19: if(!mesh->save(mesh_filename)) { nuclear@19: return false; nuclear@19: } nuclear@14: nuclear@14: // then refer to that filename in the XML tags nuclear@14: xmlout(io, level, "\n"); nuclear@14: xmlout(io, level + 1, "\n", mesh->name.c_str()); nuclear@17: if(mesh->material) { nuclear@17: xmlout(io, level + 1, "\n", mesh->material->name.c_str()); nuclear@17: } nuclear@14: xmlout(io, level + 1, "\n", mesh_filename); nuclear@18: xmlout(io, level, "\n\n"); nuclear@14: return true; nuclear@14: } nuclear@14: nuclear@14: static bool write_light(const Scene *scn, goat3d_io *io, const Light *light, int level) nuclear@14: { nuclear@14: return true; nuclear@14: } nuclear@14: nuclear@14: static bool write_camera(const Scene *scn, goat3d_io *io, const Camera *cam, int level) nuclear@14: { nuclear@14: return true; nuclear@14: } nuclear@14: nuclear@14: static bool write_node(const Scene *scn, goat3d_io *io, const Node *node, int level) nuclear@14: { nuclear@14: return true; nuclear@14: } nuclear@14: nuclear@14: nuclear@14: static void xmlout(goat3d_io *io, int level, const char *fmt, ...) nuclear@14: { nuclear@14: for(int i=0; i