34 #include <QMutexLocker> 51 BulletDskShape::BulletDskShape() : m_mesh() { }
71 for (
int i = 0; i < m_mesh->getIndexedMeshArray().size(); i++) {
72 btIndexedMesh &v_mesh = m_mesh->getIndexedMeshArray()[i];
73 delete[] v_mesh.m_triangleIndexBase;
74 v_mesh.m_triangleIndexBase =
nullptr;
75 delete[] v_mesh.m_vertexBase;
76 v_mesh.m_vertexBase =
nullptr;
88 size_t num_triangles = 0;
91 for(
int i = 0; i < m_mesh->getIndexedMeshArray().size(); i++) {
92 num_triangles += m_mesh->getIndexedMeshArray()[i].m_numTriangles;
106 size_t num_vertices = 0;
109 for(
int i = 0; i < m_mesh->getIndexedMeshArray().size(); i++) {
110 num_vertices += m_mesh->getIndexedMeshArray()[i].m_numVertices;
131 btMatrix3x3 triangle =
getTriangle(indexId, segment);
132 btVector3 edge1 = triangle.getRow(1) - triangle.getRow(0);
133 btVector3 edge2 = triangle.getRow(2) - triangle.getRow(0);
134 return ( edge1.cross( edge2 ) );
148 btAssert ( index >= 0 );
149 btAssert ( index < getIndexedMeshArray()[segment].m_numTriangles );
151 btAssert ( segment >= 0 );
152 btAssert ( segment < getIndexedMeshArray().size());
155 const btIndexedMesh &v_mesh = m_mesh->getIndexedMeshArray()[segment];
157 const int *t_index =
static_cast<int32_t *
> ((
void *) v_mesh.m_triangleIndexBase);
158 int p_index = 3 * index;
159 int vndx0 = t_index[p_index];
160 int vndx1 = t_index[p_index+1];
161 int vndx2 = t_index[p_index+2];
163 const btScalar *t_vertex =
static_cast<const btScalar *
> ((
void *) v_mesh.m_vertexBase);
165 btMatrix3x3 triangle(t_vertex[vndx0+0], t_vertex[vndx0+1], t_vertex[vndx0+2],
166 t_vertex[vndx1+0], t_vertex[vndx1+1], t_vertex[vndx1+2],
167 t_vertex[vndx2+0], t_vertex[vndx2+1], t_vertex[vndx2+2]);
187 QString mess =
"NAIF DSK file [" + dskfile +
"] does not exist.";
192 dasopr_c( dskFile.
expanded().toLatin1().data(), &handle );
197 SpiceDLADescr segment;
198 dlabfs_c( handle, &segment, &found );
201 QString mess =
"No segments found in DSK file " + dskfile ;
205 std::vector<SpiceDLADescr> segments;
206 segments.push_back(segment);
210 dlafns_c(handle, &segments.back(), &segment, &found);
213 segments.push_back(segment);
220 m_mesh.reset(
new btTriangleIndexVertexArray());
222 for (
size_t i = 0; i < segments.size(); i++) {
226 btIndexedMesh i_mesh;
229 dskz02_c( handle, &segments[i], &nvertices, &nplates);
232 m_mesh->addIndexedMesh(i_mesh, PHY_INTEGER);
235 btIndexedMesh &v_mesh = m_mesh->getIndexedMeshArray()[i];
236 v_mesh.m_vertexType = PHY_DOUBLE;
239 v_mesh.m_numTriangles = nplates;
240 v_mesh.m_triangleIndexBase =
new unsigned char[nplates * 3 *
sizeof(int)];
241 v_mesh.m_triangleIndexStride = (
sizeof(int) * 3);
244 v_mesh.m_numVertices = nvertices;
245 v_mesh.m_vertexBase =
new unsigned char[nvertices * 3 *
sizeof(double)];
246 v_mesh.m_vertexStride = (
sizeof(double) * 3);
249 (void) dskv02_c(handle, &segments[i], 1, nvertices, &n,
250 ( SpiceDouble(*)[3] ) (v_mesh.m_vertexBase));
254 (void) dskp02_c(handle, &segments[i], 1, nplates, &n,
255 ( SpiceInt(*)[3] ) (v_mesh.m_triangleIndexBase));
259 int *pindex =
static_cast<int *
> ((
void *) v_mesh.m_triangleIndexBase);
260 int nverts = nplates * 3;
261 for (
int i = 0 ; i < nverts ; i++) {
263 btAssert ( pindex[i] >= 0 );
264 btAssert ( pindex[i] < nvertices );
271 bool useQuantizedAabbCompression =
true;
273 btBvhTriangleMeshShape *v_triShape =
new btBvhTriangleMeshShape(m_mesh.data(),
274 useQuantizedAabbCompression);
275 v_triShape->setUserPointer(
this);
276 btCollisionObject *vbody =
new btCollisionObject();
277 vbody->setCollisionShape(v_triShape);
File name manipulation and expansion.
virtual btVector3 getNormal(const int indexId, const int segment=0) const
Return normal for a given triangle index.
Namespace for the standard library.
void setMaximumDistance()
Calculate and save the maximum distance across the body.
void setTargetBody(btCollisionObject *body)
Set the Bullet shape object to this object instance.
virtual btMatrix3x3 getTriangle(const int index, const int segment=0) const
Get the vertices of a triangle in the mesh.
#define _FILEINFO_
Macro for the filename and line number.
A type of error that could only have occurred due to a mistake on the user's part (e...
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
int getNumTriangles() const
Return the number of triangles in the shape.
Namespace for ISIS/Bullet specific routines.
BulletDskShape()
Default empty constructor.
virtual ~BulletDskShape()
Desctructor.
bool fileExists() const
Returns true if the file exists; false otherwise.
int getNumVertices() const
Return the number of verticies in the shape.
void loadFromDsk(const QString &dskfile)
! Triangular mesh representation of the target shape.