Changes between Version 18 and Version 19 of PythonOcc/elbow


Ignore:
Timestamp:
Dec 2, 2013, 3:52:07 PM (10 years ago)
Author:
Leon Kos
Comment:

Primer kode in navodila

Legend:

Unmodified
Added
Removed
Modified
  • PythonOcc/elbow

    v18 v19  
    152152stl_writer.Write(myShp4.Shape(), "elbow.stl", False)
    153153}}}
    154 
     154Celoten program za izdelavo modela je naslednji:
     155{{{
     156#!python
     157from OCC.gp import *
     158from OCC.BRepPrimAPI import *
     159from OCC.TopExp import *
     160from OCC.TopAbs import *
     161from OCC.BRep import *
     162from OCC.Geom import *
     163from OCC.GCE2d import *
     164from OCC.GC import *
     165from OCC.Geom2d import *
     166from OCC.BRepLib import *
     167from OCC.BRepFeat import *
     168from OCC.Utils.Topology import Topo
     169from OCC.BRepBuilderAPI import *
     170from OCC.BRepAlgoAPI import *
     171from OCC.BRepFilletAPI import *
     172from OCC.TopoDS import *
     173from OCC.StlAPI import *
     174from math import radians
     175
     176from OCC.Display.SimpleGui import *
     177from OCC.Graphic3d import *
     178
     179R = 20
     180L = 150
     181p = gp_Pnt(0.,0.,0)
     182d = gp_Dir(1. ,0., 0.)
     183myAxes1 = gp_Ax2(p,d)
     184myPrim1 = BRepPrimAPI_MakeCylinder(myAxes1, R, 100)
     185
     186mkFillet = BRepFilletAPI_MakeChamfer(myPrim1.Shape())
     187ex = TopExp_Explorer(myPrim1.Shape(), TopAbs_EDGE)
     188ex2 = TopExp_Explorer(myPrim1.Shape(), TopAbs_FACE)
     189edge = TopoDS_edge(ex.Current())
     190face = TopoDS_face(ex2.Current())
     191mkFillet.Add(15.0, 3.0, edge, face)
     192
     193myAxes2 = gp_Ax2(p, gp_Dir(0,-1,0))
     194myPrim2 = BRepPrimAPI_MakeCylinder(myAxes1, R-5, L)
     195myShp1 = BRepAlgoAPI_Cut(mkFillet.Shape(),myPrim2.Shape())
     196
     197mySphere =  BRepPrimAPI_MakeSphere(p, R)
     198
     199rotateAxis = gp_Ax1(p, gp_Dir(0.0,0.0,1.0)) #Os rotacije
     200transfRot1 = gp_Trsf()
     201transfRot1.SetRotation(rotateAxis, radians(90.0))
     202myShp2 = BRepBuilderAPI_Transform(myShp1.Shape(), transfRot1)
     203myShp3 = BRepAlgoAPI_Fuse(myShp1.Shape(),myShp2.Shape())
     204myShp4 = BRepAlgoAPI_Fuse(myShp3.Shape(), mySphere.Shape())
     205stl_writer = StlAPI()
     206stl_writer.Write(myShp4.Shape(), "elbow.stl", False)
     207
     208display, start_display, add_menu, add_function_to_menu = init_display()
     209material = Graphic3d_MaterialAspect(Graphic3d_NOM_SILVER)
     210display.DisplayShape(myShp4.Shape(), material)
     211start_display()
     212}}}
    155213== Prikaz modela na spletni strani s knjižnico jsc3d ==
     214Za prikaz modela na spletni strani Trac moramo pripeti model elbow.js
     215tej strani in pripeti še skrčeno knjižnico [http://code.google.com/p/jsc3d/ JSC3D] in natipkati
     216naslednjo kodo, ki je mešanica HTML5 in [http://www.lecad.si/~demsar/vaje/OPK/ucni_program-javascript.pdf JavaScripta].
     217{{{
     218#!javascript
    156219{{{
    157220#!html
     
    170233  style="background:lightgrey; border: 1px solid; float:right;" ></canvas>
    171234}}}
     235}}}
     236
     237{{{
     238#!html
     239<script src="/vaje/raw-attachment/wiki/PythonOcc/elbow/jsc3d.min.js"></script>
     240<script type="text/javascript">
     241function 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}     
     248window.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}}}
     253Osnovno kodo lahko še dodatno opremimo z lastnostmi, ki so podrobneje opisane v
     254[http://code.google.com/p/jsc3d/wiki/GettingStarted osnovnem primeru] jsc3d.