Camera Position

I am working on project in which I would need to put 2 different camera views. One that shows interior view and other for the exterior view.

Do you have any API tutorial regarding the usage of cameras and custom views? I found this link article but it is still empty. https://support.shapediver.com/hc/en-us/articles/360021881752-Managing-the-camera
I have also realized that there is a camera revert button in viewer settings but if enabled, it always move camera on starting position, so something doesn’t work there.

Thanks in advanced,

The article about camera updates will be completed soon. In the meantime, you can check the API functions that are available in the API reference.

As a quick introduction, a camera object in the api is a JSON object containing a position and a target:

let cameraObject = {position: {x: 10, y: 10, z: 10}, target: {x: 0, y: 0, z: 0}}

You can always get the current camera object by calling:
api.scene.camera.get()

After you’ve defined camera positions (interior and exterior views for example), you can update the camera with:
api.scene.camera.updateAsync(cameraObject);

Another useful function is api.scene.camera.zoomAsync(), which will make sure the scene is centered and optimally fills the screen. This corresponds to the “Camera Adjust” parameter of the viewer settings.

The article will include more details about the functions and their various options. I’ll post it here when it becomes available.


Regarding the “Camera Revert” setting, it is meant to always move back the model in its default position, as you described. What behaviour did you expect this setting to have instead?

Thank you for the quick introduction to camera setting. Regarding the “Camera Revert”: I think that this tool will be more functional if you include “camera revert” button. For example, looking some object from different point of view and than if you want, you can to revert it to default position with this button .
Right now, I think that it doesn’t have so much sense, because if you are end user and want to see some object by 3d orbiting view, you should probably want to spend some time looking an object from some new point of view. However it is impossible with automatic revert that send you immediately to start position. Simply, I can’t see in which situation this option automatic revert might be useful

The automatic revert was found useful in e-commerce applications, in particular for end users who don’t have much experience interacting with 3d scenes.
The behaviour you want also exists in the viewer, with a perfectible interface I’ll admit. Using the camera button on the top right of the viewer window, a single click will center and zoom on the scene contents, while a double click will revert the camera position to its default position.
image

@mathieu1 just playing around with camera as well and kind of confused by the default direction the camera is pointing. Its looking towards negative X and Y, whereas I would assume the default should be exactly 180 degrees in the other direction.

What would be really nice though would be to actually just be able to set the default camera settings in ShapeDiver. In ShapeDiver I just position the camera where it is nice and then say “set default position”. So right now its easier to just rotate my whole scene at the very end before outputting in Grasshopper.

Also is there a way to set the direction of the shadow? The spotlight seems to be in a fixed position!?

I think its nice to have all these API options, but it would be much nicer to have those options in the backend of ShapeDiver. Not everybody wants to fiddle with Javascript just to adjust those basic things.

I hope some (a lot) of improvements are coming to the ShapeDiver backend, like also saving default camera settings or simply being able to replace a .gh file and not upload again and set everything from scratch when I update a file. Thank you!

Last question about the “Camera Adjust” functionality as it’s not really explained anywhere and has a rather generic name.

So from what I can tell it takes the bounding box center of the scene and sets that as target?

Since the target is usually very easily available in GH already, could you please add a way to pass a camera target to ShapeDiver from within GH?

Otherwise what would be the way to do it? Output it to the API and then use the API to set the target? Is there a way to pass ONLY the target and not the position to the camera?

I think the default position of the camera very much depends on the contents of thes cene. However, it is already possible to set the default camera position and target on ShapeDiver: whenever you are in Edit mode, the current position of the camera when you hit “Save Settings” will be used for the default camera settings of the model. We are aware that this feature should be made more explicit.

In terms of the light and shadow directions, this will be the object of an upcoming update to the viewer. The new viewer settings will allow full control of the light scene, including addition and removal of any type of lights and the possibility to drag and drop the light position and target directly in the 3D scene. This update will be ready in the next few weeks, I will post an update here when it is released.

When it comes to re-uploading models, I just gave an answer in the related topic.

Finally, regarding the Camera Adjust functionality, you are right that it uses the centroid of the bounding box of the scene as a target. We do have plans to add components to the ShapeDiver plugin for controlling camera settings directly from Grasshopper, which should make it more convenient. In the meantime, you can always update camera position and target (independently) using the API camera interface.

1 Like