Holo
April 13, 2020, 2:46pm
1
Hi guys, I have a scritp that builds simple roads on mesh terrains:
But the road looks bumpy until I run the “RebuildMesh” command, and then it looks like this:
What I do:
start with a mesh, pick a curve, coerce a mesh in Python and adjust vertice data according to the curve and then replace the original mesh with the altered version.
So how can I automatically get a smooth LOOKING road?
It already IS smooth, it just doesn’t look like it and unwelding and rewelding doesn’t help, and neither does recalculating mesh normals
Thanks for any help.
Holo
April 13, 2020, 4:16pm
3
@piac do you know what’s causing this? And what I can do to quickly fix/rewbuild/update the vertices so they appear as smooth as they are?
Cheers!
piac
(Giulio Piacentino)
April 13, 2020, 4:24pm
4
Hi @Holo
I think its just the mesh vertex normals.
In Python you can do this:
mesh.Normals.ComputeNormals();
an example can be found here:
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Collections_MeshVertexNormalList_ComputeNormals.htm
Thanks,
Giulio
–
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
Holo
April 13, 2020, 4:35pm
5
Hi Giulio, thanks, but I tried that already.
Terrain Road.3dm (3.9 MB)
Here is the mesh if you want to have a look.
I have tried
mesh.UnifyNormals()
mesh.Normals.Clear()
mesh.Normals.ComputeNormals()
mesh.Compact()
In theory this should fix it:
import rhinoscriptsyntax as rs
import scriptcontext as sc
mesh_id = rs.GetObject("mesh", rs.filter.mesh)
if mesh_id:
mesh = rs.coercemesh(mesh_id)
mesh.Normals.ComputeNormals()
mesh.Compact()
newMesh_ID=sc.doc.Objects.Add(mesh)
rs.SelectObject(newMesh_ID)
Holo
April 13, 2020, 5:13pm
7
Thanks that worked fine, but then I guess there is a bug in the other version
I put it in here for later referance:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
mesh_id = rs.GetObject("mesh", rs.filter.mesh)
if mesh_id:
mesh = rs.coercemesh(mesh_id)
Rhino.Geometry.Mesh.RebuildNormals(mesh)
newMesh_ID=sc.doc.Objects.Add(mesh)
rs.SelectObject(newMesh_ID)
The issue before is that Mesh.Normals.ComputeNormals(); recomputes the vertex normals but not the face normals. If you want to use that one you should also run Mesh.FaceNormals.ComputeFaceNormals();
so:
Mesh.Normals.ComputeNormals();
Mesh.FaceNormals.ComputeFaceNormals();
This was the usual solution in Rhino 5 Rhinocommon. In Rhino 6 they added that Mesh.RebuildNormals(); method which is a combination of the both plus probably some other features.
I guess there are some situations where you might want to only recompute vertex normals or only recompute face normals (I’ve not run into that situation but who knows).
2 Likes
RIL
(Rolf)
April 14, 2020, 2:33pm
10
These methods has strange inconsistent names. In my book they should read:
mesh.Vertices.ComputeNormals();
mesh.Faces.ComputeNormals();
mesh.ComputeNormals(); // all of them
Period.
// Rolf
1 Like