board.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import * as three from "three";
  2. export default class Board{
  3. constructor(scene, width, height, length){
  4. this.scene = scene;
  5. this.width = width;
  6. this.height = height;
  7. this.length = length;
  8. this.type = `${width}x${height}`;
  9. const geometry = new three.BoxGeometry(width, height, length);
  10. const edges = new three.EdgesGeometry(geometry);
  11. const lineMaterial = new three.LineBasicMaterial({color: 0xffffff});
  12. const line = new three.LineSegments(edges, lineMaterial);
  13. const material = new three.MeshBasicMaterial({color: 0x7a4300});
  14. const board = new three.Mesh(geometry, material);
  15. this.board = new three.Group();
  16. this.board.add(board);
  17. this.board.add(line);
  18. scene.add(this.board);
  19. }
  20. translate(x, y, z){
  21. this.board.position.x += x;
  22. this.board.position.y += y;
  23. this.board.position.z += z;
  24. }
  25. rotate(x, y, z){
  26. this.board.rotation.x += this.toRadians(x);
  27. this.board.rotation.y += this.toRadians(y);
  28. this.board.rotation.z += this.toRadians(z);
  29. }
  30. surfaceArea(){
  31. let w = this.width;
  32. let l = this.length;
  33. let h = this.height;
  34. return 2*((w*l)+(l*h)+(h*w));
  35. }
  36. toRadians(n){
  37. return n*(Math.PI/180);
  38. }
  39. }