Hey Guys,
I’m a pretty seasoned AS3 dev and I was looking to create bitmaps from textfields and apply them to different sides of a cube primitive. However, when I’m running into trouble when it comes to using the CubeMaterialsData object to assign different BitMapMaterial to each side.
The front side comes out as expected, however the bottom and top sides appear to have different orientations. I’ve searched the forum, tried implementing a matrix transform and a few other things and have not found a solution.
Anyone got any ideas?
package
{
import away3d.containers.View3D;
import away3d.materials.BitmapMaterial;
import away3d.primitives.Cube;
import away3d.primitives.data.CubeMaterialsData;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class CubeEx3 extends Sprite
{
public var bg:Sprite = new Sprite;
public var view:View3D;
public var cube:Cube;
public var firstSideData:BitmapData;
public var firstSideText:TextField = new TextField;
public var firstSideTextFormat:TextFormat = new TextFormat;
public var secondSideData:BitmapData;
public var secondSideText:TextField = new TextField;
public var secondSideTextFormat:TextFormat = new TextFormat;
public var thirdSideData:BitmapData;
public var thirdSideText:TextField = new TextField;
public var thirdSideTextFormat:TextFormat = new TextFormat;
public var w:int = 300;
public var h:int = 100;
public function CubeEx3()
{
bg.graphics.beginFill(0xf2f2f2,1);
bg.graphics.drawRect(0,0,500,200);
bg.graphics.endFill();
addChild(bg);
drawSideOne();
drawSideTwo();
drawSideThree();
init3D();
this.addEventListener(Event.ENTER_FRAME,loop);
}
private function init3D():void
{
view = new View3D({x:250,y:150});
addChild(view);
cube = new Cube({width:w,height:h,depth:h,bothsides:true});
var cData:CubeMaterialsData = new CubeMaterialsData;
cData.front = new BitmapMaterial(firstSideData);
cData.bottom = new BitmapMaterial(secondSideData);
cData.top = new BitmapMaterial(thirdSideData);
cube.cubeMaterials = cData;
view.scene.addChild(cube);
view.render();
}
private function drawSideOne():void
{
firstSideTextFormat.font = "Myriad Pro";
firstSideTextFormat.color = 0xF2F2F2;
firstSideText.text = "First Side";
firstSideText.setTextFormat(firstSideTextFormat);
firstSideText.autoSize = TextFieldAutoSize.CENTER;
var cubeMatrix:Matrix = new Matrix;
firstSideData = new BitmapData(w,h,false,0x00000000);
firstSideData.draw(firstSideText,cubeMatrix);
}
public function drawSideTwo():void{
secondSideTextFormat.font = "Myriad Pro";
secondSideTextFormat.color = 0xF2F2F2;
secondSideText.text = "Second Side";
secondSideText.setTextFormat(secondSideTextFormat);
secondSideText.autoSize = TextFieldAutoSize.CENTER;
var cubeMatrix2:Matrix = new Matrix;
cubeMatrix2
secondSideData = new BitmapData(h,w,false,0x00000000);
secondSideData.draw(secondSideText,cubeMatrix2,null,null,null,true);
}
private function drawSideThree():void
{
thirdSideTextFormat.font = "Myriad Pro";
thirdSideTextFormat.color = 0xF2F2F2;
thirdSideText.text = "Third Side";
thirdSideText.setTextFormat(thirdSideTextFormat);
thirdSideText.autoSize = TextFieldAutoSize.CENTER;
thirdSideData = new BitmapData(h,w,false,0x00000000);
thirdSideData.draw(thirdSideText);
}
public function loop(e:Event):void{
cube.rotationX += -5;
view.render();
}
}
}