Saturday, 8 August 2015

3D Pipes - Maya edition!

If you haven't already watched our video for Delta Heavy's track Ghost then...do.

Lots of fun to make, one of the parts I was most excited by when Chris walked us through the animatic was working out how to recreate some classic Windows screensavers in Maya. I know that anyone who used a computer in the late 90s spent an unhealthy amount of time staring at these so I knew they'd have to feel authentic.

Firstly, the most famous one is probably 3D Pipes:

Now obviously this would be fairly straightforward to just build and animate, it just some cylinders and spheres. However that's
A: No fun
B: Incredibly time consuming

We only had 4 weeks start to finish on this job and there were over 70 shots to get done, so I opted to write a nice script to build the pipes for me. Unfortunately, time constraints meant I ended up building an embarrassingly messy script to build the pipes for me... Well, that's the realities of production, and it was a one use script so, hey-ho.

Fortunately, it's possible to actually get the original source for all the windows screensavers by downloading the NT 4.0 SDK. This gave me a lot of the parameters I needed to get the pipes looking right.

  • We have 3 objects, longPipe, shortPipeJoint and endSphere. 
  • Step forward placing longPipes, 
  • Every step there's a 1/5 chance we'll turn in a random direction
  • If the next step would collide with an existing pipe we have to turn
  • When we turn there's a 1/3 chance that we place a sphere and a long pipe rather than a joint
  • If there's nowhere left to go, stop

Putting this into Maya I wanted to use some premade meshes I'd created, place them in space, and animate their visibilty. I also needed to record their positions so we could keep running the script to create new pipes.

So, to jump straight into the code:
def makePipe(steps=10, startpos=(0,0,0), starttime=0, timestep=1, length=7, turnChance=0.2):
    longPipe = "longPipe"
    shortPipeJoint = "shortPipeJoint"
    endSphere = "endSphere"
So, starting off the main function, we've got a bunch of default arguments and define the names of the objects we're going to place.
    pos = startpos
    DHPipes.append(pos)
    dir = random.choice(directions)
    prevdir=dir   
    t=starttime
    grp = cmds.createNode("transform", n="pipes1")
    last = grp
We initialise our variables we're going to update in the main loop with the arguments passed into the function. Also, we create a group to keep everything nice and tidy.
for s in range(steps):       
        mv = getMove(dir, length)
        nextPos = addTuple(pos, mv)

        if random.random()<turnChance or nextPos in DHPipes:
            prevdir=dir
            dir=random.choice(possibleDirs(dir))
            mv=getMove(dir, length)
            nextPos = addTuple(pos, mv)
 For each step we work out what the move will be. getMove just multiplies each item in dir by length. In hindsight I'm sure there's a neater way of doing that, maybe someone will tell me in the comments. Really it should just be called scaleTuple... Then, get the next position with addTuple (guess what that does)
while nextPos in DHPipes and i<20:
    dir=random.choice(possibleDirs(dir))
    mv=getMove(dir, length)
    nextPos = addTuple(pos, mv)
    i+=1 
Next we check that we're not about to hit an existing pipe. DHPipes is a list of all positions of existing pipes. If we are we get a random direction to turn in (possibleDirs returns a list of directions which aren't forward or back from our current direction). I iterate i and check against it in the while because...well. I tend to always mess up whiles, cause an infinite loop and crash Maya. I just have that for safety.
    if nextPos in DHPipes:
                print "Nowhere to go, so I'm stopping"
                break #give up, we can find a way to go 

            if random.random() < 0.3333:
                new = cmds.duplicate(endSphere)[0]
                cmds.parent(new, grp)
                cmds.setAttr(new+".translateX", pos[0])
                cmds.setAttr(new+".translateY", pos[1])
                cmds.setAttr(new+".translateZ", pos[2])
                cmds.setKeyframe(new+".visibility", v=0, t=t-1)
                cmds.setKeyframe(new+".visibility", v=1, t=t)
                obj = longPipe
                rot = longRot(dir)
            elif dir!=prevdir:
                obj = shortPipeJoint
                rot=elbowRot(dir, prevdir)
            else:
                obj = longPipe
                rot = longRot(dir)
        else:
            obj = longPipe
            rot = longRot(dir)
           
        new = cmds.duplicate(obj)[0]
        cmds.parent(new, grp)
        cmds.setAttr(new+".translateX", pos[0])
        cmds.setAttr(new+".translateY", pos[1])
        cmds.setAttr(new+".translateZ", pos[2])
        cmds.setAttr(new+".rotateX", rot[0])
        cmds.setAttr(new+".rotateY", rot[1])
        cmds.setAttr(new+".rotateZ", rot[2])
        cmds.setKeyframe(new+".visibility", v=0, t=t-1)
        cmds.setKeyframe(new+".visibility", v=1, t=t)
        pos = nextPos
        DHPipes.append(pos)
        t+=timestep
This last bit does the meat, it decides which object we're going to place based on the direction we're now moving in, then duplicates the base object, moves it to the right position and rotates it. longRot and elbowRot gets the rotation needed. I'd like to say I did the maths for allthat, but it was quicker to just do it by hand and hard code it. Deadlines!

That's about it for 3D Pipes. I'm slightly concerned I just wrote quite a long, boring blog post on what is quite a simple script, but... it's my first time! Hope someone finds it useful/interesting. I'll try to get better at this. I'm write up a quickie about the flowerbox screensaver shortly. That one's less code, more Maya, and it's pretty straightforward so should be a shorter post.

Thursday, 6 August 2015

Delta Heavy - Ghost


No wait, not this.
Very excited to announce the release of our latest music video. Directed by Chris Bristow for the Delta Heavy Track 'Ghost', we follow Clippy on a journey through the dying ancient world of the 90s internet into today's modern 'cloud' full of smileys, porn and cats.


It was an absolute blast putting this together, we haven't had a chance to much full CG work in the studio so it was really fun getting to dive right in. We had 4 weeks and 6 crew working flat out for 70-odd shots and 4 minutes of final film. My next post will be a technical breakdown of a couple of the shots.


Thursday, 2 July 2015

Belated third post...

Well, I've so far done this Every. Single. Time. with every blog I've ever tried to start. two posts, then forgotten. I'm also a little embarrassed to see I have more than the 5 views I assumed I had. So, here's me second resolve to actually post things.

Just to kick things off I'll do a quick recap of what's happened since my last (and first) posts. I'm still at Blink working in the studio. Things have been going really well there, lots of great jobs! We've grown the team loads and there's a nice, positive direction that we're headed in. (in which we're headed?)

Some highlights I've been involved in to various extents over the past two years (I'll do some posts about a few of these in retrospect):
John Lewis - The Bear & The Hare
Francois and the Atlas Mountains - The Way to the Forest
Jose Cuervo - The Alchemist
Twinings - Drink it All In
Grolsch - 400 Years
Clipper - Naturally Colourful

There's a bunch more nice jobs we've done which I've had less of a hand in. Also, we've got a couple in the works right now which I'm really excited about. 

Monday, 1 July 2013

Sandy - Joseph Mann

Also recently released is Sandy - a short film by Joseph Mann. Check out the film in full on his website or on the Blink Ink site. I joined the project in post-production and didn't get my hands quite as dirty as some of the others working on it. However, I did some pipeline R&D at the start and managed to comp a couple of shots.

I'm particularly pleased with my sparkling sea at the start. Nice to dust off the After Effects skills from time to time! For that also I'll post a little tutorial as someone might find that useful. It'll all be text and images I'm afraid - not a huge fan of video tutorials.

Monday, 3 October 2011

Arctic Monkeys Waveform

Quite an exciting one for my first post, well for me at least. Check out the new Arctic Monkeys music video for Do I Wanna' Know to see my first bit of production code in action. At the Blink studio I was asked to develop a rig to easily animate a stylised waveform by director David Wilson. You can see it below - it's a pretty big bit of the video which gives me a kick.


You can also see it at the beginning of their headline Glastonbury set on iPlayer for a bit! That was very cool to watch - it's a really good set too. I'm going to try to do a quick write-up on how the rig works. It's not that complicated but hopefully there'll be something interesting or useful in there! Hopefully I'll be able to put that up here soon.