Set/unset face colors
To set the face color of one or more nodes you can use the setNodesFaceColor function. Provide
setNodesFaceColor() with a
NodeId array and a color to set all the array elements faces to that color.
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.
Several nodes’ faces in the model on the right have been colored black
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.
Several nodes’ lines in the model on the right have been colored red
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
getNodesEffectiveLineColor() 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 node ID to color and uses it with
Several nodes on the right have been colored using a color map
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 color map for the specified
ElementType. Note that the array will only contain entries for nodes colored using
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.
MeshId, we can create a
meshInstanceData object, before doing this we can specify the color and other properties of the points.
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.
Cube made of blue sphere points
Cube made of red square 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.
Several nodes on the right have had their opacity set to 0.3
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.
To reset the opacity of specific nodes use resetNodesOpacity. The opacity of all nodes in a model can be reset with resetModelOpacity().
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.
Several nodes on the right have been 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().
Several nodes on the right have been hidden using a visibility map