#!/usr/bin/env python
# coding: utf-8
# In[1]:
import os
from OCC.Core.gp import gp_Dir
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
# In[2]:
shp = read_step_file(os.path.join('..','assets', 'step', 'VentilatorAP203.step'))
# In[3]:
x3dexp = X3DExporter(shp, None, None, True, (1,1,0), (0,0,0), 0, 0, (0,0,0), 2, 1)
# In[4]:
x3dexp.compute()
# In[5]:
len(x3dexp._triangle_sets)
# In[7]:
x3dtriangles=x3dexp.to_x3dfile_string(0)
# In[8]:
from OCC.Core.VrmlAPI import VrmlAPI_Writer
# In[9]:
myWriter = VrmlAPI_Writer()
# In[10]:
myWriter.Write(shp,'Vent.wrl')
# In[11]:
from subprocess import *
# In[14]:
run(['chmod', 'a+x', '../bin/tovrmlx3d'])
# In[16]:
x3difs=run(['../bin/tovrmlx3d','--encoding','xml','Vent.wrl'], stdout=PIPE)
# In[17]:
x3domHTML = '''
'''
# In[18]:
import xml.etree.ElementTree as ET
# In[19]:
from IPython.display import HTML
# In[46]:
x3domXML = ET.tostring(ET.XML(x3difs.stdout), encoding="unicode", short_empty_elements=False)
# ## x3dom with VrmlAPI generated X3D
# In[47]:
HTML(x3domHTML + x3domXML)
# In[22]:
x3domX3Dtriangles = ET.tostring(ET.XML(x3dtriangles), encoding="unicode", short_empty_elements=False)
# ## x3dom with pythonocc generated X3D (triangles)
# In[79]:
HTML(x3domHTML + x3domX3Dtriangles)
# ## Threejs baseed Jupyter renderer
# In[78]:
my_renderer = JupyterRenderer()
# In[80]:
my_renderer.DisplayShape(shp, render_edges=True, topo_level="Face", shape_color="#abdda4", update=True)
# In[ ]: