3232 <meta name='Author' content='Thomas Paviot - tpaviot@gmail.com'>
3333 <meta name='Keywords' content='WebGl,pythonOCC'>
3434 <meta charset="utf-8">
35- <link rel="stylesheet" type="text/css" href="http ://x3dom.org/release/x3dom.css" charset="utf-8" ></link>
36- <script type="text/javascript" src="http ://x3dom.org/release/x3dom-full.js"></script>
37- <script type="text/javascript" src="http ://code.jquery.com/jquery-2.1.0.min.js" ></script>
35+ <link rel="stylesheet" type="text/css" href="https ://x3dom.org/release/x3dom.css" charset="utf-8" ></link>
36+ <script type="text/javascript" src="https ://x3dom.org/release/x3dom-full.js"></script>
37+ <script type="text/javascript" src="https ://code.jquery.com/jquery-2.1.0.min.js" ></script>
3838 <style type="text/css">
3939 body {
4040 background: linear-gradient(@bg_gradient_color1@, @bg_gradient_color2@);
8888<body>
8989 <div id="x3d_scene">@X3DSCENE@</div>
9090 <div id="pythonocc_rocks">
91- <b>pythonOCC @VERSION@ <a href="htpp ://www.x3dom.org" target="_blank">x3dom</a> renderer</b><hr>
91+ <b>pythonOCC @VERSION@ <a href="https ://www.x3dom.org" target="_blank">x3dom</a> renderer</b><hr>
9292 Check our blog at
9393 <a style="font-size:14px;" href=http://www.pythonocc.org>http://www.pythonocc.org</a>
9494 </div>
105105
106106
107107def ExportEdgeToILS (edge_point_set ):
108- str_x3d_to_return = "\t <LineSet vertexCount='%i' lit='false' solid='false' pickable='false' >" % len (edge_point_set )
108+ str_x3d_to_return = "\t <LineSet vertexCount='%i'>" % len (edge_point_set )
109109 str_x3d_to_return += "<Coordinate point='"
110110 for p in edge_point_set :
111111 str_x3d_to_return += "%g %g %g " % (p [0 ], p [1 ], p [2 ])
@@ -127,19 +127,22 @@ def get_str(self):
127127
128128
129129class HTMLBody (object ):
130- def __init__ (self , x3d_shapes_dict ):
131- self ._x3d_shapes_dict = x3d_shapes_dict
130+ def __init__ (self , x3d_shapes ):
131+ """ x3d_shapes is a list that contains uid for each shape
132+ """
133+ self ._x3d_shapes = x3d_shapes
132134
133135 def get_str (self ):
134136 # get the location where pythonocc is running from
135137 body_str = BODY .replace ('@VERSION@' , OCC_VERSION )
136- x3dcontent = '\n <x3d style="width:100%;border: none" >\n <scene>\n '
137- for shp in self ._x3d_shapes_dict :
138- trans , ori = self ._x3d_shapes_dict [shp ]
139- vx , vy , vz = trans
140- ori_vx , ori_vy , ori_vz , angle = ori
141- x3dcontent += '\t \t <inline mapDEFToID="true" url="shp%s.x3d"></inline>\n ' % shp
142- x3dcontent += "</scene>\n </x3d>\n "
138+ x3dcontent = '\n \t <X3D style="width:100%;border: none" >\n \t \t <Scene>\n '
139+ for shp_uid in self ._x3d_shapes :
140+ # TODO: here is the code related to orientation/translation
141+ # trans, ori = self._x3d_shapes_dict[shp]
142+ # vx, vy, vz = trans
143+ # ori_vx, ori_vy, ori_vz, angle = ori
144+ x3dcontent += '\t \t \t <Inline mapDEFToID="true" url="shp%s.x3d"></Inline>\n ' % shp_uid
145+ x3dcontent += "\t \t </Scene>\n \t </X3D>\n "
143146 body_str = body_str .replace ('@X3DSCENE@' , x3dcontent )
144147 return body_str
145148
@@ -171,14 +174,14 @@ def __init__(self,
171174 # the list of indexed face sets that compose the shape
172175 # if ever the map_faces_to_mesh option is enabled, this list
173176 # maybe composed of dozains of IndexedFaceSet
174- self ._indexed_face_sets = []
175- self ._indexed_line_sets = []
177+ self ._triangle_sets = []
178+ self ._line_sets = []
176179
177180 def compute (self ):
178181 shape_tesselator = Tesselator (self ._shape )
179182 shape_tesselator .Compute (compute_edges = self ._export_edges ,
180- mesh_quality = self ._mesh_quality )
181- self ._indexed_face_sets .append (shape_tesselator .ExportShapeToX3DIndexedFaceSet ())
183+ mesh_quality = self ._mesh_quality )
184+ self ._triangle_sets .append (shape_tesselator .ExportShapeToX3DIndexedFaceSet ())
182185 # then process edges
183186 if self ._export_edges :
184187 # get number of edges
@@ -189,20 +192,25 @@ def compute(self):
189192 for i_vert in range (nbr_vertices ):
190193 edge_point_set .append (shape_tesselator .GetEdgeVertex (i_edge , i_vert ))
191194 ils = ExportEdgeToILS (edge_point_set )
192- self ._indexed_line_sets .append (ils )
195+ self ._line_sets .append (ils )
193196
194197 def write_to_file (self , filename ):
195198 # write header
196199 f = open (filename , "w" )
197200 f .write ("""<?xml version="1.0" encoding="UTF-8"?>
198- <X3D style="width:100%;border: none" profile="Immersive" version="3.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.2.xsd">
201+ <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "http://www.web3d.org/specifications/x3d-3.3.dtd">
202+ <X3D profile="Immersive" version="3.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.3.xsd">
199203<head>
200- <meta name="generator" content="pythonOCC X3D exporter (www.pythonocc.org)"/>
204+ <meta name="generator" content="pythonocc-%s X3D exporter (www.pythonocc.org)"/>
205+ <meta name="title" content="%s"/>
206+ <meta name="creator" content="pythonocc-%s generator"/>
207+ <meta name="identifier" content="http://www.pythonocc.org"/>
208+ <meta name="description" content="pythonocc-%s x3dom based shape rendering"/>
201209</head>
202210<Scene>
203- """ )
211+ """ % ( OCC_VERSION , os . path . basename ( filename ), OCC_VERSION , OCC_VERSION ) )
204212 shape_id = 0
205- for indexed_face_set in self ._indexed_face_sets :
213+ for triangle_set in self ._triangle_sets :
206214 f .write ('<Shape DEF="shape%i"><Appearance>\n ' % shape_id )
207215 #
208216 # set Material or shader
@@ -229,16 +237,24 @@ def write_to_file(self, filename):
229237 f .write ('</ShaderPart></ComposedShader>\n ' )
230238 f .write ('</Appearance>\n ' )
231239 # export triangles
232- f .write (indexed_face_set )
240+ f .write (triangle_set )
233241 f .write ("</Shape>\n " )
234242 shape_id += 1
235243 # and now, process edges
236244 edge_id = 0
237- for indexed_line_set in self ._indexed_line_sets :
238- f .write ('<Shape DEF="edg%i">' % edge_id )
239- f .write (indexed_line_set )
240- f .write ("</Shape>\n " )
245+ # below '0' means show all
246+ # -1 means doesn' show line
247+ # the "Switch" node selects the group to be displayed
248+ f .write ("<Switch whichChoice='0'>\n " )
249+ f .write ("\t <Group>\n " )
250+ for line_set in self ._line_sets :
251+ f .write ('\t \t <Shape DEF="edg%i">\n ' % edge_id )
252+ f .write ('\t \t \t <Appearance><Material emissiveColor="0 0 0"/></Appearance>\n \t \t ' ) # empty appearance, but the x3d validator complains if nothing set
253+ f .write (line_set )
254+ f .write ("\t \t </Shape>\n " )
241255 edge_id += 1
256+ f .write ("\t </Group>\n " )
257+ f .write ("</Switch>\n " )
242258 f .write ('</Scene>\n </X3D>\n ' )
243259 f .close ()
244260
@@ -250,7 +266,7 @@ def __init__(self, path=None):
250266 else :
251267 self ._path = path
252268 self ._html_filename = os .path .join (self ._path , 'index.html' )
253- self ._x3d_shapes = {}
269+ self ._x3d_shapes = []
254270 print ("X3DomRenderer initiliazed. Waiting for shapes to be added to the buffer." )
255271
256272 def DisplayShape (self ,
@@ -276,13 +292,15 @@ def DisplayShape(self,
276292 x3d_filename = os .path .join (self ._path , "shp%s.x3d" % shape_hash )
277293 # the x3d filename is computed from the shape hash
278294 x3d_exporter .write_to_file (x3d_filename )
295+ ## TODO : orientation and translation
279296 # get shape translation and orientation
280- trans = shape .Location ().Transformation ().TranslationPart ().Coord () # vector
281- v = gp_Vec ()
282- angle = shape .Location ().Transformation ().GetRotation ().GetVectorAndAngle (v )
283- ori = (v .X (), v .Y (), v .Z (), angle ) # angles
297+ # trans = shape.Location().Transformation().TranslationPart().Coord() # vector
298+ # v = gp_Vec()
299+ # angle = shape.Location().Transformation().GetRotation().GetVectorAndAngle(v)
300+ # ori = (v.X(), v.Y(), v.Z(), angle) # angles
284301 # fill the shape dictionnary with shape hash, translation and orientation
285- self ._x3d_shapes [shape_hash ] = [trans , ori ]
302+ # self._x3d_shapes[shape_hash] = [trans, ori]
303+ self ._x3d_shapes .append (shape_hash )
286304
287305 def render (self , server_port = 8080 ):
288306 """ Call the render() method to display the X3D scene.
0 commit comments