Esempio n. 1
0
    def remove_datablock(self, proxy: DatablockProxy, datablock: T.ID):
        """Remove a bpy.data collection item and update the proxy state"""
        logger.info("Perform removal for %s", proxy)
        try:
            if isinstance(datablock, T.Scene):
                from mixer.blender_client.scene import delete_scene

                delete_scene(datablock)
            else:
                proxy.collection.remove(datablock)
        except ReferenceError as e:
            # We probably have processed previously the deletion of a datablock referenced by Object.data (e.g. Light).
            # On both sides it deletes the Object as well. So the sender issues a message for object deletion
            # but deleting the light on this side has already deleted the object.
            # Alternatively we could try to sort messages on the sender side
            logger.warning(f"Exception during remove_datablock for {proxy}")
            logger.warning(f"... {e!r}")
        uuid = proxy.mixer_uuid()
        del self._data[uuid]
Esempio n. 2
0
    def create_datablock(
            self, incoming_proxy: DatablockProxy, context: Context
    ) -> Tuple[Optional[T.ID], Optional[RenameChangeset]]:
        """Create a bpy.data datablock from a received DatablockProxy and update the proxy structures accordingly

        Args:
            incoming_proxy : this proxy contents is used to update the bpy.data collection item
        """

        datablock, renames = incoming_proxy.create_standalone_datablock(
            context)

        if incoming_proxy.collection_name == "scenes":
            logger.warning(
                f"Creating scene '{incoming_proxy.data('name')}' uuid: '{incoming_proxy.mixer_uuid()}'"
            )

            # One existing scene from the document loaded at join time could not be removed during clear_scene_conten().
            # Remove it now
            scenes = bpy.data.scenes
            if len(scenes) == 2 and ("_mixer_to_be_removed_" in scenes):
                from mixer.blender_client.scene import delete_scene

                scene_to_remove = scenes["_mixer_to_be_removed_"]
                logger.warning(
                    f"After create scene '{incoming_proxy.data('name')}' uuid: '{incoming_proxy.mixer_uuid()}''"
                )
                logger.warning(
                    f"... delete {scene_to_remove} uuid '{scene_to_remove.mixer_uuid}'"
                )
                delete_scene(scene_to_remove)

        if not datablock:
            return None, None

        uuid = incoming_proxy.mixer_uuid()
        self._data[uuid] = incoming_proxy
        context.proxy_state.datablocks[uuid] = datablock
        context.proxy_state.proxies[uuid] = incoming_proxy

        context.proxy_state.unresolved_refs.resolve(uuid, datablock)
        return datablock, renames