diff --git a/neo/d3xp/anim/Anim.cpp b/neo/d3xp/anim/Anim.cpp index d4648ff1..5c9a3b6a 100644 --- a/neo/d3xp/anim/Anim.cpp +++ b/neo/d3xp/anim/Anim.cpp @@ -1073,6 +1073,12 @@ idMD5Anim::CheckModelHierarchy */ void idMD5Anim::CheckModelHierarchy( const idRenderModel* model ) const { + // RB + if( com_editors & EDITOR_EXPORTDEFS ) + { + return; + } + if( jointInfo.Num() != model->NumJoints() ) { if( !fileSystem->InProductionMode() ) diff --git a/neo/framework/DeclManager.cpp b/neo/framework/DeclManager.cpp index 78d14446..1e556a27 100644 --- a/neo/framework/DeclManager.cpp +++ b/neo/framework/DeclManager.cpp @@ -2066,6 +2066,7 @@ typedef struct evar_s void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args ) { extern idCVar postLoadExportModels; + extern idCVar postLoadExportModelName; // avoid media cache com_editors |= EDITOR_EXPORTDEFS; @@ -2322,8 +2323,6 @@ void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args ) int32( bounds[1].x ), int32( bounds[1].y ), int32( bounds[1].z ) ); } - file->Printf( "= %s : \"%s\"\n", decl->GetName(), text.c_str() ); - // collect editor specific spawn flags idList evars; @@ -2342,8 +2341,6 @@ void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args ) } } - file->Printf( "[\n" ); - idDict dictToWrite; for( int i = 0; i < decl->dict.GetNumKeyVals(); i++ ) @@ -2396,7 +2393,7 @@ void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args ) } } -#if 1 + // add editor_vars that aren't already covered by the default vars for( int i = 0; i < evars.Num(); i++ ) { const evar_t* ev = &evars[ i ]; @@ -2407,7 +2404,47 @@ void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args ) dictToWrite.Set( ev->name, ev->desc ); } } -#endif + + // export models as OBJ + bool writeModel = false; + idStrStatic< MAX_OSPATH > exportedModelFileName; + + kv = dictToWrite.MatchPrefix( "model" ); + while( kv ) + { + if( kv->GetValue().Length() ) + { + declManager->MediaPrint( "Precaching model %s\n", kv->GetValue().c_str() ); + + // precache model/animations + const idDecl* modelDef = declManager->FindType( DECL_MODELDEF, kv->GetValue(), false ); + if( modelDef == NULL ) + { + // there is no modelDef so use direct path + renderModelManager->FindModel( kv->GetValue() ); + } + + // 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 ); + } + + if( writeModel ) + { + file->Printf( "model({ \"path\": \"%s\" }) ", exportedModelFileName.c_str() ); + } + + file->Printf( "= %s : \"%s\"\n", decl->GetName(), text.c_str() ); + file->Printf( "[\n" ); for( int i = 0; i < dictToWrite.GetNumKeyVals(); i++ ) { @@ -2483,16 +2520,7 @@ void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args ) file->Printf( "]\n\n" ); - /* - if( i == ( count - 1 ) ) - { - file->Printf( "\t\t}\n" ); - } - else - { - file->Printf( "\t\t},\n" ); - } - */ + } file->Flush(); @@ -2508,8 +2536,6 @@ void idDeclManagerLocal::ExportDeclsToTrenchBroom_f( const idCmdArgs& args ) postLoadExportModels.SetBool( false ); - - declManagerLocal.Reload( true ); } // RB end diff --git a/neo/renderer/ModelManager.cpp b/neo/renderer/ModelManager.cpp index 537ed784..a197269e 100644 --- a/neo/renderer/ModelManager.cpp +++ b/neo/renderer/ModelManager.cpp @@ -37,6 +37,7 @@ idCVar preload_MapModels( "preload_MapModels", "1", CVAR_SYSTEM | CVAR_BOOL, "pr // RB begin idCVar postLoadExportModels( "postLoadExportModels", "0", CVAR_BOOL | CVAR_RENDERER, "export models after loading to OBJ model format" ); +idCVar postLoadExportModelName( "postLoadExportModelName", "", CVAR_SYSTEM | CVAR_RENDERER, "" ); // RB end class idRenderModelManagerLocal : public idRenderModelManager @@ -330,7 +331,27 @@ idRenderModel* idRenderModelManagerLocal::GetModel( const char* _modelName, bool // in memory as well model->TouchData(); } + model->SetLevelLoadReferenced( true ); + + // RB ugly HACK set postLoadExportModelName for exportFGB + if( postLoadExportModels.GetBool() && ( model != defaultModel && model != beamModel && model != spriteModel ) ) + { + idStrStatic< MAX_OSPATH > exportedFileName; + + exportedFileName = "exported/rendermodels/"; + + if( com_editors & EDITOR_EXPORTDEFS ) + { + exportedFileName = "_tb/"; + } + + exportedFileName.AppendPath( canonical ); + exportedFileName.SetFileExtension( ".obj" ); + + postLoadExportModelName.SetString( exportedFileName ); + } + return model; } } @@ -367,7 +388,6 @@ idRenderModel* idRenderModelManagerLocal::GetModel( const char* _modelName, bool if( model != NULL ) { - generatedFileName = "generated/rendermodels/"; generatedFileName.AppendPath( canonical ); generatedFileName.SetFileExtension( va( "b%s", extension.c_str() ) ); @@ -447,12 +467,21 @@ idRenderModel* idRenderModelManagerLocal::GetModel( const char* _modelName, bool idStrStatic< MAX_OSPATH > exportedFileName; exportedFileName = "exported/rendermodels/"; + + if( com_editors & EDITOR_EXPORTDEFS ) + { + exportedFileName = "_tb/"; + } + exportedFileName.AppendPath( canonical ); exportedFileName.SetFileExtension( ".obj" ); ID_TIME_T sourceTimeStamp = fileSystem->GetTimestamp( canonical ); ID_TIME_T timeStamp = fileSystem->GetTimestamp( exportedFileName ); + // ugly HACK + postLoadExportModelName.SetString( exportedFileName ); + // TODO only update if generated has changed //if( timeStamp == FILE_NOT_FOUND_TIMESTAMP )