Mesh FromPartShape: Difference between revisions

From FreeCAD Documentation
(ordinate <!--T:xx-->)
(Button text.)
 
(76 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>

<!--T:1-->
<!--T:1-->
{{Docnav
{{Docnav|[[Mesh Export|Export Mesh]]|[[Mesh CurvaturePlot|Curvature Plot]]|[[Mesh_Workbench|Mesh]]|IconL=Mesh_ExportMesh.png|IconC=Workbench_Mesh.svg|IconR=Mesh_CurvaturePlot.png}}
|[[Mesh_Export|Export]]
|[[Mesh_RemeshGmsh|RemeshGmsh]]
|[[Mesh_Workbench|Mesh]]
|IconL=Mesh_Export.svg
|IconR=Mesh_RemeshGmsh.svg
|IconC=Workbench_Mesh.svg
}}


<!--T:2-->
<!--T:2-->
{{GuiCommand
{{GuiCommand|Name=Mesh MeshFromShape‏‎|MenuLocation=Meshes → Create Mesh from Shape|Workbenches=[[Mesh Workbench|Mesh]]|SeeAlso=}}
|Name=Mesh FromPartShape
|MenuLocation=Meshes → Create mesh from shape...
|Workbenches=[[Mesh_Workbench|Mesh]]
}}

==Description== <!--T:26-->

<!--T:3-->
The '''Mesh_FromPartShape''' command creates non-parametric [[mesh|mesh]] objects ([[Mesh_Feature|Mesh Features]]) from [[shape|shape]] objects ([[Part_Feature|Part Features]]).


==Introduction== <!--T:3-->
<!--T:40-->
The inverse operation is [[Part_ShapeFromMesh|Part ShapeFromMesh]] from the [[File:Workbench_Part.svg|24px]] [[Part_Workbench|Part Workbench]].
This command creates a mesh from a shape object.


==Usage== <!--T:4-->
==Usage== <!--T:4-->


<!--T:5-->
<!--T:5-->
# Optionally select one or more objects.
There are two methods:
# There are several ways to invoke the command:
# Either select the shape object, then choose {{KEY| Meshes}} → {{KEY|[[Image:Mesh_Mesh_from_Shape.svg|32px]] Create Mesh from shape...}} from the top menu.
# Just selecting {{KEY| Meshes}} → {{KEY|[[Image:Mesh_Mesh_from_Shape.svg|32px]] Create Mesh from shape...}} will give you an additional menu to choose your shape to mesh.
#* Press the {{Button|[[Image:Mesh_FromPartShape.svg|16px]] [[Mesh_FromPartShape|Create mesh from shape...]]}} button.
#* Select the {{MenuCommand|Meshes → [[Image:Mesh_FromPartShape.svg|16px]] Create mesh from shape...}} option from the menu.
# The {{MenuCommand|Tessellation}} task panel opens.
# While the task panel is open you can create a new selection or change an existing selection.
# Select the tab for the mesher you wish to use.
# Specify the required settings. See [[#Meshers|Meshers]].
# Press the {{Button|OK}} button to close the task panel and finish the command.


<!--T:6-->
==Meshers== <!--T:7-->
In both cases you get a menu that asks for the mesher program to use and its settings.<br/>
The settings you make there will be stored and used as default for the next time you create a mesh from a shape. {{Version|0.19}}.

==Mesher program== <!--T:7-->


<!--T:8-->
<!--T:8-->
These are the available meshers and their settings:
You can choose one of these 3 mesher programs:


===Standard Mesher=== <!--T:9-->
===Standard mesher=== <!--T:9-->

<!--T:10-->
[[Image:Mesh_Mesher_Standard.jpg]]


<!--T:11-->
<!--T:11-->
* {{MenuCommand|Surface deviation}}: the maximum [https://www.opencascade.com/doc/occt-7.3.0/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_11_2 linear deviation] of a mesh section from the surface of the object.
You can change these settings:
* {{MenuCommand|Surface deviation}}: Maximal [https://www.opencascade.com/doc/occt-7.3.0/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_11_2 linear deflection] of a mesh section from the surface of the object
* {{MenuCommand|Angular deviation}}: the maximum [https://www.opencascade.com/doc/occt-7.3.0/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_11_2 angular deviation] from one mesh section to the next. This setting is used when meshing curved surfaces.
* {{MenuCommand|Relative surface deviation}}: if checked, the maximum linear deviation of a mesh segment will be the specified {{MenuCommand|Surface deviation}} multiplied by the length of the current mesh segment (edge).
* {{MenuCommand|Angular deviation}}: Maximal [https://www.opencascade.com/doc/occt-7.3.0/overview/html/occt_user_guides__modeling_algos.html#occt_modalg_11_2 angular deflection] from one mesh section to the next section
* {{MenuCommand|Relative surface deviation}}: If checked, the maximal linear deviation of a mesh segment will be the specified {{MenuCommand|Surface deviation}} multiplied by the length of the current mesh segment (edge)
* {{MenuCommand|Apply face colors to mesh}}: if checked, the mesh will get the face colors of the object.
* {{MenuCommand|Apply face colors to mesh}}: If checked, the mesh will get the face colors of the object
* {{MenuCommand|Define segments by face colors}}: if checked, mesh segments will be grouped according to the colors of the object's faces. These groups will be exported for mesh output formats supporting this feature (the [https://en.wikipedia.org/wiki/Wavefront_.obj_file OBJ] format for example).
* {{MenuCommand|Define segments by face colors}}: If checked, mesh segments will be grouped according to the color of the object faces. These groups will be exported for mesh output formats supporting this feature (e.g. the format [https://en.wikipedia.org/wiki/Wavefront_.obj_file OBJ]).


===Mefisto Mesher=== <!--T:12-->
===Mefisto mesher=== <!--T:12-->

<!--T:13-->
[[Image:Mesh_Mesher_Mefisto.jpg]]


<!--T:14-->
<!--T:14-->
* {{MenuCommand|Maximum edge length}}: the maximum edge length of the mesh. A smaller value results in a finer mesh. Specifying {{Value|0}}, or unchecking the checkbox, results in a very coarse mesh.
The only setting is:
*{{MenuCommand|Maximum edge length}}: If this number is smaller the mesh becomes finer. The smallest value is 0.
** If you press the {{Button|Estimate}} button the mesher will enter an estimated value for the {{MenuCommand|Maximum edge length}}. This value is not very reliable if multiple objects have been selected.

===Netgen Mesher=== <!--T:15-->


<!--T:16-->
===Netgen mesher=== <!--T:15-->
[[Image:Mesh_Mesher_Netgen.jpg]]


<!--T:17-->
<!--T:17-->
You can choose between mesh {{MenuCommand|Fineness }} being:
* {{MenuCommand|Fineness}}: select an options for the finesse of the mesh:
*{{MenuCommand|Very coarse}}
** {{MenuCommand|Very coarse}}
*{{MenuCommand|Coarse}}
** {{MenuCommand|Coarse}}
*{{MenuCommand|Moderate}}
** {{MenuCommand|Moderate}}
*{{MenuCommand|Fine}}
** {{MenuCommand|Fine}}
*{{MenuCommand|Very fine}}
** {{MenuCommand|Very fine}}
*{{MenuCommand|User defined}}
** {{MenuCommand|User defined}}: for this option the following settings can be specified:
*** {{MenuCommand|Mesh size grading}}: a smaller value results in a finer mesh. The value must be in the {{Value|0.1}} - {{Value|1.0}} range.
:For this you can set these values:
:{{MenuCommand|Mesh size grading}}: If this parameter is smaller, the mesh becomes finer. A value in the range of 0.1-1.
*** {{MenuCommand|Element per edge}}: a larger value results in a finer mesh. The value must be in the {{Value|0.2}} - {{Value|10.0}} range.
:{{MenuCommand|Element per edge}}: If this parameter is larger, the mesh becomes finer. A value in the range of 0.2-10.
*** {{MenuCommand|Element per curvature radius}}: a larger value results in a finer mesh. The value must be in the {{Value|0.2}} - {{Value|10}} range.
:{{MenuCommand|Element per curvature radius}}: If this parameter is larger, the mesh becomes finer. A value in the range of 0.2-10.
*{{MenuCommand|Optimize surface}}: if checked, the surface shape will be optimized.
*{{MenuCommand|Second order elements}}: if checked, second order elements will be generated resulting in a finer mesh.
*{{MenuCommand|Quad dominated}}: if checked, the mesh will preferably use [https://en.wikipedia.org/wiki/Types_of_mesh#Two-dimensional quadrilateral faces].


<!--T:18-->
===Gmsh mesher=== <!--T:27-->
For every {{MenuCommand|Fineness}} you can also choose:
*{{MenuCommand|Optimize surface}}: Whether an optimization of surface shape will be done.
*{{MenuCommand|Second order elements}}: Whether second order elements will be generated.
*{{MenuCommand|Quad dominated}}: Whether meshes will be arranged preferably using [https://en.wikipedia.org/wiki/Types_of_mesh#Two-dimensional quadrilateral faces].


== Scripting == <!--T:19-->
<!--T:29-->
For Linux users: the external [https://gmsh.info/ Gmsh] module is required.

<!--T:30-->
* {{MenuCommand|Meshing}}: select a meshing option:
** {{MenuCommand|Automatic}}
** {{MenuCommand|Adaptive}}
** {{MenuCommand|Delaunay}}
** {{MenuCommand|Frontal}}
** {{MenuCommand|BAMG}}
** {{MenuCommand|Frontal Quad}}
** {{MenuCommand|Parallelograms}}
* {{MenuCommand|Max. element size}}: a smaller value results in a finer mesh. Specify {{Value|0}} to have this size automatically determined.
* {{MenuCommand|Min. element size}}: a smaller value results in a finer mesh. The value should be smaller than the {{MenuCommand|Max. element size}}. Specify {{Value|0}} to have this size automatically determined.
* {{MenuCommand|Angle}}: seems to be unsupported at this time.
* {{MenuCommand|Path}}: press the {{Button|...}} button and browse to the {{FileName|gmsh.exe}} path.
* If the meshing process takes too long you can press the {{Button|Kill}} button to abort it.
* Press the {{Button|Clear}} button to remove the information in the text area. <!--Because the task panel closes the Clear button cannot be used with this command. But the same task panel is used for the Mesh_RemeshGmsh command-->

==Notes== <!--T:22-->

<!--T:31-->
* This command is not restricted to objects created with the [[Part_Workbench|Part workbench]]. It can create a mesh from any object that has a shape including objects created with the [[PartDesign_Workbench|PartDesign workbench]].
* The [[Std_Export|Std Export]] command can export shape objects directly to a mesh format.
* See also: [[Export_to_STL_or_OBJ|Export to STL or OBJ]] tutorial.

==Preferences== <!--T:32-->

===Standard mesher=== <!--T:33-->

<!--T:34-->
* The {{MenuCommand|Surface deviation}} setting is stored: {{MenuCommand|Tools → Edit parameters... → BaseApp → Preferences → Mod → Mesh → Meshing → Standard → LinearDeflection}}.
* The {{MenuCommand|Angular deviation}} setting is stored: {{MenuCommand|Tools → Edit parameters... → BaseApp → Preferences → Mod → Mesh → Meshing → Standard → AngularDeflection}}.
* The {{MenuCommand|Relative surface deviation}} setting is stored: {{MenuCommand|Tools → Edit parameters... → BaseApp → Preferences → Mod → Mesh → Meshing → Standard → RelativeLinearDeflection}}.

===Gmsh mesher=== <!--T:35-->

<!--T:36-->
* The {{MenuCommand|Path}} is stored: {{MenuCommand|Tools → Edit parameters... → BaseApp → Preferences → Mod → Mesh → Meshing → gmshExe}}.

==Properties== <!--T:37-->

<!--T:38-->
See: [[Mesh_Feature|Mesh Feature]].

==Scripting== <!--T:19-->

<!--T:39-->
See also: [[FreeCAD_Scripting_Basics|FreeCAD Scripting Basics]].


<!--T:20-->
<!--T:20-->
To create a mesh object from a shape object use the {{incode|meshFromShape}} method of the MeshPart module. This method has several signatures. The signature determines the mesher that will be used. The example below uses the Mefisto mesher signature.
This tool can be used in [[macros|macros]] and from the [[Python|Python]] console by using the following function:
</translate>
{{Code|code=
MeshPart.meshFromShape(Shape=Shape, MaxLength=520)
}}
<translate>


<!--T:21-->
Example:
</translate>
</translate>
{{Code|code=
{{Code|code=
import FreeCAD, Draft, Arch, Mesh, MeshPart
import FreeCAD, Part, Mesh, MeshPart


cyl = FreeCAD.ActiveDocument.addObject("Part::Cylinder","Cylinder")
Line = Draft.makeWire([FreeCAD.Vector(0, 0, 0),FreeCAD.Vector(2000, 2000, 0)])
Wall = Arch.makeWall(Line, width=150, height=3000)
FreeCAD.ActiveDocument.recompute()
FreeCAD.ActiveDocument.recompute()


msh = FreeCAD.ActiveDocument.addObject("Mesh::Feature", "Mesh")
Shape = Wall.Shape.copy(False)
msh.Mesh = MeshPart.meshFromShape(Shape=cyl.Shape, MaxLength=1)
Shape.Placement = Wall.getGlobalPlacement()
msh.ViewObject.DisplayMode = "Flat Lines"

mesh_obj = FreeCAD.ActiveDocument.addObject("Mesh::Feature", "Mesh")
mesh_obj.Mesh = MeshPart.meshFromShape(Shape=Shape, MaxLength=520)
mesh_obj.ViewObject.DisplayMode = "Flat Lines"
}}
}}
<translate>
<translate>


==Notes== <!--T:22-->
* Tutorial: [[Export_to_STL_or_OBJ|Export_to_STL_or_OBJ]]


<!--T:23-->
<!--T:23-->
{{Docnav
{{Docnav|[[Mesh Export|Export Mesh]]|[[Mesh CurvaturePlot|Curvature Plot]]|[[Mesh_Workbench|Mesh]]|IconL=Mesh_ExportMesh.png|IconC=Workbench_Mesh.svg|IconR=Mesh_CurvaturePlot.png}}
|[[Mesh_Export|Export]]

|[[Mesh_RemeshGmsh|RemeshGmsh]]
<!--T:24-->
|[[Mesh_Workbench|Mesh]]
{{Mesh Tools navi}}
|IconL=Mesh_Export.svg

|IconR=Mesh_RemeshGmsh.svg
<!--T:25-->
|IconC=Workbench_Mesh.svg
{{Userdocnavi}}
}}


</translate>
</translate>
{{Mesh Tools navi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}
{{clear}}

Latest revision as of 16:26, 25 November 2023

Mesh FromPartShape

Menu location
Meshes → Create mesh from shape...
Workbenches
Mesh
Default shortcut
None
Introduced in version
-
See also
None

Description

The Mesh_FromPartShape command creates non-parametric mesh objects (Mesh Features) from shape objects (Part Features).

The inverse operation is Part ShapeFromMesh from the Part Workbench.

Usage

  1. Optionally select one or more objects.
  2. There are several ways to invoke the command:
  3. The Tessellation task panel opens.
  4. While the task panel is open you can create a new selection or change an existing selection.
  5. Select the tab for the mesher you wish to use.
  6. Specify the required settings. See Meshers.
  7. Press the OK button to close the task panel and finish the command.

Meshers

These are the available meshers and their settings:

Standard mesher

  • Surface deviation: the maximum linear deviation of a mesh section from the surface of the object.
  • Angular deviation: the maximum angular deviation from one mesh section to the next. This setting is used when meshing curved surfaces.
  • Relative surface deviation: if checked, the maximum linear deviation of a mesh segment will be the specified Surface deviation multiplied by the length of the current mesh segment (edge).
  • Apply face colors to mesh: if checked, the mesh will get the face colors of the object.
  • Define segments by face colors: if checked, mesh segments will be grouped according to the colors of the object's faces. These groups will be exported for mesh output formats supporting this feature (the OBJ format for example).

Mefisto mesher

  • Maximum edge length: the maximum edge length of the mesh. A smaller value results in a finer mesh. Specifying 0, or unchecking the checkbox, results in a very coarse mesh.
    • If you press the Estimate button the mesher will enter an estimated value for the Maximum edge length. This value is not very reliable if multiple objects have been selected.

Netgen mesher

  • Fineness: select an options for the finesse of the mesh:
    • Very coarse
    • Coarse
    • Moderate
    • Fine
    • Very fine
    • User defined: for this option the following settings can be specified:
      • Mesh size grading: a smaller value results in a finer mesh. The value must be in the 0.1 - 1.0 range.
      • Element per edge: a larger value results in a finer mesh. The value must be in the 0.2 - 10.0 range.
      • Element per curvature radius: a larger value results in a finer mesh. The value must be in the 0.2 - 10 range.
  • Optimize surface: if checked, the surface shape will be optimized.
  • Second order elements: if checked, second order elements will be generated resulting in a finer mesh.
  • Quad dominated: if checked, the mesh will preferably use quadrilateral faces.

Gmsh mesher

For Linux users: the external Gmsh module is required.

  • Meshing: select a meshing option:
    • Automatic
    • Adaptive
    • Delaunay
    • Frontal
    • BAMG
    • Frontal Quad
    • Parallelograms
  • Max. element size: a smaller value results in a finer mesh. Specify 0 to have this size automatically determined.
  • Min. element size: a smaller value results in a finer mesh. The value should be smaller than the Max. element size. Specify 0 to have this size automatically determined.
  • Angle: seems to be unsupported at this time.
  • Path: press the ... button and browse to the gmsh.exe path.
  • If the meshing process takes too long you can press the Kill button to abort it.
  • Press the Clear button to remove the information in the text area.

Notes

Preferences

Standard mesher

  • The Surface deviation setting is stored: Tools → Edit parameters... → BaseApp → Preferences → Mod → Mesh → Meshing → Standard → LinearDeflection.
  • The Angular deviation setting is stored: Tools → Edit parameters... → BaseApp → Preferences → Mod → Mesh → Meshing → Standard → AngularDeflection.
  • The Relative surface deviation setting is stored: Tools → Edit parameters... → BaseApp → Preferences → Mod → Mesh → Meshing → Standard → RelativeLinearDeflection.

Gmsh mesher

  • The Path is stored: Tools → Edit parameters... → BaseApp → Preferences → Mod → Mesh → Meshing → gmshExe.

Properties

See: Mesh Feature.

Scripting

See also: FreeCAD Scripting Basics.

To create a mesh object from a shape object use the meshFromShape method of the MeshPart module. This method has several signatures. The signature determines the mesher that will be used. The example below uses the Mefisto mesher signature.

import FreeCAD, Part, Mesh, MeshPart

cyl = FreeCAD.ActiveDocument.addObject("Part::Cylinder","Cylinder")
FreeCAD.ActiveDocument.recompute()

msh = FreeCAD.ActiveDocument.addObject("Mesh::Feature", "Mesh")
msh.Mesh = MeshPart.meshFromShape(Shape=cyl.Shape, MaxLength=1)
msh.ViewObject.DisplayMode = "Flat Lines"