// Cloned by Eoin Daly on 29 Oct 2022 from World "Castle World" by Starter user
// Please leave this clone trail here.
AB.clockTick = 100;
AB.maxSteps = 500;
AB.screenshotStep = 50;
const OBJPATH = "/uploads/starter/";
const OBJNAME = "chess.obj";
const MTLNAME = "chess.mtl";
const SKYCOLOR = 0xffffcc ; // a number, not a string
const LIGHTCOLOR = 0xffffff ;
const squaresize = 50; // size of cube length
const MODELLENGTH = 6159;
const MODELWIDTH = 3791;
const SCALE_CASTLE = 0.5; // scale it by this
const SCALEDMODELLENGTH = MODELLENGTH * SCALE_CASTLE;
const SCALEDMODELWIDTH = MODELWIDTH * SCALE_CASTLE;
const startRadiusConst = SCALEDMODELLENGTH * 0.5 ;
const maxRadiusConst = SCALEDMODELLENGTH * 10 ;
ABHandler.GROUNDZERO = true; // "ground" exists at altitude zero
ABWorld.drawCameraControls = false;
var resourcesLoaded = false;
var splashClicked = false;
var thecastle;
function loadResources()
{
// "/uploads/dalye54/legoobj.obj"
var m = new THREE.MTLLoader();
m.setResourcePath ( "/uploads/starter/" );
m.setPath ( "/uploads/starter/" );
m.load ("castle.new.mtl", function (materials)
{
materials.preload();
var loader = new THREE.OBJLoader();
loader.setPath( "/uploads/starter/" )
loader.setMaterials(materials);
loader.load("castle.obj", function (object)
{
thecastle = object;
if ( asynchFinished() ) initScene() ;
});
});
}
function asynchFinished()
{
if ( thecastle ) return true;
else return false;
}
function initScene() // file loads have returned
{
// add castle object to scene
thecastle.scale.multiplyScalar ( 1 );
thecastle.position.y = 0; // adjust so cubes (centred on 0) appear exactly above castle floor
thecastle.position.x = 0;
thecastle.position.z = 0;
ABWorld.scene.add(thecastle);
ABWorld.render();
console.log ( "Resources loaded." );
resourcesLoaded = true;
if ( resourcesLoaded && splashClicked )
AB.runReady = true; // start run loop
}
AB.world.newRun = function()
{
ABWorld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR );
// newRun can run behind splash screen
// do not start run loop until resources ready AND splash screen is dismissed
AB.runReady = false;
loadResources(); // aynch file loads
// calls initScene() when it returns
var thelight = new THREE.DirectionalLight ( LIGHTCOLOR, 3 );
thelight.position.set ( startRadiusConst, startRadiusConst, startRadiusConst );
ABWorld.scene.add(thelight);
};