
Mon, 11/25/2024 - 00:33
ok, apologies up front: I'm still figuring out OCCT and I'm probably being stupid...
I'm trying to import and display an OBJ file, but failing at the first hurdle:
Q1.
-----
Do I use:
1. XDE
2. RWObj::ReadFile()
3. RWObj_Reader class?
(using 7.8, aiming for latest-and-greatest support)
Q2.
-----
I've got somewhere with RWObj::ReadFile() but it reads it in as Poly_Triangulation. Are there any standard routines which will either allow me to display this, or convert it into a BRep/Topo shape (to display it)? Or, is it a case of walking the datastructure and re-creating?
Thought I'd take a look at the FreeCAD implementation, but alas (apart from it being python), it makes a dogs-dinner of my OBJ files, so I'm not inclined to follow that particular path!
cheers
Mat
Mon, 11/25/2024 - 06:21
Dear Mat :
I've used this function in conjunction with QT to read files in the past.
For example:
{
BRep_Builder builder;
QString filepath = QFileDialog::getOpenFileName();
QByteArray byteArray = filepath.toLatin1();
const char* cString = byteArray.constData();
Standard_CString fileName = cString;
Handle(Poly_Triangulation) triangulation = RWObj::ReadFile(fileName);
if (!triangulation.IsNull())
{
TopoDS_Face face;
builder.MakeFace(face, triangulation);
Handle(AIS_Shape) aisShape = new AIS_Shape(face);
myContext->Display(aisShape, AIS_Shaded, 0, false);
}
But it is just a simple example ,it made whole
Mon, 11/25/2024 - 08:45
If objective is to display OBJ model with materials, than you may use
RWObj_CafReader
to read OBJ file andXCAFPrs_AISObject
to display it 3D Viewer. Here is a sample for reading STEP file - you'll need replacingSTEPCAFControl_Reader
withRWObj_CafReader
and useSetDocument()
andPerform()
methods.Mon, 11/25/2024 - 23:09
Thank you both for your quick replies. Not quite there yet, but I think you were both right...
I tried the easy way first (Simons). This loaded my model on first attempt!! But, it took doing this to find that rotation and scaling are completely to-cock. Hence a more comprehensive solution is needed (gkv's). I'm currently working through this, but will post the results when I get something going...
Mat
Wed, 11/27/2024 - 00:47
ok, I'll try to reply again, this time using language which doesn't flag me for moderation :)
Thanks for both for the replies - you are both right. First example code got me up the running instantly - which immediately showed I had a scale and rotation issue with the .OBJ Importing - which pushed me to the bigger implementation. Took a little playing around, but I've got something up and running using this code:
So, progressing well. The next hurdles start to get interesting:
1. Material is being loaded using this function, but not displayed - any ideas?
(I know its being loaded because it complains when the file paths are missing)
2. To solve the rotation problem I want to auto-detect the coordinate system by measuring the object and detecting the longest edge. We're starting to swerve a little off-topic here, but do you know any way to extract bounding-box dimensions from an AIS or Topo shape? Once again, my thoughts are about manually calculating from points, but it feels like something there is a secret function for (if only I knew where to look :))
cheers
Mat
Wed, 11/27/2024 - 19:54
Check the
.mtl
file - it should be places nearby to.obj
, and associated texture files should be also accessible (note that some software may generate unusable.mtl
files referring to image files with inaccessible paths - e.g. absolute paths within some another computer).Fri, 11/29/2024 - 15:57
Aha, another magic function which does exactly what I need!
Still no luck with the materials - definitely being loaded because it complains if the texture files aren't there. I'll keep on plugging - not entirely convinced its not my view in the wrong mode!
Sun, 03/23/2025 - 13:41
coming back around to this problem again...
I can load in an OBJ file no problems, it detects when the associated material files are not present (which I therefore assume it finds them when they are present), but the visual presentation of the object is a complete white-out.
Is there a missing link between the loading of the object (XCAFDoc_ShapeTool) and the loading of the material (XCAFDoc_MaterialTool) - do I need to cross-assign these somewhere?
Anyone any ideas?
Mat
Sun, 03/23/2025 - 13:47
Mat M wrote:
When you see completely white material, than most-likely it refers to some textures, that haven't been loaded (due to wrong paths / non-existing image files or due to unsupported image format). Check the messages coming from OCCT - are you sure the log is empty?
Sun, 03/23/2025 - 22:06
hahahahaaaa, logs???
I'm feeling this is an important piece of information I've completely missed here! I've been watching stderr and stdout, but not seeing much. Where can I find the logs?
(I'm running through msys/mingw install on windows, so I guess its a Linux path)
So, wh
Sun, 03/23/2025 - 22:39
OCCT have functionality to log information into special printer. In most scenarios it is stdout. By default the gravity level is warning, it means you already will have the most important information.
I assume, there are can be one of the next issues: the OCCT do not linked to FreeImage, the Obj file have incorrect path to the texture file (image). Need to validate the patch stored inside XCAF.
Best regards, Dmitrii.