SnapPoints.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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 : Max2W3d *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/SnapPoints.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 11/23/98 11:05a $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #include "SnapPoints.h"
  39. #include "chunkio.h"
  40. #include "Max.h"
  41. #include "nodelist.h"
  42. #include "w3d_file.h"
  43. class PointFilterClass : public INodeFilterClass
  44. {
  45. public:
  46. PointFilterClass(void) { }
  47. virtual BOOL Accept_Node(INode * node, TimeValue time)
  48. {
  49. if (node == NULL) return FALSE;
  50. Object * obj = node->EvalWorldState(time).obj;
  51. if (obj == NULL) return FALSE;
  52. if
  53. (
  54. obj->ClassID() == Class_ID(POINTHELP_CLASS_ID,0) &&
  55. !node->IsHidden()
  56. )
  57. {
  58. return TRUE;
  59. } else {
  60. return FALSE;
  61. }
  62. }
  63. };
  64. void SnapPointsClass::Export_Points(INode * scene_root,TimeValue time,ChunkSaveClass & csave)
  65. {
  66. if (scene_root == NULL) return;
  67. PointFilterClass pointfilter;
  68. INodeListClass pointlist(scene_root,time,&pointfilter);
  69. if (pointlist.Num_Nodes() > 0) {
  70. csave.Begin_Chunk(W3D_CHUNK_POINTS);
  71. for (unsigned int ci=0; ci<pointlist.Num_Nodes(); ci++) {
  72. W3dVectorStruct vect;
  73. Point3 pos = pointlist[ci]->GetNodeTM(time).GetTrans();
  74. vect.X = pos.x;
  75. vect.Y = pos.y;
  76. vect.Z = pos.z;
  77. csave.Write(&vect,sizeof(vect));
  78. }
  79. csave.End_Chunk();
  80. }
  81. }