goat3d
diff exporters/maxgoat/src/maxgoat.cc @ 72:36e39632db75
- fixed exporter animation bounds calculation
- fixed missing scene name in exported meshes
- rewritting goatview as a full GUI app with Qt
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 06 May 2014 03:31:35 +0300 |
parents | 66cd8266f078 |
children | 9862541fdcf5 |
line diff
1.1 --- a/exporters/maxgoat/src/maxgoat.cc Mon Apr 21 03:44:42 2014 +0300 1.2 +++ b/exporters/maxgoat/src/maxgoat.cc Tue May 06 03:31:35 2014 +0300 1.3 @@ -107,6 +107,10 @@ 1.4 for(int i=0; fname[i]; i++) { 1.5 fname[i] = tolower(fname[i]); 1.6 } 1.7 + char *basename = (char*)alloca(strlen(fname) + 1); 1.8 + strcpy(basename, fname); 1.9 + char *suffix = strrchr(basename, '.'); 1.10 + if(suffix) *suffix = 0; 1.11 1.12 maxlog("Exporting Goat3D Scene (text) file: %s\n", fname); 1.13 if(!(igame = GetIGameInterface())) { 1.14 @@ -118,6 +122,7 @@ 1.15 igame->InitialiseIGame(); 1.16 1.17 goat3d *goat = goat3d_create(); 1.18 + goat3d_set_name(goat, basename); 1.19 1.20 process_materials(goat); 1.21 1.22 @@ -288,8 +293,6 @@ 1.23 } 1.24 1.25 // grab the animation data 1.26 - IGameControl *ctrl = maxnode->GetIGameControl(); 1.27 - 1.28 if(!dynamic_cast<GoatAnimExporter*>(this)) { 1.29 // no animation, just get the static PRS 1.30 GMatrix maxmatrix = maxnode->GetObjectTM(); 1.31 @@ -304,16 +307,21 @@ 1.32 } else { 1.33 // exporting animations (if available) 1.34 // TODO sample keys if requested 1.35 - if(ctrl->IsAnimated(IGAME_POS) || ctrl->IsAnimated(IGAME_POS_X) || 1.36 - ctrl->IsAnimated(IGAME_POS_Y) || ctrl->IsAnimated(IGAME_POS_Z)) { 1.37 - get_position_keys(ctrl, node); 1.38 - } 1.39 - if(ctrl->IsAnimated(IGAME_ROT) || ctrl->IsAnimated(IGAME_EULER_X) || 1.40 - ctrl->IsAnimated(IGAME_EULER_Y) || ctrl->IsAnimated(IGAME_EULER_Z)) { 1.41 - get_rotation_keys(ctrl, node); 1.42 - } 1.43 - if(ctrl->IsAnimated(IGAME_SCALE)) { 1.44 - get_scaling_keys(ctrl, node); 1.45 + IGameControl *ctrl = maxnode->GetIGameControl(); 1.46 + if(ctrl) { 1.47 + if(ctrl->IsAnimated(IGAME_POS) || ctrl->IsAnimated(IGAME_POS_X) || 1.48 + ctrl->IsAnimated(IGAME_POS_Y) || ctrl->IsAnimated(IGAME_POS_Z)) { 1.49 + get_position_keys(ctrl, node); 1.50 + } 1.51 + if(ctrl->IsAnimated(IGAME_ROT) || ctrl->IsAnimated(IGAME_EULER_X) || 1.52 + ctrl->IsAnimated(IGAME_EULER_Y) || ctrl->IsAnimated(IGAME_EULER_Z)) { 1.53 + get_rotation_keys(ctrl, node); 1.54 + } 1.55 + if(ctrl->IsAnimated(IGAME_SCALE)) { 1.56 + get_scaling_keys(ctrl, node); 1.57 + } 1.58 + } else { 1.59 + maxlog("%s: failed to get IGameControl for node: %s\n", __FUNCTION__, name); 1.60 } 1.61 } 1.62 1.63 @@ -496,13 +504,13 @@ 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 +static bool get_node_anim_bounds(IGameNode *node, long *tstart, long *tend); 1.70 1.71 static bool get_anim_bounds(IGameScene *igame, long *tstart, long *tend) 1.72 { 1.73 - int tmin = LONG_MAX; 1.74 - int tmax = LONG_MIN; 1.75 + long tmin = LONG_MAX; 1.76 + long tmax = LONG_MIN; 1.77 1.78 int num_nodes = igame->GetTopLevelNodeCount(); 1.79 for(int i=0; i<num_nodes; i++) { 1.80 @@ -523,8 +531,10 @@ 1.81 1.82 static bool get_anim_bounds(IGameNode *node, long *tstart, long *tend) 1.83 { 1.84 - int tmin = LONG_MAX; 1.85 - int tmax = LONG_MIN; 1.86 + long tmin = LONG_MAX; 1.87 + long tmax = LONG_MIN; 1.88 + 1.89 + get_node_anim_bounds(node, &tmin, &tmax); 1.90 1.91 int num_children = node->GetChildCount(); 1.92 for(int i=0; i<num_children; i++) { 1.93 @@ -542,7 +552,56 @@ 1.94 } 1.95 return false; 1.96 } 1.97 -#endif 1.98 + 1.99 +static bool get_node_anim_bounds(IGameNode *node, long *tstart, long *tend) 1.100 +{ 1.101 + static const IGameControlType ctypes[] = { 1.102 + IGAME_POS, IGAME_POS_X, IGAME_POS_Y, IGAME_POS_Z, 1.103 + IGAME_ROT, IGAME_EULER_X, IGAME_EULER_Y, IGAME_EULER_Z, 1.104 + IGAME_SCALE 1.105 + }; 1.106 + 1.107 + // NOTE: apparently if I don't call GetIGameObject, then GetIGameControl always returns null... 1.108 + node->GetIGameObject(); 1.109 + IGameControl *ctrl = node->GetIGameControl(); 1.110 + if(!ctrl) { 1.111 + maxlog("%s: failed to get IGameControl for node: %s\n", __FUNCTION__, max_string(node->GetName())); 1.112 + return false; 1.113 + } 1.114 + 1.115 + IGameKeyTab keys; 1.116 + long t0, t1; 1.117 + long tmin = LONG_MAX; 1.118 + long tmax = LONG_MIN; 1.119 + 1.120 + for(int i=0; i<sizeof ctypes / sizeof *ctypes; i++) { 1.121 + if(ctrl->GetBezierKeys(keys, ctypes[i]) && keys.Count()) { 1.122 + t0 = KEY_TIME(keys[0]); 1.123 + t1 = KEY_TIME(keys[keys.Count() - 1]); 1.124 + if(t0 < tmin) tmin = t0; 1.125 + if(t1 > tmax) tmax = t1; 1.126 + } 1.127 + if(ctrl->GetLinearKeys(keys, ctypes[i]) && keys.Count()) { 1.128 + t0 = KEY_TIME(keys[0]); 1.129 + t1 = KEY_TIME(keys[keys.Count() - 1]); 1.130 + if(t0 < tmin) tmin = t0; 1.131 + if(t1 > tmax) tmax = t1; 1.132 + } 1.133 + if(ctrl->GetTCBKeys(keys, ctypes[i]) && keys.Count()) { 1.134 + t0 = KEY_TIME(keys[0]); 1.135 + t1 = KEY_TIME(keys[keys.Count() - 1]); 1.136 + if(t0 < tmin) tmin = t0; 1.137 + if(t1 > tmax) tmax = t1; 1.138 + } 1.139 + } 1.140 + 1.141 + if(tmin != LONG_MAX) { 1.142 + *tstart = tmin; 1.143 + *tend = tmax; 1.144 + return true; 1.145 + } 1.146 + return false; 1.147 +} 1.148 1.149 void GoatExporter::process_mesh(goat3d *goat, goat3d_mesh *mesh, IGameObject *maxobj) 1.150 { 1.151 @@ -648,6 +707,7 @@ 1.152 1.153 1.154 // ---- GoatAnimExporter implementation ---- 1.155 +static long tstart, tend; 1.156 1.157 int GoatAnimExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent, DWORD opt) 1.158 { 1.159 @@ -658,9 +718,10 @@ 1.160 IGameConversionManager *cm = GetConversionManager(); 1.161 cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); 1.162 igame->InitialiseIGame(); 1.163 + igame->SetStaticFrame(0); 1.164 1.165 - //long tstart = 0, tend = 0; 1.166 - //get_anim_bounds(igame, &tstart, &tend); 1.167 + tstart = tend = 0; 1.168 + get_anim_bounds(igame, &tstart, &tend); 1.169 1.170 if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_ANM), 0, anim_gui_handler)) { 1.171 igame->ReleaseIGame(); 1.172 @@ -674,7 +735,6 @@ 1.173 } 1.174 1.175 maxlog("Exporting Goat3D Animation (text) file: %s\n", fname); 1.176 - igame->SetStaticFrame(0); 1.177 1.178 goat3d *goat = goat3d_create(); 1.179 1.180 @@ -699,8 +759,15 @@ 1.181 { 1.182 switch(msg) { 1.183 case WM_INITDIALOG: 1.184 - CheckDlgButton(win, IDC_GOAT_ANM_FULL, 1); 1.185 - CheckDlgButton(win, IDC_RAD_KEYS_ORIG, 1); 1.186 + { 1.187 + wchar_t buf[128]; 1.188 + CheckDlgButton(win, IDC_GOAT_ANM_FULL, BST_CHECKED); 1.189 + CheckDlgButton(win, IDC_RAD_KEYS_ORIG, BST_CHECKED); 1.190 + wsprintf(buf, L"%ld", tstart); 1.191 + SetDlgItemText(win, IDC_EDIT_TSTART, buf); 1.192 + wsprintf(buf, L"%ld", tend); 1.193 + SetDlgItemText(win, IDC_EDIT_TEND, buf); 1.194 + } 1.195 break; 1.196 1.197 case WM_COMMAND: