Code viewer for World: Fiachra's World
// Cloned by Fiachra Gill on 19 Sep 2023 from World "One Cube World (Three.js)" by Starter user
// Please leave this clone trail here.

const skycolor = 'lightblue';
const boxcolor = 0xffffff;

const loader = new THREE.TextureLoader();

const img = loader.load('http://s3-us-west-2.amazonaws.com/s.cdpn.io/1206469/earthmap1k.jpg');

const objectsize = 300; // size of object

const startRadius = 1000; // distance from center we start the camera at

const maxRadius = startRadius * 10; // maximum distance from camera we render things


var shape = new THREE.SphereGeometry(objectsize, objectsize, objectsize);
var material = new THREE.MeshBasicMaterial({ map: img }); // Provide the texture as a map
var theobject = new THREE.Mesh(shape, material);

// Define what the World does at the start of a run:
AB.world.newRun = function () {
    // start a 3D scene:
    ABWorld.init3d(startRadius, maxRadius, skycolor);

    // add the object to the scene:
    ABWorld.scene.add(theobject);
};

var rotationSpeed = .2;

function animate() {
    theobject.rotation.y += rotationSpeed; // Rotate the Earth
    requestAnimationFrame(animate);
    ABWorld.renderer.render(ABWorld.scene, ABWorld.camera);
}

animate();