gsap+three实现三维立方体塑形动画效果代码
代码语言:html
所属分类:三维
代码描述:gsap+three实现三维立方体塑形动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<html lang="en"> <head> <meta charset="UTF-8"> <style> canvas { display: block; width: 100vw; height: 100vh; cursor: -webkit-grab; cursor: grab; } a { position: fixed; top: 0; left: 0; padding: 5vmin; } </style> </head> <body> <canvas width="528" height="460" style="display: block;"></canvas> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.5.2.js"></script> <script type="module"> import * as $ from '//unpkg.com/three@0.123.0/build/three.module.js' import { OrbitControls } from '//unpkg.com/three@0.123.0/examples/jsm/controls/OrbitControls.js' import { EffectComposer } from '//unpkg.com/three@0.123.0/examples/jsm/postprocessing/EffectComposer' import { RenderPass } from '//unpkg.com/three@0.123.0/examples/jsm/postprocessing/RenderPass' import { UnrealBloomPass } from '//unpkg.com/three@0.123.0/examples/jsm/postprocessing/UnrealBloomPass' import { BokehPass } from '//unpkg.com/three@0.123.0/examples/jsm/postprocessing/BokehPass' // ---- // Boot // ---- const renderer = new $.WebGLRenderer({ antialias: true }); const scene = new $.Scene(); const camera = new $.PerspectiveCamera(45, 2, .1, 1000); const controls = new OrbitControls(camera, renderer.domElement); const composer = new EffectComposer(renderer); const drawingBufferSize = 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(drawingBufferSize); }); document.body.prepend(renderer.domElement); window.dispatchEvent(new Event('resize')); renderer.setAnimationLoop(() => { composer.render(); controls.update(); }); // ---- // Main // ---- const SZ = 32; // dim = SZ * SZ const ISZ = 2; // item sz scene.background = new $.Color('white'); camera.position.set(-30, 20, -30); controls.autoRotate = true; controls.autoRotateSpeed = 0.2; const light = new $.DirectionalLight('white', 1); scene.add(light); class Inst { //// 3js inst wrapper for gsap constructor(mesh, idx, r, g, b, x, z) { .........完整代码请登录后点击上方下载按钮下载查看
网友评论0