Jump to content

GUI mapped to Box Faces


royibernthal
 Share

Recommended Posts

I'd like to display GUI on box faces.

For that purpose, I'm creating an AdvancedDynamicTexture with 6 objects, place horizontally one after the other. Sort of like a dynamic texture atlas, each part representing a different face of the box.

Once I have that, I'm trying to map each part of the texture to its corresponding part in the box using faceUV.

 

Here's how it looks like in a full screen GUI:

https://www.babylonjs-playground.com/#XCPP9Y#337

 

Here's how it's mapped to the box faces:

https://www.babylonjs-playground.com/#ICZEXW#22

 

As you can see, it's still not working as I want it to.

I'd like to create objects in their real size (e.g. images) inside the texture, instead of filling the texture completely by using percentage to define width, height and positioning - an approach which has its own problems as well as far as I can see.

 

Is it possible to change the width and height of AdvancedDynamicTexture to match its content? (e.g. in this example width: 514 x 6, height: 514)

I assume this could possibly solve the issue and then distributing GUI parts to their corresponding faces should be easy since we could treat AdvancedDynamicTexture as if it was an ordinary texture atlas:

https://doc.babylonjs.com/how_to/createbox_per_face_textures_and_colors

Link to comment
Share on other sites

Hi guys!   Hey Royi... I just want to remind you of something Deltakosh often reminds me/us-of... and is easy to forget:

"Often, dispose old one and re-create."

Bending and twisting something... in an attempt to do after-rendered scale-to-fit/paddings/margins... can give ya tumors.

Perhaps, there is a "re-create instead of adjusting" solution for you, too.  Just a reminder of that sometimes-viable option.  :)

Hope you're doin' well!

Link to comment
Share on other sites

Yup thanks. I went through the source and found scaleTo() - which is even better for me, that way I can measure the GUI content in runtime and then resize the texture accordingly.

 

I got a couple of performance questions:

1) I have more than 1 box, each has its own AdvancedDynamicTexture. Would each set of box + texture trigger a different shader compilation? Since these are basically different diffuseTextures for different meshes.

2) Does GUI update trigger shader recompilation in this case? (e.g. if I'm animating things in the GUI)

3) How performance heavy is what I'm trying to do compared to displaying GUI on a Plane? Does it use substantially more resources? Would it be a bad idea to do this on mobile?

Link to comment
Share on other sites

1/ Nope. Same shader as you don't have different options (all are only using diffuse)

2/ ADT does not trigger any shader related stuff. You can use it freely

3/ Each ADT requires a copy from a canvas to a texture so having multiple ADT is obviously more expensive than one. But having 6 ADT of 100x100 is equivalent to 1 ADT with 100x600

Link to comment
Share on other sites

Got it, thanks for the answers.

I got a follow-up question - or rather, digging a little deeper into what I'm trying to do -

 

A box needs to have a texture skin, and only one face should have an ADT on top of the skin.

My current approach seems way too expensive according to your answer. Multiplying 6 faces times the amount of boxes I have, while 5 faces in each box shouldn't even require ADT.

I'd like to re-use the box skin - I suppose a normal texture would be the solution for that?

Would you go with MultiMaterial to mix the box skin with ADT? If so, is it possible to apply different faceUV to different sub materials somehow? Since the skin will need to be applied from a texture map to 6 faces (or 5 depending on whether the 6th will have to be part of the ADT), and the ADT only to a single face.

How would you best approach it?

Link to comment
Share on other sites

Yeah that's the link in my first post. What am I missing here?

 

What I theoretically need -

adt submat - 1 face and other 5 faces are blank

box skin submat - 5-6 faces

part of a multimat that's applied to a box.

 

The "issue" is the faceUV is set for the box and can't be set per submat (as far as I know), making what I need to do impossible? at least in a straightforward way.

Can you please elaborate on how you think this can be solved?

Link to comment
Share on other sites

No idea at all if this is of any use to you but I had fun making a box out of planes each of which contains a GUI. The GUIs happened to be ones I had lying around but please note I only played around with putting them together so they formed a box none of them do anything.

https://www.babylonjs-playground.com/#V0LBBB

Link to comment
Share on other sites

Hey,

I see, you broke a box into planes.

I'm not sure if that's the ideal solution in my case, though it'd definitely allow me to apply a different material to each plane.

Waiting to see what DK has to say :) It'd be best if this could be solved in a more straightforward way on a single box mesh.

 

Btw in your case the same could be achieved with a single ADT and a single box mesh, which is what I did in my first PG, if this is any help to you:

https://www.babylonjs-playground.com/#ICZEXW#24

Link to comment
Share on other sites

10 minutes ago, royibernthal said:

In terms of performance which will be better an extra plane per box or multimat? (imagine you have tens of boxes)

That one is a little beyond me. It also seems to me that you may have the faceUV method and multimaterial method a bit intertwined when they are separate things, but I am very often wrong, paticularly about what other people know.

FaceUV compared to Multi-materials

My other concern is that perhaps you can get the GUI as a texture but will it then still be active? Don't know not skilled enough.

So being simple minded I would do the plane plus box approach.

Link to comment
Share on other sites

42 minutes ago, JohnK said:

hat one is a little beyond me. It also seems to me that you may have the faceUV method and multimaterial method a bit intertwined when they are separate things, but I am very often wrong, paticularly about what other people know.

FaceUV compared to Multi-materials

Yeah I'm aware that they are separate things :)

42 minutes ago, JohnK said:

My other concern is that perhaps you can get the GUI as a texture but will it then still be active?

I'm not sure I understand what you mean.

 

41 minutes ago, Deltakosh said:

Both techniques are comparable ultimately as they produce the same number of draw calls

I see. Is it even possible to achieve this with MultiMaterial?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...