コード例 #1
0
ファイル: filelist.c プロジェクト: bitfusionio/blender
static int groupname_to_code(const char *group)
{
	char buf[BLO_GROUP_MAX];
	char *lslash;

	BLI_strncpy(buf, group, sizeof(buf));
	lslash = (char *)BLI_last_slash(buf);
	if (lslash)
		lslash[0] = '\0';

	return buf[0] ? BKE_idcode_from_name(buf) : 0;
}
コード例 #2
0
static int groupname_to_code(const char *group)
{
	char buf[32];
	char *lslash;
	
	BLI_strncpy(buf, group, sizeof(buf));
	lslash= BLI_last_slash(buf);
	if (lslash)
		lslash[0]= '\0';

	return BKE_idcode_from_name(buf);
}
コード例 #3
0
bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options)
{
	Main *main_newlib; /* stored as a dynamic 'main' until we free it */
	Main *main_tmp= NULL; /* created only for linking, then freed */
	LinkNode *names = NULL;
	int idcode= BKE_idcode_from_name(group);
	short flag= 0; /* don't need any special options */
	ReportList reports;
	static char err_local[255];
	
	/* 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;
	}
	
	if (GetMainDynamicPath(path)) {
		snprintf(err_local, sizeof(err_local), "blend file already open \"%s\"\n", path);
		*err_str= err_local;
		BLO_blendhandle_close(bpy_openlib);
		return false;
	}

	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");
	BKE_reports_init(&reports, RPT_STORE);	

	/* here appending/linking starts */
	main_tmp = BLO_library_append_begin(main_newlib, &bpy_openlib, (char *)path);

	int totnames_dummy;
	names = BLO_blendhandle_get_datablock_names( bpy_openlib, idcode, &totnames_dummy);
	
	int i=0;
	LinkNode *n= names;
	while(n) {
		BLO_library_append_named_part(main_tmp, &bpy_openlib, (char *)n->link, idcode);
		n= (LinkNode *)n->next;
		i++;
	}
	BLI_linklist_free(names, free);	/* free linklist *and* each node's data */
	
	BLO_library_append_end(NULL, 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(main_newlib, &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(main_tmp, &bpy_openlib, (char *)n->link, ID_AC);
			n= (LinkNode *)n->next;
			i++;
		}
		BLI_linklist_free(names, free);	/* free linklist *and* each node's data */
	
		BLO_library_append_end(NULL, main_tmp, &bpy_openlib, ID_AC, flag);
	}
	
	BLO_blendhandle_close(bpy_openlib);

	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 */
		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);
		}
	}
	else if (idcode==ID_AC) {
		/* Convert all 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);
		}
	}
	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 (options & LIB_LOAD_VERBOSE)
				printf("SceneName: %s\n", scene->name+2);
			
			/* merge into the base  scene */
			KX_Scene* other= m_ketsjiEngine->CreateScene((Scene *)scene);
			scene_merge->MergeScene(other);
			
			// RemoveScene(other); // Don't 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;
}
コード例 #4
0
KX_LibLoadStatus *KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options)
{
	Main *main_newlib; /* stored as a dynamic 'main' until we free it */
	const int idcode = BKE_idcode_from_name(group);
	ReportList reports;
	static char err_local[255];

//	TIMEIT_START(bge_link_blend_file);

	KX_LibLoadStatus *status;

	/* 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 NULL;
	}
	
	if (GetMainDynamicPath(path)) {
		snprintf(err_local, sizeof(err_local), "blend file already open \"%s\"\n", path);
		*err_str = err_local;
		BLO_blendhandle_close(bpy_openlib);
		return NULL;
	}

	if (bpy_openlib == NULL) {
		snprintf(err_local, sizeof(err_local), "could not open blendfile \"%s\"\n", path);
		*err_str = err_local;
		return NULL;
	}

	main_newlib = BKE_main_new();
	BKE_reports_init(&reports, RPT_STORE);

	short flag = 0; /* don't need any special options */
	/* created only for linking, then freed */
	Main *main_tmp = BLO_library_link_begin(main_newlib, &bpy_openlib, (char *)path);

	load_datablocks(main_tmp, bpy_openlib, path, idcode);

	if (idcode == ID_SCE && options & LIB_LOAD_LOAD_SCRIPTS) {
		load_datablocks(main_tmp, bpy_openlib, path, ID_TXT);
	}

	/* now do another round of linking for Scenes so all actions are properly loaded */
	if (idcode == ID_SCE && options & LIB_LOAD_LOAD_ACTIONS) {
		load_datablocks(main_tmp, bpy_openlib, path, ID_AC);
	}

	BLO_library_link_end(main_tmp, &bpy_openlib, flag, NULL, NULL);

	BLO_blendhandle_close(bpy_openlib);

	BKE_reports_clear(&reports);
	/* done linking */
	
	/* needed for lookups*/
	GetMainDynamic().push_back(main_newlib);
	BLI_strncpy(main_newlib->name, path, sizeof(main_newlib->name));
	
	
	status = new KX_LibLoadStatus(this, m_ketsjiEngine, scene_merge, path);

	if (idcode == ID_ME) {
		/* Convert all new meshes into BGE meshes */
		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, false); // For now only use the libloading option for scenes, which need to handle materials/shaders
			scene_merge->GetLogicManager()->RegisterMeshName(meshobj->GetName(), meshobj);
		}
	}
	else if (idcode == ID_AC) {
		/* Convert all 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);
		}
	}
	else if (idcode == ID_SCE) {
		/* Merge all new linked in scene into the existing one */
		ID *scene;
		// scenes gets deleted by the thread when it's done using it (look in async_convert())
		vector<Scene *> *scenes = (options & LIB_LOAD_ASYNC) ? new vector<Scene *>() : NULL;

		for (scene = (ID *)main_newlib->scene.first; scene; scene = (ID *)scene->next ) {
			if (options & LIB_LOAD_VERBOSE)
				printf("SceneName: %s\n", scene->name + 2);
			
			if (options & LIB_LOAD_ASYNC) {
				scenes->push_back((Scene *)scene);
			} 
			else {
				/* merge into the base  scene */
				KX_Scene* other = m_ketsjiEngine->CreateScene((Scene *)scene, true);
				scene_merge->MergeScene(other);
			
				// RemoveScene(other); // Don't run this, it frees the entire scene converter data, just delete the scene
				delete other;
			}
		}

		if (options & LIB_LOAD_ASYNC) {
			status->SetData(scenes);
			BLI_task_pool_push(m_threadinfo->m_pool, async_convert, (void *)status, false, TASK_PRIORITY_LOW);
		}

#ifdef WITH_PYTHON
		/* Handle any text datablocks */
		if (options & LIB_LOAD_LOAD_SCRIPTS)
			addImportMain(main_newlib);
#endif

		/* 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);
			}
		}
	}

	if (!(options & LIB_LOAD_ASYNC))
		status->Finish();

//	TIMEIT_END(bge_link_blend_file);

	m_status_map[main_newlib->name] = status;
	return status;
}