three实现三维空间六边形镜面镜子运动折射效果代码

代码语言:html

所属分类:三维

代码描述:three实现三维空间六边形镜面镜子运动折射效果代码

代码标签: three 三维 镜面 镜子

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

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

<head>

  <meta charset="UTF-8">
  

  
  
  
<style>
body {
  margin: 0;
}

canvas {
  vertical-align: bottom;
}

.ly_container {
  position: relative;
  width: 100%;
}

.ly_bg {
  width: 100%;
  height: 100vh;
}
</style>

  



</head>

<body >
  <div class="ly_container">
  <div id="webgl-container" class="ly_bg"></div>
</div>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.123.js"></script>
      <script >
class App {
  constructor() {
    this.container = document.querySelector('#webgl-container');

    this.containerW = this.container.offsetWidth;
    this.containerH = this.container.offsetHeight;

    this.mouseX = 0;
    this.mouseY = 0;
    this.windowHalfX = this.containerW / 2;
    this.windowHalfY = this.containerH / 2;

    this.clock = new THREE.Clock();

    this.createScene();
    this.createCamera();
    this.addLight();
    this.getMesh();
    // this.addOrbitControls();
    this.onWindowResize();
    this.render();

    //

    document.addEventListener('mousemove', this.onDocumentMouseMove.bind(this), {
      passive: true });


    document.addEventListener('touchstart', this.onDocumentTouchStart.bind(this), {
      passive: true });


    document.addEventListener('touchmove', this.onDocumentTouchMove.bind(this), {
      passive: true });


    window.addEventListener('resize', this.onWindowResize.bind(this), {
      passive: true });

  }

  createScene() {
    this.scene = new THREE.Scene();
    this.scene.fog = new THREE.Fog(0x0d0d0d, 4000, 6000);

    this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
    this.renderer.setClearColor(new THREE.Color(0x0d0d0d));
    this.renderer.setPixelRatio(window.devicePixelRatio);
    this.renderer.setSize(this.containerW, this.containerH);

    this.container.appendChild(this.renderer.domElement);
    this.renderer.domElement.width = this.containerW;
    this.renderer.domElement.height = this.containerH;
  }

  createCamera() {
    this.camera = new THREE.PerspectiveCamera(45, this.containerW / this.containerH, 1, 100000);

    this.camera.position.z = 3500;
  }

  addLight() {
    this.ambientLight = new THREE.AmbientLight(0xffffff, 1.0);
    this.scene.add(this.ambientLight);

    this.spotLight = new THREE.SpotLight(0xfffacd);
    this.spotLight.position.set(-3000, 3000, 1000);
    this.scene.add(this.spotLight);

    this.directionalLight = new THREE.DirectionalLight(0xffffff, 1.0);
    this.directionalLight.position.set(0, 500, 4000);
    this.scene.add(this.directionalLight);
  }

  addParameters() {
  }

  getM.........完整代码请登录后点击上方下载按钮下载查看

网友评论0