From 9d3157eed000e7c543d04f5ad3efc5990675903b Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Sat, 29 May 2010 21:22:24 +0000 Subject: Reversing the last merge because I botched it. --- .../Converter/KX_BlenderSceneConverter.cpp | 118 ++++++++++++--------- 1 file changed, 66 insertions(+), 52 deletions(-) (limited to 'source/gameengine/Converter/KX_BlenderSceneConverter.cpp') diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 3a5bb92b4fa..4792ead8be2 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -932,7 +932,7 @@ Main* KX_BlenderSceneConverter::GetMainDynamicPath(const char *path) return NULL; } -bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_Scene *scene_merge, char **err_str) +bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, char *filter, KX_Scene *scene_merge, char **err_str) { bContext *C; Main *main_newlib; /* stored as a dynamic 'main' until we free it */ @@ -941,6 +941,7 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_S BlendHandle *bpy_openlib = NULL; /* ptr to the open .blend file */ int idcode= BLO_idcode_from_name(group); short flag= 0; /* dont need any special options */ + bool found = false; /* used for error reporting when using item */ ReportList reports; static char err_local[255]; @@ -949,50 +950,48 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_S snprintf(err_local, sizeof(err_local), "invalid ID type given \"%s\"\n", group); return false; } - - if(GetMainDynamicPath(path)) { - snprintf(err_local, sizeof(err_local), "blend file already open \"%s\"\n", path); - *err_str= err_local; - return false; - } - bpy_openlib = BLO_blendhandle_from_file( (char *)path ); - if(bpy_openlib==NULL) { - snprintf(err_local, sizeof(err_local), "could not open blendfile \"%s\"\n", path); - *err_str= err_local; - return false; - } - - main_newlib= (Main *)MEM_callocN( sizeof(Main), "BgeMain"); - C= CTX_create(); - CTX_data_main_set(C, main_newlib); - BKE_reports_init(&reports, RPT_STORE); + main_newlib = GetMainDynamicPath(path); - /* here appending/linking starts */ - main_tmp = BLO_library_append_begin(C, &bpy_openlib, (char *)path); - - names = BLO_blendhandle_get_datablock_names( bpy_openlib, idcode); - - int i=0; - LinkNode *n= names; - while(n) { - BLO_library_append_named_part(C, main_tmp, &bpy_openlib, (char *)n->link, idcode, 0); - n= (LinkNode *)n->next; - i++; + if (main_newlib == NULL) + { + bpy_openlib = BLO_blendhandle_from_file( (char *)path ); + if(bpy_openlib==NULL) { + snprintf(err_local, sizeof(err_local), "could not open blendfile \"%s\"\n", path); + *err_str= err_local; + return false; + } + + main_newlib= (Main *)MEM_callocN( sizeof(Main), "BgeMain"); + C= CTX_create(); + CTX_data_main_set(C, main_newlib); + BKE_reports_init(&reports, RPT_STORE); + + /* here appending/linking starts */ + main_tmp = BLO_library_append_begin(C, &bpy_openlib, (char *)path); + + names = BLO_blendhandle_get_datablock_names( bpy_openlib, idcode); + + int i=0; + LinkNode *n= names; + while(n) { + BLO_library_append_named_part(C, main_tmp, &bpy_openlib, (char *)n->link, idcode, 0); + n= (LinkNode *)n->next; + i++; + } + BLI_linklist_free(names, free); /* free linklist *and* each node's data */ + + BLO_library_append_end(C, main_tmp, &bpy_openlib, idcode, flag); + BLO_blendhandle_close(bpy_openlib); + + CTX_free(C); + BKE_reports_clear(&reports); + /* done linking */ + + /* needed for lookups*/ + GetMainDynamic().push_back(main_newlib); + strncpy(main_newlib->name, path, sizeof(main_newlib->name)); } - BLI_linklist_free(names, free); /* free linklist *and* each node's data */ - - BLO_library_append_end(C, main_tmp, &bpy_openlib, idcode, flag); - BLO_blendhandle_close(bpy_openlib); - - CTX_free(C); - BKE_reports_clear(&reports); - /* done linking */ - - /* needed for lookups*/ - GetMainDynamic().push_back(main_newlib); - strncpy(main_newlib->name, path, sizeof(main_newlib->name)); - if(idcode==ID_ME) { /* Convert all new meshes into BGE meshes */ @@ -1000,24 +999,39 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_S KX_Scene *kx_scene= m_currentScene; for(mesh= (ID *)main_newlib->mesh.first; mesh; mesh= (ID *)mesh->next ) { - RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, scene_merge, this); - kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj); + /* If item is defined, use it to filter meshes */ + if (!strcmp(filter, "") || !strcmp(filter, mesh->name+2)) + { + found = true; + RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, scene_merge, this); + kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj); + } } } else if(idcode==ID_SCE) { /* Merge all new linked in scene into the existing one */ ID *scene; for(scene= (ID *)main_newlib->scene.first; scene; scene= (ID *)scene->next ) { - printf("SceneName: %s\n", scene->name); - - /* merge into the base scene */ - KX_Scene* other= m_ketsjiEngine->CreateScene((Scene *)scene); - scene_merge->MergeScene(other); - - // RemoveScene(other); // Dont run this, it frees the entire scene converter data, just delete the scene - delete other; + /* If item is defined, use it to filter scenes */ + if (!strcmp(filter, "") || !strcmp(filter, scene->name+2)) + { + found = true; + printf("Loading scene: %s\n", scene->name+2); + /* merge into the base scene */ + KX_Scene* other= m_ketsjiEngine->CreateScene((Scene *)scene); + scene_merge->MergeScene(other); + + // RemoveScene(other); // Dont run this, it frees the entire scene converter data, just delete the scene + delete other; + } } } + + if (found == false) + { + printf("Item not found: %s\n", filter); + return false; + } return true; } -- cgit v1.2.3