Complex Procedural Cube

Procedural geometry examples for Panda seem hard to come by, so I’ve put together this example script. The script contains several classes dedicated to generating geometry, texture coordinates, and textures. The code here is used both to create an example procedural cube and to implement an example obj importer. The correct method for generating tangents and bitangents is shown, as is the method I have posted elsewhere for creating a normal map at runtime. This isn’t intended to show a quick and efficient way to create geometry and textures on the fly. The sort of process used in the standard Panda Procedural Cube example is good for that, being optimized for its purpose. Rather, this is intended to present (hopefully) flexible code which can be extended to various uses. The standard procedural cube example shows only how to create a cube at the global origin, and (at least) its normals-generation process is incorrect for any other context. The approaches used here should be able to be applied more broadly than that.

The attached zip contains the script and an example obj file. By default, the script will create and display a multi-textured cube, with all geometry and textures created at runtime. To import the test obj, change the variable in line 61 of the script from False to True. A multi-textured obj sphere with two material zones is then imported. The script can also be modified to illustrate different UV-mapping methods. Box-mapping is used by the cube, but the script also shows planar, spherical, and cylindrical mapping.

I hope this may be of use to someone. I found it difficult to dig up information and examples revealing how to do these things in Panda. My hope is to make such things less obscure, by presenting this script.
complex_procedural_cube.zip (14.7 KB)


Updating this script. Added a function to export obj files. Added global, tile, and cylinder cap UV mapping types. Fixed a few bugs and refined cylinder and sphere UV mapping types.
complex_procedural_sphere2.zip (19.6 KB)

Updated with improved process for geometry-creation.
complex_procedural_cube3.zip (20 KB)