I’ve been stuck for days, and couldn’t figure it out.
I’m trying to put a small graphic (as in Team Badge, and player’s number at the back) onto a basketball jersey. I can’t use Texture as anything I specified will cover the whole jersey.
From this https://threejs.org/examples/#webgl_decals I believe decal is the way to go. What I don’t understand is that I need to shove a Mesh into the Constructor of DecalGeometry. What kind of mesh should I use? Not the mesh of the basketball jersey?
Is this the right step?
get the upload of PNG from browser
create DecalGeometry using an arbitrary Geometry (may be a square?)
specify some material (I want it to be transparent)
create a new mesh using the above DecalGeometry and material (I can’t figure out what values to use for the decal projector…)
load the PNG into a Texture
load the basketball jersey’s Mesh
merge the basketball jersey’s Mesh with the new Mesh containing the DecalGeometry
Also, how do I control the size of the graphic inside the DecalGeometry? As the graphic has color, I’m not sure if the basketball jersey’s color will affect the graphic and make the graphic look broken?
You have to apply the mesh that should receive the decal. So in your case, it’s indeed the basketball jersey.
Use the fourth parameter of DecalGeometry’s constructor. It defines the size of the decal projector which will affect the final size of the projected texture.
The red patch (nodes.MatShape_34889_Node in code) is where I want to place my Team Badge graphic.
Regarding the forth parameter, I have no idea what number to start off, as the graphic won’t show up properly at first load. Should I use 0,0,0 or 1,1,1? Or something else?
Taking your advice, I am implementing it using the code:
fiber is just a different way to express three, it won’t clash or depend on any particular version of threejs. could you post a simplified snippet of how you use decals vanilla? i have never used them to understand what you’re struggling with.
Using a standard BoxGeometry, enabling the texture map will make the square disappear. I’m not sure if it is:
black in color
too close to see?
too far to see?
Cloning the code and running it locally has the same result. But all variables are properly assigned and have proper values when checked inside WebStorm.
I really hope someone can help or share some advice.
I can’t figure out how to achieve this. Should I use Material.clippingPlanes, or variables in .map? Or I should use the right sized geometry first, then merge this geometry to a larger one?
@drcmda You know, I cannot express how grateful I’m for your advice. After going through countless number of methods, the texture is at least being displayed!
Instead of going through lots of hoops to get the texture to display on my object (the red square in my first post), and from your last post, I realise I don’t even need to use decalgeometry!
The reason is because I’ve already prepared the square using my 3D tool, and I simply need to lay the texture into the geometry, and that’s it (kind of)! I’m using react’s logo here.