+
    „°ñjŸZ  ã                   ó  € R t ^ RIt^ RIt^ RIt^ RIt^ RIHtHtH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHtHtHtHtHt ^ RIt^ RIHt ]	P8                  ! R	4      t]	P8                  ! R
4      tR R ltR R lt  ! R R]	PB                  4      t" ! R R]	PB                  4      t# ! R R]	PB                  4      t$ ! R R]	PB                  4      t% ! R R]	PB                  4      t& ! R R]	PB                  4      t' ! R R]4      t(R R lt)R# )zNComfyUI nodes for the native MoGe (Monocular Geometry Estimation) integration.N)ÚComfyExtensionÚTypesÚio)Úoverride)Úturbo)Ú	MoGeModel)Útriangulate_grid_mesh)Úget_panorama_camerasÚsplit_panorama_imageÚmerge_panorama_depthÚspherical_uv_to_directionsÚ_uv_grid)ÚtqdmÚ
MOGE_MODELÚMOGE_GEOMETRYc                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )é   ÚpointsÚreturn©ÚtorchÚTensor)Úformats   "Ú;C:\Ai_Coding\apps\studio\ComfyUI\comfy_extras\nodes_moge.pyÚ__annotate__r       s&   € ÷ Eñ E¤§¡ð E´%·,±,ñ Eó    c                ól  € \         P                  ! V 4      P                  RR7      p\         P                  ! VP	                  R4      V \         P
                  ! V 4      4      pVR,          VRRRR1R3,          ,
          pVR,          VRRR1RR3,          ,
          p\         P                  P                  P                  VP                  ^ ^^^4      R	4      P                  ^ ^^^4      p\         P                  P                  P                  VP                  ^ ^^^4      R
4      P                  ^ ^^^4      p\         P                  ! WCRR7      p\         P                  P                  P                  VRR7      p\         P                  ! VP	                  R4      V\         P
                  ! V4      4      # )zICamera-space surface normals from a (B, H, W, 3) point map (v1 fallback).©Údim.ºNNNNéÿÿÿÿ).r   ºr   NNr   éþÿÿÿ).r!   r   r   )é   r#   é    r$   )r$   r$   r#   r#   )r   ÚisfiniteÚallÚwhereÚ	unsqueezeÚ
zeros_likeÚnnÚ
functionalÚpadÚpermuteÚcrossÚ	normalize)r   ÚfiniteÚptsÚdxÚdyÚns   &     r   Ú_normals_from_pointsr5       s\  € ä�^Š^˜FÓ#×'Ñ'¨BÐ'Ó/€FÜ
�+Š+�f×&Ñ& rÓ*¨F´E×4DÒ4DÀVÓ4LÓ
M€CØ	ˆ]Õ	˜c # q¨#¨2¨#¨q .Õ1Õ	1€BØ	ˆ]Õ	˜c # s¨ s¨A¨q .Õ1Õ	1€BÜ	�‰×	Ñ	×	 Ñ	  §¡¨A¨q°!°QÓ!7¸Ó	F×	NÑ	NÈqÐRSÐUVÐXYÓ	Z€BÜ	�‰×	Ñ	×	 Ñ	  §¡¨A¨q°!°QÓ!7¸Ó	F×	NÑ	NÈqÐRSÐUVÐXYÓ	Z€Bä�Š�B Ô#€AÜ�‰×Ñ×%Ñ% a¨RÐ%Ó0€AÜ�;Š;�v×'Ñ'¨Ó+¨Q´×0@Ò0@ÀÓ0CÓDÐDr   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )r   Údepthr   r   )r   s   "r   r   r   .   s"   € ÷ ñ ¤§¡ð ´·±ñ r   c                ó²  € \         P                  ! V 4      p\        V P                  ^ ,          4       EF  pW,          p\         P                  ! V4      V^ 8„  ,          pVP                  4       '       g   KD  \         P                  ! VRVP                  R4      ,          \         P                  ! V4      4      pWT,          p\         P                  ! VR4      p\         P                  ! VR4      pW‡,
          P                  R4      p	WW,
          V	,          P                  RR4      p
\         P                  ! WJ\         P                  ! V
4      4      W&   EK"  	  V# )zIPer-batch normalize 1/depth to [0, 1] using 0.1/99.9 percentile clipping.ç      ð?g�íµ ÷Æ°>gü©ñÒMbP?g+‡ÙÎ÷ï?ç        )
r   r)   ÚrangeÚshaper%   Úanyr'   Ú	clamp_minÚquantileÚclamp)r7   ÚoutÚiÚdÚvalidÚdispÚ
disp_validÚloÚhiÚscaleÚnorms   &          r   Ú_normalize_disparityrK   .   sö   € ä
×
Ò
˜5Ó
!€CÜ�5—;‘;˜q•>×"ˆØ�HˆÜ—’˜qÓ! Q¨¡UÕ+ˆØ�y‰y�{Š{ÙÜ�{Š{˜5 #¨¯©°DÓ(9Õ"9¼5×;KÒ;KÈAÓ;NÓOˆØ•[ˆ
Ü�^Š^˜J¨Ó.ˆÜ�^Š^˜J¨Ó.ˆØ•×#Ñ# DÓ)ˆØ•˜eÕ#×*Ñ*¨3°Ó4ˆÜ—’˜U¬%×*:Ò*:¸4Ó*@ÓAˆŒñ #ð €Jr   c                   óL   a € ] tR t^@t o ]R 4       t]V 3R lR l4       tRtV tR# )ÚLoadMoGeModelc                óÆ   € \         P                  ! R RR\         P                  P                  R\        P
                  ! R4      R7      .\        P                  4       .R7      # )rM   zLoad MoGe Modelzmodel/loadersÚ
model_nameÚgeometry_estimation)Úoptions)Únode_idÚdisplay_nameÚcategoryÚinputsÚoutputs)r   ÚSchemaÚComboÚInputÚfolder_pathsÚget_filename_listÚMoGeModelTypeÚOutput©Úclss   &r   Údefine_schemaÚLoadMoGeModel.define_schemaA   sR   € ä�yŠyØ#Ø*Ø$ä—‘—‘˜|´\×5SÒ5SÐTiÓ5j�Ókðô #×)Ñ)Ó+Ð,ô
ð 	
r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# ©r   r   ©r   Ú
NodeOutput)r   Ú__classdict__s   "€r   r   ÚLoadMoGeModel.__annotate__N   s   ø€ ÷ ,ñ ,¡B§M¡Mñ ,r   c                ó°   € \         P                  ! R V4      p\        P                  P	                  VRR7      p\
        P                  ! \        V4      4      # )rP   T)Ú	safe_load)rZ   Úget_full_path_or_raiseÚcomfyÚutilsÚload_torch_filer   re   r   )r_   rO   ÚpathÚsds   &&  r   ÚexecuteÚLoadMoGeModel.executeM   sA   € ä×2Ò2Ð3HÈ*ÓUˆÜ�[‰[×(Ñ(¨¸Ð(Ó>ˆÜ�}Š}œY r›]Ó+Ð+r   © N©	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Úclassmethodr`   rp   Ú__static_attributes__Ú__classdictcell__©rf   s   @r   rM   rM   @   s+   ø‡ € Øñ	
ó ð	
ð ÷,ó ö,r   rM   c                   óP   a € ] tR t^Tt o Rt]R 4       t]V 3R lR l4       tRtV t	R# )ÚMoGePanoramaInferencez÷Equirectangular panorama inference: split into 12 perspective views, run
MoGe at fov_x=90 on each, merge via multi-scale Poisson + gradient solve.
v2's predicted normals and metric scale are ignored (per-view scales would not align across seams).
c                ó2  € \         P                  ! R . RORRR\        P                  R4      \         P                  P                  RRR7      \         P
                  P                  R^	^ ^	R	R
7      \         P
                  P                  RRRRRR
7      \         P
                  P                  RRRRRR
7      \         P
                  P                  R^^^RR
7      \         P
                  P                  R^^ ^RRR7      .\        P                  RR7      .R7      # )r}   zRun MoGe Panorama Inferenceúimage/geometry estimationzžRun MoGe on an equirectangular panorama by splitting it into 12 perspective views, running inference on each, and merging the results into a single depth map.Ú
moge_modelÚimagez&Equirectangular panorama (any aspect).)ÚtooltipÚresolution_levelz1Per-view detail (0 = fastest, 9 = most detailed).©ÚdefaultÚminÚmaxr‚   Úsplit_resolutioni   é   i   z%Resolution of each perspective split.Úmerge_resolutioni€  i    z9Long-side resolution of the merged equirect distance map.Ú
batch_sizez,Views per inference batch (12 splits total).Úrefine_stepsTúÁMoGe-3 only: sparse volumetric refinement passes over the predicted depth. More passes sharpen fine detail and edges at a roughly linear cost. 0 disables refinement. Ignored by MoGe-1 / MoGe-2.©r…   r†   r‡   Úadvancedr‚   Úmoge_geometry©rS   )rR   Úsearch_aliasesrS   rT   ÚdescriptionrU   rV   )ÚmogeÚpanoramar7   Úgeometryúdepth estimationúgeometry estimation)r   rW   r\   rY   ÚImageÚIntÚMoGeGeometryr]   r^   s   &r   r`   Ú#MoGePanoramaInference.define_schemaZ   s  € ä�yŠyØ+ÚoØ6Ø0ð yä×#Ñ# LÓ1Ü—‘—‘˜wÐ0X�ÓYÜ—‘—‘Ð/¸ÀÀqØ%Xð ó Zä—‘—‘Ð/¸À#È4Ø%Lð ó Nä—‘—‘Ð/¸À3ÈDØ%`ð ó bä—‘—‘˜\°1¸!ÀØ%Sð ó Uä—‘—‘˜^°Q¸AÀ1Ètð &ið ó jðô "×(Ñ(°oÐ(ÓFÐGô)
ð 	
r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rc   rd   )r   rf   s   "€r   r   Ú"MoGePanoramaInference.__annotate__t   s&   ø€ ÷ ^,ñ ^,Ñ{}÷  |Iñ  |Iñ ^,r   c                óp  a*a+a,a-€ VP                   ^ ,          ^8w  d!   \        RVP                   ^ ,           R24      hVR,          p\        VP                   ^,          4      \        VP                   ^,          4      r˜\        V\	        W‰4      ,          R4      p
\	        \        WŠ,          4      ^ 4      \	        \        Wš,          4      ^ 4      rË\        4       w  rÞ\        P                  P                  VP                  4       VP                  pV^ ,          P                  RR4      P                  WñP                  R7      p\        VWÞV4      pVP                   ^ ,          p. pYËpp VP                  VV34       \	        VV4      R8:  d   MV^,          V^,          ppK:  VP!                  4        \#        V4       UUu/ uF  w  ppV^V,          bK  	  uppo,V\%        V4      ,          p\'        S,P)                  4       4      p\        P*                  P-                  VV,           V,           4      o+^ o*. p. p\/        VRR7      ;_uu_ 4       o-\1        ^ VV4       Fþ  pVVVV,            pVP3                  VVR	RR
R
VR7      pVP5                  \7        VR,          P9                  4       P;                  RR7      P=                  4       P?                  4       4      4       VP5                  \7        VR,          P=                  4       P?                  4       4      4       VP                   ^ ,          pS*V,          o*S+PA                  S*4       S-PC                  V4       EK   	  RRR4       \/        VV,           RR7      ;_uu_ 4       o-V*V+V-3R lpV-3R lp V*V+V,V-3R lp!\E        WËVV\7        V4      VVV V!R7	      w  p"p#RRR4       \F        PH                  ! X"4      p"\F        PH                  ! X#4      p#W¼3W‰38w  d—   \F        PJ                  PL                  PO                  V"R ,          W‰3RR
R7      PQ                  4       p"\F        PJ                  PL                  PO                  V#R ,          P9                  4       W‰3RR7      PQ                  4       ^ 8„  p#V#PS                  4       '       dT   V#PU                  4       '       g>   \F        PV                  ! V"V#,          R4      R,          p$\F        PX                  ! V#V"V$4      p"\F        PH                  ! \[        \]        W‰4      4      4      p%V%V"R!,          ,          P_                  ^ 4      p&V"P_                  ^ 4      p'V#P_                  ^ 4      p(RV&RV'RV(RVP=                  4       /p)\`        Pb                  ! V)4      # u uppi   + '       g   i     EL=; i  + '       g   i     ELö; i)"r$   z9MoGePanoramaInference takes a single image (got batch of Ú)r9   ©ÚdeviceÚdtypeTr‰   zMoGe panorama inference©ÚtotalÚdescg     €V@F)rƒ   Úfov_xÚforce_projectionÚ
apply_maskÚapply_metric_scalerŒ   r   r   ÚmaskNúMoGe panorama merge: viewsc                  ó^   <€ S ^,          o SP                  S 4       SP                  ^4       R# )r#   N)Úupdate_absoluteÚupdate)ÚdoneÚpbarÚtqs   €€€r   Ú_on_merge_viewÚ5MoGePanoramaInference.execute.<locals>._on_merge_viewª   s%   ø€ à˜•	�Ø×$Ñ$ TÔ*Ø—	‘	˜!–r   c                 ó6   <€ SP                  R V  RV 24       R# )zMoGe panorama merge: solving ÚxN)Úset_description)ÚwÚhr²   s   &&€r   Ú_on_solve_startÚ6MoGePanoramaInference.execute.<locals>._on_solve_start°   s   ø€ Ø×"Ñ"Ð%BÀ1À#ÀQÀqÀcÐ#JÖKr   c                 ó”   <€ SW3,          pSV,          oSP                  S4       SP                  V4       SP                  R 4       R# )r¬   N)r®   r¯   r·   )r¸   r¹   Úweightr°   r±   Úsolve_weightr²   s   && €€€€r   Ú_on_solve_endÚ4MoGePanoramaInference.execute.<locals>._on_solve_end³   sA   ø€ à% q fÕ-�Ø˜•�Ø×$Ñ$ TÔ*Ø—	‘	˜&Ô!Ø×"Ñ"Ð#?Ö@r   )Úon_viewÚon_solve_startÚon_solve_endÚbilinear)ÚsizeÚmodeÚalign_cornersÚnearest)rÅ   rÆ   gffffffî?g      @r7   r�   ©.:Né   Nr    éýÿÿÿ)NN).N)2r<   Ú
ValueErrorÚintr†   r‡   r	   rk   Úmodel_managementÚload_model_gpuÚpatcherÚload_deviceÚmovedimÚtor£   r
   ÚappendÚreverseÚ	enumerateÚlenÚsumÚvaluesrl   ÚProgressBarr   r;   ÚinferÚextendÚlistÚfloatrJ   ÚcpuÚnumpyr®   r¯   r   r   Ú
from_numpyr*   r+   ÚinterpolateÚsqueezer=   r&   r?   r'   r   r   r(   r   re   ).r_   r€   r�   rƒ   rˆ   rŠ   r‹   rŒ   ÚHÚWrI   Úmerge_hÚmerge_wÚ
extrinsicsÚ
intrinsicsr¢   Úimg_chwÚsplitsÚn_viewsÚmerge_levelsÚw_Úh_rB   ÚwhÚn_merge_view_unitsÚn_merge_solve_unitsÚdistance_mapsÚmasksÚbatchÚresultr4   r³   rº   r¿   Ú
pano_depthÚ	pano_maskÚfarÚ
directionsr   r7   r«   r�   r°   r±   r¾   r²   s.   &&&&&&&&                                  @@@@r   rp   ÚMoGePanoramaInference.executes   sá  û€ ð �;‰;�q�>˜QÔÜÐXÐY^×YdÑYdÐefÕYgÐXhÐhiÐjÓkÐkà�g•ˆÜ�5—;‘;˜q•>Ó"¤C¨¯©°A­Ó$7ˆ1ÜÐ$¤s¨1£yÕ0°#Ó6ˆÜœs 1¥9›~¨rÓ2´C¼¸A½I»ÈÓ4K�ä!5Ó!7Ñˆ
ä×Ñ×-Ñ-¨j×.@Ñ.@ÔAØ×'Ñ'ˆØ˜•(×"Ñ" 2 rÓ*×-Ñ-°V×CSÑCSÐ-ÓTˆÜ% g¨zÐGWÓXˆà—,‘,˜q•/ˆð /1ˆØˆBˆØØ×Ñ  R Ô)Ü�2�r‹{˜cÔ!ØØ˜1•W˜b A�g�ˆB‘Ø×ÑÔä09¸,Ô0GÔHÑ0G¡u q¨"˜˜A �Fš
Ñ0GÒHˆØ$¤s¨<Ó'8Õ8ÐÜ! ,×"5Ñ"5Ó"7Ó8Ðä�{‰{×&Ñ& wÐ1CÕ'CÐFYÕ'YÓZˆØˆà ˆØˆÜ˜Ð&?×@Õ@ÀBÜ˜1˜g zÖ2�Ø˜q  Z¥Ð0�à#×)Ñ)¨%ÐBRØ04ÀtØ5:ÈuØ7Cð *ó E�ð ×$Ñ$¤T¨&°Õ*:×*@Ñ*@Ó*B×*GÑ*GÈBÐ*GÓ*O×*SÑ*SÓ*U×*[Ñ*[Ó*]Ó%^Ô_Ø—‘œT &¨¥.×"4Ñ"4Ó"6×"<Ñ"<Ó">Ó?Ô@Ø—K‘K •N�Ø˜•	�Ø×$Ñ$ TÔ*Ø—	‘	˜!—ñ 3÷ Aô Ð*Ð-@Õ@ÐGc×dÕdÐhj÷õL÷Að Aô %9Ø -°¼¸ZÓ8HÈ*Ø&°ÐUbô%dÑ!ˆJ˜	÷% eô, ×%Ò% jÓ1ˆ
Ü×$Ò$ YÓ/ˆ	àÐ ! Ô'ÜŸ™×,Ñ,×8Ñ8¸ÀJÕ9OÐWXÐV\Ðcmð  ~CÐ8ó  D÷  Lñ  Ló  NˆJÜŸ™×+Ñ+×7Ñ7¸	À*Õ8M×8SÑ8SÓ8UÐ]^Ð\bÐirÐ7Ós×{Ñ{Ó}ð  ABñ  BˆIð �=‰=�?Š? 9§=¡=§?¢?Ü—.’. ¨IÕ!6¸Ó=ÀÕCˆCÜŸš Y°
¸CÓ@ˆJä×%Ò%Ô&@ÄÈ!ÃÓ&PÓQˆ
Ø˜z¨)Õ4Õ4×?Ñ?ÀÓBˆØ×$Ñ$ QÓ'ˆØ×"Ñ" 1Ó%ˆð " 6¨7°E¸6À4ÈÐRW×R[ÑR[ÓR]Ð^ˆÜ�}Š}˜]Ó+Ð+ùóC I÷ A×@Ð@ú÷ e×dÐdús   Æ?V
ÉDVÎ 7V$ÖV!	Ö$V5	rr   N©
rt   ru   rv   rw   Ú__doc__rx   r`   rp   ry   rz   r{   s   @r   r}   r}   T   s4   ø‡ € ñð
 ñ
ó ð
ð0 ÷^,ó ö^,r   r}   c                   óL   a € ] tR t^Õt o ]R 4       t]V 3R lR l4       tRtV tR# )ÚMoGeInferencec                ór  € \         P                  ! R . RORRR\        P                  R4      \         P                  P                  R4      \         P
                  P                  R^	^ ^	RR7      \         P                  P                  R	R
R
RRRRR7      \         P
                  P                  R^^^@RR7      \         P                  P                  RRRR7      \         P                  P                  RRRRR7      \         P
                  P                  R^^ ^RRR7      .\        P                  RR7      .R7      # )rÿ   zRun MoGe Inferencez:Run MoGe on a single image to estimate depth and geometry.r   r€   r�   rƒ   z0 = fastest, 9 = most detail.r„   Úfov_x_degreesr:   g     @e@gš™™™™™¹?Tz™Horizontal field of view of the source camera. Sets the focal length used to unproject the depth map into 3D. 0 = auto-recover from the predicted points.)r…   r†   r‡   Ústepr�   r‚   r‹   zHImages per inference call. Lower if you OOM on a long video / image set.r¨   )r…   r�   r©   zµSet masked-out (sky / invalid) pixels to inf in points and depth so meshing culls them. Disable to keep the raw predicted geometry everywhere; the mask is still returned separately.)r…   r�   r‚   rŒ   r�   rŽ   r�   r‘   ©rR   r’   rS   r“   rT   rU   rV   )r”   r7   r–   r—   r˜   )
r   rW   r\   rY   r™   rš   ÚFloatÚBooleanr›   r]   r^   s   &r   r`   ÚMoGeInference.define_schemaÖ   s,  € ä�yŠyØ#ÚcØ-ØTØ0ä×#Ñ# LÓ1Ü—‘—‘˜wÓ'Ü—‘—‘Ð/¸ÀÀqØ%Dð ó Fä—‘—‘˜¸ÀÈ%ÐVYÐdhð (Cð ó Dä—‘—‘˜\°1¸!ÀØ%oð ó qä—
‘
× Ñ Ð!3¸TÈDÐ ÓQÜ—
‘
× Ñ  °tÀdð *að !ó bä—‘—‘˜^°Q¸AÀ1Ètð &ið ó jðô "×(Ñ(°oÐ(ÓFÐGô+
ð 	
r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rc   rd   )r   rf   s   "€r   r   ÚMoGeInference.__annotate__ñ   s'   ø€ ÷ ,ñ ,ñ  EG÷  ERñ  ERñ ,r   c	                óä  a€ VR,          pVP                  RR	4      P                  4       p	V	P                  ^ ,          p
V^ 8:  d   RM
\        V4      p\        P
                  P                  V
4      p. o\        V
RR7      ;_uu_ 4       p\        ^ W¥4       Ft  pWžWå,            pSP                  VP                  WóVWgVR7      4       VP                  \        Wå,           V
4      4       VP                  VP                  ^ ,          4       Kv  	  RRR4       V3R lpRVP                  4       /pR
 F  pV! V4      pVf   K  VVV&   K  	  \        P                   ! V4      #   + '       g   i     LZ; i).NzMoGe inferencer¤   )rƒ   r§   r¨   r©   rŒ   c                 ó�   <€ S Uu. uF  qV9   g   K  W,          NK  	  ppV'       d   \         P                  ! V^ R7      # R# u upi )r$   r   N)r   Úcat)ÚfieldÚcÚvalsÚchunkss   &  €r   ÚstackÚ$MoGeInference.execute.<locals>.stack  s>   ø€ Ù&,Ó;¡f ¸±
”H�A—H�H¡fˆDÐ;ß-1”5—9’9˜T qÔ)Ð;°tÐ;ùò <s
   †A“Ar�   rÉ   r    rË   )r   r7   ré   r«   Únormal)rÒ   Ú
contiguousr<   rÞ   rk   rl   rÚ   r   r;   rÔ   rÛ   r®   r†   r¯   rß   r   re   )r_   r€   r�   rƒ   r  r‹   r¨   r©   rŒ   ÚbchwÚBÚfovr±   r²   rB   Úchunkr  r�   r  Úvr  s   &&&&&&&&&           @r   rp   ÚMoGeInference.executeð   s>  ø€ ð �g•ˆØ�}‰}˜R Ó$×/Ñ/Ó1ˆØ�J‰J�q�MˆØ# qÔ(‰d¬e°MÓ.Bˆä�{‰{×&Ñ& qÓ)ˆØˆÜ˜Ð 0×1Õ1°RÜ˜1˜aÖ,�Ø˜q�~Ð.�Ø—‘˜j×.Ñ.¨uÐ_bØ@PØ<Hð /ó Jô Kð ×$Ñ$¤S¨­¸Ó%;Ô<Ø—	‘	˜%Ÿ+™+ a�.Ö)ñ -÷ 2õ	<ð ! %§)¡)£+Ð.ˆÛHˆEÙ�e“ˆAØŒ}Ø'(�˜eÓ$ñ Iô �}Š}˜]Ó+Ð+÷% 2×1ús   ÂBEÅE/	rr   Nrs   r{   s   @r   rÿ   rÿ   Õ   s+   ø‡ € Øñ
ó ð
ð2 ÷,ó ö,r   rÿ   c                   óP   a € ] tR tRt o Rt]R 4       t]V 3R lR l4       tRtV t	R# )Ú
MoGeRenderi  z;Render a visualization or mask from a MOGE_GEOMETRY packet.c                óê   € \         P                  ! R . R
ORRR\        P                  R4      \         P                  P                  R. RORRR7      .\         P
                  P                  4       .R	7      # )r  r7   zRender MoGe Geometryz3Render a depth map or normal map from geometry datar   r�   ÚoutputzŸDirectX vs OpenGL controls the normal-map green-channel convention. DirectX: green = -Y down (Unreal). OpenGL: green = +Y up (Blender, Substance, Unity, glTF).©rQ   r…   r‚   r  )r”   Úrenderr–   r7   r  )r7   Údepth_coloredÚnormal_openglÚnormal_directxr«   )r   rW   r›   rY   rX   r™   r]   r^   s   &r   r`   ÚMoGeRender.define_schema  sp   € ä�yŠyØ ÚLØ/ØMØ0ä×"Ñ" ?Ó3Ü—‘—‘˜xÒ1vð  AHð ~ð ó ðô
 —X‘X—_‘_Ó&Ð'ô
ð 	
r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rc   rd   )r   rf   s   "€r   r   ÚMoGeRender.__annotate__#  s   ø€ ÷ ,%ñ ,%©r¯}©}ñ ,%r   c           	     ó  € VR9   pVP                  R4      pVR9   d   RV9  d   \        R4      hVR,          pMfV'       d.   RV9   d   VR,          pMMRV9   d   VR,          pM<\        R4      hVR8X  d   RV9  d   \        R	4      hVR,          pM\        R
V 24      hVP                  ^ ,          p\        P                  P                  V4      p. p\        VRV 2R7      ;_uu_ 4       p	\        V4       EFz  p
WZV
^,            P                  4       pVR9   dj   \        V4      pTP                  VR8X  d   \        V4      M;VP                  R4      P                  ! . VP                  O^N5!  P                  4       4       MÄV'       dk   RV9   d   TM
\        V4      pV'       d   RMRpWÝP!                  RVR.4      ,          pVP                  VR,          R,           P#                  RR4      4       MRVR8X  dL   VP                  VP                  R4      P                  ! . VP                  O^N5!  P                  4       4       VP%                  V
^,           4       V	P'                  ^4       EK}  	  RRR4       \(        P*                  ! V^ R7      P-                  \        P.                  P1                  4       \        P.                  P3                  4       R7      p\4        P6                  ! V4      #   + '       g   i     L‡; i)r"  Ú_openglr7   r   z"moge_geometry has no depth output.r  r   zDmoge_geometry has neither normals nor points to derive normals from.r«   z!moge_geometry has no mask output.zUnknown output mode: zMoGe render: r¤   r9   ç      à?r:   Nr   r¡   )r"  r!  )r7   r   r    ç      ð¿)ÚendswithrÌ   r<   rk   rl   rÚ   r   r;   rÞ   rK   rÔ   Ú_turbor(   Úexpandr  r5   Ú
new_tensorr@   r®   r¯   r   r  rÓ   rÎ   Úintermediate_deviceÚintermediate_dtyper   re   )r_   r�   r  Ú	is_normalÚopenglÚsrcr  r±   rA   r²   rB   ÚslcrC   r4   Úy_signrö   s   &&&             r   rp   ÚMoGeRender.execute"  s‰  € àÐAÑAˆ	Ø—‘ Ó+ˆð Ð/Ô/Ø˜mÔ+Ü Ð!EÓFÐFØ Õ(‰CßØ˜=Ô(Ø# HÕ-‘Ø˜]Ô*Ø# HÕ-‘ä Ð!gÓhÐhØ�vÔØ˜]Ô*Ü Ð!DÓEÐEØ Õ'‰CäÐ4°V°HÐ=Ó>Ð>à�I‰I�a�LˆÜ�{‰{×&Ñ& qÓ)ˆØ"$ˆÜ˜ -°¨xÐ 8×9Õ9¸RÜ˜1—X�Ø˜A �E�l×(Ñ(Ó*�ØÐ7Ô7Ü,¨SÓ1�AØ—J‘J¨F°oÔ,Eœv aœyØ$%§K¡K°£O×$:Ò$:Ð$G¸A¿G¹GÐ$GÀQÓ$G×$RÑ$RÓ$TõVçØ'¨=Ô8™Ô>RÐSVÓ>W�Aç%+™T°�FØŸL™L¨#¨v°tÐ)<Ó=Õ=�AØ—J‘J  C¥¨#¥×4Ñ4°S¸#Ó>Õ?Ø˜vÔ%Ø—J‘J˜sŸ}™}¨RÓ0×7Ò7ÐF¸¿¹ÐFÀAÓF×QÑQÓSÔTØ×$Ñ$ Q¨¥UÔ+Ø—	‘	˜!—ñ ÷ :ô" —’˜3 AÔ&×)Ñ)´×1GÑ1G×1[Ñ1[Ó1]Ôej×e{Ñe{÷  fOñ  fOó  fQÐ)ó  RˆÜ�}Š}˜VÓ$Ð$÷% :×9ús   Ã,B K6ÆK6Æ)CK6Ë6L	rr   Nrü   r{   s   @r   r  r    s.   ø‡ € ÙEàñ
ó ð
ð ÷,%ó ö,%r   r  c                   óP   a € ] tR tRt o Rt]R 4       t]V 3R lR l4       tRtV t	R# )ÚMoGePointMapToMeshiR  zLTriangulate one image of a MoGe point map into a Types.MESH (UVs + texture).c                ó¸  € \         P                  ! R . RORRR\        P                  R4      \         P                  P                  R^ ^ RRR7      \         P                  P                  R	^^^R
R7      \         P
                  P                  RRRRRRR7      \         P                  P                  RRRR7      .\         P                  P                  4       .R7      # )r7  zConvert MoGe Point Map to Meshz(Convert a MoGe point map into a 3D mesh.r   r�   Úbatch_indexi   zWhich image of a batched MoGe geometry to mesh. Per-image vertex counts differ, so batches can't be stacked into a single MESH.r„   Ú
decimationz#Vertex stride; 1 = full resolution.Údiscontinuity_thresholdg{®Gáz¤?r:   r9   g{®Gáz„?z@Drop pixels whose 3x3 depth span exceeds this fraction. 0 = off.)r…   r†   r‡   r  r‚   ÚtextureTz8Carry the source image through as the baseColor texture.)r…   r‚   r  )r”   Úmeshr–   z	point map)	r   rW   r›   rY   rš   r  r  ÚMeshr]   r^   s   &r   r`   Ú MoGePointMapToMesh.define_schemaU  sÔ   € ä�yŠyØ(ÚDØ9ØBØ0ä×"Ñ" ?Ó3Ü—‘—‘˜]°A¸1À$ð&_ð ó `ô —‘—‘˜\°1¸!ÀØ%Jð ó Lä—‘—‘Ð8À$ÈCÐUXÐ_cØ'ið ó kä—
‘
× Ñ  °DØ)cð !ó eðô —W‘W—^‘^Ó%Ð&ô%
ð 	
r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rc   rd   )r   rf   s   "€r   r   ÚMoGePointMapToMesh.__annotate__m  s   ø€ ÷ !#ñ !#Ñbd×boÑboñ !#r   c                ó(  € R V9  d   \        R4      hVR ,          pVP                  ^ ,          pW'8¼  d   \        RV RV R24      hRV9   d   VR,          V,          MRp\        Wb,          VWHR7      w  ršpV	P                  ^ ,          ^ 8X  g   V
P                  ^ ,          ^ 8X  d   \        R4      hR	V9  d   V	R
. RO3,          P                  4       p	MFV	\        P
                  ! . ROV	P                  R7      ,          p	V
R
. RO3,          P                  4       p
V'       d   VR,          W"^,            MRp\        P                  ! V	P                  ^ 4      V
P                  ^ 4      VP                  ^ 4      VR7      p\        P                  ! V4      # )r   z#moge_geometry has no points output.zbatch_index z, out of range; moge_geometry has batch size Ú.r7   N)r:  r;  r7   zOMoGe produced an empty mesh; try discontinuity_threshold=0 or apply_mask=False.ré   r   )r£   r�   )ÚverticesÚfacesÚuvsr<  )r#   r   r$   )r9   r)  r)  )r$   r   r#   )rÌ   r<   r   r  r   Útensorr£   r   ÚMESHr(   r   re   )r_   r�   r9  r:  r;  r<  r   r  Ú
edge_depthÚvertsrE  rF  Útexr=  s   &&&&&&        r   rp   ÚMoGePointMapToMesh.executel  sd  € à˜=Ô(ÜÐBÓCÐCØ˜xÕ(ˆØ�L‰L˜�OˆØÔÜ˜|¨K¨=Ð8dÐefÐdgÐghÐiÓjÐjð =DÀ}Ô<T�] 7Õ+¨KÖ8ÐZ^ˆ
Ü1ØÕ¨JØ$;ô
Ñˆ�cð �;‰;�q�>˜QÔ %§+¡+¨a¥.°AÔ"5ÜÐnÓoÐoà˜}Ô,à˜!šY˜,Õ'×2Ñ2Ó4‰Eð œEŸLšLÒ):À%Ç+Á+ÔNÕNˆEØ˜!šY˜,Õ'×2Ñ2Ó4ˆEçELˆm˜GÕ$ [¸qµÑAÐRVˆÜ�zŠzØ—_‘_ QÓ'Ø—/‘/ !Ó$Ø—‘˜aÓ Øô	
ˆô �}Š}˜TÓ"Ð"r   rr   Nrü   r{   s   @r   r7  r7  R  s.   ø‡ € ÙVàñ
ó ð
ð, ÷!#ó ö!#r   r7  c                   óP   a € ] tR tRt o Rt]R 4       t]V 3R lR l4       tRtV t	R# )ÚMoGeGeometryToFOVi‘  z[Extract horizontal/vertical FOV from MoGe intrinsics, e.g. fov_y to feed SAM3DBody_Predict.c                ót  € \         P                  ! R . RORRR\        P                  R4      \         P                  P                  R. RORRR	7      \         P                  P                  R
RR.RRR	7      .\         P
                  P                  RR7      \         P
                  P                  RR7      .R7      # )rN  r  zGet FoV from MoGe Geometryz?Derive the field of view and focal length from MoGe intrinsics.r   r�   ÚaxisÚverticalz8'vertical' (fov_y), 'horizontal' (fov_x), or 'diagonal'.r  ÚunitÚdegreesÚradianszOutput unit for the FOV.r‘   Úfocal_pixelsr  )r”   r  r–   ré   zfield of view)rQ  Ú
horizontalÚdiagonal)r   rW   r›   rY   rX   r  r]   r^   s   &r   r`   ÚMoGeGeometryToFOV.define_schema”  s¥   € ä�yŠyØ'ÚUØ5ØYØ0ä×"Ñ" ?Ó3Ü—‘—‘˜vÒ/UÐ_iØ'að ó cä—‘—‘˜v°	¸9Ð/EÈyØ'Að ó Cð	ô —‘—‘¨U�Ó3Ü—‘—‘¨^�Ó<ðô
ð 	
r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# rc   rd   )r   rf   s   "€r   r   ÚMoGeGeometryToFOV.__annotate__ª  s   ø€ ÷ 0ñ 0±2·=±=ñ 0r   c           	     óþ  a€ \        S\        4      '       d   SP                  R 4      MRpVf   \        R4      hVP                  ^8X  d
   V^ ,          pR\        VR,          P                  4       4      ,          pR\        VR,          P                  4       4      ,          pRVRVR\        P                  ! WV4      /V,          pR\        P                  ! V4      ,          pVR8X  d   TM\        P                  ! V4      p	\        V3R	 lR 4       R4      p
V
f   \        R
4      h\        V
P                  ^,          4      p\        VR,          P                  4       4      V,          p\        P                  ! Wœ4      # )ré   Nz=moge_geometry has no intrinsics (panorama geometry has none).r(  rV  rQ  rW  g       @rT  c              3   óF   <"  € T F  qS9   g   K  SV,          x € K  	  R # 5i©Nrr   )Ú.0Úkr�   s   & €r   Ú	<genexpr>Ú,MoGeGeometryToFOV.execute.<locals>.<genexpr>¸  s$   øé € ÐaÑ.J¨ÐS`ÑN`Ô$�M !×$Ò$Ó.Jùs   ƒ!�!zFmoge_geometry has no image/points/depth to read the pixel height from.)r$   r$   )r#   r#   )r�   r   r7   )Ú
isinstanceÚdictÚgetrÌ   ÚndimrÞ   ÚitemÚmathÚhypotÚatanrS  ÚnextrÍ   r<   r   re   )r_   r�   rP  rR  ÚKÚhxÚhyÚhalf_tanÚfov_radiansr  r2  rä   rU  s   &f&&         r   rp   ÚMoGeGeometryToFOV.execute©  s%  ø€ ä/9¸-Ì×/NÒ/NˆM×Ñ˜lÔ+ÐTXˆØŠ9ÜÐ\Ó]Ð]Ø�6‰6�QŒ;Ø�!•ˆAð ”5˜˜4�Ÿ™›Ó(Õ(ˆØ”5˜˜4�Ÿ™›Ó(Õ(ˆØ  " j°"°jÄ$Ç*Â*ÈRÓBTÐUÐVZÕ[ˆØœDŸIšI hÓ/Õ/ˆØ! YÔ.‰k´D·L²LÀÓ4MˆäÔaÑ.JÓaÐcgÓhˆØŠ;ÜÐeÓfÐfÜ�—	‘	˜!•ÓˆÜ˜Q˜t�WŸ\™\›^Ó,¨qÕ0ˆÜ�}Š}˜SÓ/Ð/r   rr   Nrü   r{   s   @r   rN  rN  ‘  s.   ø‡ € Ùeàñ
ó ð
ð( ÷0ó ö0r   rN  c                   ó<   a € ] tR tRt o ]V 3R lR l4       tRtV tR# )ÚMoGeExtensioniÀ  c                óT   <€ V ^8„  d   QhRS[ S[S[P                  ,          ,          /# rc   )rÝ   Útyper   Ú	ComfyNode)r   rf   s   "€r   r   ÚMoGeExtension.__annotate__Â  s%   ø€ ÷ xñ x¡T©$©r¯|©|Õ*<Õ%=ñ xr   c              ƒ  óJ   "  € \         \        \        \        \        \
        .# 5ir]  )rM   rÿ   r}   r  r7  rN  )Úselfs   &r   Úget_node_listÚMoGeExtension.get_node_listÁ  s   é € äœ}Ô.CÄZÔQcÔevÐwÐwùs   ‚!#rr   N)rt   ru   rv   rw   r   ry  ry   rz   r{   s   @r   rr  rr  À  s   ø‡ € Ø÷xó öxr   rr  c                ó$   € V ^8„  d   QhR\         /# rc   ©rr  )r   s   "r   r   r   Æ  s   € ÷ ñ ¤ñ r   c               ƒ   ó   "  € \        4       # 5ir]  r|  rr   r   r   Úcomfy_entrypointr~  Æ  s   é € Ü‹?Ðùs   ‚)*rý   r   rg  Úcomfy.utilsrk   rZ   Úcomfy_api.latestr   r   r   Útyping_extensionsr   Úcomfy.ldm.colormapr   r+  Úcomfy.ldm.moge.modelr   Úcomfy.ldm.moge.geometryr   Úcomfy.ldm.moge.panoramar	   r
   r   r   r   Úcomfy.model_managementÚ	tqdm.autor   ÚCustomr\   r›   r5   rK   ru  rM   r}   rÿ   r  r7  rN  rr  r~  rr   r   r   Ú<module>r‰     sÝ   ðÙ Tó Û ã Û ß 6Ñ 6Ý &å .Ý *Ý 9÷ Kõ  KÛ Ý à—	’	˜,Ó'€Ø�yŠy˜Ó)€õEõô$,�B—L‘Lô ,ô(~,˜BŸL™Lô ~,ôB7,�B—L‘Lô 7,ôt@%�—‘ô @%ôF<#˜Ÿ™ô <#ô~,0˜Ÿ™ô ,0ô^x�Nô x÷r   