Sketchfab Forum

Cannot set material texture to null again

(Shaderbytes) #1

Hey there

Seems some regressive bug has crept in somewhere as I cant clear a texture on a material channel anymore?

setting the channel texture property to null and deleting it cause this in the console :

viewer-d6a1f9b6d412c8b49b10.js:1 “channels.AlbedoPBR” should match exactly one schema in oneOf
setJSON @ viewer-d6a1f9b6d412c8b49b10.js:1
setMaterialJSON @ viewer-d6a1f9b6d412c8b49b10.js:1
setMaterial @ embed-5fbcc9cfa71cf24ae1e3.js:1
(anonymous) @ embed-5fbcc9cfa71cf24ae1e3.js:1
r @ vendors-e01612df71f33eb0a801.js:58
20:14:42.770 viewer-d6a1f9b6d412c8b49b10.js:1 Failed to validate json {enable: true, factor: 1}
setJSON @ viewer-d6a1f9b6d412c8b49b10.js:1
setChannelJSON @ viewer-d6a1f9b6d412c8b49b10.js:1
setChannelJSON @ viewer-d6a1f9b6d412c8b49b10.js:1
setMaterialJSON @ viewer-d6a1f9b6d412c8b49b10.js:1
setMaterial @ embed-5fbcc9cfa71cf24ae1e3.js:1
(anonymous) @ embed-5fbcc9cfa71cf24ae1e3.js:1
r @ vendors-e01612df71f33eb0a801.js:58
20:14:42.773 viewer-d6a1f9b6d412c8b49b10.js:1 AlbedoPBR: should match exactly one schema in oneOf

(Shaderbytes) #2

here is my test codepen :

I was developing two things requested by users at the same time 1. to cache the scene textures in a useable manner just like uploaded textures. I have this working.

The second issue was for another user that found is was not straight forward to just remove a scene texture from an object , my remove system only factored in uploaded textures. Anyway they found a way around it but I said I would change up the functions so that it is straight forward to just remove a texture. This is what is not working now???


in the utility :

 this.removeTextureFromMaterialChannel = function (materialName,channelPropertyName) {

        var materialObjectRef = classScope.getMaterialObject(materialName);
        if (materialObjectRef !== null && materialObjectRef !== undefined) {
            var channelObjectRef = classScope.getChannelObject(materialObjectRef, channelPropertyName);
            if (channelObjectRef !== null && channelObjectRef !== undefined) {
                channelObjectRef.texture = null;
                delete channelObjectRef.texture;

thanks gents

(Shaderbytes) #3

hey all

I did some more investigating today and have found out more concerning this issue.

So if a scene material channel has a texture assigned to it in the editor (AlbedoPBR) , at runtime the scene graph object for that channel does not have a color property.

So if as above i try remove the texture property ( setting to null and deleting ) I get the console warnings shown above and also nothing happens in the scene.

I then tested setting a color for the channel just before I remove the texture. As mentioned the color property does not exist so i just create it and set it.

This works and the color is set and the texture is removed. I still get the console warnings though which is not good.

So next I thought let me just test setting a color and not deleting the texture , thinking perhaps it is just a preference condition in your engine. This did not work.

So to end the final conclusion to remove a scene texture from a channel (AlbedoPBR) :

• You have to create and set the color property on the channel before deleting the texture.
• You have to remove/delete the texture property of the channel ( this is expected )
• You can expect the same warnings in the console, exactly the same as if you tried to remove the texture without first setting the color. ( only difference is something actually happens in the scene now at least )

Also I tried to leave the texture object in place and just “null | undefined | 0” the uid property value, this removed the warnings but produced an error " cannot find image model of “null | undefined | 0” so that was not possible.

Seems you cant escape those warnings. This needs to be looked into obviously :wink:

Ideally I cant think why you omit the color property even when a texture is set in the editor. I would expect you can set the color , the color will persist and then you can set a texture as well.

The texture would just take precedence and if it exists it is used and color ignored ( not left out ) The data size to keep the color around is trivial.

Then if you remove the texture via the api the color of the channel would be what was set in the editor. If it was not manually set it would default to you near white value you currently use in the editor already. No need to create and set a color via code at runtime just to be able to remove a texture. The color property should always be there, and there should be no console warning when doing this.

(Shaderbytes) #4

weekend posting bumped in work week :wink: