Possible to add / remove texture overlays on the fly?

Software: Away3D 4.x

grimep, Newbie
Posted: 11 May 2012 02:24 PM   Total Posts: 4

Very newbie question… if I had say a rotating shape, could I add a graphic asset as an overlay to the existing texture? Could I add it in an exact position on the model? Could I remove it also on the fly?

If not, what sort of trick could I do to achieve a similar effect? Imagine say a pool ball rotating, but on each rotation the number graphic in the circle has been changed.

   

Mr Margaret Scratcher, Sr. Member
Posted: 15 May 2012 10:42 PM   Total Posts: 344   [ # 1 ]

Well, briefly, if you are importing the ball as an external object, with a UVmapped texture, it would be a case of copying this texture to a bitmap, adding the number to the appropriate area, then updating the texture, and repeating this on each update.

If you’re doing it using a sphere generated within flash, the technique will be the same, although you’ll have to experiment to see where abouts in the texture map you need to add your graphic…

I’ve done a similar thing with a cube, which is slightly simpler as obviously it has 6 discrete (ie, definitely separate) faces, whereas for a sphere, the area that your number graphic occupies is likely to cover more than one actual face in the mesh..

Hang on, I’ll post how I did it with a cube, to hopefully point you in the right direction..

   

Mr Margaret Scratcher, Sr. Member
Posted: 15 May 2012 10:53 PM   Total Posts: 344   [ # 2 ]
var currentCaseBitmap:Bitmap = new flash.display.Bitmap (p.material.texture.bitmapData)
    
    var 
caseMC:MovieClip = new flash.display.MovieClip;
    
caseMC.addChild(currentCaseBitmap);
    
caseMC.addChild(frontCoverloader);
    
    
//test to see where the loader is positioned. This add to the screen so I could see if the bitmap I was adding was being resized and positioned in the right place
    //addChild (caseMC)
    
    
var yRatio = (caseMC.height 2) / frontCoverloader.height;
    var 
xRatio = (caseMC.width 3) / frontCoverloader.width;
    
frontCoverloader.caseMC.height 2
    frontCoverloader
.caseMC.width /3
    frontCoverloader
.scaleY =  yRatio;
    
frontCoverloader.scaleX =  xRatio;
    
    
//create new bitmapData
    //TODO: figure out whether maybe updateTexture would be a better way?
    
var caseBMD = new flash.display.BitmapData (512512)
    
caseBMD.draw (caseMC)
    
    
//TODO replace bitmapmaterial
    
caseMaterials = new TextureMaterial(new BitmapTexture(caseBMD))
    
caseMaterials.ambientColor 0x505080;
    
caseMaterials.gloss 5000;
    
caseMaterials.specular .5;
    
caseMaterials.lightPicker lightPicker;
    
p.material caseMaterials

( ‘p’ in this case is a cube, which has already been defined, and has a bitmap texture)

Hopefully you can make some sort of sense of what is going on there…

The above works for if you;re using a bitmap texture, if you just want, say a coloured texture, and then update the number, you would skip the top bit which grabs the current texture, and just use the as3 graphics draw functions,

private var newTexFill:Shape = new Shape ();


.....
...

...


newTexFill.graphics.beginFill(0xFFCC001);
   
newTexFill.graphics.drawRect (00widthheight);
   
newTexFill.graphics.endFill();
   
newTexFill.alpha 1;
   
newTexMC.addChild(newTexFill); 

You’ll need to make sure the dimensions are a power of 2 sized ( google them), and then just adapt the first bit I posted to add in your graphics, like I say, you’ll need to experiment with the position and orientation to get it in the right place..


I’d expect there to be a more elegant solution, sugggestions gratefully received!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X