Archive for ‘Python 3’

aprile 24, 2013

dual meshes in blender

000 - cover_fx

Thanks to introduction of b-mesh it’s possible in blender, starting from a triangulated, to obtain a polygonal mesh in blender. This kind of polygonal mesh is called dual mesh.

Create a generic mesh surface in blender and then triangulate that. You can use the shortcut ctrl+T. Generally I suggest to start from a regular quad-grid, in order to achieve a more regular dual mesh:

001 - starting mesh

002 - triangulate

Now, add and apply a subsurf modifier, leaving the default settings. Now your mesh contains vertices of both starting and dual mesh. We need to surgically remove the starting mesh:

003 - subsurf modifier

For do that, we must select a vertice of the dual mesh. You can recognize it because it’s conected only to three edges. Now prest ctrl+ for “select more”:

004 - select more

Use now “select similar” tool (shift+G), and choose the option “Amount of Adjacent Faces” for select all similar vertices.
Invert the selection with ctrl+I and “Dissolve” the selected vertices:

005 - select similar

Now select one of the vertices connected to only two edges and use again the tool “select similar”. This time use the option “Amount of Connecting Edges”, and then dissolve all the selected vertices:

006 - select similar

Sometimes it’s possible that some quad faces must to be clean in a second moment, in this case you can use the same procedure for select all similar vertices. Furthermore, if your mesh is open, probably you have to clean the borders. To doing that quickly, you can simply use “Select Non Manifold” for select and delete the border vertices.

Here you can see the resulting mesh:

007 - final result

If you are lazy like me, you can also use a script that I created in order to automatically calculate the dual mesh: For do that, simply copy and paste the code inside the blender’s text editor, select your mesh and run the script.


luglio 23, 2012

Blender: Random Material Assigner (to BMesh N-gons)

This is a simple script for assignement of random materials to different faces (n-gons) of a single object. It works differently to the existing Random Material Assigner and the mine is a version very rough. I wrote this script because for the particular job that I had to do it was more comfortable handling a single object to be fixed as a random mosaic, rather than a very large number of different objects. Here is the code:

import bpy
import bmesh
import random

obj = bpy.context.active_object
mesh =

bm =

for f in bm.faces:
    f.material_index = int(random.random()*len(obj.material_slots))



novembre 15, 2011

Blender Real-time Exporter (simple version)

Sometimes, working with tools like Processing or Grasshopper I’ve felt the lack of maneuverability of blender meshes modeling. I therefore decided to develop a small script for export my mesh refreshing it in real-time. This will make it possible to read information from different software programs interactively with the ability to store files prefix.vertices and prefix.faces, containing respectively the vertices and faces of the mesh.
Is also possible to simultaneously export multiple objects with the ability to apply the modifiers before exporting. The export deals only with the mesh, so there are not applied the transformations like translation / rotation / scale of the object.

Following is a brief description of the syntax adopted for export .vertices file:

vertex_01_x vertex_01_y vertex_01_z
vertex_02_x vertex_02_y vertex_02_z
vertex_03_x vertex_03_y vertex_03_z
vertex_04_x vertex_04_y vertex_04_z
vertex_05_x vertex_05_y vertex_05_z

and .faces file:

face_01_vertex_01_ID face_01_vertex_02_ID face_01_vertex_03_ID face_01_vertex_04_ID
face_02_vertex_01_ID face_02_vertex_02_ID face_02_vertex_03_ID face_02_vertex_04_ID
face_03_vertex_01_ID face_03_vertex_02_ID face_03_vertex_03_ID face_03_vertex_04_ID
face_04_vertex_01_ID face_04_vertex_02_ID face_04_vertex_03_ID face_04_vertex_04_ID

In the future, the intention would be to expand export opportunities allowing you to export files with different formats and reporting information about the vertex-colors.

Installation of Blender Real-time Exporter:
Download and open it with blender text editor, press Alt-P for run the script and in Object Data menu it will appear the new panel: Real-time Mesh Exporter.

You can also try the exporter with my simple Processing sketch BlenderToProcessing.pde. I don’t use libraries like toxiclibs or hemesh, but only Processing function beginShape(). So with particular quad faces it gives some errors of visualization.

Happy Blending


Here is an updated versione of the script to blender 2.69: