
    l0j                     z   d Z ddlZddlmZmZ ddlmZmZm	Z	m
Z
mZ 	 ddlmZmZ n2# e$ r*Z ej        e          Z ej        e          ZY dZ[ndZ[ww xY w	 dde
d	e	e         d
efdZ	 dde
d	e	e         d
efdZ	 dde
d	e	e         d
efdZ	 dde
ded
efdZdedee
ef         fdZeeej        j        dZdS )z]
boolean.py
-------------

Do boolean operations on meshes using either Blender or Manifold.
    N   )
exceptions
interfaces)CallableNDArrayOptionalSequenceUnion)ManifoldMeshTmeshesenginecheck_volumec                     |r(t          d | D                       st          d          t          |         | fddi|S )a/  
    Compute the boolean difference between a mesh an n other meshes.

    Parameters
    ----------
    meshes : sequence of trimesh.Trimesh
      Meshes to be processed.
    engine
      Which backend to use, i.e. 'blender' or 'manifold'
    check_volume
      Raise an error if not all meshes are watertight
      positive volumes. Advanced users may want to ignore
      this check as it is expensive.
    kwargs
      Passed through to the `engine`.

    Returns
    ----------
    difference
      A `Trimesh` that contains `meshes[0] - meshes[1:]`
    c              3   $   K   | ]}|j         V  d S N	is_volume.0ms     R/home/wildlama/miniconda3/envs/lam/lib/python3.11/site-packages/trimesh/boolean.py	<genexpr>zdifference.<locals>.<genexpr>,   $      <<<<<<<<    Not all meshes are volumes!	operation
differenceall
ValueError_enginesr   r   r   kwargss       r   r   r      sY    0  8C<<V<<<<< 86777FFEElEfEEEr   c                     |r(t          d | D                       st          d          t          |         | fddi|S )a-  
    Compute the boolean union between a mesh an n other meshes.

    Parameters
    ----------
    meshes : list of trimesh.Trimesh
      Meshes to be processed
    engine : str
      Which backend to use, i.e. 'blender' or 'manifold'
    check_volume
      Raise an error if not all meshes are watertight
      positive volumes. Advanced users may want to ignore
      this check as it is expensive.
    kwargs
      Passed through to the `engine`.

    Returns
    ----------
    union
      A `Trimesh` that contains the union of all passed meshes.
    c              3   $   K   | ]}|j         V  d S r   r   r   s     r   r   zunion.<locals>.<genexpr>J   r   r   r   r   unionr   r#   s       r   r'   r'   2   sY    0  8C<<V<<<<< 86777FF@@g@@@@r   c                     |r(t          d | D                       st          d          t          |         | fddi|S )a5  
    Compute the boolean intersection between a mesh and other meshes.

    Parameters
    ----------
    meshes : list of trimesh.Trimesh
      Meshes to be processed
    engine : str
      Which backend to use, i.e. 'blender' or 'manifold'
    check_volume
      Raise an error if not all meshes are watertight
      positive volumes. Advanced users may want to ignore
      this check as it is expensive.
    kwargs
      Passed through to the `engine`.

    Returns
    ----------
    intersection
      A `Trimesh` that contains the intersection geometry.
    c              3   $   K   | ]}|j         V  d S r   r   r   s     r   r   zintersection.<locals>.<genexpr>h   r   r   r   r   intersectionr   r#   s       r   r*   r*   P   sY    0  8C<<V<<<<< 86777FFGGnGGGGr   r   c                    |r(t          d | D                       st          d          d | D             }|dk    r4t          |           dk    rt          d          |d         |d         z
  }nC|d	k    rt          d
 |          }n+|dk    rt          d |          }nt          d| d          ddlm} |                                } ||j        |j                  S )a  
    Run an operation on a set of meshes using the Manifold engine.

    Parameters
    ----------
    meshes : list of trimesh.Trimesh
      Meshes to be processed
    operation
      Which boolean operation to do.
    check_volume
      Raise an error if not all meshes are watertight
      positive volumes. Advanced users may want to ignore
      this check as it is expensive.
    kwargs
      Passed through to the `engine`.
    c              3   $   K   | ]}|j         V  d S r   r   r   s     r   r   z#boolean_manifold.<locals>.<genexpr>   r   r   r   c                     g | ]g}t          t          t          j        |j        t          j                   t          j        |j        t          j                                       hS ))dtype)vert_properties	tri_verts)mesh)r   r   nparrayverticesfloat32facesuint32)r   r1   s     r   
<listcomp>z$boolean_manifold.<locals>.<listcomp>   sw         	 "bj I I I(4:RY???  	
 	
 	
  r   r      z(Difference only defined over two meshes.r   r   r'   c                     | |z   S r    abs     r   <lambda>z"boolean_manifold.<locals>.<lambda>   
    a!e r   r*   c                     | |z  S r   r;   r<   s     r   r?   z"boolean_manifold.<locals>.<lambda>   r@   r   zInvalid boolean operation: '')Trimesh)r4   r6   )	r    r!   lenreduce_cascade rC   to_meshr/   r0   )r   r   r   r$   	manifoldsresult_manifoldrC   result_meshs           r   boolean_manifoldrK   m   s4   ,  8C<<V<<<<< 86777    I L  v;;!GHHH#A,15	g		(););YGG	n	$	$(););YGGD	DDDEEE !))++K7K7{?TUUUUr   itemsc           
         t          |          dk    rdS t          |          dk    r|d         S t          |          dk    r | |d         |d                   S t          t          dt          j        t          |                    z                       D ]}g }t          j        t          |          dz            dz  D ]0}|                     | ||         ||dz                                 1t          |          dz  r|                    |d                    |}t          |          dk    sJ |d         S )af  
    Call an operation function in a cascaded pairwise way against a
    flat list of items.

    This should produce the same result as `functools.reduce`
    if `operation` is commutable like addition or multiplication.
    This may be faster for an `operation` that runs with a speed
    proportional to its largest input, which mesh booleans appear to.

    The union of a large number of small meshes appears to be
    "much faster" using this method.

    This only differs from `functools.reduce` for commutative `operation`
    in that it returns `None` on empty inputs rather than `functools.reduce`
    which raises a `TypeError`.

    For example on `a b c d e f g` this function would run and return:
        a b
        c d
        e f
        ab cd
        ef g
        abcd efg
     -> abcdefg

    Where `functools.reduce` would run and return:
        a b
        ab c
        abc d
        abcd e
        abcde f
        abcdef g
     -> abcdefg

    Parameters
    ----------
    operation
      The function to call on pairs of items.
    items
      The flat list of items to apply operation against.
    r   Nr   r9   )rD   rangeintr2   log2arangeappend)r   rL   _resultsis        r   rE   rE      s:   T 5zzQt	UqQx	Uqyq58,,,3q273u::...//00  3u::?++a/ 	> 	>ANN99U1XuQU|<<====u::> 	&NN59%%% w<<11:r   )Nmanifoldblender)NT)T)__doc__numpyr2   rF   r   r   typedr   r   r   r	   r
   
manifold3dr   r   BaseExceptionEExceptionWrapperstrboolr   r'   r*   rK   rE   rX   booleanr"   r;   r   r   <module>rc      s.        $ $ $ $ $ $ $ $ ? ? ? ? ? ? ? ? ? ? ? ? ? ?.))))))))) . . .&:&q))D*z*1--HHHHHH. JNF FF&smFBFF F F F> JNA AA&smABFA A A A> JNH HH&smHBFH H H H@ 5V 5V5V5V 5V 5V 5V 5Vp@h @uXw5F/G @ @ @ @J  !) s   ' A AA