
    j,                       d Z ddlZddlZddlmZmZmZ ddlmZ ddl	Z
ddlmZmZmZmZmZ ddlmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZmZmZmZm Z  ddlm!Z!m"Z" ddl#m$Z$ ddddZ%dddddddZ&e&jO                         D  ci c]  \  } }|dd |  c}} Z(ddddddddZ)d g d!ddd"iZ*dZ+dZ,dZ-d#Z. e
j^                  d      Z0d$e0jb                  _2         e
jf                  d      Z4 e
jf                  d      Z5 e
jf                  d      Z6	 	 	 	 	 	 	 dQd%Z7	 	 	 	 	 	 dRd&Z8	 	 	 	 	 dSd'ee    d(ee   d)e9d*e9d+e9f
d,Z:	 	 	 	 dTd'e d(ee   d)e9d*e9d+e9f
d-Z;d.e<d(ed/e=fd0Z>d1 Z?d2ed3ed4e@d5efd6ZAd7 ZB	 	 	 	 	 	 dRd8ZC	 dUd9ee9   d:e9d;e@d<e9d=e9f
d>ZDd? ZEd@ ZFdVdAZGdB ZHdC ZIdWdDZJdWdEZK	 	 	 dXdFedGee=   dHed(ee   d)e9d*e9d+e9fdIZLdJ ZMdK ZNdL ZOdM ZPdN ZQdO ZRe;e:dPZSyc c}} w )Yz
gltf/__init__.py
------------

Provides GLTF 2.0 exports of trimesh.Trimesh objects
as GL_TRIANGLES, and trimesh.Path2D/Path3D as GL_LINES
    N)OrderedDictdefaultdictdeque)deepcopy   )	rendering	resourcestransformationsutilvisual)	hash_fast)logtol)ResolverLikeZipResolver)Camera)DictListNDArrayOptionalStream)triangle_strips_to_facesunique_name   )handle_extensionsiglTFiJSONBIN )gltfjsonbinz<i1z<u1z<i2z<u2<u4z<f4)i     i  i            )r$   r$   )r   r   r%   r%   )SCALARVEC2VEC3VEC4MAT2MAT3MAT4pbrMetallicRoughness)r   r   r   r   )baseColorFactormetallicFactorroughnessFactor   Fc                    t        j                  | d      st        | d      r| j                         } t	        | ||||      \  }}	| ||       i }
d}|rvt        |	      }dj                  |	j                               }|r3|j                  t        j                  |      j                               }nd}||
|<   |t        |      dg}ndgt        |	      z  }dgt        |	      z  }t        |	j                               D ]h  \  }}|d	t        |      d
||<   |r3|j                  t        j                  |      j                               }nd| d}||
|<   |t        |      d||<   j t        |      d	kD  r
||d<   ||d<   t        j                  |d      j                  d      |
d<   t         j"                  rt%        |       |
S )aM  
    Export a scene object as a GLTF directory.

    This puts each mesh into a separate file (i.e. a `buffer`)
    as opposed to one larger file.

    Parameters
    -----------
    scene : trimesh.Scene
      Scene to be exported
    include_normals : None or bool
      Include vertex normals
    merge_buffers : bool
      Merge buffers into one blob.
    unitize_normals
      GLTF requires unit normals, however sometimes people
      want to include non-unit normals for shading reasons.
    resolver : trimesh.resolvers.Resolver
      If passed will use to write each file.
    tree_postprocesser : None or callable
      Run this on the header tree before exiting.
    embed_buffers : bool
      Embed the buffer into JSON file as a base64 string in the URI
    extension_webp : bool
      Export textures as webP (using glTF's EXT_texture_webp extension).
    extension_draco : bool
      Compress mesh data using Draco (KHR_draco_mesh_compression).
      Requires the `dracox` package to be installed.

    Returns
    ----------
    export : dict
      Format: {file name : file data}
    Scenescene)r5   unitize_normalsinclude_normalsextension_webpextension_dracoNz'data:application/octet-stream;base64,{}    zgltf_buffer.bin)uri
byteLengthr   buffer
byteOffsetr<   gltf_buffer_z.binbuffersbufferViews,:
separatorsutf-8
model.gltf)r   is_instance_namedhasattrr5   _create_gltf_structure_build_viewsjoinvaluesformatbase64	b64encodedecodelen	enumeratejsonifyencoder   strictvalidate)r5   r7   merge_buffersr6   tree_postprocessorembed_buffersr8   r9   treebuffer_itemsfilesbase64_buffer_formatviewsbuffer_databuffer_namerA   iitems                     K/DATA/.local/lib/python3.12/site-packages/trimesh/exchange/gltf/__init__.pyexport_gltfrg   F   s   Z !!%1geW6M 0''%'D, %4  ED\*hh|2245.55  -446K ,K!,E+&c+6FGH &3|,,\** !4!4!67GAt"#1CINE!H299&:J:J4:P:W:W:YZ ,QCt4%)k"!,CIFGAJ 8 7|a!Y#],,t
CJJ7SE,
zzLr:   c           
         t        j                  | d      st        | d      r| j                         } t	        | |||||      \  }}t        |      }	dj                  |j                               }
t        |
      dkD  rdt        |
      ig|d<   |	|d<   | ||       t        j                  |d	
      }|dt        |      dz   dz  z
  dz  z  }|j                  d      }t        |      dz  dk(  sJ t        t        j                  t        d   dt        |      t        |
      z   dz   t        |      t        d   gd      j                               }t        t        j                  t        |
      dgd      j                               }dj                  ||||
g      }t         j"                  rt%        |       |S )a  
    Export a scene as a binary GLTF (GLB) file.

    Parameters
    ------------
    scene: trimesh.Scene
      Input geometry
    extras : JSON serializable
      Will be stored in the extras field.
    include_normals : bool
      Include vertex normals in output file?
    tree_postprocessor : func
      Custom function to (in-place) post-process the tree
      before exporting.
    extension_webp : bool
      Export textures as webP using EXT_texture_webp extension.
    extension_draco : bool
      Compress mesh data using Draco (KHR_draco_mesh_compression).
      Requires the `dracox` package to be installed.

    Returns
    ----------
    exported : bytes
      Exported result in GLB 2.0
    r4   r5   )r5   r6   r7   buffer_postprocessorr8   r9   r:   r   r<   rA   rB   rC   rF   r%       rH   r   r$      r   r    dtyper   )r   rJ   rK   r5   rL   rM   rN   rO   rT   rV   rW   	_byte_padnparray_magictobytesr   rX   rY   )r5   r7   r6   r[   ri   r8   r9   r]   r^   ra   rb   contentheader
bin_headerexporteds                  rf   
export_glbrx      s   F !!%1geW6M/''1%'D, &E ((<..01K ;!(#k*:;<Y#] %4  ll4J7G c'lR'1,-44GnnW%GL1""" 
v Gs;//"4 Gv 	
 ')F& 
#k"J/u=EEGJ xx*kBCH
zzOr:   file_objresolverignore_brokenmerge_primitivesskip_materialsc           	      f   	 t        j                  t        j                  | j	                                     }|j                  di       j                  dd      }t        |t              rt        |j                  dd      d         }	nt        t        |            }	|	dk  rt        d	| d
      |j                  dg       D 
cg c]  }
t        |
d   |       }}
t        |||||||      }|S # t
        $ r0 |d   }t        j                  t        j                  |            }Y w xY wc c}
w )a  
    Load a GLTF file, which consists of a directory structure
    with multiple files.

    Parameters
    -------------
    file_obj : None or file-like
      Object containing header JSON, or None
    resolver : trimesh.visual.Resolver
      Object which can be used to load other files by name
    ignore_broken : bool
      If there is a mesh we can't load and this
      is True don't raise an exception but return
      a partial result
    merge_primitives : bool
      If True, each GLTF 'mesh' will correspond
      to a single Trimesh object
    skip_materials : bool
      If true, will not load materials (if present).
    **mesh_kwargs : dict
      Passed to mesh constructor

    Returns
    --------------
    kwargs : dict
      Arguments to create scene
    rI   assetversion2.0.r   r   r$   only GLTF 2 is supported not ``rA   r;   r;   rz   )ru   rA   r{   r|   mesh_kwargsr}   rz   )r   loadsr   decode_textreadBaseExceptionget
isinstancestrintsplitfloatNotImplementedError_uri_to_bytes_read_buffers)ry   rz   r{   r|   r}   r   r]   datar   majorbrA   kwargss                rf   	load_gltfr     s-   F2zz$**8==?;< hhw#''	59G'3GMM#q)!,-E'N#qy!$B7)1"MNN AETV@W@W1!E(X6@W   #)%F ME  2%zz$**401	2&s   6C2 D.26D+*D+c           	      <   | j                  d      }t        j                  |d      }|d   t        d   k7  rt	        d      |d   dk7  rt        d	|d    d
      |dd \  }}	}
|
t        d   k7  rt	        d      | j                  t        |	            }t        |d      rt        j                  |      }t        j                  |      }g }| j                         }|j                  dg       j                         }| j                         |z
  |k  r2	 |j                  d      d   }|j!                  t#        ||             Ht+        |||||||      }|S # t$        t&        f$ r Y nw xY w| j                  d      }t)        |      dk7  rIt        j                  |d      \  }	}
|
t        d   k7  rt	        d      | j                  t        |	            }t)        |      |	k7  rt	        d      |j!                  |       | j                         |z
  |k  r)a  
    Load a GLTF file in the binary GLB format into a trimesh.Scene.

    Implemented from specification:
    https://github.com/KhronosGroup/glTF/tree/master/specification/2.0

    Parameters
    ------------
    file_obj : file- like object
      Containing GLB data
    resolver : trimesh.visual.Resolver
      Object which can be used to load other files by name
    ignore_broken : bool
      If there is a mesh we can't load and this
      is True don't raise an exception but return
      a partial result
    merge_primitives : bool
      If True, each GLTF 'mesh' will correspond to a
      single Trimesh object.
    skip_materials : bool
      If true, will not load materials (if present).

    Returns
    ------------
    kwargs : dict
      Kwargs to instantiate a trimesh.Scene
    rj   r    rm   r   r   zincorrect header on GLB filer   r$   r   r   Nr   zno initial JSON header!rS   rA   r;   r      r   znot binary GLTF!zchunk was not expected length!)ru   rA   r{   r|   r}   r   rz   )r   rp   
frombufferrr   
ValueErrorr   r   rK   r   r   r   r   tellr   copypopappendr   
IndexErrorKeyErrorrT   r   )ry   rz   r{   r|   r}   r   	head_dataheadlengthchunk_length
chunk_type	json_dataru   rA   startinfor;   
chunk_head
chunk_datar   s                       rf   load_glbr   `  s   H b!I==%0D Aw&. 788 Aw!|!$B47)1"MNN
 (,ABx$FL* VF^#233 c,/0Iy(#$$Y/	ZZ	"F GMMOE ::i$))+D==?U"f
,	((1+e$CNN=S8DE0 #)%F MC H% 		 ]]1%
z?a #%==5#I j&/00]]3|#45
z?l*=>>z"5 ==?U"f
,s   0E E-,E-r;   returnc                 n    | j                  d      }|dk  r||    S t        j                  | |dz   d       S )aJ  
    Take a URI string and load it as a
    a filename or as base64.

    Parameters
    --------------
    uri
      Usually a filename or something like:
      "data:object/stuff,base64,AABA112A..."
    resolver
      A resolver to load referenced assets

    Returns
    ---------------
    data
      Loaded data from URI
    zbase64,r      N)findrQ   	b64decode)r;   rz   indexs      rf   r   r     sC    & HHYEqy } C	,--r:   c                     t        |      }|| v r(t        | j                               j                  |      S t	        |      | |<   t        |       dz
  S )a   
    Append data to an existing OrderedDict and
    pad it to a 4-byte boundary.

    Parameters
    ----------
    od : OrderedDict
      Keyed like { hash : data }
    data : bytes
      To be stored

    Returns
    ----------
    index : int
      Index of buffer_items stored in
    r   )r   listkeysr   ro   rT   )orderedr   hasheds      rf   _buffer_appendr     sM    $ t_FGLLN#))&11oGFOw<!r:   accbuffblobr   c                    |j                         }t        |d      r|j                         }nt        |      }||v r,t        |j	                               j                  |      |d<   nt        |      ||<   t        |      dz
  |d<   	 t        t        |j                                     }||z  }|| v r(t        | j	                               j                  |      S t        j                  t         |d            }|d   }t"        j$                  r%t        j&                  |      j)                         sJ |dk(  rt+        t        j,                  |j.                              |d	<   t        j0                  |j3                         g|
      j5                         |d<   t        j0                  |j7                         g|
      j5                         |d<   n|j9                  d      rt        |      |d	<   n|j;                  dt<        |   f      }	t        |	      |d	<   |	j3                  d      j?                  |      j5                         |d<   |	j7                  d      j?                  |      j5                         |d<   || |<   t        |       dz
  S # t        $ r$ t        t        j                  |d            }Y w xY w)a  
    Append a new accessor to an OrderedDict.

    Parameters
    ------------
    acc
      Collection of accessors, will be mutated in-place
    buff
      Collection of buffer bytes, will be mutated in-place
    blob
      Candidate accessor
    data
      Data to fill in details to blob

    Returns
    ----------
    index : int
      Index of accessor that was added or reused.
    r   
bufferViewr   T)	sort_keyscomponentTypetyper'   countrm   maxminMATr   axis) rs   rK   r   r   r   r   ro   rT   hashtupleitemsr   r   dumpsrp   rn   _dtypesr   rX   isfiniteallr   prodshaperq   r   tolistr   
startswithreshape_shapesastype)
r   r   r   r   as_bytesr   keyrn   kindreshs
             rf   _data_appendr     sG   * ||~Ht[!! 8$~!$))+.44V<\ !*V Y]\55&' 6MC czCHHJ%%c** HHWT/234E<D
zz {{4 $$&&&xBGGDJJ/0Whh
|59@@BUhh
|59@@BU		D	W ||R/0D	WhhAh&--e4;;=UhhAh&--e4;;=U CHs8a<M  54::dd345s   	"J )K ?K c                     t        j                  t        j                  | j	                         D ci c]  \  }}|j                  d      r|| c}}            S c c}}w )z[
    Roundtrip a blob through json export-import cycle
    skipping any internal keys.
    _)r   r   r   rV   r   r   )r   kvs      rf   _jsonifyr   ^  sL    
 ::tzz|M|tq!1<<;Lad|MN Ms   AAc                 L   dddgigdddt               g g g g d}| j                  rt        | j                        g|d<   |rgt	        | j
                        dkD  rO	 t        | j
                        |d   d   d	<   |d   d   d	   j                  d
d      }t        |t              r||d<   i }	t               }
i }t	        |d         }| j                  j                         D ]  \  }}t        j                   |d      rt#        ||||
|||	||	       nKt        j                   |d      rt%        ||||
       n%t        j                   |d      rt'        ||||
       t	        |d         |k7  st	        |d         }|dz
  ||<    | j(                  j+                  | |      }|j-                  |       t/               }t/               }d|v r+|j1                  t/        |d   j3                                     }|d   D ]x  }d|v r+|j1                  t/        |d   j3                                     }|j5                  dg       D ]2  }d|v s|j1                  t/        |d   j3                                     }4 z d|v r|j1                  t/        |d               }|r"|j7                  d       |j7                  d       |r"|j7                  d       |j7                  d       t	        |      dkD  rt9        |      |d<   t	        |      dkD  rt9        |      |d<   |	 ||
|       t9        |d   j;                               |d<   g d}|D cg c]%  }t	        ||         dk(  s|j                  |      ' c} ||
fS # t        $ r t        j                  dd       Y w xY wc c}w ) a  
    Generate a GLTF header.

    Parameters
    -------------
    scene : trimesh.Scene
      Input scene data
    include_metadata : bool
      Include `scene.metadata` as `scenes/{idx}/extras/metadata`
    include_normals : bool
      Include vertex normals in output file?
    unitize_normals : bool
      Unitize all exported normals so as to pass GLTF validation
    extension_webp : bool
      Export textures as webP using EXT_texture_webp extension.
    extension_draco : bool
      Compress mesh data using Draco (KHR_draco_mesh_compression).

    Returns
    ---------------
    tree : dict
      Contains required keys for a GLTF scene
    buffer_items : list
      Contains bytes of data
    r   nodesr   z!https://github.com/mikedh/trimesh)r   	generator)r5   scenesr   	accessorsmeshesimagestextures	materialscamerasr   extrasgltf_extensionsN
extensionsz failed to export scene metadata!Texc_infor   Trimesh)	meshnamer]   r^   r7   r6   
mat_hashesr8   r9   Path)pathr   r]   r^   
PointCloud)pointsr   r]   r^   r   )r5   
mesh_index
primitivesextensionsUsedEXT_texture_webpKHR_draco_mesh_compressionextensionsRequiredr   )r   r   r   r   r   )r   
has_camera_convert_cameracamerarT   metadatar   r   r   dictr   r   debuggeometryr   r   rJ   _append_mesh_append_path_append_pointgraphto_gltfupdatesetunionr   r   addr   rO   )r5   r7   include_metadatar6   ri   r8   r9   r]   r   r   r^   r   previousr   r  r   extensions_usedextensions_requiredr   primcheckr   s                         rf   rL   rL   h  s   J aS>""1TU ]	D *5<<89YC/!3	I +35>>*BDN1h'h*84889JDQJ*d+%/\"
 J=L J4>"H  ....0h!!(I6) / /%- /
 ##Hf5hT<X##Hl;dL
 tH~(*4>*H'!|Jt5 1: KKe
CEKKeO%t)//D4F4K4K4M0NOX4-33C\8J8O8O8Q4RSOHH\2.Dt#"1"7"7D<N<S<S<U8V"W /	  4)//D9I4J0KL./ 2389 <=
?a!%o!6
!#%)*=%>!"'\40 T+.5578D GE#;ess49~':TXXc]e;m  	III84HH	Ih <s   AM: 	N! N!: NNr7   r6   r   r8   r9   c	           
         t        | j                        dk(  st        | j                        dk(  rt        j                  d       yt        |d   |ddd| j                  j                  t                    }	t        |d   |d	d
dd| j                  j                  t                    }
|i d|
i|	t        dgd}	 t        | j                        |d<   |d   j                  dd      }t        |t              r||d<   | j                  dvrt!        | j                        |d   d<   | j$                  j&                  dv r| j$                  j(                  }nJt+        | j$                  d      r2d| j$                  j,                  v r| j$                  j,                  d   }nd}|ot        |      t        | j                        k(  r9t        |d   |ddddd|j                  t.                    }||d   d   d   d<   nt        j0                  d        t+        | j$                  d!      rt3        | j$                  j4                  ||||"      }t+        | j$                  d#      xrO | j$                  j6                  duxr5 t        | j$                  j6                        t        | j                        k(  }|rw| j$                  j6                  j9                         dddd$f   }d%|ddd&f   z
  |ddd&f<   t        |d   |d	d'dd|j                  t                    }||d   d   d   d(<   ||d   d   d!<   |s|d)| j:                  j<                  v ry|r t?        j@                  | jB                        }n| jB                  }t        |d   |d	t        | j                        d
dd*|j                  t                    }||d   d   d   d+<   | j,                  jE                         D ]  \  }}t        |      t        | j                        k7  rt        j0                  d,| d-       B|jG                  d.      sd.|z   }|jH                  j&                  d/k(  r/|jH                  jJ                  d0kD  r|j                  t              }n,|j                  |jH                  jM                  d1      d23      }t        |jN                        d&k(  r|ddtP        jR                  f   }|jN                  d&   |jH                  jJ                  z  d0z  }|dk7  r8d0|z
  |jH                  jJ                  z  }tQ        jT                  |d4d|ffd56      }t        |d   |tW        |      |      |d   d   d   |<    |r=|xs |du xr d)| j:                  j<                  v }tY        d7i id8| ||||d   d   |9       |d:   j[                  |       y# t"        $ r t        j                  dd       Y w xY w);a  
    Append a mesh to the scene structure and put the
    data into buffer_items.

    Parameters
    -------------
    mesh : trimesh.Trimesh
      Source geometry
    name : str
      Name of geometry
    tree : dict
      Will be updated with data from mesh
    buffer_items
      Will have buffer appended with mesh data
    include_normals : bool
      Include vertex normals in export or not
    unitize_normals : bool
      Transform normals into unit vectors.
      May be undesirable but will fail validators without this.

    mat_hashes : dict
      Which materials have already been added
    extension_webp : bool
      Export textures as webP (using glTF's EXT_texture_webp extension).
    extension_draco : bool
      Compress mesh data using Draco (KHR_draco_mesh_compression).
    r   zskipping empty mesh!Nr   r"   r'   )r   r   r   r   r   r   r#   r)   r   r   r?   POSITION)
attributesindicesmode)r   r   r   r   r   r   )Nmmetersmeterunitsz$metadata not serializable, dropping!Tr   )vertexfacevertex_attributescolorr!   r*   r   
normalizedr   r?   r   r  COLOR_0zAVertex colors have different length than mesh vertices, dropping!material)matr]   r^   r   r8   uvr$         ?r   r(   
TEXCOORD_0vertex_normals)r   r   r   r?   NORMALzVertex attribute `z3` has different length than mesh vertices skipping!r   fr%   <Fr   )r   r   constant)r  r   primitive_export)r   scoper   r   r]   r^   	primitiver7   r   ).rT   facesverticesr   r  r   r   uint32float32_GL_TRIANGLESr   r  r   r   r  r  r   r   r   r   vertex_colorsrK   r!  uint8warning_append_materialr&  r(  r   _cachecacher   unitizer+  r   r   rn   itemsizenewbyteorderr   rp   newaxispad_build_accessorr   r   )r   r   r]   r^   r7   r6   r   r8   r9   acc_face
acc_vertexcurrentr   r9  	acc_colorcurrent_materialhas_uvr(  acc_uvnormalsacc_normr   attribr   row_modpad_columnsshould_include_normalss                              rf   r  r    s   N 4::!s4==1Q6		()
 #X6ZZv&	H #V1E]]!!'*	J   *:6#%

G I$T]]3 X&**+<dC
j$'$.GL!::;;),TZZGHg& {{--1101t{{44455g> }T]]!33$%!%)"&""#	 #))%0
I AJGL!!$\29=KKS t{{J'+$$%!)
 DKK& :d*:DKKNN#s4=='99 	
 $$&q"1"u-BR1X~Bq!tH!%!'+V1MYYw'	F DJGL!!$\2<@ 0@a ,$48I8I$I ll4#6#67G ))G[!!%T]]+	 (

 <Da .x8 --335Vv;#dmm,,KK$SE)\]  ~~c")C <<#(=(=(A==)D ==!:!:3!?e=LDtzz?a2::&D ::a=4::#6#66!;a<w;4::+>+>>K66$![)9 :LD 7C[! &	7
a .s3C 6R !0 "
t#M(8DKK<M<M(M 	 	4b9$%l+A.2		
 	N'"y  I		84HHIs   >A+W  W+*W+c                     g }d}| j                         D ]K  }|j                  d|t        |      d       |dz  dk(  sJ t        |      dz  dk(  sJ |t        |      z  }M |S )a  
    Create views for buffers that are simply
    based on how many bytes they are long.

    Parameters
    --------------
    buffer_items : OrderedDict
      Buffers to build views for

    Returns
    ----------
    views : (n,) list of dict
      GLTF views
    r   r=   r%   )rO   r   rT   )r^   ra   current_poscurrent_items       rf   rM   rM     s~     EK$++-3|CTU	
 aA%%%L!A%!+++s<(( . Lr:   c                 :   | j                   }d}t        |      dk(  r+|d   }|dkD  rt        d      |dkD  rdt        |       }nd}t        |      dk(  r#|d   dvrt        d	      d
t        |d          }| j                  j
                  j                  d      }|dk(  rt        j                  d       t        |   }||dd}t        |      dk  rF| j                  d      j                         |d<   | j                  d      j                         |d<   |S )z
    Build an accessor for an arbitrary array.

    Parameters
    -----------
    array : numpy array
      The array to build an accessor for

    Returns
    ----------
    accessor : dict
      The accessor for array.
    r'   r$   r   r%   z4The GLTF spec does not support vectors larger than 4VECr   )r$   r   r%   z,Matrix types must have 4, 9 or 16 componentsr   z<>|u4z+custom uint32 may cause validation failuresr   r  r   r   r   )r   rT   r   r   rn   r   lstripr   r  _dtypes_lookupr   r   r   )rq   r   	data_type
vec_lengthlookupr   accessors          rf   rD  rD    s     KKEI
5zQ1X
>STT>c*o./I I
5zQ89$KLL#eAh-)	 [[__##E*F~ 			?@ #6*M!.	QRSH
5zA~)))+224)))+224Or:   c                    t        | t              sJ t        |       |z  dk7  rf|t        |       |z  z
  }d|z  j                  d      }dj	                  | |g      }t
        j                  rt        |      |z  dk7  rt        d      |S | S )a  
    GLTF wants chunks aligned with 4 byte boundaries.
    This function will add padding to the end of a
    chunk of bytes so that it aligns with the passed
    boundary size.

    Parameters
    --------------
    data : bytes
      Data to be padded
    bound : int
      Length of desired boundary

    Returns
    --------------
    padded : bytes
      Result where: (len(padded) % bound) == 0
    r   rk   rH   r:   zbyte_pad failed!)r   bytesrT   rW   rN   r   rX   r   )r   boundr   rC  results        rf   ro   ro   B  s    & dE"""
4y5ATU*+U{""7+4+&::3v;.14/00Kr:   c                    t        j                  |       }|d   dk(  ry	 |d   j                  t              }t        |d   |dddd|d   d	   j                  t              
      }|d|it        |dgd}	 t        | j                        |d<   | j                   Qt        |d   |dddddt#        j$                  |d   d	         j                  t&              
      }||d   d   d   d<   | j(                  j+                         D ]M  \  }	}
|	j-                  d      sd|	z   }	|
j.                  j0                  dk(  r/|
j.                  j2                  dkD  r|
j                  t              }n,|
j                  |
j.                  j5                  d      d      }t7        d | j8                  D              st        j:                  d|	 d        t#        j$                  | j8                  D cg c]&  }t=        j>                  |jA                  |            ( c}      }|jC                  d!      }t        |d   |tE        |      |
      |d   d   d   |	<   P |d"   j                  |       y# t        $ r* t        |d         }|d   j                  t               Y gw xY w# t        $ r t        j                  dd       Y 6w xY wc c}w )#ac  
    Append a 2D or 3D path to the scene structure and put the
    data into buffer_items.

    Parameters
    -------------
    path : trimesh.Path2D or trimesh.Path3D
      Source geometry
    name : str
      Name of geometry
    tree : dict
      Will be updated with data from path
    buffer_items
      Will have buffer appended with path data
    r   Nr   r   r#   r)   r  r%   r   r  r  r  r  r&  r   r   r   z'failed to serialize metadata, dropping!Tr   r!   r*   r#  r2   r   r  r%  r   r-  r.  Fr/  c              3   H   K   | ]  }t        j                  |d         yw)LineN)r   rJ   ).0es     rf   	<genexpr>z_append_path.<locals>.<genexpr>  s     Lm4))!V4ms    "zBVertex attributes are only supported for Line entities, skipping `r   )r   r   )#r   path_to_vertexlistr   _default_materialr   rT   r   r   r   r7  	_GL_LINESr   r  r   r   r  colorsrp   rq   r:  r!  r   r   rn   r   r@  rA  r   entitiesr;  r   stack_linesdiscreter   rD  )r   r   r]   r^   vxlistmaterial_idxrF  rG  rH  r   rN  r   rh  data_discretizedstacked_datas                  rf   r  r  d  s   & ))$/F ayA~4K(../@A #V1EAYq\  )	J   *:6!(
	GL$T]]3 {{ [!!%"	 &)A,'..u5

	 =Fa .y9 --335V ~~c")C <<#(=(=(A==)D ==!:!:3!?e=LDLdmmLLKKTUXTYYZ[ 889=GATajj./G
 (//6 7C[! .	7
a .s35 6B 	N'"c  44,-[  !2348  L		;dKKLR Hs)   I- 8J# ++K

-/J J # KKc           
         t        j                  | j                  | j                        }t	        |d   |dddd|d   d   j                  t              	      }|d
|it        t        |d         dgd}|d   j                  t               t        t        j                  | j                              dk(  rq|d   \  }}d|v rd}	nd|v rd}	nt        d|      t	        |d   |d|d   d|	ddt        j                  |      j                  t              	      }
|
|d   d   d   d<   |d   j                  |       y)aa  
    Append a 2D or 3D pointCloud to the scene structure and
    put the data into buffer_items.

    Parameters
    -------------
    points : trimesh.PointCloud
      Source geometry
    name : str
      Name of geometry
    tree : dict
      Will be updated with data from points
    buffer_items
      Will have buffer appended with points data
    )r   rm  r   r#   r)   r   r  r%   r   r  r  r   rc  rd  r$   r2   34r*   zunknown color: %sr!   T)r   r   r$  r   r?   r   r  r%  r   N)r   points_to_vertexlistr5  rm  r   r   r7  
_GL_POINTSrT   r   rk  rp   r   r   rq   r:  )r   r   r]   r^   rq  rF  rG  
color_type
color_datar   rH  s              rf   r  r    s_   & ++6??6==YF #V1EAYq\  )	J   *:6"[ 12
	G 	./
288FMM"#q(!'
J*DJD0*== [!!%" *%,,U3
	 =Fa .y9N'"r:   c                    	 dd l }d }d| v rd gt	        | d         z  }t        | d         D ]  \  }}|j                  dd      dk(  rt        j                  d       1d|v r	||d      }n=d	|v r	 t        |d	   |
      }n't        j                  d|j                                 {	 |j                  j                  t        j                  |            ||<    |S # t        $ r t        j                  d       Y y w xY w# t        $ r, t        j                  d|j                          d       Y 	w xY w# t        $ r t        j                  dd       Y 0w xY w)Nr   z'unable to load textures without pillow!r   mimeType z
image/ktx2z0`image/ktx2` textures are unsupported, skipping!r   r;   r   zunable to load image from: Tr   zfailed to load image!)	PIL.ImageImportErrorr   r  rT   rU   r   r   r   r   Imageopenr   wrap_as_stream)ru   ra   rz   PILr   rd   imgr   s           rf   _parse_texturesr    s`    F6#fX.//x 01FAswwz2&,6		LMs"S./#(SZ(KD
 		7
|DEBIINN4+>+>t+DEq	+ 20 ME  		;<* % II ;CHHJ<HSWX ! B		1DAABs5   C /D(1D9C>=C>1D65D69 EEc                      fd}t         ||      g }d v rΉ d   D ]  }|j                         }d|v r |j                  |j                  d             |j	                  d      x}rFt        |d|      }|j                         D ]$  }	t        |	t              s|j                  |	       &  ||      }
|j                  t        j                  j                  di |
        |S )	aK  
    Convert materials and images stored in a GLTF header
    and buffer views to PBRMaterial objects.

    Parameters
    ------------
    header : dict
      Contains layout of file
    views : (n,) bytes
      Raw data

    Returns
    ------------
    materials : list
      List of trimesh.visual.texture.Material objects
    c                    i }| j                         D ]  \  }}t        |t        t        f      r)t	        j
                  |t        j                        ||<   Et        |t              s|||<   [^d|v sc	 d }d   |d      }|j                  d      x}rt        |d      }||j                  d      }||   ||<    |S # t        $ r t        j                  dd	
       Y w xY w)Nrm   r   r   r   texture_source)r   r2  sourcezunable to store textureTr   )r   r   r   r   rp   rq   float64r  r   r   r   r   r  )	r   ra  r   r   r   texturetex_extru   r   s	          rf   parse_texturesz(_parse_materials.<locals>.parse_texturesU  s    JJLDAq!dE]+HHQbjj9q	4(q	#1H E$Z07<G")++l";;w; 1'.6F! } 'H 5($*5Mq	) !.  % HII7$GHs   8A
C C)(C)r   r.   r   r&  )r   r2  r  r   )r    )r  r   r
  r   r   r   rO   r   r  r   r   r&  PBRMaterial)ru   ra   rz   r  r   r'  loopablemat_extensionsext_results
ext_resultpbrr   s   `          @rf   _parse_materialsr  C  s    $6 VUH5F If+&CxxzH%1-C DE "%!66~6/-$#1!	 #."4"4"6J!*d3 
3 #7
 !h/CV__88?3?@1 '4 r:   ru   rA   r   c                    d| v rdgt        | d         z  }t        | d         D ]=  \  }}	d|	v r|	d   }
nd}
|
|	d   z   }||	d      |
| ||<   t        ||         |	d   k(  r=J  dgt        | d         z  }t        | d         D ]  \  }}|d   }t        j                  t        |d	            }t
        |d
      }t        j                  ||      }t        j                  t        j                  |            }d|v rC| d   |d      }||d      }|j                  dd      }
d|v r|d   }||j                  z  }|dz
  |z  |z   }|dkD  sJ d       d|
cxk  r|
|z   cxk  rt        |      k  sJ  J t        j                  t        j                  j                  j                  t        j                  |t        j                   |
|      ||g|dg      j#                  |      j%                  |            ||<   z|j                  |z  |z  }t        j                  ||
|
|z    |      j%                  |      ||<   t        j&                  ||z  |      j%                  |      ||<    |rg }nt)        | ||      }t+        t,              }t/               }i }t        | j                  dg             D ]  \  }}	 dt        |d         dkD  d}t1        |j                  d      t2              r|j5                  |d          d|v r|d   |d<   |d   D ]-  }|j                  d      x} rt7        | d|       t9        |      }!|!j                  dd      i |!d<   d|!vrd|!d<   |!d   j5                  |       |j                  dt:              }"|d   }#|j                  d d!      }$t=        |$||"      }$|"t>        k(  rd#d$l m!}% |#d%      |!d&<    |%t        jD                  t        |!d&               '      g|!d(<   |#jG                         D ci c]  }|jI                  d)      s|||#|       }&}t        |&      dkD  r|&|!d*<   n|"tJ        k(  rq|#d%      |!d&<   d}'d+|#v rV	 ||#d+      }(t        |(      t        |!d&         k(  r3|'|(jM                         |!d,<   n|(jM                         |'jN                  d-<   |'i|'|!d1<   nb|"t:        tV        fv r;|#d%      |!d&<   d2|v rK|"tV        k(  r'||d2      j%                  d3      })tY        |)g      |!d4<   n||d2      j%                  d5      |!d4<   n|"tV        k(  rBtY        t        j                  t        jD                  t        |!d&               g            |!d4<   nCt        jD                  t        |!d&         t        jZ                        j%                  d5      |!d4<   d6|#v r||#d6      |!d7<   d}'d8|v rp|sntS        jT                  d9       nVd}*d:|#v r)||#d:      jM                         }*d;|*dddf   z
  |*dddf<   t\        j^                  ja                  |*||d8      <      }'d+|#v rV	 ||#d+      }(t        |(      t        |!d&         k(  r3|'|(jM                         |!d,<   n|(jM                         |'jN                  d-<   |'|'|!d1<   |#jG                         D ci c]  }|jI                  d)      s|||#|       }&}t        |&      dkD  r|&|!d*<   |j                  d      x} r)t7        | d=||!|>       ntS        jT                  d?|"       |$|vsJ |!||$<   ||   j                  |$       0  |ri },tc               }-|je                         D ]L  \  }.}/t        |/      dk  r|/|,|.<   tg        |/      }$|-j5                  tc        |/      ji                  |$g             |/D 0cg c]  }0||0   	 }1}0|1D cg c]  }|d&   	 }2}|1D cg c]  }|d4   	 }3}tk        jl                  |2|3      \  }4}5|1D cg c]  }|d1   jn                   }}g }6t        |1      D ]  \  }}|6|gt        |d4         z  z  }6 t\        j^                  ja                  t\        jn                  jq                  |A      |6B      }'d||/d      v r||/d      d   }ni }|4|5|'|ddC||$<   |$g|,|.<   O |,}|-D cg c]  }|js                  |d       c} | j                  dDg       }7i }8i }t        |7      D ]/  \  }}0||8t=        |0j                  d tu        |            |8|"      <   1 |8je                         D 94ci c]  \  }9}4|4|9
 }/}9}4dE}:|:|8v rtS        jT                  dF       |:|/|:<   tw               };tw               }<d}=d}>dG| v r| dG   }?nd}?dE}:dH| v r0| dH   |?   j                  dDg       D ]  }@|<j                  |:|@f        tc               }At        |<      dkD  r|<js                         }B|BAv r$Ajy                  B       |B\  }}C|7|C   }DdI|Dv r$|<j{                  DdI   D cg c]  }C|f c}       |/|   |/C   dJ}!dKDv rEt        j                  DdK   t        j|                        j%                  dL      j~                  |!dK<   n	t        |!dK<   dMDv r2t        j                  |!dK   t        j                  DdM               |!dK<   dNDv rMt        j$                  DdN   dO      g dP   }Et        j                  |!dK   t        j                  |E            |!dK<   dQDv rHt        j                  |!dK   t        j                  t        j                  DdQ   d;gf                  |!dK<   dRDv r"|= DdR   }F	 t        | dS   F         }=|=r|!dK   }>t1        Dj                  d      t2              rDd   |!d<   dDv rd|!vri |!d<   Dd   |!d   d<   dUDv r|DdU      }Gt        |G      dkD  r|;j                  |!jM                                GD ]Z  }H|H|!dV<   t        |!dK<   |/C   |!dW<   |/|C    d)tk        j                  dXY       }I|I|!dZ<   |;j                  |!jM                                \ nSt        G      dk(  rEGd   |!dV<   d Dv r|/C   |!dZ<   |;j                  |!jM                                n|;j                  |!       t        |<      dkD  rd[||;|:|=|>i d\}J	 Jd   j5                  | dH   | dG      d          	 | d   Jd   d<   |JS c c}w # tP        $ r tS        jT                  d.d/0       Y uw xY w# tP        $ r tS        jT                  d.d/0       Y w xY wc c}w # tP        $ r'}+|rtS        jT                  d@d/0       n|+Y d}+~+
d}+~+ww xY wc c}0w c c}w c c}w c c}w c c}w c c}4}9w c c}w # t        $ r tS        jT                  dT       Y Mw xY w# tP        $ r Y w xY w# tP        $ r Y JS w xY w)]a  
    Given binary data and a layout return the
    kwargs to create a scene object.

    Parameters
    -----------
    header : dict
      With GLTF keys
    buffers : list of bytes
      Stored data
    mesh_kwargs : dict
      To be passed to the mesh constructor.
    ignore_broken : bool
      If there is a mesh we can't load and this
      is True don't raise an exception but return
      a partial result
    merge_primitives : bool
      If true, combine primitives into a single mesh.
    skip_materials : bool
      If true, will not load materials (if present).
    resolver : trimesh.resolvers.Resolver
      Resolver to load referenced assets

    Returns
    -----------
    kwargs : dict
      Can be passed to load_kwargs for a trimesh.Scene
    rB   Nr?   r   r<   r>   r   r   r   r   r   
byteStrider   zbyteStride should be positive)rn   offsetr   rm   )ra   rz   r   r  r   )r  from_gltf_primitiver   r   r   primitive_preprocess)r   r2  r3  r   ra   r  processFr  r  r   GLTF)countsr   )rf  r  r5  )r   rn  r   r!  r%  r9  r"  zfailed to load colorsTr   r   r  r   r4  )r   r   r,  r+  r&  z"no materials! `pip install pillow`r*  r)  )r(  r&  r3  )r   r2  r3  r   r   z skipping primitive with mode %s!zfailed to load mesh)r   )r&  face_materials)r5  r4  r   r  r  r   worldz0file contains a `world` node, we may stomp on itr5   r   children)
frame_fromframe_tomatrixr&   translationrotationr%   )r   r   r   r$   scaler   r   z GLTF camera is not fully-definedr   r  r     )r   r  r4   )classr  r  
base_framer   camera_transformr  )JrT   rU   rp   rn   r   r   r   absr   r   r@  rq   libstride_tricks
as_stridedr   r:  viewr   zerosr  r   r   r   r   r  r
  r   r   r8  r   rl  path.entitiesrf  aranger   r   ry  r   r!  r   r   r  	_GL_STRIPr   int64r   r  TextureVisualsr  r   r   
differencer   append_facesr&  MultiMaterialr   r   r   r  extendr  T_EYEdotr
   translation_matrixquaternion_matrixdiagconcatenate_cam_from_gltfr   	unique_id)Kru   rA   r   rz   r{   r|   r}   ra   rd   r  r   endaccessr   ar   rn   per_itemr   	per_countbuffer_viewr   strideper_rowr   r   	mesh_primr   name_countsr  r  pprim_extensionsr   r  attrr   rf  customvisualsrm  flatr(  Emesh_prim_replacemesh_popr   namesnrG  v_seqf_seqr   r-  r  r   
name_indexr   r  r  queuer   r  scene_indexrootconsumededger   childquatcam_idx
geometries	geom_namer  ra  sK                                                                              rf   r   r     si   L VM233 !67GAtt#\*$|,,CtH~.uS9E!HuQx=D$6666 8 #f[122!&"56HE1gJEHHWQ%789E qy)HIIeX.E rwwx01Iq  %]3AlOD Q|_- lA.;.(6F'%..8G#ai61G;F "A:F'FF:DD3t9DDDDD$&HH,,77MM $BHHU& #G,#QK e 
%F5M #^^e3i?F$&MMUUV^4E%gen 5M
 !#):% H P PQV Wuw 7| I(uxPID!I]F
 Kfjj267qg	 "'*1\?';a'?H !%%/40(, q ./o*+|_ '(eeL&99?9%#24"#"(# "+.::j$/7)+F:&F*(-F9%z"))(3 uuV]3uuVV,"4D9$5)/Z0@)AF:&*.biiF:DV@W6X*Y)ZF:& 59IIK4?q1<<PSCT6$q'?*K   6{Q6<23Z')/Z0@)AF:&"G D(N%+DO%<F"6{c&2D.EE#*?>DkkmF?$; JPG$=$=g$F *+2x(mY77)/Z0@)AF:& A~9,#)!I,#7#?#?#CD.Fv.NF7O.4Qy\.B.J.J7.SF7O  9,.F ""))Cz8J4K*L)M N/F7O
 /1ii #F:$6 7rxx/%gg. #7O  4'39$x.3I/0"G!Q~$,II&JK!%B+t3 &,D,>%?%D%D%F+.AqD>1a4&,nn&C&C#%	!J-0H 'D 'G !D(N%+DO%<F"6{c&2D.EE#*?>DkkmF?$; JPG$=$=g$F *+2x( 59IIK4?q1<<PSCT6$q'?*K   6{Q6<23 +,%%*===)'6"-&'(.&, II@$G6)))%t% ''-g %! 8\  5!*!2J5zQ05!*- u:D OOCJ114&9: +00%Qvay%G0,34GqQz]GE4)01AQwZE1$$UE2DAq7>?w!8--wI?N!'*11#AgJ"77 +nn33666K- 4 G VE!H--!%(+J7!$ F4L .2Fj)I "3L &	&./hAt	h/ JJw#E JK % 1YZ
;quuVSV4jUV ! )..010daQT0E1 JZ		DE"E* GEGE F&Wo J68$[155grBDLL*d+, C
 uH e*q.yy{ 8T1 aLL%
*;<*;Q1a&*;<= !&aeAh?
 ux

;CCFKMM 8
  $F8 E!!vvx /"D"DU=EY"Z F8  ::eJ/3LAD!vvx /"C"CD"I F8 e!vvx "''"..%.3%9P*Q"R F8 uHoG>'y(9'(BC #)(#3  eii)40!&xF: 5 '%'z"49,4GF:01U?"5=1J :"V[[]+!+I)2F:&'+F8$+08F<( #((1T^^1-E,FGH)1F:&LL/ ", ZA%%/]z"U?).qF:&V[[]+ LL Q e*q.X  ,F 	z!!&"26'?"CH"MN 17|0Dz,- M}
(  - NII&=MMNz  - NII&=MMN,  			/$? @	: 141?. 	0" 2l =X  >		<=>x    Ms   Eu#t+t62u#)At>F
u#	At7u#7uuA3u#vv&v v%v*v//v5=v:  w >w. u# t40u#3t44u#7 uu#uu##	v,vv:ww	w+*w+.	w;:w;c                     d| vry| j                  d      }| d   d   }| d   d   }t        j                  | d   d         }||z  |f}t        |||      S )a  
    Convert a gltf perspective camera to trimesh.

    The retrieved camera will have default resolution, since the gltf specification
    does not contain it.

    If the camera is not perspective will return None.
    If the camera is perspective but is missing fields, will raise `KeyError`

    Parameters
    ------------
    cam : dict
      Camera represented as a dictionary according to glTF

    Returns
    -------------
    camera : trimesh.scene.cameras.Camera
      Trimesh camera object
    perspectiveNr   znearaspectRatioyfov)r   fovz_near)r   rp   degreesr   )camr   r  aspect_ratior  r  s         rf   r  r    sp    ( C776?Dw'E}%m4L::c-(01D$
%CtU33r:   c                     | j                   d| j                  d   | j                  d   z  t        j                  | j                  d         t	        | j
                        dd}|S )z
    Convert a trimesh camera to a GLTF camera.

    Parameters
    ------------
    camera : trimesh.scene.cameras.Camera
      Trimesh camera object

    Returns
    -------------
    gltf_camera : dict
      Camera represented as a GLTF dict
    r  r   r   )r  r  r  )r   r   r  )r   r  rp   radiansr   r  )r   ra  s     rf   r   r     sY     !::a=6::a=8JJvzz!}-6==)
F Mr:   c                    t        | d      sy|rd}n| j                  dk(  rd}nd}t        j                         5 }| j	                  ||       |j                  d       |j                         }ddd       t        |      }|d   j                  |d	|j                          d
       t        |d         dz
  S # 1 sw Y   NxY w)a  
    Append a PIL image to a GLTF2.0 tree.

    Parameters
    ------------
    img : PIL.Image
      Image object
    tree : dict
      GLTF 2.0 format tree
    buffer_items : (n,) bytes
      Binary blobs containing data
    extension_webp : bool
      Export textures as webP (using glTF's EXT_texture_webp extension).

    Returns
    -----------
    index : int or None
      The index of the image in the tree
      None if image append failed for any reason
    rP   NWEBPJPEGpng)rP   r   r   zimage/)r   r}  r   )rK   rP   r   BytesIOsaveseekr   r   r   lowerrT   )r  r]   r^   r8   save_asr-  r   r   s           rf   _append_imager    s    , 3!	v	  
17#	q	vvx 

 <.ENfW]]_DU<VWX tH~"" 
s   5B==Cc                    t        |       }|	||v r||   S t        | d      r| j                         }n| }di i}	 t        j                  j                  |j                        j                  d      j                         |d<   	 |j                  j                  d      j                         |d<   t        |j                  t              r|j                  |d<   t        |j                  t              r|j                  |d<   t        |j                  t               r|j                  |d	<   t        |j"                  t$              r|j"                  |d
<   t        |j&                  t               r|j&                  |d<   t        |j(                  t               r|j(                  |d<   |j*                  |j,                  |j.                  |j0                  |j2                  d}|j5                         D ]`  \  }	}
|
	t7        |
|||      }|dt9        |d         i||	<   |r|d   j;                  ddd|iii       K|d   j;                  d|i       b g d}|D ]  }	|	|v s|j=                  |	      |d   |	<     t9        |d         dk(  r|j=                  d       t9        |d         }|d   j;                  |       |||<   |S # t        $ r Y Nw xY w# t        $ r Y 1w xY w)a  
    Add passed PBRMaterial as GLTF 2.0 specification JSON
    serializable data:
    - images are added to `tree['images']`
    - texture is added to `tree['texture']`
    - material is added to `tree['materials']`

    Parameters
    ------------
    mat : trimesh.visual.materials.PBRMaterials
      Source material to convert
    tree : dict
      GLTF header blob
    buffer_items : (n,) bytes
      Binary blobs with various data
    mat_hashes : dict
      Which materials have already been added
      Stored as { hashed : material index }
    extension_webp : bool
      Export textures as webP using EXT_texture_webp extension.

    Returns
    -------------
    index : int
      Index at which material was added
    to_pbrr.   r%   r/   r   emissiveFactorr   	alphaModealphaCutoffdoubleSidedr0   r1   )baseColorTextureemissiveTexturenormalTextureocclusionTexturemetallicRoughnessTexture)r  r]   r^   r8   r   r   r   r   r  )r  r/   r1   r0   r  r   r   )r   rK   r  r   r"  to_floatr/   r   r   r   r  r   r   r   r  r   r   r  boolr0   r1   r  r  r  r  r  r   r  rT   r   r   )r'  r]   r^   r   r8   r   as_pbrra  image_mappingr   r  r   
pbr_subsets                rf   r<  r<    s   8 #YF &J"6&!! sH %b)F LL!!&"8"89AA!DKKM 	 !#)#8#8#@#@#C#J#J#L 
 &++s#v &""C($..{ &$$e, & 2 2} &$$d+ & 2 2} &''/#)#8#8 &((%0$*$:$: ! #33!11--"33$*$C$CM "'')S;$\.

 "CZ(8$9:F3K Z ''!$658I#JK Z ''5(9:' *0J &=28**S/F)*3/ 
 6()*a/

)* [!"EV$JvLm  
  s$   A	K ,K 	KK	K#"K#c                 H    ddl }t               }|j                  | |      }|S )a[  
    Validate a GLTF 2.0 header against the schema.

    Returns result from:
    `jsonschema.validate(header, schema=get_schema())`

    Parameters
    -------------
    header : dict
      Populated GLTF 2.0 header

    Raises
    --------------
    err : jsonschema.exceptions.ValidationError
      If the tree is an invalid GLTF2.0 header
    r   N)schema)
jsonschema
get_schemarY   )ru   r  r  valids       rf   rY   rY     s*    $  \Fv6ELr:   c                      ddl m}  t        j                  d      }t	        j
                  |d      }t        |      }t        j                  t	        j                  |j                  d                  } | ||      }|S )z
    Get a copy of the GLTF 2.0 schema with references resolved.

    Returns
    ------------
    schema : dict
      A copy of the GLTF 2.0 schema without external references.
    r   )resolvezschema/gltf2.schema.zipzipzglTF.schema.json)rz   )schemasr  r	   
get_streamr   
decompressr   r   r   r   r   )r  streamarchiverz   
unresolvedr  s         rf   r  r    sh     # !!";<Foofe,G7#HD,,X\\:L-MNOJZ(3FMr:   )glbr   )NFTNFFF)NTNNFF)NNFFF)NFFF)F)r%   )N)FFF)T__doc__rQ   r   collectionsr   r   r   r   r   numpyrp   r~  r   r	   r
   r   r   cachingr   	constantsr   r   	resolversr   r   scene.camerasr   typedr   r   r   r   r   r   r   r   r   rr   r   r   rY  r   rk  rl  ry  r8  r  eyer  flags	writeablern   r7  r6  r:  rg   rx   r  r   r   r   r_  r   r   r  r   r   rL   r  rM   rD  ro   r  r  r  r  r   r  r   r  r<  rY   r  _gltf_loaders)r   r   s   00rf   <module>r'     sm     7 7   C C   ! 2 # : : 9 ) j	A e5URW
X'.}}7tq!!AB%(7
  '  	
	rvvay

  "((5/	%
 dR eR "&'+" HvH|$H H 	H
 HZ (," pp|$p p 	p
 pf.s .l .u .:8Ok O OD O Od Px "v#
 d^v# v# v# v# v#r8/dDn#bC#L%PLh  " SS%[S S |$	S
 S S Sl4@4.#bEP88 !)4gE 8s   G