three打造三维走光金灿灿的播放按钮效果代码

代码语言:html

所属分类:三维

代码描述:three打造三维走光金灿灿的播放按钮效果代码

代码标签: 走光 金灿灿 播放 按钮 效果

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

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

<head>

  <meta charset="UTF-8">
  

<style>
canvas {
    display:block; width:100%; height:100vh; cursor: -webkit-grab; cursor: grab;
}
</style>




</head>

<body>
  


  
      <script  type="module">
import * as $ from '//cdn.skypack.dev/three@0.125.0/build/three.module.js?min';
import { OrbitControls } from '//cdn.skypack.dev/three@0.125.0/examples/jsm/controls/OrbitControls.js?min';
import { EffectComposer } from '//cdn.skypack.dev/three@0.125.0/examples/jsm/postprocessing/EffectComposer.js?min';
import { RenderPass } from '//cdn.skypack.dev/three@0.125.0/examples/jsm/postprocessing/RenderPass.js?min';
import { UnrealBloomPass } from '//cdn.skypack.dev/three@0.125.0/examples/jsm/postprocessing/UnrealBloomPass.js?min';

//// Boot

const renderer = new $.WebGLRenderer({});
const scene = new $.Scene();
const camera = new $.PerspectiveCamera(75, 2, .1, 1000);
const controls = new OrbitControls(camera, renderer.domElement);
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

camera.position.set(0, 0, 15);
scene.add(new $.AmbientLight('white', 1));
scene.background = new $.Color('#aaa');
renderer.shadowMap.enabled = true;

//// Ortho Projectors 

function ortho_projector({ url }) {
  const camera = new $.OrthographicCamera(-20, 20, 20, -20, 0, 1000);
  camera.position.set(0, 0, 9999);
  camera.updateMatrixWorld(true);
  const texture = new $.TextureLoader().load(url, tex => {
    camera.left *= tex.image.width / tex.image.height;
    camera.right *= tex.image.width / tex.image.height;
    camera.updateProjectionMatrix();
    helper.update();
  });
  const helper = new $.CameraHelper(camera);
  // scene.add(helper);
  const light = new $.DirectionalLight('white', 0.5);
  light.castShadow = true;
  light.shadow.camera = camera;
  light.shadow.bias = -0.001;
  scene.add(light);
  return { camera, texture, helper, light };
}

const url0 = '//repo.bfw.wiki/bfwrepo/image/5e2b80eb53d22.png';
const url1 = '//repo.bfw.wiki/bfwrepo/image/5d65ea7d8bc8b.png';
const url2 = '//repo.bfw.wiki/bfwrepo/image/5d65ea7d8bc8b.png';
const projectors = [
ortho_projector({ url: url0 }),
ortho_projector({ url: url1 }),
ortho_projector({ url: url2 })];


//// Mat

const tl = new $.TextureLoader();
const mats = [];
const mat0 = f({ side: $.FrontSide, color: new $.Color('silver') }, projectors);
const mat1 = f({ side: $.FrontSide, color: new $.Color('gold') }, projectors);
mats.push(mat0, mat1);

//// Meshes

{
  function onBeforeRender() {
    for (const [i, projector] of this.material.userData.projectors.entries()) {
      this.material.uniforms.projectors.value[i].normalMatrix.getNormalMatrix(
      projector.camera.matrixWorldInverse.clone().multiply(this.matrixWorld));

    }
  };
  const mesh0 = new $.Mesh(new $.TorusBufferGeometry(10, 2, 3, 3), mat0);
  mesh0.onBeforeRender = onBeforeRender;
  scene.add(mesh0);
  mesh0.receiveShadow = mesh0.castShadow = true;

  const mesh1 = new $.Mesh(new $.TorusBufferGeometry(10, 8, 3, 3), mat1);
  mesh1.onBeforeRender = onBeforeRender;
  mesh1.scale.set(0.4, 0.4, 0.25);
  scene.add(mesh1);
  mesh1.receiveShadow = mesh1.castShadow = true;
}

//// fx

const fx = new.........完整代码请登录后点击上方下载按钮下载查看

网友评论0