三维液体网格波动效果
代码语言:html
所属分类:三维
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> html, body { margin: 0; } canvas { display: block; } </style> </head> <body translate="no"> <canvas id="canvas"></canvas> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/three.109.js"></script> <script src='http://repo.bfw.wiki/bfwrepo/js/OrbitControls.js'></script> <script > function App() { const conf = { el: 'canvas', fov: 75, cameraZ: 100 }; let renderer, scene, camera, cameraCtrl; let width, height, cx, cy, wWidth, wHeight; let ripple; let gridWWidth, gridWHeight; let gridWidth, gridHeight; const mouse = new THREE.Vector2(); const mousePlane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0); const mousePosition = new THREE.Vector3(); const raycaster = new THREE.Raycaster(); let mouseOver = false; init(); function init() { // const gl = renderer.getContext(); // const floatTextures = gl.getExtension('OES_texture_float'); // if (!floatTextures) { // alert('no floating point texture support'); // return; // } renderer = new THREE.WebGLRenderer({ canvas: document.getElementById(conf.el), antialias: true }); camera = new THREE.PerspectiveCamera(conf.fov); camera.position.z = conf.cameraZ; updateSize(); window.addEventListener('resize', updateSize, false); // gridWHeight = wHeight - 20; // gridWWidth = gridWHeight; gridWHeight = wHeight; gridWWidth = wWidth; gridWidth = gridWWidth * width / wWidth; gridHeight = gridWHeight * height / wHeight; ripple = new RippleEffect(renderer, width, height); const getGridMP = function (e) { const v = new THREE.Vector3(); camera.getWorldDirection(v); v.normalize(); mouse.x = e.clientX / width * 2 - 1; mouse.y = -(e.clientY / height) * 2 + 1; raycaster.setFromCamera(mouse, camera); raycaster.ray.intersectPlane(mousePlane, mousePosition); return {.........完整代码请登录后点击上方下载按钮下载查看
网友评论0