Mesh+ workaround for m+Rings

I need the functionality of the m+Rings component of the Mesh+ plugin.

The goal is to extract the following lines (green) out of the attached mesh:

mesh.3dm (167.6 KB)

This can be achieved using the m+Rings component of Mesh+. However this plugin currently only works in Windows. Any other ideas how this can be achieved? Or to formulate the sub-question: How can one retrieve the topological distance of one vertex to another?

@DavidMans any ideas?

Thanks!

1 Like

It looks like WarpWeft could work there. You could then join them and sort the warp curves by where they meet one of the weft curves if you need them ordered.

1 Like

good point , that’s what I tried at first. But it does not seem to work here:

ah yes, I see those triangle fans make it impossible. It works for the rest

Also - Isn’t all of Mesh+ user objects? I’m curious why it doesn’t run on Mac.
(edit - I think I figured out why - it looks like many of the M+ objects contain VB scripts, which have a few issues on Mac as mentioned here. Converting them to C# would probably avoid these problems. There are some automated converters like this which will do the bulk of the conversion, though they usually need a bit of manual fixing too for stuff like case-sensitivity)

Awesome, that’s a great workaround! Thank you

The debug message usually shows the following:

Error (BC30451): 'ubound' is not declared. It may be inaccessible due to its protection level. (line 107)

Tried the converter, but it gives me a ton of errors, when pasting the Mesh+ code there… error messages I don’t understand currently tbh. But thank you for the suggestion!

Hey Rudi,
Really late replying to this…
Here is a c# implementation.
M+3 (whenever it gets finished) will be a single gha library and should be mac compatible.
cSharp.zip (8.4 KB)

1 Like

Hey @DavidMans, thank you very much for your C# implementation, and sorry for my late reply! Any news on M+3? There are some amazing functionalities in M+3, that I would love to be able to use on Rhino macOS!

Cheers, Rudi

Its getting close. Im down to 10 components then bug testing. Hope to release a buggy alpha very soon.

4 Likes

Awesome! Much success for the remaining components then, looking forward!

Cheers

Is Mesh + 3 Available already? I couldnt find it in the usual places.
For some reason the C# script did not work for me.
The process would take forever or crash Grasshopper completely.
I used ChatGPT to rewrite it slightly and now it works.
This is the code that works for me on an M1Pro Mac:

using System;
using System.Collections.Generic;
using Rhino;
using Rhino.Geometry;
using Grasshopper;
using Grasshopper.Kernel;

public class Script_Instance : GH_ScriptInstance
{
    private void RunScript(
	Mesh mesh,
	IList<int> indexList,
	bool useNakedVertices,
	ref object A)
    {
        // Check if the mesh is not null
        if (mesh == null)
            return;

        // Weld the mesh
        mesh.Weld(Math.PI); // Adjust the welding threshold as needed

        // Initialize the array for vertex distances
        int[] vertexDistances = new int[mesh.Vertices.Count];
        for (int i = 0; i < vertexDistances.Length; i++)
            vertexDistances[i] = -1;

        // Check if there are specified indices or if naked vertices should be used
        if (indexList.Count > 0 || (mesh.GetNakedEdges() != null && useNakedVertices))
        {
            var topologyVertices = mesh.TopologyVertices;
            var processedVertices = new bool[mesh.Vertices.Count];

            // Get naked edge point status if needed
            if (useNakedVertices)
                processedVertices = mesh.GetNakedEdgePointStatus();

            // Precompute topology vertex indices
            var topologyVertexIndices = new int[mesh.Vertices.Count];
            for (int i = 0; i < mesh.Vertices.Count; i++)
                topologyVertexIndices[i] = topologyVertices.TopologyVertexIndex(i);

            // Process specified indices in indexList
            if (indexList.Count > 0)
            {
                foreach (int i in indexList)
                {
                    foreach (int vertexIndex in topologyVertices.MeshVertexIndices(topologyVertexIndices[i]))
                        processedVertices[vertexIndex] = true;
                }
            }

            // Set of initial vertices to process
            var initialVertices = new HashSet<int>();
            for (int i = 0; i < processedVertices.Length; i++)
            {
                if (processedVertices[i])
                {
                    initialVertices.Add(i);
                    vertexDistances[i] = 0;
                }
            }

            // Variables for loop
            var nextVertices = new HashSet<int>();
            int currentDistance = 0;
            int processedCount = initialVertices.Count;

            // Loop to calculate distances
            while (processedCount < mesh.Vertices.Count)
            {
                var currentVertices = currentDistance == 0 ? initialVertices : nextVertices;
                nextVertices = new HashSet<int>();

                foreach (int vertex in currentVertices)
                {
                    foreach (int connectedVertex in topologyVertices.ConnectedTopologyVertices(topologyVertexIndices[vertex]))
                    {
                        foreach (int meshVertexIndex in topologyVertices.MeshVertexIndices(connectedVertex))
                        {
                            if (!processedVertices[meshVertexIndex])
                            {
                                processedVertices[meshVertexIndex] = true;
                                nextVertices.Add(meshVertexIndex);
                                vertexDistances[meshVertexIndex] = currentDistance + 1;
                                processedCount++;
                            }
                        }
                    }
                }

                if (processedCount >= mesh.Vertices.Count)
                    break;

                currentDistance++;
            }
        }

        A = vertexDistances;
    }

    // <Custom additional code> 

    // </Custom additional code> 
}

Mesh+ 3 is nearly finished after a year-long complete refactor, but it is still at least a month out.
I just updated version 2 to fix the .net core issues with vb and a new download is available on food4rhino.

4 Likes

Omg! Thank you very much! Big news!

This is so awesome to hear. Thank you so much. I have used your tools for a while now and absolutely love them.
Looking forward to trying mesh+3