Monday, June 27, 2011

Curves, Regular Expressions, and Blender Data Pages


This was a pretty busy week that saw a lot of victories and interesting developments on small projects and experiments. Here are some of the highlights of what happened.

String It
Last week saw the release of String It. String It is a Blender add on that generates curves that run through the center of selected objects. Right now, it just supports bezier curves though future revisions could support other spline types. Also, it might one day include support for automated hook modifiers to bound the the objects to the curves that run through them.

Regular Expressions Challenge
Repetitive work involving removal of Amazon anchor tags inspired a scripting project to automate those kinds of tasks. A practice challenge with regular expressions on an old copy of one of my PHP files was called for. The project ran into some problems. For example, what does one do if there are two sets of anchor tags on the same line being evaluated? An oversimplified expression might match both sets along with any text between them. It's interesting enough to merit further investigation.

Blender Data Pages
One of last week's projects confirmed that it is possible to have a server script invoke Blender in a way that lets the script print blend data on a web page. The project only required a PHP page, a blend file, and a few lines of Python. While it was easy to do, security concerns prevent me from making a full project for production. Still, the idea of something called "Blender Data Pages" does have a nice ring to it.

Generator for Uncle Squirrely
Usage of the any() function in Uncle Squirrely's database update script made the code cleaner. However, that meant evaluations on whether or not a game belongs in the database had to go into lists. Since every evaluation in the list has to be evaluated, that caused an efficiency hit. Sacrificing performance for code aesthetics was not a good trade off.

Lazy evaluation courtesy a generator function is the best of both worlds. Basically, all I needed to do was put all my evaluations in it's own function. If you put yield statements between evaluations, what you get is a function that can be iterated on the same as you would with a range function. It was easy to learn, easy to implement, and lead to lazy code that looked great. All projects should be that easy.

Other Little Things
In the near future, Blender PythonTutorials will be an add-on focused site. Moving the add-on scripts link to the top is one step toward that goal.

Last, but not least, I have a special lambda utility I like using for searching module properties.  The problem is I found myself rewriting it everytime I needed it. Finally getting around to putting it in my PYTHON_PATH reduced that typing to an short import statement. It also made the utility available both in and out of Blender related Python projects. It should have been done sooner.

As you can see, it was a pretty busy week. I learned a lot, put good stuff out there for users, and got inspired to explore other ideas. These are the things that make software development the worthwhile endeavor that it is.


No comments:

Post a Comment