本文整理汇总了Python中mathutils.Vector.to_2d方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.to_2d方法的具体用法?Python Vector.to_2d怎么用?Python Vector.to_2d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Vector
的用法示例。
在下文中一共展示了Vector.to_2d方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: orthogonal
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import to_2d [as 别名]
def orthogonal(v): # Vector.orthogonal isn't present in 2.70
size = len(v)
v = (Vector((v[0], v[1], 0.0)) if size == 2 else Vector(v))
if v.length_squared < 1e-8: return Vector.Fill(size)
ort = Vector((0,0,1)).cross(v).normalized()
if ort.length_squared < 0.5:
ort = Vector((0,1,0)).cross(v).normalized()
return (ort.to_2d() if size == 2 else ort)
示例2: transUvVector
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import to_2d [as 别名]
def transUvVector(self):
max_position = 0.
min_position_x = 0.
min_position_y = 0.
# calculate two rotation matrix from normal vector of selected polygons
vector_nor = self.averageNormal()
theta_x = self.calcRotAngle('X', vector_nor.x, vector_nor.y, vector_nor.z)
mat_rotx = Matrix.Rotation(theta_x, 3, 'X')
vector_nor.rotate(mat_rotx)
theta_y = self.calcRotAngle('Y', vector_nor.x, vector_nor.y, vector_nor.z)
mat_roty = Matrix.Rotation(theta_y, 3, 'Y')
# apply two rotation matrix to vertex
uv_array = self.mesh.uv_layers.active.data
for poly in self.select_poly:
for id in range(poly.loop_start, poly.loop_start + poly.loop_total):
new_vector = Vector((self.mesh.vertices[self.mesh.loops[id].vertex_index].co[0],
self.mesh.vertices[self.mesh.loops[id].vertex_index].co[1],
self.mesh.vertices[self.mesh.loops[id].vertex_index].co[2]))
new_vector.rotate(mat_rotx)
new_vector.rotate(mat_roty)
uv_array[id].uv = new_vector.to_2d()
if min_position_x > uv_array[id].uv.x:
min_position_x = uv_array[id].uv.x
if min_position_y > uv_array[id].uv.y:
min_position_y = uv_array[id].uv.y
# recalculate uv position
for poly in self.select_poly:
for id in range(poly.loop_start, poly.loop_start + poly.loop_total):
uv_array[id].uv.x = uv_array[id].uv.x + abs(min_position_x)
uv_array[id].uv.y = uv_array[id].uv.y + abs(min_position_y)
if max_position < uv_array[id].uv.x:
max_position = uv_array[id].uv.x
if max_position < uv_array[id].uv.y:
max_position = uv_array[id].uv.y
# scale uv position
for poly in self.select_poly:
for id in range(poly.loop_start, poly.loop_start + poly.loop_total):
uv_array[id].uv.x = uv_array[id].uv.x * MAX_LOCATION / max_position
uv_array[id].uv.y = uv_array[id].uv.y * MAX_LOCATION / max_position
示例3: Null
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import to_2d [as 别名]
#.........这里部分代码省略.........
self.set_values()
else:
handled = False
elif event.type in ('LEFT_CTRL', 'RIGHT_CTRL'):
if event.value == 'PRESS':
self.snap = True
elif event.value == 'RELEASE':
self.snap = False
self.update(context, event)
self.set_values()
elif event.type == 'MOUSEMOVE':
# <Move Mouse>
self.update(context, event)
self.set_values()
elif shortcut_name == 'lock':
# <Lock Trans Axis>
if self.lock is None:
self.lock = mouseco.copy()
else:
self.lock = None
elif shortcut_name == 'reset':
# <Reset>
if self.lock:
self.lock = self.lock - self.origin + mouseco
self.origin = mouseco.copy()
self.update(context, event)
self.set_values()
else:
handled = False
return handled, False
def update(self, context=None, event=None, recalcDPBU=False):
shift = self.shift
snap = self.snap
lock = self.lock
origin = self.origin
if event:
current = Vector((event.mouse_region_x, event.mouse_region_y, 0.0))
else:
current = self.current
if shift:
relative = shift - origin + (current - shift) * 0.1
else:
relative = current - origin
if lock:
origin_lock = lock - origin
if origin_lock.length >= MIN_NUMBER:
if relative.length >= MIN_NUMBER:
relative = relative.project(origin_lock)
else:
self.lock = None
if context and recalcDPBU:
dpbu, dx, unit_pow = get_DPBU_dx_unit_pow(context.region)
else:
dpbu, unit_pow = self.dpbu, self.unit_pow
dist = relative.length / dpbu
fac = relative.length / self.dpf
if lock:
if relative.dot(origin_lock) < 0.0:
dist = -dist
fac = -fac
if snap:
grid = 10 ** unit_pow
gridf = 0.1
if shift:
grid /= 10
gridf /= 10
dist = grid * math.floor(0.5 + dist / grid)
fac = gridf * math.floor(0.5 + fac / gridf)
self.current = current
self.relative = relative
self.dpbu = dpbu
self.unit_pow = unit_pow
self.dist = dist
self.fac = fac
def draw_origin(self, radius=5, raydirections=[], raylength=5):
draw_sun(self.origin[0], self.origin[1], radius, 16, \
raydirections, raylength)
def draw_relative(self, radius=5):
#if self.shift:
draw_circle(self.origin[0] + self.relative[0], \
self.origin[1] + self.relative[1], radius, 16)
def draw_lock_arrow(self, length=10, angle=math.radians(110)):
if self.lock is not None:
lock = self.lock.to_2d()
origin = self.origin.to_2d()
vec = (origin - lock).normalized()
vec *= 20
vecn = lock + vec
draw_arrow(vecn[0], vecn[1], lock[0], lock[1], \
headlength=length, headangle=angle, headonly=True)
def draw_factor_circle(self, subdivide=64):
draw_circle(self.origin[0], self.origin[1], self.dpf, subdivide)
示例4: GlLine
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import to_2d [as 别名]
#.........这里部分代码省略.........
def p0(self):
return self.p
@property
def p1(self):
return self.p + self.v
@p0.setter
def p0(self, p0):
"""
Note: setting p0
move p0 only
"""
p1 = self.p1
self.p = Vector(p0)
self.v = p1 - p0
@p1.setter
def p1(self, p1):
"""
Note: setting p1
move p1 only
"""
self.v = Vector(p1) - self.p
@property
def length(self):
return self.v.length
@property
def angle(self):
return atan2(self.v.y, self.v.x)
@property
def cross(self):
"""
Vector perpendicular on plane defined by z_axis
lie on the right side
p1
|--x
p0
"""
return self.v.cross(self.z_axis)
def normal(self, t=0):
"""
Line perpendicular on plane defined by z_axis
lie on the right side
p1
|--x
p0
"""
n = GlLine()
n.p = self.lerp(t)
n.v = self.cross
return n
def sized_normal(self, t, size):
"""
GlLine perpendicular on plane defined by z_axis and of given size
positionned at t in current line
lie on the right side
p1
|--x
p0
"""
n = GlLine()
n.p = self.lerp(t)
n.v = size * self.cross.normalized()
return n
def lerp(self, t):
"""
Interpolate along segment
t parameter [0, 1] where 0 is start of arc and 1 is end
"""
return self.p + self.v * t
def offset(self, offset):
"""
offset > 0 on the right part
"""
self.p += offset * self.cross.normalized()
def point_sur_segment(self, pt):
""" point_sur_segment (2d)
point: Vector 3d
t: param t de l'intersection sur le segment courant
d: distance laterale perpendiculaire positif a droite
"""
dp = (pt - self.p).to_2d()
v2d = self.v.to_2d()
dl = v2d.length
d = (self.v.x * dp.y - self.v.y * dp.x) / dl
t = (v2d * dp) / (dl * dl)
return t > 0 and t < 1, d, t
@property
def pts(self):
return [self.p0, self.p1]