Decals on animated mesh

I’m trying to get the decal moving with the mesh.

I searched around and saw this post from the old forum:

but its still a mystery to me. I can successful clone mesh, skeleton and the animation but then what do I do with the decal? Do I merge it with the clone?

why not just attaching the decal to the mesh by parenting it?

I wish it was that easy :frowning: Unfortunately parenting doesn’t make the child mesh animate.

I know in Blender you can reproject textures onto mesh with different topology and UV. If I could do that here then I could merge it with the texture of the avatar but I’m not sure if that’s possible in Babylon.js

Oh right:) because of the bones animating the mesh on the GPU.

Perhaps there is a trick by attaching the decal to the closer bone?

That would only change position of the decal. What I’m trying to do is get the decal to warp like the skin. Its as if I placed a tattoo on the skin. I need it to have exact same properties

So in this case I would probably recommend having a second texture (dynamic) over your mesh.
The texture will be filled with transparent pixels by defaut and you could render on it when required

But the decal is a mesh. How can I merge the decal texture into a texture for another mesh? The texture of a decal does not have the same UV as the base

@sebavan did you ever figure out how to do this?

Well I was saying you should not use decal in that case but direct draw into the texture (if possible)

As the bones are done on the GPU, the CPU has no idea where the mesh is

Yes, I need to figure out how to project an image onto a point on the texture in realtime. This is where I am stuck. The complexity lies in the UV mapping because of the different islands

At the moment my workaround is to make an ajax to call Blender (in background mode) which runs a Python script that reprojects the decal onto the mesh via texture baking. It feels very bloated to do it like this. Hopefully someone knows a better way!

So let me summarize:

  • you know the uv of the picked point
  • using this info you want to draw an image into a dynamic texture

This seems doable. The prerequisite is to have a second set of uvs for the dynamic texture

ok, maybe I’m missing something. If I use dynamic texture (for example, with text) and place it on the UV map for the 3D model the image gets broken up by the UV islands.

https://www.babylonjs-playground.com/#1BAPRM#193

This is why I said you need a second set of uvs on your mesh that will wrap the texture on the mesh

well, you’re surely going to get sick of me, but I’m stumped! I can’t find how to match one UV over another. I’ve checked doco and forum posts. Someone mentioned “uv2” array property of a mesh but I can’t find that.

I’ve got this decal and I’m trying to wrap it over this dress. 2 very different shapes with different UVs (the decal is crossing over 2 islands). Please, if you find an example or documentation, send it my way

(I know it looks like it lines up well in this picture, but remember I need it to be rigged to the skeleton exactly the same as the dress so it can be animated)

The second channel is easy to use from bjs standpoint (just set texture.coordinatesIndex = 1)
But you need to export your mesh with two channels of uv. The first one as usual to support your material diffuse etc…
The second one has to be added in blender and wrapped on the mesh

Ah, so my Blender workaround wasn’t so crazy then, 'cos that’s essentially what I’m doing.

So I guess there’s no way to do it all within Babylon.js?

Well we would need an unwrap function that we don’t have (pretty expensive to do on realtime)

Calling Blender is not so bad for me 'cos I don’t need it to be instant. User can wait a second for the result. Hopefully 100 concurrent instances of Blender doesn’t drain the server too much.

Not so good for realtime applications though, like playing a game and you shoot someone, they get a decal blood-smear but that blood-smear needs to animate with their crumbling body. Probably not many people using Babylon.js for realtime 1st-person or 3rd-person games tho.

They use the tech I told you. They prepare their assets with a second uv sets and then you can apply decals at the speed of light.

You don’t need to all belnder on every decals which seems overkill for me. Just add that second uv set and you are good to go