本文整理汇总了Python中mathutils.Quaternion.to_euler方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.to_euler方法的具体用法?Python Quaternion.to_euler怎么用?Python Quaternion.to_euler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Quaternion
的用法示例。
在下文中一共展示了Quaternion.to_euler方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rotateCam
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import to_euler [as 别名]
def rotateCam(rift):
cont = G.getCurrentController()
owner = cont.owner
scene = G.getCurrentScene()
rift.poll()
rotation = Quaternion((rift.rotation[0],
rift.rotation[1],
rift.rotation[2],
rift.rotation[3]))
eu = rotation.to_euler()
#ativecam
fix = Euler((-1.57, 0, 3*1.57), 'XYZ')
rot = Euler((-eu.z, eu.y, -eu.x), 'XYZ')
#owner
#fix = Euler((0, 2*-1.57, -1.57), 'XYZ')
#rot = Euler((-eu.x, eu.z, eu.y), 'XYZ')
rot.rotate(fix)
#cam = scene.active_camera
cam = scene.cameras["Camera"]
cam.localOrientation = rot
示例2: _arc_segment
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import to_euler [as 别名]
def _arc_segment(v_1, v_2):
ELorigin = bpy.context.scene.objects['ELorigin']
ELground = bpy.context.scene.objects['ELground']
v = v_2 - v_1
d = v.length
ELorigin.location = Vector((0, 0, 0))
ELground.location = Vector((0, 0, -d))
v_L = ELground.location - ELorigin.location
q = Quaternion()
c = Vector.cross(v_L, v)
q.x = c.x
q.y = c.y
q.z = c.z
q.w = sqrt((v_L.length ** 2) * (v.length ** 2)) + \
Vector.dot(v_L, v)
q.normalize()
euler = q.to_euler()
bpy.ops.object.runfslg_operator()
laALL = bpy.context.scene.objects['laALL']
laALL.name = 'lARC'
laALL.rotation_euler = euler
laALL.location = v_1
bpy.context.active_object.select = False
laALL.select = True
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
laALL.select = False
bpy.context.active_object.select = True
return laALL
示例3: load
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import to_euler [as 别名]
#.........这里部分代码省略.........
parent.rotation_euler = [0, 0, 0]
#obj.rotation_euler.x += (radians(90 + float(row['RotationX']))) # TODO
#obj.rotation_euler.y -= radians(float(row['RotationY'])) # TODO
parent.rotation_euler.z = radians((-90 + float(row['RotationY'])))
if row['ScaleFactor']:
parent.scale = (float(row['ScaleFactor']), float(row['ScaleFactor']), float(row['ScaleFactor']))
bpy.ops.import_scene.obj(filepath=newpath)
obj_objects = bpy.context.selected_objects[:]
# Put ADT rotations in here
for obj in obj_objects:
obj.parent = parent
wmocsvpath = newpath.replace('.obj', '_ModelPlacementInformation.csv')
# Read WMO doodads definitions file
with open(wmocsvpath) as wmocsvfile:
wmoreader = csv.DictReader(wmocsvfile, delimiter=';')
for wmorow in wmoreader:
wmodoodad_path, wmodoodad_filename = os.path.split(filepath)
wmonewpath = os.path.join(wmodoodad_path, wmorow['ModelFile'])
# Import the doodad
if(os.path.exists(wmonewpath)):
bpy.ops.import_scene.obj(filepath=wmonewpath)
# Select the imported doodad
wmoobj_objects = bpy.context.selected_objects[:]
for wmoobj in wmoobj_objects:
# Prepend name
wmoobj.name = "(" + wmorow['DoodadSet'] + ") " + wmoobj.name
# Set parent
wmoobj.parent = parent
# Set position
wmoobj.location = (float(wmorow['PositionX']) * -1, float(wmorow['PositionY']) * -1, float(wmorow['PositionZ']))
# Set rotation
rotQuat = Quaternion((float(wmorow['RotationW']), float(wmorow['RotationX']), float(wmorow['RotationY']), float(wmorow['RotationZ'])))
rotEul = rotQuat.to_euler()
rotEul.x += radians(90);
rotEul.z += radians(180);
wmoobj.rotation_euler = rotEul
# Set scale
if wmorow['ScaleFactor']:
wmoobj.scale = (float(wmorow['ScaleFactor']), float(wmorow['ScaleFactor']), float(wmorow['ScaleFactor']))
# Duplicate material removal script by Kruithne
# Merge all duplicate materials
for obj in bpy.context.scene.objects:
if obj.type == 'MESH':
i = 0
for mat_slot in obj.material_slots:
mat = mat_slot.material
obj.material_slots[i].material = bpy.data.materials[mat.name.split('.')[0]]
i += 1
# Cleanup unused materials
for img in bpy.data.images:
if not img.users:
bpy.data.images.remove(img)
else:
if(os.path.exists(newpath)):
bpy.ops.import_scene.obj(filepath=newpath)
obj_objects = bpy.context.selected_objects[:]
for obj in obj_objects:
# Set parent
obj.parent = doodadparent
# Set location
obj.location.x = (17066 - float(row['PositionX']))
obj.location.y = (17066 - float(row['PositionZ'])) * -1
obj.location.z = float(row['PositionY'])
obj.rotation_euler.x += radians(float(row['RotationZ']))
obj.rotation_euler.y += radians(float(row['RotationX']))
obj.rotation_euler.z = radians(90 + float(row['RotationY'])) # okay
# Set scale
if row['ScaleFactor']:
obj.scale = (float(row['ScaleFactor']), float(row['ScaleFactor']), float(row['ScaleFactor']))
# Set doodad and WMO parent to 0
wmoparent.location = (0, 0, 0)
doodadparent.location = (0, 0, 0)
print("Deduplicating and cleaning up materials!")
# Duplicate material removal script by Kruithne
# Merge all duplicate materials
for obj in bpy.context.scene.objects:
if obj.type == 'MESH':
i = 0
for mat_slot in obj.material_slots:
mat = mat_slot.material
obj.material_slots[i].material = bpy.data.materials[mat.name.split('.')[0]]
i += 1
# Cleanup unused materials
for img in bpy.data.images:
if not img.users:
bpy.data.images.remove(img)
progress.leave_substeps("Finished importing: %r" % filepath)
return {'FINISHED'}
示例4: CNT
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import to_euler [as 别名]
def CNT(type = 1,res = 1, m=10,n=5,bL=1.56,bR=.1,aR=.2):
import bpy
from fractions import gcd
from math import cos, sin, acos,sqrt,copysign,ceil,floor,pi
from mathutils import Vector, Matrix,Quaternion
print("Tube: (",m,",",n,"); Radius: ",bL*sqrt(m*m+n*n+m*n)/(2*pi))
cntR = bL*sqrt(m*m+n*n+m*n)/(2*pi)
a1=Vector((bL*sqrt(3)/2,bL/2))
a2=Vector((bL*sqrt(3)/2,-bL/2))
x=Vector((bL/sqrt(3),0))
def Lattice2D(i,j,k):
return i*a1+j*a2+k*x
o = Lattice2D(0,0,0)
c = Lattice2D(m,n,0)
d = gcd(2*n+m,2*m+n)
t = Lattice2D((2*n+m)/d,-(2*m+n)/d,0);print("Unit Length: ",t.magnitude)
theta = acos(c.normalized()[0]*copysign(1,c[1]))
u = Matrix(((cos(theta),sin(theta)),(-sin(theta),cos(theta))))
def Lattice3D(i,j,k):
r = c.magnitude/(2*pi)
p = Lattice2D(i,j,k)*u.transposed()
return Vector([r*cos(p[0]/r),r*sin(p[0]/r),p[1]])
imax = 2*(n+m); imin = 0
jmax = n; jmin = -(2*m+n)
indices = []
for i in range(imin,imax+1):
for j in range(jmin,jmax+1):
for k in range(2):
p = Lattice2D(i,j,k)*u.transposed()
if p[0]>=0-bL/5 and p[0]<=c.magnitude-bL/5 and p[1]>=0+bL/10 and p[1]<=t.magnitude+bL/10:
indices.append([i,j,k])
print("indices: ",len(indices))
points2D = list(map(lambda x:Lattice2D(x[0],x[1],x[2])*u.transposed(),indices))
print("points2D: ",len(points2D))
bonds2D = []
for i in range(len(indices)):
if indices[i][2] == 0:
p1=Lattice2D(indices[i][0],indices[i][1],0)*u.transposed()
p2=Lattice2D(indices[i][0],indices[i][1],1)*u.transposed()
if p2[0]>=0-bL/5 and p2[0]<=c.magnitude+bL/5 and p2[1]>=0-bL/10 and p2[1]<=t.magnitude+bL:
bonds2D.append([p1,p2])
p2=Lattice2D(indices[i][0]-1,indices[i][1],1)*u.transposed()
if p2[0]>=0-bL/5 and p2[0]<=c.magnitude+bL/5 and p2[1]>=0-bL/10 and p2[1]<=t.magnitude+bL:
bonds2D.append([p1,p2])
p2=Lattice2D(indices[i][0],indices[i][1]-1,1)*u.transposed()
if p2[0]>=0-bL/5 and p2[0]<=c.magnitude+bL/5 and p2[1]>=0-bL/10 and p2[1]<=t.magnitude+bL:
bonds2D.append([p1,p2])
print("bonds2D: ",len(bonds2D))
if type == 0:
lyrs = [False]*20; lyrs[3] = True
if bpy.data.scenes[0].layers[3] == False:
bpy.data.scenes[0].layers[3] = True
bpy.ops.object.select_by_layer(extend=False, layers=4)
bpy.ops.object.delete()
if res < 0:
res = 1
if bR > 0:
for i in range(len(bonds2D)):
temp3D1 = Vector([bonds2D[i][0][0],bonds2D[i][0][1],0])
temp3D2 = Vector([bonds2D[i][1][0],bonds2D[i][1][1],0])
p = (temp3D1+temp3D2)*.5
v = ((temp3D2-temp3D1).normalized()+Vector((0,0,1)))/2
qu = Quaternion((v[0],v[1],v[2]),pi)
eu = qu.to_euler()
bpy.ops.mesh.primitive_cylinder_add(vertices=res*4,depth=(temp3D2-temp3D1).magnitude*1.05,radius=bR, end_fill_type='NOTHING', location=(p[0], p[1], p[2]), rotation=eu,layers=lyrs)
if res > 1:
bpy.ops.object.shade_smooth()
print("C bonds rendered")
if aR > 0:
for i in range(len(points2D)):
bpy.ops.mesh.primitive_uv_sphere_add(segments=res*4,ring_count=res*2,size=aR,location=(points2D[i][0],points2D[i][1],0),layers=lyrs)
if res > 1:
bpy.ops.object.shade_smooth()
print("C atoms rendered")
bpy.ops.mesh.primitive_uv_sphere_add(size=0,layers=lyrs)
bpy.ops.object.select_by_layer(extend=False, layers=4)
bpy.ops.object.join()
bpy.ops.object.modifier_add(type='ARRAY')
bpy.context.active_object.modifiers['Array'].count=1
bpy.context.active_object.modifiers['Array'].use_relative_offset=False
bpy.context.active_object.modifiers['Array'].use_constant_offset=True
bpy.context.active_object.modifiers['Array'].constant_offset_displace.y=t.magnitude
#bpy.ops.curve.primitive_bezier_circle_add(rotation=(0, pi/2, 0), layers=lyrs)
#need to select cnt now.
#bpy.ops.object.modifier_add(type='CURVE')
#.........这里部分代码省略.........
示例5: load
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import to_euler [as 别名]
def load(context,
filepath
):
with ProgressReport(context.window_manager) as progress:
progress.enter_substeps(1, "Importing WMO OBJ %r..." % filepath)
csvpath = filepath.replace('.obj', '_ModelPlacementInformation.csv')
bpy.ops.import_scene.obj(filepath=filepath)
# Duplicate material removal script by Kruithne
# Merge all duplicate materials
for obj in bpy.context.scene.objects:
if obj.type == 'MESH':
i = 0
for mat_slot in obj.material_slots:
mat = mat_slot.material
obj.material_slots[i].material = bpy.data.materials[mat.name.split('.')[0]]
i += 1
# Cleanup unused materials
for img in bpy.data.images:
if not img.users:
bpy.data.images.remove(img)
# Select the imported WMO
obj_objects = bpy.context.selected_objects[:]
for obj in obj_objects:
obj.rotation_euler = [0, 0, 0]
obj.rotation_euler.x += radians(90)
obj.rotation_euler.z -= radians(90)
# Read doodad definitions file
with open(csvpath) as csvfile:
reader = csv.DictReader(csvfile, delimiter=';')
for row in reader:
doodad_path, doodad_filename = os.path.split(filepath)
newpath = os.path.join(doodad_path, row['ModelFile'])
# Import the doodad
bpy.ops.import_scene.obj(filepath=newpath)
# Select the imported doodad
obj_objects = bpy.context.selected_objects[:]
for obj in obj_objects:
# Print object name
# print (obj.name)
# Prepend name
obj.name = "(" + row['DoodadSet'] + ") " + obj.name
# Set position
obj.location = (float(row['PositionY']) * -1, float(row['PositionX']), float(row['PositionZ']))
# Set rotation
rotQuat = Quaternion((float(row['RotationW']), float(row['RotationX']), float(row['RotationY']), float(row['RotationZ'])))
rotEul = rotQuat.to_euler()
rotEul.x += radians(90);
rotEul.z += radians(90);
obj.rotation_euler = rotEul
# Set scale
if row['ScaleFactor']:
obj.scale = (float(row['ScaleFactor']), float(row['ScaleFactor']), float(row['ScaleFactor']))
# Duplicate material removal script by Kruithne
# Merge all duplicate materials
for obj in bpy.context.scene.objects:
if obj.type == 'MESH':
i = 0
for mat_slot in obj.material_slots:
mat = mat_slot.material
obj.material_slots[i].material = bpy.data.materials[mat.name.split('.')[0]]
i += 1
# Cleanup unused materials
for img in bpy.data.images:
if not img.users:
bpy.data.images.remove(img)
progress.leave_substeps("Finished importing: %r" % filepath)
return {'FINISHED'}
示例6: vectors2euler
# 需要导入模块: from mathutils import Quaternion [as 别名]
# 或者: from mathutils.Quaternion import to_euler [as 别名]
def vectors2euler(vec_ref, vec_actual):
rot_axis = vec_ref.cross(vec_actual).normalized()
rot_angle = angle_between(vec_actual, vec_ref)
quat_rot = Quaternion((rot_axis.x, rot_axis.y, rot_axis.z), rot_angle)
euler_rot = quat_rot.to_euler()
return euler_rot