[Bf-extensions-cvs] [bdab0c1] master: Fix T49185: Fix space_view3d_paint_bprojection to a workable state
lijenstina
noreply at git.blender.org
Wed Sep 7 14:43:35 CEST 2016
Commit: bdab0c1ca2db317f8f990ac797154da5178c57bb
Author: lijenstina
Date: Wed Sep 7 14:42:21 2016 +0200
Branches: master
https://developer.blender.org/rBACbdab0c1ca2db317f8f990ac797154da5178c57bb
Fix T49185: Fix space_view3d_paint_bprojection to a workable state
This add-on seems to be broken for a while.
Brought to a workable state with 2.78
Changes:
Style cleanup
Enabled grease pencil with the changes for 2.78
Fixed a crash with diving by zero
Fixed crash with missing GP draw variable
Cleanup dead code, commented out lines
Added shortcut information in addon preferences
Bumped the version to 0.2.1 and requirements to 2.77.3
===================================================================
M space_view3d_paint_bprojection.py
===================================================================
diff --git a/space_view3d_paint_bprojection.py b/space_view3d_paint_bprojection.py
index 72247c5..632b5d6 100644
--- a/space_view3d_paint_bprojection.py
+++ b/space_view3d_paint_bprojection.py
@@ -2,30 +2,50 @@ bl_info = {
"name": "BProjection",
"description": "Help Clone tool",
"author": "kgeogeo",
- "version": (2, 0),
- "blender": (2, 66, 0),
+ "version": (2, 0, 1),
+ "blender": (2, 77, 3),
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/bprojection",
"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
"category": "Paint"}
import bpy
from bpy.app.handlers import persistent
-from bpy.types import Panel, Operator
-from bpy.props import IntProperty, FloatProperty, BoolProperty, IntVectorProperty, StringProperty, FloatVectorProperty, CollectionProperty
+from bpy.types import (
+ Panel,
+ Operator,
+ PropertyGroup,
+ AddonPreferences,
+ )
+from bpy.props import (
+ IntProperty,
+ FloatProperty,
+ BoolProperty,
+ StringProperty,
+ FloatVectorProperty,
+ CollectionProperty,
+ )
from bpy_extras import view3d_utils
-import math
-from math import *
-import mathutils
-from mathutils import *
-BProjection_Empty = 'Empty for BProjection'
+from math import (
+ radians,
+ sqrt,
+ pi,
+ )
+
+from mathutils import (
+ Quaternion,
+ Vector,
+ )
+
+BProjection_Empty = 'Empty for BProjection'
BProjection_Material = 'Material for BProjection'
-BProjection_Texture = 'Texture for BProjection'
+BProjection_Texture = 'Texture for BProjection'
+
# Main function for align the plan to view
def align_to_view(context):
global last_mouse
- last_mouse = Vector((0,0))
+ last_mouse = Vector((0, 0))
ob = context.object
em = bpy.data.objects[BProjection_Empty]
rotation = em.custom_rotation
@@ -33,32 +53,30 @@ def align_to_view(context):
z = em.custom_location.z
pos = [em.custom_location.x, em.custom_location.y]
- reg = context.region
- width = reg.width
- height = reg.height
-
sd = context.space_data
r3d = sd.region_3d
r3d.update()
vr = r3d.view_rotation
- quat = mathutils.Quaternion((0.0, 0.0, 1.0), math.radians(float(rotation)))
- v = Vector((pos[0],pos[1],z))
+ quat = Quaternion((0.0, 0.0, 1.0), radians(float(rotation)))
+ v = Vector((pos[0], pos[1], z))
v.rotate(vr)
em = bpy.data.objects[BProjection_Empty]
img = bpy.data.textures[BProjection_Texture].image
+
if img and img.size[1] != 0:
- prop = img.size[0]/img.size[1]
- else: prop = 1
+ prop = img.size[0] / img.size[1]
+ else:
+ prop = 1
if em.custom_linkscale:
- em.scale = Vector((prop*scale[0], scale[0], 1))
+ em.scale = Vector((prop * scale[0], scale[0], 1))
else:
- em.scale = Vector((prop*scale[0], scale[1], 1))
+ em.scale = Vector((prop * scale[0], scale[1], 1))
pos_cur = em.location - sd.cursor_location
rot_cur1 = em.rotation_euler.to_quaternion()
em.location = v + ob.location
- em.rotation_euler = Quaternion.to_euler(vr*quat)
+ em.rotation_euler = Quaternion.to_euler(vr * quat)
if em.custom_c3d:
if em.custom_old_scale != em.custom_scale:
pos_cur = em.location - sd.cursor_location
@@ -67,72 +85,77 @@ def align_to_view(context):
pos_cur.rotate(rot_cur1)
pos_cur.rotate(rot_cur2)
v = em.location - pos_cur
- sd.cursor_location = v
+ sd.cursor_location = v
+
def applyimage(context):
- img = bpy.data.textures[BProjection_Texture].image
- em = bpy.data.objects[BProjection_Empty]
- ob = context.object
+ img = bpy.data.textures[BProjection_Texture].image
+ ob = context.object
- face = ob.data.polygons
- uvdata = ob.data.uv_textures.active.data
+ face = ob.data.polygons
+ uvdata = ob.data.uv_textures.active.data
- for f,d in zip(face,uvdata):
- if f.select:
- d.image = img
+ for f, d in zip(face, uvdata):
+ if f.select:
+ d.image = img
+
+ align_to_view(context)
+ ob.data.update()
- align_to_view(context)
- ob.data.update()
# Function to update the properties
def update_Location(self, context):
align_to_view(context)
+
def find_uv(context):
obj = context.object
me = obj.data.vertices
vg = obj.vertex_groups
- l=[]
+ l = []
index_uv = 0
for face in obj.data.polygons:
- x=len(face.vertices)
+ x = len(face.vertices)
for vertex in face.vertices:
- if len(me[vertex].groups)>0:
+ if (len(me[vertex]. groups) > 0):
for g in me[vertex].groups:
if vg[g.group].name == 'texture plane':
- x-=1
-
+ x -= 1
if x == 0:
- l.append([index_uv,len(face.vertices)])
+ l.append([index_uv, len(face. vertices)])
index_uv += len(face.vertices)
return l
+
# Function to update the scaleUV
def update_UVScale(self, context):
ob = context.object
em = bpy.data.objects[BProjection_Empty]
- v = Vector((em.custom_offsetuv[0]/10 + 0.5, em.custom_offsetuv[1]/10 + 0.5))
- l = Vector((0.0,0.0))
+ v = Vector((em.custom_offsetuv[0] / 10 + 0.5, em.custom_offsetuv[1] / 10 + 0.5))
+ l = Vector((0.0, 0.0))
s = em.custom_scaleuv
os = em.custom_old_scaleuv
- scale = s - os
+
l = find_uv(context)
- for i,j in l:
+
+ for i, j in l:
for t in range(j):
- d = context.object.data.uv_layers.active.data[i+t]
- vres = v - d.uv
- d.uv.x = v.x - vres.x/os[0]*s[0]
- d.uv.y = v.y - vres.y/os[1]*s[1]
+ d = ob.data.uv_layers.active.data[i + t]
+ vres = v - d.uv
+ d.uv.x = v.x - vres.x / os[0] * s[0]
+ d.uv.y = v.y - vres.y / os[1] * s[1]
em.custom_old_scaleuv = s
applyimage(context)
+
def update_PropUVScale(self, context):
em = bpy.data.objects[BProjection_Empty]
if em.custom_linkscaleuv:
- em.custom_scaleuv = [em.custom_propscaleuv,em.custom_propscaleuv]
+ em.custom_scaleuv = [em.custom_propscaleuv, em.custom_propscaleuv]
+
def update_LinkUVScale(self, context):
em = bpy.data.objects[BProjection_Empty]
@@ -142,6 +165,7 @@ def update_LinkUVScale(self, context):
else:
update_UVScale(self, context)
+
# Function to update the offsetUV
def update_UVOffset(self, context):
ob = context.object
@@ -149,36 +173,39 @@ def update_UVOffset(self, context):
o = em.custom_offsetuv
oo = em.custom_old_offsetuv
l = find_uv(context)
- for i,j in l:
+ for i, j in l:
for t in range(j):
- d = context.object.data.uv_layers.active.data[i+t]
- d.uv = [d.uv[0] - oo[0]/10 + o[0]/10, d.uv[1] - oo[1]/10 + o[1]/10]
+ d = ob.data.uv_layers.active.data[i + t]
+ d.uv = [d.uv[0] - oo[0] / 10 + o[0] / 10, d.uv[1] - oo[1] / 10 + o[1] / 10]
em.custom_old_offsetuv = o
applyimage(context)
+
# Function to update the flip horizontal
def update_FlipUVX(self, context):
l = find_uv(context)
- for i,j in l:
+ for i, j in l:
for t in range(j):
- d = context.object.data.uv_layers.active.data[i+t]
+ d = context.object.data.uv_layers.active.data[i + t]
x = d.uv.x
d.uv.x = 1 - x
applyimage(context)
+
# Function to update the flip vertical
def update_FlipUVY(self, context):
l = find_uv(context)
- for i,j in l:
+ for i, j in l:
for t in range(j):
- d = context.object.data.uv_layers.active.data[i+t]
+ d = context.object.data.uv_layers.active.data[i + t]
y = d.uv[1]
d.uv[1] = 1 - y
applyimage(context)
+
# Function to update
def update_Rotation(self, context):
ob = context.object
@@ -191,8 +218,8 @@ def update_Rotation(self, context):
e = bpy.data.objects[BProjection_Empty].location - ob.location
vo = Vector((0.0, 0.0, 1.0))
vo.rotate(vr)
- quat = mathutils.Quaternion(vo, math.radians(angle))
- v = e-c
+ quat = Quaternion(vo, radians(angle))
+ v = e - c
v.rotate(quat)
vr.invert()
v.rotate(vr)
@@ -203,6 +230,7 @@ def update_Rotation(self, context):
em.custom_old_rotation = em.custom_rotation
+
# Function to update scale
def update_Scale(self, context):
ob = context.object
@@ -210,7 +238,7 @@ def update_Scale(self, context):
if em.custom_scac3d:
sd = context.space_data
- r3d = sd.region_3d
+ r3d = sd.region_3d
vr = r3d.view_rotation.copy()
vr.invert()
e = em.location - ob.location
@@ -222,24 +250,20 @@ def update_Scale(self, context):
c.rotate(vr)
ce.rotate(vr)
- img = bpy.data.textures[BProjection_Texture].image
- if img and img.size[1] != 0:
- prop = img.size[0]/img.size[1]
- else: prop = 1
-
- v = Vector((s.x*ce.x/os.x, s.y*ce.y/os.y,0.0))
+ v = Vector((s.x * ce.x / os.x, s.y * ce.y / os.y, 0.0))
em.custom_location = c + v
-
else:
align_to_view(context)
em.custom_old_scale = em.custom_scale
+
def update_PropScale(self, context):
em = bpy.data.objects[BProjection_Empty]
if em.custom_linkscale:
- em.custom_scale = [em.custom_propscale,em.custom_propscale]
+ em.custom_scale = [em.custom_propscale, em.custom_propscale]
+
def update_LinkScale(self, context):
em = bpy.data.objects[BProjection_Empty]
@@ -249,11 +273,13 @@ def update_LinkScale(self, context):
else:
update_Scale(self, context)
+
def update_activeviewname(self, context):
em = bpy.data.objects[BProjection_Empty]
if self.custom_active:
em.custom_active_view = self.custom_active_view
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list