algorithmic modeling for Rhino
I am having an unexpected issue with combine identical returning to me an invalid mesh for a simple case yet weld works fine. Can anyone shed some light. See code below and gh + rhino file.
Thanks.
private void RunScript(Mesh M, ref object A)
{
Mesh capFace = new Mesh();
Mesh capFaces = new Mesh();
if (!(M.IsClosed))
{
Polyline[] nakedBoundaries = M.GetNakedEdges();
for (int i = 0; i <= nakedBoundaries.Count() - 1; i++)
{
capFace = Mesh.CreateFromClosedPolyline(nakedBoundaries[i]);
capFaces.Append(capFace);
}
M.Append(capFaces);
M.Vertices.CombineIdentical(false, true);
//if I put first option (ignore normals)as true I get invalid mesh
//With false I get a valid mesh but its doesnt seem to actually combine the Vertices
//M.Weld(Math.PI); <----why does weld work?
M.UnifyNormals();
}
A = M;
It works correctly for adding one cap as such
private void RunScript(Mesh M, ref object A)
{
Mesh capFace = new Mesh(); Mesh capFaces = new Mesh();
if (!(M.IsClosed))
{
Polyline[] nakedBoundaries = M.GetNakedEdges();
for (int i = 0; i <= 0 ;i++) // once cap
{
capFace = Mesh.CreateFromClosedPolyline(nakedBoundaries[i]);
M.Append(capFace);
}
M.Vertices.CombineIdentical(true, true);
}
A = M;
Tags:
CombineVertices does not take into the normals, so if you use the IsValidWithLog() method, it will inform you why the mesh is invalid: there's an invalid normal in your mesh, with a length of 0. You have to recompute your vertices if you merge vertices.
M.Normals.ComputeNormals();
As far as I know this recomputes the vertex normals based on the normal of the mesh face (which could be: the cross product of the vectors A-B and A-C).
Weld automatically keeps track of the existing vertex normals, and takes the average of the two combined vertices.
Thanks Arend I will give that a try.
Hi Michael,
did that solve the issue? Thank you,
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
Giulio,
Yes it solved it exactly.
I just wonder why? Meaning I have used combine before without recompute. Is it maybe something that occurs when you append meshes together. Other cases I used combine was on already closed meshes so maybe it is just needed for bringing two meshes together that may have different normal.
Arend,
It works perfectly. Thanks so much.
Mesh capFace = new Mesh();
if (!(M.IsClosed))
{
Polyline[] nakedBoundaries = M.GetNakedEdges();
for (int i = 0; i <= nakedBoundaries.Count() - 1; i++)
{
capFace = Mesh.CreateFromClosedPolyline(nakedBoundaries[i]);
M.Append(capFace);
}
M.Vertices.CombineIdentical(true, true);
M.Normals.ComputeNormals();
M.UnifyNormals();
}
A = M;
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by