const MAXPOS = 3500; // length of one side of the arena
const startRadiusConst = MAXPOS ; // distance from centre to start the camera at
const maxRadiusConst = MAXPOS * 10 ; // maximum distance from camera we will render things
const SKYCOLOR = 0xffffcc;
const LIGHTCOLOR = 0xffffff ;
// the object is a cube (each dimension equal):
var shape = new THREE.BoxGeometry ( objectsize, objectsize, objectsize );
var material = new THREE.MeshBasicMaterial ( { color: boxcolor.toLowerCase() } );
var theobject = new THREE.Mesh ( shape, material );
AB.world.newRun = function() {
// Camera Settings
ABWorld.drawCameraControls = false;
ABWorld.cameraMove();
AB.loadingScreen();
AB.runReady = false;
ABWorld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR );
};
AB.world.nextStep = function() {
// Code for Three.js re-drawing of objects.
};
AB.world.endRun = function() {
};
function loadResources() { // asynchronous file loads - call initScene() when all finished
// load skeleton - OBJ that we will paint with a texture
var loader = new THREE.OBJLoader ( new THREE.LoadingManager() );
loader.load ( OBJ_SKELETON, function ( object )
{
theenemy = object; // canonical enemy object - may be copied multiple times
if ( asynchFinished() ) initScene();
});
// load Peter Parker model - OBJ plus MTL (plus TGA files)
// old code:
// THREE.Loader.Handlers.add ( /.tga$/i, new THREE.TGALoader() );
THREE.DefaultLoadingManager.addHandler ( /\.tga$/i, new THREE.TGALoader() );
var m = new THREE.MTLLoader();
m.setResourcePath ( 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 )
{
theagent = object;
// if ( asynchFinished() ) initScene();
initScene();
});
});
// load textures
var loader2 = new THREE.TextureLoader();
loader2.load ( TEXTURE_SKELETON, function ( thetexture )
{
thetexture.minFilter = THREE.LinearFilter;
skeleton_texture = thetexture;
// if ( asynchFinished() ) initScene();
initScene();
});
}
function initScene() // all file loads have returned
{
// add agent model
// start at center
theagent.position.y = 0;
theagent.position.x = 0;
theagent.position.z = 0;
theagent.scale.multiplyScalar ( SCALE_HERO ); // scale it
ABWorld.scene.add( theagent );
// set up lookat and follow in direction agent is pointing in
setLookatFollow();
// add enemies
// first paint and size the canonical enemy object
theenemy.traverse ( function ( child )
{
if ( child instanceof THREE.Mesh )
child.material.map = skeleton_texture ;
});
theenemy.scale.multiplyScalar ( SCALE_SKELETON ); // scale it
// add perhaps multiple enemy models, starting near outside of arena
for ( var i = 0; i < NO_SKELETONS ; i++ )
{
var object = theenemy.clone(); // copy the object multiple times
object.position.y = 0;
object.position.x = AB.randomPick ( AB.randomIntAtoB ( -MAXPOS/2, -MAXPOS/3 ), AB.randomIntAtoB ( MAXPOS/3, MAXPOS/2 ) );
object.position.z = AB.randomPick ( AB.randomIntAtoB ( -MAXPOS/2, -MAXPOS/3 ), AB.randomIntAtoB ( MAXPOS/3, MAXPOS/2 ) );
ABWorld.scene.add( object );
// save in array for later
THESKELETONS[i] = object;
}
// finally skybox
ABWorld.scene.background = new THREE.CubeTextureLoader().load ( SKYBOX_ARRAY, function()
{
ABWorld.render();
AB.removeLoading();
AB.runReady = true;
});
}