Some handy String extension methods

Extension methods - don't we all just love them. If you've been out of the .Net 3.5 loop, here's some catching up - Extension Methods (C# Programming Guide). I thought i'd share some handy string extension methods i've come to love during my experience with C# 3.0. I've never been quite fond of the static String.IsNullOrEmpty method, but thanks to extension methods i can now turn it into an instance method as extension methods can be called on null values as well.

public static class StringExtensions
 public static string GetValueOrEmpty(this string @string)
  return @string.IsNullOrEmpty() ? String.Empty : @string;

 public static string ToSingleLine(this string @string)
   return String.Empty;

  string singleLineString = @string.Replace(Environment.NewLine, " ");
  return singleLineString;

 public static bool IsNullOrEmpty(this string @string)
  return String.IsNullOrEmpty(@string);

If you have any nifty extension methods that you'd be willing to share, let the readers know through the comments.


Discovering ReSharper live templates

Let me start this off by saying - ReSharper live templates are what Visual Studio's code snippets should have been all along. Namely ReSharper's live templates allow the programmer to create powerful custom templates for multiple situations - regular, surround and file templates. It's also possible to use variables (%variable_name%) and make them either user editable or assign a macro to it. The word "macro" here is a bit deceiving. The macros used inside live templates aren't regular Visual Studio macros, rather ReSharper's own .Net macro classes implementing the JetBrains.ReSharper.Feature.Services.LiveTemplates.Macros.IMacro interface. To think about it - this allows for much greated capabilities within macros and better packaging.

One might not recognise his or her bad habbits until someone specifically points it out to them. Something like this happened to me regarding the use of a TODO snipper i've been using. The bad habbit - having to type my name and current date every time the snippet is inserted and being completely oblivious to the fact that there are better ways of doing this. As a coworker pointed out that he's using ReSharper's live templates, i started looking into them and it didn't take long to find out there were powerful ways to extend the templates. Long story short - here's my implementation of the TODO snippet - download the template XML.

This template demonstrates quite well how to use three different types of variables: ones which are user editable, ones which have a constant value assigned to them and ones which retrieve their value from a macro. To use this template save the XML above in a .xml file, open the live templates editor from the ReSharper menu and import the XML file.

P.S. - this post was written in Visual Studio 2008 on a Lenovo IdeaPad S10e running Windows 7 (all visual effects enabled) - combined memory consumption - 800 Mb. Let me end this post by saying - Windows 7 is what Vista should have been all along.

Helping a brother out,

3D - a thing of wizardry and black magic

How many times have I had to explain to someone how to create and render 3D imagery? Well - a lot. Luckily I'm not the only one having to do all the explaining. So these guys came up with an ingenious idea of creating a website which gives all the info about taking the first steps in 3D. And this is all done in a very general fashion so that the techiques learned from the videos could be applied to whichever major 3D application (Cinema 4D, Maya, 3D Studio Max, Lightwave, Softimage, Blender etc). Here's the site itself - The Guerrilla CG Project - Computer Graphics Fundamentals. Now, whenever someone asks how this 3D stuff works, I simply send them this link. There - one less thing to worry about :)


Modeling a car - a quick run-through

I wrote this little instructional how-to at CGSociety on the topic of modeling a car in a poly-modeling fashion and thought it might be a good idea to make it a blog post. This question get's asked quite ofter - what is your modeling workflow like, so here's how I do it.

First step is to create a splinecage. This consists of setting up the blueprints and getting them aligned on all four planes - side, top, front and back. Then it's just a matter of creating splines where the edges run on the car. For the body panels I draw the spline e.g. for the hood in the top view, then go into side and front view to get the splineS bent exactly how it should be in all three dimensions. But take great care at this step as it is NOT a no-brainer to change splinecage once you start building the mesh on top of it.

Second step is not always that straight forward. I now have a spline cage in place which I can use for points snapping when creating plygons. Sometimes to understand the mesh flow better, I do some wireframe paintovers on some reference photos in photoshop with my wacom. But do remember that this step cannot be taught in my opinion, this can only be learned through practice. Then I create a single polygon which basically covers the particular area in the most simplistic fashion. e.g. for the door panel I just create a simple quad which stretches out into all the corners of the door panel. Then comes the cutting and finetuning. I then do the cuts in the polygon where they're necessary e.g. the crease in the door, more edges to achieve the curvature etc. Never manually place the points on the edges of panels, only use snapping to the splinecage!!!

At this point you should have the main body panels created, but without the bevel on the edges, which gives a nice thick feel to the body panels. This totally boils down to the tools that your particular applican offers. The end result for the panel edges and corners should look something like this:

There's one row of polygons going inwards and there are two rows of polygons on the surface edge of the body plate. The two polygon rows have a total width of about 2,5-3,5 mm. To produce the edge bevels in Cinema 4D I use the following steps:

  • select all polygons
  • clone
  • extrude inward or do a negative smooth shift of about 1,5mm
  • delete the cloned polygons
  • optimize to weld overlaping points at the newly created crease
  • the outer facing polygons I extrude inner for two steps, 1-1,5mm each
  • add the necessary cuts at the corners to crea a sharp corner

As for all the rest of the points on the bodyplate that aren't exactly on the splinecage, there I use the brush tool in smear mode with very low strength to give minute adjustments where necessary. This is the most time consuming part of the whole process as one change needs to be view at and adjusted from all the angles. It's also possible to use the iron tool or the brush tool in the smooth mode to achieve some inital smoothing from which to work onwards.

I hope this gives a little more insight into the way I model. Look forward for more modeling tutorials covering some very specific subjects like proper edge beveling, sharp corner modeling etc. And don't think this tutorial applies to only cars - the described process can be used to produce almost any hard surface(non-organic) object.


New FeedBurner feed

I have transfered my blog's feed over to FeedBurner. The current feed redirects all already subscribed users to the new feed. Here's the link -

Discovering the blogosphere,

Need more brains!!!

There's this subject that i find utterly fascinating lately - brain studies. The way neuroscientists study the jelly in our heads is by analyzing patients with very a specific kind of brain damage. They can then understand and locate which part of the brain is responsible for what behaviours.

One of the leading neurologists and my personal favourite in this field is Vilayanur Ramachandran. I've included a bunch of videos of him below. Some keywords of his work - phantom limbs, synesthesia, capgras delusion etc.

I'd like to point out one of these phenomenons - synesthesia. This is something that almost everyone of us possess but are unaware of until someone specifically mentions of its existance. When someone is any type of a synesthete (a person who has synesthesia), their brain has formed connections between seemingly unrelated subjects. For example - i have grapheme a.k.a color synesthesia for numbers and colors. The way this phenomenon manifests itself is when i think of a number i get a sensation of a specific color. Some numbers have very distinct colors while others have rather dull or faded, sometimes even undistinguishable tones.

On a more general term synesthesia allows us to engage in metaphorical thinking. Take for example a statement - "that's a blazin' car". Normal people wouldn't automatically assume that the car is on flames, rather that the car is nice looking. It'd be nice to hear from you, the readers, about your relationship with synesthesia, so feel free to leave a comment.

I've gathered together a portion of videos and articles that do quite well at explaining the peculiarities in our heads. The audio on "Phantoms In The Brain" is a bit off sync, no need to be put off by this.

I guess what i'm trying to achieve with this post is to create some interest in people in how the mysterious thing called brain functions. Far too often do we see people who carry symptoms of abnormal brain behaviour get ridiculed and called names by others who lack the knowledge of what's really going on in someone's head. So don't be too quick to judge and jump to conclusions - be open minded, learn and if possible offer some guidance and assistance.

Keeping my mind open,

Modeling away...

So there are still two topics yet uncovered - 3D and Saabs. Why not kill two birds with one stone. Here are some links to my never-ending 3D projects:

It's also quite rewarding to have my Milla model featured at the 3D Buzz website's weekly news feature :)

Trying to stay atop all things interesting,