Grasshopper

algorithmic modeling for Rhino

Can anyone tell me why my mesh edge vertices are not on the same face as they say they are coming from?

 

Dim m As mesh = msh

Dim checker As New List(Of point3d)

m.Vertices.CombineIdentical(True, True)

For i As int32 = 0 To 0'm.Faces.Count - 1
checker.Add(m.Faces.GetFaceCenter(i))
For j As int32 = 0 To m.TopologyEdges.GetEdgesForFace(i).Length - 1

checker.add(m.Vertices(m.TopologyEdges.GetTopologyVertices(m.TopologyEdges.GetEdgesForFace(i)(j)).I))
checker.add(m.vertices(m.TopologyEdges.GetTopologyVertices(m.TopologyEdges.GetEdgesForFace(i)(j)).J))

Next
Next

a = checker

Views: 582

Attachments:

Replies to This Discussion

Andy, when I took a quick look at your question, it was hard to read, so I was going to skip it.

 

I think if you make your code a little more readable, and add some comments to explain the steps, it would be easier for others to look for mistakes.

 

These lines in particular are kind of dense and long, and are a good place to look for the problem:

checker.add(m.Vertices(m.TopologyEdges.GetTopologyVertices(m.TopologyEdges.GetEdgesForFace(i)(j)).I))
checker.add(m.vertices(m.TopologyEdges.GetTopologyVertices(m.TopologyEdges.GetEdgesForFace(i)(j)).J))

 

also, you can wrap your code in <code> html tags if you switch to html input. if the line is too wide, then maybe you should spread it out to multiple lines.

The problem is here:

 

m.Vertices(m.TopologyEdges.GetTopologyVertices...

 

TopologyVertices are different from MeshVertices. Topology of a Mesh is information that contains the connection heirarchy, neighbouring vertices/edges/faces, etc.. to make certain mesh functionality faster. It is not always necessary that topological information will mirror actual meshVertices in indices.

 

The way you're writing your code is certainly extremely confusing, and breaking it up would certainly help the both of us. What I recommend doing is this:

 

Dim vertexTop as Rhino.Geometry.Collections.MeshTopologyVertexList = M.TopologyVertices

 

And then, to get the correlation between TopologyVertices and MeshVertices, use:

 

vertexTop.MeshVertexIndices()

Hope it works.

That was it. Sorry for the confusing code... I've gotten in the habit of limiting my lines by not dim-ing things.


Its a catmull clark mesh smoothing algorithm.

The correct code is...

...

For i As int32 = 0 To m.Faces.Count - 1

Dim mf As meshface = m.Faces(i)
tempm.Vertices.Add(m.Faces.GetFaceCenter(i))

For j As int32 = 0 To m.TopologyEdges.GetEdgesForFace(i).Length - 1

Dim n As int32 = m.TopologyEdges.GetEdgesForFace(i)(j)

Dim vertL As rhino.Geometry.Collections.MeshTopologyVertexList = m.TopologyVertices

Dim rlpt As New point3d

rlpt += m.Faces.GetFaceCenter(m.TopologyEdges.GetConnectedFaces(n)(0))
rlpt += m.Faces.GetFaceCenter(m.TopologyEdges.GetConnectedFaces(n)(1))

rlpt += m.Vertices(vertL.MeshVertexIndices(m.TopologyEdges.GetTopologyVertices(n).I)(0))
rlpt += m.Vertices(vertL.MeshVertexIndices(m.TopologyEdges.GetTopologyVertices(n).J)(0))

rlpt /= 4

tempm.Vertices.Add(rlpt)

Next

...

See the file for the complete code. And smooth away!

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service