
    Hj
0                        d Z ddlZddlZddlZddlmZ ej                  j                  d e ee	      j                               ddlZddlZej                  dz  ZdZddddd	idd	idd	id	d
dddidd	iddidd	dgidg dddddddd	idd	idd	idg dddddddgddZd ZdedefdZdZdefdZdZdefdZd  Zdefd!Zd"ed#efd$Zd% Zed&k(  r e        yy)'u%  s2 — 실내 체인: I0 계획 → I1 탑레이어 → I2 fp변형 → 임시샷 → A/B/C 경로 → 최종.

사용: .venv/bin/python s2_indoor.py [--only plan|toplayer|fpvar|temp|paths]
                                    [--alpha-shot 첫샷 임시배경 α 변형] [--mannequin-preview]
    N)Pathindooru  You are the background production planner for the INDOOR shots of one
real-world place. You are given: the place's aerial-sketch element plan (the spatial
root contract), the indoor floor plan identifiers available, and the FULL content of
every indoor shot.

Plan the background generation like a set photographer:
1. For each shot, state what background it needs (which part of the indoor space,
   from roughly what direction).
2. Merge those needs into AT MOST TWO "top-layer" master backgrounds — wide, clean,
   empty-room views that together cover all the shots. Prefer ONE if the space is
   small enough to read in a single wide view.
3. Give the generation order. If there are two, the second must chain on the first
   (same dwelling, same materials).
4. For each top-layer, judge whether attaching the floor plan image as a reference
   would help (geometry anchoring) or hurt (style leakage), and say why.
Ground every statement in the given data only; do not invent rooms or furniture.
Use generic physical terms, no proper names.objectarraytypestringzFwhat the master background shows, phrased as an empty-room camera view)r   descriptionbooleanintegernull)keyloc_idpurposeview_description	attach_fpattach_fp_reasonorderchain_prev_keyF)r   
propertiesrequiredadditionalProperties)r   items)shot_keytop_layer_keyneeded_background)
top_layersshot_assignmentsr   r   c                    | d   j                         D ci c]  \  }}|d   s|| }}}dj                  d | d   j                         D              }dt        j                  | d         z   dz   t	        j
                  |d	
      z   dz   |z   dz   dj                  d t        |j                               D              z   dz   }t        j                  dt        |t        d      }t        j                  d|       t        dt        |d          dt        |d          d       |d   D ]+  }t        d|d    d|d    d|d    d|d     d!|d"    
       - |S c c}}w )#Nshots	is_indoor
c              3   ^   K   | ]%  \  }}d | ddj                  d |D                ' yw)z- loc z: floor plan(s) z, c              3   &   K   | ]	  }|d      yw)fp_idN ).0xs     s2_indoor.py	<genexpr>z$i0_plan.<locals>.<genexpr>.<genexpr>E   s     /HCq'
Cs   N)join)r&   locfpss      r(   r)   zi0_plan.<locals>.<genexpr>D   s:      42HC %dii/HC/H&H%IJ2s   +-	fp_by_loczPLACE MEMBERS:
membersz'

AERIAL ROOT CONTRACT (element plan):
Fensure_asciiz

AVAILABLE FLOOR PLANS:
z

ALL INDOOR SHOTS:

z

c              3   N   K   | ]  \  }}t        j                  ||        y w)N)F
shot_block)r&   kvs      r(   r)   zi0_plan.<locals>.<genexpr>M   s"     R5QTQall1a(5Qs   #%z%

Plan the top-layer backgrounds now.forest_indoor_plangpt)modelindoor_planzI0: r   z top layers; r   z shot assignmentsz  [r   z] r   z loc=r   z attach_fp=r   z chain=r   )r   r*   r2   members_blockjsondumpssortedllm	I0_SYSTEM	I0_SCHEMA	save_planprintlen)	recon	root_planr4   r5   indoor_shotsfp_linesuserplantls	            r(   i0_planrK   B   s   %*7^%9%9%;N%;TQq~AqD%;LNyy 4k*0024 4H 	Q__U9-=>>
6	7
**YU
3	4 )	) ,4	4 &		&
 ++RVL<N<N<P5QR
R	S 4	4 	 55%y$	ODKKt$	DT,'()()*++<> ?< BwK=2e9+U2h<. Ak?+726F3G2HJ 	K ! K) Os
   EEchainedreturnc                    t        fd| d   D        i       }ddddd|j                  d       d	|j                  d
       dd    dd    ddt        |j                  dd            g
}|r|g dz  }dj                  |      S )Nc              3   :   K   | ]  }|d    d    k(  s|  yw)r   Nr%   )r&   mrJ   s     r(   r)   z#top_layer_prompt.<locals>.<genexpr>[   s#     K+aq{bl/J+s   r.   zECreate ONE photorealistic EMPTY interior master background plate of auI   real dwelling interior — a wide, clean view with NO people, no text, noz8markers. Real-world human scale (doorways adult height). z"THE PLACE (from production data): labelz: summaryzTHIS PLATE'S PURPOSE: r   z
THE VIEW: r   z5Site orientation notes from the aerial root contract:sketch_notes)rQ   uC   The LAST attached image shows ANOTHER part of THE SAME dwelling —zBmatch its wall colours, floor material, trim, door style, lightingzAmood and renovation age EXACTLY so both read as the same home. Doz)NOT copy its camera angle or composition.r!   )nextgetstrr*   )rD   rJ   rE   rL   r+   liness    `    r(   top_layer_promptrY   Z   s    
K5+KR
PCOSB

,SWWW-=,>bAS@TU
 I0
R*+,-
?IMM."-.E  
 	
 99U    u   

The FIRST attached image is the TOP-DOWN floor plan of this dwelling — use it ONLY to get the room geometry, openings and furniture positions right. NEVER copy its drawing style, numbered circles or any marks into the photorealistic output.force_abc           
         d }t        |d   d       }t        |      D ]_  \  }}| d   j                  |d         xs g }|r|d   d   nd }	t        |j                  d            xr |d u}
t	        | |||
      }g }t        |j                  d	            xr |	}|r|t
        z   }|j                  |	       n|}|
r|j                  |       t        dz  |d
    dz  }t        j                  d|d
    ||xs d d|       |}|s|dk(  s|	s|s;t        j                  d|d
    d|t
        z   |	gdt        dz  |d
    dz         /t        j                  d|d
    d|d dt        dz  |d
    dz         b y )Nr   c                     | d   S Nr   r%   ts    r(   <lambda>zi1_top_layers.<locals>.<lambda>}   s    qzrZ   r   r-   r   r   png_pathr   r   r   .pngtop_	1536x1024refssizeout_path_fpONz	_fpON.png_fpOFFz
_fpOFF.png)
r=   	enumeraterV   boolrY   	FP_CLAUSEappendOUTDIRr2   img_gpt)rD   rI   rE   r[   prev_pngorderedidxrJ   fp_listfp_pngrL   promptrh   use_fpprompt_fullouts                   r(   i1_top_layersr|   {   s   HT,'-ABGW%R$((H6<"+2J'rvv./0IXT5I!%Y@bff[)*5v 9,KKK KKK!|#E4&88			DE$k"S	2 qV		DE516I3E &xk#)L#8bi[	;R#RT 		DE62F*#)L#8bi[
;S#SU5 &rZ   u7  The attached image is a TOP-DOWN floor plan of one dwelling: numbered circles mark fixed rooms and furniture. Keep the plan EXACTLY as it is — same walls, rooms, furniture and numbered circles, do not redraw or restyle anything.
ADD exactly these annotations for ONE camera setup:
- ONE green camera icon with a green triangular view-CONE showing where the camera stands and what it looks at, following this staging description:
{cam}
{figures}Add NOTHING else — no new rooms, no new furniture, no text other than the existing numbers and the new capital letters.c                    | j                  d      xs i }|j                  d      xs i j                  d      xs g }t        d |D              }|dk  rt        |j                  d      xs g       }|dk  rydj                  d	 t	        |      D              }d
| d| ddj                  d |j                  d      xs g D              z   dz   S )Nstagingframe_spatial_contractconstraintsc              3   j   K   | ]+  }t        |t              s|j                  d       dk(  rd - yw)target_kind	character   N)
isinstancedictrV   )r&   cs     r(   r)   z!figures_clause.<locals>.<genexpr>   s0      5t!z!T2m$3 ts   33r   character_anglesu7   - This shot has NO people — add no lettered circles.
 c              3   @   K   | ]  }d t        d|z          d  yw)(A   )N)chr)r&   is     r(   r)   z!figures_clause.<locals>.<genexpr>   s"     <8a3rAv;-q)8s   z- z$ red circle(s) with capital letters z; inside the view-cone where the staging places the people:
r!   c              3   P   K   | ]  }d t        j                  |d      z      yw)z  * Fr/   N)r;   r<   )r&   cas     r(   r)   z!figures_clause.<locals>.<genexpr>   s)      F#CB BU!CC#Cs   $&)rV   sumrC   r*   range)sstconsnletterss        r(   figures_clauser      s    	
y		RBVV,-388GM2D 5t 5 	5AAv)*0b1AvIhh<58<<G7y A@ Aii F#%66*<#=#C#CF FF IMM NrZ   c                 z   | d   |   }|d   d   }| d   j                  |      xs g }|st        d| d|       t        |j                  d      xs i j                  d      xs d	      }t        j	                  |t        |      
      }t        |z  dz  }t        j                  | d||d   d   gd|      S )Nr   loc_idsr   r-   zno fp for indoor shot z loc r~   camera_directionrQ   )camfigures	fpvar.png_fpvarrc   	1024x1024rg   )	rV   
SystemExitrW   BLOCKING_PROMPTformatr   rq   r2   rr   )rD   skr   r+   rv   r   rx   r{   s           r(   i2_fpvarr      s    grA
I,q/CK $$S)/RG1"U3%@AA
quuY%2**+=>D"
EC##^A5F#GF
2+
#C99t6]F'!*Z2H1I%5 5rZ   c                 b    | d   D ]  }|d   |k(  s|d   c S  t        | d   d       d   d   S )	Nr   r   r   r   c                     | d   S r^   r%   r_   s    r(   ra   zassigned_top.<locals>.<lambda>   s    AgJrZ   rb   r   r   )r=   )rI   r   as      r(   assigned_topr      sH    $%Z=B_%% & $|$*>?B5IIrZ   alphamannequin_previewc                    | d   |   }t         |z  }t        ||      }t         dz  | dz  }|dz  }	t        j                  | |      }
t        j                  | d|||	|dz        }|rdj                  dd	d
dddt        j                  |      t        j                  |      g      }t        j                  | d||	|g|dz        }t        j                  | d|||	|dz         t        j                  | d|||
|dz  |	       t        j                  ||      }t        j                  | d|||dz  |      }t        j                  | d|||
|dz         t        j                  | d||dz        }t        j                  | d|||dz  |      }t        j                  | d |||
|d!z         |rAt        j                  | d"|||d#z  |d$%      }t        j                  | d&|||
|d'z         y y )(Nr   r   rd   r   _tempztemp.pngr!   z?Create the photorealistic EMPTY interior background seen by thezAcamera marked on the attached top-down diagram (green icon+cone),zCat eye level, real-world scale. Use the other attached image as thezBmaterial/lighting ground truth of the same dwelling. NO people, noztext, no markers.rQ   _tempbgztemp_bg.png)rh   rj   _temp_alphaztemp_alpha.png_final_Azfinal_A.png)control_png_bgBzbg_B.png)comp_final_Bzfinal_B.png_contourzcontour.png_bgCzbg_C.png)contour_png_final_Czfinal_C.png_bgC_mz
bg_C_m.pngT)r   	mannequin
_final_C_mzfinal_C_m.png)rq   r   Cpassports_for_shot	temp_shotr*   shot_content_linesstaging_linesr2   rr   
final_shotvlm_compositionbg_regencontour)rD   rI   r   r   r   r   dtop_keyenvfpvar	passportstemp	tb_prompttbr   bg_bcontbg_cbg_cms                      r(   run_shotr      s$   grAA4$G
<
WIT"2
2COE$$UA.I ;;"U|QUA
NCDIIMOQP$$Q');
 	 YY"W~ys| !M 13	rd+&2ua:J6JK LLB4x!S)Q5F"$ R&D::Dk1c1z>EDLLB4x!T9a-6GH99t8_dA,=>D::Dk1c1z>tLDLLB4x!T9a-6GH

bT=!S!l2B'+t=	t:&5)Q=PQ rZ   c            	         t        j                         } | j                  ddg d       | j                  dd       | j                         }t	        j
                         }t	        j                  d      }t	        j                  d	      d
   }|j                  dv rt        ||      }nt	        j                  d      }|j                  dv rt        ||||j                          |j                  dv rDt        |      D ]6  \  }}t        ||       |j                  dv s!t        ||||dk(  |dk(         8 t	        j                  dd|j                  |d       y )Nz--onlyall)r   rI   toplayerr   r   paths)defaultchoicesz--no-force-ab
store_true)actionrE   subsetr   )r   rI   r9   )r   r   )r[   )r   r   r   r   )r   r   r   r   )r   r   stage	s2_indoor)kindr   doner   )argparseArgumentParseradd_argument
parse_argsr2   
load_recon	load_planonlyrK   r|   no_force_abrm   r   r   runlog)apargsrD   rE   r   rI   r   r   s           r(   mainr      s,   		 	 	"BOOHeQ  SOOOLO9==?DLLNEK(I[["8,FyyO#ui({{=)yy''eT94;K;K7KLyy55v&EArUByy44ba,-F5 '
 HHgTYY  !rZ   __main__)__doc__r   r;   syspathlibr   pathinsertrW   __file__parent
forest_libr2   forest_chainr   OUTrq   r?   r@   rK   rn   rY   ro   r|   r   r   r   r   r   r   __name__r%   rZ   r(   <module>r      s  
   
  3tH~,,- .  	
	0	& &(H%x())11W!X !),!' 2i(%&'9:
S<+ %*2+ , &-#X."((!3&,h%79 K$)8+ ,!0 12!7	>0D S 4" 
UD UF	5 N N 
5Jc J'RT 'Rd 'RT!4 zF rZ   