Skip to content

My PyCon talk about blender scripting now available online

A couple of months ago (May 2-3), the first PyCon was conducted in Israel.

It was a really cool and fascinating event, which I enjoyed and that exposed its 350 participants to lots of useful knowledge and techniques.


I had a talk there, titled “Generating, automating and processing 3D graphics with Blender’s Python API“, that very briefly introduced the host of python coders in the audience to Blender python scripting. You can watch the talk here:


חוקרים מגלים שדגים מתים מדיכאון בחוות סלמון – הפתעה?

מחקר שפורסם לאחרונה וכלל ניסויים בדגי סלמון בחוות גידול, שופך אור על המנטליות של הנסיינים ביחס למושאי המחקר שלהם, ועל הפסיכולוגיה המורכבת של בעלי החיים לא מוערכים אלה…

Source: חוקרים מגלים שדגים מתים מדיכאון בחוות סלמון – הפתעה?

Pet wheelchair helps Aussie cat and is reinterpreted to try help a Bulgarian deer!


An amazing event a couple of weeks ago vividly illustrated to me the immense power of sharing knowledge online.

Remember the pet wheelchair I designed for Benji the cat last year?

You might recall that after completing the project, I uploaded the 3D files to thingieverse.

In August last year (2015), I was contacted by a guy from Australia regarding the wheelchair. He asked me to adapt my design to work with 12mm aluminum bars, which are more common and easier to get in Australia. He said there’s a project he’s working on that could use this design at a local vet clinic. I added a 12mm version to Thingieverse and forgot about it for the next 5 months.

But two weeks ago, he posted a comment in the Thingieverse page, and told me this design was used to help a cat called Mozart recover from serious fractures in his hind legs!


Mozart the cat trying out the 3D printed wheelchair. Photo: Martin Orliac.

Apparently, the story even got published in the Sydney Morning Herald. How cool is that?



The finished wheelchair. Looks far nicer than the one I built for Benji! Photo: Martin Orliac.


Why stop there?

After I posted about this on Facebook, I was contacted by Leeron, an activist who lives in Bulgaria and is involved with rehabilitating a baby deer called Kinta. The poor thing got infected with Tetanus and lost control over his hind legs, and is now undergoing physiotherapy. But progress seems really slow via standard physiotherapy, so Leeron wants to use a wheelchair to help Kinta learn to walk again, and asked if I could help.


Kinta the baby deer. Poor thing got infected with Tetanus and lost control over his hind legs.

I opened Blender, downloaded a deer model from BlendSwap and started sketching. This time, I decided to use aluminum pipes with a circular profile for the main frame instead of rectangular bars, since a deer is likely to weigh a lot more than a cat and the added strength per weight ratio will be useful.

Here are some of the sketches I sent Liron:

i1i6 i8 i3

The keen eyed blenderheads among you will likely notice the quick and dirty shading combined with freestyle, to generate clear lines for the sketches.


Waiting for updates

Leeron and co. already started gathering materials for the build. I’m anxious to hear how it goes, and will likely try to provide them with other designs if this one proves inadequate. I’ll update here when I learn more, and hopefully get good news with pics of the cute little critter with the wheelchair (or better yet -walking after rehabilitation).

Highschool algebra applied in 3D automation and modeling


In high-school, I always considered myself average in math, and I never took much interest in it.

In fact, I can’t say I took an interest in any of the classes taught except history occasionally (at least there were nice stories there). It’s not that I wasn’t interested in the subjects themselves (as I would later discover), it’s just, well… that they were taught in a dull and utterly unimaginative manner. This, unfortunately, is likely the norm in most schools.

It would take me nearly 10 years from the time I was graduated from high-school, to really appreciate how useful math could be. It was during my time as a graduate student, performing research in microbiology that required analyzing large amounts of data. At the end of that period, statistics – probably the least favorite topic for most undergrads, would become one I’m actually rather fond of! Later still, I would heavily regret my earlier disinterest in math, and learn how useful it is for my day to day work in 3D and image processing.

I believe that math is normally taught in a criminally bad way in school. Being a field full of abstractions, it’s commonly taught in an abstract, detached manner, without giving students any real indication to its applications. Our brain is a pretty economical organ, which often refuses to learn things that seem utterly useless, particularly when they require as much effort and repetitive exercise as math often does. I think this is at the heart of the modern math education crisis.

If it was up to me, I’d intertwine math with other subjects from the start. Programming specifically, but also physics, chemistry, economics and biology. Heck, why not a combination of programming and math heavy science? Let kids write code that solves their homework for them, and they will have to understand both the science and the math involved, and learn to code along the way. However its implemented, math should ALWAYS be taught alongside its applications. Optimally, interesting and compelling applications (like video games).

Of course this might not apply to the truly abstract nature of some of the higher level, academic math topics, but it does and should for middle and high-school, and most college level courses.


Intersecting Edges


Lately I’ve seen an intersting question on the Blender StackExchange website: how to add a vertex at the point of intersection of two edges. That’s a pretty useful thing, especially if your 3D geometry is distorted and noisy, a common issue with 3D scans.

There were already several answers to this question, describing a number of efficient techniques for fixing this issue. One of which, by the almighty Zeffii (who maintains the Blender Python blog), included an automated, scripted solution that employs the function geometry.intersect_line_line(v1, v2, v3, v4) to find the intersection and adds a vertex there.

It does not, however, split the edges at this point, so this vert is floating above.

That’s one reason I wanted to write a different solution. The 2nd reason is that I didn’t want to depend on the built-in intersection function. Intersecting two straight lines is a pretty trivial mathematical problem, and I wanted to see if I can revive enough of my basic math skills to solve it.


Solving it

The first step is to generate a parametric line equation for each of the two edges. This nice page showed me that a 3D line equation could be represented thus:

(x,y,z) = (x0, y0, z0) + t(a,b,c) = ( x0 + t·a, y0 + t·b, z0 + t·c )

With x0, y0, z0 being the XYZ coordinates of the edge’s first point (let’s call it p1),

and a, b, c being the XYZ values of the edge direction vector, which is calculated by subtracting the edge’s first point (p1) from the 2nd point (p2).

And finally, t is the line’s parameter, with which we can calculate any point on that line.

This could also be broken down to equations for any particular axis’ coordinate:

x = x0 + t·a
y = y0 + t·b
z = z0 + t·c


With this in mind we can reconstruct both edge’s line equations. And the intersection point between both lines, is the point where the x,y,z values will be the identical in both lines. I later found an answer in the Math StackExchange website describing this solution in a much prettier manner.


So, since I know the first points of each vector and the direction vector’s of both edges, all I needed to do is to reshuffle the variables a bit until I had an equation for one line equation’s parameter t, then plug that value in the line equation to find the intersection point’s coordinate. Here’s the python code for that bit:

globCo = lambda co: o.matrix_world * co</pre>
def find_intersection( edges, o ):
    # Calculate global locations of edge verts
    p1, p2 = [ globCo( ) for v in edges[0].verts ]
    p3, p4 = [ globCo( ) for v in edges[1].verts ]

    v1 = p2 - p1 # Edge 1 line vector
    v2 = p4 - p3 # Edge 2 line vector

    # Calcualte intersection
    # Based on paramteric line equation: (x,y,z) = p0 + t * lineVec
    numer = v2.y * ( p3.x - p1.x ) + v2.x * ( p1.y - p3.y )
    denom = v1.x * v2.y - v1.y * v2.x
    t1 = numer / denom

    co = Vector( [ getattr( p1, i ) + t1 * getattr( v1, i ) for i in 'xyz' ] )

    return co

The entire script can be found on GitHub.


Hopes and Regrets

If only someone told me the algebra and calculus that dulled my senses in school (and more advanced topics) can be used to generate amazing 3D structures, power game engines and simulate interesting phenomena in the real world, I certainly would have paid more attention and worked harder to master the material and learn more. One day, when I have a bit more free time, I hope to try and develop curricula that integrates math into programming and other scientific subjects from the get-go, preferably with gamification employed as well. If any educators are reading this, I’d be happy to hear your thoughts on the matter.

StackExchage addiction and a New spiral generating script

Add Spiral Modifiers

Extruded spiral with a few modifiers applied

Many hardcore blenderheads will probably identify with one of my latest addictions – the Blender Stack Exchange website.

Stack Exchange is part of the Stack Overflow universe, an ingenious, revolutionary project that provides invaluable information to coders and software users around the world. The idea is simple, encourage people to share knowledge and information by answering questions in a gamified social environment. Questions, answers and comments are easily ranked and carefully moderated, and good answers can easily stand out from the bad or mediocre ones by a useful system of ranking.

But the real genius of this system is its effective gamification. Good questions and answers provide points, badges and status. It quickly becomes addictive to see if an answer you posted got positive votes, or helped the person who asked the question (who often might post grateful, enthusiastic comments). Once you got enough points under your belt, it becomes interesting to examine the various leaderboards (which show top ranks by week, month, quarter and all time, among others).
The system is so effective, that world renowned experts that would probably charge hundreds of dollars per hour, work hard to provide useful answers for free.

The Blender Stack Exchange website is particularly active and there are some amazing people there who obsessively check for new questions, and would often provide a useful answer within 30 minutes or less from the time the answer was posted! Usually you don’t even need to ask a new question, as so many good questions and answers already exist. I cannot count how many hours of difficult research, struggle and experimentation I saved by simply tapping into this amazing well of knowledge.

This is a good opportunity to thank these brave women and men😉

Zeffi, Gandalf3, Poor, Cegaton, Carlo, batFINGER, David, PGmath, Sambler, Jerryno, Pink Vertex, CoDEmanX, stacker and any I might have forgotten. You guys are awesome.

Lately I’ve been expanding my addiction to additional Stack sites, one of which is Computer Graphics. The Script I’ll describe below is a result of this fortunate new interest.


Archimedian Spiral Generator Script



While browsing the Computer Graphics Stack page, I bumped into a guy who asked (and later answered) how to algorithmically generate an Archimedian Spiral in C++. The algorithm was short and elegant, and the result beautiful. It was simple to translate this into a blender script that would generate spirals in 3D, so I did.

After installing it as an addon, you will be able to add a new spiral through the Add Mesh Menu. I might make proper or addon out of this sometime soon (perhaps as a new Extra Objects variation that will also include my Koch snowflake addon and Fibonacci Spiral).


Add Spirals 3

My Witcher’s viper school medallion finally printed in metal


I designed this (not so) little thing ages ago, put it up on Shapeways and saw quite a number of people order it in metal despite the considerable price it cost to print something of this size in metal.

It’s the kind of shape you can’t really manufacture in any other automated fabrication method except 3D printing (you can make such a shape by hand if you’re a master jewelmaker, but that I am not). But if you really loved The Withcer 2, which I really did, this shape will hold a special significance and you simply must have a physical representation of it somehow (and a replica of the medallion from the game is the best kind).

I designed, printed and wore a version of Geralt’s Wolfshead Medallion for quite some time, but lots of people have these, and CD Project even gave out copies with collector’s edition of the original Witcher game and its sequels.

No one else that I know of made a really good replica of Letho’s viper school medallion, so I had to make one.


I ordered it once in the cheapest material available, nylon-12 (that shapeways call “Strong and Flexible plastic”), just to see how it feels, and it looked cool, though it was obvious this kind of object must be printed in metal to live up to its potential.


My Witcher medallions are the bestselling products in my Shapeways store, and I’m always pleasantly surprised when another person orders one, especially in metal. A few of these ordered during the last couple of months provided enough income to convince me it’s about time I got one too.

Here’s the result!

This slideshow requires JavaScript.

The medallion is pretty damn heavy in this (polished nickel steel) version, but it makes it feel solid and awesome. I’m really happy with how it came out.

New Addon: Batch Image Converter

I recently had to convert a bunch of 32 bit tif depth maps to 16 bit pngs at work, while keeping the same file names expect for the new extension.

Normally I’d do this in Photoshop, but photoshop doesn’t allow you to save 32 bit tifs as png, it only converts it to HDR, PSD, PSB, RAW, EXR or PBM.

Which program does allow you to do that? Blender. You can load tifs and render them to any of the supported formats in Blender, which includes the 16bit PNGs I wanted.

I loaded the tifs to the video sequence editor and rendered the frames as PNGs. While that worked, all the new files had frame numbers for names.

So I decided to write an addon that does the same thing, only it saves the converted files with the same name as the original, except for the extension of course.

There’s a bunch of features that will make this addon even more useful, which include:

  1. Custom name patterns (instead of keeping the same name, save as another kind of pattern with numbering).
  2. Make sure to ignore non-image files in the source folder for the script.
  3. Read the source images’ resolution, and allow using it for the output, instead of relying solely on the render settings.
  4. Avoid deleting the existing render node tree.
  5. Have any additional ideas? feel free to write a comment to this post and suggest more features.

For a detailed installation and usage guide (which really isn’t all that required for such a simple addon), watch the video above or visit the addon’s WIKI page.

To report bugs, fill this form.