ImgLabel.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import * as THREE from "three";
  2. import TouchEdge from "./TouchEdge";
  3. export default class ImgLabel extends THREE.Mesh {
  4. constructor(texture, matLine, isHorizontal = true) {
  5. let width, height, p;
  6. if (isHorizontal) {
  7. width = 1.5;
  8. height = 0.85;
  9. p = [
  10. [-0.75, 0, -0.425, 0.75, 0, -0.425],
  11. [-0.75, 0, -0.425, -0.75, 0, 0.425],
  12. [-0.75, 0, 0.425, 0.75, 0, 0.425],
  13. [0.75, 0, 0.425, 0.75, 0, -0.425],
  14. ];
  15. } else {
  16. width = 1.5;
  17. height = 2;
  18. p = [
  19. [-0.75, 0, -1, 0.75, 0, -1],
  20. [-0.75, 0, -1, -0.75, 0, 1],
  21. [-0.75, 0, 1, 0.75, 0, 1],
  22. [0.75, 0, 1, 0.75, 0, -1],
  23. ];
  24. }
  25. const g = new THREE.PlaneGeometry(width, height);
  26. g.rotateX(-Math.PI / 2);
  27. const m = new THREE.MeshBasicMaterial({
  28. map: texture,
  29. });
  30. super(g, m);
  31. this.width = width;
  32. this.height = height;
  33. this.touchLines = new TouchEdge(p, matLine);
  34. this.touchLines.position.y += 0.5;
  35. this.add(this.touchLines);
  36. // this.touchLines.children.forEach((child) => (child.visible = true));
  37. this.name = "imglabel";
  38. }
  39. }