-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestHACD.cpp
144 lines (118 loc) · 3.47 KB
/
TestHACD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "TestHACD.h"
#include "NvRenderDebug.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
class TestHACDImpl : public TestHACD, public VHACD::IVHACD::IUserCallback, public VHACD::IVHACD::IUserLogger
{
public:
TestHACDImpl(void)
{
mHACD = VHACD::CreateVHACD_ASYNC();
}
virtual ~TestHACDImpl(void)
{
mHACD->Release();
}
void getExplodePosition(const double source[3], float dest[3], const double diff[3],const float center[3])
{
dest[0] = float(source[0] + diff[0] + center[0]);
dest[1] = float(source[1] + diff[1] + center[1]);
dest[2] = float(source[2] + diff[2] + center[2]);
}
virtual void render(RENDER_DEBUG::RenderDebug *renderDebug, float explodeViewScale,const float center[3]) final
{
uint32_t hullCount = mHACD->GetNConvexHulls();
if (hullCount)
{
for (uint32_t j = 0; j < hullCount; j++)
{
VHACD::IVHACD::ConvexHull h;
mHACD->GetConvexHull(j, h);
{
renderDebug->pushRenderState();
uint32_t cindex = (j % 20) + RENDER_DEBUG::DebugColors::Red;
uint32_t color = renderDebug->getDebugColor((RENDER_DEBUG::DebugColors::Enum)cindex);
renderDebug->setCurrentColor(color,0xFFFFFF);
double diff[3];
diff[0] = h.m_center[0] - center[0];
diff[1] = h.m_center[1] - center[1];
diff[2] = h.m_center[2] - center[2];
diff[0] *= explodeViewScale;
diff[1] *= explodeViewScale;
diff[2] *= explodeViewScale;
diff[0] -= h.m_center[0];
diff[1] -= h.m_center[1];
diff[2] -= h.m_center[2];
for (uint32_t i = 0; i < h.m_nTriangles; i++)
{
uint32_t i1 = h.m_triangles[i * 3 + 0];
uint32_t i2 = h.m_triangles[i * 3 + 1];
uint32_t i3 = h.m_triangles[i * 3 + 2];
const double *p1 = &h.m_points[i1 * 3];
const double *p2 = &h.m_points[i2 * 3];
const double *p3 = &h.m_points[i3 * 3];
float v1[3];
float v2[3];
float v3[3];
getExplodePosition(p1, v1, diff, center);
getExplodePosition(p2, v2, diff, center);
getExplodePosition(p3, v3, diff, center);
renderDebug->debugTri(v1, v2, v3);
}
renderDebug->popRenderState();
}
}
}
}
virtual void decompose(
const double* const points,
const unsigned int countPoints,
const int* const triangles,
const unsigned int countTriangles,
VHACD::IVHACD::Parameters &desc)
{
desc.m_callback = this;
mHACD->Compute(points, 3, countPoints, triangles, 3, countTriangles, desc);
uint32_t hullCount = mHACD->GetNConvexHulls();
printf("Produced: %d convex hulls.\n", hullCount );
}
virtual void release(void)
{
delete this;
}
virtual void Update(const double overallProgress,
const double stageProgress,
const double operationProgress,
const char* const stage,
const char* const operation) final
{
printf("%s : %s : %0.2f : %0.2f : %0.2f\n", stage, operation, overallProgress, stageProgress, operationProgress);
}
virtual void Log(const char* const msg) final
{
printf("VHACD:%s\n", msg);
}
virtual bool Cancelled() final
{
printf("HACD::Cancelled\n");
return false;
}
virtual uint32_t getHullCount(void) const final
{
return mHACD ? mHACD->GetNConvexHulls() : 0;
}
virtual void cancel(void)
{
if (mHACD)
{
mHACD->Cancel();
}
}
VHACD::IVHACD *mHACD;
};
TestHACD *TestHACD::create(void)
{
TestHACDImpl *t = new TestHACDImpl;
return static_cast<TestHACD *>(t);
}