diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 411844841de..99cd30c76ed 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -932,23 +932,23 @@ Main* KX_BlenderSceneConverter::GetMainDynamicPath(const char *path) return NULL; } -bool KX_BlenderSceneConverter::LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str) +bool KX_BlenderSceneConverter::LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options) { BlendHandle *bpy_openlib = BLO_blendhandle_from_memory(data, length); // Error checking is done in LinkBlendFile - return LinkBlendFile(bpy_openlib, path, group, scene_merge, err_str); + return LinkBlendFile(bpy_openlib, path, group, scene_merge, err_str, options); } -bool KX_BlenderSceneConverter::LinkBlendFilePath(const char *path, char *group, KX_Scene *scene_merge, char **err_str) +bool KX_BlenderSceneConverter::LinkBlendFilePath(const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options) { BlendHandle *bpy_openlib = BLO_blendhandle_from_file((char *)path, NULL); // Error checking is done in LinkBlendFile - return LinkBlendFile(bpy_openlib, path, group, scene_merge, err_str); + return LinkBlendFile(bpy_openlib, path, group, scene_merge, err_str, options); } -bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str) +bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options) { bContext *C; Main *main_newlib; /* stored as a dynamic 'main' until we free it */ @@ -962,6 +962,7 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha /* only scene and mesh supported right now */ if(idcode!=ID_SCE && idcode!=ID_ME &&idcode!=ID_AC) { snprintf(err_local, sizeof(err_local), "invalid ID type given \"%s\"\n", group); + *err_str= err_local; BLO_blendhandle_close(bpy_openlib); return false; } @@ -1000,6 +1001,26 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha BLI_linklist_free(names, free); /* free linklist *and* each node's data */ BLO_library_append_end(C, main_tmp, &bpy_openlib, idcode, flag); + + /* now do another round of linking for Scenes so all actions are properly loaded */ + if (idcode==ID_SCE && options & LIB_LOAD_LOAD_ACTIONS) { + main_tmp = BLO_library_append_begin(C, &bpy_openlib, (char *)path); + + int totnames_dummy; + names = BLO_blendhandle_get_datablock_names( bpy_openlib, ID_AC, &totnames_dummy); + + int i=0; + LinkNode *n= names; + while(n) { + BLO_library_append_named_part(C, main_tmp, &bpy_openlib, (char *)n->link, ID_AC, 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, ID_AC, flag); + } + BLO_blendhandle_close(bpy_openlib); CTX_free(C); @@ -1016,6 +1037,8 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha ID* mesh; for(mesh= (ID *)main_newlib->mesh.first; mesh; mesh= (ID *)mesh->next ) { + if (options & LIB_LOAD_VERBOSE) + printf("MeshName: %s\n", mesh->name+2); RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, scene_merge, this); scene_merge->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj); } @@ -1025,7 +1048,8 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha ID *action; for(action= (ID *)main_newlib->action.first; action; action= (ID *)action->next) { - printf("ActionName: %s\n", action->name); + if (options & LIB_LOAD_VERBOSE) + printf("ActionName: %s\n", action->name+2); scene_merge->GetLogicManager()->RegisterActionName(action->name+2, action); } } @@ -1033,7 +1057,8 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha /* 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); + if (options & LIB_LOAD_VERBOSE) + printf("SceneName: %s\n", scene->name+2); /* merge into the base scene */ KX_Scene* other= m_ketsjiEngine->CreateScene((Scene *)scene); @@ -1042,6 +1067,17 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha // RemoveScene(other); // Dont run this, it frees the entire scene converter data, just delete the scene delete other; } + + /* Now handle all the actions */ + if (options & LIB_LOAD_LOAD_ACTIONS) { + ID *action; + + for(action= (ID *)main_newlib->action.first; action; action= (ID *)action->next) { + if (options & LIB_LOAD_VERBOSE) + printf("ActionName: %s\n", action->name+2); + scene_merge->GetLogicManager()->RegisterActionName(action->name+2, action); + } + } } return true; diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index f99ed3aa412..741b3ea8757 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -147,9 +147,9 @@ public: struct Main* GetMainDynamicPath(const char *path); vector &GetMainDynamic(); - bool LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str); - bool LinkBlendFilePath(const char *path, char *group, KX_Scene *scene_merge, char **err_str); - bool LinkBlendFile(struct BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str); + bool LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options); + bool LinkBlendFilePath(const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options); + bool LinkBlendFile(struct BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options); bool MergeScene(KX_Scene *to, KX_Scene *from); RAS_MeshObject *ConvertMeshSpecial(KX_Scene* kx_scene, Main *maggie, const char *name); bool FreeBlendFile(struct Main *maggie); @@ -176,6 +176,13 @@ public: #endif // /printf("\t m_ketsjiEngine->m_scenes: %d\n", m_ketsjiEngine->CurrentScenes()->size()); } + + /* LibLoad Options */ + enum + { + LIB_LOAD_LOAD_ACTIONS = 1, + LIB_LOAD_VERBOSE = 2, + }; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 95831b38bfa..ad3f4b06323 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -638,7 +638,7 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *) Py_RETURN_NONE; } -static PyObject *gLibLoad(PyObject*, PyObject* args) +static PyObject *gLibLoad(PyObject*, PyObject* args, PyObject* kwds) { KX_Scene *kx_scene= gp_KetsjiScene; char *path; @@ -646,10 +646,22 @@ static PyObject *gLibLoad(PyObject*, PyObject* args) Py_buffer py_buffer; py_buffer.buf = NULL; char *err_str= NULL; + + short options=0; + int load_actions=0, verbose=0; + + static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", NULL}; - if (!PyArg_ParseTuple(args,"ss|y*:LibLoad",&path, &group, &py_buffer)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*ii:LibLoad", const_cast(kwlist), + &path, &group, &py_buffer, &load_actions, &verbose)) return NULL; + /* setup options */ + if (load_actions != 0) + options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_ACTIONS; + if (verbose != 0) + options |= KX_BlenderSceneConverter::LIB_LOAD_VERBOSE; + if (!py_buffer.buf) { char abs_path[FILE_MAX]; @@ -657,14 +669,14 @@ static PyObject *gLibLoad(PyObject*, PyObject* args) BLI_strncpy(abs_path, path, sizeof(abs_path)); BLI_path_abs(abs_path, gp_GamePythonPath); - if(kx_scene->GetSceneConverter()->LinkBlendFilePath(abs_path, group, kx_scene, &err_str)) { + if(kx_scene->GetSceneConverter()->LinkBlendFilePath(abs_path, group, kx_scene, &err_str, options)) { Py_RETURN_TRUE; } } else { - if(kx_scene->GetSceneConverter()->LinkBlendFileMemory(py_buffer.buf, py_buffer.len, path, group, kx_scene, &err_str)) { + if(kx_scene->GetSceneConverter()->LinkBlendFileMemory(py_buffer.buf, py_buffer.len, path, group, kx_scene, &err_str, options)) { PyBuffer_Release(&py_buffer); Py_RETURN_TRUE; } @@ -798,7 +810,7 @@ static struct PyMethodDef game_methods[] = { {"PrintMemInfo", (PyCFunction)pyPrintStats, METH_NOARGS, (const char *)"Print engine stastics"}, /* library functions */ - {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS, (const char *)""}, + {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""}, {"LibNew", (PyCFunction)gLibNew, METH_VARARGS, (const char *)""}, {"LibFree", (PyCFunction)gLibFree, METH_VARARGS, (const char *)""}, {"LibList", (PyCFunction)gLibList, METH_VARARGS, (const char *)""},