three实现三维立体音频沙盘可视化效果代码

代码语言:html

所属分类:三维

代码描述:three实现三维立体音频沙盘可视化效果代码,点击播放按钮,听一听音乐,感受一下立体彩色网格沙盘跟随音乐上下波动的音频可视化效果。

代码标签: three 三维 立体 音频 沙盘 可视化

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


<!DOCTYPE html>
<html lang="en" >

<head>

 
<meta charset="UTF-8">

 
 
 
<style>
* {
   
margin: 0;
   
padding: 0;
 
}
 
  html
{
   
height: 100%;
   
background-color: #FFF;
 
}
 
  body
{  
   
margin: 0;
   
height: 100%;
   
font-family: 'Noto Sans JP', sans-serif;
   
height: 10000px;
 
}

 
#myCanvas {
   
overflow: hidden;
   
top: 0;
   
left: 0;
   
width: 100%;
   
height: 100%;  
 
}
 
#myCanvas canvas {  
   
display: block;
   
width: 100%;
   
height: 100%;
 
}

 
#overlay {
   
position: absolute;
   
z-index: 1;
   
top: 0;
   
left: 0;
   
width: 100%;
   
height:100%;
   
display: none;
   
align-items: center;
   
justify-content: center;
   
opacity: 1;
   
background-color: #000000;
   
color: #ffffff;
 
}

  p
{
   
color: #ffffff;
 
}

 
.link{
   
color: #000;
   
background: #FFF;
   
mix-blend-mode: exclusion;
 
font-size: 12px;
 
position: absolute;
 
left: 10px;
 
bottom: 10px;
 
}

 
.link a{
   
text-decoration: underline;
   
font-size: 10px;
     
color: #000;

 
}
</style>

 


</head>

<body>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.92.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.min.js"></script>

 
<div id="overlay">
   
<p>Play</p>
 
</div>


 
 
<div id="myCanvas"></div>

 
     
<script  >
class Audio {
  constructor(soundUrl) {

    this.listener = new THREE.AudioListener();
    const audio = new THREE.Audio(this.listener);
    this.xhr = 0;

    this.audioLoader = new THREE.AudioLoader();
    this.audioLoader.load(soundUrl,
    function (buffer) {
      audio.setBuffer(buffer);
      audio.setLoop(true);
      audio.setVolume(1.0);
    },
    // onProgress callback
    function (xhr) {
      if (xhr.loaded / xhr.total * 100 === 100) {
        setTimeout(() => {
          document.getElementById('overlay').style.display = "block";
        }, 1000);
      } else {}
    },
    // onError callback
    function (err) {
      console.log('An error happened');
    });

    this.soundPlay = () => {
      audio.play();
    };
    this.analyser = [];
    this.analyser = new THREE.AudioAnalyser(audio, 512);

    this.dataArray = new Uint8Array();
  }

  update() {
    this.FrequencyData = this.analyser.getFrequencyData(this.dataArray);

    this.AverageFrequency = this.analyser.getAverageFrequency();
  }}




class Canvas {
  constructor() {
    /**************.........完整代码请登录后点击上方下载按钮下载查看

网友评论0