Hello !
I am very new to Speckle, js, and typescript and I am trying to use Speckle Viewer new API. I would like to change the color of selected objects, to display various temperatures in a house for example. I used the function “setUserObjectColors()” and it is working. But then I wanted to display various colors by using a slider from “tweakpane”, but the color of the object stayed the same. I tried to use “removeUserObjectColors()” and “removeColorFilter()” before changing the colors, but no chance.
I was wondering if I need to use “material.needsupdate = true” for three.js ? If this is the case, I don’t know how to use it in the viewer-sandbox project, and would greatly appreciate any help
My code in Sandbox.ts:
public makeTemperatureUI() {
const container = this.tabs.pages[6];
container
.addInput(this.temperaturesParams, 'Slider', {
label: 'Slider',
step: 1,
min: 0,
max: 40
})
.on('change',(value) => {
this.viewer.getExtension(FilteringExtension).removeUserObjectColors()
this.viewer.getExtension(FilteringExtension).setUserObjectColors([{objectIds: [this.objectId], color: this.temperature_to_color(this.temperaturesParams.Slider)}])
})
public getObjectId(node: TreeNode){
return [node.model.id]
}
public temperature_to_color(temp: number){
let res_color = "#b8cc33"
if (temp <= 18){
res_color = "#33c2cc"
}
else if (temp >=26){
res_color = "#cc3333"
}
return res_color;
}
Thanks !