// Cloned by Heejin Yoon on 26 Sep 2023 from World "One Cube World (Three.js)" by Starter user
// Please leave this clone trail here.
const skyColour = 'cornflowerBlue';
const boxColour = 'HotPink';
const objectSize = 450; // size of object
const anotherObjectSize = 300; // size of another dimensions to change the shape
const startRadius = 1200; // distance from centre we start the camera at
const maxRadius = startRadius * 5; // maximum distance from camera we render things
// the object is a cube (each dimension equal):
var shape = new THREE.BoxGeometry ( anotherObjectSize, objectSize, objectSize );
var material = new THREE.MeshBasicMaterial ( { color: boxColour.toLowerCase() } );
var theobject = new THREE.Mesh ( shape, material );
// Define what the World does at the start of a run:
AB.world.newRun = function()
{
// start a 3D scene:
ABWorld.init3d ( startRadius, maxRadius, skyColour );
// add the object to the scene:
ABWorld.scene.add ( theobject );
// paint the cube:
const imageFile = '/uploads/heejin96/1695749657.png';
var loader = new THREE.TextureLoader();
loader.load (imageFile, function( theTexture ) {
// This defines a function to be called whenever the file is loaded
theTexture.minFilter = THREE.LinearFilter;
theobject.material = new THREE.MeshBasicMaterial ({ map: theTexture });
});
// add some background music
const MUSICFILE = '/uploads/heejin96/BTS-BTSFAKELOVE.mp3';
AB.backgroundMusic (MUSICFILE);
};
AB.world.nextStep = function() {
// Define the target position for the object to smoothly move towards
var targetX = theobject.position.x + AB.randomIntAtoB(-150, 150);
var targetY = theobject.position.y + AB.randomIntAtoB(-30, 30);
var targetZ = theobject.position.z + AB.randomIntAtoB(-60, 60);
// Define the speed at which the object should move
var speed = 2.0; // Adjust this value to control the speed of movement
// calculate the new position of the object based on linear interpolation
theobject.position.x = AB.lerp(theobject.position.x, targetX, speed);
theobject.position.y = AB.lerp(theobject.position.y, targetY, speed);
theobject.position.z = AB.lerp(theobject.position.z, targetZ, speed);
// Ensure the object does not move too far on left or right
theobject.position.x = Math.min(Math.max(theobject.position.x, -150), 150);
theobject.position.y = Math.min(Math.max(theobject.position.y, -30), 30);
theobject.position.z = Math.min(Math.max(theobject.position.z, -60), 60);
};
// Linear interpolation function
AB.lerp = function(start, end, speed) {
return start + (end - start) * speed;
};