Skip to content
Snippets Groups Projects
space_view3d_paint_bprojection.py 72.7 KiB
Newer Older
  • Learn to ignore specific revisions
  •                         sub.levels = self.tmp_level
                return {'FINISHED'}
    
            return {'RUNNING_MODAL'}
    
        def invoke(self, context, event):
    
            context.window_manager.modal_handler_add(self)
            self.first_mouse.x = event.mouse_region_x
    
            for sub in context.object.modifiers:
                if sub.type in ['SUBSURF', 'MULTIRES']:
                    self.tmp_level = sub.levels
    
                    if sub.levels - self.tmp_level < 0:
    
            return {'RUNNING_MODAL'}
    
    
    # Operator Class to zoom the view3D
    
    class ZoomView3D(Operator):
        bl_idname = "view3d.zoom_view3d"
        bl_label = "Zoom View3D"
    
    
        delta: FloatProperty(
    
            name="delta",
            description="Delta",
            min=-1.0, max=1,
            default=1.0)
    
    
            ob = context.object
            em = bpy.data.objects[BProjection_Empty]
            sd = context.space_data
    
            width = context.region.width
    
            r3d = sd.region_3d
            v_init = Vector((0.0, 0.0, 1.0))
    
            vtr_b = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
    
            vbl_b = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
            len_b = vtr_b - vbl_b
    
            bpy.ops.view3d.zoom(delta=self.delta)
    
            vtr_a = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
    
            vbl_a = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
    
            len_a = vtr_a - vbl_a
    
            fac = len_a.length / len_b.length
    
            r3d.view_location -= ob.location
            r3d.view_location *= fac
            r3d.view_location += ob.location
    
            vres = Vector((em. custom_location. x * fac, em.custom_location. y * fac, em.custom_location.z))
    
            if not em.custom_style_clone:
                em.custom_location = vres
    
            align_to_view(context)
    
            align_to_view(context)
    
    
    # Operator Class to use numpad shortcut
    
    class PresetView3D(Operator):
        bl_idname = "view3d.preset_view3d"
        bl_label = "Preset View3D"
    
    
        view: StringProperty(name="View", description="Select the view", default='TOP')
    
            ob = context.object
            origine = ob.location
            sd = context.space_data
    
            vr_b = sd.region_3d.view_rotation.copy()
            vr_b.invert()
            pos_init = sd.region_3d.view_location - origine
            sd.region_3d.view_location = origine
    
    
            tmp = context.preferences.view.smooth_view
            context.preferences.view.smooth_view = 0
    
            bpy.ops.view3d.viewnumpad(type=self.view)
    
            context.preferences.view.smooth_view = tmp
    
            pos_init.rotate(vr_a * vr_b)
            sd.region_3d.view_location = pos_init + origine
    
    
    class Shortcuts_Pref(AddonPreferences):
        bl_idname = __name__
    
        def draw(self, context):
            layout = self.layout
            scene = context.scene
    
            layout.prop(context.scene, "bp_shortcuts", text="Hot Keys", icon="KEYINGSET")
    
            if scene.bp_shortcuts:
                row = layout.row()
                col = row.column()
    
    
                col.label(text="Hotkey List:")
                col.label(text="Shift + left mouse - Intuitive Scale")
                col.label(text="G + mouse move to translate the projection plane")
                col.label(text="R + mouse move to rotate the projection plane")
                col.label(text="Ctrl + S + mouse move to scale the projection plane")
                col.label(text="U + mouse move to scale the projection plane UV")
                col.label(text="Y + mouse move to offset the projection plane UV")
                col.label(text="C - clear all")
                col.label(text="Q - toggle alpha of the projection plane")
    
    @persistent
    def load_handler(dummy):
        reinitkey()
    
    Geo Kgeo's avatar
    Geo Kgeo committed
    
    
    Geo Kgeo's avatar
    Geo Kgeo committed
    def register():
        bpy.utils.register_module(__name__)
    
        bpy.types.Scene.bp_shortcuts = BoolProperty(
                        default=False,
                        description='Show shortcuts for BP Projection'
                        )
    
        createcustomprops(bpy.context)
        bpy.app.handlers.load_post.append(load_handler)
    
    Geo Kgeo's avatar
    Geo Kgeo committed
    
    
    Geo Kgeo's avatar
    Geo Kgeo committed
    def unregister():
    
        del bpy.types.Scene.bp_shortcuts
    
    Geo Kgeo's avatar
    Geo Kgeo committed
        bpy.utils.unregister_module(__name__)
    
    
    Geo Kgeo's avatar
    Geo Kgeo committed
    if __name__ == "__main__":