Skybox Problems

Software: Away3D 4.x

FJW, Newbie
Posted: 30 November 2012 06:12 PM   Total Posts: 20

Hi Guys an Gals, Have got this away3d 4 example but cannot get it to work.
Gives Error: Invalid bitmapData: Width and height must be power of 2 and cannot exceed 2048
at away3d.textures::BitmapCubeTexture/testSize()
at away3d.textures::BitmapCubeTexture()
at Panorama()

Can anyone help please? The jpg files are all 600x600px and 24kb max.
Have it working in v3.6 but in 4 seems to be broken.
///example
package
{
import away3d.cameras.lenses.*;
import away3d.containers.*;
import away3d.entities.*;
import away3d.materials.*;
import away3d.materials.methods.*;
import away3d.primitives.*;
import away3d.textures.*;
import away3d.utils.*;

import flash.display.*;
import flash.events.*;
import flash.geom.Vector3D;

[SWF(backgroundColor=”#000000”, frameRate=“60”, quality=“LOW”)]

public class Panorama extends Sprite
{
  // Environment map.
  [Embed(source=“skyfront.jpg”)]
  private var EnvPosX:Class;
  [Embed(source=“skyleft.jpg”)]
  private var EnvPosY:Class;
  [Embed(source=“skyback.jpg”)]
  private var EnvPosZ:Class;
  [Embed(source=“skyright.jpg”)]
  private var EnvNegX:Class;
  [Embed(source=“skyup.jpg”)]
  private var EnvNegY:Class;
  [Embed(source=“skydown.jpg”)]
  private var EnvNegZ:Class;
 
  //engine variables
  private var view:View3D;
 
  //scene objects
  private var skyBox:SkyBox;
  private var torus:Mesh;
 
  /**
  * Constructor
  */
  public function Panorama()
  {
  stage.scaleMode = StageScaleMode.NO_SCALE;
  stage.align = StageAlign.TOP_LEFT;
 
  //setup the view
  view = new View3D();
  addChild(view);
 
  //setup the camera
  view.camera.z = -600;
  view.camera.y = 0;
  view.camera.lookAt(new Vector3D());
  view.camera.lens = new PerspectiveLens(90);
 
  //setup the cube texture
  var cubeTexture:BitmapCubeTexture = new BitmapCubeTexture(Cast.bitmapData(EnvPosX), Cast.bitmapData(EnvNegX), Cast.bitmapData(EnvPosY), Cast.bitmapData(EnvNegY), Cast.bitmapData(EnvPosZ), Cast.bitmapData(EnvNegZ));
 
  //setup the environment map material
  var material:ColorMaterial = new ColorMaterial(0xFFFFFF, 1);
  material.specular = 0.5;
  material.ambient = 0.25;
  material.ambientColor = 0x111199;
  material.ambient = 1;
  material.addMethod(new EnvMapMethod(cubeTexture, 1));
 
  //setup the scene
  torus = new Mesh(new TorusGeometry(150, 60, 40, 20), material);
  view.scene.addChild(torus);
 
  skyBox = new SkyBox(cubeTexture);
  view.scene.addChild(skyBox);
 
  //setup the render loop
  addEventListener(Event.ENTER_FRAME, _onEnterFrame);
  stage.addEventListener(Event.RESIZE, onResize);
  onResize();
  }
 
  /**
  * render loop
  */
  private function _onEnterFrame(e:Event):void
  {
  torus.rotationX += 2;
  torus.rotationY += 1;
 
  view.camera.position = new Vector3D();
  view.camera.rotationY += 0.5*(stage.mouseX-stage.stageWidth/2)/800;
  view.camera.moveBackward(600);
 
  view.render();
  }
 
  /**
  * stage listener for resize events
  */
  private function onResize(event:Event = null):void
  {
  view.width = stage.stageWidth;
  view.height = stage.stageHeight;
  }
}
}

   

Avatar
80prozent, Sr. Member
Posted: 30 November 2012 06:23 PM   Total Posts: 430   [ # 1 ]

hi

this is because in away3d 3.6 your bitmap could have any size, while in away3d 4 you have to stick to the “power of two” sizes. This is because stage3d uploads all bitmaps to the gpu, and the gpu can only work with this spezial “power of two” sizes.

power of two:

16 x 16
32 x 32
64 x 64
128 x 128
256 X 256
512 X 512
1024 x 1024
2048 x 2048

i think the bitmaps do not need to be quadratic, e.g. you can use something like 32 x 256, but since all my bitmaps this far have been quadratic, i cannot tell you for shure.

hope that helps

 Signature 

sorry…i hope my actionscript is better than my english…

   

FJW, Newbie
Posted: 30 November 2012 06:31 PM   Total Posts: 20   [ # 2 ]

Hi, thanks for the reply. I shall resize from 600 to 1024x1024 and try it out.
F

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X