goat3d
diff exporters/maxgoat/src/maxgoat.cc @ 69:66cd8266f078
fixed animation export
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 21 Apr 2014 03:44:10 +0300 |
parents | 8ecaf9cd3ce7 |
children | 36e39632db75 |
line diff
1.1 --- a/exporters/maxgoat/src/maxgoat.cc Sun Apr 20 12:43:26 2014 +0300 1.2 +++ b/exporters/maxgoat/src/maxgoat.cc Mon Apr 21 03:44:10 2014 +0300 1.3 @@ -238,16 +238,6 @@ 1.4 goat3d_set_node_name(node, name); 1.5 } 1.6 1.7 - // no animation yet, just get the static PRS 1.8 - GMatrix maxmatrix = maxnode->GetObjectTM(); 1.9 - Point3 trans = maxmatrix.Translation(); 1.10 - Quat rot = maxmatrix.Rotation(); 1.11 - Point3 scale = maxmatrix.Scaling(); 1.12 - 1.13 - goat3d_set_node_position(node, trans.x, trans.y, trans.z, 0); 1.14 - goat3d_set_node_rotation(node, rot.x, rot.y, rot.z, rot.w, 0); 1.15 - goat3d_set_node_scaling(node, scale.x, scale.y, scale.z, 0); 1.16 - 1.17 IGameObject *maxobj = maxnode->GetIGameObject(); 1.18 IGameObject::ObjectTypes type = maxobj->GetIGameType(); 1.19 1.20 @@ -300,18 +290,31 @@ 1.21 // grab the animation data 1.22 IGameControl *ctrl = maxnode->GetIGameControl(); 1.23 1.24 - // TODO sample keys if requested 1.25 + if(!dynamic_cast<GoatAnimExporter*>(this)) { 1.26 + // no animation, just get the static PRS 1.27 + GMatrix maxmatrix = maxnode->GetObjectTM(); 1.28 + Point3 trans = maxmatrix.Translation(); 1.29 + Quat rot = maxmatrix.Rotation(); 1.30 + Point3 scale = maxmatrix.Scaling(); 1.31 1.32 - if(ctrl->IsAnimated(IGAME_POS) || ctrl->IsAnimated(IGAME_POS_X) || 1.33 - ctrl->IsAnimated(IGAME_POS_Y) || ctrl->IsAnimated(IGAME_POS_Z)) { 1.34 - get_position_keys(ctrl, node); 1.35 - } 1.36 - if(ctrl->IsAnimated(IGAME_ROT) || ctrl->IsAnimated(IGAME_EULER_X) || 1.37 - ctrl->IsAnimated(IGAME_EULER_Y) || ctrl->IsAnimated(IGAME_EULER_Z)) { 1.38 - get_rotation_keys(ctrl, node); 1.39 - } 1.40 - if(ctrl->IsAnimated(IGAME_SCALE)) { 1.41 - get_scaling_keys(ctrl, node); 1.42 + goat3d_set_node_position(node, trans.x, trans.y, trans.z, 0); 1.43 + goat3d_set_node_rotation(node, rot.x, rot.y, rot.z, rot.w, 0); 1.44 + goat3d_set_node_scaling(node, scale.x, scale.y, scale.z, 0); 1.45 + 1.46 + } else { 1.47 + // exporting animations (if available) 1.48 + // TODO sample keys if requested 1.49 + if(ctrl->IsAnimated(IGAME_POS) || ctrl->IsAnimated(IGAME_POS_X) || 1.50 + ctrl->IsAnimated(IGAME_POS_Y) || ctrl->IsAnimated(IGAME_POS_Z)) { 1.51 + get_position_keys(ctrl, node); 1.52 + } 1.53 + if(ctrl->IsAnimated(IGAME_ROT) || ctrl->IsAnimated(IGAME_EULER_X) || 1.54 + ctrl->IsAnimated(IGAME_EULER_Y) || ctrl->IsAnimated(IGAME_EULER_Z)) { 1.55 + get_rotation_keys(ctrl, node); 1.56 + } 1.57 + if(ctrl->IsAnimated(IGAME_SCALE)) { 1.58 + get_scaling_keys(ctrl, node); 1.59 + } 1.60 } 1.61 1.62 for(int i=0; i<maxnode->GetChildCount(); i++) { 1.63 @@ -493,6 +496,54 @@ 1.64 } 1.65 } 1.66 1.67 +#if 0 1.68 +static bool get_anim_bounds(IGameNode *node, long *tstart, long *tend); 1.69 + 1.70 +static bool get_anim_bounds(IGameScene *igame, long *tstart, long *tend) 1.71 +{ 1.72 + int tmin = LONG_MAX; 1.73 + int tmax = LONG_MIN; 1.74 + 1.75 + int num_nodes = igame->GetTopLevelNodeCount(); 1.76 + for(int i=0; i<num_nodes; i++) { 1.77 + long t0, t1; 1.78 + if(get_anim_bounds(igame->GetTopLevelNode(i), &t0, &t1)) { 1.79 + if(t0 < tmin) tmin = t0; 1.80 + if(t1 > tmax) tmax = t1; 1.81 + } 1.82 + } 1.83 + 1.84 + if(tmin != LONG_MAX) { 1.85 + *tstart = tmin; 1.86 + *tend = tmax; 1.87 + return true; 1.88 + } 1.89 + return false; 1.90 +} 1.91 + 1.92 +static bool get_anim_bounds(IGameNode *node, long *tstart, long *tend) 1.93 +{ 1.94 + int tmin = LONG_MAX; 1.95 + int tmax = LONG_MIN; 1.96 + 1.97 + int num_children = node->GetChildCount(); 1.98 + for(int i=0; i<num_children; i++) { 1.99 + long t0, t1; 1.100 + if(get_anim_bounds(node->GetNodeChild(i), &t0, &t1)) { 1.101 + if(t0 < tmin) tmin = t0; 1.102 + if(t1 > tmax) tmax = t1; 1.103 + } 1.104 + } 1.105 + 1.106 + if(tmin != LONG_MAX) { 1.107 + *tstart = tmin; 1.108 + *tend = tmax; 1.109 + return true; 1.110 + } 1.111 + return false; 1.112 +} 1.113 +#endif 1.114 + 1.115 void GoatExporter::process_mesh(goat3d *goat, goat3d_mesh *mesh, IGameObject *maxobj) 1.116 { 1.117 IGameMesh *maxmesh = (IGameMesh*)maxobj; 1.118 @@ -600,7 +651,19 @@ 1.119 1.120 int GoatAnimExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent, DWORD opt) 1.121 { 1.122 + if(!(igame = GetIGameInterface())) { 1.123 + maxlog("failed to get the igame interface\n"); 1.124 + return IMPEXP_FAIL; 1.125 + } 1.126 + IGameConversionManager *cm = GetConversionManager(); 1.127 + cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); 1.128 + igame->InitialiseIGame(); 1.129 + 1.130 + //long tstart = 0, tend = 0; 1.131 + //get_anim_bounds(igame, &tstart, &tend); 1.132 + 1.133 if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_ANM), 0, anim_gui_handler)) { 1.134 + igame->ReleaseIGame(); 1.135 return IMPEXP_CANCEL; 1.136 } 1.137 1.138 @@ -611,13 +674,6 @@ 1.139 } 1.140 1.141 maxlog("Exporting Goat3D Animation (text) file: %s\n", fname); 1.142 - if(!(igame = GetIGameInterface())) { 1.143 - maxlog("failed to get the igame interface\n"); 1.144 - return IMPEXP_FAIL; 1.145 - } 1.146 - IGameConversionManager *cm = GetConversionManager(); 1.147 - cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); 1.148 - igame->InitialiseIGame(); 1.149 igame->SetStaticFrame(0); 1.150 1.151 goat3d *goat = goat3d_create(); 1.152 @@ -630,10 +686,12 @@ 1.153 1.154 if(goat3d_save_anim(goat, fname) == -1) { 1.155 goat3d_free(goat); 1.156 + igame->ReleaseIGame(); 1.157 return IMPEXP_FAIL; 1.158 } 1.159 1.160 goat3d_free(goat); 1.161 + igame->ReleaseIGame(); 1.162 return IMPEXP_SUCCESS; 1.163 } 1.164 1.165 @@ -642,6 +700,7 @@ 1.166 switch(msg) { 1.167 case WM_INITDIALOG: 1.168 CheckDlgButton(win, IDC_GOAT_ANM_FULL, 1); 1.169 + CheckDlgButton(win, IDC_RAD_KEYS_ORIG, 1); 1.170 break; 1.171 1.172 case WM_COMMAND: