Hi @alex ,thank you for the reference! I’m currently trying to apply materials to specific objects in speckle. The workflow is:
- Upload objects from rhino. These objects have custom userString obj_id attached to them. The objects are structured inside a layer named ‘regions’.
- I have constructed a dictionary of colors for each obj_id, this is a color representation of a value (E.g. footprint, temperature etc)
It seems that the speckle API 2.0 has changed quite a bit from the example in this thread. Could you please provide some guidance on how I can achieve this?
This is how my current function looks like:
function applyMaterial() {
if (!speckleViewer) return;
// Walking the tree and finding 'regions' objects
speckleViewer.getWorldTree().walk((node: TreeNode) => {
if (node.parent?.model?.raw?.name == 'regions') {
const renderTree = speckleViewer.getWorldTree().getRenderTree();
const rvs = renderTree.getRenderViewsForNode(node);
if (node.model.raw.userStrings) {
const material = new THREE.MeshStandardMaterial({
color: new THREE.Color(colors[node.model.raw.userStrings.ObjectId]), // Hexadecimal color
opacity: 1,
transparent: true, // Set to true if opacity < 1
roughness: 1,
metalness: 0,
});
speckleViewer.getRenderer().setMaterial(rvs, material);
}
}
return true;
});
The issue is, it seems that the renderView returned is the same for all the regions node. Meaning that it just changed the color of the whole objects inside the regions layer. I’m not sure how to fix this.
I also need the functionality to resetMaterial to what it was previously.
Thanks in advance for any help you could provide!