Jump to content

Replace an existing texture using UV Map


Iwaa-kun
 Share

Recommended Posts

Hi,

 

I'm new to BabylonJS and 3D.

 

I created a scene in Blender with a character. It has a single material, UV Map and texture.

It works fine in BabylonJS but when I replace the texture with new BABYLON.Texture or new BABYLON.DynamicTexture (in my case), the new texture does not take into account the UV Map.

I think I forgot something, but I don't know where to watch.

 

(Sorry for my English ^^')

Link to comment
Share on other sites

You must reload the model after assigning the new textures. I do not think it can be dynamically changed.

How can I do that?

Normally, there is no texture and diffuseTexture is undefined. What I wanted to do is to place a dynamic texture on the model and then I draw the character's face dynamically.

 

So I do this:

// mesh.material.diffuseTexture is undefined before thatvar skin = new BABYLON.DynamicTexture("Peau", 1024, newScene, true);skin.hasAlpha = true;skin.getContext().fillStyle = '#ff0000';skin.getContext().fillRect(0,0,1024,1024);skin.getContext().drawImage($('img.eye')[0],0,0,120,100,190,690,120,100); // There is an HTML Image Element loadedskin.update(false);mesh.material.diffuseTexture = skin;

But I find myself with the same problem: the texture does not take into account the UV and hasAlpha property changes nothing.

How do I reload the model after applying the dynamic texture?

Link to comment
Share on other sites

When you do a console.log (), you have diffuseTexture?

You must export your model with a default texture, even if it is transparent so you need to do with blender or 3ds max. diffuseTexture exist and you can modify with Babylon.

 

I think your problem is here. Babylon when exporting your model, it exports it finds as texture, if there is not, it does not create fields textures.

Link to comment
Share on other sites

Ok, I found the solution which was very very stupid ... Misuse method parameters ... Normal texture and dynamic texture.

For a normal texture :

// Wrong: mesh.material.diffuseTexture = new BABYLON.Texture("./index.png", scene, true, false);mesh.material.diffuseTexture = new BABYLON.Texture("./index.png", scene);

For a dynamic texture

// Wrong// mesh.material.diffuseTexture = new BABYLON.DynamicTexture("Skin", 1024, scene);// ---// mesh.material.diffuseTexture.update();mesh.material.diffuseTexture = new BABYLON.DynamicTexture("Skin", 1024, scene, true);// ---mesh.material.diffuseTexture.update(true);

I feel really stupid, but thank you very much for your help.

Link to comment
Share on other sites

  • 3 years later...

Hello @Iwaa-kun I have the same job for replace texture dynamically but on PBR GlTF loader,

This my code: 

var meshes = scene.meshes;
for(var i=0, len=meshes.length; i < len; i++){
     if (meshes.material) {
          meshes.material.albedoTexture = new BABYLON.DynamicTexture('assets/JRO_Copper_02/lambert1_baseColor.jpg', 2048, scene);
          meshes.material.albedoTexture.update();
     }
}

It load fine, but the texture is has inversed RGB color, any idea @Pierre Glibert ?

thanks to babylonJS team and everyone for this thread.

Link to comment
Share on other sites

  • 1 year later...

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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