Ravikumar Logani
Ravikumar Logani

Reputation: 1

How to Create Emboss and engrave text on OpenCASCADE

I am searching an API for creating emboss text on my AIS_Shape , If there is no API any better way to do that ?,I am thinking of creating text extrude and doing cut operation with AIS_Shape , can we extrude Text ?

Upvotes: 0

Views: 757

Answers (1)

gkv311
gkv311

Reputation: 2982

OCCT doesn't provide direct tool defining an emboss text - so you are right, you have to do that using a general Boolean operation.

A general idea can be found within standard samples coming with Draw Harness - take a look onto "Modeling" -> "OCCT Tutorial bottle sample" sample (source $env(CSF_OCCTSamplesPath)/tcl/bottle.tcl):

Bottle Demo in Draw Harness

Tools to use:

  • Font_BRepFont to load a font and convert a glyph into a planar TopoDS_Shape.
  • Font_BRepTextBuilder to format a text using Font_BRepFont.
  • BRepPrimAPI_MakePrism to define a solid from text.
  • BRepAlgoAPI_Cut to perform a Boolean operation between text solid and another shape.

Here is a pseudo-code:

  // text2brep
  const double aFontHeight = 20.0;
  Font_BRepFont aFont (Font_NOF_SANS_SERIF, Font_FontAspect_Bold, aFontHeight);
  Font_BRepTextBuilder aBuilder;
  TopoDS_Shape aTextShape2d = aBuilder.Perform (aFont, "OpenCASCADE");

  // prism
  const double anExtrusion = 5.0;
  BRepPrimAPI_MakePrism aPrismTool (aTextShape2d, gp_Vec (0,0,1) * anExtrusion);
  TopoDS_Shape aTextShape3d = aPrismTool->Shape();
  //aTextShape3d.SetLocation(); // move where needed

  // bopcut
  TopoDS_Shape theMainShape; // defined elsewhere
  BRepAlgoAPI_Cut aCutTool (theMainShape, aTextShape3d);
  if (!aCutTool.IsDone()) { error }
  TopoDS_Shape aResult = aCutTool.Shape();

Upvotes: 0

Related Questions