本文整理汇总了Python中mathutils.geometry.normal方法的典型用法代码示例。如果您正苦于以下问题:Python geometry.normal方法的具体用法?Python geometry.normal怎么用?Python geometry.normal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.geometry
的用法示例。
在下文中一共展示了geometry.normal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getPolyNormal
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def getPolyNormal(poly):
""" Returns the normal of poligon based on the position of their vertex. It calculates the normal, it doesn't return manually modified normals.
:param poly: The poligon.
:type poly: |KX_PolyProxy|
"""
mesh = poly.getMesh()
s = poly.getNumVertex()
v1 = mesh.getVertex(0, poly.v1)
v2 = mesh.getVertex(0, poly.v2)
v3 = mesh.getVertex(0, poly.v3)
if s == 4: v4v = mesh.getVertex(0, poly.v4).XYZ
else: v4v = None
if v4v: normal = geometry.normal(v1.XYZ, v2.XYZ, v3.XYZ, v4v)
else: normal = geometry.normal(v1.XYZ, v2.XYZ, v3.XYZ)
return normal
示例2: __init__
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def __init__(self):
self.new_ang_r = 0.0
self.new_ang_d = 0.0
self.ang_diff_d = 0.0
self.ang_diff_r = 0.0
self.axis_lk = ''
self.piv_norm = [] # pivot normal
#self.angleEq_0_180 = False
#self.obj = bpy.context.scene.objects[self.obj_idx] # short hand
# Floating point math fun! Since equality tests on floats are a crap shoot,
# instead check if floats are almost equal (is the first float within a
# certain tolerance amount of the second).
# Note, this function may fail in certain circumstances depending on the
# number of significant figures. If comparisons become problematic, you can
# try a different power of ten for the "tol" value (eg 0.01 or 0.00001)
# todo: replace this with Python 3.5's math.isclose() ?
# do recent versions of Blender support math.isclose()?
示例3: ang_match3D
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def ang_match3D(pt1, pt2, pt3, exp_ang):
ang_meas = get_line_ang_3D(pt1, pt2, pt3)
'''
print("pt1", pt1) # debug
print("pt2", pt2) # debug
print("pt3", pt3) # debug
print("exp_ang ", exp_ang) # debug
print("ang_meas ", ang_meas) # debug
'''
return flts_alm_eq(ang_meas, exp_ang)
# Calculates rotation around axis or face normal at Pivot's location.
# Takes two 3D coordinate Vectors (piv_co and mov_co), rotation angle in
# radians (ang_diff_rad), and rotation data storage object (rot_dat).
# Aligns mov_co to world origin (0, 0, 0) and rotates aligned
# mov_co (mov_aligned) around axis stored in rot_dat. After rotation,
# removes world-origin alignment.
示例4: _ascii_read
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def _ascii_read(data):
# an stl ascii file is like
# HEADER: solid some name
# for each face:
#
# facet normal x y z
# outerloop
# vertex x y z
# vertex x y z
# vertex x y z
# endloop
# endfacet
# strip header
data.readline()
curr_nor = None
for l in data:
l = l.lstrip()
if l.startswith(b'facet'):
curr_nor = tuple(map(float, l.split()[2:]))
# if we encounter a vertex, read next 2
if l.startswith(b'vertex'):
yield curr_nor, [tuple(map(float, l_item.split()[1:])) for l_item in (l, data.readline(), data.readline())]
示例5: _binary_write
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def _binary_write(filepath, faces):
with open(filepath, 'wb') as data:
fw = data.write
# header
# we write padding at header beginning to avoid to
# call len(list(faces)) which may be expensive
fw(struct.calcsize('<80sI') * b'\0')
# 3 vertex == 9f
pack = struct.Struct('<9f').pack
# number of vertices written
nb = 0
for face in faces:
# calculate face normal
# write normal + vertexes + pad as attributes
fw(struct.pack('<3f', *normal(*face)) + pack(*itertools.chain.from_iterable(face)))
# attribute byte count (unused)
fw(b'\0\0')
nb += 1
# header, with correct value now
data.seek(0)
fw(struct.pack('<80sI', _header_version().encode('ascii'), nb))
示例6: add
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def add(self, item):
"""
Add a value to the Set, return its position in it.
"""
value = self.setdefault(item, self._len)
if value == self._len:
self.list.append(item)
self._len += 1
return value
# an stl binary file is
# - 80 bytes of description
# - 4 bytes of size (unsigned int)
# - size triangles :
#
# - 12 bytes of normal
# - 9 * 4 bytes of coordinate (3*3 floats)
# - 2 bytes of garbage (usually 0)
示例7: _binary_write
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def _binary_write(filepath, faces):
with open(filepath, 'wb') as data:
fw = data.write
# header
# we write padding at header beginning to avoid to
# call len(list(faces)) which may be expensive
fw(struct.calcsize('<80sI') * b'\0')
# 3 vertex == 9f
pack = struct.Struct('<9f').pack
# number of vertices written
nb = 0
for face in faces:
# calculate face normal
# write normal + vertexes + pad as attributes
fw(struct.pack('<3f', *normal(*face)) + pack(*itertools.chain.from_iterable(face)))
# attribute byte count (unused)
fw(b'\0\0')
nb += 1
# header, with correct value now
data.seek(0)
fw(struct.pack('<80sI', _header_version().encode('ascii'), nb))
示例8: __init__
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def __init__(self):
self.newAngR = 0.0
self.newAngD = 0.0
self.angDiffD = 0.0
self.angDiffR = 0.0
self.axisLk = ''
self.pivNorm = [] # pivot normal
#self.angleEq_0_180 = False
#self.obj = bpy.context.scene.objects[self.objNum] # short hand
#def datOut(self): # debug
# return self.objNum, self.vertInd, self.coor3D, self.coor2D, self.dist2D
# placeholder function,
# do rotation calculations inside this class?
#def abcdef123(self):
# return
### linear equations ###
#def getMidpoint2D(x1,y1,x2,y2):
# return ( (x1+x2)/2 , (y1+y2)/2 )
示例9: calc_normals
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def calc_normals(self):
"""
Face normals
"""
normals = np.empty((len(self.faces), 3))
for idx, face in enumerate(self.faces):
normals[idx] = normal(self.vertices[face])
self.faces.normals = normals
示例10: do_transform
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def do_transform(self):
global curr_meas_stor, new_meas_stor
rp_ls, ax_lock = self.ref_pts.rp_ls, self.ref_pts.ax_lock
curr_ed = self.curr_ed_type
# Onto Transformations...
if self.transf_mode == XO_GET_0_OR_180:
self.new_free_co, self.r_dat.ang_diff_r = choose_0_or_180(rp_ls[1],
*self.modal_buff, self.mouse_loc, self.left_click)
if self.left_click:
self.left_click = False
if self.new_free_co != ():
do_rotate(curr_ed, self.new_free_co, self.ref_pts, self.r_dat)
reset_settings(self)
elif self.transf_mode == XO_MOVE:
new_coor = get_new_3D_co(self, ax_lock, rp_ls, curr_meas_stor, new_meas_stor)
if new_coor != None:
#print('new_coor', new_coor) #, rp_ls[1]) # debug
do_translation(curr_ed, new_coor, rp_ls[1])
reset_settings(self)
elif self.transf_mode == XO_SCALE:
scale_factor = new_meas_stor / curr_meas_stor
do_scale(self.ref_pts, scale_factor)
reset_settings(self)
elif self.transf_mode == XO_ROTATE:
# for "normal" (non 0_or_180 rotations)
if self.new_free_co != ():
do_rotate(curr_ed, self.new_free_co, self.ref_pts, self.r_dat)
reset_settings(self)
示例11: generate_3PT
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def generate_3PT(pts, obj, nv, mode=1):
mw = obj.matrix_world
V = Vector
nv = max(3, nv)
# construction
v1, v2, v3, v4 = V(pts[0]), V(pts[1]), V(pts[1]), V(pts[2])
edge1_mid = v1.lerp(v2, 0.5)
edge2_mid = v3.lerp(v4, 0.5)
axis = geometry.normal(v1, v2, v4)
mat_rot = mathutils.Matrix.Rotation(math.radians(90.0), 4, axis)
# triangle edges
v1_ = ((v1 - edge1_mid) * mat_rot) + edge1_mid
v2_ = ((v2 - edge1_mid) * mat_rot) + edge1_mid
v3_ = ((v3 - edge2_mid) * mat_rot) + edge2_mid
v4_ = ((v4 - edge2_mid) * mat_rot) + edge2_mid
r = geometry.intersect_line_line(v1_, v2_, v3_, v4_)
if r:
p1, _ = r
cp = mw * p1
bpy.context.scene.cursor_location = cp
if mode == 0:
pass
elif mode == 1:
generate_bmesh_repr(p1, v1, axis, nv)
else:
print('not on a circle')
示例12: _binary_read
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def _binary_read(data):
# Skip header...
data.seek(BINARY_HEADER)
size = struct.unpack('<I', data.read(4))[0]
if size == 0:
# Workaround invalid crap.
data.seek(0, os.SEEK_END)
file_size = data.tell()
# Reset to after-the-size in the file.
data.seek(BINARY_HEADER + 4)
file_size -= BINARY_HEADER + 4
size = file_size // BINARY_STRIDE
print("WARNING! Reported size (facet number) is 0, inferring %d facets from file size." % size)
# We read 4096 elements at once, avoids too much calls to read()!
CHUNK_LEN = 4096
chunks = [CHUNK_LEN] * (size // CHUNK_LEN)
chunks.append(size % CHUNK_LEN)
unpack = struct.Struct('<12f').unpack_from
for chunk_len in chunks:
if chunk_len == 0:
continue
buf = data.read(BINARY_STRIDE * chunk_len)
for i in range(chunk_len):
# read the normal and points coordinates of each triangle
pt = unpack(buf, BINARY_STRIDE * i)
yield pt[:3], (pt[3:6], pt[6:9], pt[9:])
示例13: _ascii_write
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def _ascii_write(filepath, faces):
with open(filepath, 'w') as data:
fw = data.write
header = _header_version()
fw('solid %s\n' % header)
for face in faces:
# calculate face normal
fw('facet normal %f %f %f\nouter loop\n' % normal(*face)[:])
for vert in face:
fw('vertex %f %f %f\n' % vert[:])
fw('endloop\nendfacet\n')
fw('endsolid %s\n' % header)
示例14: generate_3PT_mode_1_
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def generate_3PT_mode_1_(pts, obj):
origin = obj.location
transform_matrix = obj.matrix_local
V = Vector
# construction
v1, v2, v3, v4 = V(pts[0]), V(pts[1]), V(pts[1]), V(pts[2])
edge1_mid = v1.lerp(v2, 0.5)
edge2_mid = v3.lerp(v4, 0.5)
axis = geometry.normal(v1, v2, v4)
mat_rot = mathutils.Matrix.Rotation(math.radians(90.0), 4, axis)
# triangle edges
v1_ = ((v1 - edge1_mid) * mat_rot) + edge1_mid
v2_ = ((v2 - edge1_mid) * mat_rot) + edge1_mid
v3_ = ((v3 - edge2_mid) * mat_rot) + edge2_mid
v4_ = ((v4 - edge2_mid) * mat_rot) + edge2_mid
r = geometry.intersect_line_line(v1_, v2_, v3_, v4_)
if r:
p1, _ = r
# cp = transform_matrix * (p1 + origin)
cp = transform_matrix * p1
bpy.context.scene.cursor_location = cp
# generate_gp3d_stroke(cp, axis, obj, radius=(p1-v1).length)
else:
print('not on a circle')
示例15: angleMatch3D
# 需要导入模块: from mathutils import geometry [as 别名]
# 或者: from mathutils.geometry import normal [as 别名]
def angleMatch3D(self,pt1,pt2,pt3,expAng):
angMeas = getLineAngle3D(self,pt1,pt2,pt3)
#print("pt1",pt1) # debug
#print("pt2",pt2) # debug
#print("pt3",pt3) # debug
#print( "expAng ",expAng ) # debug
#print( "angMeas ",angMeas ) # debug
return AreFloatsEq(angMeas,expAng)
# Calculates rotation around axis or face normal at Pivot's location.
# Takes two 3D coordinate Vectors (PivC and movCo), rotation angle in
# radians (angleDiffRad), and rotation data storage object (rotDat).
# Aligns movCo to world origin, rotates algined movCo (vecTmp) around
# axis stored in rotDat, then removes world-origin alignment.