1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of EITHER: *
8 * (1) The GNU Lesser General Public License as published by the Free *
9 * Software Foundation; either version 2.1 of the License, or (at *
10 * your option) any later version. The text of the GNU Lesser *
11 * General Public License is included with this library in the *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
16 * This library is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
21 *************************************************************************/
24 * TriMesh code by Erwin de Vries.
27 * This is where the actual vertexdata (pointers), and BV tree is stored.
28 * Vertices should be single precision!
29 * This should be more sophisticated, so that the user can easyly implement
30 * another collision library, but this is a lot of work, and also costs some
31 * performance because some data has to be copied.
34 #ifndef _ODE_COLLISION_TRIMESH_H_
35 #define _ODE_COLLISION_TRIMESH_H_
42 * Data storage for triangle meshes.
45 typedef struct dxTriMeshData* dTriMeshDataID;
48 * These dont make much sense now, but they will later when we add more
51 ODE_API dTriMeshDataID dGeomTriMeshDataCreate(void);
52 ODE_API void dGeomTriMeshDataDestroy(dTriMeshDataID g);
56 enum { TRIMESH_FACE_NORMALS };
57 ODE_API void dGeomTriMeshDataSet(dTriMeshDataID g, int data_id, void* in_data);
58 ODE_API void* dGeomTriMeshDataGet(dTriMeshDataID g, int data_id);
63 * We need to set the last transform after each time step for
64 * accurate collision response. These functions get and set that transform.
65 * It is stored per geom instance, rather than per dTriMeshDataID.
67 ODE_API void dGeomTriMeshSetLastTransform( dGeomID g, dMatrix4 last_trans );
68 ODE_API dReal* dGeomTriMeshGetLastTransform( dGeomID g );
71 * Build a TriMesh data object with single precision vertex data.
73 ODE_API void dGeomTriMeshDataBuildSingle(dTriMeshDataID g,
74 const void* Vertices, int VertexStride, int VertexCount,
75 const void* Indices, int IndexCount, int TriStride);
76 /* same again with a normals array (used as trimesh-trimesh optimization) */
77 ODE_API void dGeomTriMeshDataBuildSingle1(dTriMeshDataID g,
78 const void* Vertices, int VertexStride, int VertexCount,
79 const void* Indices, int IndexCount, int TriStride,
82 * Build a TriMesh data object with double precision vertex data.
84 ODE_API void dGeomTriMeshDataBuildDouble(dTriMeshDataID g,
85 const void* Vertices, int VertexStride, int VertexCount,
86 const void* Indices, int IndexCount, int TriStride);
87 /* same again with a normals array (used as trimesh-trimesh optimization) */
88 ODE_API void dGeomTriMeshDataBuildDouble1(dTriMeshDataID g,
89 const void* Vertices, int VertexStride, int VertexCount,
90 const void* Indices, int IndexCount, int TriStride,
94 * Simple build. Single/double precision based on dSINGLE/dDOUBLE!
96 ODE_API void dGeomTriMeshDataBuildSimple(dTriMeshDataID g,
97 const dReal* Vertices, int VertexCount,
98 const dTriIndex* Indices, int IndexCount);
99 /* same again with a normals array (used as trimesh-trimesh optimization) */
100 ODE_API void dGeomTriMeshDataBuildSimple1(dTriMeshDataID g,
101 const dReal* Vertices, int VertexCount,
102 const dTriIndex* Indices, int IndexCount,
105 /* Preprocess the trimesh data to remove mark unnecessary edges and vertices */
106 ODE_API void dGeomTriMeshDataPreprocess(dTriMeshDataID g);
107 /* Get and set the internal preprocessed trimesh data buffer, for loading and saving */
108 ODE_API void dGeomTriMeshDataGetBuffer(dTriMeshDataID g, unsigned char** buf, int* bufLen);
109 ODE_API void dGeomTriMeshDataSetBuffer(dTriMeshDataID g, unsigned char* buf);
113 * Per triangle callback. Allows the user to say if he wants a collision with
114 * a particular triangle.
116 typedef int dTriCallback(dGeomID TriMesh, dGeomID RefObject, int TriangleIndex);
117 ODE_API void dGeomTriMeshSetCallback(dGeomID g, dTriCallback* Callback);
118 ODE_API dTriCallback* dGeomTriMeshGetCallback(dGeomID g);
121 * Per object callback. Allows the user to get the list of triangles in 1
122 * shot. Maybe we should remove this one.
124 typedef void dTriArrayCallback(dGeomID TriMesh, dGeomID RefObject, const int* TriIndices, int TriCount);
125 ODE_API void dGeomTriMeshSetArrayCallback(dGeomID g, dTriArrayCallback* ArrayCallback);
126 ODE_API dTriArrayCallback* dGeomTriMeshGetArrayCallback(dGeomID g);
130 * Allows the user to say if a ray collides with a triangle on barycentric
131 * coords. The user can for example sample a texture with alpha transparency
132 * to determine if a collision should occur.
134 typedef int dTriRayCallback(dGeomID TriMesh, dGeomID Ray, int TriangleIndex, dReal u, dReal v);
135 ODE_API void dGeomTriMeshSetRayCallback(dGeomID g, dTriRayCallback* Callback);
136 ODE_API dTriRayCallback* dGeomTriMeshGetRayCallback(dGeomID g);
139 * Triangle merging callback.
140 * Allows the user to generate a fake triangle index for a new contact generated
141 * from merging of two other contacts. That index could later be used by the
142 * user to determine attributes of original triangles used as sources for a
145 typedef int dTriTriMergeCallback(dGeomID TriMesh, int FirstTriangleIndex, int SecondTriangleIndex);
146 ODE_API void dGeomTriMeshSetTriMergeCallback(dGeomID g, dTriTriMergeCallback* Callback);
147 ODE_API dTriTriMergeCallback* dGeomTriMeshGetTriMergeCallback(dGeomID g);
151 * Construction. Callbacks are optional.
153 ODE_API dGeomID dCreateTriMesh(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback);
155 ODE_API void dGeomTriMeshSetData(dGeomID g, dTriMeshDataID Data);
156 ODE_API dTriMeshDataID dGeomTriMeshGetData(dGeomID g);
159 // enable/disable/check temporal coherence
160 ODE_API void dGeomTriMeshEnableTC(dGeomID g, int geomClass, int enable);
161 ODE_API int dGeomTriMeshIsTCEnabled(dGeomID g, int geomClass);
164 * Clears the internal temporal coherence caches. When a geom has its
165 * collision checked with a trimesh once, data is stored inside the trimesh.
166 * With large worlds with lots of seperate objects this list could get huge.
167 * We should be able to do this automagically.
169 ODE_API void dGeomTriMeshClearTCCache(dGeomID g);
173 * returns the TriMeshDataID
175 ODE_API dTriMeshDataID dGeomTriMeshGetTriMeshDataID(dGeomID g);
180 ODE_API void dGeomTriMeshGetTriangle(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2);
183 * Gets the point on the requested triangle and the given barycentric
186 ODE_API void dGeomTriMeshGetPoint(dGeomID g, int Index, dReal u, dReal v, dVector3 Out);
190 This is how the strided data works:
192 struct StridedVertex{
196 int VertexStride = sizeof(StridedVertex);
202 int TriStride = sizeof(StridedTri);
207 ODE_API int dGeomTriMeshGetTriangleCount (dGeomID g);
209 ODE_API void dGeomTriMeshDataUpdate(dTriMeshDataID g);
215 #endif /* _ODE_COLLISION_TRIMESH_H_ */