[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4330] contrib/py/scripts/addons/ space_view3d_paint_bprojection.py: BProjection: Sorry I' ve not commit the right file
geo kgeo
kgeogeo at hotmail.com
Tue Feb 26 00:15:58 CET 2013
Revision: 4330
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4330
Author: kgeogeo
Date: 2013-02-25 23:15:57 +0000 (Mon, 25 Feb 2013)
Log Message:
-----------
BProjection: Sorry I've not commit the right file
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 2013-02-25 23:10:45 UTC (rev 4329)
+++ contrib/py/scripts/addons/space_view3d_paint_bprojection.py 2013-02-25 23:15:57 UTC (rev 4330)
@@ -3,7 +3,7 @@
"description": "Help Clone tool",
"author": "kgeogeo",
"version": (2, 0),
- "blender": (2, 66, 0),
+ "blender": (2, 6, 6),
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/bprojection",
"tracker_url":"http://projects.blender.org/tracker/index.php?func=detail&aid=30521&group_id=153&atid=468",
"category": "Paint"}
@@ -18,16 +18,1529 @@
import mathutils
from mathutils import *
+BProjection_Empty = 'Empty for BProjection'
+BProjection_Material = 'Material for BProjection'
+BProjection_Texture = 'Texture for BProjection'
+# Main function for align the plan to view
+def align_to_view(context):
+ ob = context.object
+ em = bpy.data.objects[BProjection_Empty]
+ rotation = em.custom_rotation
+ scale = em.custom_scale
+ 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))
+ 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
+
+ if em.custom_linkscale:
+ em.scale = Vector((prop*scale[0], scale[0], 1))
+ else:
+ 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)
+ if em.custom_c3d:
+ if em.custom_old_scale != em.custom_scale:
+ pos_cur = em.location - sd.cursor_location
+ rot_cur2 = em.rotation_euler.to_quaternion()
+ rot_cur1.invert()
+ pos_cur.rotate(rot_cur1)
+ pos_cur.rotate(rot_cur2)
+ v = em.location - pos_cur
+ sd.cursor_location = v
+
+def applyimage(context):
+ img = bpy.data.textures[BProjection_Texture].image
+ em = bpy.data.objects[BProjection_Empty]
+ ob = context.object
+
+ face = ob.data.polygons
+ uvdata = ob.data.uv_textures.active.data
+
+ for f,d in zip(face,uvdata):
+ if f.select:
+ d.image = img
+
+ 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=[]
+ index_uv = 0
+ for face in obj.data.polygons:
+ x=len(face.vertices)
+ for vertex in face.vertices:
+ if len(me[vertex].groups)>0:
+ for g in me[vertex].groups:
+ if vg[g.group].name == 'texture plane':
+ x-=1
+
+
+ if x == 0:
+ 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))
+ s = em.custom_scaleuv
+ os = em.custom_old_scaleuv
+ scale = s - os
+ l = find_uv(context)
+ 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]
+
+ 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]
+
+def update_LinkUVScale(self, context):
+ em = bpy.data.objects[BProjection_Empty]
+ if em.custom_linkscaleuv:
+ em.custom_propscaleuv = em.custom_scaleuv.x
+ update_PropUVScale(self, context)
+ else:
+ update_UVScale(self, context)
+
+# Function to update the offsetUV
+def update_UVOffset(self, context):
+ ob = context.object
+ em = bpy.data.objects[BProjection_Empty]
+ o = em.custom_offsetuv
+ oo = em.custom_old_offsetuv
+ l = find_uv(context)
+ 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]
+ 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 t in range(j):
+ 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 t in range(j):
+ 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
+ em = bpy.data.objects[BProjection_Empty]
+ if em.custom_rotc3d:
+ angle = em.custom_rotation - em.custom_old_rotation
+ sd = context.space_data
+ vr = sd.region_3d.view_rotation.copy()
+ c = sd.cursor_location - ob.location
+ 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
+ v.rotate(quat)
+ vr.invert()
+ v.rotate(vr)
+ c.rotate(vr)
+ em.custom_location = c + v
+ else:
+ align_to_view(context)
+
+ em.custom_old_rotation = em.custom_rotation
+
+# Function to update scale
+def update_Scale(self, context):
+ ob = context.object
+ em = bpy.data.objects[BProjection_Empty]
+
+ if em.custom_scac3d:
+ sd = context.space_data
+ r3d = sd.region_3d
+ vr = r3d.view_rotation.copy()
+ vr.invert()
+ e = em.location - ob.location
+ c = sd.cursor_location - ob.location
+ ce = e - c
+
+ s = em.custom_scale
+ os = em.custom_old_scale
+ 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))
+ 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]
+
+def update_LinkScale(self, context):
+ em = bpy.data.objects[BProjection_Empty]
+ if em.custom_linkscale:
+ em.custom_propscale = em.custom_scale.x
+ update_PropScale(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
+
+class custom_props(bpy.types.PropertyGroup):
+ custom_fnlevel = IntProperty(name="Fast navigate level", description="Increase or decrease the SubSurf level, decrease make navigation faster", default=0)
+
+ custom_location = FloatVectorProperty(name="Location", description="Location of the plane",
+ default=(1.0,0,-1.0),
+ subtype = 'XYZ',
+ soft_min = -10,
+ soft_max = 10,
+ step=0.1,
+ size=3)
+
+ custom_rotation = FloatProperty(name="Rotation", description="Rotate the plane",
+ min=-180, max=180, default=0)
+
+ custom_scale = FloatVectorProperty(name="Scales", description="Scale the planes",
+ default=(1.0, 1.0),
+ subtype = 'XYZ',
+ min = 0.1,
+ max = 10,
+ soft_min=0.1,
+ soft_max=10,
+ step=0.1,
+ size=2)
+ custom_propscale = FloatProperty(name="PropScale", description="Scale the Plane",
+ default=1.0,
+ min = 0.1,
+ max = 10,
+ soft_min=0.1,
+ soft_max=10,
+ step=0.1)
+
+ custom_linkscale = BoolProperty(name="linkscale", default=True)
+
+ # UV properties
+ custom_scaleuv = FloatVectorProperty(name="ScaleUV", description="Scale the texture's UV",
+ default=(1.0,1.0),min = 0.01, subtype = 'XYZ', size=2)
+ custom_propscaleuv = FloatProperty(name="PropScaleUV", description="Scale the texture's UV",
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list