OCCT
OCCT copied to clipboard
The model has defects when converting from step format to wavefront format
Description
- create topological shapes
- generate mesh data using
BRepMesh_IncrementalMesh - using
BRep_Tool::Triangulationextracts data - manually export as wavefront model (vertices and faces)
Taking the simplest 3D surface (sphere) as an example, it is confusing that the radius of the sphere and the theLinReflection parameter of BRepMesh_IncrementalMesh affect the appearance of the final obj model.
Tested versions 7.8 and 7.9, both have this problem.
Expected Behavior
Export the correct wavefront model,the vertices are evenly distributed with the faces, without any strange defects
Actual Behavior
Using Blender to view the final exported obj file, the appearance is as follows.
From left to right, the radius of the ball is 0.5, 4.5, 13.5; the theLinReflection is 0.1(for ease of display, I manually scaled them to a uniform size in Blender, which does not affect the results at all).
A defect appeared along the seam edge of a sphere with smaller radius.
Sample Code or DRAW Tcl Script
The minimum example code is as follows:
#include <opencascade/BRepPrimAPI_MakeSphere.hxx>
#include <opencascade/BRepMesh_IncrementalMesh.hxx>
#include <opencascade/TopExp_Explorer.hxx>
#include <opencascade/BRep_Tool.hxx>
#include <opencascade/TopoDS.hxx>
#include <iostream>
#include <string>
#include <numbers>
int main() {
const TopoDS_Shape sphere = BRepPrimAPI_MakeSphere(3.0, 360.0 * std::numbers::pi_v<double> / 180.0).Shape();
std::ofstream obj_file("step2obj_test.obj");
if (!obj_file.is_open()) { std::cerr << "Failed to open file" << std::endl; }
BRepMesh_IncrementalMesh(sphere, 0.01);
int vertex_index { 0 };
for (TopExp_Explorer explorer(sphere, TopAbs_FACE); explorer.More(); explorer.Next()) {
TopoDS_Face face = TopoDS::Face(explorer.Current());
TopLoc_Location loc;
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(face, loc);
if (triangulation.IsNull()) { std::cerr << "triangulation is null" << std::endl; }
for (int i = 1; i <= triangulation->NbNodes(); ++i) {
const gp_Pnt& pnt = triangulation->Node(i);
obj_file << "v " << pnt.X() << " " << pnt.Y() << " " << pnt.Z() << '\n';
}
for (int i = 1; i <= triangulation->NbTriangles(); ++i) {
const Poly_Triangle& triangle = triangulation->Triangle(i);
int n1 { 0 };
int n2 { 0 };
int n3 { 0 };
triangle.Get(n1, n2, n3);
obj_file << "f " << n1 + vertex_index << "// " << n2 + vertex_index << "// " << n3 + vertex_index << "//" << '\n';
}
vertex_index += triangulation->NbNodes();
}
std::cout << "conversion complete." << std::endl;
return 0;
}
Operating System
Linux
Compiler
GCC
Bitness
64-bit
OCCT Version
7.8
Additional Files
No response