goat3d

changeset 25:d0260d80ae09

adding the nodes interface, and continuing the max plugin
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 28 Sep 2013 19:12:50 +0300
parents 6b651613bd9f
children 1c601bf07b86
files exporters/maxgoat/maxgoat.vcxproj exporters/maxgoat/src/maxgoat.cc src/goat3d.cc src/goat3d.h
diffstat 4 files changed, 222 insertions(+), 41 deletions(-) [+]
line diff
     1.1 --- a/exporters/maxgoat/maxgoat.vcxproj	Sat Sep 28 06:32:00 2013 +0300
     1.2 +++ b/exporters/maxgoat/maxgoat.vcxproj	Sat Sep 28 19:12:50 2013 +0300
     1.3 @@ -100,6 +100,7 @@
     1.4        <Optimization>Disabled</Optimization>
     1.5        <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MAXGOAT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     1.6        <DisableSpecificWarnings>4996</DisableSpecificWarnings>
     1.7 +      <AdditionalIncludeDirectories>$(SolutionDir)\src</AdditionalIncludeDirectories>
     1.8      </ClCompile>
     1.9      <Link>
    1.10        <SubSystem>Windows</SubSystem>
    1.11 @@ -139,6 +140,7 @@
    1.12        <IntrinsicFunctions>true</IntrinsicFunctions>
    1.13        <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MAXGOAT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    1.14        <DisableSpecificWarnings>4996</DisableSpecificWarnings>
    1.15 +      <AdditionalIncludeDirectories>$(SolutionDir)\src</AdditionalIncludeDirectories>
    1.16      </ClCompile>
    1.17      <Link>
    1.18        <SubSystem>Windows</SubSystem>
     2.1 --- a/exporters/maxgoat/src/maxgoat.cc	Sat Sep 28 06:32:00 2013 +0300
     2.2 +++ b/exporters/maxgoat/src/maxgoat.cc	Sat Sep 28 19:12:50 2013 +0300
     2.3 @@ -10,6 +10,7 @@
     2.4  #include "IGame.h"
     2.5  #include "IGameExport.h"
     2.6  #include "IConversionmanager.h"
     2.7 +#include "goat3d.h"
     2.8  #include "config.h"
     2.9  
    2.10  
    2.11 @@ -48,7 +49,9 @@
    2.12  
    2.13  	int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0);
    2.14  
    2.15 -	bool export_materials(FILE *fp);
    2.16 +	void export_materials(goat3d *goat);
    2.17 +	void export_meshes(goat3d *goat);
    2.18 +	void process_node(goat3d *goat, IGameNode *maxnode);
    2.19  };
    2.20  
    2.21  
    2.22 @@ -108,15 +111,8 @@
    2.23  	char fname[512];
    2.24  	wcstombs(fname, name, sizeof fname - 1);
    2.25  
    2.26 -	FILE *fp = fopen(fname, "wb");
    2.27 -	if(!fp) {
    2.28 -		fprintf(logfile, "failed to open %s for writting: %s", fname, strerror(errno));
    2.29 -		return IMPEXP_FAIL;
    2.30 -	}
    2.31 -
    2.32  	if(!(igame = GetIGameInterface())) {
    2.33  		fprintf(logfile, "failed to get the igame interface\n");
    2.34 -		fclose(fp);
    2.35  		return IMPEXP_FAIL;
    2.36  	}
    2.37  	IGameConversionManager *cm = GetConversionManager();
    2.38 @@ -124,64 +120,128 @@
    2.39  	igame->InitialiseIGame();
    2.40  	igame->SetStaticFrame(0);
    2.41  
    2.42 -	export_materials(fp);
    2.43 +	goat3d *goat = goat3d_create();
    2.44  
    2.45 -	fclose(fp);
    2.46 +	export_materials(goat);
    2.47 +	export_meshes(goat);
    2.48  
    2.49 +	if(goat3d_save(goat, fname) == -1) {
    2.50 +		goat3d_free(goat);
    2.51 +		return IMPEXP_FAIL;
    2.52 +	}
    2.53 +
    2.54 +	// process all nodes
    2.55 +	for(int i=0; i<igame->GetTopLevelNodeCount(); i++) {
    2.56 +		IGameNode *node = igame->GetTopLevelNode(i);
    2.57 +		process_node(goat, node);
    2.58 +	}
    2.59 +
    2.60 +	goat3d_free(goat);
    2.61  	return IMPEXP_SUCCESS;
    2.62  }
    2.63  
    2.64 -bool GoatExporter::export_materials(FILE *fp)
    2.65 +static const char *max_string(const MCHAR *wstr)
    2.66 +{
    2.67 +	if(!wstr) return 0;
    2.68 +	static char str[512];
    2.69 +	wcstombs(str, wstr, sizeof str - 1);
    2.70 +	return str;
    2.71 +}
    2.72 +
    2.73 +void GoatExporter::export_materials(goat3d *goat)
    2.74  {
    2.75  	IGameProperty *prop;
    2.76  
    2.77  	int num_mtl = igame->GetRootMaterialCount();
    2.78 -	fprintf(fp, "number of materials: %d\n", num_mtl);
    2.79 +	for(int i=0; i<num_mtl; i++) {
    2.80 +		IGameMaterial *maxmtl = igame->GetRootMaterial(i);
    2.81 +		if(maxmtl) {
    2.82 +			goat3d_material *mtl = goat3d_create_mtl();
    2.83  
    2.84 -	for(int i=0; i<num_mtl; i++) {
    2.85 -		IGameMaterial *mtl = igame->GetRootMaterial(i);
    2.86 -		if(mtl) {
    2.87 -			Point3 diffuse(1, 1, 1);
    2.88 -			Point3 specular(0, 0, 0);
    2.89 -			float shin = 1.0, sstr = 1.0;
    2.90 -			char name[512] = "unnamed";
    2.91 -
    2.92 -			const MCHAR *wname = mtl->GetMaterialName();
    2.93 -			if(wname) {
    2.94 -				wcstombs(name, wname, sizeof name - 1);
    2.95 +			const char *name = max_string(maxmtl->GetMaterialName());
    2.96 +			if(name) {
    2.97 +				goat3d_set_mtl_name(mtl, name);
    2.98  			}
    2.99  
   2.100 -			if((prop = mtl->GetDiffuseData())) {
   2.101 +			// diffuse
   2.102 +			if((prop = maxmtl->GetDiffuseData())) {
   2.103 +				Point3 diffuse(1, 1, 1);
   2.104  				prop->GetPropertyValue(diffuse);
   2.105 +				goat3d_set_mtl_attrib3f(mtl, GOAT3D_MAT_ATTR_DIFFUSE, diffuse[0],
   2.106 +					diffuse[1], diffuse[2]);
   2.107  			}
   2.108 -			if((prop = mtl->GetSpecularData())) {
   2.109 +			// specular
   2.110 +			if((prop = maxmtl->GetSpecularData())) {
   2.111 +				Point3 specular(0, 0, 0);
   2.112  				prop->GetPropertyValue(specular);
   2.113 +
   2.114 +				float sstr = 1.0;
   2.115 +				if((prop = maxmtl->GetSpecularLevelData())) {
   2.116 +					prop->GetPropertyValue(sstr);
   2.117 +				}
   2.118 +				goat3d_set_mtl_attrib3f(mtl, GOAT3D_MAT_ATTR_SPECULAR, specular[0] * sstr,
   2.119 +					specular[1] * sstr, specular[2] * sstr);
   2.120  			}
   2.121 -			if((prop = mtl->GetSpecularLevelData())) {
   2.122 -				prop->GetPropertyValue(sstr);
   2.123 -			}
   2.124 -			if((prop = mtl->GetGlossinessData())) {
   2.125 +			// shininess
   2.126 +			if((prop = maxmtl->GetGlossinessData())) {
   2.127 +				float shin;
   2.128  				prop->GetPropertyValue(shin);
   2.129 +				goat3d_set_mtl_attrib1f(mtl, GOAT3D_MAT_ATTR_SHININESS, shin * 100.0);
   2.130  			}
   2.131  
   2.132 -			fprintf(fp, "Material %d (%s):\n", i, name);
   2.133 -			fprintf(fp, "  diffuse: %f %f %f\n", diffuse[0], diffuse[1], diffuse[2]);
   2.134 -			fprintf(fp, "  specular: %f %f %f\n", specular[0] * sstr, specular[1] * sstr, specular[2] * sstr);
   2.135 -			fprintf(fp, "  shininess: %f\n", shin * 100.0);
   2.136 +			// textures
   2.137 +			for(int j=0; j<maxmtl->GetNumberOfTextureMaps(); j++) {
   2.138 +				IGameTextureMap *tex = maxmtl->GetIGameTextureMap(j);
   2.139  
   2.140 -			for(int j=0; j<mtl->GetNumberOfTextureMaps(); j++) {
   2.141 -				IGameTextureMap *tex = mtl->GetIGameTextureMap(j);
   2.142 -				const MCHAR *wfname = tex->GetBitmapFileName();
   2.143 -				if(wfname) {
   2.144 -					char fname[512];
   2.145 -					wcstombs(fname, wfname, sizeof fname - 1);
   2.146 -					fprintf(fp, "  texture%d: %s\n", j, fname);
   2.147 +				const char *fname = max_string(tex->GetBitmapFileName());
   2.148 +				if(!fname) {
   2.149 +					continue;
   2.150 +				}
   2.151 +
   2.152 +				int slot = tex->GetStdMapSlot();
   2.153 +				switch(slot) {
   2.154 +				case ID_DI:	// diffuse
   2.155 +					goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_DIFFUSE, fname);
   2.156 +					break;
   2.157 +
   2.158 +				case ID_SP:
   2.159 +				case ID_SS:
   2.160 +					goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_SPECULAR, fname);
   2.161 +					break;
   2.162 +
   2.163 +				case ID_SH:
   2.164 +					goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_SHININESS, fname);
   2.165 +					break;
   2.166 +
   2.167 +				case ID_BU:
   2.168 +					goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_NORMAL, fname);
   2.169 +					break;
   2.170 +
   2.171 +				case ID_RL:
   2.172 +					goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_REFLECTION, fname);
   2.173 +					break;
   2.174 +
   2.175 +				case ID_RR:
   2.176 +					goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_TRANSMISSION, fname);
   2.177 +					break;
   2.178 +
   2.179 +				default:
   2.180 +					break;
   2.181  				}
   2.182  			}
   2.183 +
   2.184 +			goat3d_add_mtl(goat, mtl);
   2.185  		}
   2.186  	}
   2.187 +}
   2.188  
   2.189 -	return true;
   2.190 +void GoatExporter::export_meshes(goat3d *goat)
   2.191 +{
   2.192 +	Tab<IGameNode*> meshes = igame->GetIGameNodeByType(IGameObject::IGAME_MESH);
   2.193 +
   2.194 +	for(int i=0; i<meshes.Count(); i++) {
   2.195 +		const char *name = max_string(meshes[i]->GetName());
   2.196 +	}
   2.197  }
   2.198  
   2.199  // ------------------------------------------
     3.1 --- a/src/goat3d.cc	Sat Sep 28 06:32:00 2013 +0300
     3.2 +++ b/src/goat3d.cc	Sat Sep 28 19:12:50 2013 +0300
     3.3 @@ -475,6 +475,93 @@
     3.4  }
     3.5  
     3.6  
     3.7 +// node
     3.8 +
     3.9 +struct goat3d_node *goat3d_create_node(void)
    3.10 +{
    3.11 +	return new goat3d_node;
    3.12 +}
    3.13 +
    3.14 +void goat3d_set_node_name(struct goat3d_node *node, const char *name)
    3.15 +{
    3.16 +	node->set_name(name);
    3.17 +}
    3.18 +
    3.19 +const char *goat3d_get_node_name(struct goat3d_node *node)
    3.20 +{
    3.21 +	return node->get_name();
    3.22 +}
    3.23 +
    3.24 +void goat3d_set_node_object(struct goat3d_node *node, enum goat3d_node_type type, void *obj)
    3.25 +{
    3.26 +	node->set_object((Object*)obj);
    3.27 +}
    3.28 +
    3.29 +// TODO cont.
    3.30 +
    3.31 +void *goat3d_get_node_object(struct goat3d_node *node)
    3.32 +{
    3.33 +	return 0;
    3.34 +}
    3.35 +
    3.36 +enum goat3d_node_type goat3d_get_node_type(struct goat3d_node *node)
    3.37 +{
    3.38 +	return GOAT3D_NODE_MESH;	// TODO
    3.39 +}
    3.40 +
    3.41 +void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child)
    3.42 +{
    3.43 +}
    3.44 +
    3.45 +int goat3d_get_node_child_count(struct goat3d_node *node)
    3.46 +{
    3.47 +	return 0;
    3.48 +}
    3.49 +
    3.50 +struct goat3d_node *goat3d_get_node_child(struct goat3d_node *node, int idx)
    3.51 +{
    3.52 +	return 0;
    3.53 +}
    3.54 +
    3.55 +void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec)
    3.56 +{
    3.57 +}
    3.58 +
    3.59 +void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec)
    3.60 +{
    3.61 +}
    3.62 +
    3.63 +void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec)
    3.64 +{
    3.65 +}
    3.66 +
    3.67 +void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz)
    3.68 +{
    3.69 +}
    3.70 +
    3.71 +
    3.72 +void goat3d_get_node_position(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec)
    3.73 +{
    3.74 +}
    3.75 +
    3.76 +void goat3d_get_node_rotation(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec)
    3.77 +{
    3.78 +}
    3.79 +
    3.80 +void goat3d_get_node_scaling(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec)
    3.81 +{
    3.82 +}
    3.83 +
    3.84 +void goat3d_get_node_pivot(struct goat3d_node *node, float *xptr, float *yptr, float *zptr)
    3.85 +{
    3.86 +}
    3.87 +
    3.88 +
    3.89 +void goat3d_get_node_matrix(struct goat3d_node *node, float *matrix, long tmsec)
    3.90 +{
    3.91 +}
    3.92 +
    3.93 +
    3.94  }	// extern "C"
    3.95  
    3.96  
     4.1 --- a/src/goat3d.h	Sat Sep 28 06:32:00 2013 +0300
     4.2 +++ b/src/goat3d.h	Sat Sep 28 19:12:50 2013 +0300
     4.3 @@ -25,6 +25,12 @@
     4.4  	NUM_GOAT3D_MESH_ATTRIBS
     4.5  };
     4.6  
     4.7 +enum goat3d_node_type {
     4.8 +	GOAT3D_NODE_MESH,
     4.9 +	GOAT3D_NODE_LIGHT,
    4.10 +	GOAT3D_NODE_CAMERA
    4.11 +};
    4.12 +
    4.13  /* immediate mode mesh construction primitive type */
    4.14  enum goat3d_im_primitive {
    4.15  	GOAT3D_TRIANGLES,
    4.16 @@ -158,6 +164,32 @@
    4.17  int goat3d_get_mesh_count(struct goat3d *g);
    4.18  struct goat3d_mesh *goat3d_get_mesh(struct goat3d *g, int idx);
    4.19  
    4.20 +/* nodes */
    4.21 +struct goat3d_node *goat3d_create_node(void);
    4.22 +
    4.23 +void goat3d_set_node_name(struct goat3d_node *node, const char *name);
    4.24 +const char *goat3d_get_node_name(struct goat3d_node *node);
    4.25 +
    4.26 +void goat3d_set_node_object(struct goat3d_node *node, enum goat3d_node_type type, void *obj);
    4.27 +void *goat3d_get_node_object(struct goat3d_node *node);
    4.28 +enum goat3d_node_type goat3d_get_node_type(struct goat3d_node *node);
    4.29 +
    4.30 +void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child);
    4.31 +int goat3d_get_node_child_count(struct goat3d_node *node);
    4.32 +struct goat3d_node *goat3d_get_node_child(struct goat3d_node *node, int idx);
    4.33 +
    4.34 +void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec);
    4.35 +void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec);
    4.36 +void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec);
    4.37 +void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz);
    4.38 +
    4.39 +void goat3d_get_node_position(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec);
    4.40 +void goat3d_get_node_rotation(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec);
    4.41 +void goat3d_get_node_scaling(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec);
    4.42 +void goat3d_get_node_pivot(struct goat3d_node *node, float *xptr, float *yptr, float *zptr);
    4.43 +
    4.44 +void goat3d_get_node_matrix(struct goat3d_node *node, float *matrix, long tmsec);
    4.45 +
    4.46  #ifdef __cplusplus
    4.47  }
    4.48  #endif