19#ifndef HEADER_TRIANGLE_MESH_HPP
20#define HEADER_TRIANGLE_MESH_HPP
23#include "btBulletDynamicsCommon.h"
25#include "physics/user_pointer.hpp"
26#include "utils/aligned_array.hpp"
38 std::vector<const Material*> m_triangleIndex2Material;
43 btCollisionObject *m_collision_object;
44 btTriangleMesh m_mesh;
45 btVector3 dummy1, dummy2;
46 btDefaultMotionState *m_motion_state;
47 btCollisionShape *m_collision_shape;
66 const btRigidBody::btRigidBodyConstructionInfo &ci)
75 void addTriangle(
const btVector3 &t1,
const btVector3 &t2,
76 const btVector3 &t3,
const btVector3 &n1,
77 const btVector3 &n2,
const btVector3 &n3,
81 btCollisionObject::CollisionFlags flags=
82 (btCollisionObject::CollisionFlags)0,
83 const char* serializedBhv = NULL);
85 void removeCollisionObject();
87 const btVector3 &position)
const;
102 const btRigidBody *getBody()
const {
return m_body; }
104 const Material* getMaterial(
int n)
const
105 {
return m_triangleIndex2Material[n];}
107 const btCollisionShape &getCollisionShape()
const
108 {
return *m_collision_shape; }
110 btCollisionShape &getCollisionShape() {
return *m_collision_shape; }
112 bool castRay(
const btVector3 &from,
const btVector3 &to,
113 btVector3 *xyz,
const Material **material,
114 btVector3 *normal=NULL,
bool interpolate_normal=
false)
const;
122 const IndexedMeshArray &m = m_mesh.getIndexedMeshArray();
123 btVector3 *p = &(((btVector3*)(m[0].m_vertexBase))[3*indx]);
133 btVector3 *n2, btVector3 *n3)
const
135 assert(indx < m_triangleIndex2Material.size());
136 unsigned int n = indx*3;
152 for (
int i = 0; i < tm.m_mesh.getNumTriangles(); i++)
157 const Material* m = tm.getMaterial(i);
158 addTriangle(v[0], v[1], v[2], v[3], v[4], v[5], m);
Definition: material.hpp:48
Definition: triangle_mesh.hpp:62
A special class to store a triangle mesh with a separate material per triangle.
Definition: triangle_mesh.hpp:35
void getNormals(unsigned int indx, btVector3 *n1, btVector3 *n2, btVector3 *n3) const
Returns the normals of the triangle with the given index.
Definition: triangle_mesh.hpp:132
bool castRay(const btVector3 &from, const btVector3 &to, btVector3 *xyz, const Material **material, btVector3 *normal=NULL, bool interpolate_normal=false) const
Casts a ray from 'from' to 'to'.
Definition: triangle_mesh.cpp:321
bool m_can_be_transformed
If the rigid body can be transformed (which means that normalising the normals need to update the ver...
Definition: triangle_mesh.hpp:58
bool m_free_body
Keep track if the physical body was created here or not.
Definition: triangle_mesh.hpp:41
AlignedArray< float > m_p1p2p3
Pre-compute value used in smoothing.
Definition: triangle_mesh.hpp:53
void createCollisionShape(bool create_collision_object=true, const char *serialized_bhv=NULL)
Creates a collision body only, which can be used for raycasting, but has no physical properties.
Definition: triangle_mesh.cpp:96
void removeAll()
Removes the created body and/or collision object from the physics world.
Definition: triangle_mesh.cpp:218
void addTriangle(const btVector3 &t1, const btVector3 &t2, const btVector3 &t3, const btVector3 &n1, const btVector3 &n2, const btVector3 &n3, const Material *m)
Adds a triangle to the bullet mesh.
Definition: triangle_mesh.cpp:66
AlignedArray< btVector3 > m_normals
The three normals for each triangle.
Definition: triangle_mesh.hpp:50
void createPhysicalBody(float friction, btCollisionObject::CollisionFlags flags=(btCollisionObject::CollisionFlags) 0, const char *serializedBhv=NULL)
Creates the physics body for this triangle mesh.
Definition: triangle_mesh.cpp:185
~TriangleMesh()
Destructor: delete all allocated data structures.
Definition: triangle_mesh.cpp:54
btVector3 getInterpolatedNormal(unsigned int index, const btVector3 &position) const
Interpolates the normal at the given position for the triangle with a given index.
Definition: triangle_mesh.cpp:244
void setBody(btRigidBody *body)
In case of physical objects of shape 'exact', the physical body is created outside of the mesh.
Definition: triangle_mesh.hpp:94
void getTriangle(unsigned int indx, btVector3 *p1, btVector3 *p2, btVector3 *p3) const
Returns the points of the 'indx' triangle.
Definition: triangle_mesh.hpp:119
float getP1P2P3(unsigned int indx) const
Returns basically the area of the triangle, which is needed when smoothing the normals.
Definition: triangle_mesh.hpp:144
A UserPointer is stored as a user pointer in all bullet bodies.
Definition: user_pointer.hpp:36