I've just finished a piece of code which generates a 3D level. The code adds lots plane meshes to a single object to create the level but it takes quite a while to do. Is there a faster way of doing this.
Here's my conversion code that does the job:
void WL_MAP::make3D(int objsize)
{
int tmesh;
int tobj;
int limb;
int texture;
int x,y;
int size2=objsize>>1;
int wsize=size2*wid;
int hsize=size2*hgt;
size=objsize;
// first of all lets make a plane mesh
dbMakeObjectPlane(tobj=free_object(),size,size);
dbMakeMeshFromObject(tmesh=free_mesh(),tobj);
// keeping this object for now
//dbDeleteObject(tobj);
// delete object if it exists
if ( dbObjectExist(obj) ) dbDeleteObject( obj );
obj=tobj; //re-use the ID cos we've just deleted it
limb=free_limb(obj);
// now go through each map piece and make floors, walls and roof
for (x=1; x<wid-1; x++) {
for (y=1; y<hgt-1; y++) {
if ( pieces[x+y*wid].piece != -1 ) {
texture=(pieces[x+y*wid].piece+pieces[x+y*wid].group) & 0x03;
// make floor
dbAddLimb(obj,limb,tmesh);
dbRotateLimb(obj,limb,-90,0,0);
dbOffsetLimb(obj,limb,x*size-wsize,-size2,y*size-hsize);
dbTextureLimb(obj,limb,floor[texture]);
limb++;
// make roof
dbAddLimb(obj,limb,tmesh);
dbRotateLimb(obj,limb,90,0,0);
dbOffsetLimb(obj,limb,x*size-wsize,size2,y*size-hsize);
dbTextureLimb(obj,limb,roof[texture]);
limb++;
// make left wall
if (pieces[(x-1)+y*wid].piece == -1) {
dbAddLimb(obj,limb,tmesh);
dbRotateLimb(obj,limb,0,90,0);
dbOffsetLimb(obj,limb,x*size-wsize-size2,0,y*size-hsize);
dbTextureLimb(obj,limb,wall[texture]);
limb++; }
// make right wall
if (pieces[(x+1)+y*wid].piece == -1) {
dbAddLimb(obj,limb,tmesh);
dbRotateLimb(obj,limb,0,-90,0);
dbOffsetLimb(obj,limb,x*size-wsize+size2,0,y*size-hsize);
dbTextureLimb(obj,limb,wall[texture]);
limb++; }
// make up wall
if (pieces[x+(y-1)*wid].piece == -1) {
dbAddLimb(obj,limb,tmesh);
//dbRotateLimb(obj,limb,0,0,0);
dbOffsetLimb(obj,limb,x*size-wsize,0,y*size-hsize-size2);
dbTextureLimb(obj,limb,wall[texture]);
limb++; }
// make up wall
if (pieces[x+(y+1)*wid].piece == -1) {
dbAddLimb(obj,limb,tmesh);
dbRotateLimb(obj,limb,0,180,0);
dbOffsetLimb(obj,limb,x*size-wsize,0,y*size-hsize+size2);
dbTextureLimb(obj,limb,wall[texture]);
limb++; }
} // eof if pieces[]
} // eof for y
} // eof for x
// lets try this (Woo hoo it works!)
dbHideLimb(obj,0);
// now keep it out of the way of the map (for later collision)
dbOffsetLimb(obj,0,0,size,0);
// don't need this temp mesh anymore
dbDeleteMesh(tmesh);
}
Or the full project downloaded from
HERE...
I've not yet sussed out how to build up vertices arrays but I will go down that road if it works out faster if anyone has anything to start from.
I did start by creating each part of the level separate which was much faster.
Warning! May contain Nuts!