threejs打造一个鼠标跟随点击跳跃的三维山羊效果代码

代码语言:html

所属分类:三维

代码描述:threejs打造一个鼠标跟随点击跳跃的三维山羊效果代码

代码标签: 鼠标 跟随 点击 跳跃 三维 山羊 效果

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

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

<head>

  <meta charset="UTF-8">
  

  
<style>
@import url(https://fonts.googleapis.com/css2?family=Roboto:wght@400;700);
.app {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  overflow: hidden;
}

* {
  -webkit-tap-highlight-color: transparent;
}

.scene-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background: rgb(85,121,56);
  background-image: linear-gradient(0deg, #7cb64c 0%, #81a459  100%);
}

.infos {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 84px;
  z-index: 1;
  text-align: center;
  pointer-events: none;
  color: #fff;
  font-family:'Roboto', sans-serif;
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.instructions {
  margin-bottom: 10px;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  line-height: 1.3;
  padding: 0 50px;
}

.infos .link {
  pointer-events: all;
  cursor: pointer;
  text-decoration: none;
  color: #000000;
  font-weight: bold;
  transition: all 0.5s ease-out;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.infos .link:hover {
  color: #fff;
}
</style>


</head>

<body >
  <div class='scene-background'></div>
  <canvas class='app'></canvas>
  <div class='infos'>
    <p class='instructions'>
      Click and hold to make the sheep jump the highest.
    </p>
  
  </div>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.126.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/GLTFLoader.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/BufferGeometryUtils.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.5.2.js"></script>
      <script >
//THREEJS Variables
let renderer,
camera,
scene,
background,
floor,
cameraTarget = new THREE.Vector3(),
shadowLight,
keyLight,
hemiLight,
sheepGroup,
spaceGroup,
cloudsGroup,
treeGroup,
head,
poo,
corps,
eyeLeft,
eyeRight,
pupilleLeft,
pupilleRight;


let isDown = false,
downCounter = 0,
pooCounter = 0,
status = 'default',
mouse = { x: 0, y: 0 },
currentJumpStemp = 0;


// Whole config
const CONFIG = {
  CAMERA: {
    fov: 45,
    nearPlane: 1,
    farPlane: 20 },

  PHYSICS: {
    gravity: 0.1,
    falling: false,
    colorize: false,
    force: 0,
    forceTarget: 0 },

  BLINK: {
    delay: THREE.MathUtils.randInt(100, 300),
    counter: 0,
    length: 7,
    double: false },

  STEPS: [
  {
    altitude: 2,
    impulse: 0.2,
    angle: 10,
    diffStart: 0,
    flyingLerp: 0.05,
    colorStart: '#cfe1e3',
    colorEnd: '.........完整代码请登录后点击上方下载按钮下载查看

网友评论0