Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Copyright (C) 2018 Legigan Jeremy AKA Pistiwique
- Created by Legigan jeremy AKA Pistiwique
- 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 3 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, see <http://www.gnu.org/licenses/>.
- '''
- bl_info = {
- "name": "RAL to RGB",
- "description": "",
- "author": "Legigan Jeremy AKA Pistiwique",
- "version": (0, 0, 1),
- "blender": (2, 79, 0),
- "location": "Node Editor",
- "category": "Node"
- }
- import bpy
- from bpy.types import NodeTree, Node, NodeSocket
- RAL_values = {
- 1000: (205, 186, 136),
- 1001: (208, 176, 132),
- 1002: (210, 170, 109),
- 1003: (249, 168, 0),
- 1004: (228, 158, 0),
- 1005: (203, 142, 30),
- 1006: (226, 144, 0),
- 1007: (232, 140, 0),
- 1011: (175, 128, 79),
- 1012: (221, 175, 39),
- 1013: (227, 217, 198),
- 1014: (221, 196, 154),
- 1015: (230, 210, 181),
- 1016: (241, 221, 56),
- 1017: (246, 169, 80),
- 1018: (250, 202, 48),
- 1019: (164, 143, 122),
- 1020: (160, 143, 101),
- 1021: (246, 182, 0),
- 1023: (247, 181, 0),
- 1024: (186, 143, 76),
- 1026: (255, 255, 0),
- 1027: (167, 127, 14),
- 1028: (255, 155, 0),
- 1032: (226, 163, 0),
- 1033: (249, 154, 28),
- 1034: (235, 156, 82),
- 1035: (144, 131, 112),
- 1036: (128, 100, 63),
- 1037: (240, 146, 0),
- 2000: (218, 110, 0),
- 2001: (186, 72, 27),
- 2002: (191, 57, 34),
- 2003: (246, 120, 40),
- 2004: (226, 83, 3),
- 2005: (255, 77, 6),
- 2007: (255, 178, 0),
- 2008: (237, 107, 33),
- 2009: (222, 83, 7),
- 2010: (208, 93, 40),
- 2011: (226, 110, 14),
- 2012: (213, 101, 77),
- 2013: (146, 62, 37),
- 3000: (167, 41, 32),
- 3001: (155, 36, 35),
- 3002: (155, 35, 33),
- 3003: (134, 26, 34),
- 3004: (107, 28, 35),
- 3005: (89, 25, 31),
- 3007: (62, 32, 34),
- 3009: (109, 52, 45),
- 3011: (121, 36, 35),
- 3012: (198, 132, 109),
- 3013: (151, 46, 37),
- 3014: (203, 115, 117),
- 3015: (216, 160, 166),
- 3016: (166, 61, 47),
- 3017: (203, 85, 93),
- 3018: (199, 63, 74),
- 3020: (187, 30, 16),
- 3022: (207, 105, 85),
- 3024: (255, 45, 33),
- 3026: (255, 42, 27),
- 3027: (171, 39, 60),
- 3028: (204, 44, 36),
- 3031: (166, 52, 55),
- 3032: (112, 29, 35),
- 3033: (165, 58, 45),
- 4001: (129, 97, 131),
- 4002: (141, 60, 75),
- 4003: (196, 97, 140),
- 4004: (101, 30, 56),
- 4005: (118, 104, 154),
- 4006: (144, 50, 115),
- 4007: (71, 36, 60),
- 4008: (132, 76, 130),
- 4009: (157, 134, 146),
- 4010: (188, 64, 119),
- 4011: (110, 99, 135),
- 4012: (107, 107, 127),
- 5000: (49, 79, 111),
- 5001: (15, 76, 100),
- 5002: (0, 56, 123),
- 5003: (31, 56, 85),
- 5004: (25, 30, 40),
- 5005: (0, 83, 135),
- 5007: (55, 107, 140),
- 5008: (43, 58, 68),
- 5009: (34, 95, 120),
- 5010: (0, 79, 124),
- 5011: (26, 43, 60),
- 5012: (0, 137, 182),
- 5013: (25, 49, 83),
- 5014: (99, 125, 150),
- 5015: (0, 124, 176),
- 5017: (0, 91, 140),
- 5018: (5, 139, 140),
- 5019: (0, 94, 131),
- 5020: (0, 65, 75),
- 5021: (0, 117, 119),
- 5022: (34, 45, 90),
- 5023: (66, 105, 140),
- 5024: (96, 147, 172),
- 5025: (33, 105, 124),
- 5026: (15, 48, 82),
- 6000: (60, 116, 96),
- 6001: (54, 103, 53),
- 6002: (50, 89, 40),
- 6003: (80, 83, 60),
- 6004: (2, 68, 66),
- 6005: (17, 66, 50),
- 6006: (60, 57, 46),
- 6007: (44, 50, 34),
- 6008: (55, 52, 42),
- 6009: (39, 53, 42),
- 6010: (77, 111, 57),
- 6011: (108, 124, 89),
- 6012: (48, 61, 58),
- 6013: (125, 118, 90),
- 6014: (71, 65, 53),
- 6015: (61, 61, 54),
- 6016: (0, 105, 76),
- 6017: (88, 127, 64),
- 6018: (97, 153, 59),
- 6019: (185, 206, 172),
- 6020: (55, 66, 47),
- 6021: (138, 153, 119),
- 6022: (58, 51, 39),
- 6024: (0, 131, 81),
- 6025: (94, 110, 59),
- 6026: (0, 95, 78),
- 6027: (126, 186, 181),
- 6028: (49, 84, 66),
- 6029: (0, 111, 61),
- 6032: (35, 127, 82),
- 6033: (70, 135, 127),
- 6034: (122, 172, 172),
- 6035: (25, 77, 37),
- 6036: (4, 87, 75),
- 6037: (0, 139, 41),
- 6038: (0, 181, 26),
- 7000: (122, 136, 142),
- 7001: (140, 150, 157),
- 7002: (129, 120, 99),
- 7003: (122, 118, 105),
- 7004: (155, 155, 155),
- 7005: (108, 110, 107),
- 7006: (118, 106, 94),
- 7008: (116, 94, 61),
- 7009: (93, 96, 88),
- 7010: (88, 92, 86),
- 7011: (82, 89, 93),
- 7012: (87, 93, 94),
- 7013: (87, 80, 68),
- 7015: (79, 83, 88),
- 7016: (56, 62, 66),
- 7021: (47, 50, 52),
- 7022: (76, 74, 68),
- 7023: (128, 128, 118),
- 7024: (69, 73, 78),
- 7026: (55, 67, 69),
- 7030: (146, 142, 133),
- 7031: (91, 104, 109),
- 7032: (181, 176, 161),
- 7033: (127, 130, 116),
- 7034: (146, 136, 111),
- 7035: (197, 199, 196),
- 7036: (151, 147, 146),
- 7037: (122, 123, 122),
- 7038: (176, 176, 169),
- 7039: (107, 102, 94),
- 7040: (152, 158, 161),
- 7042: (142, 146, 145),
- 7043: (79, 82, 80),
- 7044: (183, 179, 168),
- 7045: (141, 146, 149),
- 7046: (127, 134, 138),
- 7047: (200, 200, 199),
- 7048: (129, 123, 115),
- 8000: (137, 105, 62),
- 8001: (157, 98, 43),
- 8002: (121, 77, 62),
- 8003: (126, 75, 38),
- 8004: (141, 73, 49),
- 8007: (112, 69, 42),
- 8008: (114, 74, 37),
- 8011: (90, 56, 38),
- 8012: (102, 51, 43),
- 8014: (74, 53, 38),
- 8015: (94, 47, 38),
- 8016: (76, 43, 32),
- 8017: (68, 47, 41),
- 8019: (61, 54, 53),
- 8022: (26, 23, 24),
- 8023: (164, 87, 41),
- 8024: (121, 80, 56),
- 8025: (117, 88, 71),
- 8028: (81, 58, 42),
- 8029: (127, 64, 49),
- 9001: (233, 224, 210),
- 9002: (215, 213, 203),
- 9003: (236, 236, 231),
- 9004: (43, 43, 44),
- 9005: (14, 14, 16),
- 9006: (161, 161, 160),
- 9007: (135, 133, 129),
- 9010: (241, 236, 225),
- 9011: (39, 41, 43),
- 9016: (241, 240, 234),
- 9017: (42, 41, 42),
- 9018: (200, 203, 196),
- 9022: (133, 133, 131),
- 9023: (121, 123, 122),
- }
- class MyCustomTreeNode :
- @classmethod
- def poll(cls, ntree):
- return ntree.bl_idname == 'ShaderNodeTree'
- class MyCustomNode(Node, MyCustomTreeNode):
- '''A custom node'''
- bl_idname = 'CustomNodeType'
- bl_label = 'RAL to RGB'
- bl_icon = 'INFO'
- def update_value(self, context):
- self.outputs["RGB"].default_value = (int(self.RAL), int(self.RAL), int(self.RAL), 1)
- self.update ()
- RAL = bpy.props.StringProperty(default="1000", update = update_value)
- def srgb_to_linear(self, r, g, b):
- def srgb(c):
- a = .055
- if c <= .04045:
- return c / 12.92
- else:
- return ((c+a) / (1+a)) ** 2.4
- return tuple(srgb(c/255) for c in (r, g, b))
- def init(self, context):
- self.outputs.new('NodeSocketColor', "RGB")
- col = self.srgb_to_linear(*RAL_values[int(self.RAL)])
- COLOR = (col[0], col[1], col[2], 1)
- self.outputs["RGB"].default_value = COLOR
- def update(self):
- try:
- out = self.outputs["RGB"]
- can_continue = True
- except:
- can_continue = False
- if can_continue and RAL_values.get(int(self.RAL)):
- if out.is_linked:
- col = self.srgb_to_linear(*RAL_values[int(self.RAL)])
- COLOR = (col[0], col[1], col[2], 1)
- for o in out.links:
- if o.is_valid:
- o.to_socket.node.inputs[o.to_socket.name].default_value = COLOR
- def draw_buttons(self, context, layout):
- layout.prop(self, "RAL",text = 'RAL')
- if not RAL_values.get(int(self.RAL)):
- layout.label("RAL {} not in database".format(self.RAL))
- def draw_label(self):
- return "RAL to RGB"
- import nodeitems_utils
- from nodeitems_utils import NodeCategory, NodeItem
- class MyNodeCategory(NodeCategory):
- @classmethod
- def poll(cls, context):
- return context.space_data.tree_type == 'ShaderNodeTree'
- node_categories = [
- MyNodeCategory("SOMENODES", "RAL to RGB", items=[
- NodeItem("CustomNodeType"),
- ]),
- ]
- def register():
- bpy.utils.register_class(MyCustomNode)
- nodeitems_utils.register_node_categories("CUSTOM_NODES", node_categories)
- def unregister():
- nodeitems_utils.unregister_node_categories("CUSTOM_NODES")
- bpy.utils.unregister_class(MyCustomNode)
- if __name__ == "__main__":
- register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement