[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1100] contrib/py/scripts/addons: moved to contrib/py/scripts/addons/mesh_vertex_align_25
Brendon Murphy
meta.androcto1 at gmail.com
Sun Oct 17 04:10:55 CEST 2010
Revision: 1100
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1100
Author: meta-androcto
Date: 2010-10-17 04:10:46 +0200 (Sun, 17 Oct 2010)
Log Message:
-----------
moved to contrib/py/scripts/addons/mesh_vertex_align_25
this script is for contrib only
Added Paths:
-----------
contrib/py/scripts/addons/mesh_vertex_align_25/
contrib/py/scripts/addons/mesh_vertex_align_25/__init__.py
contrib/py/scripts/addons/mesh_vertex_align_25/va.py
contrib/py/scripts/addons/mesh_vertex_align_25/va_ex.py
contrib/py/scripts/addons/mesh_vertex_align_25/vertex_align_25.py
Added: contrib/py/scripts/addons/mesh_vertex_align_25/__init__.py
===================================================================
--- contrib/py/scripts/addons/mesh_vertex_align_25/__init__.py (rev 0)
+++ contrib/py/scripts/addons/mesh_vertex_align_25/__init__.py 2010-10-17 02:10:46 UTC (rev 1100)
@@ -0,0 +1,54 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+bl_addon_info = {
+ 'name': 'Vertex align',
+ 'author': 'chromoly',
+ 'version': (0, 3),
+ 'blender': (2, 5, 3),
+ 'api': 31847,
+ 'location': 'View3D > EditMode > Ctrl + A',
+ 'wiki_url': '',
+ 'category': 'Mesh'}
+
+import bpy
+
+try:
+ init_data
+
+ reload(vertex_align_25)
+except:
+ from mesh_vertex_align_25 import vertex_align_25
+
+init_data = True
+
+def register():
+ km = bpy.context.window_manager.keyconfigs.default.keymaps['Mesh']
+ kmi = km.items.new('wm.call_menu', 'A', 'PRESS', ctrl=True)
+ kmi.properties.name = 'mesh.vertex_align'
+
+def unregister():
+ km = bpy.context.window_manager.keyconfigs.default.keymaps['Mesh']
+ for kmi in km.items:
+ if kmi.idname == 'wm.call_menu':
+ if kmi.properties.name == 'mesh.vertex_align':
+ km.items.remove(kmi)
+ break
+
+if __name__ == '__main__':
+ register()
Added: contrib/py/scripts/addons/mesh_vertex_align_25/va.py
===================================================================
--- contrib/py/scripts/addons/mesh_vertex_align_25/va.py (rev 0)
+++ contrib/py/scripts/addons/mesh_vertex_align_25/va.py 2010-10-17 02:10:46 UTC (rev 1100)
@@ -0,0 +1,1206 @@
+# -*- coding: utf-8 -*-
+
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import math
+from functools import reduce
+#import time
+
+import bpy
+import mathutils as Math
+from mathutils import Euler, Matrix, Vector, Quaternion
+import bgl
+
+
+def the_other(ls, item):
+ return ls[ls.index(item) - 1]
+
+
+# pytohon cookbook
+def list_or_tuple(x):
+ return isinstance(x, (list, tuple))
+
+
+def flatten(sequence, to_expand=list_or_tuple):
+ for item in sequence:
+ if to_expand(item):
+ for subitem in flatten(item, to_expand):
+ yield subitem
+ else:
+ yield item
+
+
+class NullClass():
+ def __init__(self):
+ pass
+
+
+### blender-2.5x, python-3.1 ##################################################
+### Math Func #################################################################
+def saacos(fac):
+ if fac <= -1.0:
+ return math.pi
+ elif fac >= 1.0:
+ return 0.0
+ else:
+ return math.acos(fac)
+
+
+def saasin(fac):
+ if fac <= -1.0:
+ return -math.pi / 2.0
+ elif fac >= 1.0:
+ return math.pi / 2.0
+ else:
+ return math.asin(fac)
+
+
+def cross2D(v1, v2):
+ return v1.x * v2.y - v1.y * v2.x
+
+
+def dot2D(v1, v2):
+ return v1.x * v2.x + v1.y * v2.y
+
+
+def triangle_normal(vec1, vec2, vec3):
+ e1 = vec1 - vec2
+ e2 = vec3 - vec2
+
+ n = e2.cross(e1)
+ vec = n.normalize()
+
+ return vec
+
+
+def axis_angle_to_quat(axis, angle, deg=False):
+ if deg:
+ # convert to radians
+ ang = math.radians(angle)
+ else:
+ ang = angle
+ q = Math.Quaternion([1.0, 0.0, 0.0, 0.0])
+ if axis.length == 0.0:
+ return None
+ nor = axis.normalize()
+ si = math.sin(ang / 2)
+ q.w = math.cos(ang / 2)
+ v = nor * si
+ q.x = v.x
+ q.y = v.y
+ q.z = v.z
+
+ return q
+
+
+def rotation_between_vectors_to_quat(vec1, vec2):
+ c = vec1.cross(vec2)
+ axis = c if c.length > 0.0 else Math.Vector([1.0, 0.0, 0.0])
+ #angle = NormalizedVecAngle2(vec1, vec2)
+ angle = saacos(vec1.dot(vec2) / (vec1.length * vec2.length))
+ quat = axis_angle_to_quat(axis, angle)
+
+ return quat
+
+
+def intersect(vec1, vec2, vec3, ray, orig, clip=1):
+ v1 = vec1.copy()
+ v2 = vec2.copy()
+ v3 = vec3.copy()
+ dir = ray.copy().normalize()
+ orig = orig.copy()
+
+ # find vectors for two edges sharing v1
+ e1 = v2 - v1
+ e2 = v3 - v1
+
+ # begin calculating determinant - also used to calculated U parameter
+ pvec = dir.cross(e2)
+
+ # if determinant is near zero, ray lies in plane of triangle
+ det = e1.dot(pvec)
+
+ if (-1E-6 < det < 1E-6):
+ return None
+
+ inv_det = 1.0 / det
+
+ # calculate distance from v1 to ray origin
+ tvec = orig - v1
+
+ # calculate U parameter and test bounds
+ u = tvec.dot(pvec) * inv_det
+ if (clip and (u < 0.0 or u > 1.0)):
+ return None
+
+ # prepare to test the V parameter
+ qvec = tvec.cross(e1)
+
+ # calculate V parameter and test bounds
+ v = dir.dot(qvec) * inv_det
+
+ if (clip and (v < 0.0 or u + v > 1.0)):
+ return None
+
+ # calculate t, ray intersects triangle
+ t = e2.dot(qvec) * inv_det
+
+ dir = dir * t
+ pvec = orig + dir
+
+ return pvec
+
+
+def plane_intersect(loc, normalvec, seg1, seg2, returnstatus=0):
+ zaxis = Vector([0.0, 0.0, 1.0])
+ normal = normalvec.copy()
+ normal.normalize()
+ quat = rotation_between_vectors_to_quat(normal, zaxis)
+ s1 = (seg1 - loc) * quat
+ s2 = (seg2 - loc) * quat
+ t = crossStatus = None
+ if abs(s1[2] - s2[2]) < 1E-6:
+ crossPoint = None
+ if abs(s1[2]) < 1E-6:
+ crossStatus = 3 # 面と重なる
+ else:
+ crossStatus = -1 # 面と平行
+ elif s1[2] == 0.0:
+ crossPoint = seg1
+ t = 0
+ elif s2[2] == 0.0:
+ crossPoint = seg2
+ t = 1
+ else:
+ t = -(s1[2] / (s2[2] - s1[2]))
+ crossPoint = (seg2 - seg1) * t + seg1
+ if t is not None:
+ if 0 <= t <= 1:
+ crossStatus = 2 # seg
+ elif t > 0:
+ crossStatus = 1 # ray
+ else:
+ crossStatus = 0 # line
+ if returnstatus:
+ return crossPoint, crossStatus
+ else:
+ return crossPoint
+
+
+def vedistance(vecp, vec1, vec2, segment=1, returnVerticalPoint=False):
+ dist = None
+ if segment:
+ if DotVecs(vec2 - vec1, vecp - vec1) < 0.0:
+ dist = (vecp - vec1).length
+ elif DotVecs(vec1 - vec2, vecp - vec2) < 0.0:
+ dist = (vecp - vec2).length
+ vec = vec2 - vec1
+ p = vecp - vec1
+ zaxis = Vector([0.0, 0.0, 1.0])
+ quat = rotation_between_vectors_to_quat(vec, zaxis)
+ p2 = quat * p
+ if dist is None:
+ dist = math.sqrt(p2[0] ** 2 + p2[1] ** 2)
+ t = p2[2] / (vec2 - vec1).length
+ verticalPoint = vec1 + vec * t
+
+ if returnVerticalPoint:
+ return dist, verticalPoint
+ else:
+ return dist
+
+
+### View3D ####################################################################
+def check_view(quat, localgrid_quat=None):
+ # 0:Right, 1:Front, 2:Top, 3:Left, 4:Back, 5:Bottom
+ vs = ['right', 'front', 'top', 'left', 'back', 'bottom', 'user']
+ thr = 1E-5
+ si = math.sin(math.radians(45))
+ quats = [(0.5, -0.5, -0.5, -0.5), (si, -si, 0., 0.), (1., 0., 0., 0.),
+ (0.5, -0.5, 0.5, 0.5), (0., 0., si, si), (0., 1., 0., 0.)]
+ if localgrid_quat:
+ for i in range(6):
+ quats[i] = Math.Quaternion(quats[i]).cross(localgrid_quat)
+ for cnt in range(6):
+ if not [1 for i, j in zip(quat, quats[cnt]) if abs(i - j) > thr]:
+ return vs[cnt]
+ if not [1 for i, j in zip(quat, quats[cnt]) if abs(i + j) > thr]:
+ return vs[cnt]
+ else:
+ return vs[-1]
+
+
+def check_view_context(context):
+ spaceview3d = context.space_data
+ enable_localgrid = spaceview3d.localgrid
+ if enable_localgrid:
+ localgrid_quat = spaceview3d.localgrid_quat
+ else:
+ localgrid_quat = None
+
+ rv3d = context.space_data.region_3d
+ if rv3d is None: # toolパネル上にマウスが有る場合
+ if hasattr(context, 'region_data_3d'): # パッチ。region_dataと違い、常に取得する
+ if not spaceview3d.region_quadview:
+ rv3d = context.region_data_3d
+ if rv3d is None:
+ return None
+ if hasattr(rv3d, 'view'):
+ view_upper_case = rv3d.view
+ if view_upper_case in ('PERSPORTHO', 'CAMERA'):
+ view = 'user'
+ else:
+ view = view_upper_case.lower()
+ else:
+ viewmat = rv3d.view_matrix
+ quat = viewmat.rotation_part().to_quat()
+ view = check_view(quat, localgrid_quat)
+ return view
+
+
+def get_view_vector(persmat):
+ # persmat = context.space_data.region_3d.perspective_matrix
+ invpersmat = persmat.copy().invert()
+ v0 = invpersmat * Math.Vector([0, 0, 0])
+ v1 = invpersmat * Math.Vector([0, 0, -1])
+ return (v1 - v0).normalize()
+
+
+def world_to_window_coordinate(vec, pmat, sx, sy, size=3):
+ # return float list
+ '''
+ v = (pmat * vec + Math.Vector([1., 1., 0.])) / 2
+ window_pi = [v[0] * sx, v[1] * sy, v[2]]
+ return window_pi
+ '''
+ v = vec.copy().resize4D()
+ v = pmat * v
+ if v[3] != 0.0:
+ v /= v[3]
+ x = sx / 2 + v[0] * sx / 2
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list