|
@@ -48,6 +48,7 @@ export default class Player {
|
|
|
this.renderMarkers = [];
|
|
|
this.activeEdges = [];
|
|
|
this.renderSymbols = [];
|
|
|
+ this.renderTexts = [];
|
|
|
this.matLine = null;
|
|
|
this.lineColor = 0xe44d54;
|
|
|
// 1是画线,2是标方向, 3符号, 4文本
|
|
@@ -57,7 +58,8 @@ export default class Player {
|
|
|
|
|
|
setMode(mode) {
|
|
|
this.mode = mode;
|
|
|
- if (mode === 1 || mode === 2) {
|
|
|
+
|
|
|
+ if (mode !== 0) {
|
|
|
this.reset();
|
|
|
this.setEditMode();
|
|
|
}
|
|
@@ -77,8 +79,10 @@ export default class Player {
|
|
|
let pos = new THREE.Vector3(0, 0, -1);
|
|
|
pos.unproject(this.orthCamera);
|
|
|
pos.y = 5;
|
|
|
- this.symbolIndex += 1;
|
|
|
- this.symbol = new CircleTextLabel(this.symbolIndex, true);
|
|
|
+ const lastIndex = this.getLaSybIndex();
|
|
|
+ this.symbolIndex = lastIndex + 1;
|
|
|
+
|
|
|
+ this.symbol = new CircleTextLabel(this.symbolIndex, pos);
|
|
|
this.symbol.visible = false;
|
|
|
this.scene.scene.add(this.symbol);
|
|
|
console.log("this.symbol", this.symbol);
|
|
@@ -89,8 +93,9 @@ export default class Player {
|
|
|
let pos = new THREE.Vector3(0, 0, -1);
|
|
|
pos.unproject(this.orthCamera);
|
|
|
pos.y = 5;
|
|
|
- this.text = new PureTextLabel(this.showText, true);
|
|
|
+ this.text = new PureTextLabel(this.showText, pos);
|
|
|
this.text.visible = false;
|
|
|
+ this.showText = "文本";
|
|
|
this.scene.scene.add(this.text);
|
|
|
this.drawing = true;
|
|
|
}
|
|
@@ -100,13 +105,16 @@ export default class Player {
|
|
|
}
|
|
|
this.scene.emit("mode", this.mode);
|
|
|
}
|
|
|
+ getLaSybIndex() {
|
|
|
+ const maxIndexObject = this.renderSymbols.reduce(
|
|
|
+ (max, current) => {
|
|
|
+ return current.index > max.index ? current : max;
|
|
|
+ },
|
|
|
+ { index: 0, point: [] }
|
|
|
+ );
|
|
|
+ return maxIndexObject.index;
|
|
|
+ }
|
|
|
|
|
|
- // removeMarker() {
|
|
|
- // if (this.marker) {
|
|
|
- // this.scene.scene.remove(this.marker);
|
|
|
- // this.marker = null;
|
|
|
- // }
|
|
|
- // }
|
|
|
setFreeMode() {
|
|
|
this.floorplanControls.enablePan = true;
|
|
|
this.floorplanControls.mouseButtons = {
|
|
@@ -228,6 +236,7 @@ export default class Player {
|
|
|
pos.unproject(this.orthCamera);
|
|
|
pos.y = 5;
|
|
|
this.text.position.copy(pos);
|
|
|
+ this.text.userData.pos = pos.toArray();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -244,10 +253,31 @@ export default class Player {
|
|
|
intersects.forEach((i) => {
|
|
|
if (
|
|
|
String(i.object.name).includes("marker") ||
|
|
|
- String(i.object.name).includes("line")
|
|
|
+ String(i.object.name).includes("line") ||
|
|
|
+ String(i.object.name).includes("circle") ||
|
|
|
+ String(i.object.name).includes("pureText")
|
|
|
) {
|
|
|
+ let type;
|
|
|
+ switch (true) {
|
|
|
+ case String(i.object.name).includes("marker"):
|
|
|
+ type = 1;
|
|
|
+ break;
|
|
|
+ case String(i.object.name).includes("line"):
|
|
|
+ type = 2;
|
|
|
+ break;
|
|
|
+ case String(i.object.name).includes("circle"):
|
|
|
+ type = 3;
|
|
|
+ break;
|
|
|
+ case String(i.object.name).includes("pureText"):
|
|
|
+ type = 4;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
this.selectItem = i.object;
|
|
|
- this.scene.emit("confirmDelete", i.object.uuid);
|
|
|
+ this.scene.emit("confirmDelete", {
|
|
|
+ id: i.object.uuid,
|
|
|
+ type,
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -312,11 +342,15 @@ export default class Player {
|
|
|
this.pointerdown.y,
|
|
|
-1
|
|
|
);
|
|
|
+ lasPos.unproject(this.orthCamera);
|
|
|
+ lasPos.y = 5;
|
|
|
+
|
|
|
const activeSymbolItem = {
|
|
|
- id: this.symbolIndex,
|
|
|
+ index: this.symbolIndex,
|
|
|
point: lasPos.toArray(),
|
|
|
};
|
|
|
this.renderSymbols.push(activeSymbolItem);
|
|
|
+ console.log("activeSymbolItem", activeSymbolItem);
|
|
|
this.setMode(0);
|
|
|
}
|
|
|
}
|
|
@@ -327,8 +361,13 @@ export default class Player {
|
|
|
this.pointerdown.y,
|
|
|
-1
|
|
|
);
|
|
|
- this.scene.emit("lockText");
|
|
|
- this.drawing = false;
|
|
|
+ this.scene.emit("edit", {
|
|
|
+ type: 4,
|
|
|
+ text: this.showText,
|
|
|
+ id: this.text.uuid,
|
|
|
+ ...this.text.userData,
|
|
|
+ });
|
|
|
+ this.drawing = true;
|
|
|
// const activeSymbolItem = {
|
|
|
// id: this.symbolIndex,
|
|
|
// point: lasPos.toArray(),
|
|
@@ -348,24 +387,44 @@ export default class Player {
|
|
|
if (this.drawLine) {
|
|
|
const points = this.drawLine.userData.points;
|
|
|
const dir = this.drawLine.userData.dir;
|
|
|
- const finishLine = new LinePoints(points, 0, this.matLine);
|
|
|
- this.renderLines.push(points);
|
|
|
- this.scene.scene.add(finishLine);
|
|
|
const imageId = this.touchImg.object.userData;
|
|
|
+ const finishLine = new LinePoints(points, this.matLine, dir, imageId);
|
|
|
|
|
|
+ this.scene.scene.add(finishLine);
|
|
|
const activeLineItem = {
|
|
|
+ id: finishLine.uuid,
|
|
|
+ imgId: imageId,
|
|
|
+ dir: dir,
|
|
|
+ points: points,
|
|
|
+ };
|
|
|
+ const activeEdgeItem = {
|
|
|
id: imageId,
|
|
|
dir: [dir],
|
|
|
};
|
|
|
|
|
|
+ this.renderLines.push(activeLineItem);
|
|
|
console.log("this.touchImg", activeLineItem, points);
|
|
|
- this.insertActiveEdge(activeLineItem);
|
|
|
+ this.insertActiveEdge(activeEdgeItem);
|
|
|
+ this.scene.scene.remove(this.drawLine);
|
|
|
this.drawLine = null;
|
|
|
}
|
|
|
}
|
|
|
if (this.mode === 2) {
|
|
|
// this.drawing = false;
|
|
|
}
|
|
|
+ if (this.mode === 4) {
|
|
|
+ if (this.text) {
|
|
|
+ let pos = new THREE.Vector3(this.pointerup.x, this.pointerup.y, -1);
|
|
|
+ pos.unproject(this.orthCamera);
|
|
|
+ pos.y = 5;
|
|
|
+ this.text.position.copy(pos);
|
|
|
+ this.text.userData.pos = pos.toArray();
|
|
|
+ const activeTextItem = this.text.userData;
|
|
|
+ this.drawing = false;
|
|
|
+ console.log("activeTextItem", activeTextItem);
|
|
|
+ this.insertrenderTexts(activeTextItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
this.syncDrawData();
|
|
|
};
|
|
|
|
|
@@ -487,6 +546,16 @@ export default class Player {
|
|
|
this.activeEdges.push(item);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ insertrenderTexts(item) {
|
|
|
+ const index = this.renderTexts.findIndex((s) => item.id === s.id);
|
|
|
+ if (index > -1) {
|
|
|
+ this.renderTexts[index] = item;
|
|
|
+ } else {
|
|
|
+ this.renderTexts.push(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
showAllActiveEdges() {
|
|
|
if (this.inited) {
|
|
|
let imgList = this.scene.boxManager.imgList;
|
|
@@ -495,9 +564,14 @@ export default class Player {
|
|
|
const exist = imgList.find((item) => item.userData === edge.id);
|
|
|
// console.log("exist", exist);
|
|
|
if (exist) {
|
|
|
+ let others = [0, 1, 2, 3].filter((x) => !edge.dir.includes(x));
|
|
|
edge.dir.forEach((dir) => {
|
|
|
exist.touchLines.children[dir].visible = true;
|
|
|
});
|
|
|
+ // console.log("others", others);
|
|
|
+ others.forEach((dir) => {
|
|
|
+ exist.touchLines.children[dir].visible = false;
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
@@ -512,6 +586,75 @@ export default class Player {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ deleteItemByType(type, data) {
|
|
|
+ if (type === 1) {
|
|
|
+ const index = this.renderMarkers.findIndex((mk) => {
|
|
|
+ const p = new THREE.Vector3().fromArray(mk.point);
|
|
|
+ const v = new THREE.Vector3().fromArray(data);
|
|
|
+ return p.equals(v);
|
|
|
+ });
|
|
|
+ this.renderMarkers.splice(index, 1);
|
|
|
+ }
|
|
|
+ if (type === 2) {
|
|
|
+ const { imgId, id, dir, points } = data;
|
|
|
+ const index = this.renderLines.findIndex((item) => item.id === id);
|
|
|
+ index > -1 && this.renderLines.splice(index, 1);
|
|
|
+ //线段处理完成
|
|
|
+ const egIndex = this.activeEdges.findIndex((eg) => eg.id === imgId);
|
|
|
+ if (egIndex > -1) {
|
|
|
+ //存在activeEdge 再找renderLines的sibling
|
|
|
+ const cluEgArr = this.renderLines
|
|
|
+ .filter((l) => l.imgId === this.activeEdges[egIndex].id)
|
|
|
+ .reduce((pre, curr) => pre.concat(curr["dir"]), []);
|
|
|
+ const uni_dir = [...new Set(cluEgArr)];
|
|
|
+ console.log("uni_dir", uni_dir);
|
|
|
+ if (uni_dir.length > 0) {
|
|
|
+ this.activeEdges[egIndex].dir = uni_dir;
|
|
|
+ } else {
|
|
|
+ this.activeEdges.splice(egIndex, 1);
|
|
|
+ }
|
|
|
+ console.log("exist", this.activeEdges);
|
|
|
+ // this.showAllActiveEdges();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (type === 3) {
|
|
|
+ const index = this.renderSymbols.findIndex((syb) => {
|
|
|
+ const p = new THREE.Vector3().fromArray(syb.point);
|
|
|
+ const v = new THREE.Vector3().fromArray(data);
|
|
|
+ return p.equals(v);
|
|
|
+ });
|
|
|
+ this.renderSymbols.splice(index, 1);
|
|
|
+ }
|
|
|
+ if (type === 4) {
|
|
|
+ const { id } = data;
|
|
|
+ const index = this.renderTexts.findIndex((item) => item.id === id);
|
|
|
+ index > -1 && this.renderTexts.splice(index, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ editing(item) {
|
|
|
+ if (item.type === 4) {
|
|
|
+ if (this.text) {
|
|
|
+ const { pos } = this.text.userData;
|
|
|
+ const newP = new THREE.Vector3().fromArray(pos);
|
|
|
+ this.scene.scene.remove(this.text);
|
|
|
+ this.text = null;
|
|
|
+ this.showText = item.text;
|
|
|
+ console.log("editing", item, newP);
|
|
|
+ // // console.log("this.text", lastPos, newP, item);
|
|
|
+ this.text = new PureTextLabel(
|
|
|
+ item.text,
|
|
|
+ newP,
|
|
|
+ item.fontsize,
|
|
|
+ item.color,
|
|
|
+ item.id
|
|
|
+ );
|
|
|
+ this.scene.scene.add(this.text);
|
|
|
+ const activeTextItem = this.text.userData;
|
|
|
+ console.log("activeTextItem", activeTextItem);
|
|
|
+ this.insertrenderTexts(activeTextItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
getDrawData() {
|
|
|
let data;
|
|
|
if (this.scene.sceneType === 1) {
|
|
@@ -519,18 +662,26 @@ export default class Player {
|
|
|
hor_lines: this.renderLines,
|
|
|
hor_activeEdges: this.activeEdges,
|
|
|
hor_markers: this.renderMarkers,
|
|
|
+ hor_symbols: this.renderSymbols,
|
|
|
+ hor_texts: this.renderTexts,
|
|
|
vir_lines: [],
|
|
|
vir_activeEdges: [],
|
|
|
vir_markers: [],
|
|
|
+ vir_symbols: [],
|
|
|
+ vir_texts: [],
|
|
|
};
|
|
|
} else {
|
|
|
data = {
|
|
|
hor_lines: [],
|
|
|
hor_activeEdges: [],
|
|
|
hor_markers: [],
|
|
|
+ hor_symbols: [],
|
|
|
+ hor_texts: [],
|
|
|
vir_lines: this.renderLines,
|
|
|
vir_activeEdges: this.activeEdges,
|
|
|
vir_markers: this.renderMarkers,
|
|
|
+ vir_symbols: this.renderSymbols,
|
|
|
+ vir_texts: this.renderTexts,
|
|
|
};
|
|
|
}
|
|
|
|
|
@@ -545,12 +696,24 @@ export default class Player {
|
|
|
load(type, data) {
|
|
|
if (type === 1) {
|
|
|
console.log("data1", data);
|
|
|
- const { hor_activeEdges, hor_lines, hor_markers } = data;
|
|
|
+ const {
|
|
|
+ hor_activeEdges,
|
|
|
+ hor_lines,
|
|
|
+ hor_markers,
|
|
|
+ hor_symbols,
|
|
|
+ hor_texts,
|
|
|
+ } = data;
|
|
|
hor_activeEdges && (this.activeEdges = hor_activeEdges);
|
|
|
if (hor_lines && Array.isArray(hor_lines)) {
|
|
|
this.renderLines = hor_lines;
|
|
|
hor_lines.forEach((line) => {
|
|
|
- const finishLine = new LinePoints(line, 0, this.matLine);
|
|
|
+ const finishLine = new LinePoints(
|
|
|
+ line.points,
|
|
|
+ this.matLine,
|
|
|
+ line.dir,
|
|
|
+ line.imgId,
|
|
|
+ line.id
|
|
|
+ );
|
|
|
this.scene.scene.add(finishLine);
|
|
|
});
|
|
|
}
|
|
@@ -563,15 +726,52 @@ export default class Player {
|
|
|
this.scene.scene.add(marker);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ if (hor_symbols && Array.isArray(hor_symbols)) {
|
|
|
+ this.renderSymbols = hor_symbols;
|
|
|
+ hor_symbols.forEach((syb) => {
|
|
|
+ console.log("pos");
|
|
|
+ const p = new THREE.Vector3().fromArray(syb.point);
|
|
|
+ const symbol = new CircleTextLabel(syb.index, p);
|
|
|
+ this.scene.scene.add(symbol);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (hor_texts && Array.isArray(hor_texts)) {
|
|
|
+ this.renderTexts = hor_texts;
|
|
|
+ hor_texts.forEach((txt) => {
|
|
|
+ console.log("pos");
|
|
|
+ const p = new THREE.Vector3().fromArray(txt.pos);
|
|
|
+ const text = new PureTextLabel(
|
|
|
+ txt.text,
|
|
|
+ p,
|
|
|
+ txt.fontsize,
|
|
|
+ txt.color,
|
|
|
+ txt.id
|
|
|
+ );
|
|
|
+ this.scene.scene.add(text);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (type === 2) {
|
|
|
- const { vir_activeEdges, vir_lines, vir_markers } = data;
|
|
|
+ const {
|
|
|
+ vir_activeEdges,
|
|
|
+ vir_lines,
|
|
|
+ vir_markers,
|
|
|
+ vir_symbols,
|
|
|
+ vir_texts,
|
|
|
+ } = data;
|
|
|
vir_activeEdges && (this.activeEdges = vir_activeEdges);
|
|
|
if (vir_lines && Array.isArray(vir_lines)) {
|
|
|
this.renderLines = vir_lines;
|
|
|
vir_lines.forEach((line) => {
|
|
|
- const finishLine = new LinePoints(line, 0, this.matLine);
|
|
|
+ const finishLine = new LinePoints(
|
|
|
+ line.points,
|
|
|
+ this.matLine,
|
|
|
+ line.dir,
|
|
|
+ line.imgId,
|
|
|
+ line.id
|
|
|
+ );
|
|
|
this.scene.scene.add(finishLine);
|
|
|
});
|
|
|
}
|
|
@@ -583,6 +783,30 @@ export default class Player {
|
|
|
this.scene.scene.add(marker);
|
|
|
});
|
|
|
}
|
|
|
+ if (vir_symbols && Array.isArray(vir_symbols)) {
|
|
|
+ this.renderSymbols = vir_symbols;
|
|
|
+ vir_symbols.forEach((syb) => {
|
|
|
+ // console.log("pos", syb);
|
|
|
+ const p = new THREE.Vector3().fromArray(syb.point);
|
|
|
+ const symbol = new CircleTextLabel(syb.index, p);
|
|
|
+ this.scene.scene.add(symbol);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (vir_texts && Array.isArray(vir_texts)) {
|
|
|
+ this.renderTexts = vir_texts;
|
|
|
+ vir_texts.forEach((txt) => {
|
|
|
+ console.log("pos");
|
|
|
+ const p = new THREE.Vector3().fromArray(txt.pos);
|
|
|
+ const text = new PureTextLabel(
|
|
|
+ txt.text,
|
|
|
+ p,
|
|
|
+ txt.fontsize,
|
|
|
+ txt.color,
|
|
|
+ txt.id
|
|
|
+ );
|
|
|
+ this.scene.scene.add(text);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
this.syncDrawData();
|
|
|
}
|
|
@@ -601,6 +825,11 @@ export default class Player {
|
|
|
if (this.activeEdge) {
|
|
|
this.activeEdge = null;
|
|
|
}
|
|
|
+ if (this.text) {
|
|
|
+ this.text = null;
|
|
|
+ this.scene.scene.remove(this.text);
|
|
|
+ }
|
|
|
+ this.showText = "文本";
|
|
|
this.drawing = false;
|
|
|
}
|
|
|
|
|
@@ -608,6 +837,8 @@ export default class Player {
|
|
|
this.activeEdges = [];
|
|
|
this.renderLines = [];
|
|
|
this.renderMarkers = [];
|
|
|
+ this.renderSymbols = [];
|
|
|
+ this.renderTexts = [];
|
|
|
this.reset();
|
|
|
this.scene.clearDrawScene();
|
|
|
this.syncDrawData();
|