Esempio n. 1
0
    def execute(self, context):
        s = bpy.context.scene

        if self.asset_index > -1:
            # either get the data from search results
            sr = s['search results']
            asset_data = sr[
                self.asset_index].to_dict()  # TODO CHECK ALL OCCURRENCES OF PASSING BLENDER ID PROPS TO THREADS!
            asset_base_id = asset_data['assetBaseId']
        else:
            # or from the scene.
            asset_base_id = self.asset_base_id

        au = s.get('assets used')
        if au == None:
            s['assets used'] = {}
        if asset_base_id in s.get('assets used'):
            # already used assets have already download link and especially file link.
            asset_data = s['assets used'][asset_base_id].to_dict()

        atype = asset_data['assetType']
        if bpy.context.mode != 'OBJECT' and (
                atype == 'model' or atype == 'material') and bpy.context.view_layer.objects.active is not None:
            bpy.ops.object.mode_set(mode='OBJECT')

        if self.replace:  # cleanup first, assign later.
            obs = utils.get_selected_replace_adepts()
            # print(obs)
            for ob in obs:
                print('replace attempt ', ob.name)
                if self.asset_base_id != '':
                    # this is for a case when replace is called from a panel, this makes the first of the objects not replacable.
                    if ob.get('asset_data') is not None and ob['asset_data']['assetBaseId'] == self.asset_base_id:
                        print('skipping this oneli')
                        continue;

                kwargs = {
                    'cast_parent': self.cast_parent,
                    'target_object': ob.name,
                    'material_target_slot': ob.active_material_index,
                    'model_location': tuple(ob.matrix_world.translation),
                    'model_rotation': tuple(ob.matrix_world.to_euler()),
                    'replace': False,
                    'parent': ob.parent
                }
                utils.delete_hierarchy(ob)
                start_download(asset_data, **kwargs)
        else:
            kwargs = {
                'cast_parent': self.cast_parent,
                'target_object': self.target_object,
                'material_target_slot': self.material_target_slot,
                'model_location': tuple(self.model_location),
                'model_rotation': tuple(self.model_rotation),
                'replace': False
            }

            start_download(asset_data, **kwargs)
        return {'FINISHED'}
Esempio n. 2
0
    def execute(self, context):
        s = bpy.context.scene
        sr = s['search results']

        asset_data = sr[self.asset_index].to_dict(
        )  # TODO CHECK ALL OCCURRENCES OF PASSING BLENDER ID PROPS TO THREADS!
        au = s.get('assets used')
        if au == None:
            s['assets used'] = {}
        if asset_data['asset_base_id'] in s.get('assets used'):
            asset_data = s['assets used'][
                asset_data['asset_base_id']].to_dict()

        atype = asset_data['asset_type']
        if bpy.context.mode != 'OBJECT' and (
                atype == 'model' or atype == 'material'
        ) and bpy.context.view_layer.objects.active is not None:
            bpy.ops.object.mode_set(mode='OBJECT')

        if self.replace:  # cleanup first, assign later.
            obs = utils.get_selected_models()

            for ob in obs:
                kwargs = {
                    'cast_parent': self.cast_parent,
                    'target_object': ob.name,
                    'material_target_slot': ob.active_material_index,
                    'model_location': tuple(ob.matrix_world.translation),
                    'model_rotation': tuple(ob.matrix_world.to_euler()),
                    'replace': False,
                    'parent': ob.parent
                }
                utils.delete_hierarchy(ob)
                start_download(asset_data, **kwargs)
        else:
            kwargs = {
                'cast_parent': self.cast_parent,
                'target_object': self.target_object,
                'material_target_slot': self.material_target_slot,
                'model_location': tuple(self.model_location),
                'model_rotation': tuple(self.model_rotation),
                'replace': False
            }

            start_download(asset_data, **kwargs)
        return {'FINISHED'}