Why does this mesh needs rebuilding? And how in Python?

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 :confused:

Thanks for any help.

@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!

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

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)

Try this one: https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Mesh_RebuildNormals.htm

1 Like

Thanks that worked fine, but then I guess there is a bug in the other version :slight_smile:

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

These methods has strange inconsistent names. In my book they should read:

mesh.Vertices.ComputeNormals();
mesh.Faces.ComputeNormals();
mesh.ComputeNormals(); // all of them

Period. :nerd_face:

// Rolf

1 Like