2011-11-08 13:07:16 +00:00
|
|
|
/*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** \file blender/editors/space_buttons/buttons_texture.c
|
|
|
|
|
* \ingroup spbuttons
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BLI_string.h"
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-02-24 15:40:28 +00:00
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "DNA_brush_types.h"
|
|
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
#include "DNA_lamp_types.h"
|
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_object_force.h"
|
|
|
|
|
#include "DNA_particle_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
#include "DNA_world_types.h"
|
2014-05-03 18:51:53 +09:00
|
|
|
#include "DNA_linestyle_types.h"
|
|
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "BKE_context.h"
|
2017-11-09 13:11:20 -02:00
|
|
|
#include "BKE_layer.h"
|
2014-07-16 13:36:39 +09:00
|
|
|
#include "BKE_linestyle.h"
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "BKE_material.h"
|
|
|
|
|
#include "BKE_modifier.h"
|
|
|
|
|
#include "BKE_node.h"
|
|
|
|
|
#include "BKE_paint.h"
|
|
|
|
|
#include "BKE_particle.h"
|
|
|
|
|
#include "BKE_scene.h"
|
2014-11-28 15:50:43 +01:00
|
|
|
#ifdef WITH_FREESTYLE
|
|
|
|
|
# include "BKE_freestyle.h"
|
|
|
|
|
#endif
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
#include "ED_buttons.h"
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "ED_node.h"
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
|
|
#include "../interface/interface_intern.h"
|
|
|
|
|
|
2012-05-08 15:30:00 +00:00
|
|
|
#include "buttons_intern.h" // own include
|
2011-11-08 13:07:16 +00:00
|
|
|
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
/****************** "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);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-03 18:51:53 +09:00
|
|
|
bool ED_texture_context_check_linestyle(const bContext *C)
|
|
|
|
|
{
|
2014-05-08 10:01:49 +09:00
|
|
|
#ifdef WITH_FREESTYLE
|
2014-05-03 18:51:53 +09:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *active_view_layer;
|
2014-05-05 19:53:13 +09:00
|
|
|
FreestyleConfig *config;
|
|
|
|
|
FreestyleLineSet *lineset;
|
|
|
|
|
FreestyleLineStyle *linestyle;
|
|
|
|
|
|
|
|
|
|
if (scene && (scene->r.mode & R_EDGE_FRS)) {
|
2017-11-22 10:52:39 -02:00
|
|
|
active_view_layer = BLI_findlink(&scene->view_layers, scene->active_view_layer);
|
|
|
|
|
config = &active_view_layer->freestyle_config;
|
2014-05-05 19:53:13 +09:00
|
|
|
if (config->mode == FREESTYLE_CONTROL_EDITOR_MODE) {
|
|
|
|
|
lineset = BKE_freestyle_lineset_get_active(config);
|
|
|
|
|
if (lineset) {
|
|
|
|
|
linestyle = lineset->linestyle;
|
|
|
|
|
return linestyle && (linestyle->flag & LS_TEXTURE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-08 14:22:47 +10:00
|
|
|
#else
|
|
|
|
|
(void)C;
|
2014-05-08 10:01:49 +09:00
|
|
|
#endif
|
2014-05-05 19:53:13 +09:00
|
|
|
return false;
|
2014-05-03 18:51:53 +09:00
|
|
|
}
|
|
|
|
|
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 13:13:42 +00:00
|
|
|
static void set_texture_context(const bContext *C, SpaceButs *sbuts)
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
{
|
|
|
|
|
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);
|
2014-05-03 18:51:53 +09:00
|
|
|
bool valid_linestyle = ED_texture_context_check_linestyle(C);
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
bool valid_others = ED_texture_context_check_others(C);
|
|
|
|
|
|
2013-08-21 21:35:45 +00:00
|
|
|
/* this is similar to direct user action, no need to keep "better" ctxt in _prev */
|
2013-06-16 13:13:42 +00:00
|
|
|
if ((sbuts->mainb == BCONTEXT_WORLD) && valid_world) {
|
2013-08-21 21:35:45 +00:00
|
|
|
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_WORLD;
|
2013-06-16 13:13:42 +00:00
|
|
|
}
|
|
|
|
|
else if ((sbuts->mainb == BCONTEXT_MATERIAL) && valid_material) {
|
2013-08-21 21:35:45 +00:00
|
|
|
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_MATERIAL;
|
2013-06-16 13:13:42 +00:00
|
|
|
}
|
|
|
|
|
else if ((sbuts->mainb == BCONTEXT_DATA) && valid_lamp) {
|
2013-08-21 21:35:45 +00:00
|
|
|
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_LAMP;
|
2013-06-16 13:13:42 +00:00
|
|
|
}
|
|
|
|
|
else if ((sbuts->mainb == BCONTEXT_PARTICLE) && valid_particles) {
|
2013-08-21 21:35:45 +00:00
|
|
|
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_PARTICLES;
|
2013-06-16 13:13:42 +00:00
|
|
|
}
|
2017-11-22 10:52:39 -02:00
|
|
|
else if ((sbuts->mainb == BCONTEXT_VIEW_LAYER) && valid_linestyle) {
|
2014-05-03 18:51:53 +09:00
|
|
|
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_LINESTYLE;
|
|
|
|
|
}
|
2013-06-16 13:13:42 +00:00
|
|
|
else if ((ELEM(sbuts->mainb, BCONTEXT_MODIFIER, BCONTEXT_PHYSICS)) && valid_others) {
|
2013-08-21 21:35:45 +00:00
|
|
|
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_OTHER;
|
|
|
|
|
}
|
|
|
|
|
/* Else, try to revive a previous "better" ctxt... */
|
|
|
|
|
else if ((sbuts->texture_context_prev != sbuts->texture_context) &&
|
|
|
|
|
(((sbuts->texture_context_prev == SB_TEXC_WORLD) && valid_world) ||
|
|
|
|
|
((sbuts->texture_context_prev == SB_TEXC_MATERIAL) && valid_material) ||
|
|
|
|
|
((sbuts->texture_context_prev == SB_TEXC_LAMP) && valid_lamp) ||
|
|
|
|
|
((sbuts->texture_context_prev == SB_TEXC_PARTICLES) && valid_particles) ||
|
2014-05-03 18:51:53 +09:00
|
|
|
((sbuts->texture_context_prev == SB_TEXC_LINESTYLE) && valid_linestyle) ||
|
2013-08-21 21:35:45 +00:00
|
|
|
((sbuts->texture_context_prev == SB_TEXC_OTHER) && valid_others)))
|
|
|
|
|
{
|
|
|
|
|
sbuts->texture_context = sbuts->texture_context_prev;
|
2013-06-16 13:13:42 +00:00
|
|
|
}
|
|
|
|
|
/* Else, just be sure that current context is valid! */
|
|
|
|
|
else 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) ||
|
2014-05-03 18:51:53 +09:00
|
|
|
((sbuts->texture_context == SB_TEXC_LINESTYLE) && !valid_linestyle) ||
|
2013-06-16 13:13:42 +00:00
|
|
|
((sbuts->texture_context == SB_TEXC_OTHER) && !valid_others))
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
{
|
2013-08-21 21:35:45 +00:00
|
|
|
/* this is default fallback, do keep "better" ctxt in _prev */
|
|
|
|
|
sbuts->texture_context_prev = sbuts->texture_context;
|
|
|
|
|
if (valid_material) {
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2014-05-03 18:51:53 +09:00
|
|
|
else if (valid_linestyle) {
|
|
|
|
|
sbuts->texture_context = SB_TEXC_LINESTYLE;
|
|
|
|
|
}
|
2013-08-21 21:35:45 +00:00
|
|
|
else if (valid_world) {
|
|
|
|
|
sbuts->texture_context = SB_TEXC_WORLD;
|
|
|
|
|
}
|
|
|
|
|
else if (valid_others) {
|
|
|
|
|
sbuts->texture_context = SB_TEXC_OTHER;
|
|
|
|
|
}
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
/************************* Texture User **************************/
|
|
|
|
|
|
|
|
|
|
static void buttons_texture_user_property_add(ListBase *users, ID *id,
|
2012-05-08 15:30:00 +00:00
|
|
|
PointerRNA ptr, PropertyRNA *prop,
|
|
|
|
|
const char *category, int icon, const char *name)
|
2011-11-08 13:07:16 +00:00
|
|
|
{
|
|
|
|
|
ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser");
|
|
|
|
|
|
2012-05-08 15:30:00 +00:00
|
|
|
user->id = id;
|
2011-11-08 13:07:16 +00:00
|
|
|
user->ptr = ptr;
|
|
|
|
|
user->prop = prop;
|
|
|
|
|
user->category = category;
|
|
|
|
|
user->icon = icon;
|
|
|
|
|
user->name = name;
|
2014-11-16 13:57:58 +01:00
|
|
|
user->index = BLI_listbase_count(users);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
BLI_addtail(users, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void buttons_texture_user_node_add(ListBase *users, ID *id,
|
2012-05-08 15:30:00 +00:00
|
|
|
bNodeTree *ntree, bNode *node,
|
|
|
|
|
const char *category, int icon, const char *name)
|
2011-11-08 13:07:16 +00:00
|
|
|
{
|
|
|
|
|
ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser");
|
|
|
|
|
|
2012-05-08 15:30:00 +00:00
|
|
|
user->id = id;
|
2011-11-08 13:07:16 +00:00
|
|
|
user->ntree = ntree;
|
|
|
|
|
user->node = node;
|
|
|
|
|
user->category = category;
|
|
|
|
|
user->icon = icon;
|
|
|
|
|
user->name = name;
|
2014-11-16 13:57:58 +01:00
|
|
|
user->index = BLI_listbase_count(users);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
BLI_addtail(users, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void buttons_texture_users_find_nodetree(ListBase *users, ID *id,
|
2012-05-08 15:30:00 +00:00
|
|
|
bNodeTree *ntree, const char *category)
|
2011-11-08 13:07:16 +00:00
|
|
|
{
|
|
|
|
|
bNode *node;
|
|
|
|
|
|
2013-03-19 13:40:16 +00:00
|
|
|
if (ntree) {
|
2012-05-08 15:30:00 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
|
2011-11-08 13:07:16 +00:00
|
|
|
PointerRNA ptr;
|
2011-11-10 04:03:08 +00:00
|
|
|
/* PropertyRNA *prop; */ /* UNUSED */
|
2013-03-19 13:40:16 +00:00
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr);
|
2011-11-10 04:03:08 +00:00
|
|
|
/* prop = RNA_struct_find_property(&ptr, "texture"); */ /* UNUSED */
|
2013-03-19 13:40:16 +00:00
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
buttons_texture_user_node_add(users, id, ntree, node,
|
2012-05-08 15:30:00 +00:00
|
|
|
category, RNA_struct_ui_icon(ptr.type), node->name);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (node->type == NODE_GROUP && node->id) {
|
2012-05-08 15:30:00 +00:00
|
|
|
buttons_texture_users_find_nodetree(users, id, (bNodeTree *)node->id, category);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2015-12-28 17:46:48 +01:00
|
|
|
N_("Modifiers"), RNA_struct_ui_icon(ptr.type), md->name);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void buttons_texture_users_from_context(ListBase *users, const bContext *C, SpaceButs *sbuts)
|
|
|
|
|
{
|
2012-05-08 15:30:00 +00:00
|
|
|
Scene *scene = NULL;
|
|
|
|
|
Object *ob = NULL;
|
|
|
|
|
Material *ma = NULL;
|
|
|
|
|
Lamp *la = NULL;
|
|
|
|
|
World *wrld = NULL;
|
2017-11-09 13:11:20 -02:00
|
|
|
WorkSpace *workspace = NULL;
|
2014-05-03 18:51:53 +09:00
|
|
|
FreestyleLineStyle *linestyle = NULL;
|
2012-05-08 15:30:00 +00:00
|
|
|
Brush *brush = NULL;
|
2011-11-08 13:07:16 +00:00
|
|
|
ID *pinid = sbuts->pinid;
|
2013-05-29 11:49:39 +00:00
|
|
|
bool limited_mode = (sbuts->flag & SB_TEX_USER_LIMITED) != 0;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
/* get data from context */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (pinid) {
|
|
|
|
|
if (GS(pinid->name) == ID_SCE)
|
2012-05-08 15:30:00 +00:00
|
|
|
scene = (Scene *)pinid;
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (GS(pinid->name) == ID_OB)
|
2012-05-08 15:30:00 +00:00
|
|
|
ob = (Object *)pinid;
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (GS(pinid->name) == ID_LA)
|
2012-05-08 15:30:00 +00:00
|
|
|
la = (Lamp *)pinid;
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (GS(pinid->name) == ID_WO)
|
2012-05-08 15:30:00 +00:00
|
|
|
wrld = (World *)pinid;
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (GS(pinid->name) == ID_MA)
|
2012-05-08 15:30:00 +00:00
|
|
|
ma = (Material *)pinid;
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (GS(pinid->name) == ID_BR)
|
2012-05-08 15:30:00 +00:00
|
|
|
brush = (Brush *)pinid;
|
2014-05-03 18:51:53 +09:00
|
|
|
else if (GS(pinid->name) == ID_LS)
|
|
|
|
|
linestyle = (FreestyleLineStyle *)pinid;
|
2017-11-09 13:11:20 -02:00
|
|
|
else if (GS(pinid->name) == ID_WS)
|
|
|
|
|
workspace = (WorkSpace *)workspace;
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!scene)
|
2012-05-08 15:30:00 +00:00
|
|
|
scene = CTX_data_scene(C);
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
|
2017-11-09 08:17:35 -02:00
|
|
|
if (!pinid || GS(pinid->name) == ID_SCE) {
|
2012-05-08 15:30:00 +00:00
|
|
|
wrld = scene->world;
|
Paint refactoring commit, non-disruptive (in theory :p)
* Fix precision overflow issue with overlay previews,
* Expose alpha mask mapping to UI (still not functional but coming soon).
* More overlay refactoring:
Overlay now does minimal checking for texture refresh.
Instead, we now have invalidation flags to set an aspect of the brush
overlay as invalid. This is necessary because this way we will be able to
separate and preview different brush attributes on the overlays, using
different textures:
These attributes/aspects are:
Primary texture (main texture for sculpt, vertex, imapaint)
Secondary texture (mask/alpha texture for imapaint)
Cursor texture (cursor texture. It involves brush strength and curves)
Modified the relevant RNA property update functions and C update callback
functions to call the relevant cursor invalidation functions instead
of checking every frame for multiple properties.
Properties that affect this are:
Image changes, if image is used by current brush,
Texture slot changes, similarly
Curve changes,
Object mode change invalidates the cursor
Paint tool change invalidates the cursor.
These changes give slightly more invalidation cases than simply
comparing the relevant properties each frame, but these do not occur in
performance critical moments and it's a much more elegant system than
adding more variables to check per frame each time we add something on
the system.
2013-04-12 17:21:31 +00:00
|
|
|
brush = BKE_paint_brush(BKE_paint_get_active_from_context(C));
|
2014-07-16 15:13:40 +10:00
|
|
|
linestyle = BKE_linestyle_active_from_scene(scene);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
2017-11-09 13:11:20 -02:00
|
|
|
else if (!pinid || GS(pinid->name) == ID_WS) {
|
|
|
|
|
if (!workspace) {
|
|
|
|
|
workspace = CTX_wm_workspace(C);
|
|
|
|
|
}
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
|
|
|
|
|
ob = OBACT(view_layer);
|
2017-11-09 13:11:20 -02:00
|
|
|
}
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob && ob->type == OB_LAMP && !la)
|
2012-05-08 15:30:00 +00:00
|
|
|
la = ob->data;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob && !ma)
|
2012-05-08 15:30:00 +00:00
|
|
|
ma = give_current_material(ob, ob->actcol);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
/* fill users */
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(users);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
if (ma && !limited_mode)
|
2015-12-28 17:46:48 +01:00
|
|
|
buttons_texture_users_find_nodetree(users, &ma->id, ma->nodetree, N_("Material"));
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
if (la && !limited_mode)
|
2015-12-28 17:46:48 +01:00
|
|
|
buttons_texture_users_find_nodetree(users, &la->id, la->nodetree, N_("Lamp"));
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
if (wrld && !limited_mode)
|
2015-12-28 17:46:48 +01:00
|
|
|
buttons_texture_users_find_nodetree(users, &wrld->id, wrld->nodetree, N_("World"));
|
2014-05-03 18:51:53 +09:00
|
|
|
if (linestyle && !limited_mode)
|
2015-12-28 17:46:48 +01:00
|
|
|
buttons_texture_users_find_nodetree(users, &linestyle->id, linestyle->nodetree, N_("Line Style"));
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob) {
|
2012-05-08 15:30:00 +00:00
|
|
|
ParticleSystem *psys = psys_get_current(ob);
|
2011-11-08 13:07:16 +00:00
|
|
|
MTex *mtex;
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
/* modifiers */
|
|
|
|
|
modifiers_foreachTexLink(ob, buttons_texture_modifier_foreach, users);
|
|
|
|
|
|
|
|
|
|
/* particle systems */
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
if (psys && !limited_mode) {
|
2012-05-08 15:30:00 +00:00
|
|
|
for (a = 0; a < MAX_MTEX; a++) {
|
2011-11-08 13:07:16 +00:00
|
|
|
mtex = psys->part->mtex[a];
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mtex) {
|
2011-11-08 13:07:16 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
|
|
RNA_pointer_create(&psys->part->id, &RNA_ParticleSettingsTextureSlot, mtex, &ptr);
|
|
|
|
|
prop = RNA_struct_find_property(&ptr, "texture");
|
|
|
|
|
|
2015-12-28 17:46:48 +01:00
|
|
|
buttons_texture_user_property_add(users, &psys->part->id, ptr, prop, N_("Particles"),
|
|
|
|
|
RNA_struct_ui_icon(&RNA_ParticleSettings), psys->name);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* field */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob->pd && ob->pd->forcefield == PFIELD_TEXTURE) {
|
2011-11-08 13:07:16 +00:00
|
|
|
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,
|
2015-12-28 17:46:48 +01:00
|
|
|
N_("Fields"), ICON_FORCE_TEXTURE, IFACE_("Texture Field"));
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* brush */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (brush) {
|
2011-11-08 13:07:16 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
2013-05-01 12:58:37 +00:00
|
|
|
/* texture */
|
2011-11-08 13:07:16 +00:00
|
|
|
RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mtex, &ptr);
|
2012-05-08 15:30:00 +00:00
|
|
|
prop = RNA_struct_find_property(&ptr, "texture");
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
buttons_texture_user_property_add(users, &brush->id, ptr, prop,
|
2015-12-28 17:46:48 +01:00
|
|
|
N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush"));
|
2013-05-01 12:58:37 +00:00
|
|
|
|
|
|
|
|
/* 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,
|
2015-12-28 17:46:48 +01:00
|
|
|
N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush Mask"));
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void buttons_texture_context_compute(const bContext *C, SpaceButs *sbuts)
|
|
|
|
|
{
|
2012-11-12 07:33:01 +00:00
|
|
|
/* gather available texture users in context. runs on every draw of
|
2012-03-03 16:31:46 +00:00
|
|
|
* properties editor, before the buttons are created. */
|
2012-05-08 15:30:00 +00:00
|
|
|
ButsContextTexture *ct = sbuts->texuser;
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
ID *pinid = sbuts->pinid;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2013-06-16 13:13:42 +00:00
|
|
|
set_texture_context(C, sbuts);
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
|
2014-06-14 01:06:49 +10:00
|
|
|
if (!((sbuts->texture_context == SB_TEXC_OTHER) || BKE_scene_use_new_shading_nodes(scene))) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ct) {
|
2011-11-08 13:07:16 +00:00
|
|
|
BLI_freelistN(&ct->users);
|
2011-11-22 14:55:53 +00:00
|
|
|
MEM_freeN(ct);
|
2012-05-08 15:30:00 +00:00
|
|
|
sbuts->texuser = NULL;
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ct) {
|
2012-05-08 15:30:00 +00:00
|
|
|
ct = MEM_callocN(sizeof(ButsContextTexture), "ButsContextTexture");
|
|
|
|
|
sbuts->texuser = ct;
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_freelistN(&ct->users);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buttons_texture_users_from_context(&ct->users, C, sbuts);
|
|
|
|
|
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
if (pinid && GS(pinid->name) == ID_TE) {
|
|
|
|
|
ct->user = NULL;
|
|
|
|
|
ct->texture = (Tex *)pinid;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* set one user as active based on active index */
|
2017-06-27 16:53:43 +02:00
|
|
|
if (ct->index >= BLI_listbase_count_ex(&ct->users, ct->index + 1))
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
ct->index = 0;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
ct->user = BLI_findlink(&ct->users, ct->index);
|
|
|
|
|
ct->texture = NULL;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
if (ct->user) {
|
|
|
|
|
if (ct->user->ptr.data) {
|
|
|
|
|
PointerRNA texptr;
|
|
|
|
|
Tex *tex;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
/* 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;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
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.
2013-05-17 07:10:10 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg))
|
|
|
|
|
{
|
|
|
|
|
/* callback when selecting a texture user in the menu */
|
|
|
|
|
SpaceButs *sbuts = CTX_wm_space_buts(C);
|
2012-05-08 15:30:00 +00:00
|
|
|
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
|
|
|
|
|
ButsTextureUser *user = (ButsTextureUser *)user_p;
|
2011-11-08 13:07:16 +00:00
|
|
|
PointerRNA texptr;
|
|
|
|
|
Tex *tex;
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ct)
|
2011-11-08 13:07:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* set user as active */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (user->node) {
|
2011-11-08 13:07:16 +00:00
|
|
|
ED_node_set_active(CTX_data_main(C), user->ntree, user->node);
|
|
|
|
|
ct->texture = NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
texptr = RNA_property_pointer_get(&user->ptr, user->prop);
|
2012-05-08 15:30:00 +00:00
|
|
|
tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
ct->texture = tex;
|
2013-04-02 18:19:37 +00:00
|
|
|
|
2013-04-03 01:36:00 +00:00
|
|
|
if (user->ptr.type == &RNA_ParticleSettingsTextureSlot) {
|
2013-04-02 18:19:37 +00:00
|
|
|
/* stupid exception for particle systems which still uses influence
|
|
|
|
|
* from the old texture system, set the active texture slots as well */
|
|
|
|
|
ParticleSettings *part = user->ptr.id.data;
|
|
|
|
|
int a;
|
|
|
|
|
|
2013-04-03 01:36:00 +00:00
|
|
|
for (a = 0; a < MAX_MTEX; a++)
|
|
|
|
|
if (user->ptr.data == part->mtex[a])
|
2013-04-02 18:19:37 +00:00
|
|
|
part->texact = a;
|
|
|
|
|
}
|
2015-09-27 02:40:30 +02:00
|
|
|
|
|
|
|
|
if (sbuts && tex)
|
|
|
|
|
sbuts->preview = 1;
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ct->user = user;
|
|
|
|
|
ct->index = user->index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void template_texture_user_menu(bContext *C, uiLayout *layout, void *UNUSED(arg))
|
|
|
|
|
{
|
|
|
|
|
/* callback when opening texture user selection menu, to create buttons. */
|
|
|
|
|
SpaceButs *sbuts = CTX_wm_space_buts(C);
|
2012-09-14 06:17:14 +00:00
|
|
|
ButsContextTexture *ct = sbuts->texuser;
|
2011-11-08 13:07:16 +00:00
|
|
|
ButsTextureUser *user;
|
|
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
|
const char *last_category = NULL;
|
|
|
|
|
|
2012-05-08 15:30:00 +00:00
|
|
|
for (user = ct->users.first; user; user = user->next) {
|
2011-11-08 13:07:16 +00:00
|
|
|
uiBut *but;
|
|
|
|
|
char name[UI_MAX_NAME_STR];
|
|
|
|
|
|
|
|
|
|
/* add label per category */
|
2015-01-26 16:03:11 +01:00
|
|
|
if (!last_category || !STREQ(last_category, user->category)) {
|
2015-12-28 17:46:48 +01:00
|
|
|
uiItemL(layout, IFACE_(user->category), ICON_NONE);
|
2012-05-08 15:30:00 +00:00
|
|
|
but = block->buttons.last;
|
2013-11-21 14:43:08 +01:00
|
|
|
but->drawflag = UI_BUT_TEXT_LEFT;
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create button */
|
2012-12-16 12:55:52 +00:00
|
|
|
if (user->prop) {
|
|
|
|
|
PointerRNA texptr = RNA_property_pointer_get(&user->ptr, user->prop);
|
|
|
|
|
Tex *tex = texptr.data;
|
|
|
|
|
|
|
|
|
|
if (tex)
|
2012-12-18 01:46:15 +00:00
|
|
|
BLI_snprintf(name, UI_MAX_NAME_STR, " %s - %s", user->name, tex->id.name + 2);
|
2012-12-16 12:55:52 +00:00
|
|
|
else
|
|
|
|
|
BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
but = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, user->icon, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y,
|
2012-05-08 15:30:00 +00:00
|
|
|
NULL, 0.0, 0.0, 0.0, 0.0, "");
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_but_funcN_set(but, template_texture_select, MEM_dupallocN(user), NULL);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
last_category = user->category;
|
|
|
|
|
}
|
2016-11-13 02:27:45 +01:00
|
|
|
|
|
|
|
|
UI_block_flag_enable(block, UI_BLOCK_NO_FLIP);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uiTemplateTextureUser(uiLayout *layout, bContext *C)
|
|
|
|
|
{
|
|
|
|
|
/* texture user selection dropdown menu. the available users have been
|
2012-03-03 16:31:46 +00:00
|
|
|
* gathered before drawing in ButsContextTexture, we merely need to
|
|
|
|
|
* display the current item. */
|
2011-11-08 13:07:16 +00:00
|
|
|
SpaceButs *sbuts = CTX_wm_space_buts(C);
|
2012-05-08 15:30:00 +00:00
|
|
|
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
|
2011-11-08 13:07:16 +00:00
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
|
uiBut *but;
|
|
|
|
|
ButsTextureUser *user;
|
|
|
|
|
char name[UI_MAX_NAME_STR];
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ct)
|
2011-11-08 13:07:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* get current user */
|
2012-05-08 15:30:00 +00:00
|
|
|
user = ct->user;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!user) {
|
2013-02-24 15:40:28 +00:00
|
|
|
uiItemL(layout, IFACE_("No textures in context"), ICON_NONE);
|
2011-11-08 13:07:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create button */
|
2013-03-14 10:39:18 +00:00
|
|
|
BLI_strncpy(name, user->name, UI_MAX_NAME_STR);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (user->icon) {
|
2012-03-24 02:51:46 +00:00
|
|
|
but = uiDefIconTextMenuBut(block, template_texture_user_menu, NULL,
|
2012-05-08 15:30:00 +00:00
|
|
|
user->icon, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, "");
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-24 02:51:46 +00:00
|
|
|
but = uiDefMenuBut(block, template_texture_user_menu, NULL,
|
2012-05-08 15:30:00 +00:00
|
|
|
name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, "");
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* some cosmetic tweaks */
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_but_type_set_menu_from_pulldown(but);
|
2014-02-12 00:08:54 +11:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
but->flag &= ~UI_BUT_ICON_SUBMENU;
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************* Texture Show **************************/
|
|
|
|
|
|
|
|
|
|
static void template_texture_show(bContext *C, void *data_p, void *prop_p)
|
|
|
|
|
{
|
|
|
|
|
SpaceButs *sbuts = CTX_wm_space_buts(C);
|
2012-05-08 15:30:00 +00:00
|
|
|
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
|
2011-11-08 13:07:16 +00:00
|
|
|
ButsTextureUser *user;
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ct)
|
2011-11-08 13:07:16 +00:00
|
|
|
return;
|
|
|
|
|
|
2012-05-08 15:30:00 +00:00
|
|
|
for (user = ct->users.first; user; user = user->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (user->ptr.data == data_p && user->prop == prop_p)
|
2011-11-08 13:07:16 +00:00
|
|
|
break;
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (user) {
|
2011-11-08 13:07:16 +00:00
|
|
|
/* select texture */
|
|
|
|
|
template_texture_select(C, user, NULL);
|
|
|
|
|
|
|
|
|
|
/* change context */
|
2012-05-08 15:30:00 +00:00
|
|
|
sbuts->mainb = BCONTEXT_TEXTURE;
|
|
|
|
|
sbuts->mainbuser = sbuts->mainb;
|
|
|
|
|
sbuts->preview = 1;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
/* redraw editor */
|
|
|
|
|
ED_area_tag_redraw(CTX_wm_area(C));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uiTemplateTextureShow(uiLayout *layout, bContext *C, PointerRNA *ptr, PropertyRNA *prop)
|
|
|
|
|
{
|
|
|
|
|
/* button to quickly show texture in texture tab */
|
|
|
|
|
SpaceButs *sbuts = CTX_wm_space_buts(C);
|
2012-05-08 15:30:00 +00:00
|
|
|
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
|
2011-11-08 13:07:16 +00:00
|
|
|
ButsTextureUser *user;
|
|
|
|
|
|
|
|
|
|
/* only show button in other tabs in properties editor */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ct || sbuts->mainb == BCONTEXT_TEXTURE)
|
2011-11-08 13:07:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* find corresponding texture user */
|
2012-05-08 15:30:00 +00:00
|
|
|
for (user = ct->users.first; user; user = user->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (user->ptr.data == ptr->data && user->prop == prop)
|
2011-11-08 13:07:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* draw button */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (user) {
|
2011-11-08 13:07:16 +00:00
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
|
uiBut *but;
|
|
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
but = uiDefIconBut(block, UI_BTYPE_BUT, 0, ICON_BUTS, 0, 0, UI_UNIT_X, UI_UNIT_Y,
|
2015-12-28 17:46:48 +01:00
|
|
|
NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Show texture in texture tab"));
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_but_func_set(but, template_texture_show, user->ptr.data, user->prop);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|