Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

June 29, 2013

named tuples replacement (bounding box tools)

To maintain sanity I suggest you don't read this script, it's just a memo to self.

June 27, 2013

automatic colour ramped shader from geometry height

As part of BlenderSciViz it's going to be useful to generate materials automatically.

This is going to be fun. or not.

Given whatever kind of mesh, i want to be able to run a function that checks the mesh data and makes a shader automatically. Let's try some basic stuff first, like add nodes and connect sockets via a script.
  • allow to easily define custom color ramps
  • allow easy floor and ceiling for ramp
  • arrange neatly
  • hide unused sockets
This script places the nodes, and connects them as in the image
As you can imagine, this much repitition is going to get on my nerves. So it will be useful to write a mini node connecting grammar. Something like:

Node links mini grammar (faster link scripting)

This is a simple but effective way to reduce lines of code needed to connect nodes and sockets.

June 22, 2013

Data Viz Episode 1 (WIP don't share yet)

Creating a Vector overlay for rendered raster images.

I'm of the school that considers typography most effective when rendered in 2d, i.e. I don't want my topography for labels / names / scales / dimensions etc to be renderable 3d geometry. I'd have to set up a constraint to always point the typography at the camera so it doesn't distort. But if I can get the 2d locations of these entities it is possible to create vector graphics overlays. Not just useful for typography but grids and axis ticks too.

Let us construct some json from the cube object. This json will have a readability issue if we use indent=0, but with indent list members each get a new line. I know about it, and so do these guys. Some of this code is the same as the first post, but now it writes to a file in the same location as blender.exe

This will make a lot more sense with some images now it is possible and easy to turn this:

into this (here live d3.js code on tributary to parse the json into svg)

How to proceed from here

What i've shown so far is both trivial and awesome at the same time. Imagine now that we construct the guides / axis as a edge based mesh object, that never gets rendered as pixels. This object would still be visible in 3d view, but the edges wouldn't be rendered in the final render, instead their information can be deferred to this svg-overlay I keep banging on about. Some of this process can be bound to reusable functions both in python and d3.js. i'll probably write a few as examples and start a github repo and get this ball rolling.

Like:

here's the live link

stacked chart


With a little bit of d3.js overlay here

adding custom modules to blender python directory for easy import

example, local absolute position of 1 selected vertex
"""
in 2.6x/scripts/ i added ztools and a script inside that folder so I now have
2.6x/scripts/ztools/reposition.py

In blender console I can now import the functions from reposition.py and use them conveniently with autocomplete

>>> from ztools.reposition import move
>>> move(1,0,0)
"""

June 21, 2013

Data Visualization in Blender

Partly prompted by a post on blender.stackexchange about what options are available to visualize data, with the emphasis on scientific visualization. The next few posts will be about data visualization in Blender. Examining what methods are available and what needs to be written.

It made sense to start a repository of visualization scripts, here is BlenderSciViz


sample topic.

2d Overlays onto rendered geometry

This gets 2d pixel position of 3d coordinates seen by a camera and corresponding distance to lens.

Here a live version for chrome, using d3.js and svg
Made a first few overlays in this post:

June 16, 2013

Normalizing spline points. (make equidistant)

In college I had the opportunity to learn 3dsMax to a reasonable level. It is great in many ways, and one modifier was particularly nice: the normalize spline modifier. Normalize spline places the curve points at evenly spaced distances. If you don't know why that is awesome, you'll probably have to see it to understand.

Prompted by a post on blender.stackexchange i've started writing a blender version of the modifier, I don't foresee it to be a full blown replica but time permitting it will at least produce a replica polyline (edge mesh) with BGL overlaying points so interaction can help a user decide what distances the points should occur at.

more later.

preview code:

Note: This only draws the verts using BGL at their current locations. A nice short bgl snippet. https://gist.github.com/zeffii/5796615
.
Using Sverchok and Scripted Node : https://gist.github.com/zeffii/782e84fbdc8e8f23f64b

June 13, 2013

Scripting 3d bezier spline surface

Prompted by a question on blender.stackexchange

June 04, 2013

two ways to min/max an xyz coordinate list

June 03, 2013

keyframes and timeline markers

one might want to get the time of events for audio editing purposes.

Normalize and Quantive

A question on BA.org looking for a script that can scale an object to within the boundaries of -1 and 1 for all axis (called normalizing, maybe erroneously) and then placing further constraint on the geometry that it must fall within grid slices of 0.1 .. so xyz can only have values between the range (-1.0, -0.9 -0.8 ....0.8, 0.9, 1.0), i made the following scripts.

here is the development version:
here is everything chucked into one loop.

Alternative code

June 01, 2013

console and text editor theme script

This may be of no interest to anyone but myself: maybe i should add chromakey functions to this too..to auto_on the syntax highlighter and line ruler.

hex_to_rgb and back ( hexify )

these can be useful to dissect, if you've recently started writing python