fix: 修复多个已知问题
This commit is contained in:
@@ -490,6 +490,7 @@ export class LiquifyStateCommand extends Command {
|
||||
* @param {String} options.targetLayerId 目标图层ID
|
||||
* @param {ImageData} options.initialImageData 初始图像数据
|
||||
* @param {ImageData} options.finalImageData 最终图像数据
|
||||
* @param {Object} options.liquifyManager 液化管理器实例
|
||||
*/
|
||||
constructor(options) {
|
||||
super({
|
||||
@@ -502,6 +503,7 @@ export class LiquifyStateCommand extends Command {
|
||||
this.targetObject = options.targetObject;
|
||||
this.targetLayerId = options.targetLayerId;
|
||||
this.targetObjectId = options.targetObjectId;
|
||||
this.liquifyManager = options.liquifyManager; // 添加液化管理器引用
|
||||
|
||||
// 获取引用管理器实例
|
||||
this.refManager = getLiquifyReferenceManager();
|
||||
@@ -520,6 +522,10 @@ export class LiquifyStateCommand extends Command {
|
||||
this.initialImageData = options.initialImageData;
|
||||
this.finalImageData = options.finalImageData;
|
||||
|
||||
// 保存液化管理器的操作记录状态
|
||||
this.initialLiquifyState = null;
|
||||
this.finalLiquifyState = null;
|
||||
|
||||
this.currentState = "initial";
|
||||
|
||||
// 创建初始快照
|
||||
@@ -547,6 +553,19 @@ export class LiquifyStateCommand extends Command {
|
||||
this.finalImageData
|
||||
);
|
||||
|
||||
// 恢复液化管理器到最终状态
|
||||
if (this.liquifyManager && this.finalLiquifyState) {
|
||||
this._restoreLiquifyManagerState(this.finalLiquifyState);
|
||||
} else if (this.liquifyManager) {
|
||||
// 如果没有保存的最终状态,重新准备液化环境
|
||||
const currentTarget = this.refManager.getObjectRef(this.objectRefId);
|
||||
if (currentTarget) {
|
||||
await this.liquifyManager.prepareForLiquify(currentTarget);
|
||||
// 保存当前的液化管理器状态作为最终状态
|
||||
this.finalLiquifyState = this._captureLiquifyManagerState();
|
||||
}
|
||||
}
|
||||
|
||||
this.currentState = "final";
|
||||
this.canvas.renderAll();
|
||||
|
||||
@@ -568,6 +587,21 @@ export class LiquifyStateCommand extends Command {
|
||||
this.initialSnapshotId
|
||||
);
|
||||
|
||||
// 恢复液化管理器到初始状态
|
||||
if (this.liquifyManager) {
|
||||
if (this.initialLiquifyState) {
|
||||
this._restoreLiquifyManagerState(this.initialLiquifyState);
|
||||
} else {
|
||||
// 如果没有初始状态,重置液化管理器
|
||||
this.liquifyManager.reset();
|
||||
// 重新准备液化环境
|
||||
const currentTarget = this.refManager.getObjectRef(this.objectRefId);
|
||||
if (currentTarget) {
|
||||
await this.liquifyManager.prepareForLiquify(currentTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.currentState = "initial";
|
||||
this.canvas.renderAll();
|
||||
|
||||
@@ -589,6 +623,11 @@ export class LiquifyStateCommand extends Command {
|
||||
setFinalImageData(finalImageData) {
|
||||
this.finalImageData = finalImageData;
|
||||
this.finalSnapshotId = null; // 重置快照ID,下次执行时重新创建
|
||||
|
||||
// 捕获当前液化管理器状态作为最终状态
|
||||
if (this.liquifyManager) {
|
||||
this.finalLiquifyState = this._captureLiquifyManagerState();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -672,6 +711,12 @@ export class LiquifyStateCommand extends Command {
|
||||
};
|
||||
|
||||
this.refManager.stateSnapshots.set(this.initialSnapshotId, snapshot);
|
||||
|
||||
// 捕获初始液化管理器状态
|
||||
if (this.liquifyManager) {
|
||||
this.initialLiquifyState = this._captureLiquifyManagerState();
|
||||
}
|
||||
|
||||
console.log(`📸 初始状态快照已创建: ${this.initialSnapshotId}`);
|
||||
}
|
||||
}
|
||||
@@ -697,27 +742,180 @@ export class LiquifyStateCommand extends Command {
|
||||
};
|
||||
|
||||
this.refManager.stateSnapshots.set(this.finalSnapshotId, snapshot);
|
||||
|
||||
// 捕获最终液化管理器状态
|
||||
if (this.liquifyManager) {
|
||||
this.finalLiquifyState = this._captureLiquifyManagerState();
|
||||
}
|
||||
|
||||
console.log(`📸 最终状态快照已创建: ${this.finalSnapshotId}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算命令本身的内存使用量
|
||||
* @returns {Number} 内存使用量(字节)
|
||||
* 捕获液化管理器的当前状态
|
||||
* @returns {Object} 液化管理器状态
|
||||
* @private
|
||||
*/
|
||||
_calculateCommandMemory() {
|
||||
let bytes = 0;
|
||||
_captureLiquifyManagerState() {
|
||||
if (!this.liquifyManager) return null;
|
||||
|
||||
// 计算ImageData内存使用
|
||||
if (this.initialImageData) {
|
||||
bytes += this.initialImageData.width * this.initialImageData.height * 4;
|
||||
}
|
||||
if (this.finalImageData) {
|
||||
bytes += this.finalImageData.width * this.finalImageData.height * 4;
|
||||
}
|
||||
try {
|
||||
const state = {
|
||||
// 捕获增强管理器状态
|
||||
enhancedManagerState: null,
|
||||
// 捕获当前渲染器状态
|
||||
activeRendererState: null,
|
||||
// 捕获目标对象引用
|
||||
targetObjectRef: this.liquifyManager.targetObject,
|
||||
// 捕获初始化状态
|
||||
initialized: this.liquifyManager.initialized || false,
|
||||
};
|
||||
|
||||
return bytes;
|
||||
// 如果有增强管理器,捕获其状态
|
||||
if (this.liquifyManager.enhancedManager) {
|
||||
const enhancedManager = this.liquifyManager.enhancedManager;
|
||||
state.enhancedManagerState = {
|
||||
initialized: enhancedManager.initialized,
|
||||
renderMode: enhancedManager.renderMode,
|
||||
targetObject: enhancedManager.targetObject,
|
||||
originalImageData: enhancedManager.originalImageData,
|
||||
currentImageData: enhancedManager.currentImageData,
|
||||
params: { ...enhancedManager.params },
|
||||
currentMode: enhancedManager.currentMode,
|
||||
};
|
||||
|
||||
// 如果有激活的渲染器,捕获其状态
|
||||
if (enhancedManager.activeRenderer) {
|
||||
const renderer = enhancedManager.activeRenderer;
|
||||
state.activeRendererState = {
|
||||
initialized: renderer.initialized,
|
||||
originalImageData: renderer.originalImageData,
|
||||
currentImageData: renderer.currentImageData,
|
||||
params: { ...renderer.params },
|
||||
currentMode: renderer.currentMode,
|
||||
// 对于CPU渲染器,还需要保存网格状态
|
||||
meshState: renderer.mesh
|
||||
? this._captureMeshState(renderer.mesh)
|
||||
: null,
|
||||
// 保存变形历史
|
||||
deformHistory: renderer.deformHistory
|
||||
? [...renderer.deformHistory]
|
||||
: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`💾 液化管理器状态已捕获:`, state);
|
||||
return state;
|
||||
} catch (error) {
|
||||
console.error("捕获液化管理器状态失败:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复液化管理器状态
|
||||
* @param {Object} state 要恢复的状态
|
||||
* @private
|
||||
*/
|
||||
_restoreLiquifyManagerState(state) {
|
||||
if (!this.liquifyManager || !state) return;
|
||||
|
||||
try {
|
||||
// 恢复基本状态
|
||||
this.liquifyManager.initialized = state.initialized;
|
||||
if (state.targetObjectRef) {
|
||||
this.liquifyManager.targetObject = state.targetObjectRef;
|
||||
}
|
||||
|
||||
// 恢复增强管理器状态
|
||||
if (state.enhancedManagerState && this.liquifyManager.enhancedManager) {
|
||||
const enhancedManager = this.liquifyManager.enhancedManager;
|
||||
const enhancedState = state.enhancedManagerState;
|
||||
|
||||
enhancedManager.initialized = enhancedState.initialized;
|
||||
enhancedManager.renderMode = enhancedState.renderMode;
|
||||
enhancedManager.targetObject = enhancedState.targetObject;
|
||||
enhancedManager.originalImageData = enhancedState.originalImageData;
|
||||
enhancedManager.currentImageData = enhancedState.currentImageData;
|
||||
enhancedManager.params = { ...enhancedState.params };
|
||||
enhancedManager.currentMode = enhancedState.currentMode;
|
||||
|
||||
// 恢复激活渲染器状态
|
||||
if (state.activeRendererState && enhancedManager.activeRenderer) {
|
||||
const renderer = enhancedManager.activeRenderer;
|
||||
const rendererState = state.activeRendererState;
|
||||
|
||||
renderer.initialized = rendererState.initialized;
|
||||
renderer.originalImageData = rendererState.originalImageData;
|
||||
renderer.currentImageData = rendererState.currentImageData;
|
||||
renderer.params = { ...rendererState.params };
|
||||
renderer.currentMode = rendererState.currentMode;
|
||||
|
||||
// 恢复网格状态(如果是CPU渲染器)
|
||||
if (rendererState.meshState && renderer.mesh) {
|
||||
this._restoreMeshState(renderer.mesh, rendererState.meshState);
|
||||
}
|
||||
|
||||
// 恢复变形历史
|
||||
if (rendererState.deformHistory) {
|
||||
renderer.deformHistory = [...rendererState.deformHistory];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`🔄 液化管理器状态已恢复`);
|
||||
} catch (error) {
|
||||
console.error("恢复液化管理器状态失败:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 捕获网格状态
|
||||
* @param {Array} mesh 网格数组
|
||||
* @returns {Array} 网格状态副本
|
||||
* @private
|
||||
*/
|
||||
_captureMeshState(mesh) {
|
||||
if (!mesh || !Array.isArray(mesh)) return null;
|
||||
|
||||
return mesh.map((row) =>
|
||||
row.map((point) => ({
|
||||
x: point.x,
|
||||
y: point.y,
|
||||
originalX: point.originalX,
|
||||
originalY: point.originalY,
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复网格状态
|
||||
* @param {Array} mesh 目标网格
|
||||
* @param {Array} meshState 要恢复的网格状态
|
||||
* @private
|
||||
*/
|
||||
_restoreMeshState(mesh, meshState) {
|
||||
if (
|
||||
!mesh ||
|
||||
!meshState ||
|
||||
!Array.isArray(mesh) ||
|
||||
!Array.isArray(meshState)
|
||||
)
|
||||
return;
|
||||
|
||||
for (let i = 0; i < Math.min(mesh.length, meshState.length); i++) {
|
||||
for (let j = 0; j < Math.min(mesh[i].length, meshState[i].length); j++) {
|
||||
const point = mesh[i][j];
|
||||
const statePoint = meshState[i][j];
|
||||
|
||||
point.x = statePoint.x;
|
||||
point.y = statePoint.y;
|
||||
point.originalX = statePoint.originalX;
|
||||
point.originalY = statePoint.originalY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user