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

vectorized.py « declaration « nodes « startup « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27e608ccce8b3c628ca6cb184213399e6bf05d43 (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
84
85
86
87
88
89
90
91
92
93
94
import bpy
from bpy.props import *
from . base import SocketDeclBase, NoDefaultValue
from .. types import type_infos
from .. utils.generic import getattr_recursive

class VectorizedDeclBase:
    def build(self, node_sockets):
        data_type, name = self.get_type_and_name()
        socket = type_infos.build(
            data_type,
            node_sockets,
            name,
            self.identifier)
        for prop_name, value in self.socket_settings.items():
            setattr(socket, prop_name, value)
        return [socket]

    def validate(self, sockets):
        if len(sockets) != 1:
            return False

        socket = sockets[0]
        for prop_name, value in self.socket_settings.items():
            if getattr(socket, prop_name) != value:
                return False

        data_type, name = self.get_type_and_name()
        return self._data_socket_test(socket,
            name, data_type, self.identifier)

    def amount(self):
        return 1

    def get_type_and_name(self):
        if self.is_vectorized():
            return self.list_type, self.list_name
        else:
            return self.base_type, self.base_name


class VectorizedInputDecl(VectorizedDeclBase, SocketDeclBase):
    def __init__(self,
            node, identifier, prop_name,
            base_name, list_name,
            base_type, default, socket_settings):
        self.node = node
        self.identifier = identifier
        self.prop_name = prop_name
        self.base_name = base_name
        self.list_name = list_name
        self.base_type = base_type
        self.list_type = type_infos.to_list(base_type)
        self.default = default
        self.socket_settings = socket_settings

    def init_default(self, node_sockets):
        if self.default is not NoDefaultValue:
            socket = node_sockets[0]
            socket.restore_state(self.default)

    def is_vectorized(self):
        stored = getattr_recursive(self.node, self.prop_name)
        if stored == "BASE":
            return False
        elif stored == "LIST":
            return True
        else:
            assert False

    @staticmethod
    def Property():
        return StringProperty(default="BASE")


class VectorizedOutputDecl(VectorizedDeclBase, SocketDeclBase):
    def __init__(self,
            node, identifier, input_prop_names,
            base_name, list_name,
            base_type, socket_settings):
        self.node = node
        self.identifier = identifier
        self.input_prop_names = input_prop_names
        self.base_name = base_name
        self.list_name = list_name
        self.base_type = base_type
        self.list_type = type_infos.to_list(base_type)
        self.socket_settings = socket_settings

    def is_vectorized(self):
        for prop_name in self.input_prop_names:
            if getattr_recursive(self.node, prop_name) == "LIST":
                return True
        return False