UI button to upload image using external plugins

Hi,

we are trying to upload image texture and apply to the mesh, am trying to add UI control to upload image.
i checked this link its working out.

I tried this approach but no luck

can somebody look into this
Thanks
vijay

You were trying to change the texture of the material of the mesh named “Wolf3D_Outfit_Top.005”.
This mesh doesn’t exist in your model.
Also, there is no sense in assigning any material to the root mesh newMeshes[0].
Here is the example with changing texture - https://playground.babylonjs.com/#JHRF6T#452
Please note that the shirt consists of several meshes, so you’ll need to change texture for all of them.

1 Like

@labris am looking for UI control Button to upload image from the sys, then append the image to the mesh.

Here you are - https://playground.babylonjs.com/#JHRF6T#453

1 Like

@labris
am looking this kind of feature to upload image with dialog box for selecting the image
image

What is preventing you from using usual HTML in this case? All the mechanics is already in PG, one needs just to add file input, the same way like it is done in Sandbox.

1 Like

I suppose you are looking for an example, are you? I found this one (below) from a recent post.
You would just need to add all actions TbD after file load to assign it to your texture/material.
Hope this helps,

Thanks @mawa almost there…

using theFile object trying to get the file path so that i can pass to shirtTexture object
const shirtTexture = new BABYLON.Texture(“https://fashion-desings.s3.ap-south-1.amazonaws.com/common/casuals/tshirts/userchoice/blue_color.PNG”, scene);

to get file path tried using Window.URL.createObjectURL(theFile); but its not working out

Hi,
Hope you are well. I’m really not a specialist of this. I guess there must be other methods.
I also rushed this PG, It might require some ‘cleaning’ especially for the refreshing of the DOM container/input which seems a bit buggy. I’m sorry, I don’t have too much time this morning but this part shouldn’t be all too hard to fix.

As for your issue, the essential part to understand is that when you are uploading a ‘File’ as an input, it actually creates a blob. Problem is a new texture requires a path/URL. So in order to get this url and pass it on to your texture, you’re gonna need two lines of code.

  • One that declares the new BLOB and one that creates the object url for this blob.(lines 34&35 in PG)

I have also added an id to the element. It can eventually help if you need to dispose of it or stuff. I have added some console.log just for your understanding of what data is called.
I hope this helps a little and meanwhile, have a great day :sunglasses:

Edit: Sorry, just edited the link. Was missing the part of assigning user texture to material. Click on your button to apply loaded texture.

2 Likes

Thanks @mawa its done

fine tuned slightly…

2 Likes

@Mawa one small help…

With our existing logic we are using two buttons like ‘choose file’ and ‘upload’ to upload images.
Now we want to use single button(green color) to upload images, Now i changed the logic accordingly.

Seems unless there is event handler we cannot upload image… Any workaround for this
pls suggest

Thanks
vij

Sorry, I don’t have time today and then, as I said, I’m no specialist of that.
Looks like you are willing to use the BJS gui to import the file. I don’t know if and how you can import directly in the canvas using the BJS GUI only. I suppose so but would need to investigate. May be better to try ask someone more knowledgeable than me for that. @carolhmj
I’m sorry but today and tomorrow will be a bit complicated for me so I will have to let the others enlighten you this. Meanwhile, have a great day :sunglasses:

You can do it like this:

4 Likes