Monday, December 22, 2008

Recent Project


I did a few renderings of architectural and product design projects for Hawaii-based Global Living Systems. Design & modeling by Patrick Tozier and Hemasaila Rajan.

Monday, November 17, 2008

Rhinoscript Classes Introduction

Here's a simple example showing the use of VBScript's classes in a Rhino script. It assumes some knowledge of the basics of scripting. VBScript's classes offer a very primitive form of object-oriented programming, but it is enough to be helpful in organizing your scripts.

Why and when should you use classes? I'm not going to give you the theories you can read elsewhere about "abstraction" and the like, I'll say that it's fine, probably best to stick with basic functions and procedures when you're hacking out basic functionality, but once you get to a stage where you're struggling over what variables to make global and which to keep passing as arguments back and forth among several functions, it's time to think about packaging things up in objects. It's not necessarily going to make your code smaller, but it will make it a lot easier to manage, if you do it right(a bit of a caveat there, yes,)you'll smoothly construct really complex functionality from simple, robust components.

When you're making an "object" what you're making is your own custom type of variable, made up one or more of the basic variable types(integers, strings, etc.)or other objects. In this example, I've made a simple "Cylinder" object.
Download and load this rvb file into Rhino. As soon as you do that, a cylinder will appear. That's thanks to this code down on line 63, after defining the Cylinder Class:
Dim objPersistentCylinder
'create the cylinder object on loading the script file
Set objPersistentCylinder=New Cylinder
objPersistentCylinder.Height=10
Looks pretty clear, doesn't? We've made a new Cylinder, without having to worry about how, and set it's Height to 10. Much more elegant than without classes, if you wanted to keep track of these things you'd have to store the required parameters to build the cylinder and the identifying string for the solid as separate variables and pass them to a "ModifyCylinder" function. Then if you wanted to build an array of cylinders...ugh!
Now run the RunScript command in Rhino. You'll be given two subroutines to choose from, MakeTemporaryCylinder and ChangePersistentCylinder.
Line 68
Sub MakeTemporaryCylinder()
Dim objMyCylinder
Set objMyCylinder=New Cylinder
objMyCylinder.Radius=3
objMyCylinder.Pick
'pause for user input, just to show it exists
Dim strInput
strInput=Rhino.GetString("The volume of this cylinder is " & objMyCylinder.Volume &". Press any key to continue...")
'after this sub exists, the object ceases to exist and the cylinder is deleted as per Class_Terminate()
End Sub
This illustrates how objects have "scope" just like normal variables. The objMyCylinder variable was declared inside the function, so as soon as you press any key at the prompt, the object ceases to exist. In the class definition there's a special subroutine called Class_Terminate() you can use to execute any cleanup code you like at that time, like in this case deleting the actual solid.

You'll also notice the Pick method I added to highlight the cylinder, it's on line 57:
Public Sub Pick()
Rhino.SelectObject int_strSolid
End Sub
Functions, Subs, and variables can be defined as Public or Private. Pick is Public, so that the rest of the program can call it, but int_strSolid, the GUID of the cylinder solid itself, is one of the Private properties.

Now I could have made the GUID of the solid Public and used it to call Rhino.SelectObject outside the class, but the idea of classes--of course there have been books and books written about this stuff, pay little attention to my limited experience!--is that you want to keep as much private as possible so that you can change how things work inside the class without breaking the code that actually uses it.

There's also the problem that if the property is public, then any other code can modify it willy-nilly, which may or may not be a good idea. In this case it is probably a bad idea, if the GUID of the cylinder changes, what happened to the old one? Was it deleted or is it still hanging around? It's sort of the "responsibility" of the Cylinder class to keep track of it, so it needs to control it.

Now there is a way around it, if some outside functions did need the GUID but we didn't want it to be changeable. Notice how the volume of the cylinder is added to the command line prompt, and on line 42, how that property is called inside the class:
Public Property Get Volume
'Retrieve the volume of the cylinder
Volume=Rhino.SurfaceVolume(int_strSolid)(0)
End Property
So, we could make a Property Get for the GUID like this:
Public Property Get GUID
GUID=int_strSolid
End property

This gives the same result as if we returned a value from a function:
Public Function GetGUID()
GetGUID=int_strSolid
End Function
The difference is that as far as the calling code is concerned, "GUID" is just a property like any other rather than the result of a function. So both more elegant, isolating the logic of what you want to do with your object from the nasty dirty business of making it work, plus it means that if at some stage your GUID was a simple public property, and you decided to do something more complex with it, then that change would be transparent to the rest of your code.

Moving on to the ChangePersistentCylinder subroutine on line 79.
Sub ChangePersistentCylinder()
'randomly change radius and height
Randomize
Dim dblRadius,dblHeight
dblRadius=1+Rnd*7
dblHeight=5+Rnd*10
objPersistentCylinder.Radius=dblRadius
objPersistentCylinder.Height=dblHeight
End Sub
This function randomly modifies the radius and height of the cylinder, automatically redrawing. The last chunk of code made use of Public Property Get, this makes use of Public Property Let, and shows why you would use it.

Setting the Radius of the cylinder calls this code on line 36:
Public Property Let Radius(dblRadius)
'Set the radius
int_dblRadius=dblRadius
Redraw
End Property
The Property Let stores the entered radius in the internal radius variable, so that it can't get changed unexpectedly by outside code, and calls a Redraw function that deletes the cylinder and rebuilds it with the new dimensions.

There's a whole lot more to object-oriented programming, but this pretty much covers the features of VBScript classes. The only major feature I neglected is Property Set, which is just like Property Let except it takes an object as a parameter instead of a regular variable.

You can go crazy with arrays of objects and objects inside objects, and there are some details about using them that may trip you up, but these mechanisms are your building blocks.

Sunday, November 16, 2008

Recent Scripting Project



I've been working with Tube Guage Inspection Fixtures, Inc. on some scripting to assist with the Rhino design of their inspection fixtures, sets of wood or metal forms used for checking tolerances on piping, usually used in the automotive industry. A simple enough concept, a perfect situation for scripting automation, but there were enough details to handle that it was still about 130Kb of script.

The script works from a user-defined centerline and chosen dimensions to make a set of blocks under the straight sections of the pipe. It automatically adds clearances for tube bends, applies specific profiles to the end blocks, and formats 2D output with particular tool path requirements. It wasn't considered a good use of time to try to automatically adapt to all possible details, since they can vary quite a lot and these are made working from often dubious imported geometry, so I simply made it as simple as possible to make modifications.

Friday, October 31, 2008

PC game review: Grid

I’m a bit behind the gaming times. I don't have a video game system and just recently finally grew weary of shooting down police helicopters in San Andreas and had a hankering for a more serious driving game. Because it was available on Valve’s Steam service and decently reviewed, I opted for Grid from Codemasters.

Grid is marketed as being focused on driving. That’s code for not being able to tweak your car. That’s okay, it means that learning to win is a matter of driving, not manipulating a spreadsheet, though some would probably wish for more cars than the included 45, which isn’t that many when they’re spread out over disciplines ranging from Le Mans prototypes to drifting. However they do all handle distinctly while being “balanced” so that cars in the same class are more or less competitive, which is not realistic but does mean you might actually drive more than a handful of them regularly.

The other task is managing your team in the career mode, which consists of hiring and firing a teammate and juggling sponsors. Once a “year,” you get the option to run the 24 Hours of Le Mans, and it is appropriately gruelling, even if actually only 12 minutes.

The graphics are about as good as you can get without the hardware requirements of a Crysis. Cars—up to 20 per race--and hospitality tents literally glimmer in the sunlight. Bugs and tar accumulate on your bumper. The 3D spectators react if you crash into the wall in front of them. The cars have probably been made unrealistically durable to better show off the damage modeling that runs the gamut from scratches to missing body panels and crumpled suspension.

I can’t say how accurate the reproduction of the gear whine from a Koenigsegg CCX is, but pieces of bodywork that get knocked off cars will stay on the track, and if you run into them they might stick to your car and you’ll hear them flapping around. That’s adequate for me to rate the sound effects “excellent.”

The rest of the audio is my one big disappointment in the presentation, especially after spending a month or four on GTA. That may not be fair, but when the game yaps at you, giving you such useful information as explaining how fourth place is one step from the podium, I must assume the goal of such chatter must be to create atmosphere just like the radio stations in San Andreas. There is nothing close to what’s needed in the quantity or quality of quips from your crew chief, teammate, and business manager for them to do anything but get on your nerves.

As you’ve probably already gathered, Grid is not a hardcore simulation. It’s realistic enough that taking a high-speed turn in a new Dodge Challenger at about 130mph, going wide and having the wheels bite the gravel in a slight depression at just the right angle, will result in rolling eight times, losing a door and the windshield, shattering the mirrors, and caving the roof...but it’s still 100% drivable. If you do manage to bend a wheel into the passenger seat, you get a second chance with the Flashback feature, which lets you rewind the last few moments and restart from any point. If you turn off the electronic nannies there is a general air of realism, but the cars do accelerate and brake too fast, which I would extrapolate helps it tend towards a driving style a bit too much like off-road rallying(which makes sense considering where the physics engine originated.)

It’s definitely fun, though, and definitely challenging. It can be tricky to simply get the faster prototypes around a track without hitting anything and you can dial the AI’s skill level up to 11. Enter a race that you’re not quite ready for and the AI will quite deliberately push you out of its way. There are some real tracks and some fantasy settings, unless there really is a street course in Milan that goes through a cathedral.

Because I’m afraid of never getting any work done again I haven’t tried online multiplayer, though skimming user forums shows some concern about races turning into demolition derbies. The online feature I have used is the “test drive” mode where you can race against a “ghost” of your personal best time or the "world record," though there seem to be some glitches or cheating since the world record for most tracks is something less than one second.

Wednesday, September 3, 2008

Google Chrome

It looks like my order form has some trouble with the new browser. I don't know if it's my code or the Mootools library, it's probably early days to try much troubleshooting anyway.
UPDATE: It's working okay now, except that the product titles are overlapping the quantity input boxes.

Tuesday, August 5, 2008

Brazil Basics: Reflection Control and the Brazil Utility Material

Here's a little example showing the practical use of a few of Brazil's many, many settings.

I've been doing simple studio-type renderings like this of concepts for a client. Not concepts of sinks, but it will do. It's lit using the skylight and a single bright panel, with Global Illumination enabled but with just a couple bounces. The background is a gradient, but this would all work the same if I was using an HDR environment or whatever. The colors are intentionally 'odd' to highlight what's going on.
So what we have is the object on a plain, partially-reflective background. I used the Reflection Decay option under the Reflection Parameters on the floor to fade out the reflected sink. The floor is a Brazil Plane Primitive, set (not in the lower shot of course) as infinite.
So assuming this looks okay, the problem is that I want a pure white background.
To force the floor to be pure white, I did two things:
  • In the reflection parameters of the floor material, went to the Basic Reflection Control and checked the box labeled "Env:" This lets you set a different color or material for the environment the object is reflecting. I set the color to white.
  • Increased the Diffuse multiplier in the default material settings. The problem of course is that the shadow and reflection are 'blown out,' and it's lighting up the sink, which might be perfectly realistic, but this is not exactly about "realism."
This is where the Brazil Utility Material comes in. If we place the floor material inside a Brazil Utility Material, we can tweak, among many other things, the amount of lighting it emits and receives from global illumination. To do this, I created a Utility Material and assigned it to the floor object, then inserted the old floor material into the Base slot of the Basic material overrides section. I then scrolled down to the Global Illumination Parameters and reduced the Level and Saturation values for generating and receiving GI.

To completely remove the reflection of the pure white floor from the sink(which is not very realistic of course, but just to illustrate what you can do,) I went back to the Basic Material Overrides and inserted into the Reflected slot a copy of the original floor material, minus the adjustments.

Finally, to make the 'sky' pure white(with quicker render time than making the ground plane infinite again)I made a Single Color Texture and set it to white. I opened up the Environment section of the main Brazil settings panel, and inserted the texture into the Planar background slot of the Global Maps overrides. You can see it has no effect on the environment reflected on the object.
Here I switched the sink to a glass material and adjusted the ground plane to show the effect of the planar background setting.
With the planar background override turned on, you can see it has no effect on what's refracted or refracted in the glasss.
I posted a question about this on the Brazil support forum, thanks to Paul Sherstobitoff.

Monday, July 28, 2008

Simulation of a Prototype Part II

Here's a shot of a new iteration of the SLS Brazil material, the noise has been made 'bigger' and I tried to get more of a hint of the layer structure in the more vertical areas.

Saturday, July 26, 2008

A simulation of a prototype


I thought I'd try to make a Brazil material to approximate Selective Laser Sintering. Without some sort of actual displacement(which Brazil supports of course, though I'm not sure if that's even the answer to creating the 'stepped' appearance of the flatter areas of a rapid prototyped part, maybe it's best to simply brute-force turn the model into many many thin slices...)it's not going to look convincing up close, but at arm's length it's not too bad, the biggest problem with this shot being that the bumpiness on the rounder parts is too smooth and subtle. If I develop it a little more I might post a tutorial about it.

Wednesday, July 23, 2008

Revamping the website

I've been redesigning the hydraulicdesign.net site and have a test version posted. The content is not complete, the design needs tweaking, some of the images are placeholders or haven't been scaled so the load times may be insane...so essentially it's not done at all, but the new order form setup, which is the important part, does work and I'd like to hear comments. UPDATE: I just went live with it.

Tuesday, July 15, 2008

Flamingo 2

McNeel haven't made their official announcement yet, but (I am nonetheless authorized to say)that it is shipping now. The upgrade is $100 off for a limited time. See the order forms.

Monday, June 2, 2008

LG W2600H-PH first impression

Why is it so hard to find reviews of monitors? All my usual sources of hardware advice spend all their time on things like motherboards and RAM, taking 20 pages comparing products that perform within 2% of each other.

I picked this up yesterday primarily because it was on sale at Future Shop. My old LCD, which was my first LCD, is a 2004 vintage 20" Viewsonic VP201s, so I'm looking for something bigger. The 25.5" LG W2500H is certainly a nice size, and it does do a better job at DVD playback, but otherwise it's rather disappointing. I guess it wasn't a good sign to find that it only came with an analog cable, what sort of miserable bean-counters decide to ship a monitor in 2008 without a bloody DVI cable?

I knew there had to be a reason why it's half the price of something like the only slightly bigger Samsung 275T--and indeed not far from half what my old LCD cost new--but I guess I was expecting to see more progress in four years than simply being cheaper and bigger. Compared to my 4-year-old monitor, the viewing angles are worse and the colour...oh, the colour. It's shocking how bad it is. It's like a jumbo version of a cheap laptop panel. Wait, no, I'm writing this on a cheap laptop and it's capable of showing a bright red as red, not hot pink.

If I keep it it will only be because nothing else in the same size and price range would be much better, at least I can still use my old LCD for anything where colour matters.

Wednesday, March 19, 2008

Recent Project

Lately I've been working quite a bit with with the marketing firm Lulham Black on bottles for various household products for Simplicity Clean.

Saturday, February 9, 2008

Accelerated Rhino Training

The standard Rhino Level I and II training courses are each scheduled for three days. What I've found through recent experience is that, at least for small groups, two days is quite adequate, so that's less time off work for you or your employees. Level III training, based on my own material, can also be squeezed into two days, it's a matter of focusing on your needs.

I can come to your office or you can travel to Ottawa, Ontario. Contact me for more information.

Tuesday, January 22, 2008

Are you going to be in Berlin this April?

A German Rhino reseller, Visual-Dream, is presenting a Rhino-centred 3D modeling symposium from April 7-9 at the Universität der Künste Berlin. Among the participants will be yours truly, putting on an advanced modeling "master class" about using Rhino for concept development.