three实现三维过去现在未来时间线穿梭动画效果代码
代码语言:html
所属分类:动画
代码描述:three实现三维过去现在未来时间线穿梭动画效果代码
代码标签: three 三维 过去 现在 未来 时间线 穿梭 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url('https://api.fontshare.com/v2/css?f[]=tanker@400&display=swap" rel="stylesheet'); body { margin: 0; background-color: #060402; overflow: hidden; } canvas { touch-action: initial !important; } .container { position: absolute; top: 0; left: 0; color: #fcfcfc; font-family: tanker; height: 100vh; width: 100vw; } .container .label { position: absolute; font-size: min(80px, 10vmin); overflow: visible; } .container .presentLabel { left: 0%; right: 0%; top: 10%; text-align: center; transform-origin: 50% 200%; } .container .pastLabel { left: 13%; bottom: 52%; } .container .futureLabel { right: 20%; top: 10%; } </style> </head> <body > <div class="container"> <div class="label presentLabel" style="transform:scale(0)">Present</div> <div class="label futureLabel" style="transform:scale(0)">Future</div> <div class="label pastLabel" style="transform:scale(0)">Past</div> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.89.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> <script > class ThreeSketch { constructor() { this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true }); this.renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(this.renderer.domElement); this.framerate = 60; this.scene = new THREE.Scene(); this.camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.01, 10000); /* this.controls = new THREE.OrbitControls( this.camera, this.renderer.domElement ); this.controls.enableDamping=true; this.controls.rotateSpeed=0.4; */ //controls.update() must be called after any manual changes to the camera's transform this.camera.position.set(2, 2, 10); //this.controls.update(); window.addEventListener("resize", () => { this.onResize(); }); this.onResize(); } onResize() { const width = window.innerWidth; const height = window.innerHeight; this.camera.aspect = width / height; this.camera.updateProjectionMatrix(); this.renderer.setSize(width, height + 1); } animate(callback) { if (callback) { this.animFrameCallBack = callback; } setTimeout(() => { this.animate(); }, 1000 / this.framerate); try { // required if controls.enableDamping or controls.autoRotate are set to true this.controls?.update(); if (this.animFrameCallBack) { this.animFrameCallBack(); } this.renderer.render(this.scene, this.camera); } catch (ex) { console.log(ex); } }} class LineSet { constructor(three, numberOfLines, temporalScale) { this.temporalScale = temporalScale; this.three = three; this.numberOfLines = numberOfLines; this.setupThing(); } setupThing() { this.lineSegments = []; const geometry = new THREE.BoxGeometry(1, 1, 1); const lineMaterial = new THREE.MeshBasicMaterial({ color: 0xfcfcfc, side: THREE.DoubleSide }); for (var i = 0; i < this.numberOfLines; i++) { const line = new THREE.Mesh(geometry, lineMaterial); line.scale.x = 0.01; line.scale.z = 0.01; this.three.scene.add(line); this.lineSegments.push(line); } } setScale(scale) { this.spacing = scale; this.heights = scale; } lineHeight(inp) { var func = x => 2.74 ** -(x ** 4); var pln = x => Math.log(x + 1); return pln(func(inp / 40) * 4); } update(timePos) { for (var i = 0; i < this.numberOfLines; i++) { var seg = this.lineSegments[i]; var offset = (i - this.numberOfLines / 2) * this.temporalScale; var loopPos = this.temporalScale * (timePos / (1000 * this.tem.........完整代码请登录后点击上方下载按钮下载查看
网友评论0