Updates to API Utility


(Shaderbytes) #1

Hey all

Updates all around :smile:

• The documentation examples all updated to viewer 1.4.2.
• The Utility updated on github to version 3.0.0.0

Some changes in the Utility.

For click events the names of the “parentgroup” and “parentMatrixTransform” have been changed to “firstAncestorOfTypeMatrixTransform” , “firstAncestorOfTypeGroup”

Some of the texture uploading functions were changed in that a cachKey , is no not optional. Also the Argument was renamed to UIDKey.

The textures loaded with the viewer are now pushed into the cache on load ( using their names , without extension , as the keys )

There is a new example in the docs to show this functionality

There is now a means to simply remove a texture from any channel and it is not coupled with the caching system as before.

All the documentation has been updated to reflect all changes :

For the new click event properties :

For texture workflow enhancements and new example for scene textures :

enjoys


#2

Hi @shaderbytes

Thanks for your continued work on your utility.

The new updates broke a couple of things for me regarding setting material colour and swapping textures, although now I’ve figured it out, its definitely improved. In doing so, I found a couple of differences with what works compared to your documentation.

In order to change material colour I am first removing the applied texture. To do this, rather than:

sketchfabAPIUtilityInstance.removeTexture(“material_name_here”,sketchfabAPIUtilityInstance.AlbedoPBR);

I had to use:

sketchfabAPIUtilityInstance.removeTextureFromMaterialChannel(“material_name_here”,sketchfabAPIUtilityInstance.AlbedoPBR);

To apply a cached material, I’ve found that the documented syntax doesn’t seem to work:

sketchfabAPIUtilityInstance.applyMaterialUIDPending(“cache_id”);

but this still does:

sketchfabAPIUtilityInstance.setMaterialUIDPending(“material_name_here”,sketchfabAPIUtilityInstance.AlbedoPBR,“cache_id”);

The latter could be due to the weird way I’ve set things up with pre-cached textures, but if you find its more universal then I hope it helps. I’m using the Viewer API 1.4.2 and version 3.0.0.0 of the utility.

Best regards


(Shaderbytes) #3

hey there ,
yeah sketchfab made some horrible changes to their api so that it is impossible to have a texture and a color object exist at the same time. I tried to reason with them and ask why cant the color object just always be there and then if a texture object exists as well then it just take preference …I cant fault such logic and it would make life much more easy but they did not listen and said they had reasons for their choice. So i had not updated the tool online with the changes but I had them locally so I quickly updated the tool now , so it will remove a texture or color depending on what you are setting automatically so it works.

im not sure about the other error , i will have a look but the first syntax is only shown in relation to using scene loaded textures anyways. Also for dynamic or scene loaded textures you still always need to call setMaterialUIDPending otherwise calling applyMaterialUIDPending is pointless as nothing is pending so nothing would be applied.

read the docs clearly , it states “To use either scene textures or uploaded textures you need to place materials in a queue” and then proceeds to show the syntax for setMaterialUIDPending. so it clearly state this is always required.

The difference past that is for dynamic textures you call addTexture which will eventually call applyMaterialUIDPending internally.

For scene loaded textures you never have to call addTexture and so that is why the documentation then shows to manually call applyMaterialUIDPending.

The new uploaded version of the tool is 3.0.0.1

hth


#4

Ah, got it, thanks for the clarification.

I had it working with 3.0.0.0, I’ll try with 3.0.0.1 and see if it still goes. If not, it sounds like I’ll need a bit less code anyway with your latest changes.


(Shaderbytes) #5

by the way I added another function to the utility :

rotateOnAxis = function (key, angle,axis) {

this works on the axis local. It is different from the API rotate method in :

• you use a key for the object to target as with all utility functions , no need to know the instanceID
• you use regular degrees for the angle , will convert into radians internally , the sketchfab version needs radians as the argument
• Most importantly it respects the rotation of the object in the scene. The sketchfab version does not respect any baked rotations and the objects get aligned to global space when rotating. My function respects the baked rotations and works on the local axis orientation.

check it out in action here :

https://codepen.io/shaderbytes/pen/eozJVX

I still need to add the docs for this new function , hot off the press :wink: