/*-------------------------------------------------------------------------- | PutOmnilightMotion3ds | Puts Omnilight keyframe information into database. | | kfOmnilight3ds--->db | | KFDATA | ... | LIGHT_NODE | NODE_ID | NODE_HDR | APP_DATA | POS_TRACK | COL_TRACK | | Needs Work: | 1. NodeId: what value? | +--------------------------------------------------------------------------*/ void PutOmnilightMotion3ds(database3ds *db, kfomni3ds *kfomni) { chunk3ds *pKfChunk, *pOmniChunk, *pOmniXdata = NULL; if(db == NULL || kfomni == 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); MakeNodeTagListDirty3ds(db); /*--- Find KFSEG chunk to put keyframe data into */ kfGetKfSeg(db->topchunk, &pKfChunk); /*--- Destroy old chunks, Copy any XData and reattach it later */ kfExtractXdata(db, kfomni->name, LIGHT_NODE_TAG, &pOmniXdata); pOmniChunk = kfPutGenericNode(LIGHT_NODE_TAG, pKfChunk); kfPutNodeId(pOmniChunk); kfPutNodeHeader(kfomni->name, kfomni->flags1, kfomni->flags2, kfomni->parent, pOmniChunk); MakeNodeTagListDirty3ds(db); if (kfomni->npkeys>0 && kfomni->pkeys && kfomni->pos) kfPutPosTrack(kfomni->npkeys, kfomni->npflag, kfomni->pkeys, kfomni->pos, pOmniChunk); if (kfomni->nckeys>0 && kfomni->ckeys && kfomni->color) kfPutColorTrack(kfomni->nckeys, kfomni->ncflag, kfomni->ckeys, kfomni->color, pOmniChunk); /*--- Replace XData */ if (pOmniXdata) AddChildOrdered3ds(pOmniChunk, pOmniXdata); }
/*-------------------------------------------------------------------------- | PutAmbientLightMotion3ds | Puts AmbientLight keyframe information into database. | | kfAmbientLight3ds--->db | | KFDATA | ... | LIGHT_NODE | NODE_ID | NODE_HDR | APP_DATA | COL_TRACK | | Needs Work: | 1. NodeId: what value? | +--------------------------------------------------------------------------*/ void PutAmbientLightMotion3ds(database3ds *db, kfambient3ds *kfambient) { chunk3ds *pKfChunk, *pAmbientChunk, *pAmbientXdata = NULL; if(db == NULL || kfambient == 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)) SET_ERROR_RETURN(ERR_WRONG_DATABASE); /*--- Find KFSEG chunk to put keyframe data into */ kfGetKfSeg(db->topchunk, &pKfChunk); /*--- Destroy old chunks, Copy any XData and reattach it later */ kfExtractXdata(db, kAmbientName, AMBIENT_NODE_TAG, &pAmbientXdata); pAmbientChunk = kfPutGenericNode(AMBIENT_NODE_TAG, pKfChunk); kfPutNodeId(pAmbientChunk); kfPutNodeHeader(kAmbientName, kfambient->flags1, kfambient->flags2, (char3ds *)0, pAmbientChunk); if (kfambient->nckeys>0 && kfambient->ckeys && kfambient->color) kfPutColorTrack(kfambient->nckeys, kfambient->ncflag, kfambient->ckeys, kfambient->color, pAmbientChunk); /*--- Replace XData */ if (pAmbientXdata) AddChildOrdered3ds(pAmbientChunk, pAmbientXdata); }
/*---------------------------------------------------------------- | | PutLight3ds | | Put chunks in database from light3ds structure. | +-----------------------------------------------------------------*/ void PutLight3ds(database3ds *db, light3ds *light) { chunk3ds *pMdata, *pNamed, *pLight, *pSpot, *current, *xdata; if (db == NULL || light == 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); FindChunk3ds(db->topchunk, MDATA, &pMdata); if (pMdata == NULL) { InitChunk3ds(&pMdata); pMdata->tag = MDATA; AddChildOrdered3ds(db->topchunk, pMdata); } /* Discover if the named object already exists */ FindNamedObject3ds(db, light->name, &pNamed); /* If it does, then delete it */ if (pNamed != NULL) { /* First, rescue the xdata chunk if there is one */ FindChunk3ds(pNamed, XDATA_SECTION, ¤t); /* If there is one */ if (current != NULL) { /* Then make a copy of it to reintroduce later */ CopyChunk3ds(current, &xdata); } /* Delete the chunk's children and data, leaving it in the same list order */ DeleteChunk3ds(pNamed); pNamed->tag = NAMED_OBJECT; /* retag the chunk */ } else /* else pNamed needs to be initialized and added */ { InitChunkAs3ds(&pNamed, NAMED_OBJECT); AddChildOrdered3ds(pMdata, pNamed); } { /*--- NAME */ NamedObject *d; d = InitChunkData3ds(pNamed); d->name = strdup(light->name); MakeNamedObjectListDirty3ds(db); } { /*--- N_DIRECT_LIGHT & POSITION */ NDirectLight *d; pLight = kfPutGenericNode(N_DIRECT_LIGHT, pNamed); d = InitChunkData3ds(pLight); memcpy(&(d->lightpos), &(light->pos), sizeof(point3ds)); } /* | Add children to DIRECT_LIGHT */ /*--- COLOR */ { ColorF *d; chunk3ds *pChunk; pChunk = kfPutGenericNode(COLOR_F, pLight); d = InitChunkData3ds(pChunk); d->red = light->color.r; d->green = light->color.g; d->blue = light->color.b; } putTagFloat(pLight, DL_OUTER_RANGE, &light->attenuation.outer); ON_ERROR_RETURN; putTagFloat(pLight, DL_INNER_RANGE, &light->attenuation.inner); ON_ERROR_RETURN; putTagFloat(pLight, DL_MULTIPLIER, &light->multiplier); ON_ERROR_RETURN; if (light->dloff == True3ds) kfPutGenericNode(DL_OFF, pLight); if (light->attenuation.on == True3ds) kfPutGenericNode(DL_ATTENUATE, pLight); /*--- DL_EXCLUDE */ if (light->exclude != NULL && light->exclude->count > 0){ chunk3ds *pChunk; ulong3ds i; DlExclude *d; for(i=0; i<light->exclude->count; i++){ pChunk = kfPutGenericNode(DL_EXCLUDE, pLight); d = InitChunkData3ds(pChunk); d->name = strdup((light->exclude->list)[i].name); } } /*----------------------- | SPOTLIGHT SECTION +-----------------------*/ if (light->spot == NULL) return; { DlSpotlight *d; pSpot = kfPutGenericNode(DL_SPOTLIGHT, pLight); d = InitChunkData3ds(pSpot); memcpy(&d->spotlighttarg, &light->spot->target, sizeof(point3ds)); d->hotspotangle = light->spot->hotspot; d->falloffangle = light->spot->falloff; } putTagFloat(pSpot, DL_SPOT_ROLL, &light->spot->roll); if (light->spot->aspect != 1.0F) putTagFloat(pSpot, DL_SPOT_ASPECT, &light->spot->aspect); /*--- SHADOWS */ if (light->spot->shadows.cast == True3ds) kfPutGenericNode(DL_SHADOWED, pSpot); if (light->spot->shadows.type == UseRayTraceShadow) kfPutGenericNode(DL_RAYSHAD, pSpot); putTagFloat(pSpot, DL_RAY_BIAS, &light->spot->shadows.raybias); /*--- DL_LOCAL_SHADOW2 */ if (light->spot->shadows.local == True3ds) { DlLocalShadow2 *d; chunk3ds *pChunk; kfPutGenericNode(DL_LOCAL_SHADOW, pSpot); pChunk = kfPutGenericNode(DL_LOCAL_SHADOW2, pSpot); d = InitChunkData3ds(pChunk); d->localshadowbias = light->spot->shadows.bias; d->localshadowfilter = light->spot->shadows.filter; d->localshadowmapsize = light->spot->shadows.mapsize; } /*--- CONE */ if (light->spot->cone.type == Rectangular) kfPutGenericNode(DL_SPOT_RECTANGULAR, pSpot); if (light->spot->cone.show == True3ds) kfPutGenericNode(DL_SEE_CONE, pSpot); if (light->spot->cone.overshoot == True3ds) kfPutGenericNode(DL_SPOT_OVERSHOOT, pSpot); /*--- PROJECTOR */ if (light->spot->projector.use == True3ds) { DlSpotProjector *d; chunk3ds *pChunk; pChunk = kfPutGenericNode(DL_SPOT_PROJECTOR, pSpot); d = InitChunkData3ds(pChunk); d->name = strdup(light->spot->projector.bitmap); } }
/*-------------------------------------------------------------------------- | PutCameraMotion3ds | Puts camera keyframe information into database. | | kfcamera3ds--->db | | KFDATA | ... | TARGET | CAMERA_NODE | NODE_ID | NODE_HDR | APP_DATA | POS_TRACK | FOV_TRACK | ROLL_TRACK | | Needs Work: | 1. NodeId: what value? | +--------------------------------------------------------------------------*/ void PutCameraMotion3ds(database3ds *db, kfcamera3ds *kfcam) { chunk3ds *pKfChunk, *pCamChunk, *pTargetChunk = NULL, *pCameraXdata = NULL, *pTargetXdata = NULL; if(db == NULL || kfcam == 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)) SET_ERROR_RETURN(ERR_INVALID_DATA); /*--- Find KFSEG chunk to put keyframe data into */ kfGetKfSeg(db->topchunk, &pKfChunk); ON_ERROR_RETURN; /*--- Destroy old chunks, Copy any XData and reattach it later */ kfExtractXdata(db, kfcam->name, TARGET_NODE_TAG, &pTargetXdata); kfExtractXdata(db, kfcam->name, CAMERA_NODE_TAG, &pCameraXdata); MakeNodeTagListDirty3ds(db); /*--- TARGET TRACK */ if (kfcam->ntkeys>0 && kfcam->tkeys && kfcam->tpos) pTargetChunk = kfPutTargetTrack(kfcam->tparent, kfcam->ntkeys, kfcam->ntflag, kfcam->tkeys, kfcam->tpos, kfcam->name, kfcam->tflags1, kfcam->tflags2, CameraTarget, pKfChunk); pCamChunk = kfPutGenericNode(CAMERA_NODE_TAG, pKfChunk); kfPutNodeId(pCamChunk); kfPutNodeHeader(kfcam->name, kfcam->flags1, kfcam->flags2, kfcam->parent, pCamChunk); if (kfcam->npkeys>0 && kfcam->pkeys && kfcam->pos) kfPutPosTrack(kfcam->npkeys, kfcam->npflag, kfcam->pkeys, kfcam->pos, pCamChunk); /*-- FIELD OF VIEW */ if (kfcam->nfkeys>0 && kfcam->fkeys && kfcam->fov){ FovTrackTag *data; chunk3ds *temp = NULL; int nKeys; /*--- Create the FOV_TRACK_TAG chunk */ InitChunk3ds(&temp); temp->tag = FOV_TRACK_TAG; data = InitChunkData3ds(temp); /*--- Initialize trackhdr field */ data->trackhdr.flags = kfcam->nfflag; nKeys = data->trackhdr.keycount = kfcam->nfkeys; data->trackhdr.nu1 = data->trackhdr.nu2 = 0; /* Not Used */ /*--- Copy headers */ data->keyhdrlist = malloc(nKeys * sizeof(keyheader3ds)); memcpy(data->keyhdrlist, kfcam->fkeys, nKeys * sizeof(keyheader3ds)); /*--- Copy Points */ data->fovanglelist = malloc(nKeys * sizeof(float3ds)); memcpy(data->fovanglelist, kfcam->fov, nKeys * sizeof(float3ds)); /*--- Make if a child of the kframe node */ AddChildOrdered3ds(pCamChunk, temp); } if (kfcam->nrkeys>0 && kfcam->rkeys && kfcam->roll) kfPutRollTrack(kfcam->nrkeys, kfcam->nrflag, kfcam->rkeys, kfcam->roll, pCamChunk); /*--- Replace XData */ if (pCameraXdata) AddChildOrdered3ds(pCamChunk, pCameraXdata); if (pTargetXdata) AddChildOrdered3ds(pTargetChunk, pTargetXdata); }