Tags

, , , , , , , , , , , , ,

Arkwood sang, ‘Deck the halls with boughs of holly,’ as he put some silvery tinsel around the Christmas tree. ‘Fa la la la la, la la la la!’

I asked him why he was so merry. Turns out he’s been on the festive sherry. ‘How’s the robot going?’ he asked with a big beaming smile, if slightly slurred, and draped a lazy arm across my shoulders.

The robot is going fine. In my last post, Blender animation in OpenGL (Mark II), I created an animated 3D robot in Blender. I imported the robot into SaltwashAR – my Python Augmented Reality application – using auto-generated code to optimise the loading of OpenGL display lists.

‘What’s next?’ Arkwood enquired, a double whiskey now sloshing in his sherry glass.

Next, my dear friend, I want to make the robot talk!

In actual fact, this is quite straight forward. In Blender, we simply need to put a texture over the robot’s face. Here’s the robot with a passive face:

rocky_robot_head_passive_01

And here’s the robot blinking (notice the eyes are narrow):

rocky_robot_head_passive_02

Cool. With similar principles to the previous post – where our auto-generated code made the robot’s head bob up and down – we can make the robot blink her eyes.

But what about the robot speaking? Here’s the two textures we will flip between to animate her mouth:

rocky_robot_head_speaking_01

rocky_robot_head_speaking_02

We can update our AR application to load the passive and speaking versions of our robot:

def load_frames(self, is_animated):
    self.body_frame = rocky_robot_body_frame()
    self.head_passive_frames = rocky_robot_head_passive_frames(is_animated)
    self.head_speaking_frames = rocky_robot_head_speaking_frames(is_animated)

And to render the next frame of the robot in passive or speaking mode:

def next_frame(self, is_speaking):
    glCallList(self.body_frame)

    self.head_frame_index += 1

    if is_speaking:

        if self.head_frame_index >= len(self.head_speaking_frames):
            self.head_frame_index = 0

        glCallList(self.head_speaking_frames[self.head_frame_index])

    else:

        if self.head_frame_index >= len(self.head_passive_frames):
            self.head_frame_index = 0

        glCallList(self.head_passive_frames[self.head_frame_index])

The is_speaking boolean parameter allows us to specify whether we want to display a chatty or mute android.

Anyways, enough of the code. Let’s talk to our robot. And marvel as she talks back to us with a moving mouth!

Terrific! Rocky Robot blinks when she is passive, and moves her mouth when she speaks. Sporty Robot acts in a similar way too.

‘Arkwood!’ I shouted, ‘Come and see the robots talk!’ But the damn fool had passed out in the parlour with a box of chocolate liqueurs strewn across the carpet.

Ciao!

P.S.

I have updated SaltwashAR on GitHub with the code from this post (and amended the documentation accordingly).

I ran the code on my Windows 7 PC using Python Tools for Visual Studio.

Any questions, drop me a line.

Advertisements