PCToPS2Material.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. ** Command & Conquer Generals(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project name : Buccaneer Bay *
  23. * *
  24. * File name : PCToPS2Material.cpp *
  25. * *
  26. * Programmer : Mike Lytle *
  27. * *
  28. * Start date : 10/22/1999 *
  29. * *
  30. * Last update : 10/27/1999 *
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * PTPMC::BeginEditParams -- Change all W3D materials in the mesh to be PS2 compatible. *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #include <Max.h>
  37. #include <gport.h>
  38. #include <hsv.h>
  39. #include "dllmain.h"
  40. #include "resource.h"
  41. #include "util.h"
  42. #include "utilapi.h"
  43. #include "nodelist.h"
  44. #include "gamemtl.h"
  45. Class_ID PCToPS2MaterialClassID(0x40d11cee, 0x68881657);
  46. class PCToPS2MaterialClass : public UtilityObj {
  47. public:
  48. void BeginEditParams(Interface *ip,IUtil *iu);
  49. void EndEditParams(Interface *ip,IUtil *iu) {}
  50. void DeleteThis() {delete this;}
  51. };
  52. /***********************************************************************************************
  53. * PTPMC::BeginEditParams -- Change all W3D materials in the mesh to be PS2 compatible. *
  54. * *
  55. * *
  56. * *
  57. * *
  58. * HISTORY: *
  59. * 10/27/1999MLL: Created. *
  60. *=============================================================================================*/
  61. void PCToPS2MaterialClass::BeginEditParams(Interface *ip,IUtil *iu)
  62. {
  63. // This function is called when the utility is chosen.
  64. // Since we don't need any window gadgets, we'll just go through all the materials right away.
  65. INode *root = ip->GetRootNode();
  66. INodeListClass *meshlist = NULL;
  67. // Change all materials associated with the mesh, starting with the root node.
  68. if (root) {
  69. meshlist = new INodeListClass(root, 0);
  70. if (meshlist) {
  71. int i;
  72. for (i = 0; i < meshlist->Num_Nodes(); i++) {
  73. Mtl *nodemtl = ((*meshlist)[i])->GetMtl();
  74. if (nodemtl == NULL) {
  75. // No material on this node, go to the next.
  76. continue;
  77. }
  78. if (!nodemtl->IsMultiMtl()) {
  79. // Only change those that are W3D materials.
  80. if (nodemtl->ClassID() == GameMaterialClassID) {
  81. int pass;
  82. for (pass = 0; pass < ((GameMtl*)nodemtl)->Get_Pass_Count(); pass++) {
  83. // Change the material for each pass.
  84. ((GameMtl*)nodemtl)->Compute_PS2_Shader_From_PC_Shader(pass);
  85. }
  86. }
  87. } else {
  88. // Loop through all sub materials of the multi-material.
  89. for (unsigned mi = 0; mi < nodemtl->NumSubMtls(); mi++) {
  90. // Only change those that are W3D materials.
  91. if (nodemtl->GetSubMtl(mi)->ClassID() == GameMaterialClassID) {
  92. int pass;
  93. for (pass = 0; pass < ((GameMtl*)nodemtl->GetSubMtl(mi))->Get_Pass_Count(); pass++) {
  94. // Change the material for each pass.
  95. ((GameMtl*)nodemtl->GetSubMtl(mi))->Compute_PS2_Shader_From_PC_Shader(pass);
  96. }
  97. } else if (nodemtl->GetSubMtl(mi)->ClassID() == PS2GameMaterialClassID) {
  98. }
  99. }
  100. }
  101. }
  102. }
  103. delete meshlist;
  104. }
  105. }
  106. class PCToPS2MaterialClassDesc:public ClassDesc {
  107. public:
  108. int IsPublic() { return 1; }
  109. void * Create(BOOL loading)
  110. {
  111. return ((void*)new PCToPS2MaterialClass);
  112. }
  113. const TCHAR * ClassName() { return Get_String(IDS_PC_TO_PS2_MAT_CONVERTER); }
  114. SClass_ID SuperClassID() { return UTILITY_CLASS_ID; }
  115. Class_ID ClassID() { return PCToPS2MaterialClassID; }
  116. const TCHAR* Category() { return _T(""); }
  117. };
  118. static PCToPS2MaterialClassDesc _PCToPS2MaterialCD;
  119. ClassDesc * Get_PS2_Material_Conversion() { return &_PCToPS2MaterialCD; }