Re: Terrain

"Bram Stolk" <[email protected]> Tue, 6 Nov 2007 20:19:46 -0800
Newsgroups gmane.comp.lib.ode
Message-ID <[email protected]>
On Nov 6, 2007 6:39 PM, mpeniak <[email protected]> wrote:

>
> What are the possibilities please?


I use PLIB to read an arbitrary model format.
In my case *.3ds files.

I then use this code (abstract from stormbaan coureur) to convert PLIB's
leaf nodes into ODE geoms:

void StaticWorldObject::AddLeaf(ssgLeaf *leaf, sgVec3 initialpos)
{
  // traverse the triangles
  int cnt = leaf->getNumTriangles() ;
  int nv  = leaf->getNumVertices() ;
//  int nn  = leaf->getNumNormals() ;

  float *vertices = new float[3*nv];
  int   *indices  = new int[3*cnt];

  int i;
  for (i=0; i<nv; i++)
  {
    float *v = leaf->getVertex( i ) ;
    assert(v);
    memcpy(vertices+3*i, v, 3*sizeof(float));
  }
  for (i=0; i<cnt; i++)
  {
    short idx0, idx1, idx2 ;
    leaf->getTriangle( i, &idx0, &idx1, &idx2 ) ;
    indices[3*i+0]=idx0;
    indices[3*i+1]=idx1;
    indices[3*i+2]=idx2;
  }

  dTriMeshDataID data = dGeomTriMeshDataCreate();
  dataids.push_back(data);
  dGeomTriMeshDataBuildSingle
  (
    data,
    vertices,
    3*sizeof(float),
    nv,
    indices,
    cnt*3,
    3*sizeof(int)
  );
  //fprintf(stderr,"Adding trimesh with %d verts, %d indices\n", nv, cnt*3);
  dGeomID trimesh = dCreateTriMesh(space, data, 0,0,0);
  geomids.push_back(trimesh);
  dGeomSetPosition(trimesh, initialpos[0], initialpos[1], initialpos[2]);
  dMatrix3 R;
  dRFromAxisAndAngle (R, 0,1,0, 0.0);
  dGeomSetRotation (trimesh, R);
  dGeomSetData(trimesh, this);
}


If you want to know who to find all leaf nodes in a PLIB scenegraph, consult
the stormbaan coureur source code.

Regards,

  Bram



-- 
Zapp: Captain's log, stardate...er..
Kif: Ohhh. April 13th.
Zapp: April 13th. Point 2.

_______________________________________________
ODE mailing list
[email protected]
http://ode.org/mailman/listinfo/ode