AMC_import.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //----------------------------------------------------------------------------
  19. // amc_import.cpp
  20. //
  21. // Acclaim Motion Capture import module
  22. //
  23. // James McNeill
  24. //
  25. // Created October 1996
  26. //
  27. // Copyright (c) 1996 Westwood Studios
  28. //----------------------------------------------------------------------------
  29. #include <Max.h>
  30. #include <istdplug.h>
  31. #include <fstream.h>
  32. #include "resource.h"
  33. #include "exception.h"
  34. #include "asf_data.h"
  35. const float ANGLE_MULTIPLIER = 1.7453293e-2f; // degrees to radians
  36. const first_frame_time = 320;
  37. const amc_ticks_per_frame = 80;
  38. static int max_ticks_per_frame = 160;
  39. static HINSTANCE hInstance;
  40. static TCHAR * GetString ( int id )
  41. {
  42. static TCHAR buf[256];
  43. if (hInstance)
  44. return LoadString(hInstance, id, buf, sizeof(buf)) ? buf : NULL;
  45. return NULL;
  46. }
  47. static int MessageBox ( int s1, int s2, int option = MB_OK )
  48. {
  49. TSTR str1(GetString(s1));
  50. TSTR str2(GetString(s2));
  51. return MessageBox(GetActiveWindow(), str1, str2, option);
  52. }
  53. static int Alert ( int s1, int s2 = IDS_LIB_SHORT_DESC, int option = MB_OK )
  54. {
  55. return MessageBox(s1, s2, option);
  56. }
  57. //----------------------------------------------------------------------------
  58. // AMC_Import
  59. //----------------------------------------------------------------------------
  60. class AMC_Import : public SceneImport
  61. {
  62. public:
  63. AMC_Import();
  64. ~AMC_Import();
  65. int ExtCount(); // Number of extensions supported
  66. const TCHAR * Ext(int n); // Extension #n
  67. const TCHAR * LongDesc(); // Long ASCII description
  68. const TCHAR * ShortDesc(); // Short ASCII description
  69. const TCHAR * AuthorName(); // ASCII Author name
  70. const TCHAR * CopyrightMessage(); // ASCII Copyright message
  71. const TCHAR * OtherMessage1(); // Other message #1
  72. const TCHAR * OtherMessage2(); // Other message #2
  73. unsigned int Version(); // Version number * 100
  74. void ShowAbout(HWND); // Show DLL's "About..." box
  75. int DoImport
  76. (
  77. const TCHAR * name,
  78. ImpInterface * i,
  79. Interface * gi,
  80. BOOL suppressPrompts
  81. );
  82. };
  83. //----------------------------------------------------------------------------
  84. // DllMain
  85. //----------------------------------------------------------------------------
  86. static int controlsInit = FALSE;
  87. BOOL WINAPI DllMain
  88. (
  89. HINSTANCE hinstDLL,
  90. ULONG fdwReason,
  91. LPVOID lpvReserved
  92. )
  93. {
  94. hInstance = hinstDLL;
  95. if ( !controlsInit )
  96. {
  97. controlsInit = TRUE;
  98. InitCustomControls(hInstance);
  99. InitCommonControls();
  100. }
  101. switch(fdwReason)
  102. {
  103. case DLL_PROCESS_ATTACH: break;
  104. case DLL_THREAD_ATTACH: break;
  105. case DLL_THREAD_DETACH: break;
  106. case DLL_PROCESS_DETACH: break;
  107. }
  108. return TRUE;
  109. }
  110. //----------------------------------------------------------------------------
  111. // AMC_ClassDesc
  112. //----------------------------------------------------------------------------
  113. class AMC_ClassDesc : public ClassDesc
  114. {
  115. public:
  116. int IsPublic() { return 1; }
  117. void * Create(BOOL loading = FALSE) { return new AMC_Import; }
  118. const TCHAR * ClassName() { return GetString(IDS_SHORT_DESC); }
  119. SClass_ID SuperClassID() { return SCENE_IMPORT_CLASS_ID; }
  120. Class_ID ClassID() { return Class_ID(0x5be11422, 0x6e0177f0); }
  121. const TCHAR* Category() { return GetString(IDS_CATEGORY); }
  122. };
  123. static AMC_ClassDesc AMC_desc;
  124. //----------------------------------------------------------------------------
  125. // This is the interface to Jaguar:
  126. //----------------------------------------------------------------------------
  127. __declspec( dllexport ) const TCHAR * LibDescription()
  128. {
  129. return GetString(IDS_LIB_LONG_DESC);
  130. }
  131. __declspec( dllexport ) int LibNumberClasses()
  132. {
  133. return 1;
  134. }
  135. __declspec( dllexport ) ClassDesc * LibClassDesc(int i)
  136. {
  137. switch(i)
  138. {
  139. case 0: return & AMC_desc; break;
  140. default: return 0; break;
  141. }
  142. }
  143. // Return version so can detect obsolete DLLs
  144. __declspec( dllexport ) ULONG LibVersion()
  145. {
  146. return VERSION_3DSMAX;
  147. }
  148. //
  149. // ASF import module functions follow:
  150. //
  151. AMC_Import::AMC_Import() {}
  152. AMC_Import::~AMC_Import() {}
  153. int AMC_Import::ExtCount()
  154. {
  155. return 1;
  156. }
  157. // Extensions supported for import/export modules
  158. const TCHAR * AMC_Import::Ext(int n)
  159. {
  160. return _T("AMC");
  161. }
  162. const TCHAR * AMC_Import::LongDesc()
  163. {
  164. return GetString(IDS_LONG_DESC);
  165. }
  166. const TCHAR * AMC_Import::ShortDesc()
  167. {
  168. return GetString(IDS_SHORT_DESC);
  169. }
  170. const TCHAR * AMC_Import::AuthorName()
  171. {
  172. return GetString(IDS_AUTHOR_NAME);
  173. }
  174. const TCHAR * AMC_Import::CopyrightMessage()
  175. {
  176. return GetString(IDS_COPYRIGHT);
  177. }
  178. const TCHAR * AMC_Import::OtherMessage1()
  179. {
  180. return _T("");
  181. }
  182. const TCHAR * AMC_Import::OtherMessage2()
  183. {
  184. return _T("");
  185. }
  186. unsigned int AMC_Import::Version()
  187. {
  188. return 100;
  189. }
  190. void AMC_Import::ShowAbout(HWND hWnd)
  191. {
  192. }
  193. //----------------------------------------------------------------------------
  194. // Key_Class
  195. //----------------------------------------------------------------------------
  196. struct Key_Class
  197. {
  198. TimeValue Time;
  199. Quat Orientation;
  200. Point3 Position;
  201. };
  202. //----------------------------------------------------------------------------
  203. // Bone
  204. //----------------------------------------------------------------------------
  205. class Bone
  206. {
  207. public:
  208. Bone ( const char * name, Bone * next )
  209. {
  210. Name = new char [ strlen (name) + 1 ];
  211. strcpy ( Name, name );
  212. Next = next;
  213. Max_keys = 1;
  214. Number_of_keys = 0;
  215. Key = NULL;
  216. }
  217. ~Bone ()
  218. {
  219. delete [] Name;
  220. if ( Key != NULL )
  221. delete [] Key;
  222. }
  223. void alloc_key_space ( Interface * gi )
  224. {
  225. if ( Key == NULL && Max_keys > 0 )
  226. Key = new Key_Class [ Max_keys ];
  227. // Find the bone's I-node.
  228. // TODO: check to ensure we got the inode!
  229. INode * inode = gi->GetINodeByName ( Name );
  230. if (inode) {
  231. // Add a key at frame zero to hold the original position.
  232. Quat rotation ( 0.0f, 0.0f, 0.0f, 1.0f );
  233. Matrix3 localTM = inode->GetNodeTM (0) *
  234. Inverse (inode->GetParentTM (0));
  235. rotation *= localTM;
  236. add_key ( 0, rotation, Point3 (0,0,0) );
  237. }
  238. }
  239. void inc_max_keys () { ++ Max_keys; }
  240. void add_key ( TimeValue time, const Quat & rot, const Point3 & pos )
  241. {
  242. if ( Key != NULL && Number_of_keys < Max_keys )
  243. {
  244. Key [Number_of_keys].Time = time;
  245. Key [Number_of_keys].Orientation = rot;
  246. Key [Number_of_keys].Position = pos;
  247. ++ Number_of_keys;
  248. }
  249. }
  250. void put_keys_into_max ( ImpInterface * imp_i, Interface * i );
  251. Bone * next () const { return Next; }
  252. char * name () const { return Name; }
  253. protected:
  254. char * Name;
  255. Bone * Next;
  256. unsigned Max_keys;
  257. unsigned Number_of_keys;
  258. Key_Class * Key;
  259. };
  260. //----------------------------------------------------------------------------
  261. // Bone::put_keys_into_max
  262. //----------------------------------------------------------------------------
  263. void Bone::put_keys_into_max ( ImpInterface * imp_i, Interface * i )
  264. {
  265. unsigned k;
  266. // Find the bone's I-node.
  267. INode * inode = i->GetINodeByName ( Name );
  268. if ( inode == NULL )
  269. return;
  270. // Make each quaternion be on the same side of the hypersphere as its
  271. // predecessor.
  272. for ( k = 1; k < Number_of_keys; ++ k )
  273. {
  274. Key [k].Orientation.MakeClosest ( Key [k-1].Orientation );
  275. }
  276. // Make each rotation relative to the previous one.
  277. if ( Number_of_keys > 1 )
  278. {
  279. for ( unsigned k = Number_of_keys - 1; k > 0; -- k )
  280. {
  281. Key [k].Orientation = Key [k].Orientation / Key [k-1].Orientation;
  282. }
  283. }
  284. // Add the keys to the bone's rotation controller.
  285. // Replace the rotation controller if it is not the right type.
  286. Control * c = inode->GetTMController ()->GetRotationController ();
  287. if ( c && c->ClassID () != Class_ID (TCBINTERP_ROTATION_CLASS_ID, 0) )
  288. {
  289. Control *tcb = (Control*) i->CreateInstance ( CTRL_ROTATION_CLASS_ID,
  290. Class_ID (TCBINTERP_ROTATION_CLASS_ID,0) );
  291. if ( ! inode->GetTMController ()->SetRotationController(tcb) )
  292. {
  293. tcb->DeleteThis();
  294. }
  295. }
  296. c = inode->GetTMController ()->GetRotationController ();
  297. // c->SetORT ( ORT_LOOP, ORT_BEFORE );
  298. // c->SetORT ( ORT_LOOP, ORT_AFTER );
  299. IKeyControl * keys = GetKeyControlInterface ( c );
  300. keys->SetNumKeys ( Number_of_keys );
  301. // Create keys.
  302. for ( k = 0; k < Number_of_keys; ++ k )
  303. {
  304. ITCBRotKey key;
  305. key.tens = 0.0f;
  306. key.cont = 0.0f;
  307. key.bias = 0.0f;
  308. key.easeIn = 0.0f;
  309. key.easeOut = 0.0f;
  310. key.time = Key [k].Time;
  311. key.val = (AngAxis) Key [k].Orientation;
  312. keys->SetKey ( k, & key );
  313. }
  314. keys->SortKeys ();
  315. // &&& This is a hack; add position keys for the root node.
  316. // Another hack: The positions are multiplied by a scale factor which
  317. // should be derived from the ASF file.
  318. float length_multiplier;
  319. if ( strcmp ( Name, "root" ) == 0 )
  320. {
  321. // Since this is the root node, check for an AppData chunk defining
  322. // the length multiplier.
  323. // This "length multiplier" will convert whatever numbers are in the file
  324. // into *inches*. We later convert this to whatever units Max is using...
  325. AppDataChunk * chunk = inode->GetAppDataChunk
  326. (
  327. Class_ID(0x74975aa6, 0x1810323f),
  328. SCENE_IMPORT_CLASS_ID,
  329. 2
  330. );
  331. if ( chunk == NULL )
  332. {
  333. // (gth) HACK HACK HACK! For some time, I had removed this 'length_multiplier'
  334. // Many commando animations were created without the multiplier which was 1.0 / 0.0254
  335. // so, shove that multiplier in if one wasn't found... This only comes into play
  336. // when loading a motion into a max file that use the old importer to create the
  337. // base pose.
  338. length_multiplier = 1.0f / 0.0254f;
  339. }
  340. else
  341. {
  342. Position_Key_Scale_Chunk * data_p = (Position_Key_Scale_Chunk *) chunk->data;
  343. length_multiplier = data_p->Position_Key_Scale;
  344. }
  345. // Account for the current units setting of Max (e.g. 1 unit = 1 Meter)
  346. length_multiplier /= (float)GetMasterScale(UNITS_INCHES);
  347. // Make sure we have the right kind of controller.
  348. c = inode->GetTMController ()->GetPositionController ();
  349. if ( c && c->ClassID () != Class_ID (TCBINTERP_POSITION_CLASS_ID, 0) )
  350. {
  351. Control *tcb = (Control*) i->CreateInstance ( CTRL_POSITION_CLASS_ID,
  352. Class_ID (TCBINTERP_POSITION_CLASS_ID,0) );
  353. if ( ! inode->GetTMController ()->SetPositionController(tcb) )
  354. {
  355. tcb->DeleteThis();
  356. }
  357. }
  358. c = inode->GetTMController ()->GetPositionController ();
  359. // c->SetORT ( ORT_LOOP, ORT_BEFORE );
  360. // c->SetORT ( ORT_LOOP, ORT_AFTER );
  361. keys = GetKeyControlInterface ( c );
  362. keys->SetNumKeys ( Number_of_keys );
  363. // Create keys.
  364. for ( k = 0; k < Number_of_keys; ++ k )
  365. {
  366. ITCBPoint3Key key;
  367. key.tens = 0.0f;
  368. key.cont = 0.0f;
  369. key.bias = 0.0f;
  370. key.easeIn = 0.0f;
  371. key.easeOut = 0.0f;
  372. key.time = Key [k].Time;
  373. key.val = Key [k].Position * length_multiplier;
  374. keys->SetKey ( k, & key );
  375. }
  376. keys->SortKeys ();
  377. }
  378. }
  379. //----------------------------------------------------------------------------
  380. // Key_Manager
  381. //----------------------------------------------------------------------------
  382. class Key_Manager
  383. {
  384. public:
  385. Key_Manager () { Bones = NULL; }
  386. ~Key_Manager ();
  387. // Call this first to increment the maximum number of keys for a given
  388. // bone.
  389. void inc_max_keys ( const char * bone_name );
  390. // After all the maximums are set properly, call this to allocate space
  391. // for holding the keys.
  392. void alloc_key_space ( Interface * gi );
  393. // After allocating space, add keys by calling this.
  394. void add_key
  395. (
  396. const char * bone_name,
  397. TimeValue time,
  398. const Quat & rot,
  399. const Point3 & pos
  400. );
  401. // Once all the keys have been added, call this to massage them and
  402. // put them into 3D Studio.
  403. void put_keys_into_max ( ImpInterface *, Interface * );
  404. protected:
  405. Bone * Bones;
  406. };
  407. //----------------------------------------------------------------------------
  408. // Key_Manager::~Key_Manager
  409. //----------------------------------------------------------------------------
  410. Key_Manager::~Key_Manager ()
  411. {
  412. Bone * p = Bones;
  413. while ( p != NULL )
  414. {
  415. Bone * delete_p = p;
  416. p = p->next ();
  417. delete delete_p;
  418. }
  419. }
  420. //----------------------------------------------------------------------------
  421. // Key_Manager::inc_max_keys
  422. //----------------------------------------------------------------------------
  423. void Key_Manager::inc_max_keys ( const char * name )
  424. {
  425. for ( Bone * p = Bones; p != NULL; p = p->next () )
  426. {
  427. if ( strcmp ( p->name (), name ) == 0 )
  428. break;
  429. }
  430. if ( p == NULL )
  431. {
  432. // This is a new bone; add it to the list.
  433. p = new Bone ( name, Bones );
  434. Bones = p;
  435. }
  436. p->inc_max_keys ();
  437. }
  438. //----------------------------------------------------------------------------
  439. // Key_Manager::alloc_key_space
  440. //----------------------------------------------------------------------------
  441. void Key_Manager::alloc_key_space ( Interface * gi )
  442. {
  443. for ( Bone * p = Bones; p != NULL; p = p->next () )
  444. {
  445. p->alloc_key_space ( gi );
  446. }
  447. }
  448. //----------------------------------------------------------------------------
  449. // Key_Manager::add_key
  450. //----------------------------------------------------------------------------
  451. void Key_Manager::add_key
  452. (
  453. const char * name,
  454. TimeValue time,
  455. const Quat & rot,
  456. const Point3 & pos
  457. )
  458. {
  459. for ( Bone * p = Bones; p != NULL; p = p->next () )
  460. {
  461. if ( strcmp ( p->name (), name ) == 0 )
  462. break;
  463. }
  464. if ( p != NULL )
  465. {
  466. p->add_key ( time, rot, pos );
  467. }
  468. }
  469. //----------------------------------------------------------------------------
  470. // Key_Manager::put_keys_into_max
  471. //----------------------------------------------------------------------------
  472. void Key_Manager::put_keys_into_max ( ImpInterface * imp_i, Interface * i )
  473. {
  474. for ( Bone * p = Bones; p != NULL; p = p->next () )
  475. {
  476. p->put_keys_into_max ( imp_i, i );
  477. }
  478. }
  479. //----------------------------------------------------------------------------
  480. // get_name
  481. //----------------------------------------------------------------------------
  482. void get_name
  483. (
  484. char * & line_p,
  485. char * & name_p
  486. )
  487. {
  488. name_p = line_p;
  489. while ( ! isspace (*line_p) )
  490. ++ line_p;
  491. *line_p = '\0';
  492. ++ line_p;
  493. }
  494. //----------------------------------------------------------------------------
  495. // read_frames
  496. //----------------------------------------------------------------------------
  497. static void read_frames
  498. (
  499. FILE * file,
  500. ImpInterface * iface,
  501. Interface * gi
  502. )
  503. {
  504. char line [ 512 ];
  505. Key_Manager key_manager;
  506. // Start by identifying the bones in the system and the number of keys
  507. // for each.
  508. long start_pos = ftell ( file );
  509. while (1)
  510. {
  511. char * rv = fgets ( line, sizeof line, file );
  512. if ( rv == NULL )
  513. break;
  514. if ( ! isdigit (line [0]) )
  515. {
  516. char * line_p = line;
  517. char * name_p;
  518. get_name ( line_p, name_p );
  519. key_manager.inc_max_keys ( name_p );
  520. }
  521. }
  522. // Prepare to scan the file again. Allocate space to hold the keys.
  523. fseek ( file, start_pos, SEEK_SET );
  524. key_manager.alloc_key_space ( gi );
  525. int frame_time = 0;
  526. while (1)
  527. {
  528. char * rv = fgets ( line, sizeof line, file );
  529. if ( rv == NULL )
  530. break;
  531. if ( isdigit (line [0]) )
  532. {
  533. // This line marks the start of a new frame.
  534. int frame_number = strtol ( line, NULL, 10 );
  535. frame_time = (frame_number - 1) * amc_ticks_per_frame +
  536. first_frame_time;
  537. }
  538. else
  539. {
  540. // This line contains a bone's data for the current frame.
  541. // Get the name of the bone whose key is being defined.
  542. char * line_p = line;
  543. char * name_p;
  544. get_name ( line_p, name_p );
  545. // Find the I-node with the name given in the input file.
  546. INode * inode = gi->GetINodeByName ( name_p );
  547. #if 0
  548. if ( inode == NULL )
  549. {
  550. char message [ 256 ];
  551. sprintf ( message, "Can't find node named \"%s\".",
  552. name_p );
  553. MessageBox ( GetActiveWindow (), message, "Parse error",
  554. MB_OK );
  555. return;
  556. }
  557. #else
  558. if ( inode == NULL) {
  559. continue;
  560. }
  561. #endif
  562. // From the I-node, get the appdata chunk that defines the order
  563. // in which rotations should be applied.
  564. AppDataChunk * chunk = inode->GetAppDataChunk
  565. (
  566. Class_ID(0x74975aa6, 0x1810323f),
  567. SCENE_IMPORT_CLASS_ID,
  568. 1
  569. );
  570. if ( chunk == NULL )
  571. {
  572. char message [ 256 ];
  573. sprintf ( message, "\"%s\" has no app data chunk.",
  574. name_p );
  575. MessageBox ( GetActiveWindow (), message, "Parse error",
  576. MB_OK );
  577. return;
  578. }
  579. ASF_Data_Chunk * data_p = (ASF_Data_Chunk *) chunk->data;
  580. // Read in angle settings and build a transform matrix from them.
  581. Quat rotation (0.0f,0.0f,0.0f,1.0f);
  582. Point3 translation ( 0, 0, 0 );
  583. for ( unsigned i = 0; i < data_p->Number_of_axes; ++ i )
  584. {
  585. float value;
  586. value = (float) strtod ( line_p, & line_p );
  587. switch ( data_p->Axis [i] )
  588. {
  589. case ROTATE_X:
  590. rotation *= (Quat) AngAxis ( Point3 (1, 0, 0),
  591. -value * ANGLE_MULTIPLIER );
  592. break;
  593. case ROTATE_Y:
  594. rotation *= (Quat) AngAxis ( Point3 (0, 1, 0),
  595. -value * ANGLE_MULTIPLIER );
  596. break;
  597. case ROTATE_Z:
  598. rotation *= (Quat) AngAxis ( Point3 (0, 0, 1),
  599. -value * ANGLE_MULTIPLIER );
  600. break;
  601. case TRANSLATE_X:
  602. translation.x = value;
  603. break;
  604. case TRANSLATE_Y:
  605. translation.y = value;
  606. break;
  607. case TRANSLATE_Z:
  608. translation.z = value;
  609. break;
  610. case TRANSLATE_LENGTH:
  611. default:
  612. break;
  613. }
  614. }
  615. Matrix3 localTM = inode->GetNodeTM (0) *
  616. Inverse (inode->GetParentTM (0));
  617. rotation *= localTM;
  618. if ( frame_time % max_ticks_per_frame == 0 )
  619. key_manager.add_key ( name_p, frame_time, rotation, translation );
  620. }
  621. }
  622. key_manager.put_keys_into_max ( iface, gi );
  623. gi->SetAnimRange ( Interval (0, frame_time) );
  624. }
  625. //----------------------------------------------------------------------------
  626. // amc_load
  627. //----------------------------------------------------------------------------
  628. static int amc_load
  629. (
  630. const TCHAR * filename,
  631. ImpInterface * iface,
  632. Interface * gi
  633. )
  634. {
  635. char line [ 512 ];
  636. // Load the motion-capture data file.
  637. FILE * file = fopen ( filename, "r" );
  638. // Ignore the first line.
  639. fgets ( line, sizeof line, file );
  640. // Match the second line to ":FULLY-SPECIFIED".
  641. fgets ( line, sizeof line, file );
  642. if ( strcmp ( line, ":FULLY-SPECIFIED\n" ) != 0 )
  643. {
  644. MessageBox ( GetActiveWindow (), "First line.", "Parse error",
  645. MB_OK );
  646. return -1;
  647. }
  648. // Match the third line to ":DEGREES".
  649. fgets ( line, sizeof line, file );
  650. if ( strcmp ( line, ":DEGREES\n" ) != 0 )
  651. {
  652. MessageBox ( GetActiveWindow (), "Second line.", "Parse error",
  653. MB_OK );
  654. return -1;
  655. }
  656. // Build the data structures to hold the rotation keys.
  657. read_frames ( file, iface, gi );
  658. fclose ( file );
  659. return 1;
  660. }
  661. //----------------------------------------------------------------------------
  662. // AMC_Import::DoImport
  663. //----------------------------------------------------------------------------
  664. int AMC_Import::DoImport
  665. (
  666. const TCHAR * filename,
  667. ImpInterface * iface,
  668. Interface * gi,
  669. BOOL
  670. )
  671. {
  672. max_ticks_per_frame = GetTicksPerFrame ();
  673. int status = amc_load ( filename, iface, gi );
  674. if ( status == 0 )
  675. status = IMPEXP_CANCEL;
  676. return (status <= 0) ? IMPEXP_FAIL : status;
  677. }