-
Notifications
You must be signed in to change notification settings - Fork 18
pytha.create_part_from_mesh
Creates a part in PYTHA from a triangle mesh.
Builds a single part from a shared list of vertices and a list of triangular faces that index into it. This is the in-memory equivalent of importing a triangle mesh (e.g. an STL file).
Note: Only triangular faces are supported, and the faces may not contain holes or arcs. For a single flat face with holes or arcs, use create_polygon_ex instead.
pytha.create_part_from_mesh(points, faces [,origin [,options]])| Parameter | Type | Description |
|---|---|---|
points |
{{x,y,z}, ...} |
Shared vertex pool. Faces reference these vertices by 1-based index. |
faces |
{{i1,i2,i3}, ...} |
Triangles, each a triple of indices into points. Each index must be in [1..#points]. Triangles in which two indices are equal are silently discarded. |
origin |
{x,y,z} |
Optional: offset of the whole mesh |
options |
{...} |
Optional: a table that may contain the following options: |
options.u_axis |
{x,y,z} |
Local coordinate u-axis for the orientation of the mesh |
options.v_axis |
{x,y,z} |
Local coordinate v-axis for the orientation of the mesh |
options.w_axis |
{x,y,z} |
Local coordinate w-axis for the orientation of the mesh |
options.melt_points |
boolean |
false (default), true; welds geometrically coincident vertices that were supplied with separate indices (repairs open seams in a triangle soup) |
options.melt_faces |
boolean |
false (default), true; merges adjacent coplanar faces into larger faces (the result is then no longer a pure triangle mesh) |
| Type | Description |
|---|---|
element_handle |
An element handle of the newly created part |
Each triangle must be wound counter-clockwise (CCW) as seen from outside the solid, i.e. its vertices appear in CCW order when looking at the face against its outward-pointing normal (right-hand rule). For an internal surface (a bore or a socket) "outside" is the empty space, so its CCW winding makes the normal point into the cavity, away from the material. Wind every face consistently to this rule — a mix of CCW and CW faces yields inverted (back-facing) surfaces.
- Indices are 1-based, consistent with the rest of the API and with
points[i]. - Vertices shared between triangles via the same index are shared in the resulting part automatically; coincident vertices supplied with different indices are only welded when
melt_pointsis enabled. - Both closed solids and open shells are supported.
A cube (8 vertices, 12 triangles):
local cube = pytha.create_part_from_mesh(
{
{0, 0, 0}, {10, 0, 0}, {10, 10, 0}, {0, 10, 0}, -- bottom
{0, 0, 10}, {10, 0, 10}, {10, 10, 10}, {0, 10, 10}, -- top
},
{
{1, 3, 2}, {1, 4, 3}, -- bottom
{5, 6, 7}, {5, 7, 8}, -- top
{1, 2, 6}, {1, 6, 5}, -- front
{2, 3, 7}, {2, 7, 6}, -- right
{3, 4, 8}, {3, 8, 7}, -- back
{4, 1, 5}, {4, 5, 8}, -- left
}
)A soup whose seam vertices are duplicated, welded into a single watertight part:
local part = pytha.create_part_from_mesh(points, faces, {0, 0, 0}, { melt_points = true })Minimum PYTHA Version: V27
pytha, element handles, Axes and directions, create_polygon_ex, import_pyo