void WriteFile (void) { FILE *modelouthandle; int total = 0; int i; pStart = kalloc( 1, FILEBUFFER ); StripExtension (outname); for (i = 1; i < numseqgroups; i++) { // write the non-default sequence group data to separate files char groupname[128], localname[128]; sprintf( groupname, "%s%02d.mdl", outname, i ); printf ("writing %s:\n", groupname); modelouthandle = SafeOpenWrite (groupname); pseqhdr = (studioseqhdr_t *)pStart; pseqhdr->id = IDSTUDIOSEQHEADER; pseqhdr->version = STUDIO_VERSION; pData = pStart + sizeof( studioseqhdr_t ); pData = WriteAnimations( pData, pStart, i ); ExtractFileBase( groupname, localname ); sprintf( sequencegroup[i].name, "models\\%s.mdl", localname ); strcpy( pseqhdr->name, sequencegroup[i].name ); pseqhdr->length = pData - pStart; printf("total %6d\n", pseqhdr->length ); SafeWrite( modelouthandle, pStart, pseqhdr->length ); fclose (modelouthandle); memset( pStart, 0, pseqhdr->length ); } if (split_textures) { // write textures out to a separate file char texname[128]; sprintf( texname, "%sT.mdl", outname ); printf ("writing %s:\n", texname); modelouthandle = SafeOpenWrite (texname); phdr = (studiohdr_t *)pStart; phdr->id = IDSTUDIOHEADER; phdr->version = STUDIO_VERSION; pData = (byte *)phdr + sizeof( studiohdr_t ); WriteTextures( ); phdr->length = pData - pStart; printf("textures %6d bytes\n", phdr->length ); SafeWrite( modelouthandle, pStart, phdr->length ); fclose (modelouthandle); memset( pStart, 0, phdr->length ); pData = pStart; } // // write the model output file // strcat (outname, ".mdl"); printf ("---------------------\n"); printf ("writing %s:\n", outname); modelouthandle = SafeOpenWrite (outname); phdr = (studiohdr_t *)pStart; phdr->id = IDSTUDIOHEADER; phdr->version = STUDIO_VERSION; strcpy( phdr->name, outname ); VectorCopy( eyeposition, phdr->eyeposition ); VectorCopy( bbox[0], phdr->min ); VectorCopy( bbox[1], phdr->max ); VectorCopy( cbox[0], phdr->bbmin ); VectorCopy( cbox[1], phdr->bbmax ); phdr->flags = gflags; pData = (byte *)phdr + sizeof( studiohdr_t ); WriteBoneInfo( ); printf("bones %6d bytes (%d)\n", pData - pStart - total, numbones ); total = pData - pStart; pData = WriteAnimations( pData, pStart, 0 ); WriteSequenceInfo( ); printf("sequences %6d bytes (%d frames) [%d:%02d]\n", pData - pStart - total, totalframes, (int)totalseconds / 60, (int)totalseconds % 60 ); total = pData - pStart; WriteModel( ); printf("models %6d bytes\n", pData - pStart - total ); total = pData - pStart; if (!split_textures) { WriteTextures( ); printf("textures %6d bytes\n", pData - pStart - total ); } phdr->length = pData - pStart; printf("total %6d\n", phdr->length ); SafeWrite( modelouthandle, pStart, phdr->length ); fclose (modelouthandle); }
void MD32spr::Write() { size_t i = 0; csString vfspath; char* fileName = 0; char* mdlName = 0; if (outZipName) { if (outZipName.Length() > 0) { csArchive* zipFile = new csArchive (outZipName.GetData()); if(!zipFile) { ReportError("Error creating output zip file.\n"); return; } delete zipFile; fileName = new char[outZipName.Length() + 1]; basename(outZipName.GetData(), fileName); vfspath.Format ("/tmp/%s_out/", fileName); if (!out->Mount(vfspath, outZipName.GetData())) { ReportError("Error mounting output zip file.\n"); return; } } } if (!player && !weaponDir) { if (generic.GetSize ()) { for (i = 0; i < generic.GetSize (); i++) { md3Model *mdl = generic.Get(i); mdlName = new char[strlen(mdl->GetFileName()) + 1]; basename(mdl->GetFileName(), mdlName); csRef<iDocumentSystem> xml(csPtr <iDocumentSystem> (new csTinyDocumentSystem())); csRef <iDocument> doc = xml->CreateDocument(); csRef <iDocumentNode> root = doc->CreateRoot(); csRef <iDocumentNode> parent = root->CreateNodeBefore(CS_NODE_ELEMENT, 0); parent->SetValue("library"); WriteGeneric(mdl, parent); csString outFile(vfspath); outFile += mdlName; doc->Write(out, outFile.GetData()); } } } if (player) { if (headModel) { char *headName = new char[strlen(headModel->GetFileName()) + 1]; csString tagFileName; basename(headModel->GetFileName(), headName); tagFileName.Format ("%s%s.tag", vfspath.GetData(), headName); WriteXMLTags(headModel, tagFileName); csRef < iDocumentSystem > xml(csPtr < iDocumentSystem > (new csTinyDocumentSystem())); csRef < iDocument > doc = xml->CreateDocument(); csRef < iDocumentNode > root = doc->CreateRoot(); csRef < iDocumentNode > parent = root->CreateNodeBefore(CS_NODE_ELEMENT, 0); parent->SetValue("library"); WriteGeneric(headModel, parent); csString outFile(vfspath); outFile += headName; doc->Write(out, outFile.GetData()); } if (upperModel) { char *upperName = new char[strlen(headModel->GetFileName()) + 1]; csString tagFileName; basename(upperModel->GetFileName(), upperName); tagFileName.Format ("%s%s.tag", vfspath.GetData(), upperName); WriteXMLTags(upperModel, tagFileName); csRef < iDocumentSystem > xml(csPtr < iDocumentSystem > (new csTinyDocumentSystem())); csRef < iDocument > doc = xml->CreateDocument(); csRef < iDocumentNode > root = doc->CreateRoot(); csRef < iDocumentNode > parent = root->CreateNodeBefore(CS_NODE_ELEMENT, 0); parent->SetValue("library"); WriteGeneric(upperModel, parent); csString outFile(vfspath); outFile += upperName; doc->Write(out, outFile.GetData()); } if (lowerModel) { char *lowerName = new char[strlen(headModel->GetFileName()) + 1]; csString tagFileName; basename(lowerModel->GetFileName(), lowerName); tagFileName.Format ("%s%s.tag", vfspath.GetData(), lowerName); WriteXMLTags(lowerModel, tagFileName); csRef < iDocumentSystem > xml(csPtr < iDocumentSystem > (new csTinyDocumentSystem())); csRef < iDocument > doc = xml->CreateDocument(); csRef < iDocumentNode > root = doc->CreateRoot(); csRef < iDocumentNode > parent = root->CreateNodeBefore(CS_NODE_ELEMENT, 0); parent->SetValue("library"); WriteGeneric(lowerModel, parent); csString outFile(vfspath); outFile += lowerName; doc->Write(out, outFile.GetData()); } if (weaponDir) { for (i = 0; i < generic.GetSize (); i++) { md3Model *mdl = generic.Get(i); csRef < iDocumentSystem > xml(csPtr < iDocumentSystem > (new csTinyDocumentSystem())); csRef < iDocument > doc = xml->CreateDocument(); csRef < iDocumentNode > root = doc->CreateRoot(); csRef < iDocumentNode > parent = root->CreateNodeBefore(CS_NODE_ELEMENT, 0); parent->SetValue("library"); WriteGeneric(mdl, parent); char *fileName = new char[mdl->fileName.Length() + 1]; csString tagFileName; basename(mdl->fileName.GetData(), fileName); csString outFile(vfspath); outFile += weaponDir; outFile += "/"; outFile += fileName; doc->Write(out, outFile.GetData()); tagFileName.Format ("%s%s/%s.tag", vfspath.GetData(), weaponDir.GetData(), fileName); WriteXMLTags(mdl, tagFileName); } } } WriteTextures(mountPath.GetData(),vfspath); if(weaponDir) { csString weaponInPath(mountPath.GetData()); csString weaponOutPath(vfspath); weaponInPath += weaponDir; weaponInPath += "/"; weaponOutPath += weaponDir; weaponOutPath += "/"; WriteTextures(weaponInPath.GetData(), weaponOutPath.GetData()); } }