Welcome to mirror list, hosted at ThFree Co, Russian Federation.

normal_node.py « node_editor « amaranth - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fe77856ad854554e1976c067d3be1a64fc409949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#  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.
"""
Nodes: XYZ Sliders for Normal Node

Tweak the Normal node more accurately by using these sliders. Not the most
intuitive way to tweak, but it helps.

ProTip: Hit Shift+Drag for moving in very small steps.

Coded by Lukas Töenne. Thanks!
Find it on the Properties panel, when selecting a Normal node.
"""


import bpy
from mathutils import Vector


# FEATURE: Normal Node Values, by Lukas Tönne
def init():
    prop_normal_vector = bpy.props.FloatVectorProperty(
        name="Normal", size=3, subtype='XYZ',
        min=-1.0, max=1.0, soft_min=-1.0, soft_max=1.0,
        get=normal_vector_get, set=normal_vector_set
        )
    bpy.types.ShaderNodeNormal.normal_vector = prop_normal_vector
    bpy.types.CompositorNodeNormal.normal_vector = prop_normal_vector


def clear():
    del bpy.types.ShaderNodeNormal.normal_vector
    del bpy.types.CompositorNodeNormal.normal_vector


def normal_vector_get(self):
    return self.outputs['Normal'].default_value


def normal_vector_set(self, values):
    # default_value allows un-normalized values,
    # do this here to prevent awkward results
    values = Vector(values).normalized()
    self.outputs['Normal'].default_value = values


def act_node(context):
    try:
        return context.active_node
    except AttributeError:
        return None


def ui_node_normal_values(self, context):

    node = act_node(context)

    if act_node:
        if node and node.type == 'NORMAL':
            self.layout.prop(node, "normal_vector", text="")

# // FEATURE: Normal Node Values, by Lukas Tönne


def register():
    init()
    bpy.types.NODE_PT_active_node_properties.append(ui_node_normal_values)


def unregister():
    bpy.types.NODE_PT_active_node_properties.remove(ui_node_normal_values)
    clear()