WebGL export
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: WebGL export
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...
Re: WebGL export
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).
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
Re: WebGL export
Yeah that's probably the best to do... I'll add an option
-
- Posts: 329
- Joined: Mon Sep 09, 2013 6:08 pm
Re: WebGL export
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.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...
-
- Posts: 395
- Joined: Fri Oct 07, 2011 8:58 pm
- Location: Beaverton,Oregon, USA
- Contact:
Re: WebGL export
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.
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.
-
- Posts: 2
- Joined: Fri Dec 20, 2013 11:04 pm
Re: WebGL export / three.js / normals / Phong / computeFaceN
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
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
-
- Posts: 329
- Joined: Mon Sep 09, 2013 6:08 pm
Re: WebGL export
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
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:
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"
@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:
or (without dependency on numpy)
Code: Select all
[curve.value(u) for u in np.linspace(curve.FirstParameter,curve.Lastparameter,n_points)]
while doing discretizations with uniform deflection is much more difficult.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))
- 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.
-
- Posts: 329
- Joined: Mon Sep 09, 2013 6:08 pm
Re: WebGL export
Any opinions about a Phong shading option or how to handle the discretise issue?
Re: WebGL export
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.
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.