Problem adding new mesh to document

Hi @dale,

i am building a Rhino.Geometry.Mesh from another mesh by copying it and then chaning the vertex locations. After this is done, i update the vertex normals and facenormals. While doing this, i ran in a situation where some meshes cannot be added to the document in V5 and V6 using:

guid = scriptcontext.doc.Objects.AddMesh(new_mesh)

which results in an empty guid. If i query new_mesh.IsValid before i try to add the mesh to the document, i get False. Is there a way to find out what is not valid with the new mesh ? (It is manifold, compacted etc)

_
c.

Hi @clement,

Use Mesh.IsVaiidWithLog.

– Dale

Hi @dale,

i am getting “ON_Mesh.m_dV[] and m_V[] are not synchronized.

In my code i clear the mesh vertices before adding new ones. I also do this:

    new_mesh.Normals.Clear()
    new_mesh.FaceNormals.Clear()
    new_mesh.Vertices.Clear()
    new_mesh.Vertices.AddVertices(new_vertices)
    new_mesh.FaceNormals.ComputeFaceNormals()
    new_mesh.Normals.ComputeNormals()
    new_mesh.Compact()

EDIT: if i reduce above to just clearing the vertices and adding the new ones, i get this:

Single and double precision vertices are not synchronized.”

On some meshes it works, but on some very simple ones (with 3 faces) it fails. What is “ON_Mesh.m_dV” ?

_
c.

If you have a sample for a simple mesh where this doesn’t work, I would sure like to see it. You shouldn’t have to worry about keeping these lists synchronized

Hi @stevebaer, i stripped down as much as possible. Below example makes the first error “ON_Mesh.m_dV[] and m_V[] are not synchronized” appear when i try to add the mesh to the doc.

AddMeshProblem.3dm (28.1 KB)
AddMeshProblem.py (1.2 KB)

thanks a lot for taking a look. I’ll try now to make another example which causes the other error as well.
_
c.

Hi @clement,

Instead of this:

new_mesh.Vertices.Clear()
new_mesh.Vertices.AddVertices(new_vertices)

Do this:

new_mesh.Vertices.Clear()
# Since you've cleared the vertices, make sure
# Rhino knows you want new vertices to be
# double-precsion vertices...
new_mesh.Vertices.UseDoublePrecisionVertices = True
new_mesh.Vertices.AddVertices(new_vertices)

– Dale

Hi @dale, i am getting:

Message: ‘MeshVertexList’ object has no attribute ‘UseDoublePrecisionVertices’

unfortunately this is V5. In V6 it seems to fix the problem. Is there anything i can do to make it work in V5 as well ? I’ve tried all kinds of things to make the vertices Point3d or Point3f but that failed.

_
c.

Hi @clement,

Sorry, your file is in a Rhino 6 format, so…

Anyway, instead of clearing the vertices, how about just replacing them?

for i in xrange(new_mesh.Vertices.Count):
  vtx = mesh_obj.Geometry.Vertices[i]
  dir = mesh_obj.Geometry.Normals[i]
  new_mesh.Vertices.SetVertex(i, vtx + dir)

– Dale

Thank you @dale, it works in V5 and V6. I thought adding the vertices in one go would be faster but your method seems to give the same speed.
_
c.

Hello I have had a similar problem:

I would like to update the TopologyVertices instead of the Vertices, this improves speed like hell in my given case (no welded edges because I need individual UV coordinates…)

M.TopologyVertices[i] = some Point3f;

When I do this I get : ON_Mesh.m_dV[] and m_V[] are not synchronized

Workarround for now is to create a new mesh and append the old mesh to the new Mesh, that helps…

any other suggestions what the problem might be?

Hi @richard_schaffranek,

Topological mesh vertices are no different from standard mesh vertices. Thus, you can just use MeshVertexList.SetVertex. Doing this will ensure any double-precision vertices are in-sync with single precision vertices.

– Dale

That might be however…

Setting all Vertices that correspond to a Topological Vertex individually takes realy realy long compared to setting the topological vertex … Difference is waiting for a minute . waiting for 5 seconds…

Hi @richard_schaffranek,

You can do something like this to get around the “ON_Mesh.m_dV[] and m_V[] are not synchronized” error.

foreach (var vi in mesh.TopologyVertices.MeshVertexIndices(top_vi))
{
  mesh.Vertices.SetVertex(vi, vertex);
}

– Dale

Hmm okay, but why do the two list end up not being synchronised when setting the TopologyVertice? couldn’t that be considered a bug?

I mean as fare as I understand every time SetVertex is called the Topology of the MEsh is recomputet which than takes ages compared to changing the location of the TopologyVertice…

So it is just another workarround…

I’m working on it…

https://mcneel.myjetbrains.com/youtrack/issue/RH-53108

No, this is not true.

– Dale

But then why is setting each Vertex individually like you proposed so much slower than setting the Topology Vertex? Is there any way to see what happens in the corresponding method?

Hi @richard_schaffranek,

Can you provide a simple example that repeats this slowness?

– Dale

RH-53108 is fixed in the latest Service Release Candidate.

Hi @dale, i’m getting this error using most recent Mac version 7.24.22308.15002, 2022-11-04. I am using the suggested workarounds like:

mesh.Vertices.UseDoublePrecisionVertices = True

and i am not adding vertices but changing them using:

p = Point3d(x,y,z)
mesh.Vertices.SetVertex(i, p)

i’ll send examples via PM.

thanks,
c.