reverting previous commit from Mitchell. His commit went to the trunk instead of the branch :)

svn merge -r 29067:29066 https://svn.blender.org/svnroot/bf-blender/trunk/blender
This commit is contained in:
Dalai Felinto
2010-05-29 21:31:57 +00:00
parent 9d3157eed0
commit c6bec43330
29 changed files with 251 additions and 383 deletions

View File

@@ -932,7 +932,7 @@ Main* KX_BlenderSceneConverter::GetMainDynamicPath(const char *path)
return NULL;
}
bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, char *filter, KX_Scene *scene_merge, char **err_str)
bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_Scene *scene_merge, char **err_str)
{
bContext *C;
Main *main_newlib; /* stored as a dynamic 'main' until we free it */
@@ -941,7 +941,6 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, char
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];
@@ -950,48 +949,50 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, char
snprintf(err_local, sizeof(err_local), "invalid ID type given \"%s\"\n", group);
return false;
}
main_newlib = GetMainDynamicPath(path);
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));
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);
/* 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));
if(idcode==ID_ME) {
/* Convert all new meshes into BGE meshes */
@@ -999,39 +1000,24 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, char
KX_Scene *kx_scene= m_currentScene;
for(mesh= (ID *)main_newlib->mesh.first; mesh; mesh= (ID *)mesh->next ) {
/* 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);
}
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 ) {
/* 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;
}
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 (found == false)
{
printf("Item not found: %s\n", filter);
return false;
}
return true;
}