~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/startup/bl_ui/properties_texture.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
# <pep8 compliant>
20
20
import bpy
21
 
from bpy.types import Menu, Panel
 
21
from bpy.types import Menu, Panel, UIList
22
22
 
23
23
from bpy.types import (Brush,
24
24
                       Lamp,
25
25
                       Material,
 
26
                       Object,
26
27
                       ParticleSettings,
27
28
                       Texture,
28
29
                       World)
29
30
 
30
31
from rna_prop_ui import PropertyPanel
31
32
 
 
33
from bl_ui.properties_paint_common import brush_texture_settings
 
34
 
32
35
 
33
36
class TEXTURE_MT_specials(Menu):
34
37
    bl_label = "Texture Specials"
52
55
        layout.operator("texture.envmap_clear", icon='FILE_REFRESH')
53
56
        layout.operator("texture.envmap_clear_all", icon='FILE_REFRESH')
54
57
 
 
58
 
 
59
class TEXTURE_UL_texslots(UIList):
 
60
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
 
61
        # assert(isinstance(item, bpy.types.MaterialTextureSlot)
 
62
        ma = data
 
63
        slot = item
 
64
        tex = slot.texture if slot else None
 
65
        if self.layout_type in {'DEFAULT', 'COMPACT'}:
 
66
            layout.label(text=tex.name if tex else "", translate=False, icon_value=icon)
 
67
            if tex and isinstance(item, bpy.types.MaterialTextureSlot):
 
68
                layout.prop(ma, "use_textures", text="", index=index)
 
69
        elif self.layout_type in {'GRID'}:
 
70
            layout.alignment = 'CENTER'
 
71
            layout.label(text="", icon_value=icon)
 
72
 
 
73
 
55
74
from bl_ui.properties_material import active_node_mat
56
75
 
57
76
 
78
97
    return idblock
79
98
 
80
99
 
 
100
def id_tex_datablock(bid):
 
101
    if isinstance(bid, Object):
 
102
        if bid.type == 'LAMP':
 
103
            return bid.data
 
104
        return bid.active_material
 
105
 
 
106
    return bid
 
107
 
 
108
 
81
109
class TextureButtonsPanel():
82
110
    bl_space_type = 'PROPERTIES'
83
111
    bl_region_type = 'WINDOW'
99
127
        engine = context.scene.render.engine
100
128
        if not (hasattr(context, "texture_slot") or hasattr(context, "texture_node")):
101
129
            return False
102
 
        return ((context.material or context.world or context.lamp or context.brush or context.texture or context.particle_system or isinstance(context.space_data.pin_id, ParticleSettings))
103
 
            and (engine in cls.COMPAT_ENGINES))
 
130
        return ((context.material or
 
131
                 context.world or
 
132
                 context.lamp or
 
133
                 context.brush or
 
134
                 context.texture or
 
135
                 context.particle_system or
 
136
                 isinstance(context.space_data.pin_id, ParticleSettings)) and
 
137
                (engine in cls.COMPAT_ENGINES))
104
138
 
105
139
    def draw(self, context):
106
140
        layout = self.layout
 
141
 
107
142
        slot = getattr(context, "texture_slot", None)
108
143
        node = getattr(context, "texture_node", None)
109
144
        space = context.space_data
112
147
        pin_id = space.pin_id
113
148
 
114
149
        if space.use_pin_id and not isinstance(pin_id, Texture):
115
 
            idblock = pin_id
 
150
            idblock = id_tex_datablock(pin_id)
116
151
            pin_id = None
117
152
 
118
153
        if not space.use_pin_id:
123
158
        if tex_collection:
124
159
            row = layout.row()
125
160
 
126
 
            row.template_list(idblock, "texture_slots", idblock, "active_texture_index", rows=2)
 
161
            row.template_list("TEXTURE_UL_texslots", "", idblock, "texture_slots", idblock, "active_texture_index", rows=2)
127
162
 
128
163
            col = row.column(align=True)
129
164
            col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP'
130
165
            col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN'
131
166
            col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="")
132
167
 
133
 
        split = layout.split(percentage=0.65)
134
 
        col = split.column()
135
 
 
136
168
        if tex_collection:
137
 
            col.template_ID(idblock, "active_texture", new="texture.new")
 
169
            layout.template_ID(idblock, "active_texture", new="texture.new")
138
170
        elif node:
139
 
            col.template_ID(node, "texture", new="texture.new")
 
171
            layout.template_ID(node, "texture", new="texture.new")
140
172
        elif idblock:
141
 
            col.template_ID(idblock, "texture", new="texture.new")
 
173
            layout.template_ID(idblock, "texture", new="texture.new")
142
174
 
143
175
        if pin_id:
144
 
            col.template_ID(space, "pin_id")
145
 
 
146
 
        col = split.column()
 
176
            layout.template_ID(space, "pin_id")
147
177
 
148
178
        if tex:
149
179
            split = layout.split(percentage=0.2)
402
432
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
403
433
 
404
434
    def draw(self, context):
 
435
        if context.scene.render.engine == 'BLENDER_GAME':
 
436
            self.draw_bge(context)
 
437
        else:
 
438
            self.draw_bi(context)
 
439
 
 
440
    def draw_bi(self, context):
405
441
        layout = self.layout
406
442
 
407
443
        idblock = context_tex_datablock(context)
412
448
 
413
449
        col = split.column()
414
450
        col.label(text="Alpha:")
415
 
        col.prop(tex, "use_alpha", text="Use")
 
451
        row = col.row()
 
452
        row.active = tex.image and tex.image.use_alpha
 
453
        row.prop(tex, "use_alpha", text="Use")
416
454
        col.prop(tex, "use_calculate_alpha", text="Calculate")
417
455
        col.prop(tex, "invert_alpha", text="Invert")
418
456
        col.separator()
439
477
 
440
478
        texture_filter_common(tex, col)
441
479
 
 
480
    def draw_bge(self, context):
 
481
        layout = self.layout
 
482
 
 
483
        idblock = context_tex_datablock(context)
 
484
        tex = context.texture
 
485
        slot = getattr(context, "texture_slot", None)
 
486
 
 
487
        split = layout.split()
 
488
 
 
489
        col = split.column()
 
490
        col.label(text="Alpha:")
 
491
        col.prop(tex, "use_calculate_alpha", text="Calculate")
 
492
        col.prop(tex, "invert_alpha", text="Invert")
 
493
 
 
494
        col = split.column()
 
495
 
 
496
        #Only for Material based textures, not for Lamp/World...
 
497
        if slot and isinstance(idblock, Material):
 
498
            col.prop(tex, "use_normal_map")
 
499
            row = col.row()
 
500
            row.active = tex.use_normal_map
 
501
            row.prop(slot, "normal_map_space", text="")
 
502
 
 
503
            row = col.row()
 
504
            row.active = not tex.use_normal_map
 
505
            row.prop(tex, "use_derivative_map")
 
506
 
442
507
 
443
508
class TEXTURE_PT_image_mapping(TextureTypePanel, Panel):
444
509
    bl_label = "Image Mapping"
855
920
                split.prop(tex, "object", text="")
856
921
 
857
922
        if isinstance(idblock, Brush):
858
 
            if context.sculpt_object:
859
 
                layout.label(text="Brush Mapping:")
860
 
                layout.prop(tex, "map_mode", expand=True)
861
 
 
862
 
                row = layout.row()
863
 
                row.active = tex.map_mode in {'FIXED', 'TILED'}
864
 
                row.prop(tex, "angle")
 
923
            if context.sculpt_object or context.image_paint_object:
 
924
                brush_texture_settings(layout, idblock, context.sculpt_object)
865
925
        else:
866
926
            if isinstance(idblock, Material):
867
927
                split = layout.split(percentage=0.3)
873
933
                col = split.column()
874
934
                if tex.texture_coords in {'ORCO', 'UV'}:
875
935
                    col.prop(tex, "use_from_dupli")
 
936
                    if (idblock.type == 'VOLUME' and tex.texture_coords == 'ORCO'):
 
937
                        col.prop(tex, "use_map_to_bounds")
876
938
                elif tex.texture_coords == 'OBJECT':
877
939
                    col.prop(tex, "use_from_original")
 
940
                    if (idblock.type == 'VOLUME'):
 
941
                        col.prop(tex, "use_map_to_bounds")
878
942
                else:
879
943
                    col.label()
880
944
 
884
948
                row.prop(tex, "mapping_y", text="")
885
949
                row.prop(tex, "mapping_z", text="")
886
950
 
887
 
        row = layout.row()
888
 
        row.column().prop(tex, "offset")
889
 
        row.column().prop(tex, "scale")
 
951
            row = layout.row()
 
952
            row.column().prop(tex, "offset")
 
953
            row.column().prop(tex, "scale")
890
954
 
891
955
 
892
956
class TEXTURE_PT_influence(TextureSlotPanel, Panel):