Positioning decal in UV space on only selected meshes

Hi All, I want to position a decal in UV space. The demos use interactive raycasting to find the hitpoint and position the decal that way.

https://playground.babylonjs.com/#1BAPRM#73

That wont work for me as id like to position the decal precisely at a pre-defined position on the surface, ideally a point on the surface corresponding to some UV coordinates. So there are two parts to this.

  1. UV space positioning. The requirement here is that given a surface, if I want to position that decal on the “center” of the surface in uv space, that would be UV: 0.5,0.5 (assuming zero to 1 uv space). Currently you can only position the decal in a world x,y,z space. Do I need to transform the UV coordinate point to a world point. First . If so how would I go about this.

  2. Secondly, I want to restrict the decal from only affecting a specific mesh, not all meshes. How do I mask only the mesh I want to position my decal so it only affects that mesh. I feel like there is some renderGroup trick here that could be used but cant quite grasp it.

Would appreciate any advice,
-Anupam

1 Like

About the point 2, line 30 in the playground is the filtering one and a decal will always be drawn on 1 mesh only.

The point 1 is rather tricky and I do not think we have a build in for it. You would need to find in the vertices data where 0.5 0.5 in UV space lies. This would provide you with the requested value in a triangle. Then applying the same weight to the position data fitting with those vertices, you could find the local position associated with this point, that could finally be converted in World space.

I wonder if somebody from the community has already done similar work in the playground ?