// Cloned by Adrian Irwin on 5 Dec 2022 from World "Grass" by Ciaran Skelly
// Please leave this clone trail here.
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 loadCat() // 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 )
{
theCat = object;
theCat.bumpScale = 0.015;
if ( theCat ) initScene();
else (console.log("No cat :("))
});
});
}
function initScene() // all file loads have returned
{
// add Cat model
// start at center
theCat.position.y = -20;
theCat.position.x = 0;
theCat.position.z = -10;
theCat.rotation.y += 3.14159;
theCat.rotation.x += 1.5708;
theCat.scale.multiplyScalar ( SCALE_HERO ); // scale it
ABWorld.scene.add(theCat);
}
AB.world.newRun = function () {
loadCat();
ABWorld.init3d(150, 1500000, skycolour);
ABWorld.scene.add(directionalLight);
ABWorld.scene.add(floor);
};