oce in Browser [emscripten]

200 views
Skip to first unread message

Rui

unread,
Feb 11, 2016, 10:18:31 AM2/11/16
to oce-dev, Patrick Janssen
Dear all,

After some experiments and with the help of emscripten, a few of simple functionalities of oce are ported to javascript for testing of oce in browser.
I set up a demo github page https://github.com/chepilot/oce-emscripten includes the basic workflow and simple demo.

The porting of oce to javascript requires using webIDL as interface, right now the webIDL only contains some very simple classes in oce. It looks promising but definitely requires more webIDL writing and testing.

You can use the demo file and test code in github page to create three.js compatible geometry data directly from javascript.
Hope you find it useful.



Best Regards,
Ruize

Jake

unread,
Feb 11, 2016, 11:09:21 AM2/11/16
to oce...@googlegroups.com
Not to rain on your parade but I'm pretty sure Thomas already did this a year ago.

--
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.

Patrick Janssen

unread,
Feb 11, 2016, 9:21:00 PM2/11/16
to oce...@googlegroups.com
Hi Jake,

We are aware of Thomas's demo. But this is different. We are trying to expose the oce api to javascript, so that we can use oce as a CAD modelling kernel in the browser. In the example done by Thomas, he compiled one oce example to javascript. But that does no allow you to use the compiled code as a modelling kernel. 

As Ruize say, this is why we need to use webIDL, to expose the API. It was quite tricky to get this workflow to work. Now that we have figured it out, we are hoping that others might be interested to help cover more of the oce api (involves writing more IDL and testing). We have not yet had much experience with oce so any help or suggestions would be welcome.

The original post that led to all this

Patrick

Thomas Paviot

unread,
Feb 11, 2016, 11:21:10 PM2/11/16
to oce...@googlegroups.com
Hi Guys,

Indeed I remember playing with emscripten a couple of years ago I think. At that time, I was only able to convert a simple c++ program to javascript, to be run using node.js or a webbrowser. I did not succeed to actually port oce to js, that is to say as Patrick note, expose the API so that oce classes/methods can be accessed from javascript. At some point, it's a js wrapper over oce, quite similar to what pythonocc is for oce regarding python.  So far, I did not look at Rui's work, but it's a significant achievement and it's worth studyin this work/reviewing/reporting issues.

I can remember that the major issue I faced was the size of the generated program (dozains of megabytes only for a small program running a small coverage of the whole oce). What size is the javascript library generated ? Which oce modules did you port so far ?

Thomas

Rui

unread,
Feb 12, 2016, 2:25:22 AM2/12/16
to oce-dev
Hi Thomas,

Right now only a few classes in Model and Visualization are ported ( only webIDL for these classes are implemented) for example: 

BRepPrimAPI_MakeSphere
TopoDS_Shape
GProp_GProps
BRepGProp
BRepMesh_IncrementalMesh
...

The generated js file is quite big, around 75mb, but when generating this js file, the Model and Visualization module are already linked, we will include more functionalities and see if there will be a significant increase of the js file size.


Best,
Rui

Thomas Paviot

unread,
Feb 12, 2016, 3:27:55 AM2/12/16
to oce...@googlegroups.com
I ran a test, trying to load the demo file in my browser. It loads in about 30s in Chrome 48, my FF  44 crashes after a few seconds (test on a Win8 64 machine 8gb ram).

The generated file size was my main worrying about the port to js, that's why I gave up after a few experiments. an oce.js will have sense only if you can perform complex operations, not just creating a sphere or compute a volume. That means that you'll have to load a 500Mb js file into the browser before you can do anything, I doubt it's currently feasible on usual machines. What's your opinion about this ?
 
By the way, the demo should demo something ,currently it only loads the generated oce.js file.

Thomas


--

Ruize Li

unread,
Feb 18, 2016, 2:46:12 AM2/18/16
to oce...@googlegroups.com
Hi,

Sorry for the late reply, I just updated the demo, the live version is http://chepilot.github.io/oce-emscripten/ , it will use oce.js to build a sphere and visualise it in THREE.js.
I use a 64bit osx with 8gb ram, the loading from chrome timeline is around 20 seconds, The FF 43 on mac also crashes after a few seconds loading, will try to figure out why.

About the file size, I will includes more functionalities in the webIDL including more complex operations and see if it will bring a significant change of the .js file size. If the size increases beyond certain range, as you stated, I agree it won't be feasible for normal usage.

I noticed that the ammo.js (https://github.com/kripken/ammo.js/), a physics engine ported by emscripten, with much more webIDL for their functionalities, the size is only 1.9MB. It is just a guess, since when I generate the javascipt file, I actually linked all the binary files of oce, it could be the reason that the .js file size is so big. If it is the case, when more webIDL are added and more functionalities are ported, the size won't increase significantly. 

Hope it is the case, I will do some testing in the following days.


Ruize

Ruize Li

unread,
Feb 24, 2016, 2:07:17 AM2/24/16
to oce...@googlegroups.com
Hi,

Just included more webIDL interfaces and created simplified demo of the opencascade bottle example, operations like fuse, fillet, extrude are also included.

The demo should be something as below ( http://chepilot.github.io/oce-emscripten/):

Inline images 1


About the file size, with more webIDL interface, there is no significant increase of the .js file size, last time around 10 classes are exposed, the file size is 74.9MB and this time around 50 classes are exposed, the file size is 75MB.

On top of that, without emscripten assertion support, the .js file size decreases to 40MB. 

The bottle example is simplified because of two problems.

The first one is overloading: emscripten only differentiate constructor arguments by length, so if there are constructors with the same arguments length but different types, emscripten will fai to generate anything. For example, BRepBuilderAPI_MakeEdge (http://dev.opencascade.org/doc/refman/html/class_b_rep_builder_a_p_i___make_edge.html), which has multiple constructors with the same length, can't be properly exposed.

Another issue is the Handle in oce. I wonder if I am right about this: the handle is like a smart pointer, and in oce it is defined as 

#define Handle(ClassName)     Handle_##ClassName

Since that emscripten doesn't have macro support for webIDL, I am not really sure about how to expose it in webIDL and how to use handle in javascript.

I am quite stuck about these problems, really appreciate any advice/ correction.

Thank you very much!

Rui





Reply all
Reply to author
Forward
0 new messages