Flat bitmap background

Software: Away3D 4.x

Embalmer, Newbie
Posted: 02 January 2013 10:19 AM   Total Posts: 6

Hello everyone,

I begin with Away 3D 4.1 alpha for a flex project but I’m already stucked .
I need to draw 3d shapes over a simple bitmap (wich is a HD render of a building but it doesn’t really matter). This bitmap needs to be flat and fit to the camera size regardless the camera angle and position.
I first thought that I could render my view over a bitmap (a mx:Image component) but it seems that the view must have a visible background so I followed that tutorial : http://jansensan.net/how-to-fully-fit-away3d-plane-in-viewport which I try to adapt to Away 3D 4.1 but I failed, I can see the plane with its texture but the rotation isn’t good.

I created a simple class to include my background :

package
{
 import flash
.display.Bitmap;
 
 
import away3d.containers.View3D;
 
import away3d.entities.Mesh;
 
import away3d.materials.TextureMaterial;
 
import away3d.primitives.PlaneGeometry;
 
import away3d.textures.BitmapTexture;
 
 
import net.jansensan.utils.degreesToRadians;

 public class 
FacingPlane
 {
  
private var _view3D:View3D;
  private var 
_plane:Mesh;
  private var 
_material:TextureMaterial;
  
  public function 
FacingPlane(view:View3DpWidth:NumberpHeight:Numberbitmap:Bitmap)
  
{
   _view3D 
view;
   
   var 
texture:BitmapTexture = new BitmapTexture(bitmap.bitmapData);
   
_material = new TextureMaterial(texture);
   
_material.mipmap = (pWidth == pHeight);
   
   
// camera values
   // see away3d.camerasCamera3D's default lens' field of view 
   // in away3d.cameras.lenses.PerspectiveLens
   // it turns out that the field of view is vertical
   
var angleY:Number 60;
   var 
cameraZ:int _view3D.camera.z;
   
   
// this position is arbitrary as we will see further
   // useful to calculate the distance between the camera and the plane
   
var planeZ:int 500;
   var 
distFromCamToPlane:Number Math.abs(cameraZ) + planeZ;
   
   
// since the field of view is a vertical angle, calculate the height of the plane first
   // use pythagorean theorem to calculate
   // tip for trigonometry: soh-cah-toa
   // toa: tan(angle) = oppositeSide / adjacentSide
   
var planeHeight:int Math.tan(degreesToRadians(angleY 0.5)) * distFromCamToPlane;
   
// and since it was for a rectangle triangle, thus half the size, double the length
   
planeHeight *= 2;
   
   
// useful for resizing the image
   
var aspectRatio:Number pWidth pHeight;
   
   
// use the aspect ratio to calulcate the width of the plane
   
var planeWidth:int planeHeight aspectRatio;
   var 
geo:PlaneGeometry = new PlaneGeometry(planeWidthplaneHeight);
   
geo.yUp false;
   
   
// create the plane
   
_plane = new Mesh(geo_material);
   
_plane.planeZ;
   
   
// add 3D objects to the scene
   
_view3D.scene.addChild(_plane);
   
   
// add the away3d view to the display list
   //addChild(_view3D);
  
}
 }


If someone could explain me my mistake(s), or explain me a better way to proceed.


Thanks.

   

_kihu, Jr. Member
Posted: 04 January 2013 01:00 PM   Total Posts: 43   [ # 1 ]

Take a look at this:
http://away3d.com/tutorials/Away3D_and_Starling_Interoperation

Perhaps View3D.backgroud property could also do the trick, but I think making the background in Starling is the best idea here.

   

Embalmer, Newbie
Posted: 04 January 2013 01:20 PM   Total Posts: 6   [ # 2 ]

Hello _kihu,
You’re right using Starling seems to be much easier, even if it’s also a heavy solution for a simple background smile.

Thx

   
   
‹‹ UV splice on sphere.

X

Away3D Forum

Member Login

Username

Password

Remember_me



X