About converting step files to obj files

sjwa

Active CAD practitioner
Hi, guys
I now have a STEP format file with a tree structure. I want to save each file as an obj file, instead of exporting the entire part file as an obj file. Do you have any ideas? Thank you,JSlyadneQuaoarnatalia

1662379673291.png
 

natalia

Moderator
Staff member
Hello @sjwa

Could you please give more details about the matter. Which data you'd like to export? Is it the geometrical polygonal data or hierarchy of STEP file or attributes like color/others?
The matter is that the STEP file has geometrical and attributes information. Sample of one of STEP file imported is on the tree below:STEP_structure.png
 

sjwa

Active CAD practitioner
Hello @sjwa

Could you please give more details about the matter. Which data you'd like to export? Is it the geometrical polygonal data or hierarchy of STEP file or attributes like color/others?
The matter is that the STEP file has geometrical and attributes information. Sample of one of STEP file imported is on the tree below:View attachment 390
I did not describe clearly, my fault
My idea is to export all the parts in the xde tree from the step file as obj files
According to my previous understanding, there are not so many attributes in the step file (such as size or multi-layer shape relationship) in the obj file, so I want to export all of them as obj files, so that after lightweight processing, they can be delivered to other projects for them to convert These obj files are displayed on other platforms.
So the question is, my 80mb step file is 50mb after exporting, is this normal? Or did I not add some options when exporting?
Thank you for your answer, my code and parts are as follows:
//---------------------------------
if (m_seqRootLabel.IsEmpty()) {
return writer.Perform(m_document, fileInfo, occProgress->Start());
}
else {
return writer.Perform(m_document, m_seqRootLabel, nullptr, fileInfo, occProgress->Start());
}
(obj file doesn't seem to upload...)
 

sjwa

Active CAD practitioner
bool OccObjWriter::writeFile(const FilePath& filepath, TaskProgress* progress)
{
if (!m_document)
return false;
XCAFPrs_DocumentExplorer T = test(m_document);
Handle_Message_ProgressIndicator occProgress = new OccProgressIndicator(progress);
RWObj_CafWriter writer(filepath.u8string().c_str());
const TColStd_IndexedDataMapOfStringString fileInfo;
if (m_seqRootLabel.IsEmpty()) {
return writer.Perform(m_document, fileInfo, occProgress->Start());
}
else {
return writer.Perform(m_document, m_seqRootLabel, nullptr, fileInfo, occProgress->Start());
}

}
 

JSlyadne

Administrator
Staff member
I did not describe clearly, my fault
My idea is to export all the parts in the xde tree from the step file as obj files
According to my previous understanding, there are not so many attributes in the step file (such as size or multi-layer shape relationship) in the obj file, so I want to export all of them as obj files, so that after lightweight processing, they can be delivered to other projects for them to convert These obj files are displayed on other platforms.
So the question is, my 80mb step file is 50mb after exporting, is this normal? Or did I not add some options when exporting?
Thank you for your answer, my code and parts are as follows:
//---------------------------------
if (m_seqRootLabel.IsEmpty()) {
return writer.Perform(m_document, fileInfo, occProgress->Start());
}
else {
return writer.Perform(m_document, m_seqRootLabel, nullptr, fileInfo, occProgress->Start());
}
(obj file doesn't seem to upload...)
Is my understanding correct that you're already able to solve the initial request? And the rest point is your concern about the size of result file? Regarding the file size, without initial step and result obj files we could hardly work out any worth ideas -)
 

sjwa

Active CAD practitioner
Is my understanding correct that you're already able to solve the initial request? And the rest point is your concern about the size of result file? Regarding the file size, without initial step and result obj files we could hardly work out any worth ideas -)
Yes, JSlyadne, my original problem is solved, now I'm a little confused about the size of the file after conversion, this forum seems to be unable to upload obj files (or it's a problem with my browser) I uploaded it to gitlab, you can do it when you get off work Or download it during coffee time, thank you :)
 

JSlyadne

Administrator
Staff member
Yes, JSlyadne, my original problem is solved, now I'm a little confused about the size of the file after conversion, this forum seems to be unable to upload obj files (or it's a problem with my browser) I uploaded it to gitlab, you can do it when you get off work Or download it during coffee time, thank you :)
I guess that the uploading fault could be because of files size - they are > 60mb in total. Anyway, I downloaded the files from GitLab and will take a look when a chance.
 

sjwa

Active CAD practitioner
I guess that the uploading fault could be because of files size - they are > 60mb in total. Anyway, I downloaded the files from GitLab and will take a look when a chance.
Thank you very much for your reply, looking forward to your reply:)
 

JSlyadne

Administrator
Staff member
Hey, siwa! Sorry for a delay with answer - the things piled up here.

I took a look at the obj file, what is your concern about? The generated file looks Ok, however I noticed it contains less number of parts than in original step file - 70 vs 77. It might be good to check whether everything is in place. I also generated the obj file and it resulted in ~ 5mb. It should be because of less detailed tesselation. Might it be a matter?
 

sjwa

Active CAD practitioner
Hey, siwa! Sorry for a delay with answer - the things piled up here.

I took a look at the obj file, what is your concern about? The generated file looks Ok, however I noticed it contains less number of parts than in original step file - 70 vs 77. It might be good to check whether everything is in place. I also generated the obj file and it resulted in ~ 5mb. It should be because of less detailed tesselation. Might it be a matter?
Thanks for your answer, JSlyadne
Regarding the 77 parts you said, the reason for programming 70 parts after exporting is because there are some parts such as solder joints in this digital-analog file. I have not yet figured out how these parts are expressed in opencascade, but this is not yet. Question I want to ask.
My question is: how to make the exported obj file as small as possible, you said that the obj file you exported is only 5mb, I would like to know how you exported it?
 

JSlyadne

Administrator
Staff member
My question is: how to make the exported obj file as small as possible, you said that the obj file you exported is only 5mb, I would like to know how you exported it?
You may examine how the OBJ writer is implemented in Analysis Situs, namelly asiAlgo -> interoperability -> asiAlgo__OBJ.cpp.

The size of result OBJ file depends on how detailed triangulation of surfaces is. The rougher triangulation is, the less size of OBJ file. What algorithm do you utilize to generate the triangulation? Supposing it's default OCCT's faceter, BRepMesh_IncrementalMesh, you need to play with linear and/or angular deflections to influnce on the quality of triangulation.
 

sjwa

Active CAD practitioner
You may examine how the OBJ writer is implemented in Analysis Situs, namelly asiAlgo -> interoperability -> asiAlgo__OBJ.cpp.

The size of result OBJ file depends on how detailed triangulation of surfaces is. The rougher triangulation is, the less size of OBJ file. What algorithm do you utilize to generate the triangulation? Supposing it's default OCCT's faceter, BRepMesh_IncrementalMesh, you need to play with linear and/or angular deflections to influnce on the quality of triangulation.
thanks for your answer
I think I didn't consider the triangulation algorithm, I just used the RWObj_CafWriter class in OCC to convert obj...
 

JSlyadne

Administrator
Staff member
Even if you don't call triangulation algorithm explicitly, it must be called implicitly somewhere as OBJ format stores triangles, not BRep descriptions.
 
Top