forked from K-Meech/image-matcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
props.py
228 lines (182 loc) · 6.88 KB
/
props.py
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import bpy
def force_redraw(self, context):
"""This empty update function makes Blender re-draw the panel, which
ensures that e.g. as 3D points are added, they immediately show up in the
UI list"""
pass
def update_active_point_match(self, context):
"""When a new point match is selected, select the corresponding 2D and
3D point"""
active_point_index = self.active_point_index
active_point_match = self.point_matches[active_point_index]
# Select the current 3d point
bpy.ops.object.select_all(action="DESELECT")
if active_point_match.is_point_3d_initialised:
active_point_match.point_3d.select_set(True)
bpy.context.view_layer.objects.active = active_point_match.point_3d
# Select the current 2d point
bpy.ops.clip.select_all(action="DESELECT")
if active_point_match.is_point_2d_initialised:
track_name = active_point_match.point_2d
current_movie_clip = context.edit_movieclip
tracks = current_movie_clip.tracking.objects[0].tracks
for track in tracks:
if track.name == track_name:
track.select = True
tracks.active = track
break
export_types = [("BLENDER", "Blender", "", 1), ("THREEJS", "ThreeJS", "", 2)]
class PointMatch(bpy.types.PropertyGroup):
"""Group of properties representing a 2D-3D point match"""
is_point_2d_initialised: bpy.props.BoolProperty(
name="2D point", description="Is 2D point initialised?", default=False
)
is_point_3d_initialised: bpy.props.BoolProperty(
name="3D point",
description="Is 3D point initialised?",
default=False,
update=force_redraw,
)
point_3d: bpy.props.PointerProperty(name="3D point", type=bpy.types.Object)
# Name of track for this 2D point. Don't seem to be
# able to directly store a pointer to the track
point_2d: bpy.props.StringProperty(
name="Name of point 2D track",
default="",
description="Name of track for this 2D point",
)
class ImageMatch(bpy.types.PropertyGroup):
"""Group of properties representing an image to be matched"""
# Name of image collection/clip - may be a shortened version
# of the full name as Blender has a character limit
name: bpy.props.StringProperty(
name="Name of image collection/clip",
default="",
description="Name of image collection/clip",
)
full_name: bpy.props.StringProperty(
name="Full filename of image",
default="",
description="Full filename of image",
)
movie_clip: bpy.props.PointerProperty(
name="Movie clip for image",
description="Move clip for image",
type=bpy.types.MovieClip,
)
camera: bpy.props.PointerProperty(
name="Camera",
description="Camera for this image",
type=bpy.types.Object,
)
image_collection: bpy.props.PointerProperty(
name="Image collection",
description="Collection for image",
type=bpy.types.Collection,
)
points_3d_collection: bpy.props.PointerProperty(
name="3D points collection",
description="Collection for 3D points of image",
type=bpy.types.Collection,
)
point_matches: bpy.props.CollectionProperty(
type=PointMatch, name="Current points", description="Current points"
)
active_point_index: bpy.props.IntProperty(
name="Active point index",
description="Active point index",
default=0,
update=update_active_point_match,
)
class ImageMatchSettings(bpy.types.PropertyGroup):
"""Group of properties representing overall settings for this plugin"""
export_filepath: bpy.props.StringProperty(
name="Export filepath",
default="",
description="Define the export filepath for image matches",
subtype="FILE_PATH",
)
model: bpy.props.PointerProperty(
name="3D model", description="3D model", type=bpy.types.Object
)
image_match_collection: bpy.props.PointerProperty(
name="Image match collection",
description="Collection for image match results",
type=bpy.types.Collection,
)
image_match_collection_name: bpy.props.StringProperty(
name="Image match collection name",
description="Name of collection for image match results",
default="image-match",
)
image_matches: bpy.props.CollectionProperty(
type=ImageMatch,
name="Current image matches",
description="Current image matches",
)
active_image_index: bpy.props.IntProperty(
name="Active image index", description="Active image index", default=0
)
current_image_name: bpy.props.StringProperty(
name="Current image name", description="Current image name", default=""
)
points_3d_collection_name: bpy.props.StringProperty(
name="3D points collection name",
description="Name for collection of 3D points",
default="points-3d",
)
point_3d_display_size: bpy.props.FloatProperty(
name="Point 3D display size",
description="Display size of empty sphere representing 3D point",
default=0.1,
)
calibrate_focal_length: bpy.props.BoolProperty(
name="Calibrate focal length",
description="Whether to calibrate the focal length",
default=True,
)
calibrate_principal_point: bpy.props.BoolProperty(
name="Calibrate optical center",
description="Whether to calibrate the optical center",
default=False,
)
calibrate_distortion_k1: bpy.props.BoolProperty(
name="Calibrate distortion K1",
description="Whether to calibrate radial distortion K1",
default=False,
)
calibrate_distortion_k2: bpy.props.BoolProperty(
name="Calibrate distortion K2",
description="Whether to calibrate radial distortion K2",
default=False,
)
calibrate_distortion_k3: bpy.props.BoolProperty(
name="Calibrate distortion K3",
description="Whether to calibrate radial distortion K3",
default=False,
)
pnp_calibrate_msg: bpy.props.StringProperty(
name="Information",
description="Calibration Output Message",
default="Reprojection Error: -",
)
pnp_solve_msg: bpy.props.StringProperty(
name="Information",
description="Solver Output Message",
default="Reprojection Error: -"
)
image_filepath: bpy.props.StringProperty(
name="Image filepath",
default="",
description="Define the import filepath for image",
subtype="FILE_PATH",
)
point_mode_enabled: bpy.props.BoolProperty(
name="Point mode enabled",
description="Point mode enabled",
default=False,
update=force_redraw,
)
export_type: bpy.props.EnumProperty(
name="Export type", description="Export type", items=export_types
)