├── Json ├── block.json ├── blocks.json ├── blocks1.json ├── city.json ├── down.json ├── house.json ├── mutliple materials.json ├── myJson.json ├── myNewJson.json ├── myTree.json ├── smiley face.json ├── stairs.json ├── static-extended.json └── static.json ├── README.md ├── Three.FirstPersonControls.js ├── bluefreeze.zip ├── bluefreeze └── bluefreeze │ ├── Note.txt │ ├── back.jpg │ ├── bluefreeze.zip │ ├── front.jpg │ ├── left.jpg │ ├── right.jpg │ └── top.jpg ├── calm.zip ├── calm └── calm │ ├── Note.txt │ ├── calm.zip │ ├── calm_back.jpg │ ├── calm_front.jpg │ ├── calm_left.jpg │ ├── calm_right.jpg │ └── calm_top.jpg ├── city.zip ├── city └── city │ ├── Note.txt │ ├── back.jpg │ ├── city.zip │ ├── front.jpg │ ├── left.jpg │ ├── right.jpg │ └── top.jpg ├── comawhite.zip ├── comawhite └── comawhite │ ├── Note.txt │ ├── back.jpg │ ├── comawhite.zip │ ├── front.jpg │ ├── left.jpg │ ├── right.jpg │ └── top.jpg ├── darkland.zip ├── darkland └── darkland │ ├── Note.txt │ ├── back.jpg │ ├── darkland.zip │ ├── front.jpg │ ├── left.jpg │ ├── right.jpg │ └── top.jpg ├── file2 - cannon_attempt.html ├── gui.js ├── images ├── Untitled.png ├── first_person_view.png ├── floor-1.jpg ├── ground.jpg ├── physics.png ├── physics2.png ├── stone - Copy.png ├── stone.png ├── wall-1.jpg ├── wall-2.jpg └── wood.jpg ├── jquery-1.7.2.min.js ├── js ├── AnimationClipCreator.js ├── BlendCharacter.js ├── BlendCharacterGui.js ├── BufferGeometryUtils.js ├── Car.js ├── Cloth.js ├── CurveExtras.js ├── Detector.js ├── GPUParticleSystem.js ├── Gyroscope.js ├── ImprovedNoise.js ├── MD2Character.js ├── MD2CharacterComplex.js ├── MarchingCubes.js ├── Mirror.js ├── MorphAnimMesh.js ├── MorphAnimation.js ├── Ocean.js ├── Octree.js ├── PRNG.js ├── ParametricGeometries.js ├── ShaderGodRays.js ├── ShaderSkin.js ├── ShaderTerrain.js ├── ShaderToon.js ├── SimplexNoise.js ├── SimulationRenderer.js ├── SkyShader.js ├── TypedArrayUtils.js ├── UCSCharacter.js ├── WaterShader.js ├── cameras │ └── CombinedCamera.js ├── controls │ ├── DeviceOrientationControls.js │ ├── DragControls.js │ ├── EditorControls.js │ ├── FirstPersonControls.js │ ├── FlyControls.js │ ├── MouseControls.js │ ├── OrbitControls.js │ ├── OrthographicTrackballControls.js │ ├── PointerLockControls.js │ ├── TrackballControls.js │ ├── TransformControls.js │ └── VRControls.js ├── crossfade │ ├── gui.js │ ├── scenes.js │ └── transition.js ├── curves │ ├── NURBSCurve.js │ ├── NURBSSurface.js │ └── NURBSUtils.js ├── effects │ ├── AnaglyphEffect.js │ ├── AsciiEffect.js │ ├── ParallaxBarrierEffect.js │ ├── StereoEffect.js │ └── VREffect.js ├── exporters │ ├── OBJExporter.js │ ├── STLBinaryExporter.js │ ├── STLExporter.js │ └── TypedGeometryExporter.js ├── geometries │ ├── ConvexGeometry.js │ ├── DecalGeometry.js │ ├── TeapotBufferGeometry.js │ ├── TextGeometry.js │ ├── hilbert2D.js │ └── hilbert3D.js ├── libs │ ├── dat.gui.min.js │ ├── jszip.min.js │ ├── msgpack-js.js │ ├── pnltri.min.js │ ├── require.js │ ├── stats.min.js │ ├── system.min.js │ └── tween.min.js ├── loaders │ ├── AMFLoader.js │ ├── AWDLoader.js │ ├── AssimpJSONLoader.js │ ├── BabylonLoader.js │ ├── BinaryLoader.js │ ├── ColladaLoader.js │ ├── ColladaLoader2.js │ ├── DDSLoader.js │ ├── KMZLoader.js │ ├── MD2Loader.js │ ├── MTLLoader.js │ ├── OBJLoader.js │ ├── OBJMTLLoader.js │ ├── PDBLoader.js │ ├── PLYLoader.js │ ├── PVRLoader.js │ ├── RGBELoader.js │ ├── STLLoader.js │ ├── SVGLoader.js │ ├── TGALoader.js │ ├── UTF8Loader.js │ ├── VRMLLoader.js │ ├── VTKLoader.js │ ├── collada │ │ ├── Animation.js │ │ ├── AnimationHandler.js │ │ └── KeyFrameAnimation.js │ ├── ctm │ │ ├── CTMLoader.js │ │ ├── CTMWorker.js │ │ ├── ctm.js │ │ ├── license │ │ │ ├── OpenCTM.txt │ │ │ ├── js-lzma.txt │ │ │ └── js-openctm.txt │ │ └── lzma.js │ ├── deprecated │ │ └── SceneLoader.js │ ├── gltf │ │ ├── glTF-parser.js │ │ ├── glTFAnimation.js │ │ ├── glTFLoader.js │ │ └── glTFLoaderUtils.js │ └── sea3d │ │ ├── SEA3D.js │ │ ├── SEA3DDeflate.js │ │ ├── SEA3DLZMA.js │ │ └── SEA3DLoader.js ├── math │ ├── ColorConverter.js │ └── Lut.js ├── modifiers │ ├── ExplodeModifier.js │ ├── SubdivisionModifier.js │ └── TessellateModifier.js ├── objects │ └── ShadowMesh.js ├── postprocessing │ ├── AdaptiveToneMappingPass.js │ ├── BloomPass.js │ ├── BokehPass.js │ ├── DotScreenPass.js │ ├── EffectComposer.js │ ├── FilmPass.js │ ├── GlitchPass.js │ ├── MaskPass.js │ ├── RenderPass.js │ ├── SavePass.js │ ├── ShaderPass.js │ └── TexturePass.js ├── renderers │ ├── CSS2DRenderer.js │ ├── CSS3DRenderer.js │ ├── CSS3DStereoRenderer.js │ ├── CanvasRenderer.js │ ├── Projector.js │ ├── RaytracingRenderer.js │ ├── SVGRenderer.js │ └── SoftwareRenderer.js ├── shaders │ ├── BasicShader.js │ ├── BleachBypassShader.js │ ├── BlendShader.js │ ├── BokehShader.js │ ├── BokehShader2.js │ ├── BrightnessContrastShader.js │ ├── ColorCorrectionShader.js │ ├── ColorifyShader.js │ ├── ConvolutionShader.js │ ├── CopyShader.js │ ├── DOFMipMapShader.js │ ├── DigitalGlitch.js │ ├── DotScreenShader.js │ ├── EdgeShader.js │ ├── EdgeShader2.js │ ├── FXAAShader.js │ ├── FilmShader.js │ ├── FocusShader.js │ ├── FresnelShader.js │ ├── GammaCorrectionShader.js │ ├── HorizontalBlurShader.js │ ├── HorizontalTiltShiftShader.js │ ├── HueSaturationShader.js │ ├── KaleidoShader.js │ ├── LuminosityShader.js │ ├── MirrorShader.js │ ├── NormalMapShader.js │ ├── OceanShaders.js │ ├── ParallaxShader.js │ ├── RGBShiftShader.js │ ├── SSAOShader.js │ ├── SepiaShader.js │ ├── TechnicolorShader.js │ ├── ToneMapShader.js │ ├── TriangleBlurShader.js │ ├── UnpackDepthRGBAShader.js │ ├── VerticalBlurShader.js │ ├── VerticalTiltShiftShader.js │ └── VignetteShader.js └── utils │ ├── FontUtils.js │ ├── GeometryUtils.js │ ├── ImageUtils.js │ ├── ShadowMapViewer.js │ └── UVsDebug.js ├── level.html ├── level_editor.html ├── libs ├── TrackballControls.js ├── ammo.js ├── basic.html ├── cannon.min.js ├── package.require.js ├── physi.js ├── physijs_worker.js ├── three.js ├── three.min.js ├── threex.keyboardstate.js └── threex.universalloader.js ├── mongoose-free-5.6.exe └── textures ├── bluefreeze ├── Note.txt ├── back.jpg ├── bluefreeze.zip ├── front.jpg ├── left.jpg ├── right.jpg └── top.jpg ├── city ├── Note.txt ├── back.jpg ├── city.zip ├── front.jpg ├── left.jpg ├── right.jpg └── top.jpg ├── comawhite ├── Note.txt ├── back.jpg ├── comawhite.zip ├── front.jpg ├── left.jpg ├── right.jpg └── top.jpg ├── concrete.jpg ├── darkland ├── Note.txt ├── back.jpg ├── darkland.zip ├── front.jpg ├── left.jpg ├── right.jpg └── top.jpg ├── mountains ├── back.jpg ├── front.jpg ├── left.jpg ├── right.jpg └── top.jpg ├── snow.jpg └── white-bricks.jpg /Json/block.json: -------------------------------------------------------------------------------- 1 | [{"x":-2,"y":0,"z":9,"t":0,"static":true},{"x":4,"y":0,"z":10,"t":1,"static":true},{"x":4,"y":0,"z":11,"t":1,"static":true},{"x":5,"y":0,"z":11,"t":1,"static":true},{"x":5,"y":0,"z":12,"t":1,"static":true},{"x":4,"y":0,"z":12,"t":1,"static":true},{"x":9,"y":0,"z":10,"t":2,"static":true},{"x":9,"y":0,"z":11,"t":2,"static":true},{"x":9,"y":0,"z":12,"t":2,"static":true},{"x":11,"y":0,"z":12,"t":3,"static":true},{"x":11,"y":0,"z":13,"t":3,"static":true},{"x":10,"y":0,"z":13,"t":3,"static":true},{"x":10,"y":0,"z":14,"t":3,"static":true},{"x":9,"y":0,"z":14,"t":3,"static":true},{"x":19,"y":0,"z":5,"t":3,"static":true},{"x":19,"y":0,"z":6,"t":3,"static":true},{"x":-1,"y":0,"z":15,"t":4,"static":true}] -------------------------------------------------------------------------------- /Json/blocks.json: -------------------------------------------------------------------------------- 1 | [{"x":-2,"y":0,"z":9,"t":0,"static":true},{"x":4,"y":0,"z":10,"t":1,"static":true},{"x":4,"y":0,"z":11,"t":1,"static":true},{"x":5,"y":0,"z":11,"t":1,"static":true},{"x":5,"y":0,"z":12,"t":1,"static":true},{"x":4,"y":0,"z":12,"t":1,"static":true},{"x":9,"y":0,"z":10,"t":2,"static":true},{"x":9,"y":0,"z":11,"t":2,"static":true},{"x":9,"y":0,"z":12,"t":2,"static":true},{"x":11,"y":0,"z":12,"t":3,"static":true},{"x":11,"y":0,"z":13,"t":3,"static":true},{"x":10,"y":0,"z":13,"t":3,"static":true},{"x":10,"y":0,"z":14,"t":3,"static":true},{"x":9,"y":0,"z":14,"t":3,"static":true},{"x":19,"y":0,"z":5,"t":3,"static":true},{"x":19,"y":0,"z":6,"t":3,"static":true},{"x":0,"y":0,"z":16,"t":4,"static":true}] -------------------------------------------------------------------------------- /Json/blocks1.json: -------------------------------------------------------------------------------- 1 | [{"x":-2,"y":0,"z":9,"t":0,"static":true},{"x":4,"y":0,"z":10,"t":1,"static":true},{"x":4,"y":0,"z":11,"t":1,"static":true},{"x":5,"y":0,"z":11,"t":1,"static":true},{"x":5,"y":0,"z":12,"t":1,"static":true},{"x":4,"y":0,"z":12,"t":1,"static":true},{"x":9,"y":0,"z":10,"t":2,"static":true},{"x":9,"y":0,"z":11,"t":2,"static":true},{"x":9,"y":0,"z":12,"t":2,"static":true},{"x":11,"y":0,"z":12,"t":3,"static":true},{"x":11,"y":0,"z":13,"t":3,"static":true},{"x":10,"y":0,"z":13,"t":3,"static":true},{"x":10,"y":0,"z":14,"t":3,"static":true},{"x":9,"y":0,"z":14,"t":3,"static":true},{"x":19,"y":0,"z":5,"t":3,"static":true},{"x":19,"y":0,"z":6,"t":3,"static":true},{"x":-1,"y":0,"z":15,"t":4,"static":true}] -------------------------------------------------------------------------------- /Json/down.json: -------------------------------------------------------------------------------- 1 | [{"x":0,"y":0,"z":0,"t":0},{"x":0,"y":1,"z":0,"t":0},{"x":0,"y":2,"z":0,"t":0},{"x":0,"y":2,"z":1,"t":0},{"x":0,"y":3,"z":0,"t":0},{"x":0,"y":4,"z":0,"t":0},{"x":0,"y":5,"z":0,"t":0}] -------------------------------------------------------------------------------- /Json/mutliple materials.json: -------------------------------------------------------------------------------- 1 | [{"x":-1,"y":0,"z":1,"t":0},{"x":0,"y":0,"z":1,"t":0},{"x":0,"y":0,"z":2,"t":0},{"x":-1,"y":0,"z":2,"t":0},{"x":6,"y":0,"z":6,"t":1},{"x":7,"y":0,"z":6,"t":1},{"x":7,"y":0,"z":7,"t":1},{"x":6,"y":0,"z":7,"t":1},{"x":6,"y":0,"z":8,"t":1},{"x":7,"y":0,"z":8,"t":1},{"x":7,"y":1,"z":8,"t":1},{"x":7,"y":2,"z":8,"t":1},{"x":6,"y":1,"z":8,"t":1},{"x":7,"y":0,"z":9,"t":1},{"x":7,"y":1,"z":9,"t":1},{"x":6,"y":0,"z":9,"t":1},{"x":8,"y":0,"z":9,"t":1},{"x":8,"y":1,"z":9,"t":1},{"x":8,"y":0,"z":8,"t":1},{"x":8,"y":0,"z":7,"t":1},{"x":7,"y":1,"z":7,"t":1},{"x":3,"y":0,"z":-3,"t":1},{"x":3,"y":0,"z":-5,"t":1},{"x":3,"y":0,"z":-4,"t":1},{"x":4,"y":0,"z":-3,"t":1},{"x":4,"y":1,"z":-3,"t":1},{"x":6,"y":0,"z":-5,"t":1},{"x":5,"y":0,"z":-7,"t":1},{"x":1,"y":0,"z":-7,"t":1},{"x":-1,"y":0,"z":-7,"t":1},{"x":-5,"y":0,"z":-3,"t":1},{"x":-3,"y":0,"z":-2,"t":1},{"x":-3,"y":0,"z":-6,"t":1},{"x":-4,"y":0,"z":-8,"t":1},{"x":-8,"y":0,"z":-3,"t":1},{"x":-5,"y":0,"z":7,"t":1},{"x":1,"y":0,"z":5,"t":1},{"x":0,"y":0,"z":4,"t":1},{"x":-1,"y":0,"z":7,"t":1},{"x":2,"y":0,"z":7,"t":1},{"x":3,"y":0,"z":0,"t":3},{"x":3,"y":1,"z":0,"t":3},{"x":3,"y":2,"z":0,"t":3},{"x":3,"y":3,"z":0,"t":3},{"x":3,"y":4,"z":0,"t":3},{"x":3,"y":5,"z":0,"t":3},{"x":3,"y":5,"z":1,"t":2},{"x":4,"y":5,"z":0,"t":2},{"x":3,"y":6,"z":1,"t":2},{"x":4,"y":6,"z":0,"t":2},{"x":3,"y":5,"z":-1,"t":2},{"x":3,"y":6,"z":-1,"t":2},{"x":2,"y":5,"z":0,"t":2},{"x":2,"y":6,"z":0,"t":2},{"x":4,"y":0,"z":0,"t":2}] -------------------------------------------------------------------------------- /Json/myJson.json: -------------------------------------------------------------------------------- 1 | [{"x":9,"y":0,"z":9},{"x":-1,"y":0,"z":0},{"x":-10,"y":0,"z":-10},{"x":-4,"y":0,"z":-5}] -------------------------------------------------------------------------------- /Json/myNewJson.json: -------------------------------------------------------------------------------- 1 | [{"x":9,"y":0,"z":9},{"x":-1,"y":0,"z":0},{"x":-10,"y":0,"z":-10},{"x":-4,"y":0,"z":-5},{"x":-1,"y":0,"z":-1},{"x":-1,"y":0,"z":0},{"x":-1,"y":1,"z":0},{"x":-1,"y":1,"z":1},{"x":0,"y":1,"z":1},{"x":0,"y":1,"z":2},{"x":0,"y":2,"z":2},{"x":0,"y":2,"z":3},{"x":0,"y":3,"z":3},{"x":-1,"y":2,"z":1},{"x":0,"y":2,"z":1},{"x":0,"y":2,"z":0},{"x":1,"y":2,"z":0},{"x":1,"y":3,"z":0},{"x":2,"y":3,"z":0},{"x":2,"y":4,"z":0},{"x":2,"y":4,"z":-1},{"x":3,"y":4,"z":-1},{"x":3,"y":5,"z":-1},{"x":4,"y":5,"z":-1},{"x":4,"y":6,"z":-1},{"x":5,"y":6,"z":-1},{"x":5,"y":6,"z":-2},{"x":6,"y":6,"z":-2},{"x":6,"y":7,"z":-2},{"x":7,"y":7,"z":-2},{"x":7,"y":8,"z":-2},{"x":7,"y":8,"z":-3},{"x":8,"y":8,"z":-3},{"x":8,"y":9,"z":-3},{"x":9,"y":9,"z":-3},{"x":9,"y":10,"z":-3},{"x":10,"y":10,"z":-3},{"x":10,"y":10,"z":-4},{"x":10,"y":11,"z":-4},{"x":11,"y":11,"z":-4},{"x":12,"y":11,"z":-4},{"x":12,"y":12,"z":-4},{"x":12,"y":12,"z":-5},{"x":13,"y":12,"z":-5},{"x":13,"y":13,"z":-5},{"x":14,"y":13,"z":-5},{"x":14,"y":14,"z":-5},{"x":15,"y":14,"z":-5},{"x":15,"y":14,"z":-6},{"x":15,"y":15,"z":-6},{"x":16,"y":15,"z":-6},{"x":17,"y":15,"z":-6},{"x":17,"y":16,"z":-6},{"x":17,"y":16,"z":-7},{"x":2,"y":0,"z":-3},{"x":-1,"y":2,"z":0},{"x":-2,"y":2,"z":0},{"x":-2,"y":2,"z":-1},{"x":-2,"y":3,"z":-1},{"x":-3,"y":3,"z":-1},{"x":-3,"y":4,"z":-1},{"x":-3,"y":4,"z":-2},{"x":-4,"y":4,"z":-2},{"x":-5,"y":4,"z":-2},{"x":-5,"y":5,"z":-2},{"x":-5,"y":5,"z":-3},{"x":-6,"y":5,"z":-3},{"x":-7,"y":5,"z":-3},{"x":-7,"y":6,"z":-3},{"x":-7,"y":6,"z":-4},{"x":-8,"y":6,"z":-4},{"x":-8,"y":7,"z":-4},{"x":-9,"y":7,"z":-4},{"x":-9,"y":7,"z":-5},{"x":-10,"y":7,"z":-5},{"x":-10,"y":8,"z":-5},{"x":-10,"y":8,"z":-6},{"x":-11,"y":8,"z":-6},{"x":-11,"y":9,"z":-6},{"x":-12,"y":9,"z":-6},{"x":-12,"y":9,"z":-7},{"x":-13,"y":9,"z":-7},{"x":-13,"y":10,"z":-7},{"x":-14,"y":10,"z":-7},{"x":-14,"y":10,"z":-8},{"x":-15,"y":10,"z":-8},{"x":-15,"y":11,"z":-8},{"x":-16,"y":11,"z":-8},{"x":-16,"y":11,"z":-9},{"x":-16,"y":12,"z":-9}] -------------------------------------------------------------------------------- /Json/myTree.json: -------------------------------------------------------------------------------- 1 | [{"x":6,"y":0,"z":6,"t":1},{"x":7,"y":0,"z":6,"t":1},{"x":7,"y":0,"z":7,"t":1},{"x":6,"y":0,"z":7,"t":1},{"x":6,"y":0,"z":8,"t":1},{"x":7,"y":0,"z":8,"t":1},{"x":7,"y":1,"z":8,"t":1},{"x":7,"y":2,"z":8,"t":1},{"x":6,"y":1,"z":8,"t":1},{"x":7,"y":0,"z":9,"t":1},{"x":7,"y":1,"z":9,"t":1},{"x":6,"y":0,"z":9,"t":1},{"x":8,"y":0,"z":9,"t":1},{"x":8,"y":1,"z":9,"t":1},{"x":8,"y":0,"z":8,"t":1},{"x":8,"y":0,"z":7,"t":1},{"x":7,"y":1,"z":7,"t":1},{"x":3,"y":0,"z":-3,"t":1},{"x":3,"y":0,"z":-5,"t":1},{"x":3,"y":0,"z":-4,"t":1},{"x":4,"y":0,"z":-3,"t":1},{"x":4,"y":1,"z":-3,"t":1},{"x":6,"y":0,"z":-5,"t":1},{"x":5,"y":0,"z":-7,"t":1},{"x":1,"y":0,"z":-7,"t":1},{"x":-1,"y":0,"z":-7,"t":1},{"x":-5,"y":0,"z":-3,"t":1},{"x":-3,"y":0,"z":-2,"t":1},{"x":-3,"y":0,"z":-6,"t":1},{"x":-4,"y":0,"z":-8,"t":1},{"x":-8,"y":0,"z":-3,"t":1},{"x":-5,"y":0,"z":7,"t":1},{"x":1,"y":0,"z":5,"t":1},{"x":0,"y":0,"z":4,"t":1},{"x":-1,"y":0,"z":7,"t":1},{"x":2,"y":0,"z":7,"t":1},{"x":3,"y":0,"z":0,"t":2},{"x":3,"y":1,"z":0,"t":2},{"x":3,"y":2,"z":0,"t":2},{"x":3,"y":3,"z":0,"t":2},{"x":3,"y":4,"z":0,"t":2},{"x":3,"y":5,"z":0,"t":2},{"x":2,"y":5,"z":0,"t":1},{"x":2,"y":4,"z":0,"t":1},{"x":3,"y":4,"z":1,"t":1},{"x":3,"y":5,"z":1,"t":1},{"x":4,"y":5,"z":0,"t":1},{"x":4,"y":4,"z":0,"t":1},{"x":3,"y":5,"z":-1,"t":1},{"x":3,"y":4,"z":-1,"t":1},{"x":3,"y":6,"z":0,"t":1}] -------------------------------------------------------------------------------- /Json/smiley face.json: -------------------------------------------------------------------------------- 1 | [{"x":9,"y":0,"z":1},{"x":9,"y":1,"z":1},{"x":9,"y":2,"z":1},{"x":9,"y":3,"z":1},{"x":9,"y":4,"z":1},{"x":9,"y":5,"z":1},{"x":9,"y":6,"z":1},{"x":9,"y":7,"z":1},{"x":9,"y":8,"z":1},{"x":9,"y":9,"z":1},{"x":9,"y":10,"z":1},{"x":9,"y":11,"z":1},{"x":0,"y":0,"z":-10},{"x":0,"y":1,"z":-10},{"x":0,"y":2,"z":-10},{"x":0,"y":3,"z":-10},{"x":0,"y":4,"z":-10},{"x":0,"y":5,"z":-10},{"x":0,"y":6,"z":-10},{"x":0,"y":7,"z":-10},{"x":0,"y":8,"z":-10},{"x":0,"y":9,"z":-10},{"x":0,"y":10,"z":-10},{"x":0,"y":11,"z":-10},{"x":-10,"y":0,"z":0},{"x":-10,"y":1,"z":0},{"x":-10,"y":2,"z":0},{"x":-10,"y":3,"z":0},{"x":-10,"y":4,"z":0},{"x":-10,"y":5,"z":0},{"x":-10,"y":6,"z":0},{"x":-10,"y":7,"z":0},{"x":-10,"y":8,"z":0},{"x":-10,"y":9,"z":0},{"x":-1,"y":0,"z":9},{"x":-1,"y":1,"z":9},{"x":-1,"y":2,"z":9},{"x":-1,"y":3,"z":9},{"x":-1,"y":4,"z":9},{"x":-1,"y":5,"z":9},{"x":-1,"y":6,"z":9},{"x":-1,"y":7,"z":9},{"x":-1,"y":8,"z":9},{"x":-1,"y":9,"z":9},{"x":-1,"y":10,"z":9},{"x":-1,"y":11,"z":9},{"x":-1,"y":12,"z":9},{"x":-1,"y":13,"z":9},{"x":-1,"y":0,"z":0},{"x":0,"y":0,"z":0},{"x":0,"y":1,"z":0},{"x":-2,"y":0,"z":0},{"x":-2,"y":1,"z":0},{"x":0,"y":5,"z":0},{"x":-2,"y":5,"z":0}] -------------------------------------------------------------------------------- /Json/stairs.json: -------------------------------------------------------------------------------- 1 | [{"x":5,"y":0,"z":4,"t":0},{"x":6,"y":0,"z":4,"t":0},{"x":5,"y":0,"z":5,"t":0},{"x":6,"y":0,"z":5,"t":0},{"x":5,"y":0,"z":6,"t":0},{"x":6,"y":0,"z":6,"t":0},{"x":5,"y":0,"z":7,"t":0},{"x":6,"y":0,"z":7,"t":0},{"x":5,"y":1,"z":6,"t":0},{"x":6,"y":1,"z":6,"t":0},{"x":5,"y":1,"z":7,"t":0},{"x":6,"y":1,"z":7,"t":0},{"x":5,"y":2,"z":7,"t":0},{"x":6,"y":2,"z":7,"t":0},{"x":-1,"y":0,"z":2,"t":0},{"x":6,"y":3,"z":7,"t":0},{"x":6,"y":3,"z":8,"t":0},{"x":6,"y":4,"z":8,"t":0},{"x":6,"y":4,"z":9,"t":0},{"x":6,"y":5,"z":9,"t":0},{"x":6,"y":5,"z":10,"t":0},{"x":6,"y":6,"z":10,"t":0},{"x":6,"y":6,"z":11,"t":0},{"x":6,"y":7,"z":11,"t":0},{"x":6,"y":7,"z":12,"t":0},{"x":6,"y":8,"z":12,"t":0},{"x":6,"y":8,"z":13,"t":0},{"x":6,"y":9,"z":13,"t":0},{"x":6,"y":9,"z":14,"t":0},{"x":6,"y":10,"z":14,"t":0},{"x":6,"y":10,"z":15,"t":0},{"x":6,"y":11,"z":15,"t":0},{"x":-4,"y":0,"z":6,"t":0},{"x":8,"y":0,"z":1,"t":0},{"x":8,"y":0,"z":0,"t":0},{"x":8,"y":1,"z":0,"t":0},{"x":8,"y":1,"z":1,"t":0},{"x":8,"y":2,"z":1,"t":0},{"x":8,"y":2,"z":0,"t":0},{"x":8,"y":3,"z":1,"t":0},{"x":8,"y":3,"z":0,"t":0},{"x":8,"y":4,"z":1,"t":0},{"x":8,"y":4,"z":0,"t":0},{"x":8,"y":5,"z":1,"t":0},{"x":8,"y":5,"z":0,"t":0},{"x":8,"y":6,"z":1,"t":0},{"x":8,"y":6,"z":0,"t":0},{"x":8,"y":7,"z":1,"t":0},{"x":8,"y":7,"z":0,"t":0},{"x":8,"y":8,"z":1,"t":0},{"x":8,"y":8,"z":0,"t":0},{"x":8,"y":9,"z":1,"t":0},{"x":8,"y":9,"z":0,"t":0},{"x":9,"y":0,"z":0,"t":0},{"x":9,"y":0,"z":1,"t":0},{"x":8,"y":0,"z":-1,"t":0},{"x":9,"y":0,"z":-1,"t":0},{"x":7,"y":0,"z":-1,"t":0},{"x":7,"y":0,"z":0,"t":0},{"x":7,"y":0,"z":1,"t":0},{"x":7,"y":0,"z":2,"t":0},{"x":8,"y":0,"z":2,"t":0},{"x":9,"y":0,"z":2,"t":0},{"x":7,"y":1,"z":1,"t":0},{"x":7,"y":1,"z":0,"t":0},{"x":9,"y":1,"z":0,"t":0},{"x":9,"y":1,"z":1,"t":0},{"x":10,"y":0,"z":0,"t":0},{"x":10,"y":0,"z":1,"t":0},{"x":6,"y":0,"z":0,"t":0},{"x":6,"y":0,"z":1,"t":0},{"x":-1,"y":0,"z":-7,"t":4}] -------------------------------------------------------------------------------- /Json/static.json: -------------------------------------------------------------------------------- 1 | [{"x":-2,"y":0,"z":28,"t":4,"static":true},{"x":-8,"y":0,"z":25,"t":2,"static":true},{"x":-8,"y":1,"z":25,"t":2,"static":true},{"x":-8,"y":2,"z":25,"t":2,"static":true},{"x":-8,"y":3,"z":25,"t":2,"static":true},{"x":-8,"y":4,"z":25,"t":2,"static":true},{"x":-8,"y":4,"z":26,"t":1,"static":true},{"x":-8,"y":5,"z":25,"t":2,"static":true},{"x":-8,"y":5,"z":26,"t":1,"static":true},{"x":-7,"y":4,"z":25,"t":1,"static":true},{"x":-7,"y":5,"z":25,"t":1,"static":true},{"x":-9,"y":5,"z":25,"t":1,"static":true},{"x":-9,"y":4,"z":25,"t":1,"static":true},{"x":-8,"y":5,"z":24,"t":1,"static":true},{"x":-8,"y":4,"z":24,"t":1,"static":true},{"x":-8,"y":6,"z":25,"t":1,"static":true},{"x":3,"y":0,"z":25,"t":2,"static":true},{"x":3,"y":1,"z":25,"t":2,"static":true},{"x":3,"y":2,"z":25,"t":2,"static":true},{"x":3,"y":3,"z":25,"t":2,"static":true},{"x":3,"y":4,"z":25,"t":2,"static":true},{"x":3,"y":5,"z":25,"t":2,"static":true},{"x":3,"y":4,"z":26,"t":1,"static":true},{"x":3,"y":5,"z":26,"t":1,"static":true},{"x":3,"y":6,"z":25,"t":1,"static":true},{"x":4,"y":4,"z":25,"t":1,"static":true},{"x":4,"y":5,"z":25,"t":1,"static":true},{"x":3,"y":5,"z":24,"t":1,"static":true},{"x":3,"y":4,"z":24,"t":1,"static":true},{"x":2,"y":5,"z":25,"t":1,"static":true},{"x":2,"y":4,"z":25,"t":1,"static":true},{"x":-5,"y":0,"z":22,"t":3,"static":true},{"x":-4,"y":0,"z":22,"t":3,"static":true},{"x":-3,"y":0,"z":22,"t":3,"static":true},{"x":-2,"y":0,"z":22,"t":3,"static":true},{"x":-1,"y":0,"z":22,"t":3,"static":true},{"x":0,"y":0,"z":22,"t":3,"static":true},{"x":-5,"y":1,"z":21,"t":3,"static":true},{"x":-4,"y":1,"z":21,"t":3,"static":true},{"x":-3,"y":1,"z":21,"t":3,"static":true},{"x":-2,"y":1,"z":21,"t":3,"static":true},{"x":-1,"y":1,"z":21,"t":3,"static":true},{"x":0,"y":1,"z":21,"t":3,"static":true},{"x":-5,"y":2,"z":20,"t":3,"static":true},{"x":-4,"y":2,"z":20,"t":3,"static":true},{"x":-3,"y":2,"z":20,"t":3,"static":true},{"x":-2,"y":2,"z":20,"t":3,"static":true},{"x":-1,"y":2,"z":20,"t":3,"static":true},{"x":0,"y":2,"z":20,"t":3,"static":true},{"x":0,"y":3,"z":19,"t":3,"static":true},{"x":-1,"y":3,"z":19,"t":3,"static":true},{"x":-2,"y":3,"z":19,"t":3,"static":true},{"x":-3,"y":3,"z":19,"t":3,"static":true},{"x":-4,"y":3,"z":19,"t":3,"static":true},{"x":-5,"y":3,"z":19,"t":3,"static":true},{"x":0,"y":3,"z":18,"t":2,"static":true},{"x":-1,"y":3,"z":18,"t":2,"static":true},{"x":-2,"y":3,"z":18,"t":2,"static":true},{"x":-3,"y":3,"z":18,"t":2,"static":true},{"x":-4,"y":3,"z":18,"t":2,"static":true},{"x":-5,"y":3,"z":18,"t":2,"static":true},{"x":0,"y":3,"z":17,"t":2,"static":true},{"x":-1,"y":3,"z":17,"t":2,"static":true},{"x":-2,"y":3,"z":17,"t":2,"static":true},{"x":-3,"y":3,"z":17,"t":2,"static":true},{"x":-4,"y":3,"z":17,"t":2,"static":true},{"x":-5,"y":3,"z":17,"t":2,"static":true},{"x":0,"y":3,"z":16,"t":2,"static":true},{"x":-1,"y":3,"z":16,"t":2,"static":true},{"x":-2,"y":3,"z":16,"t":2,"static":true},{"x":-3,"y":3,"z":16,"t":2,"static":true},{"x":-4,"y":3,"z":16,"t":2,"static":true},{"x":-5,"y":3,"z":16,"t":2,"static":true},{"x":0,"y":3,"z":15,"t":2,"static":true},{"x":-1,"y":3,"z":15,"t":2,"static":true},{"x":-2,"y":3,"z":15,"t":2,"static":true},{"x":-3,"y":3,"z":15,"t":2,"static":true},{"x":-4,"y":3,"z":15,"t":2,"static":true},{"x":-5,"y":3,"z":15,"t":2,"static":true},{"x":0,"y":3,"z":14,"t":2,"static":true},{"x":-1,"y":3,"z":14,"t":2,"static":true},{"x":-2,"y":3,"z":14,"t":2,"static":true},{"x":-3,"y":3,"z":14,"t":2,"static":true},{"x":-4,"y":3,"z":14,"t":2,"static":true},{"x":-5,"y":3,"z":14,"t":2,"static":true},{"x":-30,"y":0,"z":13,"t":0,"static":true},{"x":-2,"y":4,"z":15,"t":0,"static":false},{"x":-2,"y":5,"z":15,"t":0,"static":false},{"x":-2,"y":6,"z":15,"t":0,"static":false},{"x":-2,"y":7,"z":15,"t":0,"static":false},{"x":-2,"y":7,"z":14,"t":0,"static":false},{"x":-2,"y":7,"z":13,"t":0,"static":false},{"x":-2,"y":7,"z":12,"t":0,"static":false},{"x":-2,"y":7,"z":11,"t":0,"static":false},{"x":-2,"y":8,"z":13,"t":0,"static":false},{"x":-2,"y":9,"z":13,"t":0,"static":false},{"x":-2,"y":9,"z":12,"t":0,"static":false},{"x":-2,"y":9,"z":11,"t":0,"static":false},{"x":-2,"y":8,"z":15,"t":0,"static":false},{"x":-2,"y":9,"z":15,"t":0,"static":false},{"x":-2,"y":9,"z":14,"t":0,"static":false},{"x":-2,"y":8,"z":11,"t":0,"static":false}] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 3d-Level-Editor 2 | 3 | 3D level editor based on mrDoob's [voxel painter] (https://github.com/mrdoob/three.js/blob/master/examples/webgl_interactive_voxelpainter.html) 4 | 5 | To play, run mongoose-free, open local server in chrome, and click level_editor.html 6 | 7 | Click to Place/remove blocks. Use dynamic controls to change blocktype, in-game physics, and map size. 8 | 9 | Export maps to JSON. Click n drag JSON to import. 10 | 11 | ![image](https://github.com/drealnn/3d-Level-Editor/blob/master/images/Untitled.png) 12 | 13 | 14 |

15 | 16 | 17 |

18 | 19 | -------------------------------------------------------------------------------- /bluefreeze.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/bluefreeze.zip -------------------------------------------------------------------------------- /bluefreeze/bluefreeze/Note.txt: -------------------------------------------------------------------------------- 1 | This skybox is free for use but can't be sold for profit or altered in any way. 2 | 3 | Included in this zip floder are the zipped skybox and textures. Add the zipped skybox to your models directory and the textures to you textures directory of your OP. Go to your world and click on Options/World/Features. Now click on Sky and add the name of the skybox in Skybox without the zip. Click apply and OK. Your new skybox should start to download. -------------------------------------------------------------------------------- /bluefreeze/bluefreeze/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/bluefreeze/bluefreeze/back.jpg -------------------------------------------------------------------------------- /bluefreeze/bluefreeze/bluefreeze.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/bluefreeze/bluefreeze/bluefreeze.zip -------------------------------------------------------------------------------- /bluefreeze/bluefreeze/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/bluefreeze/bluefreeze/front.jpg -------------------------------------------------------------------------------- /bluefreeze/bluefreeze/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/bluefreeze/bluefreeze/left.jpg -------------------------------------------------------------------------------- /bluefreeze/bluefreeze/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/bluefreeze/bluefreeze/right.jpg -------------------------------------------------------------------------------- /bluefreeze/bluefreeze/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/bluefreeze/bluefreeze/top.jpg -------------------------------------------------------------------------------- /calm.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/calm.zip -------------------------------------------------------------------------------- /calm/calm/Note.txt: -------------------------------------------------------------------------------- 1 | This skybox is free for use but can't be sold for profit or altered in any way. 2 | 3 | Included in this zip floder are the zipped skybox and textures. Add the zipped skybox to your models directory and the textures to you textures directory of your OP. Go to your world and click on Options/World/Features. Now click on Sky and add the name of the skybox in Skybox without the zip. Click apply and OK. Your new skybox should start to download. -------------------------------------------------------------------------------- /calm/calm/calm.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/calm/calm/calm.zip -------------------------------------------------------------------------------- /calm/calm/calm_back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/calm/calm/calm_back.jpg -------------------------------------------------------------------------------- /calm/calm/calm_front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/calm/calm/calm_front.jpg -------------------------------------------------------------------------------- /calm/calm/calm_left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/calm/calm/calm_left.jpg -------------------------------------------------------------------------------- /calm/calm/calm_right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/calm/calm/calm_right.jpg -------------------------------------------------------------------------------- /calm/calm/calm_top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/calm/calm/calm_top.jpg -------------------------------------------------------------------------------- /city.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/city.zip -------------------------------------------------------------------------------- /city/city/Note.txt: -------------------------------------------------------------------------------- 1 | This skybox is free for use but can't be sold for profit or altered in any way. 2 | 3 | Included in this zip floder are the zipped skybox and textures. Add the zipped skybox to your models directory and the textures to you textures directory of your OP. Go to your world and click on Options/World/Features. Now click on Sky and add the name of the skybox in Skybox without the zip. Click apply and OK. Your new skybox should start to download. -------------------------------------------------------------------------------- /city/city/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/city/city/back.jpg -------------------------------------------------------------------------------- /city/city/city.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/city/city/city.zip -------------------------------------------------------------------------------- /city/city/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/city/city/front.jpg -------------------------------------------------------------------------------- /city/city/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/city/city/left.jpg -------------------------------------------------------------------------------- /city/city/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/city/city/right.jpg -------------------------------------------------------------------------------- /city/city/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/city/city/top.jpg -------------------------------------------------------------------------------- /comawhite.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/comawhite.zip -------------------------------------------------------------------------------- /comawhite/comawhite/Note.txt: -------------------------------------------------------------------------------- 1 | This skybox is free for use but can't be sold for profit or altered in any way. 2 | 3 | Included in this zip floder are the zipped skybox and textures. Add the zipped skybox to your models directory and the textures to you textures directory of your OP. Go to your world and click on Options/World/Features. Now click on Sky and add the name of the skybox in Skybox without the zip. Click apply and OK. Your new skybox should start to download. -------------------------------------------------------------------------------- /comawhite/comawhite/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/comawhite/comawhite/back.jpg -------------------------------------------------------------------------------- /comawhite/comawhite/comawhite.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/comawhite/comawhite/comawhite.zip -------------------------------------------------------------------------------- /comawhite/comawhite/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/comawhite/comawhite/front.jpg -------------------------------------------------------------------------------- /comawhite/comawhite/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/comawhite/comawhite/left.jpg -------------------------------------------------------------------------------- /comawhite/comawhite/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/comawhite/comawhite/right.jpg -------------------------------------------------------------------------------- /comawhite/comawhite/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/comawhite/comawhite/top.jpg -------------------------------------------------------------------------------- /darkland.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/darkland.zip -------------------------------------------------------------------------------- /darkland/darkland/Note.txt: -------------------------------------------------------------------------------- 1 | This skybox is free for use but can't be sold for profit or altered in any way. 2 | 3 | Included in this zip floder are the zipped skybox and textures. Add the zipped skybox to your models directory and the textures to you textures directory of your OP. Go to your world and click on Options/World/Features. Now click on Sky and add the name of the skybox in Skybox without the zip. Click apply and OK. Your new skybox should start to download. -------------------------------------------------------------------------------- /darkland/darkland/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/darkland/darkland/back.jpg -------------------------------------------------------------------------------- /darkland/darkland/darkland.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/darkland/darkland/darkland.zip -------------------------------------------------------------------------------- /darkland/darkland/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/darkland/darkland/front.jpg -------------------------------------------------------------------------------- /darkland/darkland/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/darkland/darkland/left.jpg -------------------------------------------------------------------------------- /darkland/darkland/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/darkland/darkland/right.jpg -------------------------------------------------------------------------------- /darkland/darkland/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/darkland/darkland/top.jpg -------------------------------------------------------------------------------- /images/Untitled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/Untitled.png -------------------------------------------------------------------------------- /images/first_person_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/first_person_view.png -------------------------------------------------------------------------------- /images/floor-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/floor-1.jpg -------------------------------------------------------------------------------- /images/ground.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/ground.jpg -------------------------------------------------------------------------------- /images/physics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/physics.png -------------------------------------------------------------------------------- /images/physics2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/physics2.png -------------------------------------------------------------------------------- /images/stone - Copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/stone - Copy.png -------------------------------------------------------------------------------- /images/stone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/stone.png -------------------------------------------------------------------------------- /images/wall-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/wall-1.jpg -------------------------------------------------------------------------------- /images/wall-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/wall-2.jpg -------------------------------------------------------------------------------- /images/wood.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/images/wood.jpg -------------------------------------------------------------------------------- /js/AnimationClipCreator.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Creator of typical test AnimationClips / KeyframeTracks 4 | * 5 | * @author Ben Houston / http://clara.io/ 6 | * @author David Sarno / http://lighthaus.us/ 7 | */ 8 | 9 | THREE.AnimationClipCreator = function() { 10 | }; 11 | 12 | THREE.AnimationClipCreator.CreateRotationAnimation = function( period, axis ) { 13 | 14 | var keys = []; 15 | keys.push( { time: 0, value: 0 } ); 16 | keys.push( { time: period, value: 360 } ); 17 | 18 | axis = axis || 'x'; 19 | var trackName = '.rotation[' + axis + ']'; 20 | 21 | var track = new THREE.NumberKeyframeTrack( trackName, keys ); 22 | 23 | var clip = new THREE.AnimationClip( 'rotate.x', 10, [ track ] ); 24 | //console.log( 'rotateClip', clip ); 25 | 26 | return clip; 27 | }; 28 | 29 | THREE.AnimationClipCreator.CreateScaleAxisAnimation = function( period, axis ) { 30 | 31 | var keys = []; 32 | keys.push( { time: 0, value: 0 } ); 33 | keys.push( { time: period, value: 360 } ); 34 | 35 | axis = axis || 'x'; 36 | var trackName = '.scale[' + axis + ']'; 37 | 38 | var track = new THREE.NumberKeyframeTrack( trackName, keys ); 39 | 40 | var clip = new THREE.AnimationClip( 'scale.x', 10, [ track ] ); 41 | //console.log( 'scaleClip', clip ); 42 | 43 | return clip; 44 | }; 45 | 46 | THREE.AnimationClipCreator.CreateShakeAnimation = function( duration, shakeScale ) { 47 | 48 | var keys = []; 49 | 50 | for( var i = 0; i < duration * 10; i ++ ) { 51 | 52 | keys.push( { 53 | time: ( i / 10.0 ), 54 | value: new THREE.Vector3( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).multiply( shakeScale ) 55 | } ); 56 | 57 | } 58 | 59 | var trackName = '.position'; 60 | 61 | var track = new THREE.VectorKeyframeTrack( trackName, keys ); 62 | 63 | var clip = new THREE.AnimationClip( 'shake' + duration, duration, [ track ] ); 64 | //console.log( 'shakeClip', clip ); 65 | 66 | return clip; 67 | }; 68 | 69 | 70 | THREE.AnimationClipCreator.CreatePulsationAnimation = function( duration, pulseScale ) { 71 | 72 | var keys = []; 73 | 74 | for( var i = 0; i < duration * 10; i ++ ) { 75 | 76 | var scaleFactor = Math.random() * pulseScale; 77 | keys.push( { 78 | time: ( i / 10.0 ), 79 | value: new THREE.Vector3( scaleFactor, scaleFactor, scaleFactor ) 80 | } ); 81 | 82 | } 83 | 84 | var trackName = '.scale'; 85 | 86 | var track = new THREE.VectorKeyframeTrack( trackName, keys ); 87 | 88 | var clip = new THREE.AnimationClip( 'scale' + duration, duration, [ track ] ); 89 | //console.log( 'scaleClip', clip ); 90 | 91 | return clip; 92 | }; 93 | 94 | 95 | THREE.AnimationClipCreator.CreateVisibilityAnimation = function( duration ) { 96 | 97 | var keys = []; 98 | keys.push( { 99 | time: 0, 100 | value: true 101 | } ); 102 | keys.push( { 103 | time: duration - 1, 104 | value: false 105 | } ); 106 | keys.push( { 107 | time: duration, 108 | value: true 109 | } ); 110 | 111 | var trackName = '.visible'; 112 | 113 | var track = new THREE.BooleanKeyframeTrack( trackName, keys ); 114 | 115 | var clip = new THREE.AnimationClip( 'visible' + duration, duration, [ track ] ); 116 | //console.log( 'scaleClip', clip ); 117 | 118 | return clip; 119 | }; 120 | 121 | 122 | THREE.AnimationClipCreator.CreateMaterialColorAnimation = function( duration, colors, loop ) { 123 | 124 | var timeStep = duration / colors.length; 125 | var keys = []; 126 | for( var i = 0; i <= colors.length; i ++ ) { 127 | keys.push( { time: i * timeStep, value: colors[ i % colors.length ] } ); 128 | } 129 | 130 | var trackName = '.material[0].color'; 131 | 132 | var track = new THREE.ColorKeyframeTrack( trackName, keys ); 133 | 134 | var clip = new THREE.AnimationClip( 'colorDiffuse', 10, [ track ] ); 135 | //console.log( 'diffuseClip', clip ); 136 | 137 | return clip; 138 | }; 139 | 140 | -------------------------------------------------------------------------------- /js/BlendCharacter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Michael Guerrero / http://realitymeltdown.com 3 | */ 4 | 5 | THREE.BlendCharacter = function () { 6 | 7 | this.animations = {}; 8 | this.weightSchedule = []; 9 | this.warpSchedule = []; 10 | 11 | this.load = function ( url, onLoad ) { 12 | 13 | var scope = this; 14 | 15 | var loader = new THREE.JSONLoader(); 16 | loader.load( url, function( geometry, materials ) { 17 | 18 | var originalMaterial = materials[ 0 ]; 19 | originalMaterial.skinning = true; 20 | 21 | THREE.SkinnedMesh.call( scope, geometry, originalMaterial ); 22 | 23 | scope.mixer = new THREE.AnimationMixer( scope ); 24 | 25 | // Create the animations 26 | for ( var i = 0; i < geometry.animations.length; ++ i ) { 27 | 28 | var animName = geometry.animations[ i ].name; 29 | scope.animations[ animName ] = geometry.animations[ i ]; 30 | 31 | } 32 | 33 | // Loading is complete, fire the callback 34 | if ( onLoad !== undefined ) onLoad(); 35 | 36 | } ); 37 | 38 | }; 39 | 40 | this.update = function( dt ) { 41 | 42 | this.mixer.update( dt ); 43 | 44 | }; 45 | 46 | this.play = function( animName, weight ) { 47 | 48 | this.mixer.removeAllActions(); 49 | 50 | this.mixer.play( new THREE.AnimationAction( this.animations[ animName ] ) ); 51 | 52 | }; 53 | 54 | this.crossfade = function( fromAnimName, toAnimName, duration ) { 55 | 56 | this.mixer.removeAllActions(); 57 | 58 | var fromAction = new THREE.AnimationAction( this.animations[ fromAnimName ] ); 59 | var toAction = new THREE.AnimationAction( this.animations[ toAnimName ] ); 60 | 61 | this.mixer.play( fromAction ); 62 | this.mixer.play( toAction ); 63 | 64 | this.mixer.crossFade( fromAction, toAction, duration, false ); 65 | 66 | }; 67 | 68 | this.warp = function( fromAnimName, toAnimName, duration ) { 69 | 70 | this.mixer.removeAllActions(); 71 | 72 | var fromAction = new THREE.AnimationAction( this.animations[ fromAnimName ] ); 73 | var toAction = new THREE.AnimationAction( this.animations[ toAnimName ] ); 74 | 75 | this.mixer.play( fromAction ); 76 | this.mixer.play( toAction ); 77 | 78 | this.mixer.crossFade( fromAction, toAction, duration, true ); 79 | 80 | }; 81 | 82 | this.applyWeight = function( animName, weight ) { 83 | 84 | var action = this.mixer.findActionByName( animName ); 85 | if( action ) { 86 | action.weight = weight; 87 | } 88 | 89 | }; 90 | 91 | this.pauseAll = function() { 92 | 93 | this.mixer.timeScale = 0; 94 | 95 | }; 96 | 97 | this.unPauseAll = function() { 98 | 99 | this.mixer.timeScale = 1; 100 | 101 | }; 102 | 103 | 104 | this.stopAll = function() { 105 | 106 | this.mixer.removeAllActions(); 107 | 108 | }; 109 | 110 | this.showModel = function( boolean ) { 111 | 112 | this.visible = boolean; 113 | 114 | } 115 | 116 | }; 117 | 118 | 119 | THREE.BlendCharacter.prototype = Object.create( THREE.SkinnedMesh.prototype ); 120 | THREE.BlendCharacter.prototype.constructor = THREE.BlendCharacter; 121 | 122 | THREE.BlendCharacter.prototype.getForward = function() { 123 | 124 | var forward = new THREE.Vector3(); 125 | 126 | return function() { 127 | 128 | // pull the character's forward basis vector out of the matrix 129 | forward.set( 130 | - this.matrix.elements[ 8 ], 131 | - this.matrix.elements[ 9 ], 132 | - this.matrix.elements[ 10 ] 133 | ); 134 | 135 | return forward; 136 | 137 | } 138 | 139 | }; 140 | 141 | -------------------------------------------------------------------------------- /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 () { 10 | 11 | try { 12 | 13 | var canvas = document.createElement( 'canvas' ); return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) ); 14 | 15 | } catch ( e ) { 16 | 17 | return false; 18 | 19 | } 20 | 21 | } )(), 22 | workers: !! window.Worker, 23 | fileapi: window.File && window.FileReader && window.FileList && window.Blob, 24 | 25 | getWebGLErrorMessage: function () { 26 | 27 | var element = document.createElement( 'div' ); 28 | element.id = 'webgl-error-message'; 29 | element.style.fontFamily = 'monospace'; 30 | element.style.fontSize = '13px'; 31 | element.style.fontWeight = 'normal'; 32 | element.style.textAlign = 'center'; 33 | element.style.background = '#fff'; 34 | element.style.color = '#000'; 35 | element.style.padding = '1.5em'; 36 | element.style.width = '400px'; 37 | element.style.margin = '5em auto 0'; 38 | 39 | if ( ! this.webgl ) { 40 | 41 | element.innerHTML = window.WebGLRenderingContext ? [ 42 | 'Your graphics card does not seem to support WebGL.
', 43 | 'Find out how to get it here.' 44 | ].join( '\n' ) : [ 45 | 'Your browser does not seem to support WebGL.
', 46 | 'Find out how to get it here.' 47 | ].join( '\n' ); 48 | 49 | } 50 | 51 | return element; 52 | 53 | }, 54 | 55 | addGetWebGLMessage: function ( parameters ) { 56 | 57 | var parent, id, element; 58 | 59 | parameters = parameters || {}; 60 | 61 | parent = parameters.parent !== undefined ? parameters.parent : document.body; 62 | id = parameters.id !== undefined ? parameters.id : 'oldie'; 63 | 64 | element = Detector.getWebGLErrorMessage(); 65 | element.id = id; 66 | 67 | parent.appendChild( element ); 68 | 69 | } 70 | 71 | }; 72 | 73 | // browserify support 74 | if ( typeof module === 'object' ) { 75 | 76 | module.exports = Detector; 77 | 78 | } 79 | -------------------------------------------------------------------------------- /js/Gyroscope.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.Gyroscope = function () { 6 | 7 | THREE.Object3D.call( this ); 8 | 9 | }; 10 | 11 | THREE.Gyroscope.prototype = Object.create( THREE.Object3D.prototype ); 12 | THREE.Gyroscope.prototype.constructor = THREE.Gyroscope; 13 | 14 | THREE.Gyroscope.prototype.updateMatrixWorld = ( function () { 15 | 16 | var translationObject = new THREE.Vector3(); 17 | var quaternionObject = new THREE.Quaternion(); 18 | var scaleObject = new THREE.Vector3(); 19 | 20 | var translationWorld = new THREE.Vector3(); 21 | var quaternionWorld = new THREE.Quaternion(); 22 | var scaleWorld = new THREE.Vector3(); 23 | 24 | return function updateMatrixWorld( force ) { 25 | 26 | this.matrixAutoUpdate && this.updateMatrix(); 27 | 28 | // update matrixWorld 29 | 30 | if ( this.matrixWorldNeedsUpdate || force ) { 31 | 32 | if ( this.parent !== null ) { 33 | 34 | this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); 35 | 36 | this.matrixWorld.decompose( translationWorld, quaternionWorld, scaleWorld ); 37 | this.matrix.decompose( translationObject, quaternionObject, scaleObject ); 38 | 39 | this.matrixWorld.compose( translationWorld, quaternionObject, scaleWorld ); 40 | 41 | 42 | } else { 43 | 44 | this.matrixWorld.copy( this.matrix ); 45 | 46 | } 47 | 48 | 49 | this.matrixWorldNeedsUpdate = false; 50 | 51 | force = true; 52 | 53 | } 54 | 55 | // update children 56 | 57 | for ( var i = 0, l = this.children.length; i < l; i ++ ) { 58 | 59 | this.children[ i ].updateMatrixWorld( force ); 60 | 61 | } 62 | 63 | }; 64 | 65 | }() ); 66 | -------------------------------------------------------------------------------- /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/MorphAnimMesh.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | */ 4 | 5 | THREE.MorphAnimMesh = function ( geometry, material ) { 6 | 7 | THREE.Mesh.call( this, geometry, material ); 8 | 9 | this.type = 'MorphAnimMesh'; 10 | 11 | this.mixer = new THREE.AnimationMixer( this ); 12 | this.activeAction = null; 13 | }; 14 | 15 | THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype ); 16 | THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh; 17 | 18 | THREE.MorphAnimMesh.prototype.setDirectionForward = function () { 19 | 20 | this.mixer.timeScale = 1.0; 21 | 22 | }; 23 | 24 | THREE.MorphAnimMesh.prototype.setDirectionBackward = function () { 25 | 26 | this.mixer.timeScale = -1.0; 27 | 28 | }; 29 | 30 | THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) { 31 | 32 | if( this.activeAction ) { 33 | 34 | this.mixer.removeAction( this.activeAction ); 35 | this.activeAction = null; 36 | 37 | } 38 | 39 | var clip = THREE.AnimationClip.findByName( this.geometry.animations, label ); 40 | 41 | if ( clip ) { 42 | 43 | var action = new THREE.AnimationAction( clip ); 44 | action.timeScale = ( clip.tracks.length * fps ) / clip.duration; 45 | this.mixer.addAction( action ); 46 | this.activeAction = action; 47 | 48 | } else { 49 | 50 | throw new Error( 'THREE.MorphAnimMesh: animations[' + label + '] undefined in .playAnimation()' ); 51 | 52 | } 53 | 54 | }; 55 | 56 | THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) { 57 | 58 | this.mixer.update( delta ); 59 | 60 | }; 61 | 62 | THREE.MorphAnimMesh.prototype.copy = function ( source ) { 63 | 64 | THREE.Mesh.prototype.copy.call( this, source ); 65 | 66 | this.mixer = new THREE.AnimationMixer( this ); 67 | 68 | return this; 69 | 70 | }; 71 | -------------------------------------------------------------------------------- /js/MorphAnimation.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com 3 | * @author willy-vvu / http://willy-vvu.github.io 4 | */ 5 | 6 | THREE.MorphAnimation = function ( mesh ) { 7 | 8 | this.mesh = mesh; 9 | this.frames = mesh.morphTargetInfluences.length; 10 | this.currentTime = 0; 11 | this.duration = 1000; 12 | this.loop = true; 13 | this.lastFrame = 0; 14 | this.currentFrame = 0; 15 | 16 | this.isPlaying = false; 17 | 18 | }; 19 | 20 | THREE.MorphAnimation.prototype = { 21 | 22 | constructor: THREE.MorphAnimation, 23 | 24 | play: function () { 25 | 26 | this.isPlaying = true; 27 | 28 | }, 29 | 30 | pause: function () { 31 | 32 | this.isPlaying = false; 33 | 34 | }, 35 | 36 | update: function ( delta ) { 37 | 38 | if ( this.isPlaying === false ) return; 39 | 40 | this.currentTime += delta; 41 | 42 | if ( this.loop === true && this.currentTime > this.duration ) { 43 | 44 | this.currentTime %= this.duration; 45 | 46 | } 47 | 48 | this.currentTime = Math.min( this.currentTime, this.duration ); 49 | 50 | var frameTime = this.duration / this.frames; 51 | var frame = Math.floor( this.currentTime / frameTime ); 52 | 53 | var influences = this.mesh.morphTargetInfluences; 54 | 55 | if ( frame !== this.currentFrame ) { 56 | 57 | influences[ this.lastFrame ] = 0; 58 | influences[ this.currentFrame ] = 1; 59 | influences[ frame ] = 0; 60 | 61 | this.lastFrame = this.currentFrame; 62 | this.currentFrame = frame; 63 | 64 | } 65 | 66 | var mix = ( this.currentTime % frameTime ) / frameTime; 67 | 68 | influences[ frame ] = mix; 69 | influences[ this.lastFrame ] = 1 - mix; 70 | 71 | } 72 | 73 | }; 74 | -------------------------------------------------------------------------------- /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() { 8 | 9 | return ( this.gen() / 2147483647 ); 10 | 11 | }; 12 | this.nextRange = function( min, max ) { 13 | 14 | return min + ( ( max - min ) * this.next() ) 15 | 16 | }; 17 | this.gen = function() { 18 | 19 | return this.seed = ( this.seed * 16807 ) % 2147483647; 20 | 21 | }; 22 | 23 | }; 24 | -------------------------------------------------------------------------------- /js/UCSCharacter.js: -------------------------------------------------------------------------------- 1 | THREE.UCSCharacter = function() { 2 | 3 | var scope = this; 4 | 5 | var mesh; 6 | 7 | this.scale = 1; 8 | 9 | this.root = new THREE.Object3D(); 10 | 11 | this.numSkins; 12 | this.numMorphs; 13 | 14 | this.skins = []; 15 | this.materials = []; 16 | this.morphs = []; 17 | 18 | this.mixer = new THREE.AnimationMixer( this.root ); 19 | 20 | this.onLoadComplete = function () {}; 21 | 22 | this.loadCounter = 0; 23 | 24 | this.loadParts = function ( config ) { 25 | 26 | this.numSkins = config.skins.length; 27 | this.numMorphs = config.morphs.length; 28 | 29 | // Character geometry + number of skins 30 | this.loadCounter = 1 + config.skins.length; 31 | 32 | // SKINS 33 | this.skins = loadTextures( config.baseUrl + "skins/", config.skins ); 34 | this.materials = createMaterials( this.skins ); 35 | 36 | // MORPHS 37 | this.morphs = config.morphs; 38 | 39 | // CHARACTER 40 | var loader = new THREE.JSONLoader(); 41 | console.log( config.baseUrl + config.character ); 42 | loader.load( config.baseUrl + config.character, function( geometry ) { 43 | 44 | geometry.computeBoundingBox(); 45 | geometry.computeVertexNormals(); 46 | 47 | mesh = new THREE.SkinnedMesh( geometry, new THREE.MeshFaceMaterial() ); 48 | mesh.name = config.character; 49 | scope.root.add( mesh ); 50 | 51 | var bb = geometry.boundingBox; 52 | scope.root.scale.set( config.s, config.s, config.s ); 53 | scope.root.position.set( config.x, config.y - bb.min.y * config.s, config.z ); 54 | 55 | mesh.castShadow = true; 56 | mesh.receiveShadow = true; 57 | 58 | scope.mixer.addAction( new THREE.AnimationAction( geometry.animations[0] ).setLocalRoot( mesh ) ); 59 | 60 | scope.setSkin( 0 ); 61 | 62 | scope.checkLoadComplete(); 63 | 64 | } ); 65 | 66 | }; 67 | 68 | this.setSkin = function( index ) { 69 | 70 | if ( mesh && scope.materials ) { 71 | 72 | mesh.material = scope.materials[ index ]; 73 | 74 | } 75 | 76 | }; 77 | 78 | this.updateMorphs = function( influences ) { 79 | 80 | if ( mesh ) { 81 | 82 | for ( var i = 0; i < scope.numMorphs; i ++ ) { 83 | 84 | mesh.morphTargetInfluences[ i ] = influences[ scope.morphs[ i ] ] / 100; 85 | 86 | } 87 | 88 | } 89 | 90 | }; 91 | 92 | function loadTextures( baseUrl, textureUrls ) { 93 | 94 | var mapping = THREE.UVMapping; 95 | var textures = []; 96 | 97 | for ( var i = 0; i < textureUrls.length; i ++ ) { 98 | 99 | textures[ i ] = THREE.ImageUtils.loadTexture( baseUrl + textureUrls[ i ], mapping, scope.checkLoadComplete ); 100 | textures[ i ].name = textureUrls[ i ]; 101 | 102 | } 103 | 104 | return textures; 105 | 106 | } 107 | 108 | function createMaterials( skins ) { 109 | 110 | var materials = []; 111 | 112 | for ( var i = 0; i < skins.length; i ++ ) { 113 | 114 | materials[ i ] = new THREE.MeshLambertMaterial( { 115 | color: 0xeeeeee, 116 | specular: 10.0, 117 | map: skins[ i ], 118 | skinning: true, 119 | morphTargets: true 120 | } ); 121 | 122 | } 123 | 124 | return materials; 125 | 126 | } 127 | 128 | this.checkLoadComplete = function () { 129 | 130 | scope.loadCounter -= 1; 131 | 132 | if ( scope.loadCounter === 0 ) { 133 | 134 | scope.onLoadComplete(); 135 | 136 | } 137 | 138 | } 139 | 140 | }; 141 | -------------------------------------------------------------------------------- /js/controls/DeviceOrientationControls.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author richt / http://richt.me 3 | * @author WestLangley / http://github.com/WestLangley 4 | * 5 | * W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html) 6 | */ 7 | 8 | THREE.DeviceOrientationControls = function ( object ) { 9 | 10 | var scope = this; 11 | 12 | this.object = object; 13 | this.object.rotation.reorder( "YXZ" ); 14 | 15 | this.enabled = true; 16 | 17 | this.deviceOrientation = {}; 18 | this.screenOrientation = 0; 19 | 20 | var onDeviceOrientationChangeEvent = function ( event ) { 21 | 22 | scope.deviceOrientation = event; 23 | 24 | }; 25 | 26 | var onScreenOrientationChangeEvent = function () { 27 | 28 | scope.screenOrientation = window.orientation || 0; 29 | 30 | }; 31 | 32 | // The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y'' 33 | 34 | var setObjectQuaternion = function () { 35 | 36 | var zee = new THREE.Vector3( 0, 0, 1 ); 37 | 38 | var euler = new THREE.Euler(); 39 | 40 | var q0 = new THREE.Quaternion(); 41 | 42 | var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis 43 | 44 | return function ( quaternion, alpha, beta, gamma, orient ) { 45 | 46 | euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us 47 | 48 | quaternion.setFromEuler( euler ); // orient the device 49 | 50 | quaternion.multiply( q1 ); // camera looks out the back of the device, not the top 51 | 52 | quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation 53 | 54 | } 55 | 56 | }(); 57 | 58 | this.connect = function() { 59 | 60 | onScreenOrientationChangeEvent(); // run once on load 61 | 62 | window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent, false ); 63 | window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false ); 64 | 65 | scope.enabled = true; 66 | 67 | }; 68 | 69 | this.disconnect = function() { 70 | 71 | window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent, false ); 72 | window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false ); 73 | 74 | scope.enabled = false; 75 | 76 | }; 77 | 78 | this.update = function () { 79 | 80 | if ( scope.enabled === false ) return; 81 | 82 | var alpha = scope.deviceOrientation.alpha ? THREE.Math.degToRad( scope.deviceOrientation.alpha ) : 0; // Z 83 | var beta = scope.deviceOrientation.beta ? THREE.Math.degToRad( scope.deviceOrientation.beta ) : 0; // X' 84 | var gamma = scope.deviceOrientation.gamma ? THREE.Math.degToRad( scope.deviceOrientation.gamma ) : 0; // Y'' 85 | var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O 86 | 87 | setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient ); 88 | 89 | }; 90 | 91 | this.dispose = function () { 92 | 93 | this.disconnect(); 94 | 95 | }; 96 | 97 | this.connect(); 98 | 99 | }; 100 | -------------------------------------------------------------------------------- /js/controls/MouseControls.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author dmarcos / http://github.com/dmarcos 3 | * 4 | * This controls allow to change the orientation of the camera using the mouse 5 | */ 6 | 7 | THREE.MouseControls = function ( object ) { 8 | 9 | var scope = this; 10 | var PI_2 = Math.PI / 2; 11 | var mouseQuat = { 12 | x: new THREE.Quaternion(), 13 | y: new THREE.Quaternion() 14 | }; 15 | var object = object; 16 | var xVector = new THREE.Vector3( 1, 0, 0 ); 17 | var yVector = new THREE.Vector3( 0, 1, 0 ); 18 | 19 | var onMouseMove = function ( event ) { 20 | 21 | if ( scope.enabled === false ) return; 22 | 23 | var orientation = scope.orientation; 24 | 25 | var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0; 26 | var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0; 27 | 28 | orientation.y += movementX * 0.0025; 29 | orientation.x += movementY * 0.0025; 30 | 31 | orientation.x = Math.max( - PI_2, Math.min( PI_2, orientation.x ) ); 32 | 33 | }; 34 | 35 | this.enabled = true; 36 | 37 | this.orientation = { 38 | x: 0, 39 | y: 0, 40 | }; 41 | 42 | this.update = function() { 43 | 44 | if ( this.enabled === false ) return; 45 | 46 | mouseQuat.x.setFromAxisAngle( xVector, this.orientation.x ); 47 | mouseQuat.y.setFromAxisAngle( yVector, this.orientation.y ); 48 | object.quaternion.copy( mouseQuat.y ).multiply( mouseQuat.x ); 49 | return; 50 | 51 | }; 52 | 53 | this.dispose = function() { 54 | 55 | document.removeEventListener( 'mousemove', onMouseMove, false ); 56 | 57 | } 58 | 59 | document.addEventListener( 'mousemove', onMouseMove, false ); 60 | 61 | }; 62 | -------------------------------------------------------------------------------- /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 | camera.rotation.set( 0, 0, 0 ); 10 | 11 | var pitchObject = new THREE.Object3D(); 12 | pitchObject.add( camera ); 13 | 14 | var yawObject = new THREE.Object3D(); 15 | yawObject.position.y = 10; 16 | yawObject.add( pitchObject ); 17 | 18 | var PI_2 = Math.PI / 2; 19 | 20 | var onMouseMove = function ( event ) { 21 | 22 | if ( scope.enabled === false ) return; 23 | 24 | var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0; 25 | var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0; 26 | 27 | yawObject.rotation.y -= movementX * 0.002; 28 | pitchObject.rotation.x -= movementY * 0.002; 29 | 30 | pitchObject.rotation.x = Math.max( - PI_2, Math.min( PI_2, pitchObject.rotation.x ) ); 31 | 32 | }; 33 | 34 | this.dispose = function() { 35 | 36 | document.removeEventListener( 'mousemove', onMouseMove, false ); 37 | 38 | } 39 | 40 | document.addEventListener( 'mousemove', onMouseMove, false ); 41 | 42 | this.enabled = false; 43 | 44 | this.getObject = function () { 45 | 46 | return yawObject; 47 | 48 | }; 49 | 50 | this.getDirection = function() { 51 | 52 | // assumes the camera itself is not rotated 53 | 54 | var direction = new THREE.Vector3( 0, 0, - 1 ); 55 | var rotation = new THREE.Euler( 0, 0, 0, "YXZ" ); 56 | 57 | return function( v ) { 58 | 59 | rotation.set( pitchObject.rotation.x, yawObject.rotation.y, 0 ); 60 | 61 | v.copy( direction ).applyEuler( rotation ); 62 | 63 | return v; 64 | 65 | } 66 | 67 | }(); 68 | 69 | }; 70 | -------------------------------------------------------------------------------- /js/controls/VRControls.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author dmarcos / https://github.com/dmarcos 3 | * @author mrdoob / http://mrdoob.com 4 | */ 5 | 6 | THREE.VRControls = function ( object, onError ) { 7 | 8 | var scope = this; 9 | 10 | var vrInputs = []; 11 | 12 | function filterInvalidDevices( devices ) { 13 | 14 | // Exclude Cardboard position sensor if Oculus exists. 15 | 16 | var oculusDevices = devices.filter( function ( device ) { 17 | 18 | return device.deviceName.toLowerCase().indexOf( 'oculus' ) !== - 1; 19 | 20 | } ); 21 | 22 | if ( oculusDevices.length >= 1 ) { 23 | 24 | return devices.filter( function ( device ) { 25 | 26 | return device.deviceName.toLowerCase().indexOf( 'cardboard' ) === - 1; 27 | 28 | } ); 29 | 30 | } else { 31 | 32 | return devices; 33 | 34 | } 35 | 36 | } 37 | 38 | function gotVRDevices( devices ) { 39 | 40 | devices = filterInvalidDevices( devices ); 41 | 42 | for ( var i = 0; i < devices.length; i ++ ) { 43 | 44 | if ( devices[ i ] instanceof PositionSensorVRDevice ) { 45 | 46 | vrInputs.push( devices[ i ] ); 47 | 48 | } 49 | 50 | } 51 | 52 | if ( onError ) onError( 'HMD not available' ); 53 | 54 | } 55 | 56 | if ( navigator.getVRDevices ) { 57 | 58 | navigator.getVRDevices().then( gotVRDevices ); 59 | 60 | } 61 | 62 | // the Rift SDK returns the position in meters 63 | // this scale factor allows the user to define how meters 64 | // are converted to scene units. 65 | 66 | this.scale = 1; 67 | 68 | this.update = function () { 69 | 70 | for ( var i = 0; i < vrInputs.length; i ++ ) { 71 | 72 | var vrInput = vrInputs[ i ]; 73 | 74 | var state = vrInput.getState(); 75 | 76 | if ( state.orientation !== null ) { 77 | 78 | object.quaternion.copy( state.orientation ); 79 | 80 | } 81 | 82 | if ( state.position !== null ) { 83 | 84 | object.position.copy( state.position ).multiplyScalar( scope.scale ); 85 | 86 | } 87 | 88 | } 89 | 90 | }; 91 | 92 | this.resetSensor = function () { 93 | 94 | for ( var i = 0; i < vrInputs.length; i ++ ) { 95 | 96 | var vrInput = vrInputs[ i ]; 97 | 98 | if ( vrInput.resetSensor !== undefined ) { 99 | 100 | vrInput.resetSensor(); 101 | 102 | } else if ( vrInput.zeroSensor !== undefined ) { 103 | 104 | vrInput.zeroSensor(); 105 | 106 | } 107 | 108 | } 109 | 110 | }; 111 | 112 | this.zeroSensor = function () { 113 | 114 | console.warn( 'THREE.VRControls: .zeroSensor() is now .resetSensor().' ); 115 | this.resetSensor(); 116 | 117 | }; 118 | 119 | this.dispose = function () { 120 | 121 | vrInputs = []; 122 | 123 | }; 124 | 125 | }; 126 | -------------------------------------------------------------------------------- /js/crossfade/gui.js: -------------------------------------------------------------------------------- 1 | var transitionParams = { 2 | "useTexture": true, 3 | "transition": 0.5, 4 | "transitionSpeed": 2.0, 5 | "texture": 5, 6 | "loopTexture": true, 7 | "animateTransition": true, 8 | "textureThreshold": 0.3 9 | }; 10 | 11 | function initGUI() { 12 | 13 | var gui = new dat.GUI(); 14 | 15 | gui.add( transitionParams, "useTexture" ).onChange( function( value ) { 16 | 17 | transition.useTexture( value ); 18 | 19 | } ); 20 | 21 | gui.add( transitionParams, 'loopTexture' ); 22 | 23 | gui.add( transitionParams, 'texture', { Perlin: 0, Squares: 1, Cells: 2, Distort: 3, Gradient: 4, Radial: 5 } ).onChange( function( value ) { 24 | 25 | transition.setTexture( value ); 26 | 27 | } ).listen(); 28 | 29 | gui.add( transitionParams, "textureThreshold", 0, 1, 0.01 ).onChange( function( value ) { 30 | 31 | transition.setTextureThreshold( value ); 32 | 33 | } ); 34 | 35 | gui.add( transitionParams, "animateTransition" ); 36 | gui.add( transitionParams, "transition", 0, 1, 0.01 ).listen(); 37 | gui.add( transitionParams, "transitionSpeed", 0.5, 5, 0.01 ); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /js/crossfade/scenes.js: -------------------------------------------------------------------------------- 1 | function generateGeometry( objectType, numObjects ) { 2 | 3 | var geometry = new THREE.Geometry(); 4 | 5 | function applyVertexColors( g, c ) { 6 | 7 | g.faces.forEach( function( f ) { 8 | 9 | var n = ( f instanceof THREE.Face3 ) ? 3 : 4; 10 | 11 | for ( var j = 0; j < n; j ++ ) { 12 | 13 | f.vertexColors[ j ] = c; 14 | 15 | } 16 | 17 | } ); 18 | 19 | } 20 | 21 | for ( var i = 0; i < numObjects; i ++ ) { 22 | 23 | var position = new THREE.Vector3(); 24 | 25 | position.x = Math.random() * 10000 - 5000; 26 | position.y = Math.random() * 6000 - 3000; 27 | position.z = Math.random() * 8000 - 4000; 28 | 29 | var rotation = new THREE.Euler(); 30 | 31 | rotation.x = Math.random() * 2 * Math.PI; 32 | rotation.y = Math.random() * 2 * Math.PI; 33 | rotation.z = Math.random() * 2 * Math.PI; 34 | 35 | var scale = new THREE.Vector3(); 36 | 37 | var geom, color = new THREE.Color(); 38 | 39 | scale.x = Math.random() * 200 + 100; 40 | 41 | if ( objectType == "cube" ) { 42 | 43 | geom = new THREE.BoxGeometry( 1, 1, 1 ); 44 | scale.y = Math.random() * 200 + 100; 45 | scale.z = Math.random() * 200 + 100; 46 | color.setRGB( 0, 0, Math.random() + 0.1 ); 47 | 48 | } else if ( objectType == "sphere" ) { 49 | 50 | geom = new THREE.IcosahedronGeometry( 1, 1 ); 51 | scale.y = scale.z = scale.x; 52 | color.setRGB( Math.random() + 0.1, 0, 0 ); 53 | 54 | } 55 | 56 | // give the geom's vertices a random color, to be displayed 57 | applyVertexColors( geom, color ); 58 | 59 | var mesh = new THREE.Mesh( geom ); 60 | mesh.position.copy( position ); 61 | mesh.rotation.copy( rotation ); 62 | mesh.scale.copy( scale ); 63 | mesh.updateMatrix(); 64 | 65 | geometry.merge( mesh.geometry, mesh.matrix ); 66 | 67 | } 68 | 69 | return geometry; 70 | 71 | } 72 | 73 | function Scene ( type, numObjects, cameraZ, fov, rotationSpeed, clearColor ) { 74 | 75 | this.clearColor = clearColor; 76 | 77 | this.camera = new THREE.PerspectiveCamera( fov, window.innerWidth / window.innerHeight, 1, 10000 ); 78 | this.camera.position.z = cameraZ; 79 | 80 | // Setup scene 81 | this.scene = new THREE.Scene(); 82 | this.scene.add( new THREE.AmbientLight( 0x555555 ) ); 83 | 84 | var light = new THREE.SpotLight( 0xffffff, 1.5 ); 85 | light.position.set( 0, 500, 2000 ); 86 | this.scene.add( light ); 87 | 88 | this.rotationSpeed = rotationSpeed; 89 | defaultMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, shading: THREE.FlatShading, vertexColors: THREE.VertexColors } ); 90 | this.mesh = new THREE.Mesh( generateGeometry( type, numObjects ), defaultMaterial ); 91 | this.scene.add( this.mesh ); 92 | 93 | renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false }; 94 | this.fbo = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, renderTargetParameters ); 95 | 96 | this.render = function( delta, rtt ) { 97 | 98 | this.mesh.rotation.x += delta * this.rotationSpeed.x; 99 | this.mesh.rotation.y += delta * this.rotationSpeed.y; 100 | this.mesh.rotation.z += delta * this.rotationSpeed.z; 101 | 102 | renderer.setClearColor( this.clearColor ); 103 | 104 | if ( rtt ) 105 | renderer.render( this.scene, this.camera, this.fbo, true ); 106 | else 107 | renderer.render( this.scene, this.camera ); 108 | 109 | }; 110 | 111 | } 112 | -------------------------------------------------------------------------------- /js/curves/NURBSCurve.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author renej 3 | * NURBS curve object 4 | * 5 | * Derives from Curve, overriding getPoint and getTangent. 6 | * 7 | * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight. 8 | * 9 | **/ 10 | 11 | 12 | /************************************************************** 13 | * NURBS curve 14 | **************************************************************/ 15 | 16 | THREE.NURBSCurve = function ( degree, knots /* array of reals */, controlPoints /* array of Vector(2|3|4) */ ) { 17 | 18 | this.degree = degree; 19 | this.knots = knots; 20 | this.controlPoints = []; 21 | for ( var i = 0; i < controlPoints.length; ++ i ) { 22 | 23 | // ensure Vector4 for control points 24 | var point = controlPoints[ i ]; 25 | this.controlPoints[ i ] = new THREE.Vector4( point.x, point.y, point.z, point.w ); 26 | 27 | } 28 | 29 | }; 30 | 31 | 32 | THREE.NURBSCurve.prototype = Object.create( THREE.Curve.prototype ); 33 | THREE.NURBSCurve.prototype.constructor = THREE.NURBSCurve; 34 | 35 | 36 | THREE.NURBSCurve.prototype.getPoint = function ( t ) { 37 | 38 | var u = this.knots[ 0 ] + t * ( this.knots[ this.knots.length - 1 ] - this.knots[ 0 ] ); // linear mapping t->u 39 | 40 | // following results in (wx, wy, wz, w) homogeneous point 41 | var hpoint = THREE.NURBSUtils.calcBSplinePoint( this.degree, this.knots, this.controlPoints, u ); 42 | 43 | if ( hpoint.w != 1.0 ) { 44 | 45 | // project to 3D space: (wx, wy, wz, w) -> (x, y, z, 1) 46 | hpoint.divideScalar( hpoint.w ); 47 | 48 | } 49 | 50 | return new THREE.Vector3( hpoint.x, hpoint.y, hpoint.z ); 51 | 52 | }; 53 | 54 | 55 | THREE.NURBSCurve.prototype.getTangent = function ( t ) { 56 | 57 | var u = this.knots[ 0 ] + t * ( this.knots[ this.knots.length - 1 ] - this.knots[ 0 ] ); 58 | var ders = THREE.NURBSUtils.calcNURBSDerivatives( this.degree, this.knots, this.controlPoints, u, 1 ); 59 | var tangent = ders[ 1 ].clone(); 60 | tangent.normalize(); 61 | 62 | return tangent; 63 | 64 | }; 65 | 66 | -------------------------------------------------------------------------------- /js/curves/NURBSSurface.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author renej 3 | * NURBS surface object 4 | * 5 | * Implementation is based on (x, y [, z=0 [, w=1]]) control points with w=weight. 6 | * 7 | **/ 8 | 9 | 10 | /************************************************************** 11 | * NURBS surface 12 | **************************************************************/ 13 | 14 | THREE.NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */ ) { 15 | 16 | this.degree1 = degree1; 17 | this.degree2 = degree2; 18 | this.knots1 = knots1; 19 | this.knots2 = knots2; 20 | this.controlPoints = []; 21 | 22 | var len1 = knots1.length - degree1 - 1; 23 | var len2 = knots2.length - degree2 - 1; 24 | 25 | // ensure Vector4 for control points 26 | for ( var i = 0; i < len1; ++ i ) { 27 | 28 | this.controlPoints[ i ] = []; 29 | for ( var j = 0; j < len2; ++ j ) { 30 | 31 | var point = controlPoints[ i ][ j ]; 32 | this.controlPoints[ i ][ j ] = new THREE.Vector4( point.x, point.y, point.z, point.w ); 33 | 34 | } 35 | 36 | } 37 | 38 | }; 39 | 40 | 41 | THREE.NURBSSurface.prototype = { 42 | 43 | constructor: THREE.NURBSSurface, 44 | 45 | getPoint: function ( t1, t2 ) { 46 | 47 | var u = this.knots1[ 0 ] + t1 * ( this.knots1[ this.knots1.length - 1 ] - this.knots1[ 0 ] ); // linear mapping t1->u 48 | var v = this.knots2[ 0 ] + t2 * ( this.knots2[ this.knots2.length - 1 ] - this.knots2[ 0 ] ); // linear mapping t2->u 49 | 50 | return THREE.NURBSUtils.calcSurfacePoint( this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v ); 51 | 52 | } 53 | }; 54 | 55 | 56 | -------------------------------------------------------------------------------- /js/effects/StereoEffect.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * @authod mrdoob / http://mrdoob.com/ 4 | * @authod arodic / http://aleksandarrodic.com/ 5 | * @authod fonserbc / http://fonserbc.github.io/ 6 | * 7 | * Off-axis stereoscopic effect based on http://paulbourke.net/stereographics/stereorender/ 8 | */ 9 | 10 | THREE.StereoEffect = function ( renderer ) { 11 | 12 | // API 13 | 14 | var scope = this; 15 | 16 | this.eyeSeparation = 3; 17 | this.focalLength = 15; // Distance to the non-parallax or projection plane 18 | 19 | Object.defineProperties( this, { 20 | separation: { 21 | get: function () { 22 | 23 | return scope.eyeSeparation; 24 | 25 | }, 26 | set: function ( value ) { 27 | 28 | console.warn( 'THREE.StereoEffect: .separation is now .eyeSeparation.' ); 29 | scope.eyeSeparation = value; 30 | 31 | } 32 | }, 33 | targetDistance: { 34 | get: function () { 35 | 36 | return scope.focalLength; 37 | 38 | }, 39 | set: function ( value ) { 40 | 41 | console.warn( 'THREE.StereoEffect: .targetDistance is now .focalLength.' ); 42 | scope.focalLength = value; 43 | 44 | } 45 | } 46 | } ); 47 | 48 | // internals 49 | 50 | var _width, _height; 51 | 52 | var _position = new THREE.Vector3(); 53 | var _quaternion = new THREE.Quaternion(); 54 | var _scale = new THREE.Vector3(); 55 | 56 | var _cameraL = new THREE.PerspectiveCamera(); 57 | var _cameraR = new THREE.PerspectiveCamera(); 58 | 59 | var _fov; 60 | var _outer, _inner, _top, _bottom; 61 | var _ndfl, _halfFocalWidth, _halfFocalHeight; 62 | var _innerFactor, _outerFactor; 63 | 64 | // initialization 65 | 66 | renderer.autoClear = false; 67 | 68 | this.setSize = function ( width, height ) { 69 | 70 | _width = width / 2; 71 | _height = height; 72 | 73 | renderer.setSize( width, height ); 74 | 75 | }; 76 | 77 | this.render = function ( scene, camera ) { 78 | 79 | scene.updateMatrixWorld(); 80 | 81 | if ( camera.parent === null ) camera.updateMatrixWorld(); 82 | 83 | camera.matrixWorld.decompose( _position, _quaternion, _scale ); 84 | 85 | // Effective fov of the camera 86 | 87 | _fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( camera.fov ) * 0.5 ) / camera.zoom ) ); 88 | 89 | _ndfl = camera.near / this.focalLength; 90 | _halfFocalHeight = Math.tan( THREE.Math.degToRad( _fov ) * 0.5 ) * this.focalLength; 91 | _halfFocalWidth = _halfFocalHeight * 0.5 * camera.aspect; 92 | 93 | _top = _halfFocalHeight * _ndfl; 94 | _bottom = - _top; 95 | _innerFactor = ( _halfFocalWidth + this.eyeSeparation / 2.0 ) / ( _halfFocalWidth * 2.0 ); 96 | _outerFactor = 1.0 - _innerFactor; 97 | 98 | _outer = _halfFocalWidth * 2.0 * _ndfl * _outerFactor; 99 | _inner = _halfFocalWidth * 2.0 * _ndfl * _innerFactor; 100 | 101 | // left 102 | 103 | _cameraL.projectionMatrix.makeFrustum( 104 | - _outer, 105 | _inner, 106 | _bottom, 107 | _top, 108 | camera.near, 109 | camera.far 110 | ); 111 | 112 | _cameraL.position.copy( _position ); 113 | _cameraL.quaternion.copy( _quaternion ); 114 | _cameraL.translateX( - this.eyeSeparation / 2.0 ); 115 | 116 | // right 117 | 118 | _cameraR.projectionMatrix.makeFrustum( 119 | - _inner, 120 | _outer, 121 | _bottom, 122 | _top, 123 | camera.near, 124 | camera.far 125 | ); 126 | 127 | _cameraR.position.copy( _position ); 128 | _cameraR.quaternion.copy( _quaternion ); 129 | _cameraR.translateX( this.eyeSeparation / 2.0 ); 130 | 131 | // 132 | 133 | renderer.clear(); 134 | renderer.enableScissorTest( true ); 135 | 136 | renderer.setScissor( 0, 0, _width, _height ); 137 | renderer.setViewport( 0, 0, _width, _height ); 138 | renderer.render( scene, _cameraL ); 139 | 140 | renderer.setScissor( _width, 0, _width, _height ); 141 | renderer.setViewport( _width, 0, _width, _height ); 142 | renderer.render( scene, _cameraR ); 143 | 144 | renderer.enableScissorTest( false ); 145 | 146 | }; 147 | 148 | }; 149 | -------------------------------------------------------------------------------- /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 ( object ) { 12 | 13 | var output = ''; 14 | 15 | var indexVertex = 0; 16 | var indexVertexUvs = 0; 17 | var indexNormals = 0; 18 | 19 | var parseMesh = function ( mesh ) { 20 | 21 | var nbVertex = 0; 22 | var nbVertexUvs = 0; 23 | var nbNormals = 0; 24 | 25 | var geometry = mesh.geometry; 26 | 27 | if ( geometry instanceof THREE.Geometry ) { 28 | 29 | output += 'o ' + mesh.name + '\n'; 30 | 31 | var vertices = geometry.vertices; 32 | 33 | for ( var i = 0, l = vertices.length; i < l; i ++ ) { 34 | 35 | var vertex = vertices[ i ].clone(); 36 | vertex.applyMatrix4( mesh.matrixWorld ); 37 | 38 | output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n'; 39 | 40 | nbVertex ++; 41 | 42 | } 43 | 44 | // uvs 45 | 46 | var faces = geometry.faces; 47 | var faceVertexUvs = geometry.faceVertexUvs[ 0 ]; 48 | var hasVertexUvs = faces.length === faceVertexUvs.length; 49 | 50 | if ( hasVertexUvs ) { 51 | 52 | for ( var i = 0, l = faceVertexUvs.length; i < l; i ++ ) { 53 | 54 | var vertexUvs = faceVertexUvs[ i ]; 55 | 56 | for ( var j = 0, jl = vertexUvs.length; j < jl; j ++ ) { 57 | 58 | var uv = vertexUvs[ j ]; 59 | 60 | output += 'vt ' + uv.x + ' ' + uv.y + '\n'; 61 | 62 | nbVertexUvs ++; 63 | 64 | } 65 | 66 | } 67 | 68 | } 69 | 70 | // normals 71 | 72 | var normalMatrixWorld = new THREE.Matrix3(); 73 | normalMatrixWorld.getNormalMatrix( mesh.matrixWorld ); 74 | 75 | for ( var i = 0, l = faces.length; i < l; i ++ ) { 76 | 77 | var face = faces[ i ]; 78 | var vertexNormals = face.vertexNormals; 79 | 80 | if ( vertexNormals.length === 3 ) { 81 | 82 | for ( var j = 0, jl = vertexNormals.length; j < jl; j ++ ) { 83 | 84 | var normal = vertexNormals[ j ].clone(); 85 | normal.applyMatrix3( normalMatrixWorld ); 86 | 87 | output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n'; 88 | 89 | nbNormals ++; 90 | 91 | } 92 | 93 | } else { 94 | 95 | var normal = face.normal.clone(); 96 | normal.applyMatrix3( normalMatrixWorld ); 97 | 98 | for ( var j = 0; j < 3; j ++ ) { 99 | 100 | output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n'; 101 | 102 | nbNormals ++; 103 | 104 | } 105 | 106 | } 107 | 108 | } 109 | 110 | // faces 111 | 112 | 113 | for ( var i = 0, j = 1, l = faces.length; i < l; i ++, j += 3 ) { 114 | 115 | var face = faces[ i ]; 116 | 117 | output += 'f '; 118 | output += ( indexVertex + face.a + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j ) : '' ) + '/' + ( indexNormals + j ) + ' '; 119 | output += ( indexVertex + face.b + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + 1 ) : '' ) + '/' + ( indexNormals + j + 1 ) + ' '; 120 | output += ( indexVertex + face.c + 1 ) + '/' + ( hasVertexUvs ? ( indexVertexUvs + j + 2 ) : '' ) + '/' + ( indexNormals + j + 2 ) + '\n'; 121 | 122 | } 123 | 124 | } else { 125 | 126 | console.warn( 'THREE.OBJExporter.parseMesh(): geometry type unsupported', mesh ); 127 | // TODO: Support only BufferGeometry and use use setFromObject() 128 | 129 | } 130 | 131 | // update index 132 | indexVertex += nbVertex; 133 | indexVertexUvs += nbVertexUvs; 134 | indexNormals += nbNormals; 135 | 136 | }; 137 | 138 | object.traverse( function ( child ) { 139 | 140 | if ( child instanceof THREE.Mesh ) parseMesh( child ); 141 | 142 | } ); 143 | 144 | return output; 145 | 146 | } 147 | 148 | }; 149 | -------------------------------------------------------------------------------- /js/exporters/STLBinaryExporter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author kovacsv / http://kovacsv.hu/ 3 | * @author mrdoob / http://mrdoob.com/ 4 | * @author mudcube / http://mudcu.be/ 5 | */ 6 | 7 | THREE.STLBinaryExporter = function () {}; 8 | 9 | THREE.STLBinaryExporter.prototype = { 10 | 11 | constructor: THREE.STLBinaryExporter, 12 | 13 | parse: ( function () { 14 | 15 | var vector = new THREE.Vector3(); 16 | var normalMatrixWorld = new THREE.Matrix3(); 17 | 18 | return function parse( scene ) { 19 | 20 | var triangles = 0; 21 | scene.traverse( function ( object ) { 22 | 23 | if ( ! ( object instanceof THREE.Mesh ) ) return; 24 | triangles += object.geometry.faces.length; 25 | 26 | } ); 27 | 28 | var offset = 80; // skip header 29 | var bufferLength = triangles * 2 + triangles * 3 * 4 * 4 + 80 + 4; 30 | var arrayBuffer = new ArrayBuffer( bufferLength ); 31 | var output = new DataView( arrayBuffer ); 32 | output.setUint32( offset, triangles, true ); offset += 4; 33 | 34 | scene.traverse( function ( object ) { 35 | 36 | if ( ! ( object instanceof THREE.Mesh ) ) return; 37 | if ( ! ( object.geometry instanceof THREE.Geometry ) ) return; 38 | 39 | var geometry = object.geometry; 40 | var matrixWorld = object.matrixWorld; 41 | 42 | var vertices = geometry.vertices; 43 | var faces = geometry.faces; 44 | 45 | normalMatrixWorld.getNormalMatrix( matrixWorld ); 46 | 47 | for ( var i = 0, l = faces.length; i < l; i ++ ) { 48 | 49 | var face = faces[ i ]; 50 | 51 | vector.copy( face.normal ).applyMatrix3( normalMatrixWorld ).normalize(); 52 | 53 | output.setFloat32( offset, vector.x, true ); offset += 4; // normal 54 | output.setFloat32( offset, vector.y, true ); offset += 4; 55 | output.setFloat32( offset, vector.z, true ); offset += 4; 56 | 57 | var indices = [ face.a, face.b, face.c ]; 58 | 59 | for ( var j = 0; j < 3; j ++ ) { 60 | 61 | vector.copy( vertices[ indices[ j ] ] ).applyMatrix4( matrixWorld ); 62 | 63 | output.setFloat32( offset, vector.x, true ); offset += 4; // vertices 64 | output.setFloat32( offset, vector.y, true ); offset += 4; 65 | output.setFloat32( offset, vector.z, true ); offset += 4; 66 | 67 | } 68 | 69 | output.setUint16( offset, 0, true ); offset += 2; // attribute byte count 70 | 71 | } 72 | 73 | } ); 74 | 75 | return output; 76 | 77 | }; 78 | 79 | }() ) 80 | 81 | }; 82 | -------------------------------------------------------------------------------- /js/exporters/STLExporter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author kovacsv / http://kovacsv.hu/ 3 | * @author mrdoob / http://mrdoob.com/ 4 | */ 5 | 6 | THREE.STLExporter = function () {}; 7 | 8 | THREE.STLExporter.prototype = { 9 | 10 | constructor: THREE.STLExporter, 11 | 12 | parse: ( function () { 13 | 14 | var vector = new THREE.Vector3(); 15 | var normalMatrixWorld = new THREE.Matrix3(); 16 | 17 | return function parse( scene ) { 18 | 19 | var output = ''; 20 | 21 | output += 'solid exported\n'; 22 | 23 | scene.traverse( function ( object ) { 24 | 25 | if ( object instanceof THREE.Mesh ) { 26 | 27 | var geometry = object.geometry; 28 | var matrixWorld = object.matrixWorld; 29 | 30 | if ( geometry instanceof THREE.Geometry ) { 31 | 32 | var vertices = geometry.vertices; 33 | var faces = geometry.faces; 34 | 35 | normalMatrixWorld.getNormalMatrix( matrixWorld ); 36 | 37 | for ( var i = 0, l = faces.length; i < l; i ++ ) { 38 | 39 | var face = faces[ i ]; 40 | 41 | vector.copy( face.normal ).applyMatrix3( normalMatrixWorld ).normalize(); 42 | 43 | output += '\tfacet normal ' + vector.x + ' ' + vector.y + ' ' + vector.z + '\n'; 44 | output += '\t\touter loop\n'; 45 | 46 | var indices = [ face.a, face.b, face.c ]; 47 | 48 | for ( var j = 0; j < 3; j ++ ) { 49 | 50 | vector.copy( vertices[ indices[ j ] ] ).applyMatrix4( matrixWorld ); 51 | 52 | output += '\t\t\tvertex ' + vector.x + ' ' + vector.y + ' ' + vector.z + '\n'; 53 | 54 | } 55 | 56 | output += '\t\tendloop\n'; 57 | output += '\tendfacet\n'; 58 | 59 | } 60 | 61 | } 62 | 63 | } 64 | 65 | } ); 66 | 67 | output += 'endsolid exported\n'; 68 | 69 | return output; 70 | 71 | }; 72 | 73 | }() ) 74 | 75 | }; 76 | -------------------------------------------------------------------------------- /js/exporters/TypedGeometryExporter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | */ 4 | 5 | THREE.TypedGeometryExporter = function () {}; 6 | 7 | THREE.TypedGeometryExporter.prototype = { 8 | 9 | constructor: THREE.TypedGeometryExporter, 10 | 11 | parse: function ( geometry ) { 12 | 13 | var output = { 14 | metadata: { 15 | version: 4.0, 16 | type: 'TypedGeometry', 17 | generator: 'TypedGeometryExporter' 18 | } 19 | }; 20 | 21 | var attributes = [ 'vertices', 'normals', 'uvs' ]; 22 | 23 | for ( var key in attributes ) { 24 | 25 | var attribute = attributes[ key ]; 26 | 27 | var typedArray = geometry[ attribute ]; 28 | var array = []; 29 | 30 | for ( var i = 0, l = typedArray.length; i < l; i ++ ) { 31 | 32 | array[ i ] = typedArray[ i ]; 33 | 34 | } 35 | 36 | output[ attribute ] = array; 37 | 38 | } 39 | 40 | var boundingSphere = geometry.boundingSphere; 41 | 42 | if ( boundingSphere !== null ) { 43 | 44 | output.boundingSphere = { 45 | center: boundingSphere.center.toArray(), 46 | radius: boundingSphere.radius 47 | } 48 | 49 | } 50 | 51 | return output; 52 | 53 | } 54 | 55 | }; 56 | -------------------------------------------------------------------------------- /js/geometries/TextGeometry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author zz85 / http://www.lab4games.net/zz85/blog 3 | * @author alteredq / http://alteredqualia.com/ 4 | * 5 | * For creating 3D text geometry in three.js 6 | * 7 | * Text = 3D Text 8 | * 9 | * parameters = { 10 | * size: , // size of the text 11 | * height: , // thickness to extrude text 12 | * curveSegments: , // number of points on the curves 13 | * 14 | * font: , // font name 15 | * weight: , // font weight (normal, bold) 16 | * style: , // font style (normal, italics) 17 | * 18 | * bevelEnabled: , // turn on bevel 19 | * bevelThickness: , // how deep into text bevel goes 20 | * bevelSize: , // how far from text outline is bevel 21 | * } 22 | * 23 | */ 24 | 25 | /* Usage Examples 26 | 27 | // TextGeometry wrapper 28 | 29 | var text3d = new TextGeometry( text, options ); 30 | 31 | // Complete manner 32 | 33 | var textShapes = THREE.FontUtils.generateShapes( text, options ); 34 | var text3d = new ExtrudeGeometry( textShapes, options ); 35 | 36 | */ 37 | 38 | 39 | THREE.TextGeometry = function ( text, parameters ) { 40 | 41 | parameters = parameters || {}; 42 | 43 | var textShapes = THREE.FontUtils.generateShapes( text, parameters ); 44 | 45 | // translate parameters to ExtrudeGeometry API 46 | 47 | parameters.amount = parameters.height !== undefined ? parameters.height : 50; 48 | 49 | // defaults 50 | 51 | if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10; 52 | if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8; 53 | if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false; 54 | 55 | THREE.ExtrudeGeometry.call( this, textShapes, parameters ); 56 | 57 | this.type = 'TextGeometry'; 58 | 59 | }; 60 | 61 | THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype ); 62 | THREE.TextGeometry.prototype.constructor = THREE.TextGeometry; 63 | -------------------------------------------------------------------------------- /js/geometries/hilbert2D.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Hilbert Curve: Generates 2D-Coordinates in a very fast way. 3 | * 4 | * @author Dylan Grafmyre 5 | * 6 | * Based on work by: 7 | * @author Thomas Diewald 8 | * @link http://www.openprocessing.org/sketch/15493 9 | * 10 | * @param center Center of Hilbert curve. 11 | * @param size Total width of Hilbert curve. 12 | * @param iterations Number of subdivisions. 13 | * @param v0 Corner index -X, -Z. 14 | * @param v1 Corner index -X, +Z. 15 | * @param v2 Corner index +X, +Z. 16 | * @param v3 Corner index +X, -Z. 17 | */ 18 | function hilbert2D ( center, size, iterations, v0, v1, v2, v3 ) { 19 | 20 | // Default Vars 21 | var center = undefined !== center ? center : new THREE.Vector3( 0, 0, 0 ), 22 | size = undefined !== size ? size : 10, 23 | half = size / 2, 24 | iterations = undefined !== iterations ? iterations : 1, 25 | v0 = undefined !== v0 ? v0 : 0, 26 | v1 = undefined !== v1 ? v1 : 1, 27 | v2 = undefined !== v2 ? v2 : 2, 28 | v3 = undefined !== v3 ? v3 : 3 29 | ; 30 | 31 | var vec_s = [ 32 | new THREE.Vector3( center.x - half, center.y, center.z - half ), 33 | new THREE.Vector3( center.x - half, center.y, center.z + half ), 34 | new THREE.Vector3( center.x + half, center.y, center.z + half ), 35 | new THREE.Vector3( center.x + half, center.y, center.z - half ) 36 | ]; 37 | 38 | var vec = [ 39 | vec_s[ v0 ], 40 | vec_s[ v1 ], 41 | vec_s[ v2 ], 42 | vec_s[ v3 ] 43 | ]; 44 | 45 | // Recurse iterations 46 | if ( 0 <= -- iterations ) { 47 | 48 | var tmp = []; 49 | 50 | Array.prototype.push.apply( tmp, hilbert2D ( vec[ 0 ], half, iterations, v0, v3, v2, v1 ) ); 51 | Array.prototype.push.apply( tmp, hilbert2D ( vec[ 1 ], half, iterations, v0, v1, v2, v3 ) ); 52 | Array.prototype.push.apply( tmp, hilbert2D ( vec[ 2 ], half, iterations, v0, v1, v2, v3 ) ); 53 | Array.prototype.push.apply( tmp, hilbert2D ( vec[ 3 ], half, iterations, v2, v1, v0, v3 ) ); 54 | 55 | // Return recursive call 56 | return tmp; 57 | 58 | } 59 | 60 | // Return complete Hilbert Curve. 61 | return vec; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /js/geometries/hilbert3D.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Hilbert Curve: Generates 2D-Coordinates in a very fast way. 3 | * 4 | * @author Dylan Grafmyre 5 | * 6 | * Based on work by: 7 | * @author Thomas Diewald 8 | * @link http://www.openprocessing.org/visuals/?visualID=15599 9 | * 10 | * Based on `examples/canvas_lines_colors.html`: 11 | * @author OpenShift guest 12 | * @link https://github.com/mrdoob/three.js/blob/8413a860aa95ed29c79cbb7f857c97d7880d260f/examples/canvas_lines_colors.html 13 | * @see Line 149 - 186 14 | * 15 | * @param center Center of Hilbert curve. 16 | * @param size Total width of Hilbert curve. 17 | * @param iterations Number of subdivisions. 18 | * @param v0 Corner index -X, +Y, -Z. 19 | * @param v1 Corner index -X, +Y, +Z. 20 | * @param v2 Corner index -X, -Y, +Z. 21 | * @param v3 Corner index -X, -Y, -Z. 22 | * @param v4 Corner index +X, -Y, -Z. 23 | * @param v5 Corner index +X, -Y, +Z. 24 | * @param v6 Corner index +X, +Y, +Z. 25 | * @param v7 Corner index +X, +Y, -Z. 26 | */ 27 | function hilbert3D( center, size, iterations, v0, v1, v2, v3, v4, v5, v6, v7 ) { 28 | 29 | // Default Vars 30 | var center = undefined !== center ? center : new THREE.Vector3( 0, 0, 0 ), 31 | size = undefined !== size ? size : 10, 32 | half = size / 2, 33 | iterations = undefined !== iterations ? iterations : 1, 34 | v0 = undefined !== v0 ? v0 : 0, 35 | v1 = undefined !== v1 ? v1 : 1, 36 | v2 = undefined !== v2 ? v2 : 2, 37 | v3 = undefined !== v3 ? v3 : 3, 38 | v4 = undefined !== v4 ? v4 : 4, 39 | v5 = undefined !== v5 ? v5 : 5, 40 | v6 = undefined !== v6 ? v6 : 6, 41 | v7 = undefined !== v7 ? v7 : 7 42 | ; 43 | 44 | var vec_s = [ 45 | new THREE.Vector3( center.x - half, center.y + half, center.z - half ), 46 | new THREE.Vector3( center.x - half, center.y + half, center.z + half ), 47 | new THREE.Vector3( center.x - half, center.y - half, center.z + half ), 48 | new THREE.Vector3( center.x - half, center.y - half, center.z - half ), 49 | new THREE.Vector3( center.x + half, center.y - half, center.z - half ), 50 | new THREE.Vector3( center.x + half, center.y - half, center.z + half ), 51 | new THREE.Vector3( center.x + half, center.y + half, center.z + half ), 52 | new THREE.Vector3( center.x + half, center.y + half, center.z - half ) 53 | ]; 54 | 55 | var vec = [ 56 | vec_s[ v0 ], 57 | vec_s[ v1 ], 58 | vec_s[ v2 ], 59 | vec_s[ v3 ], 60 | vec_s[ v4 ], 61 | vec_s[ v5 ], 62 | vec_s[ v6 ], 63 | vec_s[ v7 ] 64 | ]; 65 | 66 | // Recurse iterations 67 | if ( -- iterations >= 0 ) { 68 | 69 | var tmp = []; 70 | 71 | Array.prototype.push.apply( tmp, hilbert3D ( vec[ 0 ], half, iterations, v0, v3, v4, v7, v6, v5, v2, v1 ) ); 72 | Array.prototype.push.apply( tmp, hilbert3D ( vec[ 1 ], half, iterations, v0, v7, v6, v1, v2, v5, v4, v3 ) ); 73 | Array.prototype.push.apply( tmp, hilbert3D ( vec[ 2 ], half, iterations, v0, v7, v6, v1, v2, v5, v4, v3 ) ); 74 | Array.prototype.push.apply( tmp, hilbert3D ( vec[ 3 ], half, iterations, v2, v3, v0, v1, v6, v7, v4, v5 ) ); 75 | Array.prototype.push.apply( tmp, hilbert3D ( vec[ 4 ], half, iterations, v2, v3, v0, v1, v6, v7, v4, v5 ) ); 76 | Array.prototype.push.apply( tmp, hilbert3D ( vec[ 5 ], half, iterations, v4, v3, v2, v5, v6, v1, v0, v7 ) ); 77 | Array.prototype.push.apply( tmp, hilbert3D ( vec[ 6 ], half, iterations, v4, v3, v2, v5, v6, v1, v0, v7 ) ); 78 | Array.prototype.push.apply( tmp, hilbert3D ( vec[ 7 ], half, iterations, v6, v5, v2, v1, v0, v3, v4, v7 ) ); 79 | 80 | // Return recursive call 81 | return tmp; 82 | 83 | } 84 | 85 | // Return complete Hilbert Curve. 86 | return vec; 87 | 88 | } 89 | -------------------------------------------------------------------------------- /js/libs/stats.min.js: -------------------------------------------------------------------------------- 1 | // stats.js - http://github.com/mrdoob/stats.js 2 | var Stats=function(){function f(a,e,b){a=document.createElement(a);a.id=e;a.style.cssText=b;return a}function l(a,e,b){var c=f("div",a,"padding:0 0 3px 3px;text-align:left;background:"+b),d=f("div",a+"Text","font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px;color:"+e);d.innerHTML=a.toUpperCase();c.appendChild(d);a=f("div",a+"Graph","width:74px;height:30px;background:"+e);c.appendChild(a);for(e=0;74>e;e++)a.appendChild(f("span","","width:1px;height:30px;float:left;opacity:0.9;background:"+ 3 | b));return c}function m(a){for(var b=c.children,d=0;dr+1E3&&(d=Math.round(1E3* 5 | t/(a-r)),u=Math.min(u,d),v=Math.max(v,d),A.textContent=d+" FPS ("+u+"-"+v+")",p(B,d/100),r=a,t=0,void 0!==h)){var b=performance.memory.usedJSHeapSize,c=performance.memory.jsHeapSizeLimit;h=Math.round(9.54E-7*b);y=Math.min(y,h);z=Math.max(z,h);E.textContent=h+" MB ("+y+"-"+z+")";p(F,b/c)}return a},update:function(){k=this.end()}}};"object"===typeof module&&(module.exports=Stats); 6 | -------------------------------------------------------------------------------- /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/loaders/KMZLoader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | */ 4 | 5 | THREE.KMZLoader = function ( manager ) { 6 | 7 | this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; 8 | 9 | }; 10 | 11 | THREE.KMZLoader.prototype = { 12 | 13 | constructor: THREE.KMZLoader, 14 | 15 | load: function ( url, onLoad, onProgress, onError ) { 16 | 17 | var scope = this; 18 | 19 | var loader = new THREE.XHRLoader( scope.manager ); 20 | loader.setCrossOrigin( this.crossOrigin ); 21 | loader.setResponseType( 'arraybuffer' ); 22 | loader.load( url, function ( text ) { 23 | 24 | onLoad( scope.parse( text ) ); 25 | 26 | }, onProgress, onError ); 27 | 28 | }, 29 | 30 | parse: function ( data ) { 31 | 32 | var zip = new JSZip( data ); 33 | 34 | // console.log( zip ); 35 | 36 | for ( var name in zip.files ) { 37 | 38 | if ( name.toLowerCase().substr( - 4 ) === '.dae' ) { 39 | 40 | return new THREE.ColladaLoader().parse( zip.file( name ).asText() ); 41 | 42 | } 43 | 44 | } 45 | 46 | console.error( 'KZMLoader: Couldn\'t find .dae file.' ); 47 | 48 | return { 49 | scene: new THREE.Group() 50 | } 51 | 52 | } 53 | 54 | }; 55 | -------------------------------------------------------------------------------- /js/loaders/SVGLoader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | * @author zz85 / http://joshuakoo.com/ 4 | */ 5 | 6 | THREE.SVGLoader = function ( manager ) { 7 | 8 | this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; 9 | 10 | }; 11 | 12 | THREE.SVGLoader.prototype = { 13 | 14 | constructor: THREE.SVGLoader, 15 | 16 | load: function ( url, onLoad, onProgress, onError ) { 17 | 18 | var scope = this; 19 | 20 | var parser = new DOMParser(); 21 | 22 | var loader = new THREE.XHRLoader( scope.manager ); 23 | loader.setCrossOrigin( this.crossOrigin ); 24 | loader.load( url, function ( svgString ) { 25 | 26 | var doc = parser.parseFromString( svgString, 'image/svg+xml' ); // application/xml 27 | 28 | onLoad( doc.documentElement ); 29 | 30 | }, onProgress, onError ); 31 | 32 | }, 33 | 34 | setCrossOrigin: function ( value ) { 35 | 36 | this.crossOrigin = value; 37 | 38 | } 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /js/loaders/VTKLoader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | */ 4 | 5 | THREE.VTKLoader = function ( manager ) { 6 | 7 | this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; 8 | 9 | }; 10 | 11 | THREE.VTKLoader.prototype = { 12 | 13 | constructor: THREE.VTKLoader, 14 | 15 | load: function ( url, onLoad, onProgress, onError ) { 16 | 17 | var scope = this; 18 | 19 | var loader = new THREE.XHRLoader( scope.manager ); 20 | loader.setCrossOrigin( this.crossOrigin ); 21 | loader.load( url, function ( text ) { 22 | 23 | onLoad( scope.parse( text ) ); 24 | 25 | }, onProgress, onError ); 26 | 27 | }, 28 | 29 | setCrossOrigin: function ( value ) { 30 | 31 | this.crossOrigin = value; 32 | 33 | }, 34 | 35 | parse: function ( data ) { 36 | 37 | var indices = []; 38 | var positions = []; 39 | 40 | var result; 41 | 42 | // float float float 43 | 44 | var pat3Floats = /([\-]?[\d]+[\.]?[\d|\-|e]*)[ ]+([\-]?[\d]+[\.]?[\d|\-|e]*)[ ]+([\-]?[\d]+[\.]?[\d|\-|e]*)/g; 45 | var patTriangle = /^3[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/; 46 | var patQuad = /^4[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)[ ]+([\d]+)/; 47 | var patPOINTS = /^POINTS /; 48 | var patPOLYGONS = /^POLYGONS /; 49 | var inPointsSection = false; 50 | var inPolygonsSection = false; 51 | 52 | var lines = data.split('\n'); 53 | for ( var i = 0; i < lines.length; ++i ) { 54 | 55 | line = lines[i]; 56 | 57 | if ( inPointsSection ) { 58 | 59 | // get the vertices 60 | 61 | while ( ( result = pat3Floats.exec( line ) ) !== null ) { 62 | positions.push( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) ); 63 | } 64 | } 65 | else if ( inPolygonsSection ) { 66 | 67 | result = patTriangle.exec(line); 68 | 69 | if ( result !== null ) { 70 | 71 | // 3 int int int 72 | // triangle 73 | 74 | indices.push( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 3 ] ) ); 75 | } 76 | else { 77 | 78 | result = patQuad.exec(line); 79 | 80 | if ( result !== null ) { 81 | 82 | // 4 int int int int 83 | // break quad into two triangles 84 | 85 | indices.push( parseInt( result[ 1 ] ), parseInt( result[ 2 ] ), parseInt( result[ 4 ] ) ); 86 | indices.push( parseInt( result[ 2 ] ), parseInt( result[ 3 ] ), parseInt( result[ 4 ] ) ); 87 | } 88 | 89 | } 90 | 91 | } 92 | 93 | if ( patPOLYGONS.exec(line) !== null ) { 94 | inPointsSection = false; 95 | inPolygonsSection = true; 96 | } 97 | if ( patPOINTS.exec(line) !== null ) { 98 | inPolygonsSection = false; 99 | inPointsSection = true; 100 | } 101 | } 102 | 103 | var geometry = new THREE.BufferGeometry(); 104 | geometry.setIndex( new THREE.BufferAttribute( new ( indices.length > 65535 ? Uint32Array : Uint16Array )( indices ), 1 ) ); 105 | geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( positions ), 3 ) ); 106 | 107 | return geometry; 108 | 109 | } 110 | 111 | }; 112 | 113 | THREE.EventDispatcher.prototype.apply( THREE.VTKLoader.prototype ); 114 | -------------------------------------------------------------------------------- /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/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/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/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/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 | 12 | h = THREE.Math.euclideanModulo( h, 1 ); 13 | s = THREE.Math.clamp( s, 0, 1 ); 14 | v = THREE.Math.clamp( v, 0, 1 ); 15 | 16 | return color.setHSL( h, ( s * v ) / ( ( h = ( 2 - s ) * v ) < 1 ? h : ( 2 - h ) ), h * 0.5 ); 17 | 18 | }, 19 | 20 | getHSV: function( color ) { 21 | 22 | var hsl = color.getHSL(); 23 | 24 | // based on https://gist.github.com/xpansive/1337890#file-index-js 25 | hsl.s *= ( hsl.l < 0.5 ) ? hsl.l : ( 1 - hsl.l ); 26 | 27 | return { 28 | h: hsl.h, 29 | s: 2 * hsl.s / ( hsl.l + hsl.s ), 30 | v: hsl.l + hsl.s 31 | }; 32 | 33 | }, 34 | 35 | // where c, m, y, k is between 0 and 1 36 | 37 | setCMYK: function ( color, c, m, y, k ) { 38 | 39 | var r = ( 1 - c ) * ( 1 - k ); 40 | var g = ( 1 - m ) * ( 1 - k ); 41 | var b = ( 1 - y ) * ( 1 - k ); 42 | 43 | return color.setRGB( r, g, b ); 44 | 45 | }, 46 | 47 | getCMYK: function ( color ) { 48 | 49 | var r = color.r; 50 | var g = color.g; 51 | var b = color.b; 52 | var k = 1 - Math.max( r, g, b ); 53 | var c = ( 1 - r - k ) / ( 1 - k ); 54 | var m = ( 1 - g - k ) / ( 1 - k ); 55 | var y = ( 1 - b - k ) / ( 1 - k ); 56 | 57 | return { 58 | c: c, m: m, y: y, k: k 59 | }; 60 | 61 | } 62 | 63 | 64 | }; 65 | -------------------------------------------------------------------------------- /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 | var a = face.a; 23 | var b = face.b; 24 | var c = face.c; 25 | 26 | var va = geometry.vertices[ a ]; 27 | var vb = geometry.vertices[ b ]; 28 | var vc = geometry.vertices[ c ]; 29 | 30 | vertices.push( va.clone() ); 31 | vertices.push( vb.clone() ); 32 | vertices.push( vc.clone() ); 33 | 34 | face.a = n; 35 | face.b = n + 1; 36 | face.c = n + 2; 37 | 38 | } 39 | 40 | geometry.vertices = vertices; 41 | delete geometry.__tmpVertices; 42 | 43 | }; 44 | -------------------------------------------------------------------------------- /js/objects/ShadowMesh.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author erichlof / http://github.com/erichlof 3 | * 4 | * A shadow Mesh that follows a shadow-casting Mesh in the scene, but is confined to a single plane. 5 | */ 6 | 7 | THREE.ShadowMesh = function ( mesh ) { 8 | 9 | var shadowMaterial = new THREE.MeshBasicMaterial( { 10 | 11 | color: 0x000000, 12 | transparent: true, 13 | opacity: 0.6, 14 | depthWrite: false 15 | 16 | } ); 17 | 18 | THREE.Mesh.call( this, mesh.geometry, shadowMaterial ); 19 | 20 | this.meshMatrix = mesh.matrixWorld; 21 | 22 | this.frustumCulled = false; 23 | this.matrixAutoUpdate = false; 24 | 25 | }; 26 | 27 | THREE.ShadowMesh.prototype = Object.create( THREE.Mesh.prototype ); 28 | THREE.ShadowMesh.prototype.constructor = THREE.ShadowMesh; 29 | 30 | THREE.ShadowMesh.prototype.update = function () { 31 | 32 | var shadowMatrix = new THREE.Matrix4(); 33 | 34 | return function ( plane, lightPosition4D ) { 35 | 36 | // based on https://www.opengl.org/archives/resources/features/StencilTalk/tsld021.htm 37 | 38 | var dot = plane.normal.x * lightPosition4D.x + 39 | plane.normal.y * lightPosition4D.y + 40 | plane.normal.z * lightPosition4D.z + 41 | - plane.constant * lightPosition4D.w; 42 | 43 | var sme = shadowMatrix.elements; 44 | 45 | sme[ 0 ] = dot - lightPosition4D.x * plane.normal.x; 46 | sme[ 4 ] = - lightPosition4D.x * plane.normal.y; 47 | sme[ 8 ] = - lightPosition4D.x * plane.normal.z; 48 | sme[ 12 ] = - lightPosition4D.x * - plane.constant; 49 | 50 | sme[ 1 ] = - lightPosition4D.y * plane.normal.x; 51 | sme[ 5 ] = dot - lightPosition4D.y * plane.normal.y; 52 | sme[ 9 ] = - lightPosition4D.y * plane.normal.z; 53 | sme[ 13 ] = - lightPosition4D.y * - plane.constant; 54 | 55 | sme[ 2 ] = - lightPosition4D.z * plane.normal.x; 56 | sme[ 6 ] = - lightPosition4D.z * plane.normal.y; 57 | sme[ 10 ] = dot - lightPosition4D.z * plane.normal.z; 58 | sme[ 14 ] = - lightPosition4D.z * - plane.constant; 59 | 60 | sme[ 3 ] = - lightPosition4D.w * plane.normal.x; 61 | sme[ 7 ] = - lightPosition4D.w * plane.normal.y; 62 | sme[ 11 ] = - lightPosition4D.w * plane.normal.z; 63 | sme[ 15 ] = dot - lightPosition4D.w * - plane.constant; 64 | 65 | this.matrix.multiplyMatrices( shadowMatrix, this.meshMatrix ); 66 | 67 | }; 68 | 69 | }(); 70 | -------------------------------------------------------------------------------- /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 | this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); 70 | this.scene = new THREE.Scene(); 71 | 72 | this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null ); 73 | this.scene.add( this.quad ); 74 | 75 | }; 76 | 77 | THREE.BloomPass.prototype = { 78 | 79 | render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) { 80 | 81 | if ( maskActive ) renderer.context.disable( renderer.context.STENCIL_TEST ); 82 | 83 | // Render quad with blured scene into texture (convolution pass 1) 84 | 85 | this.quad.material = this.materialConvolution; 86 | 87 | this.convolutionUniforms[ "tDiffuse" ].value = readBuffer; 88 | this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurX; 89 | 90 | renderer.render( this.scene, this.camera, this.renderTargetX, true ); 91 | 92 | 93 | // Render quad with blured scene into texture (convolution pass 2) 94 | 95 | this.convolutionUniforms[ "tDiffuse" ].value = this.renderTargetX; 96 | this.convolutionUniforms[ "uImageIncrement" ].value = THREE.BloomPass.blurY; 97 | 98 | renderer.render( this.scene, this.camera, this.renderTargetY, true ); 99 | 100 | // Render original scene with superimposed blur to texture 101 | 102 | this.quad.material = this.materialCopy; 103 | 104 | this.copyUniforms[ "tDiffuse" ].value = this.renderTargetY; 105 | 106 | if ( maskActive ) renderer.context.enable( renderer.context.STENCIL_TEST ); 107 | 108 | renderer.render( this.scene, this.camera, readBuffer, this.clear ); 109 | 110 | } 111 | 112 | }; 113 | 114 | THREE.BloomPass.blurX = new THREE.Vector2( 0.001953125, 0.0 ); 115 | THREE.BloomPass.blurY = new THREE.Vector2( 0.0, 0.001953125 ); 116 | -------------------------------------------------------------------------------- /js/postprocessing/BokehPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Depth-of-field post-process with bokeh shader 3 | */ 4 | 5 | 6 | THREE.BokehPass = function ( scene, camera, params ) { 7 | 8 | this.scene = scene; 9 | this.camera = camera; 10 | 11 | var focus = ( params.focus !== undefined ) ? params.focus : 1.0; 12 | var aspect = ( params.aspect !== undefined ) ? params.aspect : camera.aspect; 13 | var aperture = ( params.aperture !== undefined ) ? params.aperture : 0.025; 14 | var maxblur = ( params.maxblur !== undefined ) ? params.maxblur : 1.0; 15 | 16 | // render targets 17 | 18 | var width = params.width || window.innerWidth || 1; 19 | var height = params.height || window.innerHeight || 1; 20 | 21 | this.renderTargetColor = new THREE.WebGLRenderTarget( width, height, { 22 | minFilter: THREE.LinearFilter, 23 | magFilter: THREE.LinearFilter, 24 | format: THREE.RGBFormat 25 | } ); 26 | 27 | this.renderTargetDepth = this.renderTargetColor.clone(); 28 | 29 | // depth material 30 | 31 | this.materialDepth = new THREE.MeshDepthMaterial(); 32 | 33 | // bokeh material 34 | 35 | if ( THREE.BokehShader === undefined ) { 36 | 37 | console.error( "THREE.BokehPass relies on THREE.BokehShader" ); 38 | 39 | } 40 | 41 | var bokehShader = THREE.BokehShader; 42 | var bokehUniforms = THREE.UniformsUtils.clone( bokehShader.uniforms ); 43 | 44 | bokehUniforms[ "tDepth" ].value = this.renderTargetDepth; 45 | 46 | bokehUniforms[ "focus" ].value = focus; 47 | bokehUniforms[ "aspect" ].value = aspect; 48 | bokehUniforms[ "aperture" ].value = aperture; 49 | bokehUniforms[ "maxblur" ].value = maxblur; 50 | 51 | this.materialBokeh = new THREE.ShaderMaterial( { 52 | uniforms: bokehUniforms, 53 | vertexShader: bokehShader.vertexShader, 54 | fragmentShader: bokehShader.fragmentShader 55 | } ); 56 | 57 | this.uniforms = bokehUniforms; 58 | this.enabled = true; 59 | this.needsSwap = false; 60 | this.renderToScreen = false; 61 | this.clear = false; 62 | 63 | this.camera2 = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); 64 | this.scene2 = new THREE.Scene(); 65 | 66 | this.quad2 = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null ); 67 | this.scene2.add( this.quad2 ); 68 | 69 | }; 70 | 71 | THREE.BokehPass.prototype = { 72 | 73 | render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) { 74 | 75 | this.quad2.material = this.materialBokeh; 76 | 77 | // Render depth into texture 78 | 79 | this.scene.overrideMaterial = this.materialDepth; 80 | 81 | renderer.render( this.scene, this.camera, this.renderTargetDepth, true ); 82 | 83 | // Render bokeh composite 84 | 85 | this.uniforms[ "tColor" ].value = readBuffer; 86 | 87 | if ( this.renderToScreen ) { 88 | 89 | renderer.render( this.scene2, this.camera2 ); 90 | 91 | } else { 92 | 93 | renderer.render( this.scene2, this.camera2, writeBuffer, this.clear ); 94 | 95 | } 96 | 97 | this.scene.overrideMaterial = null; 98 | 99 | } 100 | 101 | }; 102 | 103 | -------------------------------------------------------------------------------- /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 | this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); 32 | this.scene = new THREE.Scene(); 33 | 34 | this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null ); 35 | this.scene.add( this.quad ); 36 | 37 | }; 38 | 39 | THREE.DotScreenPass.prototype = { 40 | 41 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 42 | 43 | this.uniforms[ "tDiffuse" ].value = readBuffer; 44 | this.uniforms[ "tSize" ].value.set( readBuffer.width, readBuffer.height ); 45 | 46 | this.quad.material = this.material; 47 | 48 | if ( this.renderToScreen ) { 49 | 50 | renderer.render( this.scene, this.camera ); 51 | 52 | } else { 53 | 54 | renderer.render( this.scene, this.camera, writeBuffer, false ); 55 | 56 | } 57 | 58 | } 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /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 pixelRatio = renderer.getPixelRatio(); 12 | 13 | var width = Math.floor( renderer.context.canvas.width / pixelRatio ) || 1; 14 | var height = Math.floor( renderer.context.canvas.height / pixelRatio ) || 1; 15 | var parameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false }; 16 | 17 | renderTarget = new THREE.WebGLRenderTarget( width, height, parameters ); 18 | 19 | } 20 | 21 | this.renderTarget1 = renderTarget; 22 | this.renderTarget2 = renderTarget.clone(); 23 | 24 | this.writeBuffer = this.renderTarget1; 25 | this.readBuffer = this.renderTarget2; 26 | 27 | this.passes = []; 28 | 29 | if ( THREE.CopyShader === undefined ) 30 | console.error( "THREE.EffectComposer relies on THREE.CopyShader" ); 31 | 32 | this.copyPass = new THREE.ShaderPass( THREE.CopyShader ); 33 | 34 | }; 35 | 36 | THREE.EffectComposer.prototype = { 37 | 38 | swapBuffers: function() { 39 | 40 | var tmp = this.readBuffer; 41 | this.readBuffer = this.writeBuffer; 42 | this.writeBuffer = tmp; 43 | 44 | }, 45 | 46 | addPass: function ( pass ) { 47 | 48 | this.passes.push( pass ); 49 | 50 | }, 51 | 52 | insertPass: function ( pass, index ) { 53 | 54 | this.passes.splice( index, 0, pass ); 55 | 56 | }, 57 | 58 | render: function ( delta ) { 59 | 60 | this.writeBuffer = this.renderTarget1; 61 | this.readBuffer = this.renderTarget2; 62 | 63 | var maskActive = false; 64 | 65 | var pass, i, il = this.passes.length; 66 | 67 | for ( i = 0; i < il; i ++ ) { 68 | 69 | pass = this.passes[ i ]; 70 | 71 | if ( ! pass.enabled ) continue; 72 | 73 | pass.render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive ); 74 | 75 | if ( pass.needsSwap ) { 76 | 77 | if ( maskActive ) { 78 | 79 | var context = this.renderer.context; 80 | 81 | context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff ); 82 | 83 | this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, delta ); 84 | 85 | context.stencilFunc( context.EQUAL, 1, 0xffffffff ); 86 | 87 | } 88 | 89 | this.swapBuffers(); 90 | 91 | } 92 | 93 | if ( pass instanceof THREE.MaskPass ) { 94 | 95 | maskActive = true; 96 | 97 | } else if ( pass instanceof THREE.ClearMaskPass ) { 98 | 99 | maskActive = false; 100 | 101 | } 102 | 103 | } 104 | 105 | }, 106 | 107 | reset: function ( renderTarget ) { 108 | 109 | if ( renderTarget === undefined ) { 110 | 111 | renderTarget = this.renderTarget1.clone(); 112 | 113 | var pixelRatio = this.renderer.getPixelRatio(); 114 | 115 | renderTarget.width = Math.floor( this.renderer.context.canvas.width / pixelRatio ); 116 | renderTarget.height = Math.floor( this.renderer.context.canvas.height / pixelRatio ); 117 | 118 | } 119 | 120 | this.renderTarget1.dispose(); 121 | this.renderTarget1 = renderTarget; 122 | this.renderTarget2.dispose(); 123 | this.renderTarget2 = renderTarget.clone(); 124 | 125 | this.writeBuffer = this.renderTarget1; 126 | this.readBuffer = this.renderTarget2; 127 | 128 | }, 129 | 130 | setSize: function ( width, height ) { 131 | 132 | this.renderTarget1.setSize( width, height ); 133 | this.renderTarget2.setSize( width, height ); 134 | 135 | } 136 | 137 | }; 138 | -------------------------------------------------------------------------------- /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 | this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); 33 | this.scene = new THREE.Scene(); 34 | 35 | this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null ); 36 | this.scene.add( this.quad ); 37 | 38 | }; 39 | 40 | THREE.FilmPass.prototype = { 41 | 42 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 43 | 44 | this.uniforms[ "tDiffuse" ].value = readBuffer; 45 | this.uniforms[ "time" ].value += delta; 46 | 47 | this.quad.material = this.material; 48 | 49 | if ( this.renderToScreen ) { 50 | 51 | renderer.render( this.scene, this.camera ); 52 | 53 | } else { 54 | 55 | renderer.render( this.scene, this.camera, writeBuffer, false ); 56 | 57 | } 58 | 59 | } 60 | 61 | }; 62 | -------------------------------------------------------------------------------- /js/postprocessing/GlitchPass.js: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | */ 4 | 5 | THREE.GlitchPass = function ( dt_size ) { 6 | 7 | if ( THREE.DigitalGlitch === undefined ) console.error( "THREE.GlitchPass relies on THREE.DigitalGlitch" ); 8 | 9 | var shader = THREE.DigitalGlitch; 10 | this.uniforms = THREE.UniformsUtils.clone( shader.uniforms ); 11 | 12 | if ( dt_size == undefined ) dt_size = 64; 13 | 14 | 15 | this.uniforms[ "tDisp" ].value = this.generateHeightmap( dt_size ); 16 | 17 | 18 | this.material = new THREE.ShaderMaterial( { 19 | uniforms: this.uniforms, 20 | vertexShader: shader.vertexShader, 21 | fragmentShader: shader.fragmentShader 22 | } ); 23 | 24 | this.enabled = true; 25 | this.renderToScreen = false; 26 | this.needsSwap = true; 27 | 28 | 29 | this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); 30 | this.scene = new THREE.Scene(); 31 | 32 | this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null ); 33 | this.scene.add( this.quad ); 34 | 35 | this.goWild = false; 36 | this.curF = 0; 37 | this.generateTrigger(); 38 | 39 | }; 40 | 41 | THREE.GlitchPass.prototype = { 42 | 43 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 44 | 45 | this.uniforms[ "tDiffuse" ].value = readBuffer; 46 | this.uniforms[ 'seed' ].value = Math.random();//default seeding 47 | this.uniforms[ 'byp' ].value = 0; 48 | 49 | if ( this.curF % this.randX == 0 || this.goWild == true ) { 50 | 51 | this.uniforms[ 'amount' ].value = Math.random() / 30; 52 | this.uniforms[ 'angle' ].value = THREE.Math.randFloat( - Math.PI, Math.PI ); 53 | this.uniforms[ 'seed_x' ].value = THREE.Math.randFloat( - 1, 1 ); 54 | this.uniforms[ 'seed_y' ].value = THREE.Math.randFloat( - 1, 1 ); 55 | this.uniforms[ 'distortion_x' ].value = THREE.Math.randFloat( 0, 1 ); 56 | this.uniforms[ 'distortion_y' ].value = THREE.Math.randFloat( 0, 1 ); 57 | this.curF = 0; 58 | this.generateTrigger(); 59 | 60 | } else if ( this.curF % this.randX < this.randX / 5 ) { 61 | 62 | this.uniforms[ 'amount' ].value = Math.random() / 90; 63 | this.uniforms[ 'angle' ].value = THREE.Math.randFloat( - Math.PI, Math.PI ); 64 | this.uniforms[ 'distortion_x' ].value = THREE.Math.randFloat( 0, 1 ); 65 | this.uniforms[ 'distortion_y' ].value = THREE.Math.randFloat( 0, 1 ); 66 | this.uniforms[ 'seed_x' ].value = THREE.Math.randFloat( - 0.3, 0.3 ); 67 | this.uniforms[ 'seed_y' ].value = THREE.Math.randFloat( - 0.3, 0.3 ); 68 | 69 | } else if ( this.goWild == false ) { 70 | 71 | this.uniforms[ 'byp' ].value = 1; 72 | 73 | } 74 | this.curF ++; 75 | 76 | this.quad.material = this.material; 77 | if ( this.renderToScreen ) { 78 | 79 | renderer.render( this.scene, this.camera ); 80 | 81 | } else { 82 | 83 | renderer.render( this.scene, this.camera, writeBuffer, false ); 84 | 85 | } 86 | 87 | }, 88 | generateTrigger: function() { 89 | 90 | this.randX = THREE.Math.randInt( 120, 240 ); 91 | 92 | }, 93 | generateHeightmap: function( dt_size ) { 94 | 95 | var data_arr = new Float32Array( dt_size * dt_size * 3 ); 96 | var length = dt_size * dt_size; 97 | 98 | for ( var i = 0; i < length; i ++ ) { 99 | 100 | var val = THREE.Math.randFloat( 0, 1 ); 101 | data_arr[ i * 3 + 0 ] = val; 102 | data_arr[ i * 3 + 1 ] = val; 103 | data_arr[ i * 3 + 2 ] = val; 104 | 105 | } 106 | 107 | var texture = new THREE.DataTexture( data_arr, dt_size, dt_size, THREE.RGBFormat, THREE.FloatType ); 108 | texture.needsUpdate = true; 109 | return texture; 110 | 111 | } 112 | }; 113 | -------------------------------------------------------------------------------- /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/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/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 | this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); 39 | this.scene = new THREE.Scene(); 40 | 41 | this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null ); 42 | this.scene.add( this.quad ); 43 | 44 | }; 45 | 46 | THREE.SavePass.prototype = { 47 | 48 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 49 | 50 | if ( this.uniforms[ this.textureID ] ) { 51 | 52 | this.uniforms[ this.textureID ].value = readBuffer; 53 | 54 | } 55 | 56 | this.quad.material = this.material; 57 | 58 | renderer.render( this.scene, this.camera, this.renderTarget, this.clear ); 59 | 60 | } 61 | 62 | }; 63 | -------------------------------------------------------------------------------- /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 | defines: shader.defines || {}, 14 | uniforms: this.uniforms, 15 | vertexShader: shader.vertexShader, 16 | fragmentShader: shader.fragmentShader 17 | 18 | } ); 19 | 20 | this.renderToScreen = false; 21 | 22 | this.enabled = true; 23 | this.needsSwap = true; 24 | this.clear = false; 25 | 26 | 27 | this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); 28 | this.scene = new THREE.Scene(); 29 | 30 | this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null ); 31 | this.scene.add( this.quad ); 32 | 33 | }; 34 | 35 | THREE.ShaderPass.prototype = { 36 | 37 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 38 | 39 | if ( this.uniforms[ this.textureID ] ) { 40 | 41 | this.uniforms[ this.textureID ].value = readBuffer; 42 | 43 | } 44 | 45 | this.quad.material = this.material; 46 | 47 | if ( this.renderToScreen ) { 48 | 49 | renderer.render( this.scene, this.camera ); 50 | 51 | } else { 52 | 53 | renderer.render( this.scene, this.camera, writeBuffer, this.clear ); 54 | 55 | } 56 | 57 | } 58 | 59 | }; 60 | -------------------------------------------------------------------------------- /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 | this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); 30 | this.scene = new THREE.Scene(); 31 | 32 | this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null ); 33 | this.scene.add( this.quad ); 34 | 35 | }; 36 | 37 | THREE.TexturePass.prototype = { 38 | 39 | render: function ( renderer, writeBuffer, readBuffer, delta ) { 40 | 41 | this.quad.material = this.material; 42 | 43 | renderer.render( this.scene, this.camera, readBuffer ); 44 | 45 | } 46 | 47 | }; 48 | -------------------------------------------------------------------------------- /js/renderers/CSS2DRenderer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author mrdoob / http://mrdoob.com/ 3 | */ 4 | 5 | THREE.CSS2DObject = function ( element ) { 6 | 7 | THREE.Object3D.call( this ); 8 | 9 | this.element = element; 10 | this.element.style.position = 'absolute'; 11 | 12 | this.addEventListener( 'removed', function ( event ) { 13 | 14 | if ( this.element.parentNode !== null ) { 15 | 16 | this.element.parentNode.removeChild( this.element ); 17 | 18 | } 19 | 20 | } ); 21 | 22 | }; 23 | 24 | THREE.CSS2DObject.prototype = Object.create( THREE.Object3D.prototype ); 25 | THREE.CSS2DObject.prototype.constructor = THREE.CSS2DObject; 26 | 27 | // 28 | 29 | THREE.CSS2DRenderer = function () { 30 | 31 | console.log( 'THREE.CSS2DRenderer', THREE.REVISION ); 32 | 33 | var _width, _height; 34 | var _widthHalf, _heightHalf; 35 | 36 | var vector = new THREE.Vector3(); 37 | var viewMatrix = new THREE.Matrix4(); 38 | var viewProjectionMatrix = new THREE.Matrix4(); 39 | 40 | var domElement = document.createElement( 'div' ); 41 | domElement.style.overflow = 'hidden'; 42 | 43 | this.domElement = domElement; 44 | 45 | this.setSize = function ( width, height ) { 46 | 47 | _width = width; 48 | _height = height; 49 | 50 | _widthHalf = _width / 2; 51 | _heightHalf = _height / 2; 52 | 53 | domElement.style.width = width + 'px'; 54 | domElement.style.height = height + 'px'; 55 | 56 | }; 57 | 58 | var renderObject = function ( object, camera ) { 59 | 60 | if ( object instanceof THREE.CSS2DObject ) { 61 | 62 | vector.setFromMatrixPosition( object.matrixWorld ); 63 | vector.applyProjection( viewProjectionMatrix ); 64 | 65 | var element = object.element; 66 | var style = 'translate(-50%,-50%) translate(' + ( vector.x * _widthHalf + _widthHalf ) + 'px,' + ( - vector.y * _heightHalf + _heightHalf ) + 'px)'; 67 | 68 | element.style.WebkitTransform = style; 69 | element.style.MozTransform = style; 70 | element.style.oTransform = style; 71 | element.style.transform = style; 72 | 73 | if ( element.parentNode !== domElement ) { 74 | 75 | domElement.appendChild( element ); 76 | 77 | } 78 | 79 | } 80 | 81 | for ( var i = 0, l = object.children.length; i < l; i ++ ) { 82 | 83 | renderObject( object.children[ i ], camera ); 84 | 85 | } 86 | 87 | }; 88 | 89 | this.render = function ( scene, camera ) { 90 | 91 | scene.updateMatrixWorld(); 92 | 93 | if ( camera.parent === null ) camera.updateMatrixWorld(); 94 | 95 | camera.matrixWorldInverse.getInverse( camera.matrixWorld ); 96 | 97 | viewMatrix.copy( camera.matrixWorldInverse.getInverse( camera.matrixWorld ) ); 98 | viewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, viewMatrix ); 99 | 100 | renderObject( scene, camera ); 101 | 102 | }; 103 | 104 | }; 105 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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 | "addRGB": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) } 15 | 16 | }, 17 | 18 | vertexShader: [ 19 | 20 | "varying vec2 vUv;", 21 | 22 | "void main() {", 23 | 24 | "vUv = uv;", 25 | 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 vec3 powRGB;", 36 | "uniform vec3 mulRGB;", 37 | "uniform vec3 addRGB;", 38 | 39 | "varying vec2 vUv;", 40 | 41 | "void main() {", 42 | 43 | "gl_FragColor = texture2D( tDiffuse, vUv );", 44 | "gl_FragColor.rgb = mulRGB * pow( ( gl_FragColor.rgb + addRGB ), powRGB );", 45 | 46 | "}" 47 | 48 | ].join( "\n" ) 49 | 50 | }; 51 | -------------------------------------------------------------------------------- /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/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/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/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/shaders/DigitalGlitch.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.DigitalGlitch = { 14 | 15 | uniforms: { 16 | 17 | "tDiffuse": { type: "t", value: null },//diffuse texture 18 | "tDisp": { type: "t", value: null },//displacement texture for digital glitch squares 19 | "byp": { type: "i", value: 0 },//apply the glitch ? 20 | "amount": { type: "f", value: 0.08 }, 21 | "angle": { type: "f", value: 0.02 }, 22 | "seed": { type: "f", value: 0.02 }, 23 | "seed_x": { type: "f", value: 0.02 },//-1,1 24 | "seed_y": { type: "f", value: 0.02 },//-1,1 25 | "distortion_x": { type: "f", value: 0.5 }, 26 | "distortion_y": { type: "f", value: 0.6 }, 27 | "col_s": { type: "f", value: 0.05 } 28 | }, 29 | 30 | vertexShader: [ 31 | 32 | "varying vec2 vUv;", 33 | "void main() {", 34 | "vUv = uv;", 35 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 36 | "}" 37 | ].join( "\n" ), 38 | 39 | fragmentShader: [ 40 | "uniform int byp;",//should we apply the glitch ? 41 | 42 | "uniform sampler2D tDiffuse;", 43 | "uniform sampler2D tDisp;", 44 | 45 | "uniform float amount;", 46 | "uniform float angle;", 47 | "uniform float seed;", 48 | "uniform float seed_x;", 49 | "uniform float seed_y;", 50 | "uniform float distortion_x;", 51 | "uniform float distortion_y;", 52 | "uniform float col_s;", 53 | 54 | "varying vec2 vUv;", 55 | 56 | 57 | "float rand(vec2 co){", 58 | "return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);", 59 | "}", 60 | 61 | "void main() {", 62 | "if(byp<1) {", 63 | "vec2 p = vUv;", 64 | "float xs = floor(gl_FragCoord.x / 0.5);", 65 | "float ys = floor(gl_FragCoord.y / 0.5);", 66 | //based on staffantans glitch shader for unity https://github.com/staffantan/unityglitch 67 | "vec4 normal = texture2D (tDisp, p*seed*seed);", 68 | "if(p.ydistortion_x-col_s*seed) {", 69 | "if(seed_x>0.){", 70 | "p.y = 1. - (p.y + distortion_y);", 71 | "}", 72 | "else {", 73 | "p.y = distortion_y;", 74 | "}", 75 | "}", 76 | "if(p.xdistortion_y-col_s*seed) {", 77 | "if(seed_y>0.){", 78 | "p.x=distortion_x;", 79 | "}", 80 | "else {", 81 | "p.x = 1. - (p.x + distortion_x);", 82 | "}", 83 | "}", 84 | "p.x+=normal.x*seed_x*(seed/5.);", 85 | "p.y+=normal.y*seed_y*(seed/5.);", 86 | //base from RGB shift shader 87 | "vec2 offset = amount * vec2( cos(angle), sin(angle));", 88 | "vec4 cr = texture2D(tDiffuse, p + offset);", 89 | "vec4 cga = texture2D(tDiffuse, p);", 90 | "vec4 cb = texture2D(tDiffuse, p - offset);", 91 | "gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);", 92 | //add noise 93 | "vec4 snow = 200.*amount*vec4(rand(vec2(xs * seed,ys * seed*50.))*0.2);", 94 | "gl_FragColor = gl_FragColor+ snow;", 95 | "}", 96 | "else {", 97 | "gl_FragColor=texture2D (tDiffuse, vUv);", 98 | "}", 99 | "}" 100 | 101 | ].join( "\n" ) 102 | 103 | }; 104 | -------------------------------------------------------------------------------- /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/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/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/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 | "void main() {", 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 | "uniform vec2 resolution;", 34 | 35 | "#define FXAA_REDUCE_MIN (1.0/128.0)", 36 | "#define FXAA_REDUCE_MUL (1.0/8.0)", 37 | "#define FXAA_SPAN_MAX 8.0", 38 | 39 | "void main() {", 40 | 41 | "vec3 rgbNW = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ).xyz;", 42 | "vec3 rgbNE = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ).xyz;", 43 | "vec3 rgbSW = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ).xyz;", 44 | "vec3 rgbSE = texture2D( tDiffuse, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ).xyz;", 45 | "vec4 rgbaM = texture2D( tDiffuse, gl_FragCoord.xy * resolution );", 46 | "vec3 rgbM = rgbaM.xyz;", 47 | "vec3 luma = vec3( 0.299, 0.587, 0.114 );", 48 | 49 | "float lumaNW = dot( rgbNW, luma );", 50 | "float lumaNE = dot( rgbNE, luma );", 51 | "float lumaSW = dot( rgbSW, luma );", 52 | "float lumaSE = dot( rgbSE, luma );", 53 | "float lumaM = dot( rgbM, luma );", 54 | "float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) );", 55 | "float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) );", 56 | 57 | "vec2 dir;", 58 | "dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));", 59 | "dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));", 60 | 61 | "float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN );", 62 | 63 | "float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce );", 64 | "dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),", 65 | "max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),", 66 | "dir * rcpDirMin)) * resolution;", 67 | "vec4 rgbA = (1.0/2.0) * (", 68 | "texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (1.0/3.0 - 0.5)) +", 69 | "texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (2.0/3.0 - 0.5)));", 70 | "vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (", 71 | "texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (0.0/3.0 - 0.5)) +", 72 | "texture2D(tDiffuse, gl_FragCoord.xy * resolution + dir * (3.0/3.0 - 0.5)));", 73 | "float lumaB = dot(rgbB, vec4(luma, 0.0));", 74 | 75 | "if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) ) {", 76 | 77 | "gl_FragColor = rgbA;", 78 | 79 | "} else {", 80 | "gl_FragColor = rgbB;", 81 | 82 | "}", 83 | 84 | "}" 85 | 86 | ].join( "\n" ) 87 | 88 | }; 89 | -------------------------------------------------------------------------------- /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/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/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/shaders/GammaCorrectionShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author WestLangley / http://github.com/WestLangley 3 | * 4 | * Gamma Correction Shader 5 | * http://en.wikipedia.org/wiki/gamma_correction 6 | */ 7 | 8 | THREE.GammaCorrectionShader = { 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 | "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", 24 | 25 | "}" 26 | 27 | ].join( "\n" ), 28 | 29 | fragmentShader: [ 30 | 31 | "#define GAMMA_OUTPUT", 32 | "#define GAMMA_FACTOR 2", 33 | 34 | "uniform sampler2D tDiffuse;", 35 | 36 | "varying vec2 vUv;", 37 | 38 | THREE.ShaderChunk[ "common" ], 39 | 40 | "void main() {", 41 | 42 | "vec4 tex = texture2D( tDiffuse, vec2( vUv.x, vUv.y ) );", 43 | 44 | "gl_FragColor = vec4( linearToOutput( tex.rgb ), tex.a );", 45 | 46 | "}" 47 | 48 | ].join( "\n" ) 49 | 50 | }; 51 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/shaders/TechnicolorShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author flimshaw / http://charliehoey.com 3 | * 4 | * Technicolor Shader 5 | * Simulates the look of the two-strip technicolor process popular in early 20th century films. 6 | * More historical info here: http://www.widescreenmuseum.com/oldcolor/technicolor1.htm 7 | * Demo here: http://charliehoey.com/technicolor_shader/shader_test.html 8 | */ 9 | 10 | THREE.TechnicolorShader = { 11 | 12 | uniforms: { 13 | 14 | "tDiffuse": { type: "t", value: null }, 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 sampler2D tDiffuse;", 34 | "varying vec2 vUv;", 35 | 36 | "void main() {", 37 | 38 | "vec4 tex = texture2D( tDiffuse, vec2( vUv.x, vUv.y ) );", 39 | "vec4 newTex = vec4(tex.r, (tex.g + tex.b) * .5, (tex.g + tex.b) * .5, 1.0);", 40 | 41 | "gl_FragColor = newTex;", 42 | 43 | "}" 44 | 45 | ].join( "\n" ) 46 | 47 | }; 48 | -------------------------------------------------------------------------------- /js/shaders/ToneMapShader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author miibond 3 | * 4 | * Full-screen tone-mapping shader based on http://www.graphics.cornell.edu/~jaf/publications/sig02_paper.pdf 5 | */ 6 | 7 | THREE.ToneMapShader = { 8 | 9 | uniforms: { 10 | 11 | "tDiffuse": { type: "t", value: null }, 12 | "averageLuminance": { type: "f", value: 1.0 }, 13 | "luminanceMap": { type: "t", value: null }, 14 | "maxLuminance": { type: "f", value: 16.0 }, 15 | "middleGrey": { type: "f", value: 0.6 } 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 | 35 | "varying vec2 vUv;", 36 | 37 | "uniform float middleGrey;", 38 | "uniform float maxLuminance;", 39 | "#ifdef ADAPTED_LUMINANCE", 40 | "uniform sampler2D luminanceMap;", 41 | "#else", 42 | "uniform float averageLuminance;", 43 | "#endif", 44 | 45 | "const vec3 LUM_CONVERT = vec3(0.299, 0.587, 0.114);", 46 | 47 | "vec3 ToneMap( vec3 vColor ) {", 48 | "#ifdef ADAPTED_LUMINANCE", 49 | // Get the calculated average luminance 50 | "float fLumAvg = texture2D(luminanceMap, vec2(0.5, 0.5)).r;", 51 | "#else", 52 | "float fLumAvg = averageLuminance;", 53 | "#endif", 54 | 55 | // Calculate the luminance of the current pixel 56 | "float fLumPixel = dot(vColor, LUM_CONVERT);", 57 | 58 | // Apply the modified operator (Eq. 4) 59 | "float fLumScaled = (fLumPixel * middleGrey) / fLumAvg;", 60 | 61 | "float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (maxLuminance * maxLuminance)))) / (1.0 + fLumScaled);", 62 | "return fLumCompressed * vColor;", 63 | "}", 64 | 65 | "void main() {", 66 | 67 | "vec4 texel = texture2D( tDiffuse, vUv );", 68 | 69 | "gl_FragColor = vec4( ToneMap( texel.xyz ), texel.w );", 70 | 71 | "}" 72 | 73 | ].join( "\n" ) 74 | 75 | }; 76 | -------------------------------------------------------------------------------- /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/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/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/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/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/utils/ImageUtils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author alteredq / http://alteredqualia.com/ 3 | * @author mrdoob / http://mrdoob.com/ 4 | * @author Daosheng Mu / https://github.com/DaoshengMu/ 5 | */ 6 | 7 | THREE.ImageUtils = { 8 | 9 | getNormalMap: function ( image, depth ) { 10 | 11 | // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/ 12 | 13 | function cross( a, b ) { 14 | 15 | return [ a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ], a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ], a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ] ]; 16 | 17 | } 18 | 19 | function subtract( a, b ) { 20 | 21 | return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ]; 22 | 23 | } 24 | 25 | function normalize( a ) { 26 | 27 | var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] ); 28 | return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ]; 29 | 30 | } 31 | 32 | depth = depth | 1; 33 | 34 | var width = image.width; 35 | var height = image.height; 36 | 37 | var canvas = document.createElement( 'canvas' ); 38 | canvas.width = width; 39 | canvas.height = height; 40 | 41 | var context = canvas.getContext( '2d' ); 42 | context.drawImage( image, 0, 0 ); 43 | 44 | var data = context.getImageData( 0, 0, width, height ).data; 45 | var imageData = context.createImageData( width, height ); 46 | var output = imageData.data; 47 | 48 | for ( var x = 0; x < width; x ++ ) { 49 | 50 | for ( var y = 0; y < height; y ++ ) { 51 | 52 | var ly = y - 1 < 0 ? 0 : y - 1; 53 | var uy = y + 1 > height - 1 ? height - 1 : y + 1; 54 | var lx = x - 1 < 0 ? 0 : x - 1; 55 | var ux = x + 1 > width - 1 ? width - 1 : x + 1; 56 | 57 | var points = []; 58 | var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ]; 59 | points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] ); 60 | points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] ); 61 | points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] ); 62 | points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] ); 63 | points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] ); 64 | points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] ); 65 | points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] ); 66 | points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] ); 67 | 68 | var normals = []; 69 | var num_points = points.length; 70 | 71 | for ( var i = 0; i < num_points; i ++ ) { 72 | 73 | var v1 = points[ i ]; 74 | var v2 = points[ ( i + 1 ) % num_points ]; 75 | v1 = subtract( v1, origin ); 76 | v2 = subtract( v2, origin ); 77 | normals.push( normalize( cross( v1, v2 ) ) ); 78 | 79 | } 80 | 81 | var normal = [ 0, 0, 0 ]; 82 | 83 | for ( var i = 0; i < normals.length; i ++ ) { 84 | 85 | normal[ 0 ] += normals[ i ][ 0 ]; 86 | normal[ 1 ] += normals[ i ][ 1 ]; 87 | normal[ 2 ] += normals[ i ][ 2 ]; 88 | 89 | } 90 | 91 | normal[ 0 ] /= normals.length; 92 | normal[ 1 ] /= normals.length; 93 | normal[ 2 ] /= normals.length; 94 | 95 | var idx = ( y * width + x ) * 4; 96 | 97 | output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0; 98 | output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0; 99 | output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0; 100 | output[ idx + 3 ] = 255; 101 | 102 | } 103 | 104 | } 105 | 106 | context.putImageData( imageData, 0, 0 ); 107 | 108 | return canvas; 109 | 110 | }, 111 | 112 | generateDataTexture: function ( width, height, color ) { 113 | 114 | var size = width * height; 115 | var data = new Uint8Array( 3 * size ); 116 | 117 | var r = Math.floor( color.r * 255 ); 118 | var g = Math.floor( color.g * 255 ); 119 | var b = Math.floor( color.b * 255 ); 120 | 121 | for ( var i = 0; i < size; i ++ ) { 122 | 123 | data[ i * 3 ] = r; 124 | data[ i * 3 + 1 ] = g; 125 | data[ i * 3 + 2 ] = b; 126 | 127 | } 128 | 129 | var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat ); 130 | texture.needsUpdate = true; 131 | 132 | return texture; 133 | 134 | } 135 | 136 | }; 137 | -------------------------------------------------------------------------------- /js/utils/UVsDebug.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @author zz85 / http://github.com/zz85 3 | * @author WestLangley / http://github.com/WestLangley 4 | * 5 | * tool for "unwrapping" and debugging three.js 6 | * geometries UV mapping 7 | * 8 | * Sample usage: 9 | * document.body.appendChild( THREE.UVsDebug( new THREE.SphereGeometry( 10, 10, 10, 10 ) ); 10 | * 11 | */ 12 | 13 | THREE.UVsDebug = function( geometry, size ) { 14 | 15 | // handles wrapping of uv.x > 1 only 16 | 17 | var abc = 'abc'; 18 | 19 | var uv, u, ax, ay; 20 | var i, il, j, jl; 21 | var vnum; 22 | 23 | var a = new THREE.Vector2(); 24 | var b = new THREE.Vector2(); 25 | 26 | var geo = ( geometry instanceof THREE.BufferGeometry ) ? new THREE.Geometry().fromBufferGeometry( geometry ) : geometry; 27 | 28 | var faces = geo.faces; 29 | var uvs = geo.faceVertexUvs[ 0 ]; 30 | 31 | var canvas = document.createElement( 'canvas' ); 32 | var width = size || 1024; // power of 2 required for wrapping 33 | var height = size || 1024; 34 | canvas.width = width; 35 | canvas.height = height; 36 | 37 | var ctx = canvas.getContext( '2d' ); 38 | ctx.lineWidth = 2; 39 | ctx.strokeStyle = 'rgba( 0, 0, 0, 1.0 )'; 40 | ctx.textAlign = 'center'; 41 | 42 | // paint background white 43 | 44 | ctx.fillStyle = 'rgba( 255, 255, 255, 1.0 )'; 45 | ctx.fillRect( 0, 0, width, height ); 46 | 47 | for ( i = 0, il = uvs.length; i < il; i ++ ) { 48 | 49 | uv = uvs[ i ]; 50 | 51 | // draw lines 52 | 53 | ctx.beginPath(); 54 | 55 | a.set( 0, 0 ); 56 | 57 | for ( j = 0, jl = uv.length; j < jl; j ++ ) { 58 | 59 | u = uv[ j ]; 60 | 61 | a.x += u.x; 62 | a.y += u.y; 63 | 64 | if ( j == 0 ) { 65 | 66 | ctx.moveTo( u.x * width, ( 1 - u.y ) * height ); 67 | 68 | } else { 69 | 70 | ctx.lineTo( u.x * width, ( 1 - u.y ) * height ); 71 | 72 | } 73 | 74 | } 75 | 76 | ctx.closePath(); 77 | ctx.stroke(); 78 | 79 | a.divideScalar( jl ); 80 | 81 | // label the face number 82 | 83 | ctx.font = "12pt Arial bold"; 84 | ctx.fillStyle = 'rgba( 0, 0, 0, 1.0 )'; 85 | ctx.fillText( i, a.x * width, ( 1 - a.y ) * height ); 86 | 87 | if ( a.x > 0.95 ) { 88 | 89 | // wrap x // 0.95 is arbitrary 90 | 91 | ctx.fillText( i, ( a.x % 1 ) * width, ( 1 - a.y ) * height ); 92 | 93 | } 94 | 95 | ctx.font = "8pt Arial bold"; 96 | ctx.fillStyle = 'rgba( 0, 0, 0, 1.0 )'; 97 | 98 | // label uv edge orders 99 | 100 | for ( j = 0, jl = uv.length; j < jl; j ++ ) { 101 | 102 | u = uv[ j ]; 103 | b.addVectors( a, u ).divideScalar( 2 ); 104 | 105 | vnum = faces[ i ][ abc[ j ] ]; 106 | ctx.fillText( abc[ j ] + vnum, b.x * width, ( 1 - b.y ) * height ); 107 | 108 | if ( b.x > 0.95 ) { 109 | 110 | // wrap x 111 | 112 | ctx.fillText( abc[ j ] + vnum, ( b.x % 1 ) * width, ( 1 - b.y ) * height ); 113 | 114 | } 115 | 116 | } 117 | 118 | } 119 | 120 | return canvas; 121 | 122 | }; 123 | 124 | -------------------------------------------------------------------------------- /libs/package.require.js: -------------------------------------------------------------------------------- 1 | define( [ './threex.universalloader', 2 | ], function(){ 3 | }); -------------------------------------------------------------------------------- /libs/threex.universalloader.js: -------------------------------------------------------------------------------- 1 | var THREEx = THREEx || {} 2 | 3 | 4 | THREEx.UniversalLoader = function(){} 5 | 6 | THREEx.UniversalLoader.prototype.load = function(urls, onLoad){ 7 | // handle arguments polymorphism 8 | if( typeof(urls) === 'string' ) urls = [urls] 9 | 10 | // load per type 11 | if( urls[0].match(/\.stl$/i) && urls.length === 1 ){ 12 | this.loader = new THREE.STLLoader(); 13 | this.loader.addEventListener('load', function( event ){ 14 | var geometry = event.content 15 | var material = new THREE.MeshPhongMaterial(); 16 | var object3d = new THREE.Mesh( geometry, material ); 17 | onLoad(object3d) 18 | }) 19 | this.loader.load(urls[0]) 20 | return 21 | }else if( urls[0].match(/\.dae$/i) && urls.length === 1 ){ 22 | this.loader = new THREE.ColladaLoader(); 23 | this.loader.options.convertUpAxis = true; 24 | this.loader.load(urls[0], function( collada ){ 25 | // console.dir(arguments) 26 | var object3d = collada.scene 27 | onLoad(object3d) 28 | }) 29 | return 30 | }else if( urls[0].match(/\.js$/i) && urls.length === 1 ){ 31 | this.loader = new THREE.JSONLoader(); 32 | this.loader.load(urls[0], function(geometry, materials){ 33 | if( materials.length > 1 ){ 34 | var material = new THREE.MeshFaceMaterial(materials); 35 | }else{ 36 | var material = materials[0] 37 | } 38 | var object3d = new THREE.Mesh(geometry, material) 39 | onLoad(object3d) 40 | }) 41 | return 42 | }else if( urls[0].match(/\.obj$/i) && urls.length === 1 ){ 43 | this.loader = new THREE.OBJLoader(); 44 | this.loader.load(urls[0], function(object3d){ 45 | onLoad(object3d) 46 | }) 47 | return 48 | }else if( urls.length === 2 && urls[0].match(/\.mtl$/i) && urls[1].match(/\.obj$/i) ){ 49 | this.loader = new THREE.OBJMTLLoader(); 50 | this.loader.load(urls[1], urls[0], function(object3d){ 51 | onLoad(object3d) 52 | }) 53 | return 54 | }else if( urls.length === 2 && urls[0].match(/\.obj$/i) && urls[1].match(/\.mtl$/i) ){ 55 | this.loader = new THREE.OBJMTLLoader(); 56 | this.loader.load(urls[0], urls[1], function(object3d){ 57 | onLoad(object3d) 58 | }) 59 | return 60 | }else console.assert(false) 61 | } -------------------------------------------------------------------------------- /mongoose-free-5.6.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/mongoose-free-5.6.exe -------------------------------------------------------------------------------- /textures/bluefreeze/Note.txt: -------------------------------------------------------------------------------- 1 | This skybox is free for use but can't be sold for profit or altered in any way. 2 | 3 | Included in this zip floder are the zipped skybox and textures. Add the zipped skybox to your models directory and the textures to you textures directory of your OP. Go to your world and click on Options/World/Features. Now click on Sky and add the name of the skybox in Skybox without the zip. Click apply and OK. Your new skybox should start to download. -------------------------------------------------------------------------------- /textures/bluefreeze/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/bluefreeze/back.jpg -------------------------------------------------------------------------------- /textures/bluefreeze/bluefreeze.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/bluefreeze/bluefreeze.zip -------------------------------------------------------------------------------- /textures/bluefreeze/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/bluefreeze/front.jpg -------------------------------------------------------------------------------- /textures/bluefreeze/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/bluefreeze/left.jpg -------------------------------------------------------------------------------- /textures/bluefreeze/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/bluefreeze/right.jpg -------------------------------------------------------------------------------- /textures/bluefreeze/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/bluefreeze/top.jpg -------------------------------------------------------------------------------- /textures/city/Note.txt: -------------------------------------------------------------------------------- 1 | This skybox is free for use but can't be sold for profit or altered in any way. 2 | 3 | Included in this zip floder are the zipped skybox and textures. Add the zipped skybox to your models directory and the textures to you textures directory of your OP. Go to your world and click on Options/World/Features. Now click on Sky and add the name of the skybox in Skybox without the zip. Click apply and OK. Your new skybox should start to download. -------------------------------------------------------------------------------- /textures/city/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/city/back.jpg -------------------------------------------------------------------------------- /textures/city/city.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/city/city.zip -------------------------------------------------------------------------------- /textures/city/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/city/front.jpg -------------------------------------------------------------------------------- /textures/city/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/city/left.jpg -------------------------------------------------------------------------------- /textures/city/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/city/right.jpg -------------------------------------------------------------------------------- /textures/city/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/city/top.jpg -------------------------------------------------------------------------------- /textures/comawhite/Note.txt: -------------------------------------------------------------------------------- 1 | This skybox is free for use but can't be sold for profit or altered in any way. 2 | 3 | Included in this zip floder are the zipped skybox and textures. Add the zipped skybox to your models directory and the textures to you textures directory of your OP. Go to your world and click on Options/World/Features. Now click on Sky and add the name of the skybox in Skybox without the zip. Click apply and OK. Your new skybox should start to download. -------------------------------------------------------------------------------- /textures/comawhite/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/comawhite/back.jpg -------------------------------------------------------------------------------- /textures/comawhite/comawhite.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/comawhite/comawhite.zip -------------------------------------------------------------------------------- /textures/comawhite/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/comawhite/front.jpg -------------------------------------------------------------------------------- /textures/comawhite/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/comawhite/left.jpg -------------------------------------------------------------------------------- /textures/comawhite/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/comawhite/right.jpg -------------------------------------------------------------------------------- /textures/comawhite/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/comawhite/top.jpg -------------------------------------------------------------------------------- /textures/concrete.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/concrete.jpg -------------------------------------------------------------------------------- /textures/darkland/Note.txt: -------------------------------------------------------------------------------- 1 | This skybox is free for use but can't be sold for profit or altered in any way. 2 | 3 | Included in this zip floder are the zipped skybox and textures. Add the zipped skybox to your models directory and the textures to you textures directory of your OP. Go to your world and click on Options/World/Features. Now click on Sky and add the name of the skybox in Skybox without the zip. Click apply and OK. Your new skybox should start to download. -------------------------------------------------------------------------------- /textures/darkland/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/darkland/back.jpg -------------------------------------------------------------------------------- /textures/darkland/darkland.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/darkland/darkland.zip -------------------------------------------------------------------------------- /textures/darkland/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/darkland/front.jpg -------------------------------------------------------------------------------- /textures/darkland/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/darkland/left.jpg -------------------------------------------------------------------------------- /textures/darkland/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/darkland/right.jpg -------------------------------------------------------------------------------- /textures/darkland/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/darkland/top.jpg -------------------------------------------------------------------------------- /textures/mountains/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/mountains/back.jpg -------------------------------------------------------------------------------- /textures/mountains/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/mountains/front.jpg -------------------------------------------------------------------------------- /textures/mountains/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/mountains/left.jpg -------------------------------------------------------------------------------- /textures/mountains/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/mountains/right.jpg -------------------------------------------------------------------------------- /textures/mountains/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/mountains/top.jpg -------------------------------------------------------------------------------- /textures/snow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/snow.jpg -------------------------------------------------------------------------------- /textures/white-bricks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drealnn/3d-Level-Editor/6d89612bfa1d113c16a9e059cb0d485d7fb9ba14/textures/white-bricks.jpg --------------------------------------------------------------------------------