gsap折纸飞行动画效果

代码语言:html

所属分类:动画

代码描述:gsap折纸飞行动画效果

代码标签: 动画 效果

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

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

<style>


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

a {
    display: block;
    color: black;
    padding: 5vmin;
    width: -webkit-min-content;
    width: -moz-min-content;
    width: min-content;
    font-family: 'nova mono', monospace;
    position: relative; z-index: 1;
}

a:after {
    display: block;
    content: "#2374C6, #C20F00, #FFDD22, #FFFFFF, #000000."
}

body {
    display: block;
    height: 100vh;
}
</style>

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

<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/gsap.3.3.1.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(75, 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
// ---- 

const BLUEISH = '#2374C6';
const REDISH = '#C20F00';
const YELLOWISH = '#FFDD22';
const BLACK = '#000000';
const WHITE = '#FFFFFF';

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

const light = new $.DirectionalLight(WHITE, 1.2);
light.position.set(0, 5, 0);
light.castShadow = true;
light.shadow.camera.near = 1;
light.shadow.camera.far = 10;
light.shadow.camera.left = -10;
light.shadow.camera.right = 10;
light.shadow.camera.top = 10;
light.shadow.camera.bottom = -10;
light.shadow.bias = -0.01;
scene.add(light);

//// Generalize https://codepen.io/ycw/pen/ExKyJdR?editors=0010 `class Box`

class F {
    constructor({ mat, size }) {
        this.size = size;
        this.mat = mat;
        const { pivot, object } = this.buildMesh();
        this.object = object;
        this.pivot = pivot;
    }
    buildPivot(w, h, d, tx, ty, tz, px, py, pz) {
        const geom = new $.BoxBufferGeometry(w, h, d);
        geom.translate(tx, ty, tz);
        const pivot = new $.Mesh(geom, this.mat);
        pivot.position.set(px, py, pz);
        pivot.castShadow = true;
        pivot.receiveShadow = true;
        return pivot;
    }
    buildMesh() { // t-pose on xz heading to z-
        const SZ = this.size;
        const S = SZ / 2; // box half size
        const T = SZ / 50; // thickness
        const pivot = {};
        pivot.right = this.buildPivot(SZ * 2, T, SZ, SZ, 0, 0, S, 0, 0);
        pivot.left = this.buildPivot(SZ * 2, T, SZ, -SZ, 0, 0, -S, 0, 0);
        pivot.body = this.buildPivot(SZ, T, SZ, 0, 0, 0, 0, 0, 0);
        pivot.head = this.buildPivot(SZ, T, SZ, 0, 0, -S, 0, 0, -S);
        pivot.head.rotation.x = Math.PI / 20;
        pivot.uppertail = this.buildPivot(SZ, T, SZ, 0, 0, S, 0, 0, S);
        pivot.lowertail = this.buildPivot(SZ, T, SZ, 0, 0, S, 0, 0, SZ);
        const object = new $.Group();
        object.add(pivot.right);
        object.add(pivot.left);
        object.add(pivot.body);
        object.add(pivot.head);
        object.add(pivot.uppertail);
        pivot.uppertail.add(pivot.lowertail);
   .........完整代码请登录后点击上方下载按钮下载查看

网友评论0