Remove a texture

(Rowdysign) #1


How can I remove an already present texture in a Sketchfab scene? I would like to remove a texture from an object and then apply a color to it instead.

I could not find information about it in API documentation ( so I tried to edit the material object myself. For instance I set the "Object.texCoordUnitList" and "Object.AlbedoPBR.texture" to false or null but both did not had any effect: the texture was still present in the scene.

Alternate textures for a model?
(Miekeroth) #2

Hi @rowdysign It is actually not that hard. If you know which material the texture belongs to, you can switch between texture and color in the 3d settings of the model it self. So go to the material tab in the 3d settings, select the material the texture is attached to and change the texture into a color clicking the image right before the bar that controls the influence of the texture or color.

(Miekeroth) #3

(Miekeroth) #4

(Rowdysign) #5

Hello Mieke, thank you for your reply, but my question is within the context of the Sketchfab API. I know how to switch between texture and color in the Sketchfab 3D settings interface but I do not know how to do that within the Sketchfab API. The API (Application Programming Interface) allows developers like me to change settings programmatically.

(Miekeroth) #6

OK. well. I am working on that too and the moment I have a working application I will make a tutorial for it. Right now maybe my tutorial for annotations might give you a clue on how to handle it because most of the declarations within the api are similar. The textures are like the nodes actually (of the top of my head). @james made an application for that one. He linked to it in one of my questions about that.
Here the tutorial about annotations:

How to make a real 3d model application

(Miekeroth) #7

Have been thinking of this one further because it is one of the posibilities I want to use too (it is great for my anatomy tutorials :wink: ). Will come back to it tomorrow ok?

(Rowdysign) #8

Great, thank you. I'm looking forward to it. Interesting tutorial you have.

(Shaderbytes) #9

Setting it to null does work , are you remembering to call setMaterial function after making the change? Check out this page I made to test the api a while back , view the source to see the javascript , One button injects textures into the model that were never there before , the other button removes them again ( and some color changing for other materials ) but it is straight forward stuff.

(Rowdysign) #10

Not calling the setMaterial function was indeed the reason why my texture did not disappear. I did not know I had to use setMaterial function to a texture also (I only thought I needed to use setMaterial function in order to set a color).

But now I know, thank you very much! :grinning:

(Shaderbytes) #11

All good , you always have to call it for any change you make , also now you have seen some code on how to construct the texture object of a texture being injected into the api at runtime :wink:

(Vr Go) #12

what i met problem is the texture cannot change but albedo and opacity the normal map can not change,
how can i switch the normal map on/off outside sketchfab editor

(Shaderbytes) #13

you can remove any texture by setting the texture property of the channel to null. You can also change the factor of the channel to zero without removing the texture.

EDIT… dont forget to update the material to the backend as well… making the changes only locally will have no affect on the model


Apologies for reviving an old topic but my question is almost the same, with the difference that I’d like to know if the texture applied via the editor can be replace with a material colour using Shaderbytes API Utility. Is that possible?

I can swap out textures and change colours if no texture is applied in the editor, just a starting base colour, but not if there is. I can’t see how to set texture property to null via the Utility. Setting the material factor to 0, I still can’t change the base colour though I can then see it.

Any pointers greatly appreciated


OK, I got it working but I’m not sure why.

First I set an unused cache key on the onSketchfabUtilityReady function:

function onSketchfabUtilityReady(){
sketchfabAPIUtilityInstance.removeEventListener(sketchfabAPIUtilityInstance.EVENT_INITIALIZED, onSketchfabUtilityReady);	     
// other actual textures assigned subsequent cache keys

Then I called that cache key to remove the non existent texture before setting the colour:

function uiSetPotBlue(){

After that I can toggle back and forth between various textures and colours, but not if a setMaterialUIDPending cache key has not been removed.
Is this the Utility way of setting the texture channel to null, or am I totally off??

Obviosuly just a javascript tinkerer, so grateful if anyone more experienced could point to a better way or let me know what I’m missing

(Shaderbytes) #16

Hey There

Yeah seems a bit of logic could be added to the utility to remove defaults editor textures without the caching system.

Make note there is nothing wrong with your solution , you simply found a means to set the editor texture to null but obviously not in straight forward fashion.

The caching system is very optimized so you only need to actually upload any individual texture once ( it is identified by the cachkey ) then if you call to set that texture again it skips uploading it and simply applies the cached UID of the uploaded texture to the material. The pending system also allows you to set multiple materials and material properties which will all be queued and wait for the UID to return or simply applied in a loop if it is cached.

but I see an additional branch of logic that is required now , i currently always assume removing a texture also means removing the cachkey UID. This logic should be separated into two different actions. One to simply set the material current texture property to null and do nothing to the cached key , and another to remove the cached key.

A bit difficult to explain but I will sort something out and let you know when I have a solution live to try.

chat soon


Hi shaderbytes

Thanks for your reply, that’s good to know. I think it is logical, perhaps a quick reference to this use case in your documentation would be enough. Currently it is a bit confusing when the removal of a cache key on an available texture complete removes that texture from the scene. Removing the empty one seems to working well.

Regarding the caching of textures, is it possible to pre-cache textures without actually setting them? Currently I can see that they only download when first set and then there is no network traffic when re-setting, but for a high resolution texture there is the download time on the first call that causes a delay.

BTW, thanks for everything you have done and continue to do on the sketchfab api utility. I will try to dive into the raw api as well as I make progress, but your work certainly makes it much more readbable and faster to implement.

Best regards

(Shaderbytes) #18

Sure you can upload textures and they will get cached according to the chosen cachekey when complete without you needing or having any pending material updates. So they will just upload and store the UID via the cache key , no material updates. I’m sure that is what you were asking about unless I didnt understand you correctly.

Of coarse this is all run time , meaning while the player is active and the api code is active. You cant cache textures outside of this state. So you still have to upload the required hi-res textures at least once each time the site loads.

chat soon


Yes, that was what I meant. I think I had it all backwards, assuming that setMaterialUIDPending had to be called before addTexture. I’ve got it working now with pre-cached textures, thanks a lot for the pointers!