Behaviour of camera.updateAsync with optional transition duration parameter

It seems that if you pass duration zero as an optional transition parameter, you don’t get a promise?

This doesn’t work:
await, {duration: 0});

This works:
await, {duration: 1});

Observed when creating viewports related to this behaviour:

If a duration of zero is specified, you can call camera.updateAsync (on a viewport object) while is false. I’m assuming this is not an intended design so I’m implementing the last version specified below.

This seems to work:

await, {duration: 0});
await api.updateSettingAsync("", true);

This won’t:

await api.updateSettingAsync("", true);

Nor this:

await, {duration: 1});
await api.updateSettingAsync("", true);

I’m assuming below is the expected implementation - is true when calling camera.updateAsync:

await api.updateSettingAsync("", true);
await, {duration: 1});

Use case: matching the viewport to an image (loading placeholder).

@winston I tested this, what is it that doesn’t work for you?

It works but the behaviour is different. I’m guessing it’s not returning a promise as you can’t await it in an async function.

It’s a specific use case and I’ve solved it by setting a duration of 1 (as per my previous response) but, I considered it unexpected (not async) so I thought to mention it. I guessed maybe 0 was being read as a boolean or something…

It seems to return a promise as expected:


Am I missing something?

Hmmm, I must be missing something. I had figured it might be a promise issue but apparently didn’t look into it enough.

Where I’ve noticed this:

  • When running a sequence of multiple camera.updateAsyncs or when another API function precedes or follows an await camera.updateAsync with the duration set to zero.

For example:

I have a photoshoot function that runs a for…of loop of camera positions. It takes a screenshot (via scene.getScreenshot) of a given position, pushes the image into an array, and moves to the next position. If I have the duration set to 0, all the screenshots are the same but if I set the duration to 1, it works as expected. See below:

// generate an array of image objects
// based on a studioCamera's photoshoot positions property
// studioCamera object stores a series of set positions and
// it's photoshoot property references the positions used in a photoshoot
const usePhotoshoot = async(
  filename = false
) => {
  const current = await;
  const images = [];
  for (const position of studioCamera["Photoshoot"]) {
   await[position], {duration: 1});
     // useTakeShot takes a screenshot - scene.getScreenshot()
     // then separates the base64 string for type and data attributes
     // to create an image object
     useTakeShot(viewer, position, filename)
  await, {duration: 1});
  return images;

I’m thinking that perhaps the only time I’ve noticed an issue is when I’m combining camera.updateAsync with another API function in an async function. I’ve had some other functions (in addition to usePhotoshoot) where I’ve noticed that I can’t rely on await …camera.updateAsync with duration of 0.

It might be that the redrawing doesn’t happen immediately if you use camera.updateAsync with duration 0. You could try to use scene.render()

Thanks Alexander.

I have tried using scene.render in some places but semantically, I prefer using duration: 1. I don’t like seeing extra scene.render calls just because I want to rely on an asynchronous camera update without a transition.

It’s a small thing and it hasn’t hindered my app’s functionality - I just considered the behaviour unexpected.

Actually, you bring up a good point. It might work with duration: 1 only because of process luck (i.e. whatever process needs to happen for it to work finishes within 1ms - given the environment).

I’ll look further into this at some point as, although I appreciate a bit of luck, I don’t want to count on it.

Many thanks for your feedback. We will review whether there is an obvious problem for duration 0.

Which version of the viewer are you using?

I’m using 2.22.0 but will update to the latest now

yes please let us know whether this also happens in the latest version