changeset 2:d22d386c5e04

some old addons that need updating
author drewp@bigasterisk.com
date Sat, 28 Mar 2020 15:57:33 -0700
parents d07887d9837e
children 654e4fd5042c
files add_track_corners.py paste_stencil.py
diffstat 2 files changed, 121 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/add_track_corners.py	Sat Mar 28 15:57:33 2020 -0700
@@ -0,0 +1,72 @@
+import bpy
+from mathutils import Vector
+
+class AddTrackCornersOperator(bpy.types.Operator):
+    bl_idname = 'clip.add_track_corners'
+    bl_label = 'Add track corners'
+    bl_description = 'Create new tracks that follow the corners of the active track.'
+    bl_options = {'REGISTER', 'UNDO'}
+
+    dense_fill = bpy.props.BoolProperty(
+        name="Dense fill",
+        description='Make 8 points (corners and half-edges) instead of just 4',
+        default=False,
+    )
+
+    @classmethod
+    def _tracks(cls, context):
+        clip = context.space_data.clip
+        if clip:
+            return clip.tracking.tracks
+    
+    @classmethod
+    def poll(cls, context):
+        tracks = AddTrackCornersOperator._tracks(context)
+        if tracks:
+            return tracks.active
+
+    def _new_offset_marker(self, base_marker, norm_offset, track):
+        co = base_marker.co + norm_offset
+        return track.markers.insert_frame(base_marker.frame, co=co)
+
+    def _new_track(self, tracks, name, frame):
+        # wrong: always adds to camera, even if active track was
+        # on another object
+        return tracks.new(name, frame)
+
+    def execute(self, context):
+        tracks = self._tracks(context)
+        track = tracks.active
+
+        first_frame = min(m.frame for m in track.markers)
+        for corner_index in range(4):
+            new_track = self._new_track(tracks,
+                                        '%s.%s' % (track.name, corner_index),
+                                        first_frame)
+            for marker in track.markers:
+                corner = Vector(marker.pattern_corners[corner_index])
+                self._new_offset_marker(marker, corner, new_track)
+            print("added new track %s" % new_track.name)
+        if self.dense_fill:
+            for c1, c2 in [(0, 1), (1, 2), (2, 3), (3, 0)]:
+                new_track = self._new_track(tracks,
+                                            '%s.%s-%s' % (track.name, c1, c2),
+                                            first_frame)
+                for marker in track.markers:
+                    corner1 = Vector(marker.pattern_corners[c1])
+                    corner2 = Vector(marker.pattern_corners[c2])
+                    self._new_offset_marker(marker,
+                                            corner1.lerp(corner2, .5), new_track)
+                print("added new dense track %s" % new_track.name)
+                    
+        return {'FINISHED'}
+        
+def register():
+   bpy.utils.register_module(__name__)
+  
+def unregister():
+    bpy.utils.unregister_module(__name__)
+  
+if __name__ == '__main__':
+    register()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paste_stencil.py	Sat Mar 28 15:57:33 2020 -0700
@@ -0,0 +1,49 @@
+import subprocess, os
+import bpy
+
+class PasteStencil(bpy.types.Operator):
+    """Paste system clipboard into a new stencil brush"""
+    bl_idname = "brush.paste_stencil"
+    bl_label = "Paste Stencil"
+
+    def execute(self, context):
+        png = subprocess.check_output([
+          'xclip', 
+          '-selection', 'clipboard', 
+          '-target', 'image/png', 
+          '-o']) 
+        for count in range(10000):
+            outPath = os.path.join(bpy.app.tempdir, 'paste-%d.png' % count)
+            if not os.path.exists(outPath):
+                break
+        else:
+            raise ValueError('out of filenames')
+        with open(outPath, 'wb') as f:
+            f.write(png)
+        tx = bpy.data.textures.new('paste0', 'IMAGE')
+        tx.image = bpy.data.images.load(outPath)
+        print('loaded %s' % outPath)
+        slot = bpy.data.brushes['TexDraw'].texture_slot
+        slot.texture = tx
+        slot.tex_paint_map_mode = 'STENCIL'
+            
+        return {"FINISHED"}
+
+
+def register():
+    bpy.utils.register_class(PasteStencil)
+
+def unregister():
+    bpy.utils.unregister_class(PasteStencil)
+
+bl_info = {
+    'name': 'Paste Stencil',
+    "version": (1, 0),
+    "blender": (2, 79, 0),
+    "location": "Brush",
+    "category": "Paint",
+}
+    
+if __name__ == "__main__":
+    register()
+    bpy.ops.brush.paste_stencil()