import os
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer
from OCC.Extend.DataExchange import read_step_file, export_shape_to_svg
from OCC.Display.WebGl.x3dom_renderer import X3DExporter
shp = read_step_file(os.path.join('..','assets', 'step', 'VentilatorAP203.step'))
x3dexp = X3DExporter(shp, None, None, True, (1,1,0), (0,0,0), 0, 0, (0,0,0), 2, 1)
x3dexp.compute()
len(x3dexp._triangle_sets)
1
x3dtriangles=x3dexp.to_x3dfile_string(0)
from OCC.Core.VrmlAPI import VrmlAPI_Writer
myWriter = VrmlAPI_Writer()
myWriter.Write(shp,'Vent.wrl')
True
from subprocess import *
run(['chmod', 'a+x', '../bin/tovrmlx3d'])
CompletedProcess(args=['chmod', 'a+x', '../bin/tovrmlx3d'], returncode=0)
x3difs=run(['../bin/tovrmlx3d','--encoding','xml','Vent.wrl'], stdout=PIPE)
x3domHTML = '''<script type='text/javascript' src='https://www.x3dom.org/download/dev/x3dom-full.debug.js'> </script>
<link rel='stylesheet' type='text/css' href='https://www.x3dom.org/download/dev/x3dom.css'></link>'''
import xml.etree.ElementTree as ET
from IPython.display import HTML
x3domXML = ET.tostring(ET.XML(x3difs.stdout), encoding="unicode", short_empty_elements=False)
HTML(x3domHTML + x3domXML)
x3domX3Dtriangles = ET.tostring(ET.XML(x3dtriangles), encoding="unicode", short_empty_elements=False)
HTML(x3domHTML + x3domX3Dtriangles)
my_renderer = JupyterRenderer()
my_renderer.DisplayShape(shp, render_edges=True, topo_level="Face", shape_color="#abdda4", update=True)
HBox(children=(VBox(children=(HBox(children=(Checkbox(value=True, description='Axes', layout=Layout(height='au…
import x3d.x3d as x
x3d.py package loaded, have fun with X3D Graphics!
vp=x.Viewpoint(position=(-4.36117,-66.43609,65.70160),orientation=(0.99385,-0.09560,0.05589,0.74120),
centerOfRotation=(0.00000,0.00000,0.00000),description="main view")
stepInline=x.Inline( url = [ "data:," + x3domX3Dtriangles ] )
"data:," + x3domX3Dtriangles
stepInline.toXML()