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!