-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebgl-sqlstream.min.js
1 lines (1 loc) · 6.62 KB
/
webgl-sqlstream.min.js
1
"use strict";function WebGL(){function e(){o.torusCreated?(o.removeTorus(),o.createTorus()):(o.removeLandscape(),o.createLandscape())}function t(){o.createLandscape(),o.animate(),o.bindEventListeneres()}var a,o=this,r=new dat.GUI;this.torusCreated=!1,this.defaultParams={width:window.innerWidth,height:window.innerHeight,container:"#webgl-container",models:{landscape:"./models/landscape.json"},torus:{color:"#AAAAAA",color1:"#00cea0",color2:"#fd8925",model:{},initVertices:[],centroid:new THREE.Vector3,height:.04,frequency:100,amplifier:2,radius:.8,thickness:.13,radialSegments:96,tubularSegments:96,distance:-2.4},landscape:{model:{},initVertices:[],animate:!0,width:6,height:3,widthSegments:96,heightSegments:96},renderer:{alpha:!0,antialias:!0}},this.Utils={onWindowResize:function(){o._WIDTH=window.innerWidth,o._HEIGHT=window.innerHeight,o._CAMERA.aspect=o._WIDTH/o._HEIGHT,o._CAMERA.updateProjectionMatrix(),o._RENDERER.setSize(o._WIDTH,o._HEIGHT)},checkValue:function(e,t){var a;return a=0>=e?e-t:e+t},calcSin:function(e,t){var a=e+Math.sin(t*o.torus.height);return a}},this.config=function(n){var s=n.container||o.defaultParmas.container,i=n.renderer||o.defaultParmas.renderer;o.torus=this.defaultParams.torus,o.torus.color=n.torus.color,o.torus.color1=n.torus.color1,o.torus.color2=n.torus.color2,o.torus.height=n.torus.height,o.torus.frequency=n.torus.frequency,o.torus.amplifier=n.torus.amplifier,o.torus.radius=n.torus.radius,o.torus.thickness=n.torus.thickness,o.torus.radialSegments=n.torus.radialSegments,o.torus.tubularSegments=n.torus.tubularSegments,o.landscape=o.defaultParams.landscape,o.landscape.animate=n.landscape.animate;var d=r.addFolder("Shared Options");d.open(),d.addColor(o.torus,"color").onChange(e),d.addColor(o.torus,"color1").onChange(e),d.addColor(o.torus,"color2").onChange(e),d.add(o.torus,"frequency",1,1e3).onFinishChange(e),d.add(o.torus,"amplifier",.1,16).onFinishChange(e);var l=r.addFolder("Landscape");l.open(),l.add(o.landscape,"width",1,24).onFinishChange(e),l.add(o.landscape,"height",1,24).onFinishChange(e),l.add(o.landscape,"widthSegments",16,256).onFinishChange(e),l.add(o.landscape,"heightSegments",16,256).onFinishChange(e);var c=r.addFolder("Torus");c.add(o.torus,"radius",.1,2).onFinishChange(e),c.add(o.torus,"thickness",.01,1).onFinishChange(e),c.add(o.torus,"radialSegments",1,256).onFinishChange(e),c.add(o.torus,"tubularSegments",1,256).onFinishChange(e),a=new Stats,a.showPanel(0),a.domElement.style.position="absolute",a.domElement.style.top=0,document.body.appendChild(a.domElement),this._WIDTH=n.width||o.defaultParmas.width,this._HEIGHT=n.height||o.defaultParmas.height,this._CONTAINER=document.querySelector(s),this.isChanging=!1,this._RENDERER=new THREE.WebGLRenderer({alpha:i.alpha,antialias:i.antialias}),this._RENDERER.setSize(this._WIDTH,this._HEIGHT),this._RENDERER.getPixelRatio(window.devicePixelRatio||1),this._CONTAINER.appendChild(this._RENDERER.domElement),this._SCENE=new THREE.Scene,this._CAMERA=new THREE.PerspectiveCamera(65,this._WIDTH/this._HEIGHT,.01,1e3),this._CAMERA.position.z=.1,t()};var n=0;noise.seed(Math.random()),this.setTorusPosition=function(e,t,a){o.torus.model.position.set(e,t,a)},this.animateTorusPosition=function(e,t,a,r){TweenLite.to(o.torus.model.position,r,{x:e,y:t,z:a})},this.updateTorus=function(){var e,t,a,r,s,i,d,l=n/o.torus.frequency;if(void 0!==o.torus.model.geometry){for(var c=o.torus.initVertices,u=o.torus.model.geometry.attributes.position||[],h=0,m=u.count;m>h;h++)e=c[3*h],t=c[3*h+1],a=c[3*h+2],r=noise.simplex3(e*o.torus.amplifier,t*o.torus.amplifier,l),s=o.Utils.calcSin(e,o.Utils.checkValue(e,r)),i=o.Utils.calcSin(t,o.Utils.checkValue(t,r)),d=o.Utils.calcSin(a,o.Utils.checkValue(a,r)),u.array[3*h]=s,u.array[3*h+1]=i,u.array[3*h+2]=d;u.needsUpdate=!0}},this.updateLandscape=function(){var e,t,a,r=n/o.torus.frequency*.6;if(void 0!==o.landscape.model.geometry){for(var s=o.landscape.initVertices,i=o.landscape.model.geometry.attributes.position,d=0,l=i.count;l>d;d++)e=s[3*d],t=s[3*d+1],a=.8*noise.perlin3(e,t,r),i.array[3*d+2]=s[3*d+2]+a;i.needsUpdate=!0}},this.createTorus=function(){console.log("torus created");for(var e=new THREE.TorusBufferGeometry(o.torus.radius,o.torus.thickness,o.torus.radialSegments,o.torus.tubularSegments),t=e.attributes.position,a=0,r=t.count;r>a;a++)t.array[3*a+1]+=.02*Math.random();t.needsUpdate=!0;for(var t=e.attributes.position,a=0,r=t.array;r>a;a++)t.array[a]+=Math.random();o.torus.model=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:o.torus.color,wireframe:!0,transparent:!0,opacity:.4}));var n=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:16777215})),s=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:new THREE.Color(o.torus.color1),wireframe:!0,transparent:!0,opacity:.16})),i=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:new THREE.Color(o.torus.color2),wireframe:!0,transparent:!0,opacity:.16}));o.torus.model.position.z=o.torus.distance,o.torus.model.add(n),o.torus.model.add(s),o.torus.model.add(i),s.rotation.x=Math.PI,i.rotation.y=Math.PI,o.torus.initVertices=new Float32Array(o.torus.model.geometry.attributes.position.array),o._SCENE.add(o.torus.model)},this.removeTorus=function(){o._SCENE.remove(o.torus.model)},this.createLandscape=function(){console.log("landscape created");for(var e=new THREE.PlaneBufferGeometry(o.landscape.width,o.landscape.height,o.landscape.widthSegments,o.landscape.heightSegments),t=e.attributes.position,a=0,r=t.count;r>a;a++)t.array[3*a+2]+=.02*Math.random();t.needsUpdate=!0,o.landscape.model=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:o.torus.color,wireframe:!0,transparent:!0,opacity:.8}));var n=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:16777215,side:THREE.DoubleSide})),s=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:new THREE.Color(o.torus.color1),wireframe:!0,transparent:!0,opacity:.06})),i=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:new THREE.Color(o.torus.color2),wireframe:!0,transparent:!0,opacity:.06}));o.landscape.model.add(s),o.landscape.model.add(i),o.landscape.model.add(n),s.rotation.x=Math.PI,i.rotation.z=Math.PI,o.landscape.model.position.z=-1.6,o.landscape.model.position.y=-.8,o.landscape.model.rotation.x=Math.PI/2,o.landscape.initVertices=new Float32Array(o.landscape.model.geometry.attributes.position.array),o._SCENE.add(o.landscape.model)},this.removeLandscape=function(){o._SCENE.remove(o.landscape.model)},this.render=function(){o._RENDERER.render(this._SCENE,this._CAMERA)};return this.update=function(){n++,o.landscape.animate&&o.updateLandscape(),o.torus.animate&&o.updateTorus()},this.animate=function(){a.begin(),o.update(),o.render(),a.end(),requestAnimationFrame(o.animate)},this.bindEventListeneres=function(){window.addEventListener("resize",o.Utils.onWindowResize,!1)},this}