[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4431] contrib/py/scripts/addons/ node_efficiency_tools.py: Changed severat properties of classes.
Bartek Skorupa
bartekskorupa at bartekskorupa.com
Tue Mar 26 16:45:51 CET 2013
Revision: 4431
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4431
Author: bartekskorupa
Date: 2013-03-26 15:45:51 +0000 (Tue, 26 Mar 2013)
Log Message:
-----------
Changed severat properties of classes.
StringProperty has been replaced by BoolProperty or EnumProperty in every place possible.
This change is just a code clean up, no additional functionality added.
Modified Paths:
--------------
contrib/py/scripts/addons/node_efficiency_tools.py
Modified: contrib/py/scripts/addons/node_efficiency_tools.py
===================================================================
--- contrib/py/scripts/addons/node_efficiency_tools.py 2013-03-26 08:21:39 UTC (rev 4430)
+++ contrib/py/scripts/addons/node_efficiency_tools.py 2013-03-26 15:45:51 UTC (rev 4431)
@@ -19,7 +19,7 @@
bl_info = {
'name': "Nodes Efficiency Tools",
'author': "Bartek Skorupa",
- 'version': (2, 1.2),
+ 'version': (2, 1.3),
'blender': (2, 6, 6),
'location': "Node Editor Properties Panel (Ctrl-SPACE)",
'description': "Nodes Efficiency Tools",
@@ -30,7 +30,7 @@
}
import bpy
-from bpy.props import StringProperty, FloatProperty
+from bpy.props import FloatProperty, EnumProperty, BoolProperty
#################
# rl_outputs:
@@ -68,23 +68,56 @@
('use_pass_vector', 'Speed', 'Vector', True, True),
('use_pass_z', 'Z', 'Depth', True, True),
)
-# list of blend types of "Mix" nodes
-blend_types = (
- 'MIX', 'ADD', 'MULTIPLY', 'SUBTRACT', 'SCREEN',
- 'DIVIDE', 'DIFFERENCE', 'DARKEN', 'LIGHTEN', 'OVERLAY',
- 'DODGE', 'BURN', 'HUE', 'SATURATION', 'VALUE',
- 'COLOR', 'SOFT_LIGHT', 'LINEAR_LIGHT',
- )
-# list of operations of "Math" nodes
-operations = (
- 'ADD', 'MULTIPLY', 'SUBTRACT', 'DIVIDE', 'SINE',
- 'COSINE', 'TANGENT', 'ARCSINE', 'ARCCOSINE', 'ARCTANGENT',
- 'POWER', 'LOGARITHM', 'MINIMUM', 'MAXIMUM', 'ROUND',
- 'LESS_THAN', 'GREATER_THAN',
- )
+# list of blend types of "Mix" nodes in a form that can be used as 'items' for EnumProperty.
+blend_types = [
+ ('MIX', 'Mix', 'Mix Mode'),
+ ('ADD', 'Add', 'Add Mode'),
+ ('MULTIPLY', 'Multiply', 'Multiply Mode'),
+ ('SUBTRACT', 'Subtract', 'Subtract Mode'),
+ ('SCREEN', 'Screen', 'Screen Mode'),
+ ('DIVIDE', 'Divide', 'Divide Mode'),
+ ('DIFFERENCE', 'Difference', 'Difference Mode'),
+ ('DARKEN', 'Darken', 'Darken Mode'),
+ ('LIGHTEN', 'Lighten', 'Lighten Mode'),
+ ('OVERLAY', 'Overlay', 'Overlay Mode'),
+ ('DODGE', 'Dodge', 'Dodge Mode'),
+ ('BURN', 'Burn', 'Burn Mode'),
+ ('HUE', 'Hue', 'Hue Mode'),
+ ('SATURATION', 'Saturation', 'Saturation Mode'),
+ ('VALUE', 'Value', 'Value Mode'),
+ ('COLOR', 'Color', 'Color Mode'),
+ ('SOFT_LIGHT', 'Soft Light', 'Soft Light Mode'),
+ ('LINEAR_LIGHT', 'Linear Light', 'Linear Light Mode'),
+ ]
+# list of operations of "Math" nodes in a form that can be used as 'items' for EnumProperty.
+operations = [
+ ('ADD', 'Add', 'Add Mode'),
+ ('MULTIPLY', 'Multiply', 'Multiply Mode'),
+ ('SUBTRACT', 'Subtract', 'Subtract Mode'),
+ ('DIVIDE', 'Divide', 'Divide Mode'),
+ ('SINE', 'Sine', 'Sine Mode'),
+ ('COSINE', 'Cosine', 'Cosine Mode'),
+ ('TANGENT', 'Tangent', 'Tangent Mode'),
+ ('ARCSINE', 'Arcsine', 'Arcsine Mode'),
+ ('ARCCOSINE', 'Arccosine', 'Arccosine Mode'),
+ ('ARCTANGENT', 'Arctangent', 'Arctangent Mode'),
+ ('POWER', 'Power', 'Power Mode'),
+ ('LOGARITHM', 'Logatithm', 'Logarithm Mode'),
+ ('MINIMUM', 'Minimum', 'Minimum Mode'),
+ ('MAXIMUM', 'Maximum', 'Maximum Mode'),
+ ('ROUND', 'Round', 'Round Mode'),
+ ('LESS_THAN', 'Less Than', 'Less Thann Mode'),
+ ('GREATER_THAN', 'Greater Than', 'Greater Than Mode'),
+ ]
+# in BatchChangeNodes additional types/operations in a form that can be used as 'items' for EnumProperty.
+navs = [
+ ('CURRENT', 'Current', 'Leave at current state'),
+ ('NEXT', 'Next', 'Next blend type/operation'),
+ ('PREV', 'Prev', 'Previous blend type/operation'),
+ ]
# list of mixing shaders
merge_shaders = ('MIX', 'ADD')
-# list of regular shaders. Entry: (identified, type, name for humans)
+# list of regular shaders. Entry: (identified, type, name for humans). Will be used in SwapShaders and menus.
regular_shaders = (
('ShaderNodeBsdfTransparent', 'BSDF_TRANSPARENT', 'Transparent BSDF'),
('ShaderNodeBsdfGlossy', 'BSDF_GLOSSY', 'Glossy BSDF'),
@@ -128,11 +161,25 @@
class MergeNodes(bpy.types.Operator):
bl_idname = "node.merge_nodes"
- bl_label = "Merge Selected Nodes"
+ bl_label = "Merge Nodes"
+ bl_description = "Merge Selected Nodes"
bl_options = {'REGISTER', 'UNDO'}
- # option: "BlendType/ShaderKind/MathOperation and Node Kind" separated with space
- option = StringProperty()
+ mode = EnumProperty(
+ name = "mode",
+ description = "All possible blend types and math operations",
+ items = blend_types + [op for op in operations if op not in blend_types],
+ )
+ merge_type = EnumProperty(
+ name = "merge type",
+ description = "Type of Merge to be used",
+ items = [
+ ('AUTO', 'Auto', 'Automatic Output Type Detection'),
+ ('SHADER', 'Shader', 'Merge using ADD or MIX Shader'),
+ ('MIX', 'Mix Node', 'Merge using Mix Nodes'),
+ ('MATH', 'Math Node', 'Merge using Math Nodes'),
+ ],
+ )
@classmethod
def poll(cls, context):
@@ -146,20 +193,19 @@
elif tree_type == 'SHADER':
node_type = 'ShaderNode'
set_convenience_variables(context)
- option_split = self.option.split( )
- mode = option_split[0]
- node_kind = option_split[1] # kinds: 'AUTO', 'SHADER', 'MIX', 'MATH'
+ mode = self.mode
+ merge_type = self.merge_type
selected_mix = [] # entry = [index, loc]
selected_shader = [] # entry = [index, loc]
selected_math = [] # entry = [index, loc]
for i, node in enumerate(nodes):
if node.select and node.outputs:
- if node_kind == 'AUTO':
+ if merge_type == 'AUTO':
for (type, the_list, dst) in (
('SHADER', merge_shaders, selected_shader),
- ('RGBA', blend_types, selected_mix),
- ('VALUE', operations, selected_math),
+ ('RGBA', [t[0] for t in blend_types], selected_mix),
+ ('VALUE', [t[0] for t in operations], selected_math),
):
output_type = node.outputs[0].type
valid_mode = mode in the_list
@@ -174,17 +220,17 @@
if output_type == type and valid_mode:
dst.append([i, node.location.x, node.location.y])
else:
- for (kind, the_list, dst) in (
- ('MIX', blend_types, selected_mix),
+ for (type, the_list, dst) in (
('SHADER', merge_shaders, selected_shader),
- ('MATH', operations, selected_math),
+ ('MIX', [t[0] for t in blend_types], selected_mix),
+ ('MATH', [t[0] for t in operations], selected_math),
):
- if node_kind == kind and mode in the_list:
+ if merge_type == type and mode in the_list:
dst.append([i, node.location.x, node.location.y])
# When nodes with output kinds 'RGBA' and 'VALUE' are selected at the same time
# use only 'Mix' nodes for merging.
# For that we add selected_math list to selected_mix list and clear selected_math.
- if selected_mix and selected_math and node_kind == 'AUTO':
+ if selected_mix and selected_math and merge_type == 'AUTO':
selected_mix += selected_math
selected_math = []
@@ -262,11 +308,18 @@
class BatchChangeNodes(bpy.types.Operator):
bl_idname = "node.batch_change"
- bl_label = "Batch Change Blend Type and Math Operation"
+ bl_label = "Batch Change"
+ bl_description = "Batch Change Blend Type and Math Operation"
bl_options = {'REGISTER', 'UNDO'}
- # Mix Blend Type and Math Operation separated with space.
- option = StringProperty()
+ blend_type = EnumProperty(
+ name = "Blend Type",
+ items = blend_types + navs,
+ )
+ operation = EnumProperty(
+ name = "Operation",
+ items = operations + navs,
+ )
@classmethod
def poll(cls, context):
@@ -275,53 +328,55 @@
def execute(self, context):
set_convenience_variables(context)
- navs = ('CURRENT', 'NEXT', 'PREV')
- option_split = self.option.split( )
- blend_type = option_split[0]
- operation = option_split[1]
+ blend_type = self.blend_type
+ operation = self.operation
for node in context.selected_nodes:
if node.type == 'MIX_RGB':
- if not blend_type in navs:
+ if not blend_type in [nav[0] for nav in navs]:
node.blend_type = blend_type
else:
if blend_type == 'NEXT':
- index = blend_types.index(node.blend_type)
+ index = [i for i, entry in enumerate(blend_types) if node.blend_type in entry][0]
+ #index = blend_types.index(node.blend_type)
if index == len(blend_types) - 1:
- node.blend_type = blend_types[0]
+ node.blend_type = blend_types[0][0]
else:
- node.blend_type = blend_types[index + 1]
+ node.blend_type = blend_types[index + 1][0]
if blend_type == 'PREV':
- index = blend_types.index(node.blend_type)
+ index = [i for i, entry in enumerate(blend_types) if node.blend_type in entry][0]
if index == 0:
- node.blend_type = blend_types[len(blend_types) - 1]
+ node.blend_type = blend_types[len(blend_types) - 1][0]
else:
- node.blend_type = blend_types[index - 1]
+ node.blend_type = blend_types[index - 1][0]
if node.type == 'MATH':
- if not operation in navs:
+ if not operation in [nav[0] for nav in navs]:
node.operation = operation
else:
if operation == 'NEXT':
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list