<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>太阳系二向箔攻击模拟</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #000011;
            overflow: hidden;
            font-family: 'Arial', sans-serif;
        }
        
        #container {
            width: 100vw;
            height: 100vh;
            position: relative;
        }
        
        #controls {
            position: absolute;
            top: 20px;
            left: 20px;
            z-index: 100;
            color: #ffffff;
            background: rgba(0, 0, 0, 0.7);
            padding: 15px;
            border-radius: 10px;
            backdrop-filter: blur(10px);
        }
        
        button {
            background: linear-gradient(45deg, #ff6b6b, #ee5a24);
            border: none;
            color: white;
            padding: 10px 20px;
            margin: 5px;
            border-radius: 25px;
            cursor: pointer;
            font-weight: bold;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
        }
        
        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
        }
        
        button:disabled {
            background: #666;
            cursor: not-allowed;
            transform: none;
        }
        
        #status {
            margin-top: 10px;
            font-size: 14px;
            color: #ffaa00;
        }
        
        #warning {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: #ff0000;
            font-size: 64px;
            font-weight: bold;
            text-shadow: 0 0 30px #ff0000, 0 0 50px #ff0000;
            opacity: 0;
            pointer-events: none;
            z-index: 200;
            animation: pulse 1.5s infinite;
        }
        
        @keyframes pulse {
            0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
            50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
        }
    </style>
</head>
<body>
    <div id="container">
        <div id="controls">
            <h3>太阳系二向箔攻击模拟器</h3>
            <button id="startBtn">启动二向箔攻击</button>
            <button id="resetBtn">重置太阳系</button>
            <button id="toggleOrbits">显示/隐藏轨道</button>
            <div id="status">太阳系正常运转中...</div>
            <div style="font-size: 12px; margin-top: 5px; color: #aaa;">
                鼠标拖拽旋转视角 | 滚轮缩放
            </div>
        </div>
        <div id="warning">二向箔攻击警告！</div>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
    <script>
        // 简化的轨道控制器实现
        class OrbitControls {
            constructor(camera, domElement) {
                this.camera = camera;
                this.domElement = domElement;
                this.target = new THREE.Vector3();
                
                this.minDistance = 10;
                this.maxDistance = 200;
                this.enablePan = false;
                
                this.spherical = new THREE.Spherical();
                this.sphericalDelta = new THREE.Spherical();
                
                this.scale = 1;
                this.panOffset = new THREE.Vector3();
                
                this.isMouseDown = false;
                this.rotateStart = new THREE.Vector2();
                this.rotateEnd = new THREE.Vector2();
                this.rotateDelta = new THREE.Vector2();
                
                this.bindEvents();
                this.update();
            }
            
            bindEvents() {
                this.domElement.addEventListener('mousedown', this.onMouseDown.bind(this));
                this.domElement.addEventListener('mousemove', this.onMouseMove.bind(this));
                this.domElement.addEventListener('mouseup', this.onMouseUp.bind(this));
                this.domElement.addEventListener('wheel', this.onMouseWheel.bind(this));
                this.domElement.addEventListener('contextmenu', (e) => e.preventDefault());
            }
            
            onMouseDown(event) {
                this.isMouseDown = true;
                this.rotateStart.set(event.clientX, event.clientY);
            }
            
            onMouseMove(event) {
                if (!this.isMouseDown) return;
                
                this.rotateEnd.set(event.clientX, event.clientY);
                this.rotateDelta.subVectors(this.rotateEnd, this.rotateStart).multiplyScalar(0.01);
                
                this.sphericalDelta.theta -= this.rotateDelta.x;
                this.sphericalDelta.phi -= this.rotateDelta.y;
                
                this.rotateStart.copy(this.rotateEnd);
            }
            
            onMouseUp() {
                this.isMouseDown = false;
            }
            
            onMouseWheel(event) {
                if (event.deltaY < 0) {
                    this.scale *= 0.9;
                } else {
                    this.scale *= 1.1;
                }
                this.scale = Math.max(0.1, Math.min(10, this.scale));
            }
            
            update() {
                const offset = new THREE.Vector3();
                offset.copy(this.camera.position).sub(this.target);
                
                this.spherical.setFromVector3(offset);
                this.spherical.theta += this.sphericalDelta.theta;
                this.spherical.phi += this.sphericalDelta.phi;
                
                this.spherical.phi = Math.max(0.1, Math.min(Math.PI - 0.1, this.spherical.phi));
                this.spherical.radius = Math.max(this.minDistance, Math.min(this.maxDistance, this.spherical.radius * this.scale));
                
                offset.setFromSpherical(this.spherical);
                this.camera.position.copy(this.target).add(offset);
                this.camera.lookAt(this.target);
                
                this.sphericalDelta.set(0, 0, 0);
                this.scale = 1;
            }
        }
        let scene, camera, renderer, planets = [], sun, attackActive = false, 
            originalPositions = [], originalScales = [], animationId, controls, orbits = [];
        
        const planetData = [
            { name: 'Mercury', distance: 8, size: 0.3, color: 0x8c7853, speed: 0.04 },
            { name: 'Venus', distance: 12, size: 0.5, color: 0xffc649, speed: 0.03 },
            { name: 'Earth', distance: 16, size: 0.6, color: 0x6b93d6, speed: 0.025 },
            { name: 'Mars', distance: 20, size: 0.4, color: 0xc1440e, speed: 0.02 },
            { name: 'Jupiter', distance: 28, size: 1.2, color: 0xd8ca9d, speed: 0.01 },
            { name: 'Saturn', distance: 36, size: 1.0, color: 0xfad5a5, speed: 0.008 },
            { name: 'Uranus', distance: 44, size: 0.8, color: 0x4fd0e3, speed: 0.006 },
            { name: 'Neptune', distance: 52, size: 0.8, color: 0x4b70dd, speed: 0.005 }
        ];
        
        function init() {
            // 创建场景
            scene = new THREE.Scene();
            
            // 创建相机
            camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
            camera.position.set(0, 30, 60);
            camera.lookAt(0, 0, 0);
            
            // 创建渲染器
            renderer = new THREE.WebGLRenderer({ antialias: true });
            renderer.setSize(window.innerWidth, window.innerHeight);
            renderer.setClearColor(0x000011);
            renderer.shadowMap.enabled = true;
            renderer.shadowMap.type = THREE.PCFSoftShadowMap;
            document.getElementById('container').appendChild(renderer.domElement);
            
            // 创建轨道控制器
            controls = new OrbitControls(camera, renderer.domElement);
            controls.target.set(0, 0, 0);
            
            // 创建太阳
            const sunGeometry = new THREE.SphereGeometry(2, 32, 32);
            const sunMaterial = new THREE.MeshBasicMaterial({ 
                color: 0xffff00,
                transparent: true
            });
            sun = new THREE.Mesh(sunGeometry, sunMaterial);
            scene.add(sun);
            
            // 添加太阳光晕效果
            const glowGeometry = new THREE.SphereGeometry(2.5, 32, 32);
            const glowMaterial = new THREE.MeshBasicMaterial({
                color: 0xffaa00,
                transparent: true,
                opacity: 0.3
            });
            const sunGlow = new THREE.Mesh(glowGeometry, glowMaterial);
            sun.add(sunGlow);
            
            // 创建点光源
            const light = new THREE.PointLight(0xffffff, 2, 100);
            light.position.set(0, 0, 0);
            light.castShadow = true;
            scene.add(light);
            
            // 创建行星
            planetData.forEach((data, index) => {
                const geometry = new THREE.SphereGeometry(data.size, 16, 16);
                const material = new THREE.MeshLambertMaterial({ color: data.color });
                const planet = new THREE.Mesh(geometry, material);
                
                // 设置行星的初始位置
                const angle = Math.random() * Math.PI * 2;
                planet.position.x = Math.cos(angle) * data.distance;
                planet.position.z = Math.sin(angle) * data.distance;
                
                planet.castShadow = true;
                planet.receiveShadow = true;
                planet.userData = { ...data, angle: angle };
                
                scene.add(planet);
                planets.push(planet);
                
                // 存储原始位置和缩放
                originalPositions.push(planet.position.clone());
                originalScales.push(planet.scale.clone());
            });
            
            // 创建星空背景
            createStarField();
            
            // 创建行星轨道
            createOrbits();
            
            // 事件监听
            document.getElementById('startBtn').addEventListener('click', startAttack);
            document.getElementById('resetBtn').addEventListener('click', resetSystem);
            document.getElementById('toggleOrbits').addEventListener('click', toggleOrbits);
            window.addEventListener('resize', onWindowResize);
            
            animate();
        }
        
        function createStarField() {
            const starGeometry = new THREE.BufferGeometry();
            const starCount = 2000;
            const positions = new Float32Array(starCount * 3);
            
            for (let i = 0; i < starCount * 3; i += 3) {
                positions[i] = (Math.random() - 0.5) * 400;
                positions[i + 1] = (Math.random() - 0.5) * 400;
                positions[i + 2] = (Math.random() - 0.5) * 400;
            }
            
            starGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
            
            const starMaterial = new THREE.PointsMaterial({
                color: 0xffffff,
                size: 1,
                transparent: true,
                opacity: 0.8
            });
            
            const stars = new THREE.Points(starGeometry, starMaterial);
            scene.add(stars);
        }
        
        function createOrbits() {
            planetData.forEach(data => {
                const orbitGeometry = new THREE.RingGeometry(data.distance - 0.1, data.distance + 0.1, 64);
                const orbitMaterial = new THREE.MeshBasicMaterial({
                    color: 0x444444,
                    transparent: true,
                    opacity: 0.3,
                    side: THREE.DoubleSide
                });
                
                const orbit = new THREE.Mesh(orbitGeometry, orbitMaterial);
                orbit.rotation.x = Math.PI / 2;
                scene.add(orbit);
                orbits.push(orbit);
            });
        }
        
        function toggleOrbits() {
            orbits.forEach(orbit => {
                orbit.visible = !orbit.visible;
            });
        }
        
        function startAttack() {
            if (attackActive) return;
            
            // 不要立即设置attackActive为true，而是在二向箔展开时设置
            document.getElementById('startBtn').disabled = true;
            document.getElementById('status').textContent = '检测到二向箔！';
            document.getElementById('warning').style.display = 'block';
            
            // 首先创建并投放二向箔小卡片
            dropTwoDimensionalFoil();
        }
        
        function dropTwoDimensionalFoil() {
            // 创建二向箔小卡片 - 一个白色发光的薄片
            const foilCardGeometry = new THREE.BoxGeometry(1.0, 0.5, 0.01);
            const foilCardMaterial = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1
            });
            
            const foilCard = new THREE.Mesh(foilCardGeometry, foilCardMaterial);
            foilCard.position.set(20, 50, 20); // 从侧上方开始，而不是正上方
            scene.add(foilCard);
            
            // 添加发光效果
            const glowGeometry = new THREE.BoxGeometry(1.5, 0.8, 0.05);
            const glowMaterial = new THREE.MeshBasicMaterial({
                color: 0x00ffff,
                transparent: true,
                opacity: 0.7
            });
            const glow = new THREE.Mesh(glowGeometry, glowMaterial);
            foilCard.add(glow);
            
            // 投放动画 - 斜着落向太阳并翻转
            const dropDuration = 3000;
            const startTime = Date.now();
            
            // 起始位置和目标位置
            const startPos = new THREE.Vector3(20, 50, 20);
            const targetPos = new THREE.Vector3(0, 0, 0); // 太阳位置
            
            const animateDrop = () => {
                const elapsed = Date.now() - startTime;
                const progress = elapsed / dropDuration;
                
                if (progress < 1) {
                    // 斜着下落，使用线性插值从起始位置到目标位置
                    foilCard.position.lerpVectors(startPos, targetPos, progress);
                    
                    // 不断翻转
                    foilCard.rotation.x = progress * Math.PI * 20;
                    foilCard.rotation.y = progress * Math.PI * 15;
                    foilCard.rotation.z = progress * Math.PI * 10;
                    
                    // 发光效果变化
                    const pulse = Math.sin(progress * Math.PI * 20) * 0.3 + 0.7;
                    foilCardMaterial.opacity = pulse;
                    glow.material.opacity = pulse * 0.5;
                    
                    // 当二向箔接近太阳时（大约70%的路程），隐藏警告字幕
                    if (progress > 0.7) {
                        document.getElementById('warning').style.display = 'none';
                    }
                    
                    requestAnimationFrame(animateDrop);
                } else {
                    // 小卡片到达太阳，开始展开
                    document.getElementById('status').textContent = '二向箔开始展开！';
                    scene.remove(foilCard);
                    
                    // 直接调用createTwoDimensionalFoil
                    createTwoDimensionalFoil();
                }
            };
            
            animateDrop();
        }
        
        function createTwoDimensionalFoil() {
            // 在二向箔开始展开时设置attackActive为true，停止太阳系旋转
            attackActive = true;
            
            // 创建二向箔的视觉表现 - 一个逐渐扩展的平面
            const foilGeometry = new THREE.PlaneGeometry(2, 2, 50, 50);
            const foilMaterial = new THREE.MeshBasicMaterial({
                color: 0x00ffff,
                transparent: true,
                opacity: 0.3,
                side: THREE.DoubleSide,
                wireframe: true
            });
            
            const foil = new THREE.Mesh(foilGeometry, foilMaterial);
            foil.rotation.x = Math.PI / 2;
            scene.add(foil);
            
            // 存储每个行星是否已被压缩
            const compressedPlanets = planets.map(() => false);
            // 存储太阳是否已被压缩
            let sunCompressed = false;
            
            // 动画扩展二向箔
            let scale = 0;
            const startTime = Date.now();
            const compressionDuration = 1000; // 每个天体压缩持续时间1秒
            
            const expandFoil = () => {
                const now = Date.now();
                scale += 0.8;
                foil.scale.set(scale, scale, 1);
                foilMaterial.opacity = Math.max(0.2, 0.6 - scale * 0.01);
                
                // 计算当前二向箔半径
                const currentRadius = scale;
                
                // 首先检查太阳是否被压缩
                if (!sunCompressed && currentRadius >= 2) {
                    sunCompressed = true;
                    const sunStartTime = now;
                    
                    // 太阳压缩动画
                    const compressSun = () => {
                        const elapsed = Date.now() - sunStartTime;
                        const progress = Math.min(elapsed / compressionDuration, 1);
                        const easeProgress = 1 - Math.pow(1 - progress, 3); // 缓动函数
                        
                        // 太阳Y轴压缩
                        sun.scale.y = Math.max(0.05, 1 - easeProgress * 0.95);
                        sun.material.opacity = 1 - easeProgress * 0.3;
                        
                        if (progress < 1) {
                            requestAnimationFrame(compressSun);
                        }
                    };
                    compressSun();
                }
                
                // 检查每个行星是否被二向箔触及
                planets.forEach((planet, index) => {
                    const distance = planet.userData.distance;
                    
                    // 如果二向箔已经扩散到该行星位置且行星尚未被压缩
                    if (currentRadius >= distance && !compressedPlanets[index]) {
                        compressedPlanets[index] = true;
                        const planetStartTime = now;
                        
                        // 保存当前行星位置，确保在压缩过程中不会改变
                        const currentPosition = planet.position.clone();
                        
                        // 行星压缩动画
                        const compressPlanet = () => {
                            const elapsed = Date.now() - planetStartTime;
                            const progress = Math.min(elapsed / compressionDuration, 1);
                            const easeProgress = 1 - Math.pow(1 - progress, 3); // 缓动函数
                            
                            // Y轴压缩到0（变成平面）
                            planet.position.y = currentPosition.y * (1 - easeProgress);
                            
                            // 保持X和Z坐标不变
                            planet.position.x = currentPosition.x;
                            planet.position.z = currentPosition.z;
                            
                            // 缩放效果 - Y轴压缩，XZ轴稍微扩大
                            const scaleY = Math.max(0.01, 1 - easeProgress * 0.99);
                            const scaleXZ = 1 + easeProgress * 0.3;
                            planet.scale.set(
                                originalScales[index].x * scaleXZ,
                                originalScales[index].y * scaleY,
                                originalScales[index].z * scaleXZ
                            );
                            
                            // 颜色变化效果 - 保留原始颜色并添加油画效果
                            const material = planet.material;
                            
                            // 当压缩到一半时，将材质从MeshLambertMaterial更改为MeshBasicMaterial
                            if (progress > 0.5 && material.type === 'MeshLambertMaterial') {
                                // 保存当前颜色
                                const currentColor = material.color.clone();
                                
                                // 创建新的MeshBasicMaterial材质
                                const newMaterial = new THREE.MeshBasicMaterial({ 
                                    color: currentColor,
                                    transparent: true,
                                    opacity: 1.0
                                });
                                
                                // 应用新材质
                                planet.material = newMaterial;
                            }
                            
                            // 重置为原始颜色
                            material.color.setHex(planetData[index].color);
                            
                            // 添加油画效果：增强饱和度和亮度
                            if (progress > 0.5) {
                                // 转换为HSL以便调整饱和度和亮度
                                const hsl = {};
                                material.color.getHSL(hsl);
                                
                                // 增加饱和度和亮度
                                hsl.s = Math.min(1, hsl.s * 1.5); // 增加饱和度
                                hsl.l = Math.min(0.8, hsl.l * 1.2); // 适度增加亮度
                                
                                material.color.setHSL(hsl.h, hsl.s, hsl.l);
                                
                                // 增加发光效果
                                if (!planet.userData.glowAdded && progress > 0.9) {
                                    planet.userData.glowAdded = true;
                                    
                                    // 添加轮廓发光效果
                                    const glowGeometry = new THREE.SphereGeometry(
                                        planet.geometry.parameters.radius * 1.2 * scaleXZ, 
                                        16, 16
                                    );
                                    const glowMaterial = new THREE.MeshBasicMaterial({
                                        color: material.color.clone(),
                                        transparent: true,
                                        opacity: 0.4,
                                        side: THREE.BackSide
                                    });
                                    const glow = new THREE.Mesh(glowGeometry, glowMaterial);
                                    glow.scale.y = scaleY;
                                    planet.add(glow);
                                }
                            }
                            
                            // 确保行星完全平行于平面
                            planet.rotation.x = 0;
                            planet.rotation.z = 0;
                            
                            if (progress < 1) {
                                requestAnimationFrame(compressPlanet);
                            } else {
                                // 确保最终状态完全平行
                                planet.position.y = 0;
                                planet.rotation.x = 0;
                                planet.rotation.z = 0;
                            }
                        };
                        compressPlanet();
                        
                        // 同时压缩对应的轨道
                        const orbit = orbits[index];
                        const orbitStartTime = now;
                        
                        const compressOrbit = () => {
                            const elapsed = Date.now() - orbitStartTime;
                            const progress = Math.min(elapsed / compressionDuration, 1);
                            const easeProgress = 1 - Math.pow(1 - progress, 3); // 缓动函数
                            
                            // 获取原始轨道几何体
                            const originalGeometry = orbit.geometry;
                            
                            // 创建新的更粗的轨道几何体
                            const thickness = 0.1 + easeProgress * 0.3; // 增加厚度
                            const newInnerRadius = orbit.geometry.parameters.innerRadius - thickness;
                            const newOuterRadius = orbit.geometry.parameters.outerRadius + thickness;
                            
                            // 替换轨道几何体
                            orbit.geometry.dispose(); // 释放旧几何体
                            orbit.geometry = new THREE.RingGeometry(newInnerRadius, newOuterRadius, 64);
                            
                            // 轨道颜色加深和亮度增强效果
                            const colors = [
                                0x00ffff, // 青色
                                0x0088ff, // 蓝色
                                0x0044ff, // 深蓝色
                                0x8800ff, // 紫色
                                0xff00ff, // 洋红
                                0xff0088, // 粉红
                                0xff0000, // 红色
                                0xff8800  // 橙色
                            ];
                            
                            // 根据行星索引选择颜色
                            const targetColor = colors[index % colors.length];
                            
                            // 颜色过渡效果
                            const originalColor = new THREE.Color(0x444444);
                            const finalColor = new THREE.Color(targetColor);
                            orbit.material.color.copy(originalColor).lerp(finalColor, easeProgress);
                            
                            // 增加不透明度
                            orbit.material.opacity = 0.3 + easeProgress * 0.7;
                            
                            if (progress < 1) {
                                requestAnimationFrame(compressOrbit);
                            } else {
                                // 压缩完成后，添加脉冲效果
                                const pulseOrbit = () => {
                                    if (!attackActive) return; // 如果重置了，停止脉冲
                                    
                                    const pulseTime = Date.now() * 0.001;
                                    const pulse = Math.sin(pulseTime * 2) * 0.1 + 1.0;
                                    
                                    // 轨道厚度脉冲
                                    const baseThickness = 0.1 + easeProgress * 0.3;
                                    const pulseThickness = baseThickness * pulse;
                                    
                                    // 更新轨道几何体
                                    const centerRadius = planetData[index].distance;
                                    const halfWidth = baseThickness;
                                    
                                    // 计算新的内外半径，保持中心位置不变
                                    const newInnerRadius = centerRadius - halfWidth * pulse;
                                    const newOuterRadius = centerRadius + halfWidth * pulse;
                                    
                                    // 替换轨道几何体
                                    orbit.geometry.dispose();
                                    orbit.geometry = new THREE.RingGeometry(newInnerRadius, newOuterRadius, 64);
                                    
                                    // 轻微的颜色脉冲
                                    const pulseColor = Math.sin(pulseTime * 3) * 0.2 + 0.8;
                                    orbit.material.opacity = 0.8 + pulseColor * 0.2;
                                    
                                    // 确保动画持续运行
                                    if (attackActive) {
                                        requestAnimationFrame(pulseOrbit);
                                    }
                                };
                                pulseOrbit();
                            }
                        };
                        compressOrbit();
                    }
                });
                
                // 持续扩展二向箔，不设置上限
                if (scale < 500) {  // 设置一个更大的上限，让二向箔持续扩展
                    requestAnimationFrame(expandFoil);
                } else {
                    // 到达最大扩展范围后，保持二向箔存在，但不再扩展
                    document.getElementById('status').textContent = '太阳系已被压缩为二维平面！';
                    document.getElementById('warning').style.display = 'none';
                    
                    // 确保所有轨道都已被处理
                    orbits.forEach((orbit, index) => {
                        if (!compressedPlanets[index]) {
                            // 如果有轨道还没被处理，立即处理它
                            compressedPlanets[index] = true;
                            
                            // 轨道线条加粗效果
                            const easeProgress = 1.0; // 完全效果
                            const thickness = 0.1 + easeProgress * 0.3;
                            const newInnerRadius = planetData[index].distance - thickness;
                            const newOuterRadius = planetData[index].distance + thickness;
                            
                            // 替换轨道几何体
                            orbit.geometry.dispose();
                            orbit.geometry = new THREE.RingGeometry(newInnerRadius, newOuterRadius, 64);
                            
                            // 轨道颜色加深和亮度增强效果
                            const colors = [
                                0x00ffff, // 青色
                                0x0088ff, // 蓝色
                                0x0044ff, // 深蓝色
                                0x8800ff, // 紫色
                                0xff00ff, // 洋红
                                0xff0088, // 粉红
                                0xff0000, // 红色
                                0xff8800  // 橙色
                            ];
                            
                            // 根据行星索引选择颜色
                            const targetColor = colors[index % colors.length];
                            orbit.material.color.setHex(targetColor);
                            orbit.material.opacity = 1.0;
                            
                            // 添加脉冲效果
                            const pulseOrbit = () => {
                                if (!attackActive) return; // 如果重置了，停止脉冲
                                
                                const pulseTime = Date.now() * 0.001;
                                const pulse = Math.sin(pulseTime * 2) * 0.1 + 1.0;
                                
                                // 轨道厚度脉冲
                                const baseThickness = 0.1 + easeProgress * 0.3;
                                const pulseThickness = baseThickness * pulse;
                                
                                // 更新轨道几何体
                                const centerRadius = planetData[index].distance;
                                const halfWidth = baseThickness;
                                
                                // 计算新的内外半径，保持中心位置不变
                                const newInnerRadius = centerRadius - halfWidth * pulse;
                                const newOuterRadius = centerRadius + halfWidth * pulse;
                                
                                // 替换轨道几何体
                                orbit.geometry.dispose();
                                orbit.geometry = new THREE.RingGeometry(newInnerRadius, newOuterRadius, 64);
                                
                                // 轻微的颜色脉冲
                                const pulseColor = Math.sin(pulseTime * 3) * 0.2 + 0.8;
                                orbit.material.opacity = 0.8 + pulseColor * 0.2;
                                
                                // 确保动画持续运行
                                if (attackActive) {
                                    requestAnimationFrame(pulseOrbit);
                                }
                            };
                            pulseOrbit();
                        }
                    });
                }
            };
            expandFoil();
        }
        
        function compressToPlanar() {
            // 这个函数现在不再需要，直接在dropTwoDimensionalFoil中调用createTwoDimensionalFoil
            // 保留空函数以保持代码结构
        }
        
        function resetSystem() {
            // 立即设置attackActive为false，停止所有脉冲动画
            attackActive = false;
            
            document.getElementById('startBtn').disabled = false;
            document.getElementById('status').textContent = '太阳系正常运转中...';
            document.getElementById('warning').style.display = 'none';
            
            // 移除可能存在的二向箔平面
            scene.children.forEach(child => {
                if (child.geometry && 
                    (child.geometry.type === "PlaneGeometry" || 
                     (child.material && 
                      child.material.color && 
                      child.material.color.getHex() === 0x00ffff))) {
                    scene.remove(child);
                }
            });
            
            // 重置所有行星
            planets.forEach((planet, index) => {
                // 移除可能添加的发光效果
                planet.children.forEach(child => {
                    if (child.material && child.material.transparent) {
                        planet.remove(child);
                    }
                });
                
                planet.position.copy(originalPositions[index]);
                planet.scale.copy(originalScales[index]);
                planet.rotation.set(0, 0, 0);
                
                // 重置颜色和材质
                const originalColor = planetData[index].color;
                
                // 如果当前材质不是MeshLambertMaterial，恢复为原始材质
                if (planet.material.type !== 'MeshLambertMaterial') {
                    // 创建新的MeshLambertMaterial材质
                    const newMaterial = new THREE.MeshLambertMaterial({ color: originalColor });
                    planet.material = newMaterial;
                } else {
                    // 只需更新颜色
                    planet.material.color.setHex(originalColor);
                }
                
                // 重置用户数据
                planet.userData = { 
                    ...planetData[index],
                    angle: planet.userData.angle,
                    glowAdded: false
                };
            });
            
            // 重置太阳
            sun.scale.set(1, 1, 1);
            sun.material.opacity = 1;
            
            // 重置轨道
            orbits.forEach((orbit, index) => {
                // 重新创建原始轨道几何体
                const data = planetData[index];
                orbit.geometry.dispose(); // 释放旧几何体
                orbit.geometry = new THREE.RingGeometry(data.distance - 0.1, data.distance + 0.1, 64);
                
                // 重置材质
                orbit.material.color.setHex(0x444444);
                orbit.material.opacity = 0.3;
            });
            
            // 延迟一小段时间后再允许重新启动攻击，确保所有动画都已停止
            setTimeout(() => {
                document.getElementById('startBtn').disabled = false;
            }, 100);
        }
        
        function animate() {
            animationId = requestAnimationFrame(animate);
            
            // 更新轨道控制器
            controls.update();
            
            if (!attackActive) {
                // 正常的行星运转
                planets.forEach(planet => {
                    planet.userData.angle += planet.userData.speed;
                    planet.position.x = Math.cos(planet.userData.angle) * planet.userData.distance;
                    planet.position.z = Math.sin(planet.userData.angle) * planet.userData.distance;
                    planet.rotation.y += 0.01;
                });
                
                // 太阳自转
                sun.rotation.y += 0.005;
            }
            
            renderer.render(scene, camera);
        }
        
        function onWindowResize() {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        }
        
        // 初始化场景
        init();
    </script>
</body>
</html>

在不影响最终效果的前提下，优化精简代码，消除重复冗余，添加更多注释