/* make sure path names are correct for OS */ static void clean_paths(Main *main) { Scene *scene; BKE_bpath_traverse_main(main, clean_paths_visit_cb, BKE_BPATH_TRAVERSE_SKIP_MULTIFILE, NULL); for (scene = main->scene.first; scene; scene = scene->id.next) { BLI_path_native_slash(scene->r.pic); } }
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ static void mat_livedb_draw_mat_preview(uiBlock *block, Scene *scene, ARegion *ar, SpaceLDB *slivedb, ListBase *lb) { LiveDbTreeElement *te; char *file_path = (char*)BKE_appdir_folder_id_create(BLENDER_USER_DATAFILES, 0); strcat(file_path, "/livedb/"); strcat(file_path, slivedb->server_address); strcat(file_path, "/previews/"); BLI_path_native_slash(file_path); BLI_dir_create_recursive(file_path); for (te = lb->first; te; te = te->next) { if (TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_MATERIAL && te->ys + 2 * MAT_LIVEDB_UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) { unsigned int width, height; char* buf = mat_livedb_get_mat_preview(slivedb->server_address, te->item->mat_item.id, &width, &height, file_path); if(buf) { if(width && height) { glEnable(GL_BLEND); glColor4f(0.0, 0.0, 0.0, 0.0); if (width != UI_UNIT_X || height != (MAT_LIVEDB_UI_UNIT_Y - 2)) { float facx = (float)(MAT_LIVEDB_UI_UNIT_Y - 2) / (float)width; float facy = (float)(MAT_LIVEDB_UI_UNIT_Y - 2) / (float)height; glPixelZoom(facx, facy); } glaDrawPixelsAuto((float)(ar->v2d.cur.xmax - MAT_LIVEDB_UI_UNIT_Y - 1), (float)te->ys + 1, width, height, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, buf); glPixelZoom(1.0f, 1.0f); glDisable(GL_BLEND); } MEM_freeN(buf); } } else if (MAT_LIVEDB_ELEM_OPEN(te, slivedb)) mat_livedb_draw_mat_preview(block, scene, ar, slivedb, &te->subtree); } } /* mat_livedb_draw_mat_preview() */
static bool clean_paths_visit_cb(void *UNUSED(userdata), char *path_dst, const char *path_src) { strcpy(path_dst, path_src); BLI_path_native_slash(path_dst); return !STREQ(path_dst, path_src); }
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */ static void get_material_startjob(void *customdata, short *stop, short *do_update, float *progress) { Main *bmain; bContext *C; bNodeTree *ntree; MatItem *items; uint32_t buf_size; GetMaterialJob *mj = customdata; mj->stop = stop; mj->do_update = do_update; mj->progress = progress; ntree = mj->ntree; bmain = mj->bmain; C = mj->C; *progress = 0.1f; items = mat_livedb_get_material(mj->address, mj->mat_id, &buf_size); *progress = 0.9f; if(items) { bNode *node, *next; MatItem *cur_item = items; bNode *node_to; bNodeSocket *sock_to; char file_path[FILE_MAX]; float cur_y_pos = 0; /* Remove all existing nodes */ ED_preview_kill_jobs(CTX_wm_manager(C), bmain); for (node = ntree->nodes.first; node; node = next) { next = node->next; /* check id user here, nodeFreeNode is called for free dbase too */ if (node->id) node->id->us--; nodeFreeNode(ntree, node); } ntreeUpdateTree(bmain, ntree); node_to = nodeAddNode(C, ntree, "ShaderNodeOutputMaterial"); node_to->locx = 0; node_to->locy = 0; for (sock_to = node_to->inputs.first; sock_to; sock_to = sock_to->next) { if(!sock_to || strcmp(sock_to->name, "Surface")) continue; break; } /* create file path */ if(!strlen(G.main->name)) { char *cur_path = (char*)BKE_appdir_folder_id_create(BLENDER_USER_DATAFILES, 0); strcpy(file_path, cur_path); strcat(file_path, "/livedb/"); } else { BLI_strncpy(file_path, "//livedb/", sizeof(file_path)); BLI_path_abs(file_path, G.main->name); } strcat(file_path, mj->address); strcat(file_path, "/textures/"); BLI_path_native_slash(file_path); BLI_dir_create_recursive(file_path); mat_livedb_add_mat_element(bmain, C, ntree, node_to, sock_to, &cur_item, file_path, 0, &cur_y_pos); ED_node_tree_update(C); ED_node_tag_update_nodetree(bmain, ntree, 0); MEM_freeN(items); } *do_update = 1; *stop = 0; *progress = 1.0f; return; } /* get_material_job() */