Skip to content

Commit

Permalink
Fixed export code when dumping the world render object
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianoDiDio committed Apr 13, 2024
1 parent 0200e61 commit 929ca77
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
30 changes: 22 additions & 8 deletions src/JPModelViewer/BSD.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,14 @@ void BSDRenderObjectExportFacesToPly(BSDRenderObject_t *RenderObject,BSDFace_t *
fwrite(Buffer,strlen(Buffer),1,OutFile);
}
}
void BSDRenderObjectExportToPly(BSDRenderObject_t *RenderObject,VRAM_t *VRAM,FILE *OutFile)
{
if( !RenderObject || !OutFile ) {
bool InvalidFile = (OutFile == NULL ? true : false);
DPrintf("BSDRenderObjectExportToPly: Invalid %s\n",InvalidFile ? "file" : "bsd struct");
void BSDRenderObjectExportToPly(BSDRenderObject_t *RenderObject,VRAM_t *VRAM,const char *Directory,char *BSDFileName)
{
char *PlyFile;
char *FileName;
FILE *OutFile;

if( !RenderObject ) {
DPrintf("BSDRenderObjectExportToPly: Invalid bsd struct\n");
return;
}

Expand All @@ -255,17 +258,28 @@ void BSDRenderObjectExportToPly(BSDRenderObject_t *RenderObject,VRAM_t *VRAM,FIL
return;
}
if( RenderObject->TSP ) {
TSPDumpDataToPlyFile(RenderObject->TSP,VRAM,OutFile);
asprintf(&FileName,"RenderObject-%s-JP.ply",BSDFileName);
} else {
asprintf(&FileName,"RenderObject-%u-JP.ply",RenderObject->Id);
}
asprintf(&PlyFile,"%s%c%s",Directory,PATH_SEPARATOR,FileName);
OutFile = fopen(PlyFile,"w");
if( !OutFile ) {
DPrintf("RenderObjectManagerExportSelectedModelToPly:Failed to open %s for writing\n",PlyFile);
return;
}
if( RenderObject->TSP ) {
TSPDumpDataToPlyFile(RenderObject->TSP,VRAM,OutFile);
}
if( RenderObject->NumTexturedFaces > 0 ) {
BSDRenderObjectExportFacesToPly(RenderObject,RenderObject->TexturedFaceList,RenderObject->NumTexturedFaces,VRAM,OutFile);
return;
}
if( RenderObject->NumUntexturedFaces > 0 ) {
BSDRenderObjectExportFacesToPly(RenderObject,RenderObject->UntexturedFaceList,RenderObject->NumUntexturedFaces,VRAM,OutFile);
return;
}
fclose(OutFile);
free(FileName);
free(PlyFile);
}

void BSDFillFaceVertexBuffer(int *Buffer,int *BufferSize,BSDVertex_t Vertex,int U0,int V0,BSDColor_t Color,int CLUTX,int CLUTY,int ColorMode,bool Textured)
Expand Down
2 changes: 1 addition & 1 deletion src/JPModelViewer/BSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ BSDAnimationFrame_t *BSDRenderObjectGetCurrentFrame(BSDRenderObject_t *R
void BSDRenderObjectResetFrameQuaternionList(BSDAnimationFrame_t *Frame);

void BSDRenderObjectGenerateVAO(BSDRenderObject_t *RenderObject);
void BSDRenderObjectExportToPly(BSDRenderObject_t *RenderObject,VRAM_t *VRAM,FILE *OutFile);
void BSDRenderObjectExportToPly(BSDRenderObject_t *RenderObject,VRAM_t *VRAM,const char *Directory,char *BSDFileName);
void BSDFree(BSD_t *BSD);
void BSDFreeRenderObjectList(BSDRenderObject_t *RenderObjectList);

Expand Down
24 changes: 2 additions & 22 deletions src/JPModelViewer/RenderObjectManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,8 @@ void RenderObjectManagerCloseDialog(FileDialog_t *FileDialog)
void RenderObjectManagerExportSelectedModelToPly(RenderObjectManager_t *RenderObjectManager,ProgressBar_t *ProgressBar,VideoSystem_t *VideoSystem,
const char *Directory)
{
char *PlyFile;
char *FileName;
char *TextureFile;
char *BSDName;
FILE *OutFile;
char *TextureFile;
BSDRenderObjectPack_t *CurrentBSDPack;
BSDRenderObject_t *CurrentRenderObject;

Expand All @@ -119,26 +116,14 @@ void RenderObjectManagerExportSelectedModelToPly(RenderObjectManager_t *RenderOb
DPrintf("RenderObjectManagerExportSelectedModelToPly:Invalid RenderObject\n");
return;
}
asprintf(&FileName,"RenderObject-%u-JP.ply",CurrentRenderObject->Id);
asprintf(&PlyFile,"%s%c%s",Directory,PATH_SEPARATOR,FileName);
BSDName = SwitchExt(CurrentBSDPack->Name,"");
asprintf(&TextureFile,"%s%cvram-%s.png",Directory,PATH_SEPARATOR,BSDName);
ProgressBarSetDialogTitle(ProgressBar,"Exporting Model to Ply...");
ProgressBarIncrement(ProgressBar,VideoSystem,10,"Writing BSD data.");

OutFile = fopen(PlyFile,"w");
if( !OutFile ) {
DPrintf("RenderObjectManagerExportSelectedModelToPly:Failed to open %s for writing\n",PlyFile);
return;
}
BSDRenderObjectExportToPly(CurrentRenderObject,CurrentBSDPack->VRAM,OutFile);
fclose(OutFile);

BSDRenderObjectExportToPly(CurrentRenderObject,CurrentBSDPack->VRAM,Directory,BSDName);
ProgressBarIncrement(ProgressBar,VideoSystem,95,"Exporting VRAM.");
VRAMSave(CurrentBSDPack->VRAM,TextureFile);
ProgressBarIncrement(ProgressBar,VideoSystem,100,"Done.");
free(FileName);
free(PlyFile);
free(TextureFile);
free(BSDName);
return;
Expand Down Expand Up @@ -306,7 +291,6 @@ BSDRenderObjectPack_t *RenderObjectManagerGetBSDPack(RenderObjectManager_t *Rend
int RenderObjectManagerLoadBSD(RenderObjectManager_t *RenderObjectManager,GUI_t *GUI,VideoSystem_t *VideoSystem,const char *File)
{
BSDRenderObjectPack_t *BSDPack;
BSDRenderObject_t *Iterator;
char *TAFFile;
int ErrorCode;

Expand Down Expand Up @@ -371,10 +355,6 @@ int RenderObjectManagerLoadBSD(RenderObjectManager_t *RenderObjectManager,GUI_t
ErrorCode = RENDER_OBJECT_MANAGER_BSD_ERROR_VRAM_INITIALIZATION;
goto Failure;
}
/*ProgressBarIncrement(GUI->ProgressBar,VideoSystem,90,"Setting default pose");
for( Iterator = BSDPack->RenderObjectList; Iterator; Iterator = Iterator->Next ) {
BSDRenderObjectSetAnimationPose(Iterator,0,0,0);
}*/
ProgressBarIncrement(GUI->ProgressBar,VideoSystem,100,"Done");
RenderObjectManagerAppendBSDPack(RenderObjectManager,BSDPack);
if( !RenderObjectManager->SelectedBSDPack ) {
Expand Down

0 comments on commit 929ca77

Please sign in to comment.