goat3d

changeset 30:0fe02696fb1e

yeeay, the max plugin works :)
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 29 Sep 2013 23:05:44 +0300
parents 3d669155709d
children 4058337fbb92
files exporters/maxgoat/src/maxgoat.cc goat3d.vcxproj src/goat3d_writexml.cc src/mesh.cc src/xform_node.cc src/xform_node.h
diffstat 6 files changed, 75 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/exporters/maxgoat/src/maxgoat.cc	Sun Sep 29 21:53:03 2013 +0300
     1.2 +++ b/exporters/maxgoat/src/maxgoat.cc	Sun Sep 29 23:05:44 2013 +0300
     1.3 @@ -286,6 +286,7 @@
     1.4  			}
     1.5  
     1.6  			process_mesh(goat, mesh, maxobj);
     1.7 +			goat3d_add_mesh(goat, mesh);
     1.8  		}
     1.9  		break;
    1.10  
    1.11 @@ -296,6 +297,7 @@
    1.12  			goat3d_set_node_object(node, GOAT3D_NODE_LIGHT, light);
    1.13  
    1.14  			process_light(goat, light, maxobj);
    1.15 +			goat3d_add_light(goat, light);
    1.16  		}
    1.17  		break;
    1.18  
    1.19 @@ -306,6 +308,7 @@
    1.20  			goat3d_set_node_object(node, GOAT3D_NODE_CAMERA, cam);
    1.21  
    1.22  			process_camera(goat, cam, maxobj);
    1.23 +			goat3d_add_camera(goat, cam);
    1.24  		}
    1.25  		break;
    1.26  
    1.27 @@ -328,11 +331,13 @@
    1.28  	maxobj->InitializeData();
    1.29  
    1.30  	int num_verts = maxmesh->GetNumberOfVerts();
    1.31 +	int num_faces = maxmesh->GetNumberOfFaces();
    1.32  	//assert(maxmesh->GetNumberOfTexVerts() == num_verts);
    1.33  
    1.34  	float *vertices = new float[num_verts * 3];
    1.35  	float *normals = new float[num_verts * 3];
    1.36  	//float *texcoords = new float[num_verts * 2];
    1.37 +	int *indices = new int[num_faces * 3];
    1.38  
    1.39  	for(int i=0; i<num_verts; i++) {
    1.40  		Point3 v = maxmesh->GetVertex(i, true);
    1.41 @@ -357,13 +362,24 @@
    1.42  		texcoords[i * 2 + 1] = tex.y;
    1.43  	}*/
    1.44  
    1.45 +	// get the faces
    1.46 +	for(int i=0; i<num_faces; i++) {
    1.47 +		FaceEx *face = maxmesh->GetFace(i);
    1.48 +		indices[i * 3] = face->vert[0];
    1.49 +		indices[i * 3 + 1] = face->vert[1];
    1.50 +		indices[i * 3 + 2] = face->vert[2];
    1.51 +		// TODO at some point I'll have to split based on normal/texcoord indices
    1.52 +	}
    1.53 +
    1.54  	goat3d_set_mesh_attribs(mesh, GOAT3D_MESH_ATTR_VERTEX, vertices, num_verts);
    1.55  	goat3d_set_mesh_attribs(mesh, GOAT3D_MESH_ATTR_NORMAL, normals, num_verts);
    1.56  	//goat3d_set_mesh_attribs(mesh, GOAT3D_MESH_ATTR_TEXCOORD, texcoords, num_verts);
    1.57 +	goat3d_set_mesh_faces(mesh, indices, num_faces);
    1.58  
    1.59  	delete [] vertices;
    1.60  	delete [] normals;
    1.61  	//delete [] texcoords;
    1.62 +	delete [] indices;
    1.63  }
    1.64  
    1.65  void GoatExporter::process_light(goat3d *goat, goat3d_light *light, IGameObject *maxobj)
     2.1 --- a/goat3d.vcxproj	Sun Sep 29 21:53:03 2013 +0300
     2.2 +++ b/goat3d.vcxproj	Sun Sep 29 23:05:44 2013 +0300
     2.3 @@ -180,7 +180,7 @@
     2.4        <Optimization>Disabled</Optimization>
     2.5        <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);OPENCTM_STATIC;BUILD_MAXPLUGIN</PreprocessorDefinitions>
     2.6        <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
     2.7 -      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2</AdditionalIncludeDirectories>
     2.8 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2;$(SolutionDir)\libs\anim;$(SolutionDir)\libs\vmath</AdditionalIncludeDirectories>
     2.9      </ClCompile>
    2.10      <Link>
    2.11        <SubSystem>Windows</SubSystem>
    2.12 @@ -219,7 +219,7 @@
    2.13        <IntrinsicFunctions>true</IntrinsicFunctions>
    2.14        <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);OPENCTM_STATIC</PreprocessorDefinitions>
    2.15        <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
    2.16 -      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2</AdditionalIncludeDirectories>
    2.17 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2;$(SolutionDir)\libs\anim;$(SolutionDir)\libs\vmath</AdditionalIncludeDirectories>
    2.18      </ClCompile>
    2.19      <Link>
    2.20        <SubSystem>Windows</SubSystem>
     3.1 --- a/src/goat3d_writexml.cc	Sun Sep 29 21:53:03 2013 +0300
     3.2 +++ b/src/goat3d_writexml.cc	Sun Sep 29 23:05:44 2013 +0300
     3.3 @@ -97,6 +97,46 @@
     3.4  
     3.5  static bool write_node(const Scene *scn, goat3d_io *io, const Node *node, int level)
     3.6  {
     3.7 +	xmlout(io, level, "<node>\n");
     3.8 +	xmlout(io, level + 1, "<name string=\"%s\"/>\n", node->get_name());
     3.9 +
    3.10 +	XFormNode *parent = node->get_parent();
    3.11 +	if(parent) {
    3.12 +		xmlout(io, level + 1, "<parent string=\"%s\"/>\n", parent->get_name());
    3.13 +	}
    3.14 +
    3.15 +	const char *type = 0;
    3.16 +	const Object *obj = node->get_object();
    3.17 +	if(dynamic_cast<const Mesh*>(obj)) {
    3.18 +		type = "mesh";
    3.19 +	} else if(dynamic_cast<const Light*>(obj)) {
    3.20 +		type = "light";
    3.21 +	} else if(dynamic_cast<const Camera*>(obj)) {
    3.22 +		type = "camera";
    3.23 +	}
    3.24 +
    3.25 +	if(type) {
    3.26 +		xmlout(io, level + 1, "<%s string=\"%s\"/>\n", type, obj->name.c_str());
    3.27 +	}
    3.28 +
    3.29 +	Vector3 pos = node->get_node_position();
    3.30 +	Quaternion rot = node->get_node_rotation();
    3.31 +	Vector3 scale = node->get_node_scaling();
    3.32 +	Vector3 pivot = node->get_pivot();
    3.33 +
    3.34 +	Matrix4x4 xform;
    3.35 +	node->get_node_xform(0, &xform);
    3.36 +
    3.37 +	xmlout(io, level + 1, "<pos float3=\"%g %g %g\"/>\n", pos.x, pos.y, pos.z);
    3.38 +	xmlout(io, level + 1, "<rot float4=\"%g %g %g %g\"/>\n", rot.v.x, rot.v.y, rot.v.z, rot.s);
    3.39 +	xmlout(io, level + 1, "<scale float3=\"%g %g %g\"/>\n", scale.x, scale.y, scale.z);
    3.40 +	xmlout(io, level + 1, "<pivot float3=\"%g %g %g\"/>\n", pivot.x, pivot.y, pivot.z);
    3.41 +
    3.42 +	xmlout(io, level + 1, "<matrix0 float4=\"%g %g %g %g\"/>\n", xform[0][0], xform[0][1], xform[0][2], xform[0][3]);
    3.43 +	xmlout(io, level + 1, "<matrix1 float4=\"%g %g %g %g\"/>\n", xform[1][0], xform[1][1], xform[1][2], xform[1][3]);
    3.44 +	xmlout(io, level + 1, "<matrix2 float4=\"%g %g %g %g\"/>\n", xform[2][0], xform[2][1], xform[2][2], xform[2][3]);
    3.45 +
    3.46 +	xmlout(io, level, "</node>\n");
    3.47  	return true;
    3.48  }
    3.49  
     4.1 --- a/src/mesh.cc	Sun Sep 29 21:53:03 2013 +0300
     4.2 +++ b/src/mesh.cc	Sun Sep 29 23:05:44 2013 +0300
     4.3 @@ -110,11 +110,16 @@
     4.4  bool Mesh::save(const char *fname) const
     4.5  {
     4.6  	int vnum = (int)vertices.size();
     4.7 +	int fnum = (int)faces.size();
     4.8 +
     4.9 +	if(!vnum || !fnum) {
    4.10 +		return false;
    4.11 +	}
    4.12  
    4.13  	CTMcontext ctm = ctmNewContext(CTM_EXPORT);
    4.14  
    4.15  	// vertices, normals, and face-vertex indices
    4.16 -	ctmDefineMesh(ctm, &vertices[0].x, vnum, (CTMuint*)faces[0].v, faces.size(),
    4.17 +	ctmDefineMesh(ctm, &vertices[0].x, vnum, (CTMuint*)faces[0].v, fnum,
    4.18  			normals.empty() ? 0 : &normals[0].x);
    4.19  
    4.20  	// texture coordinates
     5.1 --- a/src/xform_node.cc	Sun Sep 29 21:53:03 2013 +0300
     5.2 +++ b/src/xform_node.cc	Sun Sep 29 23:05:44 2013 +0300
     5.3 @@ -11,6 +11,8 @@
     5.4  {
     5.5  	anm = new anm_node;
     5.6  	anm_init_node(anm);
     5.7 +
     5.8 +	parent = 0;
     5.9  }
    5.10  
    5.11  XFormNode::~XFormNode()
    5.12 @@ -55,6 +57,7 @@
    5.13  {
    5.14  	children.push_back(child);
    5.15  	anm_link_node(anm, child->anm);
    5.16 +	child->parent = this;
    5.17  }
    5.18  
    5.19  void XFormNode::remove_child(XFormNode *child)
    5.20 @@ -65,6 +68,7 @@
    5.21  		children.erase(it);
    5.22  		anm_unlink_node(anm, child->anm);
    5.23  	}
    5.24 +	child->parent = 0;
    5.25  }
    5.26  
    5.27  int XFormNode::get_children_count() const
    5.28 @@ -88,6 +92,11 @@
    5.29  	return 0;
    5.30  }
    5.31  
    5.32 +XFormNode *XFormNode::get_parent() const
    5.33 +{
    5.34 +	return parent;
    5.35 +}
    5.36 +
    5.37  void XFormNode::set_position(const Vector3 &pos, long tmsec)
    5.38  {
    5.39  	anm_set_position(anm, v3_cons(pos.x, pos.y, pos.z), ANM_MSEC2TM(tmsec));
     6.1 --- a/src/xform_node.h	Sun Sep 29 21:53:03 2013 +0300
     6.2 +++ b/src/xform_node.h	Sun Sep 29 23:05:44 2013 +0300
     6.3 @@ -21,6 +21,7 @@
     6.4  private:
     6.5  	struct anm_node *anm;
     6.6  	std::vector<XFormNode*> children;
     6.7 +	XFormNode *parent;
     6.8  
     6.9  	Interp interp;
    6.10  	Extrap extrap;
    6.11 @@ -51,6 +52,7 @@
    6.12  	virtual XFormNode *get_child(int idx);
    6.13  	virtual const XFormNode *get_child(int idx) const;
    6.14  
    6.15 +	virtual XFormNode *get_parent() const;
    6.16  
    6.17  	virtual void set_position(const Vector3 &pos, long tmsec = 0);
    6.18  	virtual Vector3 get_node_position(long tmsec = 0) const;