/* Js for , Version=1785139387 */
 if(typeof(v) != "object") v = {};v.pageID = 79;;
;
    const container = document.getElementById('canvas-container');
    // --- 初始化场景 ---
    const scene = new THREE.Scene();
    scene.background = new THREE.Color(0xf8f8f8); 
    const camera = new THREE.PerspectiveCamera(45, container.clientWidth / container.clientHeight, 0.1, 1000);
    camera.position.set(0, 2, 10); 
    const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
    renderer.setSize(container.clientWidth, container.clientHeight);
    renderer.setPixelRatio(window.devicePixelRatio);
    container.appendChild(renderer.domElement);
    const labelRenderer = new THREE.CSS2DRenderer();
    labelRenderer.setSize(container.clientWidth, container.clientHeight);
    labelRenderer.domElement.className = 'css-label-renderer';
    container.appendChild(labelRenderer.domElement);
    // --- 灯光 ---
    scene.add(new THREE.AmbientLight(0xffffff, 0.7));
    const dirLight = new THREE.DirectionalLight(0xffffff, 0.6);
    dirLight.position.set(5, 10, 7);
    scene.add(dirLight);
    // --- 材质 ---
    const siMaterial = new THREE.MeshStandardMaterial({ color: 0x2196F3, roughness: 0.3, metalness: 0.2 });
    const hMaterial = new THREE.MeshStandardMaterial({ color: 0xcccccc, roughness: 0.3, metalness: 0.1 });
    const bondMaterial = new THREE.MeshStandardMaterial({ color: 0xeeeeee, roughness: 0.5 });
    const moleculeGroup = new THREE.Group();
    scene.add(moleculeGroup);
    // --- 配置参数 ---
    const siRadius = 0.8;
    const hRadius = 0.4;
    const bondRadius = 0.12;
    const siSiDist = 2.4;  
    const siHDist = 1.8;   
    const angle = 109.5 * Math.PI / 180; 
    // --- 辅助函数：创建原子 ---
    function createAtom(x, y, z, material, labelText) {
        const geometry = new THREE.SphereGeometry(material === siMaterial ? siRadius : hRadius, 32, 32);
        const atom = new THREE.Mesh(geometry, material);
        atom.position.set(x, y, z);
        moleculeGroup.add(atom);
        const div = document.createElement('div');
        div.className = `atom-label ${labelText === 'Si' ? 'si-label' : 'h-label'}`;
        div.textContent = labelText;
        const label = new THREE.CSS2DObject(div);
        atom.add(label);
        return atom;
    }
    // --- 辅助函数：创建化学键 ---
    function createBond(start, end) {
        const direction = new THREE.Vector3().subVectors(end, start);
        const len = direction.length();
        const geometry = new THREE.CylinderGeometry(bondRadius, bondRadius, len, 16);
        const bond = new THREE.Mesh(geometry, bondMaterial);
        const pos = new THREE.Vector3().addVectors(start, end).multiplyScalar(0.5);
        bond.position.copy(pos);
        const axis = new THREE.Vector3(0, 1, 0);
        bond.quaternion.setFromUnitVectors(axis, direction.clone().normalize());
        moleculeGroup.add(bond);
    }
    // --- 构建乙硅烷 Si2H6 ---
    const si1Pos = new THREE.Vector3(-siSiDist/2, 0, 0);
    const si2Pos = new THREE.Vector3(siSiDist/2, 0, 0);
    createAtom(si1Pos.x, si1Pos.y, si1Pos.z, siMaterial, 'Si');
    createAtom(si2Pos.x, si2Pos.y, si2Pos.z, siMaterial, 'Si');
    createBond(si1Pos, si2Pos);
    const rad = siHDist * Math.sin(angle);
    const offX = siHDist * Math.cos(angle);
    const h1_positions = [
        new THREE.Vector3(si1Pos.x + offX, rad, 0),
        new THREE.Vector3(si1Pos.x + offX, rad * Math.cos(2*Math.PI/3), rad * Math.sin(2*Math.PI/3)),
        new THREE.Vector3(si1Pos.x + offX, rad * Math.cos(4*Math.PI/3), rad * Math.sin(4*Math.PI/3))
    ];
    const h2_positions = [
        new THREE.Vector3(si2Pos.x - offX, rad * Math.cos(Math.PI/3), rad * Math.sin(Math.PI/3)),
        new THREE.Vector3(si2Pos.x - offX, rad * Math.cos(Math.PI), rad * Math.sin(Math.PI)),
        new THREE.Vector3(si2Pos.x - offX, rad * Math.cos(5*Math.PI/3), rad * Math.sin(5*Math.PI/3))
    ];
    h1_positions.forEach(p => {
        createAtom(p.x, p.y, p.z, hMaterial, 'H');
        createBond(si1Pos, p);
    });
    h2_positions.forEach(p => {
        createAtom(p.x, p.y, p.z, hMaterial, 'H');
        createBond(si2Pos, p);
    });
    // --- 控制与动画 ---
    const controls = new THREE.OrbitControls(camera, renderer.domElement);
    controls.enableDamping = true;
    controls.autoRotate = true;
    controls.autoRotateSpeed = 1.0;
    function animate() {
        requestAnimationFrame(animate);
        controls.update();
        renderer.render(scene, camera);
        labelRenderer.render(scene, camera);
    }
    animate();
    window.addEventListener('resize', () => {
        const width = container.clientWidth;
        const height = container.clientHeight;
        renderer.setSize(width, height);
        labelRenderer.setSize(width, height);
        camera.aspect = width / height;
        camera.updateProjectionMatrix();
    });
