Sunday, December 23, 2007

Python and Blender

I was just working on a Blender project where I have 36 objects that I should have set the rigid body property for each. It took several minutes to do manually, was very tedious, and made me realize it was time to learn how to script Blender.

Blender is scriptable through the Python language. I've never scripted Blender and I've never used Python, so it took me a bit... Figuring out the appropriate Blender APIs and then learning the Python syntax (it is very different from what I'm used to like AS3, C# and Java). Here's my tiny, first script:
import Blender

objects = Blender.Object.GetSelected()

for curObj in objects:
curObj.rbFlags = curObj.rbFlags | Blender.Object.RBFlags.RIGIDBODY

Taking it apart, the first line imports the Blender module for the Blender APIs. The second line gets all of the selected objects in a scene using the Object module's GetSelected() method. The third and fourth lines iterate through the list of objects. Line 4 uses the bitwise OR operator to set the RIGIDBODY flag for the current object.

It took me a while to figure this little script out, longer than it took to do the operation manually. But the next time I need to set a property of a large number of objects -- any property, bitwise or otherwise -- it'll take seconds to type instead of minutes in the interface.

Thursday, December 13, 2007

Flash Object Drawing

When I first saw the Flash 8 feature Object Drawing, I thought it was just automatically grouping the object (like with the Group command), so I dismissed it. I dismissed it for a whold version! Last night in Flash CS3 (Flash 9), I turned Object Drawing on for my little boy, and then noticed when he moved the cursor near the edge of the object that the curve on the cursor appeared!

After a quick test I realized that groups were indicated with a bounding box that was closer to a cyan color where the object bounding box was a darker blue. It is very cool that the objects are still modifiable in the standard Flash manner of pulling out curves, corners, or corner points, yet they do not merge with the shape below, it's like having the best of both worlds... being able to use Flash's very natural feeling vector drawing tools, but have the result be modifiable in a way that is more similar to traditional vector tools like Illustrator. I don't see this technique replacing the old Flash way of drawing, but supplementing it so I don't have to rely on moving back and forth between layers so much.

It is easy enough to break apart objects with Ctrl-B, just as you would Symbols or Groups. But how can you make them from a non-object? After cruising through the menus, I was clueless. So I resorted to using the online Help (the equivalent of driving and stopping to ask for directions, IMO). The stop was useful, to make an object select Modify > Combine Objects > Union. Whoo hoo! The only thing that was missing was a shortcut to make a union. Since I don't really using the Group command, it was a quick decision to switch the use of Ctrl-G to make objects instead of groups.

Wednesday, December 05, 2007

Programming Alice 3d

I just downloaded the Alice 3d programming environment Carnegie Mellon University. It is a interesting way to learn programming logic without getting bogged down with dealing with syntax problems. By dragging and dropping you can construct your logic and create stories with 3d characters.

Since I'm back using Blender, I had to see if there was a way to develop 3d models in Blender for Alice. The official site is slim on documentation from a user perspective, so developer documentation is non-existent. In the program, I noticed you can import and .ASE file. I'd never heard of that and didn't see it in the Blender list of export formats. Fortunately, Blender is extensible through Python and someone wrote an import and export script for .ASE.

Just put the exporter script in your Blender scripts folder. I tested it and it works as long as you make sure none of the objects you make sure your object names don't have a "." in them.

Working with Alice set my Java-sense to tingling. I could tell it is a Java app from the look and feel, plus they have all sorts of .JAR files in the application folder. Having spent some time with Java, I started poking around. Knowing Java likes the .JAR format, which is really .ZIP, I renamed an Alice .A2W file with the .ZIP extension instead. Sure enough it popped right open with WinZip. It was very cool to poke around inside. Most of the contents were XML files. It's fun to see how it's put together.

One downside is when I tried to use the "Export Movie" feature and got a "This feature is not implemented yet" dialog box. Why even put the menu item in the menu if it is not implemented? Another problem was when I tried to view it as a web page. It didn't work but there was a link with instructions. Basically, you need to make sure you have Java, Java3d, and the Java Media Framework (which requires a reboot). Those are three separate downloads from three separate pages. Not too user friendly! Lastly, after downloading and installing those, rebooting my machine, I find the applet version does not play back showing the word balloons and opacity changes in my "world". So if you want to show others your work, you'll have to pass around the .A2W file, which is basically the source code and files. Even that has some issues in that supposedly some mail programs recognize that it's really a .ZIP and change the extension. I haven't confirmed that behavior.

Still, Alice is a great tool and it is free. In a short amount of time, my kids were creating short stories using the pre-created characters.

Monday, December 03, 2007

Cleaning up HTML with grep

I came across an email I sent out a few months ago to some co-workers. I thought it would be useful on the blog. I really like grep, but I haven't had the opportunity to use it as much in the last year. These are grep searches in Dreamweaver, it can vary a little from software to software (ie, Vi, Visual Studio, etc has some varying functionality).


I just had to go through a file that had tags with a varying width attribute I needed to whack, ie:
width="1"
width="23"
width="456"

With grep it was a quick search with the following (the grep stuff is in red bold):
width="[^"]*"


Then I had to whack a bunch of opening and closing paragraph tags:
<[/]*p>


Lastly, there were a slew of span tags, ie:
<span style='font-size:10.0pt;font-family:Arial'>John <span class=SpellE>Nyquist</span></span>

To whack those:
<[/]*span[^>]*>

Wednesday, November 21, 2007

ArtRage


I stumbled upon a nifty piece of software for doing natural media digitally. After having some frustration with Painter's stability, I thought I'd take a look around to see if there were any packages out there. I came across ArtRage. I was skeptical at first because of the price ($25). Then I started looking into the forums on their website and seeing what users were doing. I was blown away. I saw that one of the users actually uses both Painter and ArtRage and was kind enough to give me feedback on how they compared.

ArtRage is impressive in its ease of use and still able to deliver professional results. While it has a consumer price, the product quality and results go well beyond. The painting above was started with an image that came with the product. I spent almost no time in the manual or looking at the actual tutorial (just enough to figure out how to set up a tracing, which didn't take much!).

The programs tools have a nice feel. The choice of hot keys are user-friendly (I figured out all the major ones without resorting to reference). And even cooler is how the palettes get out of the way if your brush gets close to them. A small but nice feature is how the program opens up a document, ready to paint, without asking you questions first. Another nice touch is if you right-click, the only thing on your screen is the painting, all other distractions are gone. Best of all... it was fun!

Tuesday, November 20, 2007

Blender


No, that's not a self-portrait! It's been quite a while since I last played around with Blender. Last weekend I decided to take a break from Flash/Flex/ActionScript and Painter activities and give Blender another try. Blender is a very powerful, stable, fast, open source 3d program. I'd found an excellent tutorial model on character animation and couldn't resist. I didn't get through the entire tutorial yet (I got through modeling and rigging), I hope to get through the rest of the tutorial soon. It's very exciting to start with just a plane (four vertices!) and build a model that you can then move around and render. It's like making your own toys :)

One of the problems with only occasionally working with a tool as complicated as Blender is that I end up having to re-learn a bunch of the basics. Blender's got a great user interface, it is very flexible and does a great job of allowing you to maximize your workspace. It's just that it is not similar to any other software I've ever used. Ironically, after using Blender a bit, I found myself wanting to use the "G" key to move stuff in Illustrator (which I've used since 1987). That says something about Blender's design.

I first got into 3d with Swivel 3d in 1989 (I think), it was the same year the IIci came out. Once I'd got all that 68K power I thought I'd try 3d. I didn't care much for Swivel because I was doing stuff for print. I did end up using it once to set up a scene in perspective which I then drew over it in Illustrator. I probably could have drawn the image quicker from scratch but it was a good experience. In 1992 I jumped into Strata 3d. After attending a 5-day training course put on by the Strata folks in beautiful St. George, Utah, I got hooked on Strata's outstanding rendering quality. The modeler wasn't great, so I dabbled in some other 3d programs as well at the time (like Infini-D), but I always came back to Strata for rendering. Strata in those days was as stable and dependable as Photoshop.

One of the other 3d packages I tried was Playmation. It had a very nice spline-based 3d, modeler. In fact the whole program, which was geared towards character animation, seemed revolutionary. Unfortunately, it was the most unstable program I ever owned. Over the years, I continued to upgrade it as it became Animation:Master. Never having much luck with the stability. When I crossed from the Mac world to the Windows world, I tried it a couple more times, hoping that it would be more stable on the platform it was developed on.

(And I'll just avoid mentioning Raydream's addDepth and Adobe Dimensions. While they're 3d and I enjoyed them both, they're not really in the same vein as they were vector tools and far simpler than your standard 3d program)

At work I got the opportunity to try Cinema 4d. It has a very approachable interface, is pretty stable, but a little on the slow side. The friendliness of its UI was reminiscent of Strata.

Eventually, I came across Blender. I downloaded it, installed it, opened it, then closed it and uninstalled. The user interface was just too strange! Some time later, I gave it another shot. This time going through a tutorial. I was hooked. The strange interface worked amazingly well. Blender was also very stable (like Strata), had a great modeler (different than A:M but just as powerful) and it was fast even on older machines. I worked with it in my spare time for a while but with mergers, job changes, etc. I'd let it fall lower in the priority cue until it fell right off.

I'm really glad to be back working with it (and 3d) again. I can't figure out what the appeal of 3d is for me, why it keeps pulling me back. Part of it is what I mentioned earlier, being able to create something from scratch and move it around (or move around it). Strata's animation ability is one of the things that led me to interactive multimedia... I didn't want to just animate, I wanted to interact with the animations, which in turn led me further down the programming path. Now I think I'm coming full circle. One of the cool things modern 3d tools have is scripting languages. Blender has Python (which I've never tried), so that might be on the agenda down the line.

Tuesday, October 09, 2007

Interacting with Flex in Flash

I was trying to bring a Flex 2 SWF into Flash CS3 and interact with it. I was able to load the Flex swf without a problem but when I tried to access a public property or function I'd get the following error:

ReferenceError: Error #1069: Property hello not found on
_Main_mx_managers_SystemManager and there is no default value.

So I did the natural thing and Googled it before spending time figuring it out :)
Unfortunately, my search came up empty :(

Looking into the docs class mx.managers.SystemManager gave me the clue I needed. To get at the actual application, I needed to get to the first child of the loaded content. The compiler was unhappy with calling getChildAt() on the content object, so I cast it into an Object along the lines:

var flexApp:Object = (loader.content as Object).getChildAt(0);
trace(flexApp.hello);

That did the trick!