Viewer API Utility Updates

(Shaderbytes) #1

Hey there Everyone

I have made two recent enhancements to the viewer api utility :

  1. Handling null color properties returned from the sketchfab api. If the object is null I will create one for it.

  2. When doing texture injection using the setTexture function and the "texture" property returned from the sketchfab api is null, I was creating one for it. The problem I found was that apart from the uid which is set after actual image is sent to the server, the default properties of this newly created texture object did not always work correctly on all models.

Namely the texCoordUnit was to blame here. I was initializing it with a value of 1 which worked on some models but found sometime this did not work and I had to set it to 0. Im almost sure I have also seen this property be an array sometimes. With this in mind I solved the problem by adding an additional optional argument to the setTexture function. you can pass in an object with any properties you want injected as defaults. The code will first set all the defaults defined in the Utility and then it will validate if you passed in an object to override any of these defaults with your own using a for in loop.

This two step process means you do not need to specify all the properties for a texture. You only need to specify the ones you want to overwrite.

Example :

sketchfabAPIUtility.setTexture("your_material_name", sketchfabAPIUtility.AlbedoPBR, 'your_image_url', {texCoordUnit:1});

(Shaderbytes) #2

Hi Again

I have added some abstraction for annotations :

The current Sketchfab API only has a means to set a specific index. I have added in some code to not have to worry about the indexing at all namely :


the Utility will pre process the annotations from the sketchfab API to handle the indexing for you and uses circular navigation.

these functions will also populate a property on the Utility for the current Annotation object namely:


This is helpful for if you want to get the name and description of the current annotation you have just navigated to.

I also wrapped the existing functionality to go to a specific index namely:


The added benefit is that it will set the currentAnnotationObject like the other two functions but also it has some additional logic to validate if you have passed in a number and also caps the ranges so you wont get an out of range error if you make a mistake setting the index.

example page :


Viewer API: animation play pause
(Shaderbytes) #3

Hi again I have added two new features :

lookat (nodeName, [direction],[distance], [duration], [callback])
translate (nodeName, [direction],[distance], [duration], [easing], [callback])

Using just the node name these are very convenient.

Internally The lookat function will get the node object and pull the position out of the matrix. Direction is the view angle to this position and distance is the direction scalar.

I have added in the six common directions namely :


these are arrays with three values for x,y,z.

So example :

sketchfabAPIUtility.lookat(nodeName, sketchfabAPIUtility.vectorForward);

I also added another helper function to get combined directions with ease (simple addition):

sketchfabAPIUtility.lookat(nodeName, sketchfabAPIUtility.combineVectorDirections(sketchfabAPIUtility.vectorForward,sketchfabAPIUtility.vectorUp));

of coarse you can pass in a custom direction if you dont want to use these axis aligned vectors.

example page :

For the translate function , the arguments are similar. Direction and distance. Internally this function will also make sure to overwrite the existing matrix values each time you make a move so each call is relevant to the current new position.

sketchfabAPIUtility.translate(nodeName, sketchfabAPIUtility.vectorForward,2);

same as before , you can pass a custom direction if you like.

example page :

(Edsahergom) #4

Hi, I am trying to use the lookat function. It was working fine yesterday and suddenly it stopped working. No error is displayed in the console. Is there any internal problem with sketchFab API. It is strange that suddenly it didnt work any more.



Thanks for the report, we're investigating!

SketchfabAPIUtility update?
(Edsahergom) #6

Thanks, I just checked again and it is working again. However, now the camera moves twice as fast as it just to. Can this be fixed?

(Edsahergom) #7

I am changing the duration but the function is not recognizing it. Doesnt matter if I put 1 or 1000, it moves at the same speed.