Model is loaded immediately after the page loads - how can I change it?

viewer-api
api

(Empe2301) #1

Hi

I have problem with correct display 3d model. I want to load the model until you click on it. Now a model loads immediately after the page loads and it isn't good solution for me. I read that autostart = 0 is the default values, so why it does not work? When I add autostart: 0 also does not help
Below is my code. Urlid is an exemplary model.
Thanks for any tip.

<head>
    <script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="https://d1jlf623bx36qa.cloudfront.net/api/sketchfab-viewer-1.0.0.js"></script>
    <script src="SketchfabAPIUtility.js"></script>
 </head>

<body>

  <iframe src="" id="api-frame" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>

  <script type="text/javascript">
    sketchfabAPIUtility = new SketchfabAPIUtility("f5427bf0d62449f2943fc904a1ae082a", document.getElementById('api-frame'), onSketchfabUtilityReady);


    var cameraPos = $('#camera'),
        targetPos = $('#target'),
        urlid,
        version = '1.0.0',
        iframe = $('#api-frame')[0],
        api

    function onSketchfabUtilityReady() {

        api = sketchfabAPIUtility.api

  }
  </script>
</body>

#2

You can add parameters like autostart during initialization:

client.init( 'MODEL_UID', {
    success: success,
    error: error,
    autostart: 0,
    autospin: 0.5
} );

However, I have not used the sketchfabAPIUtility very much, so I don't know how @shaderbytes handles this.


(Shaderbytes) #3

Hi @empe2301 sorry about that , I was starting the api via code in my utility. I realize now this should be removed and have removed it so just grab a fresh copy of the utility from github.

You can still cause an auto start if you like by adding in the autostart:1 variable of the optional init object passed to the constructor.


(Shaderbytes) #4

@james

my utility take an optional last argument in the constructor. This argument can be an object with any of the init variables you which to have injected :slight_smile:
eg :

var sketchfabAPIUtility = new SketchfabAPIUtility('sketchfabmodelid', iframeDomObject, callback, { autostart:1 });

you can obviously add multiple params to the object , I handle it internally and loop them onto my own controlled object since the success and error variables I take control of , injecting those two variables will not work. all the rest are good.


#5

Great, thanks for the quick fix and clarification. Sounds good.


(Empe2301) #6

Ok, thanks, it works perfectly now :slight_smile:


(Edsahergom) #7

Hello, I am having the same problem. Even though I took a fresh utility it is starting itself but I dont want so. Could you help me? Thanks.


(Shaderbytes) #8

Yes I added the call to api.start back into the utility because sketchfab currently has problems when using init options to autostart. The issue being it never sends the viewer ready event. It is not a consistent bug but it is there non the less and the best fix for now was to just call api.start again.

You can comment that line of code out yourself if you like , i think it is on line 88 " classScope.api.start();" , just put a double forward slash in front of it


(Edsahergom) #9

Thank you for your help. It worked. Do you know if I can use this code (https://sketchfab.com/developers/viewer/startstop) even though I am using the SketchfabAPIUtility?

Thanks again.


(Edsahergom) #10

Hello, I could solve it. Thanks.