Code viewer for World: Grass
const skycolour = "lightblue";
//loading in grass textures
const textureLoader = new THREE.TextureLoader();

const grassBaseColour = textureLoader.load("/uploads/skellyc4/Stylized_Grass_002_basecolor.jpg");
grassBaseColour.wrapS = THREE.RepeatWrapping;
grassBaseColour.wrapT = THREE.RepeatWrapping;
grassBaseColour.repeat.set( 8, 16 );

const grassAmbientOcclusionMap = textureLoader.load("/uploads/skellyc4/Stylized_Grass_002_ambientOcclusion.jpg")
grassAmbientOcclusionMap.wrapS = THREE.RepeatWrapping;
grassAmbientOcclusionMap.wrapT = THREE.RepeatWrapping;
grassAmbientOcclusionMap.repeat.set( 8, 16 );

const grassHeightMap = textureLoader.load("/uploads/skellyc4/Stylized_Grass_002_height.png")
grassHeightMap.wrapS = THREE.RepeatWrapping;
grassHeightMap.wrapT = THREE.RepeatWrapping;
grassHeightMap.repeat.set( 8, 16 );

const grassNormalMap = textureLoader.load("/uploads/skellyc4/Stylized_Grass_002_normal.jpg")
grassNormalMap.wrapS = THREE.RepeatWrapping;
grassNormalMap.wrapT = THREE.RepeatWrapping;
grassNormalMap.repeat.set( 8, 16 );

const grassRoughnessMap = textureLoader.load("/uploads/skellyc4/Stylized_Grass_002_roughness.jpg")
grassRoughnessMap.wrapS = THREE.RepeatWrapping;
grassRoughnessMap.wrapT = THREE.RepeatWrapping;
grassRoughnessMap.repeat.set( 8, 16 );

//adding light
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.x += 20;
directionalLight.position.y += 20;
directionalLight.position.z += 20;

// create the floor
const floorGeometry = new THREE.PlaneGeometry(100, 200, 1024, 2048);
floorGeometry.rotateX(- Math.PI / 2);

const floorMaterial = new THREE.MeshStandardMaterial(
    {
    map: grassBaseColour,
    normalMap: grassNormalMap,
    displacementMap: grassHeightMap,
    displacementScale: .4,
    roughnessMap: grassRoughnessMap,
    roughness: 0.5,
    aoMap: grassAmbientOcclusionMap
    }
);
floorGeometry.attributes.uv2 = floorGeometry.attributes.uv;

const floor = new THREE.Mesh(floorGeometry, floorMaterial);
floor.position.set(0, -20, -99);



const OBJPATH = "/uploads/skellyc4/";	// path of OBJ and MTL
const OBJNAME = "catMod.obj";
const MTLNAME = "catMod-3.mtl";

const SCALE_HERO 		= 0.25;

function loadResources()		// asynchronous file loads - call initScene() when all finished 
{

	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;
			theagent.bumpScale = 0.015;
			if ( theagent )	initScene();
			else (console.log("No cat :("))
		});
	});
}

function initScene()		// all file loads have returned 
{
	
 // add agent model 	
 // start at center
 
 	theagent.position.y = -20;
	theagent.position.x = 0;
	theagent.position.z = -10;
	theagent.rotation.y += 3.14159;
	theagent.rotation.x += 1.5708;
	theagent.scale.multiplyScalar ( SCALE_HERO );    	  	// scale it 
	ABWorld.scene.add( theagent );
}



AB.world.newRun = function () {
    loadResources();
    ABWorld.init3d(150, 1500000, skycolour);
    ABWorld.scene.add(directionalLight);
    ABWorld.scene.add(floor);
};