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 scene.show is false. I’m assuming this is not an intended design so I’m implementing the last version specified below.
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…
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(
viewer,
studioCamera,
filename = false
) => {
const current = await viewer.scene.camera.get().data;
const images = [];
for (const position of studioCamera["Photoshoot"]) {
await viewer.scene.camera.updateAsync(studioCamera[position], {duration: 1});
images.push(
// 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 viewer.scene.camera.updateAsync(current, {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.
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.