three实现三维夜晚地球灯光飞行轨迹效果代码
代码语言:html
所属分类:三维
代码描述:three实现三维夜晚地球灯光飞行轨迹效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html { background: black; height: 100%; overflow: hidden; } body { height: 100%; margin: 0; padding: 0; position: relative; z-index: 10; } canvas { -webkit-animation: in 2s cubic-bezier(0.23, 1, 0.32, 1) 0.25s backwards; animation: in 2s cubic-bezier(0.23, 1, 0.32, 1) 0.25s backwards; background: transparent; position: absolute; } @-webkit-keyframes in { from { opacity: 0; } } @keyframes in { from { opacity: 0; } } </style> </head> <body > <div id='container'></div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.75.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/extras.js"></script> <script > 'use strict'; var Earth = function (el, data) { let camera, scene, renderer, composer, w, h; let lines = [], mouse = { x: 0, y: 0 }, mouseOnDown = { x: 0, y: 0 }, points = [], rotation = { x: Math.PI * 1.9, y: Math.PI / 6 }, target = { x: Math.PI * 1.9, y: Math.PI / 6 }, targetOnDown = { x: 0, y: 0 }; const center = new THREE.Vector3(0, 0, 0), clock = new THREE.Clock(), distance = 350, PI_HALF = Math.PI / 2, pointRadius = 152, radius = 150; // Shaders // https://github.com/dataarts/webgl-globe const shaders = { 'atmosphere': { uniforms: {}, vertexShader: [ 'varying vec3 vNormal;', 'void main() {', 'vNormal = normalize( normalMatrix * normal );', 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}']. join('\n'), fragmentShader: [ 'varying vec3 vNormal;', 'void main() {', 'float intensity = pow( 0.8 - dot( vNormal, vec3( 0, 0, 1.0 ) ), 3.0 );', 'gl_FragColor = vec4( 0.3, 0.4, 0.6, 0.05 ) * intensity;', '}']. join('\n') } }; // ------------------------------------- // Init // ------------------------------------- function init() { w = window.innerWidth; h = window.innerHeight; camera = new THREE.PerspectiveCamera(distance / 5, w / h, 1, distance * 2); scene = new THREE.Scene(); scene.add(camera); // Stars // http://gielberkers.com/evenly-distribute-particles-shape-sphere-threejs/ let starGeometry = new THREE.Geometry(); for (let i = 0; i < 1000; i++) { let x = -1 + Math.random() * 2; let y = -1 + Math.random() * 2; let z = -1 + Math.random() * 2; const d = 1 / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)); x *= d; y *= d; z *= d; const vertex = new THREE.Vector3( x * distance, y * distance, z * distance); starGeometry.vertices.push(vertex); } const stars = new THREE.Points(starGeometry, new THREE.PointsMaterial({ color: '#555555', size: 3 })); scene.add(stars); // Light let light = new THREE.PointLight('#ffffff', 0.5); camera.add(light); light.position.set(distance / 2, distance / 2, 0); light.target = camera; // Earth THREE.ImageUtils.crossOrigin = ''; var earthLights = THREE.ImageUtils.loadTexture('//repo.bfw.wiki/bfwrepo/image/62f3a70f24bd3.png'); var earthBump = THREE.ImageUtils.loadTexture('//repo.bfw.wiki/bfwrepo/image/62f3a6e7ec864.png'); earthLights.minFilter = THREE.LinearFilter; earthBump.minFilter = THREE.LinearFilter; var earthGeometry = new THREE.SphereGeometry(radius, 50, 30); var earthMaterial = new THREE.MeshPhongMaterial({ bumpMap: earthBump, bumpScale: 4, emissiveMap: earthLights, emissive: '#333333', map: earthLights, specular: '#010101' }); const earth = new THREE.Mesh(earthGeometry, earthMaterial); scene.add(earth); // Atmosphere const atmosphereMaterial = new THREE.ShaderMaterial({ vertexShader: shaders['atmosph.........完整代码请登录后点击上方下载按钮下载查看
网友评论0