Import .OBJ File?

I tried the following but failed. Could you please give me an example of how to import an .OBJ file? please.

Handle(TDocStd_Application) anXdeApp = new TDocStd_Application();
BinXCAFDrivers::DefineFormat(anXdeApp); // to load XBF files
Handle(TDocStd_Document) anXdeDoc;
anXdeApp->NewDocument("XDE", anXdeDoc);

OSD::SetSignal(false); // catch signals

// read and translate STEP file into XCAF document
RWObj_CafReader aReader;
aReader.Perform(theFileName, Message_ProgressRange());
aReader.SetDocument(anXdeDoc);

TDF_Label mainLable = anXdeDoc->Main();
Handle(XCAFDoc_ShapeTool) myShapeTool = XCAFDoc_DocumentTool::ShapeTool(mainLable);
Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(mainLable);
TDF_LabelSequence FreeShape;

myShapeTool->GetFreeShapes(FreeShape);

int Roots = FreeShape.Length();

for (int i = 1; i <= Roots; i++)
{
TDF_Label label = FreeShape.Value(i);

Handle(XCAFPrs_AISObject) displayedShape = new XCAFPrs_AISObject(label);
myAISContext()->Display(displayedShape, true);
}

Dmitrii Pasukhin's picture

Hello.

The problem is you put document after read process. Set document need to be done before Perform.

We a going to move on DE_Wrapper functionality. You are free to use next code:

Handle(RWObj_ConfigurationNode) aNode = new RWObj_ConfigurationNode;
auto aProvider = aNode->BuildProvider()
bool aStat = aProvider->Read(filename,document);

Documentation is available on our site. Open CASCADE Technology: Data Exchange Wrapper (DE_Wrapper).

Best regards, Dmitrii.

kim jun wun's picture

thank you, junwun kim