three实现鼠标跟随三维立方体沙盘三维像素液态效果代码
代码语言:html
所属分类:三维
代码描述:three实现鼠标跟随三维立方体沙盘三维像素液态效果代码
代码标签: three 立方体 沙盘 三维 像素 液态 鼠标跟随
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> <style> body { font-family: Monospace; background-color: #f0f0f0; margin: 0px; overflow: hidden; } #info { position: absolute; top: 0px; width: 100%; padding: 5px; text-align:center; } </style> </head> <body> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Detector.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/RequestAnimationFrame.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/stats-min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.46.js"></script> <script> var size = 10, res = 32, sizeres = size * res, halfsizeres = sizeres / 2; var buffer1 = [], buffer2 = [], temp; var grid = [], plane; var scene, camera, light, renderer; var geometry, material; var mouse, projector, ray, intersects = []; var stats; if ( Detector.webgl ) { init(); animate(); } else { document.body.appendChild( Detector.getWebGLErrorMessage() ); } function init() { var container = document.createElement( 'div' ); document.body.appendChild( container ); stats = new Stats(); stats.domElement.style.position = 'absolute'; stats.domElement.style.top = '0px'; // container.appendChild( stats.domElement ); for ( var i = 0, l = res * res; i < l; i ++ ) { buffer1[ i ] = 0; buffer2[ i ] = 0; } scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 ); camera.position.x = 100 + sizeres; camera.position.y = 200; camera.position.z = 100 + sizeres; camera.lookAt( new THREE.Vector3( halfsizeres, - 50, halfsizeres ) ); scene.add( camera ); scene.add( new THREE.AmbientLight( 0x808080 ) ); light = new THREE.SpotLight( 0xffffff, 1.25 ); light.position.set( - 500, 900, 600 ); light.target.position.set( halfsizeres, 0, halfsizeres ); light.castShadow = true; scene.add( light ); geometry = new THREE.CubeGeometry( size, size, size ); geometry.applyMatrix( new THREE.Matrix4().setTranslation( 0, size / 2, 0 ) ); material = new THREE.MeshLambertMaterial( { color: 0xd0d0d0 } ); for ( var i = 0, l = res * res; i < l; i ++ ) { cube = new THREE.Mesh( geometry, material ); cube.position.x = size + ( ( i % res ) * 10 ); cube.position.z = size + ( Math.floor( i / res ) * 10 ); cube.castShadow = true; cube.receiveShadow = true; scene.add( cube ); grid.push( cube ); } geometry = new THREE.PlaneGeometry( sizeres, sizeres ); plane = new THREE.Mesh( geometry, material ); plane.position.x = halfsizeres; plane.position.z = halfsizeres; plane.rotation.x = - 90 * M.........完整代码请登录后点击上方下载按钮下载查看
网友评论0