WebGL export

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
yorik
Founder
Posts: 13664
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: WebGL export

Post by yorik »

I think this is okay, but I'm not sure it won't break other parts of freecad that depend on it, I'll wait for Werner or someone else more knowledgeable than me to have a look at your change...
User avatar
rockn
Veteran
Posts: 1791
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: WebGL export

Post by rockn »

Okay, I think I understand. So please can we remove or add an option for discretization or not ?
I can't make webgl page anymore since my little building (25 objects) make too big file ( > 350 Mo).
Formations - Assistance - Développement : https://freecad-france.com
User avatar
yorik
Founder
Posts: 13664
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: WebGL export

Post by yorik »

Yeah that's probably the best to do... I'll add an option
User avatar
yorik
Founder
Posts: 13664
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: WebGL export

Post by yorik »

jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: WebGL export

Post by jreinhardt »

yorik wrote:I think this is okay, but I'm not sure it won't break other parts of freecad that depend on it, I'll wait for Werner or someone else more knowledgeable than me to have a look at your change...
I think that is a good idea. I noticed, that one should probably also change the behaviour of discretize for Edges and Curves for consistency. It is also used a few times in the Draft workbench, I did not find more occurences.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
danielfalck
Posts: 395
Joined: Fri Oct 07, 2011 8:58 pm
Location: Beaverton,Oregon, USA
Contact:

Re: WebGL export

Post by danielfalck »

Could you make your modifications to discretize be the 3rd option? I have used the float value for breaking up circles into line segments of a constant length and it's handy to have that option. I wouldn't want to loose it.
In the change to Shape2DView , in Draft workbench, that I did recently, I did it the hard way and used the length of the curve and divided by the integer value.
LambdaTheUltimate
Posts: 2
Joined: Fri Dec 20, 2013 11:04 pm

Re: WebGL export / three.js / normals / Phong / computeFaceN

Post by LambdaTheUltimate »

Using Windows FreeCAD 0.14 3389, mesh normals don't appear in the WebGL exported file; so models appear in the browser as poorly lit flat silhouettes.

To add normals I used;

geom.computeFaceNormals();

to use a material that uses normals;

basematerial = new THREE.MeshPhongMaterial({ color: 'blue' });

to light the material well from 2 directions (instead of the standard single cutdown candle);

var d1 = new THREE.DirectionalLight(0xffffff); d1.position.set(1,1,1).normalize(); scene.add(d1);
var d2 = new THREE.DirectionalLight(0xffffff); d2.position.set(-1,-1,-1).normalize(); scene.add(d2);

But, for some reason, it only works when the standard three.js scripts are included;

three.min.js
TrackballControls.js

not the scripts that FreeCAD 0.14 3389 includes from;

http://cdnjs.cloudflare.com/ajax/libs/t ... ree.min.js
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: WebGL export

Post by jreinhardt »

I tried Lambdas suggestion with the Phong shading and I like it much better. It is much clearer and makes the wireframe unnecessary for my use case. And for me it also works with the version of three.js that is currently used.

Here is a branch that exposes this as an option:

https://github.com/jreinhardt/FreeCAD_s ... ree/webgl2

Code: Select all

import importWebGL
importWebGL.shading = "phong"
gives you phong shading. I also changed the color of the default light source to white, as the green was quite ugly. I did no other changes to the light sources, which results in very one-sided lighting for the default template. If desired it is easy to change, but I did not want to break anything for anybody relying on the current default behaviour.

@danielfalck and regarding the discretization change: Without the corresponding change in the underlying discretize behaviour this change is useless, as it will produce bloated results or bad discretizations most of the time.

I see multiple possibilities:
  • Leave discretize as it is, adjust its docstring and remove my discretize change for WebGL. This keeps compatibility, but rounded edges are not handled well in WebGL.
  • Change discretize, leave docstring as it is. This breaks compatibility for those who relied on the current behaviour of discretize, rounded edges are fine in WebGL. Getting uniform discretizations of curves can still be done manually rather easily:

    Code: Select all

    [curve.value(u) for u in np.linspace(curve.FirstParameter,curve.Lastparameter,n_points)]
    or (without dependency on numpy)

    Code: Select all

    du = (curve.LastParameter-curve.FirstParameter)/(n_points-1)
    points = []
    for i in range(n_points):
      points.append(curve.value(curve.LastParameter+i*du))
    
    while doing discretizations with uniform deflection is much more difficult.
  • Change discretize to do both things, e.g. discretize(int or float,bool=false), where discretize(int) and discretize(float) give the current behaviour, and discretize(float,true) discretizes with constant deflection. This keeps compatibility and allows to handle rounded edges in WebGL, but is not really nice, as the bool parameter only applies to calls where the first parameter is a float.
I am fine with all possibilities, with a preference for the second one, as it results in the cleanest API. I can try to do the implementation, if there is a consensus about what to do, and if somebody reviews my code.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: WebGL export

Post by jreinhardt »

Any opinions about a Phong shading option or how to handle the discretise issue?
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
User avatar
yorik
Founder
Posts: 13664
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: WebGL export

Post by yorik »

Ah sorry, I forgot to look at it...
Just tested now the phong shading, but it doesn't seem to make a difference for me?

About the change to the discretize API, I also think we can chage it, but it now looks like we're going to spit version 0.14 out soonish, so it's probably safer to wait after it, then do the change and see what happens.
Post Reply