I live in my own little world. But its ok, they know me there.

Unicorns and Jedi Controls

This is a test project with unicorns i made in cinema that i am controlling with a leap motion controller. I used the with the leap developer SDK, and adapted it slightly to send out position data for each finger over UDP. I have tried to send data directly from a leap to my 3d software, but to no avail.

(sorry the video is quite bad, i’ll film a better one soon)

Here is the code from the leap:


import Leap, sys, thread, time

import socket

fingerDict = {}

UDP_IP = "" #local host
UDP_PORT = 7864

#sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
#sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))

class SampleListener(Leap.Listener):
finger_names = [‘Thumb’, ‘Index’, ‘Middle’, ‘Ring’, ‘Pinky’]
bone_names = [‘Metacarpal’, ‘Proximal’, ‘Intermediate’, ‘Distal’]

def on_init(self, controller):
print "Initialized"

def on_connect(self, controller):
print "Connected"

def on_disconnect(self, controller):
# Note: not dispatched when running in a debugger.
print "Disconnected"

def on_exit(self, controller):
print "Exited"

def on_frame(self, controller):
# Get the most recent frame and report some basic information
frame = controller.frame()

for hand in frame.hands:

# Get fingers
for finger in hand.fingers:

#print "%s finger" % (self.finger_names[finger.type])
fingerType = self.finger_names[finger.type]
# Get bones
for b in range(3, 4): # distal bone is the finger tip
bone = finger.bone(b)
#print " Bone: %s: %s" % (self.bone_names[bone.type],[1]) # obtain just the y value of the fingers
ypos = (int([1]))

fingerDict[fingerType] = ypos
MESSAGE = str(fingerDict)
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))

if not frame.hands.is_empty:
print ""

def main():
# Create a sample listener and controller
listener = SampleListener()
controller = Leap.Controller()

# Have the sample listener receive events from the controller

# Keep this process running until Enter is pressed
print "Press Enter to quit…"
except KeyboardInterrupt:
# Remove the sample listener when done

if __name__ == "__main__":


And here is the receiver code in cinema applied to 5 cloned unicorns:


import c4d

from c4d.modules import mograph as mo
import socket

UDP_IP = ""
UDP_PORT = 7864

def main():
md = mo.GeGetMoData(op)
if md is None: return False

cnt = md.GetCount()
marr = md.GetArray(c4d.MODATA_MATRIX)

fall = md.GetFalloffs()

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
#print "received message:", data

fingerdictC4D = eval(data) # convert to dictionary again from string
fingers = [‘Thumb’, ‘Index’, ‘Middle’, ‘Ring’, ‘Pinky’] # list to sort the dictionary
#get position y of each unicorn
marrNew = [] # new vectors matrix
for im,m in enumerate(marr):

positions = #obtain position data
xpos = positions[0]
ypos = positions[1]
ypos = fingerdictC4D[fingers[im]]
zpos = positions[2]

off = c4d.Vector(xpos,ypos,zpos)
newMatrix = c4d.Matrix(off)

#set new position vector with new leap yposiiton
#create new matrix
#append matrix to empty list
#set new y position for each clone

setNewArr = md.SetArray(c4d.MODATA_MATRIX,marrNew,False) # set new cloner matrix

#each finger is linked to each row


Next Post

Previous Post

1 Comment

  1. George Martin Jr March 15, 2019

    Hello there,

    My name is George, and I was wondering if you would like to have your website promoted as a resource on my blog ?

    We are updating our broken link resources to include up to date resources for our readers. Our resource links are manually approved as a do follow link.
    If you are interested in having your site included as a resource on our blog, please let me know.


© 2023 anam-ation

Theme by Anders Norén