UV position problem of Dynamic Texture

I try to set up but fails as I need to include fabricjs or needs gltf import for that.

but I try to import gltf into sandbox


I find out that the option of invertY could be a cause of the UV issue.
I try to do set the invertY to false with new BABYLON.Texture, it works well but the parameter isn’t working with DynamicTexture.
i do something like this:
var texture = new BABYLON.DynamicTexture("texture", canvasSecond, scene, true, 0, 0, true, false);

Perhaps I send you some code so that you can dive into that?

You can inject your script in the PG using BABYLON.Tools.LoadScript or LoadScriptAsync.

Having a repro in the Playground would allow anybody willing to help.

I try to put the code into the Playground but there is some error.
The Playground is here: https://playground.babylonjs.com/#IKJYCJ#1
I also put the code into the github: GitHub - moonyuet/shirtCongrJS

Here’s a modified PG that works: could you update it so that it shows the problem? For the time being it is very dark and it’s hard to see what’s going on.

https://playground.babylonjs.com/#IKJYCJ#4

https://playground.babylonjs.com/#IKJYCJ#10
I try to import the diffuse texture but it seems that the dynamic texture is not working as I expected. I try not using fabricjs to import the texture but it still looks really dark.
I also create JSFiddle for it but it seems that the dynamic texture is not really working.(this one I am still using fabricjs)

The dynamic texture is there, as shown in the Inspector:


Next step after you are sure that the texture is working is to find where is the error in the code, and it is not difficult: we need to change var meshOne = mesh[1]; into var meshOne = mesh[0]; and… miracle!
https://playground.babylonjs.com/#IKJYCJ#11

Hi labris.
Thanks for reply!
I want to show not only just base color but also the kenzo logo overlaying on top of the diffuse map by using dynamic texture but it seems it automatically sets InvertY to true and I am not sure how to fix it by loading command. I tried to dive into documentation and set the new BABYLON.DynamicTexture(“texture”, canvasSecond, scene, 0, 0, true, false) in order for converting the invertY to false. But it seems it doesn’t work.
I can do it with just diffuse map with BABYLON Texture but it seems dynamic texture is different case.

I am not that I understood completely what do you mean by “overlaying” but you may try to use emissive texture for the logo and diffuse texture as usual.
As for Faces UV you may try to draw on canvas not the usual texture but sprite and then apply it to the mesh’ faces as you like.

I mean like assigning the logo on top of the diffuse map.
I try to write a script to allow users to put a custom pattern or text on the 2D layout of the map and they can save image to reload it in other platforms.

Here is the demo showing that it is possible - | Camisa Dimona
More info here How to submit my page to the "made with" section?

As I see your question/problem should be solved in logical way.
Let’s do it in 2D canvas.
We have

  1. Some image to be drawn on canvas

  2. User input (text or image) which should be also drawn at canvas over the first image in some position.

  3. The result = new image on canvas, nothing more
    If you can do it in 2D, there will be no problem to do it in 3D since all these images are actually just flat images (textures). The logic will be the same:

  4. Some image to be drawn on canvas as diffuseTexture. This is flat image.

  5. User input (text or image) which should be also drawn at canvas over the first image in some position. This is also flat image.

  6. The result = new image on canvas, nothing more. This new image = new diffuseTexture which you need just to change after user input.

You can try just to edit your texture in Inspector to see the logo position in 3D and 2D simultaneously:

I can do it already with the default simple cube in babylonjs. I just dont know why I can’t do with the diffuse map in a fixed uv pattern when it assigns to my shirt.The only solution I can find is, I can remove the diffuse map and set the canvas all-the-way to just color and add texts and images. But this is not the initial propose to create the configurator for the users in my case. The diffuse map with the UV-layout pattern is important for the users to make a deal with their clients or factory people.

Perhaps it is some kind of bugs when the invertY attribute of dynamic texture cannot be set to false. When I assign the diffuse textures with UV back to the shirt by setting invertY to false, it works fine.

So, as I understood you correctly, you have working example with the cube in Babylon JS.
The problem was how to get the diffuse texture (more correctly, since it is PBR material, albedoTexture) from your model. When you get it, you can draw upon it as you need.
Here it is - https://playground.babylonjs.com/#IKJYCJ#13
Just make myGoodTexture your dynamic texture and draw upon it.

I’ve tried, but still the diffuse texture is flipped while other maps are correct.

Could you try to set uScale and Vscale texture parameters to -1?

texture.update(true)? Just flip the update?

Let’s open again this example - https://playground.babylonjs.com/#IKJYCJ#11

Now change uScale and vScale to -1:

The dynamic texture is flipped and looks as in your flipped example.
image

As my logic tells me, if you flip with uScale and vScale your texture, which you receive flipped from some function, you should get the right texture in the correct UV position.

Yall know you can flip the texture right away with what I mentioned above right? No need to mess with the UV prolly.

Also possible.


1 Like

It works with this. Thanks @Pryme8 and @labris

1 Like

Actually the more simple solution of the case belongs to @Pryme8, but mine (with vScale) will work with all textures, not only dynamic ones.
I am glad that we solved this puzzle :slight_smile: