154 | | |
| 154 | Celoten program za izdelavo modela je naslednji: |
| 155 | {{{ |
| 156 | #!python |
| 157 | from OCC.gp import * |
| 158 | from OCC.BRepPrimAPI import * |
| 159 | from OCC.TopExp import * |
| 160 | from OCC.TopAbs import * |
| 161 | from OCC.BRep import * |
| 162 | from OCC.Geom import * |
| 163 | from OCC.GCE2d import * |
| 164 | from OCC.GC import * |
| 165 | from OCC.Geom2d import * |
| 166 | from OCC.BRepLib import * |
| 167 | from OCC.BRepFeat import * |
| 168 | from OCC.Utils.Topology import Topo |
| 169 | from OCC.BRepBuilderAPI import * |
| 170 | from OCC.BRepAlgoAPI import * |
| 171 | from OCC.BRepFilletAPI import * |
| 172 | from OCC.TopoDS import * |
| 173 | from OCC.StlAPI import * |
| 174 | from math import radians |
| 175 | |
| 176 | from OCC.Display.SimpleGui import * |
| 177 | from OCC.Graphic3d import * |
| 178 | |
| 179 | R = 20 |
| 180 | L = 150 |
| 181 | p = gp_Pnt(0.,0.,0) |
| 182 | d = gp_Dir(1. ,0., 0.) |
| 183 | myAxes1 = gp_Ax2(p,d) |
| 184 | myPrim1 = BRepPrimAPI_MakeCylinder(myAxes1, R, 100) |
| 185 | |
| 186 | mkFillet = BRepFilletAPI_MakeChamfer(myPrim1.Shape()) |
| 187 | ex = TopExp_Explorer(myPrim1.Shape(), TopAbs_EDGE) |
| 188 | ex2 = TopExp_Explorer(myPrim1.Shape(), TopAbs_FACE) |
| 189 | edge = TopoDS_edge(ex.Current()) |
| 190 | face = TopoDS_face(ex2.Current()) |
| 191 | mkFillet.Add(15.0, 3.0, edge, face) |
| 192 | |
| 193 | myAxes2 = gp_Ax2(p, gp_Dir(0,-1,0)) |
| 194 | myPrim2 = BRepPrimAPI_MakeCylinder(myAxes1, R-5, L) |
| 195 | myShp1 = BRepAlgoAPI_Cut(mkFillet.Shape(),myPrim2.Shape()) |
| 196 | |
| 197 | mySphere = BRepPrimAPI_MakeSphere(p, R) |
| 198 | |
| 199 | rotateAxis = gp_Ax1(p, gp_Dir(0.0,0.0,1.0)) #Os rotacije |
| 200 | transfRot1 = gp_Trsf() |
| 201 | transfRot1.SetRotation(rotateAxis, radians(90.0)) |
| 202 | myShp2 = BRepBuilderAPI_Transform(myShp1.Shape(), transfRot1) |
| 203 | myShp3 = BRepAlgoAPI_Fuse(myShp1.Shape(),myShp2.Shape()) |
| 204 | myShp4 = BRepAlgoAPI_Fuse(myShp3.Shape(), mySphere.Shape()) |
| 205 | stl_writer = StlAPI() |
| 206 | stl_writer.Write(myShp4.Shape(), "elbow.stl", False) |
| 207 | |
| 208 | display, start_display, add_menu, add_function_to_menu = init_display() |
| 209 | material = Graphic3d_MaterialAspect(Graphic3d_NOM_SILVER) |
| 210 | display.DisplayShape(myShp4.Shape(), material) |
| 211 | start_display() |
| 212 | }}} |
| 235 | }}} |
| 236 | |
| 237 | {{{ |
| 238 | #!html |
| 239 | <script src="/vaje/raw-attachment/wiki/PythonOcc/elbow/jsc3d.min.js"></script> |
| 240 | <script type="text/javascript"> |
| 241 | function onLoad(){ |
| 242 | var canvas = document.getElementById('cv'); |
| 243 | var viewer = new JSC3D.Viewer(canvas); |
| 244 | viewer.setParameter('SceneUrl', '/vaje/raw-attachment/wiki/PythonOcc/elbow/elbow.stl'); |
| 245 | viewer.init(); |
| 246 | viewer.update(); |
| 247 | } |
| 248 | window.onload = window.onresize = function() {onLoad();} |
| 249 | </script> |
| 250 | <canvas id="cv" width="600" height="400" |
| 251 | style="background:lightgrey; border: 1px solid; float:right;" ></canvas> |
| 252 | }}} |
| 253 | Osnovno kodo lahko še dodatno opremimo z lastnostmi, ki so podrobneje opisane v |
| 254 | [http://code.google.com/p/jsc3d/wiki/GettingStarted osnovnem primeru] jsc3d. |