Пример #1
0
static void buttons_texture_modifier_foreach(void *userData, Object *ob, ModifierData *md, const char *propname)
{
    PointerRNA ptr;
    PropertyRNA *prop;
    ListBase *users = userData;

    RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr);
    prop = RNA_struct_find_property(&ptr, propname);

    buttons_texture_user_property_add(users, &ob->id, ptr, prop,
                                      "Modifiers", RNA_struct_ui_icon(ptr.type), md->name);
}
Пример #2
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;
    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;
    }

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

    if (ob && ob->type == OB_LAMP && !la)
        la = ob->data;
    if (ob && !ma)
        ma = give_current_material(ob, ob->actcol);

    /* fill users */
    users->first = users->last = NULL;

    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 (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");
    }
}
Пример #3
0
static void buttons_texture_users_from_context(ListBase *users,
                                               const bContext *C,
                                               SpaceProperties *sbuts)
{
  Scene *scene = NULL;
  Object *ob = 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_BR) {
      brush = (Brush *)pinid;
    }
    else if (GS(pinid->name) == ID_LS) {
      linestyle = (FreestyleLineStyle *)pinid;
    }
  }

  if (!scene) {
    scene = CTX_data_scene(C);
  }

  const ID_Type id_type = pinid != NULL ? GS(pinid->name) : -1;
  if (!pinid || id_type == ID_SCE) {
    wmWindow *win = CTX_wm_window(C);
    ViewLayer *view_layer = (win->scene == scene) ? WM_window_get_active_view_layer(win) :
                                                    BKE_view_layer_default_view(scene);

    brush = BKE_paint_brush(BKE_paint_get_active_from_context(C));
    linestyle = BKE_linestyle_active_from_view_layer(view_layer);
    ob = OBACT(view_layer);
  }

  /* fill users */
  BLI_listbase_clear(users);

  if (linestyle && !limited_mode) {
    buttons_texture_users_find_nodetree(
        users, &linestyle->id, linestyle->nodetree, N_("Line Style"));
  }

  if (ob) {
    ParticleSystem *psys = psys_get_current(ob);
    MTex *mtex;
    int a;

    /* modifiers */
    modifiers_foreachTexLink(ob, buttons_texture_modifier_foreach, users);

    /* grease pencil modifiers */
    BKE_gpencil_modifiers_foreachTexLink(ob, buttons_texture_modifier_gpencil_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,
                                            N_("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, N_("Fields"), ICON_FORCE_TEXTURE, IFACE_("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, N_("Brush"), ICON_BRUSH_DATA, IFACE_("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, N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush Mask"));
  }
}