mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-04-19 16:21:11 +00:00
Exporting to OBJ also supports .md5mesh now
This commit is contained in:
parent
1867452c40
commit
19e207b893
5 changed files with 86 additions and 29 deletions
|
@ -2063,6 +2063,8 @@ typedef struct evar_s
|
|||
idStr desc;
|
||||
} evar_t;
|
||||
|
||||
#include <d3xp/anim/Anim.h> // idDeclModelDef
|
||||
|
||||
void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args )
|
||||
{
|
||||
extern idCVar postLoadExportModels;
|
||||
|
@ -2148,7 +2150,7 @@ void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args )
|
|||
idLib::Printf( "Failed to entity declarations data to FGD.\n" );
|
||||
}
|
||||
|
||||
file->Printf( "// DOOM 3 BFG game definition file (.fgd) created by RBDOOM-3-BFG\n\n" );
|
||||
file->Printf( "// DOOM 3 BFG game definition file (.fgd) generated by %s\n\n", ENGINE_VERSION );
|
||||
|
||||
for( int d = 0; d < count; d++ )
|
||||
{
|
||||
|
@ -2265,8 +2267,9 @@ void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args )
|
|||
file->Printf( "color(%i %i %i) ", int32( color.x * 255 ) & 0xFF, int32( color.y * 255 ) & 0xFF, int32( color.z * 255 ) & 0xFF );
|
||||
}
|
||||
|
||||
#if 0
|
||||
if( idStr::Icmp( decl->GetName(), "monster_zombie_maint_bald" ) == 0 )
|
||||
#if 1
|
||||
//if( idStr::Icmp( decl->GetName(), "monster_zombie_maint_bald" ) == 0 )
|
||||
if( idStr::Icmp( decl->GetName(), "monster_demon_imp" ) == 0 )
|
||||
{
|
||||
text += " ";
|
||||
}
|
||||
|
@ -2409,36 +2412,51 @@ void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args )
|
|||
bool writeModel = false;
|
||||
idStrStatic< MAX_OSPATH > exportedModelFileName;
|
||||
|
||||
kv = dictToWrite.MatchPrefix( "model" );
|
||||
while( kv )
|
||||
if( idStr::Icmp( decl->GetName(), "light" ) != 0 )
|
||||
{
|
||||
if( kv->GetValue().Length() )
|
||||
{
|
||||
declManager->MediaPrint( "Precaching model %s\n", kv->GetValue().c_str() );
|
||||
//kv = dictToWrite.MatchPrefix( "model" );
|
||||
//while( kv )
|
||||
|
||||
// precache model/animations
|
||||
const idDecl* modelDef = declManager->FindType( DECL_MODELDEF, kv->GetValue(), false );
|
||||
if( modelDef == NULL )
|
||||
const idKeyValue* kv = dictToWrite.FindKey( "model" );
|
||||
if( kv )
|
||||
{
|
||||
if( kv->GetValue().Length() )
|
||||
{
|
||||
// there is no modelDef so use direct path
|
||||
renderModelManager->FindModel( kv->GetValue() );
|
||||
declManager->MediaPrint( "Precaching model %s\n", kv->GetValue().c_str() );
|
||||
|
||||
// HACK
|
||||
writeModel = true;
|
||||
|
||||
// precache model/animations
|
||||
const idDeclModelDef* modelDef = static_cast<const idDeclModelDef*>( declManager->FindType( DECL_MODELDEF, kv->GetValue(), false ) );
|
||||
if( modelDef == NULL )
|
||||
{
|
||||
// there is no modelDef so use direct path
|
||||
renderModelManager->FindModel( kv->GetValue() );
|
||||
|
||||
exportedModelFileName = "_tb/";
|
||||
exportedModelFileName.AppendPath( kv->GetValue() );
|
||||
exportedModelFileName.SetFileExtension( ".obj" );
|
||||
}
|
||||
else
|
||||
{
|
||||
//exportedModelFileName = postLoadExportModelName.GetString();
|
||||
|
||||
idRenderModel* renderModel = modelDef->ModelHandle();
|
||||
if( renderModel )
|
||||
{
|
||||
exportedModelFileName = "_tb/";
|
||||
exportedModelFileName.AppendPath( renderModel->Name() );
|
||||
exportedModelFileName.SetFileExtension( ".obj" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HACK
|
||||
writeModel = true;
|
||||
|
||||
exportedModelFileName = postLoadExportModelName.GetString();
|
||||
//exportedFileName = "_tb/";
|
||||
//exportedFileName.AppendPath( modelDef->GetModelName() );
|
||||
//exportedFileName.SetFileExtension( ".obj" );
|
||||
|
||||
//dictToWrite.Set( kv->GetKey(), exportedFileName );
|
||||
//kv = dictToWrite.MatchPrefix( "model", kv );
|
||||
}
|
||||
|
||||
kv = dictToWrite.MatchPrefix( "model", kv );
|
||||
}
|
||||
|
||||
if( writeModel )
|
||||
if( writeModel && !exportedModelFileName.IsEmpty() )
|
||||
{
|
||||
file->Printf( "model({ \"path\": \"%s\" }) ", exportedModelFileName.c_str() );
|
||||
}
|
||||
|
|
|
@ -738,7 +738,7 @@ void idRenderModelStatic::WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp
|
|||
}
|
||||
|
||||
// RB begin
|
||||
void idRenderModelStatic::ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp ) const
|
||||
void idRenderModelStatic::ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp )
|
||||
{
|
||||
if( objFile == NULL || mtlFile == NULL )
|
||||
{
|
||||
|
@ -746,7 +746,7 @@ void idRenderModelStatic::ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T
|
|||
return;
|
||||
}
|
||||
|
||||
//objFile->Printf( "// generated by %s\n//\n\n", ENGINE_VERSION );
|
||||
objFile->Printf( "# generated by %s\n\n", ENGINE_VERSION );
|
||||
|
||||
int numVerts = 0;
|
||||
idList< const idMaterial* > materials;
|
||||
|
|
|
@ -173,7 +173,7 @@ public:
|
|||
virtual bool SupportsBinaryModel() = 0;
|
||||
|
||||
// RB begin
|
||||
virtual void ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp = NULL ) const = 0;
|
||||
virtual void ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp = NULL ) = 0;
|
||||
// RB end
|
||||
|
||||
// renderBump uses this to load the very high poly count models, skipping the
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
}
|
||||
|
||||
// RB begin
|
||||
virtual void ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp = NULL ) const;
|
||||
virtual void ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp = NULL );
|
||||
// RB end
|
||||
|
||||
virtual void PartialInitFromFile( const char* fileName );
|
||||
|
@ -233,6 +233,10 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
// RB begin
|
||||
virtual void ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp = NULL );
|
||||
// RB end
|
||||
|
||||
private:
|
||||
idList<idMD5Joint, TAG_MODEL> joints;
|
||||
idList<idJointQuat, TAG_MODEL> defaultPose;
|
||||
|
|
|
@ -1607,3 +1607,38 @@ int idRenderModelMD5::Memory() const
|
|||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
// RB begin
|
||||
void idRenderModelMD5::ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp )
|
||||
{
|
||||
if( objFile == NULL || mtlFile == NULL )
|
||||
{
|
||||
common->Printf( "Failed to ExportOBJ\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
renderEntity_t ent;
|
||||
|
||||
memset( &ent, 0, sizeof( ent ) );
|
||||
|
||||
ent.bounds.Clear();
|
||||
ent.suppressSurfaceInViewID = 0;
|
||||
|
||||
ent.numJoints = NumJoints();
|
||||
if( ent.numJoints > 0 )
|
||||
{
|
||||
ent.joints = ( idJointMat* )Mem_Alloc16( SIMD_ROUND_JOINTS( ent.numJoints ) * sizeof( *ent.joints ), TAG_JOINTMAT );
|
||||
|
||||
SIMD_INIT_LAST_JOINT( ent.joints, ent.numJoints );
|
||||
|
||||
idRenderModel* newmodel = InstantiateDynamicModel( &ent, NULL, NULL );
|
||||
newmodel->ExportOBJ( objFile, mtlFile, _timeStamp );
|
||||
|
||||
Mem_Free16( ent.joints );
|
||||
ent.joints = NULL;
|
||||
|
||||
delete newmodel;
|
||||
}
|
||||
}
|
||||
// RB end
|
Loading…
Reference in a new issue