How to set a color and/or transparency in 3D object (STEP)

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
Mariusz_Unilink
Posts: 8
Joined: 28 Jan 2022, 15:35

How to set a color and/or transparency in 3D object (STEP)

Post by Mariusz_Unilink » 21 Feb 2022, 14:44

Hello everyone!

I have a problem in Tsg3DDrawingNavigator.
I know how to display 3D object (STEP) and how to add there:
- additional lines (TsgDXFLine)
- additional 3D solid based on triangles (TsgDXF3dFace)
Having a possibility to add lines and triangles I'm able to add any 3D figure with contours.
An this is done, and works perfect!
You can see it on the following picture:
Image

As you can see - there is possible to set a color of the line (TsgDXFLine), but there is no possible to set a color of the triangles (TsgDXF3dFace) and there is no possible to set their transparency (as in OpenGL - for example).
Of course "no possible" means not possible by me. I don't know how to set a color and/or transparency of this object.

A part of code (a function where I create double-triangle):

Code: Select all

TsgDXFEntity* __fastcall TCadSoftOperation::GetDoubleTriangle(TFPoint p0, TFPoint p1, TFPoint p2, TFPoint p3, TColor color)
{
  //p0 is common to the triangle <p0, p1, p2> and <p0, p2, p3>
  TsgDXFEntity *ent3dFace = new TsgDXF3dFace();
  TsgDXF3dFace *face3D;
  face3D = dynamic_cast<TsgDXF3dFace *>(ent3dFace);
  //TsgColorCAD cadColor;
  //cadColor.Color = color;

  //TO DO (to solve):
  //Problem with colors!

  if(face3D)
  {
    face3D->Point = p0;
    face3D->Point1 = p1;
    face3D->Point2 = p2;
    face3D->Point3 = p3;
    //face3D->ColorCAD = cadColor; //doesn't work
    //face3D->SetColor(color);     //doesn't work
  }

  return ent3dFace;
}
//---------------------------------------------------------------------------
Thank you for any help!

Mariusz

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to set a color and/or transparency in 3D object (STEP)

Post by support » 22 Feb 2022, 15:57

Hi Mariusz,

It seems to us that you haven’t specified the layer for a 3DFace. Please see this code example:

Code: Select all

          // Add 3d Face
          vFace := TsgDXF3dFace.Create;
          vFace.Point := MakeFPoint(4,0,0);
          vFace.Point1 := MakeFPoint(0,4,0);
          vFace.Point2 := MakeFPoint(0,0,4);
          vFace.Point3 := vFace.Point2;

         // vImage - current CADImage
          vLayout := vImage.Converter.Layouts[0];
          vFace.ColorCAD := MakeColorCAD(acRGBColor, RGB(125,34,67)); //sets color in RGB
          vFace.Layer := vImage.Converter.LayerByName('0');
          vImage.Converter.Loads(vFace);
          vLayout.AddEntity(vFace);
Usually models consist of a large number of triangles. To quickly change the color of a group of triangles, it would be more convenient to add triangles not to a layout but to blocks. 3DFaces should have the color by block. Then you need to add the block via an insert, and then set the required color to the insert.

As for transparency, unfortunately, at the moment it is not possible to add it to a 3D object because the transparency won't be saved to the file.

I would like to mention that last year we released CAD VCL 15 based on our own 3D CAD kernel, If you are interested in it, you can find the list of updates on our website, as well as download the CAD VCL latest demo version.

Kind regards,
Olga
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Mariusz_Unilink
Posts: 8
Joined: 28 Jan 2022, 15:35

Re: How to set a color and/or transparency in 3D object (STEP)

Post by Mariusz_Unilink » 22 Feb 2022, 17:15

Thank you very much Olga!

Mariusz_Unilink
Posts: 8
Joined: 28 Jan 2022, 15:35

Re: How to set a color and/or transparency in 3D object (STEP)

Post by Mariusz_Unilink » 23 Feb 2022, 13:15

Unfortunately that approach doesn't work, or I do something wrong.
I use block and insert.
Changing the color of an insert does nothing.

My function to create inserts looks as follow:

Code: Select all

TsgDXFInsert* __fastcall TCadSoftOperation::CreateWholeOperationInsertEntity()
{
  //This function pushes a bunch of entities:
  //std::vector<TsgDXFEntity *> CADEntities; 
  //to one insert.
  //Notice that: TsgCADImage* GlobalCADFile;
  
  TsgDXFInsert *insert = NULL;

  if(GlobalCADFile && CADEntities.size() > 0)
  {
    TsgDXFEntity *aEnt;
    TsgDXFConverter *mainConv = NULL;
    TsgDXFBlock *block = NULL;
    TsgDXF3dFace *doubleTriangle;

    CFloat3DPoint p0;
    TFPoint zeroPosition;

    //UL PosA = 0, PosB = 0;
    p0.x = 0.0;
    p0.y = 0.0;
    p0.z = 0.0;

    zeroPosition = GetSTEPCoordinates(p0);

    block = new TsgDXFBlock();
    for(unsigned int i=0; i<CADEntities.size(); i++)
    {
      aEnt = CADEntities[i];
      block->AddEntity(aEnt);
    }
    mainConv = GlobalCADFile->Converter;
    for(int i=0; i<block->Count; i++)
    {
      mainConv->Loads(block->Entities[i]);
    }

    mainConv->Sections[csBlocks]->AddEntity(block);
    mainConv->Loads(block);

    insert = new TsgDXFInsert();
    insert->Block = block;
    //insert->Color = clRed; //doesn't work
    //insert->ColorCAD = MakeColorCAD(acRGBColor, RGB(125,34,67)); //doesn't work as well
    insert->Layer = mainConv->LayerByName('0'); //Is it in the correct place? Is it necessary?

    insert->Point = zeroPosition;
    mainConv->Sections[csEntities]->AddEntity(insert);
    mainConv->Loads(insert);
  }

  return insert;
}
Greetings,

Mariusz

Mariusz_Unilink
Posts: 8
Joined: 28 Jan 2022, 15:35

Re: How to set a color and/or transparency in 3D object (STEP)

Post by Mariusz_Unilink » 23 Feb 2022, 16:29

Finally I've found the solution!
1. Each object has to be set on the single layer.
2. Colors of the surface and contours on these layer can be different, but every single entity has to be added to that layer.

Example:
Object (TCadSoftHole):

Code: Select all

void __fastcall TCadSoftHole::GetOpView()
{
  if(hole_ && DrawingNavigator3D && GlobalCADFile)
  {
    Layer = new TsgDXFLayer();
    // adding the new layer to the drawing
    GlobalCADFile->Converter->Loads(Layer);
    GlobalCADFile->Converter->Sections[csLayers]->AddEntity(Layer);

    TsgDXFInsert *insert;

    DrawContours();
    DrawSolids();
    DrawIndicators();

    CFloat3DPoint mathPlacement; //always extruded in z (x - horizontal, y - vertical)
    TFPoint placement; //real STEP placement (extrusion can be X, Y or Z; X is vertical, Y - horizontal)

    mathPlacement.x = hole_->FPositionW;
    mathPlacement.y = hole_->FPositionH;
    mathPlacement.z = hole_->FPositionX;
    placement = GetSTEPCoordinates(mathPlacement);

    insert = CreateWholeOperationInsertEntity();

    MoveInsert(insert,placement,false);   //new place
    DrawingNavigator3D->LoadFromConverter(GlobalCADFile->Converter,GlobalCADFile);
  }
}


Where 3D part is displayed in this way:

Code: Select all

TsgDXFEntity* __fastcall TCadSoftOperation::GetDoubleTriangle(TFPoint p0, TFPoint p1, TFPoint p2, TFPoint p3, TColor color)
{
  //p0 is common to the triangle <p0, p1, p2> and <p0, p2, p3>
  TsgDXFEntity *ent3dFace = new TsgDXF3dFace();
  TsgDXF3dFace *face3D;
  face3D = dynamic_cast<TsgDXF3dFace *>(ent3dFace);

  if(face3D)
  {
    face3D->Point = p0;
    face3D->Point1 = p1;
    face3D->Point2 = p2;
    face3D->Point3 = p3;
    face3D->Color = color;
    if(this->Layer)
    {
      face3D->Layer = Layer;
    }
  }

  return ent3dFace;
}

Post Reply