Newton Dynamics  4.00
ndPolygonSoupBuilder.h
1 /* Copyright (c) <2003-2022> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 /****************************************************************************
23 *
24 * Visual C++ 6.0 created by: Julio Jerez
25 *
26 ****************************************************************************/
27 #ifndef __ND_POLYGONSOUP_BUILDER_H__
28 #define __ND_POLYGONSOUP_BUILDER_H__
29 
30 #include "ndCoreStdafx.h"
31 #include "ndTypes.h"
32 #include "ndPlane.h"
33 #include "ndArray.h"
34 #include "ndVector.h"
35 #include "ndMatrix.h"
36 
39 {
40  public:
41  ndPlane m_normal;
42  ndInt32 m_count;
43  ndInt32 *m_index;
44  ndInt64 m_edgeMap[256];
45 };
46 
48 {
49  class dgFaceMap;
50  class dgFaceInfo;
51  class dgFaceBucket;
53 
54  public:
55  D_CORE_API ndPolygonSoupBuilder ();
56  D_CORE_API ndPolygonSoupBuilder (const ndPolygonSoupBuilder& sopurce);
57  D_CORE_API virtual ~ndPolygonSoupBuilder ();
58 
59  D_CORE_API virtual void Begin();
60  D_CORE_API virtual void End(bool optimize);
61  D_CORE_API virtual void AddFace(const ndFloat32* const vertex, ndInt32 strideInBytes, ndInt32 vertexCount, const ndInt32 faceId);
62  D_CORE_API virtual void AddFaceIndirect(const ndFloat32* const vertex, ndInt32 strideInBytes, ndInt32 faceId, const ndInt32* const indexArray, ndInt32 indexCount);
63 
64  D_CORE_API void LoadPLY(const char* const fileName);
65  D_CORE_API void SavePLY(const char* const fileName) const;
66 
67  private:
68  void Optimize(ndInt32 faceId, const dgFaceBucket& faceBucket, const ndPolygonSoupBuilder& source);
69 
70  void Finalize();
71  void OptimizeByIndividualFaces();
72  void FinalizeAndOptimize(ndInt32 id);
73  ndInt32 FilterFace (ndInt32 count, ndInt32* const indexArray);
74  ndInt32 AddConvexFace (ndInt32 count, ndInt32* const indexArray, ndInt32* const facesArray);
75  void PackArray();
76 
77  public:
78  class ndVertexArray: public ndArray<ndBigVector>
79  {
80  public:
83  {
84  }
85 
86  ndVertexArray(ndInt32 count)
87  :ndArray<ndBigVector>(count)
88  {
89  }
90  };
91 
92  class ndIndexArray: public ndArray<ndInt32>
93  {
94  public:
95  ndIndexArray()
97  {
98  }
99 
100  ndIndexArray(ndInt32 count)
101  :ndArray<ndInt32>(count)
102  {
103  }
104  };
105 
106  ndIndexArray m_faceVertexCount;
107  ndIndexArray m_vertexIndex;
108  ndIndexArray m_normalIndex;
109  ndVertexArray m_vertexPoints;
110  ndVertexArray m_normalPoints;
111  ndInt32 m_run;
112 };
113 
114 #endif
115 
ndClassAlloc
Base class for providing memory allocation for all other engine classes.
Definition: ndClassAlloc.h:30
ndPolygonSoupBuilder::ndVertexArray
Definition: ndPolygonSoupBuilder.h:79
ndPolygonSoupBuilder::dgFaceMap
Definition: ndPolygonSoupBuilder.cpp:54
ndAdjacentFace
Helper intermediate class for encoding a face adjacent face to an edge of a face.
Definition: ndPolygonSoupBuilder.h:39
ndArray
Generic template vector.
Definition: ndArray.h:42
ndPolygonSoupBuilder::dgPolySoupFilterAllocator
Definition: ndPolygonSoupBuilder.cpp:85
ndPlane
Definition: ndPlane.h:35
ndPolygonSoupBuilder
Definition: ndPolygonSoupBuilder.h:48
ndPolygonSoupBuilder::dgFaceBucket
Definition: ndPolygonSoupBuilder.cpp:45
ndPolygonSoupBuilder::ndIndexArray
Definition: ndPolygonSoupBuilder.h:93
ndPolygonSoupBuilder::dgFaceInfo
Definition: ndPolygonSoupBuilder.cpp:38