<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>jmohuiのブログ</title>
<link>https://ameblo.jp/jmohui/</link>
<atom:link href="https://rssblog.ameba.jp/jmohui/rss20.xml" rel="self" type="application/rss+xml" />
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
<description>ブログの説明を入力します。</description>
<language>ja</language>
<item>
<title>あれ.json</title>
<description>
<![CDATA[ <p>{</p><p>&nbsp; "airbases": [</p><p>&nbsp; &nbsp; {"name": "浜松基地", &nbsp; "lon": 137.7031, "lat": 34.7503},</p><p>&nbsp; &nbsp; {"name": "岐阜基地", &nbsp; "lon": 136.8697, "lat": 35.3942},</p><p>&nbsp; &nbsp; {"name": "名古屋空港", "lon": 136.9244, "lat": 35.2550},</p><p>&nbsp; &nbsp; {"name": "小松基地", &nbsp; "lon": 136.4065, "lat": 36.3946}</p><p>&nbsp; ],</p><p>&nbsp; "airspaces": [</p><p>&nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; "id": "G",</p><p>&nbsp; &nbsp; &nbsp; "name": "G空域 (※公式座標へ要差替)",</p><p>&nbsp; &nbsp; &nbsp; "color": "#00e5ff",</p><p>&nbsp; &nbsp; &nbsp; "min_alt_m": 1500,</p><p>&nbsp; &nbsp; &nbsp; "max_alt_m": 15000,</p><p>&nbsp; &nbsp; &nbsp; "polygon": [</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [135.80, 36.60], [136.65, 37.35], [137.05, 37.55],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [136.25, 37.55], [135.45, 36.95], [135.80, 36.60]</p><p>&nbsp; &nbsp; &nbsp; ]</p><p>&nbsp; &nbsp; },</p><p>&nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; "id": "K",</p><p>&nbsp; &nbsp; &nbsp; "name": "K空域 (※公式座標へ要差替)",</p><p>&nbsp; &nbsp; &nbsp; "color": "#ffab00",</p><p>&nbsp; &nbsp; &nbsp; "min_alt_m": 1500,</p><p>&nbsp; &nbsp; &nbsp; "max_alt_m": 15000,</p><p>&nbsp; &nbsp; &nbsp; "polygon": [</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [137.45, 34.58], [138.30, 34.58], [138.55, 34.80],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [137.85, 34.62], [137.45, 34.58]</p><p>&nbsp; &nbsp; &nbsp; ]</p><p>&nbsp; &nbsp; },</p><p>&nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; "id": "J",</p><p>&nbsp; &nbsp; &nbsp; "name": "J空域 (※公式座標へ要差替)",</p><p>&nbsp; &nbsp; &nbsp; "color": "#ff5252",</p><p>&nbsp; &nbsp; &nbsp; "min_alt_m": 3000,</p><p>&nbsp; &nbsp; &nbsp; "max_alt_m": 15000,</p><p>&nbsp; &nbsp; &nbsp; "polygon": [</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [135.42, 35.65], [136.05, 35.95], [135.95, 36.45],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [135.42, 36.25], [135.42, 35.65]</p><p>&nbsp; &nbsp; &nbsp; ]</p><p>&nbsp; &nbsp; }</p><p>&nbsp; ],</p><p>&nbsp; "aircraft_placements": [</p><p>&nbsp; &nbsp; {"name": "F-15J #1", "lon": 136.25, "lat": 36.75, "alt_m": 4500, "heading_deg": 35},</p><p>&nbsp; &nbsp; {"name": "F-15J #2", "lon": 136.19, "lat": 36.70, "alt_m": 4500, "heading_deg": 35},</p><p>&nbsp; &nbsp; {"name": "F-15J #3", "lon": 137.85, "lat": 34.65, "alt_m": 5000, "heading_deg": 90}</p><p>&nbsp; ],</p><p>&nbsp; "f15j_mesh": {</p><p>&nbsp; &nbsp; "unit": "meters",</p><p>&nbsp; &nbsp; "vertices": [</p><p>&nbsp; &nbsp; &nbsp; [0.0, 9.7, 0.0],</p><p>&nbsp; &nbsp; &nbsp; [0.0, 6.5, 0.65], [0.55, 6.5, 0.0], [0.0, 6.5, -0.55], [-0.55, 6.5, 0.0],</p><p>&nbsp; &nbsp; &nbsp; [0.0, 4.8, 1.35], [0.0, 2.5, 1.30],</p><p>&nbsp; &nbsp; &nbsp; [0.0, 2.5, 0.85], [1.55, 2.8, 0.70], [1.55, 2.8, -0.65],</p><p>&nbsp; &nbsp; &nbsp; [0.0, 2.5, -0.75], [-1.55, 2.8, -0.65], [-1.55, 2.8, 0.70],</p><p>&nbsp; &nbsp; &nbsp; [0.0, -6.5, 0.80], [1.45, -6.5, 0.65], [1.45, -6.5, -0.60],</p><p>&nbsp; &nbsp; &nbsp; [0.0, -6.5, -0.65], [-1.45, -6.5, -0.60], [-1.45, -6.5, 0.65],</p><p>&nbsp; &nbsp; &nbsp; [0.0, -9.0, 0.45], [0.0, -9.0, -0.40],</p><p>&nbsp; &nbsp; &nbsp; [0.80, -9.7, 0.50], [1.25, -9.7, 0.0], [0.80, -9.7, -0.45], [0.35, -9.7, 0.0],</p><p>&nbsp; &nbsp; &nbsp; [-0.80, -9.7, 0.50], [-0.35, -9.7, 0.0], [-0.80, -9.7, -0.45], [-1.25, -9.7, 0.0],</p><p>&nbsp; &nbsp; &nbsp; [1.50, 2.2, 0.40], [6.525, -2.3, 0.25], [6.525, -4.4, 0.25], [1.48, -4.5, 0.35],</p><p>&nbsp; &nbsp; &nbsp; [-1.50, 2.2, 0.40], [-6.525, -2.3, 0.25], [-6.525, -4.4, 0.25], [-1.48, -4.5, 0.35],</p><p>&nbsp; &nbsp; &nbsp; [1.45, -5.8, 0.15], [4.30, -8.3, 0.10], [4.30, -9.4, 0.10], [1.35, -8.7, 0.15],</p><p>&nbsp; &nbsp; &nbsp; [-1.45, -5.8, 0.15], [-4.30, -8.3, 0.10], [-4.30, -9.4, 0.10], [-1.35, -8.7, 0.15],</p><p>&nbsp; &nbsp; &nbsp; [1.25, -4.6, 0.65], [1.38, -7.2, 4.80], [1.38, -8.7, 4.80], [1.25, -8.5, 0.60],</p><p>&nbsp; &nbsp; &nbsp; [-1.25, -4.6, 0.65], [-1.38, -7.2, 4.80], [-1.38, -8.7, 4.80], [-1.25, -8.5, 0.60],</p><p>&nbsp; &nbsp; &nbsp; [0.45, 3.6, 0.85], [-0.45, 3.6, 0.85]</p><p>&nbsp; &nbsp; ],</p><p>&nbsp; &nbsp; "faces": [</p><p>&nbsp; &nbsp; &nbsp; [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1],</p><p>&nbsp; &nbsp; &nbsp; [1, 5, 53], [5, 6, 53], [6, 7, 53], [1, 54, 5], [5, 54, 6], [6, 54, 7],</p><p>&nbsp; &nbsp; &nbsp; [1, 53, 2], [2, 53, 8], [53, 7, 8], [1, 4, 54], [4, 12, 54], [54, 12, 7],</p><p>&nbsp; &nbsp; &nbsp; [2, 8, 9], [2, 9, 3], [3, 9, 10], [4, 11, 12], [4, 3, 11], [3, 10, 11],</p><p>&nbsp; &nbsp; &nbsp; [7, 13, 14], [7, 14, 8], [7, 18, 13], [7, 12, 18],</p><p>&nbsp; &nbsp; &nbsp; [8, 14, 15], [8, 15, 9], [12, 11, 17], [12, 17, 18],</p><p>&nbsp; &nbsp; &nbsp; [9, 15, 16], [9, 16, 10], [11, 10, 16], [11, 16, 17],</p><p>&nbsp; &nbsp; &nbsp; [13, 19, 20], [13, 20, 16],</p><p>&nbsp; &nbsp; &nbsp; [13, 19, 24], [13, 24, 21], [13, 21, 14], [14, 21, 22], [14, 22, 15],</p><p>&nbsp; &nbsp; &nbsp; [15, 22, 23], [15, 23, 16], [16, 23, 24], [16, 24, 20], [20, 19, 24],</p><p>&nbsp; &nbsp; &nbsp; [21, 22, 23], [21, 23, 24],</p><p>&nbsp; &nbsp; &nbsp; [13, 26, 19], [13, 25, 26], [13, 18, 25], [18, 28, 25], [18, 17, 28],</p><p>&nbsp; &nbsp; &nbsp; [17, 27, 28], [17, 16, 27], [16, 26, 27], [16, 20, 26], [20, 19, 26],</p><p>&nbsp; &nbsp; &nbsp; [25, 28, 27], [25, 27, 26],</p><p>&nbsp; &nbsp; &nbsp; [29, 30, 31], [29, 31, 32], [33, 35, 34], [33, 36, 35],</p><p>&nbsp; &nbsp; &nbsp; [37, 38, 39], [37, 39, 40], [41, 43, 42], [41, 44, 43],</p><p>&nbsp; &nbsp; &nbsp; [45, 46, 47], [45, 47, 48], [49, 51, 50], [49, 52, 51]</p><p>&nbsp; &nbsp; ],</p><p>&nbsp; &nbsp; "face_colors": [</p><p>&nbsp; &nbsp; &nbsp; "#4e565e", "#4e565e", "#4e565e", "#4e565e",</p><p>&nbsp; &nbsp; &nbsp; "#182635", "#182635", "#182635", "#182635", "#182635", "#182635",</p><p>&nbsp; &nbsp; &nbsp; "#8c98a4", "#8c98a4", "#8c98a4", "#8c98a4", "#8c98a4", "#8c98a4",</p><p>&nbsp; &nbsp; &nbsp; "#8c98a4", "#8c98a4", "#7a8692", "#8c98a4", "#8c98a4", "#7a8692",</p><p>&nbsp; &nbsp; &nbsp; "#8c98a4", "#8c98a4", "#8c98a4", "#8c98a4",</p><p>&nbsp; &nbsp; &nbsp; "#84909c", "#84909c", "#84909c", "#84909c",</p><p>&nbsp; &nbsp; &nbsp; "#74808c", "#74808c", "#74808c", "#74808c",</p><p>&nbsp; &nbsp; &nbsp; "#7a8692", "#74808c",</p><p>&nbsp; &nbsp; &nbsp; "#2d3238", "#2d3238", "#2d3238", "#2d3238", "#2d3238",</p><p>&nbsp; &nbsp; &nbsp; "#2d3238", "#2d3238", "#2d3238", "#2d3238", "#2d3238",</p><p>&nbsp; &nbsp; &nbsp; "#111315", "#111315",</p><p>&nbsp; &nbsp; &nbsp; "#2d3238", "#2d3238", "#2d3238", "#2d3238", "#2d3238",</p><p>&nbsp; &nbsp; &nbsp; "#2d3238", "#2d3238", "#2d3238", "#2d3238", "#2d3238",</p><p>&nbsp; &nbsp; &nbsp; "#111315", "#111315",</p><p>&nbsp; &nbsp; &nbsp; "#94a0ac", "#94a0ac", "#94a0ac", "#94a0ac",</p><p>&nbsp; &nbsp; &nbsp; "#8a96a2", "#8a96a2", "#8a96a2", "#8a96a2",</p><p>&nbsp; &nbsp; &nbsp; "#84909c", "#84909c", "#84909c", "#84909c"</p><p>&nbsp; &nbsp; ]</p><p>&nbsp; }</p><p>}</p>
]]>
</description>
<link>https://ameblo.jp/jmohui/entry-12985394861.html</link>
<pubDate>Mon, 23 Nov 2026 13:35:38 +0900</pubDate>
</item>
<item>
<title>あれ2.2</title>
<description>
<![CDATA[ <p>&nbsp; // VSI &amp; Yaw自動補完</p><p>&nbsp; const autoYaw = (colsMeta.cYaw === -1);</p><p>&nbsp; for (let i = 0; i &lt; store.len; i++) {</p><p>&nbsp; &nbsp; const p = Math.max(0, i - 1), n = Math.min(store.len - 1, i + 1);</p><p>&nbsp; &nbsp; const dt = Math.max(0.01, store.t[n] - store.t[p]);</p><p>&nbsp; &nbsp; store.vsi[i] = (store.alt[n] - store.alt[p]) / dt;</p><p>&nbsp; &nbsp; if (autoYaw &amp;&amp; i &lt; store.len - 1) {</p><p>&nbsp; &nbsp; &nbsp; store.yaw[i] = (Math.atan2(store.mx[n] - store.mx[p], store.my[n] - store.my[p]) * 180 / Math.PI + 360) % 360;</p><p>&nbsp; &nbsp; }</p><p>&nbsp; }</p><p>&nbsp; if (autoYaw &amp;&amp; store.len &gt; 1) store.yaw[store.len - 1] = store.yaw[store.len - 2];</p><p>&nbsp;</p><p>&nbsp; // GPU航跡は最大12,000点へ均等サンプリングして軽量維持</p><p>&nbsp; const MAX_TRAIL_PTS = 12000;</p><p>&nbsp; const tStep = Math.max(1, Math.floor(store.len / MAX_TRAIL_PTS));</p><p>&nbsp; const tIdx = [];</p><p>&nbsp; for (let i = 0; i &lt; store.len; i += tStep) tIdx.push(i);</p><p>&nbsp; if (tIdx[tIdx.length - 1] !== store.len - 1) tIdx.push(store.len - 1);</p><p>&nbsp;</p><p>&nbsp; trailCount = tIdx.length;</p><p>&nbsp; const trailPos = new Float32Array(trailCount * 3);</p><p>&nbsp; const trailColAll = new Float32Array(trailCount * 3);</p><p>&nbsp; const trailNorm = new Float32Array(trailCount * 3);</p><p>&nbsp; for (let k = 0; k &lt; trailCount; k++) {</p><p>&nbsp; &nbsp; const idx = tIdx[k];</p><p>&nbsp; &nbsp; trailPos[k*3] = store.mx[idx]; trailPos[k*3+1] = store.my[idx]; trailPos[k*3+2] = store.alt[idx];</p><p>&nbsp; &nbsp; trailColAll[k*3] = 0.0; trailColAll[k*3+1] = 0.96; trailColAll[k*3+2] = 1.0;</p><p>&nbsp; &nbsp; trailNorm[k*3+2] = 1.0;</p><p>&nbsp; }</p><p>&nbsp;</p><p>&nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, trailPB); gl.bufferData(gl.ARRAY_BUFFER, trailPos, gl.STATIC_DRAW);</p><p>&nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, trailFullColB); gl.bufferData(gl.ARRAY_BUFFER, trailColAll, gl.STATIC_DRAW);</p><p>&nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, trailNB); gl.bufferData(gl.ARRAY_BUFFER, trailNorm, gl.STATIC_DRAW);</p><p>&nbsp;</p><p>&nbsp; fStore = store;</p><p>&nbsp; totalDuration = Math.max(0.1, store.t[store.len - 1]);</p><p>&nbsp; simTime = 0;</p><p>&nbsp; currentIdx = 0;</p><p>&nbsp;</p><p>&nbsp; const sb = document.getElementById("seek-bar");</p><p>&nbsp; sb.value = 0; sb.disabled = false;</p><p>&nbsp; document.getElementById("btn-play").disabled = false;</p><p>&nbsp; document.getElementById("btn-stop").disabled = false;</p><p>&nbsp; document.getElementById("hud-status").textContent = "READY";</p><p>&nbsp; drawMiniChartBg();</p><p>&nbsp; updateHUD(sampleFlightAt(0));</p><p>}</p><p>&nbsp;</p><p>function fmtTime(sec) {</p><p>&nbsp; const m = Math.floor(sec / 60);</p><p>&nbsp; const s = (sec % 60).toFixed(1).padStart(4, "0");</p><p>&nbsp; return `${String(m).padStart(2, "0")}:${s}`;</p><p>}</p><p>&nbsp;</p><p>function updateHUD(f) {</p><p>&nbsp; if (!fStore || fStore.len === 0) return;</p><p>&nbsp; const gndAlt = getGroundElev(f.lon, f.lat);</p><p>&nbsp; const agl = Math.max(0, f.alt - gndAlt);</p><p>&nbsp;</p><p>&nbsp; document.getElementById("hud-time").textContent = fmtTime(f.t);</p><p>&nbsp; document.getElementById("hud-spd").textContent = `${f.spd.toFixed(0)} kt (${(f.spd * 1.852).toFixed(0)} km/h)`;</p><p>&nbsp; document.getElementById("hud-alt").textContent = `${f.alt.toFixed(0)} m (${(f.alt / 0.3048).toFixed(0)} ft)`;</p><p>&nbsp; document.getElementById("hud-agl").textContent = `${agl.toFixed(0)} m`;</p><p>&nbsp; document.getElementById("hud-vsi").textContent = `${f.vsi &gt;= 0 ? "+" : ""}${f.vsi.toFixed(1)} m/s`;</p><p>&nbsp; document.getElementById("hud-pos").textContent = `${f.lat.toFixed(3)}°N ${f.lon.toFixed(3)}°E`;</p><p>&nbsp; document.getElementById("hud-yaw").textContent = `${(((f.yaw % 360) + 360) % 360).toFixed(0)}°`;</p><p>&nbsp; document.getElementById("hud-pitch").textContent = `${f.pitch &gt;= 0 ? "+" : ""}${f.pitch.toFixed(1)}°`;</p><p>&nbsp; document.getElementById("hud-roll").textContent = `${f.roll &gt;= 0 ? "+" : ""}${f.roll.toFixed(1)}°`;</p><p>&nbsp;</p><p>&nbsp; const pitchPx = Math.max(-35, Math.min(35, f.pitch * 1.2));</p><p>&nbsp; document.getElementById("adi-horizon").setAttribute("transform", `rotate(${-f.roll}) translate(0, ${pitchPx})`);</p><p>&nbsp;</p><p>&nbsp; const ratio = Math.max(0, Math.min(1, f.t / totalDuration));</p><p>&nbsp; document.getElementById("seek-bar").value = Math.round(ratio * 1000);</p><p>&nbsp; document.getElementById("frame-info").textContent = `${fmtTime(f.t)} / ${fmtTime(totalDuration)} (${fStore.len.toLocaleString()}点)`;</p><p>&nbsp; drawMiniChartCursor(ratio);</p><p>}</p><p>&nbsp;</p><p>let miniBgImg = null;</p><p>function drawMiniChartBg() {</p><p>&nbsp; const cvs = document.getElementById("mini-chart");</p><p>&nbsp; const w = cvs.clientWidth, h = cvs.clientHeight;</p><p>&nbsp; cvs.width = w; cvs.height = h;</p><p>&nbsp; const ctx = cvs.getContext("2d");</p><p>&nbsp; ctx.clearRect(0, 0, w, h);</p><p>&nbsp; if (!fStore || fStore.len &lt; 2) return;</p><p>&nbsp;</p><p>&nbsp; let maxAlt = 1000, maxSpd = 200;</p><p>&nbsp; for (let i = 0; i &lt; fStore.len; i++) {</p><p>&nbsp; &nbsp; if (fStore.alt[i] &gt; maxAlt) maxAlt = fStore.alt[i];</p><p>&nbsp; &nbsp; if (fStore.spd[i] &gt; maxSpd) maxSpd = fStore.spd[i];</p><p>&nbsp; }</p><p>&nbsp;</p><p>&nbsp; const step = Math.max(1, Math.floor(fStore.len / 2000));</p><p>&nbsp; ctx.strokeStyle = "#38bdf8"; ctx.lineWidth = 1.5; ctx.beginPath();</p><p>&nbsp; for (let i = 0; i &lt; fStore.len; i += step) {</p><p>&nbsp; &nbsp; const x = (fStore.t[i] / totalDuration) * w;</p><p>&nbsp; &nbsp; const y = h - (fStore.alt[i] / maxAlt) * (h - 6) - 3;</p><p>&nbsp; &nbsp; i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);</p><p>&nbsp; }</p><p>&nbsp; ctx.stroke();</p><p>&nbsp;</p><p>&nbsp; ctx.strokeStyle = "#ffa726"; ctx.lineWidth = 1.2; ctx.beginPath();</p><p>&nbsp; for (let i = 0; i &lt; fStore.len; i += step) {</p><p>&nbsp; &nbsp; const x = (fStore.t[i] / totalDuration) * w;</p><p>&nbsp; &nbsp; const y = h - (fStore.spd[i] / maxSpd) * (h - 6) - 3;</p><p>&nbsp; &nbsp; i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);</p><p>&nbsp; }</p><p>&nbsp; ctx.stroke();</p><p>&nbsp; miniBgImg = ctx.getImageData(0, 0, w, h);</p><p>}</p><p>&nbsp;</p><p>function drawMiniChartCursor(ratio) {</p><p>&nbsp; if (!miniBgImg || !fStore || fStore.len &lt; 2) return;</p><p>&nbsp; const cvs = document.getElementById("mini-chart");</p><p>&nbsp; const ctx = cvs.getContext("2d");</p><p>&nbsp; ctx.putImageData(miniBgImg, 0, 0);</p><p>&nbsp; const cx = ratio * cvs.width;</p><p>&nbsp; ctx.strokeStyle = "#ff5252"; ctx.lineWidth = 2;</p><p>&nbsp; ctx.beginPath(); ctx.moveTo(cx, 0); ctx.lineTo(cx, cvs.height); ctx.stroke();</p><p>}</p><p>&nbsp;</p><p>document.getElementById("mini-chart").addEventListener("click", e =&gt; {</p><p>&nbsp; if (!fStore || fStore.len &lt; 2) return;</p><p>&nbsp; const rect = e.target.getBoundingClientRect();</p><p>&nbsp; const ratio = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));</p><p>&nbsp; simTime = ratio * totalDuration;</p><p>&nbsp; updateHUD(sampleFlightAt(simTime));</p><p>});</p><p>&nbsp;</p><p>function togglePlay() {</p><p>&nbsp; if (!fStore || fStore.len === 0) return;</p><p>&nbsp; isPlaying = !isPlaying;</p><p>&nbsp; document.getElementById("btn-play").textContent = isPlaying ? "⏸ 一時停止" : "▶ 再生";</p><p>&nbsp; document.getElementById("hud-status").textContent = isPlaying ? "PLAYING" : "PAUSED";</p><p>&nbsp; if (isPlaying &amp;&amp; simTime &gt;= totalDuration) simTime = 0;</p><p>}</p><p>&nbsp;</p><p>function stopFlight() {</p><p>&nbsp; isPlaying = false;</p><p>&nbsp; document.getElementById("btn-play").textContent = "▶ 再生";</p><p>&nbsp; document.getElementById("hud-status").textContent = (fStore &amp;&amp; fStore.len) ? "READY" : "STANDBY";</p><p>&nbsp; if (fStore &amp;&amp; fStore.len &gt; 0) { simTime = 0; currentIdx = 0; updateHUD(sampleFlightAt(0)); }</p><p>}</p><p>&nbsp;</p><p>function onSeekPermille(val) {</p><p>&nbsp; if (!fStore || fStore.len === 0) return;</p><p>&nbsp; simTime = (parseFloat(val) / 1000.0) * totalDuration;</p><p>&nbsp; updateHUD(sampleFlightAt(simTime));</p><p>}</p><p>&nbsp;</p><p>window.addEventListener("keydown", e =&gt; {</p><p>&nbsp; if (e.code === "Space" &amp;&amp; document.activeElement.tagName !== "INPUT" &amp;&amp; document.activeElement.tagName !== "SELECT") {</p><p>&nbsp; &nbsp; e.preventDefault(); togglePlay();</p><p>&nbsp; }</p><p>});</p><p>&nbsp;</p><p>function loadDemoFlight() {</p><p>&nbsp; const rows = ["time,lat,lon,alt_m,speed_kt,roll,pitch,yaw"];</p><p>&nbsp; const N = 600, dt = 0.2;</p><p>&nbsp; let lat = 36.3946, lon = 136.4065, alt = 20;</p><p>&nbsp; for (let i = 0; i &lt;= N; i++) {</p><p>&nbsp; &nbsp; const t = i * dt;</p><p>&nbsp; &nbsp; let hdg = 315, pitch = 0, roll = 0, spd = 160;</p><p>&nbsp; &nbsp; if (i &lt; 80) {</p><p>&nbsp; &nbsp; &nbsp; pitch = 16; spd = 180 + i * 3.5; alt += 16; hdg = 315;</p><p>&nbsp; &nbsp; } else if (i &lt; 300) {</p><p>&nbsp; &nbsp; &nbsp; const k = (i - 80) / 220.0;</p><p>&nbsp; &nbsp; &nbsp; hdg = 315 + k * 210; roll = 48 * Math.sin(k * Math.PI);</p><p>&nbsp; &nbsp; &nbsp; pitch = 10 * Math.cos(k * Math.PI * 2); spd = 460; alt += 14;</p><p>&nbsp; &nbsp; } else if (i &lt; 440) {</p><p>&nbsp; &nbsp; &nbsp; const k = (i - 300) / 140.0;</p><p>&nbsp; &nbsp; &nbsp; hdg = 165; roll = k * 360; pitch = 14 * Math.sin(k * Math.PI * 2); spd = 500;</p><p>&nbsp; &nbsp; } else {</p><p>&nbsp; &nbsp; &nbsp; hdg = 165 - (i - 440) * 0.4; roll = -25; pitch = -5; spd = 430; alt = Math.max(2000, alt - 8);</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; const rad = hdg * Math.PI / 180;</p><p>&nbsp; &nbsp; const distM = (spd * 0.5144) * dt;</p><p>&nbsp; &nbsp; lat += (distM * Math.cos(rad)) / 110960;</p><p>&nbsp; &nbsp; lon += (distM * Math.sin(rad)) / (111320 * Math.cos(lat * Math.PI / 180));</p><p>&nbsp; &nbsp; rows.push(`${t.toFixed(2)},${lat.toFixed(6)},${lon.toFixed(6)},${alt.toFixed(1)},${spd.toFixed(1)},${roll.toFixed(1)},${pitch.toFixed(1)},${(hdg % 360).toFixed(1)}`);</p><p>&nbsp; }</p><p>&nbsp; document.getElementById("opt-alt-unit").value = "m";</p><p>&nbsp; document.getElementById("opt-spd-unit").value = "kt";</p><p>&nbsp; document.getElementById("opt-ang-unit").value = "deg";</p><p>&nbsp; document.getElementById("opt-xyz-map").value = "RPY";</p><p>&nbsp; currentSource = { type: "text", text: rows.join("\n") };</p><p>&nbsp; loadFromSource(currentSource);</p><p>}</p><p>&nbsp;</p><p>let prevFrameTime = performance.now();</p><p>let lastHudTime = 0;</p><p>&nbsp;</p><p>function projectToScreen(vp, wx, wy, wz, w, h) {</p><p>&nbsp; const cx = vp[0]*wx + vp[4]*wy + vp[8]*wz + vp[12];</p><p>&nbsp; const cy = vp[1]*wx + vp[5]*wy + vp[9]*wz + vp[13];</p><p>&nbsp; const cw = vp[3]*wx + vp[7]*wy + vp[11]*wz + vp[15];</p><p>&nbsp; if (cw &lt;= 0.0) return null;</p><p>&nbsp; return [(cx / cw * 0.5 + 0.5) * w, (-cy / cw * 0.5 + 0.5) * h];</p><p>}</p><p>&nbsp;</p><p>function drawMeshObj(vp, model, zScale, applyZ, ambient, pb, nb, cb, count, mode) {</p><p>&nbsp; gl.uniformMatrix4fv(gl.getUniformLocation(meshProg, "uVP"), false, vp);</p><p>&nbsp; gl.uniformMatrix4fv(gl.getUniformLocation(meshProg, "uModel"), false, model);</p><p>&nbsp; gl.uniform1f(gl.getUniformLocation(meshProg, "uZScale"), zScale);</p><p>&nbsp; gl.uniform1f(gl.getUniformLocation(meshProg, "uApplyZScale"), applyZ);</p><p>&nbsp; gl.uniform1f(gl.getUniformLocation(meshProg, "uAmbient"), ambient);</p><p>&nbsp;</p><p>&nbsp; const aPos = gl.getAttribLocation(meshProg, "aPos");</p><p>&nbsp; const aNorm = gl.getAttribLocation(meshProg, "aNormal");</p><p>&nbsp; const aCol = gl.getAttribLocation(meshProg, "aColor");</p><p>&nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, pb); gl.enableVertexAttribArray(aPos); gl.vertexAttribPointer(aPos, 3, gl.FLOAT, false, 0, 0);</p><p>&nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, nb); gl.enableVertexAttribArray(aNorm); gl.vertexAttribPointer(aNorm, 3, gl.FLOAT, false, 0, 0);</p><p>&nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, cb); gl.enableVertexAttribArray(aCol); gl.vertexAttribPointer(aCol, 3, gl.FLOAT, false, 0, 0);</p><p>&nbsp; gl.drawArrays(mode, 0, count);</p><p>}</p><p>&nbsp;</p><p>function renderLoop(now) {</p><p>&nbsp; const dtReal = Math.min(0.1, (now - prevFrameTime) / 1000.0);</p><p>&nbsp; prevFrameTime = now;</p><p>&nbsp;</p><p>&nbsp; if (isPlaying &amp;&amp; fStore &amp;&amp; fStore.len &gt; 0) {</p><p>&nbsp; &nbsp; const playSpd = parseFloat(document.getElementById("sel-play-spd").value);</p><p>&nbsp; &nbsp; simTime += dtReal * playSpd;</p><p>&nbsp; &nbsp; if (simTime &gt;= totalDuration) {</p><p>&nbsp; &nbsp; &nbsp; simTime = totalDuration;</p><p>&nbsp; &nbsp; &nbsp; isPlaying = false;</p><p>&nbsp; &nbsp; &nbsp; document.getElementById("btn-play").textContent = "▶ 再生";</p><p>&nbsp; &nbsp; &nbsp; document.getElementById("hud-status").textContent = "FINISHED";</p><p>&nbsp; &nbsp; &nbsp; updateHUD(sampleFlightAt(simTime));</p><p>&nbsp; &nbsp; }</p><p>&nbsp; }</p><p>&nbsp;</p><p>&nbsp; const wrap = document.getElementById("canvas-wrap");</p><p>&nbsp; const cw = wrap.clientWidth, ch = wrap.clientHeight;</p><p>&nbsp; if (glCanvas.width !== cw || glCanvas.height !== ch) {</p><p>&nbsp; &nbsp; glCanvas.width = cw; glCanvas.height = ch;</p><p>&nbsp; &nbsp; ovCanvas.width = cw; ovCanvas.height = ch;</p><p>&nbsp; }</p><p>&nbsp; gl.viewport(0, 0, cw, ch);</p><p>&nbsp; gl.enable(gl.DEPTH_TEST);</p><p>&nbsp; gl.clearColor(0.05, 0.07, 0.10, 1.0);</p><p>&nbsp; gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);</p><p>&nbsp;</p><p>&nbsp; const zScale = parseFloat(document.getElementById("sel-z").value);</p><p>&nbsp; const f15Scale = parseFloat(document.getElementById("sel-f15").value);</p><p>&nbsp;</p><p>&nbsp; let acFrame = null;</p><p>&nbsp; if (fStore &amp;&amp; fStore.len &gt; 0) {</p><p>&nbsp; &nbsp; acFrame = sampleFlightAt(simTime);</p><p>&nbsp; &nbsp; currentIdx = acFrame.idx;</p><p>&nbsp; &nbsp; if (isPlaying &amp;&amp; (now - lastHudTime &gt;= 66)) {</p><p>&nbsp; &nbsp; &nbsp; lastHudTime = now;</p><p>&nbsp; &nbsp; &nbsp; updateHUD(acFrame);</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; if (document.getElementById("chk-follow").checked) {</p><p>&nbsp; &nbsp; &nbsp; camTarget[0] = acFrame.mx;</p><p>&nbsp; &nbsp; &nbsp; camTarget[1] = acFrame.my;</p><p>&nbsp; &nbsp; &nbsp; camTarget[2] = acFrame.alt * zScale;</p><p>&nbsp; &nbsp; }</p><p>&nbsp; }</p><p>&nbsp;</p><p>&nbsp; const cosP = Math.cos(camPitch), sinP = Math.sin(camPitch);</p><p>&nbsp; const eye = [</p><p>&nbsp; &nbsp; camTarget[0] - camDist * cosP * Math.sin(camYaw),</p><p>&nbsp; &nbsp; camTarget[1] - camDist * cosP * Math.cos(camYaw),</p><p>&nbsp; &nbsp; camTarget[2] + camDist * sinP</p><p>&nbsp; ];</p><p>&nbsp; const zNear = Math.max(2.0, camDist * 0.02);</p><p>&nbsp; const zFar = Math.max(400000.0, camDist * 30.0 + 700000.0);</p><p>&nbsp; const vp = mulMat4(matPerspective(45 * Math.PI / 180, cw / Math.max(1, ch), zNear, zFar), matLookAt(eye, camTarget));</p><p>&nbsp;</p><p>&nbsp; gl.useProgram(terrainProg);</p><p>&nbsp; gl.uniformMatrix4fv(gl.getUniformLocation(terrainProg, "uVP"), false, vp);</p><p>&nbsp; gl.uniform1f(gl.getUniformLocation(terrainProg, "uZScale"), zScale);</p><p>&nbsp; const tPos = gl.getAttribLocation(terrainProg, "aPos");</p><p>&nbsp; const tGrad = gl.getAttribLocation(terrainProg, "aGrad");</p><p>&nbsp; const tCol = gl.getAttribLocation(terrainProg, "aColor");</p><p>&nbsp; for (const c of terrainChunks) {</p><p>&nbsp; &nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, c.pb); gl.enableVertexAttribArray(tPos); gl.vertexAttribPointer(tPos, 3, gl.FLOAT, false, 0, 0);</p><p>&nbsp; &nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, c.gb); gl.enableVertexAttribArray(tGrad); gl.vertexAttribPointer(tGrad, 2, gl.FLOAT, false, 0, 0);</p><p>&nbsp; &nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, c.cb); gl.enableVertexAttribArray(tCol); gl.vertexAttribPointer(tCol, 3, gl.UNSIGNED_BYTE, true, 0, 0);</p><p>&nbsp; &nbsp; gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, c.ib);</p><p>&nbsp; &nbsp; gl.drawElements(gl.TRIANGLES, c.count, gl.UNSIGNED_SHORT, 0);</p><p>&nbsp; }</p><p>&nbsp;</p><p>&nbsp; gl.useProgram(meshProg);</p><p>&nbsp; if (document.getElementById("chk-lake").checked) {</p><p>&nbsp; &nbsp; for (const lk of lakeMeshes) drawMeshObj(vp, IDENTITY_MAT, zScale, 1.0, 0.90, lk.pb, lk.nb, lk.cb, lk.count, gl.TRIANGLES);</p><p>&nbsp; }</p><p>&nbsp; if (document.getElementById("chk-airspace").checked) {</p><p>&nbsp; &nbsp; drawMeshObj(vp, IDENTITY_MAT, zScale, 1.0, 1.0, airPB, airNB, airCB, airCount, gl.LINES);</p><p>&nbsp; }</p><p>&nbsp; if (acFrame) {</p><p>&nbsp; &nbsp; if (document.getElementById("chk-trail").checked &amp;&amp; trailCount &gt; 1) {</p><p>&nbsp; &nbsp; &nbsp; drawMeshObj(vp, IDENTITY_MAT, zScale, 1.0, 1.0, trailPB, trailNB, trailFullColB, trailCount, gl.LINE_STRIP);</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; if (document.getElementById("chk-drop").checked) {</p><p>&nbsp; &nbsp; &nbsp; const gnd = getGroundElev(acFrame.lon, acFrame.lat);</p><p>&nbsp; &nbsp; &nbsp; gl.bindBuffer(gl.ARRAY_BUFFER, dropPB);</p><p>&nbsp; &nbsp; &nbsp; gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([acFrame.mx, acFrame.my, acFrame.alt, acFrame.mx, acFrame.my, gnd]), gl.DYNAMIC_DRAW);</p><p>&nbsp; &nbsp; &nbsp; drawMeshObj(vp, IDENTITY_MAT, zScale, 1.0, 1.0, dropPB, dropNB, dropCB, 2, gl.LINES);</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; const acModel = buildModelMat(acFrame.mx, acFrame.my, acFrame.alt * zScale, acFrame.roll, acFrame.pitch, acFrame.yaw, f15Scale);</p><p>&nbsp; &nbsp; drawMeshObj(vp, acModel, zScale, 0.0, 0.65, f15PB, f15NB, f15CB, f15Count, gl.TRIANGLES);</p><p>&nbsp; }</p><p>&nbsp;</p><p>&nbsp; ovCtx.clearRect(0, 0, cw, ch);</p><p>&nbsp; ovCtx.font = "12px sans-serif";</p><p>&nbsp; if (document.getElementById("chk-base").checked) {</p><p>&nbsp; &nbsp; for (const b of AIRBASES) {</p><p>&nbsp; &nbsp; &nbsp; const sp = projectToScreen(vp, b.mx, b.my, (b.elev + 80) * zScale, cw, ch);</p><p>&nbsp; &nbsp; &nbsp; if (!sp) continue;</p><p>&nbsp; &nbsp; &nbsp; ovCtx.beginPath(); ovCtx.arc(sp[0], sp[1], 5, 0, Math.PI*2);</p><p>&nbsp; &nbsp; &nbsp; ovCtx.fillStyle = "#ff1744"; ovCtx.fill();</p><p>&nbsp; &nbsp; &nbsp; ovCtx.lineWidth = 1.5; ovCtx.strokeStyle = "#ffffff"; ovCtx.stroke();</p><p>&nbsp; &nbsp; &nbsp; ovCtx.fillStyle = "#ffffff"; ovCtx.fillText(b.name, sp[0] + 8, sp[1] + 4);</p><p>&nbsp; &nbsp; }</p><p>&nbsp; }</p><p>&nbsp; if (document.getElementById("chk-airspace").checked) {</p><p>&nbsp; &nbsp; for (const asp of AIRSPACES_RAW) {</p><p>&nbsp; &nbsp; &nbsp; const sp = projectToScreen(vp, asp.labelPos[0], asp.labelPos[1], asp.labelPos[2] * zScale, cw, ch);</p><p>&nbsp; &nbsp; &nbsp; if (!sp) continue;</p><p>&nbsp; &nbsp; &nbsp; ovCtx.fillStyle = asp.color;</p><p>&nbsp; &nbsp; &nbsp; ovCtx.fillText(asp.name, sp[0], sp[1]);</p><p>&nbsp; &nbsp; }</p><p>&nbsp; }</p><p>&nbsp; if (acFrame) {</p><p>&nbsp; &nbsp; const sp = projectToScreen(vp, acFrame.mx, acFrame.my, acFrame.alt * zScale, cw, ch);</p><p>&nbsp; &nbsp; if (sp) {</p><p>&nbsp; &nbsp; &nbsp; ovCtx.strokeStyle = "#00ff88"; ovCtx.lineWidth = 1.5;</p><p>&nbsp; &nbsp; &nbsp; ovCtx.strokeRect(sp[0] - 10, sp[1] - 10, 20, 20);</p><p>&nbsp; &nbsp; &nbsp; ovCtx.fillStyle = "#00ff88";</p><p>&nbsp; &nbsp; &nbsp; ovCtx.fillText("F-15J", sp[0] + 14, sp[1] - 6);</p><p>&nbsp; &nbsp; }</p><p>&nbsp; }</p><p>&nbsp;</p><p>&nbsp; requestAnimationFrame(renderLoop);</p><p>}</p><p>&nbsp;</p><p>requestAnimationFrame(renderLoop);</p><p>&lt;/script&gt;</p><p>&lt;/body&gt;</p><p>&lt;/html&gt;</p><p>"""</p><p><br>&nbsp;</p><p>def main():</p><p>&nbsp; &nbsp; print("地形・アセットを読み込み中...")</p><p>&nbsp; &nbsp; with open(INPUT_TERRAIN_JSON, "r", encoding="utf-8") as f:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; tdata = json.load(f)</p><p>&nbsp; &nbsp; with open(INPUT_ASSETS_JSON, "r", encoding="utf-8") as f:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; adata = json.load(f)</p><p>&nbsp;</p><p>&nbsp; &nbsp; lons_full = np.array(tdata["lons"], dtype=np.float64)</p><p>&nbsp; &nbsp; lats_full = np.array(tdata["lats"], dtype=np.float64)</p><p>&nbsp; &nbsp; Z_full = np.array(</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [[np.nan if v is None else v for v in r] for r in tdata["elevations_m"]],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; dtype=np.float32</p><p>&nbsp; &nbsp; )</p><p>&nbsp;</p><p>&nbsp; &nbsp; stride = max(1, int(np.ceil(max(Z_full.shape) / MAX_GRID_DIM)))</p><p>&nbsp; &nbsp; lons = lons_full[::stride]</p><p>&nbsp; &nbsp; lats = lats_full[::stride]</p><p>&nbsp; &nbsp; Z = Z_full[::stride, ::stride].copy()</p><p>&nbsp; &nbsp; H, W = Z.shape</p><p>&nbsp; &nbsp; print(f"WebGLメッシュ構築中: {Z_full.shape} -&gt; {Z.shape} (1/{stride})")</p><p>&nbsp;</p><p>&nbsp; &nbsp; X_s, Y_s = np.meshgrid(lons, lats)</p><p>&nbsp; &nbsp; for lk in tdata.get("lake_polygons", []):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; arr = np.array(lk["polygon"])</p><p>&nbsp; &nbsp; &nbsp; &nbsp; bx0, by0, bx1, by1 = arr[:, 0].min(), arr[:, 1].min(), arr[:, 0].max(), arr[:, 1].max()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ix = np.where((lons &gt;= bx0) &amp; (lons &lt;= bx1))[0]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; iy = np.where((lats &gt;= by0) &amp; (lats &lt;= by1))[0]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if len(ix) &gt; 0 and len(iy) &gt; 0:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub_X = X_s[iy[0]:iy[-1]+1, ix[0]:ix[-1]+1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub_Y = Y_s[iy[0]:iy[-1]+1, ix[0]:ix[-1]+1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; l_mask = points_in_polygon(sub_X, sub_Y, lk["polygon"])</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub_Z = Z[iy[0]:iy[-1]+1, ix[0]:ix[-1]+1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Z[iy[0]:iy[-1]+1, ix[0]:ix[-1]+1] = np.where(</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; l_mask &amp; (~np.isnan(sub_Z)), np.minimum(sub_Z, lk["elevation_m"] - 40.0), sub_Z</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )</p><p>&nbsp;</p><p>&nbsp; &nbsp; ref_lon = float((lons.min() + lons.max()) / 2.0)</p><p>&nbsp; &nbsp; ref_lat = float((lats.min() + lats.max()) / 2.0)</p><p>&nbsp; &nbsp; m_per_lon = 111320.0 * np.cos(np.radians(ref_lat))</p><p>&nbsp; &nbsp; m_per_lat = 110960.0</p><p>&nbsp;</p><p>&nbsp; &nbsp; X_m = (X_s - ref_lon) * m_per_lon</p><p>&nbsp; &nbsp; Y_m = (Y_s - ref_lat) * m_per_lat</p><p>&nbsp; &nbsp; Z0 = np.nan_to_num(Z, nan=0.0)</p><p>&nbsp;</p><p>&nbsp; &nbsp; dy_m = abs(lats[1] - lats[0]) * m_per_lat</p><p>&nbsp; &nbsp; dx_m = abs(lons[1] - lons[0]) * m_per_lon</p><p>&nbsp; &nbsp; gy, gx = np.gradient(Z0, dy_m, dx_m)</p><p>&nbsp; &nbsp; gy = -gy</p><p>&nbsp; &nbsp; slope = np.hypot(gx, gy)</p><p>&nbsp; &nbsp; rock_factor = np.clip((slope - 0.20) / 0.55, 0.0, 1.0)</p><p>&nbsp;</p><p>&nbsp; &nbsp; h_norm = np.clip(Z0 / 3776.0, 0.0, 1.0)</p><p>&nbsp; &nbsp; stops = [0.00, 0.05, 0.22, 0.45, 0.70, 0.88, 1.00]</p><p>&nbsp; &nbsp; cols = np.array([</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [33, 77, 36], [51, 102, 44], [70, 110, 53], [107, 101, 66],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [120, 98, 77], [148, 144, 138], [248, 250, 252]</p><p>&nbsp; &nbsp; ], dtype=np.float32)</p><p>&nbsp; &nbsp; rgb = np.zeros((H, W, 3), dtype=np.float32)</p><p>&nbsp; &nbsp; for c in range(3):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; rgb[:, :, c] = np.interp(h_norm, stops, cols[:, c])</p><p>&nbsp; &nbsp; rock_col = np.array([122, 114, 105], dtype=np.float32)</p><p>&nbsp; &nbsp; rgb = rgb * (1.0 - rock_factor[:, :, None] * 0.7) + rock_col * (rock_factor[:, :, None] * 0.7)</p><p>&nbsp; &nbsp; rgb_u8 = np.clip(rgb, 0, 255).astype(np.uint8)</p><p>&nbsp;</p><p>&nbsp; &nbsp; valid_mask = ~np.isnan(Z)</p><p>&nbsp; &nbsp; chunk_rows = max(20, 55000 // W)</p><p>&nbsp; &nbsp; chunks_meta = []</p><p>&nbsp; &nbsp; for r0 in range(0, H - 1, chunk_rows):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; r1 = min(H - 1, r0 + chunk_rows)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; sub_valid = valid_mask[r0:r1+1, :]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; cell_ok = sub_valid[:-1, :-1] &amp; sub_valid[1:, :-1] &amp; sub_valid[:-1, 1:] &amp; sub_valid[1:, 1:]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if not np.any(cell_ok):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; pos = np.stack([X_m[r0:r1+1, :], Y_m[r0:r1+1, :], Z0[r0:r1+1, :]], axis=-1).astype(np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; grad = np.stack([gx[r0:r1+1, :], gy[r0:r1+1, :]], axis=-1).astype(np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; col = rgb_u8[r0:r1+1, :, :]</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; rr, cc = np.where(cell_ok)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; i0 = rr * W + cc</p><p>&nbsp; &nbsp; &nbsp; &nbsp; i1 = (rr + 1) * W + cc</p><p>&nbsp; &nbsp; &nbsp; &nbsp; i2 = rr * W + (cc + 1)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; i3 = (rr + 1) * W + (cc + 1)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; tris = np.concatenate([</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; np.stack([i0, i1, i2], axis=-1),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; np.stack([i2, i1, i3], axis=-1)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ], axis=0).astype(np.uint16)</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; chunks_meta.append({</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "pos": arr_to_b64(pos),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "grad": arr_to_b64(grad),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "col": arr_to_b64(col),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "idx": arr_to_b64(tris)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; })</p><p>&nbsp;</p><p>&nbsp; &nbsp; lakes_json = []</p><p>&nbsp; &nbsp; for lk in tdata.get("lake_polygons", []):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; pts, tris = triangulate_polygon(lk["polygon"])</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if tris:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lakes_json.append({</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "name": lk["name"],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "elevation_m": float(lk["elevation_m"]),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "pts": pts,</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "tris": [v for t in tris for v in t]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })</p><p>&nbsp;</p><p>&nbsp; &nbsp; airbases_json = []</p><p>&nbsp; &nbsp; for b in adata.get("airbases", []):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; blon, blat = parse_coord(b["lon"]), parse_coord(b["lat"])</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ix = int(np.argmin(np.abs(lons - blon)))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; iy = int(np.argmin(np.abs(lats - blat)))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev = float(Z[iy, ix]) if not np.isnan(Z[iy, ix]) else 0.0</p><p>&nbsp; &nbsp; &nbsp; &nbsp; airbases_json.append({</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "name": b["name"],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "mx": float((blon - ref_lon) * m_per_lon),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "my": float((blat - ref_lat) * m_per_lat),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "elev": elev</p><p>&nbsp; &nbsp; &nbsp; &nbsp; })</p><p>&nbsp;</p><p>&nbsp; &nbsp; airspaces_json = []</p><p>&nbsp; &nbsp; for asp in adata.get("airspaces", []):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; airspaces_json.append({</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "name": asp["name"],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "color": asp["color"],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "min_alt_m": float(asp["min_alt_m"]),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "max_alt_m": float(asp["max_alt_m"]),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "polygon": [[parse_coord(p[0]), parse_coord(p[1])] for p in asp["polygon"]]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; })</p><p>&nbsp;</p><p>&nbsp; &nbsp; mesh = adata["f15j_mesh"]</p><p>&nbsp; &nbsp; verts = np.array(mesh["vertices"], dtype=np.float32)</p><p>&nbsp; &nbsp; f15_pos, f15_norm, f15_col = [], [], []</p><p>&nbsp; &nbsp; for face, hex_col in zip(mesh["faces"], mesh["face_colors"]):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; v0, v1, v2 = verts[face[0]], verts[face[1]], verts[face[2]]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; n = np.cross(v1 - v0, v2 - v0)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; nl = np.linalg.norm(n)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; n = n / nl if nl &gt; 1e-6 else np.array([0.0, 0.0, 1.0], dtype=np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; hx = hex_col.lstrip("#")</p><p>&nbsp; &nbsp; &nbsp; &nbsp; rgb_f = [int(hx[0:2], 16) / 255.0, int(hx[2:4], 16) / 255.0, int(hx[4:6], 16) / 255.0]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for v in (v0, v1, v2):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f15_pos.extend(v.tolist())</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f15_norm.extend(n.tolist())</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f15_col.extend(rgb_f)</p><p>&nbsp;</p><p>&nbsp; &nbsp; f15_json = {"pos": f15_pos, "norm": f15_norm, "col": f15_col}</p><p>&nbsp;</p><p>&nbsp; &nbsp; html = HTML_TEMPLATE</p><p>&nbsp; &nbsp; replacements = {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__REF_LON__": str(ref_lon),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__REF_LAT__": str(ref_lat),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__LON_MIN__": str(float(lons.min())),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__DLON__": str(float(lons[1] - lons[0])),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__LAT_MAX__": str(float(lats[0])),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__DLAT__": str(abs(float(lats[1] - lats[0]))),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__GRID_H__": str(H),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__GRID_W__": str(W),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__ELEV_GRID_B64__": arr_to_b64(Z.astype(np.float32)),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__CHUNKS_META__": json.dumps(chunks_meta),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__LAKES_JSON__": json.dumps(lakes_json, ensure_ascii=False),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__AIRBASES_JSON__": json.dumps(airbases_json, ensure_ascii=False),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__AIRSPACES_JSON__": json.dumps(airspaces_json, ensure_ascii=False),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "__F15_JSON__": json.dumps(f15_json),</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; for k, v in replacements.items():</p><p>&nbsp; &nbsp; &nbsp; &nbsp; html = html.replace(k, v)</p><p>&nbsp;</p><p>&nbsp; &nbsp; Path(OUTPUT_HTML).write_text(html, encoding="utf-8")</p><p>&nbsp; &nbsp; size_mb = Path(OUTPUT_HTML).stat().st_size / (1024 * 1024)</p><p>&nbsp; &nbsp; print(f"完了！ -&gt; {OUTPUT_HTML} ({size_mb:.2f} MB)")</p><p><br>&nbsp;</p><p>if __name__ == "__main__":</p><p>&nbsp; &nbsp; main()</p>
]]>
</description>
<link>https://ameblo.jp/jmohui/entry-12985394833.html</link>
<pubDate>Mon, 23 Nov 2026 13:35:09 +0900</pubDate>
</item>
<item>
<title>あれ２.1</title>
<description>
<![CDATA[ <p>import base64</p><p>import json</p><p>import re</p><p>from pathlib import Path</p><p>import numpy as np</p><p>&nbsp;</p><p>INPUT_TERRAIN_JSON = "chubu_hokuriku_hires_3d.json"</p><p>INPUT_ASSETS_JSON = "airspaces_and_f15j.json"</p><p>OUTPUT_HTML = "chubu_hokuriku_flight_3d.html"</p><p>&nbsp;</p><p>MAX_GRID_DIM = 460</p><p>DEFAULT_Z_SCALE = 5.0</p><p><br>&nbsp;</p><p>def parse_coord(val) -&gt; float:</p><p>&nbsp; &nbsp; if isinstance(val, (int, float)):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return float(val)</p><p>&nbsp; &nbsp; s = str(val).strip().upper()</p><p>&nbsp; &nbsp; m = re.match(r"^(\d{2,3})(\d{2})(\d{2}(?:\.\d+)?)([NSEW])$", s)</p><p>&nbsp; &nbsp; if m:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; res = float(m.group(1)) + float(m.group(2)) / 60.0 + float(m.group(3)) / 3600.0</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return -res if m.group(4) in ("S", "W") else res</p><p>&nbsp; &nbsp; nums = re.findall(r"\d+(?:\.\d+)?", s)</p><p>&nbsp; &nbsp; if len(nums) &gt;= 3:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; res = float(nums[0]) + float(nums[1]) / 60.0 + float(nums[2]) / 3600.0</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return -res if ("S" in s or "W" in s) else res</p><p>&nbsp; &nbsp; return float(nums[0])</p><p><br>&nbsp;</p><p>def points_in_polygon(X, Y, poly_coords):</p><p>&nbsp; &nbsp; inside = np.zeros(X.shape, dtype=bool)</p><p>&nbsp; &nbsp; n = len(poly_coords)</p><p>&nbsp; &nbsp; for i in range(n):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; j = (i - 1) % n</p><p>&nbsp; &nbsp; &nbsp; &nbsp; xi, yi = poly_coords[i]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; xj, yj = poly_coords[j]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; cond1 = (yi &gt; Y) != (yj &gt; Y)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; denom = (yj - yi) if (yj != yi) else 1e-12</p><p>&nbsp; &nbsp; &nbsp; &nbsp; x_intersect = (xj - xi) * (Y - yi) / denom + xi</p><p>&nbsp; &nbsp; &nbsp; &nbsp; inside ^= (cond1 &amp; (X &lt; x_intersect))</p><p>&nbsp; &nbsp; return inside</p><p><br>&nbsp;</p><p>def triangulate_polygon(poly):</p><p>&nbsp; &nbsp; pts = [list(p) for p in poly]</p><p>&nbsp; &nbsp; if len(pts) &gt; 2 and pts[0] == pts[-1]:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; pts.pop()</p><p>&nbsp; &nbsp; n = len(pts)</p><p>&nbsp; &nbsp; if n &lt; 3:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return [], []</p><p>&nbsp; &nbsp; area = sum(pts[i][0] * pts[(i + 1) % n][1] - pts[(i + 1) % n][0] * pts[i][1] for i in range(n))</p><p>&nbsp; &nbsp; if area &lt; 0:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; pts.reverse()</p><p>&nbsp;</p><p>&nbsp; &nbsp; def cross(a, b, c):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])</p><p>&nbsp;</p><p>&nbsp; &nbsp; def point_in_tri(p, a, b, c):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return cross(a, b, p) &gt;= -1e-12 and cross(b, c, p) &gt;= -1e-12 and cross(c, a, p) &gt;= -1e-12</p><p>&nbsp;</p><p>&nbsp; &nbsp; indices = list(range(n))</p><p>&nbsp; &nbsp; triangles = []</p><p>&nbsp; &nbsp; guard = 0</p><p>&nbsp; &nbsp; while len(indices) &gt; 3 and guard &lt; n * n:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; guard += 1</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ear_found = False</p><p>&nbsp; &nbsp; &nbsp; &nbsp; m = len(indices)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for i in range(m):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i0, i1, i2 = indices[(i - 1) % m], indices[i], indices[(i + 1) % m]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a, b, c = pts[i0], pts[i1], pts[i2]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if cross(a, b, c) &gt; 1e-12:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not any(idx not in (i0, i1, i2) and point_in_tri(pts[idx], a, b, c) for idx in indices):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; triangles.append((i0, i1, i2))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; indices.pop(i)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ear_found = True</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if not ear_found:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</p><p>&nbsp; &nbsp; if len(indices) == 3:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; triangles.append((indices[0], indices[1], indices[2]))</p><p>&nbsp; &nbsp; return pts, triangles</p><p><br>&nbsp;</p><p>def arr_to_b64(arr: np.ndarray) -&gt; str:</p><p>&nbsp; &nbsp; return base64.b64encode(arr.tobytes()).decode("ascii")</p><p><br>&nbsp;</p><p>HTML_TEMPLATE = r"""&lt;!DOCTYPE html&gt;</p><p>&lt;html lang="ja"&gt;</p><p>&lt;head&gt;</p><p>&lt;meta charset="utf-8"&gt;</p><p>&lt;title&gt;WebGL 60FPS 3Dフライト・リプレイヤー (超大容量・全サンプリング対応)&lt;/title&gt;</p><p>&lt;style&gt;</p><p>&nbsp; * { box-sizing: border-box; }</p><p>&nbsp; body { margin:0; padding:8px; background:#0d1117; color:#e6edf3; font-family:"Segoe UI","Yu Gothic UI",sans-serif; height:100vh; display:flex; flex-direction:column; overflow:hidden; user-select:none; }</p><p>&nbsp; .toolbar { display:flex; flex-wrap:wrap; align-items:center; gap:6px; margin-bottom:6px; background:#161b22; border:1px solid #30363d; padding:6px 10px; border-radius:6px; font-size:12px; }</p><p>&nbsp; button, select { background:#21262d; color:#e6edf3; border:1px solid #30363d; padding:5px 10px; border-radius:4px; cursor:pointer; font-size:12px; }</p><p>&nbsp; button:hover { background:#30363d; }</p><p>&nbsp; button.primary { background:#238636; border-color:#2ea043; font-weight:bold; }</p><p>&nbsp; button.primary:hover { background:#2ea043; }</p><p>&nbsp; button.chase { background:#8957e5; border-color:#a371f7; font-weight:bold; }</p><p>&nbsp; button.chase:hover { background:#a371f7; }</p><p>&nbsp; .sep { width:1px; height:20px; background:#30363d; margin:0 3px; }</p><p>&nbsp; label { display:flex; align-items:center; gap:4px; cursor:pointer; }</p><p>&nbsp; .main-area { position:relative; flex:1; min-height:0; border:1px solid #30363d; border-radius:6px; overflow:hidden; background:#0b1016; }</p><p>&nbsp; canvas.gl-layer { position:absolute; inset:0; width:100%; height:100%; display:block; }</p><p>&nbsp; #overlay { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; }</p><p>&nbsp;</p><p>&nbsp; .hud { position:absolute; top:10px; right:10px; width:260px; background:rgba(13,17,23,0.82); border:1px solid #30363d; border-radius:8px; padding:10px 12px; pointer-events:none; font-family:Consolas, monospace; }</p><p>&nbsp; .hud-title { font-size:11px; color:#58a6ff; font-weight:bold; letter-spacing:1px; margin-bottom:6px; display:flex; justify-content:space-between; }</p><p>&nbsp; .hud-grid { display:grid; grid-template-columns:1fr 1fr; gap:5px 8px; font-size:12px; }</p><p>&nbsp; .hud-val { color:#7ee787; font-weight:bold; font-size:13px; }</p><p>&nbsp; .hud-lbl { color:#8b949e; font-size:10px; display:block; }</p><p>&nbsp; .attitude-wrap { display:flex; align-items:center; gap:10px; margin-top:8px; padding-top:8px; border-top:1px solid #30363d; }</p><p>&nbsp; .adi-box { width:70px; height:70px; border-radius:50%; overflow:hidden; border:2px solid #8b949e; position:relative; flex-shrink:0; background:#1c2128; }</p><p>&nbsp; .cam-hint { position:absolute; bottom:10px; left:10px; background:rgba(13,17,23,0.75); border:1px solid #30363d; border-radius:6px; padding:5px 10px; font-size:11px; color:#9fb1c6; pointer-events:none; }</p><p>&nbsp;</p><p>&nbsp; .player-bar { margin-top:6px; background:#161b22; border:1px solid #30363d; border-radius:6px; padding:8px 12px; display:flex; flex-direction:column; gap:6px; }</p><p>&nbsp; .player-row { display:flex; align-items:center; gap:8px; flex-wrap:wrap; font-size:12px; }</p><p>&nbsp; .seek-wrap { flex:1; display:flex; align-items:center; gap:8px; min-width:220px; }</p><p>&nbsp; input[type=range] { cursor:pointer; }</p><p>&nbsp; #seek-bar { flex:1; }</p><p>&nbsp; #mini-chart { width:100%; height:42px; background:#0d1117; border-radius:4px; border:1px solid #21262d; cursor:pointer; }</p><p>&nbsp; .csv-options { display:flex; align-items:center; gap:8px; flex-wrap:wrap; font-size:11px; color:#8b949e; border-top:1px solid #21262d; padding-top:5px; }</p><p>&nbsp; input[type=file] { display:none; }</p><p>&nbsp; .file-btn { background:#1f6feb; border:1px solid #58a6ff; color:#fff; padding:5px 12px; border-radius:4px; cursor:pointer; font-weight:bold; font-size:12px; }</p><p>&nbsp; .file-btn:hover { background:#388bfd; }</p><p>&lt;/style&gt;</p><p>&lt;/head&gt;</p><p>&lt;body&gt;</p><p>&nbsp;</p><p>&nbsp; &lt;div class="toolbar"&gt;</p><p>&nbsp; &nbsp; &lt;label class="file-btn"&gt;📂 CSV読込&lt;input type="file" id="csv-input" accept=".csv,.txt"&gt;&lt;/label&gt;</p><p>&nbsp; &nbsp; &lt;button onclick="loadDemoFlight()"&gt;▶ デモ飛行データ&lt;/button&gt;</p><p>&nbsp; &nbsp; &lt;div class="sep"&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &lt;button class="chase" onclick="snapToAircraft()"&gt;🎯 機体にズーム追従&lt;/button&gt;</p><p>&nbsp; &nbsp; &lt;label&gt;&lt;input type="checkbox" id="chk-follow"&gt;自動追従&lt;/label&gt;</p><p>&nbsp; &nbsp; &lt;button onclick="resetCamera()"&gt;🗺️ 全体俯瞰&lt;/button&gt;</p><p>&nbsp; &nbsp; &lt;div class="sep"&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &lt;button onclick="zoomCamera(0.6)"&gt;＋ 拡大&lt;/button&gt;</p><p>&nbsp; &nbsp; &lt;button onclick="zoomCamera(1.6)"&gt;－ 縮小&lt;/button&gt;</p><p>&nbsp; &nbsp; &lt;div class="sep"&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &lt;span&gt;高さ:&lt;/span&gt;</p><p>&nbsp; &nbsp; &lt;select id="sel-z"&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;option value="1"&gt;1x(実寸)&lt;/option&gt;&lt;option value="3"&gt;3x&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;option value="5" selected&gt;5x&lt;/option&gt;&lt;option value="10"&gt;10x&lt;/option&gt;</p><p>&nbsp; &nbsp; &lt;/select&gt;</p><p>&nbsp; &nbsp; &lt;span&gt;機体:&lt;/span&gt;</p><p>&nbsp; &nbsp; &lt;select id="sel-f15"&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;option value="1" selected&gt;1x (実寸19.4m)&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;option value="10"&gt;10x&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;option value="50"&gt;50x&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;option value="200"&gt;200x&lt;/option&gt;</p><p>&nbsp; &nbsp; &lt;/select&gt;</p><p>&nbsp; &nbsp; &lt;div class="sep"&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &lt;label&gt;&lt;input type="checkbox" id="chk-lake" checked&gt;湖&lt;/label&gt;</p><p>&nbsp; &nbsp; &lt;label&gt;&lt;input type="checkbox" id="chk-base" checked&gt;基地&lt;/label&gt;</p><p>&nbsp; &nbsp; &lt;label&gt;&lt;input type="checkbox" id="chk-airspace" checked&gt;空域&lt;/label&gt;</p><p>&nbsp; &nbsp; &lt;label&gt;&lt;input type="checkbox" id="chk-trail" checked&gt;全航跡&lt;/label&gt;</p><p>&nbsp; &nbsp; &lt;label&gt;&lt;input type="checkbox" id="chk-drop" checked&gt;対地赤線&lt;/label&gt;</p><p>&nbsp; &lt;/div&gt;</p><p>&nbsp;</p><p>&nbsp; &lt;div class="main-area" id="canvas-wrap"&gt;</p><p>&nbsp; &nbsp; &lt;canvas id="glcanvas" class="gl-layer"&gt;&lt;/canvas&gt;</p><p>&nbsp; &nbsp; &lt;canvas id="overlay"&gt;&lt;/canvas&gt;</p><p>&nbsp; &nbsp; &lt;div class="cam-hint"&gt;左ドラッグ: 回転 ／ 右ドラッグ(or Shift+左): 移動 ／ ホイール: 超広域〜実寸ズーム&lt;/div&gt;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &lt;div class="hud"&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;div class="hud-title"&gt;&lt;span&gt;F-15J TELEMETRY (60FPS WebGL)&lt;/span&gt;&lt;span id="hud-status"&gt;STANDBY&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;div class="hud-grid"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;&lt;span class="hud-lbl"&gt;TIME&lt;/span&gt;&lt;span class="hud-val" id="hud-time"&gt;00:00.0&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;&lt;span class="hud-lbl"&gt;SPEED&lt;/span&gt;&lt;span class="hud-val" id="hud-spd"&gt;---&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;&lt;span class="hud-lbl"&gt;ALT (MSL)&lt;/span&gt;&lt;span class="hud-val" id="hud-alt"&gt;---&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;&lt;span class="hud-lbl"&gt;AGL (対地高度)&lt;/span&gt;&lt;span class="hud-val" id="hud-agl"&gt;---&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;&lt;span class="hud-lbl"&gt;VSI (昇降率)&lt;/span&gt;&lt;span class="hud-val" id="hud-vsi"&gt;---&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;&lt;span class="hud-lbl"&gt;LAT / LON&lt;/span&gt;&lt;span class="hud-val" style="font-size:11px;" id="hud-pos"&gt;---&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;div class="attitude-wrap"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="adi-box"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;svg viewBox="-50 -50 100 100" width="70" height="70"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;g id="adi-horizon" transform="rotate(0) translate(0, 0)"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;rect x="-100" y="-120" width="200" height="120" fill="#2374ab"/&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;rect x="-100" y="0" width="200" height="120" fill="#6b4c2e"/&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;line x1="-100" y1="0" x2="100" y2="0" stroke="#ffffff" stroke-width="2"/&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;line x1="-20" y1="-15" x2="20" y2="-15" stroke="#fff" stroke-width="1"/&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;line x1="-20" y1="15" x2="20" y2="15" stroke="#fff" stroke-width="1"/&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/g&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;path d="M -22,0 L -8,0 L 0,6 L 8,0 L 22,0" fill="none" stroke="#ffeb3b" stroke-width="2.5"/&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;circle cx="0" cy="0" r="2" fill="#ffeb3b"/&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/svg&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div style="font-size:11px; line-height:1.5;"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;HDG(Yaw): &lt;span class="hud-val" id="hud-yaw"&gt;---&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;PITCH: &lt;span class="hud-val" id="hud-pitch"&gt;---&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;ROLL: &lt;span class="hud-val" id="hud-roll"&gt;---&lt;/span&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;/div&gt;</p><p>&nbsp; &nbsp; &lt;/div&gt;</p><p>&nbsp; &lt;/div&gt;</p><p>&nbsp;</p><p>&nbsp; &lt;div class="player-bar"&gt;</p><p>&nbsp; &nbsp; &lt;canvas id="mini-chart"&gt;&lt;/canvas&gt;</p><p>&nbsp; &nbsp; &lt;div class="player-row"&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;button id="btn-play" class="primary" onclick="togglePlay()" disabled&gt;▶ 再生&lt;/button&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;button onclick="stopFlight()" id="btn-stop" disabled&gt;⏮ 先頭&lt;/button&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;span&gt;速度:&lt;/span&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;select id="sel-play-spd"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="0.5"&gt;0.5x&lt;/option&gt;&lt;option value="1" selected&gt;1x&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="2"&gt;2x&lt;/option&gt;&lt;option value="5"&gt;5x&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="10"&gt;10x&lt;/option&gt;&lt;option value="30"&gt;30x&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="60"&gt;60x&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;/select&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;div class="seek-wrap"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input id="seek-bar" type="range" min="0" max="1000" value="0" disabled oninput="onSeekPermille(this.value)"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;span id="frame-info" style="min-width:190px; text-align:right;"&gt;CSV未読込&lt;/span&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;/div&gt;</p><p>&nbsp; &nbsp; &lt;/div&gt;</p><p>&nbsp; &nbsp; &lt;div class="csv-options"&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;span&gt;CSV設定:&lt;/span&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;label&gt;読込間引き: &lt;select id="opt-thin" onchange="reparseIfLoaded()" title="100Hz等の巨大ログを省メモリ化する際の間引き"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="1" selected&gt;1/1 (全点)&lt;/option&gt;&lt;option value="2"&gt;1/2&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="5"&gt;1/5&lt;/option&gt;&lt;option value="10"&gt;1/10&lt;/option&gt;&lt;option value="20"&gt;1/20&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;/select&gt;&lt;/label&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;label&gt;高度: &lt;select id="opt-alt-unit" onchange="reparseIfLoaded()"&gt;&lt;option value="m"&gt;m&lt;/option&gt;&lt;option value="ft"&gt;ft&lt;/option&gt;&lt;/select&gt;&lt;/label&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;label&gt;速度: &lt;select id="opt-spd-unit" onchange="reparseIfLoaded()"&gt;&lt;option value="kt"&gt;kt&lt;/option&gt;&lt;option value="kmh"&gt;km/h&lt;/option&gt;&lt;option value="ms"&gt;m/s&lt;/option&gt;&lt;/select&gt;&lt;/label&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;label&gt;角度: &lt;select id="opt-ang-unit" onchange="reparseIfLoaded()"&gt;&lt;option value="deg"&gt;度(deg)&lt;/option&gt;&lt;option value="rad"&gt;rad&lt;/option&gt;&lt;/select&gt;&lt;/label&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;label&gt;XYZ順: &lt;select id="opt-xyz-map" onchange="reparseIfLoaded()"&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="RPY"&gt;X=Roll / Y=Pitch / Z=Yaw&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="PRY"&gt;X=Pitch / Y=Roll / Z=Yaw&lt;/option&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;/select&gt;&lt;/label&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;label&gt;&lt;input type="checkbox" id="opt-inv-roll" onchange="reparseIfLoaded()"&gt;Roll反転&lt;/label&gt;</p><p>&nbsp; &nbsp; &nbsp; &lt;label&gt;&lt;input type="checkbox" id="opt-inv-pitch" onchange="reparseIfLoaded()"&gt;Pitch反転&lt;/label&gt;</p><p>&nbsp; &nbsp; &lt;/div&gt;</p><p>&nbsp; &lt;/div&gt;</p><p>&nbsp;</p><p>&lt;script&gt;</p><p>const REF_LON = __REF_LON__, REF_LAT = __REF_LAT__;</p><p>const M_PER_LON = 111320.0 * Math.cos(REF_LAT * Math.PI / 180.0);</p><p>const M_PER_LAT = 110960.0;</p><p>const LON_MIN = __LON_MIN__, DLON = __DLON__, LAT_MAX = __LAT_MAX__, DLAT = __DLAT__;</p><p>const GRID_H = __GRID_H__, GRID_W = __GRID_W__;</p><p>&nbsp;</p><p>function b64ToBuf(b64) {</p><p>&nbsp; const bin = atob(b64);</p><p>&nbsp; const len = bin.length;</p><p>&nbsp; const bytes = new Uint8Array(len);</p><p>&nbsp; for (let i = 0; i &lt; len; i++) bytes[i] = bin.charCodeAt(i);</p><p>&nbsp; return bytes.buffer;</p><p>}</p><p>&nbsp;</p><p>function lonLatToMeters(lon, lat) {</p><p>&nbsp; return [(lon - REF_LON) * M_PER_LON, (lat - REF_LAT) * M_PER_LAT];</p><p>}</p><p>&nbsp;</p><p>const ELEV_GRID = new Float32Array(b64ToBuf("__ELEV_GRID_B64__"));</p><p>const CHUNKS_RAW = __CHUNKS_META__;</p><p>const LAKES_RAW = __LAKES_JSON__;</p><p>const AIRBASES = __AIRBASES_JSON__;</p><p>const AIRSPACES_RAW = __AIRSPACES_JSON__;</p><p>const F15_RAW = __F15_JSON__;</p><p>&nbsp;</p><p>function getGroundElev(lon, lat) {</p><p>&nbsp; const ix = Math.round((lon - LON_MIN) / DLON);</p><p>&nbsp; const iy = Math.round((LAT_MAX - lat) / DLAT);</p><p>&nbsp; if (ix &lt; 0 || ix &gt;= GRID_W || iy &lt; 0 || iy &gt;= GRID_H) return 0;</p><p>&nbsp; const v = ELEV_GRID[iy * GRID_W + ix];</p><p>&nbsp; return isNaN(v) ? 0 : v;</p><p>}</p><p>&nbsp;</p><p>const glCanvas = document.getElementById("glcanvas");</p><p>const ovCanvas = document.getElementById("overlay");</p><p>const ovCtx = ovCanvas.getContext("2d");</p><p>const gl = glCanvas.getContext("webgl", { antialias: true, alpha: false });</p><p>if (!gl) alert("このブラウザはWebGLに対応していません。");</p><p>&nbsp;</p><p>function compileShader(type, src) {</p><p>&nbsp; const s = gl.createShader(type);</p><p>&nbsp; gl.shaderSource(s, src);</p><p>&nbsp; gl.compileShader(s);</p><p>&nbsp; if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s));</p><p>&nbsp; return s;</p><p>}</p><p>function createProgram(vs, fs) {</p><p>&nbsp; const p = gl.createProgram();</p><p>&nbsp; gl.attachShader(p, compileShader(gl.VERTEX_SHADER, vs));</p><p>&nbsp; gl.attachShader(p, compileShader(gl.FRAGMENT_SHADER, fs));</p><p>&nbsp; gl.linkProgram(p);</p><p>&nbsp; if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p));</p><p>&nbsp; return p;</p><p>}</p><p>&nbsp;</p><p>const terrainProg = createProgram(`</p><p>&nbsp; attribute vec3 aPos;</p><p>&nbsp; attribute vec2 aGrad;</p><p>&nbsp; attribute vec3 aColor;</p><p>&nbsp; uniform mat4 uVP;</p><p>&nbsp; uniform float uZScale;</p><p>&nbsp; varying vec3 vColor;</p><p>&nbsp; varying float vDist;</p><p>&nbsp; void main() {</p><p>&nbsp; &nbsp; vec4 wp = vec4(aPos.x, aPos.y, aPos.z * uZScale, 1.0);</p><p>&nbsp; &nbsp; gl_Position = uVP * wp;</p><p>&nbsp; &nbsp; vDist = gl_Position.w;</p><p>&nbsp; &nbsp; vec3 n = normalize(vec3(-aGrad.x * uZScale, -aGrad.y * uZScale, 1.0));</p><p>&nbsp; &nbsp; vec3 lightDir = normalize(vec3(-0.65, 0.55, 0.72));</p><p>&nbsp; &nbsp; float diff = max(dot(n, lightDir), 0.0);</p><p>&nbsp; &nbsp; float shade = 0.36 + 0.76 * diff;</p><p>&nbsp; &nbsp; vColor = aColor * shade;</p><p>&nbsp; }</p><p>`, `</p><p>&nbsp; precision mediump float;</p><p>&nbsp; varying vec3 vColor;</p><p>&nbsp; varying float vDist;</p><p>&nbsp; void main() {</p><p>&nbsp; &nbsp; float fog = clamp((vDist - 350000.0) / 850000.0, 0.0, 0.55);</p><p>&nbsp; &nbsp; vec3 col = mix(vColor, vec3(0.05, 0.07, 0.10), fog);</p><p>&nbsp; &nbsp; gl_FragColor = vec4(col, 1.0);</p><p>&nbsp; }</p><p>`);</p><p>&nbsp;</p><p>const meshProg = createProgram(`</p><p>&nbsp; attribute vec3 aPos;</p><p>&nbsp; attribute vec3 aNormal;</p><p>&nbsp; attribute vec3 aColor;</p><p>&nbsp; uniform mat4 uVP;</p><p>&nbsp; uniform mat4 uModel;</p><p>&nbsp; uniform float uZScale;</p><p>&nbsp; uniform float uApplyZScale;</p><p>&nbsp; uniform float uAmbient;</p><p>&nbsp; varying vec3 vColor;</p><p>&nbsp; void main() {</p><p>&nbsp; &nbsp; vec4 wp = uModel * vec4(aPos, 1.0);</p><p>&nbsp; &nbsp; if (uApplyZScale &gt; 0.5) wp.z *= uZScale;</p><p>&nbsp; &nbsp; gl_Position = uVP * wp;</p><p>&nbsp; &nbsp; vec3 n = normalize(mat3(uModel) * aNormal);</p><p>&nbsp; &nbsp; vec3 lightDir = normalize(vec3(-0.5, 0.5, 0.8));</p><p>&nbsp; &nbsp; float diff = max(dot(n, lightDir), 0.0);</p><p>&nbsp; &nbsp; vColor = aColor * (uAmbient + (1.0 - uAmbient) * diff);</p><p>&nbsp; }</p><p>`, `</p><p>&nbsp; precision mediump float;</p><p>&nbsp; varying vec3 vColor;</p><p>&nbsp; void main() {</p><p>&nbsp; &nbsp; gl_FragColor = vec4(vColor, 1.0);</p><p>&nbsp; }</p><p>`);</p><p>&nbsp;</p><p>const terrainChunks = CHUNKS_RAW.map(c =&gt; {</p><p>&nbsp; const pb = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, pb); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(b64ToBuf(c.pos)), gl.STATIC_DRAW);</p><p>&nbsp; const gb = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, gb); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(b64ToBuf(c.grad)), gl.STATIC_DRAW);</p><p>&nbsp; const cb = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, cb); gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(b64ToBuf(c.col)), gl.STATIC_DRAW);</p><p>&nbsp; const ib = gl.createBuffer(); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ib);</p><p>&nbsp; const idxArr = new Uint16Array(b64ToBuf(c.idx));</p><p>&nbsp; gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, idxArr, gl.STATIC_DRAW);</p><p>&nbsp; return { pb, gb, cb, ib, count: idxArr.length };</p><p>});</p><p>&nbsp;</p><p>const lakeMeshes = LAKES_RAW.map(lk =&gt; {</p><p>&nbsp; const n = lk.tris.length;</p><p>&nbsp; const pos = new Float32Array(n * 3), norm = new Float32Array(n * 3), col = new Float32Array(n * 3);</p><p>&nbsp; for (let i = 0; i &lt; n; i++) {</p><p>&nbsp; &nbsp; const p = lk.pts[lk.tris[i]];</p><p>&nbsp; &nbsp; const [mx, my] = lonLatToMeters(p[0], p[1]);</p><p>&nbsp; &nbsp; pos[i*3] = mx; pos[i*3+1] = my; pos[i*3+2] = lk.elevation_m;</p><p>&nbsp; &nbsp; norm[i*3+2] = 1.0;</p><p>&nbsp; &nbsp; col[i*3] = 0.22; col[i*3+1] = 0.74; col[i*3+2] = 0.97;</p><p>&nbsp; }</p><p>&nbsp; const pb = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, pb); gl.bufferData(gl.ARRAY_BUFFER, pos, gl.STATIC_DRAW);</p><p>&nbsp; const nb = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, nb); gl.bufferData(gl.ARRAY_BUFFER, norm, gl.STATIC_DRAW);</p><p>&nbsp; const cb = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, cb); gl.bufferData(gl.ARRAY_BUFFER, col, gl.STATIC_DRAW);</p><p>&nbsp; return { pb, nb, cb, count: n };</p><p>});</p><p>&nbsp;</p><p>const f15Count = F15_RAW.pos.length / 3;</p><p>const f15PB = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, f15PB); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(F15_RAW.pos), gl.STATIC_DRAW);</p><p>const f15NB = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, f15NB); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(F15_RAW.norm), gl.STATIC_DRAW);</p><p>const f15CB = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, f15CB); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(F15_RAW.col), gl.STATIC_DRAW);</p><p>&nbsp;</p><p>const airLines = [], airCols = [];</p><p>function hexToRgb(hex) {</p><p>&nbsp; const v = parseInt(hex.slice(1), 16);</p><p>&nbsp; return [((v &gt;&gt; 16) &amp; 255) / 255, ((v &gt;&gt; 8) &amp; 255) / 255, (v &amp; 255) / 255];</p><p>}</p><p>AIRSPACES_RAW.forEach(asp =&gt; {</p><p>&nbsp; const rgb = hexToRgb(asp.color);</p><p>&nbsp; const poly = asp.polygon.map(p =&gt; lonLatToMeters(p[0], p[1]));</p><p>&nbsp; const z0 = asp.min_alt_m, z1 = asp.max_alt_m;</p><p>&nbsp; const pushSeg = (ax, ay, az, bx, by, bz) =&gt; {</p><p>&nbsp; &nbsp; airLines.push(ax, ay, az, bx, by, bz);</p><p>&nbsp; &nbsp; airCols.push(...rgb, ...rgb);</p><p>&nbsp; };</p><p>&nbsp; for (let i = 0; i &lt; poly.length - 1; i++) {</p><p>&nbsp; &nbsp; const a = poly[i], b = poly[i+1];</p><p>&nbsp; &nbsp; pushSeg(a[0], a[1], z0, b[0], b[1], z0);</p><p>&nbsp; &nbsp; pushSeg(a[0], a[1], z1, b[0], b[1], z1);</p><p>&nbsp; &nbsp; pushSeg(a[0], a[1], z0, a[0], a[1], z1);</p><p>&nbsp; }</p><p>&nbsp; const cLon = asp.polygon.slice(0, -1).reduce((s, p) =&gt; s + p[0], 0) / (asp.polygon.length - 1);</p><p>&nbsp; const cLat = asp.polygon.slice(0, -1).reduce((s, p) =&gt; s + p[1], 0) / (asp.polygon.length - 1);</p><p>&nbsp; const [cx, cy] = lonLatToMeters(cLon, cLat);</p><p>&nbsp; asp.labelPos = [cx, cy, z1];</p><p>});</p><p>const airPB = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, airPB); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(airLines), gl.STATIC_DRAW);</p><p>const airCB = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, airCB); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(airCols), gl.STATIC_DRAW);</p><p>const airNB = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, airNB); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(airLines.length).fill(1), gl.STATIC_DRAW);</p><p>const airCount = airLines.length / 3;</p><p>&nbsp;</p><p>const trailPB = gl.createBuffer();</p><p>const trailFullColB = gl.createBuffer();</p><p>const trailNB = gl.createBuffer();</p><p>let trailCount = 0;</p><p>&nbsp;</p><p>const dropPB = gl.createBuffer();</p><p>const dropCB = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, dropCB);</p><p>gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([1, 0.32, 0.32, 1, 0.32, 0.32]), gl.STATIC_DRAW);</p><p>const dropNB = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, dropNB);</p><p>gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0,0,1, 0,0,1]), gl.STATIC_DRAW);</p><p>&nbsp;</p><p>function mulMat4(a, b) {</p><p>&nbsp; const o = new Float32Array(16);</p><p>&nbsp; for (let c = 0; c &lt; 4; c++) {</p><p>&nbsp; &nbsp; for (let r = 0; r &lt; 4; r++) {</p><p>&nbsp; &nbsp; &nbsp; o[c*4+r] = a[r]*b[c*4] + a[4+r]*b[c*4+1] + a[8+r]*b[c*4+2] + a[12+r]*b[c*4+3];</p><p>&nbsp; &nbsp; }</p><p>&nbsp; }</p><p>&nbsp; return o;</p><p>}</p><p>function matPerspective(fovY, aspect, near, far) {</p><p>&nbsp; const f = 1.0 / Math.tan(fovY / 2), nf = 1.0 / (near - far);</p><p>&nbsp; return new Float32Array([f/aspect,0,0,0, 0,f,0,0, 0,0,(far+near)*nf,-1, 0,0,2*far*near*nf,0]);</p><p>}</p><p>function matLookAt(eye, ctr) {</p><p>&nbsp; let fx = ctr[0]-eye[0], fy = ctr[1]-eye[1], fz = ctr[2]-eye[2];</p><p>&nbsp; const fl = Math.hypot(fx, fy, fz) || 1;</p><p>&nbsp; fx /= fl; fy /= fl; fz /= fl;</p><p>&nbsp; let sx = fy, sy = -fx, sz = 0;</p><p>&nbsp; const sl = Math.hypot(sx, sy, sz) || 1;</p><p>&nbsp; sx /= sl; sy /= sl; sz /= sl;</p><p>&nbsp; const ux = sy*fz - sz*fy, uy = sz*fx - sx*fz, uz = sx*fy - sy*fx;</p><p>&nbsp; return new Float32Array([</p><p>&nbsp; &nbsp; sx, ux, -fx, 0, &nbsp;sy, uy, -fy, 0, &nbsp;sz, uz, -fz, 0,</p><p>&nbsp; &nbsp; -(sx*eye[0]+sy*eye[1]+sz*eye[2]),</p><p>&nbsp; &nbsp; -(ux*eye[0]+uy*eye[1]+uz*eye[2]),</p><p>&nbsp; &nbsp; (fx*eye[0]+fy*eye[1]+fz*eye[2]), 1</p><p>&nbsp; ]);</p><p>}</p><p>function buildModelMat(tx, ty, tz, rollDeg, pitchDeg, yawDeg, scale) {</p><p>&nbsp; const rr = rollDeg * Math.PI/180, pr = pitchDeg * Math.PI/180, yr = yawDeg * Math.PI/180;</p><p>&nbsp; const cr = Math.cos(rr), sr = Math.sin(rr);</p><p>&nbsp; const cp = Math.cos(pr), sp = Math.sin(pr);</p><p>&nbsp; const cy = Math.cos(yr), sy = Math.sin(yr);</p><p>&nbsp; const mR = [cr,0,-sr,0, 0,1,0,0, sr,0,cr,0, 0,0,0,1];</p><p>&nbsp; const mP = [1,0,0,0, 0,cp,sp,0, 0,-sp,cp,0, 0,0,0,1];</p><p>&nbsp; const mY = [cy,-sy,0,0, sy,cy,0,0, 0,0,1,0, 0,0,0,1];</p><p>&nbsp; const mS = [scale,0,0,0, 0,scale,0,0, 0,0,scale,0, 0,0,0,1];</p><p>&nbsp; const mT = [1,0,0,0, 0,1,0,0, 0,0,1,0, tx,ty,tz,1];</p><p>&nbsp; return mulMat4(mT, mulMat4(mS, mulMat4(mY, mulMat4(mP, mR))));</p><p>}</p><p>&nbsp;</p><p>const IDENTITY_MAT = new Float32Array([1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]);</p><p>&nbsp;</p><p>let camTarget = [0, 0, 5000];</p><p>let camYaw = 0.0;</p><p>let camPitch = 0.72;</p><p>let camDist = 420000.0;</p><p>&nbsp;</p><p>function resetCamera() {</p><p>&nbsp; document.getElementById("chk-follow").checked = false;</p><p>&nbsp; camTarget = [0, 0, 5000]; camYaw = 0.0; camPitch = 0.72; camDist = 420000.0;</p><p>}</p><p>function zoomCamera(factor) {</p><p>&nbsp; camDist = Math.max(25.0, Math.min(1400000.0, camDist * factor));</p><p>}</p><p>function snapToAircraft() {</p><p>&nbsp; if (!fStore || fStore.len === 0) { alert("先にCSVまたはデモ飛行データを読み込んでください。"); return; }</p><p>&nbsp; const f = sampleFlightAt(simTime);</p><p>&nbsp; const zScale = parseFloat(document.getElementById("sel-z").value);</p><p>&nbsp; camTarget = [f.mx, f.my, f.alt * zScale];</p><p>&nbsp; camYaw = (f.yaw * Math.PI) / 180.0;</p><p>&nbsp; camPitch = 0.28;</p><p>&nbsp; camDist = 90.0;</p><p>&nbsp; document.getElementById("chk-follow").checked = true;</p><p>}</p><p>&nbsp;</p><p>let dragBtn = -1, lastMX = 0, lastMY = 0;</p><p>glCanvas.addEventListener("contextmenu", e =&gt; e.preventDefault());</p><p>glCanvas.addEventListener("mousedown", e =&gt; { dragBtn = e.button; lastMX = e.clientX; lastMY = e.clientY; });</p><p>window.addEventListener("mouseup", () =&gt; { dragBtn = -1; });</p><p>window.addEventListener("mousemove", e =&gt; {</p><p>&nbsp; if (dragBtn === -1) return;</p><p>&nbsp; const dx = e.clientX - lastMX, dy = e.clientY - lastMY;</p><p>&nbsp; lastMX = e.clientX; lastMY = e.clientY;</p><p>&nbsp; if (dragBtn === 0 &amp;&amp; !e.shiftKey) {</p><p>&nbsp; &nbsp; camYaw += dx * 0.006;</p><p>&nbsp; &nbsp; camPitch = Math.max(0.03, Math.min(1.54, camPitch + dy * 0.006));</p><p>&nbsp; } else {</p><p>&nbsp; &nbsp; document.getElementById("chk-follow").checked = false;</p><p>&nbsp; &nbsp; const spd = camDist * 0.0014;</p><p>&nbsp; &nbsp; const rx = Math.cos(camYaw), ry = -Math.sin(camYaw);</p><p>&nbsp; &nbsp; const fx = Math.sin(camYaw), fy = Math.cos(camYaw);</p><p>&nbsp; &nbsp; camTarget[0] -= (dx * rx - dy * fx) * spd;</p><p>&nbsp; &nbsp; camTarget[1] -= (dx * ry - dy * fy) * spd;</p><p>&nbsp; }</p><p>});</p><p>glCanvas.addEventListener("wheel", e =&gt; {</p><p>&nbsp; e.preventDefault();</p><p>&nbsp; camDist = Math.max(25.0, Math.min(1400000.0, camDist * Math.pow(1.0015, e.deltaY)));</p><p>}, { passive: false });</p><p>&nbsp;</p><p>// ==========================================</p><p>// 省メモリ TypedArray フライトストア (数百万行対応・GCゼロ)</p><p>// ==========================================</p><p>class FlightStore {</p><p>&nbsp; constructor(initCap = 16384) {</p><p>&nbsp; &nbsp; this.cap = initCap;</p><p>&nbsp; &nbsp; this.len = 0;</p><p>&nbsp; &nbsp; this.t &nbsp; &nbsp; = new Float64Array(initCap);</p><p>&nbsp; &nbsp; this.lon &nbsp; = new Float64Array(initCap);</p><p>&nbsp; &nbsp; this.lat &nbsp; = new Float64Array(initCap);</p><p>&nbsp; &nbsp; this.mx &nbsp; &nbsp;= new Float32Array(initCap);</p><p>&nbsp; &nbsp; this.my &nbsp; &nbsp;= new Float32Array(initCap);</p><p>&nbsp; &nbsp; this.alt &nbsp; = new Float32Array(initCap);</p><p>&nbsp; &nbsp; this.spd &nbsp; = new Float32Array(initCap);</p><p>&nbsp; &nbsp; this.roll &nbsp;= new Float32Array(initCap);</p><p>&nbsp; &nbsp; this.pitch = new Float32Array(initCap);</p><p>&nbsp; &nbsp; this.yaw &nbsp; = new Float32Array(initCap);</p><p>&nbsp; &nbsp; this.vsi &nbsp; = new Float32Array(initCap);</p><p>&nbsp; }</p><p>&nbsp; push(t, lon, lat, mx, my, alt, spd, roll, pitch, yaw) {</p><p>&nbsp; &nbsp; if (this.len &gt;= this.cap) {</p><p>&nbsp; &nbsp; &nbsp; const nc = this.cap * 2;</p><p>&nbsp; &nbsp; &nbsp; const g64 = a =&gt; { const n = new Float64Array(nc); n.set(a); return n; };</p><p>&nbsp; &nbsp; &nbsp; const g32 = a =&gt; { const n = new Float32Array(nc); n.set(a); return n; };</p><p>&nbsp; &nbsp; &nbsp; this.t = g64(this.t); this.lon = g64(this.lon); this.lat = g64(this.lat);</p><p>&nbsp; &nbsp; &nbsp; this.mx = g32(this.mx); this.my = g32(this.my); this.alt = g32(this.alt);</p><p>&nbsp; &nbsp; &nbsp; this.spd = g32(this.spd); this.roll = g32(this.roll); this.pitch = g32(this.pitch);</p><p>&nbsp; &nbsp; &nbsp; this.yaw = g32(this.yaw); this.vsi = g32(this.vsi);</p><p>&nbsp; &nbsp; &nbsp; this.cap = nc;</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; const k = this.len++;</p><p>&nbsp; &nbsp; this.t[k] = t; this.lon[k] = lon; this.lat[k] = lat;</p><p>&nbsp; &nbsp; this.mx[k] = mx; this.my[k] = my; this.alt[k] = alt;</p><p>&nbsp; &nbsp; this.spd[k] = spd; this.roll[k] = roll; this.pitch[k] = pitch; this.yaw[k] = yaw;</p><p>&nbsp; }</p><p>}</p><p>&nbsp;</p><p>let currentSource = null; &nbsp;// { type: "file", file } or { type: "text", text }</p><p>let loadJobId = 0;</p><p>let fStore = null;</p><p>let totalDuration = 0;</p><p>let simTime = 0;</p><p>let currentIdx = 0;</p><p>let isPlaying = false;</p><p>&nbsp;</p><p>document.getElementById("csv-input").addEventListener("change", e =&gt; {</p><p>&nbsp; const file = e.target.files[0];</p><p>&nbsp; if (!file) return;</p><p>&nbsp; currentSource = { type: "file", file };</p><p>&nbsp; loadFromSource(currentSource);</p><p>});</p><p>&nbsp;</p><p>function reparseIfLoaded() {</p><p>&nbsp; if (currentSource) loadFromSource(currentSource);</p><p>}</p><p>&nbsp;</p><p>function parseTimeVal(s) {</p><p>&nbsp; const str = String(s).trim();</p><p>&nbsp; if (/^\d{1,2}:\d{2}:\d{2}/.test(str)) {</p><p>&nbsp; &nbsp; const p = str.split(":").map(Number);</p><p>&nbsp; &nbsp; return p[0]*3600 + p[1]*60 + p[2];</p><p>&nbsp; }</p><p>&nbsp; return parseFloat(str);</p><p>}</p><p>&nbsp;</p><p>function findCol(headers, candidates) {</p><p>&nbsp; const low = headers.map(h =&gt; h.trim().toLowerCase());</p><p>&nbsp; for (const c of candidates) { const i = low.findIndex(h =&gt; h === c); if (i !== -1) return i; }</p><p>&nbsp; for (const c of candidates) { const i = low.findIndex(h =&gt; h.includes(c)); if (i !== -1) return i; }</p><p>&nbsp; return -1;</p><p>}</p><p>&nbsp;</p><p>function findFrameIndex(t) {</p><p>&nbsp; if (!fStore || fStore.len === 0) return 0;</p><p>&nbsp; let lo = 0, hi = fStore.len - 1;</p><p>&nbsp; const ts = fStore.t;</p><p>&nbsp; while (lo &lt; hi) {</p><p>&nbsp; &nbsp; const mid = (lo + hi + 1) &gt;&gt; 1;</p><p>&nbsp; &nbsp; if (ts[mid] &lt;= t) lo = mid;</p><p>&nbsp; &nbsp; else hi = mid - 1;</p><p>&nbsp; }</p><p>&nbsp; return lo;</p><p>}</p><p>&nbsp;</p><p>// 任意の時刻 t における連続補間フレームを取得 (0.1Hzでも100Hzでも60FPS滑らか)</p><p>function sampleFlightAt(t) {</p><p>&nbsp; const idx = findFrameIndex(t);</p><p>&nbsp; const nextIdx = Math.min(fStore.len - 1, idx + 1);</p><p>&nbsp; const t0 = fStore.t[idx], t1 = fStore.t[nextIdx];</p><p>&nbsp; const frac = (nextIdx &gt; idx &amp;&amp; t1 &gt; t0) ? Math.max(0, Math.min(1, (t - t0) / (t1 - t0))) : 0;</p><p>&nbsp; const lerpAng = (a, b) =&gt; a + ((((b - a + 540) % 360) - 180) * frac);</p><p>&nbsp;</p><p>&nbsp; return {</p><p>&nbsp; &nbsp; idx,</p><p>&nbsp; &nbsp; t,</p><p>&nbsp; &nbsp; lon: &nbsp; fStore.lon[idx] &nbsp; + (fStore.lon[nextIdx] &nbsp; - fStore.lon[idx]) &nbsp; * frac,</p><p>&nbsp; &nbsp; lat: &nbsp; fStore.lat[idx] &nbsp; + (fStore.lat[nextIdx] &nbsp; - fStore.lat[idx]) &nbsp; * frac,</p><p>&nbsp; &nbsp; mx: &nbsp; &nbsp;fStore.mx[idx] &nbsp; &nbsp;+ (fStore.mx[nextIdx] &nbsp; &nbsp;- fStore.mx[idx]) &nbsp; &nbsp;* frac,</p><p>&nbsp; &nbsp; my: &nbsp; &nbsp;fStore.my[idx] &nbsp; &nbsp;+ (fStore.my[nextIdx] &nbsp; &nbsp;- fStore.my[idx]) &nbsp; &nbsp;* frac,</p><p>&nbsp; &nbsp; alt: &nbsp; fStore.alt[idx] &nbsp; + (fStore.alt[nextIdx] &nbsp; - fStore.alt[idx]) &nbsp; * frac,</p><p>&nbsp; &nbsp; spd: &nbsp; fStore.spd[idx] &nbsp; + (fStore.spd[nextIdx] &nbsp; - fStore.spd[idx]) &nbsp; * frac,</p><p>&nbsp; &nbsp; roll: &nbsp;lerpAng(fStore.roll[idx], fStore.roll[nextIdx]),</p><p>&nbsp; &nbsp; pitch: fStore.pitch[idx] + (fStore.pitch[nextIdx] - fStore.pitch[idx]) * frac,</p><p>&nbsp; &nbsp; yaw: &nbsp; lerpAng(fStore.yaw[idx], &nbsp;fStore.yaw[nextIdx]),</p><p>&nbsp; &nbsp; vsi: &nbsp; fStore.vsi[idx] &nbsp; + (fStore.vsi[nextIdx] &nbsp; - fStore.vsi[idx]) &nbsp; * frac,</p><p>&nbsp; };</p><p>}</p><p>&nbsp;</p><p>async function loadFromSource(source) {</p><p>&nbsp; const myJob = ++loadJobId;</p><p>&nbsp; stopFlight();</p><p>&nbsp; document.getElementById("btn-play").disabled = true;</p><p>&nbsp; document.getElementById("btn-stop").disabled = true;</p><p>&nbsp; document.getElementById("seek-bar").disabled = true;</p><p>&nbsp; document.getElementById("hud-status").textContent = "LOADING 0%";</p><p>&nbsp; document.getElementById("frame-info").textContent = "読込中...";</p><p>&nbsp;</p><p>&nbsp; const thinStep = Math.max(1, parseInt(document.getElementById("opt-thin").value, 10));</p><p>&nbsp; const altScale = document.getElementById("opt-alt-unit").value === "ft" ? 0.3048 : 1.0;</p><p>&nbsp; const spdUnit = document.getElementById("opt-spd-unit").value;</p><p>&nbsp; const angScale = document.getElementById("opt-ang-unit").value === "rad" ? (180.0 / Math.PI) : 1.0;</p><p>&nbsp; const invR = document.getElementById("opt-inv-roll").checked ? -1.0 : 1.0;</p><p>&nbsp; const invP = document.getElementById("opt-inv-pitch").checked ? -1.0 : 1.0;</p><p>&nbsp; const xyzMap = document.getElementById("opt-xyz-map").value;</p><p>&nbsp;</p><p>&nbsp; const estBytes = source.type === "file" ? source.file.size : source.text.length;</p><p>&nbsp; const estRows = Math.min(2500000, Math.max(4096, Math.ceil(estBytes / (38 * thinStep)) + 1024));</p><p>&nbsp; const store = new FlightStore(estRows);</p><p>&nbsp;</p><p>&nbsp; let colsMeta = null;</p><p>&nbsp; let t0 = null;</p><p>&nbsp; let rowCounter = 0;</p><p>&nbsp;</p><p>&nbsp; function processLines(lines) {</p><p>&nbsp; &nbsp; for (let li = 0; li &lt; lines.length; li++) {</p><p>&nbsp; &nbsp; &nbsp; const line = lines[li].trim();</p><p>&nbsp; &nbsp; &nbsp; if (!line) continue;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; if (!colsMeta) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; const headers = line.split(",").map(h =&gt; h.trim());</p><p>&nbsp; &nbsp; &nbsp; &nbsp; const cLat = findCol(headers, ["lat", "latitude", "緯度"]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; const cLon = findCol(headers, ["lon", "lng", "long", "longitude", "経度"]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (cLat === -1 || cLon === -1) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new Error("緯度(lat)・経度(lon)の列が見つかりません。\n検出ヘッダ: " + headers.join(", "));</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; let cRoll, cPitch;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (xyzMap === "RPY") {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cRoll &nbsp;= findCol(headers, ["roll", "bank", "phi", "ang_x", "angle_x", "rot_x", "x_deg", "x", "ロール"]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cPitch = findCol(headers, ["pitch", "theta", "ang_y", "angle_y", "rot_y", "y_deg", "y", "ピッチ"]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; } else {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cPitch = findCol(headers, ["pitch", "theta", "ang_x", "angle_x", "rot_x", "x_deg", "x", "ピッチ"]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cRoll &nbsp;= findCol(headers, ["roll", "bank", "phi", "ang_y", "angle_y", "rot_y", "y_deg", "y", "ロール"]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; colsMeta = {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cTime: findCol(headers, ["time", "t", "timestamp", "sec", "時間", "時刻"]),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cLat, cLon,</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cAlt: &nbsp;findCol(headers, ["alt_m", "alt_ft", "alt", "altitude", "高度"]),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cSpd: &nbsp;findCol(headers, ["speed_kt", "speed", "spd", "tas", "ias", "gs", "velocity", "vel", "速度"]),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cRoll, cPitch,</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cYaw: &nbsp;findCol(headers, ["yaw", "heading", "hdg", "psi", "ang_z", "angle_z", "rot_z", "z_deg", "z", "方位", "ヨー"]),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; };</p><p>&nbsp; &nbsp; &nbsp; &nbsp; continue;</p><p>&nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; if ((rowCounter++ % thinStep) !== 0) continue;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; const cols = line.split(",");</p><p>&nbsp; &nbsp; &nbsp; if (cols.length &lt; 3) continue;</p><p>&nbsp; &nbsp; &nbsp; const lat = parseFloat(cols[colsMeta.cLat]);</p><p>&nbsp; &nbsp; &nbsp; const lon = parseFloat(cols[colsMeta.cLon]);</p><p>&nbsp; &nbsp; &nbsp; if (isNaN(lat) || isNaN(lon)) continue;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; let t = colsMeta.cTime !== -1 ? parseTimeVal(cols[colsMeta.cTime]) : (rowCounter - 1) * 0.05;</p><p>&nbsp; &nbsp; &nbsp; if (isNaN(t)) t = (rowCounter - 1) * 0.05;</p><p>&nbsp; &nbsp; &nbsp; if (t0 === null) t0 = t;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; const altM = (colsMeta.cAlt !== -1 ? parseFloat(cols[colsMeta.cAlt]) : 3000) * altScale;</p><p>&nbsp; &nbsp; &nbsp; let spdKt = 0;</p><p>&nbsp; &nbsp; &nbsp; if (colsMeta.cSpd !== -1) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; const rawS = parseFloat(cols[colsMeta.cSpd]) || 0;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (spdUnit === "kt") spdKt = rawS;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; else if (spdUnit === "kmh") spdKt = rawS / 1.852;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; else spdKt = rawS * 1.94384;</p><p>&nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; const roll &nbsp;= (colsMeta.cRoll &nbsp;!== -1 ? (parseFloat(cols[colsMeta.cRoll]) &nbsp;|| 0) : 0) * angScale * invR;</p><p>&nbsp; &nbsp; &nbsp; const pitch = (colsMeta.cPitch !== -1 ? (parseFloat(cols[colsMeta.cPitch]) || 0) : 0) * angScale * invP;</p><p>&nbsp; &nbsp; &nbsp; const yaw &nbsp; = (colsMeta.cYaw &nbsp; !== -1 ? (parseFloat(cols[colsMeta.cYaw]) &nbsp; || 0) : 0) * angScale;</p><p>&nbsp; &nbsp; &nbsp; const [mx, my] = lonLatToMeters(lon, lat);</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; store.push(t - t0, lon, lat, mx, my, isNaN(altM) ? 3000 : altM, spdKt, roll, pitch, yaw);</p><p>&nbsp; &nbsp; }</p><p>&nbsp; }</p><p>&nbsp;</p><p>&nbsp; try {</p><p>&nbsp; &nbsp; if (source.type === "text") {</p><p>&nbsp; &nbsp; &nbsp; processLines(source.text.split(/\r?\n/));</p><p>&nbsp; &nbsp; } else {</p><p>&nbsp; &nbsp; &nbsp; const file = source.file;</p><p>&nbsp; &nbsp; &nbsp; const CHUNK_BYTES = 4 * 1024 * 1024; // 4MB単位でストリーミング読込</p><p>&nbsp; &nbsp; &nbsp; const decoder = new TextDecoder("utf-8");</p><p>&nbsp; &nbsp; &nbsp; let offset = 0;</p><p>&nbsp; &nbsp; &nbsp; let leftover = "";</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; while (offset &lt; file.size) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (myJob !== loadJobId) return; // 別の読込が開始されたら中断</p><p>&nbsp; &nbsp; &nbsp; &nbsp; const end = Math.min(file.size, offset + CHUNK_BYTES);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; const buf = await file.slice(offset, end).arrayBuffer();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; const isLast = (end &gt;= file.size);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; const decoded = leftover + decoder.decode(buf, { stream: !isLast });</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (!isLast) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const lastNl = decoded.lastIndexOf("\n");</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (lastNl !== -1) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; processLines(decoded.slice(0, lastNl).split(/\r?\n/));</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; leftover = decoded.slice(lastNl + 1);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; leftover = decoded;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; } else {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; processLines(decoded.split(/\r?\n/));</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; leftover = "";</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; offset = end;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; const pct = Math.min(99, Math.round((offset / file.size) * 100));</p><p>&nbsp; &nbsp; &nbsp; &nbsp; document.getElementById("hud-status").textContent = `LOAD ${pct}%`;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; document.getElementById("frame-info").textContent = `読込中 ${pct}% (${store.len.toLocaleString()}点)`;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; await new Promise(r =&gt; setTimeout(r, 0)); // UIフリーズ防止</p><p>&nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; }</p><p>&nbsp; } catch (err) {</p><p>&nbsp; &nbsp; alert(err.message);</p><p>&nbsp; &nbsp; document.getElementById("hud-status").textContent = "ERROR";</p><p>&nbsp; &nbsp; return;</p><p>&nbsp; }</p><p>&nbsp;</p><p>&nbsp; if (myJob !== loadJobId) return;</p><p>&nbsp; if (store.len === 0) { alert("有効な行を読み込めませんでした"); return; }</p><p>&nbsp;</p>
]]>
</description>
<link>https://ameblo.jp/jmohui/entry-12985394806.html</link>
<pubDate>Mon, 23 Nov 2026 13:34:53 +0900</pubDate>
</item>
<item>
<title>あれ１</title>
<description>
<![CDATA[ <p>import os</p><p>import json</p><p>import time</p><p>from pathlib import Path</p><p>from concurrent.futures import ProcessPoolExecutor, as_completed</p><p>import numpy as np</p><p>&nbsp;</p><p># ==========================================</p><p># 設定パラメータ</p><p># ==========================================</p><p>GRID_RES_DEG = 0.002 &nbsp;# 約200mメッシュ</p><p>OUTPUT_JSON_PATH = "chubu_hokuriku_hires_3d.json"</p><p>MAX_CPU_CORES = os.cpu_count() or 4</p><p>&nbsp;</p><p>EROSION_ROUNDS = 4</p><p>DROPLETS_PER_ROUND = 350_000</p><p>&nbsp;</p><p>LON_MIN, LON_MAX = 135.40, 139.20</p><p>LAT_MIN, LAT_MAX = 33.65, 37.60</p><p>&nbsp;</p><p># ==========================================</p><p># 1. 対象10県輪郭</p><p># ==========================================</p><p>N_ISH_TOY_COAST &nbsp; = [137.042, 36.858]</p><p>N_ISH_TOY_GIF &nbsp; &nbsp; = [136.835, 36.320]</p><p>N_ISH_FUK_GIF &nbsp; &nbsp; = [136.771, 36.155]</p><p>N_ISH_FUK_COAST &nbsp; = [136.245, 36.295]</p><p>N_TOY_NII_COAST &nbsp; = [137.630, 36.982]</p><p>N_TOY_GIF_NAG &nbsp; &nbsp; = [137.605, 36.385]</p><p>N_FUK_KYOTO_SHIGA = [135.840, 35.440]</p><p>N_FUK_GIF_SHIGA &nbsp; = [136.320, 35.465]</p><p>N_GIF_SHIGA_MIE &nbsp; = [136.410, 35.230]</p><p>N_SHIGA_KYOTO_MIE = [136.050, 34.770]</p><p>N_GIF_AIC_MIE &nbsp; &nbsp; = [136.665, 35.140]</p><p>N_GIF_NAG_AIC &nbsp; &nbsp; = [137.645, 35.235]</p><p>N_NAG_AIC_SHI &nbsp; &nbsp; = [137.670, 35.195]</p><p>N_AIC_SHI_COAST &nbsp; = [137.485, 34.685]</p><p>N_NAG_YAM_SHI &nbsp; &nbsp; = [138.180, 35.425]</p><p>N_YAM_SHI_FUJI &nbsp; &nbsp;= [138.727, 35.361]</p><p>N_YAM_SHI_KAN &nbsp; &nbsp; = [139.020, 35.415]</p><p>N_NAG_YAM_N &nbsp; &nbsp; &nbsp; = [138.730, 35.915]</p><p>&nbsp;</p><p>B_ISH_TOY &nbsp; = [N_ISH_TOY_COAST, [136.95, 36.76], [136.92, 36.63], [136.88, 36.50], N_ISH_TOY_GIF]</p><p>B_ISH_GIF &nbsp; = [N_ISH_TOY_GIF, [136.80, 36.23], N_ISH_FUK_GIF]</p><p>B_ISH_FUK &nbsp; = [N_ISH_FUK_GIF, [136.62, 36.13], [136.42, 36.20], N_ISH_FUK_COAST]</p><p>B_TOY_GIF &nbsp; = [N_ISH_TOY_GIF, [136.95, 36.34], [137.18, 36.26], [137.38, 36.29], [137.50, 36.35], N_TOY_GIF_NAG]</p><p>B_TOY_NAG &nbsp; = [N_TOY_GIF_NAG, [137.62, 36.57], [137.69, 36.74], [137.67, 36.88], N_TOY_NII_COAST]</p><p>B_FUK_GIF &nbsp; = [N_ISH_FUK_GIF, [136.81, 36.02], [136.74, 35.84], [136.55, 35.73], [136.38, 35.62], N_FUK_GIF_SHIGA]</p><p>B_FUK_SHIGA = [N_FUK_KYOTO_SHIGA, [135.98, 35.53], [136.18, 35.63], N_FUK_GIF_SHIGA]</p><p>B_GIF_SHIGA = [N_FUK_GIF_SHIGA, [136.39, 35.38], [136.42, 35.33], [136.39, 35.27], N_GIF_SHIGA_MIE]</p><p>B_MIE_SHIGA = [N_SHIGA_KYOTO_MIE, [136.24, 34.86], [136.40, 35.02], N_GIF_SHIGA_MIE]</p><p>B_SHIGA_W &nbsp; = [N_SHIGA_KYOTO_MIE, [135.92, 34.82], [135.84, 34.93], [135.84, 35.06], [135.81, 35.24], N_FUK_KYOTO_SHIGA]</p><p>B_GIF_NAG &nbsp; = [N_TOY_GIF_NAG, [137.62, 36.22], [137.55, 36.10], [137.48, 35.89], [137.56, 35.62], [137.61, 35.42], N_GIF_NAG_AIC]</p><p>B_GIF_AIC &nbsp; = [N_GIF_AIC_MIE, [136.74, 35.24], [136.94, 35.38], [137.16, 35.27], [137.38, 35.33], [137.52, 35.34], N_GIF_NAG_AIC]</p><p>B_GIF_MIE &nbsp; = [N_GIF_SHIGA_MIE, [136.48, 35.20], N_GIF_AIC_MIE]</p><p>B_NAG_AIC &nbsp; = [N_GIF_NAG_AIC, [137.66, 35.21], N_NAG_AIC_SHI]</p><p>B_AIC_SHI &nbsp; = [N_NAG_AIC_SHI, [137.71, 35.04], [137.66, 34.89], [137.58, 34.81], [137.52, 34.74], N_AIC_SHI_COAST]</p><p>B_NAG_SHI &nbsp; = [N_NAG_AIC_SHI, [137.82, 35.22], [138.02, 35.26], [138.14, 35.35], N_NAG_YAM_SHI]</p><p>B_NAG_YAM &nbsp; = [N_NAG_YAM_SHI, [138.24, 35.67], [138.34, 35.84], [138.52, 35.89], N_NAG_YAM_N]</p><p>B_YAM_SHI &nbsp; = [N_NAG_YAM_SHI, [138.32, 35.40], [138.52, 35.32], [138.65, 35.34], N_YAM_SHI_FUJI, [138.86, 35.39], N_YAM_SHI_KAN]</p><p>B_MIE_SW &nbsp; &nbsp;= [[136.005, 33.725], [135.91, 33.85], [135.98, 34.05], [136.11, 34.22], [136.14, 34.45], [136.05, 34.60], N_SHIGA_KYOTO_MIE]</p><p>&nbsp;</p><p>TARGET_POLYGONS = [</p><p>&nbsp; &nbsp; [N_ISH_TOY_COAST, [137.00, 36.82], [137.05, 36.77], [137.14, 36.76], [137.23, 36.77], [137.35, 36.79],</p><p>&nbsp; &nbsp; &nbsp;[137.43, 36.89], [137.45, 36.92], [137.53, 36.94], N_TOY_NII_COAST]</p><p>&nbsp; &nbsp; + list(reversed(B_TOY_NAG))[1:] + list(reversed(B_TOY_GIF))[1:] + list(reversed(B_ISH_TOY))[1:],</p><p>&nbsp; &nbsp; [N_ISH_FUK_COAST, [136.38, 36.41], [136.50, 36.52], [136.64, 36.66], [136.75, 36.86],</p><p>&nbsp; &nbsp; &nbsp;[136.74, 37.00], [136.67, 37.14], [136.71, 37.27], [136.86, 37.39], [137.06, 37.51],</p><p>&nbsp; &nbsp; &nbsp;[137.33, 37.53], [137.29, 37.40], [137.16, 37.28], [137.04, 37.21], [136.94, 37.15],</p><p>&nbsp; &nbsp; &nbsp;[137.02, 37.11], [136.91, 37.05], [136.98, 37.01], [137.04, 36.96], N_ISH_TOY_COAST]</p><p>&nbsp; &nbsp; + B_ISH_TOY[1:] + B_ISH_GIF[1:] + B_ISH_FUK[1:],</p><p>&nbsp; &nbsp; [N_ISH_FUK_COAST, [136.14, 36.24], [136.11, 36.12], [136.02, 36.02], [135.96, 35.97],</p><p>&nbsp; &nbsp; &nbsp;[136.03, 35.84], [136.06, 35.72], [136.02, 35.67], [135.96, 35.75], [135.94, 35.65],</p><p>&nbsp; &nbsp; &nbsp;[135.87, 35.62], [135.84, 35.53], [135.74, 35.51], [135.68, 35.56], [135.58, 35.51],</p><p>&nbsp; &nbsp; &nbsp;[135.46, 35.48], [135.68, 35.41]]</p><p>&nbsp; &nbsp; + B_FUK_SHIGA + list(reversed(B_FUK_GIF))[1:] + B_ISH_FUK[1:],</p><p>&nbsp; &nbsp; B_NAG_YAM + [[138.94, 35.88], [139.08, 35.76], [139.14, 35.62], [139.07, 35.48], N_YAM_SHI_KAN] + list(reversed(B_YAM_SHI))[1:],</p><p>&nbsp; &nbsp; B_TOY_NAG + [[137.88, 36.92], [138.12, 36.96], [138.42, 37.02], [138.63, 36.92], [138.57, 36.70], [138.62, 36.44], [138.68, 36.22], [138.76, 36.04], N_NAG_YAM_N]</p><p>&nbsp; &nbsp; + list(reversed(B_NAG_YAM))[1:] + list(reversed(B_NAG_SHI))[1:] + list(reversed(B_NAG_AIC))[1:] + list(reversed(B_GIF_NAG))[1:],</p><p>&nbsp; &nbsp; B_GIF_SHIGA + B_GIF_MIE[1:] + B_GIF_AIC[1:] + list(reversed(B_GIF_NAG))[1:] + list(reversed(B_TOY_GIF))[1:] + B_ISH_GIF[1:] + B_FUK_GIF[1:],</p><p>&nbsp; &nbsp; [N_AIC_SHI_COAST, [137.59, 34.68], [137.82, 34.66], [138.05, 34.63], [138.22, 34.59],</p><p>&nbsp; &nbsp; &nbsp;[138.24, 34.68], [138.28, 34.77], [138.33, 34.86], [138.48, 34.96], [138.54, 35.02],</p><p>&nbsp; &nbsp; &nbsp;[138.51, 35.04], [138.64, 35.12], [138.80, 35.10], [138.86, 35.06], [138.77, 35.02],</p><p>&nbsp; &nbsp; &nbsp;[138.80, 34.93], [138.75, 34.78], [138.79, 34.66], [138.85, 34.60], [138.95, 34.66],</p><p>&nbsp; &nbsp; &nbsp;[139.04, 34.78], [139.15, 34.96], [139.11, 35.07], [139.08, 35.14], [139.01, 35.22],</p><p>&nbsp; &nbsp; &nbsp;[138.98, 35.33], N_YAM_SHI_KAN]</p><p>&nbsp; &nbsp; + list(reversed(B_YAM_SHI))[1:] + list(reversed(B_NAG_SHI))[1:] + B_AIC_SHI[1:],</p><p>&nbsp; &nbsp; [N_GIF_AIC_MIE, [136.75, 35.06], [136.85, 35.05], [136.82, 34.92], [136.86, 34.77],</p><p>&nbsp; &nbsp; &nbsp;[136.93, 34.69], [136.98, 34.73], [136.95, 34.88], [136.99, 34.87], [137.03, 34.81],</p><p>&nbsp; &nbsp; &nbsp;[137.16, 34.81], [137.27, 34.81], [137.32, 34.75], [137.20, 34.69], [137.07, 34.62],</p><p>&nbsp; &nbsp; &nbsp;[137.01, 34.58], [137.14, 34.60], [137.35, 34.65], N_AIC_SHI_COAST]</p><p>&nbsp; &nbsp; + list(reversed(B_AIC_SHI))[1:] + list(reversed(B_NAG_AIC))[1:] + list(reversed(B_GIF_AIC))[1:],</p><p>&nbsp; &nbsp; [N_GIF_AIC_MIE, [136.71, 35.03], [136.65, 34.95], [136.62, 34.85], [136.54, 34.72],</p><p>&nbsp; &nbsp; &nbsp;[136.56, 34.58], [136.78, 34.50], [136.85, 34.48], [136.92, 34.37], [136.80, 34.27],</p><p>&nbsp; &nbsp; &nbsp;[136.62, 34.30], [136.45, 34.25], [136.34, 34.19], [136.22, 34.07], [136.26, 34.00],</p><p>&nbsp; &nbsp; &nbsp;[136.11, 33.89]]</p><p>&nbsp; &nbsp; + B_MIE_SW + B_MIE_SHIGA[1:] + B_GIF_MIE[1:],</p><p>&nbsp; &nbsp; B_SHIGA_W + B_FUK_SHIGA[1:] + B_GIF_SHIGA[1:] + list(reversed(B_MIE_SHIGA))[1:],</p><p>]</p><p>&nbsp;</p><p>OTHER_LAND_POLYGONS = [</p><p>&nbsp; &nbsp; [[137.63, 36.98], [139.30, 37.65], [139.30, 35.10], [139.08, 35.14], [139.01, 35.22], [138.98, 35.33], N_YAM_SHI_KAN, [139.07, 35.48], [139.14, 35.62], [139.08, 35.76], [138.94, 35.88], N_NAG_YAM_N, [138.76, 36.04], [138.68, 36.22], [138.62, 36.44], [138.57, 36.70], [138.63, 36.92], [138.42, 37.02], [138.12, 36.96], [137.88, 36.92], N_TOY_NII_COAST],</p><p>&nbsp; &nbsp; [[135.46, 35.48], [135.20, 35.45], [135.20, 33.55], [136.005, 33.725]]</p><p>&nbsp; &nbsp; + B_MIE_SW[1:] + B_SHIGA_W[1:] + [[135.68, 35.41], [135.46, 35.48]],</p><p>]</p><p>&nbsp;</p><p>POLY_BOUNDS = []</p><p>for p in TARGET_POLYGONS:</p><p>&nbsp; &nbsp; arr = np.array(p)</p><p>&nbsp; &nbsp; POLY_BOUNDS.append((arr[:, 0].min() - 0.02, arr[:, 1].min() - 0.02, arr[:, 0].max() + 0.02, arr[:, 1].max() + 0.02))</p><p>&nbsp;</p><p># ==========================================</p><p># 2. 地形コンポーネント &amp; 精密湖沼ポリゴン</p><p># ==========================================</p><p>PEAKS = [</p><p>&nbsp; &nbsp; (137.758, 36.758, 2932, 0.12, 1.70), (137.753, 36.662, 2814, 0.11, 1.75),</p><p>&nbsp; &nbsp; (137.747, 36.624, 2889, 0.11, 1.75), (137.680, 36.824, 2418, 0.12, 1.80),</p><p>&nbsp; &nbsp; (137.617, 36.623, 2999, 0.12, 1.75), (137.619, 36.576, 3015, 0.13, 1.65),</p><p>&nbsp; &nbsp; (137.545, 36.469, 2926, 0.12, 1.75), (137.539, 36.392, 2840, 0.11, 1.80),</p><p>&nbsp; &nbsp; (137.603, 36.422, 2986, 0.11, 1.75), (137.605, 36.402, 2924, 0.10, 1.75),</p><p>&nbsp; &nbsp; (137.647, 36.342, 3180, 0.11, 1.70), (137.648, 36.289, 3190, 0.13, 1.65),</p><p>&nbsp; &nbsp; (137.727, 36.394, 2857, 0.11, 1.75), (137.713, 36.407, 2763, 0.10, 1.80),</p><p>&nbsp; &nbsp; (137.553, 36.106, 3026, 0.14, 1.65), (137.480, 35.893, 3067, 0.14, 1.55),</p><p>&nbsp; &nbsp; (137.804, 35.789, 2956, 0.12, 1.75), (137.817, 35.719, 2864, 0.11, 1.75),</p><p>&nbsp; &nbsp; (137.811, 35.689, 2841, 0.11, 1.80), (137.756, 35.568, 2363, 0.12, 1.80),</p><p>&nbsp; &nbsp; (137.596, 35.443, 2191, 0.15, 1.75), (138.237, 35.758, 2967, 0.12, 1.70),</p><p>&nbsp; &nbsp; (138.183, 35.720, 3033, 0.12, 1.75), (138.308, 35.702, 2841, 0.11, 1.75),</p><p>&nbsp; &nbsp; (138.239, 35.674, 3193, 0.13, 1.65), (138.228, 35.646, 3190, 0.12, 1.70),</p><p>&nbsp; &nbsp; (138.228, 35.622, 3026, 0.11, 1.75), (138.183, 35.573, 3047, 0.12, 1.75),</p><p>&nbsp; &nbsp; (138.182, 35.500, 3141, 0.12, 1.75), (138.157, 35.461, 3121, 0.13, 1.75),</p><p>&nbsp; &nbsp; (138.139, 35.423, 3013, 0.12, 1.75), (138.084, 35.338, 2592, 0.13, 1.80),</p><p>&nbsp; &nbsp; (138.161, 35.255, 2330, 0.13, 1.80), (138.370, 35.971, 2899, 0.13, 1.55),</p><p>&nbsp; &nbsp; (138.295, 36.103, 2531, 0.12, 1.65), (138.105, 36.226, 2034, 0.13, 1.80),</p><p>&nbsp; &nbsp; (138.197, 36.102, 1925, 0.12, 1.80), (138.523, 36.406, 2568, 0.13, 1.50),</p><p>&nbsp; &nbsp; (138.413, 36.549, 2354, 0.13, 1.70), (138.520, 36.665, 2307, 0.18, 1.75),</p><p>&nbsp; &nbsp; (138.140, 36.742, 2053, 0.13, 1.75), (138.132, 36.697, 1917, 0.12, 1.80),</p><p>&nbsp; &nbsp; (138.625, 35.871, 2599, 0.15, 1.75), (138.592, 35.893, 2230, 0.13, 1.80),</p><p>&nbsp; &nbsp; (138.729, 35.909, 2475, 0.15, 1.75), (138.845, 35.749, 2057, 0.15, 1.75),</p><p>&nbsp; &nbsp; (138.807, 35.545, 1785, 0.12, 1.80), (138.538, 35.412, 1964, 0.13, 1.75),</p><p>&nbsp; &nbsp; (138.807, 35.233, 1504, 0.10, 1.60), (139.021, 35.232, 1438, 0.12, 1.70),</p><p>&nbsp; &nbsp; (138.960, 34.863, 1406, 0.14, 1.65), (138.838, 34.955, &nbsp;982, 0.10, 1.75),</p><p>&nbsp; &nbsp; (136.771, 36.155, 2702, 0.15, 1.65), (136.765, 36.106, 2399, 0.13, 1.75),</p><p>&nbsp; &nbsp; (136.835, 36.002, 1709, 0.13, 1.80), (136.601, 35.934, 1523, 0.14, 1.75),</p><p>&nbsp; &nbsp; (136.515, 35.762, 1617, 0.14, 1.75), (137.167, 36.038, 1529, 0.15, 1.85),</p><p>&nbsp; &nbsp; (137.655, 35.228, 1415, 0.17, 1.85), (137.542, 35.125, 1152, 0.15, 1.90),</p><p>&nbsp; &nbsp; (136.406, 35.418, 1377, 0.12, 1.65), (136.440, 35.220, &nbsp;908, 0.12, 1.85),</p><p>&nbsp; &nbsp; (137.365, 34.910, &nbsp;789, 0.12, 1.90), (137.168, 35.258, &nbsp;629, 0.11, 1.90),</p><p>&nbsp; &nbsp; (136.815, 36.782, &nbsp;637, 0.15, 1.85), (136.980, 37.330, &nbsp;460, 0.20, 1.95),</p><p>&nbsp; &nbsp; (136.109, 34.186, 1695, 0.15, 1.65), (136.419, 35.019, 1212, 0.12, 1.75),</p><p>&nbsp; &nbsp; (136.442, 35.174, 1144, 0.11, 1.80), (136.165, 34.515, 1037, 0.14, 1.80),</p><p>&nbsp; &nbsp; (136.290, 34.725, &nbsp;842, 0.14, 1.85), (136.775, 34.455, &nbsp;555, 0.11, 1.85),</p><p>&nbsp; &nbsp; (136.020, 33.960, 1100, 0.14, 1.75),</p><p>&nbsp; &nbsp; (135.887, 35.253, 1214, 0.08, 1.80), (135.833, 35.066, &nbsp;848, 0.07, 1.85),</p><p>&nbsp; &nbsp; (136.332, 35.533, 1317, 0.10, 1.75), (136.377, 35.280, 1084, 0.09, 1.80),</p><p>&nbsp; &nbsp; (136.010, 34.920, &nbsp;600, 0.11, 1.85),</p><p>]</p><p>&nbsp;</p><p>RIDGES = [</p><p>&nbsp; &nbsp; (137.76, 36.76, 137.64, 36.30, 2150, 0.16), (137.64, 36.30, 137.48, 35.89, 1900, 0.17),</p><p>&nbsp; &nbsp; (137.80, 35.82, 137.75, 35.50, 1800, 0.12), (138.24, 35.76, 138.12, 35.28, 2100, 0.15),</p><p>&nbsp; &nbsp; (136.77, 36.15, 136.52, 35.74, 1150, 0.19), (138.37, 35.97, 138.85, 35.80, 1500, 0.19),</p><p>&nbsp; &nbsp; (137.05, 36.22, 137.45, 36.02, 1000, 0.26), (138.95, 35.05, 138.92, 34.72, &nbsp;820, 0.13),</p><p>&nbsp; &nbsp; (136.41, 35.42, 136.48, 35.65, &nbsp;850, 0.16), (136.42, 35.22, 136.36, 34.85, &nbsp;850, 0.14),</p><p>&nbsp; &nbsp; (136.22, 34.60, 136.02, 33.90, 1050, 0.19),</p><p>&nbsp; &nbsp; (135.84, 35.05, 135.91, 35.43, &nbsp;820, 0.085), (135.91, 35.43, 136.30, 35.58, 720, 0.11),</p><p>]</p><p>&nbsp;</p><p>PASSES = [</p><p>&nbsp; &nbsp; (136.465, 35.345, &nbsp;180, 0.07, 0.85), (137.603, 36.195, 1650, 0.06, 0.65),</p><p>&nbsp; &nbsp; (138.015, 36.095, &nbsp;950, 0.06, 0.75), (136.155, 35.745, &nbsp;550, 0.06, 0.75),</p><p>&nbsp; &nbsp; (138.865, 35.405, 1080, 0.06, 0.70), (138.625, 36.335, &nbsp;950, 0.07, 0.70),</p><p>&nbsp; &nbsp; (136.330, 34.855, &nbsp;360, 0.05, 0.75),</p><p>]</p><p>&nbsp;</p><p>RIVERS = [</p><p>&nbsp; &nbsp; (137.60, 36.42, 137.63, 36.60, 1400, &nbsp;800, 0.035, 0.76), (137.63, 36.60, 137.55, 36.82, &nbsp;800, &nbsp;150, 0.042, 0.80),</p><p>&nbsp; &nbsp; (137.55, 36.82, 137.43, 36.91, &nbsp;150, &nbsp; &nbsp;4, 0.055, 0.86), (137.53, 36.54, 137.24, 36.75, &nbsp;950, &nbsp; &nbsp;4, 0.040, 0.78),</p><p>&nbsp; &nbsp; (137.25, 36.14, 137.23, 36.48, &nbsp;560, &nbsp;220, 0.042, 0.78), (137.48, 36.28, 137.23, 36.48, &nbsp;900, &nbsp;220, 0.035, 0.75),</p><p>&nbsp; &nbsp; (137.23, 36.48, 137.22, 36.76, &nbsp;220, &nbsp; &nbsp;4, 0.050, 0.84), (136.92, 36.02, 136.97, 36.45, &nbsp;650, &nbsp;150, 0.042, 0.78),</p><p>&nbsp; &nbsp; (136.97, 36.45, 137.08, 36.77, &nbsp;150, &nbsp; &nbsp;4, 0.050, 0.84), (136.70, 36.22, 136.48, 36.50, &nbsp;500, &nbsp; &nbsp;4, 0.042, 0.78),</p><p>&nbsp; &nbsp; (136.65, 35.87, 136.48, 35.98, &nbsp;480, &nbsp;180, 0.038, 0.76), (136.48, 35.98, 136.14, 36.22, &nbsp;180, &nbsp; &nbsp;4, 0.050, 0.84),</p><p>&nbsp; &nbsp; (137.97, 36.24, 137.86, 36.85, &nbsp;590, &nbsp;340, 0.060, 0.84), (137.65, 36.25, 137.92, 36.22, 1480, &nbsp;600, 0.035, 0.78),</p><p>&nbsp; &nbsp; (138.62, 35.95, 138.48, 36.22, 1100, &nbsp;680, 0.045, 0.78), (138.48, 36.22, 138.18, 36.65, &nbsp;680, &nbsp;340, 0.065, 0.82),</p><p>&nbsp; &nbsp; (138.18, 36.65, 138.45, 36.96, &nbsp;340, &nbsp;260, 0.060, 0.82), (137.75, 35.92, 137.50, 35.49, &nbsp;850, &nbsp;280, 0.052, 0.82),</p><p>&nbsp; &nbsp; (137.50, 35.49, 136.75, 35.06, &nbsp;280, &nbsp; &nbsp;3, 0.068, 0.88), (137.24, 35.81, 137.02, 35.44, &nbsp;380, &nbsp; 60, 0.042, 0.80),</p><p>&nbsp; &nbsp; (136.90, 35.85, 136.72, 35.15, &nbsp;450, &nbsp; &nbsp;4, 0.048, 0.82), (136.52, 35.62, 136.64, 35.22, &nbsp;320, &nbsp; &nbsp;8, 0.045, 0.80),</p><p>&nbsp; &nbsp; (137.45, 35.22, 137.02, 34.86, &nbsp;350, &nbsp; &nbsp;4, 0.042, 0.78), (138.08, 36.04, 137.83, 35.48, &nbsp;750, &nbsp;400, 0.062, 0.84),</p><p>&nbsp; &nbsp; (137.83, 35.48, 137.82, 34.67, &nbsp;400, &nbsp; &nbsp;3, 0.048, 0.86), (138.22, 35.45, 138.18, 35.15, 1100, &nbsp;380, 0.038, 0.78),</p><p>&nbsp; &nbsp; (138.18, 35.15, 138.28, 34.77, &nbsp;380, &nbsp; &nbsp;4, 0.045, 0.84), (138.34, 35.78, 138.54, 35.58, &nbsp;700, &nbsp;240, 0.045, 0.80),</p><p>&nbsp; &nbsp; (138.54, 35.58, 138.64, 35.13, &nbsp;240, &nbsp; &nbsp;3, 0.052, 0.85), (138.34, 35.24, 138.40, 34.94, &nbsp;400, &nbsp; &nbsp;4, 0.038, 0.78),</p><p>&nbsp; &nbsp; (138.92, 34.89, 138.86, 35.09, &nbsp;220, &nbsp; &nbsp;4, 0.038, 0.78), (136.22, 34.56, 136.54, 34.65, &nbsp;320, &nbsp; &nbsp;4, 0.042, 0.78),</p><p>&nbsp; &nbsp; (136.18, 34.43, 136.56, 34.61, &nbsp;450, &nbsp; &nbsp;4, 0.042, 0.80), (136.14, 34.23, 136.72, 34.52, &nbsp;600, &nbsp; &nbsp;4, 0.045, 0.82),</p><p>&nbsp; &nbsp; (135.90, 33.84, 136.01, 33.72, &nbsp;180, &nbsp; &nbsp;3, 0.045, 0.82),</p><p>&nbsp; &nbsp; (136.38, 35.47, 136.22, 35.40, &nbsp;350, &nbsp; 95, 0.035, 0.78), (136.40, 35.09, 136.13, 35.19, &nbsp;450, &nbsp; 95, 0.038, 0.78),</p><p>&nbsp; &nbsp; (136.28, 34.92, 135.94, 35.12, &nbsp;260, &nbsp; 90, 0.042, 0.80), (135.91, 34.98, 135.87, 34.86, &nbsp; 85, &nbsp; 50, 0.030, 0.78),</p><p>]</p><p>&nbsp;</p><p># 各湖沼の周囲が水面と綺麗に噛み合うよう、湖岸周辺の平坦高さを調整</p><p>BASINS_PLAINS = [</p><p>&nbsp; &nbsp; (136.85, 35.14, 0.32, &nbsp;10, 0.96), (137.22, 34.93, 0.20, &nbsp;28, 0.90),</p><p>&nbsp; &nbsp; (137.38, 34.76, 0.16, &nbsp;16, 0.92), (137.76, 34.74, 0.20, &nbsp;10, 0.95),</p><p>&nbsp; &nbsp; (138.34, 34.92, 0.18, &nbsp;16, 0.90), (138.75, 35.14, 0.14, &nbsp;12, 0.90),</p><p>&nbsp; &nbsp; (137.20, 36.69, 0.19, &nbsp;12, 0.95), (136.62, 36.54, 0.17, &nbsp;12, 0.95),</p><p>&nbsp; &nbsp; (136.22, 36.07, 0.15, &nbsp;15, 0.93), (138.57, 35.63, 0.13, 260, 0.92),</p><p>&nbsp; &nbsp; (137.97, 36.24, 0.14, 590, 0.90), (138.19, 36.65, 0.14, 355, 0.90),</p><p>&nbsp; &nbsp; (137.25, 36.14, 0.08, 565, 0.86),</p><p>&nbsp; &nbsp; (136.60, 34.82, 0.18, &nbsp;12, 0.93), (136.72, 34.50, 0.11, &nbsp;10, 0.92),</p><p>&nbsp; &nbsp; (136.13, 34.74, 0.11, 160, 0.88),</p><p>&nbsp; &nbsp; # 湖周囲の盆地高さ</p><p>&nbsp; &nbsp; (136.13, 35.34, 0.18, 102, 0.95), (136.09, 35.18, 0.16, 102, 0.95), (135.94, 35.06, 0.12, 102, 0.94), &nbsp;# 琵琶湖周辺</p><p>&nbsp; &nbsp; (138.084, 36.049, 0.075, 772, 0.94), &nbsp;# 諏訪湖周辺</p><p>&nbsp; &nbsp; (137.590, 34.745, 0.095, &nbsp;14, 0.95), &nbsp;# 浜名湖周辺</p><p>&nbsp; &nbsp; (138.875, 35.415, 0.055, 995, 0.92), &nbsp;# 山中湖周辺</p><p>&nbsp; &nbsp; (138.755, 35.512, 0.055, 845, 0.92), &nbsp;# 河口湖周辺</p><p>&nbsp; &nbsp; (138.610, 35.465, 0.045, 915, 0.92), &nbsp;# 本栖湖周辺</p><p>&nbsp; &nbsp; (138.220, 36.826, 0.040, 670, 0.90), &nbsp;# 野尻湖周辺</p><p>]</p><p>&nbsp;</p><p>def ellipse_poly(lon, lat, rx, ry, n=20):</p><p>&nbsp; &nbsp; ang = np.linspace(0, 2 * np.pi, n, endpoint=False)</p><p>&nbsp; &nbsp; pts = [[round(float(lon + rx * np.cos(a)), 4), round(float(lat + ry * np.sin(a)), 4)] for a in ang]</p><p>&nbsp; &nbsp; pts.append(pts[0])</p><p>&nbsp; &nbsp; return pts</p><p>&nbsp;</p><p># 精密な湖沼ポリゴン（琵琶湖・浜名湖・山中湖・河口湖など）</p><p>BIWAKO_POLYGON = [</p><p>&nbsp; &nbsp; [136.17, 35.51], [136.20, 35.44], [136.26, 35.38], [136.28, 35.32],</p><p>&nbsp; &nbsp; [136.24, 35.27], [136.17, 35.23], [136.09, 35.21], [136.11, 35.17],</p><p>&nbsp; &nbsp; [136.04, 35.14], [135.98, 35.13], [135.95, 35.12], [135.94, 35.08],</p><p>&nbsp; &nbsp; [135.94, 35.03], [135.91, 34.97], [135.87, 35.01], [135.88, 35.07],</p><p>&nbsp; &nbsp; [135.93, 35.12], [135.94, 35.17], [135.98, 35.23], [136.02, 35.28],</p><p>&nbsp; &nbsp; [136.07, 35.32], [136.04, 35.39], [136.07, 35.46], [136.13, 35.49],</p><p>&nbsp; &nbsp; [136.17, 35.51]</p><p>]</p><p>&nbsp;</p><p>HAMANAKO_POLYGON = [</p><p>&nbsp; &nbsp; [137.60, 34.68], [137.62, 34.71], [137.64, 34.76], [137.62, 34.75],</p><p>&nbsp; &nbsp; [137.61, 34.73], [137.59, 34.76], [137.65, 34.80], [137.63, 34.81],</p><p>&nbsp; &nbsp; [137.58, 34.79], [137.54, 34.80], [137.56, 34.77], [137.55, 34.71],</p><p>&nbsp; &nbsp; [137.58, 34.69], [137.60, 34.68]</p><p>]</p><p>&nbsp;</p><p>YAMANAKAKO_POLYGON = [</p><p>&nbsp; &nbsp; [138.85, 35.42], [138.87, 35.43], [138.90, 35.42], [138.91, 35.41],</p><p>&nbsp; &nbsp; [138.89, 35.40], [138.87, 35.41], [138.85, 35.41], [138.85, 35.42]</p><p>]</p><p>&nbsp;</p><p>KAWAGUCHIKO_POLYGON = [</p><p>&nbsp; &nbsp; [138.72, 35.51], [138.74, 35.52], [138.76, 35.515], [138.78, 35.52],</p><p>&nbsp; &nbsp; [138.79, 35.51], [138.77, 35.50], [138.74, 35.505], [138.72, 35.51]</p><p>]</p><p>&nbsp;</p><p>LAKE_POLYGONS = [</p><p>&nbsp; &nbsp; {"name": "琵琶湖", "elevation_m": 85.0, &nbsp;"bed_m": 35.0, &nbsp;"polygon": BIWAKO_POLYGON},</p><p>&nbsp; &nbsp; {"name": "浜名湖", "elevation_m": 2.0, &nbsp; "bed_m": -35.0, "polygon": HAMANAKO_POLYGON},</p><p>&nbsp; &nbsp; {"name": "諏訪湖", "elevation_m": 759.0, "bed_m": 710.0, "polygon": ellipse_poly(138.084, 36.049, 0.030, 0.020)},</p><p>&nbsp; &nbsp; {"name": "山中湖", "elevation_m": 980.0, "bed_m": 930.0, "polygon": YAMANAKAKO_POLYGON},</p><p>&nbsp; &nbsp; {"name": "河口湖", "elevation_m": 830.0, "bed_m": 780.0, "polygon": KAWAGUCHIKO_POLYGON},</p><p>&nbsp; &nbsp; {"name": "本栖湖", "elevation_m": 900.0, "bed_m": 850.0, "polygon": ellipse_poly(138.610, 35.465, 0.018, 0.014)},</p><p>&nbsp; &nbsp; {"name": "野尻湖", "elevation_m": 654.0, "bed_m": 605.0, "polygon": ellipse_poly(138.220, 36.826, 0.018, 0.015)},</p><p>]</p><p><br>&nbsp;</p><p># ==========================================</p><p># 3. 幾何・ノイズ関数</p><p># ==========================================</p><p>def points_in_polygon(X, Y, poly_coords):</p><p>&nbsp; &nbsp; inside = np.zeros(X.shape, dtype=bool)</p><p>&nbsp; &nbsp; n = len(poly_coords)</p><p>&nbsp; &nbsp; for i in range(n):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; j = (i - 1) % n</p><p>&nbsp; &nbsp; &nbsp; &nbsp; xi, yi = poly_coords[i]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; xj, yj = poly_coords[j]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; cond1 = (yi &gt; Y) != (yj &gt; Y)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; denom = (yj - yi) if (yj != yi) else 1e-12</p><p>&nbsp; &nbsp; &nbsp; &nbsp; x_intersect = (xj - xi) * (Y - yi) / denom + xi</p><p>&nbsp; &nbsp; &nbsp; &nbsp; inside ^= (cond1 &amp; (X &lt; x_intersect))</p><p>&nbsp; &nbsp; return inside</p><p><br>&nbsp;</p><p>def dist_and_t_to_segment(X, Y, x1, y1, x2, y2):</p><p>&nbsp; &nbsp; dx, dy = x2 - x1, y2 - y1</p><p>&nbsp; &nbsp; len_sq = dx * dx + dy * dy</p><p>&nbsp; &nbsp; t = ((X - x1) * dx + (Y - y1) * dy) / (len_sq if len_sq &gt; 0 else 1e-12)</p><p>&nbsp; &nbsp; t = np.clip(t, 0.0, 1.0)</p><p>&nbsp; &nbsp; return np.hypot(X - (x1 + t * dx), Y - (y1 + t * dy)), t</p><p><br>&nbsp;</p><p>def value_noise_deriv(X, Y, seed=0.0):</p><p>&nbsp; &nbsp; ix, iy = np.floor(X), np.floor(Y)</p><p>&nbsp; &nbsp; fx, fy = X - ix, Y - iy</p><p>&nbsp; &nbsp; ux = fx * fx * fx * (fx * (fx * 6.0 - 15.0) + 10.0)</p><p>&nbsp; &nbsp; uy = fy * fy * fy * (fy * (fy * 6.0 - 15.0) + 10.0)</p><p>&nbsp; &nbsp; dux = 30.0 * fx * fx * (fx - 1.0) ** 2</p><p>&nbsp; &nbsp; duy = 30.0 * fy * fy * (fy - 1.0) ** 2</p><p>&nbsp;</p><p>&nbsp; &nbsp; def rnd(gx, gy):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; v = np.sin(gx * 127.1 + gy * 311.7 + seed * 74.7) * 43758.5453123</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return v - np.floor(v)</p><p>&nbsp;</p><p>&nbsp; &nbsp; a, b, c, d = rnd(ix, iy), rnd(ix + 1.0, iy), rnd(ix, iy + 1.0), rnd(ix + 1.0, iy + 1.0)</p><p>&nbsp; &nbsp; k0, k1, k2, k3 = a, b - a, c - a, a - b - c + d</p><p>&nbsp; &nbsp; return k0 + k1 * ux + k2 * uy + k3 * ux * uy, (k1 + k3 * uy) * dux, (k2 + k3 * ux) * duy</p><p><br>&nbsp;</p><p>def erosion_fbm(X, Y):</p><p>&nbsp; &nbsp; wx = X + 0.025 * np.sin(Y * 21.0 + 0.4) * np.cos(X * 19.0)</p><p>&nbsp; &nbsp; wy = Y + 0.025 * np.cos(X * 23.0 - 0.2) * np.sin(Y * 20.0)</p><p>&nbsp; &nbsp; px, py = wx * 12.0, wy * 12.0</p><p>&nbsp; &nbsp; total = np.zeros_like(X, dtype=np.float64)</p><p>&nbsp; &nbsp; gx_acc = np.zeros_like(X, dtype=np.float64)</p><p>&nbsp; &nbsp; gy_acc = np.zeros_like(X, dtype=np.float64)</p><p>&nbsp; &nbsp; amp = 0.49</p><p>&nbsp;</p><p>&nbsp; &nbsp; for oct_i, ang in enumerate([0.42, 1.15, 2.08, 0.77, 2.58, 1.49, 0.23]):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ca, sa = np.cos(ang), np.sin(ang)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; rx, ry = px * ca - py * sa, px * sa + py * ca</p><p>&nbsp; &nbsp; &nbsp; &nbsp; n, dx, dy = value_noise_deriv(rx, ry, seed=oct_i * 13.7)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ridge = 1.0 - np.abs(n * 2.0 - 1.0)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; sign = np.where(n * 2.0 - 1.0 &gt;= 0.0, -2.0, 2.0)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; gx_acc += (ca * dx + sa * dy) * sign</p><p>&nbsp; &nbsp; &nbsp; &nbsp; gy_acc += (-sa * dx + ca * dy) * sign</p><p>&nbsp; &nbsp; &nbsp; &nbsp; total += amp * (ridge ** 1.45) / (1.0 + 0.14 * (gx_acc ** 2 + gy_acc ** 2))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; px *= 2.04</p><p>&nbsp; &nbsp; &nbsp; &nbsp; py *= 2.04</p><p>&nbsp; &nbsp; &nbsp; &nbsp; amp *= 0.51</p><p>&nbsp; &nbsp; return total</p><p><br>&nbsp;</p><p># ==========================================</p><p># 4. 並列ワーカー</p><p># ==========================================</p><p>def worker_mask_chunk(task):</p><p>&nbsp; &nbsp; r_start, r_end, lons, chunk_lats = task</p><p>&nbsp; &nbsp; X, Y = np.meshgrid(lons, chunk_lats)</p><p>&nbsp; &nbsp; c_minx, c_maxx = float(lons[0]), float(lons[-1])</p><p>&nbsp; &nbsp; c_miny, c_maxy = float(chunk_lats[-1]), float(chunk_lats[0])</p><p>&nbsp;</p><p>&nbsp; &nbsp; n1, _, _ = value_noise_deriv(X * 40.0, Y * 40.0, seed=5.1)</p><p>&nbsp; &nbsp; n2, _, _ = value_noise_deriv(X * 110.0, Y * 110.0, seed=19.3)</p><p>&nbsp; &nbsp; Xw = X + (n1 - 0.5) * 0.013 + (n2 - 0.5) * 0.004</p><p>&nbsp; &nbsp; Yw = Y + (n2 - 0.5) * 0.013 + (n1 - 0.5) * 0.004</p><p>&nbsp;</p><p>&nbsp; &nbsp; in_region = np.zeros(X.shape, dtype=bool)</p><p>&nbsp; &nbsp; for poly, (bx0, by0, bx1, by1) in zip(TARGET_POLYGONS, POLY_BOUNDS):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if c_maxx &lt; bx0 or c_minx &gt; bx1 or c_maxy &lt; by0 or c_miny &gt; by1:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue</p><p>&nbsp; &nbsp; &nbsp; &nbsp; in_region |= points_in_polygon(Xw, Yw, poly)</p><p>&nbsp;</p><p>&nbsp; &nbsp; other_land = np.zeros(X.shape, dtype=bool)</p><p>&nbsp; &nbsp; for poly in OTHER_LAND_POLYGONS:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; other_land |= points_in_polygon(Xw, Yw, poly)</p><p>&nbsp;</p><p>&nbsp; &nbsp; sea_mask = (~in_region) &amp; (~other_land)</p><p>&nbsp; &nbsp; return r_start, r_end, in_region, sea_mask</p><p><br>&nbsp;</p><p>def worker_base_terrain(task):</p><p>&nbsp; &nbsp; r_start, r_end, lons, chunk_lats, mask_chunk, coast_dist_chunk, coast_scale = task</p><p>&nbsp; &nbsp; X, Y = np.meshgrid(lons, chunk_lats)</p><p>&nbsp;</p><p>&nbsp; &nbsp; elev = np.full(X.shape, 90.0, dtype=np.float64)</p><p>&nbsp; &nbsp; for x1, y1, x2, y2, h, w in RIDGES:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; d, _ = dist_and_t_to_segment(X, Y, x1, y1, x2, y2)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev = np.maximum(elev, h * np.exp(- (d / w) ** 1.75))</p><p>&nbsp;</p><p>&nbsp; &nbsp; for px, py, h, sig, pwr in PEAKS:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; d = np.hypot(X - px, Y - py)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev = np.maximum(elev, h * np.exp(- (d / sig) ** pwr))</p><p>&nbsp;</p><p>&nbsp; &nbsp; d_fuji = np.hypot(X - 138.727, Y - 35.361)</p><p>&nbsp; &nbsp; fuji_h = 3820.0 * np.exp(- (d_fuji / 0.145) ** 1.25) - 230.0 * np.exp(- (d_fuji / 0.0065) ** 2.0)</p><p>&nbsp; &nbsp; elev = np.maximum(elev, fuji_h)</p><p>&nbsp;</p><p>&nbsp; &nbsp; for px, py, th, rad, strength in PASSES:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; d = np.hypot(X - px, Y - py)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; w = strength * np.exp(- (d / rad) ** 2.0)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev = np.where(elev &gt; th, elev * (1.0 - w) + th * w, elev)</p><p>&nbsp;</p><p>&nbsp; &nbsp; for bx, by, rad, target_h, strength in BASINS_PLAINS:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; d = np.hypot(X - bx, Y - by)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; w = strength * np.exp(- (d / rad) ** 2.3)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev = elev * (1.0 - w) + target_h * w</p><p>&nbsp;</p><p>&nbsp; &nbsp; for x1, y1, x2, y2, bh1, bh2, r_width, strength in RIVERS:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; d, t = dist_and_t_to_segment(X, Y, x1, y1, x2, y2)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; bed_h = bh1 * (1.0 - t) + bh2 * t</p><p>&nbsp; &nbsp; &nbsp; &nbsp; cw = strength * np.exp(- (d / r_width) ** 1.50)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev = np.where(elev &gt; bed_h, elev * (1.0 - cw) + bed_h * cw, elev)</p><p>&nbsp;</p><p>&nbsp; &nbsp; erode = erosion_fbm(X, Y)</p><p>&nbsp; &nbsp; detail_amp = np.clip(elev * 0.30, 4.0, 480.0)</p><p>&nbsp; &nbsp; fuji_smooth = 1.0 - 0.70 * np.exp(- (d_fuji / 0.08) ** 2.0)</p><p>&nbsp; &nbsp; elev = elev + (erode - 0.36) * detail_amp * fuji_smooth</p><p>&nbsp;</p><p>&nbsp; &nbsp; taper = np.clip(coast_dist_chunk / coast_scale, 0.05, 1.0) ** 0.72</p><p>&nbsp; &nbsp; elev = elev * taper</p><p>&nbsp; &nbsp; elev = np.where(mask_chunk, np.clip(elev, 1.0, 3776.0), 0.0).astype(np.float32)</p><p>&nbsp; &nbsp; return r_start, r_end, elev</p><p><br>&nbsp;</p><p>def worker_hydraulic_erosion(task):</p><p>&nbsp; &nbsp; elev_norm, valid_coords, num_droplets, seed = task</p><p>&nbsp; &nbsp; H, W = elev_norm.shape</p><p>&nbsp; &nbsp; rng = np.random.default_rng(seed)</p><p>&nbsp;</p><p>&nbsp; &nbsp; delta = np.zeros_like(elev_norm, dtype=np.float32)</p><p>&nbsp; &nbsp; batch_size = 8_000</p><p>&nbsp; &nbsp; num_batches = max(1, (num_droplets + batch_size - 1) // batch_size)</p><p>&nbsp; &nbsp; n_valid = len(valid_coords[0])</p><p>&nbsp;</p><p>&nbsp; &nbsp; inertia, min_slope, capacity_factor = 0.20, 0.002, 3.2</p><p>&nbsp; &nbsp; erode_speed, deposit_speed, gravity, evaporate, max_steps = 0.18, 0.14, 4.0, 0.035, 55</p><p>&nbsp;</p><p>&nbsp; &nbsp; for _ in range(num_batches):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; picks = rng.integers(0, n_valid, size=batch_size)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; py = valid_coords[0][picks].astype(np.float32) + rng.uniform(0.0, 1.0, batch_size).astype(np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; px = valid_coords[1][picks].astype(np.float32) + rng.uniform(0.0, 1.0, batch_size).astype(np.float32)</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; dir_x = np.zeros(batch_size, dtype=np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; dir_y = np.zeros(batch_size, dtype=np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; speed = np.ones(batch_size, dtype=np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; water = np.ones(batch_size, dtype=np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; sediment = np.zeros(batch_size, dtype=np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; active = (px &gt;= 1.0) &amp; (px &lt; W - 2.0) &amp; (py &gt;= 1.0) &amp; (py &lt; H - 2.0)</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for _ in range(max_steps):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not np.any(active):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; idx = np.where(active)[0]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cx, cy = px[idx], py[idx]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ix, iy = cx.astype(np.int32), cy.astype(np.int32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fx, fy = cx - ix, cy - iy</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h00, h10 = elev_norm[iy, ix], elev_norm[iy, ix + 1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h01, h11 = elev_norm[iy + 1, ix], elev_norm[iy + 1, ix + 1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h_old = (h00 * (1 - fx) + h10 * fx) * (1 - fy) + (h01 * (1 - fx) + h11 * fx) * fy</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gx = (h10 - h00) * (1 - fy) + (h11 - h01) * fy</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gy = (h01 - h00) * (1 - fx) + (h11 - h10) * fx</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dx_new = dir_x[idx] * inertia - gx * (1.0 - inertia)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dy_new = dir_y[idx] * inertia - gy * (1.0 - inertia)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; norm = np.hypot(dx_new, dy_new)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; zero_mask = norm &lt; 1e-6</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if np.any(zero_mask):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ang = rng.uniform(0.0, 2.0 * np.pi, size=int(np.sum(zero_mask))).astype(np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dx_new[zero_mask], dy_new[zero_mask], norm[zero_mask] = np.cos(ang), np.sin(ang), 1.0</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dx_new /= norm</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dy_new /= norm</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nx, ny = cx + dx_new, cy + dy_new</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; in_bounds = (nx &gt;= 1.0) &amp; (nx &lt; W - 2.0) &amp; (ny &gt;= 1.0) &amp; (ny &lt; H - 2.0)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; active[idx[~in_bounds]] = False</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not np.any(in_bounds):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub = idx[in_bounds]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nx_b, ny_b = nx[in_bounds], ny[in_bounds]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nix, niy = nx_b.astype(np.int32), ny_b.astype(np.int32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nfx, nfy = nx_b - nix, ny_b - niy</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h_new = (</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (elev_norm[niy, nix] * (1 - nfx) + elev_norm[niy, nix + 1] * nfx) * (1 - nfy) +</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (elev_norm[niy + 1, nix] * (1 - nfx) + elev_norm[niy + 1, nix + 1] * nfx) * nfy</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dh = h_new - h_old[in_bounds]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; capacity = np.maximum(-dh, min_slope) * speed[sub] * water[sub] * capacity_factor</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is_deposit = (sediment[sub] &gt; capacity) | (dh &gt; 0.0)</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; amount_dep = np.where(dh &gt; 0.0, np.minimum(dh * 0.25, sediment[sub] * 0.25), (sediment[sub] - capacity) * deposit_speed)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; amount_ero = np.minimum((capacity - sediment[sub]) * erode_speed, np.maximum(-dh, 0.0))</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ox, oy = ix[in_bounds], iy[in_bounds]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ofx, ofy = fx[in_bounds], fy[in_bounds]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; change = np.where(is_deposit, amount_dep, -amount_ero)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sediment[sub] = np.where(is_deposit, sediment[sub] - amount_dep, sediment[sub] + amount_ero)</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; np.add.at(delta, (oy, ox), change * (1 - ofx) * (1 - ofy))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; np.add.at(delta, (oy, ox + 1), change * ofx * (1 - ofy))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; np.add.at(delta, (oy + 1, ox), change * (1 - ofx) * ofy)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; np.add.at(delta, (oy + 1, ox + 1), change * ofx * ofy)</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; px[sub], py[sub] = nx_b, ny_b</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dir_x[sub], dir_y[sub] = dx_new[in_bounds], dy_new[in_bounds]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speed[sub] = np.sqrt(np.maximum(speed[sub] ** 2 + (-dh) * gravity, 0.05))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; water[sub] *= (1.0 - evaporate)</p><p>&nbsp;</p><p>&nbsp; &nbsp; return delta</p><p><br>&nbsp;</p><p># ==========================================</p><p># 5. メイン処理</p><p># ==========================================</p><p>def main():</p><p>&nbsp; &nbsp; t0 = time.perf_counter()</p><p>&nbsp; &nbsp; lons = np.arange(LON_MIN, LON_MAX + GRID_RES_DEG * 0.5, GRID_RES_DEG, dtype=np.float64)</p><p>&nbsp; &nbsp; lats = np.arange(LAT_MAX, LAT_MIN - GRID_RES_DEG * 0.5, -GRID_RES_DEG, dtype=np.float64)</p><p>&nbsp; &nbsp; H, W = len(lats), len(lons)</p><p>&nbsp;</p><p>&nbsp; &nbsp; print(f"使用CPUコア数: {MAX_CPU_CORES} / メッシュ: {H} x {W} = {H * W:,} 点")</p><p>&nbsp; &nbsp; num_chunks = MAX_CPU_CORES * 4</p><p>&nbsp; &nbsp; row_indices = np.array_split(np.arange(H), num_chunks)</p><p>&nbsp;</p><p>&nbsp; &nbsp; full_mask = np.zeros((H, W), dtype=bool)</p><p>&nbsp; &nbsp; sea_mask = np.zeros((H, W), dtype=bool)</p><p>&nbsp;</p><p>&nbsp; &nbsp; print("Pass 1/4: 領域＆詳細海岸線(10県)を全コア並列計算中...")</p><p>&nbsp; &nbsp; tasks_p1 = [(int(idx[0]), int(idx[-1]) + 1, lons, lats[idx]) for idx in row_indices if len(idx) &gt; 0]</p><p>&nbsp; &nbsp; with ProcessPoolExecutor(max_workers=MAX_CPU_CORES) as pool:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for r_s, r_e, m_c, s_c in pool.map(worker_mask_chunk, tasks_p1):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; full_mask[r_s:r_e, :] = m_c</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sea_mask[r_s:r_e, :] = s_c</p><p>&nbsp;</p><p>&nbsp; &nbsp; print("Pass 2/4: 海岸線距離マップを計算中...")</p><p>&nbsp; &nbsp; coast_steps = max(15, int(round(0.045 / GRID_RES_DEG)))</p><p>&nbsp; &nbsp; coast_scale = coast_steps * 0.5</p><p>&nbsp; &nbsp; coast_dist = np.where(sea_mask, 0.0, coast_steps * 2.0).astype(np.float32)</p><p>&nbsp; &nbsp; for _ in range(coast_steps):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; nbr = np.minimum(</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; np.minimum(coast_dist[:-2, 1:-1], coast_dist[2:, 1:-1]),</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; np.minimum(coast_dist[1:-1, :-2], coast_dist[1:-1, 2:])</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ) + 1.0</p><p>&nbsp; &nbsp; &nbsp; &nbsp; coast_dist[1:-1, 1:-1] = np.minimum(coast_dist[1:-1, 1:-1], nbr)</p><p>&nbsp;</p><p>&nbsp; &nbsp; print("Pass 3/4: ベース山脈・峠・河川を全コア並列計算中...")</p><p>&nbsp; &nbsp; elev_work = np.zeros((H, W), dtype=np.float32)</p><p>&nbsp; &nbsp; tasks_p3 = [</p><p>&nbsp; &nbsp; &nbsp; &nbsp; (int(idx[0]), int(idx[-1]) + 1, lons, lats[idx],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;full_mask[int(idx[0]):int(idx[-1]) + 1, :],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;coast_dist[int(idx[0]):int(idx[-1]) + 1, :], coast_scale)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for idx in row_indices if len(idx) &gt; 0</p><p>&nbsp; &nbsp; ]</p><p>&nbsp; &nbsp; with ProcessPoolExecutor(max_workers=MAX_CPU_CORES) as pool:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for r_s, r_e, e_c in pool.map(worker_base_terrain, tasks_p3):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elev_work[r_s:r_e, :] = e_c</p><p>&nbsp;</p><p>&nbsp; &nbsp; print(f"Pass 4/4: 水理侵食（全{EROSION_ROUNDS * DROPLETS_PER_ROUND:,}滴）を全コア並列計算中...")</p><p>&nbsp; &nbsp; elev_norm = (elev_work / 3776.0).astype(np.float32)</p><p>&nbsp; &nbsp; valid_coords = np.where(full_mask)</p><p>&nbsp; &nbsp; droplets_per_core = max(12_000, DROPLETS_PER_ROUND // MAX_CPU_CORES)</p><p>&nbsp;</p><p>&nbsp; &nbsp; for rnd_i in range(EROSION_ROUNDS):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; tasks_p4 = [</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (elev_norm, valid_coords, droplets_per_core, 2000 + rnd_i * 100 + c_i)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for c_i in range(MAX_CPU_CORES)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; total_delta = np.zeros_like(elev_norm, dtype=np.float32)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; with ProcessPoolExecutor(max_workers=MAX_CPU_CORES) as pool:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; futures = [pool.submit(worker_hydraulic_erosion, t) for t in tasks_p4]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for fut in as_completed(futures):</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total_delta += fut.result()</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; d = np.clip(total_delta, -0.015, 0.008)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; d_smooth = d.copy()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; d_smooth[1:-1, 1:-1] = (</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.40 * d[1:-1, 1:-1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 0.10 * (d[:-2, 1:-1] + d[2:, 1:-1] + d[1:-1, :-2] + d[1:-1, 2:])</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 0.05 * (d[:-2, :-2] + d[:-2, 2:] + d[2:, :-2] + d[2:, 2:])</p><p>&nbsp; &nbsp; &nbsp; &nbsp; )</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev_norm = np.where(full_mask, np.clip(elev_norm + d_smooth, 0.0, 1.0), 0.0)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; print(f" &nbsp;-&gt; ラウンド {rnd_i + 1}/{EROSION_ROUNDS} 完了")</p><p>&nbsp;</p><p>&nbsp; &nbsp; elev_final = (elev_norm * 3776.0).astype(np.float32)</p><p>&nbsp; &nbsp; nbr_max = np.maximum.reduce([</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev_final[:-2, :-2], elev_final[:-2, 1:-1], elev_final[:-2, 2:],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev_final[1:-1, :-2], &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elev_final[1:-1, 2:],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; elev_final[2:, :-2], &nbsp;elev_final[2:, 1:-1], &nbsp;elev_final[2:, 2:]</p><p>&nbsp; &nbsp; ])</p><p>&nbsp; &nbsp; spike_mask = elev_final[1:-1, 1:-1] &gt; (nbr_max + 110.0)</p><p>&nbsp; &nbsp; elev_final[1:-1, 1:-1] = np.where(spike_mask, nbr_max + 25.0, elev_final[1:-1, 1:-1])</p><p>&nbsp;</p><p>&nbsp; &nbsp; # 湖底を水面より45〜50m深く設定して、斜め補間で湖面が隠れないようにする</p><p>&nbsp; &nbsp; X_all, Y_all = np.meshgrid(lons, lats)</p><p>&nbsp; &nbsp; for lk in LAKE_POLYGONS:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; arr = np.array(lk["polygon"])</p><p>&nbsp; &nbsp; &nbsp; &nbsp; bx0, by0, bx1, by1 = arr[:, 0].min(), arr[:, 1].min(), arr[:, 0].max(), arr[:, 1].max()</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ix = np.where((lons &gt;= bx0) &amp; (lons &lt;= bx1))[0]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; iy = np.where((lats &gt;= by0) &amp; (lats &lt;= by1))[0]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if len(ix) &gt; 0 and len(iy) &gt; 0:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub_X = X_all[iy[0]:iy[-1]+1, ix[0]:ix[-1]+1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub_Y = Y_all[iy[0]:iy[-1]+1, ix[0]:ix[-1]+1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; l_mask = points_in_polygon(sub_X, sub_Y, lk["polygon"])</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sub_m = full_mask[iy[0]:iy[-1]+1, ix[0]:ix[-1]+1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elev_final[iy[0]:iy[-1]+1, ix[0]:ix[-1]+1] = np.where(</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; l_mask &amp; sub_m, lk["bed_m"], elev_final[iy[0]:iy[-1]+1, ix[0]:ix[-1]+1]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )</p><p>&nbsp;</p><p>&nbsp; &nbsp; elev_final = np.where(full_mask, np.clip(elev_final, -40.0, 3776.0), np.nan)</p><p>&nbsp;</p><p>&nbsp; &nbsp; print("JSONファイルへ書き出し中...")</p><p>&nbsp; &nbsp; elev_list = [</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [None if np.isnan(v) else round(float(v), 1) for v in row]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for row in elev_final</p><p>&nbsp; &nbsp; ]</p><p>&nbsp;</p><p>&nbsp; &nbsp; output_data = {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "metadata": {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "description": "Hi-Res Offline 3D Terrain (10 Prefectures + Accurate Lakes)",</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "grid_res_deg": GRID_RES_DEG,</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "shape": [H, W]</p><p>&nbsp; &nbsp; &nbsp; &nbsp; },</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "lons": [round(float(x), 5) for x in lons],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "lats": [round(float(y), 5) for y in lats],</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "elevations_m": elev_list,</p><p>&nbsp; &nbsp; &nbsp; &nbsp; "lake_polygons": LAKE_POLYGONS</p><p>&nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; with open(OUTPUT_JSON_PATH, "w", encoding="utf-8") as f:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; json.dump(output_data, f, ensure_ascii=False)</p><p>&nbsp;</p><p>&nbsp; &nbsp; elapsed = time.perf_counter() - t0</p><p>&nbsp; &nbsp; size_mb = Path(OUTPUT_JSON_PATH).stat().st_size / (1024 * 1024)</p><p>&nbsp; &nbsp; print(f"完了！ -&gt; {OUTPUT_JSON_PATH} ({size_mb:.2f} MB, 処理時間: {elapsed:.2f} 秒)")</p><p><br>&nbsp;</p><p>if __name__ == "__main__":</p><p>&nbsp; &nbsp; main()</p>
]]>
</description>
<link>https://ameblo.jp/jmohui/entry-12985394657.html</link>
<pubDate>Mon, 23 Nov 2026 13:32:58 +0900</pubDate>
</item>
</channel>
</rss>
