// Cloned by Himanshu Warekar on 7 Oct 2021 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 = 100; // 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/starter/earth.1.jpg",
"/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 = 300; // an "army" of objects
const objectsize = 300; // bounds of the random move per timestep
const WALKSTEP = 500; // 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;
var THEARMY = new Array (ARMYSIZE);
var textureArray = new Array (FILE_ARRAY.length);
var x = null;
var y = null;
var z = null;
var steps = [];
var counter = 10000000000;
function loadResources () { // asynchronous file loads - call initScene() when all finished
for (let i = 0; i < FILE_ARRAY.length; i++) {
startFileLoad(i); // launch n asynchronous file loads
}
}
function startFileLoad(n) { // asynchronous file load of texture n
let 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 (let i = 0; i < FILE_ARRAY.length; i++) {
if (!textureArray[i])
return false;
return true;
}
}
function initArmy() { // called when all textures ready
let t = 0;
for (let c=0 ; c <= ARMYSIZE ; c++) {
// var shape = new THREE.SphereGeometry ( objectsize, 10, 10 );
let shape = new THREE.BoxGeometry(objectsize, objectsize, objectsize);
let theobject = new THREE.Mesh(shape);
theobject.position.x = 0;
theobject.position.z = 0;
theobject.position.y = 0;
let r = AB.randomIntAtoB(0, textureArray.length - 1); // random texture
theobject.material = new THREE.MeshBasicMaterial({ map: textureArray[r]});
ABWorld.scene.add(theobject);
THEARMY[t] = theobject; // save it for later
t++;
}
// can start the run loop
ABWorld.render();
AB.removeLoading();
AB.runReady = true;
}
var moveArmy = function () { // move all the objects
for ( let i = 0; i < THEARMY.length; i++ ) {
if (THEARMY[i]) { // in case initArmy() not called yet
if (steps.length < 1000) {
let x = THEARMY[i].position.x + AB.randomIntAtoB(-WALKSTEP,WALKSTEP);
let y = THEARMY[i].position.y + AB.randomIntAtoB(-WALKSTEP,WALKSTEP);
let z = THEARMY[i].position.z + AB.randomIntAtoB(-WALKSTEP,WALKSTEP);
steps.push([x, y, z])
THEARMY[i].position.x = x;
THEARMY[i].position.z = z;
THEARMY[i].position.y = y;
} else {
let step = steps.pop()
THEARMY[i].position.x = steps[0];
THEARMY[i].position.z = steps[2];
THEARMY[i].position.y = steps[1];
}
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();
};