Text in view? Need example

Software: Away3D 4.x

elwin, Newbie
Posted: 08 July 2014 09:14 AM   Total Posts: 1

How i’m make text in view and assotiate with point in my 3d model?

http://www.baumueller-services.com/de/de/?cbox=maintain

   

Mr Margaret Scratcher, Sr. Member
Posted: 15 July 2014 04:38 PM   Total Posts: 344   [ # 1 ]

Well, you can either get the screen coordinates of an object, and move a movieclip to that position on every frame,  or you could use the bitmap of the movieclip as a material for a plane, and put that plane in the positon of the object making it face the camera.

I previously used a handy piece of code which scales an object up or down, to give it a constant size no matter how far away it is from the camera.

I’m away from my work PC right now, so remind me to share it with you…

   

Hector, Sr. Member
Posted: 27 July 2014 07:16 AM   Total Posts: 137   [ # 2 ]

Please share smile

   

Avatar
ibsenleo, Newbie
Posted: 16 October 2014 10:55 PM   Total Posts: 8   [ # 3 ]

I’m new on this, but i think the easier way to do this is with the Sprite3D class (or at least i solved in this way).

This class draws a plane that is always facing to the camera, so is interesting to get this effect work.

I wrote a little function for show plain text in away3D 4 and with a little tweak you can get the same feel like that example.

The next function only uses a flash TextField for render the text. After i get this text into a bitmapData and with this, i make a texture that i apply to my sprite.

The text showed has no background, if you want a background you should use a flash Sprite behind the TextField or something similar.

i left the code here: hope to be useful

private function createSpriteText(text:String,color:int 0xffffffsize:int 30font:String "Arial"bold:Boolean=falsebgVisible:Boolean falsebgColor:int=0x000000):Sprite3D
  {
   
if(font == null)
    
font ="Arial";
   
   var 
tf:TextField
   
var textFormat:TextFormat;
   var 
_width:Number;
   var 
_height:Number;
   
   var 
bp:BitmapData;
   
   var 
textMaterial:TextureMaterial;
   var 
sp:Sprite3D;
   
   
//Text Format properties
   
textFormat = new TextFormat();
   
textFormat.size size
   textFormat
.font font;
   
textFormat.color color;
   
textFormat.align TextFormatAlign.CENTER;
   
textFormat.bold bold;
   
   
   
//Text properties
   
tf = new TextField();
   
tf.defaultTextFormat textFormat;
   
tf.text text
   tf
.background false;
   
tf.multiline true;
   
tf.cacheAsBitmap true;
   
tf.0;
   
tf.0;
   
   
//Rounding to Power of 2
   
_width Math.pow(2Math.ceil(Math.log(tf.textWidth)/Math.log(2)));
   
_width _width 2048 2048 _width;
   
   
_height Math.pow(2Math.ceil(Math.log(tf.textHeight)/Math.log(2)));
   
_height _height 2048 2048 _height;
   
   
//Giving H/W to the tf in power of 2
   
tf.width=_width
   tf
.height=_height;
   

   
//Creating bitmapdata container
   
bp = new BitmapData(_width,_height,!bgVisible,bgColor);
   
bp.draw(tf);
   
    
   
//Texture from bmdata
   
textMaterial=  new TextureMaterial(Cast.bitmapTexture(bp));
   
textMaterial.alphaBlending = !bgVisible;
   
textMaterial.mipmap false;
   
textMaterial.repeat false;
   
textMaterial.smooth true;
   
   
//Sprite with the text
   
sp = new Sprite3D(textMaterial,_width,_height);
   return 
sp;
  
   

Hector, Sr. Member
Posted: 11 November 2014 02:54 PM   Total Posts: 137   [ # 4 ]

Thanks for sharing ibsenleo, I use a similar method to include custom text as 3D Sprites, but I donĀ“t have a solution to keep the sprite’s scale ratio when camera moves. Any help with that would be appreciated.

   

Avatar
ibsenleo, Newbie
Posted: 16 November 2014 04:46 PM   Total Posts: 8   [ # 5 ]

I had to deal with some similar problem, and i found some solution (like the example you post does).

The best choice is to create the text in the DisplayList of flash (not Away3d but flash 2D) and update the text coordinates with the projection of the 3D coordinates of your mesh.

I solved like this:

private function getCoordinates2D(obj:ObjectContainer3D):Vector3D
{
    
var stage2dPos:Vector3D _view.project(obj.scenePosition);
    return 
stage2dPos;

This returns a Vector 3D where x,y values (z value is useless) are the equivalent 2D in DisplayList of your 3D position viewed from the camera.

Hope it helps! smile

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X