author Gert De Roost Sun, 15 Sep 2013 13:15:30 +0000 (13:15 +0000) committer Gert De Roost Sun, 15 Sep 2013 13:15:30 +0000 (13:15 +0000)

@@ -21,7 +21,7 @@
bl_info = {
"name": "EWOCprojects tools",
"author": "Gert De Roost - paleajed",
-       "version": (1, 3, 0),
+       "version": (1, 3, 1),
"blender": (2, 6, 3),
"location": "View3D > Toolbar and View3D > Specials (W-key)",
"description": "Edit mode tools - contrib version",
@@ -61,7 +61,7 @@ This script is an implementation of the concept of sliding vertices around
bl_info = {
"name": "EdgeTune",
"author": "Gert De Roost",
-       "version": (3, 4, 0),
+       "version": (3, 5, 0),
"blender": (2, 6, 3),
"location": "View3D > Tools",
"description": "Tuning edgeloops by redrawing them manually, sliding verts.",
@@ -296,50 +296,6 @@ class EdgeTune(bpy.types.Operator):

return {'RUNNING_MODAL'}

-
-       def getmatrix(self, obj):
-
-               # Calculate matrix.
-               if obj.rotation_mode == 'AXIS_ANGLE':
-                       # object rotationmode axisangle
-                       ang, x, y, z =  obj.rotation_axis_angle
-                       mat = Matrix.Rotation(-ang, 4, Vector((x, y, z)))
-               elif obj.rotation_mode == 'QUATERNION':
-                       # object rotationmode quaternion
-                       w, x, y, z = obj.rotation_quaternion
-                       x = -x
-                       y = -y
-                       z = -z
-                       quat = Quaternion([w, x, y, z])
-                       mat = quat.to_matrix()
-                       mat.resize_4x4()
-               else:
-                       # object rotationmode euler
-                       ax, ay, az = obj.rotation_euler
-                       mat_rotX = Matrix.Rotation(-ax, 4, 'X')
-                       mat_rotY = Matrix.Rotation(-ay, 4, 'Y')
-                       mat_rotZ = Matrix.Rotation(-az, 4, 'Z')
-               if obj.rotation_mode == 'XYZ':
-                       mat = mat_rotX * mat_rotY * mat_rotZ
-               elif obj.rotation_mode == 'XZY':
-                       mat = mat_rotX * mat_rotZ * mat_rotY
-               elif obj.rotation_mode == 'YXZ':
-                       mat = mat_rotY * mat_rotX * mat_rotZ
-               elif obj.rotation_mode == 'YZX':
-                       mat = mat_rotY * mat_rotZ * mat_rotX
-               elif obj.rotation_mode == 'ZXY':
-                       mat = mat_rotZ * mat_rotX * mat_rotY
-               elif obj.rotation_mode == 'ZYX':
-                       mat = mat_rotZ * mat_rotY * mat_rotX
-
-               # handle object scaling
-               sx, sy, sz = obj.scale
-               mat_scX = Matrix.Scale(sx, 4, Vector([1, 0, 0]))
-               mat_scY = Matrix.Scale(sy, 4, Vector([0, 1, 0]))
-               mat_scZ = Matrix.Scale(sz, 4, Vector([0, 0, 1]))
-               mat = mat_scX * mat_scY * mat_scZ * mat
-
-               return mat

@@ -397,12 +353,19 @@ class EdgeTune(bpy.types.Operator):

-       def getscreencoords(self, vector, reg):
+       def findworldco(self, vec):
+
+               vec = vec.copy()
+               vec.rotate(self.selobj.matrix_world)
+               vec.rotate(self.selobj.matrix_world)
+               vec = vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation()
+               return vec
+
+       def getscreencoords(self, vec, reg):

# calculate screencoords of given Vector
-               vector = vector * self.matrix
-               vector = vector + self.selobj.location
-               prj = self.perspm[reg] * vector.to_4d()
+               vec = self.findworldco(vec)
+               prj = self.perspm[reg] * vec.to_4d()
return (self.halfwidth[reg] + self.halfwidth[reg] * (prj.x / prj.w), self.halfheight[reg] + self.halfheight[reg] * (prj.y / prj.w), prj.z)

@@ -437,12 +400,6 @@ class EdgeTune(bpy.types.Operator):
self.undocolist = []
self.contedge = None

-               self.matrix = self.getmatrix(self.selobj)
-               obj = self.selobj
-               while obj.parent:
-                       self.matrix *= getmatrix(obj.parent)
-                       obj = obj.parent
-
for r in self.regions:
r.tag_redraw()
@@ -467,18 +424,18 @@ class EdgeTune(bpy.types.Operator):
for vert in self.keepverts:
vno = vert.normal
vno.length = 0.0001
-                               vco = (vert.co + vno) * self.matrix + self.selobj.location
+                               vco = self.findworldco(vert.co + vno)
if rv3d.is_perspective:
hit = self.scn.ray_cast(vco, eyeloc)
if hit[0]:
vno = -vno
-                                               vco = (vert.co + vno) * self.matrix + self.selobj.location
+                                               vco = self.findworldco(vert.co + vno)
hit = self.scn.ray_cast(vco, eyevec)
else:
hit = self.scn.ray_cast(vco, vco + eyevec)
if hit[0]:
vno = -vno
-                                               vco = (vert.co + vno) * self.matrix + self.selobj.location
+                                               vco = self.findworldco(vert.co + vno)
hit = self.scn.ray_cast(vco, vco + eyevec)
if not(hit[0]):
visible[vert] = True
index 98600ff..f89835e 100644 (file)
@@ -25,7 +25,7 @@ Documentation

First go to User Preferences->Addons and enable the FastOrigin addon in the Object category.
Select an object.  Invoke addon (button in Tools panel).  When in Object mode, addon will switch into
-EditMode and create a single selected vertex which can be translated by standard means with snapping
+EditMode and create a sinbgl.gle selected vertex which can be translated by standard means with snapping
on for vertices (this can be changed in the standard way to other targets or no snap , the snap target
mode will be retained when using the addon a second time).  The 3D cursor will move along with the vert
to make the chosen position a bit clearer.  The old origin will remain visible during moving, this is
@@ -47,7 +47,7 @@ Save as Default (Optional).
bl_info = {
"name": "FastOrigin",
"author": "Gert De Roost",
-       "version": (0, 3, 0),
+       "version": (0, 4, 0),
"blender": (2, 6, 8),
"location": "View3D > Tools",
"description": "Set object origin with snapping.",
@@ -59,11 +59,12 @@ bl_info = {

import bpy
-import bpy_extras
+from bpy_extras.view3d_utils import location_3d_to_region_2d
import bmesh
-from bgl import glColor3f, glBegin, GL_POLYGON, glVertex2f, glEnd
+import bgl
+import blf
from mathutils import *
-
+import time

class FastOrigin(bpy.types.Operator):
@@ -99,20 +100,18 @@ class FastOrigin(bpy.types.Operator):
return {'PASS_THROUGH'}

del bpy.types.Scene.PreSelOff
# Consolidate changes.
for v in self.vsellist:
-                               v.select = 1
+                               v.select = True
for e in self.esellist:
-                               e.select = 1
+                               e.select = True
for f in self.fsellist:
-                               f.select = 1
+                               f.select = True
self.bm.verts.remove(self.originvert)
+                       bmesh.update_edit_mesh(self.mesh, destructive=True)
self.mesh.update()
self.bm.free()
-                       self.snapelem = context.tool_settings.snap_element
-                       self.snapstate = context.tool_settings.use_snap
context.tool_settings.snap_element = self.snapelsave
context.tool_settings.use_snap = self.snapstsave
bpy.ops.object.editmode_toggle()
@@ -122,55 +121,31 @@ class FastOrigin(bpy.types.Operator):
bpy.ops.object.editmode_toggle()
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
return {'FINISHED'}
+
+               elif event.type == 'ESC':
+                       del bpy.types.Scene.PreSelOff
+                       # Cancel
+                       for v in self.vsellist:
+                               v.select = True
+                       for e in self.esellist:
+                               e.select = True
+                       for f in self.fsellist:
+                               f.select = True
+                       self.bm.verts.remove(self.originvert)
+                       bmesh.update_edit_mesh(self.mesh, destructive=True)
+                       self.mesh.update()
+                       self.bm.free()
+                       context.tool_settings.snap_element = self.snapelsave
+                       context.tool_settings.use_snap = self.snapstsave
+                       self.space3d.cursor_location = self.cursorsave
+                       if self.mode == 'EDIT':
+                               bpy.ops.object.editmode_toggle()
+                       bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
+                       return {'CANCELLED'}

return {'RUNNING_MODAL'}

-       def getmatrix(self):
-
-               # Rotating / panning / zooming 3D view is handled here.
-               # Calculate matrix.
-               if self.selobj.rotation_mode == 'AXIS_ANGLE':
-                       # object rotationmode axisangle
-                       ang, x, y, z =  self.selobj.rotation_axis_angle
-                       self.matrix = Matrix.Rotation(-ang, 4, Vector((x, y, z)))
-               elif self.selobj.rotation_mode == 'QUATERNION':
-                       # object rotationmode quaternion
-                       w, x, y, z = self.selobj.rotation_quaternion
-                       x = -x
-                       y = -y
-                       z = -z
-                       quat = Quaternion([w, x, y, z])
-                       self.matrix = quat.to_matrix()
-                       self.matrix.resize_4x4()
-               else:
-                       # object rotationmode euler
-                       ax, ay, az = self.selobj.rotation_euler
-                       mat_rotX = Matrix.Rotation(-ax, 4, 'X')
-                       mat_rotY = Matrix.Rotation(-ay, 4, 'Y')
-                       mat_rotZ = Matrix.Rotation(-az, 4, 'Z')
-               if self.selobj.rotation_mode == 'XYZ':
-                       self.matrix = mat_rotX * mat_rotY * mat_rotZ
-               elif self.selobj.rotation_mode == 'XZY':
-                       self.matrix = mat_rotX * mat_rotZ * mat_rotY
-               elif self.selobj.rotation_mode == 'YXZ':
-                       self.matrix = mat_rotY * mat_rotX * mat_rotZ
-               elif self.selobj.rotation_mode == 'YZX':
-                       self.matrix = mat_rotY * mat_rotZ * mat_rotX
-               elif self.selobj.rotation_mode == 'ZXY':
-                       self.matrix = mat_rotZ * mat_rotX * mat_rotY
-               elif self.selobj.rotation_mode == 'ZYX':
-                       self.matrix = mat_rotZ * mat_rotY * mat_rotX
-
-               # handle object scaling
-               sx, sy, sz = self.selobj.scale
-               mat_scX = Matrix.Scale(sx, 4, Vector([1, 0, 0]))
-               mat_scY = Matrix.Scale(sy, 4, Vector([0, 1, 0]))
-               mat_scZ = Matrix.Scale(sz, 4, Vector([0, 0, 1]))
-               self.matrix = mat_scX * mat_scY * mat_scZ * self.matrix
-
-
-
def init_fastorigin(self, context):

for space in context.area.spaces:
@@ -178,7 +153,7 @@ class FastOrigin(bpy.types.Operator):
self.space3d = space
self.selobj = context.active_object
self.mesh = self.selobj.data
-               self.area = context.area
+               self.region = context.region

self.rv3ds = {}
for a in bpy.context.screen.areas:
@@ -190,8 +165,6 @@ class FastOrigin(bpy.types.Operator):
if not(r.type == "WINDOW"):
continue
self.rv3ds[r] = sp.region_3d
-
-               self.getmatrix()

self.mode = self.selobj.mode
if self.mode == 'OBJECT':
@@ -212,7 +185,7 @@ class FastOrigin(bpy.types.Operator):
self.fsellist.append(f)

self.snapelem = 'VERTEX'
-               self.snapstate = 1
+               self.snapstate = True

self.snapelsave = context.tool_settings.snap_element
self.snapstsave = context.tool_settings.use_snap
@@ -220,21 +193,22 @@ class FastOrigin(bpy.types.Operator):
context.tool_settings.use_snap = self.snapstate
self.cursorsave = self.space3d.cursor_location.copy()
for v in self.bm.verts:
-                       v.select = 0
+                       v.select = False
context.tool_settings.mesh_select_mode = [True, False, False]
self.originvert = self.bm.verts.new((0, 0, 0))
-               self.originvert.select = 1
+               self.originvert.select = True
bmesh.update_edit_mesh(self.mesh, destructive=True)
self.mesh.update()
-               self.space3d.cursor_location = self.originvert.co
+               self.space3d.cursor_location = self.originvert.co[:]

-       def getscreencoords(self, vector, reg, rv3d):
+       def getscreencoords(self, vec, reg, rv3d):

# calculate screencoords of given Vector
-               vector = vector * self.matrix
-               vector = vector + self.selobj.location
-               return bpy_extras.view3d_utils.location_3d_to_region_2d(reg, rv3d, vector)
+               vec.rotate(self.selobj.matrix_world)
+               vec.rotate(self.selobj.matrix_world)
+               vec =  vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation()
+               return location_3d_to_region_2d(reg, rv3d, vec)

@@ -243,20 +217,29 @@ class FastOrigin(bpy.types.Operator):
drawregion = bpy.context.region

rv3d = self.rv3ds[drawregion]
-
-               self.area.header_text_set(text = "FastOrigin active :  Enter to exit")
-
-               self.space3d.cursor_location = self.originvert.co * self.matrix + self.selobj.location
-
-               glColor3f(1.0,1.0,0)
-               glBegin(GL_POLYGON)
-               x, y = self.getscreencoords(self.originvert.co, drawregion, rv3d)
-               glVertex2f(x-2, y-2)
-               glVertex2f(x-2, y+2)
-               glVertex2f(x+2, y+2)
-               glVertex2f(x+2, y-2)
-               glEnd()
-
+               vec = self.originvert.co.copy()
+               vec.rotate(self.selobj.matrix_world)
+               vec.rotate(self.selobj.matrix_world)
+               self.space3d.cursor_location =  vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation()
+
+               bgl.glColor3f(1.0, 1.0, 0)
+               bgl.glBegin(bgl.GL_POLYGON)
+               x, y = self.getscreencoords(Vector(self.originvert.co), drawregion, rv3d)
+               bgl.glVertex2f(x-2, y-2)
+               bgl.glVertex2f(x-2, y+2)
+               bgl.glVertex2f(x+2, y+2)
+               bgl.glVertex2f(x+2, y-2)
+               bgl.glEnd()
+
+               bgl.glColor3f(1, 1, 0.7)
+               bgl.glMatrixMode(bgl.GL_PROJECTION)