以下は、前回の統合コードに対して、以下の修正を反映した完全版コード例です。
ペダル入力からの速度は、1/216 の変換係数を用いて km/h を m/frame に変換し、前方の地形勾配に応じた補正をかけることで、通常の移動速度が約20km/h~40km/h程度になるように調整しました。
また、雲の生成処理では、描画前にキャンバスのフィルターを利用して輪郭をぼかし、さらに各雲の移動速度を半分程度に低減しています。
ペダル入力からの速度は、1/216 の変換係数を用いて km/h を m/frame に変換し、前方の地形勾配に応じた補正をかけることで、通常の移動速度が約20km/h~40km/h程度になるように調整しました。
また、雲の生成処理では、描画前にキャンバスのフィルターを利用して輪郭をぼかし、さらに各雲の移動速度を半分程度に低減しています。
以下のコード全体をお使いください。
────────────────────────────────────────────────────────────────────
htmlCopy
// Enterキーが押されたときに呼び出す
registerTap() {
const now = <URL>();
this.tapTimes.push(now);
if (this.tapTimes.length > <URL>xHistory) {
<URL>ift();
}
<URL>lculateCadence();
}
// タップ間隔からケイデンスと推定速度を計算する
calculateCadence() {
if (this.tapTimes.length < 2) return;
const intervals = [];
for (let i = 1; i < this.tapTimes.length; i++) {
intervals.push(this.tapTimes[i] - this.tapTimes[i - 1]);
}
const avgInterval = <URL>uce((a, b) => a + b, 0) / intervals.length;
// ケイデンス (rpm) = 60000 / 平均タップ間隔(ミリ秒)
const cadence = 60000 / avgInterval;
<REDACTED>)
<URL>rtualSpeed = cadence * <URL>ar * <URL>seFactor;
console.log(`ケイデンス: ${<URL>Fixed(1)} rpm, ギア: ${<URL>ar}, 推定速度: ${<URL>Fixed(1)} km/h`);
}
// 現在の推定速度を返す
getSpeed() {
return <URL>rtualSpeed;
}
// ギアの設定(1~9)
setGear(newGear) {
newGear = <URL>x(1, <REDACTED>, newGear));
<URL>ar = newGear;
console.log(`ギアを ${<URL>ar} <REDACTED>`);
// ギア変更後に再計算(直近のタップ情報がある場合)
<URL>lculateCadence();
}
}
// ペダルシミュレーターのインスタンス作成とキーイベント設定
const pedalSimulator = new PedalSimulator();
<URL>dEventListener('keydown', (e) => {
// <REDACTED>
if (<URL>y === 'Enter') {
<URL>gisterTap();
}
// 数字キー '1'~'9' でギア設定
if (<URL>y >= '1' && <URL>y <= '9') {
<URL>tGear(parseInt(<URL>y, 10));
}
});
// ── グローバル設定 ─────────────────────────────
const scene = new <URL>ene();
const camera = new <URL>rspectiveCamera(75, <URL>nerWidth/<URL>nerHeight, 0.1, 1000);
const renderer = new <REDACTED>({ antialias: true });
<URL>tSize(<URL>nerWidth, <URL>nerHeight);
<URL>adowMap.enabled = true;
<URL>adowMap.type = THREE.PCFSoftShadowMap;
<URL>endChild(<URL>mElement);
<URL>g = new <URL>gExp2(0xd7e5f0, 0.005);
<URL>ckground = new <URL>lor(0x87ceeb);
// 地形・チャンク設定
const chunkSize = 100;
const chunkResolution = 64;
const heightScale = 25;
const viewDistance = 4;
const simplex = new SimplexNoise("terrain-seed-123456");
const chunks = new <REDACTED>();
let currentChunkX = 0;
let currentChunkZ = 0;
const coordinatesElement = <URL>tElementById('coordinates');
// ── 葉テクスチャキャッシュ用 ─────────────────────────────
const cachedNeedleLeafTextures = [];
const cachedBroadLeafTextures = [];
function generateNeedleLeafTexture() {
const canvas = <URL>eateElement('canvas');
canvas.width = 256;
canvas.height = 256;
const ctx = <URL>tContext('2d');
let grad = <URL>eateLinearGradient(0, 0, <DATE_TIME>, canvas.height);
<URL>dColorStop(0, '#2a5d34');
<URL>dColorStop(1, '#3e8c4c');
<URL>llStyle = grad;
<URL>llRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < 30; i++) {
const x = Math.random() * canvas.width;
const y = Math.random() * canvas.height;
const length = 10 + Math.random() * 10;
const angle = Math.random() * Math.PI * 2;
<REDACTED> = 'rgba(20,70,30,0.8)';
<URL>neWidth = 1;
<REDACTED>();
<URL>eTo(x, y);
<URL>neTo(x + <URL>s(angle) * length, y + <URL>n(angle) * length);
<REDACTED>();
}
let imgData = <URL>tImageData(0, 0, canvas.width, canvas.height);
let data = imgData.data;
for (let i = 0; i < data.length; i += 4) {
const noise = (Math.random() - 0.5) * 20;
data[i] = Math.min(255, <DATE_TIME>, data[i] + noise));
data[i+1] = Math.min(255, <DATE_TIME>, data[i+1] + noise));
<REDACTED>] = Math.min(255, <DATE_TIME>, <REDACTED>] + noise));
}
ctx.putImageData(imgData, 0, 0);
return new <URL>nvasTexture(canvas);
}
function generateBroadLeafTexture() {
const canvas = <URL>eateElement('canvas');
canvas.width = 256;
canvas.height = 256;
const ctx = <URL>tContext('2d');
let grad = <URL>eateRadialGradient(canvas.width/2, canvas.height/2, <DATE_TIME>, canvas.width/2, canvas.height/2, canvas.width/2);
<URL>dColorStop(0, '#78c679');
<URL>dColorStop(1, '#238443');
<URL>llStyle = grad;
<URL>llRect(0, 0, canvas.width, canvas.height);
<REDACTED> = 'rgba(34,102,51,0.8)';
<URL>neWidth = 4;
<REDACTED>();
<URL>eTo(canvas.width/2, canvas.height * 0.1);
<URL>neTo(canvas.width/2, canvas.height * 0.9);
<REDACTED>();
for (let i = 0; i < 5; i++) {
const offset = (i - 2) * 10;
<REDACTED> = 'rgba(34,102,51,0.6)';
<URL>neWidth = 2;
<REDACTED>();
<URL>eTo(canvas.width/2, canvas.height * 0.1 + Math.abs(offset));
ctx.quadraticCurveTo(canvas.width/2 + offset, canvas.height/2, canvas.width/2, canvas.height * 0.9 - Math.abs(offset));
<REDACTED>();
}
let imgData = <URL>tImageData(0, 0, canvas.width, canvas.height);
let data = imgData.data;
for (let i = 0; i < data.length; i += 4) {
const noise = (Math.random() - 0.5) * 10;
data[i] = Math.min(255, <DATE_TIME>, data[i] + noise));
data[i+1] = Math.min(255, <DATE_TIME>, data[i+1] + noise));
<REDACTED>] = Math.min(255, <DATE_TIME>, <REDACTED>] + noise));
}
ctx.putImageData(imgData, 0, 0);
return new <URL>nvasTexture(canvas);
}
function initLeafTextureCache() {
for (let i = 0; i < 4; i++) {
cachedNeedleLeafTextures.push(generateNeedleLeafTexture());
cachedBroadLeafTextures.push(generateBroadLeafTexture());
}
}
function getCachedLeafTexture(isNeedle) {
if (isNeedle) {
return cachedNeedleLeafTextures[Math.floor(Math.random() * cachedNeedleLeafTextures.length)];
} else {
return cachedBroadLeafTextures[Math.floor(Math.random() * cachedBroadLeafTextures.length)];
}
}
// ── 地形テクスチャ生成 ─────────────────────────────
function createTerrainTexture() {
const canvas = <URL>eateElement('canvas');
canvas.width = 1024;
canvas.height = 1024;
const ctx = <URL>tContext('2d');
const gradient = <URL>eateLinearGradient(0, 0, <DATE_TIME>, canvas.height);
<URL>dColorStop(0, '#2d4c1e');
<URL>dColorStop(0.25, '#3d6e27');
<URL>dColorStop(0.5, '#687f45');
<URL>dColorStop(0.7, '<DATE_TIME>);
<URL>dColorStop(0.85, '#d1c6a8');
<URL>dColorStop(1, '#f5f2eb');
<URL>llStyle = gradient;
<URL>llRect(0, 0, canvas.width, canvas.height);
for (let y = 0; y < canvas.height; y++) {
for (let x = 0; x < canvas.width; <REDACTED>) {
const nx = x / canvas.width * 8;
const ny = y / canvas.height * 8;
const noise = <URL>ise2D(nx * 2, <REDACTED> * 2) * 0.5 +
<URL>ise2D(nx * 4, <REDACTED> * 4) * 0.25 +
<URL>ise2D(nx * 8, <REDACTED> * 8) * 0.125;
const intensity = <URL>x(0, Math.min(0.3, noise * 0.5 + 0.15));
<URL>llStyle = `rgba(0, 0, <REDACTED>, ${intensity})`;
<URL>llRect(x, y, 1, 1);
}
}
for (let i = 0; i < 5000; i++) {
const x = Math.floor(Math.random() * canvas.width);
const y = Math.floor(Math.random() * canvas.height);
const size = Math.random() * 2 + 0.5;
const opacity = Math.random() * 0.2 + 0.05;
<URL>llStyle = `rgba(100, 100, 100, ${opacity})`;
<REDACTED>();
<URL>c(x, y, size, 0, Math.PI * 2);
<URL>ll();
}
const texture = new <URL>nvasTexture(canvas);
texture.wrapS = <URL>peatWrapping;
texture.wrapT = <URL>peatWrapping;
<URL>t(1, 1);
return texture;
}
const terrainTexture = createTerrainTexture();
function createNormalMap(heightData, width, height) {
const canvas = <URL>eateElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = <URL>tContext('2d');
const imgData = <URL>eateImageData(width, height);
for (let y = 0; y < height; <REDACTED>) {
for (let x = 0; x < width; <REDACTED>) {
const idx = y * width + x;
const imgIdx = idx * 4;
const left = x > 0 ? heightData[y * width + (x - 1)] : heightData[y * width + x];
const right = x < width - 1 ? heightData[y * width + (x + 1)] : heightData[y * width + x];
const top = y > 0 ? heightData[(y - 1) * width + x] : heightData[y * width + x];
const bottom = y < height - 1 ? heightData[(y + 1) * width + x] : heightData[y * width + x];
const dx = (right - left) / (2 * heightScale);
const dy = (bottom - top) / (2 * heightScale);
const dz = 1.0;
const length = Math.sqrt(dx * dx + dy * dy + dz * dz);
const nx = dx / length;
const ny = dy / length;
const nz = dz / length;
imgData.data[imgIdx] = Math.floor((nx * 0.5 + 0.5) * 255);
imgData.data[imgIdx+1] = <REDACTED> * 0.5 + 0.5) * 255);
imgData.data[imgIdx+2] = Math.floor((nz * 0.5 + 0.5) * 255);
imgData.data[imgIdx+3] = 255;
}
}
ctx.putImageData(imgData, 0, 0);
return new <URL>nvasTexture(canvas);
}
function getWorldPosition(chunkX, chunkZ) {
return { x: chunkX * chunkSize, z: chunkZ * chunkSize };
}
function getChunkCoords(worldX, worldZ) {
return { x: Math.floor(worldX / chunkSize), z: Math.floor(worldZ / chunkSize) };
}
let debugInfo = { chunksCreated: 0, chunksActive: 0 };
function getHeightAt(worldX, worldZ) {
const scale = 0.01;
let h = 0;
h += <URL>ise2D(worldX * scale * 0.5, worldZ * scale * 0.5) * 0.6;
h += <URL>ise2D(worldX * scale, worldZ * scale) * 0.3;
h += <URL>ise2D(worldX * scale * 2, worldZ * scale * 2) * 0.15;
h += <URL>ise2D(worldX * scale * 4, worldZ * scale * 4) * 0.075;
const ridge = <REDACTED> scale * 0.3) * 0.3 + <URL>s(worldZ * scale * 0.2) * 0.2;
h += <URL>x(0, <REDACTED>);
return <DATE_TIME>, h) * heightScale;
}
function generateChunk(chunkX, chunkZ) {
const chunkKey = `${chunkX},${chunkZ}`;
if (chunks.has(chunkKey)) return <URL>t(chunkKey);
const worldPos = getWorldPosition(chunkX, chunkZ);
const geometry = new <URL>aneGeometry(chunkSize, chunkSize, chunkResolution, chunkResolution);
<URL>tateX(-Math.PI / 2);
const vertices = <URL>tributes.position;
const heightData = new Array(<URL>unt);
for (let i = 0; i < <URL>unt; i++) {
const x = <URL>tX(i) + worldPos.x;
const z = <URL>tZ(i) + worldPos.z;
const h = getHeightAt(x, z);
<URL>tY(i, h);
heightData[i] = h;
}
const normalMap = createNormalMap(heightData, chunkResolution + 1, chunkResolution + 1);
const material = new <URL>shStandardMaterial({
map: terrainTexture,
normalMap: normalMap,
normalScale: new <URL>ctor2(2, 2),
roughness: 0.8,
metalness: 0.1,
side: <URL>ubleSide
});
<URL>puteVertexNormals();
const chunk = new <URL>sh(geometry, material);
<URL>t(worldPos.x, <DATE_TIME>, worldPos.z);
<URL>ceiveShadow = true;
<URL>stShadow = true;
<URL>d(chunk);
const chunkInfo = { mesh: chunk, heightData: heightData, trees: [], grass: [] };
addTreesToChunk(chunkInfo, chunkX, chunkZ);
addGrassToChunk(chunkInfo, chunkX, chunkZ);
<URL>t(chunkKey, chunkInfo);
<URL>unksCreated++;
<URL>unksActive++;
return chunkInfo;
}
// ── <REDACTED> ─────────────────────────────
function createAdvancedTree(height = 1.0, complexity = 1.0) {
const treeGroup = new <URL>();
const treeType = Math.random() > 0.5 ? 0 : 1;
const trunkHeight = height * (3 + Math.random() * 2);
const trunkRadius = 0.1 + Math.random() * 0.2;
const barkCanvas = <URL>eateElement('canvas');
barkCanvas.width = 128;
barkCanvas.height = 128;
const <REDACTED> = <URL>tContext('2d');
<URL>llStyle = `rgb(${Math.floor(80 + Math.random() * 40)}, ${Math.floor(40 + Math.random() * 30)}, ${Math.floor(20 + Math.random() * 20)})`;
<URL>llRect(0, 0, 128, 128);
for (let i = 0; i < 100; i++) {
const x = Math.random() * 128;
const y = Math.random() * 128;
const w = 1 + Math.random() * 3;
const h = 3 + Math.random() * 15;
<URL>llStyle = `rgba(${Math.floor(60 + Math.random() * 40)}, ${Math.floor(30 + Math.random() * 20)}, ${Math.floor(10 + Math.random() * 15)}, ${0.3 + Math.random() * 0.7})`;
<URL>llRect(x, y, w, h);
}
const barkTexture = new <URL>nvasTexture(barkCanvas);
barkTexture.wrapS = <URL>peatWrapping;
barkTexture.wrapT = <URL>peatWrapping;
<URL>t(2, 4);
const trunkGeometry = new <URL>linderGeometry(trunkRadius * 0.7, trunkRadius * 1.3, trunkHeight, <REDACTED>;
const trunkMaterial = new <URL>shStandardMaterial({
map: barkTexture,
roughness: 0.9,
metalness: 0.0,
bumpMap: barkTexture,
bumpScale: 0.2
});
const trunk = new <REDACTED>, trunkMaterial);
trunk.position.y = trunkHeight / 2;
<URL>stShadow = true;
<URL>ceiveShadow = true;
<URL>d(trunk);
const leafTexture = getCachedLeafTexture(treeType === 0);
if (treeType === 0) {
const levels = Math.floor(2 + complexity * 3);
for (let i = 0; i < levels; i++) {
const ratio = i / levels;
const y = trunkHeight * (0.4 + ratio * 0.6);
const radius = 1.5 * height * (1 - ratio * 0.5) * (0.8 + Math.random() * 0.4);
const coneGeometry = new <URL>neGeometry(radius, trunkHeight * 0.5, 8);
const leavesColor = new <URL>lor(
0.0 + Math.random() * 0.1,
0.3 + Math.random() * 0.2,
0.0 + Math.random() * 0.1
);
const coneMaterial = new <URL>shStandardMaterial({
map: leafTexture,
color: leavesColor,
roughness: 0.8,
metalness: 0.0,
alphaTest: 0.2,
transparent: true,
side: <URL>ubleSide
});
const cone = new <URL>sh(coneGeometry, coneMaterial);
cone.position.y = y;
<URL>stShadow = true;
<URL>ceiveShadow = true;
<URL>d(cone);
}
} else {
const radius = height * (1.5 + Math.random());
const sphereGeometry = new THREE.SphereGeometry(radius, 8, <DATE_TIME>);
const positions = <URL>tributes.position;
for (let i = 0; i < <URL>unt; i++) {
const x = <URL>tX(i);
const y = <URL>tY(i);
const z = <URL>tZ(i);
const noise = <URL>ise3D(x * 0.5, y * 0.5, z * 0.5) * 0.3 * radius;
<URL>tX(i, x + noise * (x / radius));
<URL>tY(i, y + noise * (y / radius));
<URL>tZ(i, z + noise * (z / radius));
}
<URL>puteVertexNormals();
const leavesColor = new <URL>lor(
0.0 + Math.random() * 0.2,
0.3 + Math.random() * 0.3,
0.0 + Math.random() * 0.1
);
const leavesMaterial = new <URL>shStandardMaterial({
map: leafTexture,
color: leavesColor,
roughness: 0.8,
metalness: 0.0,
transparent: true,
alphaTest: 0.2,
side: <URL>ubleSide
});
const leaves = new <URL>sh(sphereGeometry, leavesMaterial);
leaves.position.y = trunkHeight * 0.8;
<URL>stShadow = true;
<URL>ceiveShadow = true;
<URL>d(leaves);
}
const tiltAngle = Math.random() * 0.2;
const tiltDirection = Math.random() * Math.PI * 2;
<URL>tation.x = <URL>n(tiltDirection) * tiltAngle;
<URL>tation.z = <URL>s(tiltDirection) * tiltAngle;
return treeGroup;
}
function addTreesToChunk(chunkInfo, chunkX, chunkZ) {
const worldPos = getWorldPosition(chunkX, chunkZ);
const numTrees = 30 + Math.floor(Math.random() * 20);
const seed = chunkX * 10000 + chunkZ;
const random = new <URL>edrandom(<URL>String());
for (let i = 0; i < numTrees; i++) {
const localX = random() * chunkSize;
const localZ = random() * chunkSize;
const worldX = worldPos.x + localX;
const worldZ = worldPos.z + localZ;
const h = getHeightAt(worldX, worldZ);
if (h > 2 && h < 20) {
const treeComplexity = 0.5 + random() * 0.5;
const treeHeight = 0.7 + random() * 0.6;
const tree = createAdvancedTree(treeHeight, treeComplexity);
<URL>t(worldX, h, worldZ);
<URL>d(tree);
<URL>ees.push(tree);
}
}
}
function addGrassToChunk(chunkInfo, chunkX, chunkZ) {
const worldPos = getWorldPosition(chunkX, chunkZ);
const numGrass = 150 + Math.floor(Math.random() * 50);
const seed = chunkX * 20000 + chunkZ;
const random = new <URL>edrandom(<URL>String());
function createGrassTexture() {
const canvas = <URL>eateElement('canvas');
canvas.width = 64;
canvas.height = 64;
const ctx = <URL>tContext('2d');
<URL>earRect(0, 0, <DATE_TIME>, <DATE_TIME>);
const grassType = random() > 0.7 ? 1 : 0;
const baseColor = {
r: 40 + random() * 40,
g: 100 + random() * 70,
b: 20 + random() * 40
};
for (let i = 0; i < 15; i++) {
const centerX = 32;
const startY = 64;
const controlX = centerX + (random() * 20 - 10);
const controlY = 40 + random() * 20;
const endX = centerX + (random() * 30 - 15);
const endY = 5 + random() * 20;
const width = 1 + random() * 2;
const colorVariation = random() * 20 - 10;
<URL>rokeStyle = `rgb(${Math.floor(baseColor.r + colorVariation)}, ${Math.floor(baseColor.g + colorVariation)}, ${Math.floor(baseColor.b + colorVariation)})`;
<URL>neWidth = width;
<URL>neCap = 'round';
<URL>ginPath();
<URL>eTo(centerX, startY);
ctx.quadraticCurveTo(controlX, controlY, endX, endY);
<URL>roke();
if (grassType === 1 && random() > 0.7) {
const flowerX = endX;
const flowerY = endY + 5;
const flowerSize = 2 + random() * 3;
const flowerColors = ['#FFFFFF', '#FFD700', '#FF6347', '#9370DB', '#FF69B4'];
const flowerColor = flowerColors[Math.floor(random() * flowerColors.length)];
<URL>llStyle = flowerColor;
for (let j = 0; j < 5; j++) {
const angle = j * Math.PI * 2 / 5;
const petalX = flowerX + <URL>s(angle) * flowerSize;
const petalY = flowerY + <URL>n(angle) * flowerSize;
<URL>ginPath();
<URL>c(petalX, petalY, flowerSize, 0, Math.PI * 2);
<URL>ll();
}
<URL>llStyle = '#FFFF00';
<URL>ginPath();
<URL>c(flowerX, flowerY, flowerSize * 0.5, 0, Math.PI * 2);
<URL>ll();
}
}
return new <URL>nvasTexture(canvas);
}
const grassTexture = createGrassTexture();
const grassItems = <REDACTED>();
for (let i = 0; i < numGrass; i++) {
const localX = random() * chunkSize;
const localZ = random() * chunkSize;
const worldX = worldPos.x + localX;
const worldZ = worldPos.z + localZ;
const h = getHeightAt(worldX, worldZ);
if (h > 0.5 && h < 18) {
const grassHeight = 0.4 + random() * 0.6;
const grassWidth = 0.3 + random() * 0.4;
const grassColor = new <URL>lor(
0.1 + random() * 0.1,
0.4 + random() * 0.3,
0.1 + random() * 0.1
);
const grassGeometry = new <URL>aneGeometry(grassWidth, grassHeight);
const grassMaterial = new <URL>shStandardMaterial({
map: grassTexture,
color: grassColor,
roughness: 0.9,
metalness: 0.0,
side: <URL>ubleSide,
transparent: true,
alphaTest: 0.1
});
const grass1 = new <URL>sh(grassGeometry, grassMaterial);
const grass2 = new <URL>sh(grassGeometry, grassMaterial);
<URL>tation.y = Math.PI / 2;
const tiltAngle = random() * 0.3;
const tiltDirection = random() * Math.PI * 2;
<URL>tation.x = <URL>n(tiltDirection) * tiltAngle;
<URL>tation.z = <URL>s(tiltDirection) * tiltAngle;
const grassGroup = new <URL>();
<URL>d(grass1);
<URL>d(grass2);
<URL>t(worldX, h, worldZ);
<URL>d(grassGroup);
}
}
<URL>d(grassItems);
<URL>ass.push(grassItems);
}
// ── チャンク管理と更新 ─────────────────────────────
function updateChunks() {
const playerChunkCoords = getChunkCoords(camera.position.x, <DATE_TIME>);
if (playerChunkCoords.x !== currentChunkX || playerChunkCoords.z !== currentChunkZ) {
currentChunkX = playerChunkCoords.x;
currentChunkZ = playerChunkCoords.z;
coordinatesElement.textContent = `座標: X: ${Math.floor(camera.position.x)}, Z: ${Math.floor(camera.position.z)} | チャンク数: ${<URL>unksActive}/${<URL>unksCreated}`;
const chunksToRender = new Set();
const removeDistance = viewDistance + 1;
for (let x = -viewDistance; x <= viewDistance; <REDACTED>) {
for (let z = -viewDistance; z <= viewDistance; z++) {
const cx = currentChunkX + x;
const cz = currentChunkZ + z;
const chunkKey = `${cx},${cz}`;
<URL>d(chunkKey);
if (!chunks.has(chunkKey)) generateChunk(cx, cz);
}
}
for (const [key, chunkInfo] of chunks.entries()) {
if (!chunksToRender.has(key)) {
const [cx, cz] = key.split(',').map(Number);
const distance = Math.abs(cx - currentChunkX) + Math.abs(cz - currentChunkZ);
if (distance > removeDistance) {
<URL>move(<URL>sh);
<URL>rEach(tree => <URL>move(tree));
<URL>rEach(grass => <URL>move(grass));
<URL>lete(key);
<URL>unksActive--;
}
}
}
}
}
// ── 水面、ライト、空・雲の設定 ─────────────────────────────
function addWater() {
const waterGeometry = new <URL>aneGeometry(chunkSize * (viewDistance * 4), chunkSize * (viewDistance * 4));
const waterMaterial = new <URL>shStandardMaterial({
color: 0x2389da,
transparent: true,
opacity: 0.6,
roughness: 0.1,
metalness: 0.1
});
const water = new <URL>sh(waterGeometry, waterMaterial);
<URL>tation.x = -Math.PI / 2;
water.position.y = 0.5;
function updateWater() {
water.position.x = camera.position.x;
water.position.z = <DATE_TIME>;
}
<URL>d(water);
return updateWater;
}
function setupLights() {
const ambientLight = new <URL>bientLight(0xffffff, 0.5);
<URL>d(ambientLight);
const directionalLight = new <URL>ionalLight(0xffffff, 0.8);
<URL>t(50, 100, 50);
<URL>stShadow = true;
<URL>pSize.width = 2048;
<URL>pSize.height = 2048;
<URL>era.left = -100;
<URL>era.right = 100;
<URL> = 100;
<URL>tom = -100;
<URL>era.far = 250;
<URL>as = -0.0005;
<URL>d(directionalLight);
const fillLight = new <URL>ionalLight(0x90a0ff, 0.15);
<URL>t(-50, 80, <REDACTED>);
<URL>d(fillLight);
function updateLights() {
directionalLight.position.x = camera.position.x + 50;
directionalLight.position.z = <DATE_TIME>;
fillLight.position.x = camera.position.x - 50;
fillLight.position.z = camera.position.z - 50;
}
return updateLights;
}
function addSkyAndClouds() {
const skyGeometry = new <REDACTED>, <DATE_TIME>, <DATE_TIME>);
<URL>ale(-1, 1, 1);
const skyCanvas = <URL>eateElement('canvas');
skyCanvas.width = 1024;
skyCanvas.height = 1024;
const skyCtx = <URL>tContext('2d');
const skyGradient = <URL>eateLinearGradient(0, 0, 0, 1024);
<URL>dColorStop(0, '#1e90ff');
<URL>dColorStop(0.4, '#87ceeb');
<URL>dColorStop(1, '#e0f2f7');
<URL>llStyle = skyGradient;
<DATE_TIME>, 0, 1024, 1024);
const skyTexture = new <URL>nvasTexture(skyCanvas);
const skyMaterial = new <URL>shBasicMaterial({ map: skyTexture, side: <URL>ckSide });
const sky = new <URL>sh(skyGeometry, skyMaterial);
function updateSky() {
sky.position.x = camera.position.x;
sky.position.z = <DATE_TIME>;
}
<URL>d(sky);
const cloudParticles = [];
const cloudCount = 50;
for (let i = 0; i < cloudCount; i++) {
const cloudSize = 10 + Math.random() * 20;
const cloudHeight = 50 + Math.random() * 30;
const radius = chunkSize * 0.5 + Math.random() * chunkSize * 0.5;
const angle = Math.random() * Math.PI * 2;
const x = <URL>s(angle) * radius;
const z = <URL>n(angle) * radius;
const cloudCanvas = <URL>eateElement('canvas');
cloudCanvas.width = 128;
cloudCanvas.height = 128;
const <REDACTED> = <URL>tContext('2d');
// 輪郭をぼかすためにフィルターを適用
<URL>lter = "blur(2px)";
<URL>llStyle = '#ffffff';
const circles = 5 + Math.floor(Math.random() * 5);
for (let j = 0; j < circles; j++) {
const circleX = 64 + (Math.random() * 40 - 20);
const circleY = <DATE_TIME> (Math.random() * 40 - 20);
const circleRadius = 20 + Math.random() * 20;
<URL>ginPath();
<URL>c(circleX, circleY, circleRadius, 0, Math.PI * 2);
<URL>ll();
}
const cloudTexture = new <URL>nvasTexture(cloudCanvas);
const cloudMaterial = new THREE.SpriteMaterial({
map: cloudTexture,
transparent: true,
opacity: 0.7
});
const cloud = new THREE.Sprite(cloudMaterial);
<URL>t(cloudSize, cloudSize * 0.6, 1);
<URL>t(x, cloudHeight, z);
// 移動速度を低減(0.05 係数)
<URL>erData = {
speed: (0.01 + Math.random() * 0.03) * 0.05,
angle: angle,
radius: radius
};
<URL>d(cloud);
cloudParticles.push(cloud);
}
function updateClouds(delta) {
<URL>rEach(cloud => {
<URL>gle += <URL>erData.speed * delta;
cloud.position.x = camera.position.x + <URL>s(<URL>gle) * <URL>erData.radius;
cloud.position.z = camera.position.z + <URL>n(<URL>gle) * <URL>erData.radius;
});
}
return { updateSky, updateClouds, cloudParticles };
}
<URL>t(0, 5, 0);
camera.lookAt(0, <DATE_TIME>, -10);
// ── プレイヤー操作設定 ─────────────────────────────
let verticalVelocity = 0;
let isJumping = false;
let moveBackward = false, moveRight = false, moveLeft = false, jump = false;
// Wキーはペダル操作により自動前進するので無効、その他は従来通り
<URL>dEventListener('keydown', function(event) {
switch (<URL>LowerCase()) {
case 's': moveBackward = true; break;
case 'a': moveLeft = true; break;
case 'd': moveRight = true; break;
case ' ': if (!isJumping) jump = true; break;
}
});
<URL>dEventListener('keyup', function(event) {
switch (<URL>LowerCase()) {
case 's': moveBackward = false; break;
case 'a': moveLeft = false; break;
case 'd': moveRight = false; break;
case ' ': jump = false; break;
}
});
let mouseX = 0, mouseY = 0;
let isMouseDown = false;
<URL>dEventListener('mousedown', function() { isMouseDown = true; });
<URL>dEventListener('mouseup', function() { isMouseDown = false; });
<URL>dEventListener('mousemove', function(event) {
if (isMouseDown) {
const movementX = <URL>ementX || 0;
const movementY = <URL>ementY || 0;
mouseX -= movementX * 0.002;
mouseY -= movementY * 0.002;
mouseY = <URL>x(-Math.PI/2+0.1, Math.min(Math.PI/2-0.1, mouseY));
}
});
// 擬似乱数生成器
<URL>edrandom = function(seed) {
function mulberry32(a) {
return function() {
let t = a += 0x6D2B79F5;
t = <URL>ul(t ^ t >>> 15, t | 1);
t ^= t + <URL>ul(t ^ t >>> 7, t | 61);
return ((t ^ t >>> 14) >>> <REDACTED>;
};
}
const seedNumber = seed.split('').reduce((a, b) => {
a = ((a << 5) - a) + <URL>arCodeAt(0);
return a & a;
}, 0);
return mulberry32(seedNumber);
};
// ── ゲーム初期化とアニメーションループ ─────────────────────────────
async function initGame() {
initLeafTextureCache();
for (let x = -viewDistance; x <= viewDistance; <REDACTED>) {
for (let z = -viewDistance; z <= viewDistance; z++) {
generateChunk(x, z);
}
}
const updateWater = <REDACTED>();
const updateLights = setupLights();
const { updateSky, updateClouds } = addSkyAndClouds();
<URL>tElementById('loading').style.display = 'none';
requestAnimationFrame(animate);
let lastTime = 0;
function animate(time) {
requestAnimationFrame(animate);
const delta = lastTime ? (time - lastTime) / 16 : 1;
lastTime = time;
// マウス操作による視点更新
<URL>tation.x = mouseY;
<URL>tation.y = mouseX;
// ペダルシミュレーターから速度取得と表示更新
const pedalSpeed = <URL>tSpeed();
<URL>tElementById('speedDisplay').textContent = `ペダル速度: ${<URL>Fixed(1)} km/h`;
// km/h -> m/s: 1km/h = <DATE_TIME>, 1 frame(約16ms)に換算すると1/216 m/frame
const conversionFactor = 1 / 216;
let effectiveSpeed = pedalSpeed * conversionFactor;
// 勾配補正:前方2m先の地形高さをサンプリング
const direction = new <URL>ctor3();
<URL>tWorldDirection(direction);
direction.y = 0;
<URL>rmalize();
const sampleDistance = 2; // サンプル距離 2m
const currentHeight = <REDACTED>, <DATE_TIME>);
const sampleX = camera.position.x + direction.x * sampleDistance;
const sampleZ = <DATE_TIME> * sampleDistance;
const aheadHeight = getHeightAt(sampleX, sampleZ);
const slope = (aheadHeight - currentHeight) / sampleDistance; // 勾配(上りなら正)
const slopeCoefficient = 0.5; // 補正感度
const slopeFactor = <URL>x(0.2, 1 - slopeCoefficient * slope);
effectiveSpeed *= slopeFactor;
// 速度ベクトル計算(自動前進+左右・後退操作)
const velocity = new <URL>ctor3();
const sideDirection = new <URL>ctor3(-direction.z, 0, direction.x);
<URL>d(<URL>ltiplyScalar(effectiveSpeed * delta));
if (moveBackward) <URL>b(<URL>one().multiplyScalar(0.4 * delta));
if (moveRight) <URL>d(<URL>ltiplyScalar(0.4 * delta));
if (moveLeft) <URL>b(<URL>one().multiplyScalar(0.4 * delta));
// ジャンプ処理
if (jump && !isJumping) {
verticalVelocity = 0.15;
isJumping = true;
}
verticalVelocity -= 0.006 * delta;
camera.position.x += velocity.x;
camera.position.z += velocity.z;
camera.position.y += verticalVelocity * delta;
const terrainHeight = <REDACTED>, <DATE_TIME>);
if (camera.position.y < terrainHeight + 2) {
camera.position.y = terrainHeight + 2;
verticalVelocity = 0;
isJumping = false;
}
if (camera.position.y < 2.5) {
camera.position.y = 2.5;
verticalVelocity = 0;
}
updateChunks();
updateWater();
updateLights();
updateSky();
updateClouds(delta);
<URL>nder(scene, camera);
}
}
initGame();
このコードでは、
移動速度の調整ペダルシミュレーターの推定速度(km/h)を 1/216 の係数で m/frame 。
ペダルシミュレーターの推定速度(km/h)を 1/216 の係数で m/frame 。
雲の表現の変更雲のテクスチャ描画時にlter = "blur(2px)"を適用し、輪郭をぼかしています。また、各雲の移動速度を従来の 0.1 倍から 0.05 倍に変更することで、よりゆっくりとした流れに調整しています。
雲のテクスチャ描画時にlter = "blur(2px)"を適用し、輪郭をぼかしています。
また、各雲の移動速度を従来の 0.1 倍から 0.05 倍に変更することで、よりゆっくりとした流れに調整しています。
移動速度の調整
ペダルシミュレーターの推定速度(km/h)を 1/216 の係数で m/frame 。
ペダルシミュレーターの推定速度(km/h)を 1/216 の係数で m/frame 。
雲の表現の変更
雲のテクスチャ描画時にlter = "blur(2px)"を適用し、輪郭をぼかしています。
また、各雲の移動速度を従来の 0.1 倍から 0.05 倍に変更することで、よりゆっくりとした流れに調整しています。
雲のテクスチャ描画時にlter = "blur(2px)"を適用し、輪郭をぼかしています。
また、各雲の移動速度を従来の 0.1 倍から 0.05 倍に変更することで、よりゆっくりとした流れに調整しています。
必要に応じて、補正係数やサンプル距離、ぼかしの強さなどのパラメータを調整してください。