当前位置: 首页>>代码示例>>Python>>正文


Python Mesh.read方法代码示例

本文整理汇总了Python中Mesh.read方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.read方法的具体用法?Python Mesh.read怎么用?Python Mesh.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mesh的用法示例。


在下文中一共展示了Mesh.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: startElement

# 需要导入模块: import Mesh [as 别名]
# 或者: from Mesh import read [as 别名]
 def startElement(self, tag, attributes):
     
     if tag == "wall":
         name = attributes["id"]
         p1 = FreeCAD.Vector(float(attributes["xStart"])*10,float(attributes["yStart"])*10,0)
         p2 = FreeCAD.Vector(float(attributes["xEnd"])*10,float(attributes["yEnd"])*10,0)
         height = float(attributes["height"])*10
         thickness = float(attributes["thickness"])*10
         if DEBUG: print "Creating wall: ",name
         line = Draft.makeLine(p1,p2)
         if self.makeIndividualWalls:
             wall = Arch.makeWall(baseobj=line,width=thickness,height=height,name=name)
             wall.Label = name
         else:
             self.lines.setdefault(str(thickness)+";"+str(height),[]).append(line)
         
     elif tag == "pieceOfFurniture":
         name = attributes["name"]
         data = self.z.read(attributes["model"])
         tf = tempfile.mkstemp(suffix=".obj")[1]
         f = pyopen(tf,"wb")
         f.write(data)
         f.close()
         m = Mesh.read(tf)
         fx = (float(attributes["width"])/100)/m.BoundBox.XLength
         fy = (float(attributes["height"])/100)/m.BoundBox.YLength
         fz = (float(attributes["depth"])/100)/m.BoundBox.ZLength
         mat = FreeCAD.Matrix()
         mat.scale(1000*fx,1000*fy,1000*fz)
         mat.rotateX(math.pi/2)
         mat.rotateZ(math.pi)
         if DEBUG: print "Creating furniture: ",name
         if "angle" in attributes.keys():
             mat.rotateZ(float(attributes["angle"]))
         m.transform(mat)
         os.remove(tf)
         p = m.BoundBox.Center.negative()
         p = p.add(FreeCAD.Vector(float(attributes["x"])*10,float(attributes["y"])*10,0))
         p = p.add(FreeCAD.Vector(0,0,m.BoundBox.Center.z-m.BoundBox.ZMin))
         m.Placement.Base = p
         obj = FreeCAD.ActiveDocument.addObject("Mesh::Feature",name)
         obj.Mesh = m
         self.furniture.append(obj)
         
     elif tag == "doorOrWindow":
         name = attributes["name"]
         data = self.z.read(attributes["model"])
         tf = tempfile.mkstemp(suffix=".obj")[1]
         f = pyopen(tf,"wb")
         f.write(data)
         f.close()
         m = Mesh.read(tf)
         fx = (float(attributes["width"])/100)/m.BoundBox.XLength
         fy = (float(attributes["height"])/100)/m.BoundBox.YLength
         fz = (float(attributes["depth"])/100)/m.BoundBox.ZLength
         mat = FreeCAD.Matrix()
         mat.scale(1000*fx,1000*fy,1000*fz)
         mat.rotateX(math.pi/2)
         m.transform(mat)
         b = m.BoundBox
         v1 = FreeCAD.Vector(b.XMin,b.YMin-500,b.ZMin)
         v2 = FreeCAD.Vector(b.XMax,b.YMin-500,b.ZMin)
         v3 = FreeCAD.Vector(b.XMax,b.YMax+500,b.ZMin)
         v4 = FreeCAD.Vector(b.XMin,b.YMax+500,b.ZMin)
         sub = Part.makePolygon([v1,v2,v3,v4,v1])
         sub = Part.Face(sub)
         sub = sub.extrude(FreeCAD.Vector(0,0,b.ZLength))
         os.remove(tf)
         shape = Arch.getShapeFromMesh(m)
         if not shape:
             shape=Part.Shape()
             shape.makeShapeFromMesh(m.Topology,0.100000)
             shape = shape.removeSplitter()
         if shape:
             if DEBUG: print "Creating window: ",name
             if "angle" in attributes.keys():
                 shape.rotate(shape.BoundBox.Center,FreeCAD.Vector(0,0,1),math.degrees(float(attributes["angle"])))
                 sub.rotate(shape.BoundBox.Center,FreeCAD.Vector(0,0,1),math.degrees(float(attributes["angle"])))
             p = shape.BoundBox.Center.negative()
             p = p.add(FreeCAD.Vector(float(attributes["x"])*10,float(attributes["y"])*10,0))
             p = p.add(FreeCAD.Vector(0,0,shape.BoundBox.Center.z-shape.BoundBox.ZMin))
             if "elevation" in attributes.keys():
                 p = p.add(FreeCAD.Vector(0,0,float(attributes["elevation"])*10))
             shape.translate(p)
             sub.translate(p)
             obj = FreeCAD.ActiveDocument.addObject("Part::Feature",name+"_body")
             obj.Shape = shape
             subobj = FreeCAD.ActiveDocument.addObject("Part::Feature",name+"_sub")
             subobj.Shape = sub
             if FreeCAD.GuiUp:
                 subobj.ViewObject.hide()
             win = Arch.makeWindow(baseobj=obj,name=name)
             win.Label = name
             win.Subvolume = subobj
             self.windows.append(win)
         else:
             print("importSH3D: Error creating shape for door/window "+name)
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:99,代码来源:importSH3D.py


注:本文中的Mesh.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。