# HG changeset patch # User John Tsiombikas # Date 1380485144 -10800 # Node ID 0fe02696fb1eaf0e849ee48e62f157f1ddc0fdaf # Parent 3d669155709df0c7f26fcf79c5e74a96308e069f yeeay, the max plugin works :) diff -r 3d669155709d -r 0fe02696fb1e exporters/maxgoat/src/maxgoat.cc --- a/exporters/maxgoat/src/maxgoat.cc Sun Sep 29 21:53:03 2013 +0300 +++ b/exporters/maxgoat/src/maxgoat.cc Sun Sep 29 23:05:44 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 3d669155709d -r 0fe02696fb1e goat3d.vcxproj --- a/goat3d.vcxproj Sun Sep 29 21:53:03 2013 +0300 +++ b/goat3d.vcxproj Sun Sep 29 23:05:44 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 3d669155709d -r 0fe02696fb1e src/goat3d_writexml.cc --- a/src/goat3d_writexml.cc Sun Sep 29 21:53:03 2013 +0300 +++ b/src/goat3d_writexml.cc Sun Sep 29 23:05:44 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 3d669155709d -r 0fe02696fb1e src/mesh.cc --- a/src/mesh.cc Sun Sep 29 21:53:03 2013 +0300 +++ b/src/mesh.cc Sun Sep 29 23:05:44 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 3d669155709d -r 0fe02696fb1e src/xform_node.cc --- a/src/xform_node.cc Sun Sep 29 21:53:03 2013 +0300 +++ b/src/xform_node.cc Sun Sep 29 23:05:44 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 3d669155709d -r 0fe02696fb1e src/xform_node.h --- a/src/xform_node.h Sun Sep 29 21:53:03 2013 +0300 +++ b/src/xform_node.h Sun Sep 29 23:05:44 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;