Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2013-05-17 11:10:10 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2013-05-17 11:10:10 +0400
commit9d567dd3662e5d79c98c64829f3d039e75697395 (patch)
treeaf8b0cd080b62b72f24729df0e15d3f38d61f64a /source/blender/editors/space_buttons/buttons_texture.c
parent308d014b498be3aaf3fd74aeee0ed52947d0b6cc (diff)
This commit addresses the somewhat weak handling of stackless textures in Blender with default (BI) renderer. To do so, it's defining an "other" texture context, and when in this one, it switches to using the "new shading" texture handling already known with Cycles engine.
So now, in the new "other" tex context, you can (depending on active data) have direct access to modifiers', force's or brushes' textures... I also refactored a bit how texture contexts are handled (once again, we had some quite similar code in both space_buttons and RNA sources). This should also solve some harmless glitches like "no texture context selected in UI" sometimes when you remove data related to current texture (see e.g. after removing the material from default cube, in startup scene). This usage of two different systems for textures, and the handling of switches between them, has been a bit tricky to get working right, but it is OK now I think. I also had to add a bool flag to buttons space, SB_TEX_USER_LIMITED (use_limited_texture_context in RNA), which indicates "new shading" texture code whether it has to ignore materials, lamps etc. (BI) or not (Cycles). Btw, pinned textures from modifiers/force/etc. were also broken (showing nothing), now it should work too. Thanks to Brecht for reviewing.
Diffstat (limited to 'source/blender/editors/space_buttons/buttons_texture.c')
-rw-r--r--source/blender/editors/space_buttons/buttons_texture.c178
1 files changed, 146 insertions, 32 deletions
diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c
index 682e6ee2225..34ce81c3af8 100644
--- a/source/blender/editors/space_buttons/buttons_texture.c
+++ b/source/blender/editors/space_buttons/buttons_texture.c
@@ -65,6 +65,7 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "ED_buttons.h"
#include "ED_node.h"
#include "ED_screen.h"
@@ -72,6 +73,109 @@
#include "buttons_intern.h" // own include
+/****************** "Old Shading" Texture Context ****************/
+
+bool ED_texture_context_check_world(const bContext *C)
+{
+ Scene *scene = CTX_data_scene(C);
+ return (scene && scene->world);
+}
+
+bool ED_texture_context_check_material(const bContext *C)
+{
+ Object *ob = CTX_data_active_object(C);
+ return (ob && (ob->totcol != 0));
+}
+
+bool ED_texture_context_check_lamp(const bContext *C)
+{
+ Object *ob = CTX_data_active_object(C);
+ return (ob && (ob->type == OB_LAMP));
+}
+
+bool ED_texture_context_check_particles(const bContext *C)
+{
+ Object *ob = CTX_data_active_object(C);
+ return (ob && ob->particlesystem.first);
+}
+
+static void texture_context_check_modifier_foreach(void *userData, Object *UNUSED(ob), ModifierData *UNUSED(md),
+ const char *UNUSED(propname))
+{
+ *((bool *)userData) = true;
+}
+
+bool ED_texture_context_check_others(const bContext *C)
+{
+ /* We cannot rely on sbuts->texuser here, as it is NULL when in "old" tex handling, non-OTHERS tex context. */
+ Object *ob = CTX_data_active_object(C);
+
+ /* object */
+ if (ob) {
+ /* Tex force field. */
+ if (ob->pd && ob->pd->forcefield == PFIELD_TEXTURE) {
+ return true;
+ }
+
+ /* modifiers */
+ {
+ bool check = false;
+ modifiers_foreachTexLink(ob, texture_context_check_modifier_foreach, &check);
+ if (check) {
+ return true;
+ }
+ }
+ }
+
+ /* brush */
+ if (BKE_paint_brush(BKE_paint_get_active_from_context(C))) {
+ return true;
+ }
+
+ return false;
+}
+
+/* Only change texture context if current one is invalid! */
+void buttons_check_texture_context(const bContext *C, SpaceButs *sbuts)
+{
+ Scene *scene = CTX_data_scene(C);
+
+ if (BKE_scene_use_new_shading_nodes(scene)) {
+ return; /* No texture context in new shading mode */
+ }
+
+ {
+ bool valid_world = ED_texture_context_check_world(C);
+ bool valid_material = ED_texture_context_check_material(C);
+ bool valid_lamp = ED_texture_context_check_lamp(C);
+ bool valid_particles = ED_texture_context_check_particles(C);
+ bool valid_others = ED_texture_context_check_others(C);
+
+ if (((sbuts->texture_context == SB_TEXC_WORLD) && !valid_world) ||
+ ((sbuts->texture_context == SB_TEXC_MATERIAL) && !valid_material) ||
+ ((sbuts->texture_context == SB_TEXC_LAMP) && !valid_lamp) ||
+ ((sbuts->texture_context == SB_TEXC_PARTICLES) && !valid_particles) ||
+ ((sbuts->texture_context == SB_TEXC_OTHER) && !valid_others))
+ {
+ if (valid_others) {
+ sbuts->texture_context = SB_TEXC_OTHER;
+ }
+ else if (valid_world) {
+ sbuts->texture_context = SB_TEXC_WORLD;
+ }
+ else if (valid_material) {
+ sbuts->texture_context = SB_TEXC_MATERIAL;
+ }
+ else if (valid_lamp) {
+ sbuts->texture_context = SB_TEXC_LAMP;
+ }
+ else if (valid_particles) {
+ sbuts->texture_context = SB_TEXC_PARTICLES;
+ }
+ }
+ }
+}
+
/************************* Texture User **************************/
static void buttons_texture_user_property_add(ListBase *users, ID *id,
@@ -154,6 +258,7 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
World *wrld = NULL;
Brush *brush = NULL;
ID *pinid = sbuts->pinid;
+ bool limited_mode = sbuts->flag & SB_TEX_USER_LIMITED;
/* get data from context */
if (pinid) {
@@ -173,7 +278,7 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
if (!scene)
scene = CTX_data_scene(C);
-
+
if (!(pinid || pinid == &scene->id)) {
ob = (scene->basact) ? scene->basact->object : NULL;
wrld = scene->world;
@@ -188,11 +293,11 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
/* fill users */
users->first = users->last = NULL;
- if (ma)
+ if (ma && !limited_mode)
buttons_texture_users_find_nodetree(users, &ma->id, ma->nodetree, "Material");
- if (la)
+ if (la && !limited_mode)
buttons_texture_users_find_nodetree(users, &la->id, la->nodetree, "Lamp");
- if (wrld)
+ if (wrld && !limited_mode)
buttons_texture_users_find_nodetree(users, &wrld->id, wrld->nodetree, "World");
if (ob) {
@@ -204,7 +309,7 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
modifiers_foreachTexLink(ob, buttons_texture_modifier_foreach, users);
/* particle systems */
- if (psys) {
+ if (psys && !limited_mode) {
for (a = 0; a < MAX_MTEX; a++) {
mtex = psys->part->mtex[a];
@@ -261,14 +366,17 @@ void buttons_texture_context_compute(const bContext *C, SpaceButs *sbuts)
* properties editor, before the buttons are created. */
ButsContextTexture *ct = sbuts->texuser;
Scene *scene = CTX_data_scene(C);
+ ID *pinid = sbuts->pinid;
+
+ buttons_check_texture_context(C, sbuts);
- if (!BKE_scene_use_new_shading_nodes(scene)) {
+ if (!(BKE_scene_use_new_shading_nodes(scene) || (sbuts->texture_context == SB_TEXC_OTHER))) {
if (ct) {
BLI_freelistN(&ct->users);
MEM_freeN(ct);
sbuts->texuser = NULL;
}
-
+
return;
}
@@ -282,35 +390,41 @@ void buttons_texture_context_compute(const bContext *C, SpaceButs *sbuts)
buttons_texture_users_from_context(&ct->users, C, sbuts);
- /* set one user as active based on active index */
- if (ct->index >= BLI_countlist(&ct->users))
- ct->index = 0;
+ if (pinid && GS(pinid->name) == ID_TE) {
+ ct->user = NULL;
+ ct->texture = (Tex *)pinid;
+ }
+ else {
+ /* set one user as active based on active index */
+ if (ct->index >= BLI_countlist(&ct->users))
+ ct->index = 0;
- ct->user = BLI_findlink(&ct->users, ct->index);
- ct->texture = NULL;
+ ct->user = BLI_findlink(&ct->users, ct->index);
+ ct->texture = NULL;
- if (ct->user) {
- if (ct->user->ptr.data) {
- PointerRNA texptr;
- Tex *tex;
+ if (ct->user) {
+ if (ct->user->ptr.data) {
+ PointerRNA texptr;
+ Tex *tex;
- /* get texture datablock pointer if it's a property */
- texptr = RNA_property_pointer_get(&ct->user->ptr, ct->user->prop);
- tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL;
+ /* get texture datablock pointer if it's a property */
+ texptr = RNA_property_pointer_get(&ct->user->ptr, ct->user->prop);
+ tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL;
- ct->texture = tex;
- }
- else if (ct->user->node && !(ct->user->node->flag & NODE_ACTIVE_TEXTURE)) {
- ButsTextureUser *user;
-
- /* detect change of active texture node in same node tree, in that
- * case we also automatically switch to the other node */
- for (user = ct->users.first; user; user = user->next) {
- if (user->ntree == ct->user->ntree && user->node != ct->user->node) {
- if (user->node->flag & NODE_ACTIVE_TEXTURE) {
- ct->user = user;
- ct->index = BLI_findindex(&ct->users, user);
- break;
+ ct->texture = tex;
+ }
+ else if (ct->user->node && !(ct->user->node->flag & NODE_ACTIVE_TEXTURE)) {
+ ButsTextureUser *user;
+
+ /* detect change of active texture node in same node tree, in that
+ * case we also automatically switch to the other node */
+ for (user = ct->users.first; user; user = user->next) {
+ if (user->ntree == ct->user->ntree && user->node != ct->user->node) {
+ if (user->node->flag & NODE_ACTIVE_TEXTURE) {
+ ct->user = user;
+ ct->index = BLI_findindex(&ct->users, user);
+ break;
+ }
}
}
}