Hey Everyone,
I needed to change the diffuse texture of a SkyBox. Unfortunatly, as some of you would know, setting the material of a skybox or creating new skybox instances throws ‘unsupported’ errors.
I *sniffed* around in the Skybox codes and created a workaround so you can actually change the CubeTexture of your skybox at will, and I thought: why not share it?
Maybe it’s not the best solution, but it’s a working solution.
added 2 new functions in SkyBox.as
public function get materialTexture():CubeTextureBase
{
return _material.cubeMap;
}
public function set materialTexture(value:CubeTextureBase):void
{
_material.cubeMap = value;
}
example usage:
//embed all the textures, here only 1 for example purpouses.
[Embed(source="/images/skybox/posxold.jpg")]
private var EnvPosX : Class; //right
//in class skyboxes vars
private var isitday:int = 1;
private var cubeTexture:BitmapCubeTexture = new BitmapCubeTexture(Cast.bitmapData(EnvPosX), Cast.bitmapData(EnvNegX), Cast.bitmapData(EnvPosY), Cast.bitmapData(EnvNegY), Cast.bitmapData(EnvPosZ), Cast.bitmapData(EnvNegZ));
private var cubeTexturenight:BitmapCubeTexture = new BitmapCubeTexture(Cast.bitmapData(EnvPosXNight), Cast.bitmapData(EnvNegXNight), Cast.bitmapData(EnvPosYNight), Cast.bitmapData(EnvNegYNight), Cast.bitmapData(EnvPosZNight), Cast.bitmapData(EnvNegZNight));
//function
private function changeSkyBox(day:int = 1,init:int = 0):void
{
if(init == 1){
if(day == 1){
_skyBox = new SkyBox(cubeTexture);
}else{
_skyBox = new SkyBox(cubeTexturenight);
}
_view.scene.addChild(_skyBox);
}
if(day == 1){
_skyBox.materialTexture = cubeTexture;
isitday = 1;
}else
if(day == 0){
_skyBox.materialTexture = cubeTexturenight;
isitday = 0;
}
}
initialize the skybox with changeSkyBox(0,1);
then create 2 buttons which calls changeSkyBox(1,0); and changeSkyBox(0,0);
Have fun with multiple skyboxes!
-Q