// Cloned by MENGTE ZHU on 15 Nov 2022 from World "Port of flying birds " by Discover three.js
// Please leave this clone trail here.
// Port of flying birds from discoverthreejs.com
// "Final code from Ch 1.7 of Discover three.js"
// https://codesandbox.io/s/github/looeee/discoverthree.com-examples/tree/master/1-first-steps/7-load-models?from-embed
const MAXPOS = 7; // start things within these bounds
const startRadiusConst = MAXPOS * 1.5 ; // distance from centre to start the camera at
const maxRadiusConst = MAXPOS * 5 ; // maximum distance from camera we will render things
// const startRadius = 1; // distance from centre we start the camera at
// const maxRadius = startRadius * 20; // maximum distance from camera we render things
// can load skybox of other user:
const SKYBOX_ARRAY = [
"/uploads/starter/dawnmountain-xpos.png",
"/uploads/starter/dawnmountain-xneg.png",
"/uploads/starter/dawnmountain-ypos.png",
"/uploads/starter/dawnmountain-yneg.png",
"/uploads/starter/dawnmountain-zpos.png",
"/uploads/starter/dawnmountain-zneg.png"
];
const mixers = [];
const clock = new THREE.Clock();
// AB customisations
// Select text and "Code Help" to see what these mean:
AB.world.newRun = function()
{
// ABWorld.renderer = new THREE.WebGLRenderer ( { antialias: true } );
// custom renderer args - uncomment if need this - otherwise init3d makes the renderer
// var color = new THREE.Color (); // renderer color is not used - there is a skybox
ABWorld.init3d ( startRadiusConst, maxRadiusConst );
initLights();
loadModels();
loadStayModels();
// skybox:
ABWorld.scene.background = new THREE.CubeTextureLoader().load ( SKYBOX_ARRAY );
};
AB.world.nextStep = function()
{
const delta = clock.getDelta();
mixers.forEach( ( mixer ) => { mixer.update( delta ); } );
};
function loadModels()
{
const loader = new THREE.GLTFLoader();
const onLoad = ( gltf, position ) =>
{
const model = gltf.scene.children[ 0 ];
model.position.copy( position );
const animation = gltf.animations[ 0 ];
const mixer = new THREE.AnimationMixer( model );
mixers.push( mixer );
const action = mixer.clipAction( animation );
action.play();
ABWorld.scene.add( model );
};
const gokuPosition = new THREE.Vector3 ( 8, 0, -3);
const buuPosition = new THREE.Vector3 ( 2, 0, 6 );
const vegetaPosition = new THREE.Vector3 ( 2, 0, 6 );
// can load 3D models of other user:
loader.load ( '/uploads/chris/goku_rigged__animated.glb', gltf => onLoad ( gltf, gokuPosition ) );
loader.load ( '/uploads/chris/kid_buu.glb', gltf => onLoad ( gltf, buuPosition ) );
loader.load ( '/uploads/chris/kid_buu.glb', gltf => onLoad ( gltf, vegetaPosition ) );
}
function loadStayModels()
{
const Sloader = new THREE.GLTFLoader();
const SonLoad = ( gltf, Sposition ) =>
{
const Smodel = gltf.scene.children[ 0 ];
Smodel.position.copy( Sposition );
ABWorld.scene.add( Smodel );
};
const vegettoPosition = new THREE.Vector3 ( 0, 0, 0);
const brolyPosition = new THREE.Vector3 ( 0, 0, -10 );
Sloader.load ( '/uploads/chris/vegetto.glb', gltf => SonLoad ( gltf, vegettoPosition ) );
Sloader.load ( '/uploads/chris/dragon_ball_zbroly.glb', gltf => SonLoad ( gltf, brolyPosition ) );
}
function initLights()
// the lights are needed to show up models
{
const ambientLight = new THREE.AmbientLight( 0xffffff, 1 );
ABWorld.scene.add( ambientLight );
const frontLight = new THREE.DirectionalLight( 0xffffff, 1 );
frontLight.position.set( 10, 10, 10 );
const backLight = new THREE.DirectionalLight( 0xffffff, 1 );
backLight.position.set( -10, 10, -10 );
ABWorld.scene.add( frontLight, backLight );
}
// background music
// can load music of other user:
// const MUSICFILE = '/uploads/test/StarCommander1.wav';
// AB.backgroundMusic ( MUSICFILE );