[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3181] contrib/py/scripts/addons/ space_view3d_paint_bprojection.py: BProjection: A lot of code clean up and more use of python abilities
geo kgeo
kgeogeo at hotmail.com
Tue Mar 27 01:35:31 CEST 2012
Revision: 3181
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3181
Author: kgeogeo
Date: 2012-03-26 23:35:22 +0000 (Mon, 26 Mar 2012)
Log Message:
-----------
BProjection: A lot of code clean up and more use of python abilities
Modified Paths:
--------------
contrib/py/scripts/addons/space_view3d_paint_bprojection.py
Modified: contrib/py/scripts/addons/space_view3d_paint_bprojection.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_paint_bprojection.py 2012-03-26 22:20:23 UTC (rev 3180)
+++ contrib/py/scripts/addons/space_view3d_paint_bprojection.py 2012-03-26 23:35:22 UTC (rev 3181)
@@ -60,34 +60,30 @@
def update_UVScale(self, context):
v = Vector((context.object.custom_offsetuv[0]/10 + 0.5, context.object.custom_offsetuv[1]/10 + 0.5))
l = Vector((0.0,0.0))
- scale = context.object.custom_scaleuv - context.object.custom_old_scaleuv
- s = context.object.custom_scaleuv
- o = context.object.custom_old_scaleuv
- uvdata = context.object.data.uv_loop_layers.active.data
+ ob = context.object
+ s = ob.custom_scaleuv
+ os = ob.custom_old_scaleuv
+ scale = s - os
+ uvdata = ob.data.uv_loop_layers.active.data
for i in range(484):
- vres = v - uvdata[len(uvdata)-1-i].uv
- l.x = vres.x
- l.y = vres.y
-
- if context.object.custom_linkscaleuv:
- uvdata[len(uvdata)-1-i].uv = [v.x - l.x/o[0]*s[0], v.y - l.y/o[0]*s[0]]
+ vres = v - uvdata[len(uvdata)-1-i].uv
+ if ob.custom_linkscaleuv:
+ uvdata[len(uvdata)-1-i].uv = [v.x - vres.x/os[0]*s[0], v.y - vres.y/os[0]*s[0]]
else:
- uvdata[len(uvdata)-1-i].uv = [v.x - l.x/o[0]*s[0], v.y - l.y/o[1]*s[1]]
-
- context.object.custom_old_scaleuv = context.object.custom_scaleuv
-
-
+ uvdata[len(uvdata)-1-i].uv = [v.x - vres.x/os[0]*s[0], v.y - vres.y/os[1]*s[1]]
+ ob.custom_old_scaleuv = s
+
align_to_view(context)
# Function to update the offsetUV
def update_UVOffset(self, context):
- o = context.object.custom_offsetuv
- oo = context.object.custom_old_offsetuv
- uvdata = context.object.data.uv_loop_layers.active.data
+ ob = context.object
+ o = ob.custom_offsetuv
+ oo = ob.custom_old_offsetuv
+ uvdata = ob.data.uv_loop_layers.active.data
for i in range(484):
uvdata[len(uvdata)-1-i].uv = [uvdata[len(uvdata)-1-i].uv[0] - oo[0]/10 + o[0]/10, uvdata[len(uvdata)-1-i].uv[1] - oo[1]/10 + o[1]/10]
- print(oo,o)
- context.object.custom_old_offsetuv = context.object.custom_offsetuv
+ ob.custom_old_offsetuv = o
align_to_view(context)
@@ -96,8 +92,7 @@
uvdata = context.object.data.uv_loop_layers.active.data
for i in range(484):
x = uvdata[len(uvdata)-1-i].uv[0]
- l = 0.5 - x
- uvdata[len(uvdata)-1-i].uv[0] = 0.5 + l
+ uvdata[len(uvdata)-1-i].uv[0] = 1 - x
align_to_view(context)
@@ -105,9 +100,8 @@
def update_FlipUVY(self, context):
uvdata = context.object.data.uv_loop_layers.active.data
for i in range(484):
- x = uvdata[len(uvdata)-1-i].uv[1]
- l = 0.5 - x
- uvdata[len(uvdata)-1-i].uv[1] = 0.5 + l
+ y = uvdata[len(uvdata)-1-i].uv[1]
+ uvdata[len(uvdata)-1-i].uv[1] = 1 - y
align_to_view(context)
@@ -115,26 +109,28 @@
def update_Rotation(self, context):
if context.object.custom_rotc3d:
angle = context.object.custom_rotation - context.object.custom_old_rotation
- c3d = context.space_data.cursor_location
+ sd = context.space_data
+ c3d = sd.cursor_location
em = bpy.data.objects['Empty for BProjection'].location
c = c3d
e = em
v1 = e-c
vo = Vector((0.0, 0.0, 1.0))
- vo.rotate(context.space_data.region_3d.view_rotation)
+ vo.rotate(sd.region_3d.view_rotation)
quat = mathutils.Quaternion(vo, math.radians(float(angle)))
quat = quat
v2 = v1.copy()
v2.rotate(quat)
v = v1 - v2
res = e - v
- context.space_data.region_3d.update()
- x = view3d_utils.location_3d_to_region_2d(context.area.regions[4], context.space_data.region_3d, res)
+ sd.region_3d.update()
+ x = view3d_utils.location_3d_to_region_2d(context.area.regions[4], sd.region_3d, res)
y=[round(x[0]), round(x[1])]
context.object.custom_location = y
else:
align_to_view(context)
+
context.object.custom_old_rotation = context.object.custom_rotation
# Function to create custom properties
@@ -164,88 +160,30 @@
default=(1.0,1.0),min = 0.01, subtype = 'XYZ', size=2,update = update_UVScale)
Ob.custom_old_scaleuv = FloatVectorProperty(name="old_ScaleUV", description="Scale the texture's UV",
default=(1.0,1.0),min = 0.01, subtype = 'XYZ', size=2)
+ Ob.custom_offsetuv = FloatVectorProperty(name="OffsetUV", description="Decal the texture's UV",
+ default=(0.0,0.0), subtype = 'XYZ', size=2,update = update_UVOffset)
+ Ob.custom_old_offsetuv = FloatVectorProperty(name="old_OffsetUV", description="Decal the texture's UV",
+ default=(0.0,0.0), subtype = 'XYZ', size=2)
Ob.custom_linkscaleuv = BoolProperty(name="linkscaleUV", default=True, update = update_UVScale)
Ob.custom_flipuvx = BoolProperty(name="flipuvx", default=False, update = update_FlipUVX)
Ob.custom_flipuvy = BoolProperty(name="flipuvy", default=False, update = update_FlipUVY)
- Ob.custom_offsetuv = FloatVectorProperty(name="OffsetUV", description="Decal the texture's UV",
- default=(0.0,0.0), subtype = 'XYZ', size=2,update = update_UVOffset)
- Ob.custom_old_offsetuv = FloatVectorProperty(name="old_OffsetUV", description="Decal the texture's UV",
- default=(0.0,0.0), subtype = 'XYZ', size=2)
-
# other properties
Ob.custom_c3d = BoolProperty(name="c3d", default=True)
Ob.custom_rot = BoolProperty(name="rot", default=True)
Ob.custom_rotc3d = BoolProperty(name="rotc3d", default=False)
-
+# Function to remove custom properties
def removecustomprops():
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_location')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_rotation')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_old_rotation')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_scale')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_z')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_c3d')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_rot')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_rotc3d')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_scaleuv')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_flipuvx')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_flipuvy')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_linkscale')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_linkscaleuv')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_old_scaleuv')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_offsetuv')
- except:
- nothing = 0
- try:
- bpy.ops.wm.properties_remove(data_path='object',property='custom_old_offsetuv')
- except:
- nothing = 0
+ list_prop = ['custom_location', 'custom_rotation', 'custom_old_rotation', 'custom_scale', 'custom_z', 'custom_c3d',
+ 'custom_rot', 'custom_rotc3d', 'custom_scaleuv', 'custom_flipuvx', 'custom_flipuvy', 'custom_linkscale',
+ 'custom_linkscaleuv', 'custom_old_scaleuv', 'custom_offsetuv', 'custom_old_offsetuv']
+ for prop in list_prop:
+ try:
+ del bpy.context.object[prop]
+ except:
+ do = 'nothing'
-
# Draw Class to show the panel
class BProjection(Panel):
bl_space_type = 'VIEW_3D'
@@ -314,15 +252,16 @@
def execute(self, context):
img = bpy.data.textures['Texture for BProjection'].image
em = bpy.data.objects['Empty for BProjection']
-
+ ob = context.object
+
bpy.ops.object.editmode_toggle()
- f = context.object.data.polygons
- nbface = len(context.object.data.polygons)
- uvdata = context.object.data.uv_textures.active.data
+ f = ob.data.polygons
+ nbface = len(ob.data.polygons)
+ uvdata = ob.data.uv_textures.active.data
wasnul = False
if len(uvdata) == 0:
bpy.ops.object.editmode_toggle()
- uvdata = context.object.data.uv_textures.active.data
+ uvdata = ob.data.uv_textures.active.data
wasnul = True
nbcut = 10
@@ -336,8 +275,9 @@
else:
bpy.ops.paint.texture_paint_toggle()
- context.object.custom_scale = [1,1]
- context.object.data.update()
+ ob.custom_scale = [1,1]
+ ob.data.update()
+
align_to_view(context)
return {'FINISHED'}
@@ -348,39 +288,39 @@
bl_label = "Draw lines"
def invoke(self, context, event):
-
+ ob = context.object
x = event.mouse_region_x
y = event.mouse_region_y
- if len(context.object.grease_pencil.layers.active.frames) == 0:
+ if len(ob.grease_pencil.layers.active.frames) == 0:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list