Sign in to follow this  
arek3D

DynamicTexture on mesh from .babylon file causes a problem.

Recommended Posts

Hello,
I have noticed that there is a problem with UV mapping, if I use a dynamicTexture on my mesh, imported from .babylon file. I am sure that my mesh has proper UV mapping, I have checked it by using standard texture.
If I use normal texture on this mesh, everything is ok.
If I use dynamic texture on BABYLON.Mesh, everything is ok.
If I use dynamic texture on my mesh, I have seen something like that:

 

I can't find an example on the playground with a mesh with proper UV mapping, so I have chosen the skull

Playground:

http://www.babylonjs-playground.com/#1NQC5D#3

babylon js bug.png

Share this post


Link to post
Share on other sites

Hi guys!  @arek3D, I got a playground rolling for you, and am doing some dynamicTexture tests.

I am getting same results as you so far.  Could be my mistake, though.

http://www.babylonjs-playground.com/#1CMD3G#32

No SceneLoader.Append in this one... I use ImportMesh instead, for this demo.  :)

As you can see, a second plane... created within the scene... is rendering the drawText fine.

SO... it is my opinion... that your imported plane has no UVs set.  I am also having troubles scaling it (line 13).  The in-scene-made plane scales correctly in line 19.  hmm.  The imported plane has a different axes-orientation or something.  :o

There may be options in your modeling software for "generate UVs", or ways to "include UVs" during the export.  I don't work with modelers very often - sorry.  You COULD even set the UV's yourself, with JS, in the scene (by setting 4-8 Vector2 values on the mesh's vertexData object).  We'll talk about that later.

First, check your modeler and perhaps view the .babylon file with wordpad or online JSON viewer... see if there is UVS data in there, or only vertices and indices.

Keep us posted.  You should be able to use that playground above... for testing.  Make more saves, bookmark the url after each save, etc.  Have fun, you cannot damage anything in the playground... no matter how much you try.  Good luck.

Share this post


Link to post
Share on other sites

Thank you very much for your answers!

I will check that PG tomorrow.

But how to explain the fact that when I put a standard texture, it works well on the same plane?

Imho without UV channel it would not be possible.

I use 3ds max 2016, with max2babylon exporter, but not the newest version, because it shows errors.

Share this post


Link to post
Share on other sites

I think UV channel is correct in my mesh (this is default plane from 3ds max 2016. So UV must be correct.

Moreover, I made a PG which prove that UV is incorrect only if I use DynamicTexture (in this example textures are swapped in the loop every 60 frames)

http://www.babylonjs-playground.com/#1CMD3G#39

uv.jpg
 

This is quite strange, isn't it?

Share this post


Link to post
Share on other sites

Hi again, good troublehshooting/research, Arek! 

I've been doing some testing:

http://www.babylonjs-playground.com/#1CMD3G#40

According to console, the imported plane UVs is a Float32Array [ 0, 1,   1, 1,   1, 2,   1, 2,   0, 2,   0, 1]    (two 3-point triangular facets)

I don't think I have ever seen a UV array with 2's in it.  As far as I know, all UVs, should be 0 to 1 inclusive, and never higher than 1.  hmm.

I created my own UVs (uvs3) in line 45, and poked it into the plane in line 46.  Then I re-query the UV data from the plane, and send it to console.  Notice it is NOT a Float32Array, but perhaps that is only because I didn't "cast" uvs3 as such.  Not sure if I CAN force a standard array... to be Float32Array.  (see update below)

But, plane started showing the draw-text. I'll be darned.  Quite strange indeed, Arek.  Perhaps @Deltakosh (or others nearby) will be able to understand this.  I'm kind of baffled.

Possibly, there is a problem with the 3dMax exporter, but I speculate incorrectly quite often.  I'll keep thinking and perhaps do more tests.  Others will have ideas... I know it.  We have a HUGE PILE of smart people nearby, including you, Arek!  You made a very interesting "find".  Well done.  Puzzling.

Update:  Oh duh, Wingnut.  There's a new Float32Array right there in line 33.  (I borrowed that code from another forum post).  I should learn to pay attention to life, huh?  :)  Thx to @JCPalmer for the Float32Array and convert-to-updatable info.  mesh.setUpdatable(true) would be "nicer", huh?  :)

Share this post


Link to post
Share on other sites

@Wingnut and @arek3D Here is an PG example using Wingy's code from above but using a plane created in/exported from Blender

Plane and text

Looks fine. It prints out the UVs in the console, but they are : "uvs":[1,0,1,1,0,1,0,0]  (from the .babylon file)

Hope that helps in some way.

cheers, gryff  :) 

Share this post


Link to post
Share on other sites

Thank you @Wingnut for your workaround!! I wrote proper UV values for my meshes and it works! :D
In my free time, I will try to fix that issue with the newest exporter, which I had and I will test this strange UV behavior once again. Or maybe I should change 3ds max to 2017 version ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.