1//Import the THREE.js library 2import * as THREE from "https://cdn.skypack.dev/[email protected]/build/three.module.js"; 3// To allow for the camera to move around the scene 4import {OrbitControls} from "https://cdn.skypack.dev/[email protected]/examples/jsm/controls/OrbitControls.js"; 5// To allow for importing the .gltf file 6import {GLTFLoader} from "https://cdn.skypack.dev/[email protected]/examples/jsm/loaders/GLTFLoader.js"; 7// === 1. СЦÐÐÐ === 8const scene = new THREE.Scene(); 9 10// СоздаÑм загÑÑзÑик ÑекÑÑÑÑ 11const textureLoader = new THREE.TextureLoader(); 12 13// ÐагÑÑжаем каÑÑÑ Ð¼ÐµÑаллиÑноÑÑи 14const metalnessMap = textureLoader.load('/static/js/2k_mars.jpg'); 15const marsMap = textureLoader.load('/static/js/2k_mercury.jpg'); 16 17 18// === 2. ÐÐÐÐÐ Ð === 19const camera = new THREE.PerspectiveCamera( 20 45, 21 window.innerWidth / window.innerHeight, 22 0.1, 23 1000 24); 25camera.position.set(0, 11, 15); 26 27const orbitCenterY = 2; // ÑенÑÑ Ð¾ÑбиÑÑ (и ÑоÑка ÑокÑÑа камеÑÑ) 28camera.lookAt(0, 0, 0); 29 30 31// === 3. Ð ÐÐÐÐÐ ÐÐ === 32const container = document.getElementById("container3D"); 33 34 35const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true }); 36renderer.setClearColor(0x000000, 0); 37container.appendChild(renderer.domElement); 38 39 40// === 4. СÐÐТ === 41const pointLight = new THREE.PointLight(0xA098CD, 10); 42pointLight.power = 25; 43pointLight.distance = 10; 44pointLight.position.set(0, 0, 0); // оÑÑавлÑем ÑÐ²ÐµÑ Ð² ÑенÑÑе оÑбиÑÑ 45scene.add(pointLight); 46 47const spotLight = new THREE.SpotLight(0xffffff); 48spotLight.position.set(10, 10, 10); 49 50scene.add(spotLight); 51 52const pointLight2 = new THREE.PointLight(0xA098CD, 10); 53pointLight2.power = 15; 54pointLight2.distance = 10; 55pointLight2.position.set(0, 5, 5); // оÑÑавлÑем ÑÐ²ÐµÑ Ð² ÑенÑÑе оÑбиÑÑ 56scene.add(pointLight2); 57// 58// const sunGeometry = new THREE.SphereGeometry(0.5, 32, 32); 59// const sunMaterial = new THREE.MeshStandardMaterial({ 60// color: 0x933FFE, 61// metalness: 0.3, 62// roughness: 0.2 63// }); 64// const sun = new THREE.Mesh(sunGeometry, sunMaterial); 65// sun.position.set(-3, 4, -2) 66// 67// scene.add(sun); 68 69 70// ÐагÑÑжаем дÑмовÑÑ ÑекÑÑÑÑÑ (PNG Ñ Ð¿ÑозÑаÑноÑÑÑÑ) 71const loader = new THREE.TextureLoader(); 72// const smokeTexture = loader.load('assets/js/pngwing.com.png'); 73 74// ÐаÑеÑиал дÑма 75// const smokeMaterial = new THREE.MeshLambertMaterial({ 76// map: smokeTexture, 77// transparent: true, 78// opacity: 0.2, 79// depthWrite: false, 80// blending: THREE.AdditiveBlending, 81// side: THREE.DoubleSide 82// }); 83 84// СоздаÑм много "облаков" дÑма 85// const smokeParticles = []; 86// 87// for (let i = 0; i < 8; i++) { 88// const cloud = new THREE.Mesh( 89// new THREE.PlaneGeometry(40, 40), 90// smokeMaterial 91// ); 92// 93// cloud.position.set( 94// Math.random() * 50 - 25, 95// Math.random() * 30 - 15, 96// Math.random() * 50 - 25 97// ); 98// 99// cloud.rotation.z = Math.random() * 2 * Math.PI; 100// scene.add(cloud); 101// smokeParticles.push(cloud); 102// } 103 104// ÐнимаÑÐ¸Ñ Ð´Ñма 105// function animateSmoke() { 106// requestAnimationFrame(animateSmoke); 107// smokeParticles.forEach(p => { 108// p.rotation.z += 0.001; // медленное вÑаÑение 109// }); 110// renderer.render(scene, camera); 111// } 112// animateSmoke(); 113 114 115 116const ambient = new THREE.AmbientLight(0xffffff, 0.5); 117scene.add(ambient); 118 119// ==== 5. ÐРУÐÐÐ ÐÐЯ ÐÐÐЪÐÐÐ ÐСÐÐ¥ ÐÐЪÐÐТÐÐ === 120const sceneGroup = new THREE.Group(); 121sceneGroup.position.y = 2; 122scene.add(sceneGroup); 123 124// === 5. ÐÐÐÐÐТР(ÑÑеÑа) === 125const planetGeometry = new THREE.SphereGeometry(1.5, 64, 64); 126const planetMaterial = new THREE.MeshStandardMaterial({ 127 color: 0xffffff, 128 metalness: 0.1, 129 roughness: 0.9, 130 // emissive: 0x823214, 131 map: metalnessMap 132 133}); 134const planet = new THREE.Mesh(planetGeometry, planetMaterial); 135sceneGroup.add(planet); 136 137// === 5. ÐÐÐÐÐТÐ2 (ÑÑеÑа) === 138const planetGeometry2 = new THREE.SphereGeometry(1, 64, 64); 139const planetMaterial2 = new THREE.MeshStandardMaterial({ 140 color: 0xffffff, 141 metalness: 0.5, 142 roughness: 10, 143 map: marsMap 144}); 145 146const planet2 = new THREE.Mesh(planetGeometry2, planetMaterial2); 147sceneGroup.add(planet2); 148 149 150// === 6. ÐÐÐ ÐÐÐТРЫ ÐÐ ÐÐТЫ === 151let angle = 22; 152let angle2 = 25; 153 154 155const radiusX = 12; // ÑиÑина ÑллипÑа 156const radiusZ = 8; // вÑÑоÑа ÑллипÑа 157 158const tilt = Math.PI/1.05; // наклон оÑбиÑÑ 159const orbitHeight = 1; // поднимаем оÑбиÑÑ Ð²Ð²ÐµÑÑ 160 161// === СÐÐÐÐÐÐ ÐÐÐÐЮ ÐÐ ÐÐТЫ === 162const points = []; 163const steps = 128; // Ñем болÑÑе â Ñем плавнее ÑÐ»Ð»Ð¸Ð¿Ñ 164 165for (let i = 0; i <= steps; i++) {
166 const angle = (i / steps) * Math.PI * 2; 167 const x = Math.cos(angle) * radiusX; 168 const z = Math.sin(angle) * radiusZ; 169 const y = x * Math.sin(tilt) + 1; // пÑименÑем наклон 170 const xTilt = x * Math.cos(tilt); 171 172 points.push(new THREE.Vector3(xTilt, y, z)); 173} 174 175const orbitGeometry = new THREE.BufferGeometry().setFromPoints(points); 176const orbitMaterial = new THREE.LineBasicMaterial({ 177 color: 0x484848, 178 transparent: true, 179 opacity: 0.5, 180}); 181const orbitLine = new THREE.LineLoop(orbitGeometry, orbitMaterial); 182sceneGroup.add(orbitLine); 183 184const points2 = []; 185const steps2 = 128; // Ñем болÑÑе â Ñем плавнее ÑÐ»Ð»Ð¸Ð¿Ñ 186 187for (let i = 0; i <= steps2; i++) { 188 const angle = (i / steps2) * Math.PI * 3; 189 const x = Math.cos(-angle / 1.5) * radiusX/1.5; 190 const z = Math.sin(-angle / 1.5) * radiusZ/1.5; 191 const y = x * Math.sin(tilt)+1; // пÑименÑем наклон 192 const xTilt = x * Math.cos(tilt); 193 194 points2.push(new THREE.Vector3(xTilt, y, z)); 195} 196 197const orbitGeometry2 = new THREE.BufferGeometry().setFromPoints(points2); 198const orbitMaterial2 = new THREE.LineBasicMaterial({ 199 color: 0x484848, 200 transparent: true, 201 opacity: 0.5, 202}); 203const orbitLine2 = new THREE.LineLoop(orbitGeometry2, orbitMaterial2); 204sceneGroup.add(orbitLine2); 205 206 207// ÐÐ ÐÐÐÐ ÐРШÐÐ ÐÐЫ ÐÐÐ ÐÐÐ. 208 209 210// === 7. ÐÐÐÐÐЦÐЯ === 211 212function animate() { 213 requestAnimationFrame(animate); 214 215 216 angle += 0.01 / 12; // ÑкоÑоÑÑÑ Ð²ÑаÑÐµÐ½Ð¸Ñ 217 angle2 += 0.01 / 12; // ÑкоÑоÑÑÑ Ð²ÑаÑÐµÐ½Ð¸Ñ 218 219 // ÑллипÑиÑеÑкое движение 220 const x = Math.cos(-angle) * radiusX; 221 const z = Math.sin(-angle) * radiusZ; 222 223 // пÑименÑем наклон и ÑмеÑение ввеÑÑ 224 planet.position.set( 225 x * Math.cos(tilt), 226 x * Math.sin(tilt) + orbitHeight, 227 z 228 ); 229 // вÑаÑение планеÑÑ Ð²Ð¾ÐºÑÑг Ñвоей оÑи 230 planet.rotation.y += 0.05 / 20; 231 232 // ÑллипÑиÑеÑкое движение Ð´Ð»Ñ Ð²ÑоÑой планеÑÑ 233 const x2 = Math.cos(angle2 * 1.5) * radiusX / 1.5; 234 const z2 = Math.sin(angle2 * 1.5) * radiusZ / 1.5; 235 236 // пÑименÑем наклон и ÑмеÑение ввеÑÑ 237 planet2.position.set( 238 x2 * Math.cos(tilt), 239 x2 * Math.sin(tilt) + orbitHeight, 240 z2 241 ); 242 // вÑаÑение планеÑÑ Ð²Ð¾ÐºÑÑг Ñвоей оÑи 243 planet2.rotation.y += 0.05 / 10; 244 // console.log("pos changed"); 245 246 247renderer.render(scene, camera); 248} 249 250animate(); 251 252// === 8. ÐÐÐ ÐÐÐТÐÐ ÐÐÐÐÐÐÐÐЯ Ð ÐÐÐÐÐ Ð ÐÐÐÐ === 253function resizeRenderer() { 254 const width = container.clientWidth; 255 const height = container.clientHeight / 2; 256 renderer.setSize(width, height, false); 257 camera.aspect = width / height; 258 camera.updateProjectionMatrix(); 259 console.log(height); 260 261} 262 263window.addEventListener("resize", resizeRenderer); 264resizeRenderer(); 265 266
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.