Export textures from inspector

Working on creating a shared material library where you can define materials and then reuse them across assets using the inspector. In order to save materials to our server, I need to save the textures as well (probably as base64), similar to what I think the inspector does when you add a texture. Can someone point me to the code that does this for the inspector or tell me if there is an easy way to serialize textures to base64? It looks like the serialize on texture just creates a JSON with the texture metadata. I need the raw texture bytes.

Hey! You will need to do a xhr or a fetch of the texture file and then using an array buffer you can convert it into a base64 string

Thanks. I’m trying to understand what the workflow would look like. FWICT, when you use inspector to specify a texture for a material, the only option is to choose a local file; there is no option to select a URL. The texture file appears to get converted to base64 and uploaded to a babylon server Then, when I save the material, I can grab all of the textures from the babylon urls and save those to our asset store. Now when I load the materials, the textures will all point to urls in our asset store. However, if a user chooses to replace a texture, they will have to choose a texture on the local file system and then it will get uploaded to babylon. Also, I wonder if the base64 texture will be less compressed than the original PNG file, etc… and will therefore take up more bandwidth when downloaded.

Ideally, I would provide some way for our users to upload textures in raw form to our asset store and then in inspector I would let them select an uploaded texture. Is there a way for me to customize the inspector behavior for selecting textures or for uploading textures. Is there some other way to achieve our objectives?

base64 is not a good format for size but it is the only one we can use to easily embed an image

If you have control over a server, I could add a way in the inspector to provide an url instead of just loading a local file. babylonjs will then store only the url in the texture and you will be responsible for storing that texture on your server.

Does that work?

Yes. The ability to specify textures in the inspector via URL would be awesome and would meet our needs nicely.

Ok please open an issue for it then

Is this in the 4.1.0-beta.18 build? I tried it in playground and I’m not seeing a way to specify a texture URL.

I see it now. When I open the texture properties on the right side, I see the option to specify the url. But how do I link those textures with a material. When I click on the material the texture buttons (e.g. Albedo, etc…) all open a file browser. Is there a way in inspector to associate a texture with a material, without browsing to the texture file?

Also when I do update a texture URL, the texture node name does not change in the inspector. Is there a way to update the node name with the URL?

This is not available directly as we do not have inputs for it directly in the material pane.

Would you be willing to create a PR ?

Possibly. I think what I would like to see is that the channel buttons give you an option to select a texture already in the tree, or a new texture (specified either by file or by URL). I could just replicate this in our admin app, but I like the idea of using the inspector as it tracks the capabilities of the engine (i.e. if a new channel is added, it would be available to our users immediately if we leverage the inspector as part of our admin app).

The thing is we only have one link to open the properties, I wonder how we could make fit a second one in ?