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.
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,

1 Like

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:

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

Another useful function is, 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.

@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

Hi @mathieu1,

I saw this post and thought I could add my question here as well.

The camera movement works very well for me. To make things more comfortably, I saw that there is a variable called CameraType that has all the standard perspectives (‘top’, ‘front’…). However, I have not figured out how to use this variable yet.

Say I want to have the perspective view for {x:100, y:100, z:0}. How would I do that with the embedded functionality? I know how to do it manually with my own values for cameraPos and targetPos and the function{cameraPos, targetPos})

So this would just make things more comfortable and it’s better if I do not implement my own function for that if the functionality already exists. Thank you!


The link you are using was a bit outdated. Always check for the latest API documentation.

Since the version 2.17, the camera interface has been completely updated with support for orthographic views. You can switch the camera by calling:

api.updateSettingAsync('', X)

where X is the CameraType index that you had mentioned (0 is the perspective camera, 1 through 6 are orthographic side views).