static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from) { SpaceNode *snode = CTX_wm_space_node(C); Scene *scene = CTX_data_scene(C); Object *ob = OBACT; if ((snode->shaderfrom == SNODE_SHADER_OBJECT) || (BKE_scene_use_new_shading_nodes(scene) == false)) { if (ob) { *r_from = &ob->id; if (ob->type == OB_LAMP) { *r_id = ob->data; *r_ntree = ((Lamp *)ob->data)->nodetree; } else { Material *ma = give_current_material(ob, ob->actcol); if (ma) { *r_id = &ma->id; *r_ntree = ma->nodetree; } } } } #ifdef WITH_FREESTYLE else if (snode->shaderfrom == SNODE_SHADER_LINESTYLE) { FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene); if (linestyle) { *r_from = NULL; *r_id = &linestyle->id; *r_ntree = linestyle->nodetree; } } #endif else { /* SNODE_SHADER_WORLD */ if (scene->world) { *r_from = NULL; *r_id = &scene->world->id; *r_ntree = scene->world->nodetree; } } }
static int buttons_context_path_linestyle(ButsContextPath *path) { Scene *scene; FreestyleLineStyle *linestyle; PointerRNA *ptr = &path->ptr[path->len - 1]; /* if we already have a (pinned) linestyle, we're done */ if (RNA_struct_is_a(ptr->type, &RNA_FreestyleLineStyle)) { return 1; } /* if we have a scene, use the lineset's linestyle */ else if (buttons_context_path_scene(path)) { scene = path->ptr[path->len - 1].data; linestyle = BKE_linestyle_active_from_scene(scene); if (linestyle) { RNA_id_pointer_create(&linestyle->id, &path->ptr[path->len]); path->len++; return 1; } } /* no path to a linestyle possible */ return 0; }
static void buttons_texture_users_from_context(ListBase *users, const bContext *C, SpaceButs *sbuts) { Scene *scene = NULL; Object *ob = NULL; Material *ma = NULL; Lamp *la = NULL; World *wrld = NULL; FreestyleLineStyle *linestyle = NULL; Brush *brush = NULL; ID *pinid = sbuts->pinid; bool limited_mode = (sbuts->flag & SB_TEX_USER_LIMITED) != 0; /* get data from context */ if (pinid) { if (GS(pinid->name) == ID_SCE) scene = (Scene *)pinid; else if (GS(pinid->name) == ID_OB) ob = (Object *)pinid; else if (GS(pinid->name) == ID_LA) la = (Lamp *)pinid; else if (GS(pinid->name) == ID_WO) wrld = (World *)pinid; else if (GS(pinid->name) == ID_MA) ma = (Material *)pinid; else if (GS(pinid->name) == ID_BR) brush = (Brush *)pinid; else if (GS(pinid->name) == ID_LS) linestyle = (FreestyleLineStyle *)pinid; } if (!scene) scene = CTX_data_scene(C); if (!(pinid || pinid == &scene->id)) { ob = (scene->basact) ? scene->basact->object : NULL; wrld = scene->world; brush = BKE_paint_brush(BKE_paint_get_active_from_context(C)); linestyle = BKE_linestyle_active_from_scene(scene); } if (ob && ob->type == OB_LAMP && !la) la = ob->data; if (ob && !ma) ma = give_current_material(ob, ob->actcol); /* fill users */ BLI_listbase_clear(users); if (ma && !limited_mode) buttons_texture_users_find_nodetree(users, &ma->id, ma->nodetree, "Material"); if (la && !limited_mode) buttons_texture_users_find_nodetree(users, &la->id, la->nodetree, "Lamp"); if (wrld && !limited_mode) buttons_texture_users_find_nodetree(users, &wrld->id, wrld->nodetree, "World"); if (linestyle && !limited_mode) buttons_texture_users_find_nodetree(users, &linestyle->id, linestyle->nodetree, "Line Style"); if (ob) { ParticleSystem *psys = psys_get_current(ob); MTex *mtex; int a; /* modifiers */ modifiers_foreachTexLink(ob, buttons_texture_modifier_foreach, users); /* particle systems */ if (psys && !limited_mode) { for (a = 0; a < MAX_MTEX; a++) { mtex = psys->part->mtex[a]; if (mtex) { PointerRNA ptr; PropertyRNA *prop; RNA_pointer_create(&psys->part->id, &RNA_ParticleSettingsTextureSlot, mtex, &ptr); prop = RNA_struct_find_property(&ptr, "texture"); buttons_texture_user_property_add(users, &psys->part->id, ptr, prop, "Particles", RNA_struct_ui_icon(&RNA_ParticleSettings), psys->name); } } } /* field */ if (ob->pd && ob->pd->forcefield == PFIELD_TEXTURE) { PointerRNA ptr; PropertyRNA *prop; RNA_pointer_create(&ob->id, &RNA_FieldSettings, ob->pd, &ptr); prop = RNA_struct_find_property(&ptr, "texture"); buttons_texture_user_property_add(users, &ob->id, ptr, prop, "Fields", ICON_FORCE_TEXTURE, "Texture Field"); } } /* brush */ if (brush) { PointerRNA ptr; PropertyRNA *prop; /* texture */ RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mtex, &ptr); prop = RNA_struct_find_property(&ptr, "texture"); buttons_texture_user_property_add(users, &brush->id, ptr, prop, "Brush", ICON_BRUSH_DATA, "Brush"); /* mask texture */ RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mask_mtex, &ptr); prop = RNA_struct_find_property(&ptr, "texture"); buttons_texture_user_property_add(users, &brush->id, ptr, prop, "Brush", ICON_BRUSH_DATA, "Brush Mask"); } }
static void texture_get_from_context(const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from) { SpaceNode *snode = CTX_wm_space_node(C); Scene *scene = CTX_data_scene(C); Object *ob = OBACT; Tex *tx = NULL; if (snode->texfrom == SNODE_TEX_OBJECT) { if (ob) { tx = give_current_object_texture(ob); if (tx) { if (ob->type == OB_LAMP) *r_from = (ID *)ob->data; else *r_from = (ID *)give_current_material(ob, ob->actcol); /* from is not set fully for material nodes, should be ID + Node then */ *r_id = &tx->id; *r_ntree = tx->nodetree; } } } else if (snode->texfrom == SNODE_TEX_WORLD) { if (scene->world) { *r_from = (ID *)scene->world; tx = give_current_world_texture(scene->world); if (tx) { *r_id = &tx->id; *r_ntree = tx->nodetree; } } } else if (snode->texfrom == SNODE_TEX_BRUSH) { struct Brush *brush = NULL; if (ob && (ob->mode & OB_MODE_SCULPT)) brush = BKE_paint_brush(&scene->toolsettings->sculpt->paint); else brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint); if (brush) { *r_from = (ID *)brush; tx = give_current_brush_texture(brush); if (tx) { *r_id = &tx->id; *r_ntree = tx->nodetree; } } } else if (snode->texfrom == SNODE_TEX_LINESTYLE) { FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene); if (linestyle) { *r_from = (ID *)linestyle; tx = give_current_linestyle_texture(linestyle); if (tx) { *r_id = &tx->id; *r_ntree = tx->nodetree; } } } }