Skip to content
Snippets Groups Projects
__init__.py 74.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • Vilem Duha's avatar
    Vilem Duha committed
                ("IMAGE", "Texture paint", "Texture brush"),
                ("SCULPT", "Sculpt", "Sculpt brush"),
                ("VERTEX", "Vertex paint", "Vertex paint brush"),
                ("WEIGHT", "Weight paint", "Weight paint brush"),
    
    Vilem Duha's avatar
    Vilem Duha committed
            ),
            description="Mode where the brush works",
            default="SCULPT",
        )
    
    
    # upload properties
    class BlenderKitModelUploadProps(PropertyGroup, BlenderKitCommonUploadProps):
        style: EnumProperty(
            name="Style",
            items=model_styles,
            description="Style of asset",
            default="REALISTIC",
        )
        style_other: StringProperty(
            name="Style Other",
            description="Style not in the list",
            default="",
        )
        engine: EnumProperty(
            name='Engine',
            items=engines,
            default='CYCLES',
            description='Output engine',
        )
    
        production_level: EnumProperty(
            name='Production Level',
            items=(
                ('FINISHED', 'Finished', 'Render or animation ready asset'),
                ('TEMPLATE', 'Template', 'Asset intended to help in creation of something else'),
            ),
            default='FINISHED',
    
    Vilém Duha's avatar
    Vilém Duha committed
            description='Production state of the asset. \n'
                        'Templates should be tools to finish certain tasks, like a thumbnailer scene, \n '
                        'finished mesh topology as start for modelling or others',
    
    Vilem Duha's avatar
    Vilem Duha committed
        )
    
        engine_other: StringProperty(
            name="Engine",
            description="engine not specified by addon",
            default="",
        )
    
        engine1: EnumProperty(
            name='2nd Engine',
            items=engines,
            default='NONE',
            description='Output engine',
        )
        engine2: EnumProperty(
            name='3rd Engine',
            items=engines,
            default='NONE',
            description='Output engine',
        )
        engine3: EnumProperty(
            name='4th Engine',
            items=engines,
            default='NONE',
            description='Output engine',
        )
    
        manufacturer: StringProperty(
            name="Manufacturer",
    
            description="Manufacturer, company making a design piece or product. Not you",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="",
        )
    
        designer: StringProperty(
            name="Designer",
    
            description="Author of the original design piece depicted. Usually not you",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="",
        )
    
        design_collection: StringProperty(
            name="Design Collection",
    
            description="Fill if this piece is part of a real world design collection",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="",
        )
    
        design_variant: StringProperty(
            name="Variant",
    
            description="Colour or material variant of the product",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="",
        )
    
        thumbnail: StringProperty(
            name="Thumbnail",
    
            description="Thumbnail path - 512x512 .jpg\n"
                        "Rendered with cycles",
    
    
    Vilem Duha's avatar
    Vilem Duha committed
            subtype='FILE_PATH',
            default="",
            update=autothumb.update_upload_model_preview)
    
        thumbnail_background_lightness: FloatProperty(name="Thumbnail Background Lightness",
    
                                                      description="set to make your material stand out", default=1.0,
    
    Vilem Duha's avatar
    Vilem Duha committed
                                                      min=0.01, max=10)
    
        thumbnail_angle: EnumProperty(
            name='Thumbnail Angle',
    
    Vilém Duha's avatar
    Vilém Duha committed
            items=autothumb.thumbnail_angles,
    
    Vilem Duha's avatar
    Vilem Duha committed
            default='DEFAULT',
            description='thumbnailer angle',
        )
    
        thumbnail_snap_to: EnumProperty(
            name='Model Snaps To:',
    
    Vilém Duha's avatar
    Vilém Duha committed
            items=autothumb.thumbnail_snap,
    
    Vilem Duha's avatar
    Vilem Duha committed
            default='GROUND',
            description='typical placing of the interior. Leave on ground for most objects that respect gravity :)',
        )
    
    
        thumbnail_resolution: EnumProperty(
            name="Resolution",
    
    Vilém Duha's avatar
    Vilém Duha committed
            items=autothumb.thumbnail_resolutions,
    
            description="Thumbnail resolution",
    
    Vilem Duha's avatar
    Vilem Duha committed
        thumbnail_samples: IntProperty(name="Cycles Samples",
    
                                       description="cycles samples setting", default=100,
    
    Vilem Duha's avatar
    Vilem Duha committed
                                       min=5, max=5000)
        thumbnail_denoising: BoolProperty(name="Use Denoising",
                                          description="Use denoising", default=True)
    
        use_design_year: BoolProperty(name="Use Design Year",
                                      description="When this thing came into world for the first time\n"
                                                  " e.g. for dinosaur, you set -240 million years ;) ",
                                      default=False)
        design_year: IntProperty(name="Design Year", description="when was this item designed", default=1960)
        # use_age : BoolProperty( name = "use item age", description = "use item age", default = False)
        condition: EnumProperty(
            items=conditions,
            default='UNSPECIFIED',
            description='age of the object',
        )
    
        adult: BoolProperty(name="Adult Content", description="adult content", default=False)
    
        work_hours: FloatProperty(name="Work Hours", description="How long did it take you to finish the asset?",
                                  default=0.0, min=0.0, max=8760)
    
        modifiers: StringProperty(
            name="Modifiers Used",
            description="if you need specific modifiers, autofilled",
            default="",
        )
    
        materials: StringProperty(
            name="Material Names",
            description="names of materials in the file, autofilled",
            default="",
        )
        shaders: StringProperty(
            name="Shaders Used",
            description="shaders used in asset, autofilled",
            default="",
        )
    
        dimensions: FloatVectorProperty(
            name="Dimensions",
            description="dimensions of the whole asset hierarchy",
            default=(0, 0, 0),
        )
        bbox_min: FloatVectorProperty(
            name="Bbox Min",
            description="dimensions of the whole asset hierarchy",
            default=(-.25, -.25, 0),
        )
        bbox_max: FloatVectorProperty(
            name="Bbox Max",
            description="dimensions of the whole asset hierarchy",
            default=(.25, .25, .5),
        )
    
        texture_resolution_min: IntProperty(name="Texture Resolution Min",
                                            description="texture resolution min, autofilled", default=0)
        texture_resolution_max: IntProperty(name="Texture Resolution Max",
                                            description="texture resolution max, autofilled", default=0)
    
        pbr: BoolProperty(name="PBR Compatible", description="Is compatible with PBR standard", default=False)
    
        uv: BoolProperty(name="Has UV", description="has an UV set", default=False)
        # printable_3d : BoolProperty( name = "3d printable", description = "can be 3d printed", default = False)
        animated: BoolProperty(name="Animated", description="is animated", default=False)
        face_count: IntProperty(name="Face count", description="face count, autofilled", default=0)
        face_count_render: IntProperty(name="Render Face Count", description="render face count, autofilled", default=0)
    
        object_count: IntProperty(name="Number of Objects", description="how many objects are in the asset, autofilled",
                                  default=0)
        mesh_poly_type: EnumProperty(
            name='Dominant Poly Type',
            items=mesh_poly_types,
            default='OTHER',
            description='',
        )
    
        manifold: BoolProperty(name="Manifold", description="asset is manifold, autofilled", default=False)
    
        rig: BoolProperty(name="Rig", description="asset is rigged, autofilled", default=False)
        simulation: BoolProperty(name="Simulation", description="asset uses simulation, autofilled", default=False)
        '''
        filepath : StringProperty(
                name="Filepath",
                description="file path",
                default="",
                )
        '''
    
        # THUMBNAIL STATES
        is_generating_thumbnail: BoolProperty(name="Generating Thumbnail",
                                              description="True when background process is running", default=False,
                                              update=autothumb.update_upload_model_preview)
    
        has_autotags: BoolProperty(name="Has Autotagging Done", description="True when autotagging done", default=False)
    
    
    class BlenderKitSceneUploadProps(PropertyGroup, BlenderKitCommonUploadProps):
        style: EnumProperty(
            name="Style",
            items=model_styles,
            description="Style of asset",
            default="REALISTIC",
        )
        style_other: StringProperty(
            name="Style Other",
            description="Style not in the list",
            default="",
        )
        engine: EnumProperty(
            name='Engine',
            items=engines,
            default='CYCLES',
            description='Output engine',
        )
    
        production_level: EnumProperty(
            name='Production Level',
            items=(
                ('FINISHED', 'Finished', 'Render or animation ready asset'),
                ('TEMPLATE', 'Template', 'Asset intended to help in creation of something else'),
            ),
            default='FINISHED',
            description='Production state of the asset, \n also template should be actually finished, \n'
                        'just the nature of it can be a template, like a thumbnailer scene, \n '
    
                        'finished mesh topology as start for modelling or similar',
    
    Vilem Duha's avatar
    Vilem Duha committed
        )
    
        engine_other: StringProperty(
            name="Engine",
            description="engine not specified by addon",
            default="",
        )
    
        engine1: EnumProperty(
            name='2nd Engine',
            items=engines,
            default='NONE',
            description='Output engine',
        )
        engine2: EnumProperty(
            name='3rd Engine',
            items=engines,
            default='NONE',
            description='Output engine',
        )
        engine3: EnumProperty(
            name='4th Engine',
            items=engines,
            default='NONE',
            description='Output engine',
        )
    
        thumbnail: StringProperty(
            name="Thumbnail",
    
            description="Thumbnail path - 512x512 .jpg\n"
                        "Rendered with cycles",
    
    Vilem Duha's avatar
    Vilem Duha committed
            subtype='FILE_PATH',
            default="",
            update=autothumb.update_upload_scene_preview)
    
        use_design_year: BoolProperty(name="Use Design Year",
                                      description="When this thing came into world for the first time\n"
                                                  " e.g. for dinosaur, you set -240 million years ;) ",
                                      default=False)
        design_year: IntProperty(name="Design Year", description="when was this item designed", default=1960)
        # use_age : BoolProperty( name = "use item age", description = "use item age", default = False)
        condition: EnumProperty(
            items=conditions,
            default='UNSPECIFIED',
            description='age of the object',
        )
    
        adult: BoolProperty(name="Adult Content", description="adult content", default=False)
    
        work_hours: FloatProperty(name="Work Hours", description="How long did it take you to finish the asset?",
                                  default=0.0, min=0.0, max=8760)
    
        modifiers: StringProperty(
            name="Modifiers Used",
            description="if you need specific modifiers, autofilled",
            default="",
        )
    
        materials: StringProperty(
            name="Material Names",
            description="names of materials in the file, autofilled",
            default="",
        )
        shaders: StringProperty(
            name="Shaders Used",
            description="shaders used in asset, autofilled",
            default="",
        )
    
        dimensions: FloatVectorProperty(
            name="Dimensions",
            description="dimensions of the whole asset hierarchy",
            default=(0, 0, 0),
        )
        bbox_min: FloatVectorProperty(
            name="Dimensions",
            description="dimensions of the whole asset hierarchy",
            default=(-.25, -.25, 0),
        )
        bbox_max: FloatVectorProperty(
            name="Dimensions",
            description="dimensions of the whole asset hierarchy",
            default=(.25, .25, .5),
        )
    
    
    Vilém Duha's avatar
    Vilém Duha committed
        texture_resolution_min: IntProperty(name="Texture Resolution Min",
    
    Vilem Duha's avatar
    Vilem Duha committed
                                            description="texture resolution min, autofilled", default=0)
    
    Vilém Duha's avatar
    Vilém Duha committed
        texture_resolution_max: IntProperty(name="Texture Resolution Max",
    
    Vilem Duha's avatar
    Vilem Duha committed
                                            description="texture resolution max, autofilled", default=0)
    
        pbr: BoolProperty(name="PBR Compatible", description="Is compatible with PBR standard", default=False)
    
        uv: BoolProperty(name="Has UV", description="has an UV set", default=False)
        # printable_3d : BoolProperty( name = "3d printable", description = "can be 3d printed", default = False)
        animated: BoolProperty(name="Animated", description="is animated", default=False)
        face_count: IntProperty(name="Face Count", description="face count, autofilled", default=0)
        face_count_render: IntProperty(name="Render Face Count", description="render face count, autofilled", default=0)
    
        object_count: IntProperty(name="Number of Objects", description="how many objects are in the asset, autofilled",
                                  default=0)
        mesh_poly_type: EnumProperty(
            name='Dominant Poly Type',
            items=mesh_poly_types,
            default='OTHER',
            description='',
        )
    
        rig: BoolProperty(name="Rig", description="asset is rigged, autofilled", default=False)
        simulation: BoolProperty(name="Simulation", description="asset uses simulation, autofilled", default=False)
    
        # THUMBNAIL STATES
        is_generating_thumbnail: BoolProperty(name="Generating Thumbnail",
                                              description="True when background process is running", default=False,
                                              update=autothumb.update_upload_model_preview)
    
        has_autotags: BoolProperty(name="Has Autotagging Done", description="True when autotagging done", default=False)
    
    
    class BlenderKitModelSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
        search_keywords: StringProperty(
            name="Search",
            description="Search for these keywords",
            default="",
            update=search.search_update
        )
        search_style: EnumProperty(
            name="Style",
            items=search_model_styles,
    
    Vilem Duha's avatar
    Vilem Duha committed
            description="Keywords defining style (realistic, painted, polygonal, other)",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="ANY",
            update=search.search_update
        )
        search_style_other: StringProperty(
            name="Style",
            description="Search style - other",
            default="",
            update=search.search_update
        )
        search_engine: EnumProperty(
            items=engines,
            default='CYCLES',
            description='Output engine',
            update=search.search_update
        )
        search_engine_other: StringProperty(
            name="Engine",
    
    Vilem Duha's avatar
    Vilem Duha committed
            description="Engine not specified by addon",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="",
            update=search.search_update
        )
    
        # CONDITION
        search_condition: EnumProperty(
            items=conditions,
            default='UNSPECIFIED',
    
    Vilem Duha's avatar
    Vilem Duha committed
            description='Condition of the object',
    
    Vilem Duha's avatar
    Vilem Duha committed
            update=search.search_update
        )
    
        search_adult: BoolProperty(
            name="Adult Content",
            description="You're adult and agree with searching adult content",
            default=False,
            update=search.search_update
        )
    
        # DESIGN YEAR
        search_design_year: BoolProperty(name="Sesigned in Year",
    
    Vilém Duha's avatar
    Vilém Duha committed
                                         description="When the object was approximately designed. \n"
                                                     "Useful for search of historical or future objects",
    
    Vilém Duha's avatar
    Vilém Duha committed
                                         default=False,
                                         update=search.search_update,
                                         )
    
        search_design_year_min: IntProperty(name="Minimum Design Year",
                                            description="Minimum design year",
    
    Vilém Duha's avatar
    Vilém Duha committed
                                            default=1950, min=-100000000, max=1000000000,
                                            update=search.search_update,
                                            )
    
        search_design_year_max: IntProperty(name="Maximum Design Year",
                                            description="Maximum design year",
    
    Vilem Duha's avatar
    Vilem Duha committed
                                            default=2017,
                                            min=0,
    
    Vilém Duha's avatar
    Vilém Duha committed
                                            max=10000000,
                                            update=search.search_update,
                                            )
    
    Vilem Duha's avatar
    Vilem Duha committed
    
        # POLYCOUNT
        search_polycount: BoolProperty(name="Use Polycount",
    
    Vilém Duha's avatar
    Vilém Duha committed
                                       description="Limit polycount",
    
    Vilém Duha's avatar
    Vilém Duha committed
                                       default=False,
    
                                       update=search.search_update, )
    
    Vilem Duha's avatar
    Vilem Duha committed
    
        search_polycount_min: IntProperty(name="Min Polycount",
    
    Vilém Duha's avatar
    Vilém Duha committed
                                          description="Minimum poly count",
    
    Vilem Duha's avatar
    Vilem Duha committed
                                          default=0,
                                          min=0,
    
    Vilém Duha's avatar
    Vilém Duha committed
                                          max=100000000,
    
                                          update=search.search_update, )
    
    Vilem Duha's avatar
    Vilem Duha committed
    
        search_polycount_max: IntProperty(name="Max Polycount",
    
    Vilém Duha's avatar
    Vilém Duha committed
                                          description="Maximum poly count",
    
    Vilem Duha's avatar
    Vilem Duha committed
                                          default=100000000,
                                          min=0,
    
    Vilém Duha's avatar
    Vilém Duha committed
                                          max=100000000,
                                          update=search.search_update,
                                          )
    
    Vilem Duha's avatar
    Vilem Duha committed
    
        append_method: EnumProperty(
            name="Import Method",
            items=(
    
                ('LINK_COLLECTION', 'Link', 'Link Collection'),
                ('APPEND_OBJECTS', 'Append', 'Append as Objects'),
    
    Vilém Duha's avatar
    Vilém Duha committed
            description="Appended objects are editable in your scene. Linked assets are saved in original files, "
                        "aren't editable but also don't increase your file size",
    
            default="APPEND_OBJECTS"
    
    Vilem Duha's avatar
    Vilem Duha committed
        )
        append_link: EnumProperty(
            name="How to Attach",
            items=(
                ('LINK', 'Link', ''),
                ('APPEND', 'Append', ''),
            ),
            description="choose if the assets will be linked or appended",
            default="LINK"
        )
        import_as: EnumProperty(
            name="Import as",
            items=(
                ('GROUP', 'group', ''),
                ('INDIVIDUAL', 'objects', ''),
    
            ),
            description="choose if the assets will be linked or appended",
            default="GROUP"
        )
        randomize_rotation: BoolProperty(name='Randomize Rotation',
                                         description="randomize rotation at placement",
                                         default=False)
        randomize_rotation_amount: FloatProperty(name="Randomization Max Angle",
                                                 description="maximum angle for random rotation",
                                                 default=math.pi / 36,
                                                 min=0,
                                                 max=2 * math.pi,
                                                 subtype='ANGLE')
        offset_rotation_amount: FloatProperty(name="Offset Rotation",
                                              description="offset rotation, hidden prop",
                                              default=0,
                                              min=0,
                                              max=360,
                                              subtype='ANGLE')
        offset_rotation_step: FloatProperty(name="Offset Rotation Step",
                                            description="offset rotation, hidden prop",
                                            default=math.pi / 2,
                                            min=0,
                                            max=180,
                                            subtype='ANGLE')
    
    
        perpendicular_snap: BoolProperty(name='Perpendicular snap',
    
                                         description="Limit snapping that is close to perpendicular angles to be perpendicular",
    
                                         default=True)
    
        perpendicular_snap_threshold: FloatProperty(name="Threshold",
    
                                                    description="Limit perpendicular snap to be below these values",
    
                                                    default=.25,
                                                    min=0,
                                                    max=.5,
                                                    )
    
    
    class BlenderKitHDRSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
        search_keywords: StringProperty(
            name="Search",
            description="Search for these keywords",
            default="",
            update=search.search_update
        )
    
    
    Vilem Duha's avatar
    Vilem Duha committed
        true_hdr: BoolProperty(
            name='Real HDRs only',
    
            description='Search only for real HDRs, this means images that have a range higher than 0-1 in their pixels',
    
    Vilem Duha's avatar
    Vilem Duha committed
            default=True,
            update=search.search_update
        )
    
    
    Vilem Duha's avatar
    Vilem Duha committed
    class BlenderKitSceneSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
        search_keywords: StringProperty(
            name="Search",
            description="Search for these keywords",
            default="",
            update=search.search_update
        )
        search_style: EnumProperty(
            name="Style",
            items=search_model_styles,
    
    Vilém Duha's avatar
    Vilém Duha committed
            description="Restrict search for style",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="ANY",
            update=search.search_update
        )
        search_style_other: StringProperty(
            name="Style",
            description="Search style - other",
            default="",
            update=search.search_update
        )
        search_engine: EnumProperty(
            items=engines,
            default='CYCLES',
            description='Output engine',
            update=search.search_update
        )
        search_engine_other: StringProperty(
            name="Engine",
    
    Vilém Duha's avatar
    Vilém Duha committed
            description="Engine not specified by addon",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="",
            update=search.search_update
        )
    
        append_link: EnumProperty(
            name="Append or link",
            items=(
                ('LINK', 'Link', ''),
                ('APPEND', 'Append', ''),
            ),
            description="choose if the scene will be linked or appended",
            default="APPEND"
        )
        switch_after_append: BoolProperty(
    
            name='Switch to scene after download',
    
            default=True
    
    def fix_subdir(self, context):
        '''Fixes project subdicrectory settings if people input invalid path.'''
    
        # pp = pathlib.PurePath(self.project_subdir)
        pp = self.project_subdir[:]
    
        pp = pp.replace('\\', '')
        pp = pp.replace('/', '')
        pp = pp.replace(':', '')
    
        pp = '//' + pp
        if self.project_subdir != pp:
            self.project_subdir = pp
    
    
            ui_panels.ui_message(title="Fixed to relative path",
                                 message="This path should be always realative.\n" \
                                         " It's a directory BlenderKit creates where your .blend is \n " \
                                         "and uses it for storing assets.")
    
    Vilem Duha's avatar
    Vilem Duha committed
    class BlenderKitAddonPreferences(AddonPreferences):
        # this must match the addon name, use '__package__'
        # when defining this in a submodule of a python package.
        bl_idname = __name__
    
    Vilem Duha's avatar
    Vilem Duha committed
        enable_oauth = True
    
    Vilem Duha's avatar
    Vilem Duha committed
        api_key: StringProperty(
            name="BlenderKit API Key",
    
            description="Your blenderkit API Key. Get it from your page on the website",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="",
            subtype="PASSWORD",
            update=utils.save_prefs
        )
    
    
        api_key_refresh: StringProperty(
            name="BlenderKit refresh API Key",
    
            description="API key used to refresh the token regularly",
    
    Vilém Duha's avatar
    Vilém Duha committed
            name='api key timeout',
            description='time where the api key will need to be refreshed',
            default=0,
    
        )
    
        api_key_life: IntProperty(
            name='api key life time',
            description='maximum lifetime of the api key, in seconds',
            default=0,
        )
    
        refresh_in_progress: BoolProperty(
            name="Api key refresh in progress",
    
            description="Api key is currently being refreshed. Don't refresh it again",
    
        login_attempt: BoolProperty(
            name="Login/Signup attempt",
    
            description="When this is on, BlenderKit is trying to connect and login",
    
        show_on_start: BoolProperty(
            name="Show assetbar when starting blender",
            description="Show assetbar when starting blender",
            default=False
        )
    
    
        tips_on_start: BoolProperty(
            name="Show tips when starting blender",
            description="Show tips when starting blender",
    
        )
    
        search_in_header: BoolProperty(
    
    Vilém Duha's avatar
    Vilém Duha committed
            name="Show BlenderKit search in 3D view header",
            description="Show BlenderKit search in 3D view header",
    
    Vilem Duha's avatar
    Vilem Duha committed
        global_dir: StringProperty(
            name="Global Files Directory",
    
            description="Global storage for your assets, will use subdirectories for the contents",
    
    Vilem Duha's avatar
    Vilem Duha committed
            subtype='DIR_PATH',
            default=default_global_dict,
            update=utils.save_prefs
        )
    
        project_subdir: StringProperty(
            name="Project Assets Subdirectory",
    
            description="where data will be stored for individual projects",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default="//assets",
    
            update=fix_subdir
    
    Vilem Duha's avatar
    Vilem Duha committed
        )
    
        directory_behaviour: EnumProperty(
            name="Use Directories",
            items=(
                ('BOTH', 'Global and subdir',
                 'store files both in global lib and subdirectory of current project. '
    
                 'Warning - each file can be many times on your harddrive, but helps you keep your projects in one piece'),
    
    Vilem Duha's avatar
    Vilem Duha committed
                ('GLOBAL', 'Global',
                 "store downloaded files only in global directory. \n "
                 "This can bring problems when moving your projects, \n"
                 "since assets won't be in subdirectory of current project"),
                ('LOCAL', 'Local',
                 'store downloaded files only in local directory.\n'
                 ' This can use more bandwidth when you reuse assets in different projects. ')
    
            ),
            description="Which directories will be used for storing downloaded data",
            default="BOTH",
        )
        thumbnail_use_gpu: BoolProperty(
    
    Vilém Duha's avatar
    Vilém Duha committed
            name="Use GPU for Thumbnails Rendering (For assets upload)",
    
            description="By default this is off so you can continue your work without any lag",
    
    Vilém Duha's avatar
    Vilém Duha committed
            default=False
    
    Vilem Duha's avatar
    Vilem Duha committed
        )
    
        panel_behaviour: EnumProperty(
            name="Panels Locations",
            items=(
                ('BOTH', 'Both Types',
                 ''),
    
                ('UNIFIED', 'Unified 3D View Panel',
    
    Vilem Duha's avatar
    Vilem Duha committed
                 ""),
                ('LOCAL', 'Relative to Data',
                 '')
    
            ),
            description="Which directories will be used for storing downloaded data",
            default="UNIFIED",
        )
    
        max_assetbar_rows: IntProperty(name="Max Assetbar Rows",
    
                                       description="max rows of assetbar in the 3D view",
    
    Vilem Duha's avatar
    Vilem Duha committed
                                       default=1,
    
    Vilem Duha's avatar
    Vilem Duha committed
                                       min=1,
    
        thumb_size: IntProperty(name="Assetbar thumbnail Size", default=96, min=-1, max=256)
    
    
        #counts usages so it can encourage user after some time to do things.
    
        asset_counter: IntProperty(name="Usage Counter",
                                   description="Counts usages so it asks for registration only after reaching a limit",
                                   default=0,
                                   min=0,
                                   max=20000)
    
        notifications_counter: IntProperty(
            name='Notifications Counter',
            description='count users notifications',
            default=0,
        )
    
        # this is now made obsolete by the new popup upon registration -ensures the user knows about the first search.
        # first_run: BoolProperty(
        #     name="First run",
        #     description="Detects if addon was already registered/run.",
        #     default=True,
        #     update=utils.save_prefs
        # )
    
    
        use_timers: BoolProperty(
            name="Use timers",
    
            description="Use timers for BlenderKit. Usefull for debugging since timers seem to be unstable",
    
        # single_timer: BoolProperty(
        #     name="Use timers",
        #     description="Use timers for BlenderKit. Usefull for debugging since timers seem to be unstable",
        #     default=True,
        #     update=utils.save_prefs
        # )
    
    
        experimental_features: BoolProperty(
            name="Enable experimental features",
    
            description="Enable all experimental features of BlenderKit. Use at your own risk",
    
            default=False,
            update=utils.save_prefs
        )
    
    Vilém Duha's avatar
    Vilém Duha committed
    
        categories_fix: BoolProperty(
            name="Enable category fixing mode",
    
            description="Enable category fixing mode",
    
    Vilém Duha's avatar
    Vilém Duha committed
            default=False,
            update=utils.save_prefs
        )
    
    Vilem Duha's avatar
    Vilem Duha committed
        # allow_proximity : BoolProperty(
        #     name="allow proximity data reports",
        #     description="This sends anonymized proximity data \n \
        #             and allows us to make relations between database objects \n \
    
    Vilem Duha's avatar
    Vilem Duha committed
        #     default=False
        # )
    
        def draw(self, context):
            layout = self.layout
    
            layout.prop(self, "show_on_start")
    
    Vilem Duha's avatar
    Vilem Duha committed
    
            if self.api_key.strip() == '':
    
                    ui_panels.draw_login_buttons(layout)
    
                else:
                    op = layout.operator("wm.url_open", text="Register online and get your API Key",
                                         icon='QUESTION')
                    op.url = paths.BLENDERKIT_SIGNUP_URL
    
            else:
                if self.enable_oauth:
                    layout.operator("wm.blenderkit_logout", text="Logout",
                                    icon='URL')
    
    Vilém Duha's avatar
    Vilém Duha committed
            # if not self.enable_oauth:
    
            layout.prop(self, "api_key", text='Your API Key')
    
            # layout.label(text='After you paste API Key, categories are downloaded, so blender will freeze for a few seconds.')
    
    Vilem Duha's avatar
    Vilem Duha committed
            layout.prop(self, "global_dir")
            layout.prop(self, "project_subdir")
            # layout.prop(self, "temp_dir")
            layout.prop(self, "directory_behaviour")
            # layout.prop(self, "allow_proximity")
            # layout.prop(self, "panel_behaviour")
    
            layout.prop(self, "thumb_size")
    
    Vilem Duha's avatar
    Vilem Duha committed
            layout.prop(self, "max_assetbar_rows")
    
            layout.prop(self, "tips_on_start")
            layout.prop(self, "search_in_header")
    
    Vilém Duha's avatar
    Vilém Duha committed
            layout.prop(self, "thumbnail_use_gpu")
    
    
            if bpy.context.preferences.view.show_developer_ui:
                layout.prop(self, "use_timers")
    
                layout.prop(self, "experimental_features")
    
    Vilém Duha's avatar
    Vilém Duha committed
                layout.prop(self, "categories_fix")
    
    # # @bpy.app.handlers.persistent
    # def blenderkit_timer():
    #
    #
    # if not user_preferences.use_timers:
    #     search.search_timer()
    #     download.download_timer()
    #     tasks_queue.queue_worker()
    #     bg_blender.bg_update()
    
    Vilem Duha's avatar
    Vilem Duha committed
    # registration
    classes = (
    
        BlenderKitAddonPreferences,
        BlenderKitUIProps,
    
        BlenderKitModelSearchProps,
        BlenderKitModelUploadProps,
    
        BlenderKitSceneSearchProps,
        BlenderKitSceneUploadProps,
    
    
        BlenderKitHDRSearchProps,
        BlenderKitHDRUploadProps,
    
    
    Vilem Duha's avatar
    Vilem Duha committed
        BlenderKitMaterialUploadProps,
        BlenderKitMaterialSearchProps,
    
        BlenderKitTextureUploadProps,
    
        BlenderKitBrushSearchProps,
        BlenderKitBrushUploadProps,
    
        BlenderKitRatingProps,
    )
    
    
    
    Vilem Duha's avatar
    Vilem Duha committed
    def register():
        for cls in classes:
            bpy.utils.register_class(cls)
    
    
        bpy.types.WindowManager.blenderkitUI = PointerProperty(
    
    Vilem Duha's avatar
    Vilem Duha committed
            type=BlenderKitUIProps)
    
        # MODELS
    
        bpy.types.WindowManager.blenderkit_models = PointerProperty(
    
    Vilem Duha's avatar
    Vilem Duha committed
            type=BlenderKitModelSearchProps)
        bpy.types.Object.blenderkit = PointerProperty(  # for uploads, not now...
            type=BlenderKitModelUploadProps)
        bpy.types.Object.bkit_ratings = PointerProperty(  # for uploads, not now...
            type=BlenderKitRatingProps)
    
        # SCENES
    
        bpy.types.WindowManager.blenderkit_scene = PointerProperty(
    
    Vilem Duha's avatar
    Vilem Duha committed
            type=BlenderKitSceneSearchProps)
        bpy.types.Scene.blenderkit = PointerProperty(  # for uploads, not now...
            type=BlenderKitSceneUploadProps)
        bpy.types.Scene.bkit_ratings = PointerProperty(  # for uploads, not now...
            type=BlenderKitRatingProps)
    
    
        bpy.types.WindowManager.blenderkit_HDR = PointerProperty(
    
            type=BlenderKitHDRSearchProps)
        bpy.types.Image.blenderkit = PointerProperty(  # for uploads, not now...
            type=BlenderKitHDRUploadProps)
        bpy.types.Image.bkit_ratings = PointerProperty(  # for uploads, not now...
            type=BlenderKitRatingProps)
    
    
    Vilem Duha's avatar
    Vilem Duha committed
        # MATERIALS
    
        bpy.types.WindowManager.blenderkit_mat = PointerProperty(
    
    Vilem Duha's avatar
    Vilem Duha committed
            type=BlenderKitMaterialSearchProps)
        bpy.types.Material.blenderkit = PointerProperty(  # for uploads, not now...
            type=BlenderKitMaterialUploadProps)
        bpy.types.Material.bkit_ratings = PointerProperty(  # for uploads, not now...
            type=BlenderKitRatingProps)
    
        # BRUSHES
    
        bpy.types.WindowManager.blenderkit_brush = PointerProperty(
    
    Vilem Duha's avatar
    Vilem Duha committed
            type=BlenderKitBrushSearchProps)
        bpy.types.Brush.blenderkit = PointerProperty(  # for uploads, not now...
            type=BlenderKitBrushUploadProps)
        bpy.types.Brush.bkit_ratings = PointerProperty(  # for uploads, not now...
            type=BlenderKitRatingProps)
    
        search.register_search()
        asset_inspector.register_asset_inspector()
        download.register_download()
        upload.register_upload()
        ratings.register_ratings()
        autothumb.register_thumbnailer()
        ui.register_ui()
    
    Vilém Duha's avatar
    Vilém Duha committed
        icons.register_icons()
    
    Vilem Duha's avatar
    Vilem Duha committed
        ui_panels.register_ui_panels()
        bg_blender.register()
        utils.load_prefs()
        overrides.register_overrides()
    
        asset_bar_op.register()
    
        user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
    
        if user_preferences.use_timers and not bpy.app.background:
    
            bpy.app.timers.register(check_timers_timer, persistent=True)
    
        bpy.app.handlers.load_post.append(scene_load)
    
        # detect if the user just enabled the addon in preferences, thus enable to run
        for w in bpy.context.window_manager.windows:
            for a in w.screen.areas:
                if a.type == 'PREFERENCES':
    
                    tasks_queue.add_task((bpy.ops.wm.blenderkit_welcome, ('INVOKE_DEFAULT',)), fake_context=True,
                                         fake_context_area='PREFERENCES')
    
                    #save preferences after manually enabling the addon
                    tasks_queue.add_task((bpy.ops.wm.save_userpref, ()), fake_context=False,)
    
    def unregister():
    
        if bpy.app.timers.is_registered(check_timers_timer):
            bpy.app.timers.unregister(check_timers_timer)
    
        ui_panels.unregister_ui_panels()
    
        ui.unregister_ui()
    
    Vilém Duha's avatar
    Vilém Duha committed
        icons.unregister_icons()
    
        search.unregister_search()
        asset_inspector.unregister_asset_inspector()
        download.unregister_download()
        upload.unregister_upload()
        ratings.unregister_ratings()
        autothumb.unregister_thumbnailer()
        bg_blender.unregister()
        overrides.unregister_overrides()
    
        asset_bar_op.unregister()
    
        del bpy.types.WindowManager.blenderkit_models
        del bpy.types.WindowManager.blenderkit_scene
        del bpy.types.WindowManager.blenderkit_HDR
        del bpy.types.WindowManager.blenderkit_brush
        del bpy.types.WindowManager.blenderkit_mat
    
    Vilem Duha's avatar
    Vilem Duha committed
    
        del bpy.types.Scene.blenderkit
        del bpy.types.Object.blenderkit
    
        del bpy.types.Image.blenderkit
    
    Vilem Duha's avatar
    Vilem Duha committed
        del bpy.types.Material.blenderkit
        del bpy.types.Brush.blenderkit
    
    
        for cls in classes:
            bpy.utils.unregister_class(cls)
    
    
        bpy.app.handlers.load_post.remove(scene_load)