How to turn mesh shape to topoShape?

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
JOE_FU
Posts: 79
Joined: Fri Jan 11, 2019 8:41 am

How to turn mesh shape to topoShape?

Post by JOE_FU »

Hi,everyone.
I always get a mesh obj, when I insert a model in obj format.But I want to turn this object to a topoShape, which can be used in Part workbench.How can I do it?
chrisb
Veteran
Posts: 54302
Joined: Tue Mar 17, 2015 9:14 am

Re: How to turn mesh shape to topoShape?

Post by chrisb »

Moved to help forum.

There are lots of forum topics explaining how to convert a stl to a solid. Basically, you import the file as a mesh, convert in Part workbench the mesh to a shape and the shape to a solid.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to turn mesh shape to topoShape?

Post by vocx »

JOE_FU wrote: Mon Dec 16, 2019 12:11 pm ...But I want to turn this object to a topoShape, which can be used in Part workbench.How can I do it?
Use Part_ShapeFromMesh.
Last edited by vocx on Thu Jan 16, 2020 7:52 am, edited 1 time in total.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
JOE_FU
Posts: 79
Joined: Fri Jan 11, 2019 8:41 am

Re: How to turn mesh shape to topoShape?

Post by JOE_FU »

JOE_FU wrote: Mon Dec 16, 2019 12:11 pm Hi,everyone.
I always get a mesh obj, when I insert a model in obj format.But I want to turn this object to a topoShape, which can be used in Part workbench.How can I do it?
In the process of converting mesh to Part, I encountered new troubles. Some obj model files are very slow in the process of converting to Part. I traced the code and found that the code that affects speed is in the function of setFace. One of them is aSewingTool.Perform ().
As far as I know, the function of this function is to stitch triangle patches.

Code: Select all

void TopoShape::setFaces(const std::vector<Base::Vector3d> &Points,
                         const std::vector<Facet> &Topo, float Accuracy)
{
    gp_XYZ p1, p2, p3;
    TopoDS_Vertex Vertex1, Vertex2, Vertex3;
    TopoDS_Face newFace;
    TopoDS_Wire newWire;
    BRepBuilderAPI_Sewing aSewingTool;
    Standard_Real x1, y1, z1;
    Standard_Real x2, y2, z2;
    Standard_Real x3, y3, z3;

    aSewingTool.Init(Accuracy,Standard_True);

    TopoDS_Compound aComp;
    BRep_Builder BuildTool;
    BuildTool.MakeCompound(aComp);

    unsigned int ctPoints = Points.size();
    for (std::vector<Facet>::const_iterator it = Topo.begin(); it != Topo.end(); ++it) {
        if (it->I1 >= ctPoints || it->I2 >= ctPoints || it->I3 >= ctPoints)
            continue;
        x1 = Points[it->I1].x; y1 = Points[it->I1].y; z1 = Points[it->I1].z;
        x2 = Points[it->I2].x; y2 = Points[it->I2].y; z2 = Points[it->I2].z;
        x3 = Points[it->I3].x; y3 = Points[it->I3].y; z3 = Points[it->I3].z;

        p1.SetCoord(x1,y1,z1);
        p2.SetCoord(x2,y2,z2);
        p3.SetCoord(x3,y3,z3);

        if ((!(p1.IsEqual(p2,0.0))) && (!(p1.IsEqual(p3,0.0)))) {
            Vertex1 = BRepBuilderAPI_MakeVertex(p1);
            Vertex2 = BRepBuilderAPI_MakeVertex(p2);
            Vertex3 = BRepBuilderAPI_MakeVertex(p3);

            newWire = BRepBuilderAPI_MakePolygon(Vertex1, Vertex2, Vertex3, Standard_True);
            if (!newWire.IsNull()) {
                newFace = BRepBuilderAPI_MakeFace(newWire);
                if (!newFace.IsNull())
                    BuildTool.Add(aComp, newFace);
            }
        }

    }

    aSewingTool.Load(aComp);
    aSewingTool.Perform();
    _Shape = aSewingTool.SewedShape();
    if (_Shape.IsNull())
        _Shape = aComp;
}
Attachments
ttt.obj
(561.27 KiB) Downloaded 10 times
Post Reply