Three.js torus shader example

# python code for exporting a shape to three.js
from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus

# create torus
torus_shp = BRepPrimAPI_MakeTorus(25., 15.).Shape()
# load shaders
vs = open('shaders/pink.vs', 'r').read()
fs = open('shaders/pink.fs', 'r').read()
u = open('shaders/pink.uniforms', 'r').read()
my_renderer = threejs_renderer.ThreejsRenderer(vertex_shader=vs, fragment_shader=fs, uniforms = u)
my_renderer.DisplayShape(torus_shp)

Check the output


x3dom cylinder head example

from OCC.Display.WebGl import x3dom_renderer
from OCC.BRep import BRep_Builder
from OCC.TopoDS import TopoDS_Shape
from OCC.BRepTools import breptools_Read
# loads brep shape
cylinder_head = TopoDS_Shape()
builder = BRep_Builder()
breptools_Read(cylinder_head, './models/cylinder_head.brep', builder)
# render cylinder head in x3dom
my_renderer = x3dom_renderer.X3DomRenderer()
my_renderer.DisplayShape(cylinder_head)

Check the output

x3dom cylinder block example - generated from a STEP model

from OCC.STEPControl import STEPControl_Reader
from OCC.Display.WebGl import x3dom_renderer
step_reader = STEPControl_Reader()
step_reader.ReadFile('cylinder_block.stp')
step_reader.TransferRoot()
block_cylinder_shape = step_reader.Shape()
# render cylinder head in x3dom
my_renderer = x3dom_renderer.X3DomRenderer()
my_renderer.DisplayShape(block_cylinder_shape)

Check the output