本文整理汇总了Python中mathutils.Vector类的典型用法代码示例。如果您正苦于以下问题:Python Vector类的具体用法?Python Vector怎么用?Python Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:paleajed,项目名称:FPSFly,代码行数:7,代码来源:space_view3d_fpsfly.py
示例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()
开发者ID:fjuhec,项目名称:blender-addons,代码行数:30,代码来源:convert.py
示例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)
开发者ID:TomACPace,项目名称:blenderpython,代码行数:25,代码来源:view.py
示例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
开发者ID:Italic-,项目名称:blenderpython,代码行数:60,代码来源:__init__.py
示例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
开发者ID:sambler,项目名称:myblenderaddons,代码行数:29,代码来源:archipack_2d.py
示例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)
开发者ID:elfnor,项目名称:sverchok,代码行数:27,代码来源:update_system.py
示例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)
开发者ID:katosh,项目名称:sym,代码行数:28,代码来源:transformations.py
示例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()
开发者ID:Redoxee,项目名称:blender_python,代码行数:7,代码来源:LSystem.py
示例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()
开发者ID:tigertowel,项目名称:BlenderTreeCurves,代码行数:7,代码来源:Guides.py
示例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
开发者ID:carter2422,项目名称:addon-samples,代码行数:27,代码来源:object_shape_alignment.py
示例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
开发者ID:randfb,项目名称:pyslapi,代码行数:31,代码来源:__init__.py
示例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()
开发者ID:linkedinyou,项目名称:blender-git,代码行数:26,代码来源:utils.py
示例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
开发者ID:johnyc90,项目名称:sverchok,代码行数:26,代码来源:mesh_select.py
示例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()
开发者ID:a-nakanosora,项目名称:Focus-on-Mouse,代码行数:35,代码来源:view3d_focus_on_mouse.py
示例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')
开发者ID:BitByte01,项目名称:myblendercontrib,代码行数:28,代码来源:utils_view3d.py
示例16: va
def va(vx, vz, iang, sang, n): # shortcut Verts.append
for i in range(n):
v = Vector((vx, 0, vz))
ai = sang + iang*i
E_rot = Euler((0, 0, ai), 'XYZ')
v.rotate(E_rot)
Verts.append((v.x, v.y, v.z))
开发者ID:Dancovich,项目名称:blender-addons-fork,代码行数:7,代码来源:add_mesh_round_brilliant.py
示例17: vecscorrect
def vecscorrect(vecs, mats):
out = []
lengthve = len(vecs)-1
for i, m in enumerate(mats):
out_ = []
k = i
if k > lengthve:
k = lengthve
vec_c = Vector((0, 0, 0))
for v in vecs[k]:
vec = v*m
out_.append(vec)
vec_c += vec
vec_c = vec_c / len(vecs[k])
v = out_[1]-out_[0]
w = out_[2]-out_[0]
A = v.y*w.z - v.z*w.y
B = -v.x*w.z + v.z*w.x
C = v.x*w.y - v.y*w.x
#D = -out_[0].x*A - out_[0].y*B - out_[0].z*C
norm = Vector((A, B, C)).normalized()
vec0 = Vector((0, 0, 1))
mat_rot_norm = vec0.rotation_difference(norm).to_matrix().to_4x4()
out_pre = []
for v in out_:
v_out = (v-vec_c) * mat_rot_norm
out_pre.append(v_out[:])
out.append(out_pre)
return out
开发者ID:nortikin,项目名称:sverchok,代码行数:35,代码来源:drop.py
示例18: _apply_planer_map
def _apply_planer_map(bm, uv_layer, size, offset, rotation, tex_aspect):
scale = 1.0 / size
sx = 1.0 * scale
sy = 1.0 * scale
ofx = offset[0]
ofy = offset[1]
rz = rotation * pi / 180.0
aspect = tex_aspect
sel_faces = [f for f in bm.faces if f.select]
# calculate average of normal
n_ave = Vector((0.0, 0.0, 0.0))
for f in sel_faces:
n_ave = n_ave + f.normal
q = n_ave.rotation_difference(Vector((0.0, 0.0, 1.0)))
# update UV coordinate
for f in sel_faces:
for l in f.loops:
co = compat.matmul(q, l.vert.co)
x = co.x * sx
y = co.y * sy
u = x * cos(rz) - y * sin(rz) + ofx
v = -x * aspect * sin(rz) - y * aspect * cos(rz) + ofy
l[uv_layer].uv = Vector((u, v))
开发者ID:nutti,项目名称:Magic-UV,代码行数:29,代码来源:uvw.py
示例19: test_orthogonal
def test_orthogonal(self):
angle_90d = math.pi / 2.0
for v in vector_data:
v = Vector(v)
if v.length_squared != 0.0:
self.assertAlmostEqual(v.angle(v.orthogonal()), angle_90d)
开发者ID:Ichthyostega,项目名称:blender,代码行数:7,代码来源:bl_pyapi_mathutils.py
示例20: rounded_primitive
def rounded_primitive(cls, verts, radius, resolution=2.0):
if not verts: return
if len(verts) == 1:
yield from cls.arc(verts[0], radius, resolution, skip_end=1)
elif len(verts) == 2:
v0, v1 = verts
dv = v1 - v0
angle = Vector((0,1)).angle_signed(Vector((-dv.y, dv.x)), 0.0)
yield from cls.arc(v0, radius, resolution, angle-math.pi, angle)
yield from cls.arc(v1, radius, resolution, angle, angle+math.pi)
elif radius == 0:
yield from verts # exactly the same
else:
vref = Vector((0,1))
count = len(verts)
for i0 in range(count):
v0 = verts[i0]
v1 = verts[(i0 + 1) % count]
v2 = verts[(i0 + 2) % count]
dv10 = v1 - v0
dv21 = v2 - v1
angle10 = vref.angle_signed(Vector((-dv10.y, dv10.x)), 0.0)
angle21 = vref.angle_signed(Vector((-dv21.y, dv21.x)), 0.0)
angle21 = angle10 + clamp_angle(angle21 - angle10)
yield from cls.arc(v1, radius, resolution, angle10, angle21)
开发者ID:TakamitsuNobe,项目名称:myblendercontrib,代码行数:25,代码来源:utils_gl.py
注:本文中的mathutils.Vector类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论