Jump to content

Set box's face texture to custom image


Recommended Posts

Hi, I'm new here, my name is Royi.

I'm loading a custom image (.png) using AssetManager, on complete I'm rendering a scene with a box.

I want one face of the box to display the custom image I loaded.

I experimented with Sprite but it seems to be completely restricted to 2D (by definition I guess), I was hoping for a thin 2D sprite I could rotate around the z axis as well.

Is there some option to set the texture of a polygon's face to an image? Otherwise, how do I achieve it?


Link to comment
Share on other sites

Thank you it was helpful.

In order to display the material with the defused texture only on one face I simply set in the faceUV array all values to new BABYLON.Vector4(0, 0, 0, 0) except for the face in which I wanted to display it.

Would that be the optimal way to go in your opinion? I'm simply playing with the code I see I'm not really sure what solution would make the most sense.

Link to comment
Share on other sites

You only need to set one face. Bit further down in document.

Imagine we want to set only the face 4.
Forget about the for{} loop, just initialize our faceUV array and set only faceUV[4] :

  var faceUV = new Array(6);
  faceUV[4] = new BABYLON.Vector4(0, 0, 1 / hSpriteNb, 1 / vSpriteNb);

Only two lines of code only and that's all : http://www.babylonjs-playground.com#1V3CAT# 25

Link to comment
Share on other sites

As JohnK explained, setting one faceUV array element will only modify the related face.

As the default uv value is (0,0,1,1) for each face, this default value will be applied to the other faces. As you discovered it, if you set (0,0,0,0) to the other faces, the texture won't just be visible... at no perf cost : there's only one initial texture passed to the GPU.

In other terms, whatever you need to set just a part of an image to one or many faces or whatever you need to apply a full image to one or some faces, faceUV is the right tool and will behave at the exact the same cost than a simple texture setting on any other mesh that doesn't support this feature.

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.

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.


  • Recently Browsing   0 members

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