11document . addEventListener ( 'DOMContentLoaded' , function ( ) {
2- // Stress Simulation Script
2+ // Stress Simulation Script (unchanged)
33 let stressLevel = 30 ;
44 let simulationInterval ;
55 const maxStress = 100 ;
@@ -53,82 +53,93 @@ document.addEventListener('DOMContentLoaded', function () {
5353 updateStressDisplay ( ) ;
5454
5555 // --- 3D Scene Script using Three.js ---
56-
57- // Initial Setup
56+
57+ // Scene Setup
5858 const scene = new THREE . Scene ( ) ;
59+
60+ // Camera Fix: Adjust near plane and position
5961 const camera = new THREE . PerspectiveCamera (
60- 75 , window . innerWidth / window . innerHeight , 0.1 , 1000
62+ 75 ,
63+ window . innerWidth / window . innerHeight ,
64+ 0.01 , // Changed from 0.1 to 0.01
65+ 1000
6166 ) ;
62- const renderer = new THREE . WebGLRenderer ( { antialias : true } ) ;
63-
64- // Renderer configuration
67+ camera . position . set ( 0 , 0 , 0.001 ) ; // Position closer to center
68+
69+ // Renderer Fix: Add alpha channel for debugging
70+ const renderer = new THREE . WebGLRenderer ( {
71+ antialias : true ,
72+ alpha : true // Enable transparency
73+ } ) ;
74+ renderer . setClearColor ( 0x000000 , 0 ) ; // Transparent background
6575 renderer . setSize ( window . innerWidth , window . innerHeight ) ;
6676 renderer . setPixelRatio ( window . devicePixelRatio ) ;
6777 document . body . appendChild ( renderer . domElement ) ;
68-
69- // 360° Sphere Setup
70- const geometry = new THREE . SphereGeometry ( 500 , 60 , 40 ) ;
78+
79+ // Geometry Fix: Reduce complexity for better performance
80+ const geometry = new THREE . SphereGeometry ( 500 , 32 , 16 ) ; // Reduced segments
7181 geometry . scale ( - 1 , 1 , 1 ) ; // Flip normals inward
72-
73- // Texture loading with error handling
82+
83+ // Texture Loading Fix: Add success logging and force update
7484 const textureLoader = new THREE . TextureLoader ( ) ;
7585 textureLoader . load (
7686 'img/er.png' ,
7787 ( texture ) => {
88+ console . log ( 'Texture loaded successfully' ) ;
7889 const material = new THREE . MeshBasicMaterial ( {
7990 map : texture ,
80- side : THREE . BackSide // Critical fix for proper sphere rendering
91+ side : THREE . BackSide ,
92+ transparent : true
8193 } ) ;
8294 const sphere = new THREE . Mesh ( geometry , material ) ;
8395 scene . add ( sphere ) ;
96+ needsUpdate = true ; // Force render after load
8497 } ,
85- undefined , // Progress callback (optional)
98+ undefined ,
8699 ( err ) => {
87- console . error ( 'Error loading texture :' , err ) ;
88- // Fallback material if texture fails to load
100+ console . error ( 'Texture error :' , err ) ;
101+ // Visible fallback material
89102 const material = new THREE . MeshBasicMaterial ( {
90- color : 0x444444 ,
103+ color : 0xFF0000 , // Bright red for visibility
91104 side : THREE . BackSide
92105 } ) ;
93106 scene . add ( new THREE . Mesh ( geometry , material ) ) ;
107+ needsUpdate = true ;
94108 }
95109 ) ;
96-
97- // Camera position
98- camera . position . set ( 0 , 0 , 0.1 ) ;
99-
100- // VR Configuration
101- renderer . xr . enabled = true ;
102- renderer . xr . setReferenceSpaceType ( 'local' ) ;
103- document . body . appendChild ( VRButton . createButton ( renderer ) ) ;
104-
110+
111+ // Debug Helpers: Add axes visualization
112+ scene . add ( new THREE . AxesHelper ( 50 ) ) ; // Red=X, Green=Y, Blue=Z
113+
114+ // VR Configuration (Temporarily Disabled)
115+ // renderer.xr.enabled = true;
116+ // renderer.xr.setReferenceSpaceType('local');
117+ // document.body.appendChild(VRButton.createButton(renderer));
118+
105119 // Controls (Mouse/Touch)
106120 const controls = new THREE . OrbitControls ( camera , renderer . domElement ) ;
107121 controls . enableZoom = false ;
108122 controls . enablePan = false ;
109123 controls . enableDamping = true ;
110124 controls . rotateSpeed = - 0.25 ;
111-
125+
112126 // Window resize handler
113127 window . addEventListener ( 'resize' , ( ) => {
114128 camera . aspect = window . innerWidth / window . innerHeight ;
115129 camera . updateProjectionMatrix ( ) ;
116130 renderer . setSize ( window . innerWidth , window . innerHeight ) ;
117131 } ) ;
118-
119- // Optimized animation loop
132+
133+ // Animation Loop Fix: Ensure continuous updates
120134 let needsUpdate = true ;
121135 renderer . setAnimationLoop ( ( ) => {
122- if ( needsUpdate || controls . isRotating ) {
123- controls . update ( ) ;
124- renderer . render ( scene , camera ) ;
125- needsUpdate = false ;
126- }
136+ controls . update ( ) ;
137+ renderer . render ( scene , camera ) ;
127138 } ) ;
128139
129140 // Cleanup on page unload
130141 window . addEventListener ( 'beforeunload' , ( ) => {
131142 clearInterval ( simulationInterval ) ;
132143 renderer . dispose ( ) ;
133144 } ) ;
134- } ) ;
145+ } ) ;
0 commit comments