Ë
    Jÿi†T  ã                   óX  — d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZmZ dd	lmZ dd
lmZ ddlmZ ddl m!Z! ddlm"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6  G d„ d«      Z7y)aÍ  
build123d exporter/import for 3MF and STL

name: mesher.py
by:   Gumyr
date: Aug 9th 2023

desc:
    This module provides the Mesher class that implements exporting and importing
    both 3MF and STL mesh files.  It uses the 3MF Consortium's Lib3MF library
    (see https://github.com/3MFConsortium/lib3mf).

    Creating a 3MF object involves constructing a valid 3D model conforming to
    the 3MF specification. The resource hierarchy represents the various
    components that make up a 3MF object. The main components required to create
    a 3MF object are:

        Wrapper: The wrapper is the highest-level component representing the
    entire 3MF model. It serves as a container for all other resources and
    provides access to the complete 3D model. The wrapper is the starting point
    for creating and managing the 3MF model.

        Model: The model is a core component that contains the geometric and
    non-geometric resources of the 3D object. It represents the actual 3D
    content, including geometry, materials, colors, textures, and other model
    information.

        Resources: Within the model, various resources are used to define
    different aspects of the 3D object. Some essential resources are:

        a. Mesh: The mesh resource defines the geometry of the 3D object. It
    contains a collection of vertices, triangles, and other geometric
    information that describes the shape.

        b. Components: Components allow you to define complex structures by
    combining multiple meshes together. They are useful for hierarchical
    assemblies and instances.

        c. Materials: Materials define the appearance properties of the
    surfaces, such as color, texture, or surface finish.

        d. Textures: Textures are images applied to the surfaces of the 3D
    object to add detail and realism.

        e. Colors: Colors represent color information used in the 3D model,
    which can be applied to vertices or faces.

        Build Items: Build items are the instances of resources used in the 3D
    model. They specify the usage of resources within the model. For example, a
    build item can refer to a specific mesh, material, and transformation to
    represent an instance of an object.

        Metadata: Metadata provides additional information about the model, such
    as author, creation date, and custom properties.

        Attachments: Attachments can include additional files or data associated
    with the 3MF object, such as texture images or other external resources.

    When creating a 3MF object, you typically start with the wrapper and then
    create or import the necessary resources, such as meshes, materials, and
    textures, to define the 3D content. You then organize the model using build
    items, specifying how the resources are used in the scene. Additionally, you
    can add metadata and attachments as needed to complete the 3MF object.

license:

    Copyright 2023 Gumyr

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
é    N)ÚPathLikeÚfsdecode)ÚUnion)ÚUUID)ÚIterable)Ú	BRep_Tool)ÚBRepBuilderAPI_MakeFaceÚBRepBuilderAPI_MakePolygonÚBRepBuilderAPI_MakeSolidÚBRepBuilderAPI_Sewing)Ú	BRepGProp)ÚBRepMesh_IncrementalMesh)Úgp_Pnt)ÚGProp_GProps)ÚTopAbs_ShapeEnum)ÚTopExp_Explorer)ÚTopLoc_Location)ÚTopoDS_Compound)ÚLib3MF)ÚMeshTypeÚUnit)Ú	TOLERANCEÚColor)ÚCompoundÚShapeÚShellÚSolidÚdowncastc                   ót  — e Zd ZdZej
                  ej                  j                  ej                  ej                  j                  ej                  ej                  j                  ej                  ej                  j                  ej                  ej                  j                   ej"                  ej                  j$                  iZej)                  «       D � ��ci c]  \  }}||“Œ
 c}}} Zej.                  ej0                  j2                  ej4                  ej0                  j6                  ej8                  ej0                  j:                  ej<                  ej0                  j>                  iZ e j)                  «       D � ��ci c]  \  }}||“Œ
 c}}} Z!ej                  fdefd„Z"e#defd„«       Z$e#de%e&   fd„«       Z'e#de%e&   fd„«       Z(e#de&fd„«       Z)e#de*fd	„«       Z+d
e*de*de*de*de,f
d„Z-d„ Z.de%e/   fd„Z0d
e*de*de/fd„Z1de%e/   fd„Z2e3de4de5de5fd„«       Z6e3de%e7e5e5e5f      de%e%e&      fd„«       Z8de4dejr                  fd„Z:ddej4                  d d fd!e4e;e4   z  de5de5d"ed#e*d z  d$e<d z  fd%„Z=dejr                  de4fd&„Z>d'e?e*z  e@z  de%e4   fd(„ZAd'e?e*z  e@z  fd)„ZBy c c}}} w c c}}} w )*ÚMesherz¨Mesher

    Tool for exporting and importing meshed objects stored in 3MF or STL files.

    Args:
        unit (Unit, optional): model units. Defaults to Unit.MM.
    Úunitc                 óè   — || _         t        j                  «       | _        | j                  j	                  «       | _        | j
                  j                  t        j                  |   «       g | _	        y )N)
r!   r   ÚWrapperÚwrapperÚCreateModelÚmodelÚSetUnitr    Ú_map_b3d_to_3mf_unitÚmeshes)Úselfr!   s     úa/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/build123d/mesher.pyÚ__init__zMesher.__init__–   sO   € ØˆŒ	Ü—~‘~Ó'ˆŒØ—\‘\×-Ñ-Ó/ˆŒ
Ø�
‰
×Ñœ6×6Ñ6°tÑ<Ô=Ø/1ˆ�ó    Úreturnc                 ó   — | j                   S )zUnit used in the model)r!   )r*   s    r+   Ú
model_unitzMesher.model_unit�   s   € ð �y‰yÐr-   c                 ó\   — | j                   D �cg c]  }|j                  «       ‘Œ c}S c c}w )z1Number of triangles in each of the model's meshes)r)   ÚGetTriangleCount©r*   Úms     r+   Útriangle_countszMesher.triangle_counts¢   s)   € ð /3¯kªkÓ:©k¨�×"Ñ"Õ$¨kÑ:Ð:ùÒ:ó   �)c                 ó\   — | j                   D �cg c]  }|j                  «       ‘Œ c}S c c}w )z1Number of vertices in each of the models's meshes)r)   ÚGetVertexCountr3   s     r+   Úvertex_countszMesher.vertex_counts§   s)   € ð -1¯KªKÓ8©K q�× Ñ Õ"¨KÑ8Ð8ùÒ8r6   c                 óV   — | j                   j                  «       }|j                  «       S )zNumber of meshes in the model)r&   ÚGetMeshObjectsÚCount)r*   Úmesh_iterators     r+   Ú
mesh_countzMesher.mesh_count¬   s%   € ð 48·:±:×3LÑ3LÓ3NˆØ×"Ñ"Ó$Ð$r-   c                 óR   — | j                   j                  «       \  }}}|› d|› d|› �S )z3MF Consortium Lib#MF versionÚ.)r$   ÚGetLibraryVersion)r*   ÚmajorÚminorÚmicros       r+   Úlibrary_versionzMesher.library_version²   s4   € ð #Ÿl™l×<Ñ<Ó>Ñˆˆu�eØ�˜˜%˜  % Ð)Ð)r-   Ú
name_spaceÚnameÚvalueÚmetadata_typeÚmust_preservec                 óº   — | j                   j                  «       }|€*| j                   j                  «       }|j                  «       }|j                  |||||«       y)a[  add_meta_data

        Add meta data to the models

        Args:
            name_space (str): categorizer of different metadata entries
            name (str): metadata label
            value (str): metadata content
            metadata_type (str): metadata type
            must_preserve (bool): metadata must not be removed if unused
        N)r&   ÚGetMetaDataGroupÚAddComponentsObjectÚAddMetaData)r*   rF   rG   rH   rI   rJ   ÚmdgÚ
componentss           r+   Úadd_meta_datazMesher.add_meta_data¸   sQ   € ð( �j‰j×)Ñ)Ó+ˆØˆ;à26·*±*×2PÑ2PÓ2RˆJØ×-Ñ-Ó/ˆCð 	�‰˜
 D¨%°ÀÕNr-   c                 ó2  — t        j                  «       j                  j                  j                  }t        |d¬«      5 }|j                  «       }ddd«       | j                  dt        j                  j                  |«      dd¬«       y# 1 sw Y   Œ=xY w)z¦Add the code calling this method to the 3MF metadata with the custom
        name space `build123d`, name equal to the base file name and the type
        as `python`zutf-8)ÚencodingNÚ	build123dÚpythonF)rF   rG   rH   rI   rJ   )ÚsysÚ	_getframeÚf_backÚf_codeÚco_filenameÚopenÚreadrQ   ÚosÚpathÚbasename)r*   Úcaller_fileÚ	code_fileÚsource_codes       r+   Úadd_code_to_metadatazMesher.add_code_to_metadataÕ   sz   € ô —m‘m“o×,Ñ,×3Ñ3×?Ñ?ˆÜ�+¨Õ0°IØ#Ÿ.™.Ó*ˆK÷ 1ð 	×ÑØ"Ü—‘×!Ñ! +Ó.ØØ"Øð 	õ 	
÷ 1Ð0ús   Á BÂBc                 óZ  — | j                   j                  «       }g }t        |j                  «       «      D ]r  }|j	                  |«      }i }|j                  «       |d<   |j                  «       |d<   |j                  «       |d<   |j                  «       |d<   |j                  |«       Œt |S )zRetrieve all of the metadatarF   rG   ÚtyperH   )
r&   rL   ÚrangeÚGetMetaDataCountÚGetMetaDataÚGetNameSpaceÚGetNameÚGetTypeÚGetValueÚappend)r*   Úmeta_data_groupÚmeta_data_contentsÚiÚ	meta_dataÚmeta_data_dicts         r+   Úget_meta_datazMesher.get_meta_dataå   s©   € àŸ*™*×5Ñ5Ó7ˆØÐÜ�×7Ñ7Ó9Ö:ˆAØ'×3Ñ3°AÓ6ˆIØˆNØ+4×+AÑ+AÓ+CˆN˜<Ñ(Ø%.×%6Ñ%6Ó%8ˆN˜6Ñ"Ø%.×%6Ñ%6Ó%8ˆN˜6Ñ"Ø&/×&8Ñ&8Ó&:ˆN˜7Ñ#Ø×%Ñ% nÕ5ð ;ð "Ð!r-   c                 ó®   — | j                   j                  «       }i }|j                  ||«      }|j                  «       |d<   |j	                  «       |d<   |S )zIRetrieve the metadata value and type for the provided name space and namere   rH   )r&   rL   ÚGetMetaDataByKeyrk   rl   )r*   rF   rG   rn   ro   rq   s         r+   Úget_meta_data_by_keyzMesher.get_meta_data_by_keyó   sZ   € àŸ*™*×5Ñ5Ó7ˆØÐØ#×4Ñ4°ZÀÓFˆ	Ø%.×%6Ñ%6Ó%8Ð˜6Ñ"Ø&/×&8Ñ&8Ó&:Ð˜7Ñ#Ø!Ð!r-   c                 óT  — g }| j                   D ]–  }i }|j                  «       |d<   |j                  «       |d<   t        j                  |j                  «       «      }t        j                  |   j                  |d<   |j                  «       \  }}||d<   |j                  |«       Œ˜ |S )z+Retrieve the properties from all the meshesrG   Úpart_numberre   Úuuid)r)   rj   ÚGetPartNumberr   Ú
ObjectTyperk   r    Ú_map_3mf_to_b3d_mesh_typerG   ÚGetUUIDrm   )r*   Ú
propertiesÚmeshÚproperty_dictÚtype_3mfÚ_uuid_validÚ
uuid_values          r+   Úget_mesh_propertieszMesher.get_mesh_propertiesü   sž   € àˆ
Ø—K”KˆDØˆMØ$(§L¡L£NˆM˜&Ñ!Ø+/×+=Ñ+=Ó+?ˆM˜-Ñ(Ü×(Ñ(¨¯©«Ó8ˆHÜ$*×$DÑ$DÀXÑ$N×$SÑ$SˆM˜&Ñ!Ø&*§l¡l£nÑ#ˆK˜Ø$.ˆM˜&Ñ!Ø×Ñ˜mÕ,ð  ð Ðr-   Úocp_meshÚlinear_deflectionÚangular_deflectionc           
      ó  — t        «       }t        | j                  |d|d¬«       g }g }d}| j                  «       D �]G  }t	        j
                  |j                  |«      }|j                  «       }	|j                  «       }
t        d|
dz   «      D ]b  }|j                  |«      j                  |	«      }|j                  «       |j                  «       |j                  «       f}|j                  |«       Œd |j                  €ŒÅ|j                  j                  «       t         j"                  k(  }|rg d¢ng d¢}|j%                  «       D ]6  }|j                  |D �cg c]  }|j'                  |«      |z   dz
  ‘Œ c}«       Œ8 ||
z  }�ŒJ ||fS c c}w )z*Mesh the shape into vertices and trianglesT)ÚtheShapeÚtheLinDeflectionÚ
isRelativeÚtheAngDeflectionÚisInParallelr   é   )rŽ   é   é   )rŽ   r�   r�   )r   r   ÚwrappedÚfacesr   ÚTriangulation_sÚTransformationÚNbNodesrf   ÚNodeÚTransformedÚXÚYÚZrm   ÚOrientationÚtaÚTopAbs_REVERSEDÚ	TrianglesÚValue)r…   r†   r‡   ÚlocÚocp_mesh_verticesÚ	trianglesÚoffsetÚfacetÚpoly_triangulationÚtrsfÚ
node_countrp   Úgp_pntÚpntÚfacet_reversedÚorderÚtris                    r+   Ú_mesh_shapezMesher._mesh_shape
  so  € ô ÓˆÜ Ø×%Ñ%Ø.ØØ/Øõ	
ð ÐØˆ	ØˆØ—^‘^×%ˆEä!*×!:Ñ!:¸5¿=¹=È#Ó!NÐØ×%Ñ%Ó'ˆDà+×3Ñ3Ó5ˆJÜ˜1˜j¨1™nÖ-�Ø+×0Ñ0°Ó3×?Ñ?ÀÓE�Ø—x‘x“z 6§8¡8£:¨v¯x©x«zÐ:�Ø!×(Ñ(¨Õ-ð .ð �}‰}Ð$ØØ"Ÿ]™]×6Ñ6Ó8¼B×<NÑ<NÑNˆNÙ!/“I²YˆEØ)×3Ñ3Ö5�Ø× Ñ ÁUÓ!KÁUÀ #§)¡)¨A£,°Ñ"7¸!Ó";ÀUÑ!KÕLð 6à�jÑ ŠFð% &ð& ! )Ð+Ð+ùò "Ls   ÅF
r¡   r¢   c           
      ó’  — t        t        t        j                  t        d«      d«      «       }i }d}i }t        | «      D ]B  \  }\  }}}	t        ||«      t        ||«      t        |	|«      f}
|
|vr
|||
<   |dz  }||
   ||<   ŒD |j                  «       D �cg c]*  }t        j                  t        j                  dz  |Ž «      ‘Œ, }}t        j                  dz  }g }|D ]^  }|d   |d   |d   }}}||   }||   }||   }||k7  sŒ'||k7  sŒ-||k7  sŒ3|j                  t        j                   ||||«      «      «       Œ` ||fS c c}w )Né
   rŽ   r   r�   r�   )ÚintÚroundÚmathÚlogr   Ú	enumerateÚkeysr   ÚPositionÚctypesÚc_floatÚc_uintrm   ÚTriangle)r¡   r¢   ÚdigitsÚvertex_to_idxÚnext_idxÚ
vert_tablerp   ÚxÚyÚzÚkeyÚvÚvertices_3mfÚc_uint3Útriangles_3mfr¬   ÚaÚbÚcÚmapped_aÚmapped_bÚmapped_cs                         r+   Ú_create_3mf_meshzMesher._create_3mf_mesh2  s|  € ô ”eœDŸH™H¤Y°Ó3°QÓ7Ó8Ð8ˆð ˆØˆØˆ
ô &Ð&7Ö8‰LˆA‰y��1�aÜ˜˜FÓ#¤U¨1¨fÓ%5´u¸QÀÓ7GÐHˆCØ˜-Ñ'Ø%-�˜cÑ"Ø˜A‘�Ø)¨#Ñ.ˆJ�qŠMð 9ð #×'Ñ'Ô)ó
á)�ô �O‰OœVŸ^™^¨aÑ/°!Ð4Õ5Ø)ð 	ð 
ô —-‘- !Ñ#ˆØˆó ˆCà˜!‘f˜c !™f c¨!¡f�!ˆqˆAØ! !‘}ˆHØ! !‘}ˆHØ! !‘}ˆHð ˜8Ó#¨°HÓ(<ÀÈXÓAUØ×$Ñ$¤V§_¡_±W¸XÀxÐQYÓ5ZÓ%[Õ\ð ð ˜mÐ,Ð,ùò+
s   Â/EÚ	b3d_shapeÚmesh_3mfc                 ó6  — |j                   r�| j                  j                  «       } | j                  j                  t        |j                   «      Ž }|j                  t        |j                   «      |¬«      }|j                  |j                  «       |«       yy)z&Transfer color info from shape to mesh)ÚNameÚDisplayColorN)
Úcolorr&   ÚAddBaseMaterialGroupr$   ÚFloatRGBAToColorÚtupleÚAddMaterialÚstrÚSetObjectLevelPropertyÚGetResourceID)r*   rÎ   rÏ   Úbase_material_groupÚcolor_lib3mfÚbase_material_ids         r+   Ú
_add_colorzMesher._add_color`  sƒ   € à�?Š?Ø"&§*¡*×"AÑ"AÓ"CÐØ8˜4Ÿ<™<×8Ñ8¼%À	ÇÁÓ:PÐQˆLØ2×>Ñ>Ü˜Ÿ™Ó)¸ð  ?ó  Ðð ×+Ñ+Ø#×1Ñ1Ó3Ð5Eõð r-   gü©ñÒMbP?gš™™™™™¹?NÚshapeÚ	mesh_typerx   rƒ   c                 óÀ  — g }t        |t        «      r|n|gD ]>  }t        |t        «      r|j                  t	        |«      «       Œ.|j                  |«       Œ@ |D �]   }	| j                  j                  «       }
t        j                  t        j                  |	«      ||«      \  }}t        |«      dk  s|st        j                  d|	› d�d¬«       Œwt        j                  ||«      \  }}|
j!                  ||«       |
j#                  t        j$                  |   «       |	j&                  r|
j)                  |	j&                  «       |r|
j+                  |«       |r|
j-                  t/        |«      «       | j1                  |	|
«       |
j3                  «       st5        d«      ‚|
j7                  «       st        j                  dd¬«       | j8                  j                  |
«       | j                  j;                  |
| j<                  j?                  «       «       | j                  jA                  «       }|jC                  |
| j<                  j?                  «       «       �Œ y)	a÷  add_shape

        Add a shape to the 3MF/STL file.

        Args:
            shape (Union[Shape, Iterable[Shape]]): build123d object
            linear_deflection (float, optional): mesh control for edges. Defaults to 0.001.
            angular_deflection (float, optional): mesh control for non-planar surfaces.
                Defaults to 0.1.
            mesh_type (MeshType, optional): 3D printing use of mesh. Defaults to MeshType.MODEL.
            part_number (str, optional): part #. Defaults to None.
            uuid_value (uuid, optional): value from uuid package. Defaults to None.

        Raises:
            RuntimeError: 3mf mesh is invalid
            Warning: Degenerate shape skipped
            Warning: 3mf mesh is not manifold
        r�   zDegenerate shape z
 - skippedr�   )Ú
stacklevelz3mf mesh is invalidz3mf mesh is not manifoldN)"Ú
isinstancer   r   ÚextendÚlistrm   r&   ÚAddMeshObjectr    r­   Úcopy_moduleÚdeepcopyÚlenÚwarningsÚwarnrÍ   ÚSetGeometryÚSetTypeÚ_map_b3d_mesh_type_3mfÚlabelÚSetNameÚSetPartNumberÚSetUUIDrØ   rÞ   ÚIsValidÚRuntimeErrorÚIsManifoldAndOrientedr)   ÚAddBuildItemr$   ÚGetIdentityTransformrM   ÚAddComponent)r*   rß   r†   r‡   rà   rx   rƒ   ÚshapesÚinput_shaperÎ   rÏ   r¡   r¢   rÄ   rÆ   rP   s                   r+   Ú	add_shapezMesher.add_shapel  sû  € ð6 ˆÜ$.¨u´hÔ$?™5ÀeÀWÒLˆKÜ˜+¤xÔ0Ø—‘œd ;Ó/Õ0à—‘˜kÕ*ð	 Mô  ˆIà*.¯*©*×*BÑ*BÓ*DˆHô ,2×+=Ñ+=Ü×$Ñ$ YÓ/Ø!Ø"ó,Ñ(Ð˜yô Ð$Ó%¨Ò)±Ü—‘Ø'¨	 {°*Ð=Ø õð ô +1×*AÑ*AØ! 9ó+Ñ'ˆL˜-ð
 × Ñ  ¨}Ô=ð ×ÑœV×:Ñ:¸9ÑEÔFØ�ŠØ× Ñ  §¡Ô1ÙØ×&Ñ& {Ô3ÙØ× Ñ ¤ Z£Ô1ð
 �O‰O˜I xÔ0ð ×#Ñ#Ô%Ü"Ð#8Ó9Ð9Ø×1Ñ1Ô3Ü—‘Ð8ÀQÕGð �K‰K×Ñ˜xÔ(Ø�J‰J×#Ñ# H¨d¯l©l×.OÑ.OÓ.QÔRð Ÿ™×7Ñ7Ó9ˆJØ×#Ñ# H¨d¯l©l×.OÑ.OÓ.QÖRñk  r-   c                 ó  — |j                  «       D �cg c]  }t        |j                  dd Ž ‘Œ }}t        «       }t	        |j                  «       «      D ]·  }|j                  |«      j                  dd }t	        d«      D �cg c]
  }|||      ‘Œ }}t        |ddiŽ}t        |j                  «       «      }	|	j                  «       }
t        «       }t        j                  |
|«       |j                  «       dk7  sŒ§|j!                  |
«       Œ¹ |j#                  «        t%        |j'                  «       «      }t)        |t*        «      rvg }t-        |t.        j0                  «      }|j3                  «       rM|j5                  t%        |j7                  «       «      «       |j9                  «        |j3                  «       rŒIn|g}t;        |«      }|j<                  r!t?        |Ž }tA        |jA                  «       «      }|S c c}w c c}w )z'Build build123d object from lib3mf meshr   r�   ÚCloseT)!ÚGetVerticesr   ÚCoordinatesr   rf   r2   ÚGetTriangleÚIndicesr
   r	   ÚWireÚFacer   r   ÚSurfaceProperties_sÚMassÚAddÚPerformr   Ú
SewedShaperã   r   r   r   ÚTopAbs_SHELLÚMorerm   ÚCurrentÚNextr   Úis_manifoldr   r   )r*   rÏ   ÚpÚgp_pntsÚshell_builderrp   Útri_indicesÚocp_verticesÚpolygon_builderÚface_builderr¤   Úfacet_propertiesÚocc_sewed_shapeÚ
occ_shellsÚexplorerÚ	shape_objÚsolid_builders                    r+   Ú
_get_shapezMesher._get_shapeÅ  sÇ  € ð 9A×8LÑ8LÔ8NÓOÑ8N°1”6˜1Ÿ=™=¨¨1Ð-Ò.Ð8NˆÐOô .Ó/ˆÜ�x×0Ñ0Ó2Ö3ˆAà"×.Ñ.¨qÓ1×9Ñ9¸!¸AÐ>ˆKä=BÀ1¼XÓF¹X¸˜G K°¡NÓ3¸XˆLÐFä8¸,ÐSÈdÑSˆOÜ2°?×3GÑ3GÓ3IÓJˆLØ ×%Ñ%Ó'ˆEÜ+›~ÐÜ×)Ñ)¨%Ð1AÔBØ×$Ñ$Ó&¨!Ó+Ø×!Ñ! %Õ(ð 4ð 	×ÑÔÜ" =×#;Ñ#;Ó#=Ó>ˆä�o¤Ô7ØˆJÜ& Ô8H×8UÑ8UÓVˆHØ—-‘-”/Ø×!Ñ!¤(¨8×+;Ñ+;Ó+=Ó">Ô?Ø—‘”ð —-‘-–/ð *Ð*ˆJô ˜/Ó*ˆ	Ø× Ò Ü4°jÐAˆMÜ˜m×1Ñ1Ó3Ó4ˆIàÐùòK Pùò Gs   “G:ÂG?Ú	file_namec                 óŒ  — t        |«      }t        j                  j                  |«      \  }}|dvrt	        d|› �«      ‚| j
                  j                  |dd «      }|j                  |«       t        j                  | j
                  j                  «          | _        | j
                  j                  «       }t        |j                  «       «      D ];  }|j                  «        | j                   j#                  |j%                  «       «       Œ= g }| j                   D ]£  }| j'                  |«      }	|j)                  «       |	_        |j-                  «       \  }
}}|rT| j
                  j/                  |
«      }|j1                  |«      }| j2                  j5                  |«      }t7        |Ž |	_        |j#                  |	«       Œ¥ |S )a   read

        Args:
            file_name Union[PathLike, str, bytes]: file path

        Raises:
            ValueError: Unknown file format - must be 3mf or stl

        Returns:
            list[Shape]: build123d shapes extracted from mesh file
        ©z.3mfz.stlúUnknown file format rŽ   N)r   r]   r^   ÚsplitextÚ
ValueErrorr&   ÚQueryReaderÚReadFromFiler    Ú_map_3mf_to_b3d_unitÚGetUnitr!   r;   rf   r<   ÚMoveNextr)   rm   ÚGetCurrentMeshObjectr  rj   rï   ÚGetObjectLevelPropertyÚGetBaseMaterialGroupByIDÚGetDisplayColorr$   ÚColorToFloatRGBAr   rÓ   )r*   r  Ú_Úinput_file_extensionÚreaderr=   Ú_irù   r   rß   Úbase_mat_idÚcolor_indexÚmaterial_enabledÚbase_matÚbase_mat_colorrÓ   s                   r+   r\   zMesher.readï  sˆ  € ô ˜YÓ'ˆ	Ü"$§'¡'×"2Ñ"2°9Ó"=ÑˆÐØÐ'7Ñ7ÜÐ3Ð4HÐ3IÐJÓKÐKØ—‘×'Ñ'Ð(<¸Q¸RÐ(@ÓAˆØ×Ñ˜IÔ&Ü×/Ñ/°·
±
×0BÑ0BÓ0DÑEˆŒ	ð 48·:±:×3LÑ3LÓ3NˆÜ˜×+Ñ+Ó-Ö.ˆBØ×"Ñ"Ô$Ø�K‰K×Ñ˜}×AÑAÓCÕDð /ð ˆØ—K”KˆDØ—O‘O DÓ)ˆEØŸ,™,›.ˆEŒKð :>×9TÑ9TÓ9VÑ6ˆK˜Ð&6ÙØŸ:™:×>Ñ>¸{ÓK�Ø/7×/GÑ/GÈÓ/T�Ø#Ÿ|™|×<Ñ<Ø"ó �ô $ U˜m�”Ø�M‰M˜%Õ ð  ð ˆr-   c                 óà   — t        |«      }t        j                  j                  |«      \  }}|dvrt	        d|› �«      ‚| j
                  j                  |dd «      }|j                  |«       y)z¬write

        Args:
            file_name Union[Pathlike, str, bytes]: file path

        Raises:
            ValueError: Unknown file format - must be 3mf or stl
        r  r  rŽ   N)r   r]   r^   r   r!  r&   ÚQueryWriterÚWriteToFile)r*   r  r,  Úoutput_file_extensionÚwriters        r+   ÚwritezMesher.write  sp   € ô ˜YÓ'ˆ	Ü#%§7¡7×#3Ñ#3°IÓ#>Ñ ˆÐ Ø Ð(8Ñ8ÜÐ3Ð4IÐ3JÐKÓLÐLØ—‘×'Ñ'Ð(=¸a¸bÐ(AÓBˆØ×Ñ˜9Õ%r-   )CÚ__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚMCr   Ú	ModelUnitÚ
MicroMeterÚMMÚ
MilliMeterÚCMÚ
CentiMeterÚINÚInchÚFTÚFootÚMÚMeterr(   Úitemsr$  r   ÚOTHERr{   ÚOtherÚMODELÚModelÚSUPPORTÚSupportÚSOLIDSUPPORTÚSolidSupportrî   r|   r,   Úpropertyr0   rå   r°   r5   r9   r>   rØ   rE   ÚboolrQ   rc   Údictrs   rv   r„   Ústaticmethodr   Úfloatr­   rÖ   rÍ   Ú
MeshObjectrÞ   r   r   rû   r  r   Úbytesr\   r:  )Ú.0ÚkrÃ   s   000r+   r    r    w   sº  „ ñð 	�‰�×!Ñ!×,Ñ,Ø�‰�×!Ñ!×,Ñ,Ø�‰�×!Ñ!×,Ñ,Ø�‰�×!Ñ!×&Ñ&Ø�‰�×!Ñ!×&Ñ&Ø�‰�× Ñ ×&Ñ&ðÐð .B×-GÑ-GÔ-IÕJÑ-I¡T Q¨˜A˜q™DÐ-IÓJÐð 	�‰˜×)Ñ)×/Ñ/Ø�‰˜×)Ñ)×/Ñ/Ø×Ñ˜&×+Ñ+×3Ñ3Ø×Ñ˜v×0Ñ0×=Ñ=ð	Ðð 3I×2NÑ2NÔ2PÕ QÑ2P©$¨!¨Q  A¡Ð2PÓ QÐà$(§G¡Gñ 2˜Tó 2ð ð˜Dò ó ðð ð;  c¡ò ;ó ð;ð ð9˜t C™yò 9ó ð9ð ð%˜Cò %ó ð%ð
 ð* ò *ó ð*ð
OàðOð ðOð ð	Oð
 ðOð óOò:
ð "˜t D™zó "ð"¨sð "¸#ð "À$ó "ð T¨$¡Zó ð ð%,Øð%,à ð%,ð "ò%,ó ð%,ðN ð+-Ø  e¨U°EÐ&9Ñ :Ñ;ð+-à˜˜S™	‘?ò+-ó ð+-ðZ
 Eð 
°V×5FÑ5Fó 
ð $)Ø$'Ø&Ÿn™nØ"&Ø"&ñWSà�x ‘Ñ&ðWSð !ðWSð "ð	WSð
 ðWSð ˜4‘ZðWSð ˜4‘KóWSðr( 6×#4Ñ#4ð (¸ó (ðT)˜h¨™n¨uÑ4ð )¸¸e¹ó )ðV&˜x¨#™~°Ñ5ô &ùôa Kùô !Rs   ÃJ,ÆJ3r    )8r>  Úcopyrç   r·   r²   r]   rV   rê   r   r   Útypingr   ry   r   Úcollections.abcr   Ú
OCP.TopAbsÚTopAbsrœ   ÚOCP.BRepr   ÚOCP.BRepBuilderAPIr	   r
   r   r   ÚOCP.BRepGPropr   ÚOCP.BRepMeshr   ÚOCP.gpr   Ú	OCP.GPropr   r   Ú
OCP.TopExpr   Ú
OCP.TopLocr   Ú
OCP.TopoDSr   Úlib3mfr   Úbuild123d.build_enumsr   r   Úbuild123d.geometryr   r   Úbuild123d.topologyr   r   r   r   r   r    © r-   r+   Ú<module>rq     sq   ðñOóf Û Û Û 	Û 
Û ß !Ý Ý å $å Ý ÷ó õ $Ý 1Ý Ý "Ý 'Ý &Ý &Ý &Ý ç 0ß /ß FÕ F÷q&ò q&r-   