Skip to content

Commit 0da0a5b

Browse files
committed
merged planet textures
1 parent 17e7c9b commit 0da0a5b

1 file changed

Lines changed: 34 additions & 39 deletions

File tree

src/pages/home/js/scene.js

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as THREE from "three";
22

33
export function createScene() {
4-
4+
5+
const loader = new THREE.TextureLoader();
6+
57
const scene = new THREE.Scene();
68

79
// Lighting
@@ -45,22 +47,28 @@ export function createScene() {
4547
scene.add(sun);
4648

4749
// Planets
48-
const planetLevels = [
49-
{ level: 1, radius: 1.1, orbitR: 14, speed: 0.8, tilt: 0.2, color: 0xff6644, emissive: 0x441100 },
50-
{ level: 2, radius: 1.5, orbitR: 24, speed: 0.45, tilt: 0.35, color: 0x44aaff, emissive: 0x001133 },
51-
{ level: 3, radius: 1.8, orbitR: 36, speed: 0.25, tilt: 0.15, color: 0x88dd55, emissive: 0x112200 },
50+
const planetData = [
51+
{ level: 1, id: 1, radius: 1.1, orbitR: 14, speed: 0.8, angle: 0 * (Math.PI / 180), tilt: 0.2, color: 0xff6644, emissive: 0x441100, texture: '/textures/texture1.webp'},
52+
{ level: 1, id: 2, radius: 1.1, orbitR: 14, speed: 0.8, angle: 120 * (Math.PI / 180), tilt: 0.2, color: 0xff6644, emissive: 0x441100, texture: '/textures/texture1.webp'},
53+
{ level: 1, id: 3, radius: 1.1, orbitR: 14, speed: 0.8, angle: 240 * (Math.PI / 180), tilt: 0.2, color: 0xff6644, emissive: 0x441100, texture: '/textures/texture1.webp'},
54+
{ level: 2, id: 4, radius: 1.5, orbitR: 24, speed: 0.45, angle: 0 * (Math.PI / 180), tilt: 0.35, color: 0x44aaff, emissive: 0x001133, texture: '/textures/texture2.webp' },
55+
{ level: 2, id: 5, radius: 1.5, orbitR: 24, speed: 0.45, angle: 120 * (Math.PI / 180), tilt: 0.35, color: 0x44aaff, emissive: 0x001133, texture: '/textures/texture2.webp' },
56+
{ level: 2, id: 6, radius: 1.5, orbitR: 24, speed: 0.45, angle: 240 * (Math.PI / 180), tilt: 0.35, color: 0x44aaff, emissive: 0x001133, texture: '/textures/texture2.webp' },
57+
{ level: 3, id: 7, radius: 1.2, orbitR: 36, speed: 0.25, angle: 0 * (Math.PI / 180), tilt: 0.15, color: 0x88dd55, emissive: 0x112200, texture: '/textures/texture3.webp'},
58+
{ level: 3, id: 8, radius: 1.2, orbitR: 36, speed: 0.25, angle: 120 * (Math.PI / 180), tilt: 0.15, color: 0x88dd55, emissive: 0x112200, texture: '/textures/texture3.webp'},
59+
{ level: 3, id: 9, radius: 1.2, orbitR: 36, speed: 0.25, angle: 240 * (Math.PI / 180), tilt: 0.15, color: 0x88dd55, emissive: 0x112200, texture: '/textures/texture3.webp'},
5260
];
5361

54-
const planets = planetLevels.flatMap(level => {
62+
const planets = planetData.map(planet => {
5563

5664
// Orbit path
5765
const pts = [];
5866
for (let i = 0; i <= 128; i++) {
5967
const theta = 2 * Math.PI * (i / 128) ;
6068
pts.push(new THREE.Vector3(
61-
Math.cos(theta) * level.orbitR,
62-
Math.sin(theta) * level.tilt * level.orbitR * 0.18,
63-
Math.sin(theta) * level.orbitR
69+
Math.cos(theta) * planet.orbitR,
70+
Math.sin(theta) * planet.tilt * planet.orbitR * 0.18,
71+
Math.sin(theta) * planet.orbitR
6472
));
6573
}
6674
const orbitGeo = new THREE.BufferGeometry().setFromPoints(pts);
@@ -71,38 +79,25 @@ export function createScene() {
7179
});
7280
scene.add(new THREE.LineLoop(orbitGeo, orbitMat));
7381

74-
return [0, 1, 2].map(planet => {
75-
76-
// Each planet
77-
const planetGeo = new THREE.SphereGeometry(level.radius, 36, 36);
78-
const planetMat = new THREE.MeshStandardMaterial({
79-
color: level.color,
80-
emissive: level.emissive,
81-
emissiveIntensity: 1.0,
82-
roughness: 0.65,
83-
metalness: 0.05
84-
});
85-
const mesh = new THREE.Mesh(planetGeo, planetMat);
86-
scene.add(mesh);
87-
88-
// Angular separation
89-
const minSeparation = 2 * Math.PI * (120 / 360);
90-
const maxSeparation = 2 * Math.PI * (240 / 360);
91-
const p = Math.random()
92-
let angle = planet * minSeparation + p * (maxSeparation - minSeparation)
93-
94-
return {
95-
id: `${level.level}-${planet}`,
96-
mesh: mesh,
97-
angle: angle,
98-
...level,
99-
}
100-
82+
// Each planet
83+
const planetGeo = new THREE.SphereGeometry(planet.radius, 36, 36);
84+
const planetMat = new THREE.MeshStandardMaterial({
85+
map: loader.load(planet.texture),
86+
roughness: 0.65,
87+
metalness: 0.05
10188
});
89+
const mesh = new THREE.Mesh(planetGeo, planetMat);
90+
scene.add(mesh);
91+
92+
// Angular separation
93+
planet.angle += (Math.random() - 0.5) * ( 2 * Math.PI * (90/360));
94+
95+
return {
96+
mesh,
97+
...planet,
98+
}
10299
});
103100

104-
105101
return {scene, sun, planets}
106102

107-
}
108-
103+
}

0 commit comments

Comments
 (0)