<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tamapolis</title>
	<atom:link href="http://www.tamats.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.tamats.com/blog</link>
	<description>where tamat&#039;s come from</description>
	<lastBuildDate>Wed, 16 May 2012 19:37:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Websockets Experiment: Shared canvas</title>
		<link>http://www.tamats.com/blog/?p=237</link>
		<comments>http://www.tamats.com/blog/?p=237#comments</comments>
		<pubDate>Tue, 15 May 2012 20:10:22 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdevelopment]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=237</guid>
		<description><![CDATA[For today experiment I tryed to recreate the cool sketchpad by mr doob using websockets and HTML5Canvas. The idea is that while you paint on the canvas your strokes are send to the server and broadcast to all the users on the web in realtime using websockets, you also can see the cursor of the [...]]]></description>
			<content:encoded><![CDATA[<p>For today experiment I tryed to recreate the cool <a title="Sketchpad" href="http://mrdoob.com/projects/multiuserpad/" target="_blank">sketchpad by mr doob</a> using websockets and HTML5Canvas.</p>
<p>The idea is that while you paint on the canvas your strokes are send to the server and broadcast to all the users on the web in realtime using websockets, you also can see the cursor of the other people. Click on the image to test it but remember that if there are not other users online you will be just drawing alone.</p>
<div id="attachment_238" class="wp-caption aligncenter" style="width: 560px"><a href="http://www.tamats.com/apps/sharedcanvas"><img class="size-full wp-image-238 " title="sharedcanvas" src="http://www.tamats.com/blog/wp-content/uploads/2012/05/sharedcanvas_screenshot.png" alt="" width="550" height="337" /></a><p class="wp-caption-text">Shared Canvas</p></div>
<p>If you want to know more about the coding read the full post.</p>
<p><span id="more-237"></span></p>
<h3>Server side</h3>
<p>I&#8217;ve been trying for a long time to make an app using websockets, but it turned out to be harder than it should be, mainly because the standard has been changing constantly for the last year so it was hard to find libraries to use on the server side to abstract me from the protocol, I even tryed to coded by myself but there was some binary info being exchanged that I couldnt handle.</p>
<p>I wanted to code a simple broadcast server. I&#8217;ve done it before in python but for this time I wanted to use <strong>node.js</strong>, I really think that nodejs is a great idea. I understand why some people hesitate, but the truth is that it allows to prototype apps really fast thanks to a good API and the benefits of using the same code on the server and the client.</p>
<p>I&#8217;ve tryed to code a broadcast server in nodejs before, but all the libraries I tryed were giving me problems during installation, even using the node package manager. Everybody recommends to use socket.IO but I find that library too big and complex to use (it forces you to serve files to fallback in case the browser doesnt support websockets, which wasnt my case).</p>
<p>Finally I found one called <a title="simple nodejs websockets library" href="http://faye.jcoglan.com/ruby/websockets.html" target="_blank">faye-websockets</a> that worked perfectly, nice sintax and support most of the version of the standard. It even creates an http server so you can use the same server to handle static files.</p>
<p>The server is really simple, every message gets resend to all the clients connected, it even allows to buffer the latest 100 messages so you can replicate the last part of the session when someone gets connected.</p>
<p>I was surprised by the performance, it will be nice to make a benchmark with several users but right now it seems it can handle a lot of concurrent users without problems.</p>
<p>And the coolest thing is that the server is totally blind to the app, so I can reuse it for any app I want in the future. I&#8217;m improving it so it allows a tiny protocol to store and retrieve info from the server.</p>
<h3>Client side</h3>
<p>Here nothing new, the user actions are transformed in messages and then processed by the painting app and sent to the server, so I dont have to code the behaviour of the users actions separately.</p>
<p>I experimented with different types of brushes but the HTML5 Canvas is limited, I wanted to tint an image and use it as a brush but the Canvas doesnt allow to tint an image, so I discarded that option).</p>
<p>The cool thing is that now I can add new types of user actions and the platform doesnt change, so to prove that I did cursor rendering on the screen of the other online users.</p>
<h3>Persistent data</h3>
<p>There is only one problem about the app, new users cant see the previous image (besides the buffered strokes which are just a few), so I&#8217;ve been thinking of an option that let the users send to the server the canvas image so the new users can download it, I can do that easily using the http server included with the library.</p>
<p>The server sets a DB where it can store data (just a name=&gt;value storage). Clients can send data with a given name or retrieve it. This info is not persistent once the server is restarted (it can be easily dumped to a text file but I dont need it by now).</p>
<p>The only problem was that due to cross-server policies I wasnt able to access the HTTP server through ajax calls if the server were I hosted the app was not the own websocket-http server (which wasnt).</p>
<p>Luckly thanks to <a href="http://enable-cors.org/" target="_blank">this wonderful site</a> I was able to set the CORS policy info on the HTTP response header very easily just adding this field:</p>
<p><code>response.writeHead(status_code, {'Content-Type': 'text/plain', "Access-Control-Allow-Origin":"*"});</code></p>
<p>Another nice feature is that I can access my server through the browser typing an special url to check how many clients are online, useful to debug purposes. I even could create a tiny admin protocol to handle stuff.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=237</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Experiment: Realtime coding with visual feedback</title>
		<link>http://www.tamats.com/blog/?p=226</link>
		<comments>http://www.tamats.com/blog/?p=226#comments</comments>
		<pubDate>Sun, 06 May 2012 17:55:09 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdevelopment]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=226</guid>
		<description><![CDATA[I guess that more or less all the people who love coding has seen this amazing talk from Bret Victor. I was amazed not only by the ideas (which are great) but for the technological part of implementing those ideas, specially by the one where he keeps coding while the screen shows the output of [...]]]></description>
			<content:encoded><![CDATA[<p>I guess that more or less all the people who love coding has seen this amazing talk from <a href="http://vimeo.com/36579366">Bret Victor</a>.</p>
<p>I was amazed not only by the ideas (which are great) but for the technological part of implementing those ideas, specially by the one where he keeps coding while the screen shows the output of the code without having to restart the app every time a line of code is changed, hard to do because while a coder is typing the code is invalid most of the time (could trigger parsing errors or execution errors). Parser errors are not dangeours because they can be detected easily and they dont mess anything, but execution errors are a big problem because once an error happens the data inside the vars could end up in an invalid state (because the code was partially executed).</p>
<p>So I started thinking about the problem and though that it shouldnt be so hard to code it in Javascript as a webapp using the HTML5 Canvas as the output. If you want to test it click on the image below.</p>
<div id="attachment_227" class="wp-caption aligncenter" style="width: 550px"><a href="http://tamats.com/apps/hotcoding/"><img class=" wp-image-227  " title="hotcoding" src="http://www.tamats.com/blog/wp-content/uploads/2012/05/hotcoding.png" alt="" width="540" height="310" /></a><p class="wp-caption-text">Click to try the app</p></div>
<p>How does it works? I reevaluate the code after every keystroke (if the code is not too big the parsing is less that 100 ms), if there is a parsing error (the eval function throws an exception) I just keep executing the previous iteration (the last safe code), otherwise I try to execute the new one, if an error is triggered during the execution I fallback to the previous safe iteration.</p>
<p>It works pretty well, besides the problem with the persistent data between iterations, that could get &#8220;corrupted&#8221; very easily. For that I only could make a &#8220;reset state&#8221; button that clears all the state (I have to create a new Canvas to avoid problems with the save and restore functions).</p>
<p>There is only one unsolved issue, what about infinite loops?, well, I can&#8217;t control that, AFAIK Javascript doesnt has the tools to fix that, and it is easy to end up with an infinite loop when using whiles. I thought about injecting some code inside every loop before evaluating it, that code could act as a yield and throw an exception if the number of iterations is too big. But that would be hard to code so I will just leave it here.</p>
<p>Feel free to check the examples and play with the them, and dont forget to share your experiments with me <img src='http://www.tamats.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Btw, there are some candies in the app like the option of selecting and dragging a number while the Control key is pressed to modify a constant, it also works with variables.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=226</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebGL and Firefox/Chrome</title>
		<link>http://www.tamats.com/blog/?p=222</link>
		<comments>http://www.tamats.com/blog/?p=222#comments</comments>
		<pubDate>Tue, 17 Apr 2012 13:31:59 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdevelopment]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=222</guid>
		<description><![CDATA[Developing web applications has been always annoying regarding the browsers difference interpretation of the what is standard and what not, thats the reason why I stopped developing for IE. At least Google and Mozilla are serious about the standards so 99% of the code I develop for Firefox (my default browser) works in Chrome as [...]]]></description>
			<content:encoded><![CDATA[<p>Developing web applications has been always annoying regarding the browsers difference interpretation of the what is standard and what not, thats the reason why I stopped developing for IE. At least Google and Mozilla are serious about the standards so 99% of the code I develop for Firefox (my default browser) works in Chrome as expected. Kudos for both of them.</p>
<p>They have their own extensions but they are for more experimental features. Regarding to what functionalities to support, they both follow the same standard and thats great.</p>
<p>But when it comes to WebGL, although they both follow the same standard, the implementation is a little bit different.</p>
<p>That means that the performance it is not the same between both browsers under the same circunstances, and that is a problem, because there is no way I can see what is the browser doing (besides downloading the fullcode&#8230;) so if the performance is unstable I feel I reached a dead-end.</p>
<p>I dont mean that one browser is more optimized than the other, my issues are more about how some actions cost more to one browser than the other.</p>
<p>My current application runs much more smoothly in Firefox than in Chrome, but Firefox loves to purge the<strong> Garbage Collector</strong> every 10 seconds freezing the application for several seconds, which makes it totally unfriendly. Chrome on the other hand is more stable but the <strong>frame-rate drops</strong> sometimes just by adding a tiny mesh to the rendering process.</p>
<p>Chrome also do not like negative values for the viewport (I can understand that) and show some weird results when stretching a texture too much (¿?), looks like an undocumented bug with the magnification filter.</p>
<p style="text-align: center;"><a href="http://www.tamats.com/blog/wp-content/uploads/2012/04/chrome-bug.png"><img class="aligncenter" title="chrome-bug" src="http://www.tamats.com/blog/wp-content/uploads/2012/04/chrome-bug.png" alt="" width="500" height="268" /></a></p>
<p>It makes me reconsider if WebGL is the perfect platform for 3D applications and games.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=222</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Canvas Experiment: VRorschach</title>
		<link>http://www.tamats.com/blog/?p=214</link>
		<comments>http://www.tamats.com/blog/?p=214#comments</comments>
		<pubDate>Tue, 17 Apr 2012 11:00:40 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdevelopment]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=214</guid>
		<description><![CDATA[VRorschach is a silly HTML5 Canvas experiment I did a year ago. You can try it clicking the image. It generates procedural symmetrical shapes and allow you to name them and share them. The algorithm to create the shapes is very random, it creates closed splines with random x,y values around an area, and keeps [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://tamats.com/apps/vrorschach"><img class="aligncenter size-full wp-image-219" title="Ape" src="http://www.tamats.com/blog/wp-content/uploads/2012/04/ape2.png" alt="" width="550" height="148" /></a></p>
<p>VRorschach is a silly HTML5 Canvas experiment I did a year ago. You can try it clicking the image.<br />
It generates procedural symmetrical shapes and allow you to name them and share them.</p>
<p>The algorithm to create the shapes is very random, it creates closed splines with random x,y values around an area, and keeps shrinking the area with every polygon. I use a seeded random function so people can see the same results using the same seed.</p>
<p>It was fun to see what people saw.</p>
<p>I should try to find a better algorithm, I&#8217;m pretty sure I can make better looking shapes using something less random.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=214</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ludum Dare 22: Alone in the city</title>
		<link>http://www.tamats.com/blog/?p=203</link>
		<comments>http://www.tamats.com/blog/?p=203#comments</comments>
		<pubDate>Mon, 16 Apr 2012 17:47:42 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=203</guid>
		<description><![CDATA[Me and my girlfriend participated on the Ludum Dare 22 competition about making a game in 48hours. After the total failure of the GGJ11 we wanted to make something more simple. The theme was simple: ALONE I wrote a post-mortem about the game on the official blog, you can read it here. General Thoughts As [...]]]></description>
			<content:encoded><![CDATA[<p>Me and my girlfriend participated on the Ludum Dare 22 competition about making a game in 48hours. After the total failure of the GGJ11 we wanted to make something more simple. The theme was simple: <strong>ALONE</strong></p>
<p style="text-align: center;"><a title="Alone in the City" href="http://tamats.com/flash/ludumdare/final"><img class="aligncenter" src="http://www.tamats.com/flash/ludumdare/alone-in-the-city.gif" alt="" width="300" height="150" /></a></p>
<p>I wrote a post-mortem about the game on the official blog, you can read it here.</p>
<p><span id="more-203"></span></p>
<p><strong>General Thoughts</strong></p>
<p>As always, I couldnt add enought gameplay, I&#8217;m a graphics programmer and I always end up expending too much adding support to features that only give eye candy. I wanted to have everything configurable from an XML file and that took me too much time. At least I hope I will reuse this in the future for other games.</p>
<p>First of all I have to say that my girlfriend Anna helped me to make this game, not only with his vital lovely support, also proposing ideas and creating most of the art you can see in the game. She is not &#8220;fluent&#8221; in pixel art but right now she is starting to get pretty good. I don&#8217;t how much this goes against the rules of the game, in any case, I didnt wanted to bother anyone, we were preparing for the event the whole month and discovered that it was a solo compo right when we started, so we just went on with it. In our defense I will say that we started the game on Saturday evening, and that most of the time we employed on arguing against each other.</p>
<p>The theme of the game was just a random exploration of ideas, she wanted to be more classical and I pushed her to do more crazy ideas instead of the classical games of jumping on top of the enemies. At the end we found this silly game concept of hoarding food from a pseudo-post-apocaliptic city (based on Barcelona).</p>
<p><strong>About Coding</strong></p>
<p>I reused the old framework I did for the Global Gamejam, it is based on Flixel which for this kind of projects is always my favourite choice.</p>
<p>I love how Adam Atomic decided to &#8220;rethink&#8221; the Flash API to keep it as simple and powerful as possible, sometimes too simple though. I encourage the people who wants to make online games to start with Flixel, you don&#8217;t need to know Flash, indeed most of the things you learn from Flixel are useless if you want to develop a common flash app because he just ignored the API and created his own. It helps to get you focused on the game.</p>
<p>I also put lot of effort on having a huge XML file with all the information of the game (map info, characters, vars, triggers, etc) so I can fine tune the game without recompiling it.</p>
<p>It feels great when you find a way to create a new game mechaning without changing a single line of code.</p>
<p><strong>About the Art</strong></p>
<p>I wanted to have lots of layers with parallax for the lanscape of the city, the problem is that you have to design the level from an XML file which is annoying and slow, so at the end Anna was just creating a single image for the whole map.</p>
<p><a href="http://tamats.com/flash/ludumdare/assets/imgs/maps/street_2.png">Example for the main street</a></p>
<p>The lighting was put on top as a Multiply layer, I like to do that so I can control the overall illumination parametrically, I love to over use the blending options. If an engine doesnt have blending modes then I wont use it.</p>
<p><img src="http://tamats.com/flash/ludumdare/assets/imgs/maps/room_1.png" alt="" width="200" height="100" /> +<img src="http://tamats.com/flash/ludumdare/assets/imgs/maps/room_1_light.png" alt="" width="200" height="100" />=</p>
<p><img src="http://tamats.com/flash/ludumdare/room-light.png" alt="" width="200" height="100" /></p>
<p>I also added some gaussian sprites to create the light halo around the lamps, but because the halos are on top of the light image, the effects is not perfect. The good solution would be to sum all the lights on a bitmap (ala RenderToTexture) and apply it on top, I will try to do that on the next compo (I hope flixel allows me to do that).</p>
<p>I wanted to play with different light images to switch between day and night, but there was no time. Indeed it wont be hard to have a night/day cycle using the assets the way they are now, but it was just eye candy so the idea was rejected.</p>
<p>But talking about the art of the game is talking about the amazing work of Anna and her skills placing one pixel at a time. Her main influences were the Super Bros S&amp;S and some old school games I showed to her, and she was pleased to mimic those hard styles without hesitation.</p>
<p>She even made more animations and locations that didnt end up on the game.</p>
<p><strong>Gameplay</strong></p>
<p>We wanted to have a map to explore where you can stumble upon threats, but I didnt know how to code them in a clean way so at the end I implemented some basic behaviours.</p>
<p>I had three types of character behaviour for the NPCs, the follower (follows you around), the wanderer (walks randomly around the map) and the stalker (tries to get close to you and avoids eye-contact).</p>
<p>I like how some lines of code could add so much personality to a character. Sadly I didnt went too deep in this part.</p>
<p>Anna wanted to put effort on a clear interface, so the game mechanics would be clear from the beginning, but I like to leave those aspect to the imagination or the trial-error approach, I find it more thrilling to play without knowing.</p>
<p><strong>Conclusions</strong></p>
<p>I can&#8217;t say I have learn a lot from this compo, because I have made the same mistakes, but I like to use this compos to explore ideas rather than create a generic game. I think that Im getting closer to finish a game in a compo&#8230;</p>
<p>Anyway, I plant to keep developing this game for a while with the help of Anna, I think that if we explore a little bit more the narrative in the game we can find something interesting.</p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=203</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Global Gamejam 2011: Things to remember</title>
		<link>http://www.tamats.com/blog/?p=160</link>
		<comments>http://www.tamats.com/blog/?p=160#comments</comments>
		<pubDate>Mon, 16 Apr 2012 17:41:06 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=160</guid>
		<description><![CDATA[I decided to participate on the Global Gamejam 2011 at Barcelona with three of my best friends. We make &#8220;something&#8221; that barely can be called game, but it was fun. You can try it here: The game has no gameplay at all but the atmosphere is cute. You just walk around a city and if [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to participate on the Global Gamejam 2011 at Barcelona with three of my best friends.</p>
<p>We make &#8220;something&#8221; that barely can be called game, but it was fun. You can try it here:</p>
<p><a title="Our entry in GGJ12" href="http://tamats.com/flash/ggj/"><img class="aligncenter size-full wp-image-200" title="ggj12" src="http://www.tamats.com/blog/wp-content/uploads/2012/04/ggj12.jpg" alt="" width="617" height="317" /></a></p>
<p>The game has no gameplay at all but the atmosphere is cute. You just walk around a city and if there is more people logged to the game you will see them. Thats all. We wanted to force the people to interact between them somehow, but we never made it.</p>
<p>You can read a small post-mortem about it following this post.</p>
<p><span id="more-160"></span></p>
<p><strong>The Event</strong></p>
<p>The GGJ is an international competition where people from different countries gather in their cities (like small LAN parties) to code a game in 48 hours, but all using the the same topic, and simultaneously.</p>
<p>The organizers of this event have an amazing website to check all the games from previous editions, to know more about the teams, and they use it to coordinate all the jams so the groups spread around the globe can experience the same feeling.</p>
<p>On the local part, the guys from the VGAUPC (a gamedev students association from the Universitat Politecnica de Catalunya) organized the Barcelona event. They promote the jam, they found the place and they ensure everything was perfect for the compo. Amazing work.</p>
<p><strong>The Why</strong></p>
<p>Why would we want to be closed in a room for 48 hours coding something that probably will end up in a folder where nobody can see it? Well, there are lots or reasons:</p>
<ul>
<li>We are talented people and we love videogames, why not to try to make one?</li>
<li>Despite some stressful moments, it is fun!</li>
<li>When coding something from scratch the first steps are the harder ones, so if you have some people backing you up and a close deadline, those steps can be exceeded with ease. The rest will come without much effort.</li>
<li>As Miguel Angel said, most of the problems related to big projects are also present in small projects when the time is limited. So you can learn lots of lessons in just 48 hours.</li>
<li>It is a nice excuse to do something you have been delaying for a long time (try that language, library, sdk, etc).</li>
<li>And the most important, because to create something with a group of friends is always amazing, and we dont have the chance to do that very offten.</li>
</ul>
<p><strong>The Team</strong><br />
So I went with three of my best friends, Miguel Angel (codename debiatan), Graham (codename ravelite) and Anna (codename sugarmuffin), and me Javi (codename tamat).<br />
The idea was to split the work in four different fields so we could create faster without having to wait till someone finishes his part. We arranged the work this way:</p>
<ul>
<li><strong>Anna</strong> would make all the art, she is a good designer, with no experience in game design but a good profesional that doesnt get scared when she has to explore new fields.</li>
<li><strong>Miguel Angel</strong> would make the server side, he is a great programmer and when it comes to control a server he is the best. He can also create scripts to resolve easily annoying tasks so he could create also some of the data for the game like procedural generated maps, so I can focus on the client side.</li>
<li><strong>Graham</strong> would be in charge of the audio and music. He knows a lot about music and procedural music so he is the best candidate. The challenge for him was to create the score for the game but adding some procedural ideas.</li>
<li><strong>Javi </strong>(me), I have plenty experience coding games so I would code the game using the graphics from Anna, interacting with the audio code from graham and connected to the server of miguel angel.</li>
</ul>
<p>As you can see everybody had its field and during the first 24 hours we barely interact with each other, only to talk about game mechanics, gameplay and so.</p>
<p><strong>The Idea</strong></p>
<p>The topic gave by the organizers of the Global Gamejam was <strong>E X T I N T I O N</strong></p>
<p>As soon as we could we started brainstoorming, proposing crazy ideas, some using non-obvious meanings of the word, others too close to what we thought everybody would make. There were ideas about language extintion, about a metal band killing people with its music, about matting animals, about taking care of your plants, about zombie apocalipse, tribes, city painting, etc.</p>
<p>My idea was to create a city where nobody lives (so humanity is extinct) and you have to walk around trying to find other people alive. But the city has to be so big that you need to put marks on the walls to coordinate with the people. When you find people you get points by standing together, or you stop loosing &#8220;loneliness points&#8221;. The more people together the better.</p>
<p>I pushed my idea further because it was the idea I knew I could code, I was afraid that picking up other idea would make the game too hard to code for me.</p>
<p>Miguel Angel put all the ideas together and create a nice game mechanic:</p>
<blockquote><p>You will be in an empty city and you will have to find other players (other online gamers), to find them you can shout, and other players could see indications on the map telling them that somebody shouted. When you find them you will have to go together to a point on the map where interacting all together will make one of them reach the exit of the map, he then will see the game ending and if he wants he can come back to help the other people to see the ending (the funny thing is that everyplayer gets a different ending).</p></blockquote>
<p>It sounded great, so we all started to work.</p>
<p><strong>The Technology</strong></p>
<p>Before the event I made took some decissions about which technology, framework and visual style we will follow according to the context of the compo.</p>
<p>First, we need to decide if the game will be 3D or 2D. But for a 48 hours compo 3D will be too hard, and the designer in our team didnt have any experience with 3D modelling so 2D would be the best option.</p>
<p>From the point of view of the code, I decided before hand that the game would be coded in flash. I like actionscript, its a nice language with great API and a good IDE, and I feel really confortable coding in flash. On the other hand, we wanted the game to have as much visibility as possible, and the best way to achieve that is to use flash, people can play it without downloading anything and it is powerful enough to make any kind of 2D game.</p>
<p>The server could be make in any language but I knew that Miguel Angel will go with python which was perfect for me.</p>
<p>From the artistic point of view, I thought that pixel art was the best choice, because less pixels means less work, and because pixelart animations are a lot easier, people dont care too much of how many frames the animation has.</p>
<p><strong>The first steps</strong></p>
<p>So this is how we started working:</p>
<ul>
<li>Anna creating a character and making some animations for him (walking, talking) and also creating a couple of buildings for our city.</li>
<li>Graham coding a sound engine in flash (he never coded in flash before!) so the game score could fade to another song in a seamless way.</li>
<li>Miguel Angel coding a python app that could hold a representation of whats going on in the world, like streets, crossings, people and important information. So when I have my game working I could read information from his side instead of creating it.</li>
<li>Me creating a small app in flash where a character can move around the map.</li>
</ul>
<p>I wanted to use flixel because is a nice library to create simple games, I have had some experience before and it goes straight to the point for a 2d game.</p>
<p>And here comes my first big mistake, to go there without having the main tools not even installed nor tested, it wouldnt have been a problem if I had used them before but I haven&#8217;t. So I wasted two hours trying to compile the demo application of Flixel under Flex Builder due to some problems with the configuration of the compiler, two precious hours that would have make a huge difference at the end.</p>
<p><strong>The Development</strong></p>
<p>Do not sleep, do not sleep, code code code, do not sleep&#8230; woah, its been 24 hours coding without stop&#8230;</p>
<p><strong>The Last Minute Call</strong></p>
<p>They said you dont need to polish the game if it is a 48 hours compo, but I didnt wanted &#8216;to ship&#8217; the game without an intro, so I asked Anna to create a nice image, we will scroll it to create a small narration with the name of the game at the end.</p>
<p><strong>The Conclusion</strong><br />
After handling the game we all were dead, we barely slept during the last 30 hours and we all need a shower and some rest. So the team was dismantled.</p>
<p>Now looking back I can say that I had a wonderful team, all of them did their job in a complete professional way, and somehow I feel I wasnt at the same level as them, because I wasted lots of time in stuff that could had been done much faster/better.</p>
<p>Anna was incredible, it was the first time she worked on a game and I couldnt notice it. She understood the constraits of the project all the time, always using the limitations I gave her, handling the assets faster than I could integrate them on the game, and expending the rest of the time polishing every one of them or creating new ones &#8216;just in case&#8217;.</p>
<p>I love to work with Miguel Angel, we understand each other</p>
<p><strong>The Tips</strong></p>
<p>When planning, think in the simplest possible version of your game, the one that achieves the gameplay without anything else, but when coding leave the option to improve it once you have time. For instance, we created a procedural generated map with lots of info about the map, but at the end we could have work with something like a char string where every character is the type of building and nothing else.</p>
<p>Bring all the tools installed in your laptop, with all the libraries that you could need, no matter the kind of game you are going to do. Tools like Photoshop, nice text editors, Dropbox, svn clients, python compiler, whatever you could need.</p>
<p>Gather your team before the compo to create something really simple in a couple of hours, like a ball bouncing on the screen. At least you will know that you are ready to do something bigger.</p>
<p>Give your artist a way to test the assets without having to interact with the coders, or even a config text file so he can change a little bit the behaviour of the game. Something simple, it is not necessary to use XML. That would save some time.</p>
<p>Do not waste time in things that do not add gameplay, those things can come at the end. First try to achieve the gameplay (we totally failed in this point).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=160</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resurrecting the Blog</title>
		<link>http://www.tamats.com/blog/?p=195</link>
		<comments>http://www.tamats.com/blog/?p=195#comments</comments>
		<pubDate>Mon, 16 Apr 2012 17:25:48 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[webdevelopment]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=195</guid>
		<description><![CDATA[I loose count on how many times I&#8217;ve trying to resurrect my blog. I wanted to do a propper devlog like all those amazing blogs I&#8217;m suscribed (I should make a post about them), but when I&#8217;m very active at coding I do not feel very communicative to write about it, so here we go [...]]]></description>
			<content:encoded><![CDATA[<p>I loose count on how many times I&#8217;ve trying to resurrect my blog.<br />
I wanted to do a propper devlog like all those amazing blogs I&#8217;m suscribed (I should make a post about them), but when I&#8217;m very active at coding I do not feel very communicative to write about it, so here we go again.</p>
<p>I plan to write at least once a week to explain how some of my projects are going and to share all those annoying bugs or problems I had discovered and which solutions did I use.</p>
<p>And as I always do, I cleaned my wordpress theme so at least it will help me find the strength to write.</p>
<p>I did a small WebGL widget to make it more interesting, I plan to do more silly 3d widgets over the time.<br />
This one is tiny in code, and it shouldnt take too much resources (it only gets executed when the tab is visible).<br />
I used the library <a title="lightgl" href="https://github.com/evanw/lightgl.js/">lightgl</a> to simplify the code.<br />
Lightgl is a tiny javascript library to wrap some of the WebGL funcionalities in a more friendly code. It helps to upload textures and meshes, compile shaders and it comes with the mathematical operations common to 3D.</p>
<p>Check the code to make the example above</p>
<p><span id="more-195"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> launch3D<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> is_chrome <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">userAgent</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'chrome'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> angle <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> is_mouse_over <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> scale <span style="color: #339933;">=</span> <span style="color: #CC0000;">1.0</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> gl <span style="color: #339933;">=</span> GL.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	gl.<span style="color: #660066;">clearColor</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0.9</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0.9</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0.9</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> mesh <span style="color: #339933;">=</span> GL.<span style="color: #660066;">Mesh</span>.<span style="color: #660066;">cube</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> shader <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> GL.<span style="color: #660066;">Shader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\</span>
	  varying vec2 coord;<span style="color: #000099; font-weight: bold;">\</span>
	  void main() {<span style="color: #000099; font-weight: bold;">\</span>
		coord = gl_TexCoord.xy;<span style="color: #000099; font-weight: bold;">\</span>
		gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;<span style="color: #000099; font-weight: bold;">\</span>
	  }<span style="color: #000099; font-weight: bold;">\</span>
	'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\</span>
	uniform sampler2D texture;<span style="color: #000099; font-weight: bold;">\</span>
    varying vec2 coord;<span style="color: #000099; font-weight: bold;">\</span>
	uniform vec3 u_color;<span style="color: #000099; font-weight: bold;">\</span>
	uniform float u_usetex;<span style="color: #000099; font-weight: bold;">\</span>
	void main() {<span style="color: #000099; font-weight: bold;">\</span>
		gl_FragColor = vec4(0.7, 0.7, 0.7, 1.0);<span style="color: #000099; font-weight: bold;">\</span>
		vec3 color = u_color + vec3(1.0 - gl_FragCoord.x/256.0,1.0 - gl_FragCoord.y/256.0,1.0);<span style="color: #000099; font-weight: bold;">\</span>
		if(u_usetex == 1.0)<span style="color: #000099; font-weight: bold;">\</span>
			color *= texture2D(texture,  gl_FragCoord.xy / 4.0 ).xyz;<span style="color: #000099; font-weight: bold;">\</span>
		gl_FragColor = vec4( color,1.0);<span style="color: #000099; font-weight: bold;">\</span>
	}<span style="color: #000099; font-weight: bold;">\</span>
	'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> texture <span style="color: #339933;">=</span> GL.<span style="color: #660066;">Texture</span>.<span style="color: #660066;">fromURL</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'data/pattern4.png'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>wrap<span style="color: #339933;">:</span> gl.<span style="color: #660066;">REPEAT</span><span style="color: #339933;">,</span> filter<span style="color: #339933;">:</span> gl.<span style="color: #660066;">NEAREST</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	gl.<span style="color: #660066;">onupdate</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>seconds<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	  angle <span style="color: #339933;">+=</span> <span style="color: #CC0000;">20</span> <span style="color: #339933;">*</span> seconds<span style="color: #339933;">;</span>
	  scale <span style="color: #339933;">=</span> scale <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.9</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">0.1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	gl.<span style="color: #660066;">ondraw</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	  gl.<span style="color: #660066;">clear</span><span style="color: #009900;">&#40;</span>gl.<span style="color: #660066;">COLOR_BUFFER_BIT</span> <span style="color: #339933;">|</span> gl.<span style="color: #660066;">DEPTH_BUFFER_BIT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  gl.<span style="color: #660066;">loadIdentity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  gl.<span style="color: #660066;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	  texture.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  gl.<span style="color: #660066;">scale</span><span style="color: #009900;">&#40;</span>scale<span style="color: #339933;">,</span>scale<span style="color: #339933;">,</span>scale<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	  <span style="color: #006600; font-style: italic;">//bg</span>
	  gl.<span style="color: #660066;">pushMatrix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  gl.<span style="color: #660066;">rotate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">45</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  gl.<span style="color: #660066;">rotate</span><span style="color: #009900;">&#40;</span>angle<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  shader.<span style="color: #660066;">uniforms</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> texture<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> u_color<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2.0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2.0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2.0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> u_usetex<span style="color: #339933;">:</span> is_chrome <span style="color: #339933;">?</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  shader.<span style="color: #660066;">draw</span><span style="color: #009900;">&#40;</span>mesh<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	  gl.<span style="color: #660066;">scale</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0.9</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0.9</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0.9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  shader.<span style="color: #660066;">uniforms</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> texture<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> u_color<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0.0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0.0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0.0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> u_usetex<span style="color: #339933;">:</span> is_chrome <span style="color: #339933;">?</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  shader.<span style="color: #660066;">draw</span><span style="color: #009900;">&#40;</span>mesh<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  gl.<span style="color: #660066;">popMatrix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//set size</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#bgwidget&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span> gl.<span style="color: #660066;">canvas</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  gl.<span style="color: #660066;">canvas</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">256</span><span style="color: #339933;">;</span>
	  gl.<span style="color: #660066;">canvas</span>.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">256</span><span style="color: #339933;">;</span>
	  <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	  gl.<span style="color: #660066;">viewport</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> gl.<span style="color: #660066;">canvas</span>.<span style="color: #660066;">width</span><span style="color: #339933;">,</span> gl.<span style="color: #660066;">canvas</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	gl.<span style="color: #660066;">matrixMode</span><span style="color: #009900;">&#40;</span>gl.<span style="color: #660066;">PROJECTION</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	gl.<span style="color: #660066;">loadIdentity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	gl.<span style="color: #660066;">perspective</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">fov</span> <span style="color: #339933;">||</span> <span style="color: #CC0000;">45</span><span style="color: #339933;">,</span> gl.<span style="color: #660066;">canvas</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">/</span> gl.<span style="color: #660066;">canvas</span>.<span style="color: #660066;">height</span><span style="color: #339933;">,</span>
	  options.<span style="color: #660066;">near</span> <span style="color: #339933;">||</span> <span style="color: #CC0000;">0.1</span><span style="color: #339933;">,</span> options.<span style="color: #660066;">far</span> <span style="color: #339933;">||</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	setInterval<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		scale <span style="color: #339933;">+=</span> <span style="color: #CC0000;">0.05</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//gl.loadIdentity();</span>
	<span style="color: #006600; font-style: italic;">//gl.ortho(-2,2,-2,2,-10,10);</span>
&nbsp;
	gl.<span style="color: #660066;">matrixMode</span><span style="color: #009900;">&#40;</span>gl.<span style="color: #660066;">MODELVIEW</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">//gl.fullscreen();</span>
	gl.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=195</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.OBJ to JSON python script</title>
		<link>http://www.tamats.com/blog/?p=169</link>
		<comments>http://www.tamats.com/blog/?p=169#comments</comments>
		<pubDate>Sun, 26 Jun 2011 10:45:31 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[webdevelopment]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=169</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>I have developed a small script in python to convert OBJs to JSON, well suited for WebGL rendering.<br />
It is not very optimized, and it only support OBJs with one mesh with UVs and Normals.<br />
It computes the bounding box and clamp to 3 decimals all the values to avoid some ugly values.<br />
It support indexed meshes and coordinates swap for 3ds MAX exported meshes.</p>
<p>The code after the jump.<br />
<span id="more-169"></span></p>
<p>Usage: call the script passing the obj filename as a parameter<br />
You can add a second parameter specifying a name for the object, this is useful when using the output file as a script include in your code instead of a AJAX call. Then the output will be: myname = {&#8230;}</p>
<p>Enjoy it!</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #808080; font-style: italic;"># .OBJ to JSON</span>
<span style="color: #808080; font-style: italic;"># by Javi Agenjo (javi.agenjo@gmail.com) 26/6/11</span>
<span style="color: #808080; font-style: italic;"># only works with OBJs with normals and uvs</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>,<span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> json,<span style="color: #dc143c;">math</span>
&nbsp;
version = <span style="color: #483d8b;">&quot;0.4&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">2</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Error: Filename parameter missing&quot;</span>
    exit<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
filename = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
meshname = <span style="color: #483d8b;">&quot;&quot;</span>
objectname = <span style="color: #483d8b;">''</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">2</span>:
    objectname = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>
&nbsp;
use_3dsmax = <span style="color: #008000;">False</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">&quot;-max&quot;</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span>: use_3dsmax = <span style="color: #008000;">True</span>
&nbsp;
use_indexed = <span style="color: #008000;">True</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">&quot;-indexed&quot;</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span>: use_indexed = <span style="color: #008000;">True</span>
&nbsp;
indexed_vertices = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
indexed_normals = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
indexed_uvs = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
positions = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
normals = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
uvs = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
indices = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
unique_indexed = <span style="color: #ff4500;">0</span>
indexed_triplets = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> add<span style="color: black;">&#40;</span>v<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">global</span> positions,normals,uvs,indexed_vertices,indexed_normals,indexed_uvs
    t = v.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #808080; font-style: italic;">#print &quot;*&quot;+v+&quot;*&quot;</span>
    positions.<span style="color: black;">append</span><span style="color: black;">&#40;</span> indexed_vertices<span style="color: black;">&#91;</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span> <span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>    
    uvs.<span style="color: black;">append</span><span style="color: black;">&#40;</span> indexed_uvs<span style="color: black;">&#91;</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span> <span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
    normals.<span style="color: black;">append</span><span style="color: black;">&#40;</span> indexed_normals<span style="color: black;">&#91;</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span> <span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>positions<span style="color: black;">&#41;</span> - <span style="color: #ff4500;">1</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> addIndexed<span style="color: black;">&#40;</span>v<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">global</span> indexed_triplets, indices
    i = indexed_triplets.<span style="color: black;">get</span><span style="color: black;">&#40;</span>v<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> i == <span style="color: #008000;">None</span>:
        i = add<span style="color: black;">&#40;</span>v<span style="color: black;">&#41;</span>
	indexed_triplets<span style="color: black;">&#91;</span>v<span style="color: black;">&#93;</span> = i
    indices.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> array2string<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>:
    r = <span style="color: #483d8b;">&quot;[&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> v <span style="color: #ff7700;font-weight:bold;">in</span> a:
        <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> v:
            r += <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;,&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> r<span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;]&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> linealize<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>:
    r = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> v <span style="color: #ff7700;font-weight:bold;">in</span> a:
        <span style="color: #ff7700;font-weight:bold;">for</span> n <span style="color: #ff7700;font-weight:bold;">in</span> v:
            r.<span style="color: black;">append</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> r
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> computeMinMax<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>:
    min_v = <span style="color: black;">&#91;</span><span style="color: #ff4500;">1000000</span>,<span style="color: #ff4500;">1000000</span>,<span style="color: #ff4500;">1000000</span><span style="color: black;">&#93;</span>
    max_v = <span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1000000</span>,-<span style="color: #ff4500;">1000000</span>,-<span style="color: #ff4500;">1000000</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> v <span style="color: #ff7700;font-weight:bold;">in</span> a:
        min_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">min</span><span style="color: black;">&#40;</span> min_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, v<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
        min_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">min</span><span style="color: black;">&#40;</span> min_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, v<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
        min_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">min</span><span style="color: black;">&#40;</span> min_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>, v<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
        max_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span> max_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, v<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
        max_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span> max_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, v<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
        max_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span> max_v<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>, v<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span>min_v,max_v<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">try</span>:
    fin = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">IOError</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Error: file cannot be opened&quot;</span>
    exit<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">try</span>:
    <span style="color: #808080; font-style: italic;">#if True:</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> fin.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;">#print line</span>
        line = line.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>,<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>
        line = line.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;  &quot;</span>,<span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#41;</span>
	line = line.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        words = line.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">' '</span><span style="color: black;">&#41;</span>
        <span style="color: #808080; font-style: italic;">#print &quot;:::&quot; + words[0]</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> words<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'#'</span>:
            <span style="color: #ff7700;font-weight:bold;">continue</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> words<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'v'</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> use_3dsmax:
                indexed_vertices.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: black;">&#91;</span> -<span style="color: #ff4500;">1</span> <span style="color: #66cc66;">*</span> <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                indexed_vertices.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: black;">&#91;</span> <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> ,<span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>    
        <span style="color: #ff7700;font-weight:bold;">elif</span> words<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'vn'</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> use_3dsmax:
	        indexed_normals.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: black;">&#91;</span> -<span style="color: #ff4500;">1</span> <span style="color: #66cc66;">*</span> <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> , <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
	    <span style="color: #ff7700;font-weight:bold;">else</span>:
	        indexed_normals.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: black;">&#91;</span> <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> , <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> words<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'vt'</span>:
            indexed_uvs.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: black;">&#91;</span> <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> words<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'f'</span>:
            size = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#41;</span>
            <span style="color: #808080; font-style: italic;">#0 is f, #1 first vertex, start in 2, ends when there is one remaining</span>
            <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>,size-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
                <span style="color: #808080; font-style: italic;">#print &quot;T:&quot;+line+&quot;=&gt;[&quot;+str(i)+&quot;]&quot;+words[i]+&quot; len: &quot;+str(len(words))</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> use_indexed:
                    addIndexed<span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                    addIndexed<span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                    addIndexed<span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
                    add<span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                    add<span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                    add<span style="color: black;">&#40;</span>words<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> words<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'g'</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">1</span>:
	    <span style="color: #808080; font-style: italic;">#print words</span>
            meshname = words<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Error, problem parsing OBJ&quot;</span>
    exit<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
fin.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>positions<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Error, no OBJ info found&quot;</span>
    exit<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
minmax = computeMinMax<span style="color: black;">&#40;</span>indexed_vertices<span style="color: black;">&#41;</span>
&nbsp;
obj = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;version&quot;</span><span style="color: black;">&#93;</span> = version
obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;filename&quot;</span><span style="color: black;">&#93;</span> = filename
obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;meshname&quot;</span><span style="color: black;">&#93;</span> = meshname
obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;positions&quot;</span><span style="color: black;">&#93;</span> = linealize<span style="color: black;">&#40;</span>positions<span style="color: black;">&#41;</span>
obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;normals&quot;</span><span style="color: black;">&#93;</span> = linealize<span style="color: black;">&#40;</span>normals<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>indices<span style="color: black;">&#41;</span>:
    obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;indices&quot;</span><span style="color: black;">&#93;</span> = indices
obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;uvs&quot;</span><span style="color: black;">&#93;</span> = linealize<span style="color: black;">&#40;</span>uvs<span style="color: black;">&#41;</span>
obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;aabb_min&quot;</span><span style="color: black;">&#93;</span> = minmax<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;aabb_max&quot;</span><span style="color: black;">&#93;</span> = minmax<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;numvertices&quot;</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>positions<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> json <span style="color: #ff7700;font-weight:bold;">import</span> encoder
encoder.<span style="color: black;">FLOAT_REPR</span> = <span style="color: #ff7700;font-weight:bold;">lambda</span> o: format<span style="color: black;">&#40;</span>o, <span style="color: #483d8b;">'.3f'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> objectname <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">''</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> objectname + <span style="color: #483d8b;">&quot; = &quot;</span>,
<span style="color: #ff7700;font-weight:bold;">print</span> json.<span style="color: black;">dumps</span><span style="color: black;">&#40;</span>obj<span style="color: black;">&#41;</span>
exit<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=169</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solution: WordPress problem uploading images</title>
		<link>http://www.tamats.com/blog/?p=153</link>
		<comments>http://www.tamats.com/blog/?p=153#comments</comments>
		<pubDate>Thu, 16 Sep 2010 17:31:50 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[webdevelopment]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=153</guid>
		<description><![CDATA[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&#8217;t able to upload [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>After installing WordPress on my server I wasn&#8217;t able to upload images using the admin page, it said something like <strong>&#8220;The uploaded file could not be moved to &#8230;&#8221;</strong> (&#8220;El archivo subido no se ha podido mover a &#8230;&#8221; in spanish).</p>
<p>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.</p>
<p>But it didnt. I realized that the uploads folder of WordPress &#8220;wp-content/uploads&#8221; was created by Apache, not by my user, so that was the problem.</p>
<p>I deleted the folder <strong>/wp-content/uploads</strong> which was empty, and create it again using my ftp client, problem solved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=153</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WebGL: Day 1</title>
		<link>http://www.tamats.com/blog/?p=148</link>
		<comments>http://www.tamats.com/blog/?p=148#comments</comments>
		<pubDate>Thu, 08 Jul 2010 14:15:58 +0000</pubDate>
		<dc:creator>tamat</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[webdevelopment]]></category>

		<guid isPermaLink="false">http://www.tamats.com/blog/?p=148</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>I like to code in OpenGL, andI like to code javascript, and now WebGL allows me to do both things at the same time!.</p>
<p>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).</p>
<p>Unfortunately WebGL is not mature enough and It is kind of hard to start even for a experienced programmer.</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>Also JS doesnt support operands so you can do V1 + V2, you end up with sum(V1,V2) which is annoying for long formulas.</p>
<p>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.</p>
<p>Anyway, I decided to switch to a framework build uppon WebGL, because working straight to WebGL is slow and tedious.</p>
<p>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&#8230;</p>
<p>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.</p>
<p>Sadly I havent figured out how to export meshes in a binary format&#8230;</p>
<p>Anyway, If I have time I will upload some of the examples I coded, but remember that you need a WebGL capable browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tamats.com/blog/?feed=rss2&#038;p=148</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

