Discover Pycao¶



What is Pycao in a few words ?¶
Pycao is a 3D-modeller for Python. In other words, Pycao is a language based on Python usable to describe a 3D-scene. In practice, you describe your 3D-picture writing python/pycao code, you run python on your code, and that’s it, you get your image. Pycao is usable both for photo realistic 3D (as the room of the first image) or as a CAD software with precise measurements (as the bike prototype in the second image). As 2D is a special case of 3D, 2D-CAD is possible too but is not the main goal.
Pycao does not compete with professional tools carrying thousands of options. The focus of Pycao is towards simplification rather than versatility. To be honest, 3D-drawing is difficult, whatever the approach. But Pycao tries to make 3D-design as simple as it can be, and hopefully makes 3D modelisation of real projects possible for the hobbyist or the scientist. It may be suitable for people with a project of medium size, like building a wood furniture, a bike or drawing a scientific illustration, discouraged by the complexity and/or inapropriate documentation of some 3D software.
The choices in the design of Pycao are the following. It relies on Python because Python is an object-oriented language with a rich vocabulary and a simple syntax. This helps to minimize the time necessary to code our models. A good documentation is required to work in good conditions, and one of the objectives is to furnish a good complete documentation. Finally, Pycao is free from any graphical interface, for simplicity and power. We use our prefered editor with no supplementary environment to learn. This approach makes it possible to bridge the 3D software with data from external program.
Is Pycao a Povray modeller ? What are the supported formats ?¶
In the first versions, Pycao relied heavily on the Povray software. In the current version, there are two other possibilities for the rendering : using OpenSCAD or using tikz/Latex to render 2D-curves.
Pycao does not render by itself. It is only a language to describe the scene. It tries to offers you the best possible language for this objective, wheras. the rendering is deferred to other existing tools which fulfil this mission perfectly. Currently, the rendering external tools are Povray,OpenScad,or tikz/Latex.
You don’t need to know the external software to use Pycao. You just write your Python/Pycao code to describe your scene. Then Pycao works for you. It takes the Python objects you have constructed and generates transparently the external code corresponding to your objects, and produces the images you want.
After exporting to OpenScad, you have access to the formats supported by OpenScad (.stl, .obj etc…), but there is no direct export to these formats from Pycao.
Originally, the goal was to produce a Blender modeller. Since the documentation in Povray was more precise, the Pycao project switched to Povray. The OpenScad and Latex frontends were added afterwards.
The adequate front-end depends on your goal. If the goal is to sketch and visualize the 3D scene easily, the export to OpenSCAD is the best choice as a fast graphical interactive visualisation is possible. If the goal is to get a very nice photo-realistic scene, Povray is a much better choice. If you want to draw 2D-curves, the latex export is the canonical choice.
Where is the graphical interface ?¶
In the first versions of Pycao, there was no graphical interface. A simple image appeared after the compilation of the python code.
In practice, choosing the location of the camera, zooming, … to get the expected view was time consuming. This limitation has been tackled introducing two possiblilities for the rendering. A fast one using openscad. A second visualization is possible throuhg Povray, it is more detailed and more precise, but it is slower. In this detailed rendering, the scene will be displayed after compilation in a window where you can move the camera, the zoom… in an interactive way with buttons. It is also possible to visualize standard povray files modelled out of pycao with the viewer. The viewer and the buttons look like this

Although there is graphical interface for the visualisation of the objects built, Pycao is not a graphical modeller. The objects are described/built with python code in a text interface and and Pycao will remain a text software in the future. My experience is that describing a 3D object with a mouse on a 2D screen is extremly challenging and difficult to maintain. Pycao is designed towards people who think that it is easier to describe a 3d object with a good language than with a graphical interface, or for people who want to easily draw a 3D picture using output from an other software.
How is designed the pycao code ? What are the objectives.¶
Since Pycao is designed to be a language for 3D-scenes, its efficiency depends on the concepts introduced for the simplification of the description.
A carpenter does not use mathematical computations, or more exactly uses a very minimal set of measurements and usual natural words otherwise, which are sufficient to transmit the knowledge from one carpenter to a colleague. In particular, a carpenter never uses matrices commonly seen in 3D-software. Yet is able to build a full window. The objective of Pycao is to mimic the attitude of a carpenter, and in some sense to build a language close to the natural language with few maths in the code. You describe the scene in pseudo-natural language. Pycao computes the maths for you.
Simplifying paradigms towards this objective have been introduced :carrying objects in boxes, genealogy system with parents and children, CSG geometry, hooks which are markers similar to the pen marks in a workshop, measurements possible from the left and from the right using various units, easy to build libraries …
Summing up, a language that allows a short and natural code for the description of a 3D-object is the main objective of Pycao.
To get an idea of the complexity, the above bike requires around 250 lines of code. The simple scene with a table or a wheel as below require in the library around 20 lines of code for the geometrical description, plus a few lines of code for the colors.


The second main objective of Pycao is to make the code coordinate free. Maybe you have experienced the problem : you have 200 lines of codes, you change the coordinate of an oject line 56 and then you have to read and adapt the following lines after this change. For this reason, the geometric code saying “put this object above this one” is more stable than the code based on coordinates saying “put this object at coordinate (x,y,z)”. Pycao avoids math computations and coordinates as much as possible. However, mathematical computations are sometimes unavoidable, and the mathematical language of affine geometry ( barycenters, points and vectors, affine transformations …) is nativly understood by Pycao when needed.
I am new to 3D. What are the alternatives to pycao ?¶
In the free software world, we find freecad, blender, povray, salome, openscad. Although all are great tools, their philosophies are different. Here are a few words to help you choose the project suitable to you.
The povray language is a language with a very complete and clear documentation. This makes it easy to master this language. On the other hand, povray language is a very “low level” language, where the description of an object is quite involved: you need to compute plenty of coordinates, no genealogy, no classes or inheritance, many curly braces around. Povray is a fantastic piece of code, very precise, but the code required to describe a 3D-object is long,difficult to write, to read and to maintain. This is logical and povray is not to blame: povray is a rayTracer, not a modeler, The language is built to feed the rayTracer, not to simplify the work of the developper.
Blender, Freecad, Salome include both graphical modeler and scripting possibilities. I will comment only on the scripting possibilities.
Blender comes with a python api. If you work mostly with the graphical interface, with rare use of the api, it may be a good choice. If you use intensivly the api, you should avoid blender. The api is very complex because of its integration with the graphical tool: be ready to spend countless hours to understand the “context errors” in your code, be ready to see some variables updated by the api without your asking for. Since there is a very active community in Blender, you will find help for these problems and for the debugging work.
Freecad and Salome api seem powerful. I have not used them very much because they appeared to be too complex for my needs. There is a huge difference of complexity between Pycao and these projects. The philosophy is very different from pycao, they are API whereas Pycao is a modeller : Both try to give the user power and versatility with elaborate syntax and many modules whereas in contrast Pycao tries to expose only the high level functions required to describe an object in a simplified syntax. Their code is marked by the integrated graphical environnement whereas pycao is a pure text modeller with code free from any IDE. They export to many formats.
Openscad may seem at first glance close to Pycao : the objects are built using written code with no graphical interface. However, the designs and goals are different. Openscad has plenty of useful exports. For instance, Openscad exports to stl and it may be usable for 3D-printing machines. However OpenSCAD uses a simple low level language with nearly no simplifying paradigms. You have to computate coordinates by yourself to draw the object or you will have to implement by hand the paradigms required to avoid coordinates and maths. Photo realistic drawing is not possible with openscad. Pycao is the opposite, it comes with many simplifying paradigms and the high level Python language, and photo-realistic rendering is possible with Povray. However, to export in stl or .obj, you will have to make the export to openscad first, and then use open scad to export to .stl, there is no direct conversion in Pycao.
For simple parts of a machine, the extreme simplicity of OpenScad is an advantage. The language is learned in a few hours. However, with this very stripped-down language, a complete modelisation of an object with medium complexity like the above bike and dummy seems hardly feasible to me. Thus the choice also depends on the complexity of your project and your long term objectives.
I am an expert. A few words about the architecture ?¶
Pycao is a Python module which constructs some python objects using your code. Then an instruction camera.shoot at the end of your python code calls a module povrayshoot.py. Povrayshoot takes the objects you built as input and produces povray/OpenScad/Latex code as output. An other instruction camera.show in your code calls povray/OpenScad/Latex to create the image file nameOfYourImage.png or nameOfYourImage.pdf and displays the image on the screen.
In other words, in the dialog chain from the developper to the display, pycao talks with the developper, the povray/OpenScad/Latex language talks with the X interface, and povrayshoot makes the translation between pycao and povray/OpenScad/Latex. The architecture is then:
developper <—> pycao <—> povrayshoot <—> povray/openscad/tex language <—> compilation and display kernel
In principle, it would be possible to export to stl or blender directly replacing only the povrayshoot module of pycao. There is no project along these lines as the export through openscad is satisfactory and gives access to .stl exports.
What are the defaults of pycao ?¶
The concepts and paradigms are now essentially fixed. However, the software is not completly mature. The vocabulary of the language may still evolve a bit in the future, if we can express things in a more natural way.
There are no Windows versions, only Linux versions.
Is it free software ?¶
Yes. The license is GPL v3.0.
Acknowledgments¶
The pycao project stemmed from my experiments with Blender and Povray. I warmly thank the developpers of Blender and Povray because I have learned so much from their software.