// Cloned by Yuwei Chen on 27 Nov 2020 from World "One Cube World (Three.js)" by Starter user
// Please leave this clone trail here.
const skycolor = 'LightBlue'; // sky color
const objectsize = 300; // size of object
const startRadius = 1000; // distance from centre we start the camera at
const maxRadius = startRadius * 10; // maximum distance from camera we render things
// the object is a cube (each dimension equal):
var shape = new THREE.BoxGeometry ( objectsize, objectsize, objectsize );
var theobject1 = new THREE.Mesh ( shape );
var theobject2 = new THREE.Mesh ( shape );
var geometry = new THREE.Geometry();
var material = new THREE.LineBasicMaterial( { color: 0x0000ff } );
var line = new THREE.Line( geometry, material, THREE.LineSegments );
var color1 = new THREE.Color( 0x444444 );
var color2 = new THREE.Color( 0xFF0000 );
geometry.colors.push( color1, color2 );
var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
// Define what the World does at the start of a run:
AB.world.newRun = function()
{
const texturefile = '/uploads/finally/hqdefault.jpg';
var loader = new THREE.TextureLoader();
loader.load ( texturefile, function ( thetexture )
// this defines a function to be called whenever the file is loaded
{
thetexture.minFilter = THREE.LinearFilter;
theobject1.material = new THREE.MeshBasicMaterial ( { map: thetexture } );
});
// start a 3D scene:
ABWorld.init3d ( startRadius, maxRadius, skycolor );
// add the object to the scene:
ABWorld.scene.add ( theobject1 );
ABWorld.scene.add ( theobject2 );
ABWorld.scene.add ( line);
};
AB.world.nextStep = function()
{
theobject1.position.x = theobject1.position.x + AB.randomIntAtoB ( -30, 30 );
theobject1.position.y = theobject1.position.y + AB.randomIntAtoB ( -30, 30 );
theobject1.position.z = theobject1.position.z + AB.randomIntAtoB ( -300, 300 );
var p1 = new THREE.Vector3( theobject1.position.x, theobject1.position.y, theobject1.position.z);
var p2 = new THREE.Vector3( theobject2.position.x, theobject2.position.y, theobject2.position.z );
geometry.vertices.push(p1);
geometry.vertices.push(p2);
var line = new THREE.Line( geometry, material, THREE.LineSegments);
console.log(line)
};