three.js 实现鼠标滚动天降馅饼效果

代码语言:html

所属分类:视觉差异

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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<title> Three.js - Scroll for hot dogs</title>

<style>
      body {
  align-items: center;
  display: flex;
  height: 100vh;
  justify-content: center;
}

canvas {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
}

div {
  align-items: center;
  color: darkslategrey;
  display: flex;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 2px;
  line-height: 1.5;
  pointer-events: none;
  position: relative;
  text-align: center;
  text-transform: uppercase;
  z-index: 1;
}

span {
  font-size: 3em;
  margin: 0 .5rem;
}

    </style>

</head>
<body translate="no">
<div>
Scroll for <span>🌭</span> hot dogs
</div>

<script src='http://repo.bfw.wiki/bfwrepo/js/three.js'></script>
<script src='http://repo.bfw.wiki/bfwrepo/js/OrbitControls.js'></script>
<script src='http://repo.bfw.wiki/bfwrepo/js/OBJLoader.js'></script>
<script src='http://repo.bfw.wiki/bfwrepo/js/MTLLoader.js'></script>
<script>
      var camera, controls, scene, renderer;

init();
animate();

function init() {

  //New hot dog array
  hotdogs = [];

  camera = new THREE.PerspectiveCamera(1000, window.innerWidth / window.innerHeight, 1, 1000);

  camera.position.z = 1000;

  // Scene
  scene = new THREE.Scene();
  scene.background = new THREE.Color(0x8ee7f0);
  scene.fog = new THREE.FogExp2(0xcccccc, 0.001);

  // Obj loader
  var loader = new THREE.OBJLoader();

  // Download object
  var onProgress = function (xhr) {
    if (xhr.lengthComputable) {
      var percentComplete = xhr.loaded / xhr.total * 100;
      console.log(Math.round(percentComplete, 2) + '% downloaded');
    }
  };

  var onError = function () {};

  //Load texture
  new THREE.MTLLoader().
  setPath('https://s3-us-west-2.amazonaws.com/s.c.........完整代码请登录后点击上方下载按钮下载查看

网友评论0