.OBJ to JSON python script

June 26th, 2011

I have developed a small script in python to convert OBJs to JSON, well suited for WebGL rendering.
It is not very optimized, and it only support OBJs with one mesh with UVs and Normals.
It computes the bounding box and clamp to 3 decimals all the values to avoid some ugly values.
It support indexed meshes and coordinates swap for 3ds MAX exported meshes.

The code after the jump.
Read the rest of this entry »

Solution: WordPress problem uploading images

September 16th, 2010

I spend half an hour trying to find the solution to a problem related to WordPress, and nobody on the Internet seems to have it, so now I had figured it out I have the duty of post it so others can take advantage.

After installing WordPress on my server I wasn’t able to upload images using the admin page, it said something like “The uploaded file could not be moved to …” (“El archivo subido no se ha podido mover a …” in spanish).

It looked like a privileges problem, so I gave to all the folders the rights to read and write (you can do this from your FTP Client, right click on the root folder and search for Atributes or Permissions and set it to read and write to all users), not the safest solution but it should work.

But it didnt. I realized that the uploads folder of WordPress “wp-content/uploads” was created by Apache, not by my user, so that was the problem.

I deleted the folder /wp-content/uploads which was empty, and create it again using my ftp client, problem solved.

WebGL: Day 1

July 8th, 2010

I like to code in OpenGL, andI like to code javascript, and now WebGL allows me to do both things at the same time!.

WebGL is a Javascript binding to access all the OpenGL ES features right from the browser. The idea is not bad, it allows to create true hardware accelerated 3D apps embeded on the sites, and it blends perfectly with the rest of web technologies (like HTML+CSS, Ajax, etc).

Unfortunately WebGL is not mature enough and It is kind of hard to start even for a experienced programmer.

The first big problem I found is that Javascript was never meant to be used with binary data, and 3D graphics needs binary data to save all the information (textures, meshes). WebGL can do the ugly work to convert from regular non-typed arrays to low-level streams, but sometimes it is confusing, or just it looks slow, and hard to optimize, but if we agree that a 3d app in a browser is not meant to have Crysis quality we can keep going.

Usually working with OpenGL from scratch tends to be annoying, because there are lots of actions you have to do to create and transform simple things like meshes or textures, things that usually are wrapped in classes to speed up the developing process, and here we have the non-binary data issue that can make the wrapping harder.

For starters all the geometry calculations (projections, transformations, vector operations, etc) should be coded from scratch because JS libraries tend to be focus on HTML and web interaction, no in 3D. Now with WebGL some libraries are emerging for 3D calculations but they do the calculations in JS, which is slow for intensive computation.

Also JS doesnt support operands so you can do V1 + V2, you end up with sum(V1,V2) which is annoying for long formulas.

So thats when you realize you are touching the limits of the technology, JS was never meant for this and WebGL wont solve this issues, it is just a wrapper of a library.

Anyway, I decided to switch to a framework build uppon WebGL, because working straight to WebGL is slow and tedious.

So I chose SpiderGL as that middle-ware, and it looks nice but it is not documented at all!!, gaaagh. I have to read the source code to discover most of its usefull features, and found some bugs too…

But after sorting all the problems, it works, I have coded several shaders, do PostFX in scenes and some intensive mathmatics and it looks nice in a browser.

Sadly I havent figured out how to export meshes in a binary format…

Anyway, If I have time I will upload some of the examples I coded, but remember that you need a WebGL capable browser.

My simple IP Socket Server in Python

June 25th, 2010

This is a small python code I wrote to create easily apps that connect using a socket.

The interface is really fast:

from easyserver import *

def on_client(info):
print “Alguien viene… ”
print info.details

def on_message(info, msg):
print “Dice: ” + msg

def on_close(info):
print “Se fue…”
print info.details

EasyServer(20000,on_client, on_message, on_close)

This will call any of those callbacks anytime somebody connects to the server listening in port 20000. More simple is impossible.

Here is the code: easyserver.zip

Previously on 2009

February 14th, 2010

Brief list of good things and bad things that happened to me this last year:

  • Gla finally decided to visit me, and I had the chance to show her all the things I’ve been talking about during all these years. I was glad to see her here, to have the oportunity to spend time with her and create good moments to remember, sitting next to each other, showing our own little worlds.
  • Encouraged by my friends and co-workers I started playing in a heavy metal band. They needed a bass guitar player and I had too much spare time and some guitar skills, so I went every friday to play with them in a rented-by-hours local, and a couple of months later my skills as a bass player were surprisingly enhaced. Now even my good friend Pau come with us as the lead singer, and the “metal friday evenings” had become one of the best moments of the week, surrounded by great people, playing cool songs and having fun all together. Funny taking into account that I wasn’t a big fan of metal music till now. And If you want to know which songs we play they are mostly Iron Maiden, Judas Priest and Guns’n Roses, but we also play songs from Wolfmother, Jet, Kiss, or some oldies like The Shadows.
  • Anton pushed me to go with him to learn french on a one-month course, where I remembered what was to study, and where I learnt a new language from scratch. One year later I’m studying french again two times per week and I can’t say I’m not enjoying it. And it helped me to make new good friends, like Marta :)
  • Encouraged by Ceci I took a one week course of 3D Computer Animation, my long time dream job. During the last years I learnt all the technical aspect about 3D Animation from the programming side but I never spend time animating a character, moving every bone along the timeline. After the course I realized that that wasn’t meant to be my future career. To animate doesnt have anything technical, it is only art, far away from anything I ever done, so I better stick to the technical parts of 3D Animation, like materials, lights, and so.
  • Ceci suggested me to travel with her to visit Santiago de Compostela, I don’t really like touristic trips, but this was the better I can remember. We spend a couple of days discovering the city and a couple more enjoying it. We met great people, we relax in nice parks, even the weather was perfect and the city wasn’t crowded at all being a touristic spot as it is. It couldn’t be better. Ceci was a great traveling partner, besides her obsession for taking macro pictures of every flower on the streets and parks.

There were bad things too:

  • That I am almost 30 and I still need the people to push me to do things (as you can deduce from the previous points), I never find reasons or strength to do them by myself. And the worse part is that when eventually I do something I’m usually pretty good, but anyway, I’m still a mixture of lazy and coward.
  • I stopped falling in love, after too many heart-broken moments, I realized that I stopped loving the people, and worse than that, I stopped caring about finding the true love, which for me was the main source of energy to wake me up everyday. Now I don’t know if I will ever find somebody to spend the rest of my life, but somehow it doesnt matter. I thought I was a romantic, but I guess that couldnt last forever.
  • Somehow I ruined my relationship with one of my best friends, the person that know me better and now I miss her every single day.
  • To run in a hurry to the hospital after a call telling me Elena had have a crash with her scooter, and to see her so scared, worried and ashamed. But after one year we can remember that and make fun of it, I even feel that after all she become a stronger person.

From 2009 I will carry with me the great days I had with Gla, all the rollerblading sundays with Ceci, the daily lunch with Miguel Angel and our geek conversations, the monday’s dinners with Pau and our nerdy moments, the metal evenings with the twins, my everyday chats about life and love with Julian, the working silly hours with Alun and Marco, the funny classes with Anton and Mikel, the yoga classes with Miriam, the drawing sessions with Ana, watching TV with Marta, hanging out with Graham, the unpredicted calls from Marcos to go eat somewhere, and all the supporting conversations with Magda and Elena. All of them helped me to bare this 2009. After all, it wasnt so bad.

Testing NVIDIA 3D Vision (Stereographic gaming)

December 20th, 2009

I spend this weekend in my parents house, where my brother lives. This won’t have anything to do with the topic of the post if it wasnt that my brother is 35 and have a well paid job, under this circunstances he likes to waste the money in all kind of gadgets, even those who will never use, just for the pleassure of showing off in front of the people.

Sometime ago he decided to purchase a nice pack from NVidia that bundle a monitor, 3d card and stereographic glasses. They sell it as the next experience in videogames, and I wanted to know if this is really an improvement.

First of all I have to battle against the driver, using the latest it didnt work. The “NVidia Stereo Controller” driver was not found, I had to download a previous driver and install just the USB driver item (I document this beacuse maybe somebody find this useful).

Once it worked I tested some demos that look nice, but I wanted to see it on games, and I did, and I have some kind of contradictory impressions:

The technology itself is nothing new, the glasses are just LCD synchronized using a IR flashing device connected through USB. You know how it works, the computer shows the frame for the left eye on the screen and syncronize the glasses to block the right eye, and switches fast enough so the perception is that both eyes are watching different images.

This technology was easy with previous CRT Monitors, but TFTs can’t switch images so fast, so with current TFT monitors the other eye still can see the image that was rendered for the first eye.

This is the reason why this pack comes with a monitor, this monitor (Samsung) is able to work at 120Hz so there is no problem to work with the active glasses.

Amd about the glasses, I was hoping some improvement but no, all the glasses that uses LCDs have the same problems, and this ones are not an exception.

First, the brightness. Your eyes are watching half of the frames, and when they are not supposed to see the screen they are covered with a dark screen, that means that the perceived brightness is half of the monitor brightness, and you feel it, when you are used to bright monitors this is like playing with your brightness set to 50%. Annoying. Of course they could create special monitors with the double of brightness, but that brings us to the next problem:

Ghosting. When working with LCD glasses you have to ensure that the darkened eye won’t see anything on the screen, otherwise the user sees strange objects floating on the screen that reduces the stereographic sensation.

So where is the great improvement here? Well, it is not a hardware improvement, it is more a software improvement, and the improvement is that the game do not need to be coded to work in 3D, the driver is able to do it by itself.

Thats a great step forward, and I can tell you that it is not easy. Because the driver somehow has to understand all the steps during the rendering process and it has to determine which parts needs to be redone, readjust the camera position and render the frame for the other eye. And it works!, but not perfectly, because the rendering pipelines are composed of lots of steps and a driver it is not able to understand them fully. Thats why DirectX has some specific features meant to take advantage of this technology.

Those games developed to be used in 3D will work perfectly, the others probably will show horrible gliches, or will have inter-ocular distances that will make your brain explode. Because thats another big point, when working with stereographic you have to set the distance between the cameras used for every eye, and the focus point distance, if you don’t set these distances right, the sensation is annoying or you just loose the 3D effect. For instance, I’ve been testing Colin McRae Dirt 2, the game looks amazing in 3D, the speed feeling is awesome, but you can’t play it using the inside-car camera, because the intra-ocular distance is too big.

I guess that what the driver uses to determine the distance is probably something like ( (far_plane – near_plane) / 2 ) and as I said it work, but not under all circunstances. Another game I tested is TorchLight, in this game I couldnt find any glich (and the game is not meant to work with 3DVision) but the only annoying thing was the cursor, which floated on the screen instead of being at the ground level.

So at the end what is my impression? It is hard to say. It really looks 3D, it really improves the gaming experience, but at the same time you feel that this is some kind of natural evolution in games, and you are used to play in 2D that you really don’t bother if there is no depth perception. I think that this technology needs to walk hand to hand with the headtracking technology, otherwise is some kind of expensive eye-candy.

Twittear para decir que twitteo

December 8th, 2009

Cuando uno twittea me estoy casando, deja automáticamente de casarse. E ingresa en la metavida. Cuando se pretende narrar en directo, el único hecho que resulta es el propio acto de narrar. La narración, como la felicidad de Ferlosio, sólo puede ser retrospectiva. Todo esos tweets llevan un único mensaje. Estoy twitteando.

Aunque no esté de acuerdo con el contexto, me ha sorprendido esta valoracion sobre el arte del twitteo, escrita por Arcadi Espada.

pygame makes me waste my time

October 11th, 2009

Today I had some free time so I decided to take back python programming to add some features I had in mind for the pyncel app.

But then I discovered an anoying bug, if you resize the window the mouse messages from pygame don’t work properly, they are limited to the old size, so if the new window is bigger, when the mouse moves outside the old size it stop sending messages, and when it sends it, the position is always in the old border.

I track the problem till pygame, and I discovered that it is just a bug, nothing else to say. I guess the problem is some kind of ‘if’ statement inside pygame code, because I’ve been working with SDL for long time and it never gave me this problem

The weird thing is that I’ve been trying to find more people commenting this bug and there is no trail. And being such an obvious error I’m dazed. Maybe is a problem that only arises with Windows 7

So this is why I comment it here, with the keywords to help search engines: pygame VIDEORESIZE mouse border problem error. I hope somebody finds this post somebody and stop wasting time with pygame.

No improvements to my app today.

DDS in Python

September 22nd, 2009

Due to some work duties I’ve been all day messing around with DDS files and python. DDS is a file format that is capable to store compressed textures, the interesting thing is that the compression algorithms on DDS files are supported by the current graphics card, it means you don’t have to uncompress them before sending them to the VRAM, opposed to what you would do when you  use JPGs (you have to load the file, uncompress it, ans send it to VRAM).

There are more pros, the mipmaps for instance, with the regular textures the driver is in charge to create the mipmaps when uploading a texture, and that is slow as hell, indeed most of the time we spend uploading a texture is the mipmaps’s construction process.

And there is still an advantage, the textures are stored compressed in VRAM (less memory), and can be accesed without uncompressing the whole texture, so it means the internal buses of the card are more free, and it traduces to better performance.

Ok, so what about DDS in python? well, sad news is I couldnt find anybody who made a DDS file loader, PIL doesnt support them. So maybe I will get interested on adding DDS file support to my little framework.

It is not hard, I just need to read the header but to support DDS means lots of work.

But once again, too much wrapping, not enough creation. So this feature will get on hold till I really need it.

Today I found this interesting work by Dasol, it is a procedural spiral generator and he uses also some celullar automata for the background. I felt like he beated me somehow because that was more or less the kind of stuff I tryed to achieve when coding my celullar automata but I didn’t spend much time in polishing it or giving it some kind of meaning. Also the automata is cool, and the way he renders the board (using a texture for every cell looks cool when you zoom in) is clean.

Anyway, ideas for the pyncel app:

  • create a SceneGraph
  • refactor the canvas to make every canvas more like a SceneEntity of a SceneGraph
  • some tools to move and rotate objects
  • create a background texture loader
  • create a internet image loader

Sounds boring but the results could be nice. So no screenshots or code for today.

Hackpact Day 10: Bug fixes and multicanvas

September 18th, 2009

Today some minor bug fixes, for instance, I extended the app to support more than one canvas at the same time. The idea is to overlap them as layers but right now I just use them as a way to extend the canvas on the sides which should be the same as having a bigger canvas, but I want to use separated canvas so maybe in the future I have some kind of infinite canvas where it can create new ones just but painting outside of the current canvas.

But it didnt worked, I only could paint in the first one, in the other ones it didnt paint. I was convinced that it was a problem with the FBOs in the RenderTexture, so I keep watching all the OpenGL code without much luck. Then today I realize that the problem was the brush, after painting in the first canvas the internal var storing the last time it painted was updated, so when it has to paint in the other canvas it block it according to the flow property in the brush.

So now I have several canvas that I can overlap, I don’t have an interface to move them around, to sort them in Z or to choose the active one, and I’m lazy about it, I don’t want to code GUI stuff, so I will see how I can sort it out.

I also discovered an easier way to create a FileDialog, check the code:

def ChooseFileDialog(caption="Choose a file",folder="C:/",default="file.png",wildcard="*.png"):
 result=""
 app = wx.PySimpleApp()
 dlg = wx.FileDialog(None, "", "c:/", "", "*.*", wx.FD_SAVE)
 if dlg.ShowModal() == wx.ID_OK:
  result = dlg.GetPath()
 app.Destroy()
 return result

Better than the last one, indeed I don’t think I need the Destroy line, but I’m always scared of leaving an app running in background because I don’t have any way to check it.

I also added the option to resize the application window, more according to the kind of application I’m creating.

Today there is no code to upload, I don’t think it will be interesting to release this version without a propper control. I’m also planning to create new brushes and textures.

hackpact_4canvas

You can see 4 canvas arranged horizontally. I render a grid to make it easy to see it.