Counter Strike : Global Offensive Source Code
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.

219 lines
3.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "vbsp.h"
  9. int c_glfaces;
  10. int PortalVisibleSides (portal_t *p)
  11. {
  12. int fcon, bcon;
  13. if (!p->onnode)
  14. return 0; // outside
  15. fcon = p->nodes[0]->contents;
  16. bcon = p->nodes[1]->contents;
  17. // same contents never create a face
  18. if (fcon == bcon)
  19. return 0;
  20. // FIXME: is this correct now?
  21. if (!fcon)
  22. return 1;
  23. if (!bcon)
  24. return 2;
  25. return 0;
  26. }
  27. void OutputWinding (winding_t *w, FileHandle_t glview)
  28. {
  29. static int level = 128;
  30. vec_t light;
  31. int i;
  32. CmdLib_FPrintf( glview, "%i\n", w->numpoints);
  33. level+=28;
  34. light = (level&255)/255.0;
  35. for (i=0 ; i<w->numpoints ; i++)
  36. {
  37. CmdLib_FPrintf(glview, "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
  38. w->p[i][0],
  39. w->p[i][1],
  40. w->p[i][2],
  41. light,
  42. light,
  43. light);
  44. }
  45. //CmdLib_FPrintf(glview, "\n");
  46. }
  47. void OutputWindingColor (winding_t *w, FileHandle_t glview, int r, int g, int b)
  48. {
  49. int i;
  50. CmdLib_FPrintf( glview, "%i\n", w->numpoints);
  51. float lr = r * (1.0f/255.0f);
  52. float lg = g * (1.0f/255.0f);
  53. float lb = b * (1.0f/255.0f);
  54. for (i=0 ; i<w->numpoints ; i++)
  55. {
  56. CmdLib_FPrintf(glview, "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
  57. w->p[i][0],
  58. w->p[i][1],
  59. w->p[i][2],
  60. lr,
  61. lg,
  62. lb);
  63. }
  64. //CmdLib_FPrintf(glview, "\n");
  65. }
  66. /*
  67. =============
  68. OutputPortal
  69. =============
  70. */
  71. void OutputPortal (portal_t *p, FileHandle_t glview)
  72. {
  73. winding_t *w;
  74. int sides;
  75. sides = PortalVisibleSides (p);
  76. if (!sides)
  77. return;
  78. c_glfaces++;
  79. w = p->winding;
  80. if (sides == 2) // back side
  81. w = ReverseWinding (w);
  82. OutputWinding (w, glview);
  83. if (sides == 2)
  84. FreeWinding(w);
  85. }
  86. /*
  87. =============
  88. WriteGLView_r
  89. =============
  90. */
  91. void WriteGLView_r (node_t *node, FileHandle_t glview)
  92. {
  93. portal_t *p, *nextp;
  94. if (node->planenum != PLANENUM_LEAF)
  95. {
  96. WriteGLView_r (node->children[0], glview);
  97. WriteGLView_r (node->children[1], glview);
  98. return;
  99. }
  100. // write all the portals
  101. for (p=node->portals ; p ; p=nextp)
  102. {
  103. if (p->nodes[0] == node)
  104. {
  105. OutputPortal (p, glview);
  106. nextp = p->next[0];
  107. }
  108. else
  109. nextp = p->next[1];
  110. }
  111. }
  112. void WriteGLViewFaces_r( node_t *node, FileHandle_t glview )
  113. {
  114. portal_t *p, *nextp;
  115. if (node->planenum != PLANENUM_LEAF)
  116. {
  117. WriteGLViewFaces_r (node->children[0], glview);
  118. WriteGLViewFaces_r (node->children[1], glview);
  119. return;
  120. }
  121. // write all the portals
  122. for (p=node->portals ; p ; p=nextp)
  123. {
  124. int s = (p->nodes[1] == node);
  125. if ( p->face[s] )
  126. {
  127. OutputWinding( p->face[s]->w, glview );
  128. }
  129. nextp = p->next[s];
  130. }
  131. }
  132. /*
  133. =============
  134. WriteGLView
  135. =============
  136. */
  137. void WriteGLView (tree_t *tree, char *source)
  138. {
  139. char name[1024];
  140. FileHandle_t glview;
  141. c_glfaces = 0;
  142. sprintf (name, "%s%s.gl",outbase, source);
  143. Msg("Writing %s\n", name);
  144. glview = g_pFileSystem->Open( name, "w" );
  145. if (!glview)
  146. Error ("Couldn't open %s", name);
  147. WriteGLView_r (tree->headnode, glview);
  148. g_pFileSystem->Close( glview );
  149. Msg("%5i c_glfaces\n", c_glfaces);
  150. }
  151. void WriteGLViewFaces( tree_t *tree, const char *pName )
  152. {
  153. char name[1024];
  154. FileHandle_t glview;
  155. c_glfaces = 0;
  156. sprintf (name, "%s%s.gl", outbase, pName);
  157. Msg("Writing %s\n", name);
  158. glview = g_pFileSystem->Open( name, "w" );
  159. if (!glview)
  160. Error ("Couldn't open %s", name);
  161. WriteGLViewFaces_r (tree->headnode, glview);
  162. g_pFileSystem->Close( glview );
  163. Msg("%5i c_glfaces\n", c_glfaces);
  164. }
  165. void WriteGLViewBrushList( bspbrush_t *pList, const char *pName )
  166. {
  167. char name[1024];
  168. FileHandle_t glview;
  169. sprintf (name, "%s%s.gl", outbase, pName );
  170. Msg("Writing %s\n", name);
  171. glview = g_pFileSystem->Open( name, "w" );
  172. if (!glview)
  173. Error ("Couldn't open %s", name);
  174. for ( bspbrush_t *pBrush = pList; pBrush; pBrush = pBrush->next )
  175. {
  176. for (int i = 0; i < pBrush->numsides; i++ )
  177. OutputWinding( pBrush->sides[i].winding, glview );
  178. }
  179. g_pFileSystem->Close( glview );
  180. }