本文整理汇总了Python中mathutils.Vector.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.copy方法的具体用法?Python Vector.copy怎么用?Python Vector.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Vector
的用法示例。
在下文中一共展示了Vector.copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emparentar
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def emparentar(seleccionados):
wm = bpy.context.window_manager
nube, caras, objetos = [], [], []
d1 = Vector([0.06, 0.08, 0.0])
d2 = Vector([0.06, -0.08, 0.0])
d3 = Vector([-0.1, 0.0, 0.0])
c = 0
for ob in seleccionados:
objetos.append(ob)
dd = ob.location
mat = ob.matrix_world
if wm.single:
nube.append(dd)
else:
dd1 = d1.copy()
dd2 = d2.copy()
dd3 = d3.copy()
if wm.rotate:
dd1.rotate(mat)
dd2.rotate(mat)
dd3.rotate(mat)
nube.append(dd + dd1 * wm.scale)
nube.append(dd + dd2 * wm.scale)
nube.append(dd + dd3 * wm.scale)
caras.append([c, c + 1, c + 2])
c += 3
malla = bpy.data.meshes.new('puntos')
padre = bpy.data.objects.new('padre', malla)
bpy.context.scene.objects.link(padre)
padre.hide_render = True
padre.draw_type = 'WIRE'
malla.from_pydata(nube, [], caras)
malla.update()
bpy.context.scene.objects.active = padre
bpy.ops.object.select_all(action = 'DESELECT')
bpy.ops.object.mode_set()
for c in range(len(nube)):
malla.vertices[c].select = False
for c in range(len(objetos)):
objetos[c].select = True
if wm.single:
malla.vertices[c].select = True
else:
for n in range(3):
malla.vertices[c * 3 + n].select = True
bpy.ops.object.editmode_toggle()
bpy.ops.object.vertex_parent_set()
bpy.ops.object.editmode_toggle()
if wm.single:
malla.vertices[c].select = False
else:
for n in range(3):
malla.vertices[c * 3 + n].select = False
objetos[c].select = False
padre.select = True
示例2: createLeaves
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def createLeaves(
tree, probability=0.5, size=0.5, randomsize=0.1, randomrot=0.1, maxconnections=2, bunchiness=1.0, connectoffset=-0.1
):
p = bpy.context.scene.cursor_location
verts = []
faces = []
c1 = Vector((connectoffset, -size / 2, 0))
c2 = Vector((size + connectoffset, -size / 2, 0))
c3 = Vector((size + connectoffset, size / 2, 0))
c4 = Vector((connectoffset, size / 2, 0))
t = gauss(1.0 / probability, 0.1)
bpswithleaves = 0
for bp in tree.branchpoints:
if bp.connections < maxconnections:
dv = tree.branchpoints[bp.parent].v - bp.v if bp.parent else Vector((0, 0, 0))
dvp = Vector((0, 0, 0))
bpswithleaves += 1
nleavesonbp = 0
while t < bpswithleaves:
nleavesonbp += 1
rx = (random() - 0.5) * randomrot * 6.283 # TODO vertical tilt in direction of tropism
ry = (random() - 0.5) * randomrot * 6.283
rot = Euler((rx, ry, random() * 6.283), "ZXY")
scale = 1 + (random() - 0.5) * randomsize
v = c1.copy()
v.rotate(rot)
verts.append(v * scale + bp.v + dvp)
v = c2.copy()
v.rotate(rot)
verts.append(v * scale + bp.v + dvp)
v = c3.copy()
v.rotate(rot)
verts.append(v * scale + bp.v + dvp)
v = c4.copy()
v.rotate(rot)
verts.append(v * scale + bp.v + dvp)
n = len(verts)
faces.append((n - 1, n - 4, n - 3, n - 2))
t += gauss(
1.0 / probability, 0.1
) # this is not the best choice of distribution because we might get negative values especially if sigma is large
dvp = nleavesonbp * (dv / (probability ** bunchiness)) # TODO add some randomness to the offset
mesh = bpy.data.meshes.new("Leaves")
mesh.from_pydata(verts, [], faces)
mesh.update(calc_edges=True)
mesh.uv_textures.new()
return mesh
示例3: __init__
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
class Turtle:
def __init__(self, position=(0, 0, 0),direction =(0,0,1), orientation=(0, 1, 0),axe_rotation = (0,0,1), vitesse=1, angle=90,imperfection = 0.2):
self.position = Vector(position)
self.direction = Vector(direction).normalized()
self.orientation = Vector(orientation).normalized()
self.vitesse = vitesse
self.angle = radians(angle)
self.memoireEtat = []
self.comportement_initialisation()
self.imperfection = imperfection
def comportement_initialisation(self):
self.comportements = {
'+':self.comportement_plus,
'-':self.comportement_moins,
'F':self.comportement_F,
'[':self.comportement_save_etat,
']':self.comportement_restor_etat
}
def comportement_F(self):
p_debut = self.position.copy()
self.position += self.direction * self.vitesse
dx = (random() - 0.5) * self.imperfection
dy = (random() - 0.5) * self.imperfection
dz = (random() - 0.5) * self.imperfection
self.direction += Vector((dx,dy,dz))
p_fin = self.position.copy()
return Section(debut = p_debut,fin = p_fin)
def comportement_save_etat(self):
etat = (self.position.copy(),
self.direction.copy(),
self.vitesse,
self.angle)
self.memoireEtat.append(etat)
def comportement_restor_etat(self):
(self.position,
self.direction,
self.vitesse,
self.angle) = self.memoireEtat.pop()
def comportement_plus(self):
rotation = Matrix.Rotation(self.angle,4,self.orientation)
self.direction.rotate(rotation)
def comportement_moins(self):
rotation = Matrix.Rotation(- self.angle, 4,self.orientation)
self.direction.rotate(rotation)
def interpretation(self,s):
for char in s:
comportement = self.comportements[char]() if char in self.comportements else None
yield comportement
示例4: unmirror_sym
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def unmirror_sym(obj_list):
'''Unmirror symetrical elements.'''
for object in obj_list:
mesh = object.data
# remove the mirror modifier
# set object active
bpy.context.scene.objects.active = object
bpy.ops.object.modifier_remove(modifier='Mirror')
# the first vertice gives us the coordinates for the backtransformation
v = Vector((mesh.vertices[0].co[0], mesh.vertices[0].co[1], mesh.vertices[0].co[2]))
# backtransformation
mesh.transform(Matrix.Translation(-v))
#recalculate !!!!!!! odd behaviour if not done !!!!!!!
mesh.update()
# set location point back
# adaption for FG CSYS
if bpy.context.scene.csys == '1':
object.location = (v)
elif bpy.context.scene.csys == '0':
u = v.copy()
u.x = -u.x
u.y = -u.y
object.location = u
示例5: nautical_euler_from_axes
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def nautical_euler_from_axes(forward, right):
x = Vector(right)
y = Vector(forward)
world_x = Vector((1, 0, 0))
world_z = Vector((0, 0, 1))
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')
示例6: widget_iter_shapekey
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def widget_iter_shapekey(context, mpr, ob, fmap, fmap_target):
from mathutils import (
Vector,
)
# generic initialize
if USE_VERBOSE:
print("(iter-init)")
context.area.header_text_set("ShapeKey face-map: {}".format(fmap.name))
# invoke()
# ...
if USE_VERBOSE:
print("(iter-invoke)")
event = yield
tweak = set()
# modal(), first step
mval_init = Vector((event.mouse_region_x, event.mouse_region_y))
mval = mval_init.copy()
# impl vars
shape = fmap_target
del fmap_target
value_init = shape.value
# Keep this loop fast! runs on mouse-movement.
while True:
event, tweak_next = yield
if event in {True, False}:
break
tweak = tweak_next
if USE_VERBOSE:
print("(iter-modal)", event, tweak)
mval = Vector((event.mouse_region_x, event.mouse_region_y))
input_scale = 1.0
is_precise = 'PRECISE' in tweak
if is_precise:
input_scale /= 10.0
final_value = value_init + ((mval.y - mval_init.y) / 200.0) * input_scale
if 'SNAP' in tweak:
final_value = round(final_value, 2 if is_precise else 1)
shape.value = final_value
# exit()
if USE_VERBOSE:
print("(iter-exit)", event)
if event is True: # cancel
shape.value = scale_init
else:
shape.id_data.keyframe_insert(shape.path_from_id() + ".value")
context.area.header_text_set()
示例7: __init__
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
class Turtle:
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()
def comportement_initialisation(self):
self.comportements = {
'+':self.comportement_plus,
'-':self.comportement_moins,
'F':self.comportement_F,
'[':self.comportement_save_etat,
']':self.comportement_restor_etat
}
def comportement_F(self):
p_debut = self.position.copy()
self.position += self.orientation * self.vitesse
p_fin = self.position.copy()
return Section(debut = p_debut,fin = p_fin)
def comportement_save_etat(self):
etat = (self.position.copy(),
self.orientation.copy(),
self.vitesse,
self.angle)
self.memoireEtat.append(etat)
def comportement_restor_etat(self):
(self.position,
self.orientation,
self.vitesse,
self.angle) = self.memoireEtat.pop()
def comportement_plus(self):
rotation = Matrix.Rotation(self.angle,4,(0,1,0))
self.orientation.rotate(rotation)
def comportement_moins(self):
rotation = Matrix.Rotation(- self.angle, 4,(0,1,0))
self.orientation.rotate(rotation)
def interpretation(self,s):
for char in s:
comportement = self.comportements[char]() if char in self.comportements else None
yield comportement
示例8: __init__
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
class TextBox:
def __init__(self):
self.text = ""
self.position = Vector((0, 0))
self.width = 400
self.background_color = (1.0, 1.0, 1.0, 1.0)
self.background_border_color = (0.9, 0.76, 0.4, 1.0)
self.text_color = (0.1, 0.1, 0.1, 1.0)
self.font_size = 8
self.font = 1
self.line_height = 23
self.padding = 5
def draw(self):
blf.size(self.font, self.font_size, int(getDpi()))
self.calc_lines()
background = self.get_background_rectangle()
background.draw()
glColor4f(*self.text_color)
pos = self.position.copy()
pos.x += self.padding
pos.y -= self.padding - self.line_height / 2
pos.y -= blf.dimensions(self.font, "i")[1] / 2
for i, line in enumerate(self.lines):
pos.y -= self.line_height
blf.position(self.font, pos.x, pos.y, 0)
blf.draw(self.font, line)
def calc_lines(self):
lines = self.text.split("\n")
while len(lines) > 0:
if lines[-1] != "": break
del lines[-1]
self.lines = lines
def get_background_rectangle(self):
self.calc_height()
self.calc_width()
background = Rectangle(
x1 = self.position.x,
y1 = self.position.y,
x2 = self.position.x + self.width,
y2 = self.position.y - self.height )
background.border_thickness = -1
background.color = self.background_color
background.border_color = self.background_border_color
return background
def calc_height(self):
self.height = 2 * self.padding + self.line_height * len(self.lines)
def calc_width(self):
widths = [blf.dimensions(self.font, line)[0] for line in self.lines]
self.width = max(widths) + 2 * self.padding
示例9: spokes
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def spokes(n):
up = Vector((0,1,0))
angle = Euler((0,0,2*pi/float(n)),'XYZ')
angle2 = Euler((0,0,pi/float(n)),'XYZ')
of = rotate(up, angle2)
verts = []
for i in range(n):
verts.append(up.copy())
verts.append(up+of)
up = rotate(up, angle)
verts.append(up+of)
of = rotate(of, angle)
faces = []
for i in range(n):
faces.append((3*i,3*i+1,3*i+2,(3*i+3) % (n*3)))
return verts, faces
示例10: align
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def align(aligny=Vector((0,1,0)), alignz=Vector((0,0,1))):
'''
Get a Rotation Matrix.
The Matrix Local +Y Axis gets aligned with aligny.
The +Z Local Axis gets aligned with alignz as best as possible,
without disturbing the Y alignment.
This implementation looks a little brutish to the Coders eyes.
Better ideas are very welcome.
'''
X=Vector((1,0,0))
Y=Vector((0,1,0))
Z=Vector((0,0,1))
if alignz.length == 0:
alignz = Z.copy()
mat = Matrix().to_3x3()
#Align local-Y axis with aligny
axis, angle = axisangle(Y, aligny)
if axis.length == 0:
axis = X
rot_to_y = Matrix.Rotation(angle,3,axis)
bm1 = get_axis_aligned_bm(rot_to_y)
#Align local-Z with projected alignz
eul = rot_to_y.to_euler()
target_localx = aligny.cross(alignz).normalized()
target_localz = target_localx.cross(aligny).normalized()
angle = target_localz.angle(bm1.verts[2].co)
### NEED SOME TEST FOR ANGLE FLIPPING
eul.rotate_axis('Y', angle)
mat = eul.to_matrix().to_4x4()
### Test if rotation is good
bmf = get_axis_aligned_bm(mat)
dist = distance_point_to_plane(bmf.verts[2].co, target_localz, target_localz.cross(alignz))
error = 1e-06
### Flip the angle
if abs(dist)>error:
eul = rot_to_y.to_euler()
eul.rotate_axis('Y', -angle)
mat = eul.to_matrix().to_4x4()
bm1.free()
bmf.free()
return mat.to_4x4()
示例11: box_selection_vis
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def box_selection_vis(cont):
global b
scene = logic.getCurrentScene()
cam = scene.active_camera
own = cont.owner
click = cont.sensors["MouseClick"]
if click.positive:
if own['held']:
a = Vector(logic.mouse.position)
draw_box(a, b)
else:
a = Vector(logic.mouse.position)
b = a.copy()
own['held'] = True
else:
if own['held']:
own['held'] = False
示例12: invoke
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def invoke(self, context, event):
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
active_space = context.space_data
if active_space.type == 'VIEW_3D':
context.window_manager.modal_handler_add(self)
self._handle = context.region.callback_add(draw_lines,\
(self, context), 'POST_PIXEL')
self.vertices = []
mouseco = Vector((event.mouse_region_x, event.mouse_region_y, 0))
self.mouseco = mouseco
self.current_vec = mouseco.copy()
self.along = -1
self.snap_type = ''
self.vec_snap_vert = None
context.area.tag_redraw()
self.time = time.time()
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "Active space must be a View3d")
return {'CANCELLED'}
示例13: group_in_frame
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def group_in_frame(node_tree, name, nodes):
frame_node = node_tree.nodes.new("NodeFrame")
frame_node.label = name
frame_node.name = name + "_frame"
min_pos = Vector(nodes[0].location)
max_pos = min_pos.copy()
for node in nodes:
top_left = node.location
bottom_right = top_left + Vector((node.width, -node.height))
for i in (0, 1):
min_pos[i] = min(min_pos[i], top_left[i], bottom_right[i])
max_pos[i] = max(max_pos[i], top_left[i], bottom_right[i])
node.parent = frame_node
frame_node.width = max_pos[0] - min_pos[0] + 50
frame_node.height = max(max_pos[1] - min_pos[1] + 50, 450)
frame_node.shrink = True
return frame_node
示例14: draw_square_pyramid
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def draw_square_pyramid(point, orientation, angle=45, depth=1, colour=[1, 1, 1], pyramid=True, incline=True):
points = []
axis_values = [-1, 1]
hypotenuse = depth if depth else 1
angle = radians(angle)
for x in axis_values:
for z in axis_values:
x_coordinate = hypotenuse * sin(angle) * x
if incline:
z += 1
z_coordinate = hypotenuse * cos(angle) * z
point_a = Vector((x_coordinate, depth, z_coordinate))
points.append(point_a)
for point_a in points:
for point_b in points:
if point_a is point_b:
continue
same_axis = [True for i in range(3) if point_a[i] == point_b[i]]
if len(same_axis) < 2:
continue
a = point_a.copy()
a.rotate(orientation)
b = point_b.copy()
b.rotate(orientation)
render.drawLine(a + point, b + point, colour)
if pyramid:
render.drawLine(point, b + point, colour)
示例15: execute
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import copy [as 别名]
def execute(self, context):
selected_objects = context.selected_objects
uv_obj = context.scene.objects.active
wrap_name = uv_obj.name.replace('_WRAP', '')
if len(selected_objects) < 2:
self.report({'WARNING'}, "Select more objects")
return {'CANCELLED'}
if uv_obj not in selected_objects or '_WRAP' not in uv_obj.name:
self.report({'WARNING'}, "Select WRAP object at the end of selection")
return {'CANCELLED'}
if not wrap_name in context.scene.objects:
self.report({'WARNING'}, "No object " + wrap_name)
return {'CANCELLED'}
wrap_obj = context.scene.objects[wrap_name]
if len(wrap_obj.data.polygons) != len(uv_obj.data.polygons):
self.report({'WARNING'}, "Object " + wrap_name + " and object " + uv_obj.name + " have different faces count")
return {'CANCELLED'}
bvh = mathu.bvhtree.BVHTree.FromObject(uv_obj, context.scene)
uv_matrix = uv_obj.matrix_world
uv_matrix_inv = uv_matrix.inverted()
wrap_matrix = wrap_obj.matrix_world
wrap_matrix_inv = wrap_matrix.inverted()
for the_obj in selected_objects:
if the_obj != uv_obj:
if self.copy_objects:
# create new object
new_mesh = the_obj.to_mesh(scene=context.scene, apply_modifiers=True, settings='PREVIEW')
new_obj = bpy.data.objects.new(wrap_obj.name + '_WRAP', new_mesh)
new_obj.select = True
context.scene.objects.link(new_obj)
new_obj.matrix_world = the_obj.matrix_world
new_obj.data.update()
final_obj = new_obj
else:
final_obj = the_obj
# all verts
if self.transform_objects:
all_verts = [final_obj.location]
else:
all_verts = []
if final_obj.type == 'MESH':
if final_obj.data.shape_keys:
all_verts = final_obj.data.shape_keys.key_blocks[final_obj.active_shape_key_index].data
else:
all_verts = final_obj.data.vertices
elif final_obj.type == 'CURVE':
if final_obj.data.shape_keys:
all_verts = final_obj.data.shape_keys.key_blocks[final_obj.active_shape_key_index].data
else:
for spline in final_obj.data.splines:
if spline.type == 'BEZIER':
for point in spline.bezier_points:
all_verts.append(point)
else:
for point in spline.points:
all_verts.append(point)
# wrap main code
for vert in all_verts:
if self.transform_objects:
vert_pos = vert # here vert is just object's location
else:
if final_obj.type == 'CURVE':
vert_pos = Vector((vert.co[0], vert.co[1], vert.co[2]))
vert_pos = final_obj.matrix_world * vert_pos
else:
vert_pos = final_obj.matrix_world * vert.co.copy()
# near
vert_pos_zero = vert_pos.copy()
vert_pos_zero[1] = uv_obj.location[1]
vert_pos_zero = uv_obj.matrix_world.inverted() * vert_pos_zero
nearest = bvh.find_nearest(vert_pos_zero)
if nearest and nearest[2] is not None:
near_face = uv_obj.data.polygons[nearest[2]]
near_center = uv_obj.matrix_world * near_face.center
near_axis1 = ut_base.get_normal_world(near_face.normal, uv_matrix, uv_matrix_inv)
near_v1 = uv_obj.matrix_world * uv_obj.data.vertices[near_face.vertices[0]].co
near_v2 = uv_obj.matrix_world * uv_obj.data.vertices[near_face.vertices[1]].co
near_axis2 = (near_v1 - near_v2).normalized()
near_axis3 = near_axis1.cross(near_axis2).normalized()
dist_1 = mathu.geometry.distance_point_to_plane(vert_pos, near_center, near_axis1)
#.........这里部分代码省略.........