# Handling normals in a procedurally generated cubeworld

I’m wondering what would be the best way to handle normals in a procedurally generated cube world. Currently as it is right now the details are not quite visible.
Chunk.zip (3.11 KB)

I don’t have Numpy accessible to my Panda3D installation of Python, so I couldn’t run your example, but in looking at your code it looks like you’re using normals-generation process from the Panda Procedural Cube sample script. The process used in that script will only generate correct normals for an object generated at the world center. Most other implementations of procedural geometry in Panda will probably require another approach.

In recent months I dealt with the same problem, starting from that misleading Procedural Cube sample script. I applied three different approaches for generating face normals on cuboid geometries.

1. The correct and most involved approach is to calculate each vertex normal as the crossproduct of the two edges for which that vertex serves as the corner point. Smooth the normals for a vertex between polygons by determining all polygons which share the same vertex, then calculating the average of all the normals for that “welded” vertex using all of its polygons.

2. A simplified approach, adequate for controlled cases such as a cubelike geometry which does not require smoothed normals, is to calculate the normal for the first vertex of a polygon, then duplicate that for all of the other vertices in that poly. This is sort of a cheap trick, like the gimmick used in the Procedural Cube example, and it isn’t suitable for all cases.

3. If you’re only dealing with axis-aligned cube geometries and you thus know the direction in which your normals will always be pointing, you can simply pre-calculate your normals, store them in a list or array, then use those values when you construct each cube. This can allow you to skip some unnecessary calculations, and thus might offer some potential speed gains if you’re generating a large number of geometries.

However, as I say… I couldn’t run your code on my system, so I’m not 100% sure that I’m actually answering your question. I assume here that you’ve run up against the same problems I encountered. My apologies if I’ve misunderstood. 