The ShapeDiver viewer comes with many global settings that can be set independently of the contents of the current model. One can get a list of those settings with their description by calling
api.getSettingDefinitions();
There are two ways to update those settings: using the dot notation or using the settings javascript object. The dot notation is the easiest way to update a single setting, while using the javascript object is more convenient when one wants to update multiple settings at once.
Updating a single setting
Each setting has a name in dot notation, which can be used to update it. For instance, let's consider the toggle setting used to enable or disable shadows:
scene.render.shadows: {description: "Enable / disable shadows for rendering", type: "boolean"}
One can disable shadows in the scene by simply calling
api.updateSettingAsync('scene.render.shadows', false);
Like all asynchronous functions from the API, it returns a promise which resolves when the scene is updated with the new changes visible.
Updating multiple settings
When loading the viewer, one wants to set the settings according to the needs of their application. This often means updating multiple settings at once. Of course, it is always possible to call updateSettingAsync() several times and wait for all promises to return before proceeding with the next steps. However, there is a more convenient and more efficient way to do so by calling a single API command.
Internally, the viewer settings are stored in a single javascript object which can be read by calling
var settings = api.getSettings();
The returned object contains all the current settings values. One can update multiple settings at once by storing them in a full or partial settings object.
var updatedSettings = {
scene : {
render : {
shadows : false
},
camera : {
rotationSpeed : 2
}
}
}
Use this object with the command updateSettingsAsync() (note the added 's'!).
api.updateSettingsAsync(updatedSettings);
Full settings list
Find the list of all the settings that can be adjusted in the ShapeDiver viewer here.
Updating the default settings
The initial call to getSettings() returns the default values that were defined by the model owner on the ShapeDiver platform. The owner can always use his dashboard to update those settings manually and save new default values (see the model Edit mode). It is also possible to do via the API using the following command after updating the settings object:
api.saveSettingsAsync();
However, note that this operation is only possible using the author ticket, as opposed to the standard ticket which only allows to view and interact with a model but not to change its settings.
Comments
0 comments
Article is closed for comments.