WebGL export
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 329
- Joined: Mon Sep 09, 2013 6:08 pm
Re: WebGL export
Strange. I get different results when activating phong shading, see attachments. Did you really try the webgl2 branch? I put the phong changes to a new branch, as they are independent from the discretize stuff.
Ok, then I will bring the discretize issue up again, once 0.14 is out of the door. Should I post in this thread again or better open a thread in the pull request forum?
Ok, then I will bring the discretize issue up again, once 0.14 is out of the door. Should I post in this thread again or better open a thread in the pull request forum?
- Attachments
-
- cylinder_phong.png (6.54 KiB) Viewed 6613 times
-
- cylinder_normal.png (2.67 KiB) Viewed 6613 times
Last edited by jreinhardt on Sun May 11, 2014 9:58 pm, edited 1 time in total.
Re: WebGL export
Yes, I had the importWebGL.shading option...jreinhardt wrote:Did you really try the webgl2 branch?
As you prefer!jreinhardt wrote:Ok, then I will bring the discretize issue up again, once 0.14 is out of the door. Should I post in this thread again or better open a thread in the pull request forum?
Re: WebGL export
Hi,
I started tinkering with webgl2 branch and I had been a bit disappointed (sorry Johannes!).
A cylinder exported with "phong":
It looks like flat shading - one normal vector for face/3 vertices. Then I found:
and added:
The effect is even worse:
I'd started analysing Coin3d output, as example for a cube it looks like:
I used vertices coordinates, normals per vertex and index in my custom WebGL file, example for the above data:
Finally, I put a cylinder data in my file and... it looks pretty nice, even with Gouraud shading only (I haven't written Phong one yet):
I started tinkering with webgl2 branch and I had been a bit disappointed (sorry Johannes!).
A cylinder exported with "phong":
It looks like flat shading - one normal vector for face/3 vertices. Then I found:
Code: Select all
geom.computeFaceNormals();
Code: Select all
geom.computeVertexNormals();
I'd started analysing Coin3d output, as example for a cube it looks like:
Code: Select all
print FreeCADGui.ActiveDocument.ActiveObject.toString()
#Inventor V2.1 ascii
Separator {
Transform {
translation 0 0 0
rotation 0 0 1 0
center 0 0 0
}
Coordinate3 {
point [ 0 0 0,
0 0 10,
0 10 10,
0 10 0,
10 0 0,
10 0 10,
10 10 10,
10 10 0,
0 0 0,
10 0 0,
10 0 10,
0 0 10,
0 10 0,
10 10 0,
10 10 10,
0 10 10,
0 0 0,
0 10 0,
10 10 0,
10 0 0,
0 0 10,
0 10 10,
10 10 10,
10 0 10,
0 0 10,
0 0 0,
0 10 10,
0 10 0,
10 0 10,
10 0 0,
10 10 10,
10 10 0 ]
}
Switch {
whichChild 0
Separator {
DEF _+0 Separator {
Material {
ambientColor 0.2 0.2 0.2
diffuseColor 0.098039217 0.098039217 0.098039217
specularColor 0 0 0
emissiveColor 0 0 0
shininess 1
transparency 0
}
DrawStyle {
style LINES
lineWidth 2
linePattern 0xffff
}
SoBrepEdgeSet {
fields [ SFNode vertexProperty, MFInt32 coordIndex, MFInt32 materialIndex, MFInt32 normalIndex, MFInt32 textureCoordIndex, SFInt32 highlightIndex, MFInt32 selectionIndex ]
coordIndex [ 0, 1, -1, 1, 2, -1, 3, 2,
-1, 0, 3, -1, 4, 5, -1, 5,
6, -1, 7, 6, -1, 4, 7, -1,
8, 9, -1, 11, 10, -1, 12, 13,
-1, 15, 14, -1 ]
highlightIndex -1
selectionIndex [ ]
}
}
PolygonOffset {
}
DEF _+1 Separator {
ShapeHints {
vertexOrdering COUNTERCLOCKWISE
shapeType UNKNOWN_SHAPE_TYPE
}
MaterialBinding {
value OVERALL
}
Material {
diffuseColor 0.80000001 0.80000001 0.80000001
}
DrawStyle {
style FILLED
}
Normal {
vector [ -1 0 0,
-1 0 0,
-1 0 0,
-1 0 0,
1 0 0,
1 0 0,
1 0 0,
1 0 0,
0 -1 0,
0 -1 0,
0 -1 0,
0 -1 0,
0 1 0,
0 1 0,
0 1 0,
0 1 0,
0 0 -1,
0 0 -1,
0 0 -1,
0 0 -1,
0 0 1,
0 0 1,
0 0 1,
0 0 1 ]
}
NormalBinding {
value PER_VERTEX_INDEXED
}
SoBrepFaceSet {
fields [ SFNode vertexProperty, MFInt32 coordIndex, MFInt32 materialIndex, MFInt32 normalIndex, MFInt32 textureCoordIndex, MFInt32 partIndex, SFInt32 highlightIndex, MFInt32 selectionIndex ]
coordIndex [ 3, 1, 2, -1, 0, 1, 3, -1,
5, 7, 6, -1, 5, 4, 7, -1,
9, 10, 8, -1, 8, 10, 11, -1,
14, 13, 12, -1, 14, 12, 15, -1,
17, 18, 16, -1, 16, 18, 19, -1,
22, 21, 20, -1, 22, 20, 23, -1 ]
partIndex [ 2, 2, 2, 2, 2, 2 ]
highlightIndex -1
selectionIndex [ ]
}
}
DEF _+2 Separator {
Material {
ambientColor 0.2 0.2 0.2
diffuseColor 0.098039217 0.098039217 0.098039217
specularColor 0 0 0
emissiveColor 0 0 0
shininess 1
transparency 0
}
DrawStyle {
style POINTS
pointSize 2
}
SoBrepPointSet {
fields [ SFNode vertexProperty, SFInt32 startIndex, SFInt32 numPoints, SFInt32 highlightIndex, MFInt32 selectionIndex ]
startIndex 24
highlightIndex -1
selectionIndex [ ]
}
}
}
USE _+1
Separator {
USE _+0
USE _+2
}
USE _+2
}
}
Code: Select all
function initBuffers() {
modelVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, modelVertexPositionBuffer);
vertices = [
0.0, 0.0, 0.0, //from Coordinate3
0.0, 0.0, 10.0,
0.0, 10.0, 10.0,
0.0, 10.0, 0.0,
10.0, 0.0, 0.0,
10.0, 0.0, 10.0,
10.0, 10.0, 10.0,
10.0, 10.0, 0.0,
0.0, 0.0, 0.0,
10.0, 0.0, 0.0,
10.0, 0.0, 10.0,
0.0, 0.0, 10.0,
0.0, 10.0, 0.0,
10.0, 10.0, 0.0,
10.0, 10.0, 10.0,
0.0, 10.0, 10.0,
0.0, 0.0, 0.0,
0.0, 10.0, 0.0,
10.0, 10.0, 0.0,
10.0, 0.0, 0.0,
0.0, 0.0, 10.0,
0.0, 10.0, 10.0,
10.0, 10.0, 10.0,
10.0, 0.0, 10.0,
0.0, 0.0, 10.0,
0.0, 0.0, 0.0,
0.0, 10.0, 10.0,
0.0, 10.0, 0.0,
10.0, 0.0, 10.0,
10.0, 0.0, 0.0,
10.0, 10.0, 10.0,
10.0, 10.0, 0.0,
];
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
modelVertexPositionBuffer.itemSize = 3;
modelVertexPositionBuffer.numItems = 32;
modelVertexNormalBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, modelVertexNormalBuffer);
var vertexNormals = [
-1.0, 0.0, 0.0, //from Normals
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
];
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertexNormals), gl.STATIC_DRAW);
modelVertexNormalBuffer.itemSize = 3;
modelVertexNormalBuffer.numItems = 24;
modelVertexIndexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, modelVertexIndexBuffer);
var modelVertexIndices = [ //from coordIndex without -1
3, 1, 2, 0, 1, 3,
5, 7, 6, 5, 4, 7,
9, 10, 8, 8, 10, 11,
14, 13, 12, 14, 12, 15,
17, 18, 16, 16, 18, 19,
22, 21, 20, 22, 20, 23,
];
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(modelVertexIndices), gl.STATIC_DRAW);
modelVertexIndexBuffer.itemSize = 1;
modelVertexIndexBuffer.numItems = 36;
}
- Attachments
-
- fc-cylinder-webgl.zip
- (8.77 KiB) Downloaded 201 times
-
- Posts: 329
- Joined: Mon Sep 09, 2013 6:08 pm
Re: WebGL export
I brought up the Wireframe problem up in the developers corner:
viewtopic.php?f=10&t=7316
Werner had a very good proposal how to resolve the issue while preserving backwards compatibility, and also implemented it. Building on that I created a branch where the discretize setting is removed and the new invocations are used to create nice wireframes and small files:
https://github.com/jreinhardt/FreeCAD_s ... discretize
viewtopic.php?f=10&t=7316
Werner had a very good proposal how to resolve the issue while preserving backwards compatibility, and also implemented it. Building on that I created a branch where the discretize setting is removed and the new invocations are used to create nice wireframes and small files:
https://github.com/jreinhardt/FreeCAD_s ... discretize
Re: WebGL export
Hi,
It seem that WebGL export is broken somewhere :
I'm just trying to export a Part Box.
OS: Ubuntu 14.04.2 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.4701 (Git)
Branch: master
Hash: f6d50e6f33d71a533d18707aa3d74d0d45a5fc28
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17-dev
It seem that WebGL export is broken somewhere :
Code: Select all
Traceback (most recent call last):
File "<string>", line 4, in <module>
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Arch/importWebGL.py", line 116, in export
html = getHTML(exportList)
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Arch/importWebGL.py", line 128, in getHTML
objectsData += getObjectData(obj)
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Arch/importWebGL.py", line 174, in getObjectData
wo = Part.Wire(DraftGeomUtils.sortEdges(w.Edges))
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Draft/DraftGeomUtils.py", line 727, in sortEdges
print("DraftGeomUtils.sortEdges failed - running old version")
<type 'exceptions.AttributeError'>: 'method_descriptor' object has no attribute 'write'
Stack Trace: Traceback (most recent call last):
File "<string>", line 4, in <module>
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Arch/importWebGL.py", line 116, in export
html = getHTML(exportList)
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Arch/importWebGL.py", line 128, in getHTML
objectsData += getObjectData(obj)
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Arch/importWebGL.py", line 174, in getObjectData
wo = Part.Wire(DraftGeomUtils.sortEdges(w.Edges))
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Draft/DraftGeomUtils.py", line 727, in sortEdges
print("DraftGeomUtils.sortEdges failed - running old version")
OS: Ubuntu 14.04.2 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.4701 (Git)
Branch: master
Hash: f6d50e6f33d71a533d18707aa3d74d0d45a5fc28
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17-dev
Formations - Assistance - Développement : https://freecad-france.com
Re: WebGL export
For me it works without error...
This line:
makes me think that the file object hasn't been correctly created and therefore has no write method... What is the filepath you're trying to write to?
This line:
Code: Select all
<type 'exceptions.AttributeError'>: 'method_descriptor' object has no attribute 'write'
Re: WebGL export
Thanks to look at this.
Now the export work but I still get this error in the report view :
Nothing particular. But I get this error (no attribute write) here and here. So I investigate in my mind and I remove the last custum workbench I had (CadQuery).yorik wrote:makes me think that the file object hasn't been correctly created and therefore has no write method... What is the filepath you're trying to write to?
Now the export work but I still get this error in the report view :
Code: Select all
Traceback (most recent call last):
File "<string>", line 4, in <module>
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Arch/importWebGL.py", line 120, in export
FreeCAD.Console.PrintMessage(translate("Arch","successfully written ")+filename+"\n")
<type 'exceptions.UnicodeDecodeError'>: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)
Stack Trace: Traceback (most recent call last):
File "<string>", line 4, in <module>
File "/home/jo/Logiciels/FreeCAD/free-cad-code/masterOCE17_build/Mod/Arch/importWebGL.py", line 120, in export
FreeCAD.Console.PrintMessage(translate("Arch","successfully written ")+filename+"\n")
Formations - Assistance - Développement : https://freecad-france.com
Re: WebGL export
This is weirdrockn wrote:I remove the last custum workbench I had (CadQuery). Now the export work
The error you are getting in the console is probably because of the translation stuff... Probably someting not encoded the way the Console expects, I'll have a look at it
Re: WebGL export
Today i struggled to understand why i get this issue when using a macro that worked fine in the past:
Luckily i found this forum thread and indeed removing CadQuery module removed that error. Therefore i am guessing i will report this to cadquery-freecad-module developer. Before i do that just one question:
https://github.com/jmwright/cadquery-fr ... InitGui.py
The issue must be introduced in this file?
P.S. As if i start FreeCAD and don't switch to CadQuery WB the issue occurs.
Code: Select all
object has no attribute 'write'
https://github.com/jmwright/cadquery-fr ... InitGui.py
The issue must be introduced in this file?
P.S. As if i start FreeCAD and don't switch to CadQuery WB the issue occurs.
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: WebGL export
The cause for this error seems to be print calls in the code when the script is executed from a Qt Gui.
I had the same problem last days.
Go through the code and deactivate all prints.
I still have no idea to redirect print in such cases.
I had the same problem last days.
Go through the code and deactivate all prints.
I still have no idea to redirect print in such cases.