From: brett h. <bha...@ya...> - 2004-06-25 00:31:01
|
--- Matthias Baas <ba...@ir...> wrote: > Bernie Roehl wrote: > > in) into Python, and then from Python back into C for ODE to use. I > > think the more common case by far will be simply passing the data from > > the 3D engine to ODE directly. Perhaps this can be done using Python's > > array module (not the one in Numeric, the other one). Something to > > explore. > > How do we get to the mesh data when using a particular 3D engine? Which > engines are available from Python? Brett mentioned PyOpenGL, vtk and > PyOSG. So far, I've only used PyOpenGL and that's really only a direct > binding of the OpenGL API which does not have any mesh import > functionality or a mesh data structure (maybe in OpenGLContext, but I've > never used that one). > Brett, how would that work for PyOSG? Can the vertices and faces > directly be accessed from Python? > OSG has a Geode class that holds all the vertices, faces, uvs and normals that make up a mesh object. Vertices and faces can be accessed to/from Python, below is how you can build a cube in PyOSG, in c++ it looks pretty much the same - just replace 'self' with 'geode->' Once you have passed the geode all the data it turns it into an OpenGL display list so it renders quickly. If triangle data is not being passed from ODE to OSG every frame then it should be pretty fast. It would be nice to have some fast C functions that can convert ODE's dReals vertices to osg's Vec3 vertices and pass that object directly to an osg geode. These functions could then be exposed to Python, then we would not have to do the conversion in Python using tuples as the middle-man. It sounds like its going to be hard, any ideas? -brett def makeCube(self): self.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.POLYGON,0,4)) self.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.POLYGON,4,4)) self.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.POLYGON,8,4)) self.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.POLYGON,12,4)) self.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.POLYGON,16,4)) self.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.POLYGON,20,4)) # set up coords. coords = osg.Vec3Array() coords.resize(24) coords[0].set( -1.0000, 1.0000, -1.000 ) coords[1].set( 1.0000, 1.0000, -1.0000 ) coords[2].set( 1.0000, -1.0000, -1.0000 ) coords[3].set( -1.0000, -1.0000, -1.000 ) coords[4].set( 1.0000, 1.0000, -1.0000 ) coords[5].set( 1.0000, 1.0000, 1.0000 ) coords[6].set( 1.0000, -1.0000, 1.0000 ) coords[7].set( 1.0000, -1.0000, -1.0000 ) coords[8].set( 1.0000, 1.0000, 1.0000 ) coords[9].set( -1.0000, 1.0000, 1.000 ) coords[10].set( -1.0000, -1.0000, 1.000 ) coords[11].set( 1.0000, -1.0000, 1.0000 ) coords[12].set( -1.0000, 1.0000, 1.000 ) coords[13].set( -1.0000, 1.0000, -1.000 ) coords[14].set( -1.0000, -1.0000, -1.000 ) coords[15].set( -1.0000, -1.0000, 1.000 ) coords[16].set( -1.0000, 1.0000, 1.000 ) coords[17].set( 1.0000, 1.0000, 1.0000 ) coords[18].set( 1.0000, 1.0000, -1.0000 ) coords[19].set( -1.0000, 1.0000, -1.000 ) coords[20].set( -1.0000, -1.0000, 1.000 ) coords[21].set( -1.0000, -1.0000, -1.000 ) coords[22].set( 1.0000, -1.0000, -1.0000 ) coords[23].set( 1.0000, -1.0000, 1.0000 ) self.setVertexArray(coords) # set up the normals. cubeNormals = osg.Vec3Array() cubeNormals.resize(6) cubeNormals[0].set(0.0,0.0,-1.0) cubeNormals[1].set(1.0,0.0,0.0) cubeNormals[2].set(0.0,0.0,1.0) cubeNormals[3].set(-1.0,0.0,0.0) cubeNormals[4].set(0.0,1.0,0.0) cubeNormals[5].set(0.0,-1.0,0.0) self.setNormalArray( cubeNormals ) self.setNormalBinding(osg.Geometry.BIND_PER_PRIMITIVE ) cubeState = osg.StateSet() redMaterial = osg.Material() red = osg.Vec4(1.0, 0.0, 0.0, 1.0) redMaterial.setDiffuse(osg.Material.FRONT_AND_BACK, red) cubeState.setAttribute(redMaterial) self.setStateSet(cubeState) __________________________________ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail |