Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

970 lines
22 KiB

  1. //=============================================================================
  2. //
  3. //========= Copyright Valve Corporation, All rights reserved. ============//
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //
  11. // Converts from any one DMX file format to another
  12. // Can also output SMD or a QCI header from DMX input
  13. //
  14. //=============================================================================
  15. #ifndef DMXEDIT_H
  16. #define DMXEDIT_H
  17. // Valve includes
  18. #include "movieobjects/dmemesh.h"
  19. #include "tier1/utlstring.h"
  20. #include "tier1/utlvector.h"
  21. #include "tier1/UtlStringMap.h"
  22. // Lua includes
  23. #include <lua.h>
  24. class CDmxEditProxy;
  25. //=============================================================================
  26. // CDmxEdit declaration
  27. //=============================================================================
  28. class CDmxEdit
  29. {
  30. public:
  31. void SetScriptFilename( const char *pFilename );
  32. class delta : public CUtlString
  33. {
  34. public:
  35. delta() {};
  36. delta( const char *pString ) : CUtlString( pString ) {}
  37. delta( const CUtlString &string ) : CUtlString( string ) {}
  38. };
  39. class CFalloffType
  40. {
  41. public:
  42. CFalloffType( CDmeMesh::Falloff_t falloffType )
  43. : m_falloffType( falloffType )
  44. {
  45. }
  46. CDmeMesh::Falloff_t StringToFalloff( const char *pFalloffTypeString )
  47. {
  48. if ( !Q_strnicmp( pFalloffTypeString, "L", 1 ) )
  49. return CDmeMesh::LINEAR;
  50. if ( !Q_strnicmp( pFalloffTypeString, "ST", 2 ) )
  51. return CDmeMesh::STRAIGHT;
  52. if ( !Q_strnicmp( pFalloffTypeString, "B", 1 ) )
  53. return CDmeMesh::BELL;
  54. if ( !Q_strnicmp( pFalloffTypeString, "SM", 2 ) )
  55. return CDmeMesh::SMOOTH;
  56. if ( !Q_strnicmp( pFalloffTypeString, "SP", 2 ) )
  57. return CDmeMesh::SPIKE;
  58. if ( !Q_strnicmp( pFalloffTypeString, "D", 1 ) )
  59. return CDmeMesh::DOME;
  60. Msg( "// ERROR: Can't Figure Out Which Falloff Type Is Meant By \"%s\", Assuming STRAIGHT\n", pFalloffTypeString );
  61. return CDmeMesh::STRAIGHT;
  62. }
  63. CFalloffType( const char *pFalloffTypeString )
  64. : m_falloffType( StringToFalloff( pFalloffTypeString ) )
  65. {
  66. }
  67. CDmeMesh::Falloff_t operator()() const { return m_falloffType; }
  68. operator char *() const
  69. {
  70. switch ( m_falloffType )
  71. {
  72. case CDmeMesh::LINEAR:
  73. return "STRAIGHT";
  74. case CDmeMesh::BELL:
  75. return "BELL";
  76. case CDmeMesh::SPIKE:
  77. return "SPIKE";
  78. case CDmeMesh::DOME:
  79. return "DOME";
  80. default:
  81. break;
  82. }
  83. return "STRAIGHT";
  84. }
  85. protected:
  86. const CDmeMesh::Falloff_t m_falloffType;
  87. };
  88. static const CFalloffType STRAIGHT;
  89. static const CFalloffType LINEAR;
  90. static const CFalloffType BELL;
  91. static const CFalloffType SMOOTH;
  92. static const CFalloffType SPIKE;
  93. static const CFalloffType DOME;
  94. class CSelectOp
  95. {
  96. public:
  97. enum SelectOp_t
  98. {
  99. kAdd,
  100. kSubtract,
  101. kToggle,
  102. kIntersect,
  103. kReplace
  104. };
  105. CSelectOp( SelectOp_t selectOp )
  106. : m_selectOp( selectOp )
  107. {
  108. }
  109. SelectOp_t StringToSelectOp( const char *pSelectOpString )
  110. {
  111. if ( !Q_strnicmp( pSelectOpString, "A", 1 ) )
  112. return kAdd;
  113. if ( !Q_strnicmp( pSelectOpString, "S", 1 ) )
  114. return kSubtract;
  115. if ( !Q_strnicmp( pSelectOpString, "T", 1 ) )
  116. return kToggle;
  117. if ( !Q_strnicmp( pSelectOpString, "I", 1 ) )
  118. return kIntersect;
  119. if ( !Q_strnicmp( pSelectOpString, "R", 1 ) )
  120. return kReplace;
  121. Msg( "// ERROR: Can't Figure Out Which Select Operation Type Is Meant By \"%s\", Assuming REPLACE\n", pSelectOpString );
  122. return kReplace;
  123. }
  124. CSelectOp( const char *pSelectOp )
  125. : m_selectOp( StringToSelectOp( pSelectOp ) )
  126. {
  127. }
  128. SelectOp_t operator()() const { return m_selectOp; }
  129. operator char *() const
  130. {
  131. switch ( m_selectOp )
  132. {
  133. case kAdd:
  134. return "ADD";
  135. case kSubtract:
  136. return "SUBTRACT";
  137. case kToggle:
  138. return "TOGGLE";
  139. case kIntersect:
  140. return "INTERSECT";
  141. default:
  142. break;
  143. }
  144. return "REPLACE";
  145. }
  146. protected:
  147. const SelectOp_t m_selectOp;
  148. };
  149. static const CSelectOp ADD;
  150. static const CSelectOp SUBTRACT;
  151. static const CSelectOp TOGGLE;
  152. static const CSelectOp INTERSECT;
  153. static const CSelectOp REPLACE;
  154. class CSelectType
  155. {
  156. public:
  157. enum Select_t
  158. {
  159. kNone,
  160. kAll,
  161. kDelta
  162. };
  163. CSelectType( Select_t selectType )
  164. : m_selectType( selectType )
  165. {
  166. }
  167. Select_t SelectTypeStringToType( const char *pSelectString )
  168. {
  169. if ( !Q_stricmp( pSelectString, "NONE" ) )
  170. return kNone;
  171. if ( !Q_stricmp( pSelectString, "ALL" ) )
  172. return kAll;
  173. return kDelta;
  174. }
  175. CSelectType( const char *pSelectTypeString )
  176. : m_selectType( SelectTypeStringToType( pSelectTypeString ) )
  177. {
  178. }
  179. Select_t operator()() const { return m_selectType; }
  180. operator char *() const
  181. {
  182. switch ( m_selectType )
  183. {
  184. case kNone:
  185. return "NONE";
  186. case kAll:
  187. return "ALL";
  188. default:
  189. break;
  190. }
  191. return "DELTA";
  192. }
  193. protected:
  194. const Select_t m_selectType;
  195. };
  196. static const CSelectType ALL;
  197. static const CSelectType NONE;
  198. //=============================================================================
  199. //
  200. //=============================================================================
  201. class CObjType
  202. {
  203. public:
  204. enum Obj_t
  205. {
  206. kAbsolute,
  207. kRelative
  208. };
  209. CObjType( Obj_t objType )
  210. : m_objType( objType )
  211. {
  212. }
  213. CObjType &operator=( const CObjType &rhs )
  214. {
  215. m_objType = rhs.m_objType;
  216. return *this;
  217. }
  218. Obj_t ObjTypeStringToType( const char *pObjString )
  219. {
  220. if ( pObjString && ( *pObjString == 'r' || *pObjString == 'R' ) )
  221. return kRelative;
  222. return kAbsolute;
  223. }
  224. CObjType( const char *pObjTypeString )
  225. : m_objType( ObjTypeStringToType( pObjTypeString ) )
  226. {
  227. }
  228. Obj_t operator()() const { return m_objType; }
  229. operator char *() const
  230. {
  231. switch ( m_objType )
  232. {
  233. case kRelative:
  234. return "RELATIVE";
  235. default:
  236. break;
  237. }
  238. return "ABSOLUTE";
  239. }
  240. protected:
  241. Obj_t m_objType;
  242. };
  243. static const CObjType ABSOLUTE;
  244. static const CObjType RELATIVE;
  245. //=============================================================================
  246. //
  247. //=============================================================================
  248. class CDistanceType
  249. {
  250. public:
  251. CDistanceType( CDmeMesh::Distance_t distanceType )
  252. : m_distanceType( distanceType )
  253. {
  254. }
  255. CDmeMesh::Distance_t DistanceTypeStringToType( const char *pDistanceTypeString )
  256. {
  257. if ( pDistanceTypeString && ( *pDistanceTypeString == 'a' || *pDistanceTypeString == 'A' ) )
  258. return CDmeMesh::DIST_ABSOLUTE;
  259. if ( pDistanceTypeString && ( *pDistanceTypeString == 'r' || *pDistanceTypeString == 'R' ) )
  260. return CDmeMesh::DIST_RELATIVE;
  261. return CDmeMesh::DIST_DEFAULT;
  262. }
  263. CDistanceType( const char *pDistanceTypeString )
  264. : m_distanceType( DistanceTypeStringToType( pDistanceTypeString ) )
  265. {
  266. }
  267. CDmeMesh::Distance_t operator()() const { return m_distanceType; }
  268. operator char *() const
  269. {
  270. switch ( m_distanceType )
  271. {
  272. case CDmeMesh::DIST_ABSOLUTE:
  273. return "ABSOLUTE";
  274. case CDmeMesh::DIST_RELATIVE:
  275. return "RELATIVE";
  276. default:
  277. break;
  278. }
  279. return "DEFAULT";
  280. }
  281. protected:
  282. CDmeMesh::Distance_t m_distanceType;
  283. };
  284. static const CDistanceType DIST_ABSOLUTE;
  285. static const CDistanceType DIST_RELATIVE;
  286. static const CDistanceType DIST_DEFAULT;
  287. class CAxisType
  288. {
  289. public:
  290. enum Axis_t
  291. {
  292. kXAxis,
  293. kYAxis,
  294. kZAxis
  295. };
  296. CAxisType( Axis_t axisType )
  297. : m_axisType( axisType )
  298. {
  299. }
  300. Axis_t AxisTypeStringToType( const char *pAxisString )
  301. {
  302. if ( pAxisString && ( *pAxisString == 'y' || *pAxisString == 'Y' ) )
  303. return kYAxis;
  304. if ( pAxisString && ( *pAxisString == 'z' || *pAxisString == 'Z' ) )
  305. return kZAxis;
  306. return kXAxis;
  307. }
  308. CAxisType( const char *pAxisTypeString )
  309. : m_axisType( AxisTypeStringToType( pAxisTypeString ) )
  310. {
  311. }
  312. Axis_t operator()() const { return m_axisType; }
  313. operator char *() const
  314. {
  315. switch ( m_axisType )
  316. {
  317. case kYAxis:
  318. return "YAXIS";
  319. case kZAxis:
  320. return "ZAXIS";
  321. default:
  322. break;
  323. }
  324. return "XAXIS";
  325. }
  326. protected:
  327. const Axis_t m_axisType;
  328. };
  329. static const CAxisType XAXIS;
  330. static const CAxisType YAXIS;
  331. static const CAxisType ZAXIS;
  332. class CHalfType
  333. {
  334. public:
  335. enum Half_t
  336. {
  337. kLeft,
  338. kRight
  339. };
  340. CHalfType( Half_t halfType )
  341. : m_halfType( halfType )
  342. {
  343. }
  344. Half_t HalfTypeStringToType( const char *pHalfString )
  345. {
  346. if ( pHalfString && ( *pHalfString == 'l' || *pHalfString == 'L' ) )
  347. return kLeft;
  348. if ( pHalfString && ( *pHalfString == 'r' || *pHalfString == 'R' ) )
  349. return kRight;
  350. return kLeft;
  351. }
  352. CHalfType( const char *pHalfTypeString )
  353. : m_halfType( HalfTypeStringToType( pHalfTypeString ) )
  354. {
  355. }
  356. Half_t operator()() const { return m_halfType; }
  357. operator char *() const
  358. {
  359. switch ( m_halfType )
  360. {
  361. case kLeft:
  362. return "LEFT";
  363. case kRight:
  364. return "RIGHT";
  365. default:
  366. break;
  367. }
  368. return "LEFT";
  369. }
  370. protected:
  371. const Half_t m_halfType;
  372. };
  373. static const CHalfType LEFT;
  374. static const CHalfType RIGHT;
  375. CDmxEdit();
  376. virtual ~CDmxEdit() {};
  377. bool Load( const char *pFilename, const CObjType &loadType = ABSOLUTE );
  378. bool Import( const char *pFilename, const char *pParentName = NULL );
  379. operator bool() const { return m_pMesh != NULL; }
  380. void DoIt();
  381. bool ListDeltas();
  382. int DeltaCount();
  383. const char *DeltaName( int nDeltaIndex );
  384. void Unload();
  385. bool ImportComboRules( const char *pFilename, bool bOverwrite = true, bool bPurgeDeltas = true );
  386. bool ResetState();
  387. bool SetState( const char *pDeltaName );
  388. bool Select( const char *selectString, CDmeSingleIndexedComponent *pPassedSelection = NULL, CDmeMesh *pPassedMesh = NULL );
  389. bool Select( const CSelectType &selectType, CDmeSingleIndexedComponent *pPassedSelection = NULL, CDmeMesh *pPassedMesh = NULL );
  390. bool Select( const CSelectOp &selectOp, const char *pSelectTypeString, CDmeSingleIndexedComponent *pPassedSelection = NULL, CDmeMesh *pPassedMesh = NULL );
  391. bool Select( const CSelectOp &selectOp, const CSelectType &selectType, CDmeSingleIndexedComponent *pPassedSelection = NULL, CDmeMesh *pPassedMesh = NULL );
  392. bool SelectHalf( const CSelectOp &selectOp, const CHalfType &halfType, CDmeSingleIndexedComponent *pPassedSelection = NULL, CDmeMesh *pPassedMesh = NULL );
  393. bool SelectHalf( const CHalfType &halfType, CDmeSingleIndexedComponent *pPassedSelection = NULL, CDmeMesh *pPassedMesh = NULL );
  394. bool GrowSelection( int nSize = 1 );
  395. bool ShrinkSelection( int nSize = 1 );
  396. enum AddType { kRaw, kCorrected };
  397. bool Add(
  398. AddType addType,
  399. const CDmxEditProxy &e,
  400. float weight = 1.0f,
  401. float featherDistance = 0.0f,
  402. const CFalloffType &falloffType = STRAIGHT,
  403. const CDistanceType &distanceType = DIST_DEFAULT );
  404. bool Add(
  405. const CDmxEditProxy &e,
  406. float weight = 1.0f,
  407. float featherDistance = 0.0f,
  408. const CFalloffType &falloffType = STRAIGHT,
  409. const CDistanceType &distanceType = DIST_DEFAULT )
  410. {
  411. return Add( kRaw, e, weight, featherDistance, falloffType, distanceType );
  412. }
  413. bool Add(
  414. AddType addType,
  415. const char *pDeltaName,
  416. float weight = 1.0f,
  417. float featherDistance = 0.0f,
  418. const CFalloffType &falloffType = STRAIGHT,
  419. const CDistanceType &distanceType = DIST_DEFAULT );
  420. bool Add(
  421. const char *pDeltaName,
  422. float weight = 1.0f,
  423. float featherDistance = 0.0f,
  424. const CFalloffType &falloffType = STRAIGHT,
  425. const CDistanceType &distanceType = DIST_DEFAULT )
  426. {
  427. return Add( kRaw, pDeltaName, weight, featherDistance, falloffType, distanceType );
  428. }
  429. bool Interp( const CDmxEditProxy &e, float weight = 1.0f, float featherDistance = 0.0f, const CFalloffType &falloffType = STRAIGHT, const CDistanceType &distanceType = DIST_DEFAULT );
  430. bool Interp( const char *pDeltaName, float weight = 1.0f, float featherDistance = 0.0f, const CFalloffType &falloffType = STRAIGHT, const CDistanceType &distanceType = DIST_DEFAULT );
  431. bool SaveDelta( const char *pDeltaName );
  432. bool DeleteDelta( const delta &d );
  433. bool Save( const char *pFilename, const CObjType &saveType = ABSOLUTE, const char *pDeltaName = NULL );
  434. bool Save() { return Save( m_filename ); }
  435. void CleanupWork();
  436. void CreateWork();
  437. bool Merge( const char *pInFilename, const char *pOutFilename );
  438. bool RemapMaterial( int nMaterialIndex, const char *pNewMaterialName );
  439. bool RemapMaterial( const char *pOldMaterialName, const char *pNewMaterialName );
  440. bool RemoveFacesWithMaterial( const char *pMaterialName );
  441. bool RemoveFacesWithMoreThanNVerts( int nVertexCount );
  442. bool Mirror( CAxisType = XAXIS );
  443. bool ComputeNormals();
  444. bool CreateDeltasFromPresets( const char *pPresetFilename, bool bDeleteNonPresetDeltas = true, const CUtlVector< CUtlString > *pPurgeAllButThese = NULL, const char *pExpressionFilename = NULL );
  445. bool CachePreset( const char *pPresetFilename, const char *pExpressionFilename = NULL );
  446. bool ClearPresetCache();
  447. bool CreateDeltasFromCachedPresets( bool bDeleteNonPresetDeltas = true, const CUtlVector< CUtlString > *pPurgeAllButThese = NULL ) const;
  448. bool CreateExpressionFileFromPresets( const char *pPresetFilename, const char *pExpressionFilename );
  449. bool CreateExpressionFilesFromCachedPresets() const;
  450. bool ComputeWrinkles( bool bOverwrite );
  451. bool ComputeWrinkle( const char *pDeltaName, float scale, const char *pOperation );
  452. bool Scale( float sx, float sy, float sz );
  453. bool SetDistanceType( const CDistanceType &distanceType );
  454. bool Translate(
  455. Vector t,
  456. float featherDistance = 0.0f,
  457. const CFalloffType &falloffType = STRAIGHT,
  458. const CDistanceType &distanceType = DIST_DEFAULT,
  459. CDmeMesh *pPassedMesh = NULL,
  460. CDmeVertexData *pPassedBase = NULL,
  461. CDmeSingleIndexedComponent *pPassedSelection = NULL );
  462. bool Translate( Vector t, float featherDistance, const CFalloffType &falloffType = STRAIGHT )
  463. {
  464. return Translate( t, featherDistance, falloffType, m_distanceType );
  465. }
  466. bool Rotate(
  467. Vector r,
  468. Vector o,
  469. float featherDistance = 0.0f,
  470. const CFalloffType &falloffType = STRAIGHT,
  471. const CDistanceType &passedDistanceType = DIST_DEFAULT,
  472. CDmeMesh *pPassedMesh = NULL,
  473. CDmeVertexData *pPassedBase = NULL,
  474. CDmeSingleIndexedComponent *pPassedSelection = NULL );
  475. bool FixPresetFile( const char *pPresetFilename );
  476. bool GroupControls( const char *pGroupName, CUtlVector< const char * > &rawControlNames );
  477. bool ReorderControls( CUtlVector< CUtlString > &controlNames );
  478. bool AddDominationRule( CUtlVector< CUtlString > &dominators, CUtlVector< CUtlString > &supressed );
  479. bool SetStereoControl( const char *pControlName, bool bStereo );
  480. bool SetEyelidControl( const char *pControlName, bool bEyelid );
  481. float MaxDeltaDistance( const char *pDeltaName );
  482. float DeltaRadius( const char *pDeltaName );
  483. float SelectionRadius();
  484. bool SetWrinkleScale( const char *pControlName, const char *pRawControlName, float flScale );
  485. bool ErrorState() {
  486. return m_errorState;
  487. }
  488. void Error( PRINTF_FORMAT_STRING const tchar *pMsgFormat, ... );
  489. const CUtlString &SetFuncString( lua_State *pLuaState );
  490. const CUtlString &GetFuncString() const { return m_funcString; }
  491. int GetLineNumber() const { return m_lineNo; }
  492. const CUtlString &GetSourceFile() const { return m_sourceFile; }
  493. const CUtlString &GetErrorString() const { return m_errorString; }
  494. int LuaOk( lua_State *pLuaState )
  495. {
  496. Msg( "// %s\n", GetFuncString().Get() );
  497. lua_pushboolean( pLuaState, true );
  498. return 1;
  499. }
  500. int LuaError( lua_State *pLuaState )
  501. {
  502. if ( GetLineNumber() >= 0 )
  503. {
  504. Error( "// ERROR: %s:%d: %s - %s\n",
  505. GetSourceFile().Get(),
  506. GetLineNumber(),
  507. GetFuncString().Get(),
  508. GetErrorString().Get() );
  509. }
  510. else
  511. {
  512. Error( "// ERROR: %s - %s\n",
  513. GetFuncString().Get(),
  514. GetErrorString().Get() );
  515. }
  516. lua_pushboolean( pLuaState, false );
  517. return 1;
  518. }
  519. int LuaError( lua_State *pLuaState, PRINTF_FORMAT_STRING const char *pFormat, ... )
  520. {
  521. char tmpBuf[ 4096 ];
  522. va_list marker;
  523. va_start( marker, pFormat );
  524. #ifdef _WIN32
  525. int len = _vsnprintf( tmpBuf, sizeof( tmpBuf ) - 1, pFormat, marker );
  526. #elif LINUX
  527. int len = vsnprintf( tmpBuf, sizeof( tmpBuf ) - 1, pFormat, marker );
  528. #else
  529. #error "define vsnprintf type."
  530. #endif
  531. va_end( marker );
  532. // Len < 0 represents an overflow
  533. if( len < 0 )
  534. {
  535. len = sizeof( tmpBuf ) - 1;
  536. tmpBuf[sizeof( tmpBuf ) - 1] = 0;
  537. }
  538. if ( GetLineNumber() >= 0 )
  539. {
  540. Error( "// ERROR: %s:%d: %s - %s\n",
  541. GetSourceFile().Get(),
  542. GetLineNumber(),
  543. GetFuncString().Get(),
  544. tmpBuf );
  545. }
  546. else
  547. {
  548. Error( "// ERROR: %s - %s\n",
  549. GetFuncString().Get(),
  550. tmpBuf );
  551. }
  552. lua_pushboolean( pLuaState, false );
  553. return 1;
  554. }
  555. void LuaWarning( PRINTF_FORMAT_STRING const char *pFormat, ... )
  556. {
  557. char tmpBuf[ 4096 ];
  558. va_list marker;
  559. va_start( marker, pFormat );
  560. #ifdef _WIN32
  561. int len = _vsnprintf( tmpBuf, sizeof( tmpBuf ) - 1, pFormat, marker );
  562. #elif LINUX
  563. int len = vsnprintf( tmpBuf, sizeof( tmpBuf ) - 1, pFormat, marker );
  564. #else
  565. #error "define vsnprintf type."
  566. #endif
  567. va_end( marker );
  568. // Len < 0 represents an overflow
  569. if( len < 0 )
  570. {
  571. len = sizeof( tmpBuf ) - 1;
  572. tmpBuf[sizeof( tmpBuf ) - 1] = 0;
  573. }
  574. if ( GetLineNumber() >= 0 )
  575. {
  576. Warning( "// WARNING: %s:%d: %s - %s\n",
  577. GetSourceFile().Get(),
  578. GetLineNumber(),
  579. GetFuncString().Get(),
  580. tmpBuf );
  581. }
  582. else
  583. {
  584. Warning( "// WARNING: %s - %s\n",
  585. GetFuncString().Get(),
  586. tmpBuf );
  587. }
  588. }
  589. bool SetErrorString( PRINTF_FORMAT_STRING const char *pFormat, ... )
  590. {
  591. char tmpBuf[ 4096 ];
  592. va_list marker;
  593. va_start( marker, pFormat );
  594. #ifdef _WIN32
  595. int len = _vsnprintf( tmpBuf, sizeof( tmpBuf ) - 1, pFormat, marker );
  596. #elif LINUX
  597. int len = vsnprintf( tmpBuf, sizeof( tmpBuf ) - 1, pFormat, marker );
  598. #else
  599. #error "define vsnprintf type."
  600. #endif
  601. va_end( marker );
  602. // Len < 0 represents an overflow
  603. if( len < 0 )
  604. {
  605. len = sizeof( tmpBuf ) - 1;
  606. tmpBuf[sizeof( tmpBuf ) - 1] = 0;
  607. }
  608. m_errorString = tmpBuf;
  609. return false;
  610. }
  611. protected:
  612. CUtlString m_filename;
  613. CDmElement *m_pRoot;
  614. CDmeMesh *m_pMesh;
  615. CDmeSingleIndexedComponent *m_pCurrentSelection;
  616. bool m_errorState;
  617. CDistanceType m_distanceType;
  618. CUtlStringMap< CUtlString > m_presetCache;
  619. CUtlString m_scriptFilename;
  620. bool Select( CDmeVertexDeltaData *pDelta, CDmeSingleIndexedComponent *pPassedSelection = NULL, CDmeMesh *pPassedMesh = NULL );
  621. bool Select( const CSelectOp &selectOp, CDmeSingleIndexedComponent *pOriginal, const CDmeSingleIndexedComponent *pNew );
  622. bool Select( const CSelectOp &selectOp, CDmeVertexDeltaData *pDelta, CDmeSingleIndexedComponent *pPassedSelection = NULL, CDmeMesh *pPassedMesh = NULL );
  623. void ImportCombinationControls( CDmeCombinationOperator *pSrcComboOp, CDmeCombinationOperator *pDstComboOp, bool bOverwrite );
  624. void ImportDominationRules( CDmeCombinationOperator *pDestComboOp, CDmeCombinationOperator *pSrcComboOp, bool bOverwrite );
  625. CDmeMesh *GetMesh( CDmeMesh *pPassedMesh )
  626. {
  627. return pPassedMesh ? pPassedMesh : m_pMesh;
  628. }
  629. void SetErrorState()
  630. {
  631. m_errorState = true;
  632. }
  633. void ResetErrorState()
  634. {
  635. m_errorState = false;
  636. }
  637. CDmeSingleIndexedComponent *GetSelection( CDmeSingleIndexedComponent *pPassedSelection )
  638. {
  639. return pPassedSelection ? pPassedSelection : m_pCurrentSelection;
  640. }
  641. CDmeVertexDeltaData *FindDeltaState( const char *pDeltaName, const CDmeMesh *pPassedMesh = NULL ) const
  642. {
  643. const CDmeMesh *pMesh = pPassedMesh ? pPassedMesh : m_pMesh;
  644. if ( !pMesh )
  645. return NULL;
  646. return pMesh->FindDeltaState( pDeltaName );
  647. }
  648. CDmeVertexData *GetBindState( const CDmeMesh *pPassedMesh = NULL ) const
  649. {
  650. const CDmeMesh *pMesh = pPassedMesh ? pPassedMesh : m_pMesh;
  651. if ( !pMesh )
  652. return NULL;
  653. return pMesh->FindBaseState( "bind" );
  654. }
  655. void GetFuncArg( lua_State *pLuaState, int nIndex, CUtlString &funcString );
  656. CUtlString m_funcString;
  657. int m_lineNo;
  658. CUtlString m_sourceFile;
  659. CUtlString m_errorString;
  660. void UpdateMakefile( CDmElement *pRoot );
  661. void AddExportTags( CDmElement *pRoot, const char *pFilename );
  662. void RemoveExportTags( CDmElement *pRoot, const char *pExportTagsName );
  663. };
  664. //=============================================================================
  665. //
  666. //=============================================================================
  667. typedef int ( * LuaFunc_t ) ( lua_State * );
  668. //=============================================================================
  669. //
  670. //=============================================================================
  671. struct LuaFunc_s
  672. {
  673. LuaFunc_s( const char *pName, LuaFunc_t pFunc, const char *pProto, const char *pDoc )
  674. : m_pFuncName( pName )
  675. , m_pFunc( pFunc )
  676. , m_pFuncPrototype( pProto )
  677. , m_pFuncDesc( pDoc )
  678. {
  679. m_pNextFunc = s_pFirstFunc;
  680. s_pFirstFunc = this;
  681. }
  682. const char *m_pFuncName;
  683. LuaFunc_t m_pFunc;
  684. const char *m_pFuncPrototype;
  685. const char *m_pFuncDesc;
  686. static LuaFunc_s *s_pFirstFunc;
  687. LuaFunc_s *m_pNextFunc;
  688. static CDmxEdit m_dmxEdit;
  689. };
  690. //-----------------------------------------------------------------------------
  691. // Macro to install a valve lua command
  692. //
  693. // Use like this:
  694. //
  695. // LUA_COMMAND( blah, "blah prototype", "blah documentation" )
  696. // {
  697. // // ... blah implementation ...
  698. // // ... Function is passed single struct of lua_State *pLuaState ...
  699. // // ... Function returns an int ...
  700. //
  701. // // Example usage:
  702. //
  703. // const char *pArg = luaL_checkstring( pLuaState, 1 );
  704. // return 0;
  705. // }
  706. //-----------------------------------------------------------------------------
  707. #define LUA_COMMAND( _name, _proto, _doc ) \
  708. static int _name##_luaFunc( lua_State *pLuaState ); \
  709. static LuaFunc_s _name##_LuaFunc_s( #_name, _name##_luaFunc, _proto, _doc ); \
  710. static int _name##_luaFunc( lua_State *pLuaState )
  711. //=============================================================================
  712. //
  713. //=============================================================================
  714. class CDmxEditLua
  715. {
  716. public:
  717. CDmxEditLua();
  718. bool DoIt( const char *pFilename );
  719. void SetVar( const CUtlString &var, const CUtlString &val );
  720. void SetGame( const CUtlString &game );
  721. static int FileExists( lua_State *pLuaState );
  722. protected:
  723. lua_State *m_pLuaState;
  724. };
  725. //=============================================================================
  726. //
  727. //=============================================================================
  728. class CDmxEditProxy
  729. {
  730. public:
  731. CDmxEditProxy( CDmxEdit &dmxEdit )
  732. : m_dmxEdit( dmxEdit )
  733. {}
  734. CDmxEditProxy &operator=( const char *pFilename ) { m_dmxEdit.Load( pFilename ); return *this; }
  735. operator bool() const { m_dmxEdit; }
  736. protected:
  737. CDmxEdit &m_dmxEdit;
  738. };
  739. #endif // DMXEDIT_H