コード例 #1
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)
        # returned datablock is None for ShapeKey and Library. Datablock creation is deferred until :
        # - ShapeKey : Object update
        # - Library : creation of a link datablock

        if incoming_proxy.collection_name == "scenes":
            logger.info(
                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.info(
                    f"After create scene '{incoming_proxy.data('name_full')}' uuid: '{incoming_proxy.mixer_uuid}''"
                )
                logger.info(
                    f"... delete {scene_to_remove} uuid '{scene_to_remove.mixer_uuid}'"
                )
                delete_scene(scene_to_remove)

        uuid = incoming_proxy.mixer_uuid
        self._data[uuid] = incoming_proxy

        # TODO code placement is inconsistent with BpyDataProxy.remove_datablock()
        context.proxy_state.add_datablock(uuid, datablock)
        context.proxy_state.proxies[uuid] = incoming_proxy
        if datablock is not None:
            context.proxy_state.unresolved_refs.resolve(uuid, datablock)

        return datablock, renames
コード例 #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