Jump to content

DynamicTexture on mesh from .babylon file causes a problem.


Recommended Posts

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



babylon js bug.png

Link to comment
Share on other sites

  • arek3D changed the title to DynamicTexture on mesh from .babylon file causes a problem.

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.


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.

Link to comment
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.

Link to comment
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)



This is quite strange, isn't it?

Link to comment
Share on other sites

Hi again, good troublehshooting/research, Arek! 

I've been doing some testing:


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?  :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...