Skip to content
Snippets Groups Projects
shading_nodes.py 64 KiB
Newer Older
Maurice Raybaud's avatar
Maurice Raybaud committed
# ##### 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.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>
""""Nodes based User interface for shaders exported to POV textures."""
import bpy

from bpy.utils import register_class, unregister_class
from bpy.types import Menu, Node, NodeSocket, CompositorNodeTree, TextureNodeTree, Operator
from bpy.props import (
    StringProperty,
    BoolProperty,
    IntProperty,
    FloatProperty,
    FloatVectorProperty,
    EnumProperty,
)
import nodeitems_utils
from nodeitems_utils import NodeCategory, NodeItem


# ---------------------------------------------------------------- #
Maurice Raybaud's avatar
Maurice Raybaud committed
# Pov Nodes init
# ---------------------------------------------------------------- #
Maurice Raybaud's avatar
Maurice Raybaud committed


class PovraySocketUniversal(NodeSocket):
    bl_idname = "PovraySocketUniversal"
    bl_label = "Povray Socket"
    value_unlimited: bpy.props.FloatProperty(default=0.0)
    value_0_1: bpy.props.FloatProperty(min=0.0, max=1.0, default=0.0)
    value_0_10: bpy.props.FloatProperty(min=0.0, max=10.0, default=0.0)
    value_000001_10: bpy.props.FloatProperty(min=0.000001, max=10.0, default=0.0)
    value_1_9: bpy.props.IntProperty(min=1, max=9, default=1)
    value_0_255: bpy.props.IntProperty(min=0, max=255, default=0)
    percent: bpy.props.FloatProperty(min=0.0, max=100.0, default=0.0)

    def draw(self, context, layout, node, text):
        space = context.space_data
        tree = space.edit_tree
        links = tree.links
        if self.is_linked:
            value = []
            for link in links:
                if link.from_node == node:
                    inps = link.to_node.inputs
                    for inp in inps:
                        if inp.bl_idname == "PovraySocketFloat_0_1" and inp.is_linked:
                            prop = "value_0_1"
                            if prop not in value:
                                value.append(prop)
                        if inp.bl_idname == "PovraySocketFloat_000001_10" and inp.is_linked:
                            prop = "value_000001_10"
                            if prop not in value:
                                value.append(prop)
                        if inp.bl_idname == "PovraySocketFloat_0_10" and inp.is_linked:
                            prop = "value_0_10"
                            if prop not in value:
                                value.append(prop)
                        if inp.bl_idname == "PovraySocketInt_1_9" and inp.is_linked:
                            prop = "value_1_9"
                            if prop not in value:
                                value.append(prop)
                        if inp.bl_idname == "PovraySocketInt_0_255" and inp.is_linked:
                            prop = "value_0_255"
                            if prop not in value:
                                value.append(prop)
                        if inp.bl_idname == "PovraySocketFloatUnlimited" and inp.is_linked:
                            prop = "value_unlimited"
                            if prop not in value:
                                value.append(prop)
            if len(value) == 1:
                layout.prop(self, "%s" % value[0], text=text)
            else:
                layout.prop(self, "percent", text="Percent")
        else:
            layout.prop(self, "percent", text=text)

    def draw_color(self, context, node):
        return (1, 0, 0, 1)


class PovraySocketFloat_0_1(NodeSocket):
    bl_idname = "PovraySocketFloat_0_1"
    bl_label = "Povray Socket"
    default_value: bpy.props.FloatProperty(
        description="Input node Value_0_1", min=0, max=1, default=0
    )

    def draw(self, context, layout, node, text):
        if self.is_linked:
            layout.label(text=text)
        else:
            layout.prop(self, "default_value", text=text, slider=True)

    def draw_color(self, context, node):
        return (0.5, 0.7, 0.7, 1)


class PovraySocketFloat_0_10(NodeSocket):
    bl_idname = "PovraySocketFloat_0_10"
    bl_label = "Povray Socket"
    default_value: bpy.props.FloatProperty(
        description="Input node Value_0_10", min=0, max=10, default=0
    )

    def draw(self, context, layout, node, text):
        if node.bl_idname == "ShaderNormalMapNode" and node.inputs[2].is_linked:
            layout.label(text="")
            self.hide_value = True
        if self.is_linked:
            layout.label(text=text)
        else:
            layout.prop(self, "default_value", text=text, slider=True)

    def draw_color(self, context, node):
        return (0.65, 0.65, 0.65, 1)


class PovraySocketFloat_10(NodeSocket):
    bl_idname = "PovraySocketFloat_10"
    bl_label = "Povray Socket"
    default_value: bpy.props.FloatProperty(
        description="Input node Value_10", min=-10, max=10, default=0
    )

    def draw(self, context, layout, node, text):
        if node.bl_idname == "ShaderNormalMapNode" and node.inputs[2].is_linked:
            layout.label(text="")
            self.hide_value = True
        if self.is_linked:
            layout.label(text=text)
        else:
            layout.prop(self, "default_value", text=text, slider=True)

    def draw_color(self, context, node):
        return (0.65, 0.65, 0.65, 1)


class PovraySocketFloatPositive(NodeSocket):
    bl_idname = "PovraySocketFloatPositive"
    bl_label = "Povray Socket"
    default_value: bpy.props.FloatProperty(
        description="Input Node Value Positive", min=0.0, default=0
    )

    def draw(self, context, layout, node, text):
        if self.is_linked:
            layout.label(text=text)
        else:
            layout.prop(self, "default_value", text=text, slider=True)

    def draw_color(self, context, node):
        return (0.045, 0.005, 0.136, 1)


class PovraySocketFloat_000001_10(NodeSocket):
    bl_idname = "PovraySocketFloat_000001_10"
    bl_label = "Povray Socket"
    default_value: bpy.props.FloatProperty(min=0.000001, max=10, default=0.000001)

    def draw(self, context, layout, node, text):
        if self.is_output or self.is_linked:
            layout.label(text=text)
        else:
            layout.prop(self, "default_value", text=text, slider=True)

    def draw_color(self, context, node):
        return (1, 0, 0, 1)


class PovraySocketFloatUnlimited(NodeSocket):
    bl_idname = "PovraySocketFloatUnlimited"
    bl_label = "Povray Socket"
    default_value: bpy.props.FloatProperty(default=0.0)

    def draw(self, context, layout, node, text):
        if self.is_linked:
            layout.label(text=text)
        else:
            layout.prop(self, "default_value", text=text, slider=True)

    def draw_color(self, context, node):
        return (0.7, 0.7, 1, 1)

Loading
Loading full blame...