[Solved]Mesh Object Base Problem

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

[Solved]Mesh Object Base Problem

Post by HakanSeven12 »

I created a mesh and changed its base but when I try to edit it its returns to old base. How can I fix it?

Mesh creation:

Code: Select all

        MeshObject = Mesh.Mesh(MeshList)
        Surface = FreeCAD.ActiveDocument.addObject("Mesh::Feature", SurfaceNameLE)
        MeshBase = MeshObject.Placement.Base
        MeshObject.Placement.Base = MeshBase.add(Base)
        Surface.Mesh = MeshObject
Mesh edit:

Code: Select all

    def SwapEdge(self,cb):
        event = cb.getEvent()
        if event.getButton() == coin.SoMouseButtonEvent.BUTTON2 and event.getState() == coin.SoMouseButtonEvent.DOWN:
            FreeCADGui.ActiveDocument.ActiveView.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.MC)
        if event.getButton() == coin.SoMouseButtonEvent.BUTTON1 and event.getState() == coin.SoMouseButtonEvent.DOWN:
            pp = cb.getPickedPoint()
            if not pp is None:
                detail = pp.getDetail()
                if detail.isOfType(coin.SoFaceDetail.getClassTypeId()):
                    face_detail = coin.cast(detail, str(detail.getTypeId().getName()))
                    index = face_detail.getFaceIndex()
                    self.FaceIndexes.append(index)
                    if len(self.FaceIndexes) == 2:
                        Surface = FreeCADGui.Selection.getSelection()[-1]
                        CopyMesh = Surface.Mesh.copy()
                        try:
                            CopyMesh.swapEdge(self.FaceIndexes[0],self.FaceIndexes[1])
                        except:
                            pass
                        Surface.Mesh = CopyMesh
                        self.FaceIndexes.clear()
Last edited by HakanSeven12 on Fri May 17, 2019 2:15 pm, edited 1 time in total.
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: Mesh Object Base Problem

Post by HakanSeven12 »

Any idea?
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Mesh Object Base Problem

Post by wmayer »

CopyMesh = Surface.Mesh.copy()
This only copies the mesh data but not the placement information. So, you have to also add

Code: Select all

CopyMesh.Placement = Surface.Mesh.Placement
I think this is a bug and should be fixed.
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: Mesh Object Base Problem

Post by HakanSeven12 »

wmayer wrote: Mon May 13, 2019 8:16 am
CopyMesh = Surface.Mesh.copy()
This only copies the mesh data but not the placement information. So, you have to also add

Code: Select all

CopyMesh.Placement = Surface.Mesh.Placement
I think this is a bug and should be fixed.
Yes it looks like a bug.
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Mesh Object Base Problem

Post by wmayer »

User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: Mesh Object Base Problem

Post by HakanSeven12 »

wmayer wrote: Mon May 13, 2019 1:52 pm git commit 0e86b2a73
Also when I change placement of mesh I cant create contours using by Mesh.crossSections()

Code: Select all

        zmax = Surface.Mesh.BoundBox.ZMax
        zmin = Surface.Mesh.BoundBox.ZMin
        h = 0
        dh =1000

        while h < zmax:
            if h > zmin:
                CrossSections = Surface.Mesh.crossSections([((0,0,h),(0,0,1))],0.5)
                for i in CrossSections[0]:
                    Contour = Draft.makeWire(i, face=False)
                    self.Contours.addObject(Contour)
                h += dh
            else:
                h += dh
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Mesh Object Base Problem

Post by wmayer »

Currently there are some mesh algorithms that don't respect the placement. To overcome this limitation you can apply the placement directly on the geometry, i.e. the mesh points are directly changed.

Code: Select all

CopyMesh = Surface.Mesh.copy()
CopyMesh.transform(Surface.Mesh.Placement.toMatrix())
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Mesh Object Base Problem

Post by wmayer »

User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: Mesh Object Base Problem

Post by HakanSeven12 »

wmayer wrote: Mon May 13, 2019 3:45 pm git commit 0644ed8e6
One more thing. Do you have any idea about that?

https://forum.freecadweb.org/viewtopic.php?f=22&t=36256
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Mesh Object Base Problem

Post by wmayer »

git commit ae1723b946

At the moment this requires that the shape must be near to the mesh already and then you define a maximum distance. However, it's not the same as the parallel projection offered by OCCT for projecting on shapes. Instead it seems to project it in a way that the projection direction for each point of the shape is normal to the mesh surface.

In the Surface workbench you find a function to draw a line onto a mesh. Afterwards it collects the intersection points with the triangle edges and build a wire. It's rather the opposite of what you need but the used algorithm can be used to project a given wire on the mesh.
Post Reply