Set/Unset Face Colors
The following code gets NodeIds from the selection in webviewer and sets the color of the nodes' faces to black. Multiple nodes can be selected by holding ctrl while left clicking.
To unset the face color of nodes you can call unsetNodesFaceColor() and provide it the array of NodeIds whose color you want to unset.
You can get nodes' face color with getNodesFaceColor() or getNodesEffectiveFaceColor(). Both functions take an array of NodeIds and return a promise containing a color array. getNodesFaceColor() will return colors set using setNodesFaceColor(), but if a node's color hasn't been set this function will return null at that index in the array. getNodesEffectiveFaceColor() will return the set color, but if not color has been set it will return the color specified when the model was authored.
You can also retrieve the color of a specific face on a node with getNodeEffectiveFaceColor(). This function takes a partId and a faceIndex then returns a promise containing the color of the specified face.
Set/Unset Line Colors
To set the line color of a one or more nodes the setNodesLineColor() function can be used. Provide setNodesLineColor() with a NodeId array and a color to set all the listed nodes' lines to that color.
The following code gets NodeIds from the selection in webviewer and sets their line color to red. Multiple nodes can be selected by holding ctrl while left clicking.
To unset the nodes line color call the unsetNodesLineColor() function and pass it an array of node ids whose color you wish to unset.
You can retrieve the current color of several nodes' lines with getNodesLineColor() or getNodesEffectiveLineColor(). For getNodesLineColor() pass in a NodeId array and the function will return a promise containing a color array for the nodes' lines, note that it will return null for nodes that have not had their line color set. The getNodesEffectiveLineColor() function takes a NodeId array and returns a promise containing a color array with an element for each node in the argument array. For this function, if no line color has been set it will return the color of the line that was specified when the model was authored.
To get the color from a specific line element of a node call getNodeEffectiveLineColor() and pass it a PartId and a lineIndex. The function will return a promise containing the color of the line element at the input index.
Reset Node Face and Line Color
To reset all nodes' faces and lines back to their default color call resetNodesColor(). This will also reset colors set using a color map as described in the next section.
Communicator gives users the ability to color many nodes at once with the setNodesColors(). By providing the function with a map (from NodeId to Color) it will color nodes in the model with a specific color. setNodesColors() also takes an optional third argument, in the form of a boolean, that will also apply the color from the map to the models lines.
The code below creates a map from NodeID to Color and uses it with setNodesColors():
Color maps can be obtained from models with the getNodeColorMap() function. The first argument to the function is the startNodeId. This is the starting node to walk from to build the color map. The second argument is an ElementType (faces, lines or points). The function will return a colorMap for the specified ElementType. Note that the array will only contain entries for nodes colored using setNodesColors().
When creating a mesh instance composed of points several properties can be set. The function below generates data that can be used to create a cube mesh instance made of many points.
Using the function from above we create a mesh and obtain a MeshId.
In the code above the color of the points is set to red. The opacity, shape and size of the points are also specified. The images below demonstrate the effect these settings can have on meshes composed of points.
The transparency of several nodes can be set at once using setNodesOpacity(). The first argument to setNodesOpacity() is a NodeId array and the second argument is the opacity to set the nodes to. The value of the second argument should be in the range 0.0 to 1.0, with values near 0.0 being more transparent and values nearing 1.0 being more opaque.
To get the opacity of several nodes use either getNodesOpacity() or getNodesEffectiveOpacity(). getNodesOpacity() requires a NodeId array as input and will return a promise containing an array of opacities for each node. The value will only be returned for nodes whose opacities have been set. getNodesEffectiveOpacity() takes a NodeId array and an ElementType as input and returns the opacity for the specified elements of the input nodes. If the nodes opacity has not been set this function will return the opacity for the node as it specified when it was authored.
The visibility of nodes can be disabled or enabled by using setNodesVisibility(). The first argument to the function is a NodeId array. The second argument is a boolean that determines if nodes will be visible or hidden. The third argument is a boolean and is optional it will control if initially hidden geometries will stay hidden.
You can get the visibility setting of a node using getNodeVisibility().
The visibility of all nodes can be reset with resetNodesVisibility().
Node visibilities can also be set using a map (from node id to boolean) using setNodesVisibilities().