本文整理汇总了Python中MeshPart.wireFromSegment方法的典型用法代码示例。如果您正苦于以下问题:Python MeshPart.wireFromSegment方法的具体用法?Python MeshPart.wireFromSegment怎么用?Python MeshPart.wireFromSegment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshPart
的用法示例。
在下文中一共展示了MeshPart.wireFromSegment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getShapeFromMesh
# 需要导入模块: import MeshPart [as 别名]
# 或者: from MeshPart import wireFromSegment [as 别名]
def getShapeFromMesh(mesh,fast=True,tolerance=0.001,flat=False,cut=True):
import Part, MeshPart, DraftGeomUtils
if mesh.isSolid() and (mesh.countComponents() == 1) and fast:
# use the best method
faces = []
for f in mesh.Facets:
p=f.Points+[f.Points[0]]
pts = []
for pp in p:
pts.append(FreeCAD.Vector(pp[0],pp[1],pp[2]))
try:
f = Part.Face(Part.makePolygon(pts))
except:
pass
else:
faces.append(f)
shell = Part.makeShell(faces)
solid = Part.Solid(shell)
solid = solid.removeSplitter()
return solid
faces = []
segments = mesh.getPlanarSegments(tolerance)
#print len(segments)
for i in segments:
if len(i) > 0:
wires = MeshPart.wireFromSegment(mesh, i)
if wires:
if flat:
nwires = []
for w in wires:
nwires.append(DraftGeomUtils.flattenWire(w))
wires = nwires
try:
faces.append(makeFace(wires,method=int(cut)+1))
except:
return None
try:
se = Part.makeShell(faces)
se = se.removeSplitter()
if flat:
return se
except Part.OCCError:
try:
cp = Part.makeCompound(faces)
except Part.OCCError:
return None
else:
return cp
else:
try:
solid = Part.Solid(se)
except Part.OCCError:
return se
else:
return solid
示例2: meshToShape
# 需要导入模块: import MeshPart [as 别名]
# 或者: from MeshPart import wireFromSegment [as 别名]
def meshToShape(obj,mark=True):
'''meshToShape(object,[mark]): turns a mesh into a shape, joining coplanar facets. If
mark is True (default), non-solid objects will be marked in red'''
name = obj.Name
import Part,MeshPart
from draftlibs import fcgeo
if "Mesh" in obj.PropertiesList:
faces = []
mesh = obj.Mesh
plac = obj.Placement
segments = mesh.getPlanes(0.001) # use rather strict tolerance here
print len(segments)," segments ",segments
for i in segments:
print "treating",segments.index(i),i
if len(i) > 0:
wires = MeshPart.wireFromSegment(mesh, i)
print "wire done"
print wires
if wires:
faces.append(makeFace(wires))
print "done facing"
print "faces",faces
try:
se = Part.makeShell(faces)
solid = Part.Solid(se)
except:
pass
else:
if solid.isClosed():
FreeCAD.ActiveDocument.removeObject(name)
newobj = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
newobj.Shape = solid
newobj.Placement = plac
if not solid.isClosed():
if mark:
newobj.ViewObject.ShapeColor = (1.0,0.0,0.0,1.0)
return newobj
return None
示例3: len
# 需要导入模块: import MeshPart [as 别名]
# 或者: from MeshPart import wireFromSegment [as 别名]
# FreeCAD TemplatePyMod module
# (c) 2010 Werner Mayer LGPL
import Mesh,Part,MeshPart
faces = []
mesh = App.ActiveDocument.ActiveObject.Mesh
segments = mesh.getPlanarSegments(0.00001) # use rather strict tolerance here
for i in segments:
if len(i) > 0:
# a segment can have inner holes
wires = MeshPart.wireFromSegment(mesh, i)
# we assume that the exterior boundary is that one with the biggest bounding box
if len(wires) > 0:
ext=None
max_length=0
for i in wires:
if i.BoundBox.DiagonalLength > max_length:
max_length = i.BoundBox.DiagonalLength
ext = i
wires.remove(ext)
# all interior wires mark a hole and must reverse their orientation, otherwise Part.Face fails
for i in wires:
i.reverse()
# make sure that the exterior wires comes as first in the list
wires.insert(0, ext)
faces.append(Part.Face(wires))