quick correction... my material had to be flipped horizontal also to
line up right....
private function doneSlicingImage(evt:Event):void
{
trace("Done Slicing Image");
_sliceBitmap.removeEventListener("doneSlicingImage",
doneSlicingImage);
//copy sliced bitmap to local arrays
_cubeFrontMat = _sliceBitmap._bitmapGrid.concat();
_cubeBackMatTemp = _sliceBitmap._bitmapGrid.concat();
//flip bitmaps in _cubeBackMatTemp and populate into
_cubeBackMat
for (var i:int=0 ; i<numCubes ; ++i)
{
var myBitmap:BitmapData = new BitmapData(160,
160);
myBitmap.draw(_cubeBackMatTemp[i]);
//flip vertical matrix
var flipVerticalMatrix:Matrix = new Matrix()
flipVerticalMatrix.scale(-1,-1)
flipVerticalMatrix.translate(myBitmap.width,myBitmap.height)
var flippedBitmap:BitmapData = new
BitmapData(myBitmap.width,myBitmap.height,false,0xFFCC00)
flippedBitmap.draw(myBitmap,flipVerticalMatrix)
_cubeBackMat.push(flippedBitmap);
}
initMaterials();
}
On Nov 20, 10:14 pm, NickBee <[email protected]> wrote:
> GOT IT!!!!
>
> private function doneSlicingImage(evt:Event):void
> {
> trace("Done Slicing Image");
> _sliceBitmap.removeEventListener("doneSlicingImage",
> doneSlicingImage);
> //copy sliced bitmap to local arrays
> _cubeFrontMat = _sliceBitmap._bitmapGrid.concat();
> _cubeBackMatTemp = _sliceBitmap._bitmapGrid.concat();
> //flip bitmaps in _cubeBackMatTemp and populate into
> _cubeBackMat
> for (var i:int=0 ; i<numCubes ; ++i)
> {
> var myBitmap:BitmapData = new BitmapData(160,
> 160);
> myBitmap.draw(_cubeBackMatTemp[i]);
> //flip vertical matrix
> var flipVerticalMatrix:Matrix = new Matrix()
> flipVerticalMatrix.scale(1,-1)
>
> flipVerticalMatrix.translate(0,myBitmap.height)
>
> var flippedBitmap:BitmapData = new
> BitmapData(myBitmap.width,myBitmap.height,false,0xFFCC00)
>
> flippedBitmap.draw(myBitmap,flipVerticalMatrix)
> _cubeBackMat.push(flippedBitmap);
> }
>
> initMaterials();
> }
>
> On Nov 20, 9:47 pm, NickBee <[email protected]> wrote:
>
> > Some insight on this would be great.
>
> > The best case scenario would be some kind of loop that would
> > vertically flip all the items in my _cubeBackMat array.
>
> > THANKS!!!!
>
> > On Nov 20, 7:41 pm, Darcey Lloyd <[email protected]> wrote:
>
> > > planes have back = material
>
> > > back.material = xxxxx
>
> > > With cube just specify the bitmap that is y-
>
> > > to save making 2 x textures / jpgs etc//// do some bitmap work (standard
> > > as3) to do this for u.
>
> > > If you need example of this.. let me know and i will create article for
> > > you...
>
> > > D
>
> > > On 20 November 2010 21:16, NickBee <[email protected]> wrote:
>
> > > > Is there an easy way to do this?
>
> > > > Check out this quick prototype:
>
> > > >http://www.nickbee.com/away3d/
>
> > > > I would like the material on the back of the cube to be flipped
> > > > vertically so that it views properly.
>
> > > > Below is the code I'm using. I have an external class to load and
> > > > slice up my image. I'm using the resulting array for my front and
> > > > back materials. I figure I either have to flip the bitmap data in the
> > > > array or how the material is viewed on on the cube. Some direction
> > > > either way would be great!!!!
>
> > > > package
> > > > {
> > > > import away3d.cameras.*;
> > > > import away3d.containers.*;
> > > > import away3d.materials.*;
> > > > import away3d.primitives.*;
> > > > import away3d.primitives.data.*;
> > > > import away3d.core.utils.*;
> > > > import away3d.core.clip.*;
>
> > > > import flash.display.*;
> > > > import flash.events.*;
>
> > > > import com.SliceBitmap;
>
> > > > public class away3D16 extends Sprite
> > > > {
> > > > //engine variables
> > > > private var scene:Scene3D;
> > > > private var camera:Camera3D;
> > > > private var view:View3D;
>
> > > > //cube vars
> > > > private var _cubePosX:Array = new Array(-160, -160,
> > > > -160, 0,
> > > > 0, 0,
> > > > 160, 160, 160);
> > > > private var _cubePosY:Array = new Array(160, 0, -160,
> > > > 160,
> > > > 0, -160,
> > > > 160, 0, -160);
> > > > private var _cubeFrontMat:Array = new Array();
> > > > private var _cubeBackMat:Array = new Array();
> > > > private var _cubeMatData:Array = new Array();
> > > > private var _cubes:Array = new Array();
>
> > > > //general vars
> > > > var _sliceBitmap:SliceBitmap;
> > > > var numCubes:uint = 9;
>
> > > > /**
> > > > * Constructor
> > > > */
> > > > public function away3D16()
> > > > {
> > > > init();
> > > > }
>
> > > > private function init():void
> > > > {
> > > > initEngine();
> > > > sliceImage();
> > > > }
>
> > > > private function initEngine():void
> > > > {
> > > > scene = new Scene3D();
>
> > > > //camera = new Camera3D({z:-1000});
> > > > camera = new Camera3D();
> > > > camera.z = -910;
>
> > > > //view = new View3D({scene:scene,
> > > > camera:camera});
> > > > view = new View3D();
> > > > view.x = 240;
> > > > view.y = 240;
> > > > view.scene = scene;
> > > > view.camera = camera;
>
> > > > //add view to stage
> > > > addChild(view);
> > > > }
>
> > > > /**
> > > > * Silce Image
> > > > */
> > > > private function sliceImage():void
> > > > {
> > > > _sliceBitmap = new
> > > > SliceBitmap("images/dart.jpg", 3,
> > > > 3)
> > > > _sliceBitmap.addEventListener("doneSlicingImage",
> > > > doneSlicingImage);
> > > > }
>
> > > > /**
> > > > * Done Silcing Image
> > > > */
> > > > private function doneSlicingImage(evt:Event):void
> > > > {
> > > > trace("Done Slicing Image");
> > > >
> > > > _sliceBitmap.removeEventListener("doneSlicingImage",
> > > > doneSlicingImage);
> > > > //copy sliced bitmap to local arrays
> > > > _cubeFrontMat =
> > > > _sliceBitmap._bitmapGrid.concat();
> > > > _cubeBackMat = _sliceBitmap._bitmapGrid.concat();
>
> > > > initMaterials();
> > > > }
>
> > > > /**
> > > > * Initialise the materials
> > > > */
> > > > private function initMaterials():void
> > > > {
> > > > for (var i:int=0 ; i<numCubes ; ++i)
> > > > {
> > > > var sideMat:ColorMaterial = new
> > > > ColorMaterial(0x333333);
> > > > var frontMat:BitmapMaterial = new
> > > > BitmapMaterial(Cast.bitmap(_cubeFrontMat[i]));
> > > > var backMat:BitmapMaterial = new
> > > > BitmapMaterial(Cast.bitmap(_cubeBackMat[i]));
>
> > > > var CubeMat:CubeMaterialsData = new
> > > > CubeMaterialsData();
> > > > CubeMat.front = frontMat;
> > > > CubeMat.back = backMat;
> > > > CubeMat.bottom = sideMat;
> > > > CubeMat.top = sideMat;
> > > > CubeMat.left = sideMat;
> > > > CubeMat.right = sideMat;
>
> > > > _cubeMatData.push(CubeMat);
> > > > }
>
> > > > initObjects();
> > > > }
>
> > > > /**
> > > > * Initialise the scene objects
> > > > */
> > > > private function initObjects():void
> > > > {
> > > > for (var i:int=0 ; i<numCubes ; ++i)
> > > > {
> > > > var cube:Cube = new Cube()
> > > > cube.cubeMaterials = _cubeMatData[i];
> > > > cube.x = _cubePosX[i];
> > > > cube.y = _cubePosY[i];
> > > > cube.width = 160;
> > > > cube.height = 160;
> > > > cube.depth = 20;
> > > > cube.segmentsW = 5;
> > > > cube.segmentsH = 5;
> > > > cube.segmentsD = 5;
> > > > _cubes.push(cube);
> > > > scene.addChild(cube);
> > > > }
>
> > > > initListeners();
> > > > }
>
> > > > /**
> > > > * Initialise the listeners
> > > > */
> > > > private function initListeners():void
> > > > {
> > > > addEventListener(Event.ENTER_FRAME,
> > > > onEnterFrame);
> > > > }
>
> > > > /**
> > > > * Navigation and render loop
> > > > */
> > > > private function
>
> ...
>
> read more »