[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3326] contrib/py/scripts/addons/ space_view3d_paint_bprojection.py: BProjection: we can now switch betwen several mesh, don' t need to remove the plane for texturing another mesh, but need a few bug fix, specially for shapekey
geo kgeo
kgeogeo at hotmail.com
Mon Apr 30 22:30:13 CEST 2012
Revision: 3326
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3326
Author: kgeogeo
Date: 2012-04-30 20:30:13 +0000 (Mon, 30 Apr 2012)
Log Message:
-----------
BProjection: we can now switch betwen several mesh, don't need to remove the plane for texturing another mesh, but need a few bug fix, specially for shapekey
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-04-30 09:36:43 UTC (rev 3325)
+++ contrib/py/scripts/addons/space_view3d_paint_bprojection.py 2012-04-30 20:30:13 UTC (rev 3326)
@@ -19,11 +19,12 @@
# Main function for align the plan to view
def align_to_view(context):
- ob = context.object
- rotation = ob.custom_rotation
- scale = ob.custom_scale
- z = ob.custom_location.z
- pos = [ob.custom_location.x, ob.custom_location.y]
+ ob = context.object
+ em = bpy.data.objects['Empty for BProjection']
+ rotation = em.custom_rotation
+ scale = em.custom_scale
+ z = em.custom_location.z
+ pos = [em.custom_location.x, em.custom_location.y]
reg = context.area.regions[4]
width = reg.width
@@ -43,18 +44,17 @@
prop = img.size[0]/img.size[1]
else: prop = 1
- if ob.custom_linkscale:
+ 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 ob.custom_c3d:
- if ob.custom_old_scale != ob.custom_scale:
- pos_cur = em.location - sd.cursor_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)
@@ -66,32 +66,56 @@
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):
- v = Vector((context.object.custom_offsetuv[0]/10 + 0.5, context.object.custom_offsetuv[1]/10 + 0.5))
+ ob = context.object
+ em = bpy.data.objects['Empty for BProjection']
+ v = Vector((em.custom_offsetuv[0]/10 + 0.5, em.custom_offsetuv[1]/10 + 0.5))
l = Vector((0.0,0.0))
- ob = context.object
- s = ob.custom_scaleuv
- os = ob.custom_old_scaleuv
+ s = em.custom_scaleuv
+ os = em.custom_old_scaleuv
scale = s - os
- uvdata = ob.data.uv_layers.active.data
- for i in range(trunc(pow(ob.custom_sub+1, 2)*4)):
- vres = v - uvdata[len(uvdata)-1-i].uv
- uvdata[len(uvdata)-1-i].uv.x = v.x - vres.x/os[0]*s[0]
- uvdata[len(uvdata)-1-i].uv.y = v.y - vres.y/os[1]*s[1]
+ 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]
- ob.custom_old_scaleuv = s
- align_to_view(context)
+ em.custom_old_scaleuv = s
+
+ bpy.ops.object.applyimage()
def update_PropUVScale(self, context):
- ob = context.object
- if ob.custom_linkscaleuv:
- ob.custom_scaleuv = [ob.custom_propscaleuv,ob.custom_propscaleuv]
+ em = bpy.data.objects['Empty for BProjection']
+ if em.custom_linkscaleuv:
+ em.custom_scaleuv = [em.custom_propscaleuv,em.custom_propscaleuv]
def update_LinkUVScale(self, context):
- ob = context.object
- if ob.custom_linkscaleuv:
- ob.custom_propscaleuv = ob.custom_scaleuv.x
+ em = bpy.data.objects['Empty for BProjection']
+ if em.custom_linkscaleuv:
+ em.custom_propscaleuv = em.custom_scaleuv.x
update_PropUVScale(self, context)
else:
update_UVScale(self, context)
@@ -99,41 +123,49 @@
# Function to update the offsetUV
def update_UVOffset(self, context):
ob = context.object
- o = ob.custom_offsetuv
- oo = ob.custom_old_offsetuv
- uvdata = ob.data.uv_layers.active.data
- for i in range(trunc(pow(ob.custom_sub+1, 2)*4)):
- 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]
- ob.custom_old_offsetuv = o
+ em = bpy.data.objects['Empty for BProjection']
+ 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
- align_to_view(context)
+ bpy.ops.object.applyimage()
# Function to update the flip horizontal
-def update_FlipUVX(self, context):
- uvdata = context.object.data.uv_layers.active.data
- for i in range(trunc(pow(context.object.custom_sub+1, 2)*4)):
- x = uvdata[len(uvdata)-1-i].uv[0]
- uvdata[len(uvdata)-1-i].uv[0] = 1 - x
+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
- align_to_view(context)
+ bpy.ops.object.applyimage()
# Function to update the flip vertical
-def update_FlipUVY(self, context):
- uvdata = context.object.data.uv_layers.active.data
- for i in range(trunc(pow(context.object.custom_sub+1, 2)*4)):
- y = uvdata[len(uvdata)-1-i].uv[1]
- uvdata[len(uvdata)-1-i].uv[1] = 1 - y
+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
- align_to_view(context)
+ bpy.ops.object.applyimage()
# Function to update
def update_Rotation(self, context):
- if context.object.custom_rotc3d:
- ob = context.object
- angle = ob.custom_rotation - ob.custom_old_rotation
+ ob = context.object
+ em = bpy.data.objects['Empty for BProjection']
+ 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.copy() - ob.location
+ c = sd.cursor_location - ob.location
e = bpy.data.objects['Empty for BProjection'].location - ob.location
vo = Vector((0.0, 0.0, 1.0))
vo.rotate(vr)
@@ -143,29 +175,28 @@
vr.invert()
v.rotate(vr)
c.rotate(vr)
- context.object.custom_location = c + v
+ em.custom_location = c + v
else:
align_to_view(context)
- context.object.custom_old_rotation = context.object.custom_rotation
+ em.custom_old_rotation = em.custom_rotation
# Function to update scale
def update_Scale(self, context):
ob = context.object
+ em = bpy.data.objects['Empty for BProjection']
- if context.object.custom_scac3d:
- #ob.custom_c3d = False
+ if em.custom_scac3d:
sd = context.space_data
r3d = sd.region_3d
vr = r3d.view_rotation.copy()
vr.invert()
- e = bpy.data.objects['Empty for BProjection'].location - ob.location
- c = sd.cursor_location.copy() - ob.location
+ e = em.location - ob.location
+ c = sd.cursor_location - ob.location
ce = e - c
- s = ob.custom_scale
- os = ob.custom_old_scale
- delta = ob.custom_scale - ob.custom_old_scale
+ s = em.custom_scale
+ os = em.custom_old_scale
c.rotate(vr)
ce.rotate(vr)
@@ -175,32 +206,32 @@
else: prop = 1
v = Vector((s.x*ce.x/os.x, s.y*ce.y/os.y,0.0))
- ob.custom_location = c + v
- #ob.custom_c3d = True
+ em.custom_location = c + v
else:
align_to_view(context)
- ob.custom_old_scale = ob.custom_scale
+ em.custom_old_scale = em.custom_scale
def update_PropScale(self, context):
- ob = context.object
- if ob.custom_linkscale:
- ob.custom_scale = [ob.custom_propscale,ob.custom_propscale]
+ em = bpy.data.objects['Empty for BProjection']
+ if em.custom_linkscale:
+ em.custom_scale = [em.custom_propscale,em.custom_propscale]
def update_LinkScale(self, context):
- ob = context.object
- if ob.custom_linkscale:
- ob.custom_propscale = ob.custom_scale.x
+ em = bpy.data.objects['Empty for BProjection']
+ 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['Empty for BProjection']
if self.custom_active:
- context.object.custom_active_view = self.custom_active_view
+ em.custom_active_view = self.custom_active_view
class custom_props(bpy.types.PropertyGroup):
custom_location = FloatVectorProperty(name="Location", description="Location of the plan",
@@ -283,25 +314,37 @@
# 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)
Ob.custom_scac3d = BoolProperty(name="scac3d", default=False)
Ob.custom_expand = BoolProperty(name="expand", default=True)
Ob.custom_active_view = StringProperty(name = "custom_active_view",default = "View")
+ Ob.custom_active_object = StringProperty(name = "custom_active_object",default = context.object.name)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list