void list_colors(FILE *f) { struct crange *r; struct crange *nextr; write_colors(f, 2); linelim = -1; if (brokenpipe) return; if (!are_colors()) { fprintf(f, " No color ranges"); return; } fprintf(f, " %-30s %s\n","Range", "Color"); if (!brokenpipe) fprintf(f, " %-30s %s\n","-----", "-----"); for (r = nextr = color_base; nextr; r = nextr, nextr = r->r_next) /* */ ; while (r) { fprintf(f, " %-32s %d\n", r_name(r->r_left->row, r->r_left->col, r->r_right->row, r->r_right->col), r->r_color); if (brokenpipe) return; r = r->r_prev; } }
/** * Write a M2/BC file from its corresponding structure * @param bc_m2_file The file to write data. * @param ptr A pointer to a M2/BC structure. */ int write_model(FILE *bc_m2_file, BCM2 *ptr) { //Header fwrite(&ptr->header, sizeof(ModelHeader), 1, bc_m2_file); align(bc_m2_file); //Filename ptr->header.nameOfs = getPos(bc_m2_file); fwrite(ptr->filename, sizeof(char), ptr->header.nameLength, bc_m2_file); align(bc_m2_file); //Global Sequences if (ptr->header.nGlobalSequences > 0) { ptr->header.ofsGlobalSequences = getPos(bc_m2_file); fwrite(ptr->globalsequences, sizeof(int), ptr->header.nGlobalSequences, bc_m2_file); align(bc_m2_file); } //Animations if (ptr->header.nAnimations > 0) { ptr->header.ofsAnimations = getPos(bc_m2_file); fwrite(ptr->animations, sizeof(ModelAnimation), ptr->header.nAnimations, bc_m2_file); align(bc_m2_file); } //Bones write_bones(bc_m2_file, ptr); //Animlookup if (ptr->header.nAnimationLookup > 0) { ptr->header.ofsAnimationLookup = getPos(bc_m2_file); fwrite(ptr->AnimLookup, sizeof(int16), ptr->header.nAnimationLookup, bc_m2_file); align(bc_m2_file); } //PlayAnimlookup if (ptr->header.nPlayableAnimationLookup > 0) { ptr->header.ofsPlayableAnimationLookup = getPos(bc_m2_file); fwrite(ptr->PlayAnimLookup, sizeof(PlayAnimRecord), ptr->header.nPlayableAnimationLookup, bc_m2_file); align(bc_m2_file); } //Keybonelookup if (ptr->header.nKeyBoneLookup > 0) { ptr->header.ofsKeyBoneLookup = getPos(bc_m2_file); fwrite(ptr->keybonelookup, sizeof(short), ptr->header.nKeyBoneLookup, bc_m2_file); align(bc_m2_file); } //Vertices if (ptr->header.nVertices > 0) { ptr->header.ofsVertices = getPos(bc_m2_file); fwrite(ptr->vertices, sizeof(ModelVertex), ptr->header.nVertices, bc_m2_file); align(bc_m2_file); } //Views write_views(bc_m2_file, ptr); //Transparency write_transparency(bc_m2_file, ptr); //Colors write_colors(bc_m2_file, ptr); //Textures if (ptr->header.nTextures > 0) { ptr->header.ofsTextures = getPos(bc_m2_file); fwrite(ptr->textures_def, sizeof(ModelTextureDef), ptr->header.nTextures, bc_m2_file); align(bc_m2_file); int i; for (i = 0; i < ptr->header.nTextures; i++) { if (ptr->textures_def[i].type == 0) { ptr->textures_def[i].nameOfs = getPos(bc_m2_file); fwrite(ptr->texture_names[i], sizeof(char), ptr->textures_def[i].nameLen, bc_m2_file); align(bc_m2_file); } } fseek(bc_m2_file, ptr->header.ofsTextures, SEEK_SET); fwrite(ptr->textures_def, sizeof(ModelTextureDef), ptr->header.nTextures, bc_m2_file); fseek(bc_m2_file, 0, SEEK_END); } //RenderFlags if (ptr->header.nRenderFlags > 0) { ptr->header.ofsRenderFlags = getPos(bc_m2_file); fwrite(ptr->renderflags, sizeof(int), ptr->header.nRenderFlags, bc_m2_file); align(bc_m2_file); } //TexReplace if (ptr->header.nTexReplace > 0) { ptr->header.ofsTexReplace = getPos(bc_m2_file); fwrite(ptr->TexReplace, sizeof(short), ptr->header.nTexReplace, bc_m2_file); align(bc_m2_file); } //BoneLookupTable if (ptr->header.nBoneLookupTable > 0) { ptr->header.ofsBoneLookupTable = getPos(bc_m2_file); fwrite(ptr->BoneLookupTable, sizeof(int16), ptr->header.nBoneLookupTable, bc_m2_file); align(bc_m2_file); } //Lookups if (ptr->header.nTexLookup > 0) { ptr->header.ofsTexLookup = getPos(bc_m2_file); fwrite(ptr->TexLookupTable, sizeof(short), ptr->header.nTexLookup, bc_m2_file); align(bc_m2_file); } if (ptr->header.nTexUnitLookup > 0) { ptr->header.ofsTexUnitLookup = getPos(bc_m2_file); fwrite(ptr->TexUnit, sizeof(short), ptr->header.nTexUnitLookup, bc_m2_file); align(bc_m2_file); } if (ptr->header.nTransparencyLookup > 0) { ptr->header.ofsTransparencyLookup = getPos(bc_m2_file); fwrite(ptr->TransparencyLookup, sizeof(short), ptr->header.nTransparencyLookup, bc_m2_file); align(bc_m2_file); } if (ptr->header.nTexAnimLookup > 0) { ptr->header.ofsTexAnimLookup = getPos(bc_m2_file); fwrite(ptr->TexAnimLookup, sizeof(short), ptr->header.nTexAnimLookup, bc_m2_file); align(bc_m2_file); } //Attachments write_attachments(bc_m2_file, ptr); if (ptr->header.nAttachLookup > 0) { ptr->header.ofsAttachLookup = getPos(bc_m2_file); fwrite(ptr->AttachLookup, sizeof(int16), ptr->header.nAttachLookup, bc_m2_file); align(bc_m2_file); } //Events write_events(bc_m2_file, ptr); //Cameras write_cameras(bc_m2_file, ptr); if (ptr->header.nCameraLookup > 0) { ptr->header.ofsCameraLookup = getPos(bc_m2_file); fwrite(ptr->CameraLookup, sizeof(int16), ptr->header.nCameraLookup, bc_m2_file); align(bc_m2_file); } //Rewrite the header with updated offsets fseek(bc_m2_file, 0, SEEK_SET); fwrite(&ptr->header, sizeof(ModelHeader), 1, bc_m2_file); return 0; }