|
@@ -2,10 +2,12 @@ import * as THREE from "three";
|
|
|
|
|
|
import FloorplanControls from "../controls/FloorplanControls.js";
|
|
import FloorplanControls from "../controls/FloorplanControls.js";
|
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
|
|
+
|
|
import { TrackballControls } from "three/examples/jsm/controls/TrackballControls.js";
|
|
import { TrackballControls } from "three/examples/jsm/controls/TrackballControls.js";
|
|
import Line from "../box/object/Line";
|
|
import Line from "../box/object/Line";
|
|
import LinePoints from "../box/object/LinePoints.js";
|
|
import LinePoints from "../box/object/LinePoints.js";
|
|
import Marker from "../box/object/marker.js";
|
|
import Marker from "../box/object/marker.js";
|
|
|
|
+import CircleTextLabel from "../box/object/CircleTextLabel.js";
|
|
import { LineMaterial } from "three/examples/jsm/lines/LineMaterial.js";
|
|
import { LineMaterial } from "three/examples/jsm/lines/LineMaterial.js";
|
|
|
|
|
|
const convertScreenToNDC = function (event, domElement) {
|
|
const convertScreenToNDC = function (event, domElement) {
|
|
@@ -33,16 +35,20 @@ export default class Player {
|
|
this.drawLine = null;
|
|
this.drawLine = null;
|
|
this.startObj = null;
|
|
this.startObj = null;
|
|
this.marker = null;
|
|
this.marker = null;
|
|
- this.allowDrawing = false;
|
|
|
|
|
|
+ this.symbol = null;
|
|
|
|
+ this.symbolIndex = 0;
|
|
|
|
+ this.text = null;
|
|
|
|
+ this.selectItem = null;
|
|
|
|
|
|
this.drawing = false;
|
|
this.drawing = false;
|
|
this.inited = false;
|
|
this.inited = false;
|
|
this.renderLines = [];
|
|
this.renderLines = [];
|
|
this.renderMarkers = [];
|
|
this.renderMarkers = [];
|
|
this.activeEdges = [];
|
|
this.activeEdges = [];
|
|
|
|
+ this.renderSymbols = [];
|
|
this.matLine = null;
|
|
this.matLine = null;
|
|
this.lineColor = 0xe44d54;
|
|
this.lineColor = 0xe44d54;
|
|
- // 1是画线,2是标方向
|
|
|
|
|
|
+ // 1是画线,2是标方向, 3符号, 4文本
|
|
this.mode = 0;
|
|
this.mode = 0;
|
|
this.init();
|
|
this.init();
|
|
}
|
|
}
|
|
@@ -53,6 +59,36 @@ export default class Player {
|
|
this.reset();
|
|
this.reset();
|
|
this.setEditMode();
|
|
this.setEditMode();
|
|
}
|
|
}
|
|
|
|
+ // 2方向
|
|
|
|
+ if (mode === 2) {
|
|
|
|
+ let pos = new THREE.Vector3(0, 0, -1);
|
|
|
|
+ pos.unproject(this.orthCamera);
|
|
|
|
+ pos.y = 5;
|
|
|
|
+
|
|
|
|
+ this.marker = new Marker(pos);
|
|
|
|
+ this.marker.visible = false;
|
|
|
|
+ this.scene.scene.add(this.marker);
|
|
|
|
+ this.drawing = true;
|
|
|
|
+ }
|
|
|
|
+ //符号
|
|
|
|
+ if (mode === 3) {
|
|
|
|
+ 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);
|
|
|
|
+ this.symbol.visible = false;
|
|
|
|
+ this.scene.scene.add(this.symbol);
|
|
|
|
+ console.log("this.symbol", this.symbol);
|
|
|
|
+ this.drawing = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (mode === 4) {
|
|
|
|
+ let pos = new THREE.Vector3(0, 0, -1);
|
|
|
|
+ pos.unproject(this.orthCamera);
|
|
|
|
+ pos.y = 5;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (mode === 0) {
|
|
if (mode === 0) {
|
|
this.setFreeMode();
|
|
this.setFreeMode();
|
|
}
|
|
}
|
|
@@ -129,10 +165,25 @@ export default class Player {
|
|
};
|
|
};
|
|
|
|
|
|
onPointerMove = (e) => {
|
|
onPointerMove = (e) => {
|
|
- if (!this.drawing) return;
|
|
|
|
|
|
+ // console.log("intersects", intersects);
|
|
|
|
+ // if (this.mode === 0) {
|
|
|
|
+ // const intersects = this.raycaster.intersectObjects(
|
|
|
|
+ // this.scene.scene.children,
|
|
|
|
+ // true
|
|
|
|
+ // );
|
|
|
|
+ // intersects.forEach((i) => {
|
|
|
|
+ // if (String(i.object.name).includes("marker")) {
|
|
|
|
+ // // console.log("i.object.name", i.object);
|
|
|
|
+ // // debugger
|
|
|
|
+ // }
|
|
|
|
+ // });
|
|
|
|
+ // }
|
|
this.pointermove = convertScreenToNDC(e, this.scene.domElement);
|
|
this.pointermove = convertScreenToNDC(e, this.scene.domElement);
|
|
|
|
+ this.raycaster.setFromCamera(this.pointermove, this.orthCamera);
|
|
|
|
+
|
|
|
|
+ if (!this.drawing) return;
|
|
|
|
+
|
|
if (this.mode === 1) {
|
|
if (this.mode === 1) {
|
|
- this.raycaster.setFromCamera(this.pointermove, this.orthCamera);
|
|
|
|
let intersectArr = this.scene.boxManager.imgList;
|
|
let intersectArr = this.scene.boxManager.imgList;
|
|
// if(this.startObj) {
|
|
// if(this.startObj) {
|
|
// let i = intersectArr.indexOf(this.startObj)
|
|
// let i = intersectArr.indexOf(this.startObj)
|
|
@@ -146,6 +197,7 @@ export default class Player {
|
|
}
|
|
}
|
|
if (this.mode === 2) {
|
|
if (this.mode === 2) {
|
|
if (this.marker) {
|
|
if (this.marker) {
|
|
|
|
+ this.marker.visible = true;
|
|
let pos = new THREE.Vector3(this.pointermove.x, this.pointermove.y, -1);
|
|
let pos = new THREE.Vector3(this.pointermove.x, this.pointermove.y, -1);
|
|
pos.unproject(this.orthCamera);
|
|
pos.unproject(this.orthCamera);
|
|
pos.y = 5;
|
|
pos.y = 5;
|
|
@@ -153,11 +205,40 @@ export default class Player {
|
|
this.marker.position.copy(pos);
|
|
this.marker.position.copy(pos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (this.mode === 3) {
|
|
|
|
+ if (this.symbol) {
|
|
|
|
+ this.symbol.visible = true;
|
|
|
|
+ let pos = new THREE.Vector3(this.pointermove.x, this.pointermove.y, -1);
|
|
|
|
+ pos.unproject(this.orthCamera);
|
|
|
|
+ pos.y = 5;
|
|
|
|
+ // console.log("pos", pos);
|
|
|
|
+ // console.log("symbol", this.symbol);
|
|
|
|
+ this.symbol.position.copy(pos);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
onPointerDown = (e) => {
|
|
onPointerDown = (e) => {
|
|
console.log("start draw");
|
|
console.log("start draw");
|
|
this.pointerdown = convertScreenToNDC(e, this.scene.domElement);
|
|
this.pointerdown = convertScreenToNDC(e, this.scene.domElement);
|
|
|
|
+
|
|
|
|
+ if (this.mode === 0) {
|
|
|
|
+ const intersects = this.raycaster.intersectObjects(
|
|
|
|
+ this.scene.scene.children,
|
|
|
|
+ true
|
|
|
|
+ );
|
|
|
|
+ intersects.forEach((i) => {
|
|
|
|
+ if (
|
|
|
|
+ String(i.object.name).includes("marker") ||
|
|
|
|
+ String(i.object.name).includes("line")
|
|
|
|
+ ) {
|
|
|
|
+ this.selectItem = i.object;
|
|
|
|
+ this.scene.emit("confirmDelete", i.object.uuid);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this.mode === 1) {
|
|
if (this.mode === 1) {
|
|
this.raycaster.setFromCamera(this.pointerdown, this.orthCamera);
|
|
this.raycaster.setFromCamera(this.pointerdown, this.orthCamera);
|
|
let intersectArr = this.scene.boxManager.imgList;
|
|
let intersectArr = this.scene.boxManager.imgList;
|
|
@@ -173,15 +254,7 @@ export default class Player {
|
|
}
|
|
}
|
|
|
|
|
|
if (this.mode === 2) {
|
|
if (this.mode === 2) {
|
|
- if (!this.marker) {
|
|
|
|
- let pos = new THREE.Vector3(this.pointerdown.x, this.pointerdown.y, -1);
|
|
|
|
- pos.unproject(this.orthCamera);
|
|
|
|
- pos.y = 5;
|
|
|
|
- this.marker = new Marker(pos);
|
|
|
|
- this.scene.scene.add(this.marker);
|
|
|
|
- this.drawing = true;
|
|
|
|
- } else {
|
|
|
|
- // this.drawing = false;
|
|
|
|
|
|
+ if (this.marker) {
|
|
this.raycaster.setFromCamera(this.pointerdown, this.orthCamera);
|
|
this.raycaster.setFromCamera(this.pointerdown, this.orthCamera);
|
|
let intersectArr = this.scene.boxManager.imgList;
|
|
let intersectArr = this.scene.boxManager.imgList;
|
|
const intersects = this.raycaster.intersectObjects(intersectArr, false);
|
|
const intersects = this.raycaster.intersectObjects(intersectArr, false);
|
|
@@ -214,15 +287,30 @@ export default class Player {
|
|
}
|
|
}
|
|
|
|
|
|
console.log("activeMarkeritem", activeMarkeritem);
|
|
console.log("activeMarkeritem", activeMarkeritem);
|
|
|
|
+ this.setMode(0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // this.floorplanControls.enabled = false;
|
|
|
|
|
|
+
|
|
|
|
+ if (this.mode === 3) {
|
|
|
|
+ if (this.symbol) {
|
|
|
|
+ let lasPos = new THREE.Vector3(
|
|
|
|
+ this.pointerdown.x,
|
|
|
|
+ this.pointerdown.y,
|
|
|
|
+ -1
|
|
|
|
+ );
|
|
|
|
+ const activeSymbolItem = {
|
|
|
|
+ id: this.symbolIndex,
|
|
|
|
+ point: lasPos.toArray(),
|
|
|
|
+ };
|
|
|
|
+ this.renderSymbols.push(activeSymbolItem);
|
|
|
|
+ this.setMode(0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
};
|
|
};
|
|
onPointerUp = (e) => {
|
|
onPointerUp = (e) => {
|
|
this.pointerup = convertScreenToNDC(e, this.scene.domElement);
|
|
this.pointerup = convertScreenToNDC(e, this.scene.domElement);
|
|
- console.log("onPointerUp", this.pointerup);
|
|
|
|
-
|
|
|
|
|
|
+ // console.log("onPointerUp", this.pointerup);
|
|
if (this.mode === 1) {
|
|
if (this.mode === 1) {
|
|
this.drawing = false;
|
|
this.drawing = false;
|
|
this.floorplanControls.enabled = true;
|
|
this.floorplanControls.enabled = true;
|
|
@@ -425,7 +513,6 @@ export default class Player {
|
|
this.scene.emit("data", data);
|
|
this.scene.emit("data", data);
|
|
}
|
|
}
|
|
load(type, data) {
|
|
load(type, data) {
|
|
-
|
|
|
|
if (type === 1) {
|
|
if (type === 1) {
|
|
console.log("data1", data);
|
|
console.log("data1", data);
|
|
const { hor_activeEdges, hor_lines, hor_markers } = data;
|
|
const { hor_activeEdges, hor_lines, hor_markers } = data;
|