Archive for the ‘ Three.js ’ Category

Fish GL Released

Fish GL Tank

Fish GL Tank

Well for the past 2 months I’ve been tucked away working on my first official WebGL project – FishGL (www.fishGL.com, www.fishgl/mobile for mobile)!  The Internet Explorer team wanted to create a graphics showcase with the classic “fish bowl” theme and enlisted ThinkPixelLab.com to create the experience along with Scott Wetterschneider as the 3D artist.

The Fish Tank has many interactive features and elements that bring and rich experience to not only the desktop, but to touch devices as well.  In fact, you’ll have the most fun with the Fish Tank if you’re on a touch device since it has features that allow you to pan and zoom around the room, tap the glass, feed the fish and even SWIM with the fish!  There’s also a couple of nice easter-eggs for those of you who like to explore.

Some features include:

  • Swim in tank (click diver mask on panel)
  • Add fish to the tank with the fish dial
  • Set algae level with “last cleaned” slider
  • Tap the glass to scatter fish
  • Feed the fish by tapping the food jar
  • Turn the lights on and off with the light switch on the wall
  • Advanced panel gives you a TON of options for customizing the scene (hit the second dot at the top of the panel to switch to the advanced panel)
  • Real-time lighting from the sun and tank light as well as shadows (turn shadows on via the advanced panel)
  • Change clean/dirty water tint for in-tank swimming experience.  To see the change, change the amount of algae in the water while simming
  • Change color of light in the tank as well as its intensity, distance
  • Change the tank glass to your liking
  • Work with the realism of the gravel in the tank
  • … and so much more!

You can create a tank that matches your mood, room, computer, phone or whatever you like:

If you had told me 6 months ago that I would be working on a WebGL project, I would have laughed you of my office waving my Unity3D banner!  But God has been good and blessed me with some awesome people to work with at ThinkPixelLab.com – namely, Robby Ingebretsen and Joe Fillmore.  Super cool people, extremely talented in what they do and very patient!

If you’re interested in creating 3D WebGL content, I’d encourage you to look at the Three.js library – the api’s nomenclature and approach is right inline with other technologies like Unity3D, so getting up and running is very easy.

 

Creating Cube map / Environment map in Three.js with preloaded assets

[tweetmeme source=”neoRiley” only_single=false] All the Three.js samples I found were all using the same technique of just passing the image URL’s in an array to  ImageUtils.loadTextureCube() , and used whatever it returned as the necessary texture for a environment, reflection or refraction map.  Well, I’d written an AssetManager to preload all necessary assets for creating our scene, and when it came time to assemble the reflection map, I had to dig through the source code to see what ImageUtils.loadTextureCube() was actually producing and how.

In my scenario, I have a class that is called CubeMap and after passing it the image URL’s, it takes care of preparing what is to be preloaded with the AssetManager.  When the AssetManager has completed the preload, I then have access to CubeMap.texturesArray, which is an array of the preloaded images, and I can then put together the environment map texture I need:

// create a new THREE.Texture
var envMap = new THREE.Texture();

// After preloading your images, set the image property of your new texture to the array of images you preloaded
envMap.image = this.tankReflectionBox.texturesArray; // array of images = [];

// Set the mapping type
envMap.mapping = new THREE.CubeReflectionMapping();

// You have to set this to false, otherwise your images will be inverted on the Y axis
envMap.flipY = false;

// Mark as dirty, otherwise you won't see anything
envMap.needsUpdate = true;

Have a bandit day!

Error with Three.js shader – ERROR :GL_INVALID_OPERATION – fix

[tweetmeme source=”neoRiley” only_single=false] I was just in the process of trying to narrow down what does and doesn’t work in IE11 with Three.js’ shaders and ran into this error message while working with the normalmap shader:

ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1

The fix is to simply call computeTangents() on your mesh’s geometry object, and bingo, we’re in business:

model.geometry.computeTangents();

Here’s the block for context:

var shader = THREE.ShaderLib[ "normalmap" ];</pre>
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );

uniforms[ "enableAO" ].value = false;
uniforms[ "enableDiffuse" ].value = true;
uniforms[ "enableSpecular" ].value = true;

uniforms[ "tDiffuse" ].value = fdo.colorMap;
uniforms[ "tNormal" ].value = fdo.normalMap;
uniforms[ "tSpecular" ].value = fdo.specularMap;

uniforms[ "diffuse" ].value.setHex( 0xFFFFFF );
uniforms[ "specular" ].value.setHex( 0xFFFFFF );
uniforms[ "ambient" ].value.setHex( 0x222222 );

uniforms[ "shininess" ].value = 10;
parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true };
mat = new THREE.ShaderMaterial( parameters );

model.geometry.computeTangents();
model.material = mat;