8 #include "BulletDskShape.h"
15 #include "NaifDskApi.h"
17 #include <QMutexLocker>
21 #include "IException.h"
24 #include "NaifDskPlateModel.h"
25 #include "NaifStatus.h"
34 BulletDskShape::BulletDskShape() : m_mesh() { }
54 for (
int i = 0; i < m_mesh->getIndexedMeshArray().size(); i++) {
55 btIndexedMesh &v_mesh = m_mesh->getIndexedMeshArray()[i];
56 delete[] v_mesh.m_triangleIndexBase;
57 v_mesh.m_triangleIndexBase =
nullptr;
58 delete[] v_mesh.m_vertexBase;
59 v_mesh.m_vertexBase =
nullptr;
71 size_t num_triangles = 0;
74 for(
int i = 0; i < m_mesh->getIndexedMeshArray().size(); i++) {
75 num_triangles += m_mesh->getIndexedMeshArray()[i].m_numTriangles;
89 size_t num_vertices = 0;
92 for(
int i = 0; i < m_mesh->getIndexedMeshArray().size(); i++) {
93 num_vertices += m_mesh->getIndexedMeshArray()[i].m_numVertices;
114 btMatrix3x3 triangle =
getTriangle(indexId, segment);
115 btVector3 edge1 = triangle.getRow(1) - triangle.getRow(0);
116 btVector3 edge2 = triangle.getRow(2) - triangle.getRow(0);
117 return ( edge1.cross( edge2 ) );
131 btAssert ( index >= 0 );
132 btAssert ( index < getIndexedMeshArray()[segment].m_numTriangles );
134 btAssert ( segment >= 0 );
135 btAssert ( segment < getIndexedMeshArray().size());
138 const btIndexedMesh &v_mesh = m_mesh->getIndexedMeshArray()[segment];
140 const int *t_index =
static_cast<int32_t *
> ((
void *) v_mesh.m_triangleIndexBase);
141 int p_index = 3 * index;
142 int vndx0 = t_index[p_index];
143 int vndx1 = t_index[p_index+1];
144 int vndx2 = t_index[p_index+2];
146 const btScalar *t_vertex =
static_cast<const btScalar *
> ((
void *) v_mesh.m_vertexBase);
148 btMatrix3x3 triangle(t_vertex[vndx0+0], t_vertex[vndx0+1], t_vertex[vndx0+2],
149 t_vertex[vndx1+0], t_vertex[vndx1+1], t_vertex[vndx1+2],
150 t_vertex[vndx2+0], t_vertex[vndx2+1], t_vertex[vndx2+2]);
170 QString mess =
"NAIF DSK file [" + dskfile +
"] does not exist.";
175 dasopr_c( dskFile.
expanded().toLatin1().data(), &handle );
180 SpiceDLADescr segment;
181 dlabfs_c( handle, &segment, &found );
184 QString mess =
"No segments found in DSK file " + dskfile ;
188 std::vector<SpiceDLADescr> segments;
189 segments.push_back(segment);
193 dlafns_c(handle, &segments.back(), &segment, &found);
196 segments.push_back(segment);
203 m_mesh.reset(
new btTriangleIndexVertexArray());
205 for (
size_t i = 0; i < segments.size(); i++) {
209 btIndexedMesh i_mesh;
212 dskz02_c( handle, &segments[i], &nvertices, &nplates);
215 m_mesh->addIndexedMesh(i_mesh, PHY_INTEGER);
218 btIndexedMesh &v_mesh = m_mesh->getIndexedMeshArray()[i];
219 v_mesh.m_vertexType = PHY_DOUBLE;
222 v_mesh.m_numTriangles = nplates;
223 v_mesh.m_triangleIndexBase =
new unsigned char[nplates * 3 *
sizeof(int)];
224 v_mesh.m_triangleIndexStride = (
sizeof(int) * 3);
227 v_mesh.m_numVertices = nvertices;
228 v_mesh.m_vertexBase =
new unsigned char[nvertices * 3 *
sizeof(double)];
229 v_mesh.m_vertexStride = (
sizeof(double) * 3);
232 (void) dskv02_c(handle, &segments[i], 1, nvertices, &n,
233 ( SpiceDouble(*)[3] ) (v_mesh.m_vertexBase));
237 (void) dskp02_c(handle, &segments[i], 1, nplates, &n,
238 ( SpiceInt(*)[3] ) (v_mesh.m_triangleIndexBase));
242 int *pindex =
static_cast<int *
> ((
void *) v_mesh.m_triangleIndexBase);
243 int nverts = nplates * 3;
244 for (
int i = 0 ; i < nverts ; i++) {
246 btAssert ( pindex[i] >= 0 );
247 btAssert ( pindex[i] < nvertices );
254 bool useQuantizedAabbCompression =
true;
256 btBvhTriangleMeshShape *v_triShape =
new btBvhTriangleMeshShape(m_mesh.data(),
257 useQuantizedAabbCompression);
258 v_triShape->setUserPointer(
this);
259 btCollisionObject *vbody =
new btCollisionObject();
260 vbody->setCollisionShape(v_triShape);