Make the size of the plane similar to the parent's mesh

So I am currently trying to create a plane that will create GUI buttons on any screens that I selected as designated mesh.

I understand that you can assign the plane’s parent into the selected mesh but will it be possible to size it as well the same of the parent/selected mesh.

I’ve created a sample play ground with a mesh that has a lot of child mesh to play with: (sorry if it’s all black!)

cc @msDestiny14

Yes this is actually how we do it in the GYU Editor! Let me get some details for you…brb

In the GUI Editor, we take a 1,1 plane and then render a advanceTexture onto the mesh.

We do this with:
adt = AdvancedDynamicTexture.CreateForMesh(textureMesh, textureSize, textureSize, true);

Now the next thing we do is scale up the planes size to match the adt.
textureMesh.scaling.x = textureSize;
textureMesh.scaling.y = textureSize;.

You can then update the size of the adt or the plane when you need to. For example if you are switching meshes. Here is how it’s done in the editor:
textureMesh.scaling.x = newvalue.x;
textureMesh.scaling.y = newvalue.y;
adt.scaleTo(newvalue.x, newvalue.y);

Hope this helps and please let me know if you have follow up questions.

Hi @msDestiny14 ! Thank you for your input. I am currently trying to apply the solution you mentioned. Just a quick question is the textureSize refer to the:

const flatScreenSize = flatScreen.getBoundingInfo().boundingBox.extendSize;

And just a noob question, why do you not include the scaling of y? (or is it correct that scaling z would be equivalent to size.y?)

In any case, this gave me somewhere to start with and I’ll try implementing it ^^ Thanks!

Texture size is a predefined value, whatever you want to make it. It could be the size of all your different screens that you have.

Oh yes, the scaling would be Y. (It’s Z on the editor because of the angle of the camera so sorry for the confusion. Let me edit the code the be generalized)

Sorry just to clarify. Is the textureSize something I can get on the Mesh class (Since scene.getMeshById returns that type) and if so what property/function would it be?.

It’s whatever you want it to be. How we do it for the editor, the mesh is 1x1 and then we scale it to textureSize: 1200. This will be in pixels.

In your example you are loading a mesh so you will have to figure out your size ratio.

But what if you were not the one who made the mesh but rather simply load it?
So in this case I’m essentially just loading a mesh and only has the name of the mesh I want to apply a screen at.
Will there be a way to compute the textureSize? (Sorry for asking a lot >.<)

So you can information about the mesh to determine the right size you’ll need.

Also if you are just switching the texture to be on the different sized meshes then it should be calculating this automatically when you call AdvancedDynamicTexture.CreateForMesh(mesh) width and height specifications are optional.

Got it that should complete it! I guess last question for me (though it may be out of topic for this thread). So when I try to apply that plane to the parent mesh. It seems that it is inside of the mesh (see image for reference)

When the plan is to add it like this:

I was able to do this by adjusting the plane’s z position but is there a way to dynamically do this to let the plane appear above a parents mesh?