LEAP intergration with blender game engine

So i go my devkit and my device the the other day, and i’ve been working hard on learning python, not only “standard” python but BGE python.

and then i took a look at the python api for the LEAP device and i’m completely confused.

here is the python api https://developer.leapmotion.com/documentation/guide/Sample_Python_Tutorial

I was wondering if anybody could explain this or help me out with it?

thanks

I can’t see the tutorial as that page is only for LEAP developers. The tutorial should be relatively straightforward. Is there something in particular that you’re having trouble with?

Oh right i didnt think about that,

Ok so i know this will sound noobish, but for example to gather or listen to data from the leap you use this:[TABLE=“class: memberdecls, width: 100%”]
[TR=“class: memitem:a67da9febb33a6104864b5196f33d02ae”]
LEAP_EXPORT
Controller (Listener *listener=0)
[/TR]
[TR=“class: memdesc:a67da9febb33a6104864b5196f33d02ae”]

Creates a Controller instance.
[/TR]
[/TABLE]

The question is do i type it just like that? or would i use it to assign a variable say:
listen = LEAP_EXPORT.Controller(Listener*listener=0)

here is some more info
[TABLE=“class: memberdecls, width: 100%”]
[TR=“class: memitem:a67da9febb33a6104864b5196f33d02ae”]
LEAP_EXPORT
Controller (Listener *listener=0)
[/TR]
[TR=“class: memdesc:a67da9febb33a6104864b5196f33d02ae”]

Creates a Controller instance.

[/TR]
[TR=“class: separator:a67da9febb33a6104864b5196f33d02ae”]

[/TR]
[TR=“class: memitem:a5796b988806ea9fd94e2d987e0e24b32”]
LEAP_EXPORT Frame
frame (int history=0) const
[/TR]
[TR=“class: memdesc:a5796b988806ea9fd94e2d987e0e24b32”]

Returns a frame of motion tracking data from the Leap.

[/TR]
[TR=“class: separator:a5796b988806ea9fd94e2d987e0e24b32”]

[/TR]
[TR=“class: memitem:abbb48ad47a8d0859a6a98f48c3d0a322”]
LEAP_EXPORT Config
config () const
[/TR]
[TR=“class: memdesc:abbb48ad47a8d0859a6a98f48c3d0a322”]

Returns a Config object, which you can use to query the Leap system for configuration information.

[/TR]
[TR=“class: separator:abbb48ad47a8d0859a6a98f48c3d0a322”]

[/TR]
[TR=“class: memitem:a9a72878aa5e16b219693402089b5c221”]
LEAP_EXPORT Listener *
listener () const
[/TR]
[TR=“class: memdesc:a9a72878aa5e16b219693402089b5c221”]

Returns a pointer to the Listener instance associated with this controller, or a null pointer if no listener is associated.
[/TR]
[/TABLE]

I guess my question is how and in what order/way do i arrange these functions?

That looks like C++. Isn’t the link you posted to Python? Does it use C++ to communicate with the device?

Your absolutely right, I apologies No its just a wrong link, it said learn more about controller, functions, and i guess it transferred me to the c++ page, being a beginner at python, I couldn’t tell the difference until you pointed it out. :slight_smile:

Okay so here is small example script from the python section (BELOW)
so it seems somewhat understandable but there is also other stuff that goes with it further down the page, witch you then combine into one script (i’m assuming). But how would you take this and translate it or incorporate it within blender, cause i know there are specific functions and what not that you have to use in blender.

def main():

Create a sample listener and assign it to a controller to receive events

listener = SampleListener()
controller = Leap.Controller(listener)

Keep this process running until Enter is pressed print “Press Enter to quit…”

sys.stdin.readline()

The controller must be disposed of before the listener

controller = None

Snippets aren’t very useful, since I don’t know what SampleListener or Leap.Controller are (though I assume the Listener is for listening for events, and the Controller represents the device). The tutorial should present you with a line-by-line explanation of what’s going on. If you’re having trouble, try looking through more of the tutorial before trying to understand what each individual line is - get an idea of what the whole tutorial / source does.

Ok, will do, I just not sure how much of it I can paste, it doesnt seem like they want you to.

Yeah, they probably don’t (hence only developers can access the API, and not everyone). If you’re having trouble, perhaps you should learn a bit more about Python before approaching integrating an API into the BGE. I think you should try learning about general Python classes, if you don’t know about them. I believe that’s what SampleListener and Leap.Controller are referring to.

Looks almost like Second Life’s limited Linden scripting language,
You can’t call out a function unless it’s conditions are met,
in second life

llListen(integer -Channel,string -Message,key -sender UUID,string name);
then anywhere in the script
if Message=“Fire” {Do X}

or something like that,
I am not sure if C++ is real time object oriented programming, or linear,

Ok my next question is how to get the leap python module, etc. to install into python, the bundled python that comes with blender. Ive tried doing it but it still brings up airs in the scripts.

I get this error msg when i try to run a leap sample python script in blender Im assuming this is because the leap package is not installed into this bundled python

Attachments


The first problem is that this script is written for Python 2.x (as is evident by the use of the “print” statement, as opposed to the print() function in 3.x)
You should read about porting applications from Python 2.x to 3.x, it might be as simple as changing those print statements.
However, if the leap package is not just a simple C extension module, but rather contains Python 2.x code, you would have to change all that code as well, possibly using the automated 2-to-3 tool. (Unless the leap people provide a version for 3.x, of course)

That’s all an annoying consequence of the stupid idea to break compatibility in Python 3.x, which blender uses exclusively. A lot of (most?) people still use Python 2.x and don’t bother supporting both versions.

In order to get the leap module to be loaded into the bundled python, you can use sys.path.append or you can look for the site-packages of the bundled python. (Which is probably located in the 2.6x/python/lib folder of your blender installation).

Ya i noticed that and I changed the print statement, after I posted this. Its really weird why they changed that but

so in the blender version i’m using its a portable build, so i just copy the lib folders for the leap python into the lib under 2.6x ?

these are what is included in the SDK for python

Attachments



It depends a lot on how they interface between Python and C++.

  1. If they use ctypes to call into the DLL, then it should work (except for Python syntax differences, but the 2to3 tool may help there).
  2. If they call into the Python/C API, tough luck, it won’t work.
    How to find out whether it is 1. or 2: Search for “ctypes” within the .py files (1.), or look for files ending with .pyd (2.)

Good luck, you got yourself one hell of a hard project!

Just for reference, the LeapPython.pyd is compiled C code, which means you will be extending Blender with an external library. You cannot publicly release anything you make this way unless the LeapPython.pyd library is licensed with a GPL-compatible license, otherwise you will be violating Blender’s GPL license. See the Blender FAQ “What About My Python Scripts” for clarity on that:
http://www.blender.org/education-help/faq/gpl-for-artists/#c2129

My guess is that LeapPython is not GPL compatible, which would be a shame as far as BGE dev is concerned. Perhaps you could look into linking it into gamekit?

If the Leap is recognized by the computer as a normal pointer or joystick, then you might be able to check it yourself (I’m guessing the Leap provides helper functions, like the ability to check for a swipe or a hovering motion, or similar functions).

@blendenzo I didnt even think about that, I will most likely have to use gamekit then.

@Sol i dont think it has any gesture based things its just continues tracking, witch in some ways is good and bad, I guess.

If you really want to make a hard break between the compiled LeapPython.pyd and your Blender python scripts I could imagine you put the Leap data you want on a port and use sockets or something to send and receive data. It will just be an annoying hassle because you need to have a second program to put the data on a port. This option might also help you with the python versions since it does not matter which program is sending the data and I expect you can use 2.x for that and receive data in 3.x.

Of course nothing is stopping you from using gamekit.

There is nothing wrong with that statement, but often when you make a change in a statement and that there is another error still there or you have removed something, python is looking for that something till it realizes it can’t find it so another error is noted in the following statement.

print("2000 - This line is not good!) # missing quote at end of text.

ya just adding parenthesis around the print text solves that problem, however lots of others come up after that.