three实现三维时空轨道穿梭动画效果代码

代码语言:html

所属分类:动画

代码描述:three实现三维时空轨道穿梭动画效果代码

代码标签: three 三维 时空 轨道 穿梭 动画

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

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

<head>
  <meta charset="UTF-8">
  

  <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/reset.min.css">
  
<style>
canvas {
    display:block; width:100%; height:100vh;
}
</style>


  
</head>

<body >
  
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.123.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/CopyShader.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ShaderPass.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/EffectComposer.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/LuminosityHighPassShader.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/RenderPass.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/UnrealBloomPass.js"></script>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/CurveExtras.js"></script>
      <script  type="module">


const renderer = new THREE.WebGLRenderer({});
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, 2, .01, 5000);
window.addEventListener('resize', () => {
  const { clientWidth, clientHeight } = renderer.domElement;
  renderer.setSize(clientWidth, clientHeight, false);
  renderer.setPixelRatio(window.devicePixelRatio);
  camera.aspect = clientWidth / clientHeight;
  camera.updateProjectionMatrix();
});
document.body.prepend(renderer.domElement);
window.dispatchEvent(new Event('resize'));

// ---- setup

scene.fog = new THREE.FogExp2('black', 0.05);
scene.add(new THREE.HemisphereLight('cyan', 'orange', 2));

// ---- const

const mpms = 20 / 1e3;
const steps = 2000;

// ---- mesh

const shape = new THREE.Shape();
// cw
shape.moveTo(-5, -1);
shape.quadraticCurveTo(0, -4, 5, -1);
shape.lineTo(6, -1);
shape.quadraticCurveTo(0, -5, -6, -1);
const extrudePath = new THREE.TorusKnot();
const UVGenerator = (() => {
  let i = 0; // face id
  return {
    generateTopUV(...xs) {// for 2 "cap" faces
      return [new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2()];
    },
    generateSideWallUV(_geom, _vs, _a, _b, _c, _d) {// all side faces
      const segments = 5; // (shape-related; NOT eq `curveSegments`)
      if (i < segments * steps) {// ignore bottom road faces
        ++i;
        return [new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2()];
      }
      const n = i - segments * steps; // offseted face idx
      const total_col_segments = 7; // (shape-related) 
      const col = n / steps | 0;
      const left = col / total_col_segments; // normalize
      const right = (col + 1) / total_col_segments; // normalize
      co.........完整代码请登录后点击上方下载按钮下载查看

网友评论0