One Surface/Face, Two Sides, Two Colors

Hello,
As part of a bigger project, we’ve been creating a plugin for Sketchup that detects enclosed volumes and color them in a specific color. Now we want to devellop the same idea on Rhino but I’m immediately conftonted to the following issue :

In sketchup we could assign a different material (color) on the two sides of a surface. So that two neighbor enclosed rooms would have different color (see on the following pictures).


As far as I’ve been in the RhinoCommon API, I couldn’t find any way to figure this out. It looks that every surface has the same material/color on both sides. Are there any ideas to figure this out ?
I could change the surfaces, into a mesh, or any equivalent geometric component. But I could never find a way to have different colors on the two sides. I hope one can help me.

Take a look at DisplayPipeline.DrawBrepShaded. This takes a Brep and a DisplayMaterial, which allows you to set different material parameters for the front and back of the surface.
The property you’re looking for specifically would be the diffuse color (DisplayMaterial.Diffuse for the front and DisplayMaterial.BackDiffuse for the back).
You likely have to set IsTwoSided to true for this to have an effect. Also note that the front and back would be defined by the normal of the Brep.

Thanks Robin for your answer.
I’ve been strugling a while by trying to use DrawBrepShaded. So I come back for help. Here is what I tried to do, the script:

            // Import all Rhino Objects
            Rhino.DocObjects.Tables.ObjectTable rhinoObjects = doc.Objects;
         
            // Select only the BReps
            IEnumerable<BrepObject> BrepInTheScene = rhinoObjects.GetObjectsByType<BrepObject>();
            RhinoApp.WriteLine("{0} Breps", BrepInTheScene.Count());

            // Construct a two sided material
            DisplayMaterial twoSidedMaterial = new DisplayMaterial();
            twoSidedMaterial.IsTwoSided = true;
            twoSidedMaterial.Diffuse = System.Drawing.Color.FromArgb(0, 180, 230, 120);
            twoSidedMaterial.BackDiffuse = System.Drawing.Color.FromArgb(0, 180, 230, 120);

            // Apply the material to all BReps in the scene
            foreach (BrepObject geo in BrepInTheScene)
            {
                DisplayPipeline.DrawBrepShaded(geo.BrepGeometry, twoSidedMaterial);
            }

This code doesn’t work. It actually tells me that An object reference is required for the non-static field, method, or property ‘DisplayPipeline.DrawBrepShaded(Brep, DisplayMaterial)’.

I suppose that I’m trying to use the DisplayPipeline in the wrong way. I actually couldn’t understand what is ‘pipeline’ for. And also why don’t we set the material in the object propreties.
The purpose of this process (in the end) is to export an 2017 .skp file, with the correct coloration of surfaces (different on the two sides). Does it seam doable with the Rhino API ?

Hi @em.rudelle,

Does this sample help you any?

SampleCsDrawMesh.cs

– Dale

Hi @dale ,
Thanks for this sample, it helped a lot. So now I can prompt geometry (mesh is exactly what we are looking for, no need for more) with a different color on the two faces. I also found a very nice explanation of display conduits here (in case it can help someone reading this).

But I am not able to have it as a real geometry that I can save and re-open later on Rhino or Sketchup. This display conduit is somehow a display trick but the colors are not really saved in the model. Am I wrong ?

Would you have a suggestion to achieve saving mesh geometry with different color on two side and being operable on other softwares (skp for example) ?

Also @robin_l I could not really understand the difference between DisplayConduit and DisplayPipeline, except that I was not able to derive from DisplayPipeline (sealed type).

Hi @em.rudelle,

No, you are right. Stuff drawn in a display conduit doesn’t save to the document, unless you do the saving.

If you just using Rhino, you can assign a double-sided material to any renderable object.

Edit: looks like the double-sided material is only available in the WIP. You might ask in the Rhino for WIndows category for further help on this.

– Dale

Sorry it took me a long time to answer on this.

Double sided material is exactly what I’m searching for. Indeed, it is only a feature of Rhino WIP. The thing is that the feature is also not stable so far. I couldn’t get it working. I’ve reported the issues I had during my tests.

So I need to use these double sided materials from C#, not in Rhino itself. But I couldn’t find anything in the Rhino WIP API. Do you have an example of a C# file using these two sided materials ?

Thank you,
Emmanuel

Hi @em.rudelle,

Now that I look at your image closer, you just want to modify the Shaded display mode, or make a new one, and adjust the color and backface settings. No programming requried…

– Dale

Hi @dale,

Sorry I might not have been clear. I’m writing an algorithm that perform volume recognition with ray-traycing. I now want to prompt the result and export it so it can be read by another software, in my case an energy simulation software.

In our software we use the informations stored in the colors of the surfaces to retrieve the closed volumes (and actually other kinds of assignements like surface constructions, still for energy analysis). This process has already been succesfully done on Sketchup and we want to enlarge it to Rhino.

The .3dm format allows us to use the UserData which would be very appropriate in our case, rather than passing information in surface colors. But doing so would also mean that we have to rebuild the import process on our side. So I am now trying to achieve the same result as what I did on Sketchup. If it appears too complicated or very inadapted, we will probably turn to the .3dm format.


Then I tried your proposition, with the shaded settings. But I couldn’t recreate the precedent result (picture under). Indeed the objects only have one color/material in their propreties so either the backfaces or the frontfaces will all have the same color/material. On the picture, I have surfaces in the middle that are purple/green or blue/orange for example.

Well, can you give me your opinion on how possible it would be for us to transfer our process to Rhino. ? Or if we should directly turn to the 3dm file format ?

I hope I have been clear enough on what I’m trying to do.
Emmanuel

Hi @em.rudelle,

By default, Rhino objects are drawn with a single color. That color can from from the object itself from the layer on which it resides.

If you want to draw an object with more than one color, a front and back face color in a shaded display mode for example, then you will need to do something custom.

There has been several options provided in this thread: a custom display conduit, a custom advanced display model, and custom render materials. If I were doing this, I would draw the results of the analysis using using a display conduit that provided for unique front and back face colors. A simple example has been provided in this thread. With a conduit, you should be able to achieve the same results as the image you’ve provided.

You’ve also mentioned the requirement to save the results of the analysis in some format so that another application can read it. I guess the format you choose, either .3dm or something else, depends on the target application. As Rhino’s file format does not have provisions for more than a single object color, you’d need to store this extra data somewhere in the 3dm file and then provide instructions for those reading the file on how to retrieve it. Another option is, of course, to write a file native to whatever energy simulation software you are targeting.

– Dale

Thanks for clarifying all this.
I’ll be trying these solutions. I’m giving update when the job is done.