<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:planet="http://planet.intertwingly.net/" xmlns:indexing="urn:atom-extension:indexing" indexing:index="no"><access:restriction xmlns:access="http://www.bloglines.com/about/specs/fac-1.0" relationship="deny"/>
  <title>Planet WebGL</title>
  <updated>2012-02-05T08:00:10Z</updated>
  <generator uri="http://intertwingly.net/code/venus/">Venus</generator>
  <author>
    <name>Christopher Blizzard</name>
    <email>blizzard@mozilla.com</email>
  </author>
  <id>http://planet-webgl.com/atom.xml</id>
  <link href="http://planet-webgl.com/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://planet-webgl.com/" rel="alternate"/>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2012/01/20/casting-shadows</id>
    <link href="http://learningthreejs.com/blog/2012/01/20/casting-shadows/" rel="alternate" type="text/html"/>
    <title>Casting Shadows</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post is about
<a href="http://en.wikipedia.org/wiki/Shadow_mapping">shadow casting</a>,
a technique which approximates the effect you see in real life everyday.
They may be tricky to tune but they looks so good, it worths it.
Shadows are an efficient tool when you to make your scene more realistic.
We will see how they can be used inside
<a href="https://github.com/mrdoob/three.js/">three.js</a>
and see more about lights while we are at it.</p>

<p>As usual, there is a <a href="http://learningthreejs.com/data/casting-shadows/">demo</a>.
It is kept it real simple thus you can read the code more easily.
The scene is a simple object in the middle, a spotlight moving around and a plane
to receive the object shadow. The light frustum is left visible in orange.</p>

&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="420" mozallowfullscreen="mozallowfullscreen" src="http://learningthreejs.com/data/casting-shadows" webkitallowfullscreen="webkitallowfullscreen" width="100%"&gt;
&lt;/iframe&gt;







<h2>Let's Code Shadows</h2>

<p>Casting shadows in
<a href="https://github.com/mrdoob/three.js/">three.js</a>
involves 3 parts: the
<a href="https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLRenderer.js">renderer</a>
which does the computation, the
<a href="https://github.com/mrdoob/three.js/tree/master/src/lights">lights</a>
which cast shadows, and
<a href="https://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js">objects</a>
which receives lights and shadows.</p>

<h2>Set up the Renderer</h2>

<p>The renderer is the one which will compute the shadows positions for your 3D scene.
Shadow casting is quite expensive. It is only supported by
<a href="https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLRenderer.js">WebGLRenderer</a>.
It uses
<a href="http://en.wikipedia.org/wiki/Shadow_mapping">Shadow mapping</a>, a technique specific
to WebGL, performed directly on the <a href="http://en.wikipedia.org/wiki/Graphics_processing_unit">GPU</a>.</p>

<p>```javascript</p>

<pre><code>renderer.shadowMapEnabled = true;
</code></pre>

<p>```</p>

<p><img alt="" class="right " height="" src="http://learningthreejs.com/data/casting-shadows/images/screenshot-withsoftshadow-small.png" title="" width=""/>
<img alt="" class="left " height="" src="http://learningthreejs.com/data/casting-shadows/images/screenshot-nosoftshadow-small.png" title="" width=""/></p>

<p>You can smooth produced shadows with <code>shadowMapSoft</code>. It default to false.
On the left, the shadow is crisp, on the right it is soft.</p>

<p>```javascript</p>

<pre><code>// to antialias the shadow
renderer.shadowMapSoft = true;
</code></pre>

<p>```</p>

<h2>Configure your objects</h2>

<p>For
<a href="https://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js">Object3D</a>,
two parameters controls how they interact with lights and shadows.
Set <code>.castShadow</code> to true if the object occludes light, so to cast a shadow.
Set <code>.receiveShadow</code> to true if the object is supposed to receive shadows.
Both default to false</p>

<p>```javascript</p>

<pre><code>object3d.castShadow = true;
object3d.receiveShadow  = false;
</code></pre>

<p>```</p>

<p>This is the configuration for the central object in the demo. It will occlude lights but
won't be able to receive shadow. So you wont see any
<a href="http://en.wikipedia.org/wiki/Self-shadowing">self shadow</a>.</p>

<h2>Tune your Lights</h2>

<p><img alt="" class="left  " height="" src="http://learningthreejs.com/data/casting-shadows/images/light-directionallight-small.jpg" title="" width=""/>
<img alt="" class="right " height="" src="http://learningthreejs.com/data/casting-shadows/images/light-spotlight-small.jpg" title="" width=""/></p>

<p><a href="https://github.com/mrdoob/three.js/blob/master/src/lights/DirectionalLight.js">THREE.DirectionalLight</a>
or
<a href="https://github.com/mrdoob/three.js/blob/master/src/lights/SpotLight.js">THREE.SpotLight</a>
are able to cast shadows.
Let's details them.
A directional light is when light rays are parallel.
A bit like when you look at the sun rays on the left.
It mostly behaves like a light source very far from us.
A spot light is when light rays seems to originate from a single point, and
spreads outward in a coned direction, like in the dance club on the right
(Images are from wikipedia).
To enable the shadow casting on a light,
just use this line.</p>

<p>```javascript</p>

<pre><code>light.castShadow = true;
</code></pre>

<p>```</p>

<p>You can tune the <code>shadowDarkness</code>.
It is the opacity of the shadow. 0 means no shadow, 1 means pure back shadow.</p>

<p>```javascript</p>

<pre><code>light.shadowDarkness = 0.5;
</code></pre>

<p>```</p>

<p><img alt="" class="right " height="" src="http://learningthreejs.com/data/casting-shadows/images/screenshot-shadowCameraVisible-small.png" title="" width=""/></p>

<p>In the same vibe, it possible to show the shadow camera on the screen
with <code>shadowCameraVisible</code>.
A very usefull feature during tuning or debugging.</p>

<p>```javascript</p>

<pre><code>light.shadowCameraVisible = true;
</code></pre>

<p>```</p>

<h2>More of Directional Lights</h2>

<p><img alt="" class="right " height="" src="http://learningthreejs.com/data/casting-shadows/images/screenshot-fustrum-orthographic-small.png" title="" width=""/>
<img alt="" class="left  " height="" src="http://learningthreejs.com/data/casting-shadows/images/screenshot-fustrum-perspective-small.png" title="" width=""/></p>

<p>Additionally, when casting shadow with a
<a href="https://github.com/mrdoob/three.js/blob/master/src/lights/DirectionalLight.js">THREE.DirectionalLight</a>,
you need to setup an orthographic camera.
What is that ? it is a different form of
<a href="http://en.wikipedia.org/wiki/3D_projection">3D projection</a>.
<a href="http://en.wikipedia.org/wiki/Perspective_(graphical)">Perspective</a>
is the way we see things in real life.
So it seems more natural to us than
<a href="http://en.wikipedia.org/wiki/Orthographic_projection">orthographic projection</a>.
On the left, an illustration shows a perspective projection.
You can see what is inside the orange shape.
On the right, the same for a orthographic one.</p>

<p>Recent
<a href="https://github.com/mrdoob/three.js/commit/32b581f24fddeaf9e91b7825aa93ec0ad3a45c83">three.js r47 release</a>
includes a
<a href="http://mrdoob.github.com/three.js/examples/webgl_camera.html">very didactic example</a>
from
<a href="http://alteredqualia.com/">alteredq</a>.
Play with it, it may understand the difference between
<a href="https://github.com/mrdoob/three.js/blob/master/src/cameras/OrthographicCamera.js">orthographic</a>
and
<a href="https://github.com/mrdoob/three.js/blob/master/src/cameras/PerspectiveCamera.js">perspective</a>
cameras.
Here is a possible configuration of the frustum for the orthographic camera of our light.</p>

<p>```javascript</p>

<pre><code>light.shadowCameraRight     =  5;
light.shadowCameraLeft      = -5;
light.shadowCameraTop       =  5;
light.shadowCameraBottom    = -5;
</code></pre>

<p>```</p>

<h2>Conclusion</h2>

<p>This is it, you can code shadow casting in three.js now :)
Go ahead and play with them. They are hard to master but very efficient visually.
Keep in mind that those shadows aren't real.
They only uses
<a href="http://en.wikipedia.org/wiki/Shadow_mapping">'some tricks'</a>
to make them appears as real. And they do so in real time !!
To achieve this result, they take significant shortcuts which
produce artifacts. To avoid those require tuning and experience.</p>

<p>That's all for today folks. Have fun.</p></div>
    </summary>
    <updated>2012-01-20T13:44:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:11Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2012/01/19/boilerplate-builder-for-three-js</id>
    <link href="http://learningthreejs.com/blog/2012/01/19/boilerplate-builder-for-three-js/" rel="alternate" type="text/html"/>
    <title>Boilerplate Builder for Three.js</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>We recently introduced a
<a href="https://github.com/jeromeetienne/threejsboilerplate">boilerplate for three.js</a>
in a
<a href="http://learningthreejs.com/blog/2011/12/20/boilerplate-for-three-js/">previous post</a>.
It aims to ease your first contact with
<a href="https://github.com/mrdoob/three.js/">three.js</a>.
It contains a template for a simple project,
a sample on which we already applied good practices.
You download it and run it in a matter of minutes.
Thus you can immediatly focus on your own things.
In short, it aims for <em>Fast bootstrap + Good Practices</em>.</p>

<p>It seems nice, hey ?
Well there is a glitch.
The
<a href="https://github.com/jeromeetienne/threejsboilerplate">boilerplate for three.js</a>
needs more flexibily.
In a way, it acts as a ground on top of which you start your own thing.
We do our best to provide good defaults, but they are only defaults.
What if you got specific requirements ?
How to start your project then ?
The
<a href="http://jeromeetienne.github.com/threejsboilerplatebuilder/">boilerplate builder</a>
has been written for you :)</p>

<p><a href="http://jeromeetienne.github.com/threejsboilerplatebuilder/">Try it out</a>.
Go ahead, play with the options,
discover what they do and customize your own boilerplate.
The
<a href="http://www.youtube.com/watch?v=ANnPWZGRsGk">screencast</a>
below is short introduction where i describe the
<a href="http://jeromeetienne.github.com/threejsboilerplatebuilder/">boilerplate builder</a>.</p>






<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="349" src="http://www.youtube.com/embed/ANnPWZGRsGk?hl=en&amp;amp;fs=1" width="425"&gt;&lt;/iframe&gt;
</center>


<h2>Making-Of the Builder</h2>

<p>The
<a href="http://jeromeetienne.github.com/threejsboilerplatebuilder/">builder</a>
itself was interesting to build.
It uses various nice features from the current web.
It is a pure-browser webapp with a file download,
a preview of a webgl project
and a nice looking visual appearance.</p>

<h3>Pure Browser Download</h3>

<p>I like to write pure-browser application.
They dont require a server to run, only static files.
It makes it much easier to host your application.
So
<a href="http://jeromeetienne.github.com/threejsboilerplatebuilder/">boilerplate builder</a>
has been written as a pure-browser application :)
It uses
<a href="http://jszip.stuartk.co.uk/">jszip</a>
, a library which create .zip files with Javascript.
Its creates the boilerplater.zip that you download.
Additionally, it uses
<a href="https://github.com/dcneiner/Downloadify">downloadify</a>
, a small library to create and download files without server.</p>

<p>Together,
<a href="http://jszip.stuartk.co.uk/">jszip</a>
and
<a href="https://github.com/dcneiner/Downloadify">downloadify</a>
makes it easy to pack several files together,
and allow the user to download it.
All that in pure-browser, neat no?
I love what the web is becoming!</p>

<h3>Boilerplate Preview</h3>

<p>The preview is a bit different.
We start to load the <em>index.html</em> template for the boilerplate.
We apply all the options you configured and produce the final version.
To actually preview this file, we encode it in
<a href="http://en.wikipedia.org/wiki/Base64">base64</a>
to build a
<a href="http://en.wikipedia.org/wiki/Data_URI_scheme">data url</a>
with it.
Only then, we create an iframe with this data uri
and you can see the webgl preview :)</p>

<p><a href="http://en.wikipedia.org/wiki/Data_URI_scheme">Data url</a>
is <a href="http://tools.ietf.org/html/rfc2397">an old thing from 1998</a>
which is back in spotlight due to HTML5.
It allows to encode data directly in the URL.
It may be used to include image directly in css for examples.
Very usefull but not for human consumption.
To give you an idea, here is
<a href="http://pastebin.com/yF3XDSFW">index.html</a>
as a data url in
<a href="http://en.wikipedia.org/wiki/Base64">base64</a>.
You could encode it as text if you
<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURI">escape</a>
it
<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent">properly</a>.
It looks like long ugly random string.</p>

<p>```</p>

<pre><code>data:text/html;base64,PCFkb2N0eXBlIGh0....
</code></pre>

<p>```</p>

<h3>Visual Appearance</h3>

<p>It includes
<a href="http://twitter.github.com/bootstrap/">twitter bootstrap</a> for css.
I am quite grateful for this framework.
Without it, the
<a href="http://jeromeetienne.github.com/threejsboilerplatebuilder/">builder page</a>
will be so ugly, that people run away without even trying the application itself.
<a href="http://twitter.github.com/bootstrap/">twitter bootstrap</a>
makes it so easy to write a webapp which looks good on the screen.
I think all the css-impaired of the world should thanks twitter for this framework :)</p>

<h2>Conclusion</h2>

<p>It has been quite fun to write it.
I learned some web skills,
discovered new part of three.js,
and on top of that, it looks good on screen.
I could not ask for more.
The goal of
<a href="http://jeromeetienne.github.com/threejsboilerplatebuilder/">boilerplate builder for three.js</a>
is to add more <em>flexibility</em> to the <em>fast bootstrap + good practices</em> from the
<a href="https://github.com/jeromeetienne/threejsboilerplate">boilerplate</a>.
I hope it will help people starting lots of new
<a href="https://github.com/mrdoob/three.js/">three.js</a>
projects :)</p>

<p>That's all folks.
Have fun.</p></div>
    </summary>
    <updated>2012-01-19T09:59:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:12Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2012/01/17/dom-events-in-3d-space</id>
    <link href="http://learningthreejs.com/blog/2012/01/17/dom-events-in-3d-space/" rel="alternate" type="text/html"/>
    <title>Dom Events in 3D Space</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Ever dreamed of a <strong>object3d.on('click', function(){ ... });</strong>?</p>

<p>I have :) This post presents a little experiment.
What about implementing the concept of
<a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html">dom events</a>
in 3D Space.
In a web page, a
<a href="http://www.quirksmode.org/dom/events/click.html">click</a>
event is trigger when a user click on a
<a href="http://en.wikipedia.org/wiki/HTML_element">element</a>.
This is common knowledge in web development.
What about having that but in a three.js scene ?
Maybe people will start do 3D user interface with that, who knows.
How great would that be ?!?
So let's do that.</p>

<p><a href="http://jeromeetienne.github.com/threex/examples/threex.domevent/">Try it out</a>.
The demo contains 3 teapots.
Each bind a different type of events.
When the events are triggered, teapots are animated.
Animations are made by <a href="https://github.com/sole/tween.js/">tween.js</a>, a nice js tweening engine
seen in a <a href="http://learningthreejs.com/blog/2011/08/17/tweenjs-for-smooth-animation/">previous post</a>.
Play with it to get a feel of it, maybe think about the type of UI you could do in 3D.</p>






<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="349" src="http://www.youtube.com/embed/c2KLj8sie9Q?hl=en&amp;amp;fs=1" width="425"&gt;&lt;/iframe&gt;
</center>


<h2>Let's Get Started</h2>

<p>First let's include the source.
You download <a href="https://github.com/jeromeetienne/threex/blob/master/threex.domevent.js">threex.domevent.js</a>.
and copy this line in your page.</p>

<p>```html</p>

<pre><code>&lt;script src='threex.domevent.js'&gt;&lt;/script&gt;
</code></pre>

<p>```</p>

<h2>Let's Use It</h2>

&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" mozallowfullscreen="mozallowfullscreen" src="http://jeromeetienne.github.com/threex/examples/threex.domevent" style="float: right; margin-left: 1em;" webkitallowfullscreen="webkitallowfullscreen" width="420"&gt;
&lt;/iframe&gt;


<p>Let's say we want do to an action when the user is clicking on a object.
We just do the following.</p>

<p>```javascript</p>

<pre><code>mesh.on('click', function(){
    mesh.scale.x *= 2;
});
</code></pre>

<p>```</p>

<p>This short line means "<em>if the user click on this mesh, make it twice wider</em>".
Eloquent meaning, short syntax ... pretty sweet in my book.
If you wish to stop listening just do as usual.</p>

<p>```javascript</p>

<pre><code>mesh.off('click', callback)
</code></pre>

<p>```</p>

<p>In fact, there is 2 naming for those functions:
one is
<a href="https://developer.mozilla.org/en/DOM/element.addEventListener">addEventListener</a>
/
<a href="https://developer.mozilla.org/en/DOM/element.removeEventListener">removeEventListener</a>
from
<a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html">HTMLElement</a>
The other is copied on
<a href="http://jquery.com/">jQuery</a> api:
<a href="http://api.jquery.com/on/">on</a>
/
<a href="http://api.jquery.com/off/">off</a>
Pick the one you like. They are doing the same thing.</p>

<p>Always in a effort to stay close to usual pratices, the events name are the same as in DOM.
The semantic is the same too.
Currently, the available events are
<a href="http://www.quirksmode.org/dom/events/click.html">click, dblclick, mouseup, mousedown</a>,
<a href="http://www.quirksmode.org/dom/events/mouseover.html">mouseover and mouse out</a>.</p>

<h2>Some Internals</h2>

<p><a href="https://github.com/mrdoob/three.js/">three.js</a>
already has the ability to interact with the mouse.
You can see it in action
<a href="http://mrdoob.github.com/three.js/examples/webgl_interactive_cubes.html">here</a>
and
<a href="http://mrdoob.github.com/three.js/examples/webgl_interactive_voxelpainter.html">here</a>.
Internally they use 2 three.js classes:
<a href="https://github.com/mrdoob/three.js/blob/master/src/core/Projector.js">THREE.Projector</a>
and
<a href="https://github.com/mrdoob/three.js/blob/master/src/core/Ray.js">THREE.Ray</a>.
<a href="https://github.com/jeromeetienne/threex/blob/master/threex.domevent.js">threex.domevent.js</a>
is an higher level api on top of those functions,
an interface which mimic dom events,
something closer to the usual web developper.</p>

<p>It is a nice api. clean, short, object oriented and feels familiar to web developpers.
A little hichup tho, it modifies THREE.Object3D class.
It is a global class, so it may be legitimatly considered unclean by some people.
If this bother you, simply do <code>THREEx.DomEvent.noConflict()</code> and use the
standalone API. It is documented in the
<a href="http://jeromeetienne.github.com/threex/docs/threex.domevent.html">annoted source</a>.
In fact, the object oriented API is just a thin wrapper
on top of the standalone API.</p>

<h2>Conclusion</h2>

<p>We all know the click event when the user click on a webpage.
This experiment wishes to provide to web developpers the same experience in 3D.
I hope people will do crazy innovations by using 3D in user interfaces.
This is a first version. Maybe we will implement
<a href="http://www.quirksmode.org/js/events_order.html">bubbling</a>
in the future, even events like
<a href="http://www.quirksmode.org/dom/events/change.html">'change'</a>.</p>

<p>As usual, <a href="https://github.com/jeromeetienne/threex/blob/master/threex.domevent.js">threex.domevent.js</a>
source is available on
<a href="https://github.com/jeromeetienne/threex/blob/master/threex.domevent.js">github</a>.
There is an
<a href="http://jeromeetienne.github.com/threex/docs/threex.domevent.html">annoted source</a>
for implementation details.
That's all folks. Have fun.</p></div>
    </summary>
    <updated>2012-01-17T10:56:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:11Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2012/01/11/tunnel-effect</id>
    <link href="http://learningthreejs.com/blog/2012/01/11/tunnel-effect/" rel="alternate" type="text/html"/>
    <title>Tunnel Effect for your Demo</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post presents a tunnel effect.
This is a classic in 3D demo.
They are visually efficient and easy to code.
In fact, tunnels are so trendy that
even
<a href="http://en.wikipedia.org/wiki/Doctor_Who">doctor who</a>
and
<a href="http://en.wikipedia.org/wiki/Stargate">stargate</a>
have
<a href="http://www.youtube.com/watch?v=IKo9f5npLNM">fun</a>
<a href="http://www.youtube.com/watch?v=KDIdJtW0vN4">in them</a>
:)</p>

<p><a href="http://jeromeetienne.github.com/tunnelgl/">Try the demo</a>.
It has been built using the
<a href="https://github.com/jeromeetienne/threejsboilerplate">boilerplate for three.js</a>
seen in a
<a href="http://learningthreejs.com/blog/2011/12/20/boilerplate-for-three-js/">previous post</a>.
The code is simple and small.
Less than 20lines has been added on top of the boilerplate.
We will create a
<a href="https://github.com/mrdoob/three.js/blob/master/src/core/Geometry.js">THREE.Geometry</a>
to get the shape of tunnel.
Then we will use a
<a href="https://github.com/mrdoob/three.js/blob/master/src/textures/Texture.js">texture</a>
trick to create the
<a href="http://en.wikipedia.org/wiki/Optical_illusion">visual illusion</a>
of moving.</p>






&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="420px" mozallowfullscreen="mozallowfullscreen" src="http://jeromeetienne.github.com/tunnelgl/" webkitallowfullscreen="webkitallowfullscreen" width="100%"&gt;
&lt;/iframe&gt;


<h2>Let's build the walls</h2>

<p>The first step is to build the <em>walls</em> of the tunnel.
It is easier that one would expect.
A tunnel may be seen as a cylinder with the camera inside.
Once you realized that, most of the work is done.
Luckily for us,
<a href="https://github.com/mrdoob/three.js/">three.js</a>
got an easy way to build cylinders, called
<a href="https://github.com/mrdoob/three.js/blob/master/src/extras/geometries/CylinderGeometry.js">CylinderGeometry</a>.
Nevertheless our tunnel / cylinder got 2 special points.</p>

<p>First, it is open-ended. So we must not build its top and bottom.
We need this to see thru its extremities.
This is handled by a parameter in
<a href="https://github.com/mrdoob/three.js/blob/master/src/extras/geometries/CylinderGeometry.js">CylinderGeometry</a>.
We just set <code>openended</code> parameter to true and the rest is done for us :)</p>

<p>Second, the camera is usually located outside of objects.
But our tunnel/cylinder has the camera inside it.
To make our object visible from the inside, we need to turn it inside out.
For that, just use <code>mesh.flipSided = true</code></p>

<h2>Let's go forward</h2>

<p>Now we need to go forward in this tunnel
For that we will use an old trick.
We won't move the tunnel walls themselves, only their appearance.
It gives the visual illusion that we are moving.
Remember what they say in matrix ?
<a href="http://www.youtube.com/watch?v=dzm8kTIj_0M">"there is no spoon"</a>.
It is all the same, we are moving while staying still :)</p>

<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="349" src="http://www.youtube.com/embed/dzm8kTIj_0M?hl=en&amp;amp;fs=1" width="425"&gt;&lt;/iframe&gt;
</center>


<h2>A Texture isn't a spoon</h2>

<p>First we want to move the appearance of the cylinder, thus the player got the illusion to go forward.
We will use <a href="https://github.com/mrdoob/three.js/blob/master/src/textures/Texture.js">THREE.Texture</a> for that.
We wont move the actual pixels of the textures, only its coordinates.
Additionnaly we want the texture to repeat on the cylinder, thus it appears as continuous.
WebGL texture is a powerfull and flexible tool.
You can tweak so many features.</p>

<p>First let's make this texture move.
Suppose we want the texture to loop once every 10 seconds.
So the coordinate <code>.offset.y</code> needs to go from 0 to 1 in 10 seconds.
This line is enougth to make the tunnel move forward.
You can change your speed within the tunnel by changing this number.</p>

<p>```javascript</p>

<pre><code>texture.offset.y    += 0.1 * seconds;
</code></pre>

<p>```</p>

<p>Now the texture repetition.
For that we will use a texture parameter called <em>wrap</em>.
It indicates how the gpu repeat the texture on a face.
Here is a good
<a href="http://lucera-project.blogspot.com/2010/06/opengl-wrap.html">tutorial on opengl wrap</a>.
By default, wrapS / wrapT are set to <code>THREE.ClampToEdgeWrapping</code>.
So the texture is scaled to match exactly the size of the face.
In our case, we want to repeat the texture and not scale it.
So we use <code>THREE.RepeatWrapping</code>.</p>

<p>```javascript</p>

<pre><code>texture.wrapT   = THREE.RepeatWrapping;
</code></pre>

<p>```</p>

<h2>Conclusion</h2>

<p>We have seen how to do a tunnel with
<a href="https://github.com/mrdoob/three.js/">three.js</a>.
This is very simple to code and awesome on the screen.
It is less than 20 lines added to the <a href="https://github.com/jeromeetienne/threejsboilerplate">boilerplate</a>.
The cylinder geometry was already provided.
We used
<a href="https://github.com/mrdoob/three.js/blob/master/src/textures/Texture.js">THREE.Texture</a>
offsets to provide the optical illusion of moving.</p>

<p>Later, we may add a <a href="http://en.wikipedia.org/wiki/TARDIS">blue phonebooth</a>
and play <em>doctor who</em> :)
The code is available on
<a href="https://github.com/jeromeetienne/tunnelgl">github</a>
under MIT license.
Feel free to fork and modify.
That's all folks, have fun.</p></div>
    </summary>
    <updated>2012-01-11T12:00:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:11Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/12/28/let-s-make-a-3d-game-supporting-mobile</id>
    <link href="http://learningthreejs.com/blog/2011/12/28/let-s-make-a-3d-game-supporting-mobile/" rel="alternate" type="text/html"/>
    <title>Let’s Make a 3D Game: Supporting Mobile</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post is about supporting mobile.
We will try to port <a href="http://marblesoccer.com">marblesoccer</a> on mobile.
When doing a
<a href="http://127.0.0.1:8000/blog/2011/12/20/boilerplate-for-three-js/">boilerplate for three.js</a>,
mobile had to be supported for compatibility.
So it gave me the idea of this post.
What about porting our game on mobile ?
Porting a 3D web game to mobile ? crazy :)</p>

<p>The desktop version looks kindof ok.
What would be the result of this experiment ?
Is that even possible ?
What about usable ?
This is the purpose of this experiment to find out.</p>






<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="349" src="http://www.youtube.com/embed/Ow_ceac1aEE?hl=en&amp;amp;fs=1" width="425"&gt;&lt;/iframe&gt;
</center>


<h2>Mobile isn't desktop</h2>

<p>Indeed... desktop and mobile are quite different plateforms.
Which differences are relevant to us ?
First, mobile network is bad, especially latency.
So avoid download of long files, such as texture or sound.
Here is a good talk on
<a href="http://www.youtube.com/watch?v=L2YqfVNHQO4">Mobile Web Performance</a>.
Another thing, mobile got no keyboard, no mouse, but a touch screen
We need to get a game controller for this environement.
We use <a href="https://github.com/jeromeetienne/virtualjoystick.js">virtualjoystick.js</a>.
See details in our <a href="http://learningthreejs.com/blog/2011/12/26/let-s-make-a-3d-game-virtual-joystick/">previous post</a>.</p>

<p>One big thing is that currently, on mobile, WebGL hasnt reached mainstream to say the least.
No major vendor is shipping phone with webgl, so nobody or close get webgl on phone.
So for our little experiment, we will display in
<a href="http://www.w3.org/TR/2010/WD-2dcontext-20100304/">Canvas 2D</a>
with
<a href="https://github.com/mrdoob/three.js/blob/master/src/renderers/CanvasRenderer.js">THREE.CanvasRenderer</a>.</p>

<h2>Porting to canvas 2D</h2>

<p>So what need to be done ?
First step is to use the proper renderer when suitable.
Second is fixing material and geometry to fit canvas2D renderer capability.
Last step is to look for room of optimisations.
Ok now let's intanciate the renderer. If webgl is available, use
<code>THREE.WebGLRenderer</code>
else use
<code>THREE.CanvasRenderer</code>.
Not too hard hey ?
We already did that in the
<a href="http://learningthreejs.com/blog/2011/12/20/boilerplate-for-three-js/">boilerplate for three.js</a></p>

&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" mozallowfullscreen="mozallowfullscreen" src="http://marblesoccer.com?render=canvas&amp;amp;bypasslanding=1" style="float: right; margin-left: 1em;" webkitallowfullscreen="webkitallowfullscreen" width="420"&gt;
&lt;/iframe&gt;


<p>We simplify geometry to reduce the number of polygon.
For marble geometry, the sphere got 512 faces on webgl, and only 9 on canvas2d.
Drastic :)
What about material ? For webgl, we used
<a href="http://en.wikipedia.org/wiki/Phong_shading">phong</a>
for fancy lightings,
We used
<a href="http://en.wikipedia.org/wiki/Texture_mapping">textures</a>
for realistic effects.
But with canvas2D, those technics cant be used.
They are way too slow.</p>

<p>This is enougth to get it working.
It display something reasonable on the screen at least.
We sacrifice a lot tho, no more texture not fancy lighting.
And now the bad new, it results in 3fps on my ipad2 ios4... ouch.</p>

<h2>More measures</h2>

<p>How come performances are so bad ? So i did more measures.
I disabled the display of map and marbles to see how they impact performance.
If we display the map and the marbles, we got 3fps on my ipad2.
If we display only marbles, no more maps, we got 23fps, much better.
but still not great... Considere that we are only displaying marbles and they are real simple.</p>

<p>If we display no marble, and no map. we got only 30fps. So all the rest, all the non display
part is already using a big part of time ? what are we doing ? not much...
Still we run
<a href="http://learningthreejs.com/blog/2011/10/17/lets-make-a-3d-game-microphysics-js/">realistic 3D physics</a>
and ipad2 cpu isnt as fast as usual desktop ones.</p>

<h2>Time to optimize</h2>

<p>Ok it is slow but this is a first try.
I admit the code isnt not too optimized.
<a href="http://en.wikipedia.org/wiki/Central_processing_unit">cpu</a>
/
<a href="http://en.wikipedia.org/wiki/Graphics_processing_unit">gpu</a>
performance are so good on desktop, i may have been sloppy here and there :)
There are areas of optimisations.
We need to draw less polygons.</p>

<p>First we need to <em>reduce the geometry</em> of the map.
We can do that by clustering voxels:
if 2 voxels got the same color and touch each other, display one large box, instead of 2 small boxes.
We did it to optimize our physics.
See details in <a href="http://learningthreejs.com/blog/2011/10/17/lets-make-a-3d-game-microphysics-js/">microphysics post</a>.
Additionnaly we could use marblesoccer's
<a href="http://127.0.0.1:8000/blog/2011/09/14/lets-make-a-3D-game-map-editor/">map editor</a>
to redesign a map with a simpler geometry.</p>

<p>Another low-hanging fruit is to remove faces which are never seen, like in
<a href="http://mrdoob.github.com/three.js/examples/webgl_geometry_minecraft_ao.html">minecraft example</a>
from
<a href="https://github.com/mrdoob/three.js/">three.js</a>.
We could try to 2D sprites instead of 3D spheres for marble.
We wont use
<a href="https://github.com/mrdoob/three.js/blob/master/src/objects/Sprite.js">THREE.Sprite</a>.
It isnt supported
<a href="https://github.com/mrdoob/three.js/blob/master/src/renderers/CanvasRenderer.js">THREE.CanvasRenderer</a>.
But dont worry, it is possible with the particle system.
See how <code>THREE.Particle</code> is used in
<a href="http://mrdoob.github.com/three.js/examples/canvas_particles_sprites.html">canvas_particles_sprites.html</a>
example.</p>

<h2>Conclusion</h2>

<p>And after all that, what can you expect ?
Will that run at 60fps ? 30fps ? Not likely or it will require a lot of effort.
<img alt="" class="left " height="" src="http://learningthreejs.com/data/lets-make-a-3d-game-supporting-mobile/images/screenshot-webgl-small.png" title="" width=""/>
<img alt="" class="right " height="" src="http://learningthreejs.com/data/lets-make-a-3d-game-supporting-mobile/images/screenshot-canvas-small.png" title="" width=""/>
So animations arent smooth, what about the look?
Watch what you got on the screen...
On the right, a canvas version. <a href="http://marblesoccer.com/?render=canvas">live here</a>.
On the left you can see a webgl version. <a href="http://marblesoccer.com">live here</a>.
Lets face it... <em>canvas version is ugly</em>.</p>

<p>After a significant work, you get poor performance and crappy look.
Not many players would accept that...
currently canvas performance doesnt seems suitable to display 3D on mobile.
It is a good way to monitor performances and see how they evolve with time.</p></div>
    </summary>
    <updated>2011-12-28T12:46:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:11Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/12/26/let-s-make-a-3d-game-virtual-joystick</id>
    <link href="http://learningthreejs.com/blog/2011/12/26/let-s-make-a-3d-game-virtual-joystick/" rel="alternate" type="text/html"/>
    <title>Let’s Make a 3D Game: Virtual Joystick</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Here is another article of the "Let's Make a 3D Game"
<a href="http://learningthreejs.com/blog/categories/tutorial3dgame/">series</a>.
We have already seen how to handle other inputs like
<a href="http://learningthreejs.com/blog/2011/09/12/lets-Make-a-3D-game-keyboard/">keyboard</a>
and
<a href="http://learningthreejs.com/blog/2011/09/20/lets-make-a-3D-game-device-orientation/">device orientation</a>.
This post is about <a href="https://github.com/jeromeetienne/virtualjoystick.js">virtualjoystick.js</a>
It <strong>virtual joystick</strong>, another input you can use for your games.
A virtual joystick emulates a joystick behaviour on a touch screen.
<a href="https://github.com/jeromeetienne/virtualjoystick.js">virtualjoystick.js</a>
has been coded in a effort to port
<a href="http://marblesoccer.com">marblesoccer</a>
to mobile device.
Show, dont tell,
<a href="http://jeromeetienne.github.com/virtualjoystick.js/">Try it out</a>.</p>

<p>This
<a href="http://jeromeetienne.github.com/virtualjoystick.js/">demo</a>
works with mouse events too thus, it is easier to test/debug.
<a href="https://github.com/jeromeetienne/virtualjoystick.js">virtualjoystick.js</a>
has been widely inpired by
<a href="http://sebleedelisle.com/2011/04/multi-touch-game-controller-in-javascripthtml5-for-ipad/">this post</a>
by
<a href="http://sebleedelisle.com/">Seb Lee-Delisle</a>.
The screencast below is short introduction about
<a href="https://github.com/jeromeetienne/virtualjoystick.js">virtualjoystick.js</a></p>






<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="349" src="http://www.youtube.com/embed/viyr_W0z1U8?hl=en&amp;amp;fs=1" width="425"&gt;&lt;/iframe&gt;
</center>


<h2>Let's Get Started</h2>

<p>First step, you download
<a href="https://raw.github.com/jeromeetienne/virtualjoystick.js/master/virtualjoystick.js">virtualjoystick.js</a>
from its
<a href="https://github.com/jeromeetienne/virtualjoystick.js">github</a>
Then include it in your own code.</p>

<p>```html</p>

<pre><code>&lt;script src="virtualjoystick.js"&gt;&lt;/script&gt;
</code></pre>

<p>```</p>

<p>The joystick is composed of 2 parts: the <em>base</em> and the <em>stick</em>.
First the plare touch the screen, it gives the position of the <em>base</em>.
Then it drags its fingers to gives the position of the <em>stick</em></p>

<h2>Let's Use it</h2>

&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" mozallowfullscreen="mozallowfullscreen" src="http://jeromeetienne.github.com/virtualjoystick.js/" style="float: right; margin-left: 1em;" webkitallowfullscreen="webkitallowfullscreen" width="420"&gt;
&lt;/iframe&gt;


<p>First step is to create the object from <code>VirtualJoystick</code> class.</p>

<p>```javascript</p>

<pre><code>var joystick = new VirtualJoystick()
</code></pre>

<p>```</p>

<p>The constructor has some options.
They have sensible default.
You can change them to fit your specific needs.
See
<a href="https://github.com/jeromeetienne/virtualjoystick.js#readme">github README</a>
for a full API description.
You may look at the <a href="https://github.com/jeromeetienne/virtualjoystick.js/blob/master/index.html">index.html</a>.
It is an example which uses the library.</p>

<p>It is possible to read
<a href="http://en.wikipedia.org/wiki/Analog_stick">analogic</a>
coordinates.
<code>joystick.deltaX()</code> gives the <em>delta x</em> between the base and the stick in pixel.
<code>joystick.deltaY()</code> gives the <em>delta y</em>.
Those analogic coordinates may be interpreted as a
<a href="http://www.slagcoin.com/joystick/restrictors.html">joystick with 4 switches</a>.
Similar to
<a href="http://en.wikipedia.org/wiki/Arrow_keys">arrow keys</a>
in a way.
<code>joystick.up()</code> tells you if your joystick is up or not.
You guessed the meaning of <code>.down()</code>, <code>.right()</code> and <code>.left()</code>.</p>

<h2>Conclusion</h2>

<p>The source is available on
<a href="https://github.com/jeromeetienne/virtualjoystick.js">github</a>
under MIT license.
Later, a button may be implemented as well.
It is alway usefull to able to fire in video games :)
That's all folks, have fun.</p></div>
    </summary>
    <updated>2011-12-26T11:21:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:11Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/12/20/boilerplate-for-three-js</id>
    <link href="http://learningthreejs.com/blog/2011/12/20/boilerplate-for-three-js/" rel="alternate" type="text/html"/>
    <title>Boilerplate for Three.js</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post presents
<a href="https://github.com/jeromeetienne/threejsboilerplate">boilerplate for three.js</a>.
I looked at
<a href="http://html5boilerplate.com/">html5 boilerplate</a>
and found
<a href="http://www.youtube.com/watch?v=NMEB78VX2P0">it</a>
<a href="http://www.youtube.com/watch?v=oDlsOyPKUTM">awesome</a>.
<a href="http://html5boilerplate.com/">html5 boilerplate</a>
is a fast way start a clean project.
It avoids repetitive tasks, following <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a> principles.
It includes all those good practices, which are so easy to forget.
It seems all good to me :)
<a href="https://github.com/jeromeetienne/threejsboilerplate">boilerplate for three.js</a> tries to apply similar principles.
I frequently write simple three.js demo for tutorials, and repeat the first steps way too often for my tastes :)
It has been done in effort to make 3D on the web even easier.</p>

<p><a href="http://jeromeetienne.github.com/threejsboilerplate/">Try it</a> out.
"Boilerplate for three.js is a web template for a fast, robust and future-proof site.
Boilerplate is not a framework, nor does it prescribe any philosophy of
development, it's just got some tricks to get your project off the ground
quickly and right-footed."
- freely adapted from <a href="http://html5boilerplate.com/">html5 boilerplate site</a>.</p>




<h2>Walkthrough</h2>

<p>This project is at an early stage.
Dont hesitate to suggest improvements or
bug fixes in
<a href="https://github.com/jeromeetienne/threejsboilerplate/issues">github issues</a>.
It has been done to run everywhere, and to promote good practices.
The
<a href="http://www.youtube.com/watch?v=kOReCN5t2Eo">screencast</a>
below will walk you through the source of the project.
22min... a long one :)</p>

<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="349" src="http://www.youtube.com/embed/kOReCN5t2Eo?hl=en&amp;amp;fs=1" width="425"&gt;&lt;/iframe&gt;
</center>


<h2>Compatibility is key</h2>

<p>It has to run everywhere.
We believe that compatibility is crucial on the web.
The boilerplate seamlessly works on desktop and mobile.
It is working on webgl/canvas2d and supports mouse/touch events.</p>

<p>It renders on
<a href="http://en.wikipedia.org/wiki/WebGL">webgl</a>
if available, else it fallbacks on
<a href="http://html5doctor.com/an-introduction-to-the-canvas-2d-api/">canvas2D</a>.
It is often forgotten, but <a href="http://feeds.feedburner.com/LearningThreejs">three.js</a> is able render on various backends,
they are called <a href="https://github.com/mrdoob/three.js/tree/master/src/renderers">renderers</a>.
It isnt always possible to fallback tho.
Materials are especially sensible to the type of renderer you use.
For examples, many materials are webgl specific as they contains shaders and canvas2D got no shaders.
Up to you to find the balance that fit your needs.</p>

<p>The camera controls is rather basic.
If you need a different controls for your camera, pick one in
<a href="https://github.com/mrdoob/three.js/tree/master/src/extras/controls">this list</a>.
This one is simple to use and understand, a nice feature for a boilerplate.
It supports
<a href="http://www.quirksmode.org/js/events_mouse.html">mouse events</a>
and
<a href="https://developer.mozilla.org/en/DOM/Touch_events">touch events</a>.
So you can run with a touch screen with a glitch.</p>

<h2>Good Practices</h2>

<p>Some features have been added: fullscreen, screenshot and window resize.
I consider them <a href="http://en.wikipedia.org/wiki/Best_practice">good pratices</a> which are often forgotten.
Some numbers based on <a href="https://github.com/mrdoob/three.js/tree/master/examples">three.js examples</a>:
128 examples total,
26 of them handle touch events,
11 handle window resize,
2 handle screenshot,
0 handle fullscreen.</p>

&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" mozallowfullscreen="mozallowfullscreen" src="http://jeromeetienne.github.com/threejsboilerplate" style="float: right; margin-left: 1em;" webkitallowfullscreen="webkitallowfullscreen" width="420"&gt;
&lt;/iframe&gt;


<p><strong>Fullscreen</strong> is supported to enjoy your 3D on a large display
without visual distraction.
If you press <em>f</em>, your demo will go fullscreen.
For technical details, see "<a href="http://learningthreejs.com/blog/2011/11/17/lets-make-a-3d-game-make-it-fullscreen/">Make It Fullscreen</a>" post.</p>

<p><strong>Screenshot</strong> makes it easy to share the image
as what you see on the screen at a given moment.
If you press <em>p</em>, a new tab will open with a screenshot of the rendered content.
For technical details, see "<a href="http://learningthreejs.com/blog/2011/09/03/screenshot-in-javascript/">screenhot in javascript</a>" post.
It it usefull to share nice images and to help debug on various plateforms.</p>

<p><strong>Window resize</strong> is supported because it is required. Without it, your 3D scene will loose scaleing and center
when you resize the window or go fullscreen.
For technical details, see "<a href="http://learningthreejs.com/blog/2011/08/30/window-resize-for-your-demos/">window resize your demos</a>" post.</p>

<h2>How to use it ?</h2>

<p>It is quite simple, first you download the code as
a <a href="https://github.com/jeromeetienne/threejsboilerplate/zipball/master">.zip file</a>
or with the <a href="http://git-scm.com/">git</a> command line below.</p>

<p>```</p>

<pre><code>git clone git://github.com/jeromeetienne/threejsboilerplate.git
</code></pre>

<p>```</p>

<p>then start updating <a href="https://github.com/jeromeetienne/threejsboilerplate/blob/master/index.html">index.html</a> to
fit your needs.
Below is a screencast where i use the
<a href="https://github.com/jeromeetienne/threejsboilerplate">boilerplate</a>
to display a
<a href="http://en.wikipedia.org/wiki/Utah_teapot">teapot</a>
in only 3min!
Why a teapot ? Because it is the "hello world" of 3D :)
Be warned, the video is a bit speedy, im just starting at doing screencast.
Next ones will hopefully be slower.</p>

<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="349" src="http://www.youtube.com/embed/0XPOCi6FJX0?hl=en&amp;amp;fs=1" width="425"&gt;&lt;/iframe&gt;
</center>


<h2>Conclusion</h2>

<p>Later, it may be cool to have a builder.
I think it may be possible to make it client only.
<a href="http://jszip.stuartk.co.uk/">jszip</a> library would create the zip containing all the files.
<a href="https://github.com/jeromeetienne/shorttag.js">shorttag.js</a> library would compile templates according to user needs.
A builder would produce a cleaner and smaller result for you to play with.</p>

<p>I gave a short talk at <a href="http://parisjs.org">parisjs</a> about it, here are the <a href="http://jeromeetienne.github.com/slides-3jsbp-parisjs14">slides</a>.
I hope
<a href="https://github.com/jeromeetienne/threejsboilerplate">boilerplate for three.js</a>.
will help make
<a href="https://github.com/mrdoob/three.js/">three.js</a>
even easier to use.
This project is quite new and will likely improve soon.
That's all folks, have fun :)</p></div>
    </summary>
    <updated>2011-12-20T18:09:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:12Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/12/19/particles-online-editor-for-sparks-js</id>
    <link href="http://learningthreejs.com/blog/2011/12/19/particles-online-editor-for-sparks-js/" rel="alternate" type="text/html"/>
    <title>Particles: Online Editor for Sparks.js</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post is the second of our <a href="http://learningthreejs.com/blog/categories/particles">serie on particles</a>.
It presents
<a href="https://github.com/jeromeetienne/sparkseditor">sparkseditor</a>
, an online editor for
<a href="https://github.com/zz85/sparks.js">sparks.js</a>
with
<a href="https://github.com/mrdoob/three.js/">three.js</a>.
In a few word, it is a webpage which provide an text editor
with a
<a href="https://github.com/zz85/sparks.js">sparks.js</a>
effect.
You got the code in the editor
and
you see <em>live</em> the resulting particles effect.
I like this <em>live</em> aspect a lot :)
I think it makes your design more direct, lower latency, less overhead.
More creative in a way.
<a href="http://jeromeetienne.github.com/sparkseditor/">Try it out</a>.</p>

<p>This editor has been made to lower the barrier of entry on
<a href="https://github.com/zz85/sparks.js">sparks.js</a>
with
<a href="https://github.com/mrdoob/three.js/">three.js</a>
particles.
The UI is rather simple and obvious. You can find a small presentation in the
screencast below.</p>






<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="349" src="http://www.youtube.com/embed/nu00FhIW5bc?hl=en&amp;amp;fs=1" width="425"&gt;&lt;/iframe&gt;
</center>


<h2>Live editor rocks</h2>

<p><a href="http://jeromeetienne.github.com/sparkseditor/">Sparkseditor</a>
is widely inpired by
<a href="http://glsl.heroku.com/e">glsl editor</a>
from
<a href="http://mrdoob.com/">mrdoob</a>
and
<a href="http://www.iquilezles.org/apps/shadertoy/">shadertoy</a>
from
<a href="http://www.iquilezles.org/">Inigo Quilez</a>.
On the same vibe,
<a href="http://lea.verou.me/">lea verou</a>
recently
released
<a href="http://lea.verou.me/2011/12/introducing-dabblet-an-interactive-css-playground/">dablet</a>,
an online editor for
<a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets">css</a>.
There is a clear trend here...
What is it about those live editors ?
A live editor produces a result immediatly.
This helps design your effect faster.
Be light on your foot kindof style.
Very agile way to design.</p>

<p>Additionally, it is easy to share with others because we have <em>bookmarkability</em>.
We do that by storing state in url.
On the down side, it makes super long+ugly urls...
<a href="http://en.wikipedia.org/wiki/URL_shortening">url shortening</a>
helps us reduces this issue.
In our case, we use
<a href="https://bitly.com/">bitly</a>
service.</p>

<p>This editor is purely static files.
No specific server to run, no need to admin and no risk to go offline.
Oh and by the way i dont not even have to pay for hosting this application.
I think it shows html5 in all its power.
The web is becoming something real nice :) html5 i love you!</p>

<h2>conclusion</h2>

<p>Under the hood,
<a href="https://github.com/jeromeetienne/sparkseditor">sparkseditor</a>
uses
<a href="https://github.com/jeromeetienne/threex/blob/master/threex.sparks.js">threex.sparks.js</a>, a
<a href="https://github.com/jeromeetienne/threex">threex</a>
helper, to make
<a href="https://github.com/zz85/sparks.js/">sparks.js</a>
even easier to use.
This helper will be the subject of a future post of our
<a href="http://learningthreejs.com/blog/categories/particles">particles series</a>.</p>

<p>The source is open-source under
<a href="https://github.com/jeromeetienne/sparkseditor/blob/master/MIT-LICENSE.txt">MIT</a>.
You can get it in its <a href="https://github.com/jeromeetienne/sparkseditor">git repository</a>.
If you hit bugs, fill issues on github.
Feel free to fork and modify it!
That's all folks, have fun :)</p></div>
    </summary>
    <updated>2011-12-19T11:11:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:11Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4395</id>
    <link href="http://learningwebgl.com/blog/?p=4395" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 15 December 2011</title>
    <summary>jgrc’s translation of my WebGL tutorials into Spanish is now complete! WebGL Camp was, once again, excellent; Nicolas Garcia Belmonte has written a review that summarises things much better than I could. If you didn’t make it, you can see what you missed here — the videos will apparently be going up sometime early next [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><ul>
<li><a href="http://www.jlabstudio.com/webgl/tutoriales-webgl/">jgrc’s translation of my WebGL tutorials into Spanish</a> is now complete!
</li><li>WebGL Camp was, once again, excellent; <a href="http://blog.thejit.org/2011/12/09/webglcamp/">Nicolas Garcia Belmonte has written a review</a> that summarises things much better than I could.  If you didn’t make it, <a href="http://www.webglcamp.com/wiki/index.php?title=Agenda4">you can see what you missed here</a> — the videos will apparently be going up <a href="http://mozillalabs.com/blog/2011/12/mozilla-welcomes-webgl-camp-4/">sometime early next year</a>.
</li><li>The <a href="http://www.airtightinteractive.com/2011/12/los-angeles-webgl-meetup-recap/">Los Angeles WebGL meetup</a> also seems to have gone well.
</li><li><a href="http://www.spacegoo.com/bubbles">An interesting multimedia demo</a> from Xavier Bourry and the Spacegoo team.
</li><li>Google’s <a href="http://workshop.chromeexperiments.com/bookcase/">WebGL bookcase</a> is now available in <a href="http://workshop.chromeexperiments.com/bookcasefr/">a French version</a>.
</li><li>I’ve mentioned the GLOW WebGL framework before; <a href="http://i-am-glow.com/?page_id=183">this is a cool demo and explanation</a>.
</li><li>Brandon Jones has expanded on some points he made in his WebGL Camp talk on <a href="http://blog.tojicode.com/2011/12/compressed-textures-in-webgl.html">the value of compressed image formats</a>
</li><li>Andor Salga’s written <a href="http://asalga.wordpress.com/2011/12/12/shadows-in-webgl-part-1/">an interesting post on implementing vertex projection shadows</a>.
</li><li>I think everyone will agree, what the world needs right now is a <a href="http://dl.dropbox.com/u/6213850/WebGL/nyanCat/nyan.html">3D Nyan Cat</a>.  Yes, it does play the music. (h/t <a href="http://twitter.com/#!/mrdoob/status/146879933640228865">Mr. doob</a>).
</li><li>Chris O’Dell’s making some first steps toward a <a href="https://github.com/ChrisAnn/webgl-music-visualiser">WebGL music visualiser</a>.
</li><li>LSD users in the 60s could have saved a lot of money and brain cells if they’d had access to WebGL and <a href="http://twitter.com/#!/neave/status/146282724699807745">a bit of help from Paul Neave</a>.
</li><li>The Guardian did an interesting animation (using WebGL if available) of how rumours about the summer riots in London spread over Twitter.  <a href="http://www.guardian.co.uk/news/datablog/2011/dec/08/twitter-riots-interactive?newsfeed=true">More about it here</a>.
</li><li>Remember the Million Dollar Home Page?  <a href="http://www.famousball.com/">Now there’s a new one, in 3D, and spherical</a>.
</li></ul></div>
    </content>
    <updated>2011-12-15T14:10:10Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/12/14/particles-introduction-to-sparks-js</id>
    <link href="http://learningthreejs.com/blog/2011/12/14/particles-introduction-to-sparks-js/" rel="alternate" type="text/html"/>
    <title>Particles: Introduction to Sparks.js</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post is the first of a <a href="http://learningthreejs.com/blog/categories/particles">serie on particles</a>.
It specifically is about
<a href="https://github.com/zz85/sparks.js">sparks.js</a>.
<em>sparks.js</em> is lightweight 3d
<a href="http://en.wikipedia.org/wiki/Particle_system">Particle system</a>
in javascript, for use with
<a href="https://github.com/mrdoob/three.js/">three.js</a>
and
<a href="https://github.com/sole/tween.js">tween.js</a>.
It is from
<a href="http://www.lab4games.net/zz85/blog/">zz85</a>
who already did
<a href="http://mrdoob.github.com/three.js/examples/webgl_geometry_text.html">3D text</a>
and
<a href="http://mrdoob.github.com/three.js/examples/webgl_geometry_subdivison.html">Catmull Clark subdivision</a>.
a productive guy :)</p>

<p>The <a href="http://mrdoob.github.com/three.js/examples/webgl_particles_shapes.html">demo</a>
below is one of the many <a href="https://github.com/mrdoob/three.js/tree/master/examples">three.js examples</a>.
While im on it, the <a href="https://github.com/mrdoob/three.js/tree/master/examples">example directory</a> is a gold mine.
Go dig in it to understand how to code three.js :)
Back to the point, this
<a href="http://mrdoob.github.com/three.js/examples/webgl_particles_shapes.html">demo</a>
is rather cool no ?
You want to do the same ?
During this short post, let me walk you walk thru the code for particles in this example.</p>






&lt;iframe frameborder="0" height="420" src="http://mrdoob.github.com/three.js/examples/webgl_particles_shapes.html" width="100%"&gt;&lt;/iframe&gt;


<h2>Lets Get Started</h2>

<p>So lets see how to use it. First step, you download
<a href="https://raw.github.com/zz85/sparks.js/master/Sparks.js">sparks.js</a>
from
<a href="https://github.com/zz85/sparks.js">its github</a>.
Then include it in your own code.</p>

<p>```html</p>

<pre><code>&lt;script src="Sparks.js"&gt;&lt;/script&gt;
</code></pre>

<p>```</p>

<p>First a few words on what is a <a href="http://en.wikipedia.org/wiki/Particle_system">particle system</a>.
It is usually composed of 2 big parts: the <em>emitter</em> and the <em>particle</em> itself.
Emitter creates particles.
Particles are usually smallish objects on the screen.
As you got many particles at the same time, they appears a single mass.</p>




<h2>Let's create an emitter</h2>

<p>First we create the emitter like this.
<code>emitter</code> is the main object we will play with.</p>

<p>```javascript</p>

<pre><code>var counter = new SPARKS.SteadyCounter( 500 );
var emitter = new SPARKS.Emitter( counter );
</code></pre>

<p>```</p>

<p><code>counter</code> controls how frequently particles are created. Here it will
emit 500 particles per seconds.
Now let's start emit particles.</p>

<p>```javascript</p>

<pre><code>emitter.start();
</code></pre>

<p>```</p>

<p>Sparks.js has a very flexible core.
It mainly uses two stacks of functions.
<em>Initializers</em> is the stack run at the creation of a particle.
<em>Actions</em> is another stack which is run at every step of a particle life.
Those functions are run in order.
Up to you to configure them to fit your needs.
You can easily code your own <em>initializer</em> or <em>action</em>.
Dont worry it got a bunch of predefined ones.</p>

<h2>Let's initialize</h2>

<p>Lets me walk you thru the ones used in our example. The whole stack is below.
<code>emitter.addInitializer()</code> to push a new initializer, and <code>emitter.removeInitializer()</code>
to remove it, not too hard :)</p>

<p>```javascript</p>

<pre><code>emitterpos = new THREE.Vector3( 0, 0, 0 );
emitter.addInitializer( new SPARKS.Position( new SPARKS.PointZone( emitterpos ) ) );
emitter.addInitializer( new SPARKS.Lifetime( 1, 15 ));
var vector = new THREE.Vector3( 0, -5, 1 );
emitter.addInitializer( new SPARKS.Velocity( new SPARKS.PointZone( vector ) ) );
</code></pre>

<p>```</p>

<p><code>SPARKS.Position(zone)</code> initializer set the original position of the particle.
A <code>zone</code> provide a location in space.
<code>new SPARKS.PointZone( emitterpos )</code> means the particles will always start from this specific point in space.
It is possible to have other zones.
For example, <code>SPARKS.LineZone( startVector3, endVector3 )</code> represents a line between 2 points, so
your particle would start anywhere on this line.</p>

<p><code>SPARKS.Lifetime(mintime, maxtime)</code> initializer set particle's lifetime.
You can specify a range and a random value will be assigned.
Don't forget to add <code>SPARKS.Age</code> action to handle its lifetime.
And the last one.
<code>SPARKS.Velocity(zone)</code> set particle's velocity based on a <code>zone</code> location.
The initializer stack is setup the particle at the begining of its life.
Let's see what happen during this life.</p>

<h2>Let's do some actions</h2>

<p>Actions are performed at every step of a particle life.
Same as with initializers, <code>emitter.addAction()</code> to push a new action,
<code>emitter.removeAction()</code> to remove it.
For our examples the whole action stack is this.</p>

<p>```javascript</p>

<pre><code>emitter.addAction( new SPARKS.Age() );
emitter.addAction( new SPARKS.Accelerate( 0, 0, -50 ) );
emitter.addAction( new SPARKS.Move() );
emitter.addAction( new SPARKS.RandomDrift( 90, 100, 2000 ) );
</code></pre>

<p>```</p>

<p>Now lets details it.
We have already seen <code>SPARKS.Age()</code>. It is handle the lifetime of each particle.
<code>SPARKS.Accelerate(x,y,z)</code> changes the velocity by adding a fixed amount at every step.
This one produces a gravity effect with a negative <code>y</code>.
<code>SPARKS.Move()</code> makes the particles move in our 3D space.
<code>SPARKS.RandomDrift(x,y,z)</code> changes the velocity by adding a random amount at every step.</p>

<h2>Conclusion</h2>

<p>I hope this short introduction got you excited about
<a href="https://github.com/zz85/sparks.js/">sparks.js</a>.
Next posts on the
<a href="http://learningthreejs.com/blog/categories/particles">particle series</a>
may be a UI editor, stay tuned!
I find sparks.js clean and flexible.
Flexibility is very important for particles.
It helps provide a wide variety of effect in your games/demos.
For more informations and authoritative answer, see the
<a href="https://github.com/zz85/sparks.js/">github repository</a>.
That's all for today folks, have fun.</p></div>
    </summary>
    <updated>2011-12-14T11:08:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:11Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/12/10/constructive-solid-geometry-with-csg-js</id>
    <link href="http://learningthreejs.com/blog/2011/12/10/constructive-solid-geometry-with-csg-js/" rel="alternate" type="text/html"/>
    <link href="http://chandler.prallfamily.com/labs/three/csg/ThreeCSG.js" length="5270" rel="enclosure" type="application/octet-stream"/>
    <title>Constructive Solid Geometry With csg.js</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post is about
<a href="http://en.wikipedia.org/wiki/Constructive_solid_geometry">constructive solid geometry</a>
, an impressive word :)
In fact, it is just a way to build complex objects from simpler ones.
Those simple objects are assembled using
<a href="http://en.wikipedia.org/wiki/Algebra_of_sets">operations</a>
such as union, difference and intersection.</p>

<p>Recently
<a href="http://madebyevan.com/">Evan Wallas</a>
released
<a href="http://evanw.github.com/csg.js/">csg.js</a>,
a clean self-contained library to do
<a href="http://en.wikipedia.org/wiki/Constructive_solid_geometry">constructive solid geometry</a>.
So <a href="http://chandler.prallfamily.com/">Chandler Prall</a>
wrote a
<a href="http://chandler.prallfamily.com/2011/12/constructive-solid-geometry-with-three-js/">bridge</a>
to make it easy to use with
<a href="https://github.com/mrdoob/three.js/">three.js</a>.</p>

<p>With all this nice code, i wrote the little
<a href="http://learningthreejs.com/data/constructive-solid-geometry-with-csg-js/">demo of a dice</a>
you can see on the right. Thus you can click to change the operations, play
with it and have a feel of the various operations.</p>






&lt;iframe frameborder="0" height="420" src="http://learningthreejs.com/data/constructive-solid-geometry-with-csg-js/" style="float: right; margin-left: 1em;" width="100%"&gt;
&lt;/iframe&gt;


<h2>Let's start</h2>

<p>So lets see how to use it. First step, you download
csg.js from
<a href="http://evanw.github.com/csg.js/">here</a>
, ThreeCSG.js bridge from
<a href="http://chandler.prallfamily.com/labs/three/csg/ThreeCSG.js">here</a>
. Then include those line in your own code.</p>

<p>```html</p>

<pre><code>&lt;script src="csg.js"&gt;&lt;/script&gt;
&lt;script src="ThreeCSG.js"&gt;&lt;/script&gt;
</code></pre>

<p>```</p>

<h2>Let's convert</h2>

<p>Ok now that we got the source, let's use it.
<a href="http://chandler.prallfamily.com/2011/12/constructive-solid-geometry-with-three-js/">ThreeCSG.js</a>
is a bridge between
<a href="https://github.com/mrdoob/three.js/">three.js</a>
and
<a href="http://evanw.github.com/csg.js/">csg.js</a>.
Both libraries use a different format for geometry.
<a href="http://chandler.prallfamily.com/2011/12/constructive-solid-geometry-with-three-js/">ThreeCSG.js</a>
does the conversion back and forth.
To convert your three.js geometry to a csg geometry, use this line.</p>

<p>```javascript</p>

<pre><code>var geometryCsg = THREE.CSG.toCSG(geometryThree);
</code></pre>

<p>```</p>

<p>Then you likely apply
<a href="http://en.wikipedia.org/wiki/Algebra_of_sets">boolean operations</a>
on
<a href="http://evanw.github.com/csg.js/">csg.js</a> geometry.
To convert it back to three.js, just do</p>

<p>```javascript</p>

<pre><code>var geometryThree   = THREE.CSG.fromCSG(geometryCsg);
</code></pre>

<p>```</p>

<p>You end up with a normal <a href="https://github.com/mrdoob/three.js/blob/master/src/core/Geometry.js">three.js geometry</a>
than you can use everywhere, like
<a href="https://github.com/mrdoob/three.js/blob/master/src/extras/GeometryUtils.js">GeometryUtils</a>
or
<a href="https://github.com/mrdoob/three.js/blob/master/src/objects/Mesh.js">Mesh</a>.</p>

<h2>Let's assemble</h2>

<p>Now the fun part, lets assemble objects with those misterious
<a href="http://en.wikipedia.org/wiki/Algebra_of_sets">boolean operations</a>
on ours
<a href="http://evanw.github.com/csg.js/">csg.js</a>
geometries.
There are <a href="http://en.wikipedia.org/wiki/Constructive_solid_geometry">3 of them</a>:
<a href="http://en.wikipedia.org/wiki/Complement_(set_theory)">difference</a>,
<a href="http://en.wikipedia.org/wiki/Union_(set_theory)">union</a>
and
<a href="http://en.wikipedia.org/wiki/Intersection_(set_theory)">intersect</a>.
To build our dice, first we build a
<a href="https://github.com/mrdoob/three.js/blob/master/src/extras/geometries/CubeGeometry.js">cube</a>
then we subtract a bunch of
<a href="https://github.com/mrdoob/three.js/blob/master/src/extras/geometries/SphereGeometry.js">spheres</a>
to makes the holes.</p>

<p><img alt="" class="right " height="" src="http://learningthreejs.com/data/constructive-solid-geometry-with-csg-js/images/image-substract-320x240.png" title="" width=""/></p>

<p>Once you converted your objects, you apply operations on them.
For the dice, we use <code>.subtract()</code>.</p>

<p>```javascript</p>

<pre><code>cube.substract(spheres)
</code></pre>

<p>```</p>

<div style="clear: both;"/>


<p><img alt="" class="right " height="" src="http://learningthreejs.com/data/constructive-solid-geometry-with-csg-js/images/image-union-320x240.png" title="" width=""/></p>

<p>But it is possible to use <code>.union()</code> to add them.</p>

<p>```javascript</p>

<pre><code>cube.union(spheres)
</code></pre>

<p>```</p>

<p>Or to keep only the common part of both objects with <code>.intersect()</code>.</p>

<p><img alt="" class="right " height="" src="http://learningthreejs.com/data/constructive-solid-geometry-with-csg-js/images/image-intersect-320x240.png" title="" width=""/></p>

<p>You can chain those operations to your own taste.
Up to you to be creative :)</p>

<p>```javascript</p>

<pre><code>cube.intersect(spheres)
</code></pre>

<p>```</p>

<h2>Conclusion</h2>

<p><a href="http://en.wikipedia.org/wiki/Constructive_solid_geometry">Constructive solid Geometry</a>
is simple and quite powerfull.
<a href="http://evanw.github.com/csg.js/">csg.js</a>
,
<a href="http://chandler.prallfamily.com/2011/12/constructive-solid-geometry-with-three-js/">ThreeCSG.js</a>
and
<a href="https://github.com/mrdoob/three.js/">three.js</a>
makes it real easy to play with.
You may look at the source of our dice
<a href="http://learningthreejs.com/data/constructive-solid-geometry-with-csg-js/">demo</a>
to see a working version of this code.
That's all for today, have fun :)</p></div>
    </summary>
    <content>This post is about constructive solid geometry , an impressive word :) In fact, it is just a way to build complex objects from simpler ones. Those simple objects are assembled using operations such as union, difference and intersection. Recently Evan Wallas released csg.js, a clean self-contained library to do constructive solid geometry. So Chandler Prall wrote a bridge to make it easy to use with three.js. With all this nice code, i wrote the little demo of a dice you can see on the right. Thus you can click to change the operations, play with it and have a feel of the various operations. Let's start So lets see how to use it. First step, you download csg.js from here , ThreeCSG.js bridge from here . Then include those line in your own code. ```html &lt;script src="csg.js"&gt;&lt;/script&gt; &lt;script src="ThreeCSG.js"&gt;&lt;/script&gt; ``` Let's convert Ok now that we got the source, let's use it. ThreeCSG.js is a bridge between three.js and csg.js. Both libraries use a different format for geometry. ThreeCSG.js does the conversion back and forth. To convert your three.js geometry to a csg geometry, use this line. ```javascript var geometryCsg = THREE.CSG.toCSG(geometryThree); ``` Then you likely apply boolean operations on csg.js geometry. To convert it back to three.js, just do ```javascript var geometryThree = THREE.CSG.fromCSG(geometryCsg); ``` You end up with a normal three.js geometry than you can use everywhere, like GeometryUtils or Mesh. Let's assemble Now the fun part, lets assemble objects with those misterious boolean operations on ours csg.js geometries. There are 3 of them: difference, union and intersect. To build our dice, first we build a cube then we subtract a bunch of spheres to makes the holes. Once you converted your objects, you apply operations on them. For the dice, we use .subtract(). ```javascript cube.substract(spheres) ``` But it is possible to use .union() to add them. ```javascript cube.union(spheres) ``` Or to keep only the common part of both objects with .intersect(). You can chain those operations to your own taste. Up to you to be creative :) ```javascript cube.intersect(spheres) ``` Conclusion Constructive solid Geometry is simple and quite powerfull. csg.js , ThreeCSG.js and three.js makes it real easy to play with. You may look at the source of our dice demo to see a working version of this code. That's all for today, have fun :)</content>
    <updated>2011-12-10T15:30:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:12Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4383</id>
    <link href="http://learningwebgl.com/blog/?p=4383" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 8 December 2011</title>
    <summary>A relatively quiet week! BlackBerry’s tunneltilt game is now live for non-PlayBook WebGL browsers on GitHub: drag to steer. Warning: it’s addictive! Another addictive one is Rinesh Thomas’ WebGL Air Hockey. If you liked the pendulum waves video that did the rounds a while back, you’ll love Yuv’s WebGL version. It’s probably best not to [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>A relatively quiet week!</p>
<ul>
<li><a href="http://blackberry.github.com/WebGL-Samples/tunneltilt/">BlackBerry’s tunneltilt game is now live for non-PlayBook WebGL browsers on GitHub</a>: drag to steer.  Warning: it’s addictive!
</li><li>Another addictive one is <a href="http://www.chromeexperiments.com/detail/webgl-air-hockey-demo/">Rinesh Thomas’ WebGL Air Hockey</a>.
</li><li>If you liked the pendulum waves video that did the rounds a while back, you’ll love <a href="http://toplessproductions.com/pendulum/">Yuv’s WebGL version</a>.</li>
<li>It’s probably best not to follow <a href="http://www.spacegoo.com/tiananmen">this link to Xavier Bourry’s “Tiananmen” demo</a> if you’re in China…
</li><li><a href="http://evanw.github.com/csg.js/">Evan Wallace has released csg.js</a>, a tool for creating 3D solids by intersecting and subtracting simpler ones.  (h/t <a href="http://badassjs.com/post/13788484076/csg-js-constructive-solid-geometry-3d-modeling-in">Badass Javascript</a>)
</li><li>Evan’s also made some updates to <a href="https://github.com/evanw/lightgl.js">lightgl.js</a>, a library that adds commonly-used functions from OpenGL back into WebGL.
</li><li>If you want to render text in your WebGL scenes, check out <a href="http://www.spoonofdeath.com/delph/webgltext.html">Harry Jones’ tutorial</a>!
</li><li>Here’s a “first steps” kind of walkthough for <a href="http://igorjacauna.com.br/2011/12/02/aprendendo-um-pouco-de-webgl-e-three-js/">three.js in Portuguese</a> by Ígor Jacaúna.
</li></ul></div>
    </content>
    <updated>2011-12-08T14:50:27Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4379</id>
    <link href="http://learningwebgl.com/blog/?p=4379" rel="alternate" type="text/html"/>
    <title>Retrospective changes to the lessons, part 94</title>
    <summary>WebGL is increasingly being supported on mobile devices. Firefox on my Android phone (a Samsung Galaxy S II) quite happily displays all of my tutorials, and many other WebGL sites as well. But not all mobile devices are equal; some quite popular ones apparently don’t support highp precision in fragment shaders. The WebGL spec says [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>WebGL is increasingly being supported on mobile devices.  Firefox on my Android phone (a Samsung Galaxy S II) quite happily displays all of my tutorials, and many other WebGL sites as well.  But not all mobile devices are equal; some quite popular ones apparently don’t support <code>highp</code> precision in fragment shaders.  </p>
<p>The WebGL spec says that all implementations must support at least <code>mediump</code>, so it looks like that’s the most sensible precision to use as a default for most WebGL sites.  I’ve changed the lessons here so that they use it.  I also took the opportunity to get rid of some compatibility cruft that dated from the early days of WebGL: the <code>#ifdef GL_ES</code> that surrounded the precision qualifiers.  </p>
<p>If you’ve got some WebGL demos out there, I strongly recommend you do likewise!</p>
<p>Many thanks to Ken Russell and Cedric Vivier for the heads-up about this.</p>
<p>[UPDATE: Cedric <a href="https://twitter.com/#!/neonux/status/142441268289609729">tweets</a> that the precision operators have no effect on desktop machines right now anyway, so it sounds like there really is no downside to making this change.]</p></div>
    </content>
    <updated>2011-12-01T20:45:03Z</updated>
    <category term="Retrospective changes"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4346</id>
    <link href="http://learningwebgl.com/blog/?p=4346" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 1 December 2011</title>
    <summary>From Iacopo Sassarini, a gorgeous mathematical demo in Three.js: Martin’s Hopalong Orbits Visualizer Krystian Samp’s WebGL Playground is a nice in-browser WebGL editor/runner. Pl4n3′s game Wloom is getting ever better. From the prolific AlteredQualia, a procedurally-generated city. From Gerwin Sturm, a WebGL-based view onto Google+ Hangouts (no live demo yet). “CAAT is a multi-instance director-based [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><ul>
<li>From Iacopo Sassarini, a gorgeous mathematical demo in Three.js: <a href="http://iacopoapps.appspot.com/hopalongwebgl/">Martin’s Hopalong Orbits Visualizer</a>
</li><li>Krystian Samp’s <a href="http://webglplayground.net/">WebGL Playground</a> is a nice in-browser WebGL editor/runner.
</li><li><a href="http://pl4n3.blogspot.com/2011/11/wloom-webgl-game-work-in-progress-7.html">Pl4n3′s game Wloom is getting ever better</a>.
</li><li>From the prolific AlteredQualia, <a href="http://alteredqualia.com/three/examples/webgl_city.html">a procedurally-generated city</a>.
</li><li>From Gerwin Sturm, <a href="http://code.google.com/p/hangout-3d/">a WebGL-based view onto Google+ Hangouts</a> (no live demo yet).
</li><li>“<a href="http://labs.hyperandroid.com/static/caat/">CAAT is a multi-instance director-based scene-graph manager</a>.  It is able to render using Canvas, WebGL and CSS with the same code base.”</li>
<li>3dtin, the online 3D design site, <a href="http://blog.3dtin.com/3d-text">now supports text</a>.
</li><li>It’s fascinating to see the slow but steady rise in WebGL ads.  <a href="http://www.adidas.com/football/uk/pages/f50">Here’s one by Stopp for Adidas sports footwear</a>.
</li><li><a href="http://dev.opera.com/articles/view/porting-3d-graphics-to-the-web-webgl-intro-part-2/">A useful article from dev.opera</a> — how to convert 3D models from popular editors into a JSON format you can render in WebGL.
</li><li>Similarly, here’s a presentation (with embedded WebGL demos, nice) from Jochen Wilhelmy: “<a href="http://www.inka3d.com/llvm2011/">Exporting 3D scenes from Maya to WebGL using Clang and LLVM</a>”
</li><li>Via Eduardo Pelegri-Llopart, here’s <a href="http://www.youtube.com/watch?feature=player_embedded&amp;v=TxazzRLa0qQ">another better video of RIM’s TunnelTilt WebGL game</a> running on a BlackBerry PlayBook — I’m hoping to be able to post more about this soon.
</li><li>Firefox on Android has supported WebGL for a while now, but now WebGL’s appeared in a live release of the stock Android browser for the first time, <a href="http://developer.sonyericsson.com/wp/2011/11/29/xperia-phones-first-to-support-webgl/">thanks to Sony Ericsson</a>.
</li><li>If you’re interested in playing with WebGL in Dart, Google’s new JavaScript competitor, then <a href="http://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/3eafb5ee13a5e8d6/a451ae4f71610372?show_docid=a451ae4f71610372&amp;pli=1">it sounds like it’s possible</a> — has anyone tried it?
</li></ul></div>
    </content>
    <updated>2011-12-01T14:08:09Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4332</id>
    <link href="http://learningwebgl.com/blog/?p=4332" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 24 November 2011</title>
    <summary>Registration for the next WebGL Camp on 9 December in Mountain View, California, is now open. A bit of nostalgia from OutsideOfSociety: X-Wing. A real-world use of WebGL: Building Information Modeling is an abstraction of architectural designs, and BIMsurfer has been built to help you surf your BIM just like you surf the Web. An [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><ul>
<li><a href="http://webglcamp4.eventbrite.com/">Registration for the next WebGL Camp</a> on 9 December in Mountain View, California, is now open.
</li><li>A bit of nostalgia from OutsideOfSociety: <a href="http://oos.moxiecode.com/js_webgl/xwing/">X-Wing</a>.
</li><li>A real-world use of WebGL: Building Information Modeling is an abstraction of architectural designs, and <a href="http://bimsurfer.org/">BIMsurfer</a> has been built to help you surf your BIM just like you surf the Web.
</li><li>An interesting visualisation of <a href="http://www.waterunderground.info/">the distribution of groundwater worldwide</a>. (<a href="https://twitter.com/#!/alteredq/status/137002633884991488">via</a> AlteredQualia)
</li><li>By AlteredQualia: <a href="http://alteredqualia.com/three/examples/webgl_lensflares.html">a three.js lens flare demo</a>.
</li><li>Quite fun: <a href="http://stickmanventures.com/labs/demo/ccab-night-drive-webgl-threejs/">C-Cab night drive</a>, by Stickman Ventures
</li><li><a href="http://blog.xeolabs.com/ray-picking-in-scenejs">A nice explanation of a GPU picking implementation in SceneJS</a> by Lindsay Kay.
</li><li>Andor Salga has blogged about <a href="http://asalga.wordpress.com/2011/11/18/anaglyph-point-clouds/">doing anaglyphs (old-school red/blue glasses 3D) using XB PointStream</a>.
</li><li>From Scirra, <a href="http://www.scirra.com/blog/58/html5-2d-gaming-performance-analysis">a comparison of Canvas 2D, WebGL and their own DirectX/C++ based engine for 2D games</a>.  Relative speeds are pretty much as you’d expect (though IE’s hardware-accelerated Canvas 2D and Opera 12′s WebGL performance are extremely impressive).
</li><li>Peter Strohm has updated <a href="http://www.peter-strohm.de/webgl/">his WebGL tutorials</a> (in German, more maths-orientated than mine).
</li><li>For Polish readers (or those who can put up with Google Translate), 3dgames.pl have put together <a href="http://3dgames.pl/blog/2011/11/przeglad-frameworkow/">a comparison of four WebGL frameworks</a>: SceneJS, Three.js, X3DOM and Copperlicht.
</li></ul></div>
    </content>
    <updated>2011-11-24T14:48:37Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/11/21/lets-make-a-3d-game-make-it-embedded</id>
    <link href="http://learningthreejs.com/blog/2011/11/21/lets-make-a-3d-game-make-it-embedded/" rel="alternate" type="text/html"/>
    <link href="http://learningthreejs.com/data/THREEx/THREEx.WindowResize.js" length="1159" rel="enclosure" type="application/x-javascript"/>
    <title>Lets Make a 3D Game: Make It Embedded</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" mozallowfullscreen="mozallowfullscreen" src="http://marblesoccer.com" style="float: right; margin-left: 1em;" webkitallowfullscreen="webkitallowfullscreen" width="420"&gt;
&lt;/iframe&gt;


<p>This post is part of the <a href="http://learningthreejs.com/blog/categories/tutorial3dgame/">"Let's make a 3D game"</a> series.
The previous post was on
<a href="http://learningthreejs.com/blog/2011/11/17/lets-make-a-3d-game-make-it-fullscreen/">fullscreen API</a>.
Here is another one on resizing the display area.
This post is about embedding your game in another page.
It is usefull to include it in a blog, in facebook, iGoogle or other game plateforms.</p>

<p><a href="http://marblesoccer.com">MarbleSoccer</a>
now contains all the tricks explained in this post.
<em>Show dont tell</em>, you can see it embedded on the left.
Embedding your game implies various things.
As your game is hosted in another page, it likely got a smaller display area.
HTML5
<a href="http://www.w3.org/TR/css3-mediaqueries/">CSS media query</a>
makes it easy to fit various sizes.
Another part are the
<a href="http://en.wikipedia.org/wiki/DOM_events">DOM events</a>
from the iframe.
They will be propagated to the host page and may produce undesirable effects.
We see how to shield them.
But first let's see about
<a href="http://en.wikipedia.org/wiki/HTML_element#Frames">iframe</a></p>

<h2>Let's go play in an iframe</h2>

<p><a href="http://en.wikipedia.org/wiki/HTML_element#Frames">iframe</a>
is an easy and secure way to embed a page in another.
Let's declare it.</p>

<p>```html</p>

<pre><code>&lt;iframe src="http://marblesoccer.com"
    allowfullscreen webkitallowfullscreen mozallowfullscreen
    width="480" height="320" frameborder="0"&gt;
&lt;/iframe&gt;
</code></pre>

<p>```</p>




<p>The attributes are pretty classics: <code>frameborder</code> to remove an ugly default border,
<code>width</code> and <code>height</code> for size and <code>src</code> for your game page.
The ones ending with <code>allowfullscreen</code> tell the browser that this iframe is
allowed to go fullscreen. More about fullscreen in this
<a href="http://learningthreejs.com/blog/2011/11/17/lets-make-a-3d-game-make-it-fullscreen/">previous post</a>
or in the <a href="http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html">spec</a>.</p>

<p>You may need to determined if your game is embedded or not.
Use this line will tell if it is in a iframe or not.</p>

<p>```javascript</p>

<pre><code>var isInIframe  = (window != window.top);
</code></pre>

<p>```</p>

<h2>Fit in a smaller display area</h2>

<p>When your game is embedded, it is likely to have a smaller display area.
How to deal with this ?
First, we have 2 types of rendering in our game:
a 3D display where
<a href="https://github.com/mrdoob/three.js/">three.js</a>
displays the
<a href="http://en.wikipedia.org/wiki/WebGL">WebGL</a>, and
a DOM display for
<a href="http://en.wikipedia.org/wiki/On-screen_display">OSD</a>
such as score, timers and other popups.</p>

<p>For <em>3D rendering</em>, we have already seen window resizing in
<a href="http://learningthreejs.com/blog/2011/08/30/window-resize-for-your-demos/">this post</a>.
Just download
<a href="http://learningthreejs.com/data/THREEx/THREEx.WindowResize.js">THREEx.WindowResize</a>
and add this line and you are done. Not too hard, hey.</p>

<p>```javascript</p>

<pre><code>THREEx.WindowResize(renderer, camera);
</code></pre>

<p>```</p>

<p>Now <em>the DOM display</em>. It may simply be done via CSS
and
<a href="http://www.w3.org/TR/css3-mediaqueries/">media queries</a>.
Typically, you may reduce the size of your font or icons.
I won't try to teach css, other do that much
<a href="https://developer.mozilla.org/en/CSS/Media_queries">better</a>
<a href="http://www.html5rocks.com/en/mobile/mobifying.html#toc-mediaqueries">than</a>
<a href="http://thinkvitamin.com/code/media-queries-width-and-height-video-tutorial/">me</a>.
Just a pick of what i did, not sure at all it is the best way.
I reduce the OSD display if your game page is 640px or less.</p>

<p>```css</p>

<pre><code>@media all and (max-width: 640px) {
    /* here put your style specific for embedded case */
    body { font-size : 60%; }
    img { width : 48px; }
}
</code></pre>

<p>```</p>

<h2>Shield Events</h2>

<p>Strange section title, hey.
It means <em>prevents DOM events from the iframe to interfere with the host page</em>.
Not much clearer...
Maybe with an example ? Let's see the arrows+scroll case.
Show dont tell.
Below are 2 iframes: on the left, no shielding happens, on the right shielding happens.
Try to click on them and use arrows up/down.</p>

&lt;iframe height="120px" src="http://learningthreejs.com/data/THREEx/examples/threex.embedded/noshield-iframe.html" width="50%"&gt;&lt;/iframe&gt;


&lt;iframe height="120px" src="http://learningthreejs.com/data/THREEx/examples/threex.embedded/withshield-iframe.html" width="49%"&gt;&lt;/iframe&gt;


<p>On the left, the host page scrolls, but not on the right.
Why does this happen ? good question :)
If our game iframe got the focus and users press up or down, the iframe will received
<a href="http://www.quirksmode.org/dom/events/keys.html">keydown/keyup events</a>.
Up to now, all is ok...
Troubles appear when those events are bubbling to the host page, they may trigger a scrolling.</p>

<p>Imagine the page going up and down while you play, the game becomes unplayable very fast :)
So here is the code which prevents this behavior. It listens to arrows
<a href="http://www.quirksmode.org/dom/events/keys.html">keydown events</a>.
and prevent their default.</p>

<p>```javascript</p>

<pre><code>document.addEventListener('keydown', function(event){
    // if it is keydown on a arrow, prevent default
    if( event.keyCode &gt;= 37 &amp;&amp; event.keyCode &lt;= 40 ){
        event.preventDefault();
    }
}, true);
</code></pre>

<p>```</p>

<h2>Conclusion</h2>

<p>I gathered the code in
<a href="http://learningthreejs.com/data/THREEx/threex.embedded.js">threex.embedded</a>,
see its
<a href="http://learningthreejs.com/data/THREEx/docs/threex.embedded.html">annoted source</a>.
Iframe is a easy and secure way to make your game embeddable.
We have seen how to handle smaller display area
with
<a href="http://learningthreejs.com/data/THREEx/THREEx.WindowResize.js">THREEx.WindowResize</a>
and
<a href="http://www.w3.org/TR/css3-mediaqueries/">media queries</a>.
Additionnaly we even shield DOM events, so we can use arrow keys for player control.
You are all set! Go embed your game now :)</p></div>
    </summary>
    <content>This post is part of the "Let's make a 3D game" series. The previous post was on fullscreen API. Here is another one on resizing the display area. This post is about embedding your game in another page. It is usefull to include it in a blog, in facebook, iGoogle or other game plateforms. MarbleSoccer now contains all the tricks explained in this post. Show dont tell, you can see it embedded on the left. Embedding your game implies various things. As your game is hosted in another page, it likely got a smaller display area. HTML5 CSS media query makes it easy to fit various sizes. Another part are the DOM events from the iframe. They will be propagated to the host page and may produce undesirable effects. We see how to shield them. But first let's see about iframe Let's go play in an iframe iframe is an easy and secure way to embed a page in another. Let's declare it. ```html &lt;iframe src="http://marblesoccer.com" allowfullscreen webkitallowfullscreen mozallowfullscreen width="480" height="320" frameborder="0"&gt; &lt;/iframe&gt; ``` The attributes are pretty classics: frameborder to remove an ugly default border, width and height for size and src for your game page. The ones ending with allowfullscreen tell the browser that this iframe is allowed to go fullscreen. More about fullscreen in this previous post or in the spec. You may need to determined if your game is embedded or not. Use this line will tell if it is in a iframe or not. ```javascript var isInIframe = (window != window.top); ``` Fit in a smaller display area When your game is embedded, it is likely to have a smaller display area. How to deal with this ? First, we have 2 types of rendering in our game: a 3D display where three.js displays the WebGL, and a DOM display for OSD such as score, timers and other popups. For 3D rendering, we have already seen window resizing in this post. Just download THREEx.WindowResize and add this line and you are done. Not too hard, hey. ```javascript THREEx.WindowResize(renderer, camera); ``` Now the DOM display. It may simply be done via CSS and media queries. Typically, you may reduce the size of your font or icons. I won't try to teach css, other do that much better than me. Just a pick of what i did, not sure at all it is the best way. I reduce the OSD display if your game page is 640px or less. ```css @media all and (max-width: 640px) { /* here put your style specific for embedded case */ body { font-size : 60%; } img { width : 48px; } } ``` Shield Events Strange section title, hey. It means prevents DOM events from the iframe to interfere with the host page. Not much clearer... Maybe with an example ? Let's see the arrows+scroll case. Show dont tell. Below are 2 iframes: on the left, no shielding happens, on the right shielding happens. Try to click on them and use arrows up/down. On the left, the host page scrolls, but not on the right. Why does this happen ? good question :) If our game iframe got the focus and users press up or down, the iframe will received keydown/keyup events. Up to now, all is ok... Troubles appear when those events are bubbling to the host page, they may trigger a scrolling. Imagine the page going up and down while you play, the game becomes unplayable very fast :) So here is the code which prevents this behavior. It listens to arrows keydown events. and prevent their default. ```javascript document.addEventListener('keydown', function(event){ // if it is keydown on a arrow, prevent default if( event.keyCode &gt;= 37 &amp;&amp; event.keyCode &lt;= 40 ){ event.preventDefault(); } }, true); ``` Conclusion I gathered the code in threex.embedded, see its annoted source. Iframe is a easy and secure way to make your game embeddable. We have seen how to handle smaller display area with THREEx.WindowResize and media queries. Additionnaly we even shield DOM events, so we can use arrow keys for player control. You are all set! Go embed your game now :)</content>
    <updated>2011-11-21T15:32:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:11Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4330</id>
    <link href="http://learningwebgl.com/blog/?p=4330" rel="alternate" type="text/html"/>
    <title>Server upgrade</title>
    <summary>I’ve just upgraded the Learning WebGL server from Debian Lenny to Squeeze. It looks like everything went smoothly, but please do let me know if anything’s broken…</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>I’ve just upgraded the Learning WebGL server from Debian Lenny to Squeeze.  It looks like everything went smoothly, but please do let me know if anything’s broken…</p></div>
    </content>
    <updated>2011-11-20T17:33:08Z</updated>
    <category term="Meta"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4308</id>
    <link href="http://learningwebgl.com/blog/?p=4308" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 17 November 2011</title>
    <summary>An awesome demo from Florian Bösch — WebGL GPU Landscaping and Erosion. You’ll need a decent graphics card to be able to run the live version, though. The Light is a new game by Stefan Wagner showing off WebGL, HTML5 Audio and the Fullscreen API “The plants in the ECOSPHERE grow from your tweets tagged [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><ul>
<li>An awesome demo from Florian Bösch — <a href="http://codeflow.org/entries/2011/nov/10/webgl-gpu-landscaping-and-erosion/">WebGL GPU Landscaping and Erosion</a>.  You’ll need a decent graphics card to be able to run the live version, though.
</li><li><a href="http://bompo.github.com/thelight/">The Light</a> is a new game by Stefan Wagner showing off WebGL, HTML5 Audio and the Fullscreen API
</li><li>“The plants in the <a href="http://cnn-ecosphere.com/">ECOSPHERE</a> grow from your tweets tagged with #COP17.”
</li><li>A nice demoscene production, using Three.js: <a href="http://litewerx.dk/anaemia/demo/demo.html?s=max">Anaemia by Litewerx</a> (via <a href="http://www.photonstorm.com/archives/2586/anaemia-demo-by-litewerx-webgl">Photon Storm</a>)
</li><li>Not quite so pretty to look at, but technically incredibly impressive!  <a href="http://www.bitsnbites.eu/?p=112">Frank is a WebGL demo in 4kb</a>, including visuals and music.
</li><li><a href="http://shapesmith.net/">Shapesmith’s</a> “aim is to make designing 3D printable models accessible to anyone with a modern browser”
</li><li><a href="http://www.netmagazine.com/tutorials/create-amazing-webgl-effects-shaders">A nice basic shader tutorial in .NET magazine by Bartek Drozdz</a>.
</li><li><a href="http://blog.xeolabs.com/scenejs-20-release">Good news for SceneJS fans</a> — the long-awaited version 2.0 has now been released.  If focuses on “high rendering speed for complex scenes containing many individually articulated and pickable objects, which is characteristic of model viewing applications for engineering, architecture and medical visualisation.”
</li><li><a href="https://github.com/idflood/ThreeNodes.js">ThreeNodes.js</a> is a graphical programming environment for building real-time interactive media, drawing inspiration from <a href="http://vvvv.org/">vvvv</a>.
</li><li>Illyriad’s first WebGL experiment was published last week; here’s an interesting <a href="http://blog.illyriad.co.uk/index.php/2011/11/webgl-experiments-texture-compression/">follow-up post about their experiments with compressed textures</a>.
</li><li>WebCL looks like it’ll bring some amazing parallelisation features to JavaScript, but — like WebGL’s GLSL — coding it might be harder than you might like.  <a href="http://www.infoq.com/news/2011/11/webgl-webcl-multicore-rivertrail">River Trail</a>, an Intel Labs project that pre-dates WebCL (but has a fork using WebCL as a back-end) adds much simpler-to-program parallelisation support, compiling JavaScript to OpenCL kernels.  It has some way to go, but it’s very clever stuff.
</li><li>If you want something a bit ahead of the current Firefox beta, but don’t want to have to go quite as far as a nightly build, you might want to try out Aurora — a new pre-beta channel.  <a href="http://hacks.mozilla.org/2011/11/announcing-firefox-aurora-10/">It’s currently at version 10</a> (as you’d expect, two versions ahead of the release version) and has some nice enhancements, including WebGL antialiasing.
</li><li>Here’s the beginnings of a translation of my tutorials into Russian — just <a href="http://forum.boolean.name/showthread.php?p=209849">the first half of lesson 1</a> for now.
</li></ul></div>
    </content>
    <updated>2011-11-17T14:28:47Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/11/17/lets-make-a-3d-game-make-it-fullscreen</id>
    <link href="http://learningthreejs.com/blog/2011/11/17/lets-make-a-3d-game-make-it-fullscreen/" rel="alternate" type="text/html"/>
    <link href="http://learningthreejs.com/data/THREEx/THREEx.FullScreen.js" length="2197" rel="enclosure" type="application/x-javascript"/>
    <title>Lets Make a 3D Game: Make It Fullscreen</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post is part of the <a href="http://learningthreejs.com/blog/categories/tutorial3dgame/">"Lets make a 3D game"</a> series.
It is about the <a href="http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html">fullscreen API</a>.
This API allows to make DOM elements fullscreen.
Fullscreen is quite important for games.
It provides a larger display so a more immersive experience for your players.
All that from javascript, so no more needed to ask "please f11" to your
players, isnt that sweet ? :)</p>

<p><img alt="" class="right " height="" src="http://learningthreejs.com/data/lets-make-a-3d-game-make-it-fullscreen/images/fullscreen-icon.png" title="" width=""/></p>

<p>The <a href="http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html">fullscreen API</a>
is still in discussion, but the basics are settled. At the time of this writing,
it is available in
<a href="http://blog.pearce.org.nz/2011/11/firefoxs-html-full-screen-api-enabled.html">firefox nightly</a>,
<a href="http://peter.sh/2011/01/javascript-full-screen-api-navigation-timing-and-repeating-css-gradients/">webkit nightly</a>and
<a href="http://updates.html5rocks.com/2011/10/Let-Your-Content-Do-the-Talking-Fullscreen-API">chrome stable</a>.
It has been already added in <a href="http://marblesoccer.com">marbleSoccer</a>.
The icon is from <a href="http://thenounproject.com/">The Noun Project</a>, a source of nice and clean icons.
Try it out! Click on it to toggle fullscreen state. If you dont see the icon, your browser
doesn't yet have the fullscreen API.</p>

<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="320" mozallowfullscreen="mozallowfullscreen" src="http://marblesoccer.com" webkitallowfullscreen="webkitallowfullscreen" width="100%"&gt;&lt;/iframe&gt;
</center>


<p>Ok now is time for code :)</p>

<h2>Let's get started</h2>

<p>As usual, i provide a little helper to make it easier for you to include it in
your games. It is called <a href="http://learningthreejs.com/data/THREEx/THREEx.FullScreen.js">THREEx.FullScreen.js</a>.
It hides the prefix of each vendor and the little discrepencies between their API
implementation.
You download this file from <a href="http://learningthreejs.com/data/THREEx/THREEx.FullScreen.js">here</a> and include
it in your page like this</p>

<p>```html</p>

<pre><code>&lt;script src='THREEx.FullScreen.js'&gt;&lt;/script&gt;
</code></pre>

<p>```</p>




<h2>How to use it ?</h2>

<p>The API is simple, only 4 calls. Lets see them one by one.
To test if it is possible to have fullscreen on your system, do</p>

<p>```javascript</p>

<pre><code>THREEx.FullScreen.available();
</code></pre>

<p>```</p>

<p>To test if fullscreen is currently activated on your page</p>

<p>```javascript</p>

<pre><code>THREEx.FullScreen.activated();
</code></pre>

<p>```</p>

<p>To Request fullscreen on a given element, just do</p>

<p>```javascript</p>

<pre><code>THREEx.FullScreen.request(element);
</code></pre>

<p>```</p>

<p>If element isnt provided, it defaults to <code>document.body</code>.
To cancel fullscreen on your page, use this line.</p>

<p>```javascript</p>

<pre><code>THREEx.FullScreen.cancel();
</code></pre>

<p>```</p>

<p>Quite straight forward, no ? :) As an example, let's make a toggle, the same used
in <a href="http://marblesoccer.com">marbleSoccer</a>.</p>

<p>```javascript</p>

<pre><code>if( THREEx.FullScreen.activated() ){
    THREEx.FullScreen.cancel();
}else{
    THREEx.FullScreen.request();
}
</code></pre>

<p>```</p>

<h2>What about the standard ?</h2>

<p>There is a <a href="http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html">w3c proposal</a> in dicussion.
John dyer has written an in-depth <a href="http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/">summary</a>.
Mozilla provides details on <a href="https://wiki.mozilla.org/Gecko:FullScreenAPI">their API</a>.
At the time of this writing
It is available in
<a href="http://blog.pearce.org.nz/2011/11/firefoxs-html-full-screen-api-enabled.html">firefox nightly</a>,
<a href="http://peter.sh/2011/01/javascript-full-screen-api-navigation-timing-and-repeating-css-gradients/">webkit nightly</a>
and
<a href="http://updates.html5rocks.com/2011/10/Let-Your-Content-Do-the-Talking-Fullscreen-API">chrome stable</a>.</p>

<h2>Conclusion</h2>

<p>For more details on <a href="http://learningthreejs.com/data/THREEx/THREEx.FullScreen.js">THREEx.FullScreen</a>,
see its <a href="http://learningthreejs.com/data/THREEx/docs/THREEx.FullScreen.html">annoted source</a>.
It is a simple to add in your game.
It provides a more immersive experience to your players.
On a related subject, we will soon likely do a post about embedding your game in another page.
It is usefull when you want to include it in a blog, in facebook or other game plateforms.</p></div>
    </summary>
    <content>This post is part of the "Lets make a 3D game" series. It is about the fullscreen API. This API allows to make DOM elements fullscreen. Fullscreen is quite important for games. It provides a larger display so a more immersive experience for your players. All that from javascript, so no more needed to ask "please f11" to your players, isnt that sweet ? :) The fullscreen API is still in discussion, but the basics are settled. At the time of this writing, it is available in firefox nightly, webkit nightlyand chrome stable. It has been already added in marbleSoccer. The icon is from The Noun Project, a source of nice and clean icons. Try it out! Click on it to toggle fullscreen state. If you dont see the icon, your browser doesn't yet have the fullscreen API. Ok now is time for code :) Let's get started As usual, i provide a little helper to make it easier for you to include it in your games. It is called THREEx.FullScreen.js. It hides the prefix of each vendor and the little discrepencies between their API implementation. You download this file from here and include it in your page like this ```html &lt;script src='THREEx.FullScreen.js'&gt;&lt;/script&gt; ``` How to use it ? The API is simple, only 4 calls. Lets see them one by one. To test if it is possible to have fullscreen on your system, do ```javascript THREEx.FullScreen.available(); ``` To test if fullscreen is currently activated on your page ```javascript THREEx.FullScreen.activated(); ``` To Request fullscreen on a given element, just do ```javascript THREEx.FullScreen.request(element); ``` If element isnt provided, it defaults to document.body. To cancel fullscreen on your page, use this line. ```javascript THREEx.FullScreen.cancel(); ``` Quite straight forward, no ? :) As an example, let's make a toggle, the same used in marbleSoccer. ```javascript if( THREEx.FullScreen.activated() ){ THREEx.FullScreen.cancel(); }else{ THREEx.FullScreen.request(); } ``` What about the standard ? There is a w3c proposal in dicussion. John dyer has written an in-depth summary. Mozilla provides details on their API. At the time of this writing It is available in firefox nightly, webkit nightly and chrome stable. Conclusion For more details on THREEx.FullScreen, see its annoted source. It is a simple to add in your game. It provides a more immersive experience to your players. On a related subject, we will soon likely do a post about embedding your game in another page. It is usefull when you want to include it in a blog, in facebook or other game plateforms.</content>
    <updated>2011-11-17T06:59:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:11Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://hacks.mozilla.org/?p=10176</id>
    <link href="http://hacks.mozilla.org/2011/11/announcing-firefox-aurora-10/" rel="alternate" type="text/html"/>
    <title>Announcing Firefox Aurora 10</title>
    <summary>We’re happy to announce the availability of Aurora 10. (Download and Test Aurora 10) In additional to the normal improvements that you’ve come to expect like performance, security and bug fixes, Aurora 10 focuses in HTML5 enhancements. New additions HTML5 Visibility API createProcessingInstruction WebGL antialiasing 3D Transforms Visibility API Document.mozFullScreenEnabled\ Developer Tools Code Editor CSS [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>We’re happy to announce the availability of Aurora 10. <br/>(<a href="http://www.mozilla.org/en-US/firefox/channel/">Download and Test Aurora 10</a>)</p>
<p>In additional to the normal improvements that you’ve come to expect like performance, security and bug fixes, Aurora 10 focuses in HTML5 enhancements. </p>
<h2>New additions</h2>
<ul>
<li><a href="https://developer.mozilla.org/en/DOM/Using_the_Page_Visibility_API">HTML5 Visibility API </a></li>
<li><a href="https://developer.mozilla.org/en/DOM/document.createProcessingInstruction">createProcessingInstruction</a></li>
<li>WebGL antialiasing</li>
<li>3D Transforms</li>
<li>Visibility API</li>
<li>Document.mozFullScreenEnabled\</li>
</ul>
<h2>Developer Tools</h2>
<ul>
<li><a href="https://wiki.mozilla.org/DevTools/Features/CodeEditor" title="DevTools/Features/CodeEditor">Code Editor</a></li>
<li><a href="https://wiki.mozilla.org/DevTools/Features/RulesView" title="DevTools/Features/RulesView">CSS Rules View</a></li>
<li><a href="https://wiki.mozilla.org/DevTools/Features/Highlighter" title="DevTools/Features/Highlighter">Page Inspector/Highlighter</a></li>
<li><a href="https://wiki.mozilla.org/DevTools/Features/ConsoleObjectCompletion" title="DevTools/Features/ConsoleObjectCompletion">Console Object Completion</a></li>
<li><a href="https://wiki.mozilla.org/DevTools/Features/StyleInspector" title="DevTools/Features/StyleInspector">Style Inspector</a></li>
</ul>
<p>Aurora 10 also implements incremental enhancements like IndexedDB setVersion API changes. Ongoing detailed attention to evolving specifications help to keep Firefox at the front of the Web revolution. (Read more about <a href="https://developer.mozilla.org/en/IndexedDB/IndexedDB_primer">IndexedDB on MDN</a>.)</p>
<h2>DOM</h2>
<ul>
<li>We now fire a “load” event on stylesheet linking when the sheet load finishes or “error” if the load fails.</li>
<li>We turn the POSTDATA prompt into an information page (when navigating in session history).</li>
<li>We only forward event attributes on body/frameset to the window if we also forward the corresponding on* property.</li>
<li>We no longer allow more than one call to window.open() when we allow popups.</li>
<li>We fixed a bug where a success callback never fired when a position update is triggered after getCurrentPosition().</li>
<li>We removed replaceWholeText().</li>
<li>We fixed an error with createPattern(zero-size canvas).</li>
<li>We now handle putImageData(nonfinite) correctly.</li>
<li>We now throw INVALID_STATE_ERR when dispatching uninitialized events.</li>
<li>We’ve made Document.documentURI readonly.</li>
<li>We fixed document.importNode to comply with optional argument omitted.</li>
</ul>
<h2>Web workers</h2>
<ul>
<li>We now allow data URLs.</li>
<li>We implemented event.stopImmediatePropagation in workers.</li>
<li>We made XHR2 response/responseType work in Web Workers.</li>
</ul>
<h2>Graphics</h2>
<ul>
<li>We implement the WebGL OES_standard_derivatives extension.</li>
<li>We implement minimal-capabilities WebGL mode.</li>
</ul>
<h2>JavaScript</h2>
<ul>
<li>The function caller property no longer skips over eval frames.</li>
<li>We fixed E4X syntax so that it is not accepted in ES5 strict mode.</li>
<li>weakmap.set no longer returns itself instead of undefined.</li>
<li>We implemented the battery API.</li>
</ul>
<h2>Offline: IndexedDB enhancements</h2>
<ul>
<li>IndexedDB setVersion API changes</li>
<li>Added support for IDBObjectStore/IDBIndex.count</li>
<li>Various methods accept both keys and KeyRanges.</li>
<li>Added support for IDBCursor.advance.</li>
<li>Implemented deleteDatabase.</li>
<li> objectStoreNames are no longer updated on closed databases when another connection adds or removes object stores</li>
<li>IDBObjectStore.delete and IDBCursor.delete now return undefined.</li>
<li>No longer throws an error if there are unknown properties in the options objects to createObjectStore/createIndex.</li>
<li>We now the errorCode to “ABORT_ERR” for all pending requests when IDBTransaction.abort() is called.</li>
<li>Fixed the sort order for indexes.</li>
</ul>
<h2>Layout</h2>
<ul>
<li>We have updated the current rule for handling malformed media queries.</li>
<li>We now support the HTML5 &lt;bdi&gt; element and CSS property unicode-bidi: isolate.</li>
<li>The CSS3 implementation now supports unicode-bidi: plaintext.</li>
</ul>
<h2>Media</h2>
<ul>
<li>Implemented Document.mozFullScreenEnabled.</li>
<li>Enabled the DOM full-screen API on desktop Firefox by default.</li>
</ul></div>
    </content>
    <updated>2011-11-11T22:34:00Z</updated>
    <category term="Aurora"/>
    <category term="Developer Tools"/>
    <category term="DOM"/>
    <category term="Feature"/>
    <category term="Featured Article"/>
    <category term="Firefox"/>
    <category term="HTML5"/>
    <category term="IndexedDB"/>
    <category term="WebGL"/>
    <author>
      <name>jstagner</name>
    </author>
    <source>
      <id>http://hacks.mozilla.org</id>
      <link href="http://hacks.mozilla.org/category/webgl/feed/" rel="self" type="application/atom+xml"/>
      <link href="http://hacks.mozilla.org" rel="alternate" type="text/html"/>
      <subtitle>hacks.mozilla.org</subtitle>
      <title>Mozilla Hacks - the Web developer blog » WebGL</title>
      <updated>2012-02-04T10:40:10Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4269</id>
    <link href="http://learningwebgl.com/blog/?p=4269" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 10 November 2011</title>
    <summary>This is excellent: the Google MapsGL team have open sourced a unit testing framework they use to test their shaders. The code is here, and there’s a demo test here. They’re planning to give a talk about it at the WebGL Camp next month. A WebGL documentary: the National Film Board of Canada has produced [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><ul>
<li>This is excellent: the Google MapsGL team have open sourced a unit testing framework they use to test their shaders.  <a href="http://code.google.com/p/glsl-unit/">The code is here</a>, and there’s <a href="http://glslunit.appspot.com/">a demo test here</a>.  They’re planning to give a talk about it at the <a href="http://www.webglcamp.com/wiki/index.php?title=Main_Page">WebGL Camp</a> next month.
</li><li>A WebGL documentary: the National Film Board of Canada has produced <a href="http://highrise.nfb.ca/onemillionthtower">One Millionth Tower</a>, showing new possibilities for high-rise homes.
</li><li>Want to see WebGL on an iOS device? Nathan de Vries has worked out <a href="http://atnan.com/blog/2011/11/03/enabling-and-using-webgl-on-ios/">a slightly scary hack</a> to get it running.  If you don’t want to try it out yourself, <a href="http://marcinignac.com/">Marcin Ignac</a> has videoed the results: <a href="http://vimeo.com/31553850">on an iPhone</a>, and, in more depth, <a href="http://vimeo.com/31644717">on an iPad 2</a>.
</li><li>Cool: <a href="http://mrdoob.com/projects/glsl_sandbox/">a GLSL sandbox from Mr. doob</a>.
</li><li><a href="http://alteredqualia.com/three/examples/webgl_terrain_dynamic.html">AlteredQualia’s dynamic procedural terrain</a> is very beautiful.
</li><li>Another one from Mr. doob: <a href="http://mrdoob.com/lab/javascript/webgl/kinect/">WebGL + Kinect = crazy demo</a>.
</li><li>Brandon Jones is writing a WebGL game and blogging his progress: <a href="http://blog.tojicode.com/2011/10/building-game-part-0-foreword.html">here’s part zero</a>, there are links to the next part at the bottom of each post.
</li><li>Mike Cann: it’s “possible have <a href="http://mikecann.co.uk/personal-project/terrainicles-webgl-haxe/">millions of particles interacting updating and rendering simultaneously</a> as all the operations are performed on the GPU”.
</li><li>Here are some ongoing translations of my <a href="http://www.jlabstudio.com/webgl/tutoriales-webgl/">WebGL tutorials into Spanish</a>.
</li><li><a href="http://www.netmagazine.com/node/1538">An interesting article by Carlos Ulloa</a> on the creation of <a href="http://lights.elliegoulding.com/">the interactive video for Ellie Goulding’s song ‘Lights’</a>.
</li><li>If you’re wondering how to use CORS to be able to load textures for your WebGL apps from other domains, something that’s been in Chrome for a little while and has now landed in Firefox 8, <a href="http://hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/">Benoit Jacob has written an explanation</a>.
</li><li>Colin MacKenzie IV’s <a href="https://github.com/sinisterchipmunk/jax">Jax</a>, a WebGL framework designed to help build rich applications with Ruby on Rails on the server side, <a href="http://blog.jaxgl.com/2011/11/jax-v2-0-released/">has reached version 2.0</a>.
</li><li>Illyriad is a free-to-play, real-time, HTML5 Massively-Multiplayer strategy game.  <a href="http://blog.illyriad.co.uk/index.php/2011/11/webgl-experiments-illyriads-3d-town/">Its developers are experimenting with WebGL</a> — sadly Chrome-only, though that’s fair enough given that it’s a first experiment. (<a href="https://twitter.com/#!/alteredq/status/134238089349566464">via</a> AlteredQualia)
</li><li>Good news — the Blackberry PlayBook 2.0 will apparently support WebGL.  The latest developer release already has it, and there’s a brief demo at around 24:20 in <a href="http://www.blackberrydevcon.com/americas/webcast/part1">this presentation</a>.
</li><li><a href="http://www.toyota.com/itsacar/">An amusing WebGL-enabled Toyota ad</a> — pity it also insists on Chrome.
</li><li><a href="http://www.skulpt.org/">Skulpt is an in-browser Python interpreter</a>, apparently with WebGL bindings.  I’ve only tried it on one of my less reliable machines, and the WebGL stuff didn’t work there for me, but others might have more luck — reports welcome in the comments.
</li><li><a href="https://github.com/operasoftware/Odin">Odin</a> is a demo from Opera’s Erik Möller.  <a href="http://operasoftware.github.com/Odin/demo.html">The live version</a> works well on <a href="http://www.opera.com/browser/next/">the latest Opera 12 beta</a>, is rather slow on Firefox, and doesn’t work on Chrome yet.  But it’s pretty impressive.
</li><li>Stephen Bannasch has updated his <a href="http://stepheneb.github.com/webgl-matrix-benchmarks/matrix_benchmark.html">WebGL matrix library comparison table</a>.  Looks like Closure and TDLFast are the current leaders.
</li><li>If you’re in or near Los Angeles and want to meet fellow WebGL enthusiasts, Felix Turner and Bartek Drozdz have set up an <a href="http://www.meetup.com/LA-WebGL-Meetup/">LA WebGL meetup</a>.
</li><li>On the subject of meetups, it sounds like last weekend’s Mozilla Media Festival in London was fun — <a href="http://vocamus.net/dave/?p=1362">David Humphreys has a summary here</a> (as well as <a href="http://vocamus.net/dave/?p=1360">a nice post</a> on the workings of Processing.js, the WebGL-based JavaScript implementation of the Processing graphics language).
</li></ul></div>
    </content>
    <updated>2011-11-10T14:35:33Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://hacks.mozilla.org/?p=10079</id>
    <link href="http://hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/" rel="alternate" type="text/html"/>
    <title>Using CORS to load WebGL textures from cross-domain images</title>
    <summary>In Firefox, as well as in Chrome, it is now possible to load cross-domain images into WebGL textures, if they have been approved by CORS. Most prominently, this feature allows for impressive 3D mapping applications such as Google MapsGL and Nokia Maps 3D. What happened Earlier this year, the Editor’s Draft WebGL specification got updated [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>In Firefox, as well as in Chrome, it is now possible to load cross-domain images into WebGL textures, if they have been approved by <a href="http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing">CORS</a>.</p>
<p>Most prominently, this feature allows for impressive 3D mapping applications such as <a href="http://maps.google.com/mapsgl">Google MapsGL</a> and <a href="http://maps3d.svc.nokia.com/webgl/">Nokia Maps 3D</a>.</p>
<h3>What happened</h3>
<p>Earlier this year, the<a href="http://www.khronos.org/registry/webgl/specs/latest/"> Editor’s Draft WebGL specification</a> got <a href="http://hacks.mozilla.org/2011/06/cross-domain-webgl-textures-disabled-in-firefox-5/">updated</a> in response to a security concern. The <a href="http://www.khronos.org/registry/webgl/specs/latest/#4.2">additions</a> were:</p>
<ol>
<li>A mandatory clause disallowing usage of cross-domain elements as WebGL textures in the general case.</li>
<li>A non-normative clause specifically allowing cross-domain elements that have CORS approval. For that occasion, the HTML specification on the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content-1.html#the-img-element">&lt;img&gt; element</a> got updated to add a <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content-1.html#attr-img-crossorigin">new crossorigin attribute</a>.</li>
</ol>
<p>The first got implemented in Firefox 5, the second is now in Firefox 8.</p>
<h3>How to use this feature</h3>
<p>There are <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/fetching-resources.html#cors-settings-attribute">two CORS modes</a>: “anonymous” and “use-credentials”. We’ll focus on “anonymous” as it’s the common case. A great example of images served with anonymous CORS is Google Maps imagery, such as:</p>
<p><a href="http://khm0.googleapis.com/kh?v=95&amp;x=0&amp;y=0&amp;z=0">http://khm0.googleapis.com/kh?v=95&amp;x=0&amp;y=0&amp;z=0</a></p>
<p>In order to load it with CORS as a WebGL texture, we set the crossOrigin attribute on it:</p>
<pre style="padding-left: 30px;">var earthImage = new Image();
earthImage.crossOrigin = "anonymous";</pre>
<p>Now we load it as usual:</p>
<pre>    earthImage.onload = function() {
      // whatever you usually to do load WebGL textures
    };
    earthImage.src = "http://khm0.googleapis.com/kh?v=95&amp;x=0&amp;y=0&amp;z=0";</pre>
<p>That’s it! Aside from setting the crossOrigin attribute, we didn’t have to do anything. Here is the <strong><a href="http://people.mozilla.org/~bjacob/webgltexture-cors-js.html">full self-contained example</a></strong>.</p>
<h3>The HTTP headers</h3>
<p>If we study the HTTP headers for this image (using, for example, Firefox’s Web Console), we find that the <em>Request Headers</em> contain</p>
<pre style="padding-left: 30px;">Origin: null</pre>
<p>which is the effect of having set this crossOrigin attribute on the img element. And the <em>Response Headers</em> contain</p>
<pre style="padding-left: 30px;">Access-Control-Allow-Origin: null</pre>
<p>which is the effect of the server supporting CORS for this file.</p>
<h3>Doing this in HTML</h3>
<p>Of course, one could also set this attribute in HTML, in which case it’s case-insensitive:</p>
<pre style="padding-left: 30px;">&lt;img src="http://khm0.googleapis.com/kh?v=95&amp;x=0&amp;y=0&amp;z=0" crossorigin="anonymous"&gt;</pre>
<p>And since “anonymous” is both the missing-value-default and the invalid-value-default for the crossorigin attribute, we can pass any invalid value for it, or even just omit its value:</p>
<pre style="padding-left: 30px;">&lt;img src="http://khm0.googleapis.com/kh?v=95&amp;x=0&amp;y=0&amp;z=0" crossorigin&gt;</pre>
<h3>Coming soon: CORS approval for Canvas 2D drawImage</h3>
<p>What if you first draw a CORS-approved cross-domain image onto a 2D<br/>
canvas, and then use that canvas as the source of a WebGL texture? The<br/>
good news is that this <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=685518">will work</a> in Firefox 9, which is hitting the Beta<br/>
channel soon. This fix means that demos like <a href="http://www.clicktorelease.com/code/weather/">this</a> will work really<br/>
nicely in Firefox 9.</p></div>
    </content>
    <updated>2011-11-08T15:43:17Z</updated>
    <category term="Firefox 8"/>
    <category term="WebGL"/>
    <author>
      <name>Benoit Jacob</name>
    </author>
    <source>
      <id>http://hacks.mozilla.org</id>
      <link href="http://hacks.mozilla.org/category/webgl/feed/" rel="self" type="application/atom+xml"/>
      <link href="http://hacks.mozilla.org" rel="alternate" type="text/html"/>
      <subtitle>hacks.mozilla.org</subtitle>
      <title>Mozilla Hacks - the Web developer blog » WebGL</title>
      <updated>2012-02-04T10:40:10Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4243</id>
    <link href="http://learningwebgl.com/blog/?p=4243" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 3 November 2011</title>
    <summary>Lots of good stuff today! A gorgeous WebGL experience from French web agency ultranoir: Nouvelle Vague. VideoRiot lets you mash up videos in your brower, using YouTube as the source. From Florian Boesch, a great demo of ambient occlusion, an impressive lighting technique. Project Nell aims to produce a 3D learning environment for One Laptop [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Lots of good stuff today!</p>
<ul>
<li>A gorgeous WebGL experience from French web agency ultranoir: <a href="http://nouvellevague.ultranoir.com/fr/">Nouvelle Vague</a>.
</li><li><a href="http://sp0t.org/videoriot/">VideoRiot lets you mash up videos in your brower</a>, using YouTube as the source.
</li><li>From Florian Boesch, a great <a href="http://codeflow.org/entries/2011/oct/25/webgl-screenspace-ambient-occlusion/">demo of ambient occlusion</a>, an impressive lighting technique.
</li><li><a href="http://cananian.livejournal.com/65077.html">Project Nell</a> aims to produce a 3D learning environment for One Laptop Per Child (the laptops don’t support WebGL yet, but there are plans to change that).  Here’s <a href="http://cananian.livejournal.com/65380.html">a collection of mostly-WebGL demos</a> showing the direction they’re going, with a bit of help from three.js.
</li><li>Another nice demo from Xavier Bourry at Spacegoo — <a href="http://www.spacegoo.com/beach/">a beach scene with animated water</a>.
</li><li>Ralph Schurade has built <a href="http://www-onpub.cbs.mpg.de/">a WebGL interactive version of an upcoming paper</a> about the mechanisms of language processing in the brain.  It has “the functionality of a basic mri viewer”, with “textured slices, surfaces and fibre tracts”.
</li><li>This is cool: <a href="http://www.myrobotnation.com/">My Robot Nation</a> lets you design your own toy robot online (using WebGL, of course), then realises it with a 3D printer and mails it to you.
</li><li>A new framework: <a href="https://github.com/funkaster/ChesterGL">ChesterGL is a 2D game library based on WebGL</a>, with some fallback to Canvas 2D when WebGL isn’t enabled.
</li><li><a href="http://webglmol.sourceforge.jp/index-en.html">GLmol is a WebGL molecular viewer</a>
</li><li><a href="http://www.clicktorelease.com/code/urban-arteries/">An interesting experiment in 3D mapping</a> by Jaume Sánchez Elias.
</li><li>Another Chester: <a href="http://altdevblogaday.com/2011/09/29/meet-my-dog-chester/">Chester the Dog definitely writes better tutorials than I do</a>.
</li><li>Serious games need full-screen graphics; Brandon Jones has been <a href="http://blog.tojicode.com/2011/09/state-of-javascript-fullscreen-api.html">experimenting with a new API providing that</a> (currently Webkit-only).  Read the full article including the corrections he added later.
</li><li>Relatedly, mouse lock is another new API that will be useful for games: here’s <a href="http://vocamus.net/dave/?p=1354">David Humphrey’s description</a> of why it’s useful, and how and why he and his students will be building it into Mozilla.
</li><li><a href="http://oos.moxiecode.com/js_webgl/snake/">Thanks to OutsideOfSociety</a>, we now only need someone to create WebGL badgers and mushrooms.
</li><li>Here’s a <a href="http://www.cse.yorku.ca/~shuryork/MotionBlurTest.html">nice simple demo of motion blurring in WebGL</a> by Dmitri Shuralyov.</li>
<li>Jacob Seidelin, who write some of the best <a href="http://blog.nihilogic.dk/2009/11/webgl-musical-solar-system.html">early WebGL demos</a>, has written a book <a href="http://blog.nihilogic.dk/2011/09/i-wrote-book-re-html5-games.html">HTML5 Games: Creating Fun with HTML5, CSS3 and WebGL</a>.  It should be well worth reading.
</li><li>Not strictly WebGL, but if you’ve not seen it then you should take a look at <a href="http://www.adobe.com/devnet/html5/articles/css-shaders.html">Adobe’s CSS shaders</a> proposal, which would allow you to use the OpenGL ES shader language we all know and love to modify normal web page elements.  Definite possibilities there!
</li><li>Learn OpenGL ES is branching out into WebGL lessons; <a href="http://www.learnopengles.com/webgl-lesson-one-getting-started/">here’s the first one</a>, along with a useful post about <a href="http://www.learnopengles.com/how-to-embed-webgl-into-a-wordpress-post/">how to put WebGL canvases into WordPress blog posts</a>.
</li></ul></div>
    </content>
    <updated>2011-11-03T15:06:09Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/11/02/lets-make-a-3d-game-helper-for-microphysics-js</id>
    <link href="http://learningthreejs.com/blog/2011/11/02/lets-make-a-3d-game-helper-for-microphysics-js/" rel="alternate" type="text/html"/>
    <title>Lets Make a 3D Game: microphysics.js, even easier</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post is part of the <a href="http://learningthreejs.com/blog/categories/tutorial3dgame/">"Lets make a 3D game"</a> series.
It is a follow up from the previous article on <a href="http://learningthreejs.com/blog/2011/10/17/lets-make-a-3d-game-microphysics-js/">microphysics.js</a>.
It will describe how to easily include <strong>microphysics.js</strong> in your three.js games.
<a href="https://raw.github.com/jeromeetienne/microphysics.js/master/THREEx.microphysics.js">THREEx.microphysics.js</a> is a THREEx wrapper for microphysics.js.
It helps binding <a href="https://github.com/mrdoob/three.js/">three.js</a> objects to <a href="http://learningthreejs.com/blog/2011/10/17/lets-make-a-3d-game-microphysics-js/">microphysics.js</a>.
The API is chained for convenience.</p>

<h2>Let's get started</h2>

<p>So lets see how to use it.
First step, you download it
<a href="https://raw.github.com/jeromeetienne/microphysics.js/master/THREEx.microphysics.js">here</a>.
Then include it in your own code with this line.</p>

<p>```html</p>

<pre><code>&lt;script src="THREEx.microphysics.js"&gt;&lt;/script&gt;
</code></pre>

<p>```</p>




<h2>Initialisation</h2>

<p>You instanciate the physics engine, like that.</p>

<p>```javascript</p>

<pre><code>var microphysics = new THREEx.Microphysics(opts);
</code></pre>

<p>```</p>

<p><code>opts</code> is optional.
<code>opts.timeStep</code> controls the frequency of the world update.
The smaller it is the more accurate is the physics but the longer it is to compute.
It defaults to <code>1/60</code>. Once instanciated, you start it.</p>

<p>```javascript</p>

<pre><code>microphysics.start();
</code></pre>

<p>```</p>

<h2>Binding THREE.Mesh</h2>

<p>Of course we need to add some mesh in the world. After this line, the <code>mesh</code>
is bound to microphysics.js, so its position is driven by the physics.</p>

<p>```javascript</p>

<pre><code>microphysics.bindMesh(mesh, opts);
</code></pre>

<p>```</p>

<p><code>mesh.position</code> is honored.
If you need to unbind a <code>mesh</code>, just do</p>

<p>```javascript</p>

<pre><code>microphysics.unbindMesh(mesh);
</code></pre>

<p>```</p>

<p>At the time of this writing, microphysics.js support only moving sphere and static
boxes, so geometry may only be <code>THREE.SphereGeometry</code> or <code>THREE.CubeGeometry</code>.
If your mesh got another geometry, use <code>opts.geometry</code> to say how you wish the mesh
to be handled.</p>

<p>```javascript</p>

<pre><code>microphysics.bindMesh(mesh, {
     geometry   : new THREE.CubeGeometry(200,200,200);
});
</code></pre>

<p>```</p>

<p>It is also possible to overwrite <code>Mesh.position</code> with <code>opts.position</code>, or
to send options directly to microphysics.js with <code>opts.physics</code>.</p>

<p>```javascript</p>

<pre><code>microphysics.bindMesh(mesh, {
    // to overwrite the Mesh.position
    position    : { x : 1, y : 1, z : 2 },
    // to pass options directly to microphysics.js
    physics     : { restitution : 0.98 }
});
</code></pre>

<p>```</p>

<h2>Updating the physics</h2>

<p>In your render loop, just add this line. It will first update the physics world and
then move accordingly any <code>THREE.Mesh</code> you bound.</p>

<p>```javascript</p>

<pre><code>microphysics.update();  
</code></pre>

<p>```</p>

<h2>Needs a Direct Access ?</h2>

<p>If you need to have direct access to microphysics.js, uses
<code>microphysics.body(mesh)</code> to get the <code>vphy.Body</code> bound to <code>mesh</code>.
To access <code>vphy.World</code>, just use <code>microphysics.word()</code>.</p>

<h2>Conclusion</h2>

<p>In the previous article on <a href="http://learningthreejs.com/blog/2011/10/17/lets-make-a-3d-game-microphysics-js/">microphysics.js</a>,
we learned how to use microphysics.js directly. This article makes it really easy to include
in your <a href="https://github.com/mrdoob/three.js/">three.js</a> demo/game.
It is so nice that it is what is used in the
<a href="http://jeromeetienne.github.com/microphysics.js/playground/">playground</a>.
That's all for today folks. Have fun :)</p></div>
    </summary>
    <updated>2011-11-02T17:16:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:12Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://hacks.mozilla.org/?p=10046</id>
    <link href="http://hacks.mozilla.org/2011/10/beam-me-up-scotty-bringing-html5-to-the-enterprise/" rel="alternate" type="text/html"/>
    <link href="http://www.archive.org/download/Html5101-WhatItIsWhatItIsntAndWhereItMightGo/WhatIsHtml5.mp3" length="0" rel="enclosure" type="audio/mpeg"/>
    <link href="http://www.archive.org/download/Html5101-WhatItIsWhatItIsntAndWhereItMightGo/WhatIsHtml5.ogg" length="0" rel="enclosure" type="audio/ogg"/>
    <title>Beam me up, Scotty – bringing HTML5 to the enterprise</title>
    <summary>The last few days I was busy talking to in-house developers at two large enterprise companies, Sabre in Poland and SAP in Germany. Both these companies approached us asking for a talk about HTML5 as the topic gets a lot of interest in the upper echelons and there is a lot of confusion about it. [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>The last few days I was busy talking to in-house developers at two large enterprise companies, Sabre in Poland and SAP in Germany. Both these companies approached us asking for a talk about HTML5 as the topic gets a lot of interest in the upper echelons and there is a lot of confusion about it. </p>
<p>As we were in Poland anyways to attend <a href="http://frontrowconf.com/">Frontrow</a> it was easy to visit Sabre and give a one hour presentation on the ins and outs of HTML5 and where the web might go. The day after the same talk was repeated over Skype for the German office of SAP. </p>
<p>In the one hour presentation we covered:</p>
<ul>
<li>the basics of HTML5</li>
<li>what it meant as an evolution of markup</li>
<li>what HTML5 is not</li>
<li>common HTML5 myths</li>
<li>“Friends of HTML5″ – related technologies and</li>
<li>what the future of web technologies could look like</li>
</ul>
<p>The slides are <a href="http://icant.co.uk/talks/what-is-html5">available online</a> or embedded below (cursor keys to navigate, press N to show and hide notes and cursor down to proceed on slides with bullet points):</p>
<p>&lt;iframe src="http://icant.co.uk/talks/what-is-html5/#1" style="border:none;width:100%;height:400px;"&gt;&lt;/iframe&gt;</p>
<p>The <a href="http://www.archive.org/details/Html5101-WhatItIsWhatItIsntAndWhereItMightGo">audio recording of the talk</a> is available on archive.org. </p>
<p>&lt;audio controls="controls" preload="metadata" style="display:block;margin:1em;"&gt;&lt;source src="http://www.archive.org/download/Html5101-WhatItIsWhatItIsntAndWhereItMightGo/WhatIsHtml5.mp3" type="audio/mp3"&gt;&lt;/source&gt;&lt;source src="http://www.archive.org/download/Html5101-WhatItIsWhatItIsntAndWhereItMightGo/WhatIsHtml5.ogg" type="audio/ogg"&gt;&lt;/source&gt;&lt;/audio&gt;</p>
<p>The slides and the audio is licensed with Creative Commons, so feel free to re-use and distribute them. </p></div>
    </content>
    <updated>2011-10-28T13:08:56Z</updated>
    <category term="B2G"/>
    <category term="HTML5"/>
    <category term="WebGL"/>
    <author>
      <name>Chris Heilmann</name>
    </author>
    <source>
      <id>http://hacks.mozilla.org</id>
      <link href="http://hacks.mozilla.org/category/webgl/feed/" rel="self" type="application/atom+xml"/>
      <link href="http://hacks.mozilla.org" rel="alternate" type="text/html"/>
      <subtitle>hacks.mozilla.org</subtitle>
      <title>Mozilla Hacks - the Web developer blog » WebGL</title>
      <updated>2012-02-04T10:40:10Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4221</id>
    <link href="http://learningwebgl.com/blog/?p=4221" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 27 October 2011</title>
    <summary>Nokia’s (sadly Chrome-only, apparently they’re fixing some cross-domain issues [UPDATE Paul comments that it works in Firefox 8 or later]) 3D WebGL maps are extremely impressive! Use the tilt buttons (right-hand side of the control panel at bottom-centre) when zoomed in for maximum awesomeness. From Raul Hao: my WebGL tutorials, converted to use Oak3D and [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><ul>
<li>Nokia’s (<del datetime="2011-10-27T21:39:43+00:00">sadly Chrome-only, apparently they’re fixing some cross-domain issues</del> [UPDATE Paul <a href="http://learningwebgl.com/blog/?p=4221&amp;cpage=1#comment-42977">comments</a> that it works in Firefox 8 or later]) <a href="http://maps3d.svc.nokia.com/webgl/">3D WebGL maps</a> are extremely impressive!  Use the tilt buttons (right-hand side of the control panel at bottom-centre) when zoomed in for maximum awesomeness.</li>
<li>From Raul Hao: <a href="http://www.hiwebgl.com/?p=42">my WebGL tutorials, converted to use Oak3D and translated into Chinese</a></li>
<li>So, I’ve been being pretty useless about organising another London WebGL meetup — but there’s some good news for fellow Londoners who fancy a meetup: the <a href="https://mozillafestival.org/">London Mozilla Festival, from 4-6 November</a>, “open web developers, journalists and educators coming together to reinvent media on the web”.  Sadly I can’t make it myself, but the guys at Mozilla have said that WebGL / JavaScript developers are very welcome, and can sign up at the reduced “student/partner/community member” rate of £30.
</li><li>A lovely interactive music video: <a href="http://lights.elliegoulding.com/">Ellie Goulding’s Lights</a>, by <a href="http://helloenjoy.com/">HelloEnjoy</a> (of <a href="http://helloracer.com/">HelloRacer</a> fame)
</li><li><a href="http://www.inka3d.com/">Inka3D helps you convert Maya scenes for use in WebGL apps</a>.  It was apparently used in the creation of the excellent <a href="http://azathioprine.digisnap.bplaced.net/">Azathioprine</a> demo, which is a good recommendation!
</li><li><a href="http://kleki.com/">Here’s Kleki, an online paint package</a> by bitbof, with WebGL-based filters using Evan Wallace’s <a href="http://evanw.github.com/glfx.js/">glfx.js library</a>.
</li><li>Ilmari Heikkinen has posted <a href="http://fhtr.blogspot.com/2011/09/basics-of-threejs-presentation.html">a presentation on the basics of Three.js</a>.
</li><li>Not quite as shiny as some of his older demos, but perhaps more scientifically useful: Evgeny Demidov has ported some old VRML <a href="http://www.ibiblio.org/e-notes/Cryst/Cryst.htm">crystal models</a> to WebGL.
</li><li><a href="http://oos.moxiecode.com/js_webgl/explosion/">Do not click</a> this demo from OutsideOfSociety.
</li></ul></div>
    </content>
    <updated>2011-10-27T15:11:52Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2012-01-17T18:40:03Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://hacks.mozilla.org/?p=9896</id>
    <link href="http://hacks.mozilla.org/2011/10/debugging-and-editing-webpages-in-3d/" rel="alternate" type="text/html"/>
    <title>Debugging and editing webpages in 3D</title>
    <summary>Tilt is a Firefox addon that lets you visualize any web page in 3D. A new update is available, coming with more developer-oriented features. Try the addon. Since the first alpha version of Tilt was announced (a Firefox extension focused on creating a 3D visualization of a webpage), a lot of work has been done [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p><em><strong>Tilt</strong> is a Firefox addon that lets you visualize any web page in 3D. A new update is available, coming with more developer-oriented features. Try the <a href="http://hacks.mozilla.org/category/webgl/feed/#availableasanaddon">addon</a>.</em></p>
<p>&lt;object height="375" width="500"&gt;&lt;param name="movie" value="http://www.youtube.com/v/_7eG_PONHRw?version=3&amp;amp;feature=oembed"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed allowfullscreen="true" allowscriptaccess="always" height="375" src="http://www.youtube.com/v/_7eG_PONHRw?version=3&amp;amp;feature=oembed" type="application/x-shockwave-flash" width="500"&gt;&lt;/embed&gt;&lt;/object&gt;</p>
<p>Since the <a href="http://hacks.mozilla.org/2011/07/tilt-visualize-your-web-page-in-3d/">first alpha version of Tilt was announced</a> (a Firefox extension focused on creating a 3D visualization of a webpage), a lot of work has been done to add a great number of developer-oriented features. These focus on debugging the structure of a webpage, inspecting styling and attributes for each node and seamlessly refreshing the visualization when the DOM structure changes or after contents of document are repainted.</p>
<h2>Solve nesting problems</h2>
<p>Tilt is useful when searching problems in the HTML structure (like finding unclosed DIV elements for example) by providing the extra third dimension, layering each node based on nesting in the DOM tree. Stacks of elements visually represent branches in the DOM, and each node can be inspected for the inner HTML contents, its computed CSS style and the attributes.</p>
<p>Clicking anywhere on the visualization highlights a color-coded rectangle surrounding the corresponding node. Double click shows up the source preview for that node. Tilt also tries to show the most relevant information when needed (one is most likely to inspect the attributes of an input, button or image element, for example, but can easily switch between HTML, CSS and attributes view at any time).</p>
<p><a href="http://hacks.mozilla.org/wp-content/uploads/2011/10/tilt3d2.png"><img alt="" class="aligncenter size-full wp-image-9911" height="312" src="http://hacks.mozilla.org/wp-content/uploads/2011/10/tilt3d2.png" width="500"/></a></p>
<h2>Minidom map</h2>
<p>The “minidom” is a tree view representation showing a minimalistic snapshot of the document object model. Each node is assigned a color associated by tag name (blue for div, green for span etc.) and represented as a strip, along with visual markers for the id and/or class if available. Each one of these strips also has a width relative to the type, id and class name length for the respective element, and the corresponding 3D stack in the visualization has color-coded margins. The coloring for individual elements is easily changeable using the color picker near to the minidom legend.</p>
<p>Clicking a strip in the tree view (or directly a stack on the 3D document visualization mesh) also highlights the node with a colored quad. This behavior is a good way to relate with the Style Inspector, and a more unified interaction between Tilt and other Developer Tools is planned in the future. All of these additions make it easier to analyze the bounds of each node, along with the HTML, computed CSS and attributes.</p>
<h2>Realtime editing</h2>
<p>Because Tilt is able to detect when a webpage’s DOM structure changes or when a repaint is necessary, integration is seamless with existing Developer Tools. Using Tilt and Firebug or Style Editor at the same time is easy. One can enable or disable CSS properties, changing the style of a node, and the visualization changes accordingly.</p>
<p>&lt;object height="375" width="500"&gt;&lt;param name="movie" value="http://www.youtube.com/v/ae1p5W20Ug8?version=3&amp;amp;feature=oembed"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed allowfullscreen="true" allowscriptaccess="always" height="375" src="http://www.youtube.com/v/ae1p5W20Ug8?version=3&amp;amp;feature=oembed" type="application/x-shockwave-flash" width="500"&gt;&lt;/embed&gt;&lt;/object&gt;</p>
<p><em>To enable realtime updates for the 3D webpage, go to the Options menu and check “Refresh visualization”.</em></p>
<h2>Useful for learning</h2>
<p>Developer tools such as “view source” have always been used to help people learn about web development. The 3D view highlights the structure of a page better than a flat view, thus anyone can immediately understand the parent-child relationship between nodes in a webpage, their positioning and how the layout is influenced.</p>
<p>One use case for this is the Hackasaurus mashup. The <a href="http://hackasaurus.org/goggles/" target="_blank">X-Ray Goggles</a> is a nice and fun tool designed to make it easier to learn about the different document node types, the “building blocks” which create a webpage.</p>
<h2>Export</h2>
<p>A requested feature was the ability to export the visualization as a 3D mesh, to be used in games or other 3D editors. Tilt adds the ability to export to <em>.obj</em>, along with a material <em>.mtl</em> file and a <em>.png</em> texture (a screenshot of the entire webpage). The open <em>.obj</em> format ensures the fact that the mesh can be opened with almost any editor. Here’s a ray-traced rendering of <a href="http://hacks.mozilla.org/2011/07/tilt-visualize-your-web-page-in-3d/" target="_blank">hacks.mozilla.org</a> in <a href="http://www.blender.org/" target="_blank">Blender</a>:</p>
<p style="text-align: center;"><a href="http://hacks.mozilla.org/wp-content/uploads/2011/10/tilt3d3.png"><img alt="" class="aligncenter size-full wp-image-9927" height="305" src="http://hacks.mozilla.org/wp-content/uploads/2011/10/tilt3d3.png" width="500"/></a></p>
<h2>Fun with experiments</h2>
<p>As soon as it was released, many people found clever and interesting alternative ways to interact with Tilt. One experiment was creating a 3D visualization of an image, by exporting chunks of pixels to a HTML representation. The result was a voxel-like representation, with node blocks and stacks instead of pixels. A simple <a href="http://tinyurl.com/Img2Tilt" target="_blank">Image2Tilt converter</a> was written in JavaScript, and you can try it directly in the browser.</p>
<p>&lt;object height="375" width="500"&gt;&lt;param name="movie" value="http://www.youtube.com/v/7YXq4gylERE?version=3&amp;amp;feature=oembed"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed allowfullscreen="true" allowscriptaccess="always" height="375" src="http://www.youtube.com/v/7YXq4gylERE?version=3&amp;amp;feature=oembed" type="application/x-shockwave-flash" width="500"&gt;&lt;/embed&gt;&lt;/object&gt;</p>
<p>Accelerometer support was another addition based on community request. This shows how easy it is to add functionality that wasn’t originally planned.</p>
<p>&lt;object height="281" width="500"&gt;&lt;param name="movie" value="http://www.youtube.com/v/rbTLwVEfPn0?version=3&amp;amp;feature=oembed"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;embed allowfullscreen="true" allowscriptaccess="always" height="281" src="http://www.youtube.com/v/rbTLwVEfPn0?version=3&amp;amp;feature=oembed" type="application/x-shockwave-flash" width="500"&gt;&lt;/embed&gt;&lt;/object&gt;</p>
<p>You can view the source code, fork it and also contribute to the addon with ideas or feature requests on Github, at <a href="https://github.com/victorporof/Tilt" target="_blank">github.com/victorporof/Tilt</a>.</p>
<h2><a name="availableasanaddon"/>Available as an addon</h2>
<p>The latest version of <a href="https://github.com/victorporof/Tilt/raw/master/bin/Tilt.xpi" target="_blank">Tilt</a> can be found on <a href="https://github.com/victorporof/Tilt/raw/master/bin/Tilt.xpi" target="_blank">Github</a>, but you can also download Tilt as an <a href="https://addons.mozilla.org/en-US/firefox/addon/tilt/" target="_blank">addon from addons.mozilla.org</a>.</p>
<p>For compatibility, Tilt requires WebGL capabilities. Go to <a href="http://get.webgl.org/" target="_blank">get.webgl.org</a> to check availability and troubleshoot any issues. The current version works with Firefox 6.0 to latest <a href="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/" target="_blank">10.0 Nightly releases</a> (latest Nightly builds now also support WebGL anti-aliasing, working great with Tilt).</p>
<p>To start Tilt, hit <em>Control+Shift+M</em> (or <em>Command+Shift+M</em> if you’re on Mac OS), or go to <strong>Web Developer -&gt; Tilt</strong>, available in the Firefox application menu (or the Tools menu on Mac OS). You can modify this hotkey (and other properties) from the Options menu after starting Tilt.</p>
<p>More information about Tilt, the development process and milestone updates can be found on <a href="http://blog.mozilla.com/tilt">blog.mozilla.com/tilt</a>.</p>
<h2>Future</h2>
<p>Tilt has become an active Developer Tools project, and an ongoing effort is made to integrate it with other existing tools like Style Inspector and Style Editor (<a href="https://github.com/neonux/StyleEditor" target="_blank">source code</a> and <a href="http://neonux.com/StyleEditor/builds/" target="_blank">latest builds</a>). As the 3D view of a webpage has proven to be useful for debugging, this main functionality will gradually become part of Firefox in future releases.</p></div>
    </content>
    <updated>2011-10-26T14:47:09Z</updated>
    <category term="Add-ons"/>
    <category term="Debugging"/>
    <category term="Demo"/>
    <category term="Developer Tools"/>
    <category term="WebGL"/>
    <author>
      <name>victor</name>
    </author>
    <source>
      <id>http://hacks.mozilla.org</id>
      <link href="http://hacks.mozilla.org/category/webgl/feed/" rel="self" type="application/atom+xml"/>
      <link href="http://hacks.mozilla.org" rel="alternate" type="text/html"/>
      <subtitle>hacks.mozilla.org</subtitle>
      <title>Mozilla Hacks - the Web developer blog » WebGL</title>
      <updated>2012-02-04T10:40:09Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4199</id>
    <link href="http://learningwebgl.com/blog/?p=4199" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 20 October 2011</title>
    <summary>Opera with WebGL is now in alpha! They’ve written a nice introduction here. (h/t Nicolas Garcia Belmonte) Good news for those in the San Francisco Bay Area: the next WebGL Camp will take place on Friday, 9 December, 2011 at Mozilla. Previous ones have sounded fantastic, it’s free, and there’s a 100-person limit — so [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><ul>
<li><a href="https://twitter.com/#!/andreasbovens/status/124389622053748736">Opera with WebGL</a> is now in alpha! They’ve written <a href="http://dev.opera.com/articles/view/an-introduction-to-webgl/">a nice introduction here</a>.  (<a href="http://learningwebgl.com/blog/?p=4170&amp;cpage=1#comment-41477">h/t</a> Nicolas Garcia Belmonte)
</li><li>Good news for those in the San Francisco Bay Area: the next <a href="http://www.webglcamp.com/wiki/index.php?title=Main_Page">WebGL Camp</a> will take place on Friday, 9 December, 2011 at Mozilla.  Previous ones have sounded fantastic, it’s free, and there’s a 100-person limit — so keep an eye on the website for when registration goes live.  For those of us that can’t make it, hopefully there will be a live video stream of the talks.
</li><li>Some nice new demos from Mr. doob: liquid WebGL voxels, <a href="http://mrdoob.com/lab/javascript/webgl/voxels_liquid/">part 1</a> and <a href="http://mrdoob.com/lab/javascript/webgl/voxels_liquid/index2.html">part 2</a>, (click them to see the effect), and a strangely disturbing <a href="http://mrdoob.com/lab/javascript/webgl/voxels_video/">video in voxels</a>.
</li><li>“Unfortunately the GPU is a shared resource and as such there are times when it might be taken away from your [WebGL] program.”  The ContextLost event is fired by the canvas when that happens, and not many WebGL demos handle it gracefully.  Gregg Tavares has written <a href="http://www.khronos.org/webgl/wiki/HandlingContextLost">a useful Wiki page explaining what you need to do and why</a>, and has also updated the <a href="http://www.khronos.org/webgl/wiki/Demo_Repository">Khronos WebGL demos</a> to deal with it.
</li><li>Also via Gregg, some nice demos from the WebGL samples repo on Google Code: <a href="http://webglsamples.googlecode.com/hg/toon-shading/toon-shading.html">adjustable toon shading</a>, <a href="http://webglsamples.googlecode.com/hg/persistence/persistence.html">persistence of vision</a>, and <a href="http://webglsamples.googlecode.com/hg/color-adjust/color-adjust.html">live colour adjustment of a video</a>.  Also, separately, a <a href="http://workshop.chromeexperiments.com/bookcase">WebGL bookbase</a> of books from Google books.
</li><li>From Stefan, <a href="http://granular.cs.umu.se/browserphysics/?p=541">a cool car demo using ammo.js and three.js</a>.
</li><li>Over at Spacegoo, Xavier’s produced <a href="http://www.spacegoo.com/demo_html5toflash.php">a tool that can package up your HTML5 app as Flash</a> so that (for example) you can enter it into Flash competitions.
</li><li>Trying to get WebGL to work in Internet Explorer?  <a href="http://blog.virtualglobebook.com/2011/10/webgl-in-internet-explorer.html">Patrick Cozzi has blogged a summary of the options</a>.
</li><li>From Jonas Wagner — <a href="http://29a.ch/sandbox/2011/addresscloud/">over 3 million Swiss addresses plotted as a point cloud</a>.  Your graphics card will not thank you ;-)
</li></ul></div>
    </content>
    <updated>2011-10-20T13:36:00Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2011-12-15T00:00:04Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningthreejs.com/blog/2011/10/17/lets-make-a-3d-game-microphysics-js</id>
    <link href="http://learningthreejs.com/blog/2011/10/17/lets-make-a-3d-game-microphysics-js/" rel="alternate" type="text/html"/>
    <link href="http://learningthreejs.com/data/THREEx/THREEx.KeyboardState.js" length="3173" rel="enclosure" type="application/x-javascript"/>
    <title>Lets Make a 3D Game: microphysics.js</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>This post is part of the <a href="http://learningthreejs.com/blog/categories/tutorial3dgame/">"Lets make a 3D game"</a> series.
3D and physics simulation always go well together
<a href="http://www.youtube.com/watch?v=Rd7TyU9RdQk">even</a>
<a href="http://www.youtube.com/watch?v=o_xr8Htj9GI">more</a>
<a href="http://www.youtube.com/watch?v=Xfrzi-yVcsM">so</a>
<a href="http://www.youtube.com/watch?v=uvCbc8vFUMo">with</a>
<a href="http://www.youtube.com/watch?v=7lBUBBW_sF0">marble</a>
<a href="http://www.youtube.com/watch?v=c7npJ3E-ydA">games</a>.
One is required for <a href="http://marblesoccer.com">marblesoccer</a> but i wasnt
convinced by current 3d physics engines. I explain why at the end.
Fortunatly, <a href="http://twitter.com/#!/pyalot">@pyalot</a> from <a href="http://codeflow.org/">codeflow.org</a>
has been kind enough to write one taylor-made for us: <strong>microphysics.js</strong>!!</p>

<p>It is bite-sized, elegant and efficient.
Less than 500 lines at the moment!!
It is small engouh to be understood, important feature for a tutorial blog.
It is a work in progress tho.
We aren't aware of any bugs.
New features will be added and the API is expected to move.
Currently it implements moving spheres and static boxes (or <a href="http://en.wikipedia.org/wiki/Axis-aligned_bounding_box">AABB</a> as we like to say).
This is all we need for <a href="http://marblesoccer.com">marblesoccer</a>, the good thing about tailor-made.
<em>We are in business!!!</em></p>

<p>Below is a screencast of me doing a short introduction of the
<a href="http://jeromeetienne.github.com/microphysics.js/playground/">playground</a>.
This just a page for you to experiment with microphysics.js.</p>

<center>
    &lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="349" src="http://www.youtube.com/embed/DI5PV2_sLoM" width="425"&gt;&lt;/iframe&gt;
</center>


<h2>Let's get started</h2>

<p>So lets see how to use it.
First step, you download it <a href="https://raw.github.com/jeromeetienne/microphysics.js/master/codeflow/physics.js">here</a>.
Then include it in your own code with this line.</p>

<p>```html</p>

<pre><code>&lt;script src="physics.js"&gt;&lt;/script&gt;
</code></pre>

<p>```</p>




<h2>Let's Create a World</h2>

<p><img alt="" class="right " height="" src="http://learningthreejs.com/data/lets-make-a-3d-game-microphysics-js/images/galactus.png" title="" width=""/></p>

<p>Quite a title hey ?
Dont you feel like <a href="http://en.wikipedia.org/wiki/Galactus">galactus</a> when you say it ?
First you instanciate the physics <code>world</code> like this.</p>

<p>```javascript</p>

<pre><code>var world = new vphy.World()
</code></pre>

<p>```</p>

<p>Now you start it. Dont forget to give it the date as you see it.</p>

<p>```javascript</p>

<pre><code>world.start(Date.now()/1000);
</code></pre>

<p>```</p>

<p>The <code>world</code> is now fully initialized.
You just have to periodically update it in your game/render loop.</p>

<p>```javascript</p>

<pre><code>var timeStep    = 1/180;
world.step(timeStep, Date.now()/1000);
</code></pre>

<p>```</p>

<p>The <code>timeStep</code> parameter is the precision of the physics engine, expressed in seconds.
Quite a subtle tradeoff.
The smaller it is, the more accurate is the physics, but the slower it is to compute.
Up to you to find the balance that fit your needs.</p>

<h2>Let's Add Bodies</h2>

<p><img alt="" class="left " height="" src="http://learningthreejs.com/data/lets-make-a-3d-game-microphysics-js/images/The_shining_heres_johnny.jpg" title="" width=""/></p>

<p>Don't worry, this is not about killing people and dispose of their dead bodies :)
In physics, A <a href="http://en.wikipedia.org/wiki/Rigid_body">body</a> is a solid object that you put in your world.
microphysics bodies can be spheres or static boxes.
Lets start right away by creating a sphere.</p>

<p>```javascript</p>

<pre><code>var sphere  = new vphy.Sphere({
    x : 10,
    y : 10,
    z : 10,
    restitution : 0.6,
    radius : 5,
});
</code></pre>

<p>```</p>

<p>This will position it at <code>(10,10,10)</code> in the world.
<a href="http://en.wikipedia.org/wiki/Coefficient_of_restitution">restitution</a> will determine how
bouncy is this during a collision.
A bouncing ball restitutes a lot.
A falling eggs restitutes less :)
This declaration seems quite verbose at first.
Don't worry those parameters got sensible defaults, no need to specify them all.</p>

<p>Now lets add it to our world</p>

<p>```javascript</p>

<pre><code>world.add(sphere);
</code></pre>

<p>```</p>

<p>If you need to remove it, just do <code>world.remove(sphere)</code>. Not too hard hey ?
Now lets create a static box.
Boxes are called <em>AABB</em>.
It stands for <a href="http://en.wikipedia.org/wiki/Axis-aligned_bounding_box">Axis-aligned bounding box</a>.
It is graphic jarguon for the smallest box containing your object.
<code>vphy.Sphere</code>and <code>vphy.AABB</code> both derived from <code>vphy.Body</code>.
<code>x, y, z, resitution</code> are <code>vphy.Body</code> parameters, common to both.
So we wont review them again.</p>

<p>```javascript</p>

<pre><code>var body = new vphy.AABB({
    width : 1,
    height: 1,
    depth : 1
});
</code></pre>

<p>```</p>

<p><code>width</code>, <code>height</code> and <code>depth</code> gives the dimensions of the box.
After <code>world.step()</code>, you can read the new position of each body. Quite usefull
to push back the resulting physics in your 3D scene :)</p>

<p>```javascript</p>

<pre><code>var pos = body.getPosition();   // x = pos[0], y = pos[1], z = pos[2]
</code></pre>

<p>```</p>

<p>Ok, so we got a <code>world</code> with solid objects in it, all bound to <a href="http://en.wikipedia.org/wiki/Physical_law">physical law</a>.
Now what about moving them ?</p>

<h2>Let's move our Bodies</h2>

<p><img alt="" class="right " height="" src="http://learningthreejs.com/data/lets-make-a-3d-game-microphysics-js/images/aerobic-small.jpg" title="" width=""/></p>

<p>Lets make our sphere moves.
The bodies you added to the world will move according to the <a href="http://en.wikipedia.org/wiki/Force">forces</a> applied on them.
All that according to
<a href="http://en.wikipedia.org/wiki/Newton%27s_laws_of_motion">laws of motion</a>
from <a href="http://en.wikipedia.org/wiki/Isaac_Newton">Newton</a>.
He discovered that by receiving an <a href="http://en.wikipedia.org/wiki/Isaac_Newton#Apple_analogy">apple on the head</a>,
creativity can take strange paths sometime :)</p>

<p>Ok let's add <a href="http://en.wikipedia.org/wiki/Gravity_of_Earth">gravity</a>, the force which moved this falling apple.
This force is applied along a given direction to all our objects.
The library already contains an helper just for that. Simply do</p>

<p>```javascript</p>

<pre><code>world.add(new vphy.LinearAccelerator({
    x   :  0, 
    y   : -9.8,
    z   :  0
}));
</code></pre>

<p>```</p>

<p>Quite easy, no? Now lets see a custom accelerator, for example a player moving
according to the keyboard. The player will be a <code>vphy.Sphere</code> and we will
reuse the <a href="http://learningthreejs.com/data/THREEx/THREEx.KeyboardState.js">keyboard helper</a> we
did in this <a href="http://learningthreejs.com/blog/2011/09/12/lets-Make-a-3D-game-keyboard/">post</a>.</p>

<p>```javascript</p>

<pre><code>var player  = new vphy.Sphere({ radius : 20 });
world.add({
    type: vphy.types.ACCELERATOR,   // let the lib know it is an accelerator
    perform: function(bodies){      // bodies is the array of all vphy.Body
        if( keyboard.pressed('right') ) player.accelerate(1,0,0);
        if( keyboard.pressed('left') )  player.accelerate(-1,0,0);
        if( keyboard.pressed('up') )    player.accelerate(0,0,1);
        if( keyboard.pressed('down') )  player.accelerate(0,0,-1);
    }
});
</code></pre>

<p>```</p>

<p><code>.perform()</code> will be called at every world step.
It accesses <code>player</code> via
<a href="https://developer.mozilla.org/en/JavaScript/Guide/Closures">closure</a>
, read current keyboard state and accelerate in the proper direction.</p>

<h2>Motivation</h2>

<p>The need for 3D physics is clear for <a href="http://marblesoccer.com">marblesoccer</a>.
Marble in physics are fun, generic and instinctive for the player.
Ok so how to get a 3D physics engine ?</p>

<ul>
<li><strong>Do it yourself ? </strong>
Well no, it is hard, long and im lazy :)</li>
<li><strong>Use an existing one ? </strong>
i tried some and left unimpressed. All those are new experimental stuff.
Documentation is inexistant.
They are issued from existing libraries in other languages and convert them to js, sometime multiple conversions in a row.
I experienced major bugs when i tried. Were those bugs ? Was it me misusing it ?
Quite possible as the doc is inexistant.
All in all, i didnt feel it would be a reliable dependancy for our game.</li>
<li><strong>Used a 2D one, like Box2D ? </strong>
Box2D is kind of special.
<a href="http://blog.sethladd.com/">Seth Ladd</a> recently did
<a href="http://blog.sethladd.com/2011/09/box2d-collision-damage-for-javascript.html">a</a>
<a href="http://blog.sethladd.com/2011/09/box2d-impulse-and-javascript.html">lot</a>
<a href="http://blog.sethladd.com/2011/09/box2d-with-complex-and-concave-objects.html">of</a>
<a href="http://blog.sethladd.com/2011/09/box2d-and-polygons-for-javascript.html">good</a>
<a href="http://blog.sethladd.com/2011/09/box2d-web-workers-better-performance.html">things</a>
to explain box2D. Ok, box2D is a converted one but it is of very good quality.
So why not using box2D ?
Well because it is 2D and we do 3D.
Quite an insight, hey :)
It would be such a tough limitation.
This webgl + box2D strategy can produce excelent results tho, like this
<a href="http://game.2x.io/">game demo</a> from <a href="http://twitter.com/#!/einaros">@einaros</a>.
Take a close look at the physics when object move, it is amazingly
realistic and it is all box2D.</li>
<li><strong>Ask somebody else to do it ? </strong>
We got a <em>winner!</em> <a href="http://twitter.com/#!/pyalot">@pyalot</a> from <a href="http://codeflow.org/">codeflow.org</a></li>
</ul>


<h2>Credits</h2>

<p>All images are from <a href="http://en.wikipedia.org">wikipedia</a>. All hard work is from <a href="http://twitter.com/#!/pyalot">@pyalot</a></p>

<h2>Conclusion</h2>

<p>This is the first post about physics.
It presented microphysics.js API.
Thus you can start playing with it immediatly.
More posts will come shortly.
At least, one about performance and another one on how to easily bind microphysics to your three.js game.
That's all folks.
Have fun with microphysics.js :)</p></div>
    </summary>
    <content>This post is part of the "Lets make a 3D game" series. 3D and physics simulation always go well together even more so with marble games. One is required for marblesoccer but i wasnt convinced by current 3d physics engines. I explain why at the end. Fortunatly, @pyalot from codeflow.org has been kind enough to write one taylor-made for us: microphysics.js!! It is bite-sized, elegant and efficient. Less than 500 lines at the moment!! It is small engouh to be understood, important feature for a tutorial blog. It is a work in progress tho. We aren't aware of any bugs. New features will be added and the API is expected to move. Currently it implements moving spheres and static boxes (or AABB as we like to say). This is all we need for marblesoccer, the good thing about tailor-made. We are in business!!! Below is a screencast of me doing a short introduction of the playground. This just a page for you to experiment with microphysics.js. Let's get started So lets see how to use it. First step, you download it here. Then include it in your own code with this line. ```html &lt;script src="physics.js"&gt;&lt;/script&gt; ``` Let's Create a World Quite a title hey ? Dont you feel like galactus when you say it ? First you instanciate the physics world like this. ```javascript var world = new vphy.World() ``` Now you start it. Dont forget to give it the date as you see it. ```javascript world.start(Date.now()/1000); ``` The world is now fully initialized. You just have to periodically update it in your game/render loop. ```javascript var timeStep = 1/180; world.step(timeStep, Date.now()/1000); ``` The timeStep parameter is the precision of the physics engine, expressed in seconds. Quite a subtle tradeoff. The smaller it is, the more accurate is the physics, but the slower it is to compute. Up to you to find the balance that fit your needs. Let's Add Bodies Don't worry, this is not about killing people and dispose of their dead bodies :) In physics, A body is a solid object that you put in your world. microphysics bodies can be spheres or static boxes. Lets start right away by creating a sphere. ```javascript var sphere = new vphy.Sphere({ x : 10, y : 10, z : 10, restitution : 0.6, radius : 5, }); ``` This will position it at (10,10,10) in the world. restitution will determine how bouncy is this during a collision. A bouncing ball restitutes a lot. A falling eggs restitutes less :) This declaration seems quite verbose at first. Don't worry those parameters got sensible defaults, no need to specify them all. Now lets add it to our world ```javascript world.add(sphere); ``` If you need to remove it, just do world.remove(sphere). Not too hard hey ? Now lets create a static box. Boxes are called AABB. It stands for Axis-aligned bounding box. It is graphic jarguon for the smallest box containing your object. vphy.Sphereand vphy.AABB both derived from vphy.Body. x, y, z, resitution are vphy.Body parameters, common to both. So we wont review them again. ```javascript var body = new vphy.AABB({ width : 1, height: 1, depth : 1 }); ``` width, height and depth gives the dimensions of the box. After world.step(), you can read the new position of each body. Quite usefull to push back the resulting physics in your 3D scene :) ```javascript var pos = body.getPosition(); // x = pos[0], y = pos[1], z = pos[2] ``` Ok, so we got a world with solid objects in it, all bound to physical law. Now what about moving them ? Let's move our Bodies Lets make our sphere moves. The bodies you added to the world will move according to the forces applied on them. All that according to laws of motion from Newton. He discovered that by receiving an apple on the head, creativity can take strange paths sometime :) Ok let's add gravity, the force which moved this falling apple. This force is applied along a given direction to all our objects. The library already contains an helper just for that. Simply do ```javascript world.add(new vphy.LinearAccelerator({ x : 0, y : -9.8, z :</content>
    <updated>2011-10-17T10:36:00Z</updated>
    <source>
      <id>http://learningthreejs.com/</id>
      <author>
        <name>Jerome Etienne</name>
        <email>noemail@noemail.org</email>
      </author>
      <link href="http://learningthreejs.com/" rel="alternate" type="text/html"/>
      <link href="http://feeds.feedburner.com/LearningThreejs" rel="self" type="application/rss+xml"/>
      <link href="http://pubsubhubbub.appspot.com/" rel="hub" type="text/html"/>
      <title>Learning Three.js</title>
      <updated>2012-01-27T14:00:12Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://learningwebgl.com/blog/?p=4170</id>
    <link href="http://learningwebgl.com/blog/?p=4170" rel="alternate" type="text/html"/>
    <title>WebGL around the net, 13 October 2011</title>
    <summary>From Charles J Cliffe, some new CubicVR stuff: a collection of cool examples and demos and a WebGL PDF viewer using David Humphrey’s PDF texture generation CubicVR module (drag the pages around to turn/pan them, mouse wheel to zoom). Every effect under the sun in another corking demo from AlteredQualia. The new WebGL-based Google Maps [...]</summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><ul>
<li>From Charles J Cliffe, some new <a href="http://www.cubicvr.org/">CubicVR</a> stuff: a collection of cool <a href="https://github.com/cjcliffe/CubicVR.js/wiki/Examples-and-Demos">examples and demos</a> and a <a href="http://cjcliffe.github.com/CubicVR.js/cubicvr/samples/pdf/pdf_gallery.html">WebGL PDF viewer</a> using <a href="http://vocamus.net/dave/?p=1328">David Humphrey’s PDF texture generation CubicVR module</a> (drag the pages around to turn/pan them, mouse wheel to zoom).
</li><li>Every effect under the sun in <a href="http://alteredqualia.com/three/examples/webgl_cars.html">another corking demo from AlteredQualia</a>.</li>
<li>The new WebGL-based Google Maps interface is pretty nice!  Here are some <a href="http://googlesystem.blogspot.com/2011/10/google-maps-in-webgl.html">instructions on how to get it working</a>.
</li><li><a href="http://www.storminthecastle.com/2011/10/09/webgl-sand-toy/">Fun drawing in sand</a> — by John Robinson.
</li><li><a href="http://egraether.com/mine3d/">Minesweeper in 3D</a> — Eelis van der Weegen has found a fine new way to destroy productivity worldwide ;-)
</li><li>Brandon Jones has written code to render a new game engine’s files in <a href="http://blog.tojicode.com/2011/10/source-engine-levels-in-webgl-video.html">WebGL: Source</a>.
</li><li>From Jagadish: <a href="http://jarav.posterous.com/75040897">visualizing electrostatic potentials using webgl, web workers and Coffeescript</a>.
</li><li>If you didn’t get a chance to come to the London WebGL meetup and see Mr. doob talk about the making of RO.ME, <a href="http://www.youtube.com/watch?v=D8mOtkuN864">here’s a video of a talk he did more recently</a>.
<ul/></li></ul></div>
    </content>
    <updated>2011-10-13T13:45:30Z</updated>
    <category term="Links"/>
    <category term="Roundups"/>
    <author>
      <name>giles</name>
    </author>
    <source>
      <id>http://learningwebgl.com/blog</id>
      <link href="http://learningwebgl.com/blog/?feed=rss2" rel="self" type="application/atom+xml"/>
      <link href="http://learningwebgl.com/blog" rel="alternate" type="text/html"/>
      <subtitle>...lessons 'n' links...</subtitle>
      <title>Learning WebGL</title>
      <updated>2011-12-03T14:40:03Z</updated>
    </source>
  </entry>
</feed>

