Does anybody know where to find python source code for Mesh Data functions, such as calc_normals_split and calc_tessface()? I’m trying to figure out what they do exactly and how they work. I’ve been struggling to find any information online, especially on calc_tessface() function. The docs just describe these in a couple of words.
They are written in C. Here’s a place to start:
You can find other internal references by using the
Pattern Search in the repository.
Thanks, appreciate it!
I tried going through the code, but unfortunately it didn’t help me much in understanding this functions. Do you know what
calc_tessface is used for?
I don’t read much C source, but from what I already know, Opengl can only draw convex polys, which means that concave polys have to be internally partitioned. This is done by a tesselation algorithm which looks for quads within the mesh loops and breaks them down if the mesh loops are outside a given threshold.
Usually we don’t ever need to think about tesselation in Blender. This is not the same as doing tesselation in 3ds max, which is a triangulation on a mesh level. The calc_tessface is internal triangulation only for the purpose of drawing the mesh - it doesn’t triangulate the actual mesh.
Great explanation, thanks! So it’s something used internally, but for some reason I’ve seen it in different export scripts. Would there be any reason/need to call this function when exporting a model?
I hope you don’t mind if I also ask you about the
calc_normals function. I haven’t been able to get clarification on this for some time.
If I want to extract normals, I would go through each loop like this:
for loop in mesh.loops: normal = loop.normal
Now why do we need to “calculate normals” in this case, why are they not automatically calculated? I don’t need to do anything when accessing them through
MeshVertex, why in this case then?
The other thing is I don’t understand when you’re supposed to use
calc_normals and when
calc_normals_split. When accessing normals through mesh loops, calling
calc_normals doesn’t seem to do anything. Normals only get calculated with
That’s a good question. I haven’t had the pleasure of working with exporters so I don’t know why they did it like that. Maybe because they were made back in a time when Blender didn’t fully support ngons.
There’s some interesting read here:
Thanks, I’ll give it a look! You don’t happen to know how that normals function works, do you?
calc_normals works on the base mesh’s normals while
calc_normals_split works on split (custom) normals. I don’t know exactly where custom normals are stored, but I would presume it is on a mesh loop, since you can store 3 times more information on a loop than on a vertex.
If you want to see a difference in normal after using
calc_normals, you probably need to access the normals on the base mesh on
mesh.vertices etc. You also probably need to toggle modes to see a change in value.
Suggest you have a look at the python source in this addon and see how they are used. In essence, it ensures that the normals queried from a piece of geometry is fresh and up to date, since Blender doesn’t refresh them automatically (that would be horrible haha).
calc_normals_split is used for custom normals, but somehow it’s called in many export scripts before extracting normals from mesh loops. If you try to access normal in a loop, it’s going to be empty, unless you call this function. Which doesn’t make any sense to me, since I don’t use custom normals.