Reputation: 2243
I am trying to build a feature to select multiple objects with a different colour to differentiate their status.
Is this possible to have multi-selection in a different colour?
Upvotes: 0
Views: 194
Reputation: 662
You can use some sort of mapping to do this elegantly. If you have an object that describes a dbId and a status you can map from status to color automaticly. You can use enums for more type safety but this is ommited for this example.:
typescript:
interface ItemStatus{
dbId: number,
status: string
}
let statusColors: { [key: string]: string; } = {};
statusColors['INITIATED'] = "#0000FF";
statusColors['COMPLETED'] = "#00FF00";
statusColors['FAILED'] = "#FF0000";
let items: ItemStatus[] = [{ dbId: 1, status: 'INITIATED' }, { dbId: 2, status: 'COMPLETED' }]
// add color to items
setColor(items)
// select colored items
this.viewer.select(items.map(x => x.dbId));
function setColor(items: ItemStatus[]) : void{
items.forEach(item => {
// setThemingColor requires we a THREE.Vector4 so we have to provide it
// using our hex color we generate a THREE.Color object and assign the 4th value of THREE.Vector4 manually to 1
let color = new THREE.Color(statusColors[item.status]);
this.viewer.setThemingColor(item.dbId, new THREE.Vector4(color.r, color.g, color.b, 1))
})
}
Upvotes: 1
Reputation: 823
You can just pass the different color for different dbid in
viewer.setThemingColor();
Related helpful blogs:
https://forge.autodesk.com/blog/happy-easter-setthemingcolor-model-material https://forge.autodesk.com/blog/revisiting-viewers-theming-coloring-selective-cancelling-deferred-rendering-and-recursive
Upvotes: 0