annotate add_track_corners.py @ 3:654e4fd5042c default tip

not sure how blender wants multiple addons in one subdir
author drewp@bigasterisk.com
date Sat, 28 Mar 2020 16:31:49 -0700
parents d22d386c5e04
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
1 import bpy
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
2 from mathutils import Vector
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
3
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
4 class AddTrackCornersOperator(bpy.types.Operator):
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
5 bl_idname = 'clip.add_track_corners'
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
6 bl_label = 'Add track corners'
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
7 bl_description = 'Create new tracks that follow the corners of the active track.'
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
8 bl_options = {'REGISTER', 'UNDO'}
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
9
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
10 dense_fill = bpy.props.BoolProperty(
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
11 name="Dense fill",
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
12 description='Make 8 points (corners and half-edges) instead of just 4',
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
13 default=False,
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
14 )
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
15
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
16 @classmethod
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
17 def _tracks(cls, context):
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
18 clip = context.space_data.clip
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
19 if clip:
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
20 return clip.tracking.tracks
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
21
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
22 @classmethod
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
23 def poll(cls, context):
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
24 tracks = AddTrackCornersOperator._tracks(context)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
25 if tracks:
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
26 return tracks.active
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
27
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
28 def _new_offset_marker(self, base_marker, norm_offset, track):
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
29 co = base_marker.co + norm_offset
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
30 return track.markers.insert_frame(base_marker.frame, co=co)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
31
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
32 def _new_track(self, tracks, name, frame):
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
33 # wrong: always adds to camera, even if active track was
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
34 # on another object
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
35 return tracks.new(name, frame)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
36
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
37 def execute(self, context):
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
38 tracks = self._tracks(context)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
39 track = tracks.active
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
40
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
41 first_frame = min(m.frame for m in track.markers)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
42 for corner_index in range(4):
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
43 new_track = self._new_track(tracks,
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
44 '%s.%s' % (track.name, corner_index),
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
45 first_frame)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
46 for marker in track.markers:
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
47 corner = Vector(marker.pattern_corners[corner_index])
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
48 self._new_offset_marker(marker, corner, new_track)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
49 print("added new track %s" % new_track.name)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
50 if self.dense_fill:
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
51 for c1, c2 in [(0, 1), (1, 2), (2, 3), (3, 0)]:
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
52 new_track = self._new_track(tracks,
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
53 '%s.%s-%s' % (track.name, c1, c2),
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
54 first_frame)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
55 for marker in track.markers:
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
56 corner1 = Vector(marker.pattern_corners[c1])
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
57 corner2 = Vector(marker.pattern_corners[c2])
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
58 self._new_offset_marker(marker,
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
59 corner1.lerp(corner2, .5), new_track)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
60 print("added new dense track %s" % new_track.name)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
61
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
62 return {'FINISHED'}
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
63
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
64 def register():
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
65 bpy.utils.register_module(__name__)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
66
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
67 def unregister():
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
68 bpy.utils.unregister_module(__name__)
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
69
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
70 if __name__ == '__main__':
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
71 register()
d22d386c5e04 some old addons that need updating
drewp@bigasterisk.com
parents:
diff changeset
72