62 sphereGeometry->clear();
67 sphereGeometry->setStride(32);
69 sphereGeometry->setBounds(
QVector3D(-radius, -radius, -radius),
74 const int circleSegments = 24;
75 constexpr double TAU = 2 *
M_PI;
76 const float step = float(TAU / circleSegments);
77 QVector<QVector2D> circlePoints;
78 for (
float theta = 0; theta < TAU; theta += step) {
79 const float x = radius *
qCos(theta);
80 const float y = radius *
qSin(theta);
86 for (
int i = 0;
i < circlePoints.count(); ++
i) {
87 const auto refPoint1 = circlePoints[
i];
89 if (index2 == circlePoints.count())
91 const auto refPoint2 = circlePoints[index2];
92 const auto vertex1 =
QVector3D(0.0f, refPoint1.x(), refPoint1.y());
93 const auto vertex2 =
QVector3D(0.0f, refPoint2.x(), refPoint2.y());
98 for (
int i = 0;
i < circlePoints.count(); ++
i) {
99 const auto refPoint1 = circlePoints[
i];
101 if (index2 == circlePoints.count())
103 const auto refPoint2 = circlePoints[index2];
104 const auto vertex1 =
QVector3D(refPoint1.x(), 0.0f, refPoint1.y());
105 const auto vertex2 =
QVector3D(refPoint2.x(), 0.0f, refPoint2.y());
110 for (
int i = 0;
i < circlePoints.count(); ++
i) {
111 const auto refPoint1 = circlePoints[
i];
113 if (index2 == circlePoints.count())
115 const auto refPoint2 = circlePoints[index2];
116 const auto vertex1 =
QVector3D(refPoint1.x(), refPoint1.y(), 0.0f);
117 const auto vertex2 =
QVector3D(refPoint2.x(), refPoint2.y(), 0.0f);
122 return sphereGeometry;
126 const float halfHeight)
129 capsuleGeometry->clear();
134 capsuleGeometry->setStride(32);
136 capsuleGeometry->setBounds(
QVector3D(-(halfHeight + radius), -radius, -radius),
137 QVector3D(halfHeight + radius, radius, radius));
143 const int circleSegments = 32;
144 constexpr double TAU = 2 *
M_PI;
147 const float step = float(TAU / circleSegments);
148 QVector<QVector2D> circlePoints;
149 for (
float theta = 0; theta < TAU; theta += step) {
150 const float x = radius *
qCos(theta);
151 const float y = radius *
qSin(theta);
158 for (
int i = 0;
i < circlePoints.count(); ++
i) {
159 const auto refPoint1 = circlePoints[
i];
161 if (index2 == circlePoints.count())
163 const auto refPoint2 = circlePoints[index2];
164 const auto vertex1 =
QVector3D(halfHeight, refPoint1.x(), refPoint1.y());
165 const auto vertex2 =
QVector3D(halfHeight, refPoint2.x(), refPoint2.y());
167 builder.
addLine(vertex1, vertex2, normal);
171 for (
int i = 0;
i < circlePoints.count(); ++
i) {
172 const auto refPoint1 = circlePoints[
i];
174 if (index2 == circlePoints.count())
176 const auto refPoint2 = circlePoints[index2];
177 const auto vertex1 =
QVector3D(-halfHeight, refPoint1.x(), refPoint1.y());
178 const auto vertex2 =
QVector3D(-halfHeight, refPoint2.x(), refPoint2.y());
180 builder.
addLine(vertex1, vertex2, normal);
185 const auto vertex1 =
QVector3D(halfHeight, 0, radius);
186 const auto vertex2 =
QVector3D(-halfHeight, 0, radius);
188 builder.
addLine(vertex1, vertex2, normal);
193 const auto vertex1 =
QVector3D(halfHeight, 0, -radius);
194 const auto vertex2 =
QVector3D(-halfHeight, 0, -radius);
196 builder.
addLine(vertex1, vertex2, normal);
201 const auto vertex1 =
QVector3D(halfHeight, -radius, 0);
202 const auto vertex2 =
QVector3D(-halfHeight, -radius, 0);
204 builder.
addLine(vertex1, vertex2, normal);
209 const auto vertex1 =
QVector3D(halfHeight, radius, 0);
210 const auto vertex2 =
QVector3D(-halfHeight, radius, 0);
212 builder.
addLine(vertex1, vertex2, normal);
216 QVector<int> topIndexes;
217 QVector<int> bottomIndexes;
219 const int half = circlePoints.count() / 2;
220 for (
int i = 0;
i < half + 1; ++
i)
221 topIndexes.append(
i);
223 for (
int i = half;
i <= circlePoints.count(); ++
i) {
225 if (
i >= circlePoints.count())
227 bottomIndexes.append(
index);
232 for (
int i = 0;
i < topIndexes.count(); ++
i) {
233 const auto refPoint1 = circlePoints[topIndexes[
i]];
235 if (index2 == topIndexes.count())
237 const auto refPoint2 = circlePoints[topIndexes[index2]];
238 const auto vertex1 =
QVector3D(refPoint1.y() + halfHeight, refPoint1.x(), 0.0f);
239 const auto vertex2 =
QVector3D(refPoint2.y() + halfHeight, refPoint2.x(), 0.0f);
241 builder.
addLine(vertex1, vertex2, normal);
245 for (
int i = 0;
i < bottomIndexes.count(); ++
i) {
246 const auto refPoint1 = circlePoints[bottomIndexes[
i]];
248 if (index2 == bottomIndexes.count())
250 const auto refPoint2 = circlePoints[bottomIndexes[index2]];
251 const auto vertex1 =
QVector3D(refPoint1.y() - halfHeight, refPoint1.x(), 0.0f);
252 const auto vertex2 =
QVector3D(refPoint2.y() - halfHeight, refPoint2.x(), 0.0f);
254 builder.
addLine(vertex1, vertex2, normal);
258 for (
int i = 0;
i < topIndexes.count(); ++
i) {
259 const auto refPoint1 = circlePoints[topIndexes[
i]];
261 if (index2 == topIndexes.count())
263 const auto refPoint2 = circlePoints[topIndexes[index2]];
264 const auto vertex1 =
QVector3D(refPoint1.y() + halfHeight, 0.0f, refPoint1.x());
265 const auto vertex2 =
QVector3D(refPoint2.y() + halfHeight, 0.0f, refPoint2.x());
267 builder.
addLine(vertex1, vertex2, normal);
271 for (
int i = 0;
i < bottomIndexes.count(); ++
i) {
272 const auto refPoint1 = circlePoints[bottomIndexes[
i]];
274 if (index2 == bottomIndexes.count())
276 const auto refPoint2 = circlePoints[bottomIndexes[index2]];
277 const auto vertex1 =
QVector3D(refPoint1.y() - halfHeight, 0.0f, refPoint1.x());
278 const auto vertex2 =
QVector3D(refPoint2.y() - halfHeight, 0.0f, refPoint2.x());
280 builder.
addLine(vertex1, vertex2, normal);
284 return capsuleGeometry;
436 geometry->setStride(32);
441 const physx::PxU32 triangleCount = triangleMesh->getNbTriangles();
442 const physx::PxU32 has16BitIndices =
443 triangleMesh->getTriangleMeshFlags() & physx::PxTriangleMeshFlag::e16_BIT_INDICES;
444 const void *indexBuffer = triangleMesh->getTriangles();
445 const physx::PxVec3 *vertexBuffer = triangleMesh->getVertices();
446 const physx::PxU32 *intIndices =
reinterpret_cast<const physx::PxU32 *
>(indexBuffer);
447 const physx::PxU16 *shortIndices =
reinterpret_cast<const physx::PxU16 *
>(indexBuffer);
448 for (physx::PxU32
i = 0;
i < triangleCount; ++
i) {
449 physx::PxVec3 triVert[3];
451 if (has16BitIndices) {
452 triVert[0] = vertexBuffer[*shortIndices++];
453 triVert[1] = vertexBuffer[*shortIndices++];
454 triVert[2] = vertexBuffer[*shortIndices++];
456 triVert[0] = vertexBuffer[*intIndices++];
457 triVert[1] = vertexBuffer[*intIndices++];
458 triVert[2] = vertexBuffer[*intIndices++];
470 auto bounds = triangleMesh->getLocalBounds();