VerticalBox.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import * as THREE from "three";
  2. import TextLabel from "./object/TextLabel";
  3. import ImgLabel from "./object/ImgLabel";
  4. import SimpleLabel from "./object/SimpleLabel";
  5. import { LineMaterial } from "three/examples/jsm/lines/LineMaterial.js";
  6. export default class VerticalBox extends THREE.Group {
  7. constructor(manager, data, index, total) {
  8. super();
  9. this.manager = manager;
  10. this.total = total;
  11. this.name = "vertical_box";
  12. this.getStyle();
  13. this.load(data, index);
  14. }
  15. getStyle() {
  16. this.width = 2;
  17. this.height = (2 * 710) / 500;
  18. this.color = 0xffffff;
  19. }
  20. load(data, index) {
  21. //box
  22. const geometry = new THREE.PlaneGeometry(1, 1);
  23. geometry.rotateX(-Math.PI / 2);
  24. const bm = new THREE.MeshBasicMaterial({
  25. color: this.color,
  26. });
  27. const box = new THREE.Mesh(geometry, bm);
  28. box.scale.set(this.width, 1, this.height);
  29. this.add(box);
  30. this.position.x = (this.width + 0.125) * index;
  31. const matLine = new LineMaterial({
  32. color: 0xe44d54,
  33. linewidth: 3, // in world units with size attenuation, pixels otherwise
  34. dashed: false,
  35. alphaToCoverage: true,
  36. });
  37. matLine.resolution = new THREE.Vector2(
  38. this.manager.scene.width,
  39. this.manager.scene.height
  40. );
  41. //content
  42. data.forEach((i, j) => {
  43. //img
  44. let img;
  45. this.manager.loader.load(i.imgUrl, (texture) => {
  46. texture.colorSpace = THREE.SRGBColorSpace;
  47. img = new ImgLabel(texture, matLine, false);
  48. img.position.y += 1;
  49. img.position.z -= 0.2;
  50. this.add(img);
  51. this.manager.imgList.push(img);
  52. const textlabel = new TextLabel(i.imgInfo, true);
  53. this.add(textlabel);
  54. textlabel.position.copy(img.position);
  55. textlabel.position.z += textlabel.scale.z * 0.5 + 0.7;
  56. });
  57. });
  58. //页脚
  59. const f_txt_label = ` 第 ${index + 1} 页 共 ${this.total} 页`;
  60. const footlabel = new SimpleLabel(f_txt_label, true);
  61. footlabel.renderOrder = 100;
  62. footlabel.position.z += 1.26;
  63. this.add(footlabel);
  64. }
  65. }