
    Mi	9                         S SK rSSKJr  SSKJr  SSKJrJrJ	r	  SSK
JrJr   S SKJrJr       SS	\	\   S
\	\   S\	S   S\	S   S\	\   S\4S jjrg! \ a  r\" \5      r\" \5      r SrCNCSrCff = f)    N   )log)ExceptionWrapper)	ArrayLikeNumberOptional   )linear_to_srgbsrgb_to_linear)Image	fromarrayspecularFactorglossinessFactorspecularGlossinessTexturer   diffuseTexturediffuseFactorreturnc           
      	  ^^^^^ [        [        [        5      (       a;  [        R                  " S5        0 n[        T[
        5      (       a  TUS'   Ub  XFS'   U$ [        R                  " / SQ[        R                  S9mSmUU4S jnS	 nS(S
 jn	S n
U4S jnU4S jnTb  Tb  [        UU4S j[        S5       5       5      nTR                  S   US   :w  d  TR                  S   US   :w  a  TR                  U5      mTR                  S   US   :w  d  TR                  S   US   :w  a  TR                  U5      mS mS nU" UT5      nU" XT5      u  nnnU" U" U5      U" U5      U5      n[        U[        R                  5      (       d#  [        R                  " U[        R                  S9nUSSS24   nUUSTS   -
  -  [        R                  " SU-
  TS5      -  -  nUTSU-
  -  -
  S[        R                  " UTS5      -  -  nUU-  nUU-  SU-
  U-  -   n[        R                  " USS5      n UR                  S:X  a  US   nUR                  S:X  a  [        R                   " UU5      nO[#        UR                  5      S:X  ah  UR                  n[        R$                  " U[        R&                  " [        R(                  " USS 5      U5      R+                  US   US   S45      45      nO2UR                  S   S:X  a  US   n[        R,                  " UUS   /SS9n0 n[#        UR                  5      S:  a&  U	" U" U5      UR                  S   S:X  a  S"OS#S$9US'   OUR3                  5       US'   [#        UR                  5      S:  d  [#        UR                  5      S:  a  [#        UR                  5      S:X  a4  [        R4                  " UUR                  S   UR                  S   S45      n[#        UR                  5      S:X  a4  [        R4                  " UUR                  S   UR                  S   S45      nU	" [        R,                  " [        R6                  " U5      SU-
  U/SS9S"S$9US%'   SUS&'   SUS''   U$ U
" U5      US&'   U
" SU-
  5      US''   U$ ! [.         a    [        R0                  " SS S!9   GNf = f))a  
Convert the KHR_materials_pbrSpecularGlossiness to a
metallicRoughness visual.

Parameters
-----------
specularFactor : list[float]
    Specular color values. Ignored if specularGlossinessTexture
    is present and defaults to [1.0, 1.0, 1.0].
glossinessFactor : float
    glossiness factor in range [0, 1], scaled
    specularGlossinessTexture if present.
    Defaults to 1.0.
specularGlossinessTexture : PIL.Image
    Texture with 4 color channels. With [0,1,2] representing
    specular RGB and 3 glossiness.
diffuseTexture : PIL.Image
    Texture with 4 color channels. With [0,1,2] representing diffuse
    RGB and 3 opacity.
diffuseFactor: float
    Diffuse RGBA color. scales diffuseTexture if present.
    Defaults to [1.0, 1.0, 1.0, 1.0].

Returns
----------
kwargs : dict
  Constructor args for a PBRMaterial object.
  Containing:
    - either baseColorTexture or baseColorFactor
    - either metallicRoughnessTexture or metallicFactor and roughnessFactor
z:unable to convert specular-glossy material without pillow!baseColorTextureNbaseColorFactor){Gz?r   r   dtypegư>c                   > [        U[        5      (       a
  UTS   :  a  g[        U R                  5      S:X  a  U S   n [        UR                  5      S:X  a  US   nTS   nX-  STS   -
  -  U-   STS   -  -
  nTS   U-
  nXD-  SU-  U-  -
  n[        R
                  " UT	S 5      n[        R
                  " U* [        R                  " U5      -   SU-  -  SS5      n[        U[        R                  5      (       a
  SXqTS   :  '   U$ )Nr           r   .N      ?g       @g      @)
isinstancefloatlenshapenpclipsqrtndarray)
diffusespecularone_minus_specular_strengthabcDmetallicdielectric_specularepsilons
           n/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/visual/gloss.pysolve_metallic'specular_to_pbr.<locals>.solve_metallicE   s   h&&86I!6L+Lw}}"i(Gx~~!#	*H"1S;Nq;Q5QR'**+ 	

  "X-EC!GaKGGAw%77QBOa8#sCh

++:=H 3A 667    c                 p    [         R                  " [         R                  " U SS S24   S-  / SQ5      5      $ )N.   r   )gA`"?gbX9?gv/?)r"   r$   dot)rgbs    r0   get_perceived_brightness1specular_to_pbr.<locals>.get_perceived_brightness\   s.    wwrvvc#rr'la/1FGHHr3   c                 .   [        U [        5      (       a  U $ U R                  [        R                  :X  d  U R                  [        R
                  :X  a8  [        R                  " U SS5      S-  R                  [        R                  5      n [        U 5      $ )Nr   r        o@)
r   r   r   r"   float32float64r#   astypeuint8r   )imgmodes     r0   toPILspecular_to_pbr.<locals>.toPIL_   sc    c5!!J99

"cii2::&=773S)E199"((CC~r3   c                     [        U [        5      (       a  U $ [        U [        R                  5      (       a  [	        U R
                  5      S:X  a  U S   $ U R                  5       $ )Nr	   r   )r   r   r"   r%   r    r!   tolist)vals    r0   	get_float"specular_to_pbr.<locals>.get_floatf   sI    c5!!Jc2::&&3syy>Q+>q6Mzz|r3   c           	      4  > U b  U O/ SQn [         R                  " U [         R                  S9n UGb  UR                  S:X  a  UR	                  S5      nO!UR                  S:X  a  UR	                  S5      n[         R                  " U5      S-  nT" U5      n[        UR                  5      S:X  a  US	   nUR                  S
   S:X  a  X -  nU$ UR                  S
   S:X  aT  USSS24   nUSS S24   U -  nU R                  S
   S:X  a  [         R                  " X#/S
S9nU$ USS
S 24==   U-  ss'    U$ UR                  S
   U R                  S
   :X  a  X -  nU$ UR                  S
   S:X  aJ  U R                  S
   S:X  a7  [         R                  " U[         R                  " USS S24   5      /S
S9U -  nU$ [        R                  " SU R                   SUR                   3-   5         U$ U b  U O/ SQn[         R                  " U[         R                  S9nU$ )N)r   r   r   r   r   BGRRGBBGRARGBAr;   r   r   r	   .r5   axis   z?`diffuseFactor` and `diffuseTexture` have incompatible shapes: z and )r	   r	   r	   r	   )r"   arrayr<   rA   convertr    r!   concatenate	ones_liker   warning)r   r   r&   alphaconvert_texture_srgb2lins       r0   get_diffuse$specular_to_pbr.<locals>.get_diffusem   s;   *6M<P 	 bjjA%""e+!/!7!7!>$$.!/!7!7!?hh~.6G /w7G7==!Q&!),}}R A%!10 / r"a'QqS)!#rr'*]: &&r*a/ nng-=BGG$ ! CH%.%   r"m&9&9"&==!1  r"a'M,?,?,Cq,HNNGR\\'#rr':J-K#LSUV#$   U&,,-U7==/BC  (5'@mlGhhwbjj9Gr3   c                 h  > U c  / SQn [         R                  " U [         R                  S9n Uc  Sn[         R                  " U/[         R                  S9nUGbp  UR                  S:X  a  UR	                  S5      nO!UR                  S:X  a  UR	                  S5      n[         R                  " U5      S-  nS	u  p4[        UR                  5      S
:X  a/  UR                  UR                  S   UR                  S   S5      =p4OUR                  S   S:X  a  US[         R                  4   =p4OhUR                  S   S:X  a
  USS S24   nOKUR                  S   S
:X  a  USS S24   nUSSS
24   nO%UR                  S   S:X  a  USS S24   nUSSS 24   nUb  T" U5      nX0-  nOU nUb  XA-  nOUnS[         R                  " USSS9-
  nOgU b  U O/ SQn[         R                  " U[         R                  S9nUb  UOSn[         R                  " U[         R                  S9nS[        US S 5      -
  nXVU4$ )N)r   r   r   r   r   rJ   rK   rL   rM   r;   )NNr   r   r	   rN   .r5   rQ   T)rP   keepdims)
r"   rR   r<   rA   rS   r    r!   reshapenewaxismax)	r   r   r   specularTextureglossinessTexturer'   
glossinessr(   rX   s	           r0   get_specular_glossiness0specular_to_pbr.<locals>.get_specular_glossiness   sj    !,N.

C#"88%5$6bjjI %0(--6,E,M,Me,T)*//69,E,M,Mf,U)(*1J(Ke(S%1;.O,223q86O6W6W-33A6-33A67 "3
 +00496OO7 "3 +0049";C!G"D*0049";C!G"D$=c1Q3h$G!*0049";C!G"D$=c12g$F!*":?"K*;) ,.A
-
*-xbSW0X*X')7)C~Hxx

;H-=-I)sJ*BJJ?J*-HRaL0A*A'%@@@r3   c              3   p   >#    U  H+  n[        TR                  U   TR                  U   5      v   M-     g 7fN)r_   size).0ir   r   s     r0   	<genexpr>"specular_to_pbr.<locals>.<genexpr>   s9      
 ##A&(A(F(Fq(IJJs   36r   r   r	   c                     U R                  5       nUR                  S   nUS:X  d  US:X  a  US-  n[        USSU24   5      USSU24'   U$ )z
Wrapper for srgb2lin that converts color values from sRGB to linear.
If texture has 2 or 4 channels, the last channel (alpha) is left unchanged.
rN   rQ   r   r	   .N)copyr!   r   textureresultcolor_channelss      r0   rX   1specular_to_pbr.<locals>.convert_texture_srgb2lin   sa    
 b)Q.A"5aN'5fS/>/=Q6R'SsO^O#$r3   c                     U R                  5       nUR                  S   nUS:X  d  US:X  a  US-  n[        USSU24   5      USSU24'   U$ )z
Wrapper for lin2srgb that converts color values from linear to sRGB.
If texture has 2 or 4 channels, the last channel (alpha) is left unchanged.
rN   rQ   r   r	   .N)rm   r!   r
   rn   s      r0   convert_texture_lin2srgb1specular_to_pbr.<locals>.convert_texture_lin2srgb  sa     b)Q.A"5aN'5fS/>/=Q6R'SsO^O#$r3   .r5   r   r   )rQ   rN   )r5   rQ   ).rN   r   rO   zunable to get opacityT)exc_inforK   rM   )rA   metallicRoughnessTexturemetallicFactorroughnessFactorrf   )r   r   r   r   debugdictr"   rR   r<   tuplerangerg   resizer%   r#   r!   appendr    dstackfullprodr]   rT   BaseExceptionerrorrE   tile
zeros_like)r   r   r   r   r   kwargsrp   r1   r8   rB   rG   rY   rc   	max_shapert   r&   r'   rb   r(   r-   diffuse_rgbbase_color_from_diffusebase_color_from_specularmm
base_coloropacitydimrX   r.   r/   s     ``                       @@@r0   specular_to_pbrr      s   T %)**		NOnd++)7F%&$(5$%((#5RZZHG.I-^EAN !&?&K 
1X
 
	
 "il2""1%15+229=N%**1-1=(--a0IaL@(A(H(H(S% -8G8O*C95Hj5  ) *#H
 h

++88HBJJ7#rr'"K)#$Q''	)
''3>GT
2	3
 !)+>#.+Q Qbggh..  
H	B..#(>U1UUJS#.J:==D bkG4'  YYz7;
Z%%&!+ &&YY"BQ 0':BBCFCPQFTUCVW
 ]]2!#g&GWY5G(HrRJ F
:q %*$Z0%++B/14%&&
!"
 %/$5$5$7 !
8>>Q#j&6&6"7!";z A%hnnQ.?PQARTU-VWJx~~!#wwx**:*:1*=z?O?OPQ?RTU)VWH .3NNx(#
*:HEB 	.
)* $' $' !
 M $-X#6 $-cJ.>$? !MA  :		)D9:s   8<R' 5BR' 72R' 'S
	S
)NNNNN)numpyr"   	constantsr   
exceptionsr   typedr   r   r   colorr
   r   	PIL.Imager   r   r   Er{   r    r3   r0   <module>r      s      ) / / 1$* +/)-37(,)-PY'Pv&P  (0P W%	P
 I&P 
P  $QE #I$s   A A4A//A4