本文整理汇总了Python中mathutils.Vector.rotation_difference方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.rotation_difference方法的具体用法?Python Vector.rotation_difference怎么用?Python Vector.rotation_difference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Vector
的用法示例。
在下文中一共展示了Vector.rotation_difference方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vecscorrect
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
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
示例2: _apply_planer_map
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
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))
示例3: doodads
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
def doodads(object1, mesh1, dmin, dmax):
"""function to generate the doodads"""
global dVerts
global dPolygons
i = 0
# on parcoure cette boucle pour ajouter des doodads a toutes les polygons
# english translation: this loops adds doodads to all polygons
while(i < len(object1.data.polygons)):
if object1.data.polygons[i].select is False:
continue
doods_nbr = random.randint(dmin, dmax)
j = 0
while(j <= doods_nbr):
origin_dood = randVertex(object1.data.polygons[i].vertices[0], object1.data.polygons[i].vertices[1],
object1.data.polygons[i].vertices[2], object1.data.polygons[i].vertices[3], Verts)
type_dood = random.randint(0, len(bpy.context.scene.discomb.DISC_doodads) - 1)
polygons_add = []
verts_add = []
# First we have to apply scaling and rotation to the mesh
bpy.ops.object.select_pattern(pattern=bpy.context.scene.discomb.DISC_doodads[type_dood], extend=False)
bpy.context.scene.objects.active = bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]]
bpy.ops.object.transform_apply(rotation=True, scale=True)
for polygon in bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]].data.polygons:
polygons_add.append(polygon.vertices)
for vertex in bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]].data.vertices:
verts_add.append(vertex.co.copy())
normal_original_polygon = object1.data.polygons[i].normal
nor_def = Vector((0.0, 0.0, 1.0))
qr = nor_def.rotation_difference(normal_original_polygon.normalized())
if(test_v2_near_v1(nor_def, -normal_original_polygon)):
qr = Quaternion((0.0, 0.0, 0.0, 0.0))
# qr = angle_between_nor(nor_def, normal_original_polygon)
for vertex in verts_add:
vertex.rotate(qr)
vertex += origin_dood
findex = len(dVerts)
for polygon in polygons_add:
dPolygons.append([polygon[0] + findex, polygon[1] + findex, polygon[2] + findex, polygon[3] + findex])
i_dood_type.append(bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]].name)
for vertex in verts_add:
dVerts.append(vertex)
j += 1
i += 5
示例4: execute
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
def execute(self, context):
obj = context.active_object
bm = bmesh.from_edit_mesh(obj.data)
if muv_common.check_version(2, 73, 0) >= 0:
bm.faces.ensure_lookup_table()
# get UV layer
if not bm.loops.layers.uv:
self.report(
{'WARNING'}, "Object must have more than one UV map")
return {'CANCELLED'}
uv_layer = bm.loops.layers.uv.verify()
scale = 1.0 / self.size
sx = 1.0 * scale
sy = 1.0 * scale
ofx = self.offset[0]
ofy = self.offset[1]
rz = self.rotation * pi / 180.0
aspect = self.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 = 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))
bmesh.update_edit_mesh(obj.data)
return {'FINISHED'}
示例5: drawBone2
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
def drawBone2(p1, p2, radiuses, material):
length = dist(p1,p2)
print('length :',length)
v = Vector(diffv(p1, p2))
up = Vector((0,0,1))
if v!=-up:
rot = up.rotation_difference(v)
else:
rot = Quaternion((1,0,0),math.pi)
s1 = drawEllipsoid((0,0,-0.5*length),radiuses,material)
s2 = drawEllipsoid((0,0,0.5*length),radiuses,material)
c1 = drawCylinder(zero,radiuses,length,materials.blue)
s1.select = True
s2.select = True
c1.select = True
#bpy.ops.transform.translate(value=(0,0,length/2))
#bpy.ops.object.editmode_toggle()
bpy.ops.transform.rotate(value=rot.angle, axis=rot.axis)
#bpy.ops.object.editmode_toggle()
#bpy.ops.transform.translate(value=Vector((0,0,-0.5*length))*rot.to_matrix())
rot.normalize();
bpy.ops.transform.translate(value=Vector((0,0,0.5*length))*rot.to_matrix())
bpy.ops.transform.translate(value=p1)
return (s1,s2,c1)
示例6: get_point_rotation
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
def get_point_rotation(scene, curve_obj, index=0, spline_index=0):
# Get curve attributes
curve_mat = curve_obj.matrix_world
curve = curve_obj.data
points = get_spline_points(curve.splines[spline_index])
# new temp object to detect local x-axis and y-axis of first handle
# Temp Bevel Object for temp curve
temp_bevel_curve = bpy.data.curves.new('__temp_bevel', 'CURVE')
temp_spline = temp_bevel_curve.splines.new('POLY')
temp_spline.points.add(2)
temp_spline.points[0].co = Vector((1.0, 0.0, 0.0, 1.0))
temp_spline.points[1].co = Vector((0.0, 1.0, 0.0, 1.0))
temp_bevel_obj = bpy.data.objects.new('__temp_bevel', temp_bevel_curve)
scene.objects.link(temp_bevel_obj)
# Temp Curve
curve_copy = curve_obj.data.copy()
curve_copy.use_fill_caps = False
curve_copy.bevel_object = temp_bevel_obj
temp_obj = bpy.data.objects.new('__temp', curve_copy)
scene.objects.link(temp_obj)
temp_obj.location = curve_obj.location
temp_obj.rotation_mode = curve_obj.rotation_mode
temp_obj.rotation_quaternion = curve_obj.rotation_quaternion
temp_obj.rotation_euler = curve_obj.rotation_euler
# Convert temp curve to mesh
bpy.ops.object.select_all(action='DESELECT') # deselect all first
scene.objects.active = temp_obj
temp_obj.select = True
bpy.ops.object.convert(target='MESH')
offset = 0
micro_offset = 0
#cyclic check
for i, spline in enumerate(curve.splines):
if i > spline_index:
break
#ps = get_spline_points(spline)
if i > 0:
ps_count = len(get_spline_points(curve.splines[i-1]))
offset += ps_count-1
if spline.use_cyclic_u:
offset += 1
elif i > 0:
micro_offset += 1
#offset += spline_index * curve.resolution_u
#print(offset)
# get x-axis and y-axis of the first handle
handle_x = temp_obj.data.vertices[curve.resolution_u * (index + offset) * 3 + micro_offset * 3].co
handle_y = temp_obj.data.vertices[curve.resolution_u * (index + offset) * 3 + 1 + micro_offset * 3].co
target_x = handle_x - points[index].co.xyz
target_y = handle_y - points[index].co.xyz
target_x.normalize()
target_y.normalize()
# delete temp objects
temp_bevel_obj.select = True
bpy.ops.object.delete()
# Match bevel x-axis to handle x-axis
bevel_x = Vector((1.0, 0.0, 0.0))
target_x = curve_mat.to_3x3() * target_x
rot_1 = bevel_x.rotation_difference(target_x)
# Match bevel y-axis to handle y-axis
bevel_y = rot_1.to_matrix() * Vector((0.0, 1.0, 0.0))
target_y = curve_mat.to_3x3() * target_y
rot_2 = bevel_y.rotation_difference(target_y)
# Select curve object again
scene.objects.active = curve_obj
curve_obj.select = True
return rot_2 * rot_1
示例7: best_planar_map
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
def best_planar_map():
global all_scale_def,xoffset_def,yoffset_def,zrot_def, tex_aspect
obj = bpy.context.active_object
mesh = obj.data
is_editmode = (obj.mode == 'EDIT')
# if in EDIT Mode switch to OBJECT
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
# if no UVtex - create it
if not mesh.uv_textures:
uvtex = bpy.ops.mesh.uv_texture_add()
uvtex = mesh.uv_textures.active
#uvtex.active_render = True
img = None
aspect = 1.0
mat = obj.active_material
try:
if mat:
img = mat.active_texture
aspect = img.image.size[0]/img.image.size[1]
except:
pass
aspect = aspect * tex_aspect
#
# Main action
#
if all_scale_def:
sc = 1.0/all_scale_def
else:
sc = 1.0
# Calculate Average Normal
v = Vector((0,0,0))
cnt = 0
for f in mesh.polygons:
if f.select:
cnt += 1
v = v + f.normal
zv = Vector((0,0,1))
q = v.rotation_difference(zv)
sx = 1 * sc
sy = 1 * sc
sz = 1 * sc
ofx = xoffset_def
ofy = yoffset_def
rz = zrot_def / 180 * pi
cosrz = cos(rz)
sinrz = sin(rz)
#uvs = mesh.uv_loop_layers[mesh.uv_loop_layers.active_index].data
uvs = mesh.uv_layers.active.data
for i, pol in enumerate(mesh.polygons):
if not is_editmode or mesh.polygons[i].select:
for j, loop in enumerate(mesh.polygons[i].loop_indices):
v_idx = mesh.loops[loop].vertex_index
n = pol.normal
co = q * mesh.vertices[v_idx].co
x = co.x * sx
y = co.y * sy
z = co.z * sz
uvs[loop].uv[0] = x * cosrz - y * sinrz + xoffset_def
uvs[loop].uv[1] = aspect*(- x * sinrz - y * cosrz) + yoffset_def
# Back to EDIT Mode
if is_editmode:
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
示例8: process
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
def process(self):
verts_socket, poly_socket = self.inputs
norm_socket, norm_abs_socket, origins_socket, centers_socket = self.outputs
if not any([s.is_linked for s in self.outputs]):
return
if not (verts_socket.is_linked and poly_socket.is_linked):
return
pols_ = poly_socket.sv_get()
vers_tupls = verts_socket.sv_get()
vers_vects = Vector_generate(vers_tupls)
# make mesh temp утилитарно - удалить в конце
mat_collect = []
normals_out = []
origins = []
norm_abs_out = []
for verst, versv, pols in zip(vers_tupls, vers_vects, pols_):
# medians в векторах
medians = []
normals = []
centrs = []
norm_abs = []
for p in pols:
# medians
# it calcs middle point of opposite edges,
# than finds length vector between this two points
v0 = versv[p[0]]
v1 = versv[p[1]]
v2 = versv[p[2]]
lp=len(p)
if lp >= 4:
l = ((lp-2)//2) + 2
v3 = versv[p[l]]
poi_2 = (v2+v3)/2
# normals
norm = geometry.normal(v0, v1, v2, v3)
normals.append(norm)
else:
poi_2 = v2
# normals
norm = geometry.normal(v0, v1, v2)
normals.append(norm)
poi_1 = (v0+v1)/2
vm = poi_2 - poi_1
medians.append(vm)
# centrs
x,y,z = zip(*[verst[poi] for poi in p])
x,y,z = sum(x)/len(x), sum(y)/len(y), sum(z)/len(z)
current_center = Vector((x,y,z))
centrs.append(current_center)
# normal absolute !!!
# это совершенно нормально!!! ;-)
norm_abs.append(current_center+norm)
if self.Separate:
norm_abs_out.append(norm_abs)
origins.append(centrs)
normals_out.append(normals)
else:
norm_abs_out.extend(norm_abs)
origins.extend(centrs)
normals_out.extend(normals)
mat_collect_ = []
for cen, med, nor in zip(centrs, medians, normals):
loc = Matrix.Translation(cen)
# need better solution for Z,Y vectors + may be X vector correction
vecz = Vector((0, 1e-6, 1))
q_rot0 = vecz.rotation_difference(nor).to_matrix().to_4x4()
q_rot2 = nor.rotation_difference(vecz).to_matrix().to_4x4()
if med[1]>med[0]:
vecy = Vector((1e-6, 1, 0)) * q_rot2
else:
vecy = Vector((1, 1e-6, 0)) * q_rot2
q_rot1 = vecy.rotation_difference(med).to_matrix().to_4x4()
# loc is matrix * rot vector * rot vector
M = loc*q_rot1*q_rot0
lM = [ j[:] for j in M ]
mat_collect_.append(lM)
mat_collect.extend(mat_collect_)
if not self.Separate:
norm_abs_out = [norm_abs_out]
origins = [origins]
normals_out = [normals_out]
centers_socket.sv_set(mat_collect)
norm_abs_socket.sv_set(Vector_degenerate(norm_abs_out))
origins_socket.sv_set(Vector_degenerate(origins))
norm_socket.sv_set(Vector_degenerate(normals_out))
示例9: process
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
def process(self):
if self.outputs['Centers'].is_linked or self.outputs['Normals'].is_linked or \
self.outputs['Origins'].is_linked or self.outputs['Norm_abs'].is_linked:
if 'Polygons' in self.inputs and 'Vertices' in self.inputs \
and self.inputs['Polygons'].is_linked and self.inputs['Vertices'].is_linked:
pols_ = SvGetSocketAnyType(self, self.inputs['Polygons'])
vers_tupls = SvGetSocketAnyType(self, self.inputs['Vertices'])
vers_vects = Vector_generate(vers_tupls)
# make mesh temp утилитарно - удалить в конце
mat_collect = []
normals_out = []
origins = []
norm_abs_out = []
for verst, versv, pols in zip(vers_tupls, vers_vects, pols_):
# medians в векторах
medians = []
normals = []
centrs = []
norm_abs = []
for p in pols:
# medians
# it calcs middle point of opposite edges,
# than finds length vector between this two points
v0 = versv[p[0]]
v1 = versv[p[1]]
v2 = versv[p[2]]
lp=len(p)
if lp >= 4:
l = ((lp-2)//2) + 2
v3 = versv[p[l]]
poi_2 = (v2+v3)/2
# normals
norm = geometry.normal(v0, v1, v2, v3)
normals.append(norm)
else:
poi_2 = v2
# normals
norm = geometry.normal(v0, v1, v2)
normals.append(norm)
poi_1 = (v0+v1)/2
vm = poi_2 - poi_1
medians.append(vm)
# centrs
x,y,z = zip(*[verst[poi] for poi in p])
x,y,z = sum(x)/len(x), sum(y)/len(y), sum(z)/len(z)
current_center = Vector((x,y,z))
centrs.append(current_center)
# normal absolute !!!
# это совершенно нормально!!! ;-)
norm_abs.append(current_center+norm)
norm_abs_out.append(norm_abs)
origins.append(centrs)
normals_out.extend(normals)
mat_collect_ = []
for cen, med, nor in zip(centrs, medians, normals):
loc = Matrix.Translation(cen)
# need better solution for Z,Y vectors + may be X vector correction
vecz = Vector((0, 1e-6, 1))
q_rot0 = vecz.rotation_difference(nor).to_matrix().to_4x4()
q_rot2 = nor.rotation_difference(vecz).to_matrix().to_4x4()
vecy = Vector((1e-6, 1, 0)) * q_rot2
q_rot1 = vecy.rotation_difference(med).to_matrix().to_4x4()
# loc is matrix * rot vector * rot vector
M = loc*q_rot1*q_rot0
lM = [ j[:] for j in M ]
mat_collect_.append(lM)
mat_collect.extend(mat_collect_)
SvSetSocketAnyType(self, 'Centers', mat_collect)
SvSetSocketAnyType(self, 'Norm_abs', Vector_degenerate(norm_abs_out))
SvSetSocketAnyType(self, 'Origins', Vector_degenerate(origins))
SvSetSocketAnyType(self, 'Normals', Vector_degenerate([normals_out]))
示例10: main2
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotation_difference [as 别名]
def main2():
global all_scale_def,xoffset_def,yoffset_def,zrot_def
obj = bpy.context.active_object
mesh = obj.data
is_editmode = (obj.mode == 'EDIT')
# if in EDIT Mode switch to OBJECT
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
# if no UVtex - create it
if not mesh.uv_textures:
uvtex = bpy.ops.mesh.uv_texture_add()
uvtex = mesh.uv_textures.active
uvtex.active_render = True
img = None
aspect = 1.0
mat = obj.active_material
try:
if mat:
img = mat.active_texture
aspect = img.image.size[0]/img.image.size[1]
for f in mesh.faces:
if not is_editmode or f.select:
uvtex.data[f.index].image = img.image
else:
img = None
except:
pass
#
# Main action
#
if all_scale_def:
sc = 1.0/all_scale_def
else:
sc = 1.0
# Calculate Average Normal
v = Vector((0,0,0))
cnt = 0
for f in mesh.faces:
if f.select:
cnt += 1
v = v + f.normal
zv = Vector((0,0,1))
q = v.rotation_difference(zv)
sx = 1 * sc
sy = 1 * sc
sz = 1 * sc
ofx = xoffset_def
ofy = yoffset_def
rz = zrot_def / 180 * pi
for i, uv in enumerate(uvtex.data):
if mesh.faces[i].select:
uvs = uv.uv1, uv.uv2, uv.uv3, uv.uv4
for j, v_idx in enumerate(mesh.faces[i].vertices):
n = mesh.faces[i].normal
co = q * mesh.vertices[v_idx].co
x = co.x * sx
y = co.y * sy
z = co.z * sz
uvs[j][0] = x * cos(rz) - y * sin(rz) + xoffset_def
uvs[j][1] = aspect*(- x * sin(rz) - y * cos(rz)) + yoffset_def
# Back to EDIT Mode
if is_editmode:
bpy.ops.object.mode_set(mode='EDIT', toggle=False)