@@ -16,7 +16,6 @@ const PARTICLES_CONFIG = {
1616 l4 : [ { name : '調' , type : 'flow' , color : 0x88DDAA } , { name : '変' , type : 'drive' , color : 0xAAFF88 } , { name : '静' , type : 'freeze' , color : 0x88AADD } ] ,
1717 l5 : [ { name : '観' , type : 'flow' , color : 0xCCCCFF } , { name : '響' , type : 'drive' , color : 0xFFCCCC } , { name : '隔' , type : 'freeze' , color : 0xCCFFCC } ]
1818} ;
19-
2019// ===== 層構造定義 =====
2120const LAYERS = [
2221 { index : 0 , name : '核層' , radius : 8 , color : 0xFFFFAA , opacity : 0.25 } ,
@@ -26,10 +25,9 @@ const LAYERS = [
2625 { index : 4 , name : '外部接合層' , radius : 40 , color : 0x88DDAA , opacity : 0.15 } ,
2726 { index : 5 , name : '外部雰囲気層' , radius : 50 , color : 0xCCCCFF , opacity : 0.12 }
2827] ;
29-
3028// ===== Global variables =====
3129let scene , camera , renderer ;
32- let particles = [ ] , weather , externalAuraCloud ;
30+ let particles = [ ] , weather , externalAuraCloud , coherenceLinkManager ;
3331
3432const globalParams = {
3533 // Physics parameters
@@ -50,9 +48,11 @@ const globalParams = {
5048 pi_n_average : 0 ,
5149 maxInfluenceIndex : 0 , // E-1: K_EM計算用に最大影響度指数を格納
5250 avg_temp_by_layer : [ ] , // 層ごとの平均温度を格納
53- avg_stress_by_layer : [ ] // 層ごとの平均ストレスを格納
51+ avg_stress_by_layer : [ ] , // 層ごとの平均ストレスを格納
52+ avg_phase_diff_L0_L1 : 0 , // ⚛️ L0-L1間の平均位相差
53+ josephsonEnergy_EJ : 1.0 , // ⚛️ ジョセフソン結合エネルギー (動的に更新)
54+ coherenceThreshold : 0.5 // ⚛️ 位相線を描画する位相差の閾値
5455} ;
55-
5656// U-1: Timeline-related global variables
5757let timelineData = null ;
5858let simulationStartTime = 0 ;
@@ -61,7 +61,6 @@ let nextKeyframeIndex = 0;
6161let wpm = 400 ; // Words Per Minute
6262
6363let lastTime = Date . now ( ) ;
64-
6564function init ( ) {
6665 scene = new THREE . Scene ( ) ;
6766 scene . background = new THREE . Color ( 0x050510 ) ;
@@ -74,18 +73,17 @@ function init() {
7473 renderer . setSize ( window . innerWidth , window . innerHeight ) ;
7574 renderer . shadowMap . enabled = true ;
7675 document . getElementById ( 'container' ) . appendChild ( renderer . domElement ) ;
77-
7876 drawLayerBoundaries ( ) ;
7977 weather = new AuraWeather ( scene ) ;
8078 externalAuraCloud = new ExternalAuraCloud ( scene ) ; // Add this line
79+ coherenceLinkManager = new CoherenceLinkManager ( scene ) ; // ⚛️ 位相線マネージャーを初期化
8180 createParticles ( ) ;
8281
8382 const ambientLight = new THREE . AmbientLight ( 0x333355 , 0.5 ) ;
8483 scene . add ( ambientLight ) ;
8584 const dirLight = new THREE . DirectionalLight ( 0xFFFFFF , 0.3 ) ;
8685 dirLight . position . set ( 10 , 20 , 10 ) ;
8786 scene . add ( dirLight ) ;
88-
8987 setupMouseControls ( ) ;
9088 setupUIToggle ( ) ;
9189 setupEmotionControls ( ) ;
@@ -98,10 +96,8 @@ function init() {
9896 camera . updateProjectionMatrix ( ) ;
9997 renderer . setSize ( window . innerWidth , window . innerHeight ) ;
10098 } ) ;
101-
10299 animate ( ) ;
103100}
104-
105101function drawLayerBoundaries ( ) {
106102 LAYERS . forEach ( layer => {
107103 const geom = new THREE . SphereGeometry ( layer . radius , 32 , 32 ) ;
@@ -112,7 +108,6 @@ function drawLayerBoundaries() {
112108 scene . add ( new THREE . Mesh ( wireGeom , wireMat ) ) ;
113109 } ) ;
114110}
115-
116111function createParticles ( ) {
117112 Object . keys ( PARTICLES_CONFIG ) . forEach ( ( layerKey , idx ) => {
118113 const outerRadius = LAYERS [ idx ] . radius ;
@@ -128,12 +123,21 @@ function createParticles() {
128123 particles . push ( new Particle ( config , idx , initialRadius , baseRadius , scene ) ) ;
129124 } ) ;
130125 } ) ;
131-
132126 // 19番目の粒子「光体」を生成し、配列の先頭に追加
133127 const coreParticle = new CoreParticle ( scene ) ;
134128 particles . unshift ( coreParticle ) ;
135- }
136129
130+ // ⚛️ ジョセフソン効果導入準備: π₃ を使って位相を初期化
131+ // 最初のDDD計算を実行して、pi_n_by_layerを初期化する
132+ updateGlobalDDD ( particles , globalParams ) ;
133+ particles . forEach ( p => {
134+ // ⚛️ 各層のπ_nを使って位相を初期化する
135+ if ( p . initCoherencePhase ) {
136+ const pi_n_for_layer = globalParams . pi_n_by_layer [ p . layer ] || Math . PI ;
137+ p . initCoherencePhase ( pi_n_for_layer ) ;
138+ }
139+ } ) ;
140+ }
137141function setupMouseControls ( ) {
138142 let isDragging = false ;
139143 renderer . domElement . addEventListener ( 'mousedown' , ( e ) => { if ( e . target === renderer . domElement ) isDragging = true ; } ) ;
@@ -152,7 +156,6 @@ function setupMouseControls() {
152156 camera . position . z = Math . max ( 30 , Math . min ( 150 , camera . position . z + e . deltaY * 0.05 ) ) ;
153157 } ) ;
154158}
155-
156159function setupUIToggle ( ) {
157160 const footer = document . getElementById ( 'fixed-footer' ) , button = document . getElementById ( 'toggle-button' ) , icon = document . getElementById ( 'toggle-icon' ) ;
158161 button . addEventListener ( 'click' , ( ) => {
@@ -161,7 +164,6 @@ function setupUIToggle() {
161164 button . setAttribute ( 'aria-expanded' , String ( ! isCollapsed ) ) ;
162165 } ) ;
163166}
164-
165167function setupDebugToggle ( ) {
166168 const button = document . getElementById ( 'toggle-debug-button' ) ;
167169 const container = document . getElementById ( 'debug-stats-container' ) ;
@@ -171,7 +173,6 @@ function setupDebugToggle() {
171173 button . textContent = isHidden ? 'デバッグ非表示' : 'デバッグ表示' ;
172174 } ) ;
173175}
174-
175176function setupWpmSlider ( ) {
176177 const slider = document . getElementById ( 'wpm-slider' ) ;
177178 const valueDisplay = document . getElementById ( 'wpm-value' ) ;
@@ -180,7 +181,6 @@ function setupWpmSlider() {
180181 valueDisplay . textContent = wpm ;
181182 } ) ;
182183}
183-
184184function setupEmotionControls ( ) {
185185 document . querySelectorAll ( '.emotion-button' ) . forEach ( button => {
186186 button . addEventListener ( 'click' , ( ) => {
@@ -214,7 +214,6 @@ function setupEmotionControls() {
214214 } ) ;
215215 } ) ;
216216}
217-
218217function setupToonInput ( ) {
219218 document . getElementById ( 'apply-prompt-button' ) . addEventListener ( 'click' , ( ) => {
220219 const toonString = document . getElementById ( 'json-input-area' ) . value , statusElement = document . getElementById ( 'input-status-message' ) ;
@@ -228,7 +227,6 @@ function setupToonInput() {
228227 }
229228 } ) ;
230229}
231-
232230function parseToonInput ( toonString ) {
233231 // U-1: Advanced TOON Parser
234232 if ( ! toonString || toonString . trim ( ) === "" ) throw new Error ( "TOON入力が空です。" ) ;
@@ -324,7 +322,6 @@ function parseToonInput(toonString) {
324322 if ( ! result . metadata || ! Array . isArray ( result . metadata ) ) throw new Error ( "TOON形式にはトップレベルの`metadata`配列が必要です。" ) ;
325323 return result ;
326324}
327-
328325function resetSimulation ( params ) {
329326 // U-1: Reset timeline state
330327 timelineData = null ;
@@ -359,7 +356,6 @@ function resetSimulation(params) {
359356 document . querySelector ( '#calm' ) . click ( ) ;
360357 }
361358}
362-
363359function animate ( ) {
364360 requestAnimationFrame ( animate ) ;
365361 // この更新はループの先頭で必ず行う
@@ -462,6 +458,42 @@ function animate() {
462458 globalParams . avg_temp_by_layer = avgTemps ;
463459 globalParams . avg_stress_by_layer = avgStresses ;
464460
461+ // ⚛️ ジョセフソンエネルギー E_J の動的計算
462+ // L0層の平均質量と平均ストレスから「意志の強さ」をモデル化する
463+ const l0ParticlesForEJ = particles . filter ( p => p . layer === 0 && ! ( p instanceof CoreParticle ) ) ;
464+ if ( l0ParticlesForEJ . length > 0 ) {
465+ const avg_massEff_L0 = l0ParticlesForEJ . reduce ( ( sum , p ) => sum + p . massEff , 0 ) / l0ParticlesForEJ . length ;
466+ const avg_stress_L0 = globalParams . avg_stress_by_layer [ 0 ] || 0 ;
467+
468+ const E_J_base = 0.5 ; // 基本エネルギー
469+ const k_m = 1.0 ; // 質量係数
470+ const k_s = 1.5 ; // ストレス係数
471+
472+ // E_J = E_J_base * (1 + k_m * avg_massEff) * (1 + k_s * avg_stress)
473+ const dynamic_EJ = E_J_base * ( 1 + k_m * avg_massEff_L0 ) * ( 1 + k_s * avg_stress_L0 ) ;
474+
475+ globalParams . josephsonEnergy_EJ = Math . max ( 0.1 , Math . min ( dynamic_EJ , 10.0 ) ) ; // 値が発散しないように制限
476+ }
477+
478+ // ⚛️ L0-L1間の平均位相差を計算
479+ const l0Particles = particles . filter ( p => p . layer === 0 ) ;
480+ const l1Particles = particles . filter ( p => p . layer === 1 ) ;
481+ if ( l0Particles . length > 0 && l1Particles . length > 0 ) {
482+ let totalPhaseDiff = 0 ;
483+ let pairCount = 0 ;
484+ for ( const p0 of l0Particles ) {
485+ for ( const p1 of l1Particles ) {
486+ totalPhaseDiff += Math . abs ( p0 . coherencePhase - p1 . coherencePhase ) ;
487+ pairCount ++ ;
488+ }
489+ }
490+ globalParams . avg_phase_diff_L0_L1 = totalPhaseDiff / pairCount ;
491+ }
492+
493+ // ⚛️ 量子位相線の更新
494+ const l0ParticlesForLink = particles . filter ( p => p . layer === 0 ) ;
495+ coherenceLinkManager . update ( l0ParticlesForLink , l1Particles , globalParams . coherenceThreshold ) ;
496+
465497 updateGlobalDDD ( particles , globalParams ) ;
466498
467499 // 光体(particles[0])は他の粒子に影響を与えるため、最初に更新
@@ -533,13 +565,13 @@ function animate() {
533565 document . getElementById ( 'magnetic-mass' ) . textContent = coreParticle . massEff . toFixed ( 3 ) ;
534566 }
535567
568+ document . getElementById ( 'josephson-energy' ) . textContent = ( globalParams . josephsonEnergy_EJ || 0 ) . toFixed ( 3 ) ;
536569 document . getElementById ( 'system-potential' ) . textContent = ( globalParams . systemPotential_Sn_total || 0 ) . toFixed ( 3 ) ;
537570
538571 updateUI ( ) ;
539572 camera . lookAt ( 0 , 0 , 0 ) ;
540573 renderer . render ( scene , camera ) ;
541574}
542-
543575function updateUI ( ) {
544576 const { pi_n_by_layer, rho_n_by_layer, Gamma_n_by_layer, systemPotential_Sn_total, season, internalAuraWeather, pi_n_average, dominantEmotion, brainwaveState } = globalParams ;
545577
@@ -551,6 +583,7 @@ function updateUI() {
551583 document . getElementById ( 'avg-pi-n' ) . textContent = ( globalParams . pi_n_average || 0 ) . toFixed ( 4 ) ;
552584 document . getElementById ( 'dominant-emotion' ) . textContent = dominantEmotion ;
553585 document . getElementById ( 'brainwave-state' ) . textContent = brainwaveState ;
586+ document . getElementById ( 'avg-phase-diff' ) . textContent = ( globalParams . avg_phase_diff_L0_L1 || 0 ) . toFixed ( 3 ) ;
554587
555588 // Determine display weather from display params
556589 let displayAuraWeather ;
0 commit comments