Code viewer for World: Tesla Cube
// Cloned by Niveditha Vudayagiri on 19 Sep 2024 from World "One Cube World (Three.js)" by Starter user 
// Please leave this clone trail here.
 

const skycolor          = 'SkyBlue';           
const boxcolor          = 'Gray';

const objectsize    = 300;                  // size of object   

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

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

// the object is a cube (each dimension equal): 
  
var shape       = new THREE.BoxGeometry ( 500, 200, 300 );
var material    = new THREE.MeshBasicMaterial ( { color: boxcolor.toLowerCase() } );
var theobject   = new THREE.Mesh ( shape, material );

const BACKGROUND_IMG = '/uploads/paulbashford/roadback.jpg'; // Define background image
const BOX_IMG  = '/uploads/nivedithavudayagiri/tesla.jpg';


// Define what the World does at the start of a run: 

AB.world.newRun = function() 
{
   var   loader       = new THREE.TextureLoader();
 
   // Load the background image and set it to the scene's background
   loader.load(BACKGROUND_IMG, function(texture) {
     ABWorld.scene.background = texture; // Set background texture
   });
  
  
   loader.load ( BOX_IMG, function ( thetexture ) 
   // this defines a function to be called whenever the file is loaded 
    {			 
        thetexture.minFilter  = THREE.LinearFilter;
        theobject.material    = new THREE.MeshBasicMaterial ( { map: thetexture } );
    }); 

    // start a 3D scene: 
    ABWorld.init3d ( startRadius, maxRadius ); 

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

AB.world.nextStep = function()
{
    theobject.position.x = theobject.position.x + AB.randomIntAtoB ( -30, 30 );
};