tiistai 21. joulukuuta 2010

Using threads in Blender game engine




I just made an experiment of using threads in Blender's game engine. Even though using threads in Python does not necessarily make code any faster (see GIL), in this case using thread(s) has a really big difference.

AFAIK, rendering and execution of python scripts are running sequential in BGE. This is a bad thing if you have to make some heavy lifting in the script. Whole game engine have to wait until the job is done ruining your FPS. By using threads, the heavy lifting can be done parallel (or at least semiparallel) to main rendering loop.

The script can be found from Blenderartists.

maanantai 20. joulukuuta 2010

Towards Blender 2.55





I had a little break from Blender but now its time to go back and see what devs have been doing. I just converted my old pyramidaze script for 2.55. It is REALLY simple but it was my first python script back in 2006 :)

It just iterates through selected faces of the object and adds a pyramid top of them (see image above).

Here is 2.55 version:
#**********************************************************************************************
#pyramidaze.py
# - This script adds a "pyramid" over every selected face
#
# - Open this file in the Blender's text window
# - Select faces
# - set settings (see below)
# - run script (Alt + P)
# 
# there is nothing special in this script but it shows how to iterate 
# through all faces in selected object, how to get normal and how to 
create new mesh object.
#
# Feel free to use this script any way you like, I'm sure this is very useful ;)
#
#Ari Hayrinen 29.11.2006 
# updated for Blender 2.55 20.12.2010
#www.opendimension.org/blender_en
#
# TODO:
# - GUI 
# 
#*************************************************************************************************

import bpy
import mathutils

#************************************************************************************************
# settings
#************************************************************************************************
py_height = 1       # pyramid height if use_area is 0, negative value inverts pyramid
use_area = 1        # if 1, uses face area as pyramid height
area_multi = 1      # multiplier for face area, negative values inverts pyramid



#********************************************************************************
#main
#*********************************************************************************

objekti = bpy.context.active_object
scene = bpy.context.scene

# list for new faces
coords = []
faces = []

# counter so we know where to add new faces 
verts = 0  
vertices = objekti.data.vertices


# let's go through all faces in selected object
for face in objekti.data.faces:
#use only selected faces    

if face.select:


center = face.center

#number of vertices
vco = len(face.vertices) 

if use_area:
py_height = face.area * area_multi


#multiple normal with pyramid height and add result to the center of the face
center.x = center.x + face.normal[0] * py_height
center.y = center.y + face.normal[1] * py_height
center.z = center.z + face.normal[2] * py_height

#create vertices 
coords.append([center.x,center.y,center.z])
verts +=1

for i in range(vco):
coords.append(vertices[face.vertices[i]].co)
verts +=1


#create triangles
cco = vco + 1                        # number of created vertices
for j in range(vco):    
if j < (vco-1):
faces.append([verts-cco, verts-(cco-(j+1)), verts-(vco-j-1)])
else:
faces.append([verts-cco, verts-(cco-(j+1)), verts-(cco-1)])


# Create new mesh block and add faces to it
mesh = bpy.data.meshes.new('myMesh')

mesh.from_pydata(coords,"",faces)
mesh.update()

new_obj = bpy.data.objects.new("koe", mesh)
scene.objects.link(new_obj)

new_obj.location = objekti.location

keskiviikko 17. marraskuuta 2010


Why do I have a problem with Android market

I bought Samsung Galaxy S phone. It has Android in it and it is a wonderful phone. And then there is the Android market which has a lot of nice applications in it. The problem is that I don't trust them. I'm so used to use Free software that any proprietary code makes me suspicious.

And why should I trust? Android applications knows more than they should.


Where is a market place for Free software only?
I think FLOSS-market place could be a great way to support Free software. So far, I haven't paid for Free software (although I've donated), but I can see myself paying for Free applications more happily than proprietary ones.

maanantai 4. lokakuuta 2010

Handy Perl script for generating passwords:

 perl -e 'print crypt("something_here", "this_is_salt"),"\n"' 

lauantai 5. kesäkuuta 2010

Are information agents the format radio of Internet?

Those who have bought books from Amazon.com knows of their habit of recommend other books that Amazon thinks could be in your interest. And I hate to admit but usually these recommendations are pretty good. I think this is the basic idea of web 3.0 in general. It knows more than current web and it can act based on that knowledge.

So Web 3.0 should be smarter web. Not just documents but information provided by context sensitive agents. But how about information outside my context?

There is a radio channel that advertises itself with slogan "Hit Music Only". The listener can be sure that he or she is never exposed to Bach or Arvo Pärt. Those things simply does not exist in that universe.

So what if intelligent agents works similarly than radio stations that are concentrated only one type of music? They filters out everything that is not suitable to our "context" and we don't never have to see anything inappropriate (e.g. something that does fit in our beliefs)?

keskiviikko 5. toukokuuta 2010

Ubuntu 10.4 is fast!

I tried the latest version of Ubuntu and it is just fast! Boots quickly and overall appearance is snappy. I hope next version of Fedora can compete with that.

Anyway, good work devs!

http://www.ubuntu.com/

maanantai 14. joulukuuta 2009

From Ubuntu to Fedora

There are lot of distros to choose for Linux users and I've been a loyal Ubuntu user since the beginning of the Ubuntu saga. Until now. Ubuntu is doing great work enabling "out-of-a-box" experience for novice users. But when you are not a novice user any more, this approach starts to annoy a little bit. So it was time switch from comfort zone to Fedora.


Why Fedora?
According to Paul Frields (Fedora's project leader) Fedora is intended "first and foremost for users interested in and capable of contributing to open source." I would really like to count myself to those users. In addition, Fedora is a bleeding edge distro and Red Hat is a big contributor to Linux kernel.

So Fedora just seems right for me :)


In practise
Of course I had tried several distros earlier but now I wanted to convert my work PC to another system and that is something that you I'm not willing to do very often. I've listed some differences that I had to deal with:


Selinux
Selinux is an additional security layer and it can drive you crazy. I did not remember that Fedora has this on by default. I spent whole one day trying to get PostgreSQL and Apache working nicely. Finally I realised what was causing the trouble up and I turned the selinux off.

http://www.crypt.gen.nz/selinux/disable_selinux.html

PHP Development
There are some differences in PHP settings between Ubuntu and Fedora.
I need PHP's xml and mbstring modules for my development. In ubuntu these are included by default, but in fedora they can be found as a separate packakeges: php-xml and php-mbstring. In fedora, PHP's errors are logged to file instead of showing them. That's good for production server but not for a development server. Not a big deal, just small edit in php.ini file.

display_errors = On


Yum
Yum is Fedora's "apt". It is little bit slower that Apt in Debian or Ubuntu, but it is also more verbal by default. The speed is really not an issue, at least for me. Yum install XXX, yum remove XXX, yum update, not big differences here.


Multimedia
By default Fedora does not find any closed codecs like MP3. Luckily there is a RPM Fusion. Just install RPM from the Fusion site and codecs are found when you try to play those unneeded closed formats.


Software Development
So far I haven't found any significant differences here. Make, scons, SVN and CVS just do their work like expected.

DWM
DWM is the window manager I'm using and can't live without. Downloaded source, compiled and it was working. So no complaints!

http://dwm.suckless.org/