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

util.py « curve_tools - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5960318605ce45c9e924267af26f9e8dec1b317f (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# SPDX-License-Identifier: GPL-2.0-or-later

import bpy
from mathutils import *


def GetSelectedCurves():
    rvList = []

    for obj in bpy.context.selected_objects:
        try:
            if obj.type == "CURVE": rvList.append(obj)
        except:
            pass

    return rvList


def GetSelectedMeshes():
    rvList = []

    for obj in bpy.context.selected_objects:
        try:
            if obj.type == "MESH": rvList.append(obj)
        except:
            pass

    return rvList


def Selected1Curve():
    try:
        if len(GetSelectedCurves()) == 1:
            return (bpy.context.active_object.type == "CURVE")
    except:
        pass

    return False


def Selected1Mesh():
    try:
        if len(GetSelectedMeshes()) == 1:
            return (bpy.context.active_object.type == "MESH")
    except:
        pass

    return False


def Selected1SingleSplineCurve():
    try:
        if Selected1Curve():
            return (len(bpy.context.active_object.data.splines) == 1)
    except:
        pass

    return False


def Selected2Curves():
    try:
        if len(GetSelectedCurves()) == 2:
            return (bpy.context.active_object.type == "CURVE")
    except:
        pass

    return False


def Selected3Curves():
    try:
        if len(GetSelectedCurves()) == 3:
            return (bpy.context.active_object.type == "CURVE")
    except:
        pass

    return False


def Selected1OrMoreCurves():
    try:
        if len(GetSelectedCurves()) > 0:
            return (bpy.context.active_object.type == "CURVE")
    except:
        pass

    return False

def Selected2OrMoreCurves():
    try:
        if len(GetSelectedCurves()) > 1:
            return (bpy.context.active_object.type == "CURVE")
    except:
        pass

    return False


def Selected1OrMoreMesh():
    try:
        if len(GetSelectedMeshes()) > 0:
            return (bpy.context.active_object.type == "MESH")
    except:
        pass

    return False


def GetToolsRegion():
    for area in bpy.context.screen.areas:
        if area.type == 'VIEW_3D':
            for region in area.regions:
                if region.type == 'TOOLS': return region

    return None


def GetFirstRegionView3D():
    for area in bpy.context.screen.areas:
        if area.type == 'VIEW_3D':
            return area.spaces[0].region_3d

    return None


def LogFirstRegionView3D():
    print("LogFirstRegionView3D()")
    regionView3D = GetFirstRegionView3D()
    if regionView3D is None:
        print("--", "ERROR:", "regionView3D is None")
        return

    print("--", "view_matrix:")
    print("--", "--", regionView3D.view_matrix)
    print("--", "view_location:")
    print("--", "--", regionView3D.view_location)


class Intersection:
    # listIP: list of BezierSplineIntersectionPoint
    # return: list of splines
    @staticmethod
    def GetBezierSplines(listIP):
        rvList = []

        for ip in listIP:
            if not (ip.spline in rvList): rvList.append(ip.spline)

        return rvList


    # listIP: list of BezierSplineIntersectionPoint
    # return: list of segments
    @staticmethod
    def GetBezierSegments(listIP, spline):
        rvList = []

        for ip in listIP:
            if not ip.spline is spline: continue

            segIP = ip.bezierSegmentIntersectionPoint
            if not (segIP.segment in rvList): rvList.append(segIP.segment)

        return rvList


    # listIP: list of BezierSplineIntersectionPoint
    # return: list of floats (not necessarily ordered)
    @staticmethod
    def GetBezierSegmentParameters(listIP, segment):
        rvList = []

        for ip in listIP:
            segIP = ip.bezierSegmentIntersectionPoint
            if not segIP.segment is segment: continue

            rvList.append(segIP.parameter)

        return rvList