add text on a cube : the text is stretched ...

Software: Away3D 3.x

Erroll, Newbie
Posted: 28 August 2011 05:34 PM   Total Posts: 6

Hi,

Does anyone know if it(s possible to put some text on a cube, but avoid that the text is stretched ?

for example, if i test this code, the text is barely lisible, i’d like to have the text to its normal size, and put it on the cube, and rotate the cube for example :

private function initMaterials():void{
          cubeMaterialsData 
= new CubeMaterialsData();
    
    var 
textfield:TextField = new TextField();
                
textfield.text "SavageLook.com";
                
textfield.setTextFormat(new TextFormat("Arial"300xff0000));
                
textfield.autoSize "left";
    
    
//text_sprite = new Plane({width:TEXT_WIDTH, height:TEXT_HEIGHT});                
                
var bmd:BitmapData = new BitmapData(textfield.widthtextfield.heighttrue0x00000000);
                
bmd.draw(textfield);
    
    
    
          
cubeMaterialsData.front = new BitmapMaterial(bmd);
cube = new Cube({name:"cube"x:0y:0z:0width:100height:100depth:100});
          
cube.cubeMaterials cubeMaterialsData

example on this site : http://www.adenek.com/

Thanks for your help

   

Richard Olsson, Administrator
Posted: 29 August 2011 07:49 AM   Total Posts: 1192   [ # 1 ]

A cube is by default square, and UV-mapped such that textures will be stretched to fill the entire side. Make sure your BitmapData is square, for example by creating using hard-coded square dimensions and drawing your text field into the center.

 

   

Erroll, Newbie
Posted: 29 August 2011 11:49 AM   Total Posts: 6   [ # 2 ]

Thanks for your post, i tried to put 100 x 100 on the bitmapData :

var bmd:BitmapData = new BitmapData(100100true0x00000000);
                
bmd.draw(textfield); 

which are the dimensions of the cube.

Then, did you mean to do this :

textfield.autoSize "center"

the result is the text pixelised, that goes beyond the dimensions, i tried this code :

cube = new Cube({name:"cube"x:0y:0z:0width:100height:100depth:100});
          
cube.cubeMaterials cubeMaterialsData;
var 
textfield:TextField = new TextField();
                
textfield.text "qlmkdj qsldkj sqdlmkj qmsldkfj qslmdkj sdmlfkj sd ddf lqskjdf ";
                
textfield.setTextFormat(new TextFormat("Arial"120xff0000));
                
textfield.autoSize "center";
    
    
//text_sprite = new Plane({width:TEXT_WIDTH, height:TEXT_HEIGHT});                
                
var bmd:BitmapData = new BitmapData(100100true0x00000000);
                
bmd.draw(textfield);
cubeMaterialsData.front = new BitmapMaterial(bmd); 

and the result enclosed.

Do you have any idea?

thanks again

 

   

Richard Olsson, Administrator
Posted: 29 August 2011 12:08 PM   Total Posts: 1192   [ # 3 ]

You need to use a Matrix to scale down your text field (and probably translate it as well) as you draw it to the bitmap. This is basic BitmapData manipulation and not really related to Away3D, so if you think it’s difficult, you’re best off trying to find a tutorial on how to use BitmapData, draw to it (including transformation) et c.

 

   

Erroll, Newbie
Posted: 29 August 2011 01:32 PM   Total Posts: 6   [ # 4 ]

Ok, will this give me a “clean” text, as if it was a “normal” text written on the stage? because we use bitmapData and the scale property from the Matrix, i thought this should be used with images only.

Also, i found out you wrote the book “the essential guide…”, i didn’t realize at first, congrats because i think it is fantastic!

edit : ok actually it would be really nice if you could help me with this textfield : i found out about the matrix and its property scale, but then i’m a bit lost to use this with my textField and the face of the cube, can you tell me a bit more about how to fix this?
i try the matrix with random numbers, but how can i reach the “normal” size of the text, and also have “multiple lines” ?
i also tried to test it with a simple movieclip, but it seems that my code (width & height on the mc) doesn’t work…

var transf Matrix = new Matrix();
    
transf.scale(1.0/3.0,1.0/3.0);
    
var 
bmd:BitmapData = new BitmapData(textfield.widthtextfield.heighttrue0x00000000);
    
bmd.draw(textfieldtransf);
var 
bit:Bitmap = new Bitmap(bmd);
    
    var 
myclip:MovieClip = new MovieClip();
     
//myclip.width = 100;
   //myclip.height = 100;
   
myclip.myclip.10;
   
myclip.addChild(bit);
   
addChild(myclip); 

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X