Sign in to follow this  
devour

How to draw text on meshes with the same material

Recommended Posts

Hey guys, i need ur help.

Is it possible to use a different dynamic texture on all meshes with the same material? I want to draw different text on each mesh. the meshes should be only different in their position, rotation, scaling and the text on it.

Best regards and thx

Share this post


Link to post
Share on other sites
1 hour ago, RaananW said:

Hi,

in this case you will need to clone the material and set a different texture for each of them. 

Is there a better way ? I create 1 to 300 boxes. If i clone the material and set a different texture for each of them i got performance problems. the performance even goes as far that the game become unplayable

Share this post


Link to post
Share on other sites

Hi guys.  They are boxes, eh?

Can text be on only one side?  Would that be ok?

If so, there might be a sprite or Solid Particle System solution.  Create a sprite/sps plane on one side of each box, and then create a single "sprite atlas" texture that contains ALL the text used for ALL the boxes.

Then set UVS on each sps plane or sprite... so it has the wanted text from the correct texture atlas "cell".  Essentially, you are adding a "sign maker" to your box-maker factory.  :)

https://www.babylonjs-playground.com/#WCDZS#82  (not a perfect demo, but we can see how it might work)

I dunno if performance will improve, or actually get worse.  But... using one big texture can't be all bad.  (but can be sort-of bad)  :)

Share this post


Link to post
Share on other sites
1 hour ago, Wingnut said:

there might be a sprite or Solid Particle System solution

Here's an SPS version. By no means perfect and still a lot of work to do but here are some boxes that have a (albeit stretched) shared texture and different words on each box.

https://www.babylonjs-playground.com/#A9K31I#3

Share this post


Link to post
Share on other sites

(Jerome is avoiding talking about the drag/drop part.  He speaks only of picking.)  :)

http://playground.babylonjs.com/#UZ23UH#0

Make same functionality... with SPS boxes.   :o

I wanna see it.  ;)  (My dog got scared and ran under the fridge again.)

"Transformers... more than meets the eye."  (tv commercial jingle from long-ago).

Actually, SPS particles have .position, so, should be do-able, in theory.

Share this post


Link to post
Share on other sites

about the initial question (one material and different texts), if you use some BJS provided mesh implementing the faceUV parameter in its constructor (like planes, boxes, etc), you could :

- create one big dynamic texture and write your different texts on it at separate different positions

- set this texture to a single material

- set the faceUV values of each mesh to match the wanted different texts

- assign the same material to every mesh

 

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

http://doc.babylonjs.com/how_to/set_shapes

I just can't retrieve an old PG example I did about how apply a different image from the same texture/material to 2 separate meshes.

Share this post


Link to post
Share on other sites

@devour

 

Load your meshes or create them in a loop and assign the same material with a different var name++ for the dynamic texture in the material associated with the loop. And define each dynamic texture by the var++ name prior to the loop. This should be very simplified code.

DB

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.