<!--
Auto-generated by: https://github.com/threlte/threlte/tree/main/packages/gltf
Command: npx @threlte/gltf@2.0.1 static/models/earth.glb
-->

<script lang="ts">
  import { theme } from "$lib/stores/theme_store";
  import { T, forwardEventHandlers } from "@threlte/core";
  import { useGltf } from "@threlte/extras";
  import { backInOut } from "svelte/easing";
  import { tweened } from "svelte/motion";
  import { Group } from "three";

  export const ref = new Group();

  export let rotation: number = 0;

  const gltf = useGltf("/models/earth2.glb");

  const component = forwardEventHandlers();

  const sunXRotation = tweened($theme == "light" ? 0 : -Math.PI, {
    duration: 1000,
    easing: backInOut,
  });

  const sunLightIntensitiy = tweened($theme == "light" ? 1.5 : 0, {
    duration: 500,
  });
  const moonLightIntensitiy = tweened($theme == "dark" ? 3.0 : 0, {
    duration: 500,
  });
  $: sunLightIntensitiy.set($theme == "light" ? 1.5 : 0);
  $: moonLightIntensitiy.set($theme == "dark" ? 3.0 : 0);
  $: sunXRotation.set($theme == "light" ? 0 : -Math.PI);
</script>

<T is={ref} dispose={false} {...$$restProps} bind:this={$component}>
  {#await gltf}
    <slot name="fallback" />
  {:then gltf}
    <!-- Clouds -->
    <T.Group rotation={[-rotation / 4, rotation / 4, 0]}>
      <T.Mesh
        geometry={gltf.nodes.Icosphere002.geometry}
        material={gltf.materials.Material}
        position={[-0.94, 0.95, -0.12]}
        rotation={[2.48, -0.48, 2.24]}
        scale={0.65}
        castShadow
      />
      <T.Mesh
        geometry={gltf.nodes.Icosphere003.geometry}
        material={gltf.materials.Material}
        position={[-0.02, 0.15, 1.33]}
        rotation={[-1.67, 0.46, 3.13]}
        scale={0.65}
        castShadow
      />
      <T.Mesh
        geometry={gltf.nodes.Icosphere004.geometry}
        material={gltf.materials.Material}
        position={[0.58, 1.05, -0.6]}
        rotation={[2.96, -0.61, -2.59]}
        scale={0.65}
        castShadow
      />
      <T.Mesh
        geometry={gltf.nodes.Icosphere005.geometry}
        material={gltf.materials.Material}
        position={[-1.18, -0.32, 0.56]}
        rotation={[-0.57, 0.25, 2.01]}
        scale={0.65}
        castShadow
      />
      <T.Mesh
        geometry={gltf.nodes.Icosphere006.geometry}
        material={gltf.materials.Material}
        position={[0.03, 1.31, -0.54]}
        rotation={[2.98, -1.09, -2.9]}
        scale={0.9}
        castShadow
      />
    </T.Group>
    <!-- /Clouds -->
    <!-- Airplane -->
    <T.Group rotation={[0, rotation, rotation]}>
      <T.Group position={[0, 1.2, 0]} rotation={[0, 0, 0]} scale={0.78}>
        <T.Mesh
          geometry={gltf.nodes.Plane005_1.geometry}
          material={gltf.materials["Material.006"]}
          castShadow
        />
        <T.Mesh
          geometry={gltf.nodes.Plane005_2.geometry}
          material={gltf.materials["Material.007"]}
          castShadow
        />
        <T.Mesh
          geometry={gltf.nodes.Plane005_3.geometry}
          material={gltf.materials["Material.008"]}
          castShadow
        />
      </T.Group>
    </T.Group>

    <!-- /Airplane -->
    <!-- Sun & Moon -->
    <T.Group rotation={[$sunXRotation, 0, 0]}>
      <T.Mesh
        geometry={gltf.nodes.Icosphere007.geometry}
        material={gltf.materials["Material.009"]}
        position={[0, 2, 0]}
        scale={0.88}
      >
        <T.PointLight position={[0.7, -0.2, 0]} color="#ffffff" intensity={0.5}
        ></T.PointLight>
        <T.DirectionalLight
          position={[0, 0, 0]}
          color="#ffffff"
          intensity={$sunLightIntensitiy}
          castShadow
        ></T.DirectionalLight>
      </T.Mesh>
      <T.Mesh
        geometry={gltf.nodes.Moon01.geometry}
        material={gltf.materials["Material.011"]}
        position={[0, -2, 0]}
        rotation={[Math.PI / 2, 0, Math.PI]}
        scale={0.045}
      >
        <T.PointLight position={[-4, 0, 0]} color="#a2cbf5" intensity={0.1}
        ></T.PointLight>
        <T.DirectionalLight
          position={[0, -0.5, 0]}
          color="#a2cbf5"
          intensity={$moonLightIntensitiy}
          castShadow
        ></T.DirectionalLight>
      </T.Mesh>
    </T.Group>
    <!-- /Sun -->
    <T.Group scale={1} rotation.y={rotation}>
      <!-- Earth -->
      <T.Mesh
        geometry={gltf.nodes.Icosphere_1.geometry}
        material={gltf.materials["Material.003"]}
        receiveShadow
      />
      <!-- /Earth -->
      <!-- Water -->
      <T.Mesh
        geometry={gltf.nodes.Icosphere001.geometry}
        material={gltf.materials["Material.002"]}
        receiveShadow
      />
      <!-- /Water -->
      <!-- Trees -->
      <T.Mesh
        geometry={gltf.nodes.Icosphere_2.geometry}
        material={gltf.materials["Material.004"]}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.36, 0.96, 0.03]}
        rotation={[0.09, -0.02, -0.4]}
        scale={0.7}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane001.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.32, 0.98, -0.03]}
        rotation={[-0.08, 0.05, -0.4]}
        scale={0.68}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane002.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.2, 1.01, -0.05]}
        rotation={[-0.08, 0.06, -0.13]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane003.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.21, 1.01, 0.04]}
        rotation={[0.1, 0.03, -0.13]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane004.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.29, 0.98, 0.12]}
        rotation={[0.18, 0.02, -0.24]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane005.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.26, 0.99, -0.12]}
        rotation={[-0.15, 0.1, -0.24]}
        scale={0.51}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane006.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.39, 0.95, 0.12]}
        rotation={[0.11, 0.01, -0.4]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane007.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.16, 1, 0.19]}
        rotation={[0.17, -0.01, -0.24]}
        scale={0.51}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane008.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.81, 0.69, 0.31]}
        rotation={[0.38, -0.13, -0.82]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane009.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.84, 0.6, 0.39]}
        rotation={[0.38, -0.13, -0.82]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane010.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.88, 0.61, 0.28]}
        rotation={[0.26, 0, -0.85]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane011.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.79, 0.61, -0.5]}
        rotation={[-0.07, 0.4, -0.91]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane012.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.72, 0.68, -0.51]}
        rotation={[-0.16, 0.49, -0.75]}
        scale={0.51}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane013.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.72, 0.61, -0.6]}
        rotation={[-0.3, 0.6, -0.74]}
        scale={0.61}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane014.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.8, 0.65, -0.42]}
        rotation={[-0.08, 0.39, -0.9]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane015.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.81, 0.53, -0.56]}
        rotation={[-0.2, 0.55, -1.08]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane016.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.32, -0.47, 0.96]}
        rotation={[1.65, -0.8, -0.42]}
        scale={0.53}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane017.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.42, -0.49, 0.91]}
        rotation={[1.61, -0.78, -0.62]}
        scale={0.59}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane018.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.29, -0.59, 0.92]}
        rotation={[1.87, -0.86, -0.21]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane019.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.34, -0.54, 0.92]}
        rotation={[1.61, -0.78, -0.62]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane020.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.2, -0.55, 0.95]}
        rotation={[1.87, -0.86, -0.21]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane021.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.33, -0.65, 0.85]}
        rotation={[1.79, -0.84, -0.61]}
        scale={0.74}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane022.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.39, -0.58, 0.87]}
        rotation={[1.63, -0.76, -0.6]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane023.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.46, -0.58, 0.84]}
        rotation={[1.63, -0.76, -0.6]}
        scale={0.62}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane024.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.22, -0.72, 0.82]}
        rotation={[2.02, -0.9, -0.38]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane025.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.11, 0.28, -0.99]}
        rotation={[-1.19, 1.03, -0.03]}
        scale={0.61}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane026.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.02, 0.28, -0.99]}
        rotation={[-1.19, 1.03, -0.03]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane027.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.06, 0.14, -1.02]}
        rotation={[-1.4, 1.03, 0]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane028.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.11, 0.14, -1.01]}
        rotation={[-1.23, 1.02, -0.3]}
        scale={0.5}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane029.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.02, 0.16, -1.02]}
        rotation={[-1.4, 1.03, 0]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane030.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.23, 0.23, -0.98]}
        rotation={[-1.85, 0.96, 0.56]}
        scale={0.69}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane031.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.11, 0.24, -1]}
        rotation={[-1.4, 1.03, 0]}
        scale={0.64}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane032.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.19, 0.14, -1]}
        rotation={[-1.72, 1.01, 0.3]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane033.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.07, 0.02, -1.03]}
        rotation={[-1.72, 1.01, 0.3]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane034.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.06, 0.02, -1.03]}
        rotation={[-1.24, 1.01, -0.29]}
        scale={0.67}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane035.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.03, -0.12, -1.02]}
        rotation={[-1.75, 1.05, 0]}
        scale={0.36}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane036.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.2, -0.04, -1.01]}
        rotation={[-1.92, 1.03, 0.31]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane037.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.3, 0.05, -0.99]}
        rotation={[-1.93, 1.03, 0.63]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane038.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.37, 0.18, -0.94]}
        rotation={[-1.93, 1.03, 0.63]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane039.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.48, 0.32, -0.86]}
        rotation={[-2.14, 0.89, 1.11]}
        scale={0.62}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane040.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.62, 0.08, -0.82]}
        rotation={[-2.2, 0.81, 1]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane041.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.53, 0.2, -0.86]}
        rotation={[-2.2, 0.81, 1]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane042.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.45, 0, -0.93]}
        rotation={[-2.12, 0.88, 0.79]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane043.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.37, -0.11, -0.96]}
        rotation={[-2.14, 0.87, 0.49]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane044.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.26, -0.18, -0.98]}
        rotation={[-2.14, 0.87, 0.49]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane045.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.47, 0.96, 0.41]}
        rotation={[0.36, -0.12, -0.52]}
        scale={0.71}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane046.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.32, 0.93, 0.58]}
        rotation={[0.43, -0.15, -0.35]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane047.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.49, 0.89, 0.52]}
        rotation={[0.43, -0.15, -0.35]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane048.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.3, 0.85, 0.69]}
        rotation={[0.59, -0.2, -0.3]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane049.geometry}
        material={gltf.materials["Material.005"]}
        position={[0.61, 0.87, 0.41]}
        rotation={[0.37, -0.1, -0.52]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane050.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.33, 0.77, 0.61]}
        rotation={[0.6, 0.15, 0.19]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane051.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.48, 0.76, 0.5]}
        rotation={[0.28, 0.45, 0.54]}
        scale={0.51}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane052.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.37, 0.79, 0.56]}
        rotation={[0.32, 0.5, 0.36]}
        scale={0.61}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane053.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.37, 0.75, 0.62]}
        rotation={[0.79, 0.08, 0.23]}
        scale={0.82}
      />
      <T.Mesh
        geometry={gltf.nodes.Plane054.geometry}
        material={gltf.materials["Material.005"]}
        position={[-0.23, 0.76, 0.66]}
        rotation={[0.59, 0.18, 0.19]}
        scale={0.82}
      />
      <!-- /Trees -->
      <!-- Houses -->
      <T.Group
        position={[0.45, 0.74, 0.74]}
        rotation={[0.73, -0.16, -0.41]}
        scale={1.08}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane002_1.geometry}
          material={gltf.materials.Material}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane002_2.geometry}
          material={gltf.materials["Material.007"]}
        />
      </T.Group>
      <T.Group
        position={[-0.34, 0.68, 0.7]}
        rotation={[0.85, -0.17, 0.24]}
        scale={0.81}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane002_1.geometry}
          material={gltf.materials.Material}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane002_2.geometry}
          material={gltf.materials["Material.007"]}
        />
      </T.Group>
      <T.Group
        position={[0.83, 0.55, -0.5]}
        rotation={[-1.49, -0.47, -1.12]}
        scale={0.69}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane002_1.geometry}
          material={gltf.materials.Material}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane002_2.geometry}
          material={gltf.materials["Material.007"]}
        />
      </T.Group>
      <T.Group
        position={[0.4, 0.94, -0.09]}
        rotation={[-1.02, -1.08, -0.99]}
        scale={0.69}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane002_1.geometry}
          material={gltf.materials.Material}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane002_2.geometry}
          material={gltf.materials["Material.007"]}
        />
      </T.Group>
      <T.Group
        position={[0.39, -0.42, 0.96]}
        rotation={[-0.88, -0.78, -2.72]}
        scale={0.69}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane002_1.geometry}
          material={gltf.materials.Material}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane002_2.geometry}
          material={gltf.materials["Material.007"]}
        />
      </T.Group>
      <T.Group
        position={[0.81, 0.53, 0.55]}
        rotation={[0.32, -0.49, -1.02]}
        scale={0.69}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane002_1.geometry}
          material={gltf.materials.Material}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane002_2.geometry}
          material={gltf.materials["Material.007"]}
        />
      </T.Group>
      <T.Group
        position={[0.88, 0.51, 0.43]}
        rotation={[-0.21, -0.54, -1.21]}
        scale={0.69}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane002_1.geometry}
          material={gltf.materials.Material}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane002_2.geometry}
          material={gltf.materials["Material.007"]}
        />
      </T.Group>
      <T.Group
        position={[0.86, 0.43, 0.54]}
        rotation={[0.32, -0.49, -1.02]}
        scale={0.69}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane002_1.geometry}
          material={gltf.materials.Material}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane002_2.geometry}
          material={gltf.materials["Material.007"]}
        />
      </T.Group>
      <T.Group
        position={[0.77, 0.45, 0.66]}
        rotation={[0.68, -0.25, -0.89]}
        scale={0.75}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane002_1.geometry}
          material={gltf.materials.Material}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane002_2.geometry}
          material={gltf.materials["Material.007"]}
        />
      </T.Group>
      <!-- /Houses -->
      <!-- Boats -->
      <T.Group
        position={[-0.15, 0.97, 0.21]}
        rotation={[0.18, 0.81, 0.13]}
        scale={0.79}
        castShadow
      >
        <T.Mesh
          geometry={gltf.nodes.Plane003_1.geometry}
          material={gltf.materials["Material.009"]}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane003_2.geometry}
          material={gltf.materials.Material}
        />
      </T.Group>
      <T.Group
        position={[0.85, -0.51, -0.16]}
        rotation={[-0.62, 0.4, -1.85]}
        scale={0.75}
      >
        <T.Mesh
          geometry={gltf.nodes.Plane003_1.geometry}
          material={gltf.materials["Material.009"]}
        />
        <T.Mesh
          geometry={gltf.nodes.Plane003_2.geometry}
          material={gltf.materials.Material}
        />
      </T.Group>
      <!-- /Boats -->
    </T.Group>
  {:catch error}
    <slot name="error" {error} />
  {/await}

  <slot {ref} />
</T>
