Jump to content
psla314

Floating 2d text over 3d Cube

Recommended Posts

I am using a TViewport3D on an FMX Form.

I am trying to display 2D text floating over a 3d Cube (as a simplification of my project) I need the text projected to Camera (not Screen) because i want it to rotate with the cube.

I have tried using

- TPlane with a texture of the text on a transparent png,

- TTextLayer3d using the text field

- TImage3D with the text on a transparent Bitmap,

every time the background of the plane containing the text/image obscures the cube.

 

I dont really want to use TText3D because it is so slow, drops frame rate from 50 down to 12 FPS (I need about 8 floating texts) textures are much faster if I can get the transparency to work.

 

The first attachemnt shows the background of the TTextLayer3d hiding the cube and the second image shows the text getting hidden with z-write turned off ( thought this might be the answer)

 

Any Ideas ?

 

 

 

 

 

Screenshot 2022-02-28 144832.png

Screenshot 2022-02-28 144932.png

Share this post


Link to post

Try putting a TLayer3D on the cube (as a child object) and then adding a TLabel to that. To make the TLayer3D transparent, check Transparency property and make sure the Fill.Kind property is set to None (sometimes you have to toggle that to Solid and then back to None to get it realize it really should be transparent).

Share this post


Link to post
On 2/27/2022 at 11:58 PM, psla314 said:

I dont really want to use TText3D

Had to drop it too, was bugging me out..

If you want to spin the text with the cube, maybe just use a Timage3D and loose all the other layers..

really should be TText3d then you can see all sides.

 

I'm playing in 3d. Github here..

Share this post


Link to post
7 hours ago, corneliusdavid said:

Try putting a TLayer3D on the cube (as a child object) and then adding a TLabel to that. To make the TLayer3D transparent, check Transparency property and make sure the Fill.Kind property is set to None (sometimes you have to toggle that to Solid and then back to None to get it realize it really should be transparent).

That seems to work, great thanks for that idea.

Update - Works in Design mode but when i try to create the objects dynamically the layer is opaque again, see attached image. Here is my code, any ideas how to have the Transparency Property work, i tried your suggestion to toggle the brush and toggle the transparency at runtime, but no luck.

 

var
   box : TDummy;
   layer : TLayer3D;
   textlabel : TLabel;
begin
      box := TDummy.create(Viewport3D1);
      box.SetSize(1, 1, 1);
      box.OnMouseDown := CubeMouseDown;
      box.OnMouseUp := CubeMouseUp;
      box.OnMouseMove := CubeMouseMove;
      box.AutoCapture := true;
      Viewport3D1.AddObject(box);

      layer := TLayer3D.Create(Viewport3D1);
      layer.Position.Point := TPoint3D.Create(0, 0, -2);
      layer.setSize(1, 1, 0);
      layer.HitTest := false;
      layer.Fill.Kind := TBrushKind.None;
      layer.Transparency := true;
      box.AddObject(layer);

      textlabel := TLabel.create(layer);
      textlabel.Align := TAlignLayout.Center;
      textlabel.AutoSize := True;
      textlabel.Text := 'My Text';
      textlabel.TextAlign := TTextAlign.Center;
      textlabel.VertTextAlign := TTextAlign.Center;
      layer.AddObject(textlabel);

 

label.png

Edited by psla314

Share this post


Link to post
On 3/2/2022 at 11:24 AM, psla314 said:

That seems to work, great thanks for that idea.

Update - Works in Design mode but when i try to create the objects dynamically the layer is opaque again, see attached image. Here is my code, any ideas how to have the Transparency Property work, i tried your suggestion to toggle the brush and toggle the transparency at runtime, but no luck.

 

 

label.png

Update: Found my problem, the layer has to be a child of the cube otherwise doesnt work. Once changed the layer3d to be a child of the cube it works.

Share this post


Link to post
1 hour ago, psla314 said:

Found my problem

Sorry I hadn't seen your question from a few days ago but glad you found the solution.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×