Earth model by me

3D Earth Model body { margin: 0; overflow: hidden; } canvas { display: block; }

Hi! :waving_hand: Welcome to the community! Maybe share all the code or give a link to the project so you can show off your Earth model!

1 Like

recovered

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3D Earth Model</title>
  <style>
    body { margin: 0; overflow: hidden; }
    canvas { display: block; }
  </style>
</head>
<body>
  <!-- Three.js CDN -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>

  <script>
    // Scene Setup
    const scene = new THREE.Scene();
    const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    // Earth Texture (You can replace this with your own texture URL)
    const textureLoader = new THREE.TextureLoader();
    const earthTexture = textureLoader.load('https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/earth.jpg');

    // Earth Sphere Geometry
    const geometry = new THREE.SphereGeometry(1, 64, 64);  // 1 radius, 64 segments
    const material = new THREE.MeshBasicMaterial({ map: earthTexture });
    const earth = new THREE.Mesh(geometry, material);
    scene.add(earth);

    // Camera Position
    camera.position.z = 3;

    // Animation Function
    function animate() {
      requestAnimationFrame(animate);

      // Rotate Earth for Animation
      earth.rotation.y += 0.01;

      renderer.render(scene, camera);
    }

    animate();

    // Handle Window Resizing
    window.addEventListener('resize', () => {
      renderer.setSize(window.innerWidth, window.innerHeight);
      camera.aspect = window.innerWidth / window.innerHeight;
      camera.updateProjectionMatrix();
    });
  </script>
</body>
</html>