Skip to content
The Chat Archive
minimax-m1 LMArena Human Preference 140K

Create a 3D rotating globe.

  1. User

    Create a 3D rotating globe.

  2. Assistant

    Here's a complete HTML/JS implementation of a 3D rotating globe using Three.js:

    <!DOCTYPE html>
    <html>
    <head>
        <title>3D Rotating Globe</title>
        <style>
            body { margin: 0; overflow: hidden; background-color: #000; }
            canvas { display: block; }
        </style>
    </head>
    <body>
        <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/controls/OrbitControls.js"></script>
        <script>
            // Initialize scene, camera, and renderer
            const scene = new THREE.Scene();
            const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
            const renderer = new THREE.WebGLRenderer({ antialias: true });
            
            renderer.setSize(window.innerWidth, window.innerHeight);
            document.body.appendChild(renderer.domElement);
    
            // Create globe geometry
            const globeGeometry = new THREE.SphereGeometry(5, 64, 64);
            
            // Load Earth texture
            const textureLoader = new THREE.TextureLoader();
            const earthTexture = textureLoader.load('https://cdn.jsdelivr.net/gh/mrdoob/three.js@master/examples/textures/planets/earth_atmos_2048.jpg');
            
            // Create material with texture
            const globeMaterial = new THREE.MeshPhongMaterial({
                map: earthTexture,
                bumpMap: earthTexture,
                bumpScale: 0.05,
            });
    
            // Create mesh and add to scene
            const globe = new THREE.Mesh(globeGeometry, globeMaterial);
            scene.add(globe);
    
            // Add lights
            const ambientLight = new THREE.AmbientLight(0x333333);
            scene.add(ambientLight);
    
            const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
            directionalLight.position.set(5, 3, 5);
            scene.add(directionalLight);
    
            // Add stars background
            const starsGeometry = new THREE.BufferGeometry();
            const starsMaterial = new THREE.PointsMaterial({
                color: 0xffffff,
                size: 0.1
            });
    
            const starsVertices = [];
            for (let i = 0; i < 5000; i++) {
                const x = (Math.random() - 0.5) * 2000;
                const y = (Math.random() - 0.5) * 2000;
                const z = (Math.random() - 0.5) * 2000;
                starsVertices.push(x, y, z);
            }
    
            starsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starsVertices, 3));
            const starField = new THREE.Points(starsGeometry, starsMaterial);
            scene.add(starField);
    
            // Position camera
            camera.position.z = 15;
    
            // Add orbit controls
            const controls = new THREE.OrbitControls(camera, renderer.domElement);
            controls.enableDamping = true;
            controls.dampingFactor = 0.05;
    
            // Animation loop
            function animate() {
                requestAnimationFrame(animate);
                
                // Auto-rotation
                globe.rotation.y += 0.005;
                
                controls.update();
                renderer.render(scene, camera);
            }
    
            // Handle window resize
            window.addEventListener('resize', () => {
                camera.aspect = window.innerWidth / window.innerHeight;
                camera.updateProjectionMatrix();
                renderer.setSize(window.innerWidth, window.innerHeight);
            });
    
            animate();
        </script>
    </body>
    </html>
    

    This implementation features:

    1. A detailed Earth texture with bump mapping for realistic surface features
    2. Automatic rotation around the Y-axis
    3. Interactive controls (zoom, pan, rotate using mouse/touch)
    4. A starfield background for better visual effect
    5. Responsive design that adapts to window size
    6. Proper lighting with ambient and directional lights
    7. Smooth animation using requestAnimationFrame

    To use it:

    1. Save the code as an HTML file
    2. Open in a modern web browser
    3. Interact using:
      • Left-click + drag to rotate
      • Right-click + drag to pan
      • Scroll to zoom

    The globe will automatically rotate while still allowing manual interaction. The texture is loaded from a reliable CDN source, but you can replace the texture URL with any equirectangular Earth texture of your choice.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.