main.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js';
  2. import {GUI} from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/libs/dat.gui.module.js';
  3. import {controls} from './controls.js';
  4. import {game} from './game.js';
  5. import {sky} from './sky.js';
  6. import {terrain} from './terrain.js';
  7. import {textures} from './textures.js';
  8. let _APP = null;
  9. class ProceduralTerrain_Demo extends game.Game {
  10. constructor() {
  11. super();
  12. }
  13. _OnInitialize() {
  14. this._CreateGUI();
  15. this._userCamera = new THREE.Object3D();
  16. this._userCamera.position.set(4100, 0, 0);
  17. this._graphics.Camera.position.set(3853, -609, -1509);
  18. this._graphics.Camera.quaternion.set(0.403, 0.59, -0.549, 0.432);
  19. this._graphics.Camera.position.set(1412, -1674, -3848);
  20. this._graphics.Camera.quaternion.set(0.1004, 0.7757, -0.6097, 0.1278);
  21. this._entities['_terrain'] = new terrain.TerrainChunkManager({
  22. camera: this._graphics.Camera,
  23. scene: this._graphics.Scene,
  24. gui: this._gui,
  25. guiParams: this._guiParams,
  26. game: this
  27. });
  28. this._entities['_controls'] = new controls.FPSControls({
  29. camera: this._graphics.Camera,
  30. scene: this._graphics.Scene,
  31. domElement: this._graphics._threejs.domElement,
  32. gui: this._gui,
  33. guiParams: this._guiParams,
  34. });
  35. // this._entities['_controls'] = new controls.OrbitControls({
  36. // camera: this._graphics.Camera,
  37. // scene: this._graphics.Scene,
  38. // domElement: this._graphics._threejs.domElement,
  39. // gui: this._gui,
  40. // guiParams: this._guiParams,
  41. // });
  42. this._focusMesh = new THREE.Mesh(
  43. new THREE.SphereGeometry(25, 32, 32),
  44. new THREE.MeshBasicMaterial({
  45. color: 0xFFFFFF
  46. }));
  47. this._focusMesh.castShadow = true;
  48. this._focusMesh.receiveShadow = true;
  49. //this._graphics.Scene.add(this._focusMesh);
  50. this._totalTime = 0;
  51. this._LoadBackground();
  52. }
  53. _CreateGUI() {
  54. this._guiParams = {
  55. general: {
  56. },
  57. };
  58. this._gui = new GUI();
  59. const generalRollup = this._gui.addFolder('General');
  60. this._gui.close();
  61. }
  62. _LoadBackground() {
  63. this._graphics.Scene.background = new THREE.Color(0x000000);
  64. const loader = new THREE.CubeTextureLoader();
  65. const texture = loader.load([
  66. './resources/space-posx.jpg',
  67. './resources/space-negx.jpg',
  68. './resources/space-posy.jpg',
  69. './resources/space-negy.jpg',
  70. './resources/space-posz.jpg',
  71. './resources/space-negz.jpg',
  72. ]);
  73. this._graphics._scene.background = texture;
  74. }
  75. _OnStep(timeInSeconds) {
  76. this._totalTime += timeInSeconds;
  77. const x = Math.cos(this._totalTime * 0.025) * 4100;
  78. const y = Math.sin(this._totalTime * 0.025) * 4100;
  79. this._userCamera.position.set(x, 0, y);
  80. this._focusMesh.position.copy(this._userCamera.position);
  81. }
  82. }
  83. function _Main() {
  84. _APP = new ProceduralTerrain_Demo();
  85. }
  86. _Main();