6. December 2011

Fine tune three.js export from Blender

Three.js exporter for new version of Blender 2.60 supports many features. The problem is that default exporter settings generates quite big JSON file even for small models.

Here is list of defaut options for save model function from export_threejs.js:

         filepath = "",
         option_flip_yz = True,
         option_vertices = True,
         option_vertices_truncate = False,
         option_faces = True,
         option_normals = True,
         option_uv_coords = True,
         option_materials = True,
         option_colors = True,
         align_model = 0,
         option_export_scene = False,
         option_lights = False,
         option_cameras = False,
         option_scale = 1.0,
         option_embed_meshes = True,
         option_url_base_html = False,
         option_copy_textures = False,
         option_animation = False,
         option_frame_step = 1,
         option_all_meshes = True

These are good settings when you want to save all objects from scene. It is quite overkill when you need to save just one dynamically generated object. I recommend to turn off following options:

option_all_meshes, option_materials

Here is sample code in Python which will select object by name and save it to file with defined options:

import bpy

bpy.ops.object.select_name(name="ObjectName")
bpy.ops.export.threejs(filepath="ObjectName.js", option_all_meshes=False, option_materials=False)

Further articles about Blender and Python are located under the tag Blender on my blog.

Enjoy :)

8. August 2011

Which programming language is the most popular?

Do you wonder whether your favorite language is the most popular?

Tiobe Programming Community Index could give you some hints about it.

Here is small sample:

You can find more details about other languages also at Tiobe.com.

27. June 2011

Quick start: Blender and Python

If you know right tricks then writing scripts for Blender is quite easy.

Here is video tutorial that explains some of those tricks. Enjoy.

22. June 2011

Create mesh with correct faces in Blender by Python script

This video tutorial explains how to create mesh using Python script.

Vertices must be defined in right order when we want to define correct face.

Let’s imagine that we would like to create following object:

Numbers are marking vertices beginning from 0.

Let’s define them:

faces = ((0,1,2,3), (1,2,6,5), (1,0,4,5), (2,3,7,6), (0,3,7,4), (4,5,6,7)

Just display normals to see whether everything is ok.

As you can see, only few faces have correct normal.

In order to define face correctly use following rule:

Imagine that you’re sitting inside object and you’re looking outside.

You have to define face by naming vertices in clockwise fashion.

Solution is:

faces = ((0,1,2,3), (5,6,2,1), (4,5,1,0), (2,6,7,3), (0,3,7,4),(7,6,5,4))

For more details about Python and Blender pay a visit to blendercookie.com.

21. June 2011

Writing Python scripts for Blender with Intellij IDEA

Blender is powerful 3D modelling tool. What makes it really powerful is support for Python.

I was playing little bit with configuration of Intellij IDEA and I found out that it is possible to use Intellij IDEA for developing Python scripts for Blender.

Here is video tutorial:

Update 23.06.2011: Video tutorial was recorded for Blender 2.57. There is small change in Blende 2.58 – scripts are located in Program Files directory, like: C:\Program Files\Blender Foundation\Blender\2.58\scripts\modules

Some useful links:

20. February 2011

EuroPython 2011 – Florence

EuroPython will be this year in Italy – Florence.

When? 20.-26. 6. 2011

Speakers can submit their talk. Call for paper is now open.

You can find further information at: ep2011.europython.eu.

Twitter: @europython

10. January 2011

PyXML is dead project – warning: PyXML does not work with Python2.6

PyXML project has been dead for several years. Last version was released in 2004.

When you try to install PyXML with Python 2.6 you’ll get following error:

Failed to load application: invalid syntax (ParsedAbbreviatedRelativeLocationPath.py, line 31)

When you try to start PyXML with Python 2.5 you could see nice compiler warning:

python2.5 xml/xpath/ParsedAbbreviatedAbsoluteLocationPath.py

xml/xpath/ParsedAbbreviatedAbsoluteLocationPath.py:27:

Warning: ‘as’ will become a reserved keyword in Python 2.6

Problem is caused by following line:

as = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self')

PyXML is dead project. It does not accept patches. Some Linux distros already excluded it from repositories and Windows version for new Python does not exist as well.

Try to avoid using PyXML and replace it e.g. by xml.dom.minidom or elemettree.

7. January 2011

How to dump POST request with Python

Python contains one helpful module: SimpleHTTPServer. You can expose local directory via HTTP by following command:

python -m SimpleHTTPServer

Python will start HTTP server at http://localhost:8000

It is very worthy when you’re doing some tests of web application.

The only problem is that SimpleHTTPServer does not support POST. Sometimes it’s very useful to see content of POST request. E.g. you have an app written in Flex and you want to see content of POST request without starting Flash Builder.

Is there any simple way how to achieve this in Python?

Here is small extension of SimpleHTTPServer with do_POST handler:

import SimpleHTTPServer
import SocketServer
import logging
import cgi

PORT = 8000

class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):

    def do_GET(self):
        logging.error(self.headers)
        SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

    def do_POST(self):
        logging.error(self.headers)
        form = cgi.FieldStorage(
            fp=self.rfile,
            headers=self.headers,
            environ={'REQUEST_METHOD':'POST',
                     'CONTENT_TYPE':self.headers['Content-Type'],
                     })
        for item in form.list:
            logging.error(item)
        SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

Handler = ServerHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()

You can download SimpleServer.py here and start it with command:

python SimpleServer.py

3. January 2011

pyamf.DecodeError: Array type required for request body

PyAMF is quite handy library for building apps that communicate with BlazeDS servers via AMF protocol.

Manual says that you should use setCredential to authenticate client.

The only problem is that PyAMF throws strange error after calling any method from remote service:

pyamf.DecodeError: Array type required for request body (ticket 711)

This is quite misleading error message. In this case it means that you do not have correct credentials. Check your user name and password in setCredential method. ;-)

14. December 2010

Bez testů do vývoje nelez

Parafráza na: Bez peněz do hospody nelez ;-)

Príklad z praxe: Finálny výsledok bol zle generovaný. Asi 50 krát som prešiel kód. Prešiel som všetky vrstvy. To proste nebolo možné, výsledok sa musí generovať správne!

Pozorný čitateľ iste poznamenal: Nemusí. :-P

Presne tak. Výsledok sa generoval nesprávne. A to aj napriek mojej utkvelej predstave, že všetko je napísané správne.

Tak som sa zamyslel, napísal som 5 testov, ktoré sa spustili za menej než jednu sekundu. Nad testami som pustil debugger, predebuggoval som chybný test.

Ajhľa. Bug. Miniatúrny. Fakt malý. Chýbajúci jeden riadok v štvrtej vrstve.

Preto nezabudnite písať testy a hlavne nezabudnite na to, že testy sa dajú ľahšie debuggovať než finálna aplikácia. :-)

Ešte poznamenám, že pre vývoj na Pythonierskom Googliom AppEngine, je Intellj IDEA 10 (s Python pluginom) parádny nástroj. Pri unittestoch je potrebné správne nastaviť PYTHONPATH, a to nie len do google_appengine, ale aj do google_appengine/lib/webob.

  • Babel fish

      Translate from:

      Translate to:

  • Where’s the fish?

  • Further info

  • Badges

  • Video channel

  • Learning

    Grow your brain.
  • Tags

  • Topics

  • May 2013
    M T W T F S S
    « Feb    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
  • Comments