o
    äeQ  ã                
   @  s¬   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlmZmZ dd	lmZmZmZmZ ed
ƒ eƒ G dd„ deeeeeeƒƒZdS )zgr.Model3D() component.é    )Úannotations)ÚPath)ÚAnyÚCallableÚLiteral)Ú
media_data)ÚdocumentÚset_documentation_group)ÚFileSerializable)ÚIOComponentÚ	_Keywords)Ú
ChangeableÚ	ClearableÚEditableÚ
UploadableÚ	componentc                   @  s”   e Zd ZdZ	d9ddddddddddddddœd:d!d"„Zd#d$„ Zd;d'd(„Zeej	ddddddddddfd<d+d,„ƒZ
d=d/d0„Zd>d3d4„Zd?d7d8„ZdS )@ÚModel3DaV  
    Component allows users to upload or view 3D Model files (.obj, .glb, or .gltf).
    Preprocessing: This component passes the uploaded file as a {str}filepath.
    Postprocessing: expects function to return a {str} or {pathlib.Path} filepath of type (.obj, glb, or .gltf)

    Demos: model3D
    Guides: how-to-use-3D-model-component
    N)NNNé   Té    )Úclear_colorÚcamera_positionÚ
zoom_speedÚheightÚlabelÚ
show_labelÚeveryÚ	containerÚscaleÚ	min_widthÚvisibleÚelem_idÚelem_classesÚvalueústr | Callable | Noner   ú(tuple[float, float, float, float] | Noner   úAtuple[int | float | None, int | float | None, int | float | None]r   Úfloatr   ú
int | Noner   ú
str | Noner   úbool | Noner   úfloat | Noner   Úboolr   r   Úintr   r    r!   úlist[str] | str | Nonec                K  sL   |pg d¢| _ || _|| _|| _tj| f||||	|
|||||dœ
|¤Ž dS )a'	  
        Parameters:
            value: path to (.obj, glb, or .gltf) file to show in model3D viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.
            clear_color: background color of scene, should be a tuple of 4 floats between 0 and 1 representing RGBA values.
            camera_position: initial camera position of scene, provided as a tuple of `(alpha, beta, radius)`. Each value is optional. If provided, `alpha` and `beta` should be in degrees reflecting the angular position along the longitudinal and latitudinal axes, respectively. Radius corresponds to the distance from the center of the object to the camera.
            zoom_speed: the speed of zooming in and out of the scene when the cursor wheel is rotated or when screen is pinched on a mobile device. Should be a positive float, increase this value to make zooming faster, decrease to make it slower. Affects the wheelPrecision property of the camera.
            height: height of the model3D component, in pixels.
            label: component name in interface.
            show_label: if True, will display label.
            every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
            visible: If False, component will be hidden.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
        )r   r   r   r   )
r   r   r   r   r   r   r   r    r!   r"   N)r   r   r   r   r   Ú__init__)Úselfr"   r   r   r   r   r   r   r   r   r   r   r   r    r!   Úkwargs© r1   úID:\Projects\ConvertPro\env\Lib\site-packages\gradio/components/model3d.pyr.   $   s(   *ÿõ
ôzModel3D.__init__c                 C  s$   | j | j| j| j| jdœt | ¡¥S )N)r   r"   r   r   r   )r   r"   r   r   r   r   Ú
get_config©r/   r1   r1   r2   r3   b   s   ûúzModel3D.get_configÚreturnúdict[str, Any]c                 C  s   dt jdœddœS )NF)Úis_fileÚdatazFhttps://github.com/gradio-app/gradio/raw/main/test/test_files/Box.gltf)ÚrawZ
serialized)r   ZBASE64_MODEL3Dr4   r1   r1   r2   Úexample_inputsl   s   
þzModel3D.example_inputsú(Any | Literal[_Keywords.NO_VALUE] | NoneúHtuple[int | float | None, int | float | None, int | float | None] | Nonec                 C  s"   |||||||||	|
| ddœ}|S )NÚupdate)r   r   r   r   r   r   r   r   r   r   r"   Z__type__r1   )r"   r   r   r   r   r   r   r   r   r   r   Zupdated_configr1   r1   r2   r=   r   s   ôzModel3D.updateÚxúdict[str, str] | Nonec                 C  sN   |du r|S |d |d |  dd¡}}}|r|  |¡}|S |  ||¡}|S )zÔ
        Parameters:
            x: JSON object with filename as 'name' property and base64 data as 'data' property
        Returns:
            string file path to temporary file with the 3D image model
        NÚnamer8   r7   F)ÚgetÚmake_temp_copy_if_neededZbase64_to_temp_file_if_needed)r/   r>   Ú	file_nameÚ	file_datar7   Ztemp_file_pathr1   r1   r2   Ú
preprocess“   s   

ý
þzModel3D.preprocessÚyústr | Path | Nonec                 C  s"   |du r|S |   |¡dddœ}|S )z
        Parameters:
            y: path to the model
        Returns:
            file name mapped to base64 url data
        NT)r@   r8   r7   )rB   )r/   rF   r8   r1   r1   r2   Úpostprocess¨   s   ýzModel3D.postprocessÚ
input_dataÚstrc                 C  s   |rt |ƒjS dS )NÚ )r   r@   )r/   rI   r1   r1   r2   Ú
as_example¸   s   zModel3D.as_example)N)r"   r#   r   r$   r   r%   r   r&   r   r'   r   r(   r   r)   r   r*   r   r+   r   r'   r   r,   r   r+   r    r(   r!   r-   )r5   r6   )r"   r;   r   r<   r   r$   r   r'   r   r*   r   r(   r   r)   r   r)   r   r'   r   r'   r   r)   )r>   r?   r5   r(   )rF   rG   r5   r?   )rI   r(   r5   rJ   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r.   r3   r:   Ústaticmethodr   ZNO_VALUEr=   rE   rH   rL   r1   r1   r1   r2   r      sH    þê>

ò
 
r   N)rP   Ú
__future__r   Úpathlibr   Útypingr   r   r   Zgradio_clientr   Zgradio_client.documentationr   r	   Zgradio_client.serializingr
   Zgradio.components.baser   r   Zgradio.eventsr   r   r   r   r   r1   r1   r1   r2   Ú<module>   s    

ÿ