eaglelandsonce commited on
Commit
ee44b0e
·
verified ·
1 Parent(s): c0c3f27

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +38 -131
index.html CHANGED
@@ -2,169 +2,70 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8" />
5
- <title>3D Simulation with Three.js</title>
6
  <style>
7
  body {
8
  margin: 0;
9
  overflow: hidden;
10
- background-color: #000;
11
- }
12
- #info {
13
- position: absolute;
14
- top: 10px;
15
- left: 10px;
16
- color: #fff;
17
- font-family: sans-serif;
18
- z-index: 2;
19
- }
20
- .dg.main {
21
- position: absolute;
22
- top: 0px;
23
- right: 0px;
24
- z-index: 100;
25
  }
26
  </style>
27
  </head>
28
  <body>
29
- <div id="info">
30
- 3D Simulation with Three.js<br />
31
- Use the GUI controls to interact with the scene.
32
- </div>
33
  <!-- Include Three.js -->
34
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r152/three.min.js"></script>
35
- <!-- Include dat.GUI -->
36
- <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.9/dat.gui.min.js"></script>
37
  <!-- Include OrbitControls -->
38
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r152/examples/js/controls/OrbitControls.js"></script>
39
  <script>
40
- // Initialize scene, camera, and renderer
41
  const scene = new THREE.Scene();
42
- scene.background = new THREE.Color(0x000000);
43
 
 
44
  const camera = new THREE.PerspectiveCamera(
45
- 60,
46
  window.innerWidth / window.innerHeight,
47
  0.1,
48
- 10000
49
  );
50
- camera.position.set(0, 50, 150);
51
 
 
52
  const renderer = new THREE.WebGLRenderer({ antialias: true });
53
  renderer.setSize(window.innerWidth, window.innerHeight);
54
  document.body.appendChild(renderer.domElement);
55
 
56
- // OrbitControls for camera interaction
57
  const controls = new THREE.OrbitControls(camera, renderer.domElement);
58
 
59
  // Lighting
60
- const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
61
  scene.add(ambientLight);
62
- const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
63
- directionalLight.position.set(50, 100, 50);
64
- scene.add(directionalLight);
65
-
66
- // Earth (blue sphere)
67
- const earthGeometry = new THREE.SphereGeometry(30, 32, 32);
68
- const earthMaterial = new THREE.MeshPhongMaterial({
69
- color: 0x2233ff,
70
- shininess: 10,
71
- });
72
- const earth = new THREE.Mesh(earthGeometry, earthMaterial);
73
- earth.position.set(0, 0, 0);
74
- scene.add(earth);
75
 
76
- // Payload (red cylinder)
77
- const payloadGeometry = new THREE.CylinderGeometry(2, 2, 6, 32);
78
- const payloadMaterial = new THREE.MeshPhongMaterial({ color: 0xff3333 });
79
- const payload = new THREE.Mesh(payloadGeometry, payloadMaterial);
80
- payload.position.set(40, 0, 0);
81
- scene.add(payload);
82
 
83
- // Manned vehicle (blue cube)
84
- const vehicleGeometry = new THREE.BoxGeometry(5, 5, 5);
85
- const vehicleMaterial = new THREE.MeshPhongMaterial({ color: 0x3333ff });
86
- const mannedVehicle = new THREE.Mesh(vehicleGeometry, vehicleMaterial);
87
- mannedVehicle.position.set(-40, 60, 0);
88
- scene.add(mannedVehicle);
89
 
90
- // Control parameters with dat.GUI
91
- const params = {
92
- stage: 1,
93
- spinRate: 0.5,
94
- thrusterBurn: 2.0,
95
- despinRate: 0.01,
96
- dockingSpeed: 0.02,
97
- nextStage: function () {
98
- if (this.stage < 5) {
99
- this.stage++;
100
- elapsedTime = 0;
101
- }
102
- },
103
- };
104
-
105
- const gui = new dat.GUI();
106
- gui.add(params, 'stage', 1, 5, 1).name('Stage').listen();
107
- gui.add(params, 'spinRate', 0.1, 2.0).name('Spin Rate');
108
- gui.add(params, 'thrusterBurn', 0.5, 5.0).name('Thruster Burn');
109
- gui.add(params, 'despinRate', 0.001, 0.05).name('Despin Rate');
110
- gui.add(params, 'dockingSpeed', 0.005, 0.05).name('Docking Speed');
111
- gui.add(params, 'nextStage').name('Next Stage');
112
-
113
- // Animation variables
114
- let elapsedTime = 0;
115
- const clock = new THREE.Clock();
116
 
 
117
  function animate() {
118
  requestAnimationFrame(animate);
119
- const delta = clock.getDelta();
120
- elapsedTime += delta;
121
 
122
- switch (params.stage) {
123
- case 1:
124
- // Stage 1: Ground-Based Spin-Up Launch
125
- const radius = 40;
126
- payload.position.x = radius * Math.cos(elapsedTime * params.spinRate);
127
- payload.position.z = radius * Math.sin(elapsedTime * params.spinRate);
128
- payload.position.y = 0;
129
- break;
130
- case 2:
131
- // Stage 2: Orbital Insertion via Thruster Burn
132
- const upwardGain = params.thrusterBurn * elapsedTime * 10;
133
- payload.position.x = radius * Math.cos(elapsedTime * params.spinRate);
134
- payload.position.z = radius * Math.sin(elapsedTime * params.spinRate);
135
- payload.position.y = upwardGain;
136
- break;
137
- case 3:
138
- // Stage 3: On-Orbit Stabilization and Despin
139
- const orbitRadius = 80;
140
- params.spinRate = Math.max(
141
- 0.1,
142
- params.spinRate - params.despinRate * delta
143
- );
144
- payload.position.x =
145
- orbitRadius * Math.cos(elapsedTime * params.spinRate);
146
- payload.position.z =
147
- orbitRadius * Math.sin(elapsedTime * params.spinRate);
148
- payload.position.y = 20;
149
- break;
150
- case 4:
151
- // Stage 4: Rendezvous and Docking with Manned Vehicle
152
- payload.position.lerp(mannedVehicle.position, params.dockingSpeed);
153
- break;
154
- case 5:
155
- // Stage 5: Integrated Mission Operations (Combined Orbit)
156
- const angularSpeed = 0.01;
157
- const angle = elapsedTime * angularSpeed;
158
- const center = new THREE.Vector3(0, 20, 0);
159
- const offset = new THREE.Vector3(
160
- orbitRadius * Math.cos(angle),
161
- 0,
162
- orbitRadius * Math.sin(angle)
163
- );
164
- payload.position.copy(center).add(offset);
165
- mannedVehicle.position.copy(center).add(offset);
166
- break;
167
- }
168
 
169
  controls.update();
170
  renderer.render(scene, camera);
@@ -172,6 +73,12 @@
172
 
173
  animate();
174
 
175
- // Handle window
176
- ::contentReference[oaicite:0]{index=0}
177
-
 
 
 
 
 
 
 
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8" />
5
+ <title>Three.js Orbital Simulation</title>
6
  <style>
7
  body {
8
  margin: 0;
9
  overflow: hidden;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  }
11
  </style>
12
  </head>
13
  <body>
 
 
 
 
14
  <!-- Include Three.js -->
15
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r152/three.min.js"></script>
 
 
16
  <!-- Include OrbitControls -->
17
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r152/examples/js/controls/OrbitControls.js"></script>
18
  <script>
19
+ // Scene setup
20
  const scene = new THREE.Scene();
 
21
 
22
+ // Camera setup
23
  const camera = new THREE.PerspectiveCamera(
24
+ 75,
25
  window.innerWidth / window.innerHeight,
26
  0.1,
27
+ 1000
28
  );
29
+ camera.position.z = 50;
30
 
31
+ // Renderer setup
32
  const renderer = new THREE.WebGLRenderer({ antialias: true });
33
  renderer.setSize(window.innerWidth, window.innerHeight);
34
  document.body.appendChild(renderer.domElement);
35
 
36
+ // OrbitControls setup
37
  const controls = new THREE.OrbitControls(camera, renderer.domElement);
38
 
39
  // Lighting
40
+ const ambientLight = new THREE.AmbientLight(0x404040); // Soft white light
41
  scene.add(ambientLight);
42
+ const pointLight = new THREE.PointLight(0xffffff, 1, 0);
43
+ scene.add(pointLight);
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ // Central planet
46
+ const planetGeometry = new THREE.SphereGeometry(10, 32, 32);
47
+ const planetMaterial = new THREE.MeshPhongMaterial({ color: 0x0077ff });
48
+ const planet = new THREE.Mesh(planetGeometry, planetMaterial);
49
+ scene.add(planet);
 
50
 
51
+ // Orbiting satellite
52
+ const satelliteGeometry = new THREE.SphereGeometry(1, 16, 16);
53
+ const satelliteMaterial = new THREE.MeshPhongMaterial({ color: 0xff0000 });
54
+ const satellite = new THREE.Mesh(satelliteGeometry, satelliteMaterial);
55
+ scene.add(satellite);
 
56
 
57
+ // Animation parameters
58
+ const orbitRadius = 30;
59
+ const orbitSpeed = 0.01; // Radians per frame
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ // Animation loop
62
  function animate() {
63
  requestAnimationFrame(animate);
 
 
64
 
65
+ // Update satellite position
66
+ const time = Date.now() * 0.001;
67
+ satellite.position.x = orbitRadius * Math.cos(time * orbitSpeed);
68
+ satellite.position.z = orbitRadius * Math.sin(time * orbitSpeed);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  controls.update();
71
  renderer.render(scene, camera);
 
73
 
74
  animate();
75
 
76
+ // Handle window resize
77
+ window.addEventListener('resize', () => {
78
+ camera.aspect = window.innerWidth / window.innerHeight;
79
+ camera.updateProjectionMatrix();
80
+ renderer.setSize(window.innerWidth, window.innerHeight);
81
+ });
82
+ </script>
83
+ </body>
84
+ </html>