Sketchfab Forum

API update a texture


(Digitaldraping) #1

Using the updateTexture( textureURL, textureUid, [callback] ) I can update a texture. What I would like to do is to update a texture based on the material name.

For example "Part 2"

Is there a way to do this?

var my_uid = "";

			api.getTextureList( function( err, textures ) {
			    console.log( textures );
			    console.log( textures[1].uid );
			    my_uid = textures[1].uid;

			} );
			    function ( err, textureUid ) {
			        console.log( 'New texture registered with ID ' + textureUid );
			            function ( err, textureUid ) {
			                console.log( 'replaced texture with uid: ' + textureUid );


You should be able to if you use getMaterialList() to get your material names?

(Digitaldraping) #4

Great, that is it. When I called them first onSuccess I was getting no materials. But when I called them using viewerready I was getting the list.

onSuccess must have just been too soon to call them.

api.addEventListener( 'viewerready', function() {
    console.log( 'Viewer is ready' );
    my_api.getMaterialList( function( err, materials ) {
        console.log( materials );
    } );	    
} );

Thank you.


Yep, I think everything should wait until viewerready. success just means the iframe has been initialized.