TopoDS_Shape serialization

730 views
Skip to first unread message

eric sherouse

unread,
Nov 17, 2014, 8:18:41 PM11/17/14
to oce...@googlegroups.com
All,

I am trying to serialize a TopoDS_Shape object into an ArrayBuffer to be de-serialized and rendered by javascript. It is my understanding that a TopoDS_Shape object is a tessellation that can be easily rendered using WebGL (I am using three.js for this). I have two questions:

1) Is my understanding correct?
2) Does oce provide such a serialization interface (into a "WebGL-renderable" object), or do I need to build this? I see some references to serialization in oce's OpenGl source, but these only seem to deal with material and light sources.

I would appreciate any insight at all.

Thank you,
Eric

István Csanády

unread,
Nov 18, 2014, 4:36:34 AM11/18/14
to oce...@googlegroups.com
1.) Nope. TopoDS_Shape is a topological representation of a 3D object.

2.) To create OpenGL buffers from it, you will have to tessellate it.

BRepMesh_FastDiscret(shape, deflection, angularDeflection, box);

Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(shape, loc);


From the triangulation, you can easily create index, vertex, and normal buffers.




--
You received this message because you are subscribed to the Google Groups "oce-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to oce-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

eric sherouse

unread,
Nov 18, 2014, 8:04:22 AM11/18/14
to oce...@googlegroups.com
István,
Thank you for your reply. I will try this this evening.

On a somewhat related note, aside from reading the source code, examples, oce-dev mailing list, and occt documentation, are there any good resources for learning oce? Perhaps a recommended book on modeling and CAD applications in general?

Thank you,
Eric

István Csanády

unread,
Nov 18, 2014, 8:15:47 AM11/18/14
to oce...@googlegroups.com
Roman's blog is a good point to start: http://opencascade.blogspot.hu
And reading the forum on opencascade.org can be very helpful sometimes. Also reading OCCT test cases can be helpful as well. But unfortunately OCCT has a very very long learning curve.


Thank you,
Eric

Thomas Paviot

unread,
Nov 19, 2014, 12:57:48 AM11/19/14
to oce...@googlegroups.com, pyth...@googlegroups.com
Hi Eric,

A TopoDS_Shape is a BRep representation. The usual serialization (in the sense it can be reverted) of a TopoDS_Shape is performed using, for instance, the BRepTools class. The builtin tesselation algorithm enables to export a TopoDS_Shape to the STL file format, for instance.

I've been stuying the webgl export for a couple of years. In the latest pythonocc release (see https://github.com/tpaviot/pythonocc-core/releases/tag/0.16.0), I achieved the export/rendering for both three.js and x3dom. I uploaded two examples to http://webgl.pythonocc.org: one using three.js (a torus, rendered with a shader available from the three.js page), and the other using x3dom (the export of the well known occt cylinder_head example - check http://www.opencascade.org/showroom/shapegallery/gal4/). Go to the pythonocc-core examples directory to check how to use the Tesselator class. To generate a three.js visualization, it's quite simple :

from OCC.Display.WebGl import threejs_renderer
from OCC.BRepPrimAPI import BRepPrimAPI_MakeTorus
torus_shp = BRepPrimAPI_MakeTorus(20., 10.).Shape() # or whatever TopoDS_Shape here
my_renderer = threejs_renderer.ThreejsRenderer()
my_renderer.DisplayShape(torus_shp)

You run the code, the html page will be rendered in your default web browser.

The source code for both the three.js and x3dom export is in the Tesselator.cpp file (https://github.com/tpaviot/pythonocc-core/blob/master/src/Visualization/Tesselator.cpp).

Hope this help,

Thomas

eric sherouse

unread,
Nov 22, 2014, 6:35:41 PM11/22/14
to oce...@googlegroups.com, pyth...@googlegroups.com
Thomas,

This was extremely helpful. Thank you very much. I reviewed Tesselator.cpp and actually found that I was pulling vertices, normals, etc from the shape as you are, so that is reassuring. I am not serializing in the same way that you are (writing directly to javascript), just because of my implementation. I am going to try a few more prebuilt examples (the bottle and cylinder head) and then start exploring how to manipulate these things.

Thank you again,
Eric
Reply all
Reply to author
Forward
0 new messages