three实现视觉差异滚动方块效果代码

代码语言:html

所属分类:视觉差异

代码描述:three实现视觉差异滚动方块效果代码

代码标签: three 视觉 差异 滚动 方块

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

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

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

  
  
  
<style>
body {
    margin: 0;
    overflow: hidden;
}
</style>

  
</head>

<body translate="no">
  <script type="module">
    import {
        Scene, WebGLRenderer, PerspectiveCamera,
        Mesh, BoxGeometry, MeshNormalMaterial,
        Line, LineBasicMaterial, Vector3, BufferGeometry
    } from "//repo.bfw.wiki/bfwrepo/js/module/three/build/140/three.module.js";

    const factor = {value: 0}
    let currentPosition = 0;
    let targetPosition = 0;

    const renderer = new WebGLRenderer({
        antialias: true
    });
    document.body.appendChild(renderer.domElement);

    const camera = new PerspectiveCamera();
    camera.position.set(0, 0, 5);

    addEventListener("mousewheel", (e) => {
        targetPosition += Math.sign(e.wheelDelta) * 5;
        targetPosition = Math.max(Math.min(0, targetPosition), -20)
    });

    const scene = new Scene();

    for (let i = 0; i < 5; i++) {
        let box = new Mesh(new BoxGeometry(), new MeshNormalMaterial());
        box.position.y = -i * 5
        scene.add(box)
    }

    const lineMaterial = new LineBasicMaterial({
        color: 0xffffff
    });

    lineMaterial.onBeforeCompile = (mat) => {
        mat.uniforms.factor = factor;
        mat.vertexShader = mat.vertexShader
            .split("#include <common>".........完整代码请登录后点击上方下载按钮下载查看

网友评论0