本文整理汇总了Python中mathutils.Vector.x方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.x方法的具体用法?Python Vector.x怎么用?Python Vector.x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Vector
的用法示例。
在下文中一共展示了Vector.x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getBoundsBF
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [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
示例2: getBoundingBox
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [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: readPackedVector
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [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
示例4: calcAlign
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [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
示例5: analyzeMeshObject
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [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: __neg__
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [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)
示例7: __get_uv_max_min
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [as 别名]
def __get_uv_max_min(self, loop_seqs, uv_layer):
uv_max = Vector((-1000000.0, -1000000.0))
uv_min = Vector((1000000.0, 1000000.0))
for hseq in loop_seqs:
for l in hseq[0]:
uv = l[uv_layer].uv
uv_max.x = max(uv.x, uv_max.x)
uv_max.y = max(uv.y, uv_max.y)
uv_min.x = min(uv.x, uv_min.x)
uv_min.y = min(uv.y, uv_min.y)
return uv_max, uv_min
示例8: plank
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [as 别名]
def plank(
face_vs,
thickness,
offset = Vector(( 0,0,0 ))
):
verts = []
faces = []
if len( face_vs ) == 4:
for j in range( 0,2 ):
for v in face_vs:
vv = Vector( v )
if j == 0:
vv.x = vv.x - thickness * 0.5
else:
vv.x = vv.x + thickness * 0.5
vv += offset
verts.append( ( vv.x, vv.y, vv.z ) )
faces = [
(0,1,2,3),
(7,6,5,4),
(0,3,7,4),
(0,1,5,4),
(1,2,6,5),
(2,3,7,6)
]
elif len( face_vs ) == 7:
for j in range( 0,2 ):
for i in range( 0, 6 ):
vv = Vector( face_vs[ i ] )
if j == 0:
vv.x = vv.x - thickness * 0.5
else:
vv.x = vv.x + thickness * 0.5
vv += offset
verts.append( ( vv.x, vv.y, vv.z ) )
faces = [
(0,1,2,3), (3,4,5,0),
(9,8,7,6), (6,11,10,9),
(0,1,7,6),
(1,2,8,7),
(2,3,9,8),
(3,4,10,9),
(4,5,11,10),
(5,0,6,11)
]
return verts, faces
示例9: bounding_box
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [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
示例10: __get_island_info
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [as 别名]
def __get_island_info(uv_layer, islands):
"""
get information about each island
"""
island_info = []
for isl in islands:
info = {}
max_uv = Vector((-10000000.0, -10000000.0))
min_uv = Vector((10000000.0, 10000000.0))
ave_uv = Vector((0.0, 0.0))
num_uv = 0
for face in isl:
n = 0
a = Vector((0.0, 0.0))
ma = Vector((-10000000.0, -10000000.0))
mi = Vector((10000000.0, 10000000.0))
for l in face['face'].loops:
uv = l[uv_layer].uv
ma.x = max(uv.x, ma.x)
ma.y = max(uv.y, ma.y)
mi.x = min(uv.x, mi.x)
mi.y = min(uv.y, mi.y)
a = a + uv
n = n + 1
ave_uv = ave_uv + a
num_uv = num_uv + n
a = a / n
max_uv.x = max(ma.x, max_uv.x)
max_uv.y = max(ma.y, max_uv.y)
min_uv.x = min(mi.x, min_uv.x)
min_uv.y = min(mi.y, min_uv.y)
face['max_uv'] = ma
face['min_uv'] = mi
face['ave_uv'] = a
ave_uv = ave_uv / num_uv
info['center'] = ave_uv
info['size'] = max_uv - min_uv
info['num_uv'] = num_uv
info['group'] = -1
info['faces'] = isl
info['max'] = max_uv
info['min'] = min_uv
island_info.append(info)
return island_info
示例11: saveVertex
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [as 别名]
def saveVertex(fh, fnormal, useSmooth, uvLayer, vtx, vInx, ofst, exportType):
uv = Vector((0.0, 1.0))
normal = Vector((fnormal.x, fnormal.y, fnormal.z))
weights = (0.0, 0.0, 0.0, 0.0)
co = vtx.co - ofst
if uvLayer != None:
uv.x = uvLayer.uv_raw[vInx * 2 + 0]
uv.y = -uvLayer.uv_raw[vInx * 2 + 1]
if useSmooth:
normal = vtx.normal
rotationMatrix = Matrix.Rotation(math.radians(-90.0), 3, "X")
co = rotationMatrix * co
normal = rotationMatrix * normal
if exportType == eTypes.TYPE0:
saveVertexType0(fh, co, uv)
elif exportType == eTypes.TYPE1:
saveVertexType1(fh, co, normal, uv)
elif exportType == eTypes.TYPE2:
saveVertexType2(fh, co, normal, uv, weights)
elif exportType == eTypes.TYPE3:
saveVertexType3(fh, co, normal, uv)
elif exportType == eTypes.TYPE4:
saveVertexType4(fh, co, normal, uv, weights)
示例12: modal
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [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'}
示例13: pointInIsland
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [as 别名]
def pointInIsland(pt, island):
vec1, vec2, vec3 = Vector(), Vector(), Vector()
for f in island:
vec1.x, vec1.y = f.uv[0]
vec2.x, vec2.y = f.uv[1]
vec3.x, vec3.y = f.uv[2]
if pointInTri2D(pt, vec1, vec2, vec3):
return True
if len(f.v) == 4:
vec1.x, vec1.y = f.uv[0]
vec2.x, vec2.y = f.uv[2]
vec3.x, vec3.y = f.uv[3]
if pointInTri2D(pt, vec1, vec2, vec3):
return True
return False
示例14: saveVertex
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [as 别名]
def saveVertex(fh, obj, fnormal, useSmooth, uvLayer, vtx, vInx):
uv = Vector((0.0, 1.0))
normal = Vector((fnormal.x, fnormal.y, fnormal.z))
weights = (0.0, 0.0, 0.0, 0.0)
co = obj.location + vtx.co;
co.x = -co.x
if uvLayer != None:
uv.x = uvLayer.uv_raw[vInx * 2 + 0]
uv.y = -uvLayer.uv_raw[vInx * 2 + 1]
if useSmooth:
normal = vtx.normal
normal.x = -normal.x
saveVertexType4(fh, co, normal, uv, weights)
示例15: gui_space
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import x [as 别名]
def gui_space(p):
p = Vector(p).copy()
p.x = p.x*16 - 8
p.y = p.y*9 - 4.5
p.y *= -1
return p