// Cloned by Niveditha Vudayagiri on 25 Sep 2024 from World "Blank Three.js World" by Starter user
// Please leave this clone trail here.
// ==== Starter World =================================================================================================
// This code is designed for use on the Ancient Brain site.
// This code may be freely copied and edited by anyone on the Ancient Brain site.
// To include a working run of this program on another site, see the "Embed code" links provided on Ancient Brain.
// ====================================================================================================================
// Starter World for Three.js experiments
// No Mind
// Just World
// ===================================================================================================================
// === Start of tweaker's box ========================================================================================
// ===================================================================================================================
// The easiest things to modify are in this box.
// You should be able to change things in this box without being a JavaScript programmer.
// Go ahead and change some of these. What's the worst that could happen?
AB.clockTick = 250;
// Speed of run: Step every n milliseconds. Default 100.
AB.maxSteps = 1000;
// Length of run: Maximum length of run in steps. Default 1000.
AB.screenshotStep = 50;
// Take screenshot on this step. (All resources should have finished loading.) Default 50.
const FILE_ARRAY = [
"/uploads/nivedithavudayagiri/cocoa.png",
"/uploads/starter/earth.2.jpg",
"/uploads/starter/earth.3.jpg",
"/uploads/starter/earth.4.jpg",
"/uploads/starter/earth.5.jpg"
];
const SKYCOLOR = 0xffffff; // a number, not a string
const ARMYSIZE = 100; // an "army" of objects
const objectsize = 3000 ;
const WALKSTEP = 50; // bounds of the random move per timestep
// try 50 (vibrating sheet) versus 1000 (cloud)
const MAXPOS = 4000 ; // start things within these bounds
const startRadiusConst = MAXPOS * 2 ; // distance from centre to start the camera at
const maxRadiusConst = MAXPOS * 5 ; // maximum distance from camera we will render things
//--- change ABWorld defaults: -------------------------------
ABHandler.MAXCAMERAPOS = MAXPOS * 10 ; // allow camera go far away
ABWorld.drawCameraControls = false;
// ===================================================================================================================
// === End of tweaker's box ==========================================================================================
// ===================================================================================================================
// You will need to be some sort of JavaScript programmer to change things below the tweaker's box.
var THEARMY = new Array( ARMYSIZE );
var textureArray = new Array ( FILE_ARRAY.length );
function loadResources() // asynchronous file loads - call initScene() when all finished
{
for ( var i = 0; i < FILE_ARRAY.length; i++ )
startFileLoad ( i ); // launch n asynchronous file loads
}
function startFileLoad ( n ) // asynchronous file load of texture n
{
var loader = new THREE.TextureLoader();
loader.load ( FILE_ARRAY[n], function ( thetexture )
{
thetexture.minFilter = THREE.LinearFilter;
textureArray[n] = thetexture;
if ( asynchFinished() ) initArmy();
});
}
function asynchFinished() // all file loads returned
{
for ( var i = 0; i < FILE_ARRAY.length; i++ )
if ( ! textureArray[i] )
return false;
return true;
}
function initArmy() // called when all textures ready
{
var t = 0;
for ( var c=1 ; c <= ARMYSIZE ; c++ )
{
const geometry = new THREE.TorusGeometry(100, 50, 160, 1000);
const donut = new THREE.Mesh(geometry);
/*donut.position.x = AB.randomIntAtoB ( -MAXPOS, MAXPOS );
donut.position.z = AB.randomIntAtoB ( -MAXPOS, MAXPOS );
donut.position.y = 0;*/
donut.rotation.x += Math.random() * 0.05;
donut.rotation.y += Math.random() * 0.05;
var r = AB.randomIntAtoB ( 0, textureArray.length - 1 ); // random texture
donut.material = new THREE.MeshBasicMaterial ( { map: textureArray[r] } );
ABWorld.scene.add(donut);
THEARMY[t] = donut; // save it for later
t++;
}
// can start the run loop
ABWorld.render();
AB.removeLoading();
AB.runReady = true;
}
function moveArmy() // move all the objects
{
for ( var i = 0; i < THEARMY.length; i++ )
{
if ( THEARMY[i] ) // in case initArmy() not called yet
{
THEARMY[i].position.x = THEARMY[i].position.x + AB.randomIntAtoB(-WALKSTEP,WALKSTEP) ;
THEARMY[i].position.z = THEARMY[i].position.z + AB.randomIntAtoB(-WALKSTEP,WALKSTEP) ;
THEARMY[i].position.y = THEARMY[i].position.y + AB.randomIntAtoB(-WALKSTEP,WALKSTEP) ;
ABWorld.scene.add( THEARMY[i] );
}
}
}
AB.world.newRun = function()
{
AB.loadingScreen();
AB.runReady = false;
ABWorld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR );
loadResources(); // aynch file loads
// calls initArmy() when it returns
};
AB.world.nextStep = function()
{
moveArmy();
};