goat3d

diff src/goat3d_writexml.cc @ 19:b35427826b60

- added XML format reading support - wrote a rudimentary version of goatview
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 Sep 2013 06:58:37 +0300
parents bdfc8dd14965
children 0fe02696fb1e
line diff
     1.1 --- a/src/goat3d_writexml.cc	Fri Sep 27 03:17:36 2013 +0300
     1.2 +++ b/src/goat3d_writexml.cc	Fri Sep 27 06:58:37 2013 +0300
     1.3 @@ -1,11 +1,9 @@
     1.4  #include <stdarg.h>
     1.5  #include "goat3d_impl.h"
     1.6  #include "log.h"
     1.7 -#include "openctm.h"
     1.8  
     1.9  static bool write_material(const Scene *scn, goat3d_io *io, const Material *mat, int level);
    1.10  static bool write_mesh(const Scene *scn, goat3d_io *io, const Mesh *mesh, int idx, int level);
    1.11 -static void write_ctm_mesh(const Mesh *mesh, const char *fname);
    1.12  static bool write_light(const Scene *scn, goat3d_io *io, const Light *light, int level);
    1.13  static bool write_camera(const Scene *scn, goat3d_io *io, const Camera *cam, int level);
    1.14  static bool write_node(const Scene *scn, goat3d_io *io, const Node *node, int level);
    1.15 @@ -72,7 +70,9 @@
    1.16  	char *mesh_filename = (char*)alloca(strlen(prefix) + 32);
    1.17  	sprintf(mesh_filename, "%s-mesh%04d.ctm", prefix, idx);
    1.18  
    1.19 -	write_ctm_mesh(mesh, mesh_filename);
    1.20 +	if(!mesh->save(mesh_filename)) {
    1.21 +		return false;
    1.22 +	}
    1.23  
    1.24  	// then refer to that filename in the XML tags
    1.25  	xmlout(io, level, "<mesh>\n");
    1.26 @@ -85,75 +85,6 @@
    1.27  	return true;
    1.28  }
    1.29  
    1.30 -static void write_ctm_mesh(const Mesh *mesh, const char *fname)
    1.31 -{
    1.32 -	int vnum = (int)mesh->vertices.size();
    1.33 -
    1.34 -	CTMcontext ctm = ctmNewContext(CTM_EXPORT);
    1.35 -
    1.36 -	// vertices, normals, and face-vertex indices
    1.37 -	ctmDefineMesh(ctm, &mesh->vertices[0].x, vnum, (CTMuint*)mesh->faces[0].v,
    1.38 -			mesh->faces.size(), mesh->normals.empty() ? 0 : &mesh->normals[0].x);
    1.39 -
    1.40 -	// texture coordinates
    1.41 -	if(!mesh->texcoords.empty()) {
    1.42 -		ctmAddUVMap(ctm, &mesh->texcoords[0].x, "texcoord", 0);
    1.43 -	}
    1.44 -
    1.45 -	// vertex colors
    1.46 -	if(!mesh->colors.empty()) {
    1.47 -		ctmAddAttribMap(ctm, &mesh->colors[0].x, "color");
    1.48 -	}
    1.49 -
    1.50 -	// skin weights
    1.51 -	if(!mesh->skin_weights.empty()) {
    1.52 -		ctmAddAttribMap(ctm, &mesh->skin_weights[0].x, "skin_weight");
    1.53 -	}
    1.54 -
    1.55 -	// if either of the non-float4 attributes are present we need to make a tmp array
    1.56 -	CTMfloat *attr_array = 0;
    1.57 -	if(!mesh->tangents.empty() || !mesh->skin_matrices.empty()) {
    1.58 -		attr_array = new CTMfloat[vnum * 4 * sizeof *attr_array];
    1.59 -	}
    1.60 -
    1.61 -	// tangents
    1.62 -	if(!mesh->tangents.empty()) {
    1.63 -		CTMfloat *ptr = attr_array;
    1.64 -
    1.65 -		for(int i=0; i<vnum; i++) {
    1.66 -			*ptr++ = mesh->tangents[i].x;
    1.67 -			*ptr++ = mesh->tangents[i].y;
    1.68 -			*ptr++ = mesh->tangents[i].z;
    1.69 -			*ptr++ = 1.0;
    1.70 -		}
    1.71 -		ctmAddAttribMap(ctm, attr_array, "tangent");
    1.72 -	}
    1.73 -
    1.74 -	// skin matrix indices (4 per vertex)
    1.75 -	if(!mesh->skin_matrices.empty()) {
    1.76 -		CTMfloat *ptr = attr_array;
    1.77 -
    1.78 -		for(int i=0; i<vnum; i++) {
    1.79 -			*ptr++ = (float)mesh->skin_matrices[i].x;
    1.80 -			*ptr++ = (float)mesh->skin_matrices[i].y;
    1.81 -			*ptr++ = (float)mesh->skin_matrices[i].z;
    1.82 -			*ptr++ = (float)mesh->skin_matrices[i].w;
    1.83 -		}
    1.84 -		ctmAddAttribMap(ctm, attr_array, "skin_matrix");
    1.85 -	}
    1.86 -
    1.87 -	delete [] attr_array;
    1.88 -
    1.89 -	/* TODO find a way to specify the nodes participating in the skinning of this mesh
    1.90 -	 * probably in the comment field?
    1.91 -	 */
    1.92 -
    1.93 -	logmsg(LOG_INFO, "saving CTM mesh file: %s\n", fname);
    1.94 -	ctmSave(ctm, fname);
    1.95 -
    1.96 -	ctmFreeContext(ctm);
    1.97 -}
    1.98 -
    1.99  static bool write_light(const Scene *scn, goat3d_io *io, const Light *light, int level)
   1.100  {
   1.101  	return true;