123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import * as THREE from "three";
- import { Line2 } from "three/examples/jsm/lines/Line2.js";
- import { LineGeometry } from "three/examples/jsm/lines/LineGeometry.js";
- import gotoPic from "@/assets/image/goto.png";
- const offset = 0.25;
- function pointsToArray(arr) {
- let res = [];
- arr.forEach((i) => {
- res = res.concat(i.toArray());
- });
- return res;
- }
- let m = new THREE.MeshBasicMaterial({
- map: new THREE.TextureLoader().load(gotoPic),
- color: 0x26559b,
- transparent: true,
- });
- export default class Line extends Line2 {
- constructor(startPoint, endPoint, endEdge, matLine) {
- let points;
- let g = new THREE.PlaneGeometry(0.1, 0.1);
- g.rotateX(-Math.PI / 2);
- let cross = new THREE.Mesh(g, m);
- if (endEdge.name === 0) {
- // top
- let a = startPoint.clone();
- let b = new THREE.Vector3(
- startPoint.x,
- startPoint.y,
- endEdge.y + endEdge.parent.parent.position.z - offset
- );
- let c = new THREE.Vector3(
- endPoint.x,
- endPoint.y,
- endEdge.y + endEdge.parent.parent.position.z - offset
- );
- let d = new THREE.Vector3(
- endPoint.x,
- endPoint.y,
- endEdge.y + endEdge.parent.parent.position.z
- );
- cross.position.copy(d);
- cross.rotation.y = -Math.PI / 2;
- cross.position.z -= 0.02;
- points = pointsToArray([a, b, c, d]);
- } else if (endEdge.name === 1) {
- //left
- let a = startPoint.clone();
- let b = new THREE.Vector3(
- (startPoint.x + endPoint.x) / 2,
- startPoint.y,
- startPoint.z
- );
- let c = new THREE.Vector3(
- (startPoint.x + endPoint.x) / 2,
- startPoint.y,
- endPoint.z
- );
- let d = new THREE.Vector3(
- endEdge.x + endEdge.parent.parent.parent.position.x,
- startPoint.y,
- endPoint.z
- );
- cross.position.copy(d);
- const diff = c.x < d.x;
- cross.rotation.y = diff ? 0 : -Math.PI;
- diff ? (cross.position.x -= 0.02) : (cross.position.x += 0.02);
- points = pointsToArray([a, b, c, d]);
- } else if (endEdge.name === 2) {
- //bottom
- let a = startPoint.clone();
- let b = new THREE.Vector3(
- startPoint.x,
- startPoint.y,
- endEdge.y + endEdge.parent.parent.position.z + offset
- );
- let c = new THREE.Vector3(
- endPoint.x,
- endPoint.y,
- endEdge.y + endEdge.parent.parent.position.z + offset
- );
- let d = new THREE.Vector3(
- endPoint.x,
- endPoint.y,
- endEdge.y + endEdge.parent.parent.position.z
- );
- cross.rotation.y = Math.PI / 2;
- cross.position.copy(d);
- cross.position.z += 0.02;
- points = pointsToArray([a, b, c, d]);
- } else {
- //right
- let a = startPoint.clone();
- let b = new THREE.Vector3(
- (startPoint.x + endPoint.x) / 2,
- startPoint.y,
- startPoint.z
- );
- let c = new THREE.Vector3(
- (startPoint.x + endPoint.x) / 2,
- startPoint.y,
- endPoint.z
- );
- let d = new THREE.Vector3(
- endEdge.x + endEdge.parent.parent.parent.position.x,
- startPoint.y,
- endPoint.z
- );
- const diff = c.x < d.x;
- cross.position.copy(d);
- cross.rotation.y = diff ? 0 : Math.PI;
- diff ? (cross.position.x -= 0.02) : (cross.position.x += 0.02);
- points = pointsToArray([a, b, c, d]);
- }
- const geometry = new LineGeometry();
- console.log("points", points);
- // console.log("endEdge", endEdge.name);
- geometry.setPositions(points);
- super(geometry, matLine);
- this.scale.set(1, 1, 1);
- this.position.y += 0.5;
- this.add(cross);
- }
- }
|