├── js └── threejs │ ├── .gitignore │ ├── examples │ └── js │ │ ├── loaders │ │ ├── ctm │ │ │ ├── CTMWorker.js │ │ │ └── license │ │ │ │ ├── OpenCTM.txt │ │ │ │ ├── js-lzma.txt │ │ │ │ └── js-openctm.txt │ │ ├── VTKLoader.js │ │ ├── PLYLoader.js │ │ └── ObjectLoader.js │ │ ├── PRNG.js │ │ ├── shaders │ │ ├── BasicShader.js │ │ ├── CopyShader.js │ │ ├── LuminosityShader.js │ │ ├── ColorifyShader.js │ │ ├── ColorCorrectionShader.js │ │ ├── BlendShader.js │ │ ├── SepiaShader.js │ │ ├── UnpackDepthRGBAShader.js │ │ ├── MirrorShader.js │ │ ├── DOFMipMapShader.js │ │ ├── NormalMapShader.js │ │ ├── RGBShiftShader.js │ │ ├── KaleidoShader.js │ │ ├── BrightnessContrastShader.js │ │ ├── VignetteShader.js │ │ ├── BleachBypassShader.js │ │ ├── DotScreenShader.js │ │ ├── HueSaturationShader.js │ │ ├── VerticalBlurShader.js │ │ ├── HorizontalBlurShader.js │ │ ├── TriangleBlurShader.js │ │ ├── EdgeShader2.js │ │ ├── VerticalTiltShiftShader.js │ │ ├── HorizontalTiltShiftShader.js │ │ ├── FresnelShader.js │ │ ├── ConvolutionShader.js │ │ ├── FocusShader.js │ │ ├── FilmShader.js │ │ ├── FXAAShader.js │ │ ├── EdgeShader.js │ │ └── BokehShader.js │ │ ├── postprocessing │ │ ├── TexturePass.js │ │ ├── ShaderPass.js │ │ ├── RenderPass.js │ │ ├── SavePass.js │ │ ├── DotScreenPass.js │ │ ├── FilmPass.js │ │ ├── MaskPass.js │ │ ├── EffectComposer.js │ │ └── BloomPass.js │ │ ├── math │ │ ├── ColorConverter.js │ │ └── TypeArrayVector3.js │ │ ├── libs │ │ ├── system.min.js │ │ ├── stats.min.js │ │ └── tween.min.js │ │ ├── modifiers │ │ └── ExplodeModifier.js │ │ ├── effects │ │ ├── CrosseyedEffect.js │ │ ├── ParallaxBarrierEffect.js │ │ ├── AnaglyphEffect.js │ │ ├── OculusRiftEffect.js │ │ └── AsciiEffect.js │ │ ├── Detector.js │ │ ├── exporters │ │ ├── MaterialExporter.js │ │ ├── OBJExporter.js │ │ └── GeometryExporter.js │ │ ├── ImprovedNoise.js │ │ ├── controls │ │ ├── PointerLockControls.js │ │ ├── EditorControls.js │ │ └── FirstPersonControls.js │ │ ├── AudioObject.js │ │ ├── UVsUtils.js │ │ ├── MD2Character.js │ │ ├── renderers │ │ └── CSS3DRenderer.js │ │ ├── Cloth.js │ │ ├── ParametricGeometries.js │ │ └── CurveExtras.js │ └── LICENSE ├── README.md ├── demo └── path.json └── index.html /js/threejs/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | .project 4 | utils/npm/node_modules/* -------------------------------------------------------------------------------- /js/threejs/examples/js/loaders/ctm/CTMWorker.js: -------------------------------------------------------------------------------- 1 | importScripts( "lzma.js", "ctm.js" ); 2 | 3 | self.onmessage = function( event ) { 4 | 5 | var files = []; 6 | 7 | for ( var i = 0; i < event.data.offsets.length; i ++ ) { 8 | 9 | var stream = new CTM.Stream( event.data.data ); 10 | stream.offset = event.data.offsets[ i ]; 11 | 12 | files[ i ] = new CTM.File( stream ); 13 | 14 | } 15 | 16 | self.postMessage( files ); 17 | self.close(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /js/threejs/examples/js/PRNG.js: -------------------------------------------------------------------------------- 1 | // Park-Miller-Carta Pseudo-Random Number Generator 2 | // https://github.com/pnitsch/BitmapData.js/blob/master/js/BitmapData.js 3 | 4 | var PRNG = function () { 5 | 6 | this.seed = 1; 7 | this.next = function() { return (this.gen() / 2147483647); }; 8 | this.nextRange = function(min, max) { return min + ((max - min) * this.next()) }; 9 | this.gen = function() { return this.seed = (this.seed * 16807) % 2147483647; }; 10 | 11 | }; 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | three.js-camera-path-tool 2 | ========================= 3 | 4 | Crude tool for building camera paths for three.js scenes. 5 | 6 | 7 | KEY CONTROLS 8 | ------------ 9 | 10 | = Add Path 11 | 12 | \- Remove Path 13 | 14 | Click and drag to rotate camera 15 | Use Mouse Wheel to Zoom In/Out 16 | 17 | Click Nodes to Move 18 | 19 | Click off Node to Deselect 20 | 21 | UP/DOWN/LEFT/RIGHT Translate Node on Y or X Axis 22 | 23 | OPTION + UP/DOWN Translate Node on Z Axis 24 | 25 | W/A/S/D Rotate Node 26 | 27 | SHIFT Moves Faster 28 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/BasicShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://www.mrdoob.com 3 | * 4 | * Simple test shader 5 | */ 6 | 7 | THREE.BasicShader = { 8 | 9 | uniforms: {}, 10 | 11 | vertexShader: [ 12 | 13 | "void main() {", 14 | 15 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 16 | 17 | "}" 18 | 19 | ].join("\n"), 20 | 21 | fragmentShader: [ 22 | 23 | "void main() {", 24 | 25 | "gl_FragColor = vec4( 1.0, 0.0, 0.0, 0.5 );", 26 | 27 | "}" 28 | 29 | ].join("\n") 30 | 31 | }; 32 | -------------------------------------------------------------------------------- /demo/path.json: -------------------------------------------------------------------------------- 1 | {"vertices": [ 2 | {"x": -37, "y": 80, "z": 370}, 3 | {"x": 76, "y": 41, "z": 274}, 4 | {"x": 195, "y": 35, "z": 164}, 5 | {"x": 97, "y": 41, "z": 156}, 6 | {"x": -3, "y": 55, "z": 245}, 7 | {"x": -218, "y": 37, "z": 176}, 8 | {"x": -228, "y": 33, "z": 58}, 9 | {"x": 3, "y": 12, "z": -29}, 10 | {"x": 81, "y": 46, "z": -220}, 11 | {"x": 272, "y": 30, "z": -347}, 12 | {"x": 349, "y": 33, "z": -270}, 13 | {"x": 251, "y": 38, "z": -209}, 14 | {"x": 76, "y": 31, "z": -274}, 15 | {"x": -127, "y": 48, "z": -355}, 16 | {"x": -320, "y": 100, "z": -359}, 17 | {"x": -373, "y": 84, "z": -398} 18 | ] 19 | } -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/CopyShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Full-screen textured quad shader 5 | */ 6 | 7 | THREE.CopyShader = { 8 | 9 | uniforms: { 10 | 11 | "tDiffuse": { type: "t", value: null }, 12 | "opacity": { type: "f", value: 1.0 } 13 | 14 | }, 15 | 16 | vertexShader: [ 17 | 18 | "varying vec2 vUv;", 19 | 20 | "void main() {", 21 | 22 | "vUv = uv;", 23 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 24 | 25 | "}" 26 | 27 | ].join("\n"), 28 | 29 | fragmentShader: [ 30 | 31 | "uniform float opacity;", 32 | 33 | "uniform sampler2D tDiffuse;", 34 | 35 | "varying vec2 vUv;", 36 | 37 | "void main() {", 38 | 39 | "vec4 texel = texture2D( tDiffuse, vUv );", 40 | "gl_FragColor = opacity * texel;", 41 | 42 | "}" 43 | 44 | ].join("\n") 45 | 46 | }; 47 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/LuminosityShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Luminosity 5 | * http://en.wikipedia.org/wiki/Luminosity 6 | */ 7 | 8 | THREE.LuminosityShader = { 9 | 10 | uniforms: { 11 | 12 | "tDiffuse": { type: "t", value: null } 13 | 14 | }, 15 | 16 | vertexShader: [ 17 | 18 | "varying vec2 vUv;", 19 | 20 | "void main() {", 21 | 22 | "vUv = uv;", 23 | 24 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 25 | 26 | "}" 27 | 28 | ].join("\n"), 29 | 30 | fragmentShader: [ 31 | 32 | "uniform sampler2D tDiffuse;", 33 | 34 | "varying vec2 vUv;", 35 | 36 | "void main() {", 37 | 38 | "vec4 texel = texture2D( tDiffuse, vUv );", 39 | 40 | "vec3 luma = vec3( 0.299, 0.587, 0.114 );", 41 | 42 | "float v = dot( texel.xyz, luma );", 43 | 44 | "gl_FragColor = vec4( v, v, v, texel.w );", 45 | 46 | "}" 47 | 48 | ].join("\n") 49 | 50 | }; 51 | -------------------------------------------------------------------------------- /js/threejs/examples/js/loaders/ctm/license/OpenCTM.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2010 Marcus Geelnard 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must not 17 | be misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/ColorifyShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Colorify shader 5 | */ 6 | 7 | THREE.ColorifyShader = { 8 | 9 | uniforms: { 10 | 11 | "tDiffuse": { type: "t", value: null }, 12 | "color": { type: "c", value: new THREE.Color( 0xffffff ) } 13 | 14 | }, 15 | 16 | vertexShader: [ 17 | 18 | "varying vec2 vUv;", 19 | 20 | "void main() {", 21 | 22 | "vUv = uv;", 23 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 24 | 25 | "}" 26 | 27 | ].join("\n"), 28 | 29 | fragmentShader: [ 30 | 31 | "uniform vec3 color;", 32 | "uniform sampler2D tDiffuse;", 33 | 34 | "varying vec2 vUv;", 35 | 36 | "void main() {", 37 | 38 | "vec4 texel = texture2D( tDiffuse, vUv );", 39 | 40 | "vec3 luma = vec3( 0.299, 0.587, 0.114 );", 41 | "float v = dot( texel.xyz, luma );", 42 | 43 | "gl_FragColor = vec4( v * color, texel.w );", 44 | 45 | "}" 46 | 47 | ].join("\n") 48 | 49 | }; 50 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/ColorCorrectionShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Color correction 5 | */ 6 | 7 | THREE.ColorCorrectionShader = { 8 | 9 | uniforms: { 10 | 11 | "tDiffuse": { type: "t", value: null }, 12 | "powRGB": { type: "v3", value: new THREE.Vector3( 2, 2, 2 ) }, 13 | "mulRGB": { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) } 14 | 15 | }, 16 | 17 | vertexShader: [ 18 | 19 | "varying vec2 vUv;", 20 | 21 | "void main() {", 22 | 23 | "vUv = uv;", 24 | 25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 26 | 27 | "}" 28 | 29 | ].join("\n"), 30 | 31 | fragmentShader: [ 32 | 33 | "uniform sampler2D tDiffuse;", 34 | "uniform vec3 powRGB;", 35 | "uniform vec3 mulRGB;", 36 | 37 | "varying vec2 vUv;", 38 | 39 | "void main() {", 40 | 41 | "gl_FragColor = texture2D( tDiffuse, vUv );", 42 | "gl_FragColor.rgb = mulRGB * pow( gl_FragColor.rgb, powRGB );", 43 | 44 | "}" 45 | 46 | ].join("\n") 47 | 48 | }; 49 | -------------------------------------------------------------------------------- /js/threejs/examples/js/postprocessing/TexturePass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.TexturePass = function ( texture, opacity ) { 6 | 7 | if ( THREE.CopyShader === undefined ) 8 | console.error( "THREE.TexturePass relies on THREE.CopyShader" ); 9 | 10 | var shader = THREE.CopyShader; 11 | 12 | this.uniforms = THREE.UniformsUtils.clone( shader.uniforms ); 13 | 14 | this.uniforms[ "opacity" ].value = ( opacity !== undefined ) ? opacity : 1.0; 15 | this.uniforms[ "tDiffuse" ].value = texture; 16 | 17 | this.material = new THREE.ShaderMaterial( { 18 | 19 | uniforms: this.uniforms, 20 | vertexShader: shader.vertexShader, 21 | fragmentShader: shader.fragmentShader 22 | 23 | } ); 24 | 25 | this.enabled = true; 26 | this.needsSwap = false; 27 | 28 | }; 29 | 30 | THREE.TexturePass.prototype = { 31 | 32 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 33 | 34 | THREE.EffectComposer.quad.material = this.material; 35 | 36 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, readBuffer ); 37 | 38 | } 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/BlendShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Blend two textures 5 | */ 6 | 7 | THREE.BlendShader = { 8 | 9 | uniforms: { 10 | 11 | "tDiffuse1": { type: "t", value: null }, 12 | "tDiffuse2": { type: "t", value: null }, 13 | "mixRatio": { type: "f", value: 0.5 }, 14 | "opacity": { type: "f", value: 1.0 } 15 | 16 | }, 17 | 18 | vertexShader: [ 19 | 20 | "varying vec2 vUv;", 21 | 22 | "void main() {", 23 | 24 | "vUv = uv;", 25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 26 | 27 | "}" 28 | 29 | ].join("\n"), 30 | 31 | fragmentShader: [ 32 | 33 | "uniform float opacity;", 34 | "uniform float mixRatio;", 35 | 36 | "uniform sampler2D tDiffuse1;", 37 | "uniform sampler2D tDiffuse2;", 38 | 39 | "varying vec2 vUv;", 40 | 41 | "void main() {", 42 | 43 | "vec4 texel1 = texture2D( tDiffuse1, vUv );", 44 | "vec4 texel2 = texture2D( tDiffuse2, vUv );", 45 | "gl_FragColor = opacity * mix( texel1, texel2, mixRatio );", 46 | 47 | "}" 48 | 49 | ].join("\n") 50 | 51 | }; 52 | -------------------------------------------------------------------------------- /js/threejs/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010-2013 three.js authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /js/threejs/examples/js/loaders/ctm/license/js-lzma.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Juan Mellado 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /js/threejs/examples/js/loaders/ctm/license/js-openctm.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Juan Mellado 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /js/threejs/examples/js/postprocessing/ShaderPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.ShaderPass = function ( shader, textureID ) { 6 | 7 | this.textureID = ( textureID !== undefined ) ? textureID : "tDiffuse"; 8 | 9 | this.uniforms = THREE.UniformsUtils.clone( shader.uniforms ); 10 | 11 | this.material = new THREE.ShaderMaterial( { 12 | 13 | uniforms: this.uniforms, 14 | vertexShader: shader.vertexShader, 15 | fragmentShader: shader.fragmentShader 16 | 17 | } ); 18 | 19 | this.renderToScreen = false; 20 | 21 | this.enabled = true; 22 | this.needsSwap = true; 23 | this.clear = false; 24 | 25 | }; 26 | 27 | THREE.ShaderPass.prototype = { 28 | 29 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 30 | 31 | if ( this.uniforms[ this.textureID ] ) { 32 | 33 | this.uniforms[ this.textureID ].value = readBuffer; 34 | 35 | } 36 | 37 | THREE.EffectComposer.quad.material = this.material; 38 | 39 | if ( this.renderToScreen ) { 40 | 41 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera ); 42 | 43 | } else { 44 | 45 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, this.clear ); 46 | 47 | } 48 | 49 | } 50 | 51 | }; 52 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/SepiaShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Sepia tone shader 5 | * based on glfx.js sepia shader 6 | * https://github.com/evanw/glfx.js 7 | */ 8 | 9 | THREE.SepiaShader = { 10 | 11 | uniforms: { 12 | 13 | "tDiffuse": { type: "t", value: null }, 14 | "amount": { type: "f", value: 1.0 } 15 | 16 | }, 17 | 18 | vertexShader: [ 19 | 20 | "varying vec2 vUv;", 21 | 22 | "void main() {", 23 | 24 | "vUv = uv;", 25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 26 | 27 | "}" 28 | 29 | ].join("\n"), 30 | 31 | fragmentShader: [ 32 | 33 | "uniform float amount;", 34 | 35 | "uniform sampler2D tDiffuse;", 36 | 37 | "varying vec2 vUv;", 38 | 39 | "void main() {", 40 | 41 | "vec4 color = texture2D( tDiffuse, vUv );", 42 | "vec3 c = color.rgb;", 43 | 44 | "color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );", 45 | "color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );", 46 | "color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );", 47 | 48 | "gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );", 49 | 50 | "}" 51 | 52 | ].join("\n") 53 | 54 | }; 55 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/UnpackDepthRGBAShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Unpack RGBA depth shader 5 | * - show RGBA encoded depth as monochrome color 6 | */ 7 | 8 | THREE.UnpackDepthRGBAShader = { 9 | 10 | uniforms: { 11 | 12 | "tDiffuse": { type: "t", value: null }, 13 | "opacity": { type: "f", value: 1.0 } 14 | 15 | }, 16 | 17 | vertexShader: [ 18 | 19 | "varying vec2 vUv;", 20 | 21 | "void main() {", 22 | 23 | "vUv = uv;", 24 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 25 | 26 | "}" 27 | 28 | ].join("\n"), 29 | 30 | fragmentShader: [ 31 | 32 | "uniform float opacity;", 33 | 34 | "uniform sampler2D tDiffuse;", 35 | 36 | "varying vec2 vUv;", 37 | 38 | // RGBA depth 39 | 40 | "float unpackDepth( const in vec4 rgba_depth ) {", 41 | 42 | "const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );", 43 | "float depth = dot( rgba_depth, bit_shift );", 44 | "return depth;", 45 | 46 | "}", 47 | 48 | "void main() {", 49 | 50 | "float depth = 1.0 - unpackDepth( texture2D( tDiffuse, vUv ) );", 51 | "gl_FragColor = opacity * vec4( vec3( depth ), 1.0 );", 52 | 53 | "}" 54 | 55 | ].join("\n") 56 | 57 | }; 58 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/MirrorShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author felixturner / http://airtight.cc/ 3 | * 4 | * Mirror Shader 5 | * Copies half the input to the other half 6 | * 7 | * side: side of input to mirror (0 = left, 1 = right, 2 = top, 3 = bottom) 8 | */ 9 | 10 | THREE.MirrorShader = { 11 | 12 | uniforms: { 13 | 14 | "tDiffuse": { type: "t", value: null }, 15 | "side": { type: "i", value: 1 } 16 | 17 | }, 18 | 19 | vertexShader: [ 20 | 21 | "varying vec2 vUv;", 22 | 23 | "void main() {", 24 | 25 | "vUv = uv;", 26 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 27 | 28 | "}" 29 | 30 | ].join("\n"), 31 | 32 | fragmentShader: [ 33 | 34 | "uniform sampler2D tDiffuse;", 35 | "uniform int side;", 36 | 37 | "varying vec2 vUv;", 38 | 39 | "void main() {", 40 | 41 | "vec2 p = vUv;", 42 | "if (side == 0){", 43 | "if (p.x > 0.5) p.x = 1.0 - p.x;", 44 | "}else if (side == 1){", 45 | "if (p.x < 0.5) p.x = 1.0 - p.x;", 46 | "}else if (side == 2){", 47 | "if (p.y < 0.5) p.y = 1.0 - p.y;", 48 | "}else if (side == 3){", 49 | "if (p.y > 0.5) p.y = 1.0 - p.y;", 50 | "} ", 51 | "vec4 color = texture2D(tDiffuse, p);", 52 | "gl_FragColor = color;", 53 | 54 | "}" 55 | 56 | ].join("\n") 57 | 58 | }; 59 | -------------------------------------------------------------------------------- /js/threejs/examples/js/postprocessing/RenderPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.RenderPass = function ( scene, camera, overrideMaterial, clearColor, clearAlpha ) { 6 | 7 | this.scene = scene; 8 | this.camera = camera; 9 | 10 | this.overrideMaterial = overrideMaterial; 11 | 12 | this.clearColor = clearColor; 13 | this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 1; 14 | 15 | this.oldClearColor = new THREE.Color(); 16 | this.oldClearAlpha = 1; 17 | 18 | this.enabled = true; 19 | this.clear = true; 20 | this.needsSwap = false; 21 | 22 | }; 23 | 24 | THREE.RenderPass.prototype = { 25 | 26 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 27 | 28 | this.scene.overrideMaterial = this.overrideMaterial; 29 | 30 | if ( this.clearColor ) { 31 | 32 | this.oldClearColor.copy( renderer.getClearColor() ); 33 | this.oldClearAlpha = renderer.getClearAlpha(); 34 | 35 | renderer.setClearColor( this.clearColor, this.clearAlpha ); 36 | 37 | } 38 | 39 | renderer.render( this.scene, this.camera, readBuffer, this.clear ); 40 | 41 | if ( this.clearColor ) { 42 | 43 | renderer.setClearColor( this.oldClearColor, this.oldClearAlpha ); 44 | 45 | } 46 | 47 | this.scene.overrideMaterial = null; 48 | 49 | } 50 | 51 | }; 52 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/DOFMipMapShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Depth-of-field shader using mipmaps 5 | * - from Matt Handley @applmak 6 | * - requires power-of-2 sized render target with enabled mipmaps 7 | */ 8 | 9 | THREE.DOFMipMapShader = { 10 | 11 | uniforms: { 12 | 13 | "tColor": { type: "t", value: null }, 14 | "tDepth": { type: "t", value: null }, 15 | "focus": { type: "f", value: 1.0 }, 16 | "maxblur": { type: "f", value: 1.0 } 17 | 18 | }, 19 | 20 | vertexShader: [ 21 | 22 | "varying vec2 vUv;", 23 | 24 | "void main() {", 25 | 26 | "vUv = uv;", 27 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 28 | 29 | "}" 30 | 31 | ].join("\n"), 32 | 33 | fragmentShader: [ 34 | 35 | "uniform float focus;", 36 | "uniform float maxblur;", 37 | 38 | "uniform sampler2D tColor;", 39 | "uniform sampler2D tDepth;", 40 | 41 | "varying vec2 vUv;", 42 | 43 | "void main() {", 44 | 45 | "vec4 depth = texture2D( tDepth, vUv );", 46 | 47 | "float factor = depth.x - focus;", 48 | 49 | "vec4 col = texture2D( tColor, vUv, 2.0 * maxblur * abs( focus - depth.x ) );", 50 | 51 | "gl_FragColor = col;", 52 | "gl_FragColor.a = 1.0;", 53 | 54 | "}" 55 | 56 | ].join("\n") 57 | 58 | }; 59 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/NormalMapShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Normal map shader 5 | * - compute normals from heightmap 6 | */ 7 | 8 | THREE.NormalMapShader = { 9 | 10 | uniforms: { 11 | 12 | "heightMap": { type: "t", value: null }, 13 | "resolution": { type: "v2", value: new THREE.Vector2( 512, 512 ) }, 14 | "scale": { type: "v2", value: new THREE.Vector2( 1, 1 ) }, 15 | "height": { type: "f", value: 0.05 } 16 | 17 | }, 18 | 19 | vertexShader: [ 20 | 21 | "varying vec2 vUv;", 22 | 23 | "void main() {", 24 | 25 | "vUv = uv;", 26 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 27 | 28 | "}" 29 | 30 | ].join("\n"), 31 | 32 | fragmentShader: [ 33 | 34 | "uniform float height;", 35 | "uniform vec2 resolution;", 36 | "uniform sampler2D heightMap;", 37 | 38 | "varying vec2 vUv;", 39 | 40 | "void main() {", 41 | 42 | "float val = texture2D( heightMap, vUv ).x;", 43 | 44 | "float valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;", 45 | "float valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;", 46 | 47 | "gl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height ) ) + 0.5 ), 1.0 );", 48 | 49 | "}" 50 | 51 | ].join("\n") 52 | 53 | }; 54 | -------------------------------------------------------------------------------- /js/threejs/examples/js/math/ColorConverter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bhouston / http://exocortex.com/ 3 | * @author zz85 / http://github.com/zz85 4 | */ 5 | 6 | THREE.ColorConverter = { 7 | 8 | setHSV: function ( color, h, s, v ) { 9 | 10 | // https://gist.github.com/xpansive/1337890#file-index-js 11 | return color.setHSL( h, ( s * v ) / ( ( h = ( 2 - s ) * v ) < 1 ? h : ( 2 - h ) ), h * 0.5 ); 12 | 13 | }, 14 | 15 | getHSV: function( color ) { 16 | 17 | var hsl = color.getHSL(); 18 | 19 | // based on https://gist.github.com/xpansive/1337890#file-index-js 20 | hsl.s *= ( hsl.l < 0.5 ) ? hsl.l : ( 1 - hsl.l ); 21 | 22 | return { 23 | h: hsl.h, 24 | s: 2 * hsl.s / ( hsl.l + hsl.s ), 25 | v: hsl.l + hsl.s 26 | }; 27 | }, 28 | 29 | // where c, m, y, k is between 0 and 1 30 | 31 | setCMYK: function ( color, c, m, y, k ) { 32 | 33 | var r = ( 1 - c ) * ( 1 - k ); 34 | var g = ( 1 - m ) * ( 1 - k ); 35 | var b = ( 1 - y ) * ( 1 - k ); 36 | 37 | return color.setRGB( r, g, b ); 38 | 39 | }, 40 | 41 | getCMYK: function ( color ) { 42 | 43 | var r = color.r; 44 | var g = color.g; 45 | var b = color.b; 46 | var k = 1 - Math.max(r, g, b); 47 | var c = ( 1 - r - k ) / ( 1 - k ); 48 | var m = ( 1 - g - k ) / ( 1 - k ); 49 | var y = ( 1 - b - k ) / ( 1 - k ); 50 | 51 | return { 52 | c: c, m: m, y: y, k: k 53 | }; 54 | 55 | } 56 | 57 | 58 | }; -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/RGBShiftShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author felixturner / http://airtight.cc/ 3 | * 4 | * RGB Shift Shader 5 | * Shifts red and blue channels from center in opposite directions 6 | * Ported from http://kriss.cx/tom/2009/05/rgb-shift/ 7 | * by Tom Butterworth / http://kriss.cx/tom/ 8 | * 9 | * amount: shift distance (1 is width of input) 10 | * angle: shift angle in radians 11 | */ 12 | 13 | THREE.RGBShiftShader = { 14 | 15 | uniforms: { 16 | 17 | "tDiffuse": { type: "t", value: null }, 18 | "amount": { type: "f", value: 0.005 }, 19 | "angle": { type: "f", value: 0.0 } 20 | 21 | }, 22 | 23 | vertexShader: [ 24 | 25 | "varying vec2 vUv;", 26 | 27 | "void main() {", 28 | 29 | "vUv = uv;", 30 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 31 | 32 | "}" 33 | 34 | ].join("\n"), 35 | 36 | fragmentShader: [ 37 | 38 | "uniform sampler2D tDiffuse;", 39 | "uniform float amount;", 40 | "uniform float angle;", 41 | 42 | "varying vec2 vUv;", 43 | 44 | "void main() {", 45 | 46 | "vec2 offset = amount * vec2( cos(angle), sin(angle));", 47 | "vec4 cr = texture2D(tDiffuse, vUv + offset);", 48 | "vec4 cga = texture2D(tDiffuse, vUv);", 49 | "vec4 cb = texture2D(tDiffuse, vUv - offset);", 50 | "gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);", 51 | 52 | "}" 53 | 54 | ].join("\n") 55 | 56 | }; 57 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/KaleidoShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author felixturner / http://airtight.cc/ 3 | * 4 | * Kaleidoscope Shader 5 | * Radial reflection around center point 6 | * Ported from: http://pixelshaders.com/editor/ 7 | * by Toby Schachman / http://tobyschachman.com/ 8 | * 9 | * sides: number of reflections 10 | * angle: initial angle in radians 11 | */ 12 | 13 | THREE.KaleidoShader = { 14 | 15 | uniforms: { 16 | 17 | "tDiffuse": { type: "t", value: null }, 18 | "sides": { type: "f", value: 6.0 }, 19 | "angle": { type: "f", value: 0.0 } 20 | 21 | }, 22 | 23 | vertexShader: [ 24 | 25 | "varying vec2 vUv;", 26 | 27 | "void main() {", 28 | 29 | "vUv = uv;", 30 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 31 | 32 | "}" 33 | 34 | ].join("\n"), 35 | 36 | fragmentShader: [ 37 | 38 | "uniform sampler2D tDiffuse;", 39 | "uniform float sides;", 40 | "uniform float angle;", 41 | 42 | "varying vec2 vUv;", 43 | 44 | "void main() {", 45 | 46 | "vec2 p = vUv - 0.5;", 47 | "float r = length(p);", 48 | "float a = atan(p.y, p.x) + angle;", 49 | "float tau = 2. * 3.1416 ;", 50 | "a = mod(a, tau/sides);", 51 | "a = abs(a - tau/sides/2.) ;", 52 | "p = r * vec2(cos(a), sin(a));", 53 | "vec4 color = texture2D(tDiffuse, p + 0.5);", 54 | "gl_FragColor = color;", 55 | 56 | "}" 57 | 58 | ].join("\n") 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/BrightnessContrastShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author tapio / http://tapio.github.com/ 3 | * 4 | * Brightness and contrast adjustment 5 | * https://github.com/evanw/glfx.js 6 | * brightness: -1 to 1 (-1 is solid black, 0 is no change, and 1 is solid white) 7 | * contrast: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast) 8 | */ 9 | 10 | THREE.BrightnessContrastShader = { 11 | 12 | uniforms: { 13 | 14 | "tDiffuse": { type: "t", value: null }, 15 | "brightness": { type: "f", value: 0 }, 16 | "contrast": { type: "f", value: 0 } 17 | 18 | }, 19 | 20 | vertexShader: [ 21 | 22 | "varying vec2 vUv;", 23 | 24 | "void main() {", 25 | 26 | "vUv = uv;", 27 | 28 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 29 | 30 | "}" 31 | 32 | ].join("\n"), 33 | 34 | fragmentShader: [ 35 | 36 | "uniform sampler2D tDiffuse;", 37 | "uniform float brightness;", 38 | "uniform float contrast;", 39 | 40 | "varying vec2 vUv;", 41 | 42 | "void main() {", 43 | 44 | "gl_FragColor = texture2D( tDiffuse, vUv );", 45 | 46 | "gl_FragColor.rgb += brightness;", 47 | 48 | "if (contrast > 0.0) {", 49 | "gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) / (1.0 - contrast) + 0.5;", 50 | "} else {", 51 | "gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5;", 52 | "}", 53 | 54 | "}" 55 | 56 | ].join("\n") 57 | 58 | }; 59 | -------------------------------------------------------------------------------- /js/threejs/examples/js/libs/system.min.js: -------------------------------------------------------------------------------- 1 | // system.js - http://github.com/mrdoob/system.js 2 | 'use strict';var System={browser:function(){var a=navigator.userAgent;return/Arora/i.test(a)?"Arora":/Chrome/i.test(a)?"Chrome":/Epiphany/i.test(a)?"Epiphany":/Firefox/i.test(a)?"Firefox":/Mobile(\/.*)? Safari/i.test(a)?"Mobile Safari":/MSIE/i.test(a)?"Internet Explorer":/Midori/i.test(a)?"Midori":/Opera/.test(a)?"Opera":/Safari/i.test(a)?"Safari":!1}(),os:function(){var a=navigator.userAgent;return/Android/i.test(a)?"Android":/CrOS/i.test(a)?"Chrome OS":/iP[ao]d|iPhone/i.test(a)?"iOS":/Linux/i.test(a)? 3 | "Linux":/Mac OS/i.test(a)?"Mac OS":/windows/i.test(a)?"Windows":!1}(),support:{canvas:!!window.CanvasRenderingContext2D,localStorage:function(){try{return!!window.localStorage.getItem}catch(a){return!1}}(),file:!!window.File&&!!window.FileReader&&!!window.FileList&&!!window.Blob,fileSystem:!!window.requestFileSystem||!!window.webkitRequestFileSystem,getUserMedia:!!window.navigator.getUserMedia||!!window.navigator.webkitGetUserMedia||!!window.navigator.mozGetUserMedia||!!window.navigator.msGetUserMedia, 4 | requestAnimationFrame:!!window.mozRequestAnimationFrame||!!window.webkitRequestAnimationFrame||!!window.oRequestAnimationFrame||!!window.msRequestAnimationFrame,sessionStorage:function(){try{return!!window.sessionStorage.getItem}catch(a){return!1}}(),webgl:function(){try{return!!window.WebGLRenderingContext&&!!document.createElement("canvas").getContext("experimental-webgl")}catch(a){return!1}}(),worker:!!window.Worker}}; 5 | -------------------------------------------------------------------------------- /js/threejs/examples/js/postprocessing/SavePass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.SavePass = function ( renderTarget ) { 6 | 7 | if ( THREE.CopyShader === undefined ) 8 | console.error( "THREE.SavePass relies on THREE.CopyShader" ); 9 | 10 | var shader = THREE.CopyShader; 11 | 12 | this.textureID = "tDiffuse"; 13 | 14 | this.uniforms = THREE.UniformsUtils.clone( shader.uniforms ); 15 | 16 | this.material = new THREE.ShaderMaterial( { 17 | 18 | uniforms: this.uniforms, 19 | vertexShader: shader.vertexShader, 20 | fragmentShader: shader.fragmentShader 21 | 22 | } ); 23 | 24 | this.renderTarget = renderTarget; 25 | 26 | if ( this.renderTarget === undefined ) { 27 | 28 | this.renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false }; 29 | this.renderTarget = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, this.renderTargetParameters ); 30 | 31 | } 32 | 33 | this.enabled = true; 34 | this.needsSwap = false; 35 | this.clear = false; 36 | 37 | }; 38 | 39 | THREE.SavePass.prototype = { 40 | 41 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 42 | 43 | if ( this.uniforms[ this.textureID ] ) { 44 | 45 | this.uniforms[ this.textureID ].value = readBuffer; 46 | 47 | } 48 | 49 | THREE.EffectComposer.quad.material = this.material; 50 | 51 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, this.renderTarget, this.clear ); 52 | 53 | } 54 | 55 | }; 56 | -------------------------------------------------------------------------------- /js/threejs/examples/js/postprocessing/DotScreenPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.DotScreenPass = function ( center, angle, scale ) { 6 | 7 | if ( THREE.DotScreenShader === undefined ) 8 | console.error( "THREE.DotScreenPass relies on THREE.DotScreenShader" ); 9 | 10 | var shader = THREE.DotScreenShader; 11 | 12 | this.uniforms = THREE.UniformsUtils.clone( shader.uniforms ); 13 | 14 | if ( center !== undefined ) this.uniforms[ "center" ].value.copy( center ); 15 | if ( angle !== undefined ) this.uniforms[ "angle"].value = angle; 16 | if ( scale !== undefined ) this.uniforms[ "scale"].value = scale; 17 | 18 | this.material = new THREE.ShaderMaterial( { 19 | 20 | uniforms: this.uniforms, 21 | vertexShader: shader.vertexShader, 22 | fragmentShader: shader.fragmentShader 23 | 24 | } ); 25 | 26 | this.enabled = true; 27 | this.renderToScreen = false; 28 | this.needsSwap = true; 29 | 30 | }; 31 | 32 | THREE.DotScreenPass.prototype = { 33 | 34 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 35 | 36 | this.uniforms[ "tDiffuse" ].value = readBuffer; 37 | this.uniforms[ "tSize" ].value.set( readBuffer.width, readBuffer.height ); 38 | 39 | THREE.EffectComposer.quad.material = this.material; 40 | 41 | if ( this.renderToScreen ) { 42 | 43 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera ); 44 | 45 | } else { 46 | 47 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, false ); 48 | 49 | } 50 | 51 | } 52 | 53 | }; 54 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/VignetteShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Vignette shader 5 | * based on PaintEffect postprocess from ro.me 6 | * http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js 7 | */ 8 | 9 | THREE.VignetteShader = { 10 | 11 | uniforms: { 12 | 13 | "tDiffuse": { type: "t", value: null }, 14 | "offset": { type: "f", value: 1.0 }, 15 | "darkness": { type: "f", value: 1.0 } 16 | 17 | }, 18 | 19 | vertexShader: [ 20 | 21 | "varying vec2 vUv;", 22 | 23 | "void main() {", 24 | 25 | "vUv = uv;", 26 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 27 | 28 | "}" 29 | 30 | ].join("\n"), 31 | 32 | fragmentShader: [ 33 | 34 | "uniform float offset;", 35 | "uniform float darkness;", 36 | 37 | "uniform sampler2D tDiffuse;", 38 | 39 | "varying vec2 vUv;", 40 | 41 | "void main() {", 42 | 43 | // Eskil's vignette 44 | 45 | "vec4 texel = texture2D( tDiffuse, vUv );", 46 | "vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset );", 47 | "gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a );", 48 | 49 | /* 50 | // alternative version from glfx.js 51 | // this one makes more "dusty" look (as opposed to "burned") 52 | 53 | "vec4 color = texture2D( tDiffuse, vUv );", 54 | "float dist = distance( vUv, vec2( 0.5 ) );", 55 | "color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) );", 56 | "gl_FragColor = color;", 57 | */ 58 | 59 | "}" 60 | 61 | ].join("\n") 62 | 63 | }; 64 | -------------------------------------------------------------------------------- /js/threejs/examples/js/modifiers/ExplodeModifier.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Make all faces use unique vertices 3 | * so that each face can be separated from others 4 | * 5 | * @author alteredq / http://alteredqualia.com/ 6 | */ 7 | 8 | THREE.ExplodeModifier = function () { 9 | 10 | }; 11 | 12 | THREE.ExplodeModifier.prototype.modify = function ( geometry ) { 13 | 14 | var vertices = []; 15 | 16 | for ( var i = 0, il = geometry.faces.length; i < il; i ++ ) { 17 | 18 | var n = vertices.length; 19 | 20 | var face = geometry.faces[ i ]; 21 | 22 | if ( face instanceof THREE.Face4 ) { 23 | 24 | var a = face.a; 25 | var b = face.b; 26 | var c = face.c; 27 | var d = face.d; 28 | 29 | var va = geometry.vertices[ a ]; 30 | var vb = geometry.vertices[ b ]; 31 | var vc = geometry.vertices[ c ]; 32 | var vd = geometry.vertices[ d ]; 33 | 34 | vertices.push( va.clone() ); 35 | vertices.push( vb.clone() ); 36 | vertices.push( vc.clone() ); 37 | vertices.push( vd.clone() ); 38 | 39 | face.a = n; 40 | face.b = n + 1; 41 | face.c = n + 2; 42 | face.d = n + 3; 43 | 44 | } else { 45 | 46 | var a = face.a; 47 | var b = face.b; 48 | var c = face.c; 49 | 50 | var va = geometry.vertices[ a ]; 51 | var vb = geometry.vertices[ b ]; 52 | var vc = geometry.vertices[ c ]; 53 | 54 | vertices.push( va.clone() ); 55 | vertices.push( vb.clone() ); 56 | vertices.push( vc.clone() ); 57 | 58 | face.a = n; 59 | face.b = n + 1; 60 | face.c = n + 2; 61 | 62 | } 63 | 64 | } 65 | 66 | geometry.vertices = vertices; 67 | delete geometry.__tmpVertices; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/BleachBypassShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Bleach bypass shader [http://en.wikipedia.org/wiki/Bleach_bypass] 5 | * - based on Nvidia example 6 | * http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html#post_bleach_bypass 7 | */ 8 | 9 | THREE.BleachBypassShader = { 10 | 11 | uniforms: { 12 | 13 | "tDiffuse": { type: "t", value: null }, 14 | "opacity": { type: "f", value: 1.0 } 15 | 16 | }, 17 | 18 | vertexShader: [ 19 | 20 | "varying vec2 vUv;", 21 | 22 | "void main() {", 23 | 24 | "vUv = uv;", 25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 26 | 27 | "}" 28 | 29 | ].join("\n"), 30 | 31 | fragmentShader: [ 32 | 33 | "uniform float opacity;", 34 | 35 | "uniform sampler2D tDiffuse;", 36 | 37 | "varying vec2 vUv;", 38 | 39 | "void main() {", 40 | 41 | "vec4 base = texture2D( tDiffuse, vUv );", 42 | 43 | "vec3 lumCoeff = vec3( 0.25, 0.65, 0.1 );", 44 | "float lum = dot( lumCoeff, base.rgb );", 45 | "vec3 blend = vec3( lum );", 46 | 47 | "float L = min( 1.0, max( 0.0, 10.0 * ( lum - 0.45 ) ) );", 48 | 49 | "vec3 result1 = 2.0 * base.rgb * blend;", 50 | "vec3 result2 = 1.0 - 2.0 * ( 1.0 - blend ) * ( 1.0 - base.rgb );", 51 | 52 | "vec3 newColor = mix( result1, result2, L );", 53 | 54 | "float A2 = opacity * base.a;", 55 | "vec3 mixRGB = A2 * newColor.rgb;", 56 | "mixRGB += ( ( 1.0 - A2 ) * base.rgb );", 57 | 58 | "gl_FragColor = vec4( mixRGB, base.a );", 59 | 60 | "}" 61 | 62 | ].join("\n") 63 | 64 | }; 65 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/DotScreenShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Dot screen shader 5 | * based on glfx.js sepia shader 6 | * https://github.com/evanw/glfx.js 7 | */ 8 | 9 | THREE.DotScreenShader = { 10 | 11 | uniforms: { 12 | 13 | "tDiffuse": { type: "t", value: null }, 14 | "tSize": { type: "v2", value: new THREE.Vector2( 256, 256 ) }, 15 | "center": { type: "v2", value: new THREE.Vector2( 0.5, 0.5 ) }, 16 | "angle": { type: "f", value: 1.57 }, 17 | "scale": { type: "f", value: 1.0 } 18 | 19 | }, 20 | 21 | vertexShader: [ 22 | 23 | "varying vec2 vUv;", 24 | 25 | "void main() {", 26 | 27 | "vUv = uv;", 28 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 29 | 30 | "}" 31 | 32 | ].join("\n"), 33 | 34 | fragmentShader: [ 35 | 36 | "uniform vec2 center;", 37 | "uniform float angle;", 38 | "uniform float scale;", 39 | "uniform vec2 tSize;", 40 | 41 | "uniform sampler2D tDiffuse;", 42 | 43 | "varying vec2 vUv;", 44 | 45 | "float pattern() {", 46 | 47 | "float s = sin( angle ), c = cos( angle );", 48 | 49 | "vec2 tex = vUv * tSize - center;", 50 | "vec2 point = vec2( c * tex.x - s * tex.y, s * tex.x + c * tex.y ) * scale;", 51 | 52 | "return ( sin( point.x ) * sin( point.y ) ) * 4.0;", 53 | 54 | "}", 55 | 56 | "void main() {", 57 | 58 | "vec4 color = texture2D( tDiffuse, vUv );", 59 | 60 | "float average = ( color.r + color.g + color.b ) / 3.0;", 61 | 62 | "gl_FragColor = vec4( vec3( average * 10.0 - 5.0 + pattern() ), color.a );", 63 | 64 | "}" 65 | 66 | ].join("\n") 67 | 68 | }; 69 | -------------------------------------------------------------------------------- /js/threejs/examples/js/postprocessing/FilmPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount, grayscale ) { 6 | 7 | if ( THREE.FilmShader === undefined ) 8 | console.error( "THREE.FilmPass relies on THREE.FilmShader" ); 9 | 10 | var shader = THREE.FilmShader; 11 | 12 | this.uniforms = THREE.UniformsUtils.clone( shader.uniforms ); 13 | 14 | this.material = new THREE.ShaderMaterial( { 15 | 16 | uniforms: this.uniforms, 17 | vertexShader: shader.vertexShader, 18 | fragmentShader: shader.fragmentShader 19 | 20 | } ); 21 | 22 | if ( grayscale !== undefined ) this.uniforms.grayscale.value = grayscale; 23 | if ( noiseIntensity !== undefined ) this.uniforms.nIntensity.value = noiseIntensity; 24 | if ( scanlinesIntensity !== undefined ) this.uniforms.sIntensity.value = scanlinesIntensity; 25 | if ( scanlinesCount !== undefined ) this.uniforms.sCount.value = scanlinesCount; 26 | 27 | this.enabled = true; 28 | this.renderToScreen = false; 29 | this.needsSwap = true; 30 | 31 | }; 32 | 33 | THREE.FilmPass.prototype = { 34 | 35 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 36 | 37 | this.uniforms[ "tDiffuse" ].value = readBuffer; 38 | this.uniforms[ "time" ].value += delta; 39 | 40 | THREE.EffectComposer.quad.material = this.material; 41 | 42 | if ( this.renderToScreen ) { 43 | 44 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera ); 45 | 46 | } else { 47 | 48 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, writeBuffer, false ); 49 | 50 | } 51 | 52 | } 53 | 54 | }; 55 | -------------------------------------------------------------------------------- /js/threejs/examples/js/effects/CrosseyedEffect.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.CrosseyedEffect = function ( renderer ) { 6 | 7 | // API 8 | 9 | this.separation = 10; 10 | 11 | // internals 12 | 13 | var _width, _height; 14 | 15 | var _cameraL = new THREE.PerspectiveCamera(); 16 | _cameraL.target = new THREE.Vector3(); 17 | 18 | var _cameraR = new THREE.PerspectiveCamera(); 19 | _cameraR.target = new THREE.Vector3(); 20 | 21 | // initialization 22 | 23 | renderer.autoClear = false; 24 | 25 | this.setSize = function ( width, height ) { 26 | 27 | _width = width / 2; 28 | _height = height; 29 | 30 | renderer.setSize( width, height ); 31 | 32 | }; 33 | 34 | this.render = function ( scene, camera ) { 35 | 36 | // left 37 | 38 | _cameraL.fov = camera.fov; 39 | _cameraL.aspect = 0.5 * camera.aspect; 40 | _cameraL.near = camera.near; 41 | _cameraL.far = camera.far; 42 | _cameraL.updateProjectionMatrix(); 43 | 44 | _cameraL.position.copy( camera.position ); 45 | _cameraL.target.copy( camera.target ); 46 | _cameraL.translateX( this.separation ); 47 | _cameraL.lookAt( _cameraL.target ); 48 | 49 | // right 50 | 51 | _cameraR.near = camera.near; 52 | _cameraR.far = camera.far; 53 | 54 | _cameraR.projectionMatrix = _cameraL.projectionMatrix; 55 | 56 | _cameraR.position.copy( camera.position ); 57 | _cameraR.target.copy( camera.target ); 58 | _cameraR.translateX( - this.separation ); 59 | _cameraR.lookAt( _cameraR.target ); 60 | 61 | // 62 | 63 | renderer.clear(); 64 | 65 | renderer.setViewport( 0, 0, _width, _height ); 66 | renderer.render( scene, _cameraL ); 67 | 68 | renderer.setViewport( _width, 0, _width, _height ); 69 | renderer.render( scene, _cameraR, false ); 70 | 71 | }; 72 | 73 | }; 74 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/HueSaturationShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author tapio / http://tapio.github.com/ 3 | * 4 | * Hue and saturation adjustment 5 | * https://github.com/evanw/glfx.js 6 | * hue: -1 to 1 (-1 is 180 degrees in the negative direction, 0 is no change, etc. 7 | * saturation: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast) 8 | */ 9 | 10 | THREE.HueSaturationShader = { 11 | 12 | uniforms: { 13 | 14 | "tDiffuse": { type: "t", value: null }, 15 | "hue": { type: "f", value: 0 }, 16 | "saturation": { type: "f", value: 0 } 17 | 18 | }, 19 | 20 | vertexShader: [ 21 | 22 | "varying vec2 vUv;", 23 | 24 | "void main() {", 25 | 26 | "vUv = uv;", 27 | 28 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 29 | 30 | "}" 31 | 32 | ].join("\n"), 33 | 34 | fragmentShader: [ 35 | 36 | "uniform sampler2D tDiffuse;", 37 | "uniform float hue;", 38 | "uniform float saturation;", 39 | 40 | "varying vec2 vUv;", 41 | 42 | "void main() {", 43 | 44 | "gl_FragColor = texture2D( tDiffuse, vUv );", 45 | 46 | // hue 47 | "float angle = hue * 3.14159265;", 48 | "float s = sin(angle), c = cos(angle);", 49 | "vec3 weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + 1.0) / 3.0;", 50 | "float len = length(gl_FragColor.rgb);", 51 | "gl_FragColor.rgb = vec3(", 52 | "dot(gl_FragColor.rgb, weights.xyz),", 53 | "dot(gl_FragColor.rgb, weights.zxy),", 54 | "dot(gl_FragColor.rgb, weights.yzx)", 55 | ");", 56 | 57 | // saturation 58 | "float average = (gl_FragColor.r + gl_FragColor.g + gl_FragColor.b) / 3.0;", 59 | "if (saturation > 0.0) {", 60 | "gl_FragColor.rgb += (average - gl_FragColor.rgb) * (1.0 - 1.0 / (1.001 - saturation));", 61 | "} else {", 62 | "gl_FragColor.rgb += (average - gl_FragColor.rgb) * (-saturation);", 63 | "}", 64 | 65 | "}" 66 | 67 | ].join("\n") 68 | 69 | }; 70 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/VerticalBlurShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author zz85 / http://www.lab4games.net/zz85/blog 3 | * 4 | * Two pass Gaussian blur filter (horizontal and vertical blur shaders) 5 | * - described in http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/ 6 | * and used in http://www.cake23.de/traveling-wavefronts-lit-up.html 7 | * 8 | * - 9 samples per pass 9 | * - standard deviation 2.7 10 | * - "h" and "v" parameters should be set to "1 / width" and "1 / height" 11 | */ 12 | 13 | THREE.VerticalBlurShader = { 14 | 15 | uniforms: { 16 | 17 | "tDiffuse": { type: "t", value: null }, 18 | "v": { type: "f", value: 1.0 / 512.0 } 19 | 20 | }, 21 | 22 | vertexShader: [ 23 | 24 | "varying vec2 vUv;", 25 | 26 | "void main() {", 27 | 28 | "vUv = uv;", 29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 30 | 31 | "}" 32 | 33 | ].join("\n"), 34 | 35 | fragmentShader: [ 36 | 37 | "uniform sampler2D tDiffuse;", 38 | "uniform float v;", 39 | 40 | "varying vec2 vUv;", 41 | 42 | "void main() {", 43 | 44 | "vec4 sum = vec4( 0.0 );", 45 | 46 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;", 47 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;", 48 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;", 49 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;", 50 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;", 51 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;", 52 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;", 53 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;", 54 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;", 55 | 56 | "gl_FragColor = sum;", 57 | 58 | "}" 59 | 60 | ].join("\n") 61 | 62 | }; 63 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/HorizontalBlurShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author zz85 / http://www.lab4games.net/zz85/blog 3 | * 4 | * Two pass Gaussian blur filter (horizontal and vertical blur shaders) 5 | * - described in http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/ 6 | * and used in http://www.cake23.de/traveling-wavefronts-lit-up.html 7 | * 8 | * - 9 samples per pass 9 | * - standard deviation 2.7 10 | * - "h" and "v" parameters should be set to "1 / width" and "1 / height" 11 | */ 12 | 13 | THREE.HorizontalBlurShader = { 14 | 15 | uniforms: { 16 | 17 | "tDiffuse": { type: "t", value: null }, 18 | "h": { type: "f", value: 1.0 / 512.0 } 19 | 20 | }, 21 | 22 | vertexShader: [ 23 | 24 | "varying vec2 vUv;", 25 | 26 | "void main() {", 27 | 28 | "vUv = uv;", 29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 30 | 31 | "}" 32 | 33 | ].join("\n"), 34 | 35 | fragmentShader: [ 36 | 37 | "uniform sampler2D tDiffuse;", 38 | "uniform float h;", 39 | 40 | "varying vec2 vUv;", 41 | 42 | "void main() {", 43 | 44 | "vec4 sum = vec4( 0.0 );", 45 | 46 | "sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * h, vUv.y ) ) * 0.051;", 47 | "sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * h, vUv.y ) ) * 0.0918;", 48 | "sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * h, vUv.y ) ) * 0.12245;", 49 | "sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * h, vUv.y ) ) * 0.1531;", 50 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;", 51 | "sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * h, vUv.y ) ) * 0.1531;", 52 | "sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * h, vUv.y ) ) * 0.12245;", 53 | "sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * h, vUv.y ) ) * 0.0918;", 54 | "sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * h, vUv.y ) ) * 0.051;", 55 | 56 | "gl_FragColor = sum;", 57 | 58 | "}" 59 | 60 | ].join("\n") 61 | 62 | }; 63 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/TriangleBlurShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author zz85 / http://www.lab4games.net/zz85/blog 3 | * 4 | * Triangle blur shader 5 | * based on glfx.js triangle blur shader 6 | * https://github.com/evanw/glfx.js 7 | * 8 | * A basic blur filter, which convolves the image with a 9 | * pyramid filter. The pyramid filter is separable and is applied as two 10 | * perpendicular triangle filters. 11 | */ 12 | 13 | THREE.TriangleBlurShader = { 14 | 15 | uniforms : { 16 | 17 | "texture": { type: "t", value: null }, 18 | "delta": { type: "v2", value:new THREE.Vector2( 1, 1 ) } 19 | 20 | }, 21 | 22 | vertexShader: [ 23 | 24 | "varying vec2 vUv;", 25 | 26 | "void main() {", 27 | 28 | "vUv = uv;", 29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 30 | 31 | "}" 32 | 33 | ].join("\n"), 34 | 35 | fragmentShader: [ 36 | 37 | "#define ITERATIONS 10.0", 38 | 39 | "uniform sampler2D texture;", 40 | "uniform vec2 delta;", 41 | 42 | "varying vec2 vUv;", 43 | 44 | "float random( vec3 scale, float seed ) {", 45 | 46 | // use the fragment position for a different seed per-pixel 47 | 48 | "return fract( sin( dot( gl_FragCoord.xyz + seed, scale ) ) * 43758.5453 + seed );", 49 | 50 | "}", 51 | 52 | "void main() {", 53 | 54 | "vec4 color = vec4( 0.0 );", 55 | 56 | "float total = 0.0;", 57 | 58 | // randomize the lookup values to hide the fixed number of samples 59 | 60 | "float offset = random( vec3( 12.9898, 78.233, 151.7182 ), 0.0 );", 61 | 62 | "for ( float t = -ITERATIONS; t <= ITERATIONS; t ++ ) {", 63 | 64 | "float percent = ( t + offset - 0.5 ) / ITERATIONS;", 65 | "float weight = 1.0 - abs( percent );", 66 | 67 | "color += texture2D( texture, vUv + delta * percent ) * weight;", 68 | "total += weight;", 69 | 70 | "}", 71 | 72 | "gl_FragColor = color / total;", 73 | 74 | "}" 75 | 76 | ].join("\n") 77 | 78 | }; 79 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/EdgeShader2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author zz85 / https://github.com/zz85 | https://www.lab4games.net/zz85/blog 3 | * 4 | * Edge Detection Shader using Sobel filter 5 | * Based on http://rastergrid.com/blog/2011/01/frei-chen-edge-detector 6 | * 7 | * aspect: vec2 of (1/width, 1/height) 8 | */ 9 | 10 | THREE.EdgeShader2 = { 11 | 12 | uniforms: { 13 | 14 | "tDiffuse": { type: "t", value: null }, 15 | "aspect": { type: "v2", value: new THREE.Vector2( 512, 512 ) }, 16 | }, 17 | 18 | vertexShader: [ 19 | 20 | "varying vec2 vUv;", 21 | 22 | "void main() {", 23 | 24 | "vUv = uv;", 25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 26 | 27 | "}" 28 | 29 | ].join("\n"), 30 | 31 | fragmentShader: [ 32 | 33 | "uniform sampler2D tDiffuse;", 34 | "varying vec2 vUv;", 35 | "uniform vec2 aspect;", 36 | 37 | 38 | "vec2 texel = vec2(1.0 / aspect.x, 1.0 / aspect.y);", 39 | 40 | "mat3 G[2];", 41 | 42 | "const mat3 g0 = mat3( 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -1.0 );", 43 | "const mat3 g1 = mat3( 1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0 );", 44 | 45 | 46 | "void main(void)", 47 | "{", 48 | "mat3 I;", 49 | "float cnv[2];", 50 | "vec3 sample;", 51 | 52 | "G[0] = g0;", 53 | "G[1] = g1;", 54 | 55 | /* fetch the 3x3 neighbourhood and use the RGB vector's length as intensity value */ 56 | "for (float i=0.0; i<3.0; i++)", 57 | "for (float j=0.0; j<3.0; j++) {", 58 | "sample = texture2D( tDiffuse, vUv + texel * vec2(i-1.0,j-1.0) ).rgb;", 59 | "I[int(i)][int(j)] = length(sample);", 60 | "}", 61 | 62 | /* calculate the convolution values for all the masks */ 63 | "for (int i=0; i<2; i++) {", 64 | "float dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);", 65 | "cnv[i] = dp3 * dp3; ", 66 | "}", 67 | 68 | "gl_FragColor = vec4(0.5 * sqrt(cnv[0]*cnv[0]+cnv[1]*cnv[1]));", 69 | "} ", 70 | 71 | ].join("\n") 72 | 73 | }; 74 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/VerticalTiltShiftShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Simple fake tilt-shift effect, modulating two pass Gaussian blur (see above) by vertical position 5 | * 6 | * - 9 samples per pass 7 | * - standard deviation 2.7 8 | * - "h" and "v" parameters should be set to "1 / width" and "1 / height" 9 | * - "r" parameter control where "focused" horizontal line lies 10 | */ 11 | 12 | THREE.VerticalTiltShiftShader = { 13 | 14 | uniforms: { 15 | 16 | "tDiffuse": { type: "t", value: null }, 17 | "v": { type: "f", value: 1.0 / 512.0 }, 18 | "r": { type: "f", value: 0.35 } 19 | 20 | }, 21 | 22 | vertexShader: [ 23 | 24 | "varying vec2 vUv;", 25 | 26 | "void main() {", 27 | 28 | "vUv = uv;", 29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 30 | 31 | "}" 32 | 33 | ].join("\n"), 34 | 35 | fragmentShader: [ 36 | 37 | "uniform sampler2D tDiffuse;", 38 | "uniform float v;", 39 | "uniform float r;", 40 | 41 | "varying vec2 vUv;", 42 | 43 | "void main() {", 44 | 45 | "vec4 sum = vec4( 0.0 );", 46 | 47 | "float vv = v * abs( r - vUv.y );", 48 | 49 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * vv ) ) * 0.051;", 50 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * vv ) ) * 0.0918;", 51 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * vv ) ) * 0.12245;", 52 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * vv ) ) * 0.1531;", 53 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;", 54 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * vv ) ) * 0.1531;", 55 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * vv ) ) * 0.12245;", 56 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * vv ) ) * 0.0918;", 57 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * vv ) ) * 0.051;", 58 | 59 | "gl_FragColor = sum;", 60 | 61 | "}" 62 | 63 | ].join("\n") 64 | 65 | }; 66 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/HorizontalTiltShiftShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Simple fake tilt-shift effect, modulating two pass Gaussian blur (see above) by vertical position 5 | * 6 | * - 9 samples per pass 7 | * - standard deviation 2.7 8 | * - "h" and "v" parameters should be set to "1 / width" and "1 / height" 9 | * - "r" parameter control where "focused" horizontal line lies 10 | */ 11 | 12 | THREE.HorizontalTiltShiftShader = { 13 | 14 | uniforms: { 15 | 16 | "tDiffuse": { type: "t", value: null }, 17 | "h": { type: "f", value: 1.0 / 512.0 }, 18 | "r": { type: "f", value: 0.35 } 19 | 20 | }, 21 | 22 | vertexShader: [ 23 | 24 | "varying vec2 vUv;", 25 | 26 | "void main() {", 27 | 28 | "vUv = uv;", 29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 30 | 31 | "}" 32 | 33 | ].join("\n"), 34 | 35 | fragmentShader: [ 36 | 37 | "uniform sampler2D tDiffuse;", 38 | "uniform float h;", 39 | "uniform float r;", 40 | 41 | "varying vec2 vUv;", 42 | 43 | "void main() {", 44 | 45 | "vec4 sum = vec4( 0.0 );", 46 | 47 | "float hh = h * abs( r - vUv.y );", 48 | 49 | "sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * hh, vUv.y ) ) * 0.051;", 50 | "sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * hh, vUv.y ) ) * 0.0918;", 51 | "sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * hh, vUv.y ) ) * 0.12245;", 52 | "sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * hh, vUv.y ) ) * 0.1531;", 53 | "sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;", 54 | "sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * hh, vUv.y ) ) * 0.1531;", 55 | "sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * hh, vUv.y ) ) * 0.12245;", 56 | "sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * hh, vUv.y ) ) * 0.0918;", 57 | "sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * hh, vUv.y ) ) * 0.051;", 58 | 59 | "gl_FragColor = sum;", 60 | 61 | "}" 62 | 63 | ].join("\n") 64 | 65 | }; 66 | -------------------------------------------------------------------------------- /js/threejs/examples/js/postprocessing/MaskPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.MaskPass = function ( scene, camera ) { 6 | 7 | this.scene = scene; 8 | this.camera = camera; 9 | 10 | this.enabled = true; 11 | this.clear = true; 12 | this.needsSwap = false; 13 | 14 | this.inverse = false; 15 | 16 | }; 17 | 18 | THREE.MaskPass.prototype = { 19 | 20 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 21 | 22 | var context = renderer.context; 23 | 24 | // don't update color or depth 25 | 26 | context.colorMask( false, false, false, false ); 27 | context.depthMask( false ); 28 | 29 | // set up stencil 30 | 31 | var writeValue, clearValue; 32 | 33 | if ( this.inverse ) { 34 | 35 | writeValue = 0; 36 | clearValue = 1; 37 | 38 | } else { 39 | 40 | writeValue = 1; 41 | clearValue = 0; 42 | 43 | } 44 | 45 | context.enable( context.STENCIL_TEST ); 46 | context.stencilOp( context.REPLACE, context.REPLACE, context.REPLACE ); 47 | context.stencilFunc( context.ALWAYS, writeValue, 0xffffffff ); 48 | context.clearStencil( clearValue ); 49 | 50 | // draw into the stencil buffer 51 | 52 | renderer.render( this.scene, this.camera, readBuffer, this.clear ); 53 | renderer.render( this.scene, this.camera, writeBuffer, this.clear ); 54 | 55 | // re-enable update of color and depth 56 | 57 | context.colorMask( true, true, true, true ); 58 | context.depthMask( true ); 59 | 60 | // only render where stencil is set to 1 61 | 62 | context.stencilFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1 63 | context.stencilOp( context.KEEP, context.KEEP, context.KEEP ); 64 | 65 | } 66 | 67 | }; 68 | 69 | 70 | THREE.ClearMaskPass = function () { 71 | 72 | this.enabled = true; 73 | 74 | }; 75 | 76 | THREE.ClearMaskPass.prototype = { 77 | 78 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 79 | 80 | var context = renderer.context; 81 | 82 | context.disable( context.STENCIL_TEST ); 83 | 84 | } 85 | 86 | }; 87 | -------------------------------------------------------------------------------- /js/threejs/examples/js/Detector.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * @author mr.doob / http://mrdoob.com/ 4 | */ 5 | 6 | var Detector = { 7 | 8 | canvas: !! window.CanvasRenderingContext2D, 9 | webgl: ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(), 10 | workers: !! window.Worker, 11 | fileapi: window.File && window.FileReader && window.FileList && window.Blob, 12 | 13 | getWebGLErrorMessage: function () { 14 | 15 | var element = document.createElement( 'div' ); 16 | element.id = 'webgl-error-message'; 17 | element.style.fontFamily = 'monospace'; 18 | element.style.fontSize = '13px'; 19 | element.style.fontWeight = 'normal'; 20 | element.style.textAlign = 'center'; 21 | element.style.background = '#fff'; 22 | element.style.color = '#000'; 23 | element.style.padding = '1.5em'; 24 | element.style.width = '400px'; 25 | element.style.margin = '5em auto 0'; 26 | 27 | if ( ! this.webgl ) { 28 | 29 | element.innerHTML = window.WebGLRenderingContext ? [ 30 | 'Your graphics card does not seem to support WebGL.
', 31 | 'Find out how to get it here.' 32 | ].join( '\n' ) : [ 33 | 'Your browser does not seem to support WebGL.
', 34 | 'Find out how to get it here.' 35 | ].join( '\n' ); 36 | 37 | } 38 | 39 | return element; 40 | 41 | }, 42 | 43 | addGetWebGLMessage: function ( parameters ) { 44 | 45 | var parent, id, element; 46 | 47 | parameters = parameters || {}; 48 | 49 | parent = parameters.parent !== undefined ? parameters.parent : document.body; 50 | id = parameters.id !== undefined ? parameters.id : 'oldie'; 51 | 52 | element = Detector.getWebGLErrorMessage(); 53 | element.id = id; 54 | 55 | parent.appendChild( element ); 56 | 57 | } 58 | 59 | }; 60 | -------------------------------------------------------------------------------- /js/threejs/examples/js/libs/stats.min.js: -------------------------------------------------------------------------------- 1 | // stats.js - http://github.com/mrdoob/stats.js 2 | var Stats=function(){var l=Date.now(),m=l,g=0,n=Infinity,o=0,h=0,p=Infinity,q=0,r=0,s=0,f=document.createElement("div");f.id="stats";f.addEventListener("mousedown",function(b){b.preventDefault();t(++s%2)},!1);f.style.cssText="width:80px;opacity:0.9;cursor:pointer";var a=document.createElement("div");a.id="fps";a.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#002";f.appendChild(a);var i=document.createElement("div");i.id="fpsText";i.style.cssText="color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px"; 3 | i.innerHTML="FPS";a.appendChild(i);var c=document.createElement("div");c.id="fpsGraph";c.style.cssText="position:relative;width:74px;height:30px;background-color:#0ff";for(a.appendChild(c);74>c.children.length;){var j=document.createElement("span");j.style.cssText="width:1px;height:30px;float:left;background-color:#113";c.appendChild(j)}var d=document.createElement("div");d.id="ms";d.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#020;display:none";f.appendChild(d);var k=document.createElement("div"); 4 | k.id="msText";k.style.cssText="color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";k.innerHTML="MS";d.appendChild(k);var e=document.createElement("div");e.id="msGraph";e.style.cssText="position:relative;width:74px;height:30px;background-color:#0f0";for(d.appendChild(e);74>e.children.length;)j=document.createElement("span"),j.style.cssText="width:1px;height:30px;float:left;background-color:#131",e.appendChild(j);var t=function(b){s=b;switch(s){case 0:a.style.display= 5 | "block";d.style.display="none";break;case 1:a.style.display="none",d.style.display="block"}};return{REVISION:11,domElement:f,setMode:t,begin:function(){l=Date.now()},end:function(){var b=Date.now();g=b-l;n=Math.min(n,g);o=Math.max(o,g);k.textContent=g+" MS ("+n+"-"+o+")";var a=Math.min(30,30-30*(g/200));e.appendChild(e.firstChild).style.height=a+"px";r++;b>m+1E3&&(h=Math.round(1E3*r/(b-m)),p=Math.min(p,h),q=Math.max(q,h),i.textContent=h+" FPS ("+p+"-"+q+")",a=Math.min(30,30-30*(h/100)),c.appendChild(c.firstChild).style.height= 6 | a+"px",m=b,r=0);return b},update:function(){l=this.end()}}}; 7 | -------------------------------------------------------------------------------- /js/threejs/examples/js/exporters/MaterialExporter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | */ 4 | 5 | THREE.MaterialExporter = function () {}; 6 | 7 | THREE.MaterialExporter.prototype = { 8 | 9 | constructor: THREE.MaterialExporter, 10 | 11 | parse: function ( material ) { 12 | 13 | var output = { 14 | metadata: { 15 | version: 4.0, 16 | type: 'material', 17 | generator: 'MaterialExporter' 18 | } 19 | }; 20 | 21 | if ( material.name !== "" ) output.name = material.name; 22 | 23 | if ( material instanceof THREE.MeshBasicMaterial ) { 24 | 25 | output.type = 'MeshBasicMaterial'; 26 | output.color = material.color.getHex(); 27 | output.opacity = material.opacity; 28 | output.transparent = material.transparent; 29 | output.wireframe = material.wireframe; 30 | 31 | } else if ( material instanceof THREE.MeshLambertMaterial ) { 32 | 33 | output.type = 'MeshLambertMaterial'; 34 | output.color = material.color.getHex(); 35 | output.ambient = material.ambient.getHex(); 36 | output.emissive = material.emissive.getHex(); 37 | output.opacity = material.opacity; 38 | output.transparent = material.transparent; 39 | output.wireframe = material.wireframe; 40 | 41 | } else if ( material instanceof THREE.MeshPhongMaterial ) { 42 | 43 | output.type = 'MeshPhongMaterial'; 44 | output.color = material.color.getHex(); 45 | output.ambient = material.ambient.getHex(); 46 | output.emissive = material.emissive.getHex(); 47 | output.specular = material.specular.getHex(); 48 | output.shininess = material.shininess; 49 | output.opacity = material.opacity; 50 | output.transparent = material.transparent; 51 | output.wireframe = material.wireframe; 52 | 53 | } else if ( material instanceof THREE.MeshNormalMaterial ) { 54 | 55 | output.type = 'MeshNormalMaterial'; 56 | output.opacity = material.opacity; 57 | output.transparent = material.transparent; 58 | output.wireframe = material.wireframe; 59 | 60 | } else if ( material instanceof THREE.MeshDepthMaterial ) { 61 | 62 | output.type = 'MeshDepthMaterial'; 63 | output.opacity = material.opacity; 64 | output.transparent = material.transparent; 65 | output.wireframe = material.wireframe; 66 | 67 | } 68 | 69 | return output; 70 | 71 | } 72 | 73 | }; 74 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/FresnelShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Based on Nvidia Cg tutorial 5 | */ 6 | 7 | THREE.FresnelShader = { 8 | 9 | uniforms: { 10 | 11 | "mRefractionRatio": { type: "f", value: 1.02 }, 12 | "mFresnelBias": { type: "f", value: 0.1 }, 13 | "mFresnelPower": { type: "f", value: 2.0 }, 14 | "mFresnelScale": { type: "f", value: 1.0 }, 15 | "tCube": { type: "t", value: null } 16 | 17 | }, 18 | 19 | vertexShader: [ 20 | 21 | "uniform float mRefractionRatio;", 22 | "uniform float mFresnelBias;", 23 | "uniform float mFresnelScale;", 24 | "uniform float mFresnelPower;", 25 | 26 | "varying vec3 vReflect;", 27 | "varying vec3 vRefract[3];", 28 | "varying float vReflectionFactor;", 29 | 30 | "void main() {", 31 | 32 | "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );", 33 | "vec4 worldPosition = modelMatrix * vec4( position, 1.0 );", 34 | 35 | "vec3 worldNormal = normalize( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );", 36 | 37 | "vec3 I = worldPosition.xyz - cameraPosition;", 38 | 39 | "vReflect = reflect( I, worldNormal );", 40 | "vRefract[0] = refract( normalize( I ), worldNormal, mRefractionRatio );", 41 | "vRefract[1] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.99 );", 42 | "vRefract[2] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.98 );", 43 | "vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), worldNormal ), mFresnelPower );", 44 | 45 | "gl_Position = projectionMatrix * mvPosition;", 46 | 47 | "}" 48 | 49 | ].join("\n"), 50 | 51 | fragmentShader: [ 52 | 53 | "uniform samplerCube tCube;", 54 | 55 | "varying vec3 vReflect;", 56 | "varying vec3 vRefract[3];", 57 | "varying float vReflectionFactor;", 58 | 59 | "void main() {", 60 | 61 | "vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );", 62 | "vec4 refractedColor = vec4( 1.0 );", 63 | 64 | "refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;", 65 | "refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;", 66 | "refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;", 67 | 68 | "gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );", 69 | 70 | "}" 71 | 72 | ].join("\n") 73 | 74 | }; 75 | -------------------------------------------------------------------------------- /js/threejs/examples/js/ImprovedNoise.js: -------------------------------------------------------------------------------- 1 | // http://mrl.nyu.edu/~perlin/noise/ 2 | 3 | var ImprovedNoise = function () { 4 | 5 | var p = [151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10, 6 | 23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87, 7 | 174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211, 8 | 133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 9 | 89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5, 10 | 202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119, 11 | 248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232, 12 | 178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249, 13 | 14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205, 14 | 93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]; 15 | 16 | for (var i=0; i < 256 ; i++) { 17 | 18 | p[256+i] = p[i]; 19 | 20 | } 21 | 22 | function fade(t) { 23 | 24 | return t * t * t * (t * (t * 6 - 15) + 10); 25 | 26 | } 27 | 28 | function lerp(t, a, b) { 29 | 30 | return a + t * (b - a); 31 | 32 | } 33 | 34 | function grad(hash, x, y, z) { 35 | 36 | var h = hash & 15; 37 | var u = h < 8 ? x : y, v = h < 4 ? y : h == 12 || h == 14 ? x : z; 38 | return ((h&1) == 0 ? u : -u) + ((h&2) == 0 ? v : -v); 39 | 40 | } 41 | 42 | return { 43 | 44 | noise: function (x, y, z) { 45 | 46 | var floorX = ~~x, floorY = ~~y, floorZ = ~~z; 47 | 48 | var X = floorX & 255, Y = floorY & 255, Z = floorZ & 255; 49 | 50 | x -= floorX; 51 | y -= floorY; 52 | z -= floorZ; 53 | 54 | var xMinus1 = x -1, yMinus1 = y - 1, zMinus1 = z - 1; 55 | 56 | var u = fade(x), v = fade(y), w = fade(z); 57 | 58 | var A = p[X]+Y, AA = p[A]+Z, AB = p[A+1]+Z, B = p[X+1]+Y, BA = p[B]+Z, BB = p[B+1]+Z; 59 | 60 | return lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z), 61 | grad(p[BA], xMinus1, y, z)), 62 | lerp(u, grad(p[AB], x, yMinus1, z), 63 | grad(p[BB], xMinus1, yMinus1, z))), 64 | lerp(v, lerp(u, grad(p[AA+1], x, y, zMinus1), 65 | grad(p[BA+1], xMinus1, y, z-1)), 66 | lerp(u, grad(p[AB+1], x, yMinus1, zMinus1), 67 | grad(p[BB+1], xMinus1, yMinus1, zMinus1)))); 68 | 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/ConvolutionShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Convolution shader 5 | * ported from o3d sample to WebGL / GLSL 6 | * http://o3d.googlecode.com/svn/trunk/samples/convolution.html 7 | */ 8 | 9 | THREE.ConvolutionShader = { 10 | 11 | defines: { 12 | 13 | "KERNEL_SIZE_FLOAT": "25.0", 14 | "KERNEL_SIZE_INT": "25", 15 | 16 | }, 17 | 18 | uniforms: { 19 | 20 | "tDiffuse": { type: "t", value: null }, 21 | "uImageIncrement": { type: "v2", value: new THREE.Vector2( 0.001953125, 0.0 ) }, 22 | "cKernel": { type: "fv1", value: [] } 23 | 24 | }, 25 | 26 | vertexShader: [ 27 | 28 | "uniform vec2 uImageIncrement;", 29 | 30 | "varying vec2 vUv;", 31 | 32 | "void main() {", 33 | 34 | "vUv = uv - ( ( KERNEL_SIZE_FLOAT - 1.0 ) / 2.0 ) * uImageIncrement;", 35 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 36 | 37 | "}" 38 | 39 | ].join("\n"), 40 | 41 | fragmentShader: [ 42 | 43 | "uniform float cKernel[ KERNEL_SIZE_INT ];", 44 | 45 | "uniform sampler2D tDiffuse;", 46 | "uniform vec2 uImageIncrement;", 47 | 48 | "varying vec2 vUv;", 49 | 50 | "void main() {", 51 | 52 | "vec2 imageCoord = vUv;", 53 | "vec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );", 54 | 55 | "for( int i = 0; i < KERNEL_SIZE_INT; i ++ ) {", 56 | 57 | "sum += texture2D( tDiffuse, imageCoord ) * cKernel[ i ];", 58 | "imageCoord += uImageIncrement;", 59 | 60 | "}", 61 | 62 | "gl_FragColor = sum;", 63 | 64 | "}" 65 | 66 | 67 | ].join("\n"), 68 | 69 | buildKernel: function ( sigma ) { 70 | 71 | // We lop off the sqrt(2 * pi) * sigma term, since we're going to normalize anyway. 72 | 73 | function gauss( x, sigma ) { 74 | 75 | return Math.exp( - ( x * x ) / ( 2.0 * sigma * sigma ) ); 76 | 77 | } 78 | 79 | var i, values, sum, halfWidth, kMaxKernelSize = 25, kernelSize = 2 * Math.ceil( sigma * 3.0 ) + 1; 80 | 81 | if ( kernelSize > kMaxKernelSize ) kernelSize = kMaxKernelSize; 82 | halfWidth = ( kernelSize - 1 ) * 0.5; 83 | 84 | values = new Array( kernelSize ); 85 | sum = 0.0; 86 | for ( i = 0; i < kernelSize; ++i ) { 87 | 88 | values[ i ] = gauss( i - halfWidth, sigma ); 89 | sum += values[ i ]; 90 | 91 | } 92 | 93 | // normalize the kernel 94 | 95 | for ( i = 0; i < kernelSize; ++i ) values[ i ] /= sum; 96 | 97 | return values; 98 | 99 | } 100 | 101 | }; 102 | -------------------------------------------------------------------------------- /js/threejs/examples/js/math/TypeArrayVector3.js: -------------------------------------------------------------------------------- 1 | THREE.TypeArrayVector3 = function ( x, y, z ) { 2 | 3 | this.elements = new Float64Array( 3 ); 4 | this.set( x, y, z ); 5 | 6 | }; 7 | 8 | 9 | THREE.TypeArrayVector3.prototype = { 10 | 11 | constructor: THREE.TypeArrayVector3, 12 | 13 | get x() { 14 | 15 | return this.elements[ 0 ]; 16 | 17 | }, 18 | 19 | set x( value ) { 20 | 21 | this.elements[ 0 ] = value; 22 | 23 | }, 24 | 25 | get y() { 26 | 27 | return this.elements[ 1 ]; 28 | 29 | }, 30 | 31 | set y( value ) { 32 | 33 | this.elements[ 1 ] = value; 34 | 35 | }, 36 | 37 | get z() { 38 | 39 | return this.elements[ 2 ]; 40 | 41 | }, 42 | 43 | set z( value ) { 44 | 45 | this.elements[ 2 ] = value; 46 | 47 | }, 48 | 49 | set: function ( x, y, z ) { 50 | 51 | var elements = this.elements; 52 | 53 | elements[ 0 ] = x; 54 | elements[ 1 ] = y; 55 | elements[ 2 ] = z; 56 | 57 | return this; 58 | 59 | }, 60 | 61 | copy: function ( v ) { 62 | 63 | var elements = this.elements; 64 | var velements = v.elements; 65 | 66 | elements[ 0 ] = velements[ 0 ]; 67 | elements[ 1 ] = velements[ 1 ]; 68 | elements[ 2 ] = velements[ 2 ]; 69 | 70 | return this; 71 | 72 | }, 73 | 74 | add: function ( v ) { 75 | 76 | var elements = this.elements; 77 | var velements = v.elements; 78 | 79 | elements[ 0 ] += velements[ 0 ]; 80 | elements[ 1 ] += velements[ 1 ]; 81 | elements[ 2 ] += velements[ 2 ]; 82 | 83 | return this; 84 | 85 | }, 86 | 87 | addVectors: function ( a, b ) { 88 | 89 | var elements = this.elements; 90 | var aelements = a.elements; 91 | var belements = b.elements; 92 | 93 | elements[ 0 ] = aelements[ 0 ] + belements[ 0 ]; 94 | elements[ 1 ] = aelements[ 1 ] + belements[ 1 ]; 95 | elements[ 2 ] = aelements[ 2 ] + belements[ 2 ]; 96 | 97 | return this; 98 | 99 | }, 100 | 101 | sub: function ( v, w ) { 102 | 103 | var elements = this.elements; 104 | var velements = v.elements; 105 | 106 | elements[ 0 ] -= velements[ 0 ]; 107 | elements[ 1 ] -= velements[ 1 ]; 108 | elements[ 2 ] -= velements[ 2 ]; 109 | 110 | return this; 111 | 112 | }, 113 | 114 | subVectors: function ( a, b ) { 115 | 116 | var elements = this.elements; 117 | var aelements = a.elements; 118 | var belements = b.elements; 119 | 120 | elements[ 0 ] = aelements[ 0 ] - belements[ 0 ]; 121 | elements[ 1 ] = aelements[ 1 ] - belements[ 1 ]; 122 | elements[ 2 ] = aelements[ 2 ] - belements[ 2 ]; 123 | 124 | return this; 125 | 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /js/threejs/examples/js/exporters/OBJExporter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | */ 4 | 5 | THREE.OBJExporter = function () {}; 6 | 7 | THREE.OBJExporter.prototype = { 8 | 9 | constructor: THREE.OBJExporter, 10 | 11 | parse: function ( geometry ) { 12 | 13 | console.log( geometry ); 14 | 15 | var output = ''; 16 | 17 | for ( var i = 0, l = geometry.vertices.length; i < l; i ++ ) { 18 | 19 | var vertex = geometry.vertices[ i ]; 20 | output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n'; 21 | 22 | } 23 | 24 | // uvs 25 | 26 | for ( var i = 0, l = geometry.faceVertexUvs[ 0 ].length; i < l; i ++ ) { 27 | 28 | var vertexUvs = geometry.faceVertexUvs[ 0 ][ i ]; 29 | 30 | for ( var j = 0; j < vertexUvs.length; j ++ ) { 31 | 32 | var uv = vertexUvs[ j ]; 33 | output += 'vt ' + uv.x + ' ' + uv.y + '\n'; 34 | 35 | } 36 | 37 | } 38 | 39 | // normals 40 | 41 | for ( var i = 0, l = geometry.faces.length; i < l; i ++ ) { 42 | 43 | var normals = geometry.faces[ i ].vertexNormals; 44 | 45 | for ( var j = 0; j < normals.length; j ++ ) { 46 | 47 | var normal = normals[ j ]; 48 | output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n'; 49 | 50 | } 51 | 52 | } 53 | 54 | // map 55 | 56 | var count = 1; // OBJ values start by 1 57 | var map = [ count ]; 58 | 59 | for ( var i = 0, l = geometry.faces.length; i < l; i ++ ) { 60 | 61 | var face = geometry.faces[ i ]; 62 | 63 | if ( face instanceof THREE.Face3 ) { 64 | 65 | count += 3; 66 | 67 | } else if ( face instanceof THREE.Face4 ) { 68 | 69 | count += 4; 70 | 71 | } 72 | 73 | map.push( count ); 74 | 75 | } 76 | 77 | // faces 78 | 79 | for ( var i = 0, l = geometry.faces.length; i < l; i ++ ) { 80 | 81 | var face = geometry.faces[ i ]; 82 | 83 | output += 'f '; 84 | 85 | if ( face instanceof THREE.Face3 ) { 86 | 87 | output += ( face.a + 1 ) + '/' + ( map[ i ] ) + '/' + ( map[ i ] ) + ' '; 88 | output += ( face.b + 1 ) + '/' + ( map[ i ] + 1 ) + '/' + ( map[ i ] + 1 ) + ' '; 89 | output += ( face.c + 1 ) + '/' + ( map[ i ] + 2 ) + '/' + ( map[ i ] + 2 ) + '\n'; 90 | 91 | } else if ( face instanceof THREE.Face4 ) { 92 | 93 | output += ( face.a + 1 ) + '/' + ( map[ i ] ) + '/' + ( map[ i ] ) + ' '; 94 | output += ( face.b + 1 ) + '/' + ( map[ i ] + 1 ) + '/' + ( map[ i ] + 1 ) + ' '; 95 | output += ( face.c + 1 ) + '/' + ( map[ i ] + 2 ) + '/' + ( map[ i ] + 2 ) + ' '; 96 | output += ( face.d + 1 ) + '/' + ( map[ i ] + 3 ) + '/' + ( map[ i ] + 3 ) + '\n'; 97 | 98 | } 99 | 100 | } 101 | 102 | return output; 103 | 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/FocusShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Focus shader 5 | * based on PaintEffect postprocess from ro.me 6 | * http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js 7 | */ 8 | 9 | THREE.FocusShader = { 10 | 11 | uniforms : { 12 | 13 | "tDiffuse": { type: "t", value: null }, 14 | "screenWidth": { type: "f", value: 1024 }, 15 | "screenHeight": { type: "f", value: 1024 }, 16 | "sampleDistance": { type: "f", value: 0.94 }, 17 | "waveFactor": { type: "f", value: 0.00125 } 18 | 19 | }, 20 | 21 | vertexShader: [ 22 | 23 | "varying vec2 vUv;", 24 | 25 | "void main() {", 26 | 27 | "vUv = uv;", 28 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 29 | 30 | "}" 31 | 32 | ].join("\n"), 33 | 34 | fragmentShader: [ 35 | 36 | "uniform float screenWidth;", 37 | "uniform float screenHeight;", 38 | "uniform float sampleDistance;", 39 | "uniform float waveFactor;", 40 | 41 | "uniform sampler2D tDiffuse;", 42 | 43 | "varying vec2 vUv;", 44 | 45 | "void main() {", 46 | 47 | "vec4 color, org, tmp, add;", 48 | "float sample_dist, f;", 49 | "vec2 vin;", 50 | "vec2 uv = vUv;", 51 | 52 | "add = color = org = texture2D( tDiffuse, uv );", 53 | 54 | "vin = ( uv - vec2( 0.5 ) ) * vec2( 1.4 );", 55 | "sample_dist = dot( vin, vin ) * 2.0;", 56 | 57 | "f = ( waveFactor * 100.0 + sample_dist ) * sampleDistance * 4.0;", 58 | 59 | "vec2 sampleSize = vec2( 1.0 / screenWidth, 1.0 / screenHeight ) * vec2( f );", 60 | 61 | "add += tmp = texture2D( tDiffuse, uv + vec2( 0.111964, 0.993712 ) * sampleSize );", 62 | "if( tmp.b < color.b ) color = tmp;", 63 | 64 | "add += tmp = texture2D( tDiffuse, uv + vec2( 0.846724, 0.532032 ) * sampleSize );", 65 | "if( tmp.b < color.b ) color = tmp;", 66 | 67 | "add += tmp = texture2D( tDiffuse, uv + vec2( 0.943883, -0.330279 ) * sampleSize );", 68 | "if( tmp.b < color.b ) color = tmp;", 69 | 70 | "add += tmp = texture2D( tDiffuse, uv + vec2( 0.330279, -0.943883 ) * sampleSize );", 71 | "if( tmp.b < color.b ) color = tmp;", 72 | 73 | "add += tmp = texture2D( tDiffuse, uv + vec2( -0.532032, -0.846724 ) * sampleSize );", 74 | "if( tmp.b < color.b ) color = tmp;", 75 | 76 | "add += tmp = texture2D( tDiffuse, uv + vec2( -0.993712, -0.111964 ) * sampleSize );", 77 | "if( tmp.b < color.b ) color = tmp;", 78 | 79 | "add += tmp = texture2D( tDiffuse, uv + vec2( -0.707107, 0.707107 ) * sampleSize );", 80 | "if( tmp.b < color.b ) color = tmp;", 81 | 82 | "color = color * vec4( 2.0 ) - ( add / vec4( 8.0 ) );", 83 | "color = color + ( add / vec4( 8.0 ) - color ) * ( vec4( 1.0 ) - vec4( sample_dist * 0.5 ) );", 84 | 85 | "gl_FragColor = vec4( color.rgb * color.rgb * vec3( 0.95 ) + color.rgb, 1.0 );", 86 | 87 | "}" 88 | 89 | 90 | ].join("\n") 91 | }; 92 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/FilmShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Film grain & scanlines shader 5 | * 6 | * - ported from HLSL to WebGL / GLSL 7 | * http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html 8 | * 9 | * Screen Space Static Postprocessor 10 | * 11 | * Produces an analogue noise overlay similar to a film grain / TV static 12 | * 13 | * Original implementation and noise algorithm 14 | * Pat 'Hawthorne' Shearon 15 | * 16 | * Optimized scanlines + noise version with intensity scaling 17 | * Georg 'Leviathan' Steinrohder 18 | * 19 | * This version is provided under a Creative Commons Attribution 3.0 License 20 | * http://creativecommons.org/licenses/by/3.0/ 21 | */ 22 | 23 | THREE.FilmShader = { 24 | 25 | uniforms: { 26 | 27 | "tDiffuse": { type: "t", value: null }, 28 | "time": { type: "f", value: 0.0 }, 29 | "nIntensity": { type: "f", value: 0.5 }, 30 | "sIntensity": { type: "f", value: 0.05 }, 31 | "sCount": { type: "f", value: 4096 }, 32 | "grayscale": { type: "i", value: 1 } 33 | 34 | }, 35 | 36 | vertexShader: [ 37 | 38 | "varying vec2 vUv;", 39 | 40 | "void main() {", 41 | 42 | "vUv = uv;", 43 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 44 | 45 | "}" 46 | 47 | ].join("\n"), 48 | 49 | fragmentShader: [ 50 | 51 | // control parameter 52 | "uniform float time;", 53 | 54 | "uniform bool grayscale;", 55 | 56 | // noise effect intensity value (0 = no effect, 1 = full effect) 57 | "uniform float nIntensity;", 58 | 59 | // scanlines effect intensity value (0 = no effect, 1 = full effect) 60 | "uniform float sIntensity;", 61 | 62 | // scanlines effect count value (0 = no effect, 4096 = full effect) 63 | "uniform float sCount;", 64 | 65 | "uniform sampler2D tDiffuse;", 66 | 67 | "varying vec2 vUv;", 68 | 69 | "void main() {", 70 | 71 | // sample the source 72 | "vec4 cTextureScreen = texture2D( tDiffuse, vUv );", 73 | 74 | // make some noise 75 | "float x = vUv.x * vUv.y * time * 1000.0;", 76 | "x = mod( x, 13.0 ) * mod( x, 123.0 );", 77 | "float dx = mod( x, 0.01 );", 78 | 79 | // add noise 80 | "vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx * 100.0, 0.0, 1.0 );", 81 | 82 | // get us a sine and cosine 83 | "vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );", 84 | 85 | // add scanlines 86 | "cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;", 87 | 88 | // interpolate between source and result by intensity 89 | "cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );", 90 | 91 | // convert to grayscale if desired 92 | "if( grayscale ) {", 93 | 94 | "cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );", 95 | 96 | "}", 97 | 98 | "gl_FragColor = vec4( cResult, cTextureScreen.a );", 99 | 100 | "}" 101 | 102 | ].join("\n") 103 | 104 | }; 105 | -------------------------------------------------------------------------------- /js/threejs/examples/js/loaders/VTKLoader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | */ 4 | 5 | THREE.VTKLoader = function () {}; 6 | 7 | THREE.VTKLoader.prototype = { 8 | 9 | constructor: THREE.VTKLoader, 10 | 11 | addEventListener: THREE.EventDispatcher.prototype.addEventListener, 12 | hasEventListener: THREE.EventDispatcher.prototype.hasEventListener, 13 | removeEventListener: THREE.EventDispatcher.prototype.removeEventListener, 14 | dispatchEvent: THREE.EventDispatcher.prototype.dispatchEvent, 15 | 16 | load: function ( url, callback ) { 17 | 18 | var scope = this; 19 | var request = new XMLHttpRequest(); 20 | 21 | request.addEventListener( 'load', function ( event ) { 22 | 23 | var geometry = scope.parse( event.target.responseText ); 24 | 25 | scope.dispatchEvent( { type: 'load', content: geometry } ); 26 | 27 | if ( callback ) callback( geometry ); 28 | 29 | }, false ); 30 | 31 | request.addEventListener( 'progress', function ( event ) { 32 | 33 | scope.dispatchEvent( { type: 'progress', loaded: event.loaded, total: event.total } ); 34 | 35 | }, false ); 36 | 37 | request.addEventListener( 'error', function () { 38 | 39 | scope.dispatchEvent( { type: 'error', message: 'Couldn\'t load URL [' + url + ']' } ); 40 | 41 | }, false ); 42 | 43 | request.open( 'GET', url, true ); 44 | request.send( null ); 45 | 46 | }, 47 | 48 | parse: function ( data ) { 49 | 50 | var geometry = new THREE.Geometry(); 51 | 52 | function vertex( x, y, z ) { 53 | 54 | geometry.vertices.push( new THREE.Vector3( x, y, z ) ); 55 | 56 | } 57 | 58 | function face3( a, b, c ) { 59 | 60 | geometry.faces.push( new THREE.Face3( a, b, c ) ); 61 | 62 | } 63 | 64 | function face4( a, b, c, d ) { 65 | 66 | geometry.faces.push( new THREE.Face4( a, b, c, d ) ); 67 | 68 | } 69 | 70 | var pattern, result; 71 | 72 | // float float float 73 | 74 | pattern = /([\+|\-]?[\d]+[\.][\d|\-|e]+)[ ]+([\+|\-]?[\d]+[\.][\d|\-|e]+)[ ]+([\+|\-]?[\d]+[\.][\d|\-|e]+)/g; 75 | 76 | while ( ( result = pattern.exec( data ) ) != null ) { 77 | 78 | // ["1.0 2.0 3.0", "1.0", "2.0", "3.0"] 79 | 80 | vertex( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) ); 81 | 82 | } 83 | 84 | // 3 int int int 85 | 86 | pattern = /3[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g; 87 | 88 | while ( ( result = pattern.exec( data ) ) != null ) { 89 | 90 | // ["3 1 2 3", "1", "2", "3"] 91 | 92 | face3( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ) ); 93 | 94 | } 95 | 96 | // 4 int int int int 97 | 98 | pattern = /4[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/g; 99 | 100 | while ( ( result = pattern.exec( data ) ) != null ) { 101 | 102 | // ["4 1 2 3 4", "1", "2", "3", "4"] 103 | 104 | face4( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ), parseInt( result[ 4 ] ) ); 105 | 106 | } 107 | 108 | geometry.computeCentroids(); 109 | geometry.computeFaceNormals(); 110 | geometry.computeVertexNormals(); 111 | geometry.computeBoundingSphere(); 112 | 113 | return geometry; 114 | 115 | } 116 | 117 | }; 118 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/FXAAShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * @author davidedc / http://www.sketchpatch.net/ 4 | * 5 | * NVIDIA FXAA by Timothy Lottes 6 | * http://timothylottes.blogspot.com/2011/06/fxaa3-source-released.html 7 | * - WebGL port by @supereggbert 8 | * http://www.glge.org/demos/fxaa/ 9 | */ 10 | 11 | THREE.FXAAShader = { 12 | 13 | uniforms: { 14 | 15 | "tDiffuse": { type: "t", value: null }, 16 | "resolution": { type: "v2", value: new THREE.Vector2( 1 / 1024, 1 / 512 ) } 17 | 18 | }, 19 | 20 | vertexShader: [ 21 | 22 | "varying vec2 vUv;", 23 | 24 | "void main() {", 25 | 26 | "vUv = uv;", 27 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 28 | 29 | "}" 30 | 31 | ].join("\n"), 32 | 33 | fragmentShader: [ 34 | 35 | "uniform sampler2D tDiffuse;", 36 | "uniform vec2 resolution;", 37 | 38 | "varying vec2 vUv;", 39 | 40 | "#define FXAA_REDUCE_MIN (1.0/128.0)", 41 | "#define FXAA_REDUCE_MUL (1.0/8.0)", 42 | "#define FXAA_SPAN_MAX 8.0", 43 | 44 | "void main() {", 45 | 46 | "vec3 rgbNW = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ).xyz;", 47 | "vec3 rgbNE = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ).xyz;", 48 | "vec3 rgbSW = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ).xyz;", 49 | "vec3 rgbSE = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ).xyz;", 50 | "vec4 rgbaM = texture2D( tDiffuse, gl_FragCoord.xy * resolution );", 51 | "vec3 rgbM = rgbaM.xyz;", 52 | "float opacity = rgbaM.w;", 53 | 54 | "vec3 luma = vec3( 0.299, 0.587, 0.114 );", 55 | 56 | "float lumaNW = dot( rgbNW, luma );", 57 | "float lumaNE = dot( rgbNE, luma );", 58 | "float lumaSW = dot( rgbSW, luma );", 59 | "float lumaSE = dot( rgbSE, luma );", 60 | "float lumaM = dot( rgbM, luma );", 61 | "float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) );", 62 | "float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) );", 63 | 64 | "vec2 dir;", 65 | "dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));", 66 | "dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));", 67 | 68 | "float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN );", 69 | 70 | "float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce );", 71 | "dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),", 72 | "max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),", 73 | "dir * rcpDirMin)) * resolution;", 74 | 75 | "vec3 rgbA = 0.5 * (", 76 | "texture2D( tDiffuse, gl_FragCoord.xy * resolution + dir * ( 1.0 / 3.0 - 0.5 ) ).xyz +", 77 | "texture2D( tDiffuse, gl_FragCoord.xy * resolution + dir * ( 2.0 / 3.0 - 0.5 ) ).xyz );", 78 | 79 | "vec3 rgbB = rgbA * 0.5 + 0.25 * (", 80 | "texture2D( tDiffuse, gl_FragCoord.xy * resolution + dir * -0.5 ).xyz +", 81 | "texture2D( tDiffuse, gl_FragCoord.xy * resolution + dir * 0.5 ).xyz );", 82 | 83 | "float lumaB = dot( rgbB, luma );", 84 | 85 | "if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) ) {", 86 | 87 | "gl_FragColor = vec4( rgbA, opacity );", 88 | 89 | "} else {", 90 | 91 | "gl_FragColor = vec4( rgbB, opacity );", 92 | 93 | "}", 94 | 95 | "}" 96 | 97 | ].join("\n") 98 | 99 | }; 100 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/EdgeShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author zz85 / https://github.com/zz85 | https://www.lab4games.net/zz85/blog 3 | * 4 | * Edge Detection Shader using Frei-Chen filter 5 | * Based on http://rastergrid.com/blog/2011/01/frei-chen-edge-detector 6 | * 7 | * aspect: vec2 of (1/width, 1/height) 8 | */ 9 | 10 | THREE.EdgeShader = { 11 | 12 | uniforms: { 13 | 14 | "tDiffuse": { type: "t", value: null }, 15 | "aspect": { type: "v2", value: new THREE.Vector2( 512, 512 ) }, 16 | }, 17 | 18 | vertexShader: [ 19 | 20 | "varying vec2 vUv;", 21 | 22 | "void main() {", 23 | 24 | "vUv = uv;", 25 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 26 | 27 | "}" 28 | 29 | ].join("\n"), 30 | 31 | fragmentShader: [ 32 | 33 | "uniform sampler2D tDiffuse;", 34 | "varying vec2 vUv;", 35 | 36 | "uniform vec2 aspect;", 37 | 38 | "vec2 texel = vec2(1.0 / aspect.x, 1.0 / aspect.y);", 39 | 40 | 41 | "mat3 G[9];", 42 | 43 | // hard coded matrix values!!!! as suggested in https://github.com/neilmendoza/ofxPostProcessing/blob/master/src/EdgePass.cpp#L45 44 | 45 | "const mat3 g0 = mat3( 0.3535533845424652, 0, -0.3535533845424652, 0.5, 0, -0.5, 0.3535533845424652, 0, -0.3535533845424652 );", 46 | "const mat3 g1 = mat3( 0.3535533845424652, 0.5, 0.3535533845424652, 0, 0, 0, -0.3535533845424652, -0.5, -0.3535533845424652 );", 47 | "const mat3 g2 = mat3( 0, 0.3535533845424652, -0.5, -0.3535533845424652, 0, 0.3535533845424652, 0.5, -0.3535533845424652, 0 );", 48 | "const mat3 g3 = mat3( 0.5, -0.3535533845424652, 0, -0.3535533845424652, 0, 0.3535533845424652, 0, 0.3535533845424652, -0.5 );", 49 | "const mat3 g4 = mat3( 0, -0.5, 0, 0.5, 0, 0.5, 0, -0.5, 0 );", 50 | "const mat3 g5 = mat3( -0.5, 0, 0.5, 0, 0, 0, 0.5, 0, -0.5 );", 51 | "const mat3 g6 = mat3( 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.6666666865348816, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204 );", 52 | "const mat3 g7 = mat3( -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, 0.6666666865348816, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408 );", 53 | "const mat3 g8 = mat3( 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408 );", 54 | 55 | "void main(void)", 56 | "{", 57 | 58 | "G[0] = g0,", 59 | "G[1] = g1,", 60 | "G[2] = g2,", 61 | "G[3] = g3,", 62 | "G[4] = g4,", 63 | "G[5] = g5,", 64 | "G[6] = g6,", 65 | "G[7] = g7,", 66 | "G[8] = g8;", 67 | 68 | "mat3 I;", 69 | "float cnv[9];", 70 | "vec3 sample;", 71 | 72 | /* fetch the 3x3 neighbourhood and use the RGB vector's length as intensity value */ 73 | "for (float i=0.0; i<3.0; i++) {", 74 | "for (float j=0.0; j<3.0; j++) {", 75 | "sample = texture2D(tDiffuse, vUv + texel * vec2(i-1.0,j-1.0) ).rgb;", 76 | "I[int(i)][int(j)] = length(sample);", 77 | "}", 78 | "}", 79 | 80 | /* calculate the convolution values for all the masks */ 81 | "for (int i=0; i<9; i++) {", 82 | "float dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);", 83 | "cnv[i] = dp3 * dp3;", 84 | "}", 85 | 86 | "float M = (cnv[0] + cnv[1]) + (cnv[2] + cnv[3]);", 87 | "float S = (cnv[4] + cnv[5]) + (cnv[6] + cnv[7]) + (cnv[8] + M);", 88 | 89 | "gl_FragColor = vec4(vec3(sqrt(M/S)), 1.0);", 90 | "}", 91 | 92 | ].join("\n") 93 | }; 94 | -------------------------------------------------------------------------------- /js/threejs/examples/js/postprocessing/EffectComposer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.EffectComposer = function ( renderer, renderTarget ) { 6 | 7 | this.renderer = renderer; 8 | 9 | if ( renderTarget === undefined ) { 10 | 11 | var width = window.innerWidth || 1; 12 | var height = window.innerHeight || 1; 13 | var parameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false }; 14 | 15 | renderTarget = new THREE.WebGLRenderTarget( width, height, parameters ); 16 | 17 | } 18 | 19 | this.renderTarget1 = renderTarget; 20 | this.renderTarget2 = renderTarget.clone(); 21 | 22 | this.writeBuffer = this.renderTarget1; 23 | this.readBuffer = this.renderTarget2; 24 | 25 | this.passes = []; 26 | 27 | if ( THREE.CopyShader === undefined ) 28 | console.error( "THREE.EffectComposer relies on THREE.CopyShader" ); 29 | 30 | this.copyPass = new THREE.ShaderPass( THREE.CopyShader ); 31 | 32 | }; 33 | 34 | THREE.EffectComposer.prototype = { 35 | 36 | swapBuffers: function() { 37 | 38 | var tmp = this.readBuffer; 39 | this.readBuffer = this.writeBuffer; 40 | this.writeBuffer = tmp; 41 | 42 | }, 43 | 44 | addPass: function ( pass ) { 45 | 46 | this.passes.push( pass ); 47 | 48 | }, 49 | 50 | insertPass: function ( pass, index ) { 51 | 52 | this.passes.splice( index, 0, pass ); 53 | 54 | }, 55 | 56 | render: function ( delta ) { 57 | 58 | this.writeBuffer = this.renderTarget1; 59 | this.readBuffer = this.renderTarget2; 60 | 61 | var maskActive = false; 62 | 63 | var pass, i, il = this.passes.length; 64 | 65 | for ( i = 0; i < il; i ++ ) { 66 | 67 | pass = this.passes[ i ]; 68 | 69 | if ( !pass.enabled ) continue; 70 | 71 | pass.render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive ); 72 | 73 | if ( pass.needsSwap ) { 74 | 75 | if ( maskActive ) { 76 | 77 | var context = this.renderer.context; 78 | 79 | context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff ); 80 | 81 | this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, delta ); 82 | 83 | context.stencilFunc( context.EQUAL, 1, 0xffffffff ); 84 | 85 | } 86 | 87 | this.swapBuffers(); 88 | 89 | } 90 | 91 | if ( pass instanceof THREE.MaskPass ) { 92 | 93 | maskActive = true; 94 | 95 | } else if ( pass instanceof THREE.ClearMaskPass ) { 96 | 97 | maskActive = false; 98 | 99 | } 100 | 101 | } 102 | 103 | }, 104 | 105 | reset: function ( renderTarget ) { 106 | 107 | if ( renderTarget === undefined ) { 108 | 109 | renderTarget = this.renderTarget1.clone(); 110 | 111 | renderTarget.width = window.innerWidth; 112 | renderTarget.height = window.innerHeight; 113 | 114 | } 115 | 116 | this.renderTarget1 = renderTarget; 117 | this.renderTarget2 = renderTarget.clone(); 118 | 119 | this.writeBuffer = this.renderTarget1; 120 | this.readBuffer = this.renderTarget2; 121 | 122 | }, 123 | 124 | setSize: function ( width, height ) { 125 | 126 | var renderTarget = this.renderTarget1.clone(); 127 | 128 | renderTarget.width = width; 129 | renderTarget.height = height; 130 | 131 | this.reset( renderTarget ); 132 | 133 | } 134 | 135 | }; 136 | 137 | // shared ortho camera 138 | 139 | THREE.EffectComposer.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 ); 140 | 141 | THREE.EffectComposer.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null ); 142 | 143 | THREE.EffectComposer.scene = new THREE.Scene(); 144 | THREE.EffectComposer.scene.add( THREE.EffectComposer.quad ); 145 | -------------------------------------------------------------------------------- /js/threejs/examples/js/controls/PointerLockControls.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | */ 4 | 5 | THREE.PointerLockControls = function ( camera ) { 6 | 7 | var scope = this; 8 | 9 | var pitchObject = new THREE.Object3D(); 10 | pitchObject.add( camera ); 11 | 12 | var yawObject = new THREE.Object3D(); 13 | yawObject.position.y = 10; 14 | yawObject.add( pitchObject ); 15 | 16 | var moveForward = false; 17 | var moveBackward = false; 18 | var moveLeft = false; 19 | var moveRight = false; 20 | 21 | var isOnObject = false; 22 | var canJump = false; 23 | 24 | var velocity = new THREE.Vector3(); 25 | 26 | var PI_2 = Math.PI / 2; 27 | 28 | var onMouseMove = function ( event ) { 29 | 30 | if ( scope.enabled === false ) return; 31 | 32 | var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0; 33 | var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0; 34 | 35 | yawObject.rotation.y -= movementX * 0.002; 36 | pitchObject.rotation.x -= movementY * 0.002; 37 | 38 | pitchObject.rotation.x = Math.max( - PI_2, Math.min( PI_2, pitchObject.rotation.x ) ); 39 | 40 | }; 41 | 42 | var onKeyDown = function ( event ) { 43 | 44 | switch ( event.keyCode ) { 45 | 46 | case 38: // up 47 | case 87: // w 48 | moveForward = true; 49 | break; 50 | 51 | case 37: // left 52 | case 65: // a 53 | moveLeft = true; break; 54 | 55 | case 40: // down 56 | case 83: // s 57 | moveBackward = true; 58 | break; 59 | 60 | case 39: // right 61 | case 68: // d 62 | moveRight = true; 63 | break; 64 | 65 | case 32: // space 66 | if ( canJump === true ) velocity.y += 10; 67 | canJump = false; 68 | break; 69 | 70 | } 71 | 72 | }; 73 | 74 | var onKeyUp = function ( event ) { 75 | 76 | switch( event.keyCode ) { 77 | 78 | case 38: // up 79 | case 87: // w 80 | moveForward = false; 81 | break; 82 | 83 | case 37: // left 84 | case 65: // a 85 | moveLeft = false; 86 | break; 87 | 88 | case 40: // down 89 | case 83: // a 90 | moveBackward = false; 91 | break; 92 | 93 | case 39: // right 94 | case 68: // d 95 | moveRight = false; 96 | break; 97 | 98 | } 99 | 100 | }; 101 | 102 | document.addEventListener( 'mousemove', onMouseMove, false ); 103 | document.addEventListener( 'keydown', onKeyDown, false ); 104 | document.addEventListener( 'keyup', onKeyUp, false ); 105 | 106 | this.enabled = false; 107 | 108 | this.getObject = function () { 109 | 110 | return yawObject; 111 | 112 | }; 113 | 114 | this.isOnObject = function ( boolean ) { 115 | 116 | isOnObject = boolean; 117 | canJump = boolean; 118 | 119 | }; 120 | 121 | this.update = function ( delta ) { 122 | 123 | if ( scope.enabled === false ) return; 124 | 125 | delta *= 0.1; 126 | 127 | velocity.x += ( - velocity.x ) * 0.08 * delta; 128 | velocity.z += ( - velocity.z ) * 0.08 * delta; 129 | 130 | velocity.y -= 0.25 * delta; 131 | 132 | if ( moveForward ) velocity.z -= 0.12 * delta; 133 | if ( moveBackward ) velocity.z += 0.12 * delta; 134 | 135 | if ( moveLeft ) velocity.x -= 0.12 * delta; 136 | if ( moveRight ) velocity.x += 0.12 * delta; 137 | 138 | if ( isOnObject === true ) { 139 | 140 | velocity.y = Math.max( 0, velocity.y ); 141 | 142 | } 143 | 144 | yawObject.translateX( velocity.x ); 145 | yawObject.translateY( velocity.y ); 146 | yawObject.translateZ( velocity.z ); 147 | 148 | if ( yawObject.position.y < 10 ) { 149 | 150 | velocity.y = 0; 151 | yawObject.position.y = 10; 152 | 153 | canJump = true; 154 | 155 | } 156 | 157 | }; 158 | 159 | }; 160 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | camera path tool 8 | 9 | 102 | 103 | 104 | 105 | 106 |
107 | 108 | 109 | 110 |
111 |

Instructions

112 | 113 |

Click a Node to Move

114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 |
=Add Spline
-Remove Spline
HToggle Code View
UP/DOWNY Axis
LEFT/RIGHTX Axis
OPTION + UP/DOWNZ Axis
SHIFTSpeed Up
124 |
125 |
126 |
127 | 128 |
129 |
130 |
131 | 132 |
133 | 134 |
135 | 136 |
137 |
138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /js/threejs/examples/js/postprocessing/BloomPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.BloomPass = function ( strength, kernelSize, sigma, resolution ) { 6 | 7 | strength = ( strength !== undefined ) ? strength : 1; 8 | kernelSize = ( kernelSize !== undefined ) ? kernelSize : 25; 9 | sigma = ( sigma !== undefined ) ? sigma : 4.0; 10 | resolution = ( resolution !== undefined ) ? resolution : 256; 11 | 12 | // render targets 13 | 14 | var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat }; 15 | 16 | this.renderTargetX = new THREE.WebGLRenderTarget( resolution, resolution, pars ); 17 | this.renderTargetY = new THREE.WebGLRenderTarget( resolution, resolution, pars ); 18 | 19 | // copy material 20 | 21 | if ( THREE.CopyShader === undefined ) 22 | console.error( "THREE.BloomPass relies on THREE.CopyShader" ); 23 | 24 | var copyShader = THREE.CopyShader; 25 | 26 | this.copyUniforms = THREE.UniformsUtils.clone( copyShader.uniforms ); 27 | 28 | this.copyUniforms[ "opacity" ].value = strength; 29 | 30 | this.materialCopy = new THREE.ShaderMaterial( { 31 | 32 | uniforms: this.copyUniforms, 33 | vertexShader: copyShader.vertexShader, 34 | fragmentShader: copyShader.fragmentShader, 35 | blending: THREE.AdditiveBlending, 36 | transparent: true 37 | 38 | } ); 39 | 40 | // convolution material 41 | 42 | if ( THREE.ConvolutionShader === undefined ) 43 | console.error( "THREE.BloomPass relies on THREE.ConvolutionShader" ); 44 | 45 | var convolutionShader = THREE.ConvolutionShader; 46 | 47 | this.convolutionUniforms = THREE.UniformsUtils.clone( convolutionShader.uniforms ); 48 | 49 | this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurx; 50 | this.convolutionUniforms[ "cKernel" ].value = THREE.ConvolutionShader.buildKernel( sigma ); 51 | 52 | this.materialConvolution = new THREE.ShaderMaterial( { 53 | 54 | uniforms: this.convolutionUniforms, 55 | vertexShader: convolutionShader.vertexShader, 56 | fragmentShader: convolutionShader.fragmentShader, 57 | defines: { 58 | "KERNEL_SIZE_FLOAT": kernelSize.toFixed( 1 ), 59 | "KERNEL_SIZE_INT": kernelSize.toFixed( 0 ) 60 | } 61 | 62 | } ); 63 | 64 | this.enabled = true; 65 | this.needsSwap = false; 66 | this.clear = false; 67 | 68 | }; 69 | 70 | THREE.BloomPass.prototype = { 71 | 72 | render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) { 73 | 74 | if ( maskActive ) renderer.context.disable( renderer.context.STENCIL_TEST ); 75 | 76 | // Render quad with blured scene into texture (convolution pass 1) 77 | 78 | THREE.EffectComposer.quad.material = this.materialConvolution; 79 | 80 | this.convolutionUniforms[ "tDiffuse" ].value = readBuffer; 81 | this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurX; 82 | 83 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, this.renderTargetX, true ); 84 | 85 | 86 | // Render quad with blured scene into texture (convolution pass 2) 87 | 88 | this.convolutionUniforms[ "tDiffuse" ].value = this.renderTargetX; 89 | this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurY; 90 | 91 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, this.renderTargetY, true ); 92 | 93 | // Render original scene with superimposed blur to texture 94 | 95 | THREE.EffectComposer.quad.material = this.materialCopy; 96 | 97 | this.copyUniforms[ "tDiffuse" ].value = this.renderTargetY; 98 | 99 | if ( maskActive ) renderer.context.enable( renderer.context.STENCIL_TEST ); 100 | 101 | renderer.render( THREE.EffectComposer.scene, THREE.EffectComposer.camera, readBuffer, this.clear ); 102 | 103 | } 104 | 105 | }; 106 | 107 | THREE.BloomPass.blurX = new THREE.Vector2( 0.001953125, 0.0 ); 108 | THREE.BloomPass.blurY = new THREE.Vector2( 0.0, 0.001953125 ); 109 | -------------------------------------------------------------------------------- /js/threejs/examples/js/libs/tween.min.js: -------------------------------------------------------------------------------- 1 | // tween.js - http://github.com/sole/tween.js 2 | 'use strict';var TWEEN=TWEEN||function(){var a=[];return{REVISION:"7",getAll:function(){return a},removeAll:function(){a=[]},add:function(c){a.push(c)},remove:function(c){c=a.indexOf(c);-1!==c&&a.splice(c,1)},update:function(c){if(0===a.length)return!1;for(var b=0,d=a.length,c=void 0!==c?c:Date.now();b(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)}},Cubic:{In:function(a){return a*a*a},Out:function(a){return--a*a*a+1},InOut:function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)}},Quartic:{In:function(a){return a*a*a*a},Out:function(a){return 1- --a*a*a*a},InOut:function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)}},Quintic:{In:function(a){return a*a*a* 7 | a*a},Out:function(a){return--a*a*a*a*a+1},InOut:function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)}},Sinusoidal:{In:function(a){return 1-Math.cos(a*Math.PI/2)},Out:function(a){return Math.sin(a*Math.PI/2)},InOut:function(a){return 0.5*(1-Math.cos(Math.PI*a))}},Exponential:{In:function(a){return 0===a?0:Math.pow(1024,a-1)},Out:function(a){return 1===a?1:1-Math.pow(2,-10*a)},InOut:function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)}},Circular:{In:function(a){return 1- 8 | Math.sqrt(1-a*a)},Out:function(a){return Math.sqrt(1- --a*a)},InOut:function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)}},Elastic:{In:function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))},Out:function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)* 9 | 2*Math.PI/0.4)+1},InOut:function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1}},Back:{In:function(a){return a*a*(2.70158*a-1.70158)},Out:function(a){return--a*a*(2.70158*a+1.70158)+1},InOut:function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)}},Bounce:{In:function(a){return 1- 10 | TWEEN.Easing.Bounce.Out(1-a)},Out:function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375},InOut:function(a){return 0.5>a?0.5*TWEEN.Easing.Bounce.In(2*a):0.5*TWEEN.Easing.Bounce.Out(2*a-1)+0.5}}}; 11 | TWEEN.Interpolation={Linear:function(a,c){var b=a.length-1,d=b*c,e=Math.floor(d),f=TWEEN.Interpolation.Utils.Linear;return 0>c?f(a[0],a[1],d):1b?b:e+1],d-e)},Bezier:function(a,c){var b=0,d=a.length-1,e=Math.pow,f=TWEEN.Interpolation.Utils.Bernstein,h;for(h=0;h<=d;h++)b+=e(1-c,d-h)*e(c,h)*a[h]*f(d,h);return b},CatmullRom:function(a,c){var b=a.length-1,d=b*c,e=Math.floor(d),f=TWEEN.Interpolation.Utils.CatmullRom;return a[0]===a[b]?(0>c&&(e=Math.floor(d=b*(1+c))),f(a[(e- 12 | 1+b)%b],a[e],a[(e+1)%b],a[(e+2)%b],d-e)):0>c?a[0]-(f(a[0],a[0],a[1],a[1],-d)-a[0]):1 0; 44 | var hasFaceVertexNormal = face.vertexNormals[ 0 ] !== undefined; 45 | var hasFaceColor = false; // face.color; 46 | var hasFaceVertexColor = false; // face.vertexColors[ 0 ] !== undefined; 47 | 48 | var faceType = 0; 49 | 50 | faceType = setBit( faceType, 0, ! isTriangle ); 51 | faceType = setBit( faceType, 1, hasMaterial ); 52 | faceType = setBit( faceType, 2, hasFaceUv ); 53 | faceType = setBit( faceType, 3, hasFaceVertexUv ); 54 | faceType = setBit( faceType, 4, hasFaceNormal ); 55 | faceType = setBit( faceType, 5, hasFaceVertexNormal ); 56 | faceType = setBit( faceType, 6, hasFaceColor ); 57 | faceType = setBit( faceType, 7, hasFaceVertexColor ); 58 | 59 | faces.push( faceType ); 60 | 61 | if ( isTriangle ) { 62 | 63 | faces.push( face.a, face.b, face.c ); 64 | 65 | } else { 66 | 67 | faces.push( face.a, face.b, face.c, face.d ); 68 | 69 | } 70 | 71 | if ( hasMaterial ) { 72 | 73 | faces.push( face.materialIndex ); 74 | 75 | } 76 | 77 | /* 78 | if ( hasFaceUv ) { 79 | 80 | var uv = geometry.faceUvs[ 0 ][ i ]; 81 | uvs[ 0 ].push( uv.u, uv.v ); 82 | 83 | } 84 | */ 85 | 86 | /* 87 | if ( hasFaceVertexUv ) { 88 | 89 | var uvs = geometry.faceVertexUvs[ 0 ][ i ]; 90 | 91 | if ( isTriangle ) { 92 | 93 | faces.push( 94 | uvs[ 0 ].u, uvs[ 0 ].v, 95 | uvs[ 1 ].u, uvs[ 1 ].v, 96 | uvs[ 2 ].u, uvs[ 2 ].v 97 | ); 98 | 99 | } else { 100 | 101 | faces.push( 102 | uvs[ 0 ].u, uvs[ 0 ].v, 103 | uvs[ 1 ].u, uvs[ 1 ].v, 104 | uvs[ 2 ].u, uvs[ 2 ].v, 105 | uvs[ 3 ].u, uvs[ 3 ].v 106 | ); 107 | 108 | } 109 | 110 | } 111 | */ 112 | 113 | if ( hasFaceNormal ) { 114 | 115 | var faceNormal = face.normal; 116 | faces.push( getNormalIndex( faceNormal.x, faceNormal.y, faceNormal.z ) ); 117 | 118 | } 119 | 120 | if ( hasFaceVertexNormal ) { 121 | 122 | var vertexNormals = face.vertexNormals; 123 | 124 | if ( isTriangle ) { 125 | 126 | faces.push( 127 | getNormalIndex( vertexNormals[ 0 ].x, vertexNormals[ 0 ].y, vertexNormals[ 0 ].z ), 128 | getNormalIndex( vertexNormals[ 1 ].x, vertexNormals[ 1 ].y, vertexNormals[ 1 ].z ), 129 | getNormalIndex( vertexNormals[ 2 ].x, vertexNormals[ 2 ].y, vertexNormals[ 2 ].z ) 130 | ); 131 | 132 | } else { 133 | 134 | faces.push( 135 | getNormalIndex( vertexNormals[ 0 ].x, vertexNormals[ 0 ].y, vertexNormals[ 0 ].z ), 136 | getNormalIndex( vertexNormals[ 1 ].x, vertexNormals[ 1 ].y, vertexNormals[ 1 ].z ), 137 | getNormalIndex( vertexNormals[ 2 ].x, vertexNormals[ 2 ].y, vertexNormals[ 2 ].z ), 138 | getNormalIndex( vertexNormals[ 3 ].x, vertexNormals[ 3 ].y, vertexNormals[ 3 ].z ) 139 | ); 140 | 141 | } 142 | 143 | } 144 | 145 | } 146 | 147 | function setBit( value, position, enabled ) { 148 | 149 | return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position) ); 150 | 151 | } 152 | 153 | function getNormalIndex( x, y, z ) { 154 | 155 | var hash = x.toString() + y.toString() + z.toString(); 156 | 157 | if ( normalsHash[ hash ] !== undefined ) { 158 | 159 | return normalsHash[ hash ]; 160 | 161 | } 162 | 163 | normalsHash[ hash ] = normals.length / 3; 164 | normals.push( x, y, z ); 165 | 166 | return normalsHash[ hash ]; 167 | 168 | } 169 | 170 | output.vertices = vertices; 171 | output.normals = normals; 172 | output.uvs = uvs; 173 | output.faces = faces; 174 | 175 | // 176 | 177 | return output; 178 | 179 | } 180 | 181 | }; 182 | -------------------------------------------------------------------------------- /js/threejs/examples/js/effects/ParallaxBarrierEffect.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | * @author marklundin / http://mark-lundin.com/ 4 | * @author alteredq / http://alteredqualia.com/ 5 | */ 6 | 7 | THREE.ParallaxBarrierEffect = function ( renderer ) { 8 | 9 | var eyeRight = new THREE.Matrix4(); 10 | var eyeLeft = new THREE.Matrix4(); 11 | var focalLength = 125; 12 | var _aspect, _near, _far, _fov; 13 | 14 | var _cameraL = new THREE.PerspectiveCamera(); 15 | _cameraL.matrixAutoUpdate = false; 16 | 17 | var _cameraR = new THREE.PerspectiveCamera(); 18 | _cameraR.matrixAutoUpdate = false; 19 | 20 | var _scene = new THREE.Scene(); 21 | 22 | var _camera = new THREE.PerspectiveCamera( 53, 1, 1, 10000 ); 23 | _camera.position.z = 2; 24 | _scene.add( _camera ); 25 | 26 | var _params = { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat }; 27 | 28 | var _renderTargetL = new THREE.WebGLRenderTarget( 512, 512, _params ); 29 | var _renderTargetR = new THREE.WebGLRenderTarget( 512, 512, _params ); 30 | 31 | var _material = new THREE.ShaderMaterial( { 32 | 33 | uniforms: { 34 | 35 | "mapLeft": { type: "t", value: _renderTargetL }, 36 | "mapRight": { type: "t", value: _renderTargetR } 37 | 38 | }, 39 | 40 | vertexShader: [ 41 | 42 | "varying vec2 vUv;", 43 | 44 | "void main() {", 45 | 46 | " vUv = vec2( uv.x, uv.y );", 47 | " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 48 | 49 | "}" 50 | 51 | ].join("\n"), 52 | 53 | fragmentShader: [ 54 | 55 | "uniform sampler2D mapLeft;", 56 | "uniform sampler2D mapRight;", 57 | "varying vec2 vUv;", 58 | 59 | "void main() {", 60 | 61 | " vec2 uv = vUv;", 62 | 63 | " if ( ( mod( gl_FragCoord.x, 2.0 ) ) > 1.00 ) {", 64 | 65 | " gl_FragColor = texture2D( mapLeft, uv );", 66 | 67 | " } else {", 68 | 69 | " gl_FragColor = texture2D( mapRight, uv );", 70 | 71 | " }", 72 | 73 | "}" 74 | 75 | ].join("\n") 76 | 77 | } ); 78 | 79 | var mesh = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), _material ); 80 | _scene.add( mesh ); 81 | 82 | this.setSize = function ( width, height ) { 83 | 84 | _renderTargetL = new THREE.WebGLRenderTarget( width, height, _params ); 85 | _renderTargetR = new THREE.WebGLRenderTarget( width, height, _params ); 86 | 87 | _material.uniforms[ "mapLeft" ].value = _renderTargetL; 88 | _material.uniforms[ "mapRight" ].value = _renderTargetR; 89 | 90 | renderer.setSize( width, height ); 91 | 92 | }; 93 | 94 | /* 95 | * Renderer now uses an asymmetric perspective projection 96 | * (http://paulbourke.net/miscellaneous/stereographics/stereorender/). 97 | * 98 | * Each camera is offset by the eye seperation and its projection matrix is 99 | * also skewed asymetrically back to converge on the same projection plane. 100 | * Added a focal length parameter to, this is where the parallax is equal to 0. 101 | */ 102 | 103 | this.render = function ( scene, camera ) { 104 | 105 | scene.updateMatrixWorld(); 106 | 107 | if ( camera.parent === undefined ) camera.updateMatrixWorld(); 108 | 109 | var hasCameraChanged = ( _aspect !== camera.aspect ) || ( _near !== camera.near ) || ( _far !== camera.far ) || ( _fov !== camera.fov ); 110 | 111 | if ( hasCameraChanged ) { 112 | 113 | _aspect = camera.aspect; 114 | _near = camera.near; 115 | _far = camera.far; 116 | _fov = camera.fov; 117 | 118 | var projectionMatrix = camera.projectionMatrix.clone(); 119 | var eyeSep = focalLength / 30 * 0.5; 120 | var eyeSepOnProjection = eyeSep * _near / focalLength; 121 | var ymax = _near * Math.tan( THREE.Math.degToRad( _fov * 0.5 ) ); 122 | var xmin, xmax; 123 | 124 | // translate xOffset 125 | 126 | eyeRight.elements[12] = eyeSep; 127 | eyeLeft.elements[12] = -eyeSep; 128 | 129 | // for left eye 130 | 131 | xmin = -ymax * _aspect + eyeSepOnProjection; 132 | xmax = ymax * _aspect + eyeSepOnProjection; 133 | 134 | projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin ); 135 | projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin ); 136 | 137 | _cameraL.projectionMatrix.copy( projectionMatrix ); 138 | 139 | // for right eye 140 | 141 | xmin = -ymax * _aspect - eyeSepOnProjection; 142 | xmax = ymax * _aspect - eyeSepOnProjection; 143 | 144 | projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin ); 145 | projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin ); 146 | 147 | _cameraR.projectionMatrix.copy( projectionMatrix ); 148 | 149 | } 150 | 151 | _cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft ); 152 | _cameraL.position.copy( camera.position ); 153 | _cameraL.near = camera.near; 154 | _cameraL.far = camera.far; 155 | 156 | renderer.render( scene, _cameraL, _renderTargetL, true ); 157 | 158 | _cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight ); 159 | _cameraR.position.copy( camera.position ); 160 | _cameraR.near = camera.near; 161 | _cameraR.far = camera.far; 162 | 163 | renderer.render( scene, _cameraR, _renderTargetR, true ); 164 | 165 | _scene.updateMatrixWorld(); 166 | 167 | renderer.render( _scene, _camera ); 168 | 169 | }; 170 | 171 | }; 172 | -------------------------------------------------------------------------------- /js/threejs/examples/js/effects/AnaglyphEffect.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | * @author marklundin / http://mark-lundin.com/ 4 | * @author alteredq / http://alteredqualia.com/ 5 | */ 6 | 7 | THREE.AnaglyphEffect = function ( renderer, width, height ) { 8 | 9 | var eyeRight = new THREE.Matrix4(); 10 | var eyeLeft = new THREE.Matrix4(); 11 | var focalLength = 125; 12 | var _aspect, _near, _far, _fov; 13 | 14 | var _cameraL = new THREE.PerspectiveCamera(); 15 | _cameraL.matrixAutoUpdate = false; 16 | 17 | var _cameraR = new THREE.PerspectiveCamera(); 18 | _cameraR.matrixAutoUpdate = false; 19 | 20 | var _camera = new THREE.OrthographicCamera( -1, 1, 1, - 1, 0, 1 ); 21 | 22 | var _scene = new THREE.Scene(); 23 | 24 | var _params = { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat }; 25 | 26 | if ( width === undefined ) width = 512; 27 | if ( height === undefined ) height = 512; 28 | 29 | var _renderTargetL = new THREE.WebGLRenderTarget( width, height, _params ); 30 | var _renderTargetR = new THREE.WebGLRenderTarget( width, height, _params ); 31 | 32 | var _material = new THREE.ShaderMaterial( { 33 | 34 | uniforms: { 35 | 36 | "mapLeft": { type: "t", value: _renderTargetL }, 37 | "mapRight": { type: "t", value: _renderTargetR } 38 | 39 | }, 40 | 41 | vertexShader: [ 42 | 43 | "varying vec2 vUv;", 44 | 45 | "void main() {", 46 | 47 | " vUv = vec2( uv.x, uv.y );", 48 | " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 49 | 50 | "}" 51 | 52 | ].join("\n"), 53 | 54 | fragmentShader: [ 55 | 56 | "uniform sampler2D mapLeft;", 57 | "uniform sampler2D mapRight;", 58 | "varying vec2 vUv;", 59 | 60 | "void main() {", 61 | 62 | " vec4 colorL, colorR;", 63 | " vec2 uv = vUv;", 64 | 65 | " colorL = texture2D( mapLeft, uv );", 66 | " colorR = texture2D( mapRight, uv );", 67 | 68 | // http://3dtv.at/Knowhow/AnaglyphComparison_en.aspx 69 | 70 | " gl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;", 71 | 72 | "}" 73 | 74 | ].join("\n") 75 | 76 | } ); 77 | 78 | var mesh = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), _material ); 79 | _scene.add( mesh ); 80 | 81 | this.setSize = function ( width, height ) { 82 | 83 | _renderTargetL = new THREE.WebGLRenderTarget( width, height, _params ); 84 | _renderTargetR = new THREE.WebGLRenderTarget( width, height, _params ); 85 | 86 | _material.uniforms[ "mapLeft" ].value = _renderTargetL; 87 | _material.uniforms[ "mapRight" ].value = _renderTargetR; 88 | 89 | renderer.setSize( width, height ); 90 | 91 | }; 92 | 93 | /* 94 | * Renderer now uses an asymmetric perspective projection 95 | * (http://paulbourke.net/miscellaneous/stereographics/stereorender/). 96 | * 97 | * Each camera is offset by the eye seperation and its projection matrix is 98 | * also skewed asymetrically back to converge on the same projection plane. 99 | * Added a focal length parameter to, this is where the parallax is equal to 0. 100 | */ 101 | 102 | this.render = function ( scene, camera ) { 103 | 104 | scene.updateMatrixWorld(); 105 | 106 | if ( camera.parent === undefined ) camera.updateMatrixWorld(); 107 | 108 | var hasCameraChanged = ( _aspect !== camera.aspect ) || ( _near !== camera.near ) || ( _far !== camera.far ) || ( _fov !== camera.fov ); 109 | 110 | if ( hasCameraChanged ) { 111 | 112 | _aspect = camera.aspect; 113 | _near = camera.near; 114 | _far = camera.far; 115 | _fov = camera.fov; 116 | 117 | var projectionMatrix = camera.projectionMatrix.clone(); 118 | var eyeSep = focalLength / 30 * 0.5; 119 | var eyeSepOnProjection = eyeSep * _near / focalLength; 120 | var ymax = _near * Math.tan( THREE.Math.degToRad( _fov * 0.5 ) ); 121 | var xmin, xmax; 122 | 123 | // translate xOffset 124 | 125 | eyeRight.elements[12] = eyeSep; 126 | eyeLeft.elements[12] = -eyeSep; 127 | 128 | // for left eye 129 | 130 | xmin = -ymax * _aspect + eyeSepOnProjection; 131 | xmax = ymax * _aspect + eyeSepOnProjection; 132 | 133 | projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin ); 134 | projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin ); 135 | 136 | _cameraL.projectionMatrix.copy( projectionMatrix ); 137 | 138 | // for right eye 139 | 140 | xmin = -ymax * _aspect - eyeSepOnProjection; 141 | xmax = ymax * _aspect - eyeSepOnProjection; 142 | 143 | projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin ); 144 | projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin ); 145 | 146 | _cameraR.projectionMatrix.copy( projectionMatrix ); 147 | 148 | } 149 | 150 | _cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft ); 151 | _cameraL.position.copy( camera.position ); 152 | _cameraL.near = camera.near; 153 | _cameraL.far = camera.far; 154 | 155 | renderer.render( scene, _cameraL, _renderTargetL, true ); 156 | 157 | _cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight ); 158 | _cameraR.position.copy( camera.position ); 159 | _cameraR.near = camera.near; 160 | _cameraR.far = camera.far; 161 | 162 | renderer.render( scene, _cameraR, _renderTargetR, true ); 163 | 164 | renderer.render( _scene, _camera ); 165 | 166 | }; 167 | 168 | }; 169 | -------------------------------------------------------------------------------- /js/threejs/examples/js/loaders/PLYLoader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Wei Meng / http://about.me/menway 3 | * 4 | * Description: A THREE loader for PLY ASCII files (known as the Polygon File Format or the Stanford Triangle Format). 5 | * 6 | * Currently only supports ASCII encoded files. 7 | * 8 | * Limitations: ASCII decoding assumes file is UTF-8. 9 | * 10 | * Usage: 11 | * var loader = new THREE.PLYLoader(); 12 | * loader.addEventListener( 'load', function ( event ) { 13 | * 14 | * var geometry = event.content; 15 | * scene.add( new THREE.Mesh( geometry ) ); 16 | * 17 | * } ); 18 | * loader.load( './models/ply/ascii/dolphins.ply' ); 19 | */ 20 | 21 | 22 | THREE.PLYLoader = function () {}; 23 | 24 | THREE.PLYLoader.prototype = { 25 | 26 | constructor: THREE.PLYLoader, 27 | 28 | addEventListener: THREE.EventDispatcher.prototype.addEventListener, 29 | hasEventListener: THREE.EventDispatcher.prototype.hasEventListener, 30 | removeEventListener: THREE.EventDispatcher.prototype.removeEventListener, 31 | dispatchEvent: THREE.EventDispatcher.prototype.dispatchEvent, 32 | 33 | load: function ( url, callback ) { 34 | 35 | var scope = this; 36 | var request = new XMLHttpRequest(); 37 | 38 | request.addEventListener( 'load', function ( event ) { 39 | 40 | var geometry = scope.parse( event.target.response ); 41 | 42 | scope.dispatchEvent( { type: 'load', content: geometry } ); 43 | 44 | if ( callback ) callback( geometry ); 45 | 46 | }, false ); 47 | 48 | request.addEventListener( 'progress', function ( event ) { 49 | 50 | scope.dispatchEvent( { type: 'progress', loaded: event.loaded, total: event.total } ); 51 | 52 | }, false ); 53 | 54 | request.addEventListener( 'error', function () { 55 | 56 | scope.dispatchEvent( { type: 'error', message: 'Couldn\'t load URL [' + url + ']' } ); 57 | 58 | }, false ); 59 | 60 | request.open( 'GET', url, true ); 61 | request.responseType = "arraybuffer"; 62 | request.send( null ); 63 | 64 | }, 65 | 66 | bin2str: function (buf) { 67 | 68 | var array_buffer = new Uint8Array(buf); 69 | var str = ''; 70 | for(var i = 0; i < buf.byteLength; i++) { 71 | str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian 72 | } 73 | 74 | return str; 75 | 76 | }, 77 | 78 | isASCII: function(buf){ 79 | 80 | // currently only supports ASCII encoded files. 81 | return true; 82 | 83 | }, 84 | 85 | parse: function ( data ) { 86 | 87 | if ( data instanceof ArrayBuffer ) { 88 | 89 | return this.isASCII( data ) 90 | ? this.parseASCII( this.bin2str( data ) ) 91 | : this.parseBinary( data ); 92 | 93 | } else { 94 | 95 | return this.parseASCII( data ); 96 | 97 | } 98 | 99 | }, 100 | 101 | parseASCII: function ( data ) { 102 | 103 | // PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format) 104 | 105 | var geometry = new THREE.Geometry(); 106 | 107 | var result; 108 | 109 | var patternHeader = /ply([\s\S]*)end_header/; 110 | var header = ""; 111 | if ( ( result = patternHeader.exec( data ) ) != null ) { 112 | header = result [ 1 ]; 113 | } 114 | 115 | var patternBody = /end_header([\s\S]*)$/; 116 | var body = ""; 117 | if ( ( result = patternBody.exec( data ) ) != null ) { 118 | body = result [ 1 ]; 119 | } 120 | 121 | var patternVertexCount = /element[\s]+vertex[\s]+(\d+)/g; 122 | var vertexCount = 0; 123 | if ( ( result = patternVertexCount.exec( header ) ) != null ) { 124 | vertexCount = parseInt( result[ 1 ] ); 125 | } 126 | 127 | var patternFaceCount = /element[\s]+face[\s]+(\d+)/g; 128 | var faceCount = 0; 129 | if ( ( result = patternFaceCount.exec( header ) ) != null ) { 130 | faceCount = parseInt( result[ 1 ] ); 131 | } 132 | 133 | if ( vertexCount != 0 && faceCount != 0 ) { 134 | // Vertex 135 | // assume x y z 136 | var patternVertex = /([-+]?[0-9]+\.?[0-9]*([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+[\s]+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+/g; 137 | for ( var i = 0; i < vertexCount; i++) { 138 | if ( ( result = patternVertex.exec( body ) ) != null ) { 139 | geometry.vertices.push( new THREE.Vector3( parseFloat( result[ 1 ] ), parseFloat( result[ 3 ] ), parseFloat( result[ 5 ] ) ) ); 140 | } else { 141 | console.error('Vertex error: vertex count mismatch.'); 142 | return geometry; 143 | } 144 | } 145 | 146 | // Face 147 | // assume 3 index0 index1 index2 148 | var patternFace = /3[\s]+([-+]?[0-9]+)[\s]+([-+]?[0-9]+)[\s]+([-+]?[0-9]+)/g; 149 | for (var i = 0; i < faceCount; i++) { 150 | if ( ( result = patternFace.exec( body ) ) != null ) { 151 | geometry.faces.push( new THREE.Face3( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ) ) ); 152 | } else { 153 | console.error('Face error: vertex count mismatch.'); 154 | return geometry; 155 | } 156 | } 157 | 158 | } else { 159 | console.error( 'Header error: vertexCount(' + vertexCount + '), faceCount(' + faceCount + ').' ); 160 | } 161 | 162 | geometry.computeCentroids(); 163 | geometry.computeBoundingSphere(); 164 | 165 | return geometry; 166 | 167 | }, 168 | 169 | parseBinary: function (buf) { 170 | 171 | // not supported yet 172 | console.error('Not supported yet.'); 173 | 174 | } 175 | 176 | 177 | }; 178 | -------------------------------------------------------------------------------- /js/threejs/examples/js/AudioObject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * AudioObject 5 | * 6 | * - 3d spatialized sound with Doppler-shift effect 7 | * 8 | * - uses Audio API (currently supported in WebKit-based browsers) 9 | * https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html 10 | * 11 | * - based on Doppler effect demo from Chromium 12 | * http://chromium.googlecode.com/svn/trunk/samples/audio/doppler.html 13 | * 14 | * - parameters 15 | * 16 | * - listener 17 | * dopplerFactor // A constant used to determine the amount of pitch shift to use when rendering a doppler effect. 18 | * speedOfSound // The speed of sound used for calculating doppler shift. The default value is 343.3 meters / second. 19 | * 20 | * - panner 21 | * refDistance // A reference distance for reducing volume as source move further from the listener. 22 | * maxDistance // The maximum distance between source and listener, after which the volume will not be reduced any further. 23 | * rolloffFactor // Describes how quickly the volume is reduced as source moves away from listener. 24 | * coneInnerAngle // An angle inside of which there will be no volume reduction. 25 | * coneOuterAngle // An angle outside of which the volume will be reduced to a constant value of coneOuterGain. 26 | * coneOuterGain // Amount of volume reduction outside of the coneOuterAngle. 27 | */ 28 | 29 | THREE.AudioObject = function ( url, volume, playbackRate, loop ) { 30 | 31 | THREE.Object3D.call( this ); 32 | 33 | if ( playbackRate === undefined ) playbackRate = 1; 34 | if ( volume === undefined ) volume = 1; 35 | if ( loop === undefined ) loop = true; 36 | 37 | if ( ! this.context ) { 38 | 39 | try { 40 | 41 | THREE.AudioObject.prototype.context = new webkitAudioContext(); 42 | 43 | } catch( error ) { 44 | 45 | console.warn( "THREE.AudioObject: webkitAudioContext not found" ); 46 | return this; 47 | 48 | } 49 | 50 | } 51 | 52 | this.directionalSource = false; 53 | 54 | this.listener = this.context.listener; 55 | this.panner = this.context.createPanner(); 56 | this.source = this.context.createBufferSource(); 57 | 58 | this.masterGainNode = this.context.createGainNode(); 59 | this.dryGainNode = this.context.createGainNode(); 60 | 61 | // Setup initial gains 62 | 63 | this.masterGainNode.gain.value = volume; 64 | this.dryGainNode.gain.value = 3.0; 65 | 66 | // Connect dry mix 67 | 68 | this.source.connect( this.panner ); 69 | this.panner.connect( this.dryGainNode ); 70 | this.dryGainNode.connect( this.masterGainNode ); 71 | 72 | // Connect master gain 73 | 74 | this.masterGainNode.connect( this.context.destination ); 75 | 76 | // Set source parameters and load sound 77 | 78 | this.source.playbackRate.value = playbackRate; 79 | this.source.loop = loop; 80 | 81 | loadBufferAndPlay( url ); 82 | 83 | // private properties 84 | 85 | var soundPosition = new THREE.Vector3(), 86 | cameraPosition = new THREE.Vector3(), 87 | oldSoundPosition = new THREE.Vector3(), 88 | oldCameraPosition = new THREE.Vector3(), 89 | 90 | soundDelta = new THREE.Vector3(), 91 | cameraDelta = new THREE.Vector3(), 92 | 93 | soundFront = new THREE.Vector3(), 94 | cameraFront = new THREE.Vector3(), 95 | soundUp = new THREE.Vector3(), 96 | cameraUp = new THREE.Vector3(); 97 | 98 | var _this = this; 99 | 100 | // API 101 | 102 | this.setVolume = function ( volume ) { 103 | 104 | this.masterGainNode.gain.value = volume; 105 | 106 | }; 107 | 108 | this.update = function ( camera ) { 109 | 110 | oldSoundPosition.copy( soundPosition ); 111 | oldCameraPosition.copy( cameraPosition ); 112 | 113 | soundPosition.getPositionFromMatrix( this.matrixWorld ); 114 | cameraPosition.getPositionFromMatrix( camera.matrixWorld ); 115 | 116 | soundDelta.subVectors( soundPosition, oldSoundPosition ); 117 | cameraDelta.subVectors( cameraPosition, oldCameraPosition ); 118 | 119 | cameraUp.copy( camera.up ); 120 | 121 | cameraFront.set( 0, 0, -1 ); 122 | cameraFront.transformDirection( camera.matrixWorld ); 123 | 124 | this.listener.setPosition( cameraPosition.x, cameraPosition.y, cameraPosition.z ); 125 | this.listener.setVelocity( cameraDelta.x, cameraDelta.y, cameraDelta.z ); 126 | this.listener.setOrientation( cameraFront.x, cameraFront.y, cameraFront.z, cameraUp.x, cameraUp.y, cameraUp.z ); 127 | 128 | this.panner.setPosition( soundPosition.x, soundPosition.y, soundPosition.z ); 129 | this.panner.setVelocity( soundDelta.x, soundDelta.y, soundDelta.z ); 130 | 131 | if ( this.directionalSource ) { 132 | 133 | soundFront.set( 0, 0, -1 ); 134 | soundFront.transformDirection( this.matrixWorld ); 135 | 136 | soundUp.copy( this.up ); 137 | this.panner.setOrientation( soundFront.x, soundFront.y, soundFront.z, soundUp.x, soundUp.y, soundUp.z ); 138 | 139 | } 140 | 141 | 142 | }; 143 | 144 | function loadBufferAndPlay( url ) { 145 | 146 | // Load asynchronously 147 | 148 | var request = new XMLHttpRequest(); 149 | request.open( "GET", url, true ); 150 | request.responseType = "arraybuffer"; 151 | 152 | request.onload = function() { 153 | 154 | _this.source.buffer = _this.context.createBuffer( request.response, true ); 155 | _this.source.noteOn( 0 ); 156 | 157 | } 158 | 159 | request.send(); 160 | 161 | } 162 | 163 | }; 164 | 165 | THREE.AudioObject.prototype = Object.create( THREE.Object3D.prototype ); 166 | 167 | THREE.AudioObject.prototype.context = null; 168 | THREE.AudioObject.prototype.type = null; 169 | 170 | -------------------------------------------------------------------------------- /js/threejs/examples/js/UVsUtils.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @author gyuque / http://github.com/gyuque 3 | * 4 | * Cylinder Mapping for ExtrudeGeometry 5 | * 6 | */ 7 | 8 | THREE.UVsUtils = { 9 | 10 | }; 11 | 12 | THREE.UVsUtils.CylinderUVGenerator = function() { 13 | this.uRepeat = 1; 14 | this.targetGeometry = null; 15 | this.lengthCache = null; 16 | }; 17 | 18 | THREE.UVsUtils.CylinderUVGenerator.prototype = { 19 | generateTopUV: THREE.ExtrudeGeometry.WorldUVGenerator.generateTopUV, 20 | generateBottomUV: THREE.ExtrudeGeometry.WorldUVGenerator.generateBottomUV, 21 | 22 | generateSideWallUV: function( geometry, extrudedShape, wallContour, extrudeOptions, 23 | indexA, indexB, indexC, indexD, stepIndex, stepsLength, 24 | contourIndex1, contourIndex2 ) { 25 | // first call 26 | if (this.targetGeometry !== geometry) { 27 | this.prepare(geometry, wallContour); 28 | } 29 | 30 | // generate uv 31 | var u_list = this.lengthCache; 32 | var v1 = stepIndex / stepsLength; 33 | var v2 = ( stepIndex + 1 ) / stepsLength; 34 | 35 | var u1 = u_list[contourIndex1]; 36 | var u2 = u_list[contourIndex2]; 37 | if (u1 < u2) {u1 += 1.0;} 38 | 39 | u1 *= this.uRepeat; 40 | u2 *= this.uRepeat; 41 | return [ 42 | new THREE.Vector2( u1, v1 ), 43 | new THREE.Vector2( u2, v1 ), 44 | new THREE.Vector2( u2, v2 ), 45 | new THREE.Vector2( u1, v2 ) 46 | ]; 47 | }, 48 | 49 | prepare: function(geometry, wallContour) { 50 | var p1, p2; 51 | var u_list = []; 52 | var lengthSum = 0; 53 | var len = wallContour.length; 54 | for (var i = 0;i < len;i++) { 55 | p1 = wallContour[ i ]; 56 | p2 = wallContour[ (i+1) % len ]; 57 | 58 | var dx = p1.x - p2.x; 59 | var dy = p1.y - p2.y; 60 | var segmentLength = Math.sqrt(dx*dx + dy*dy); 61 | 62 | u_list.push(lengthSum); 63 | lengthSum += segmentLength; 64 | } 65 | 66 | this.normalizeArray(u_list, lengthSum); 67 | this.targetGeometry = geometry; 68 | this.lengthCache = u_list; 69 | }, 70 | 71 | normalizeArray: function(ls, v) { 72 | var len = ls.length; 73 | for (var i = 0;i < len;i++) { 74 | ls[i] /= v; 75 | } 76 | 77 | return ls; 78 | } 79 | }; 80 | 81 | 82 | 83 | /* 84 | * @author zz85 / http://github.com/zz85 85 | * @author WestLangley / http://github.com/WestLangley 86 | * 87 | * tool for "unwrapping" and debugging three.js 88 | * geometries UV mapping 89 | * 90 | * Sample usage: 91 | * document.body.appendChild( 92 | * THREE.UVsDebug( 93 | * new THREE.SphereGeometry(10,10,10,10)); 94 | * 95 | */ 96 | 97 | THREE.UVsDebug = function( geometry, size ) { 98 | 99 | // handles wrapping of uv.x > 1 only 100 | 101 | var abc = 'abcd'; 102 | 103 | var uv, u, ax, ay; 104 | var i, il, j, jl; 105 | var vnum; 106 | 107 | var a = new THREE.Vector2(); 108 | var b = new THREE.Vector2(); 109 | 110 | var faces = geometry.faces; 111 | var uvs = geometry.faceVertexUvs[ 0 ]; 112 | 113 | var canvas = document.createElement( 'canvas' ); 114 | var width = size || 1024; // power of 2 required for wrapping 115 | var height = size || 1024; 116 | canvas.width = width; 117 | canvas.height = height; 118 | 119 | var ctx = canvas.getContext( '2d' ); 120 | ctx.lineWidth = 2; 121 | ctx.strokeStyle = 'rgba( 0, 0, 0, 1.0 )'; 122 | ctx.textAlign = 'center'; 123 | 124 | // paint background white 125 | 126 | ctx.fillStyle = 'rgba( 255, 255, 255, 1.0 )'; 127 | ctx.fillRect( 0, 0, width, height ); 128 | 129 | for ( i = 0, il = uvs.length; i < il; i++ ) { 130 | 131 | uv = uvs[ i ]; 132 | 133 | // draw lines 134 | 135 | ctx.beginPath(); 136 | 137 | a.set( 0, 0 ); 138 | 139 | for ( j = 0, jl = uv.length; j < jl; j++ ) { 140 | 141 | u = uv[ j ]; 142 | 143 | a.x += u.x; 144 | a.y += u.y; 145 | 146 | if ( j == 0 ) { 147 | 148 | ctx.moveTo( u.x * width, ( 1 - u.y ) * height ); 149 | 150 | } else { 151 | 152 | ctx.lineTo( u.x * width, ( 1 - u.y ) * height ); 153 | 154 | } 155 | 156 | } 157 | 158 | ctx.closePath(); 159 | ctx.stroke(); 160 | 161 | a.divideScalar( jl ); 162 | 163 | // label the face number 164 | 165 | ctx.font = "12pt Arial bold"; 166 | ctx.fillStyle = 'rgba( 0, 0, 0, 1.0 )'; 167 | ctx.fillText( i, a.x * width, ( 1 - a.y ) * height ); 168 | 169 | if ( a.x > 0.95 ) { // wrap x // 0.95 is arbitrary 170 | 171 | ctx.fillText( i, ( a.x % 1 ) * width, ( 1 - a.y ) * height ); 172 | 173 | } 174 | 175 | ctx.font = "8pt Arial bold"; 176 | ctx.fillStyle = 'rgba( 0, 0, 0, 1.0 )'; 177 | 178 | // label uv edge orders 179 | 180 | for ( j = 0, jl = uv.length; j < jl; j++ ) { 181 | 182 | u = uv[ j ]; 183 | b.addVectors( a, u ).divideScalar( 2 ); 184 | 185 | vnum = faces[ i ][ abc[ j ] ]; 186 | ctx.fillText( abc[ j ] + vnum, b.x * width, ( 1 - b.y ) * height ); 187 | 188 | if ( b.x > 0.95 ) { // wrap x 189 | 190 | ctx.fillText( abc[ j ] + vnum, ( b.x % 1 ) * width, ( 1 - b.y ) * height ); 191 | 192 | } 193 | 194 | } 195 | 196 | } 197 | 198 | return canvas; 199 | 200 | } 201 | 202 | -------------------------------------------------------------------------------- /js/threejs/examples/js/shaders/BokehShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * 4 | * Depth-of-field shader with bokeh 5 | * ported from GLSL shader by Martins Upitis 6 | * http://artmartinsh.blogspot.com/2010/02/glsl-lens-blur-filter-with-bokeh.html 7 | */ 8 | 9 | THREE.BokehShader = { 10 | 11 | uniforms: { 12 | 13 | "tColor": { type: "t", value: null }, 14 | "tDepth": { type: "t", value: null }, 15 | "focus": { type: "f", value: 1.0 }, 16 | "aspect": { type: "f", value: 1.0 }, 17 | "aperture": { type: "f", value: 0.025 }, 18 | "maxblur": { type: "f", value: 1.0 } 19 | 20 | }, 21 | 22 | vertexShader: [ 23 | 24 | "varying vec2 vUv;", 25 | 26 | "void main() {", 27 | 28 | "vUv = uv;", 29 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 30 | 31 | "}" 32 | 33 | ].join("\n"), 34 | 35 | fragmentShader: [ 36 | 37 | "varying vec2 vUv;", 38 | 39 | "uniform sampler2D tColor;", 40 | "uniform sampler2D tDepth;", 41 | 42 | "uniform float maxblur;", // max blur amount 43 | "uniform float aperture;", // aperture - bigger values for shallower depth of field 44 | 45 | "uniform float focus;", 46 | "uniform float aspect;", 47 | 48 | "void main() {", 49 | 50 | "vec2 aspectcorrect = vec2( 1.0, aspect );", 51 | 52 | "vec4 depth1 = texture2D( tDepth, vUv );", 53 | 54 | "float factor = depth1.x - focus;", 55 | 56 | "vec2 dofblur = vec2 ( clamp( factor * aperture, -maxblur, maxblur ) );", 57 | 58 | "vec2 dofblur9 = dofblur * 0.9;", 59 | "vec2 dofblur7 = dofblur * 0.7;", 60 | "vec2 dofblur4 = dofblur * 0.4;", 61 | 62 | "vec4 col = vec4( 0.0 );", 63 | 64 | "col += texture2D( tColor, vUv.xy );", 65 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.0, 0.4 ) * aspectcorrect ) * dofblur );", 66 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.15, 0.37 ) * aspectcorrect ) * dofblur );", 67 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.29, 0.29 ) * aspectcorrect ) * dofblur );", 68 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.37, 0.15 ) * aspectcorrect ) * dofblur );", 69 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.40, 0.0 ) * aspectcorrect ) * dofblur );", 70 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.37, -0.15 ) * aspectcorrect ) * dofblur );", 71 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.29, -0.29 ) * aspectcorrect ) * dofblur );", 72 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.15, -0.37 ) * aspectcorrect ) * dofblur );", 73 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.0, -0.4 ) * aspectcorrect ) * dofblur );", 74 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.15, 0.37 ) * aspectcorrect ) * dofblur );", 75 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.29, 0.29 ) * aspectcorrect ) * dofblur );", 76 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.37, 0.15 ) * aspectcorrect ) * dofblur );", 77 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.4, 0.0 ) * aspectcorrect ) * dofblur );", 78 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.37, -0.15 ) * aspectcorrect ) * dofblur );", 79 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.29, -0.29 ) * aspectcorrect ) * dofblur );", 80 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.15, -0.37 ) * aspectcorrect ) * dofblur );", 81 | 82 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.15, 0.37 ) * aspectcorrect ) * dofblur9 );", 83 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.37, 0.15 ) * aspectcorrect ) * dofblur9 );", 84 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.37, -0.15 ) * aspectcorrect ) * dofblur9 );", 85 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.15, -0.37 ) * aspectcorrect ) * dofblur9 );", 86 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.15, 0.37 ) * aspectcorrect ) * dofblur9 );", 87 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.37, 0.15 ) * aspectcorrect ) * dofblur9 );", 88 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.37, -0.15 ) * aspectcorrect ) * dofblur9 );", 89 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.15, -0.37 ) * aspectcorrect ) * dofblur9 );", 90 | 91 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.29, 0.29 ) * aspectcorrect ) * dofblur7 );", 92 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.40, 0.0 ) * aspectcorrect ) * dofblur7 );", 93 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.29, -0.29 ) * aspectcorrect ) * dofblur7 );", 94 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.0, -0.4 ) * aspectcorrect ) * dofblur7 );", 95 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.29, 0.29 ) * aspectcorrect ) * dofblur7 );", 96 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.4, 0.0 ) * aspectcorrect ) * dofblur7 );", 97 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.29, -0.29 ) * aspectcorrect ) * dofblur7 );", 98 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.0, 0.4 ) * aspectcorrect ) * dofblur7 );", 99 | 100 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.29, 0.29 ) * aspectcorrect ) * dofblur4 );", 101 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.4, 0.0 ) * aspectcorrect ) * dofblur4 );", 102 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.29, -0.29 ) * aspectcorrect ) * dofblur4 );", 103 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.0, -0.4 ) * aspectcorrect ) * dofblur4 );", 104 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.29, 0.29 ) * aspectcorrect ) * dofblur4 );", 105 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.4, 0.0 ) * aspectcorrect ) * dofblur4 );", 106 | "col += texture2D( tColor, vUv.xy + ( vec2( -0.29, -0.29 ) * aspectcorrect ) * dofblur4 );", 107 | "col += texture2D( tColor, vUv.xy + ( vec2( 0.0, 0.4 ) * aspectcorrect ) * dofblur4 );", 108 | 109 | "gl_FragColor = col / 41.0;", 110 | "gl_FragColor.a = 1.0;", 111 | 112 | "}" 113 | 114 | ].join("\n") 115 | 116 | }; 117 | -------------------------------------------------------------------------------- /js/threejs/examples/js/controls/EditorControls.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author qiao / https://github.com/qiao 3 | * @author mrdoob / http://mrdoob.com 4 | * @author alteredq / http://alteredqualia.com/ 5 | * @author WestLangley / http://github.com/WestLangley 6 | */ 7 | 8 | THREE.EditorControls = function ( object, domElement ) { 9 | 10 | domElement = ( domElement !== undefined ) ? domElement : document; 11 | 12 | // API 13 | 14 | this.enabled = true; 15 | 16 | // internals 17 | 18 | var scope = this; 19 | var vector = new THREE.Vector3(); 20 | 21 | var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2 }; 22 | var state = STATE.NONE; 23 | 24 | var center = new THREE.Vector3(); 25 | var normalMatrix = new THREE.Matrix3(); 26 | 27 | // events 28 | 29 | var changeEvent = { type: 'change' }; 30 | 31 | this.focus = function ( target ) { 32 | 33 | center.getPositionFromMatrix( target.matrixWorld ); 34 | object.lookAt( center ); 35 | 36 | scope.dispatchEvent( changeEvent ); 37 | 38 | }; 39 | 40 | this.pan = function ( distance ) { 41 | 42 | normalMatrix.getNormalMatrix( object.matrix ); 43 | 44 | distance.applyMatrix3( normalMatrix ); 45 | distance.multiplyScalar( vector.copy( center ).sub( object.position ).length() * 0.001 ); 46 | 47 | object.position.add( distance ); 48 | center.add( distance ); 49 | 50 | scope.dispatchEvent( changeEvent ); 51 | 52 | }; 53 | 54 | this.zoom = function ( distance ) { 55 | 56 | normalMatrix.getNormalMatrix( object.matrix ); 57 | 58 | distance.applyMatrix3( normalMatrix ); 59 | distance.multiplyScalar( vector.copy( center ).sub( object.position ).length() * 0.001 ); 60 | 61 | object.position.add( distance ); 62 | 63 | scope.dispatchEvent( changeEvent ); 64 | 65 | }; 66 | 67 | this.rotate = function ( delta ) { 68 | 69 | vector.copy( object.position ).sub( center ); 70 | 71 | var theta = Math.atan2( vector.x, vector.z ); 72 | var phi = Math.atan2( Math.sqrt( vector.x * vector.x + vector.z * vector.z ), vector.y ); 73 | 74 | theta += delta.x; 75 | phi += delta.y; 76 | 77 | var EPS = 0.000001; 78 | 79 | phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) ); 80 | 81 | var radius = vector.length(); 82 | 83 | vector.x = radius * Math.sin( phi ) * Math.sin( theta ); 84 | vector.y = radius * Math.cos( phi ); 85 | vector.z = radius * Math.sin( phi ) * Math.cos( theta ); 86 | 87 | object.position.copy( center ).add( vector ); 88 | 89 | object.lookAt( center ); 90 | 91 | scope.dispatchEvent( changeEvent ); 92 | 93 | }; 94 | 95 | // mouse 96 | 97 | function onMouseDown( event ) { 98 | 99 | if ( scope.enabled === false ) return; 100 | 101 | event.preventDefault(); 102 | 103 | if ( event.button === 0 ) { 104 | 105 | state = STATE.ROTATE; 106 | 107 | } else if ( event.button === 1 ) { 108 | 109 | state = STATE.ZOOM; 110 | 111 | } else if ( event.button === 2 ) { 112 | 113 | state = STATE.PAN; 114 | 115 | } 116 | 117 | document.addEventListener( 'mousemove', onMouseMove, false ); 118 | document.addEventListener( 'mouseup', onMouseUp, false ); 119 | 120 | } 121 | 122 | function onMouseMove( event ) { 123 | 124 | if ( scope.enabled === false ) return; 125 | 126 | event.preventDefault(); 127 | 128 | var movementX = event.movementX || event.webkitMovementX || event.mozMovementX || event.oMovementX || 0; 129 | var movementY = event.movementY || event.webkitMovementY || event.mozMovementY || event.oMovementY || 0; 130 | 131 | if ( state === STATE.ROTATE ) { 132 | 133 | scope.rotate( new THREE.Vector3( - movementX * 0.005, - movementY * 0.005, 0 ) ); 134 | 135 | } else if ( state === STATE.ZOOM ) { 136 | 137 | scope.zoom( new THREE.Vector3( 0, 0, movementY ) ); 138 | 139 | } else if ( state === STATE.PAN ) { 140 | 141 | scope.pan( new THREE.Vector3( - movementX, movementY, 0 ) ); 142 | 143 | } 144 | 145 | } 146 | 147 | function onMouseUp( event ) { 148 | 149 | if ( scope.enabled === false ) return; 150 | 151 | document.removeEventListener( 'mousemove', onMouseMove, false ); 152 | document.removeEventListener( 'mouseup', onMouseUp, false ); 153 | 154 | state = STATE.NONE; 155 | 156 | } 157 | 158 | function onMouseWheel( event ) { 159 | 160 | if ( scope.enabled === false ) return; 161 | 162 | var delta = 0; 163 | 164 | if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9 165 | 166 | delta = - event.wheelDelta; 167 | 168 | } else if ( event.detail ) { // Firefox 169 | 170 | delta = event.detail * 10; 171 | 172 | } 173 | 174 | scope.zoom( new THREE.Vector3( 0, 0, delta ) ); 175 | 176 | } 177 | 178 | domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false ); 179 | domElement.addEventListener( 'mousedown', onMouseDown, false ); 180 | domElement.addEventListener( 'mousewheel', onMouseWheel, false ); 181 | domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox 182 | 183 | // touch 184 | 185 | var touch = new THREE.Vector3(); 186 | var prevTouch = new THREE.Vector3(); 187 | var prevDistance = null; 188 | 189 | function touchStart( event ) { 190 | 191 | if ( scope.enabled === false ) return; 192 | 193 | var touches = event.touches; 194 | 195 | switch ( touches.length ) { 196 | 197 | case 2: 198 | var dx = touches[ 0 ].pageX - touches[ 1 ].pageX; 199 | var dy = touches[ 0 ].pageY - touches[ 1 ].pageY; 200 | prevDistance = Math.sqrt( dx * dx + dy * dy ); 201 | break; 202 | 203 | } 204 | 205 | prevTouch.set( touches[ 0 ].pageX, touches[ 0 ].pageY, 0 ); 206 | 207 | } 208 | 209 | function touchMove( event ) { 210 | 211 | if ( scope.enabled === false ) return; 212 | 213 | event.preventDefault(); 214 | event.stopPropagation(); 215 | 216 | var touches = event.touches; 217 | 218 | touch.set( touches[ 0 ].pageX, touches[ 0 ].pageY, 0 ); 219 | 220 | switch ( touches.length ) { 221 | 222 | case 1: 223 | scope.rotate( touch.sub( prevTouch ).multiplyScalar( - 0.005 ) ); 224 | break; 225 | 226 | case 2: 227 | var dx = touches[ 0 ].pageX - touches[ 1 ].pageX; 228 | var dy = touches[ 0 ].pageY - touches[ 1 ].pageY; 229 | var distance = Math.sqrt( dx * dx + dy * dy ); 230 | scope.zoom( new THREE.Vector3( 0, 0, prevDistance - distance ) ); 231 | prevDistance = distance; 232 | break; 233 | 234 | case 3: 235 | scope.pan( touch.sub( prevTouch ).setX( - touch.x ) ); 236 | break; 237 | 238 | } 239 | 240 | prevTouch.set( touches[ 0 ].pageX, touches[ 0 ].pageY, 0 ); 241 | 242 | } 243 | 244 | domElement.addEventListener( 'touchstart', touchStart, false ); 245 | domElement.addEventListener( 'touchmove', touchMove, false ); 246 | 247 | }; 248 | 249 | THREE.EditorControls.prototype = Object.create( THREE.EventDispatcher.prototype ); 250 | -------------------------------------------------------------------------------- /js/threejs/examples/js/MD2Character.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.MD2Character = function () { 6 | 7 | var scope = this; 8 | 9 | this.scale = 1; 10 | this.animationFPS = 6; 11 | 12 | this.root = new THREE.Object3D(); 13 | 14 | this.meshBody = null; 15 | this.meshWeapon = null; 16 | 17 | this.skinsBody = []; 18 | this.skinsWeapon = []; 19 | 20 | this.weapons = []; 21 | 22 | this.activeAnimation = null; 23 | 24 | this.onLoadComplete = function () {}; 25 | 26 | this.loadCounter = 0; 27 | 28 | this.loadParts = function ( config ) { 29 | 30 | this.loadCounter = config.weapons.length * 2 + config.skins.length + 1; 31 | 32 | var weaponsTextures = [] 33 | for ( var i = 0; i < config.weapons.length; i ++ ) weaponsTextures[ i ] = config.weapons[ i ][ 1 ]; 34 | 35 | // SKINS 36 | 37 | this.skinsBody = loadTextures( config.baseUrl + "skins/", config.skins ); 38 | this.skinsWeapon = loadTextures( config.baseUrl + "skins/", weaponsTextures ); 39 | 40 | // BODY 41 | 42 | var loader = new THREE.JSONLoader(); 43 | 44 | loader.load( config.baseUrl + config.body, function( geo ) { 45 | 46 | geo.computeBoundingBox(); 47 | scope.root.position.y = - scope.scale * geo.boundingBox.min.y; 48 | 49 | var mesh = createPart( geo, scope.skinsBody[ 0 ] ); 50 | mesh.scale.set( scope.scale, scope.scale, scope.scale ); 51 | 52 | scope.root.add( mesh ); 53 | 54 | scope.meshBody = mesh; 55 | scope.activeAnimation = geo.firstAnimation; 56 | 57 | checkLoadingComplete(); 58 | 59 | } ); 60 | 61 | // WEAPONS 62 | 63 | var generateCallback = function ( index, name ) { 64 | 65 | return function( geo ) { 66 | 67 | var mesh = createPart( geo, scope.skinsWeapon[ index ] ); 68 | mesh.scale.set( scope.scale, scope.scale, scope.scale ); 69 | mesh.visible = false; 70 | 71 | mesh.name = name; 72 | 73 | scope.root.add( mesh ); 74 | 75 | scope.weapons[ index ] = mesh; 76 | scope.meshWeapon = mesh; 77 | 78 | checkLoadingComplete(); 79 | 80 | } 81 | 82 | } 83 | 84 | for ( var i = 0; i < config.weapons.length; i ++ ) { 85 | 86 | loader.load( config.baseUrl + config.weapons[ i ][ 0 ], generateCallback( i, config.weapons[ i ][ 0 ] ) ); 87 | 88 | } 89 | 90 | }; 91 | 92 | this.setPlaybackRate = function ( rate ) { 93 | 94 | if ( this.meshBody ) this.meshBody.duration = this.meshBody.baseDuration / rate; 95 | if ( this.meshWeapon ) this.meshWeapon.duration = this.meshWeapon.baseDuration / rate; 96 | 97 | }; 98 | 99 | this.setWireframe = function ( wireframeEnabled ) { 100 | 101 | if ( wireframeEnabled ) { 102 | 103 | if ( this.meshBody ) this.meshBody.material = this.meshBody.materialWireframe; 104 | if ( this.meshWeapon ) this.meshWeapon.material = this.meshWeapon.materialWireframe; 105 | 106 | } else { 107 | 108 | if ( this.meshBody ) this.meshBody.material = this.meshBody.materialTexture; 109 | if ( this.meshWeapon ) this.meshWeapon.material = this.meshWeapon.materialTexture; 110 | 111 | } 112 | 113 | }; 114 | 115 | this.setSkin = function( index ) { 116 | 117 | if ( this.meshBody && this.meshBody.material.wireframe === false ) { 118 | 119 | this.meshBody.material.map = this.skinsBody[ index ]; 120 | 121 | } 122 | 123 | }; 124 | 125 | this.setWeapon = function ( index ) { 126 | 127 | for ( var i = 0; i < this.weapons.length; i ++ ) this.weapons[ i ].visible = false; 128 | 129 | var activeWeapon = this.weapons[ index ]; 130 | 131 | if ( activeWeapon ) { 132 | 133 | activeWeapon.visible = true; 134 | this.meshWeapon = activeWeapon; 135 | 136 | activeWeapon.playAnimation( this.activeAnimation, this.animationFPS ); 137 | 138 | this.meshWeapon.baseDuration = this.meshWeapon.duration; 139 | 140 | this.meshWeapon.time = this.meshBody.time; 141 | this.meshWeapon.duration = this.meshBody.duration; 142 | 143 | } 144 | 145 | }; 146 | 147 | this.setAnimation = function ( animationName ) { 148 | 149 | if ( this.meshBody ) { 150 | 151 | this.meshBody.playAnimation( animationName, this.animationFPS ); 152 | this.meshBody.baseDuration = this.meshBody.duration; 153 | 154 | } 155 | 156 | if ( this.meshWeapon ) { 157 | 158 | this.meshWeapon.playAnimation( animationName, this.animationFPS ); 159 | this.meshWeapon.baseDuration = this.meshWeapon.duration; 160 | this.meshWeapon.time = this.meshBody.time; 161 | 162 | } 163 | 164 | this.activeAnimation = animationName; 165 | 166 | }; 167 | 168 | this.update = function ( delta ) { 169 | 170 | if ( this.meshBody ) { 171 | 172 | this.meshBody.updateAnimation( 1000 * delta ); 173 | 174 | } 175 | 176 | if ( this.meshWeapon ) { 177 | 178 | this.meshWeapon.updateAnimation( 1000 * delta ); 179 | 180 | } 181 | 182 | }; 183 | 184 | function loadTextures( baseUrl, textureUrls ) { 185 | 186 | var mapping = new THREE.UVMapping(); 187 | var textures = []; 188 | 189 | for ( var i = 0; i < textureUrls.length; i ++ ) { 190 | 191 | textures[ i ] = THREE.ImageUtils.loadTexture( baseUrl + textureUrls[ i ], mapping, checkLoadingComplete ); 192 | textures[ i ].name = textureUrls[ i ]; 193 | 194 | } 195 | 196 | return textures; 197 | 198 | }; 199 | 200 | function createPart( geometry, skinMap ) { 201 | 202 | geometry.computeMorphNormals(); 203 | 204 | var whiteMap = THREE.ImageUtils.generateDataTexture( 1, 1, new THREE.Color( 0xffffff ) ); 205 | var materialWireframe = new THREE.MeshPhongMaterial( { color: 0xffaa00, specular: 0x111111, shininess: 50, wireframe: true, shading: THREE.SmoothShading, map: whiteMap, morphTargets: true, morphNormals: true, metal: false } ); 206 | 207 | var materialTexture = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess: 50, wireframe: false, shading: THREE.SmoothShading, map: skinMap, morphTargets: true, morphNormals: true, metal: false } ); 208 | materialTexture.wrapAround = true; 209 | 210 | // 211 | 212 | var mesh = new THREE.MorphAnimMesh( geometry, materialTexture ); 213 | mesh.rotation.y = -Math.PI/2; 214 | 215 | mesh.castShadow = true; 216 | mesh.receiveShadow = true; 217 | 218 | // 219 | 220 | mesh.materialTexture = materialTexture; 221 | mesh.materialWireframe = materialWireframe; 222 | 223 | // 224 | 225 | mesh.parseAnimations(); 226 | 227 | mesh.playAnimation( geometry.firstAnimation, scope.animationFPS ); 228 | mesh.baseDuration = mesh.duration; 229 | 230 | return mesh; 231 | 232 | }; 233 | 234 | function checkLoadingComplete() { 235 | 236 | scope.loadCounter -= 1; 237 | 238 | if ( scope.loadCounter === 0 ) scope.onLoadComplete(); 239 | 240 | }; 241 | 242 | }; 243 | -------------------------------------------------------------------------------- /js/threejs/examples/js/renderers/CSS3DRenderer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Based on http://www.emagix.net/academic/mscs-project/item/camera-sync-with-css3-and-webgl-threejs 3 | * @author mrdoob / http://mrdoob.com/ 4 | */ 5 | 6 | THREE.CSS3DObject = function ( element ) { 7 | 8 | THREE.Object3D.call( this ); 9 | 10 | this.element = element; 11 | this.element.style.position = "absolute"; 12 | this.element.style.WebkitTransformStyle = 'preserve-3d'; 13 | this.element.style.MozTransformStyle = 'preserve-3d'; 14 | this.element.style.oTransformStyle = 'preserve-3d'; 15 | this.element.style.transformStyle = 'preserve-3d'; 16 | 17 | }; 18 | 19 | THREE.CSS3DObject.prototype = Object.create( THREE.Object3D.prototype ); 20 | 21 | THREE.CSS3DSprite = function ( element ) { 22 | 23 | THREE.CSS3DObject.call( this, element ); 24 | 25 | }; 26 | 27 | THREE.CSS3DSprite.prototype = Object.create( THREE.CSS3DObject.prototype ); 28 | 29 | // 30 | 31 | THREE.CSS3DRenderer = function () { 32 | 33 | console.log( 'THREE.CSS3DRenderer', THREE.REVISION ); 34 | 35 | var _width, _height; 36 | var _widthHalf, _heightHalf; 37 | var _projector = new THREE.Projector(); 38 | 39 | var _tmpMatrix = new THREE.Matrix4(); 40 | 41 | this.domElement = document.createElement( 'div' ); 42 | 43 | this.domElement.style.overflow = 'hidden'; 44 | 45 | this.domElement.style.WebkitTransformStyle = 'preserve-3d'; 46 | this.domElement.style.WebkitPerspectiveOrigin = '50% 50%'; 47 | 48 | this.domElement.style.MozTransformStyle = 'preserve-3d'; 49 | this.domElement.style.MozPerspectiveOrigin = '50% 50%'; 50 | 51 | this.domElement.style.oTransformStyle = 'preserve-3d'; 52 | this.domElement.style.oPerspectiveOrigin = '50% 50%'; 53 | 54 | this.domElement.style.transformStyle = 'preserve-3d'; 55 | this.domElement.style.perspectiveOrigin = '50% 50%'; 56 | 57 | // TODO: Shouldn't it be possible to remove cameraElement? 58 | 59 | this.cameraElement = document.createElement( 'div' ); 60 | 61 | this.cameraElement.style.WebkitTransformStyle = 'preserve-3d'; 62 | this.cameraElement.style.MozTransformStyle = 'preserve-3d'; 63 | this.cameraElement.style.oTransformStyle = 'preserve-3d'; 64 | this.cameraElement.style.transformStyle = 'preserve-3d'; 65 | 66 | this.domElement.appendChild( this.cameraElement ); 67 | 68 | this.setSize = function ( width, height ) { 69 | 70 | _width = width; 71 | _height = height; 72 | 73 | _widthHalf = _width / 2; 74 | _heightHalf = _height / 2; 75 | 76 | this.domElement.style.width = width + 'px'; 77 | this.domElement.style.height = height + 'px'; 78 | 79 | this.cameraElement.style.width = width + 'px'; 80 | this.cameraElement.style.height = height + 'px'; 81 | 82 | }; 83 | 84 | var epsilon = function ( value ) { 85 | 86 | return Math.abs( value ) < 0.000001 ? 0 : value; 87 | 88 | }; 89 | 90 | var getCameraCSSMatrix = function ( matrix ) { 91 | 92 | var elements = matrix.elements; 93 | 94 | return 'matrix3d(' + 95 | epsilon( elements[ 0 ] ) + ',' + 96 | epsilon( - elements[ 1 ] ) + ',' + 97 | epsilon( elements[ 2 ] ) + ',' + 98 | epsilon( elements[ 3 ] ) + ',' + 99 | epsilon( elements[ 4 ] ) + ',' + 100 | epsilon( - elements[ 5 ] ) + ',' + 101 | epsilon( elements[ 6 ] ) + ',' + 102 | epsilon( elements[ 7 ] ) + ',' + 103 | epsilon( elements[ 8 ] ) + ',' + 104 | epsilon( - elements[ 9 ] ) + ',' + 105 | epsilon( elements[ 10 ] ) + ',' + 106 | epsilon( elements[ 11 ] ) + ',' + 107 | epsilon( elements[ 12 ] ) + ',' + 108 | epsilon( - elements[ 13 ] ) + ',' + 109 | epsilon( elements[ 14 ] ) + ',' + 110 | epsilon( elements[ 15 ] ) + 111 | ')'; 112 | 113 | } 114 | 115 | var getObjectCSSMatrix = function ( matrix ) { 116 | 117 | var elements = matrix.elements; 118 | 119 | return 'translate3d(-50%,-50%,0) matrix3d(' + 120 | epsilon( elements[ 0 ] ) + ',' + 121 | epsilon( elements[ 1 ] ) + ',' + 122 | epsilon( elements[ 2 ] ) + ',' + 123 | epsilon( elements[ 3 ] ) + ',' + 124 | epsilon( - elements[ 4 ] ) + ',' + 125 | epsilon( - elements[ 5 ] ) + ',' + 126 | epsilon( - elements[ 6 ] ) + ',' + 127 | epsilon( - elements[ 7 ] ) + ',' + 128 | epsilon( elements[ 8 ] ) + ',' + 129 | epsilon( elements[ 9 ] ) + ',' + 130 | epsilon( elements[ 10 ] ) + ',' + 131 | epsilon( elements[ 11 ] ) + ',' + 132 | epsilon( elements[ 12 ] ) + ',' + 133 | epsilon( elements[ 13 ] ) + ',' + 134 | epsilon( elements[ 14 ] ) + ',' + 135 | epsilon( elements[ 15 ] ) + 136 | ')'; 137 | 138 | } 139 | 140 | this.render = function ( scene, camera ) { 141 | 142 | var fov = 0.5 / Math.tan( THREE.Math.degToRad( camera.fov * 0.5 ) ) * _height; 143 | 144 | this.domElement.style.WebkitPerspective = fov + "px"; 145 | this.domElement.style.MozPerspective = fov + "px"; 146 | this.domElement.style.oPerspective = fov + "px"; 147 | this.domElement.style.perspective = fov + "px"; 148 | 149 | var objects = _projector.projectScene( scene, camera, false ).objects; 150 | 151 | var style = "translate3d(0,0," + fov + "px)" + getCameraCSSMatrix( camera.matrixWorldInverse ) + " translate3d(" + _widthHalf + "px," + _heightHalf + "px, 0)"; 152 | 153 | this.cameraElement.style.WebkitTransform = style; 154 | this.cameraElement.style.MozTransform = style; 155 | this.cameraElement.style.oTransform = style; 156 | this.cameraElement.style.transform = style; 157 | 158 | for ( var i = 0, il = objects.length; i < il; i ++ ) { 159 | 160 | var object = objects[ i ].object; 161 | 162 | if ( object instanceof THREE.CSS3DObject ) { 163 | 164 | var element = object.element; 165 | 166 | if ( object instanceof THREE.CSS3DSprite ) { 167 | 168 | // http://swiftcoder.wordpress.com/2008/11/25/constructing-a-billboard-matrix/ 169 | 170 | _tmpMatrix.copy( camera.matrixWorldInverse ); 171 | _tmpMatrix.transpose(); 172 | _tmpMatrix.copyPosition( object.matrixWorld ); 173 | _tmpMatrix.scale( object.scale ); 174 | 175 | _tmpMatrix.elements[ 3 ] = 0; 176 | _tmpMatrix.elements[ 7 ] = 0; 177 | _tmpMatrix.elements[ 11 ] = 0; 178 | _tmpMatrix.elements[ 15 ] = 1; 179 | 180 | style = getObjectCSSMatrix( _tmpMatrix ); 181 | 182 | } else { 183 | 184 | style = getObjectCSSMatrix( object.matrixWorld ); 185 | 186 | } 187 | 188 | /* 189 | element.style.WebkitBackfaceVisibility = 'hidden'; 190 | element.style.MozBackfaceVisibility = 'hidden'; 191 | element.style.oBackfaceVisibility = 'hidden'; 192 | element.style.backfaceVisibility = 'hidden'; 193 | */ 194 | 195 | element.style.WebkitTransform = style; 196 | element.style.MozTransform = style; 197 | element.style.oTransform = style; 198 | element.style.transform = style; 199 | 200 | if ( element.parentNode !== this.cameraElement ) { 201 | 202 | this.cameraElement.appendChild( element ); 203 | 204 | } 205 | 206 | } 207 | 208 | } 209 | 210 | }; 211 | 212 | }; 213 | -------------------------------------------------------------------------------- /js/threejs/examples/js/Cloth.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Cloth Simulation using a relaxed constrains solver 3 | */ 4 | 5 | // Suggested Readings 6 | 7 | // Advanced Character Physics by Thomas Jakobsen Character 8 | // http://freespace.virgin.net/hugo.elias/models/m_cloth.htm 9 | // http://en.wikipedia.org/wiki/Cloth_modeling 10 | // http://cg.alexandra.dk/tag/spring-mass-system/ 11 | // Real-time Cloth Animation http://www.darwin3d.com/gamedev/articles/col0599.pdf 12 | 13 | var DAMPING = 0.03; 14 | var DRAG = 1 - DAMPING; 15 | var MASS = .1; 16 | var restDistance = 25; 17 | 18 | 19 | var xSegs = 10; // 20 | var ySegs = 10; // 21 | 22 | var clothFunction = plane(restDistance * xSegs, restDistance * ySegs); 23 | 24 | var cloth = new Cloth(xSegs, ySegs); 25 | 26 | var GRAVITY = 981 * 1.4; // 27 | var gravity = new THREE.Vector3( 0, -GRAVITY, 0 ).multiplyScalar(MASS); 28 | 29 | 30 | var TIMESTEP = 18 / 1000; 31 | var TIMESTEP_SQ = TIMESTEP * TIMESTEP; 32 | 33 | var pins = []; 34 | 35 | 36 | var wind = true; 37 | var windStrength = 2; 38 | var windForce = new THREE.Vector3(0,0,0); 39 | 40 | var ballPosition = new THREE.Vector3(0, -45, 0); 41 | var ballSize = 60; //40 42 | 43 | var tmpForce = new THREE.Vector3(); 44 | 45 | var lastTime; 46 | 47 | 48 | function plane(width, height) { 49 | 50 | return function(u, v) { 51 | var x = (u-0.5) * width; 52 | var y = (v+0.5) * height; 53 | var z = 0; 54 | 55 | return new THREE.Vector3(x, y, z); 56 | }; 57 | } 58 | 59 | function Particle(x, y, z, mass) { 60 | this.position = clothFunction(x, y); // position 61 | this.previous = clothFunction(x, y); // previous 62 | this.original = clothFunction(x, y); 63 | this.a = new THREE.Vector3(0, 0, 0); // acceleration 64 | this.mass = mass; 65 | this.invMass = 1 / mass; 66 | this.tmp = new THREE.Vector3(); 67 | this.tmp2 = new THREE.Vector3(); 68 | } 69 | 70 | // Force -> Acceleration 71 | Particle.prototype.addForce = function(force) { 72 | this.a.add( 73 | this.tmp2.copy(force).multiplyScalar(this.invMass) 74 | ); 75 | }; 76 | 77 | 78 | // Performs verlet integration 79 | Particle.prototype.integrate = function(timesq) { 80 | var newPos = this.tmp.subVectors(this.position, this.previous); 81 | newPos.multiplyScalar(DRAG).add(this.position); 82 | newPos.add(this.a.multiplyScalar(timesq)); 83 | 84 | this.tmp = this.previous; 85 | this.previous = this.position; 86 | this.position = newPos; 87 | 88 | this.a.set(0, 0, 0); 89 | } 90 | 91 | 92 | var diff = new THREE.Vector3(); 93 | 94 | function satisifyConstrains(p1, p2, distance) { 95 | diff.subVectors(p2.position, p1.position); 96 | var currentDist = diff.length(); 97 | if (currentDist==0) return; // prevents division by 0 98 | var correction = diff.multiplyScalar(1 - distance/currentDist); 99 | var correctionHalf = correction.multiplyScalar(0.5); 100 | p1.position.add(correctionHalf); 101 | p2.position.sub(correctionHalf); 102 | } 103 | 104 | 105 | function Cloth(w, h) { 106 | w = w || 10; 107 | h = h || 10; 108 | this.w = w; 109 | this.h = h; 110 | 111 | var particles = []; 112 | var constrains = []; 113 | 114 | var u, v; 115 | 116 | // Create particles 117 | for (v=0;v<=h;v++) { 118 | for (u=0;u<=w;u++) { 119 | particles.push( 120 | new Particle(u/w, v/h, 0, MASS) 121 | ); 122 | } 123 | } 124 | 125 | // Structural 126 | 127 | for (v=0;v" + strThisChar + ""; 250 | } else { 251 | strChars += strThisChar; 252 | } 253 | } 254 | strChars += "
"; 255 | } 256 | 257 | oAscii.innerHTML = "" + strChars + ""; 258 | 259 | // console.timeEnd('rendering'); 260 | 261 | // return oAscii; 262 | } 263 | 264 | // end modified asciifyImage block 265 | 266 | }; 267 | --------------------------------------------------------------------------------