本文整理汇总了Python中Mesh类的典型用法代码示例。如果您正苦于以下问题:Python Mesh类的具体用法?Python Mesh怎么用?Python Mesh使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: machinebuilder
def machinebuilder(text, size, height):
'''
[doc]
-title-
Text Generator
-description-
Create text in 3D
[inputs]
str(text)
int(size)
int(height)
'''
#-- Generate text
doc = FreeCAD.newDocument("TextGenerator")
ss=Draft.makeShapeString(String=text,FontFile="/usr/share/fonts/truetype/droid/DroidSans.ttf",Size=size,Tracking=0)
#ss=Draft.extrude(ss,FreeCAD.Base.Vector(0,0,10))
obj = doc.addObject("Part::Extrusion","TextGenerator")
obj.Base = ss
obj.Dir = (0,0,height)
doc.recompute()
#-- Export the file
name = text+"-"+str(size)+".stl"
Mesh.export([obj], './%s' % name)
return name
示例2: testRayPick
def testRayPick(self):
if not FreeCAD.GuiUp:
return
self.planarMesh.append([-16.097176, -29.891157, 15.987688])
self.planarMesh.append([-16.176304, -29.859991, 15.947966])
self.planarMesh.append([-16.071451, -29.900553, 15.912505])
self.planarMesh.append([-16.092241, -29.893408, 16.020439])
self.planarMesh.append([-16.007210, -29.926180, 15.967641])
self.planarMesh.append([-16.064457, -29.904951, 16.090832])
planarMeshObject = Mesh.Mesh(self.planarMesh)
from pivy import coin
import FreeCADGui
Mesh.show(planarMeshObject)
view = FreeCADGui.ActiveDocument.ActiveView.getViewer()
rp = coin.SoRayPickAction(view.getSoRenderManager().getViewportRegion())
rp.setRay(coin.SbVec3f(-16.05, 16.0, 16.0), coin.SbVec3f(0, -1, 0))
rp.apply(view.getSoRenderManager().getSceneGraph())
pp = rp.getPickedPoint()
self.failUnless(pp != None)
det = pp.getDetail()
self.failUnless(det.getTypeId() == coin.SoFaceDetail.getClassTypeId())
det = coin.cast(det, str(det.getTypeId().getName()))
self.failUnless(det.getFaceIndex() == 1)
示例3: makeMengerSponge
def makeMengerSponge(level=3,x0=0,y0=0,z0=0):
mesh=Sierpinski(level,x0,y0,z0)
mesh.removeDuplicatedPoints()
mesh.removeFacets(mesh.getInternalFacets())
mesh.rebuildNeighbourHood()
print("Mesh is solid: %s" % (mesh.isSolid()))
Mesh.show(mesh)
示例4: process_mesh_file
def process_mesh_file(fname,ext):
import Mesh,Part
fullname = fname+'.'+ext
filename = os.path.join(pathName,fullname)
objname = os.path.split(fname)[1]
mesh1 = doc.getObject(objname) #reuse imported object
if not mesh1:
Mesh.insert(filename)
mesh1=doc.getObject(objname)
if mesh1 is not None:
if gui:
mesh1.ViewObject.hide()
sh=Part.Shape()
sh.makeShapeFromMesh(mesh1.Mesh.Topology,0.1)
solid = Part.Solid(sh)
obj=doc.addObject('Part::Feature',"Mesh")
#ImportObject(obj,mesh1) #This object is not mutable from the GUI
#ViewProviderTree(obj.ViewObject)
solid=solid.removeSplitter()
if solid.Volume < 0:
#sh.reverse()
#sh = sh.copy()
solid.complement()
obj.Shape=solid#.removeSplitter()
else: #mesh1 is None
FreeCAD.Console.PrintError('Mesh not imported %s.%s %s\n' % \
(objname,ext,filename))
import Part
obj=doc.addObject('Part::Feature',"FailedMeshImport")
obj.Shape=Part.Compound([])
return(obj)
示例5: main
def main():
start = time.time()
# set default values
tol = 1.e-8
cell_size = 10.0
solve_method = 'NEM4'
iterations = 100
# create mesh
mesh = Mesh([cell_size,cell_size], [cell_size])
# create fuel
fuel = Material(2, 'fuel')
fuel.setSigmaA([0.005, 0.10])
fuel.setD([1.5, 0.40])
fuel.setNuSigmaF([0.005, 0.15])
fuel.setChi([1.0, 0.0])
fuel.setSigmaS(np.array([[0.0, 0.02],[0.0, 0.0]]))
# create fuel
moderator = Material(2, 'moderator')
moderator.setSigmaA([0.0, 0.01])
moderator.setD([1.5, 0.20])
moderator.setSigmaS(np.array([[0.0, 0.025],[0.0, 0.0]]))
if solve_method == 'NEM4':
order = 4
else:
order = 2
# add materials to cells
mesh.cells[0].setMaterial(fuel, order)
mesh.cells[1].setMaterial(moderator, order)
# mesh = mesh.refineMesh(.1)
mesh.makeSurfaces()
# plot the mesh
pttr.plotMesh(mesh)
# create solver
solver = Solver(mesh, solve_method)
# solve the matrix problem to get flux profile and keff
solver.solve(tol, iterations)
# plot the flux
pttr.plotFlux(solver)
pttr.plotCellFlux(solver)
pttr.plotCurrent(solver)
stop = time.time()
print 'Ran time ' + str(stop-start)[0:5] + ' seconds'
print '----------------------------------------------------------------------'
示例6: makeMengerSponge_mt
def makeMengerSponge_mt(level=3,x0=0,y0=0,z0=0):
"""
Is much slower than makeMengerSponge!!! :(
"""
if level == 0:
mesh=Sierpinski(level,x0,y0,z0)
Mesh.show(mesh)
return
boxnums = pow(3,level)
thirds = boxnums / 3
twothirds = thirds * 2
rangerx = [ x0, x0 + thirds, x0 + twothirds ]
rangery = [ y0, y0 + thirds, y0 + twothirds ]
rangerz = [ z0, z0 + thirds, z0 + twothirds ]
block = 1
skip=[5,11,13,14,15,17,23]
# collect the arguments for the algorithm in a list
args=[]
for i in rangerx:
for j in rangery:
for k in rangerz:
if block not in skip:
args.append((level-1,i,j,k))
block+=1
numJobs = 4
threads=[]
while numJobs > 0:
size = len(args)
count = size / numJobs
numJobs-=1
thr=MengerThread(args[:count])
threads.append(thr)
args=args[count:]
print("Number of threads: %i" % (len(threads)))
for thr in threads:
thr.start()
for thr in threads:
thr.join()
mesh=Mesh.Mesh()
for thr in threads:
mesh.addMesh(thr.mesh)
del thr.mesh
print(mesh)
mesh.removeDuplicatedPoints()
mesh.removeFacets(mesh.getInternalFacets())
mesh.rebuildNeighbourHood()
print("Mesh is solid: %s" % (mesh.isSolid()))
Mesh.show(mesh)
示例7: Activated
def Activated(self):
pol=np.loadtxt(FreeCAD.getHomePath()+'Mod/glider/examples/p.dat', dtype=int)
nod=np.loadtxt(FreeCAD.getHomePath()+'Mod/glider/examples/n.dat', dtype=float)
planarMesh = []
for i in pol:
planarMesh.append(nod[i[0]])
planarMesh.append(nod[i[1]])
planarMesh.append(nod[i[2]])
planarMesh.append(nod[i[0]])
planarMesh.append(nod[i[2]])
planarMesh.append(nod[i[3]])
planarMeshObject = Mesh.Mesh(planarMesh)
Mesh.show(planarMeshObject)
示例8: commonMesh
def commonMesh(mesh,box):
t=Mesh.Mesh()
Mesh.show(t)
m_out=App.ActiveDocument.ActiveObject
App.ActiveDocument.ActiveObject.ViewObject.Lighting="Two side"
m_out.ViewObject.ShapeColor=(random.random(),random.random(),random.random())
[pts,tris]=mesh.Mesh.Topology
filter=np.array([0]*len(pts))
n=1
for i,p in enumerate(pts):
if box.Shape.BoundBox.isInside(p):
filter[i]=n
if i % 1000 == 0:
FreeCAD.Console.PrintMessage(" ** " + str(i))
tris2=[]
for t in tris:
(a,b,c)=t
if filter[a] and filter[b] and filter[c]:
tris2.append((filter[a]-1,filter[b]-1,filter[c]-1))
pts2=[]
for i,p in enumerate(pts):
if filter[i]:
pts2.append(pts[i])
m_out.Mesh=Mesh.Mesh((pts2,tris2))
m_out.ViewObject.DisplayMode = u"Flat Lines"
Gui.updateGui()
n += 1
tris2=[]
for t in tris:
(a,b,c)=t
if filter[a] and filter[b] and filter[c]:
tris2.append((filter[a]-1,filter[b]-1,filter[c]-1))
pts2=[]
for i,p in enumerate(pts):
if filter[i]:
pts2.append(pts[i])
m_out.Mesh=Mesh.Mesh((pts2,tris2))
示例9: _createEllipsoid
def _createEllipsoid(proxy, radius, colour, moiScale, withMesh):
"""
Private function.
Use createEllipsoid() or createArticulatedEllipsoid() instead.
"""
# Mesh and cdps will be set manually
proxy.meshes = None
proxy.cdps = None
# Compute box moi
moi = [0, 0, 0]
for i in range(3):
j = (i + 1) % 3
k = (i + 2) % 3
moi[i] = proxy.mass * (radius[j] * radius[j] + radius[k] * radius[k]) / 5.0
proxy.moi = PyUtils.toVector3d(moi) * moiScale
ellipsoid = proxy.createAndFillObject()
cdp = Physics.SphereCDP()
cdp.setCenter(Point3d(0, 0, 0))
cdp.setRadius(min(radius))
ellipsoid.addCollisionDetectionPrimitive(cdp)
if withMesh:
mesh = Mesh.createEllipsoid((0, 0, 0), radius, colour)
ellipsoid.addMesh(mesh)
return ellipsoid
示例10: machinebuilder
def machinebuilder(diameter, height, file_path):
#-- Get the freecad document
document = os.path.abspath("cylinder.fcstd")
doc = FreeCAD.openDocument(document)
#-- Get the Cylinder object from the document
cyl = doc.getObjectsByLabel("mycylinder")[0]
#-- Set the cylinder's parameters
if cyl:
cyl.Radius = diameter / 2.0
cyl.Height = height
doc.recompute()
#-- Export the file
Mesh.export([cyl], file_path)
示例11: testPrimitiveCount
def testPrimitiveCount(self):
if not FreeCAD.GuiUp:
return
self.planarMesh.append( [-16.097176,-29.891157,15.987688] )
self.planarMesh.append( [-16.176304,-29.859991,15.947966] )
self.planarMesh.append( [-16.071451,-29.900553,15.912505] )
self.planarMesh.append( [-16.092241,-29.893408,16.020439] )
self.planarMesh.append( [-16.007210,-29.926180,15.967641] )
self.planarMesh.append( [-16.064457,-29.904951,16.090832] )
planarMeshObject = Mesh.Mesh(self.planarMesh)
from pivy import coin; import FreeCADGui
Mesh.show(planarMeshObject)
view=FreeCADGui.ActiveDocument.ActiveView
pc=coin.SoGetPrimitiveCountAction()
pc.apply(view.getSceneGraph())
self.failUnless(pc.getTriangleCount() == 2)
示例12: addelement
def addelement(self):
scadstr=unicode(self.form.textEdit.toPlainText())
asmesh=self.form.checkboxmesh.checkState()
import OpenSCADUtils, os
extension= 'stl' if asmesh else 'csg'
tmpfilename=OpenSCADUtils.callopenscadstring(scadstr,extension)
if tmpfilename:
doc=FreeCAD.activeDocument() or FreeCAD.newDocument()
if asmesh:
import Mesh
Mesh.insert(tmpfilename,doc.Name)
else:
import importCSG
importCSG.insert(tmpfilename,doc.Name)
os.unlink(tmpfilename)
else:
FreeCAD.Console.PrintError(unicode(translate('OpenSCAD','Running OpenSCAD failed'))+u'\n')
示例13: makeMesh
def makeMesh():
FreeCAD.newDocument()
import Mesh
a=FreeCAD.ActiveDocument.addObject("Mesh::FeaturePython","Mesh")
a.Mesh=Mesh.createSphere(5.0)
MeshFeature(a)
ViewProviderMesh(a.ViewObject)
示例14: testLoadMesh
def testLoadMesh(self):
mesh=Mesh.createSphere(10.0,100) # a fine sphere
name=tempfile.gettempdir() + os.sep + "mesh.stl"
mesh.write(name)
FreeCAD.Console.PrintMessage("Write mesh to %s\n"%(name))
#lock=thread.allocate_lock()
for i in range(2):
thread.start_new(loadFile,(name,))
time.sleep(1)
示例15: saveAndClose
def saveAndClose(self, name, saveSTL):
# Save the FCStd file
if os.path.isfile(self.partsDir + name + ".FCStd"):
os.remove(self.partsDir + name + ".FCStd")
App.getDocument(name).saveAs(self.partsDir + name + ".FCStd")
if saveSTL:
# Export an STL
if os.path.isfile(self.stlDir + name + ".stl"):
os.remove(self.stlDir + name + ".stl")
__objs__ = []
__objs__.append(App.getDocument(name).Objects[-1])
Mesh.export(__objs__, self.stlDir + name + ".stl")
del __objs__
# close document
App.closeDocument(name)