[RhinoCommon] Joinable and explodable CustomMeshObject


(Menno Deij - van Rijswijk) #1

I was wondering if it is possible to have classes derived of e.g. CustomMeshObject where joining into an aggregate exploding the aggregate into its constituents is supported?

For example, if I join two meshes I can later explode them back into their constituents. What I would like to have, conceptually, is this:

public MyCustomMeshObject : CustomMeshObject
{
    public MyAggregateCustomMeshObject OnJoin(IEnumerable<CustomMeshObject> others)
    { 
        var othersArr = others.ToArray();
        var all = new MyCustomMeshObject[othersArr.Length+1];
        Array.Copy(othersArr, all, 0, othersArr.Length);
        all[othersArr.Length] = this;
        return new MyAggregateCustomMeshObject(all);
    }

    // special drawing routines, etc. implemented here
}

public MyAggregateCustomMeshObject : CustomMeshObject, IEnumerable<MyCustomMesh>
{
    private IEnumerable<CustomMeshObject> _constituents;
    public MyAggregateCustomMeshObject(IEnumerable<MyCustomMeshObject> meshes)
    {
        _constituents = meshes;
    }

    public IEnumerable<CustomMeshObject> OnExplode()
    { 
        return _constituents;
    }

    // special drawing routines for aggregate mesh implemnted here

}

Of course, I could write my own Join and Explode equivalents for these classes, but it would be nice if they responded to the native Rhino Join and Explode commands.


(Dale Fugier) #2

I guess I am not sure how to respond. Can you provide more details as to what you are doing?

I’m sure this is going to take your own versions of Join and Explode…


(Menno Deij - van Rijswijk) #3

Basically, what I want to achieve is a multi-block structured grid object, which consists of multiple structured grids.

Currently, I have implemented structured grid as a custom mesh object. It would be nice if, when I call Join on these, that the result is one multi-block structured grid object, and when I call Explode on that, that the original structured grids are restored.

So, I was feeling the water for possible extensions on the Custom Object paradigm, to have them respond to the commands with overridable OnJoin and OnExplode methods. I understand that currently I would have to code these myself, but was hoping to interest you in adding this functionality.

Another idea I had was to subscribe to Command.BeginCommand and Command.EndCommand and listen for the Join and Explode commands and simulate the behavior myself if the objects are selected. Are there any reasons why that would be a bad idea?