本文整理汇总了Python中mathutils.Vector.z方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.z方法的具体用法?Python Vector.z怎么用?Python Vector.z使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Vector
的用法示例。
在下文中一共展示了Vector.z方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calcAlign
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def calcAlign(self, localArea):
alnVec = Vector([0, 0, 0])
if len(localArea) == 0:
return alnVec
agents = self.sim.agents
for neighbour in localArea:
alnVec.x += agents[neighbour].arx
alnVec.y += agents[neighbour].ary
alnVec.z += agents[neighbour].arz
alnVec /= len(localArea)
alnVec.x -= agents[self.userid].arx
alnVec.y -= agents[self.userid].ary
alnVec.z -= agents[self.userid].arz
alnVec.x %= 2 * math.pi
alnVec.y %= 2 * math.pi
alnVec.z %= 2 * math.pi
if alnVec.x < math.pi:
alnVec.x = alnVec.x / math.pi
else:
alnVec.x = -2 + alnVec.x / math.pi
if alnVec.y < math.pi:
alnVec.y = alnVec.y / math.pi
else:
alnVec.y = -2 + alnVec.y / math.pi
if alnVec.z < math.pi:
alnVec.z = alnVec.z / math.pi
else:
alnVec.z = -2 + alnVec.z / math.pi
return alnVec
示例2: getBoundingBox
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def getBoundingBox(scene):
minimum = Vector()
maximum = Vector()
for obj in scene.objects:
if obj.type == 'MESH':
bbox_corners = [obj.matrix_world * Vector(corner) for corner in obj.bound_box]
for v in bbox_corners:
if v.x < minimum.x:
minimum.x = v.x
if v.y < minimum.y:
minimum.y = v.y
if v.z < minimum.z:
minimum.z = v.z
if v.x > maximum.x:
maximum.x = v.x
if v.y > maximum.y:
maximum.y = v.y
if v.z > maximum.z:
maximum.z = v.z
return {
"minimum" : { "x" : minimum.x, "y" : minimum.y, "z" : minimum.z },
"maximum" : { "x" : maximum.x, "y" : maximum.y, "z" : maximum.z }
}
示例3: getBoundsBF
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def getBoundsBF(obj:Object):
""" brute force method for obtaining object bounding box """
# initialize min and max
min = Vector((math.inf, math.inf, math.inf))
max = Vector((-math.inf, -math.inf, -math.inf))
# calculate min and max verts
for v in obj.data.vertices:
if v.co.x > max.x:
max.x = v.co.x
elif v.co.x < min.x:
min.x = v.co.x
if v.co.y > max.y:
max.y = v.co.y
elif v.co.y < min.y:
min.y = v.co.y
if v.co.z > max.z:
max.z = v.co.z
elif v.co.z < min.z:
min.z = v.co.z
# set up bounding box list of coord lists
bound_box = [list(min),
[min.x, min.y, min.z],
[min.x, min.y, max.z],
[min.x, max.y, max.z],
[min.x, max.y, min.z],
[max.x, min.y, min.z],
[max.y, min.y, max.z],
list(max),
[max.x, max.y, min.z]]
return bound_box
示例4: readPackedVector
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def readPackedVector(f, format):
packed = f
output = Vector()
if format == 'XZY':
output.x = packed
output.y = packed / 65536.0
output.z = packed / 256.0
elif format == 'ZXY':
output.x = packed / 256.0
output.y = packed / 65536.0
output.z = packed
elif format == 'XYZ':
output.x = packed
output.y = packed / 256.0
output.z = packed / 65536.0
output.x -= math.floor(output.x)
output.y -= math.floor(output.y)
output.z -= math.floor(output.z)
output.x = output.x*2 - 1
output.y = output.y*2 - 1
output.z = output.z*2 - 1
return output
示例5: analyzeMeshObject
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def analyzeMeshObject(obj, meshFaces):
global DEFAULT_PART_NAME
mesh = obj.data
parts = []
halfSize = obj.dimensions * 0.5
candidParts = []
centerOfMass = Vector((0.0, 0.0, 0.0))
trianglesCount = 0
meshVerticesCount = len(mesh.vertices)
meshMaterialCount = len(mesh.materials)
if meshMaterialCount > 0:
# Create parts. It is important to iterate it manually
# so material names order is preserved.
for i in range(meshMaterialCount):
candidParts.append({'name': mesh.materials[i].name, 'start': 0, 'count': 0})
else:
# If there are no materials defined, create default part placeholder.
candidParts.append({'name': DEFAULT_PART_NAME, 'start': 0, 'count': 0})
for f in meshFaces:
# Some faces can be quads - values have to doubled then.
modifier = 2 if len(f.vertices) == 4 else 1
candidParts[f.material_index]['count'] += 3 * modifier
trianglesCount += 1 * modifier
# Update part`s start attribute so they take other parts into account.
for i in range(0, len(candidParts)):
if i > 0:
candidParts[i]['start'] = candidParts[i - 1]['start'] + candidParts[i - 1]['count']
# Only export parts that have any triangles assigned.
for p in candidParts:
if p['count'] > 0:
parts.append(p)
centerMax = Vector((-9999.999, -9999.999, -9999.999))
centerMin = Vector(( 9999.999, 9999.999, 9999.999))
for v in mesh.vertices:
centerMax.x = max(centerMax.x, v.co.x)
centerMin.x = min(centerMin.x, v.co.x)
centerMax.y = max(centerMax.y, v.co.y)
centerMin.y = min(centerMin.y, v.co.y)
centerMax.z = max(centerMax.z, v.co.z)
centerMin.z = min(centerMin.z, v.co.z)
centerOfMass.x = abs(centerMax.x) - abs(centerMin.x)
centerOfMass.y = abs(centerMax.y) - abs(centerMin.y)
centerOfMass.z = abs(centerMax.z) - abs(centerMin.z)
centerOfMass *= 0.5
return centerOfMass, halfSize, trianglesCount, parts
示例6: bounding_box
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def bounding_box(mesh):
v0 = mesh.vertices[0].co
vmin = Vector((v0.x, v0.y, v0.z))
vmax = Vector((v0.x, v0.y, v0.z))
for i in range(1, len(mesh.vertices)):
v = mesh.vertices[i].co
vmin.x = min(vmin.x, v.x)
vmin.y = min(vmin.y, v.y)
vmin.z = min(vmin.z, v.z)
vmax.x = max(vmax.x, v.x)
vmax.y = max(vmax.y, v.y)
vmax.z = max(vmax.z, v.z)
return vmin, vmax
示例7: modal
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def modal(self, context, event):
props = context.scene.tom_props
prefs = context.user_preferences.addons[__name__].preferences
# 3Dビューの画面を更新
if context.area:
context.area.tag_redraw()
# キーボードのQキーが押された場合は、オブジェクト並進移動モードを終了
if event.type == 'Q' and event.value == 'PRESS':
props.running = False
print("サンプル3-10: 通常モードへ移行しました。")
return {'FINISHED'}
if event.value == 'PRESS':
value = Vector((0.0, 0.0, 0.0))
if event.type == prefs.x_axis:
value.x = 1.0 if not event.shift else -1.0
if event.type == prefs.y_axis:
value.y = 1.0 if not event.shift else -1.0
if event.type == prefs.z_axis:
value.z = 1.0 if not event.shift else -1.0
# 選択中のオブジェクトを並進移動する
bpy.ops.transform.translate(value=value)
return {'RUNNING_MODAL'}
示例8: fencehop
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def fencehop():
cont = bge.logic.getCurrentController()
own = cont.owner
auto_action = cont.sensors['auto_action']
if not auto_action:
return False
elif own['isSpaceon']:
#Gather info on the fence
fence_obj = auto_action.hitObject
fence_pos = fence_obj.worldPosition
#get the normal of the fence
hit_norm = Vector(auto_action.hitNormal)
hit_norm.z = 0.0
#Vector axis of Sintel
own_negative_y = Vector(own.getAxisVect((0.0, -1.0, 0.0)))
own_negative_y.z = 0.0
#Cross it, then get the absolute vaule
cross = hit_norm.cross(own_negative_y)
cross = math.fabs(cross[2])
#print (cross)
#Check the angle of approach
if cross <=.5:
new_pos = (fence_pos[2] + 2)
own.worldPosition[2] = new_pos
own['Leaping']=True
CURRENT_SPEED = own.getLinearVelocity(True)
if CURRENT_SPEED[1] < 11:
CURRENT_SPEED[1] = 11
CURRENT_SPEED[2] = 10
#print (CURRENT_SPEED)
own.setLinearVelocity(CURRENT_SPEED ,True)
own['Tracking']=False
return True
else:
return False
示例9: onKeyPressed
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def onKeyPressed(self, keys):
rot = self.obj.worldOrientation.to_euler()
pos = Vector([0,0,0])
if key.W in keys: rot.x += 0.01
if key.S in keys: rot.x -= 0.01
if key.A in keys: rot.z += 0.01
if key.D in keys: rot.z -= 0.01
if key.WHEELUPMOUSE in keys: pos.z = -self.obj.worldPosition.z * 0.3
if key.WHEELDOWNMOUSE in keys: pos.z = self.obj.worldPosition.z * 0.3
#Max speed is dependent of the Tile sizes, ex (200m/s = size) / 50fps = 4m/tick
#Since we are using an extra radius we can guarante a speed of 8m/tick without glitches: 8*60fps = 480m/s = 1728 km/h
#if pos.length > 8: pos.length = 8
#But we don't care for now
if pos.length > 50: pos.length = 50
pos.rotate(self.obj.worldOrientation)
self.obj.worldPosition += pos
self.obj.worldOrientation = rot
示例10: roi2point
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def roi2point(self, msg):
"""
Returns a normalized point at the center of the given RegionOfInterest
message.
"""
p = Vector([0,0,0])
if self.camerainfo.width > 0:
p.x = 0.5 - (msg.x_offset+(msg.width/2.0))/self.camerainfo.width
if self.camerainfo.height > 0:
p.z = 0.5 - (msg.y_offset+(msg.height/2.0))/self.camerainfo.height
return p
示例11: __neg__
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def __neg__(self):
""" return antipodal point """
coo=Vector()
if self.co.x > 0:
coo.x = self.co.x - math.pi
else:
coo.x = self.co.x + math.pi
coo.y = abs(math.pi - self.co.y)
coo.z = -self.co.z
return Reflection(co=coo,
normalize=False)
示例12: main
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
wall_ray = cont.sensors["wall_ray"]
wall_normal = Vector(wall_ray.hitNormal)
wall_normal.z = 0.0
own_negative_y = Vector(own.getAxisVect((0.0, -1.0, 0.0)))
own_negative_y.z = 0.0
cross = wall_normal.cross(own_negative_y)
if cross.z > 0.0:
new_dir = Matrix.Rotation(-90.0, 3, 'X') * wall_normal
else:
new_dir = Matrix.Rotation(90.0, 3, 'X') * wall_normal
#print (new_dir)
#own.alignAxisToVect(new_dir, 0, .1)
示例13: getDimensions
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def getDimensions(self):
highest = Vector((-10000, -10000, -10000))
lowest = Vector(( 10000, 10000, 10000))
for bone in self.bones:
if highest.x < bone.restHead.x: highest.x = bone.restHead.x
if highest.y < bone.restHead.y: highest.y = bone.restHead.y
if highest.z < bone.restHead.z: highest.z = bone.restHead.z
if highest.x < bone.restTail.x: highest.x = bone.restTail.x
if highest.y < bone.restTail.y: highest.y = bone.restTail.y
if highest.z < bone.restTail.z: highest.z = bone.restTail.z
if lowest .x > bone.restHead.x: lowest .x = bone.restHead.x
if lowest .y > bone.restHead.y: lowest .y = bone.restHead.y
if lowest .z > bone.restHead.z: lowest .z = bone.restHead.z
if lowest .x > bone.restTail.x: lowest .x = bone.restTail.x
if lowest .y > bone.restTail.y: lowest .y = bone.restTail.y
if lowest .z > bone.restTail.z: lowest .z = bone.restTail.z
return Vector((highest.x - lowest.x, highest.y - lowest.y, highest.z - lowest.z))
示例14: _move
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def _move(self, direction, value):
""" Moves view into direction by value. """
for view in self.get3DView():
offset = Vector((0.0, 0.0, 0.0))
if direction == "horizontal":
offset.x = value
elif direction == "vertical":
offset.y = value
elif direction == "straightforward":
offset.z = value
view.view_location = view.view_rotation*offset + view.view_location
示例15: execute
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import z [as 别名]
def execute(self, context):
scene = context.scene
obj = context.active_object
# check if active object is a mesh object
if not obj or obj.type != 'MESH':
self.report({'ERROR'}, "No selected mesh object!")
return {'CANCELLED'}
# check if it has one single face
if len(obj.data.polygons) != 1:
self.report({'ERROR'}, "The selected mesh object has to have exactly one quad!")
return {'CANCELLED'}
rl = scene.lightfield.row_length
# use a degree angle here
angle = degrees(scene.lightfield.angle)
spacing = scene.lightfield.spacing
# resolution of final renderings
res = round(scene.render.resolution_x * (scene.render.resolution_percentage / 100.))
width = self.getWidth(obj)
# the offset between n pixels on the focal plane
fplane_offset = (width / res) * spacing
# vertices for the basemesh
verts = []
# the offset vector
vec = self.getCamVec(obj, angle)
# lower left coordinates of the grid
sx = obj.location[0] - fplane_offset * int(rl / 2)
sy = obj.location[1] - fplane_offset * int(rl / 2)
z = obj.location[2]
# position on the focal plane
fplane_pos = Vector()
for x in [sx + fplane_offset * i for i in range(rl)]:
for y in [sy + fplane_offset * i for i in range(rl)]:
fplane_pos.x = x
fplane_pos.y = y
fplane_pos.z = z
# position of a vertex in a basemesh
pos = fplane_pos + vec
# pack coordinates flat into the vert list
verts.append((pos.x, pos.y, pos.z))
# setup the basemesh and add verts
mesh = bpy.data.meshes.new(self.objName)
mesh.from_pydata(verts, [], [])
self.addMeshObj(mesh)
return {'FINISHED'}