/*------------------------------------------------------------------------ | | GetSpotlightCount3ds | +--------------------------------------------------------------------*/ ulong3ds GetSpotlightCount3ds(database3ds *db) { chunk3ds *dlite, *spotl; ulong3ds spotcount = 0, i; if (db == NULL) SET_ERROR_RETURNR(ERR_INVALID_ARG, 0); /* Update the index to named objects if the list has changed recently */ UpdateNamedObjectList3ds(db); if (db->objlist == NULL) return 0; /* Scan through the list of named objects looking for lights */ for (i = 0; i < db->objlist->count; i++) { /* Search each object for a light chunk */ FindChunk3ds(db->objlist->list[i].chunk, N_DIRECT_LIGHT, &dlite); /* if one was found, check to see if its a spotlight */ if (dlite != NULL) { FindChunk3ds(dlite, DL_SPOTLIGHT, &spotl); /* if it is a spotlight, then increment the count */ if (spotl != NULL) spotcount++; } } return spotcount; }
/* Fills out the **mesh structure contained in *db with the name listed in *name */ void GetMeshByName3ds(database3ds *db, /* Chunk listing to be searched */ char3ds *name, /* Name of mesh being searched for */ mesh3ds **mesh /* A pointer to the address of the mesh structure, if (*mesh) is null, then memory will be allocated for the new structure, otherwise, the existing structure will be filled in with the new values. If no match is found, then **mesh remains unchanged */ ) { chunk3ds *nobj = NULL, *ntri = NULL; if (db == NULL || name == NULL || mesh == 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); UpdateNamedObjectList3ds(db); /* Find the matching mesh name in the chunk list */ FindNamedObject3ds(db, name, &nobj); /* if a match is found */ if (nobj != NULL) { /* See it the named object is a mesh object */ FindChunk3ds(nobj, N_TRI_OBJECT, &ntri); /* If it is a mesh object, then fill in the mesh structure */ if (ntri != NULL) GetMeshEntryChunk3ds(nobj, mesh); } }
/* Fills out the **mesh structure from the (index)th mesh reference found in *db */ void GetMeshByIndex3ds(database3ds *db, ulong3ds index, mesh3ds **mesh) { chunk3ds *ntri; ulong3ds i, meshcount; if (db == NULL || mesh == 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); /* Update the index to named objects if the list has changed recently */ UpdateNamedObjectList3ds(db); /* Scan through the list of named objects */ for (i = 0, meshcount = 0; i < db->objlist->count; i++) { /* Search each named object for a mesh chunk */ FindChunk3ds(db->objlist->list[i].chunk, N_TRI_OBJECT, &ntri); /* If a mesh chunk is found */ if (ntri != NULL) { /* Increment the running total */ meshcount++; /* If this is the (index)th mesh, fill out the structure */ if (meshcount-1 == index) { GetMeshEntryChunk3ds(db->objlist->list[i].chunk, mesh); break; } } } }
/*------------------------------------------------------------------------ | | GetSpotlightByIndex3ds | Fills out the **spot structure from the (index)th spot reference | found in *db. | +------------------------------------------------------------------------*/ void GetSpotlightByIndex3ds(database3ds *db, long3ds index, light3ds **spotlight) { chunk3ds *lite, *spot; ulong3ds i; long3ds spotcount; if (db == NULL || spotlight == 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); /* Update the list if it's changed recently */ UpdateNamedObjectList3ds(db); /* Scan through the list */ for (i = 0, spotcount=0; i < db->objlist->count; i++) { /* Search for a light chunk */ FindChunk3ds(db->objlist->list[i].chunk, N_DIRECT_LIGHT, &lite); /* if one was found, check to see if its a spot */ if (lite != NULL) { FindChunk3ds(lite, DL_SPOTLIGHT, &spot); { /* if its a spot then increment the count */ if (spot != NULL) { spotcount++; /* If thisis the (index)th light, file out the structure */ if (spotcount-1 == index) { GetLightEntryChunk3ds(db->objlist->list[i].chunk, spotlight); break; } } } } } }
/*-------------------------------------------------------------------------- | | GetOmnilightNameList3ds | Searches *db to construct **list, a list of omnilight names within | the database | | db: The database bing searched. | list: The resulting namelist pairs, if *list is null, then a namelist | structure will be allocated. | +--------------------------------------------------------------------------*/ void GetOmnilightNameList3ds(database3ds *db, namelist3ds **list) { chunk3ds *lite, *spot; ulong3ds omnilightcount, i, j; if (db == NULL || list == NULL) SET_ERROR_RETURN(ERR_INVALID_ARG); /* Update the index to named objects if the list has changed recently */ UpdateNamedObjectList3ds(db); /* Get the number of omnilights contained in the named object list */ omnilightcount = GetOmnilightCount3ds(db); /* Initilize the namelist array */ InitNameList3ds(list, omnilightcount); /* Scan through the list of named objects */ for (i = 0, j = 0; (i < db->objlist->count) && (j < omnilightcount); i++) { /* Search each named object for a light chunk */ FindChunk3ds(db->objlist->list[i].chunk, N_DIRECT_LIGHT, &lite); /* if its a light chunk, check to see if its a spotlight */ if (lite != NULL) { FindChunk3ds(lite, DL_SPOTLIGHT, &spot); /* If its not a spot */ if (spot == NULL) { /* Copy the name into the list */ (*list)->list[j].name = strdup(db->objlist->list[i].name); j++; /* increment the omnilight counter */ } } } }
/* Returns a count of mesh objects referenced in the chunk list */ ulong3ds GetMeshCount3ds(database3ds *db /* The chunk listing that is being searched */ ) { chunk3ds *ntri; /* The possible pointer for the mesh chunk */ ulong3ds meshcount = 0, i; /* Update the index to named objects if the list has changed recently */ UpdateNamedObjectList3ds(db); ON_ERROR_RETURNR(0); if (db->objlist == NULL) return 0; /* Scan through the list of named objects */ for (i = 0; i < db->objlist->count; i++) { /* Search each named object for a mesh chunk */ FindChunk3ds(db->objlist->list[i].chunk, N_TRI_OBJECT, &ntri); /* if a mesh chunk was found, increment the count */ if (ntri != NULL) meshcount++; } return meshcount; }
/*-------------------------------------------------------------------------- | | GetSpotlightNameList3ds | Searches *db to construct **list, a list of spotlight names within | the database | | db: The database bing searched. | list: The resulting namelist pairs, if *list is null, then a namelist | structure will be allocated. | +--------------------------------------------------------------------------*/ void GetSpotlightNameList3ds(database3ds *db, namelist3ds **list) { chunk3ds *spot; ulong3ds spotlightcount, i, j; if (db == NULL || list == NULL) SET_ERROR_RETURN(ERR_INVALID_ARG); /* Update the index to named objects if the list has changed recently */ UpdateNamedObjectList3ds(db); /* Get the number of spotlights contained in the named object list */ spotlightcount = GetSpotlightCount3ds(db); /* Initilize the namelist array */ InitNameList3ds(list, spotlightcount); /* Scan through the list of named objects */ for (i = 0, j = 0; (i < db->objlist->count) && (j < spotlightcount); i++) { /* Search each named object for a direct light chunk */ FindChunk3ds(db->objlist->list[i].chunk, N_DIRECT_LIGHT, &spot); /* Search each direct light for a spotlight chunk */ if (spot != NULL) FindChunk3ds(spot, DL_SPOTLIGHT, &spot); /* If it is a spotlight chunk */ if (spot != NULL) { /* Copy the name into the list */ (*list)->list[j].name = strdup(db->objlist->list[i].name); j++; } } }
/* Searches *db to construct **list, a list of mesh names associated with their chunk definition. */ void GetMeshNameList3ds(database3ds *db, /* The chunk database being searched */ namelist3ds **list /* The resulting namelist pairs, if *list is null, then a namelist structure will be allocated */ ) { chunk3ds *current=NULL, *nobj=NULL, *ntri; ulong3ds meshcount, i, j; if (db == NULL || list == NULL) SET_ERROR_RETURN(ERR_INVALID_ARG); /* Update the index to named objects if the list has changed recently */ UpdateNamedObjectList3ds(db); /* Get the number of meshes contained in the named object list */ meshcount = GetMeshCount3ds(db); /* Initilize the namelist array */ InitNameList3ds(list, meshcount); /* Scan through the list of named objects */ for (i = 0, j = 0; (i < db->objlist->count) && (j < meshcount); i++) { /* Search each named object for a mesh chunk */ FindChunk3ds(db->objlist->list[i].chunk, N_TRI_OBJECT, &ntri); /* If it is a mesh chunk */ if (ntri != NULL) { /* Copy the name into the list */ (*list)->list[j].name = strdup(db->objlist->list[i].name); j++; } } }