[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3094] contrib/py/scripts/addons/ BProjection.py: Add BProjection.py

Campbell Barton ideasman42 at gmail.com
Tue Mar 13 10:04:48 CET 2012


please give description of the script and link to wiki/docs

On Tue, Mar 13, 2012 at 6:36 PM, geo kgeo <kgeogeo at hotmail.com> wrote:
> Revision: 3094
>          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3094
> Author:   kgeogeo
> Date:     2012-03-13 07:35:58 +0000 (Tue, 13 Mar 2012)
> Log Message:
> -----------
> Add BProjection.py
>
> Added Paths:
> -----------
>    contrib/py/scripts/addons/BProjection.py
>
> Added: contrib/py/scripts/addons/BProjection.py
> ===================================================================
> --- contrib/py/scripts/addons/BProjection.py                            (rev 0)
> +++ contrib/py/scripts/addons/BProjection.py    2012-03-13 07:35:58 UTC (rev 3094)
> @@ -0,0 +1,630 @@
> +bl_info = {
> +    "name": "Z Projection",
> +    "description": "Help Clone tool",
> +    "author": "kgeogeo",
> +    "version": (1, 0),
> +    "blender": (2, 6, 3),
> +    "category": "Paint"}
> +
> +import bpy
> +from bpy.types import Panel, Operator
> +from bpy.props import IntProperty, FloatProperty, BoolProperty, IntVectorProperty, StringProperty
> +from bpy_extras import view3d_utils
> +from mathutils import *
> +from math import *
> +import mathutils
> +import math
> +
> +def align_to_view(context):
> +    ob = context.object
> +    rotation = ob.custom_rotation
> +    scale = ob.custom_scale
> +    z = ob.custom_z
> +    posx = ob.custom_location[0]
> +    posy = ob.custom_location[1]
> +
> +    reg = bpy.context.area.regions[4]
> +    width = reg.width
> +    height = reg.height
> +
> +    r3d =  context.space_data.region_3d
> +    r3d.update()
> +    vl = r3d.view_location
> +    vr = r3d.view_rotation
> +    quat = mathutils.Quaternion((0.0, 0.0, 1.0), math.radians(float(rotation)))
> +
> +    v = Vector((1,0,z))
> +    v.rotate(vr)
> +
> +    pos = (posx,posy)
> +
> +    em = bpy.data.objects['Empty for clone']
> +    img = bpy.data.textures['Texture for clone'].image
> +    if img and img.size[1] != 0:
> +        prop = img.size[0]/img.size[1]
> +        em.scale[0] = prop
> +    else: prop = 1
> +
> +    em.scale =  Vector((prop*scale, scale, scale))
> +    em.location = view3d_utils.region_2d_to_location_3d(context.area.regions[4], r3d, pos, v)
> +    em.rotation_euler = Quaternion.to_euler(vr*quat)
> +
> +class HelpClone(Panel):
> +    bl_space_type = 'VIEW_3D'
> +    bl_region_type = 'UI'
> +    bl_label = "Help Clone"
> +
> +    @classmethod
> +    def poll(cls, context):
> +        return (context.image_paint_object)
> +
> +    def draw(self, context):
> +        layout = self.layout
> +
> +        try:
> +            bpy.data.objects['Empty for clone']
> +
> +            col = layout.column(align =True)
> +            col.operator("object.removecloneplane", text="Remove clone plane")
> +
> +            tex = bpy.data.textures['Texture for clone']
> +
> +            layout.template_ID_preview(tex, "image", open="image.open", rows=3, cols=3)
> +
> +            col = layout.column(align =True)
> +            col.operator('object.applyimage', text = "Apply image")
> +            col = layout.column(align =True)
> +            ob = context.object
> +            col.prop(ob, "custom_c3d",text="Capture Cursor3d")
> +            col.prop(ob, "custom_rot",text="Rotate around selection")
> +            col = layout.column(align =True)
> +            col.prop(ob,'custom_rotation', slider = True)
> +            col.prop(ob,'custom_scale', slider = True)
> +            col.prop(ob,'custom_z', slider = True)
> +            col.prop(ob,'custom_location')
> +            col = layout.column(align =True)
> +            col.prop(ob,'custom_scaleuv', slider = True)
> +            col = layout.column(align =True)
> +            col.prop(ob.material_slots['Material for clone'].material,'alpha', slider = True)
> +
> +        except:
> +            col = layout.column(align =True)
> +            col.operator("object.addcloneplane", text="Add clone plan")
> +
> +class ApplyImage(Operator):
> +    bl_idname = "object.applyimage"
> +    bl_label = "Apply image"
> +
> +    def execute(self, context):
> +        img = bpy.data.textures['Texture for clone'].image
> +        em = bpy.data.objects['Empty for clone']
> +        uvdata = bpy.context.object.data.uv_textures.active.data
> +        uvdata[len(uvdata)-1].image = img
> +        if img and img.size[1] != 0:
> +            prop = img.size[0]/img.size[1]
> +            em.scale[0] = prop
> +
> +        context.object.data.update()
> +        align_to_view(context)
> +
> +        return {'FINISHED'}
> +
> +class DrawLines(Operator):
> +    bl_idname = "object.drawlines"
> +    bl_label = "Draw lines"
> +
> +    def invoke(self, context, event):
> +
> +        x = event.mouse_region_x
> +        y = event.mouse_region_y
> +        if len(bpy.context.object.grease_pencil.layers.active.frames)==0:
> +            bpy.ops.gpencil.draw(mode='DRAW', stroke=[{"name":"", "pen_flip":False,
> +                                                                "is_start":True, "location":(0, 0, 0),
> +                                                                "mouse":(x,y), "pressure":1, "time":0}])
> +        else:
> +            if len(bpy.context.object.grease_pencil.layers.active.frames[0].strokes) < 4:
> +                bpy.ops.gpencil.draw(mode='DRAW', stroke=[{"name":"", "pen_flip":False,
> +                                                                    "is_start":True, "location":(0, 0, 0),
> +                                                                    "mouse":(x,y), "pressure":1, "time":0}])
> +            if len(bpy.context.object.grease_pencil.layers.active.frames[0].strokes) == 4:
> +                s = bpy.context.object.grease_pencil.layers.active.frames[0]
> +                v1 = s.strokes[1].points[0].co - s.strokes[0].points[0].co
> +                v2 = s.strokes[3].points[0].co - s.strokes[2].points[0].co
> +                prop = v1.x/v2.x
> +                bpy.context.object.custom_scale *= abs(prop)
> +                bpy.ops.gpencil.active_frame_delete()
> +
> +        return {'FINISHED'}
> +
> +class AddClonePlane(Operator):
> +    bl_idname = "object.addcloneplane"
> +    bl_label = "Configure"
> +
> +    def creatematerial(self, context):
> +        try:
> +            matclone = bpy.data.materials['Material for clone']
> +        except:
> +            bpy.data.textures.new(name='Texture for clone',type='IMAGE')
> +
> +            bpy.data.materials.new(name='Material for clone')
> +
> +            matclone = bpy.data.materials['Material for clone']
> +            matclone.texture_slots.add()
> +            matclone.use_shadeless = True
> +            matclone.use_transparency = True
> +            matclone.active_texture = bpy.data.textures['Texture for clone']
> +
> +            index = matclone.active_texture_index
> +            matclone.texture_slots[index].texture_coords = 'UV'
> +
> +        old_index = context.object.active_material_index
> +        bpy.ops.object.material_slot_add()
> +        index = context.object.active_material_index
> +        bpy.context.object.material_slots[index].material = bpy.data.materials['Material for clone']
> +        bpy.ops.object.material_slot_assign()
> +        context.object.active_material_index = old_index
> +
> +    def execute(self, context):
> +        try:
> +            bpy.data.objects['Empty for clone']
> +
> +        except:
> +            bpy.ops.paint.texture_paint_toggle()
> +
> +            bpy.context.space_data.show_relationship_lines = False
> +
> +            ob = bpy.context.object
> +
> +            bpy.ops.object.add()
> +            em = bpy.context.object
> +            em.name = "Empty for clone"
> +
> +            bpy.data.scenes['Scene'].objects.active = ob
> +            ob.select = True
> +
> +            bpy.ops.object.editmode_toggle()
> +
> +            bpy.ops.mesh.primitive_plane_add()
> +            bpy.ops.object.vertex_group_assign(new = True)
> +            ob.vertex_groups.active.name = 'texture plane'
> +            bpy.ops.uv.unwrap()
> +
> +            bpy.ops.object.editmode_toggle()
> +            for i in range(4):
> +                ob.data.edges[len(ob.data.edges)-1-i].crease = 1
> +            bpy.ops.object.editmode_toggle()
> +
> +            em.select = True
> +            bpy.ops.object.hook_add_selob()
> +
> +            self.creatematerial(context)
> +
> +            bpy.ops.gpencil.data_add()
> +            bpy.context.object.grease_pencil.draw_mode = 'VIEW'
> +            bpy.ops.gpencil.layer_add()
> +            bpy.context.object.grease_pencil.layers.active.color = [1.0,0,0]
> +
> +            bpy.ops.mesh.hide()
> +
> +            em.select = False
> +            em.hide = True
> +
> +            bpy.ops.object.editmode_toggle()
> +
> +            bpy.ops.object.applyimage()
> +            km = bpy.data.window_managers['WinMan'].keyconfigs['Blender'].keymaps['3D View']
> +            km.keymap_items[3-1].idname = 'view3d.rotate_view3d'
> +            km.keymap_items[19-1].idname = 'view3d.zoom_view3d'
> +            km.keymap_items[19-1].properties.delta = 1.0
> +            km.keymap_items[20-1].idname = 'view3d.zoom_view3d'
> +            km.keymap_items[20-1].properties.delta = -1.0
> +            km.keymap_items[4-1].idname = 'view3d.pan_view3d'
> +            km.keymap_items[26-1].idname = 'view3d.preset_view3d'
> +            km.keymap_items[26-1].properties.view = 'FRONT'
> +            km.keymap_items[28-1].idname = 'view3d.preset_view3d'
> +            km.keymap_items[28-1].properties.view = 'RIGHT'
> +            km.keymap_items[32-1].idname = 'view3d.preset_view3d'
> +            km.keymap_items[32-1].properties.view = 'TOP'
> +            km.keymap_items[34-1].idname = 'view3d.preset_view3d'
> +            km.keymap_items[34-1].properties.view = 'BACK'
> +            km.keymap_items[35-1].idname = 'view3d.preset_view3d'
> +            km.keymap_items[35-1].properties.view = 'LEFT'
> +            km.keymap_items[36-1].idname = 'view3d.preset_view3d'
> +            km.keymap_items[36-1].properties.view = 'BOTTOM'
> +            km = bpy.context.window_manager.keyconfigs.default.keymaps['Image Paint']
> +            kmi = km.keymap_items.new("object.drawlines", 'LEFTMOUSE', 'PRESS', shift=True)
> +
> +            align_to_view(context)
> +
> +            bpy.ops.paint.texture_paint_toggle()
> +
> +        return {'FINISHED'}
> +
> +class RemoveClonePlane(Operator):
> +    bl_idname = "object.removecloneplane"
> +    bl_label = "Configure"
> +
> +    def removematerial(self, context):
> +        i = 0
> +        for ms in context.object.material_slots:
> +            if ms.name == 'Material for clone':
> +                index = i
> +            i+=1
> +
> +        context.object.active_material_index = index
>
> @@ Diff output truncated at 10240 characters. @@
> _______________________________________________
> Bf-extensions-cvs mailing list
> Bf-extensions-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-extensions-cvs



-- 
- Campbell


More information about the Bf-extensions-cvs mailing list