Code viewer for World: Pool Table

// Cloned by Ian Gilligan on 5 Feb 2019 from World " World" by Starter user 
// Please leave this clone trail here.
 



// ==== Starter World ===============================================================================================
// (c) Ancient Brain Ltd. All rights reserved.
// This code is only for use on the Ancient Brain site.
// This code may be freely copied and edited by anyone on the Ancient Brain site.
// This code may not be copied, re-published or used on any other website.
// To include a run of this code on another website, see the "Embed code" links provided on the Ancient Brain site.
// ==================================================================================================================




// Demo of 3D model
// OBJ plus MTL

// A "Simple World" like chase inside an invisible arena inside the  
// Chase uses x,y,z rather than grid of squares 

 // user_span1 - Status line  

  
  
  

// ===================================================================================================================
// === 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.  
	
AB.maxSteps        = 500;    

// Length of run: Maximum length of run in steps.  

AB.screenshotStep  = 50;   
  
// Take screenshot on this step. (All resources should have finished loading.)  


//---- global constants: -------------------------------------------------------
const OBJPATH = "/uploads/gilligi2/";	// path of OBJ and MTL 
const OBJNAME = "PoolTable.obj";
const MTLNAME = "PoolTable.obj.mtl";
	
const SKYCOLOR 		= 0xffffcc ;				// a number, not a string 
const LIGHTCOLOR 	= 0xffffff ;

const MODELLENGTH 			= 11054;							
const MODELWIDTH			= 6279; 

const SCALE     			= 1;							// scale it by this		 

const startRadiusConst 		= 100
const maxRadiusConst 		= 2500 

//--- change ABWorld defaults: -------------------------------
//ABHandler.GROUNDZERO		= true;
ABWorld.drawCameraControls = false; 


// ===================================================================================================================
// === End of tweaker's box ==========================================================================================
// ===================================================================================================================

var resourcesLoaded = false;
var splashClicked = false;

//---- start of World class -------------------------------------------------------
function World() 
{ 

var table;

function loadResources()
{
	var m = new THREE.MTLLoader();
	m.setTexturePath (OBJPATH);
	m.setPath        (OBJPATH);
	
	m.load ( MTLNAME, function ( materials ) 
	{
		materials.preload(); 
		var o = new THREE.OBJLoader();
		o.setMaterials ( materials );
		o.setPath ( OBJPATH );
		
		o.load ( OBJNAME, function ( object ) 
		{
			table = object;
			if ( asynchFinished() )	initScene();		 
		});
	});
}

function asynchFinished()		 
{
	if (table)  return true;  
	else return false;
}	

function initScene()
{
	table.scale.multiplyScalar ( SCALE );    	  
    table.position.y = 0;
    table.position.x = 0;
    table.position.z = 0; 
   	ABWorld.scene.add (table);
	ABWorld.render();
	console.log ( "Resources loaded." );
	resourcesLoaded = true;
	if ( resourcesLoaded && splashClicked ) 
		ABRun.runReady = true;
}

//--- public functions / interface / API ----------------------------------------------------------
this.newRun = function() 
{
	ABWorld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR  ); 
	ABRun.runReady = false; 
	loadResources();
    var thelight = new THREE.DirectionalLight ( LIGHTCOLOR, 1 );
    thelight.position.set ( 0, 100, 0 );
    ABWorld.scene.add(thelight);
};

}

//---- end of World class -------------------------------------------------------

// --- Splash screen --------------------------------------------------------------
	AB.newSplash();
	$("#splashbutton").click ( function ()        
	{
		AB.removeSplash();
		splashClicked = true;
		if ( resourcesLoaded && splashClicked ) 
			ABRun.runReady = true;
	});