Source: GroundPlane.js

  1. /*jshint esversion: 6 */
  2. // @ts-check
  3. /**
  4. * CS559 3D World Framework Code
  5. *
  6. * Example Object Type: Ground Plane
  7. *
  8. * This object is completely static and simple, so it's good to learn
  9. * from. It's also convenient to use.
  10. *
  11. * There are a few variants of the ground plane. We'll give the simple ones
  12. * at first, since students will make better ones in later projects.
  13. */
  14. // we need to have the BaseClass definition
  15. import { GrObject } from "./GrObject.js";
  16. // a global variable to keep track of how many objects we create
  17. // this allows us to give unique names
  18. let numberOfGrounds = 0;
  19. // these four lines fake out TypeScript into thinking that THREE
  20. // has the same type as the T.js module, so things work for type checking
  21. // type inferencing figures out that THREE has the same type as T
  22. // and then I have to use T (not THREE) to avoid the "UMD Module" warning
  23. /** @type typeof import("./../THREE/threets/index"); */
  24. let T;
  25. // @ts-ignore
  26. T=THREE;
  27. /**
  28. * This is the simplest - just a solid grey box
  29. * Mainly for testing
  30. */
  31. export class SimpleGroundPlane extends GrObject {
  32. /**
  33. * The size is in each direction (so X goes from -size to +size)
  34. * Thickness is because the object is a box (like a table top)
  35. *
  36. * @param {Number} size=5
  37. * @param {Number} thickness=0.2
  38. * @param {string|Number} [color="white"]
  39. */
  40. constructor(size=5, thickness=0.2,color="white") {
  41. // we need to create the parts before we can call "super"
  42. let geom = new T.BoxGeometry(size*2,thickness,size*2);
  43. let material = new T.MeshStandardMaterial( {color:color,roughness:0.9});
  44. let mesh = new T.Mesh(geom,material);
  45. numberOfGrounds += 1;
  46. // set up the base class
  47. super(`SimpleGroundPlane-${numberOfGrounds}`,mesh);
  48. // now we can set up "this" - we have to do this after we call super
  49. this.geom = geom;
  50. this.material = material;
  51. this.mesh = mesh;
  52. this.size = size;
  53. this.height = thickness/2;
  54. // put the box into the right place
  55. this.mesh.position.y = -thickness/2;
  56. }
  57. // animation doesn't do anything, but we have it anyway
  58. advance(delta, timeOfDay) {
  59. // just sits there
  60. }
  61. // parameter changing doesn't do anything, as there are no parameters
  62. update(values) {
  63. }
  64. }