Sat, 07/08/2017 - 12:34
Forums:
Hi. For example, i have TopoDS_Shape and i have my own 3D engine on OpenGL. I need pure faces data, to put it into the VertexBuffer on GPU and draw it via OpenGl. (i don't use cascade viewer) I need:
1. Triangles collection of 3D model
2. 3 vertices data per each triangle (each triangle have 3 points :-) ) in absolute world coords
3. Normal vector to face for each vertex
4. good, if i will have UVs coords too :-)
So, guys, how to get pure vertices data?
Sat, 07/08/2017 - 14:23
I solved my problem myself, as always :-) I know that many newcomers will have similar questions, therefore I insert here the complete code:
And about boutle generation functions (from tuturial):
Just for a testig, i hardcoded this in PRO file (Qt project):
OpenCASCADE was builded by mysalf via VisualStudio 2017
Sat, 07/08/2017 - 14:44
I have made an online application(specially for newcomers :)) here you can see lot of code snippets, edit , and run it from the browser:
Have a look at:
MakeMesh
MakeBottle
Hope you enjoy it?
Guido
Sat, 07/08/2017 - 15:04
Hmm, good, but my 3D engine looks better :-)
You can watch some videos about my Mirage Engine there https://www.youtube.com/watch?v=fvaRIc73Oi8 or there https://www.youtube.com/watch?v=hwuvALgRNec or there :-) https://www.youtube.com/watch?v=SNE1uOfCTMY
But now I'm doing CAD system and I would like to adapt Open CASCADE to it. There's another problem, how do you get smoothed normals for each triangle vertex? If you calculate them yourself, you get a flat shading...
Sat, 07/08/2017 - 15:05
Hmm, good, but my 3D engine looks better :-)
You can watch some videos about my Mirage Engine there https://www.youtube.com/watch?v=fvaRIc73Oi8 or there https://www.youtube.com/watch?v=hwuvALgRNec or there :-) https://www.youtube.com/watch?v=SNE1uOfCTMY
But now I'm doing CAD system and I would like to adapt Open CASCADE to it. There's another problem, how do you get smoothed normals for each triangle vertex? If you calculate them yourself, you get a flat shading...
Sat, 07/08/2017 - 15:18
Hi Malcolm,
Thank you for your complete code
I was wondering should UV points also not be reversed? ( if if(faceOrientation == TopAbs_Orientation::TopAbs_FORWARD))
It may be easier to swap the indices n1 and n3 ?
Best regards,
Guido
Sat, 07/08/2017 - 15:44
hehe i don't know, I copied the code for the texture coordinates from one example, so far I have not even tested it :-)
I'm now interested in another problem at now (I'll figure out the textures later), how do I get smoothed normals for each vertex of the triangle? If you calculate the normal for the entire triangle and substitute it for each of the three points of the triangle, It looks very bad...
Здесь русские есть? :-D
Sat, 07/08/2017 - 15:49
Есть!
Sat, 07/08/2017 - 15:57
If you want smoothed normals (which contradicts to your first post) - why you don't use StdPrs_ShadedShape tool (or its source code if you really want using std::vector<QVector3D> instead of OCCT graphic arrays used by OpenGL viewer)?
Sat, 07/08/2017 - 15:56
You have to combine all the normals of the triangles sharing a vertex.
Thus for each vertex get the "parent" triangles, and combine the normals.
I don't know if you use plain OpenGL?
Sat, 07/08/2017 - 16:03
Yes, i use native OpenGL rendering. Hmm... Do you understand what I am talking about? For smoothed shading, I need smoothed normals in order to correctly calculate PBR lighting ... I have enough 3 normals for each vertex of triangle, all other normals will be interpolated in an fragment shader..
По поводу русских, это очень хорошо, что вы здесь есть, надо бы создать ветку для русских и общаться на нормальном языке :-) Не, ну согласитесь, на русском языке мы сможем намного быстрее друг друга понять :-)
Sat, 07/08/2017 - 16:22
Русский -- это хорошо, но идея англоязычного общения состоит в том, что накапливается база знаний по каскейду, доступная всему миру. Подумайте о страждущих в Бразилии, Венесуэле и Иране. Они тоже хотят знать, как сглаживаются нормали! На русском, кстати, есть отличный форум http://cccp3d.ru/ Там можно отрастить веточку.
Sat, 07/08/2017 - 16:28
Согласен -)
Sat, 07/08/2017 - 16:00
No Rusian here, only Google translate :-)
Sat, 07/08/2017 - 16:05
So... guys, how to get smothed normals for each vertex of triangle?
Sat, 07/08/2017 - 16:30
You need to combine the normal of each triangle sharing the vertex.
See:http://www.opengl-tutorial.org/beginners-tutorials/tutorial-8-basic-shad...
So you need a normal for each vertex, then OpenGL can smooth them with shader.
Sat, 07/08/2017 - 16:36
I know it :-) But for this, i need to get different directions of normals for each vertex (smoothed normals), at now, i calc only one normal for my triangle trough cross product of (p2-1, p3-p1). 3DS max, when export normals, he exporting smoothed normals on OBJ files, but how i can to enable this in OCC?
Sat, 07/08/2017 - 17:00
You get best results if you split the mesh by faces. Then sharp edges remain sharp if you combine the normals.
Sat, 07/08/2017 - 16:46
you can have only one normal attribute per vertex in OpenGL
Use the normals you have calculate for each triangle.
3DS max is doing the same when exporting
Sat, 07/08/2017 - 17:21
guys, for smoothed normals, i need adjacent triangles date to calc mind normals. I can calc it by mysalf in geom shader, but maybe CCT do it?
Sat, 07/08/2017 - 18:36
I have modified your example so you have the smoothed normals for each vertex.
Sat, 07/08/2017 - 18:58
The problem with the code above is that you put same points multiple times in the std::vector.
You should really make a mesh per face,map same vertices, and not one mesh for the shape.
Sat, 07/08/2017 - 18:45
Guido, your code is wrong.
Do you understand, that we need adjacency triangles, to cacl smoothed normals?
Sat, 07/08/2017 - 19:21
Malcolm, I have done smoothing : MakeBottle
Sat, 07/08/2017 - 20:25
Another option would be, if you don't want to map vertices to triangles, to use GeomAPI_ProjectPointOnSurf to project point on the surface and get the normal?
Thu, 08/03/2017 - 21:57
So guys...any new ideas, how to take smoothed normals of the shape?