src/core/AssetManager.js
/**
	* Loads all models from the backend.
	*
	* @return {AssetManager} A reference to this asset manager.
	*/
Loads all models from the backend.
@return {AssetManager} A reference to this asset manager.
Loads all models from the backend . @return { AssetManager } A reference to this asset manager .
_loadModels() {
		const gltfLoader = this.gltfLoader;
		const textureLoader = this.textureLoader;
		const models = this.models;
		const animations = this.animations;
		const shadowTexture = textureLoader.load( './textures/shadow.png' );
		const planeGeometry = new PlaneBufferGeometry();
		const planeMaterial = new MeshBasicMaterial( { map: shadowTexture, transparent: true, opacity: 0.4 } );
		const shadowPlane = new Mesh( planeGeometry, planeMaterial );
		shadowPlane.position.set( 0, 0.05, 0 );
		shadowPlane.rotation.set( - Math.PI * 0.5, 0, 0 );
		shadowPlane.scale.multiplyScalar( 2 );
		shadowPlane.matrixAutoUpdate = false;
		shadowPlane.updateMatrix();
		gltfLoader.load( './models/soldier.glb', ( gltf ) => {
			const renderComponent = gltf.scene;
			renderComponent.animations = gltf.animations;
			renderComponent.matrixAutoUpdate = false;
			renderComponent.updateMatrix();
			renderComponent.traverse( ( object ) => {
				if ( object.isMesh ) {
					object.material.side = DoubleSide;
					object.matrixAutoUpdate = false;
					object.updateMatrix();
				}
			} );
			renderComponent.add( shadowPlane );
			models.set( 'soldier', renderComponent );
			for ( let animation of gltf.animations ) {
				animations.set( animation.name, animation );
			}
		} );
		gltfLoader.load( './models/level.glb', ( gltf ) => {
			const renderComponent = gltf.scene;
			renderComponent.matrixAutoUpdate = false;
			renderComponent.updateMatrix();
			renderComponent.traverse( ( object ) => {
				object.matrixAutoUpdate = false;
				object.updateMatrix();
			} );
			const mesh = renderComponent.getObjectByName( 'level' );
			mesh.material.lightMap = textureLoader.load( './textures/lightmap.png' );
			mesh.material.lightMap.flipY = false;
			mesh.material.map.anisotropy = 4;
			models.set( 'level', renderComponent );
		} );
		gltfLoader.load( './models/blaster_high.glb', ( gltf ) => {
			const renderComponent = gltf.scene;
			renderComponent.matrixAutoUpdate = false;
			renderComponent.updateMatrix();
			renderComponent.traverse( ( object ) => {
				object.matrixAutoUpdate = false;
				object.updateMatrix();
			} );
			models.set( 'blaster_high', renderComponent );
		} );
		gltfLoader.load( './models/blaster_low.glb', ( gltf ) => {
			const renderComponent = gltf.scene;
			renderComponent.matrixAutoUpdate = false;
			renderComponent.updateMatrix();
			renderComponent.traverse( ( object ) => {
				object.matrixAutoUpdate = false;
				object.updateMatrix();
			} );
			models.set( 'blaster_low', renderComponent );
		} );
		gltfLoader.load( './models/shotgun_high.glb', ( gltf ) => {
			const renderComponent = gltf.scene;
			renderComponent.matrixAutoUpdate = false;
			renderComponent.updateMatrix();
			renderComponent.traverse( ( object ) => {
				object.matrixAutoUpdate = false;
				object.updateMatrix();
			} );
			models.set( 'shotgun_high', renderComponent );
		} );
		gltfLoader.load( './models/shotgun_low.glb', ( gltf ) => {
			const renderComponent = gltf.scene;
			renderComponent.matrixAutoUpdate = false;
			renderComponent.updateMatrix();
			renderComponent.traverse( ( object ) => {
				object.matrixAutoUpdate = false;
				object.updateMatrix();
			} );
			models.set( 'shotgun_low', renderComponent );
		} );
		gltfLoader.load( './models/assaultRifle_high.glb', ( gltf ) => {
			const renderComponent = gltf.scene;
			renderComponent.matrixAutoUpdate = false;
			renderComponent.updateMatrix();
			renderComponent.traverse( ( object ) => {
				object.matrixAutoUpdate = false;
				object.updateMatrix();
			} );
			models.set( 'assaultRifle_high', renderComponent );
		} );
		gltfLoader.load( './models/assaultRifle_low.glb', ( gltf ) => {
			const renderComponent = gltf.scene;
			renderComponent.matrixAutoUpdate = false;
			renderComponent.updateMatrix();
			renderComponent.traverse( ( object ) => {
				object.matrixAutoUpdate = false;
				object.updateMatrix();
			} );
			models.set( 'assaultRifle_low', renderComponent );
		} );
		gltfLoader.load( './models/healthPack.glb', ( gltf ) => {
			const renderComponent = gltf.scene;
			renderComponent.matrixAutoUpdate = false;
			renderComponent.updateMatrix();
			renderComponent.traverse( ( object ) => {
				object.matrixAutoUpdate = false;
				object.updateMatrix();
			} );
			models.set( 'healthPack', renderComponent );
		} );
		const muzzleTexture = textureLoader.load( './textures/muzzle.png' );
		muzzleTexture.matrixAutoUpdate = false;
		const muzzleMaterial = new SpriteMaterial( { map: muzzleTexture } );
		const muzzle = new Sprite( muzzleMaterial );
		muzzle.matrixAutoUpdate = false;
		muzzle.visible = false;
		models.set( 'muzzle', muzzle );
		const bulletLineGeometry = new BufferGeometry();
		const bulletLineMaterial = new LineBasicMaterial( { color: 0xfbf8e6 } );
		bulletLineGeometry.setFromPoints( [ new Vector3(), new Vector3( 0, 0, - 1 ) ] );
		const bulletLine = new LineSegments( bulletLineGeometry, bulletLineMaterial );
		bulletLine.matrixAutoUpdate = false;
		models.set( 'bulletLine', bulletLine );
	}
_loadModels ( ) { const gltfLoader = this . gltfLoader ; const textureLoader = this . textureLoader ; const models = this . models ; const animations = this . animations ; const shadowTexture = textureLoader . load ( './textures/shadow.png' ) ; const planeGeometry = new PlaneBufferGeometry ( ) ; const planeMaterial = new MeshBasicMaterial ( { map : shadowTexture , transparent : true , opacity : 0.4 } ) ; const shadowPlane = new Mesh ( planeGeometry , planeMaterial ) ; shadowPlane . position . set ( 0 , 0.05 , 0 ) ; shadowPlane . rotation . set ( - Math . PI * 0.5 , 0 , 0 ) ; shadowPlane . scale . multiplyScalar ( 2 ) ; shadowPlane . matrixAutoUpdate = false ; shadowPlane . updateMatrix ( ) ; gltfLoader . load ( './models/soldier.glb' , ( gltf ) => { const renderComponent = gltf . scene ; renderComponent . animations = gltf . animations ; renderComponent . matrixAutoUpdate = false ; renderComponent . updateMatrix ( ) ; renderComponent . traverse ( ( object ) => { if ( object . isMesh ) { object . material . side = DoubleSide ; object . matrixAutoUpdate = false ; object . updateMatrix ( ) ; } } ) ; renderComponent . add ( shadowPlane ) ; models . set ( 'soldier' , renderComponent ) ; for ( let animation of gltf . animations ) { animations . set ( animation . name , animation ) ; } } ) ; gltfLoader . load ( './models/level.glb' , ( gltf ) => { const renderComponent = gltf . scene ; renderComponent . matrixAutoUpdate = false ; renderComponent . updateMatrix ( ) ; renderComponent . traverse ( ( object ) => { object . matrixAutoUpdate = false ; object . updateMatrix ( ) ; } ) ; const mesh = renderComponent . getObjectByName ( 'level' ) ; mesh . material . lightMap = textureLoader . load ( './textures/lightmap.png' ) ; mesh . material . lightMap . flipY = false ; mesh . material . map . anisotropy = 4 ; models . set ( 'level' , renderComponent ) ; } ) ; gltfLoader . load ( './models/blaster_high.glb' , ( gltf ) => { const renderComponent = gltf . scene ; renderComponent . matrixAutoUpdate = false ; renderComponent . updateMatrix ( ) ; renderComponent . traverse ( ( object ) => { object . matrixAutoUpdate = false ; object . updateMatrix ( ) ; } ) ; models . set ( 'blaster_high' , renderComponent ) ; } ) ; gltfLoader . load ( './models/blaster_low.glb' , ( gltf ) => { const renderComponent = gltf . scene ; renderComponent . matrixAutoUpdate = false ; renderComponent . updateMatrix ( ) ; renderComponent . traverse ( ( object ) => { object . matrixAutoUpdate = false ; object . updateMatrix ( ) ; } ) ; models . set ( 'blaster_low' , renderComponent ) ; } ) ; gltfLoader . load ( './models/shotgun_high.glb' , ( gltf ) => { const renderComponent = gltf . scene ; renderComponent . matrixAutoUpdate = false ; renderComponent . updateMatrix ( ) ; renderComponent . traverse ( ( object ) => { object . matrixAutoUpdate = false ; object . updateMatrix ( ) ; } ) ; models . set ( 'shotgun_high' , renderComponent ) ; } ) ; gltfLoader . load ( './models/shotgun_low.glb' , ( gltf ) => { const renderComponent = gltf . scene ; renderComponent . matrixAutoUpdate = false ; renderComponent . updateMatrix ( ) ; renderComponent . traverse ( ( object ) => { object . matrixAutoUpdate = false ; object . updateMatrix ( ) ; } ) ; models . set ( 'shotgun_low' , renderComponent ) ; } ) ; gltfLoader . load ( './models/assaultRifle_high.glb' , ( gltf ) => { const renderComponent = gltf . scene ; renderComponent . matrixAutoUpdate = false ; renderComponent . updateMatrix ( ) ; renderComponent . traverse ( ( object ) => { object . matrixAutoUpdate = false ; object . updateMatrix ( ) ; } ) ; models . set ( 'assaultRifle_high' , renderComponent ) ; } ) ; gltfLoader . load ( './models/assaultRifle_low.glb' , ( gltf ) => { const renderComponent = gltf . scene ; renderComponent . matrixAutoUpdate = false ; renderComponent . updateMatrix ( ) ; renderComponent . traverse ( ( object ) => { object . matrixAutoUpdate = false ; object . updateMatrix ( ) ; } ) ; models . set ( 'assaultRifle_low' , renderComponent ) ; } ) ; gltfLoader . load ( './models/healthPack.glb' , ( gltf ) => { const renderComponent = gltf . scene ; renderComponent . matrixAutoUpdate = false ; renderComponent . updateMatrix ( ) ; renderComponent . traverse ( ( object ) => { object . matrixAutoUpdate = false ; object . updateMatrix ( ) ; } ) ; models . set ( 'healthPack' , renderComponent ) ; } ) ; const muzzleTexture = textureLoader . load ( './textures/muzzle.png' ) ; muzzleTexture . matrixAutoUpdate = false ; const muzzleMaterial = new SpriteMaterial ( { map : muzzleTexture } ) ; const muzzle = new Sprite ( muzzleMaterial ) ; muzzle . matrixAutoUpdate = false ; muzzle . visible = false ; models . set ( 'muzzle' , muzzle ) ; const bulletLineGeometry = new BufferGeometry ( ) ; const bulletLineMaterial = new LineBasicMaterial ( { color : 0xfbf8e6 } ) ; bulletLineGeometry . setFromPoints ( [ new Vector3 ( ) , new Vector3 ( 0 , 0 , - 1 ) ] ) ; const bulletLine = new LineSegments ( bulletLineGeometry , bulletLineMaterial ) ; bulletLine . matrixAutoUpdate = false ; models . set ( 'bulletLine' , bulletLine ) ; }
Loads all models from the backend.
Loads all models from the backend .
// shadow for soldiers // soldier // level // add lightmap manually since glTF does not support this type of texture so far // blaster, high poly // blaster, low poly // shotgun, high poly // shotgun, low poly // assault rifle, high poly // assault rifle, low poly // health pack // muzzle sprite // bullet line