本文整理汇总了Python中mathutils.Vector类的典型用法代码示例。如果您正苦于以下问题:Python Vector类的具体用法?Python Vector怎么用?Python Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: moveup
def moveup(self):
bfvec = Vector((0, 0, 1))
bfvec.length = self.addonprefs.Speed * self.addonprefs.Scale * self.runmulti / self.divi
if self.scn.FPS_Walk:
self.addonprefs.Height += bfvec.length * self.addonprefs.Scale
else:
self.rv3d.view_location += bfvec
示例2: extrusion_to_matrix
def extrusion_to_matrix(entity):
"""
Converts an extrusion vector to a rotation matrix that denotes the transformation between world coordinate system
and the entity's own coordinate system (described by the extrusion vector).
"""
def arbitrary_x_axis(extrusion_normal):
world_y = Vector((0, 1, 0))
world_z = Vector((0, 0, 1))
if abs(extrusion_normal[0]) < 1 / 64 and abs(extrusion_normal[1]) < 1 / 64:
a_x = world_y.cross(extrusion_normal)
else:
a_x = world_z.cross(extrusion_normal)
a_x.normalize()
return a_x, extrusion_normal.cross(a_x)
az = Vector(entity.extrusion)
ax, ay = arbitrary_x_axis(az)
ax4 = ax.to_4d()
ay4 = ay.to_4d()
az4 = az.to_4d()
ax4[3] = 0
ay4[3] = 0
az4[3] = 0
translation = Vector((0, 0, 0, 1))
if hasattr(entity, "elevation"):
if type(entity.elevation) is tuple:
translation = Vector(entity.elevation).to_4d()
else:
translation = (az * entity.elevation).to_4d()
return Matrix((ax4, ay4, az4, translation)).transposed()
示例3: __init__
def __init__(self, context=None, event=None, recalcDPBU=True, dpf=200,
expnames=('Dist {exp}',)):
self.shift = None # *0.1. type:Vector. relativeに影響。
self.lock = None # lock direction. type:Vector. relativeに影響。
self.snap = False # type:Bool
self.origin = Vector() # Rキーで変更
self.current = Vector() # (event.mouse_region_x, event.mouse_region_y, 0)
self.relative = Vector() # shift,lockを考慮
self.dpbu = 1.0 # 初期化時、及びupdateの際に指定した場合に更新。
self.unit_pow = 1.0 # 上記と同様
self.dist = 0.0 # relativesnapを考慮
self.fac = 0.0
self.inputexp = False
self.exp = InputExpression(names=expnames)
#self.finaldist = 0.0 # exp等を考慮した最終的な値
self.exptargets = {}
self.shortcuts = []
if event:
self.origin = Vector((event.mouse_region_x, event.mouse_region_y, \
0.0))
self.dpf = dpf # dot per fac
self.update(context, event, recalcDPBU)
示例4: viewrotate_apply
def viewrotate_apply(self, context, event):
# FIXME
vod = self.vod
x, y = event.x, event.y
if context.user_preferences.inputs.view_rotate_method == 'TRACKBALL':
newvec = calctrackballvec(context.region, event.x, event.y)
dvec = newvec - vod.trackvec
angle = (dvec.length / (2.0 * TRACKBALLSIZE)) * math.pi
angle = angle_wrap_rad(angle)
axis = vod.trackvec.cross(newvec)
q1 = Quaternion(axis, angle)
vod.viewquat = q1 * vod.oldquat
self.viewrotate_apply_dyn_ofs(vod.viewquat)
else:
zvec_global = Vector([0, 0, 1])
sensitivity = 0.007
m = vod.viewquat.to_matrix()
m_inv = m.inverted()
if (zvec_global - m_inv.col[2]).length > 0.001:
xaxis = zvec_global.closs(m_inv.col[0])
if xaxis.dot(m_inv.col[0]) < 0:
xaxis.negate()
fac = zvec_global.angle(m_inv.col[2]) / math.pi
fac = abs(fac - 0.5) * 2
fac *= fac
xaxis = xaxis.lerp(m_inv.col[0], fac)
else:
xaxis = m_inv[0].copy()
quat_local_x = Quaternion(xaxis, sensitivity * - (y - vod.oldy))
quat_local_x = vod.viewquat * quat_local_x
def axis_angle_to_quat_single(axis, angle):
angle_half = angle * 0.5
angle_cos = math.cos(angle_half)
angle_sin = math.sin(angle_half)
axis_index = ['X', 'Y', 'Z'].index(axis)
q = Quaternion([angle_cos, 0, 0, 0])
q[axis_index + 1] = angle_sin
return q
quat_global_z = axis_angle_to_quat_single(
'Z', sensitivity * vod.reverse * (x - vod.oldx))
vod.viewquat = quat_local_x * quat_global_z
self.viewrotate_apply_dyn_ofs(vod.viewquat)
vod.viewquat.normalize()
context.region_data.view_rotation = vod.viewquat.inverted()
if vod.axis_snap:
self.viewrotate_apply_snap(vod)
vod.oldx = x
vod.oldy = y
ED_view3d_camera_lock_sync(vod.v3d, context.region_data)
context.region.tag_redraw()
pass
示例5: proj_z
def proj_z(self, t, dz0, next=None, dz1=0):
"""
length of projection along crossing line / circle
deformation unit vector for profil in z axis at line / line intersection
so f(y) = position of point in yz plane
"""
return Vector((0, 1)), 1
"""
NOTE (to myself):
In theory this is how it has to be done so sections follow path,
but in real world results are better when sections are z-up.
So return a dumb 1 so f(y) = y
"""
if next is None:
dz = dz0 / self.length
else:
dz = (dz1 + dz0) / (self.length + next.length)
return Vector((0, 1)), sqrt(1 + dz * dz)
# 1 / sqrt(1 + (dz0 / self.length) * (dz0 / self.length))
if next is None:
return Vector((-dz0, self.length)).normalized(), 1
v0 = Vector((self.length, dz0))
v1 = Vector((next.length, dz1))
direction = Vector((-dz0, self.length)).normalized() + Vector((-dz1, next.length)).normalized()
adj = v0 * v1
hyp = (v0.length * v1.length)
c = min(1, max(-1, adj / hyp))
size = -cos(pi - 0.5 * acos(c))
return direction.normalized(), size
示例6: do_update_heat_map
def do_update_heat_map(node_list, nodes):
"""
Create a heat map for the node tree,
Needs development.
"""
if not nodes.id_data.sv_user_colors:
color_data = {node.name: (node.color[:], node.use_custom_color) for node in nodes}
nodes.id_data.sv_user_colors = str(color_data)
times = do_update_general(node_list, nodes)
if not times:
return
t_max = max(times)
addon_name = data_structure.SVERCHOK_NAME
addon = bpy.context.user_preferences.addons.get(addon_name)
if addon:
# to use Vector.lerp
cold = Vector(addon.preferences.heat_map_cold)
hot = addon.preferences.heat_map_hot
else:
error("Cannot find preferences")
cold = Vector((1, 1, 1))
hot = (.8, 0, 0)
for name, t in zip(node_list, times):
nodes[name].use_custom_color = True
# linear scale.
nodes[name].color = cold.lerp(hot, t / t_max)
示例7: draw
def draw(self, scene=bpy.context.scene, maxdensity=None, matrix_world=None):
""" draws the reflection plane in the scene """
base = self.rnor * self.roff
#rme = bpy.data.meshes.new('rNormal')
#normalverts = [base, base + self.rnor]
#normaledge = [[0, 1]]
#rme.from_pydata(normalverts,normaledge,[])
#ob_normal = bpy.data.objects.new("rNormal", rme)
#scene.objects.link(ob_normal)
n = Vector() # self rotation in (phi,theta,0)
n.xyz = (-self.co.x,
-self.co.y,
0)
mesh = bpy.ops.mesh.primitive_plane_add(
radius=2,
location = base,
rotation=n.zyx)
obj = bpy.context.active_object
obj.hide = True
if matrix_world:
obj.matrix_world = matrix_world * obj.matrix_world
if maxdensity:
material = bpy.data.materials.new('color')
material.diffuse_color = (self.weight/maxdensity,
1 - self.weight/maxdensity,
1 - self.weight/maxdensity)
mesh = obj.data
mesh.materials.append(material)
示例8: __init__
def __init__(self, position=(0, 0, 0), orientation=(1, 0, 0), vitesse=1, angle=radians(90)):
self.position = Vector(position)
self.orientation = Vector(orientation).normalized()
self.vitesse = vitesse
self.angle = angle
self.memoireEtat = []
self.comportement_initialisation()
示例9: getVector
def getVector(self, point):
vect = Vector((0.0, 0.0, 0.0))
for n in range(0, len(self.guides)):
guide = self.guides[n]
weight = self.weights[n]
vect += guide.getVector(point).normalized() * weight
return vect.normalized()
示例10: shape_circle
def shape_circle(context, orientation):
center = context.scene.cursor_location
active = context.active_object
zed = active.location[2]
base_dir = active.location.xy - center.xy
if orientation == 'XY':
zero_dir = get_xy(base_dir).resized(3)
else:
zero_dir = base_dir.xy.resized(3)
num_objects = len(context.selected_objects)
delta_angle = 2 * math.pi / num_objects
# sort objects based on angle to center
sorted_objects = sorted(context.selected_objects, key=lambda ob: get_angle(base_dir, ob, center))
for i in range(num_objects):
angle = delta_angle * i
euler = Euler((0, 0, -angle))
direction = Vector(zero_dir)
direction.rotate(euler)
sorted_objects[i].location = center + direction
sorted_objects[i].location[2] = zed
示例11: write_camera
def write_camera(self, camera, name="Active Camera"):
pos, target, up = camera.GetOrientation()
bpy.ops.object.add(type='CAMERA', location=pos)
ob = self.context.object
ob.name = name
z = (Vector(pos) - Vector(target))
x = Vector(up).cross(z)
y = z.cross(x)
x.normalize()
y.normalize()
z.normalize()
ob.matrix_world.col[0] = x.resized(4)
ob.matrix_world.col[1] = y.resized(4)
ob.matrix_world.col[2] = z.resized(4)
cam = ob.data
aspect_ratio = camera.aspect_ratio
fov = camera.fov
if aspect_ratio == False: # we seem to be using dynamic / screen aspect ratio
sketchupLog("CAMERA {} uses dynamic / screen aspect ratio ".format(name))
aspect_ratio = self.aspect_ratio
if fov == False:
sketchupLog("CAMERA {} is ortho ".format(name))
cam.type = 'ORTHO'
else:
cam.angle = (pi * fov / 180 ) * aspect_ratio
cam.clip_end = self.prefs.camera_far_plane
cam.name = name
示例12: stroke_normal
def stroke_normal(it):
"""
Compute the 2D normal at the stroke vertex pointed by the iterator
'it'. It is noted that Normal2DF0D computes normals based on
underlying FEdges instead, which is inappropriate for strokes when
they have already been modified by stroke geometry modifiers.
"""
# first stroke segment
it_next = it.incremented()
if it.is_begin:
e = it_next.object.point_2d - it.object.point_2d
n = Vector((e[1], -e[0]))
return n.normalized()
# last stroke segment
it_prev = it.decremented()
if it_next.is_end:
e = it.object.point_2d - it_prev.object.point_2d
n = Vector((e[1], -e[0]))
return n.normalized()
# two subsequent stroke segments
e1 = it_next.object.point_2d - it.object.point_2d
e2 = it.object.point_2d - it_prev.object.point_2d
n1 = Vector((e1[1], -e1[0])).normalized()
n2 = Vector((e2[1], -e2[0])).normalized()
n = (n1 + n2)
return n.normalized()
示例13: by_edge_dir
def by_edge_dir(self, vertices, edges, faces):
percent = self.inputs['Percent'].sv_get(default=[1.0])[0][0]
direction = self.inputs['Direction'].sv_get()[0][0]
dirvector = Vector(direction)
dirlength = dirvector.length
if dirlength <= 0:
raise ValueError("Direction vector must have nonzero length!")
values = []
for i, j in edges:
u = vertices[i]
v = vertices[j]
edge = Vector(u) - Vector(v)
if edge.length > 0:
value = abs(edge.dot(dirvector)) / (edge.length * dirlength)
else:
value = 0
values.append(value)
threshold = self.map_percent(values, percent)
out_edges_mask = [(value >= threshold) for value in values]
out_edges = [edge for (edge, mask) in zip (edges, out_edges_mask) if mask]
out_verts_mask = self.select_verts_by_faces(out_edges, vertices)
out_faces_mask = self.select_faces_by_verts(out_verts_mask, faces)
return out_verts_mask, out_edges_mask, out_faces_mask
示例14: focus_view_on
def focus_view_on(region_3d, location):
r3d = region_3d
a = r3d.view_location.copy()
b = location
mm = r3d.view_matrix.inverted()
vr = mm.to_3x3()
loc = mm.translation
n = (a-loc).cross(b-loc).normalized()
alp = math.acos( max(-1.0,min(1.0, (a-loc).normalized().dot( (b-loc).normalized() ) )))
zero = Vector()
u0,v0,w0 = vr.transposed()
u = rot_on( zero, n, alp, u0 )
v = rot_on( zero, n, alp, v0 )
w = rot_on( zero, n, alp, w0 )
if bpy.context.user_preferences.inputs.view_rotate_method == 'TURNTABLE':
ez = Vector((0,0,1))
u2 = ez.cross(w)
v2 = w.cross(u2)
u,v = u2,v2
vr2 = Matrix((u,v,w)).transposed()
mm2 = vr2.to_4x4()
mm2[0][3] = loc[0]
mm2[1][3] = loc[1]
mm2[2][3] = loc[2]
dist0 = (loc-location).length
r3d.view_distance = dist0
r3d.view_matrix = mm2.inverted()
示例15: __get
def __get(self): # in object axes
world_x = Vector((1, 0, 0))
world_z = Vector((0, 0, 1))
x = self.right # right
y = self.forward # forward
z = self.up # up
if abs(y.z) > (1 - 1e-12): # sufficiently close to vertical
roll = 0.0
xdir = x.copy()
else:
xdir = y.cross(world_z)
rollPos = angle_signed(-y, x, xdir, 0.0)
rollNeg = angle_signed(-y, x, -xdir, 0.0)
if abs(rollNeg) < abs(rollPos):
roll = rollNeg
xdir = -xdir
else:
roll = rollPos
xdir = Vector((xdir.x, xdir.y, 0)).normalized()
yaw = angle_signed(-world_z, xdir, world_x, 0.0)
zdir = xdir.cross(y).normalized()
pitch = angle_signed(-xdir, zdir, world_z, 0.0)
return Euler((pitch, roll, yaw), 'YXZ')