Color Coding Mesh to show ADA path

I am trying to color code a mesh by triangle slope (to highlight ADA path) but it does not seem to be working. Is this even possible? Is there a different method I could use to approach this. (I can mess around with python if this is the only way.)
SurfaceViewer_V1.dyn (59.5 KB)

I am not sure if this helps but, in this question Color mesh/directshape in different colors based on z-values
the mesh seems like colorized on Dynamo interface. Below the script shows making the mesh seemed colorized in Revit Interface.

1 Like

The MeshDisplay class is built for Mesh Toolkit, so you need to make sure that your mesh is the right kind of mesh - not the default Dynamo mesh. The following bit of Python can help convert things while simplifying rather well, even for meshes which aren’t properly closed (unlikely if your data is coming from Revit or Civil 3D, but possible with other tools).

ConvertToMeshToolkitMesh
########################################
############## Properties ##############
########################################
__author__ = 'Jacob Small'
__version__ = '0.1.0'
__description__ = "Convert a Dynamo mesh element to a mesh toolkit element"
__DynamoBuilds__ = "2.18"
__ReleaseNotes__ = "none"
__Dependancies__ = "Mesh Toolkit"
__Copyright__ = "2024, Autodesk Inc."
__license__ = "Apache 3.0"



########################################
### Configure the Python environment ###
########################################
### standard imports ###
import sys #add the sys class to the Python environment so we can work with the sys objects
import clr #add the CLR (common language runtime) class to the Python environment so we can work with .net libraries
import math #add the Math class to the Python environment so we can do math stuff
import random #add the Random module to the Python environment so we can impersonate a squirrel

### basic Dynamo imports ###
clr.AddReference('ProtoGeometry') #add the Dynamo geometry library to the CLR
from Autodesk.DesignScript import Geometry as DG #add the Dynamo geometry class using the alias DG, to ensure no overlap between class calls in Revit or Dynamo
import Autodesk.Dynamo.MeshToolkit as TM #import the mesh toolkit package as TM to prevent namespace collision
from collections import defaultdict #import the defaultdict class so we can use stuff other than strings as keys to a dictionary



########################################
########### code starts here ###########
########################################
### inputs from dynamo ###
mesh = IN[0] #the Dynamo mesh from the Dynamo environment
positions = mesh.VertexPositions #get the points from the mesh

### build a dictionary with each position as a key ###
positionDict = defaultdict() #build a new defaultdict object
for i in positions: positionDict[i] = None #add each point as a new key

### set the index of each position to it's sequence ###
j = 0 #set j to 0
for key in positionDict.keys(): #for each key in the positionDict
    positionDict[key] = j #set the key's value to the current value of j
    j+=1 #increment j by 1

### generate the index groups ###
indexGroups = [] #create a new list of idnex groups
for faceIndex in mesh.FaceIndices: #for each face index
    indexGroups.append(positionDict[positions[faceIndex.A]]) #get the original mesh's index for index A from the dictioanry and append the value to the list of index groups
    indexGroups.append(positionDict[positions[faceIndex.B]]) #get the original mesh's index for index B from the dictioanry and append the value to the list of index groups
    indexGroups.append(positionDict[positions[faceIndex.C]]) #get the original mesh's index for index C from the dictioanry and append the value to the list of index groups

### generate the list of points ###
pnts = [i for i in positionDict.keys()] #get each key from the positinoDict as a list

### create the toolkit mesh ###
tkMesh = TM.Mesh.ByVerticesAndIndices(pnts, indexGroups) #build mesh toolkit mesh

### return the results to the Dynamo environment ###
OUT = tkMesh #send the toolkit mesh to Dynamo

Once you’ve got a MeshToolkit Mesh object, make sure all your other geometry display is disabled (ctrl+a, right click the background, and select “Hide Geometry Preview”. This will prevent Z Fighting on the display. Now we can start to build the display.

The MeshDisplay.ByMeshColor has 3 ways it can product a mesh:

  • If you provide a single color (as you did here) it will wash the entire mesh with the single color.
  • If you provide a number of colors equal to the number of vertexes it will wash each face by UV mapping the color range between the corresponding vertexes.
  • If you provide a number of colors equal to the number of faces it will wash each face with corresponding color.

The following graph illustrates all 3 methods:

Notice the hard lines present on the ‘Faces’ method:
image

Meanwhile the by verticies blends from vertex color to vertex color:
image

And on the single color, we have… well a single color so not much fun to see.
image

The graph for anyone interested in trying it out (you can swap the Dynamo for Forma nodes for any other mesh selection and extraction nodes - Civil 3D or Revit or…):
Highlight Excessive Slopes.dyn (68.0 KB)

2 Likes

@jacob.small

Thanks for the info. (My code has individual Meshs for each triangle (instead of one.) I was able to make it work by turning off some geometry display (thank you for that tip). The only remaining issue is that is seems like the traingle.grade node is not working 100%. Any ideas. The curb and shown foundation around the building should be 100% slope or grader but that is not coming back true in dynamo.


SurfaceViewer_V3.dyn (65.5 KB)

Bonus snip to see what I am doing.

I don’t recommend using individual triangles as that isn’t very computationally efficient (3*n points for n triangles instead of m points making n triangles), but glad to see you’ve made progress.

I haven’t used Triangle.Grade, is that from a package?

I’m away from the computer for awhile (perhaps the whole weekend), but one guess is that the grade node is t calculating things correctly. Another is that the filtering in Python might be off - a color range node might be better suited there.

1 Like

against your recommendation, I made a mesh from individual triangles. The method you provide requires me to send my geometry FORMA. Can this graph be updated to work with a mesh (toolkit or dynamo) that was built from individual triangles and already lives in the current .dyn.

Or can you confirm that there is some special sauce in FORMA that does something to a mesh, and that is why you are fetching the mesh from FORMA.

This smacks of “works in REVIT but not CIVIL” :slight_smile:

The Toolkit Mesh Package seems to not work with a dynamo mesh made from faces.

@jacob.small

So either FORMA is doing something special to the mesh, or toolkit “mesh by dynamo mesh” is not supported…or the most likely scenarios is I am missing something?

I have built it in sandbox using no special methods, which means it works fine for Revit, Civil 3D, Forma, FormIt, Alias, Advance Steel, Robot…

So something is off somewhere. Post a small subset of your dataset, an indication of which host application you’re in, and your current dynamo graph and I will try to have a look.

I am working in C3D.

Question: does this graph HAVE to start with a terrain from FORMA, or can it start with a mesh made from faces in FORMA?

It can start with a mesh from Civil 3D, Revit, Forma, etc… What you’re seeing from Forma is just me selecting the object and extracting the goemetry. From there I convert to a Toolkit Mesh. In Civil / Revit / whatever else the process is the same. The key part is that you just have to convert the mesh to a toolkit mesh.

1 Like

I see that it does work with a ACAD MESH by select object.
When I try and recreate a dynamo mesh from the triangles of a TIN SURFACE, it is crashing on me. So I suspect there is a bug (or maybe just as likely is that I don’t really know meshes that well as a civil3D user).

Either way, I think there are some improvements to core mesh functionality that I absolutely can’t wait for…Also, side note @jacob.small , are you gonna be watching Spain vs. England tomorrow???

Don’t pull the triangles - it’s horribly inefficient and the Dynamo for Civil 3D team did us no favors by including that and not a way to pull the mesh directly. Civil 3D Toolkit has a “TinSurfaceExtensions.GetMesh” which should help quite a bit.

All of which means you can take advantage of this right away, and have been able to for quite awhile (this is Dynamo for Civil 3D 2023). Bychanging out the two nodes at the front the rest of the graph just does the work (though I had to increase from 5 degree slope to 10 degree slope as my terrain didn’t have enough ‘flat’ areas to make it interesting) on all 10201 points in this terrain.

Not likely - most of my sports interests lay back in Boston, and I never really got into the soccer/football. Likely spend some of the weekend exploring some more terrain stuff in the context of Forma (will work in Civil 3d too as it’ll be based on analysis of the mesh). Yes I am a nerd.