Jump to content

How to change the size (u, v) of a texture for one face of a mesh?


hit2501
 Share

Recommended Posts

I can apply a texture to a complete exported model (lets say a dodecahedron) from Blender and change its size with vScale and uScale. But now I'm trying change the size of only 1 face of the dodecahedron, is there a way or sample to achieve this? It would be necessary to apply the texture for each mesh by separated?

Thank you all.

Link to comment
Share on other sites

Hi hit, good to see you again.  I can TRY to answer this... probably wrong... but I will tell some things.

Let's playground-up and do some thinkin'.

https://www.babylonjs-playground.com/#2GXQ13#11

Ok, that's all the further I'M going.  The rest... scares me.  FaceUV's.  Phew.

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

http://doc.babylonjs.com/playground/?code=CreatePolyhedron

Flat.  Flat is important... which is one parameter of the possible options of a CreatePolyhedron() call, I think.  Look at console.  After convert-to-flat, our dodec has many more verts.  I THINK... a flat-shaded mesh has THREE available UV's at EACH corner/vert-position.  This is because their are actually 3 verts at each corner-point, on a flat-shaded mesh.

And that... is what YOU need, I believe.  You want to affect the texture on ONE face of the dodec, but not affect other faces.  Without flat-shaded... adjusting the UV at ONE vert-point... would affect the texture of all faces that intersected at that vert-point.  You just want to affect one face, so you need a "private uv", right?  heh.  No affecting the neighbors.  :)

Understand the difference between faceUVs adjusting scale/size of a face texture AT CREATION TIME, versus adjusting it later, "live".

I think one way is easy, the other way, not so easy.  :) Let's ping @jerome, just because I know he LOVES being pinged.

That guy drives faceUV's amazingly well.  He sort-of invented them for BJS, I think.  :)

Link to comment
Share on other sites

@hit2501

This is not necessarily simple in your code. If it were me, I would unwrap your texture, and modify the texture and or most likely the UV mapping in your application. Then export, which is far faster and far less calculations - if doable at all for your needs.

DB

Link to comment
Share on other sites

hi @hit2501

i have one solution 

https://www.babylonjs-playground.com/#UXCB15#45

step 1 make png and select your selected face on this and  cut it

n3XIz9J.png

make custom shader  and read texture 2 ways

   diffuseColor = texture2D(mainTexture,vDiffuseUV).rgb;   // main texture
 
   float specialFart = texture2D(colorpatern,vDiffuseUV).a;   // special face condition
 
   vec3 def2 = texture2D(mainTexture,vDiffuseUV*20.).rgb; // read new  texture by scale 20
   

and in final mix them

 diffuseColor =  diffuseColor*(specialFart)+def2*(1.-specialFart)  ;

 

Link to comment
Share on other sites

13 hours ago, dbawel said:

This is not necessarily simple in your code. If it were me, I would unwrap your texture, and modify the texture and or most likely the UV mapping in your application. Then export, which is far faster and far less calculations - if doable at all for your needs.

Hi guys.  This, and some of the other ideas... are "done at creation time" ideas.

Hit2501... you haven't yet told us if/not you need to resize a face texture... AFTER creation/first-render (later, during game-play).

If you DO need to resize a face's texture... later... after creation, that requires a different kind of solution, I think.  *shrug*

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...