Spaces:
Running
Running
cutechicken
commited on
Commit
β’
2a18e50
1
Parent(s):
080df83
Update game.js
Browse files
game.js
CHANGED
@@ -519,33 +519,46 @@ class Game {
|
|
519 |
roughness: 0.8,
|
520 |
metalness: 0.2
|
521 |
});
|
522 |
-
|
523 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
524 |
ground.rotation.x = -Math.PI / 2;
|
525 |
ground.receiveShadow = true;
|
526 |
|
527 |
-
// λ
|
528 |
const vertices = ground.geometry.attributes.position.array;
|
529 |
-
const heightScale =
|
530 |
-
const
|
531 |
|
532 |
for (let i = 0; i < vertices.length; i += 3) {
|
533 |
const x = vertices[i];
|
534 |
const y = vertices[i + 1];
|
535 |
-
// Perlin λ
Έμ΄μ¦μ μ μ¬ν ν¨κ³Όλ₯Ό λ΄λ μμ λ μμ
|
536 |
-
vertices[i + 2] =
|
537 |
-
(Math.sin(x * frequency) * Math.cos(y * frequency) * heightScale) +
|
538 |
-
(Math.sin(x * frequency * 2) * Math.cos(y * frequency * 2) * heightScale * 0.5);
|
539 |
|
540 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
541 |
const distanceFromCenter = Math.sqrt(x * x + y * y) / (MAP_SIZE * 0.5);
|
542 |
-
const edgeFactor = Math.max(0, 1 - distanceFromCenter);
|
543 |
-
|
|
|
|
|
544 |
}
|
545 |
|
546 |
ground.geometry.attributes.position.needsUpdate = true;
|
547 |
ground.geometry.computeVertexNormals();
|
548 |
-
this.ground = ground;
|
549 |
this.scene.add(ground);
|
550 |
|
551 |
// μ¬λ§ μ₯μ μΆκ°
|
|
|
519 |
roughness: 0.8,
|
520 |
metalness: 0.2
|
521 |
});
|
|
|
522 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
523 |
ground.rotation.x = -Math.PI / 2;
|
524 |
ground.receiveShadow = true;
|
525 |
|
526 |
+
// λ λ€μν μ§ν μμ±
|
527 |
const vertices = ground.geometry.attributes.position.array;
|
528 |
+
const heightScale = 15; // λμ΄ μ€μΌμΌ
|
529 |
+
const baseFrequency = 0.008; // κΈ°λ³Έ μ£Όνμ
|
530 |
|
531 |
for (let i = 0; i < vertices.length; i += 3) {
|
532 |
const x = vertices[i];
|
533 |
const y = vertices[i + 1];
|
|
|
|
|
|
|
|
|
534 |
|
535 |
+
// μ¬λ¬ μ£Όνμλ₯Ό μ‘°ν©ν μ§ν μμ±
|
536 |
+
let height = 0;
|
537 |
+
|
538 |
+
// ν° μΈλ (κΈ°λ³Έ μ§ν)
|
539 |
+
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
540 |
+
|
541 |
+
// μ€κ° ν¬κΈ° μ§ν
|
542 |
+
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
543 |
+
|
544 |
+
// μμ ꡴곑
|
545 |
+
height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
|
546 |
+
|
547 |
+
// λλ€ λ
Έμ΄μ¦ μΆκ° (μμ£Ό μμ ꡴곑)
|
548 |
+
const noise = (Math.random() - 0.5) * heightScale * 0.1;
|
549 |
+
height += noise;
|
550 |
+
|
551 |
+
// 맡 κ°μ₯μλ¦¬λ‘ κ°μλ‘ λμ΄λ₯Ό λΆλλ½κ² κ°μ
|
552 |
const distanceFromCenter = Math.sqrt(x * x + y * y) / (MAP_SIZE * 0.5);
|
553 |
+
const edgeFactor = Math.pow(Math.max(0, 1 - distanceFromCenter), 2); // λΆλλ¬μ΄ κ°μ
|
554 |
+
|
555 |
+
// μ΅μ’
λμ΄ μ€μ
|
556 |
+
vertices[i + 2] = height * edgeFactor;
|
557 |
}
|
558 |
|
559 |
ground.geometry.attributes.position.needsUpdate = true;
|
560 |
ground.geometry.computeVertexNormals();
|
561 |
+
this.ground = ground;
|
562 |
this.scene.add(ground);
|
563 |
|
564 |
// μ¬λ§ μ₯μ μΆκ°
|