| 605 | |
| 606 | === Izdelava CAD kocke z predhodno definiranimi točkami (Uporaba for zanke za generiranje točk, površin, mreže) === |
| 607 | {{{ |
| 608 | #!python |
| 609 | import sys |
| 610 | from OCC.Display.SimpleGui import * |
| 611 | |
| 612 | from OCC.gp import gp_Pnt |
| 613 | from OCC.GC import GC_MakeSegment |
| 614 | from OCC.BRepBuilderAPI import \ |
| 615 | BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire,\ |
| 616 | BRepBuilderAPI_MakeShell, BRepBuilderAPI_MakeSolid |
| 617 | from OCC.BRep import BRep_Builder |
| 618 | from OCC.TopoDS import TopoDS_Shell, TopoDS_Solid |
| 619 | from OCC import StlAPI |
| 620 | |
| 621 | mesh = { |
| 622 | "vertices":[[-0.2,-0.2,0.2],[0.2,-0.2,0.2],[0.2,0.2,0.2],[-0.2,0.2,0.2],\ |
| 623 | [-0.2,-0.2,0.6000000000000001],[0.2,-0.2,0.6000000000000001],\ |
| 624 | [0.2,0.2,0.6000000000000001],[-0.2,0.2,0.6000000000000001]], |
| 625 | "faces":[[3,2,1,0],[4,5,6,7],[7,6,2,3],[5,4,0,1],[6,5,1,2],[4,7,3,0]] |
| 626 | } |
| 627 | |
| 628 | def main(): |
| 629 | |
| 630 | vertices = [ gp_Pnt(p[0],p[1],p[2]) for p in mesh['vertices'] ] |
| 631 | oFaces = [] |
| 632 | |
| 633 | builder = BRep_Builder() |
| 634 | shell = TopoDS_Shell() |
| 635 | builder.MakeShell(shell) |
| 636 | |
| 637 | for face in mesh['faces']: |
| 638 | edges = [] |
| 639 | face.reverse() |
| 640 | for i in range(len(face)): |
| 641 | cur = face[i] |
| 642 | nxt = face[(i+1)%len(face)] |
| 643 | segment = GC_MakeSegment(vertices[cur],vertices[nxt]) |
| 644 | edges.append(BRepBuilderAPI_MakeEdge(segment.Value())) |
| 645 | |
| 646 | wire = BRepBuilderAPI_MakeWire() |
| 647 | for edge in edges: |
| 648 | wire.Add(edge.Edge()) |
| 649 | |
| 650 | oFace = BRepBuilderAPI_MakeFace(wire.Wire()) |
| 651 | |
| 652 | builder.Add(shell, oFace.Shape()) |
| 653 | display.DisplayShape(shell) |
| 654 | |
| 655 | if __name__ == '__main__': |
| 656 | display, start_display, add_menu, add_function_to_menu = \ |
| 657 | init_display() |
| 658 | main() |
| 659 | start_display() |
| 660 | }}} |