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.

100 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include "studio.h"
  10. int g_NumBonesInLOD[MAX_NUM_LODS];
  11. void Usage( void )
  12. {
  13. fprintf( stderr, "Usage: printbones blah.mdl\n" );
  14. exit( -1 );
  15. }
  16. void PrintSpaces( int numSpaces )
  17. {
  18. int i;
  19. for( i = 0; i < numSpaces; i++ )
  20. {
  21. printf( " " );
  22. }
  23. }
  24. void PrintBoneGraphRecursive( studiohdr_t *phdr, int boneIndex, int level )
  25. {
  26. int j;
  27. PrintSpaces( level );
  28. printf( "%d \"%s\" ", boneIndex, phdr->pBone( boneIndex )->pszName() );
  29. int i;
  30. for( i = 0; i < 8; i++ )
  31. {
  32. if( phdr->pBone( boneIndex )->flags & ( BONE_USED_BY_VERTEX_LOD0 << i ) )
  33. {
  34. printf( "lod%d ", i );
  35. g_NumBonesInLOD[i]++;
  36. }
  37. }
  38. printf( "\n" );
  39. for( j = 0; j < phdr->numbones; j++ )
  40. {
  41. mstudiobone_t *pBone = phdr->pBone( j );
  42. if( pBone->parent == boneIndex )
  43. {
  44. PrintBoneGraphRecursive( phdr, j, level+1 );
  45. }
  46. }
  47. }
  48. int main( int argc, char **argv )
  49. {
  50. if( argc != 2 )
  51. {
  52. Usage();
  53. }
  54. memset( g_NumBonesInLOD, 0, sizeof( int ) * MAX_NUM_LODS );
  55. FILE *fp;
  56. fp = fopen( argv[1], "rb" );
  57. if( !fp )
  58. {
  59. fprintf( stderr, "Can't open: %s\n", argv[1] );
  60. Usage();
  61. }
  62. fseek( fp, 0, SEEK_END );
  63. int len = ftell( fp );
  64. rewind( fp );
  65. studiohdr_t *pStudioHdr = ( studiohdr_t * )malloc( len );
  66. fread( pStudioHdr, 1, len, fp );
  67. Studio_ConvertStudioHdrToNewVersion( pStudioHdr );
  68. if( pStudioHdr->version != STUDIO_VERSION )
  69. {
  70. fprintf( stderr, "Wrong version (%d != %d)\n", ( int )pStudioHdr->version, ( int )STUDIO_VERSION );
  71. Usage();
  72. }
  73. int i;
  74. for( i = 0; i < pStudioHdr->numbones; i++ )
  75. {
  76. mstudiobone_t *pBone = pStudioHdr->pBone( i );
  77. if( pBone->parent == -1 )
  78. {
  79. PrintBoneGraphRecursive( pStudioHdr, i, 0 );
  80. }
  81. }
  82. fclose( fp );
  83. for( i = 0; i < MAX_NUM_LODS; i++ )
  84. {
  85. printf( "%d bones used in lod %d\n", g_NumBonesInLOD[i], i );
  86. }
  87. return 0;
  88. }