three打造三维鼠标跟随小蓝屋效果
代码语言:html
所属分类:三维
代码描述:three打造三维鼠标跟随小蓝屋效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> canvas { width: 100%; height: 100vh; display: block; } a { position: fixed; left: 0; top: 0; padding: 5vmin; color: #eee; } </style> </head> <body translate="no"> <script type="module"> import * as $ from '//unpkg.com/three@0.117.1/build/three.module.js' import { OrbitControls } from '//unpkg.com/three@0.117.1/examples/jsm/controls/OrbitControls.js' import { EffectComposer } from '//unpkg.com/three@0.117.1/examples/jsm/postprocessing/EffectComposer' import { RenderPass } from '//unpkg.com/three@0.117.1/examples/jsm/postprocessing/RenderPass' import { UnrealBloomPass } from '//unpkg.com/three@0.117.1/examples/jsm/postprocessing/UnrealBloomPass' // ---- // Boot // ---- const renderer = new $.WebGLRenderer({ antialias: false }); const scene = new $.Scene(); const camera = new $.PerspectiveCamera(75, 2, .1, 100); const controls = new OrbitControls(camera, renderer.domElement); const composer = new EffectComposer(renderer); 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); }); document.body.prepend(renderer.domElement); window.dispatchEvent(new Event('resize')); renderer.setAnimationLoop(function (t) { animate(t); composer.render(); controls.update(); }); // ---- // Main // ---- renderer.shadowMapEnabled = true; scene.background = new $.Color('black'); camera.position.set(-2, -3, 4); controls.target.set(0, -4, 0); const N_INST = 7; const $froms = Array.from(Array(N_INST), () => new $.Vector3()); //// Make Meshes let tail; { const geom = new $.BoxBufferGeometry(2, 2, 2); const mat = new $.MeshPhongMaterial({ color: 'tomato' }); tail = new $.InstancedMesh(geom, mat, N_INST); tail.castShadow = true; tail.receiveShadow = true; tail.instanceMatrix.setUsage($.DynamicDrawUsage); scene.add(tail); } let wall; { const geom = new $.BoxBufferGeometry(10, 10, 10); const mat = new.........完整代码请登录后点击上方下载按钮下载查看
网友评论0