python script to extracts all the shape key related information out of blender character into JSON format

Hello to everybody. I'm interested to learn how to make a facial animation using WebGL + Blender + Python. I've found a nice WebGL animation and I've mirrored the files from
the github rep located at this address :

https://github.com/antonpantev/webgl-shape-keys

I would like to understand how it works. To do it I've tried to change the blender character that the author has used with this :

http://www.blendswap.com/blends/view/68458

To do this I need to understand how works the export_shape_keys python script that he wrote to extracts all the shape key related information out of a blender character into JSON format. When I run the script on my Ubuntu 13.04 terminal window I see that the mouse cursor changes appearance because it gets ready to accept a mouse click. When I click somewhere on the screen the script ends giving these errors :

root@mario-ThinkCentre-XXXX:/home/marietto/Scrivania/taxi_driver#
./export_shape_keys.py
./export_shape_keys.py: line 4: OUTPUT_DIRECTORY: command not found
./export_shape_keys.py: line 5: PRECISION: command not found
./export_shape_keys.py: line 7: syntax error near unexpected token "("
./export_shape_keys.py: line 7: `def getTextureCoords(texture, fIndex,
vInFIndex):'

can someone help me to fix them ? Again,on the beginning of the script there are these two lines :

import bpy
import os

I've changed the OUTPUT_DIRECTORY parameter with this :

OUTPUT_DIRECTORY = /home/marietto/Scrivania
PRECISION = 6

but the errors happen again. What's the meaning of bpy and os ? Are they libraries ? Where can I find them ? When the mouse cursor change appearance and I click on the screen,two files called bpy and os are produced. I don't know which kind of files they are and I don't know which kind of application can open them.
LVL 2
marietto2008Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

marietto2008Author Commented:
I've attached the export_shape_keys python script....
export-shape-keys.py
0
peprCommented:
I do not know the framework/environment... How exactly you launch the script? Does it contain the #! info at the first line? Or do you explicitly launch it via python? Or it is launched from another Python script?

Definitely, the path is a string and must be enclosed or in single or in double quotes like this:
OUTPUT_DIRECTORY = '/home/marietto/Scrivania'

Open in new window

or
OUTPUT_DIRECTORY = "/home/marietto/Scrivania"

Open in new window

(You can choose -- both alternatives produce exactly the same result.) The PRECISION variable is OK. Integer values are used this way also in Python.

However, if the script is interpreted by a non-Python interpreter, anything could happen.
0
marietto2008Author Commented:
I launch the script like this :

root@mario-ThinkCentre-XXXX:/home/marietto/Scrivania/taxi_driver# ./export_shape_keys.py
./export_shape_keys.py: line 4: OUTPUT_DIRECTORY: command not found
./export_shape_keys.py: line 5: PRECISION: command not found
./export_shape_keys.py: line 7: syntax error near unexpected token "("
./export_shape_keys.py: line 7: `def getTextureCoords(texture, fIndex,
vInFIndex):'

Check the script by yourself. I've attached it on the previous message. What's the meaning of bpy and os ? Are they libraries ? Where can I find them ? When the mouse cursor change appearance and I click on the screen,two files called bpy and os are produced. I don't know which kind of files they are and I don't know which kind of application can open them.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

peprCommented:
The os is a standard module. You can find its file in your python/Lib/os.py. When importing, the .py extension is not used in the source. Importing it means that you can use its functionality in your own code.

The bpy is the Blender module for Python. It is not the part of the standard Python distribution. You have to download the neccessary files and install them (probably from here http://www.blender.org/documentation/blender_python_api_2_59_0/info_overview.html).

On launching your export_shape_keys.py, it seems that the script was made executable via chmod. However, it seems it has no #! first line inside. I am not sure but I guess it tries to interpret the conten by your bash or another Unix shell. Or you have to add the first line like #! /usr/bin/env python, or you can launch it via explicitly passing the python script to the Python interpreter on command line:
python ./export_shape_keys.py

Open in new window

0
marietto2008Author Commented:
What should be the goal of this script ? Maybe I miss something. I can tell you what I would like that it did,please tell me if it does. I would like that it was able to generate a file containing all the coordinates of a blender character part,like the one that I have attached here. It contains the coordinates of this blender character's eye :

http://www.blendswap.com/blends/view/41157

Anton Pantev has used it to build the WebGL facial animation that you can see here :

http://www.antonpantev.com/shapekeys/
Eye.001-0.js
0
marietto2008Author Commented:
.
0
peprCommented:
I have no experience with the Blender tool. I can help you with Python. Anyway, the Eye.001-0.js is apparently generated javascript that is used for storing the data. The format is called JSON (JavaScript Object Notation), and it is used for data interchange. You can think about it as about a text file that is capable to capture identifiers, data, and the data types. (Another alternative is a XML file.)

In Python, there is the json standard module in Python. Similarly, there are the like libraries for other programming languages. This way, the format that looks like JavaScript-only is actually the form to transfer the data reliably not only over the network, but also from a programming language to another programming language.

Otherwise, JSON is not directly related to Blender, and I do not know the details of Blender. I do not know how the data for the Eye.001-0.js was generated by the Blender. Definitely, Blender generated the data somehow, and then it used a JSON library to write the data in the Eye.001-0.js form to the file.
0
marietto2008Author Commented:
Yes. Here you can find another version of the same kind of script :

https://gist.github.com/paulkaplan/5209228

I tried to run it,but it didn't work :

root@mario-ThinkCentre-XXXX:/home/marietto/Scrivania# ./shapeKeysToJSON.py
from: can't read /var/mail/json
./shapeKeysToJSON.py: riga 9: syntax error near unxeptected token "("
./shapeKeysToJSON.py: riga 9: `encoder.FLOAT_REPR = lambda o: format(o, '.15g')'

Again,as before,two files are produced when I click on the screen : bpy and json. But I don't see any file containing the coordinates expressed with numbers that I need to use with WebGL...
0
marietto2008Author Commented:
root@mario-ThinkCentre-XXXX:/media/marietto/09274c80-4a49-4f4f-9e2e-83c4a5578a04/Animazione/Tools/Python# python ./shapeKeysToJSON.py
Traceback (most recent call last):
  File "./shapeKeysToJSON.py", line 3, in <module>
    import bpy
ImportError: No module named bpy
0
peprCommented:
The last two lines say the reason. You have to install the Python support for the Blender or possibly also the Blender itself. I cannot help you with that, as I have no experience with Blender. Study the documentation http://www.blender.org/documentation/blender_python_api_2_59_0/info_overview.html

One more thing, your last comment also proved that you launched Python scripts the wrong way earlier. Or you must launch it via explicit python command, or you must add the above mentioned #! line into the script.
0
marietto2008Author Commented:
What about this script ?

http://code.google.com/p/blender-webgl-exporter/downloads/list

I ran it and it didn't work,but it seems to me that the errors aren't caused by the same reasons as before.
Schermata.png
Schermata-1.png
WebGLExport.py
0
peprCommented:
Well, the last script suggests that there is the executable named BPY that is used for interpretation of the script. It suggests that Blender has a Python interpreter embedded inside of its own code. At least you know how the scripts should be launched. You should probably launch it explicitly as BPY the_script.py instead of python the_script.py.
0
marietto2008Author Commented:
No. This is not the solution. I think that some kind of PYTHON PATH environment variable is missing....

root@mario-ThinkCentre-XXXX:/media/marietto/09274c80-4a49-4f4f-9e2e-83c4a5578a04/Animazione/Esempi/blender-webgl-exporter# python ./WebGLExport.py
Traceback (most recent call last):
  File "./WebGLExport.py", line 41, in <module>
    import Blender
ImportError: No module named Blender

root@mario-ThinkCentre-XXXX:/media/marietto/09274c80-4a49-4f4f-9e2e-83c4a5578a04/Animazione/Esempi/blender-webgl-exporter# BPY ./WebGLExport.py
BPY: comando non trovato
root@mario-ThinkCentre-XXXX:/media/marietto/09274c80-4a49-4f4f-9e2e-83c4a5578a04/Animazione/Esempi/blender-webgl-exporter#
0
peprCommented:
Possibly the BPY executable was not found. However, it is named inside the above WebGLExport.py script. Try to find the BPY executable first.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marietto2008Author Commented:
I have no BPY file. But I have a folder called bpy here :

/media/marietto/09274c80-4a49-4f4f-9e2e-83c4a5578a04/Animazione/Tools/Blender/blender-2.66a/2.66/scripts/modules/bpy

this is the content of the bpy folder :

__init__.py  ops.py  path.py  __pycache__  utils.py
0
marietto2008Author Commented:
I tried to run the script directly inside the blender modules folder :

root@mario-ThinkCentre-XXXX:/media/marietto/09274c80-4a49-4f4f-9e2e-83c4a5578a04/Animazione/Tools/Blender/blender-2.66a/2.66/scripts/modules# python WebGLExport.py
Traceback (most recent call last):
  File "WebGLExport.py", line 41, in <module>
    import Blender
ImportError: No module named Blender


read here :

http://www.blender.org/forum/viewtopic.php?t=18931&sid=2d977cee0f1a085f7390fa87fc37899c

he says : "The Blender Python API has changed, there is indeed no Blender module anymore, nor any of the modules you try to import from it. See the new Blender Python API instead..."  

Posted: Fri Jan 14, 2011 6:37 pm
0
marietto2008Author Commented:
Maybe this is the updated version ?

https://github.com/lubosz/blender-glge-exporter
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.