cheapBoard.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import * as three from "three";
  2. import Board from "Board";
  3. export default class CheapBoard extends Board{
  4. constructor(scene, length){
  5. this.scene = scene;
  6. this.dimensions = [0.625, 5.5, length];
  7. const loader = new three.TextureLoader();
  8. const texture = loader.load("/wood-material.jpg", (t)=>{
  9. t.wrapS = t.wrapT = three.RepeatWrapping;
  10. t.offset.set(0, 0);
  11. t.repeat.set(length / 24, 3);
  12. });
  13. texture.colorSpace = three.SRGBColorSpace;
  14. const geometry = new three.BoxGeometry(0.625, 5.5, length);
  15. const edges = new three.EdgesGeometry(geometry);
  16. const lineMaterial = new three.LineBasicMaterial({color: 0xffffff});
  17. const line = new three.LineSegments(edges, lineMaterial);
  18. const material = new three.MeshBasicMaterial({map: texture});
  19. const board = new three.Mesh(geometry, material);
  20. this.board = new three.Group();
  21. this.board.add(board);
  22. this.board.add(line);
  23. scene.add(this.board);
  24. }
  25. translate(x, y, z){
  26. this.board.position.x += x;
  27. this.board.position.y += y;
  28. this.board.position.z += z;
  29. }
  30. rotate(x, y, z){
  31. let toRadians = (n)=>n*(Math.PI/180);
  32. this.board.rotation.x += toRadians(x);
  33. this.board.rotation.y += toRadians(y);
  34. this.board.rotation.z += toRadians(z);
  35. }
  36. clone(){
  37. let newBoard = new CheapBoard(this.scene, this.dimensions[2]);
  38. this.copyBoardData(newBoard.board);
  39. return newBoard;
  40. }
  41. surfaceArea(){
  42. let w = this.dimensions[0];
  43. let l = this.dimensions[1];
  44. let h = this.dimentsions[2];
  45. return 2 * ((w * l) + (l * h) + (h * w));
  46. }
  47. }