feat: 优化跨层级移动和套索抠图命令,支持异步执行,改进画布刷新逻辑,新增背景裁剪选项
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
createLayer,
|
||||
findInChildLayers,
|
||||
LayerType,
|
||||
OperationType,
|
||||
} from "../utils/layerHelper.js";
|
||||
import { createRasterizedImage } from "../utils/selectionToImage.js";
|
||||
import { CompositeCommand, Command } from "./Command.js";
|
||||
@@ -11,6 +12,7 @@ import {
|
||||
} from "./LayerCommands.js";
|
||||
import { fabric } from "fabric-with-all";
|
||||
import { generateId } from "../utils/helper.js";
|
||||
import { ToolCommand } from "./ToolCommands.js";
|
||||
|
||||
/**
|
||||
* 套索抠图命令
|
||||
@@ -256,16 +258,16 @@ export class LassoCutoutCommand extends CompositeCommand {
|
||||
// this.fabricImage.toObject("id", "layerId", "layerName", "parentId"),
|
||||
// ];
|
||||
// 2. 删除原图层命令
|
||||
const removeOriginalLayerCmd = new RemoveLayerCommand({
|
||||
canvas: this.canvas,
|
||||
layers: this.layerManager.layers,
|
||||
layerId: this.originalLayer.id,
|
||||
activeLayerId: this.layerManager.activeLayerId,
|
||||
});
|
||||
// const removeOriginalLayerCmd = new RemoveLayerCommand({
|
||||
// canvas: this.canvas,
|
||||
// layers: this.layerManager.layers,
|
||||
// layerId: this.originalLayer.id,
|
||||
// activeLayerId: this.layerManager.activeLayerId,l
|
||||
// });
|
||||
|
||||
// 执行删除原图层命令
|
||||
await removeOriginalLayerCmd.execute();
|
||||
this.executedCommands.push(removeOriginalLayerCmd);
|
||||
// // 执行删除原图层命令
|
||||
// await removeOriginalLayerCmd.execute();
|
||||
// this.executedCommands.push(removeOriginalLayerCmd);
|
||||
|
||||
this.groupLayer.clippingMask = clippingMask.toObject(["id", "layerId"]); // 设置组图层的fabricObject为遮罩图像
|
||||
|
||||
@@ -275,6 +277,21 @@ export class LassoCutoutCommand extends CompositeCommand {
|
||||
|
||||
this.layerManager.activeLayerId.value = selectLayer.id; // 设置新组图层为活动图层
|
||||
|
||||
// 切换工具到选择模式
|
||||
// 3. 切换工具到选择模式命令
|
||||
if (this.toolManager) {
|
||||
const toolCmd = new ToolCommand({
|
||||
toolManager: this.toolManager,
|
||||
tool: OperationType.SELECT,
|
||||
previousTool: this.toolManager.getCurrentTool(),
|
||||
});
|
||||
|
||||
// 执行工具切换命令
|
||||
await toolCmd.execute();
|
||||
this.commands.push(toolCmd);
|
||||
this.executedCommands.push(toolCmd);
|
||||
}
|
||||
|
||||
this.canvas.discardActiveObject();
|
||||
// this.canvas.setActiveObject(this.fabricImage);
|
||||
await this.layerManager.updateLayersObjectsInteractivity(true);
|
||||
|
||||
Reference in New Issue
Block a user