goat3d

changeset 69:66cd8266f078

fixed animation export
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 21 Apr 2014 03:44:10 +0300
parents 8ecaf9cd3ce7
children 39d8457e43df
files exporters/maxgoat/maxgoat.rc exporters/maxgoat/resource.h exporters/maxgoat/src/maxgoat.cc
diffstat 3 files changed, 87 insertions(+), 28 deletions(-) [+]
line diff
     1.1 Binary file exporters/maxgoat/maxgoat.rc has changed
     2.1 Binary file exporters/maxgoat/resource.h has changed
     3.1 --- a/exporters/maxgoat/src/maxgoat.cc	Sun Apr 20 12:43:26 2014 +0300
     3.2 +++ b/exporters/maxgoat/src/maxgoat.cc	Mon Apr 21 03:44:10 2014 +0300
     3.3 @@ -238,16 +238,6 @@
     3.4  		goat3d_set_node_name(node, name);
     3.5  	}
     3.6  
     3.7 -	// no animation yet, just get the static PRS
     3.8 -	GMatrix maxmatrix = maxnode->GetObjectTM();
     3.9 -	Point3 trans = maxmatrix.Translation();
    3.10 -	Quat rot = maxmatrix.Rotation();
    3.11 -	Point3 scale = maxmatrix.Scaling();
    3.12 -
    3.13 -	goat3d_set_node_position(node, trans.x, trans.y, trans.z, 0);
    3.14 -	goat3d_set_node_rotation(node, rot.x, rot.y, rot.z, rot.w, 0);
    3.15 -	goat3d_set_node_scaling(node, scale.x, scale.y, scale.z, 0);
    3.16 -
    3.17  	IGameObject *maxobj = maxnode->GetIGameObject();
    3.18  	IGameObject::ObjectTypes type = maxobj->GetIGameType();
    3.19  
    3.20 @@ -300,18 +290,31 @@
    3.21  	// grab the animation data
    3.22  	IGameControl *ctrl = maxnode->GetIGameControl();
    3.23  
    3.24 -	// TODO sample keys if requested
    3.25 +	if(!dynamic_cast<GoatAnimExporter*>(this)) {
    3.26 +		// no animation, just get the static PRS
    3.27 +		GMatrix maxmatrix = maxnode->GetObjectTM();
    3.28 +		Point3 trans = maxmatrix.Translation();
    3.29 +		Quat rot = maxmatrix.Rotation();
    3.30 +		Point3 scale = maxmatrix.Scaling();
    3.31  
    3.32 -	if(ctrl->IsAnimated(IGAME_POS) || ctrl->IsAnimated(IGAME_POS_X) ||
    3.33 -			ctrl->IsAnimated(IGAME_POS_Y) || ctrl->IsAnimated(IGAME_POS_Z)) {
    3.34 -		get_position_keys(ctrl, node);
    3.35 -	}
    3.36 -	if(ctrl->IsAnimated(IGAME_ROT) || ctrl->IsAnimated(IGAME_EULER_X) ||
    3.37 -			ctrl->IsAnimated(IGAME_EULER_Y) || ctrl->IsAnimated(IGAME_EULER_Z)) {
    3.38 -		get_rotation_keys(ctrl, node);
    3.39 -	}
    3.40 -	if(ctrl->IsAnimated(IGAME_SCALE)) {
    3.41 -		get_scaling_keys(ctrl, node);
    3.42 +		goat3d_set_node_position(node, trans.x, trans.y, trans.z, 0);
    3.43 +		goat3d_set_node_rotation(node, rot.x, rot.y, rot.z, rot.w, 0);
    3.44 +		goat3d_set_node_scaling(node, scale.x, scale.y, scale.z, 0);
    3.45 +
    3.46 +	} else {
    3.47 +		// exporting animations (if available)
    3.48 +		// TODO sample keys if requested
    3.49 +		if(ctrl->IsAnimated(IGAME_POS) || ctrl->IsAnimated(IGAME_POS_X) ||
    3.50 +				ctrl->IsAnimated(IGAME_POS_Y) || ctrl->IsAnimated(IGAME_POS_Z)) {
    3.51 +			get_position_keys(ctrl, node);
    3.52 +		}
    3.53 +		if(ctrl->IsAnimated(IGAME_ROT) || ctrl->IsAnimated(IGAME_EULER_X) ||
    3.54 +				ctrl->IsAnimated(IGAME_EULER_Y) || ctrl->IsAnimated(IGAME_EULER_Z)) {
    3.55 +			get_rotation_keys(ctrl, node);
    3.56 +		}
    3.57 +		if(ctrl->IsAnimated(IGAME_SCALE)) {
    3.58 +			get_scaling_keys(ctrl, node);
    3.59 +		}
    3.60  	}
    3.61  
    3.62  	for(int i=0; i<maxnode->GetChildCount(); i++) {
    3.63 @@ -493,6 +496,54 @@
    3.64  	}
    3.65  }
    3.66  
    3.67 +#if 0
    3.68 +static bool get_anim_bounds(IGameNode *node, long *tstart, long *tend);
    3.69 +
    3.70 +static bool get_anim_bounds(IGameScene *igame, long *tstart, long *tend)
    3.71 +{
    3.72 +	int tmin = LONG_MAX;
    3.73 +	int tmax = LONG_MIN;
    3.74 +
    3.75 +	int num_nodes = igame->GetTopLevelNodeCount();
    3.76 +	for(int i=0; i<num_nodes; i++) {
    3.77 +		long t0, t1;
    3.78 +		if(get_anim_bounds(igame->GetTopLevelNode(i), &t0, &t1)) {
    3.79 +			if(t0 < tmin) tmin = t0;
    3.80 +			if(t1 > tmax) tmax = t1;
    3.81 +		}
    3.82 +	}
    3.83 +
    3.84 +	if(tmin != LONG_MAX) {
    3.85 +		*tstart = tmin;
    3.86 +		*tend = tmax;
    3.87 +		return true;
    3.88 +	}
    3.89 +	return false;
    3.90 +}
    3.91 +
    3.92 +static bool get_anim_bounds(IGameNode *node, long *tstart, long *tend)
    3.93 +{
    3.94 +	int tmin = LONG_MAX;
    3.95 +	int tmax = LONG_MIN;
    3.96 +
    3.97 +	int num_children = node->GetChildCount();
    3.98 +	for(int i=0; i<num_children; i++) {
    3.99 +		long t0, t1;
   3.100 +		if(get_anim_bounds(node->GetNodeChild(i), &t0, &t1)) {
   3.101 +			if(t0 < tmin) tmin = t0;
   3.102 +			if(t1 > tmax) tmax = t1;
   3.103 +		}
   3.104 +	}
   3.105 +
   3.106 +	if(tmin != LONG_MAX) {
   3.107 +		*tstart = tmin;
   3.108 +		*tend = tmax;
   3.109 +		return true;
   3.110 +	}
   3.111 +	return false;
   3.112 +}
   3.113 +#endif
   3.114 +
   3.115  void GoatExporter::process_mesh(goat3d *goat, goat3d_mesh *mesh, IGameObject *maxobj)
   3.116  {
   3.117  	IGameMesh *maxmesh = (IGameMesh*)maxobj;
   3.118 @@ -600,7 +651,19 @@
   3.119  
   3.120  int GoatAnimExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent, DWORD opt)
   3.121  {
   3.122 +	if(!(igame = GetIGameInterface())) {
   3.123 +		maxlog("failed to get the igame interface\n");
   3.124 +		return IMPEXP_FAIL;
   3.125 +	}
   3.126 +	IGameConversionManager *cm = GetConversionManager();
   3.127 +	cm->SetCoordSystem(IGameConversionManager::IGAME_OGL);
   3.128 +	igame->InitialiseIGame();
   3.129 +
   3.130 +	//long tstart = 0, tend = 0;
   3.131 +	//get_anim_bounds(igame, &tstart, &tend);
   3.132 +
   3.133  	if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_ANM), 0, anim_gui_handler)) {
   3.134 +		igame->ReleaseIGame();
   3.135  		return IMPEXP_CANCEL;
   3.136  	}
   3.137  
   3.138 @@ -611,13 +674,6 @@
   3.139  	}
   3.140  
   3.141  	maxlog("Exporting Goat3D Animation (text) file: %s\n", fname);
   3.142 -	if(!(igame = GetIGameInterface())) {
   3.143 -		maxlog("failed to get the igame interface\n");
   3.144 -		return IMPEXP_FAIL;
   3.145 -	}
   3.146 -	IGameConversionManager *cm = GetConversionManager();
   3.147 -	cm->SetCoordSystem(IGameConversionManager::IGAME_OGL);
   3.148 -	igame->InitialiseIGame();
   3.149  	igame->SetStaticFrame(0);
   3.150  
   3.151  	goat3d *goat = goat3d_create();
   3.152 @@ -630,10 +686,12 @@
   3.153  
   3.154  	if(goat3d_save_anim(goat, fname) == -1) {
   3.155  		goat3d_free(goat);
   3.156 +		igame->ReleaseIGame();
   3.157  		return IMPEXP_FAIL;
   3.158  	}
   3.159  
   3.160  	goat3d_free(goat);
   3.161 +	igame->ReleaseIGame();
   3.162  	return IMPEXP_SUCCESS;
   3.163  }
   3.164  
   3.165 @@ -642,6 +700,7 @@
   3.166  	switch(msg) {
   3.167  	case WM_INITDIALOG:
   3.168  		CheckDlgButton(win, IDC_GOAT_ANM_FULL, 1);
   3.169 +		CheckDlgButton(win, IDC_RAD_KEYS_ORIG, 1);
   3.170  		break;
   3.171  
   3.172  	case WM_COMMAND: