/* Sets the M3dMagicRelease level */ void PutM3dMagicRelease3ds(database3ds *db, releaselevel3ds release) { if (db == NULL) SET_ERROR_RETURN(ERR_INVALID_ARG); if (db->topchunk == NULL) SET_ERROR_RETURN(ERR_INVALID_DATA); if (db->topchunk->tag == M3DMAGIC) { chunk3ds *c; M3dVersion *d; ReplaceOrAddChild3ds(db->topchunk, M3D_VERSION, &c); ON_ERROR_RETURN; d = InitChunkData3ds(c); ON_ERROR_RETURN; switch(release) { case Release13ds: d->version = 1; break; case Release23ds: d->version = 2; break; case Release33ds: d->version = 3; break; case ReleaseNotKnown3ds: d->version = 4; } } }
/* Sets the MeshRelease level */ void PutMeshRelease3ds(database3ds *db, releaselevel3ds release) { if (db == NULL) SET_ERROR_RETURN(ERR_INVALID_ARG); if (db->topchunk == NULL) SET_ERROR_RETURN(ERR_INVALID_DATA); if ((db->topchunk->tag == M3DMAGIC) || (db->topchunk->tag == CMAGIC)) { chunk3ds *mdata; chunk3ds *c; M3dVersion *d; FindChunk3ds(db->topchunk, MDATA, &mdata); if (mdata == NULL) { InitChunkAs3ds(&mdata, MDATA); AddChildOrdered3ds(db->topchunk, mdata); } ReplaceOrAddChild3ds(mdata, MESH_VERSION, &c); d = InitChunkData3ds(c); switch(release) { case Release13ds: d->version = 1; break; case Release23ds: d->version = 2; break; case Release33ds: d->version = 3; break; case ReleaseNotKnown3ds: d->version = 4; } } }
void PutBackground3ds(database3ds *db, background3ds *bgnd) { chunk3ds *mdata; if(db == NULL || bgnd == NULL) SET_ERROR_RETURN(ERR_INVALID_ARG); if(db->topchunk == NULL) SET_ERROR_RETURN(ERR_INVALID_DATABASE); if (!(db->topchunk->tag == M3DMAGIC || db->topchunk->tag == CMAGIC)) SET_ERROR_RETURN(ERR_WRONG_DATABASE); /* Search for a mesh data chunk */ FindChunk3ds(db->topchunk, MDATA, &mdata); /* If one isn't found, add it to the list */ if (mdata == NULL) { InitChunkAs3ds(&mdata, MDATA); AddChildOrdered3ds(db->topchunk, mdata); } /* if (1) */ /* Put bitmap background chunk. */ { chunk3ds *c; BitMap *d; ReplaceOrAddChild3ds(mdata, BIT_MAP, &c); d = InitChunkData3ds(c); d->bitmap = (bgnd->bitmap.name)? strdup(bgnd->bitmap.name): strdup(""); } /* if (1) */ /* Put the SOLID_BGND chunk */ { chunk3ds *cs, *cc; ColorF *dc; ReplaceOrAddChild3ds(mdata, SOLID_BGND, &cs); dc = InitChunkAndData3ds(&cc, COLOR_F); dc->red = bgnd->solid.color.r; dc->green = bgnd->solid.color.g; dc->blue = bgnd->solid.color.b; AddChild3ds(cs, cc); dc = InitChunkAndData3ds(&cc, LIN_COLOR_F); dc->red = bgnd->solid.color.r; dc->green = bgnd->solid.color.g; dc->blue = bgnd->solid.color.b; AddChild3ds(cs, cc); } /* if (1) */ /* Put the V_GRADIENT chunk */ { chunk3ds *cv, *cc; VGradient *dv; ColorF *dc; ReplaceOrAddChild3ds(mdata, V_GRADIENT, &cv); dv = InitChunkData3ds(cv); dv->gradpercent = bgnd->vgradient.gradpercent; dc = InitChunkAndData3ds(&cc, COLOR_F); dc->red = bgnd->vgradient.top.r; dc->green = bgnd->vgradient.top.g; dc->blue = bgnd->vgradient.top.b; AddChild3ds(cv, cc); dc = InitChunkAndData3ds(&cc, LIN_COLOR_F); dc->red = bgnd->vgradient.top.r; dc->green = bgnd->vgradient.top.g; dc->blue = bgnd->vgradient.top.b; AddChild3ds(cv, cc); dc = InitChunkAndData3ds(&cc, COLOR_F); dc->red = bgnd->vgradient.mid.r; dc->green = bgnd->vgradient.mid.g; dc->blue = bgnd->vgradient.mid.b; AddChild3ds(cv, cc); dc = InitChunkAndData3ds(&cc, LIN_COLOR_F); dc->red = bgnd->vgradient.mid.r; dc->green = bgnd->vgradient.mid.g; dc->blue = bgnd->vgradient.mid.b; AddChild3ds(cv, cc); dc = InitChunkAndData3ds(&cc, COLOR_F); dc->red = bgnd->vgradient.bottom.r; dc->green = bgnd->vgradient.bottom.g; dc->blue = bgnd->vgradient.bottom.b; AddChild3ds(cv, cc); dc = InitChunkAndData3ds(&cc, LIN_COLOR_F); dc->red = bgnd->vgradient.bottom.r; dc->green = bgnd->vgradient.bottom.g; dc->blue = bgnd->vgradient.bottom.b; AddChild3ds(cv, cc); } /* if (1) */ /* Add a use_bitmap_bgnd, use_solid_bgnd, or use_v_gradient */ { chunk3ds *chunk; /* first, find any existing use_* chunks */ FindChunk3ds(mdata, USE_BIT_MAP, &chunk); if (chunk == NULL) { FindChunk3ds(mdata, USE_SOLID_BGND, &chunk); if (chunk == NULL) { FindChunk3ds(mdata, USE_V_GRADIENT, &chunk); } } /* If one was found, delete it */ if (chunk != NULL) { DeleteChunk3ds(chunk); } if (bgnd->bgndused != NoBgnd) { if (chunk == NULL) { InitChunk3ds(&chunk); chunk->tag = USE_BIT_MAP; /* just to help place in order */ AddChildOrdered3ds(mdata,chunk); } /* add the new use_* chunk */ switch (bgnd->bgndused) { case UseBitmapBgnd: chunk->tag = USE_BIT_MAP; break; case UseSolidBgnd: chunk->tag = USE_SOLID_BGND; break; case UseVGradientBgnd: chunk->tag = USE_V_GRADIENT; break; case NoBgnd: chunk->tag = NULL_CHUNK; break; } } } }