three实现三维碎片纸屑跟随鼠标动画效果代码

代码语言:html

所属分类:粒子

代码描述:three实现三维碎片纸屑跟随鼠标动画效果代码

代码标签: three 三维 碎片 纸屑 跟随 鼠标 动画

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

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
    html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

canvas {
  position: fixed;
  width: 100%;
  height: 100%;
  z-index: -1;
}

#help {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 10px;
  width: 100%;
  position:absolute;
  color: #fff;
  text-align: center;
  z-index: 0;
}
</style>

</head>
<body>

<p id="help">移动鼠标试试^^</p>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.92.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/dat.gui-min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Stats-16.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.min.js"></script>
<script >
    
    const nbObjects = 1000;
var conf, scene, camera, cameraCtrl, light, renderer;
var whw, whh;

var objects;
var cubeGeometry, cubeMaterial;
var destination = new THREE.Vector3();

var mouse = new THREE.Vector2();
var mouseOver = false;
var mousePlane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
var mousePosition = new THREE.Vector3();
var raycaster = new THREE.Raycaster();

function init() {
  conf = {
    move: true,
    followMouse: true,
    attraction: 0.03,
    velocityLimit: 1.2,
    lightColor: 0x1b6cff,
    lightIntensity: 1,
    shuffle: shuffle
  };

  scene = new THREE.Scene();
  camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
  cameraCtrl = new THREE.OrbitControls(camera);

  renderer = new THREE.WebGLRenderer({ antialias: true });
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  initScene();

  stats = new Stats();
  document.body.appendChild(renderer.domElement);

  const gui = new dat.GUI();
  gui.add(conf, 'move');
  gui.add(conf, 'followMouse');
  gui.add(conf, 'attraction', 0.01, 0.1);
  gui.add(conf, 'velocityLimit', 0.1, 2);
  gui.addColor(conf, 'lightColor');
  gui.add(conf, 'lightIntensity', 0.1, 2);
  gui.add(conf, 'shuffle');
  gui.close();

  onWindowResize();
  window.addEventListener('resize', onWindowResize, false);

  document.addEventListener('mousemove', onMouseMove, false);
  // document.addEventListener('mouseover', function () { mouseOver = true; }, false);
  document.addEventListener('mouseout', onMouseOut, false);

  animate();
};

function initScene() {
  scene = new THREE.Scene();
  scene.background = new THREE.Color(0x000000);
  scene.add(new THREE.AmbientLight(0x808080));

  var plight = new THREE.PointLight(0xffffff, 0.5, 1000);
  plight.position.set(0, 0, 0);
  scene.add(plight);

  light = new THREE.PointLight(conf.lightColor, conf.lightIntensity, 500);
  light.position.set(0, 0, 0);
  scene.add(light);

  camera.position.z = 150;

  cubeGeometry = new THREE.BoxBufferGeometry(10, 10, 10);
  cubeMaterial = new THREE.Mes.........完整代码请登录后点击上方下载按钮下载查看

网友评论0