# HG changeset patch # User John Tsiombikas # Date 1380931702 -10800 # Node ID 8471225a460c5ab20086d9d79e0d9f6ea6e68b86 # Parent f43f4849c86aaa5969c5438a8d3a98357fb74b00# Parent d24f63e8031e54e20b099d45d26d27b1685857f4 merged diff -r f43f4849c86a -r 8471225a460c exporters/maxgoat/src/maxgoat.cc --- a/exporters/maxgoat/src/maxgoat.cc Sat Oct 05 03:07:45 2013 +0300 +++ b/exporters/maxgoat/src/maxgoat.cc Sat Oct 05 03:08:22 2013 +0300 @@ -286,6 +286,7 @@ } process_mesh(goat, mesh, maxobj); + goat3d_add_mesh(goat, mesh); } break; @@ -296,6 +297,7 @@ goat3d_set_node_object(node, GOAT3D_NODE_LIGHT, light); process_light(goat, light, maxobj); + goat3d_add_light(goat, light); } break; @@ -306,6 +308,7 @@ goat3d_set_node_object(node, GOAT3D_NODE_CAMERA, cam); process_camera(goat, cam, maxobj); + goat3d_add_camera(goat, cam); } break; @@ -328,11 +331,13 @@ maxobj->InitializeData(); int num_verts = maxmesh->GetNumberOfVerts(); + int num_faces = maxmesh->GetNumberOfFaces(); //assert(maxmesh->GetNumberOfTexVerts() == num_verts); float *vertices = new float[num_verts * 3]; float *normals = new float[num_verts * 3]; //float *texcoords = new float[num_verts * 2]; + int *indices = new int[num_faces * 3]; for(int i=0; iGetVertex(i, true); @@ -357,13 +362,24 @@ texcoords[i * 2 + 1] = tex.y; }*/ + // get the faces + for(int i=0; iGetFace(i); + indices[i * 3] = face->vert[0]; + indices[i * 3 + 1] = face->vert[1]; + indices[i * 3 + 2] = face->vert[2]; + // TODO at some point I'll have to split based on normal/texcoord indices + } + goat3d_set_mesh_attribs(mesh, GOAT3D_MESH_ATTR_VERTEX, vertices, num_verts); goat3d_set_mesh_attribs(mesh, GOAT3D_MESH_ATTR_NORMAL, normals, num_verts); //goat3d_set_mesh_attribs(mesh, GOAT3D_MESH_ATTR_TEXCOORD, texcoords, num_verts); + goat3d_set_mesh_faces(mesh, indices, num_faces); delete [] vertices; delete [] normals; //delete [] texcoords; + delete [] indices; } void GoatExporter::process_light(goat3d *goat, goat3d_light *light, IGameObject *maxobj) diff -r f43f4849c86a -r 8471225a460c goat3d.vcxproj --- a/goat3d.vcxproj Sat Oct 05 03:07:45 2013 +0300 +++ b/goat3d.vcxproj Sat Oct 05 03:08:22 2013 +0300 @@ -180,7 +180,7 @@ Disabled WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);OPENCTM_STATIC;BUILD_MAXPLUGIN 4244;4305;4996 - $(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2 + $(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2;$(SolutionDir)\libs\anim;$(SolutionDir)\libs\vmath Windows @@ -219,7 +219,7 @@ true WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);OPENCTM_STATIC 4244;4305;4996 - $(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2 + $(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2;$(SolutionDir)\libs\anim;$(SolutionDir)\libs\vmath Windows diff -r f43f4849c86a -r 8471225a460c src/goat3d.cc --- a/src/goat3d.cc Sat Oct 05 03:07:45 2013 +0300 +++ b/src/goat3d.cc Sat Oct 05 03:08:22 2013 +0300 @@ -1,12 +1,21 @@ #include #include +#include +#include #include "goat3d.h" #include "goat3d_impl.h" #include "log.h" +#ifndef _MSC_VER +#include +#else +#include +#endif + struct goat3d { Scene *scn; unsigned int flags; + char *search_path; }; struct goat3d_material : public Material {}; @@ -20,12 +29,15 @@ static long write_file(const void *buf, size_t bytes, void *uptr); static long seek_file(long offs, int whence, void *uptr); +static std::string clean_filename(const char *str); + extern "C" { struct goat3d *goat3d_create(void) { goat3d *goat = new goat3d; goat->flags = 0; + goat->search_path = 0; goat->scn = new Scene; goat3d_setopt(goat, GOAT3D_OPT_SAVEXML, 1); @@ -34,6 +46,7 @@ void goat3d_free(struct goat3d *g) { + delete g->search_path; delete g->scn; delete g; } @@ -60,6 +73,24 @@ return -1; } + /* if the filename contained any directory components, keep the prefix + * to use it as a search path for external mesh file loading + */ + g->search_path = new char[strlen(fname) + 1]; + strcpy(g->search_path, fname); + + char *slash = strrchr(g->search_path, '/'); + if(slash) { + *slash = 0; + } else { + if((slash = strrchr(g->search_path, '\\'))) { + *slash = 0; + } else { + delete [] g->search_path; + g->search_path = 0; + } + } + int res = goat3d_load_file(g, fp); fclose(fp); return res; @@ -197,7 +228,7 @@ void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname) { - (*mtl)[attrib].map = std::string(mapname); + (*mtl)[attrib].map = clean_filename(mapname); } const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib) @@ -706,3 +737,23 @@ } return ftell((FILE*)uptr); } + +static std::string clean_filename(const char *str) +{ + const char *last_slash = strrchr(str, '/'); + if(!last_slash) { + last_slash = strrchr(str, '\\'); + } + + if(last_slash) { + str = last_slash + 1; + } + + char *buf = (char*)alloca(strlen(str) + 1); + char *dest = buf; + while(*str) { + char c = *str++; + *dest++ = tolower(c); + } + return buf; +} diff -r f43f4849c86a -r 8471225a460c src/goat3d_writexml.cc --- a/src/goat3d_writexml.cc Sat Oct 05 03:07:45 2013 +0300 +++ b/src/goat3d_writexml.cc Sat Oct 05 03:08:22 2013 +0300 @@ -97,6 +97,46 @@ static bool write_node(const Scene *scn, goat3d_io *io, const Node *node, int level) { + xmlout(io, level, "\n"); + xmlout(io, level + 1, "\n", node->get_name()); + + XFormNode *parent = node->get_parent(); + if(parent) { + xmlout(io, level + 1, "\n", parent->get_name()); + } + + const char *type = 0; + const Object *obj = node->get_object(); + if(dynamic_cast(obj)) { + type = "mesh"; + } else if(dynamic_cast(obj)) { + type = "light"; + } else if(dynamic_cast(obj)) { + type = "camera"; + } + + if(type) { + xmlout(io, level + 1, "<%s string=\"%s\"/>\n", type, obj->name.c_str()); + } + + Vector3 pos = node->get_node_position(); + Quaternion rot = node->get_node_rotation(); + Vector3 scale = node->get_node_scaling(); + Vector3 pivot = node->get_pivot(); + + Matrix4x4 xform; + node->get_node_xform(0, &xform); + + xmlout(io, level + 1, "\n", pos.x, pos.y, pos.z); + xmlout(io, level + 1, "\n", rot.v.x, rot.v.y, rot.v.z, rot.s); + xmlout(io, level + 1, "\n", scale.x, scale.y, scale.z); + xmlout(io, level + 1, "\n", pivot.x, pivot.y, pivot.z); + + xmlout(io, level + 1, "\n", xform[0][0], xform[0][1], xform[0][2], xform[0][3]); + xmlout(io, level + 1, "\n", xform[1][0], xform[1][1], xform[1][2], xform[1][3]); + xmlout(io, level + 1, "\n", xform[2][0], xform[2][1], xform[2][2], xform[2][3]); + + xmlout(io, level, "\n"); return true; } diff -r f43f4849c86a -r 8471225a460c src/mesh.cc --- a/src/mesh.cc Sat Oct 05 03:07:45 2013 +0300 +++ b/src/mesh.cc Sat Oct 05 03:08:22 2013 +0300 @@ -110,11 +110,16 @@ bool Mesh::save(const char *fname) const { int vnum = (int)vertices.size(); + int fnum = (int)faces.size(); + + if(!vnum || !fnum) { + return false; + } CTMcontext ctm = ctmNewContext(CTM_EXPORT); // vertices, normals, and face-vertex indices - ctmDefineMesh(ctm, &vertices[0].x, vnum, (CTMuint*)faces[0].v, faces.size(), + ctmDefineMesh(ctm, &vertices[0].x, vnum, (CTMuint*)faces[0].v, fnum, normals.empty() ? 0 : &normals[0].x); // texture coordinates diff -r f43f4849c86a -r 8471225a460c src/xform_node.cc --- a/src/xform_node.cc Sat Oct 05 03:07:45 2013 +0300 +++ b/src/xform_node.cc Sat Oct 05 03:08:22 2013 +0300 @@ -11,6 +11,8 @@ { anm = new anm_node; anm_init_node(anm); + + parent = 0; } XFormNode::~XFormNode() @@ -55,6 +57,7 @@ { children.push_back(child); anm_link_node(anm, child->anm); + child->parent = this; } void XFormNode::remove_child(XFormNode *child) @@ -65,6 +68,7 @@ children.erase(it); anm_unlink_node(anm, child->anm); } + child->parent = 0; } int XFormNode::get_children_count() const @@ -88,6 +92,11 @@ return 0; } +XFormNode *XFormNode::get_parent() const +{ + return parent; +} + void XFormNode::set_position(const Vector3 &pos, long tmsec) { anm_set_position(anm, v3_cons(pos.x, pos.y, pos.z), ANM_MSEC2TM(tmsec)); diff -r f43f4849c86a -r 8471225a460c src/xform_node.h --- a/src/xform_node.h Sat Oct 05 03:07:45 2013 +0300 +++ b/src/xform_node.h Sat Oct 05 03:08:22 2013 +0300 @@ -21,6 +21,7 @@ private: struct anm_node *anm; std::vector children; + XFormNode *parent; Interp interp; Extrap extrap; @@ -51,6 +52,7 @@ virtual XFormNode *get_child(int idx); virtual const XFormNode *get_child(int idx) const; + virtual XFormNode *get_parent() const; virtual void set_position(const Vector3 &pos, long tmsec = 0); virtual Vector3 get_node_position(long tmsec = 0) const;