HorizontalBox.js 1.8 KB

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