|
|
@ -4,7 +4,6 @@ import type BaseRenderer from '@/core/base/BaseRenderer' |
|
|
import { getRenderer } from './ModuleManager' |
|
|
import { getRenderer } from './ModuleManager' |
|
|
import { getLineId, parseLineId } from '@/core/ModelUtils' |
|
|
import { getLineId, parseLineId } from '@/core/ModelUtils' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 实体管理器 |
|
|
* 实体管理器 |
|
|
* 缓存所有 数据(ItemJson)和他们的关系, 以及渲染对象 THREE.Object3D |
|
|
* 缓存所有 数据(ItemJson)和他们的关系, 以及渲染对象 THREE.Object3D |
|
|
@ -101,7 +100,6 @@ export default class EntityManager { |
|
|
|
|
|
|
|
|
// 先判断坐标是否变化
|
|
|
// 先判断坐标是否变化
|
|
|
const coordinateChanged = originEntity?.tf && entity?.tf && !_.isEqual(originEntity.tf[0], entity.tf[0]) |
|
|
const coordinateChanged = originEntity?.tf && entity?.tf && !_.isEqual(originEntity.tf[0], entity.tf[0]) |
|
|
|
|
|
|
|
|
this.entities.set(entity.id, entity) |
|
|
this.entities.set(entity.id, entity) |
|
|
|
|
|
|
|
|
// 更新关系网
|
|
|
// 更新关系网
|
|
|
@ -111,6 +109,7 @@ export default class EntityManager { |
|
|
this.writeBackEntities.add(entity.id) |
|
|
this.writeBackEntities.add(entity.id) |
|
|
// 点的坐标发生变化, 要通知所有关联线更新
|
|
|
// 点的坐标发生变化, 要通知所有关联线更新
|
|
|
const relation = this.relationIndex.get(entity.id) |
|
|
const relation = this.relationIndex.get(entity.id) |
|
|
|
|
|
|
|
|
if (relation) { |
|
|
if (relation) { |
|
|
for (const type of (['center', 'in', 'out'] as LinkType[])) { |
|
|
for (const type of (['center', 'in', 'out'] as LinkType[])) { |
|
|
const relatedIds = relation[type] |
|
|
const relatedIds = relation[type] |
|
|
@ -118,8 +117,11 @@ export default class EntityManager { |
|
|
|
|
|
|
|
|
for (const relatedId of relatedIds) { |
|
|
for (const relatedId of relatedIds) { |
|
|
const lineId = getLineId(entity.id, relatedId, type) |
|
|
const lineId = getLineId(entity.id, relatedId, type) |
|
|
|
|
|
console.log(`[update] ${entity.id} -> ${relatedId} [${type}] => ${lineId}`) |
|
|
this.lineDiffs.update.set(lineId, { startId: entity.id, endId: relatedId, type }) |
|
|
this.lineDiffs.update.set(lineId, { startId: entity.id, endId: relatedId, type }) |
|
|
|
|
|
|
|
|
|
|
|
this.writeBackEntities.add(relatedId) |
|
|
|
|
|
|
|
|
// 如果是双向线(比如 center),也要反向加一次
|
|
|
// 如果是双向线(比如 center),也要反向加一次
|
|
|
if (type === 'center') { |
|
|
if (type === 'center') { |
|
|
this.lineDiffs.update.set(lineId, { startId: relatedId, endId: entity.id, type }) |
|
|
this.lineDiffs.update.set(lineId, { startId: relatedId, endId: entity.id, type }) |
|
|
@ -146,7 +148,7 @@ export default class EntityManager { |
|
|
if (!entity) return |
|
|
if (!entity) return |
|
|
|
|
|
|
|
|
option.originEntity = _.cloneDeep(entity) |
|
|
option.originEntity = _.cloneDeep(entity) |
|
|
this.writeBackEntities.add(entity.id) |
|
|
this.writeBackEntities.add(id) |
|
|
|
|
|
|
|
|
// 先生成线差量,再清理关系
|
|
|
// 先生成线差量,再清理关系
|
|
|
this.generateLineDiffsForDelete(id) |
|
|
this.generateLineDiffsForDelete(id) |
|
|
@ -162,6 +164,7 @@ export default class EntityManager { |
|
|
|
|
|
|
|
|
const removeLine = (relatedId: string, type: LinkType) => { |
|
|
const removeLine = (relatedId: string, type: LinkType) => { |
|
|
const lineId = getLineId(id, relatedId, type) |
|
|
const lineId = getLineId(id, relatedId, type) |
|
|
|
|
|
this.writeBackEntities.add(relatedId) |
|
|
this.lineDiffs.delete.set(lineId, { startId: id, endId: relatedId, type }) |
|
|
this.lineDiffs.delete.set(lineId, { startId: id, endId: relatedId, type }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -314,7 +317,7 @@ export default class EntityManager { |
|
|
if (!newIds.has(relatedId)) { |
|
|
if (!newIds.has(relatedId)) { |
|
|
const rev = this.relationIndex.get(relatedId) |
|
|
const rev = this.relationIndex.get(relatedId) |
|
|
rev.delete(relationType, id) |
|
|
rev.delete(relationType, id) |
|
|
this.writeBackEntities.add(id) |
|
|
this.writeBackEntities.add(relatedId) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -327,7 +330,7 @@ export default class EntityManager { |
|
|
this.relationIndex.set(relatedId, rev) |
|
|
this.relationIndex.set(relatedId, rev) |
|
|
} |
|
|
} |
|
|
rev.add(relationType, id) |
|
|
rev.add(relationType, id) |
|
|
this.writeBackEntities.add(id) |
|
|
this.writeBackEntities.add(relatedId) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -340,6 +343,10 @@ export default class EntityManager { |
|
|
for (const relatedId of oldIds) { |
|
|
for (const relatedId of oldIds) { |
|
|
if (!newIds.has(relatedId)) { |
|
|
if (!newIds.has(relatedId)) { |
|
|
const lineId = getLineId(id, relatedId, lineType) |
|
|
const lineId = getLineId(id, relatedId, lineType) |
|
|
|
|
|
|
|
|
|
|
|
// 如果这条线已经在 update 列表中,则跳过 delete
|
|
|
|
|
|
if (this.lineDiffs.update.has(lineId)) continue |
|
|
|
|
|
console.log(`[delete] ${id} -> ${relatedId} [${lineType}] => ${lineId}`) |
|
|
this.lineDiffs.delete.set(lineId, { startId: id, endId: relatedId, type: lineType }) |
|
|
this.lineDiffs.delete.set(lineId, { startId: id, endId: relatedId, type: lineType }) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -348,6 +355,10 @@ export default class EntityManager { |
|
|
for (const relatedId of newIds) { |
|
|
for (const relatedId of newIds) { |
|
|
if (!oldIds.has(relatedId)) { |
|
|
if (!oldIds.has(relatedId)) { |
|
|
const lineId = getLineId(id, relatedId, lineType) |
|
|
const lineId = getLineId(id, relatedId, lineType) |
|
|
|
|
|
|
|
|
|
|
|
// 如果这条线已经在 update 列表中,则跳过 create
|
|
|
|
|
|
if (this.lineDiffs.update.has(lineId)) continue |
|
|
|
|
|
|
|
|
this.lineDiffs.create.set(lineId, { startId: id, endId: relatedId, type: lineType }) |
|
|
this.lineDiffs.create.set(lineId, { startId: id, endId: relatedId, type: lineType }) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|