Web SDK Reference - Context
Use the methods below on the context object: see the Create context reference documentation.
Method setValue
The method setValue()
allows to update the value of a parameter.
setValue(
parameterId: string,
value: string | number
): void,
Parameters
Name | Type | Description |
---|---|---|
parameterId |
| The ID of the parameter, unique in the product. Can be retrieved from the parameter HTML element or parameter data. |
value |
| New parameter value to set. |
Example usage
context.setValue("52-wheel-patterns-38-select-a-pattern", "Cross");
Method save
Calling the save()
method stores the current product configuration (i.e. parameter settings) on the Twikit server. An overview of all stored configurations can be viewed at https://configurations.twikit.com.
save(callback : (err? , data) => void): void
Example usage
context.save(function(err, data) {
if (err) {
// An error happened while saving the configuration.
}
console.log('Configuration ID:', data.configurationId);
console.log('Preview URL:', data.previewUrl);
console.log('Data sent to Twikit', saveData.savedData);
});
Method setEnvironment (not fully supported)
context.setEnvironment
can be called to select a predefined environment. The environment contains all settings regarding:
3D scene
Camera
Animations
Rendering effects (ambient occlusion, bloom, blur, …)
setEnvironment(name: string): void
Example usage
context.setEnvironment("myEnvironmentName")
This method is not fully supported yet in the current version of the software.
Method renderPreview
The method context.renderPreview()
can be called to render a preview image of the current 3D view.
renderPreview(options, callback): void
Parameters
Name | Type | Description |
---|---|---|
options | | Rendering options.
CODE
|
- |
| Callback function that is called when preview image is rendered. |
Example usage
IRenderPreviewOptions: {
backgroundColor?: string;
resolution?: { height: number, width: number };
cameraState?: { pitch: number, yaw: number, roll, number, zoomDistance: number };
download?: { fileName: string } | boolean;
}
renderPreview(
{
backgroundColor: '#123422',
resolution: { height: 70, width: 100},
cameraState: { pitch: 30 /* deg */, yaw: 60 /* deg */, roll: 90 /* deg */, zoomDistance: 300 /* mm */ },
download?: { fileName: string } | boolean;
},
function(base64EncodedImageUrl) {
// Store image.
}
);