From: Matthias B. <mb...@us...> - 2004-07-19 15:02:15
|
Update of /cvsroot/pyode/pyode/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13551 Modified Files: geoms.pyx Added Files: trimeshdata.pyx Log Message: Initial trimesh support --- NEW FILE: trimeshdata.pyx --- # TriMeshData cdef class TriMeshData: """This class stores the mesh data. """ cdef dTriMeshDataID tmdid cdef dReal* vertex_buffer cdef int* face_buffer def __new__(self): self.tmdid = dGeomTriMeshDataCreate() self.vertex_buffer = NULL self.face_buffer = NULL def __dealloc__(self): if self.tmdid!=NULL: dGeomTriMeshDataDestroy(self.tmdid) if self.vertex_buffer!=NULL: free(self.vertex_buffer) if self.face_buffer!=NULL: free(self.face_buffer) def build(self, verts, faces): """build(verts, faces) @param verts: Vertices @type verts: Sequence of 3-sequences of floats @param faces: Face definitions (three indices per face) @type faces: Sequence of 3-sequences of ints """ cdef int numverts cdef int numfaces cdef dReal* vp cdef int* fp cdef int a,b,c numverts = len(verts) numfaces = len(faces) # Allocate the vertex and face buffer self.vertex_buffer = <dReal*>malloc(numverts*3*sizeof(dReal)) self.face_buffer = <int*>malloc(numfaces*3*sizeof(int)) # Fill the vertex buffer vp = self.vertex_buffer for v in verts: vp[0] = v[0] vp[1] = v[1] vp[2] = v[2] # vp[3] = 0 vp = vp+3 # Fill the face buffer fp = self.face_buffer for f in faces: a = f[0] b = f[1] c = f[2] if a<0 or b<0 or c<0 or a>=numverts or b>=numverts or c>=numverts: raise ValueError, "Vertex index out of range" fp[0] = a fp[1] = b fp[2] = c fp = fp+3 # Pass the data to ODE # dGeomTriMeshDataBuildSimple(self.tmdid, self.vertex_buffer, numverts, self.face_buffer, numfaces) dGeomTriMeshDataBuildSingle(self.tmdid, self.vertex_buffer, 3*sizeof(dReal), numverts, self.face_buffer, numfaces, 3*sizeof(int), NULL) Index: geoms.pyx =================================================================== RCS file: /cvsroot/pyode/pyode/src/geoms.pyx,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** geoms.pyx 13 Jul 2004 16:44:18 -0000 1.3 --- geoms.pyx 19 Jul 2004 15:02:05 -0000 1.4 *************** *** 296,300 **** def pointDepth(self, p): ! """pointDepth() -> float Return the depth of the point p in the sphere. Points inside --- 296,300 ---- def pointDepth(self, p): ! """pointDepth(p) -> float Return the depth of the point p in the sphere. Points inside *************** *** 349,353 **** def pointDepth(self, p): ! """pointDepth() -> float Return the depth of the point p in the box. Points inside the --- 349,353 ---- def pointDepth(self, p): ! """pointDepth(p) -> float Return the depth of the point p in the box. Points inside the *************** *** 403,407 **** def pointDepth(self, p): ! """pointDepth() -> float Return the depth of the point p in the plane. Points inside the --- 403,407 ---- def pointDepth(self, p): ! """pointDepth(p) -> float Return the depth of the point p in the plane. Points inside the *************** *** 456,460 **** def pointDepth(self, p): ! """pointDepth() -> float Return the depth of the point p in the cylinder. Points inside the --- 456,460 ---- def pointDepth(self, p): ! """pointDepth(p) -> float Return the depth of the point p in the cylinder. Points inside the *************** *** 561,562 **** --- 561,630 ---- + include "trimeshdata.pyx" + + # GeomTriMesh + cdef class GeomTriMesh(GeomObject): + """TriMesh object. + + To construct the trimesh geom you need a TriMeshData object that + stores the actual mesh. This object has to be passed as first + argument to the constructor. + """ + + # Keep a reference to the data + cdef TriMeshData data + + def __new__(self, TriMeshData data not None, space=None): + cdef Space sp + cdef dSpaceID sid + + self.data = data + + sid=NULL + if space!=None: + sp = space + sid = sp.sid + self.gid = dCreateTriMesh(sid, data.tmdid, NULL, NULL, NULL) + + _geom_c2py_lut[<long>self.gid] = self + + + def __init__(self, TriMeshData data not None, space=None): + self.space = space + self.body = None + + def placeable(self): + return True + + def _id(self): + cdef long id + id = <long>self.gid + return id + + def clearTCCache(self): + """clearTCCache() + + Clears the internal temporal coherence caches. + """ + dGeomTriMeshClearTCCache(self.gid) + + def getTriangle(self, int idx): + """getTriangle(idx) -> (v0, v1, v2) + + @param idx: Triangle index + @type idx: int + """ + + cdef dVector3 v0, v1, v2 + cdef dVector3* vp0 + cdef dVector3* vp1 + cdef dVector3* vp2 + + vp0 = <dVector3*>v0 + vp1 = <dVector3*>v1 + vp2 = <dVector3*>v2 + + dGeomTriMeshGetTriangle(self.gid, idx, vp0, vp1, vp2) + return ((v0[0],v0[1],v0[2]), (v1[0],v1[1],v1[2]), (v2[0],v2[1],v2[2])) + + |