three模拟三维场景不同方向不同位置听到音乐效果代码

代码语言:html

所属分类:多媒体

代码描述:three模拟三维场景不同方向不同位置听到音乐效果代码

代码标签: three 模拟 三维 场景 不同 方向 位置 音乐

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
	<head>
	
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
	
	</head>
<body>

	<audio loop id="music" crossorigin="anonymous" preload="auto" style="display: none">
		<source src="//repo.bfw.wiki/bfwtool/examples/sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg" type="audio/ogg">
		<source src="//repo.bfw.wiki/bfwtool/examples/sounds/376737_Skullbeatz___Bad_Cat_Maste.mp3" type="audio/mpeg">
	</audio>

	<div id="overlay">
		<button id="startButton">Play</button>
	</div>
	<div id="container"></div>


	<!-- Import maps polyfill -->
	<!-- Remove this when import maps will be widely supported -->
	<script async type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/es-module-shims.1.3.6.js"></script>


		<script type="importmap">
			{
				"imports": {
					"three": "//repo.bfw.wiki/bfwtool/build/three.module.js"
				}
			}
		</script>

		<script type="module">

			import * as THREE from 'three';

			import Stats from '//repo.bfw.wiki/bfwtool/examples/jsm/libs/stats.module.js';
		import { OrbitControls } from '//repo.bfw.wiki/bfwtool/examples/jsm/controls/OrbitControls.js';
		import { PositionalAudioHelper } from '//repo.bfw.wiki/bfwtool/examples/jsm/helpers/PositionalAudioHelper.js';
		import { GLTFLoader } from '//repo.bfw.wiki/bfwtool/examples/jsm/loaders/GLTFLoader.js';

		let scene, camera, renderer;

		const startButton = document.getElementById( 'startButton' );
		startButton.addEventListener( 'click', init );

		function init() {

			const overlay = document.getElementById( 'overlay' );
			overlay.remove();

			const container = document.getElementById( 'container' );

			//

			camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 100 );
			camera.position.set( 3, 2, 3 );

			const reflectionCube = new THREE.CubeTextureLoader()
				.setPath( '//repo.bfw.wiki/bfwtool/examples/textures/cube/SwedishRoyalCastle/' )
				.load( [ 'px.jpg', 'nx.jpg', 'py.jpg', 'ny.jpg', 'pz.jpg', 'nz.jpg' ] );

			scene = new THREE.Scene();
			scene.background = new THREE.Color( 0xa0a0a0 );
			scene.fog = new THREE.Fog( 0xa0a0a0, 2, 20 );

			//

			const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
			hemiLight.position.set( 0, 20, 0 );
			scene.add( hemiLight );

			const dirLight = new THREE.DirectionalLight( 0xffffff );
			dirLight.position.set( 5, 5, 0 );
			dirLight.castShadow = true;
			dirLight.shadow.cam.........完整代码请登录后点击上方下载按钮下载查看

网友评论0