Skip to content
Snippets Groups Projects
__init__.py 53.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • Vilem Duha's avatar
    Vilem Duha committed
                                            description="texture resolution min, autofilled", default=0)
        texture_resolution_max: IntProperty(name="Texture Eesolution 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='',
        )
    
        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,
            description="keywords defining style (realistic, painted, polygonal, other)",
            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",
            description="engine not specified by addon",
            default="",
            update=search.search_update
        )
    
        search_advanced: BoolProperty(name="Advanced Search Options", description="use advanced search properties",
                                      default=False)
    
        # CONDITION
        search_condition: EnumProperty(
            items=conditions,
            default='UNSPECIFIED',
            description='condition of the object',
            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",
                                         description="when the object was approximately designed",
                                         default=False)
    
        search_design_year_min: IntProperty(name="Min Age",
                                            description="when the object was approximately designed",
                                            default=1950, min=-100000000, max=1000000000)
    
        search_design_year_max: IntProperty(name="Max Age",
                                            description="when the object was approximately designed",
                                            default=2017,
                                            min=0,
                                            max=10000000)
    
        # TEXTURE RESOLUTION
        search_texture_resolution: BoolProperty(name="Texture Resolution",
                                                description="Span of the texture resolutions",
                                                default=False)
    
        search_texture_resolution_min: IntProperty(name="Min Texture Resolution",
                                                   description="when the object was approximately designed",
                                                   default=256,
                                                   min=0,
                                                   max=32768)
    
        search_texture_resolution_max: IntProperty(name="Max Texture Resolution",
                                                   description="when the object was approximately designed",
                                                   default=4096,
                                                   min=0,
                                                   max=32768)
    
        # POLYCOUNT
        search_polycount: BoolProperty(name="Use Polycount",
                                       description="use polycount of object search tag",
                                       default=False)
    
        search_polycount_min: IntProperty(name="Min Polycount",
                                          description="polycount of the asset minimum",
                                          default=0,
                                          min=0,
                                          max=100000000)
    
        search_polycount_max: IntProperty(name="Max Polycount",
                                          description="polycount of the asset maximum",
                                          default=100000000,
                                          min=0,
                                          max=100000000)
    
        append_method: EnumProperty(
            name="Import Method",
            items=(
                ('LINK_GROUP', 'Link Group', ''),
                ('APPEND_OBJECTS', 'Append Objects', ''),
            ),
            description="choose if the assets will be linked or appended",
            default="LINK_GROUP"
        )
        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')
    
    
    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,
            description="keywords defining style (realistic, painted, polygonal, other)",
            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",
            description="engine not specified by addon",
            default="",
            update=search.search_update
        )
    
    
    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
    
        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.",
            default="",
            subtype="PASSWORD",
        )
    
        login_attempt: BoolProperty(
            name="Login/Signup attempt",
            description="When this is on, BlenderKit is trying to connect and login.",
            default=False
        )
    
    
    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
            subtype='DIR_PATH',
            default="//assets",
        )
    
        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(
            name="Use GPU for Thumbnails Rendering",
    
            description="By default this is off so you can continue your work without any lag",
    
    Vilem Duha's avatar
    Vilem Duha committed
            default=True
        )
    
        panel_behaviour: EnumProperty(
            name="Panels Locations",
            items=(
                ('BOTH', 'Both Types',
                 ''),
                ('UNIFIED', 'Unified 3d View Panel',
                 ""),
                ('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",
                                       default=1,
                                       min=0,
                                       max=20)
    
    
        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)
    
    
    
    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
    
            if self.api_key.strip() == '':
    
    Vilem Duha's avatar
    Vilem Duha committed
                layout.operator("wm.blenderkit_login", text="Login/ Sign up",
                                icon='URL')
    
    Vilem Duha's avatar
    Vilem Duha committed
            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, "thumbnail_use_gpu")
            # layout.prop(self, "allow_proximity")
            # layout.prop(self, "panel_behaviour")
            layout.prop(self, "max_assetbar_rows")
    
    
    # registration
    classes = (
    
        BlenderKitAddonPreferences,
        BlenderKitUIProps,
    
        BlenderKitModelSearchProps,
        BlenderKitModelUploadProps,
    
        BlenderKitSceneSearchProps,
        BlenderKitSceneUploadProps,
    
        BlenderKitMaterialUploadProps,
        BlenderKitMaterialSearchProps,
    
        BlenderKitTextureUploadProps,
    
        BlenderKitBrushSearchProps,
        BlenderKitBrushUploadProps,
    
        BlenderKitRatingProps,
    )
    
    
    def register():
        for cls in classes:
            bpy.utils.register_class(cls)
    
        bpy.types.Scene.blenderkitUI = PointerProperty(
            type=BlenderKitUIProps)
    
        # MODELS
        bpy.types.Scene.blenderkit_models = PointerProperty(
            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.Scene.blenderkit_scene = PointerProperty(
            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)
    
        # MATERIALS
        bpy.types.Scene.blenderkit_mat = PointerProperty(
            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.Scene.blenderkit_brush = PointerProperty(
            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()
        ui_panels.register_ui_panels()
        bg_blender.register()
        utils.load_prefs()
        overrides.register_overrides()
    
        bpy.app.handlers.load_post.append(scene_load)
    
    Vilem Duha's avatar
    Vilem Duha committed
    
    def unregister():
    
    
        ui.unregister_ui()
        search.unregister_search()
        asset_inspector.unregister_asset_inspector()
        download.unregister_download()
        upload.unregister_upload()
        ratings.unregister_ratings()
        autothumb.unregister_thumbnailer()
        ui_panels.unregister_ui_panels()
        bg_blender.unregister()
        overrides.unregister_overrides()
    
    Vilem Duha's avatar
    Vilem Duha committed
    
        del bpy.types.Scene.blenderkit_models
        del bpy.types.Scene.blenderkit_scene
        del bpy.types.Scene.blenderkit_brush
        del bpy.types.Scene.blenderkit_mat
    
        del bpy.types.Scene.blenderkit
        del bpy.types.Object.blenderkit
        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)