three打造慌忙中行走的圆柱动画效果

代码语言:html

所属分类:三维

代码描述:three打造慌忙中行走的圆柱动画效果

代码标签: 中行 走的 圆柱 动画 效果

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

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

<style>


body {
    display: grid;
    height: 100vh;
}

canvas {
    width: 100%;
    height: 100vh;
    display: block;
    cursor: -webkit-grab;
    cursor: grab;
    position: fixed;
    top: 0;
    left: 0;
}

a {
    position: relative;
    z-index: 1;
    width: -webkit-min-content;
    width: -moz-min-content;
    width: min-content;
    padding: 5vmin;
    font-family: 'Amatic SC', cursive;
    font-size: 2em;
    color: black;
}
</style>

</head>
<body translate="no">

<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.0/gsap.min.js'></script>
<script type="module">
import * as $ from '//unpkg.com/three@0.118.3/build/three.module.js';
import { OrbitControls } from '//unpkg.com/three@0.118.3/examples/jsm/controls/OrbitControls.js';
import { EffectComposer } from '//unpkg.com/three@0.118.3/examples/jsm/postprocessing/EffectComposer';
import { RenderPass } from '//unpkg.com/three@0.118.3/examples/jsm/postprocessing/RenderPass';
import { UnrealBloomPass } from '//unpkg.com/three@0.118.3/examples/jsm/postprocessing/UnrealBloomPass';

// ----
// Boot
// ----


const renderer = new $.WebGLRenderer({ antialias: true });
const scene = new $.Scene();
const camera = new $.PerspectiveCamera(120, 2, 0.1, 100);
const controls = new OrbitControls(camera, renderer.domElement);
const composer = new EffectComposer(renderer);
const res = new $.Vector2();
window.addEventListener('resize', () => {
  const { clientWidth, clientHeight } = renderer.domElement;
  renderer.setPixelRatio(window.devicePixelRatio);
  renderer.setSize(clientWidth, clientHeight, false);
  camera.aspect = clientWidth / clientHeight;
  camera.updateProjectionMatrix();
  composer.setPixelRatio(window.devicePixelRatio);
  composer.setSize(clientWidth, clientHeight);
  renderer.getDrawingBufferSize(res);
});
document.body.prepend(renderer.domElement);
window.dispatchEvent(new Event('resize'));
renderer.setAnimationLoop(t => {
  composer.render();
  controls.update();
});

// ----
// Main
// ---- 

scene.background = new $.Color().setHSL(0, 0, 0.5);
camera.position.set(7, 5, 7);
controls.autoRotate = true;
renderer.shadowMap.enabled = true;

const light = new $.DirectionalLight('white', 2);
light.position.set(0, 5, 0);
light.castShadow = true;
light.shadow.camera.near = 2;
light.shadow.camera.far = 20;
light.shadow.camera.left = -20;
light.shadow.camera.right = 20;
light.shadow.camera.top = 20;
light.shadow.camera.bottom = -20;
scene.add(light);

class Barrel {
  constructor({ mat, size, height }) {
    this.size = size;
    this.height = height;
    this.mat = mat;
    const { pivot, object } = this.buildMesh();
    this.object = object;
    this.pivot = pivot;
  }

  buildBody(rad, bodyH, legH) {
    const geom = new $.CylinderBufferGeometry(rad, rad, bodyH, 16, 1);
    geom.translate(0, bodyH / 2, 0);
    const mesh = new $.Mesh(geom, this.mat);
    mesh.position.y = legH;
    mesh.castShadow = true;
    return mesh;
  }

  buildLeg(rad, tX, kneeRad, legH) {
    const object = new $.Group();
    //// hip
    const geomHip = new $.SphereBufferGeometry(rad * 1.2, 32, 32);
    const hip = new $.Mesh(geomHip, this.mat);
    hip.position.x = tX;
    object.add(hip);
    //// upper
    const geomUpper = new $.CylinderBufferGeometry(rad, rad, legH / 2);
    geomUpper.translate(0, -legH / 4, 0);
    const upper = new $.Mesh(geomUpper, this.mat);
    hip.add.........完整代码请登录后点击上方下载按钮下载查看

网友评论0