Dynamically load an image into a movieClip and update texture

Software: Away3D 4.x

Mr Margaret Scratcher, Sr. Member
Posted: 12 September 2011 03:50 AM   Total Posts: 344

Scratching my head over this one…

I need to dynamically load an image, and I’m adding that as a child to a movieClip which is the texture for a BitmapMaterial.

var fLQmc:MovieClip = new MovieClip;
   var 
frontCoverloader:Loader = new Loader()
   var 
frontCoverRequest:URLRequest = new URLRequest("http://videoemporium.co.uk/movie_title_covers/covers/LQ/fLQ/4700/4759fLQ.jpg");
   
frontCoverloader.load(frontCoverRequest)
   
frontCoverloader.contentLoaderInfo.addEventListener(Event.COMPLETEloadFront);
   
    function 
loadFront(e:Event):void 
    {
    
//trace ("front Cover Loaded")
    //addChild (frontCoverloader)
    //var mat:Matrix = new Matrix (256 / frontCoverloader.height, 0, 0, 256 / frontCoverloader.height, 0, 0);
    //fLQmc.BitmapData = new BitmapData(256, 256)
    //fLQmc.BitmapData.draw (mat,frontCoverloader)
    
fLQmc.addChild(frontCoverloader);
    
addChild(fLQmc);
    
materials.updateTexture;
    
    

and then later:

var materialsBitmapMaterial = new BitmapMaterial (fLQmc.bitmapData)
   
    
   
// Create a cube with DVD dimensions
   
   
var p:Cube = new CubematerialsDVDwDVDhDVDd); 


but the cubes are all showing up white?

   

Avatar
theMightyAtom, Sr. Member
Posted: 12 September 2011 06:01 AM   Total Posts: 669   [ # 1 ]

Hopefully you should be getting an error, as a MovieClip doesn’t have a bitmapData, only a Bitmap does.
You need to create a BitmapData, use the draw command to get a graphical representation of the movieClip, then use the bitmapData for your material.

var bmd:BitmapData = new flash.display.BitmapData(flQmc.widthflQmc.heightfalse0x00);
bmd.draw(flQmc);
var 
materialsBitmapMaterial = new BitmapMaterial (bmd); 

Good Luck!

   

Mr Margaret Scratcher, Sr. Member
Posted: 12 September 2011 01:47 PM   Total Posts: 344   [ # 2 ]

Aha, yep that seems to be working now… Kind of… I now need to get that matrix resize working..

Wasn’t giving me an error, just a white texture..
Now, oddly, it seems like the texture is offset? Up on the top left is the moveclip added to the stage, and on the lower right DVD case you can see how that translates to the texture…

http://www.margaretscratcher.co.uk/virtemp/offsettexture.jpg

   

Avatar
theMightyAtom, Sr. Member
Posted: 12 September 2011 01:59 PM   Total Posts: 669   [ # 3 ]

Use a CubeMap, otherwise Away3D will spread the bitmap over all sides, instead of full map on each side.

   

Mr Margaret Scratcher, Sr. Member
Posted: 12 September 2011 02:08 PM   Total Posts: 344   [ # 4 ]

Yeah, I was thinking that, and add the bitmap data at the relevant place?

3 x 2 grid correct?

   

Avatar
theMightyAtom, Sr. Member
Posted: 12 September 2011 04:00 PM   Total Posts: 669   [ # 5 ]

To be honest, last time I looked I couldn’t quite work out how it was mapping to a simple Box, but it wasn’t a 3x2 as I’d guessed.
My advice, use the cubeMap. Then you can add different graphics to sides/back etc. If you want the same on all sides, just use then same BitmapData for each part of the CubeMap.

   

Mr Margaret Scratcher, Sr. Member
Posted: 12 September 2011 04:20 PM   Total Posts: 344   [ # 6 ]

Yeah, I couldn’t figure it out either, I’ve been waiting for someone to make it all nice and easy for me in that respect, and with the power of 2 texture dimensions thing too…

Anywyas, so i tried:

var caseMaterialsCubeMap = new CubeMap (fLQBMDfLQBMD,
     
fLQBMDfLQBMD,
     
fLQBMDfLQBMD);
    
p.material caseMaterials

gives me the error:

Error: Implicit coercion of a value of type away3d.materials.utils:CubeMap to an unrelated type away3d.materials:MaterialBase.


I’ve only seen the cubemap used with the skybox primitive, so not sure how to apply it to a cube…

 

   

Avatar
jansensan, Newbie
Posted: 09 January 2012 06:20 PM   Total Posts: 16   [ # 7 ]

This is not exactly an answer to your Bitmap question, but more about how to apply an image to a cube, if you’re still looking. I’ve had an issue about that too, so I wrote a blog post to share the solution I found: http://jansensan.net/apply-a-texture-on-a-cube-in-away3d-4-0

I hope that helps!

-mat.

   

falinks, Newbie
Posted: 20 March 2014 02:52 AM   Total Posts: 2   [ # 8 ]

sorry for not being able to provide exact answer. i am happy to show you how to load image from file and how to dynamatically load image from web. if this can helps a little bit, i will be glad.

   

Mr Margaret Scratcher, Sr. Member
Posted: 20 March 2014 09:29 PM   Total Posts: 344   [ # 9 ]

Nah I’m all set now, with a whole load of new problems to solve wink

Thanks all the same though smile

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X