Search code examples
c#stepopencascade

How can i show the side in OpenCascade with color?


I have a .step File and i need to make images from the sides for a project. Now i have the problem that the sides are all white.

To get the side i change viewpoint and for now i change it a bit to show the colors but that does often not work and the object is still white. I also tried to ad a PositionalLight and a DirectionalLight, they give at best a slightly more gray white. But i might overlook something simple.

The Code to change the View

            localView = new View3D();
            localView.Dock = DockStyle.Fill;
            Visualizer = new ObjectVisualizer();
            localView.AddVisualizer(Visualizer);
            stepImport = new StepImport();
            Import = stepImport.Import(_currentFile);
            localView.BeginUpdate();
            localView.ViewBottom();
            localView.EndUpdate();

Examplelightsources i tried

            localView.View.SetLightOn(new OCV3d_DirectionalLight(localView.View.Viewer(), OCV3d_TypeOfOrientation.V3d_Zneg, OCQuantity_NameOfColor.Quantity_NOC_RED));
            localView.View.SetLightOn(new OCV3d_PositionalLight(localView.View.Viewer(), -10, -10, -10, OCQuantity_NameOfColor.Quantity_NOC_BLACK));

I trie to get a sideview like in the FreeCad software, where the colors of the Object are shown.


Solution

  • Thanks to the Comment of Benjamin Bihler I was able to resolve my problem as it was indeed the material that made the Object shine white from the side. To change the material i had to access the AisShapes from my VisualNode Object that i am using to show the Object.

    VisualNode visualNode = new VisualNode(item.Name, new ObjectVisualizer(localView));
    visualNode.AddShape(item.Shape, c, (double)c.A / 255);
    foreach(var x in visualNode.AisShapes)
    {
        x.SetMaterial(OCGraphic3d_NameOfMaterial.Graphic3d_NOM_PLASTIC);
    }
    Visualizer.RootNode.Children.Add(visualNode);
    visualNode.Show();