├── res └── Marching_Cubes_Picture.png ├── README.md ├── index.html ├── sketch.js ├── tables.js └── lib ├── OrbitControls.js └── OpenSimplexNoise.js /res/Marching_Cubes_Picture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KineticTactic/marching-cubes-js/HEAD/res/Marching_Cubes_Picture.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Marching Cubes! (3D) 2 | 3 | ![Marching Cubes](res/Marching_Cubes_Picture.png) 4 | 5 | This is an implementation of the Marching Cubes Algorithm in 3d in Javascript using [three.js](https://threejs.org/). -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 23 | 24 | Marching Cubes 25 | 26 | 27 |
28 |

Click and drag to orbit

29 |

Scroll to zoom

30 |

Right Click drag to pan

31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /sketch.js: -------------------------------------------------------------------------------- 1 | let scene; 2 | let camera; 3 | let controls; 4 | let renderer; 5 | 6 | let geometry; 7 | let material; 8 | let mesh; 9 | 10 | let field = []; 11 | let res = 0.5; 12 | let xSize = 100; 13 | let ySize = 100; 14 | let zSize = 100; 15 | let increment = 0.04; 16 | 17 | let noise; 18 | 19 | function setup() { 20 | scene = new THREE.Scene(); 21 | camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); 22 | 23 | controls = new THREE.OrbitControls(camera); 24 | 25 | renderer = new THREE.WebGLRenderer(); 26 | renderer.setSize(window.innerWidth, window.innerHeight); 27 | document.body.appendChild(renderer.domElement); 28 | 29 | noise = new OpenSimplexNoise(); 30 | 31 | // Calculate the Noise Field 32 | let xoff = 0; 33 | for (let i = 0; i < xSize; i++) { 34 | let yoff = 0; 35 | field[i] = []; 36 | for (let j = 0; j < ySize; j++) { 37 | let zoff = 0; 38 | field[i][j] = []; 39 | for (let k = 0; k < zSize; k++) { 40 | field[i][j][k] = noise.noise3D(xoff, yoff, zoff); 41 | zoff += increment; 42 | } 43 | yoff += increment; 44 | } 45 | xoff += increment; 46 | } 47 | 48 | let vertices = []; 49 | for (let i = 0; i < xSize - 1; i++) { 50 | let x = i * res; 51 | for (let j = 0; j < ySize - 1; j++) { 52 | let y = j * res; 53 | for (let k = 0; k < zSize - 1; k++) { 54 | let z = k * res; 55 | 56 | let values = [ 57 | field[i][j][k] + 1, 58 | field[i + 1][j][k] + 1, 59 | field[i + 1][j][k + 1] + 1, 60 | field[i][j][k + 1] + 1, 61 | field[i][j + 1][k] + 1, 62 | field[i + 1][j + 1][k] + 1, 63 | field[i + 1][j + 1][k + 1] + 1, 64 | field[i][j + 1][k + 1] + 1, 65 | ]; 66 | 67 | let edges = [ 68 | new THREE.Vector3( 69 | lerp(x, x + res, (1 - values[0]) / (values[1] - values[0])), 70 | y, 71 | z 72 | ), 73 | new THREE.Vector3( 74 | x + res, 75 | y, 76 | lerp(z, z + res, (1 - values[1]) / (values[2] - values[1])) 77 | ), 78 | new THREE.Vector3( 79 | lerp(x, x + res, (1 - values[3]) / (values[2] - values[3])), 80 | y, 81 | z + res 82 | ), 83 | new THREE.Vector3( 84 | x, 85 | y, 86 | lerp(z, z + res, (1 - values[0]) / (values[3] - values[0])) 87 | ), 88 | new THREE.Vector3( 89 | lerp(x, x + res, (1 - values[4]) / (values[5] - values[4])), 90 | y + res, 91 | z 92 | ), 93 | new THREE.Vector3( 94 | x + res, 95 | y + res, 96 | lerp(z, z + res, (1 - values[5]) / (values[6] - values[5])) 97 | ), 98 | new THREE.Vector3( 99 | lerp(x, x + res, (1 - values[7]) / (values[6] - values[7])), 100 | y + res, 101 | z + res 102 | ), 103 | new THREE.Vector3( 104 | x, 105 | y + res, 106 | lerp(z, z + res, (1 - values[4]) / (values[7] - values[4])) 107 | ), 108 | new THREE.Vector3( 109 | x, 110 | lerp(y, y + res, (1 - values[0]) / (values[4] - values[0])), 111 | z 112 | ), 113 | new THREE.Vector3( 114 | x + res, 115 | lerp(y, y + res, (1 - values[1]) / (values[5] - values[1])), 116 | z 117 | ), 118 | new THREE.Vector3( 119 | x + res, 120 | lerp(y, y + res, (1 - values[2]) / (values[6] - values[2])), 121 | z + res 122 | ), 123 | new THREE.Vector3( 124 | x, 125 | lerp(y, y + res, (1 - values[3]) / (values[7] - values[3])), 126 | z + res 127 | ), 128 | 129 | // Comment out the upper ones, and uncomment these commented ones 130 | // to disable interpolation 131 | 132 | // new THREE.Vector3(x + res / 2, y, z), 133 | // new THREE.Vector3(x + res, y, z + res / 2), 134 | // new THREE.Vector3(x + res / 2, y, z + res), 135 | // new THREE.Vector3(x, y, z + res / 2), 136 | // new THREE.Vector3(x + res / 2, y + res, z), 137 | // new THREE.Vector3(x + res, y + res, z + res / 2), 138 | // new THREE.Vector3(x + res / 2, y + res, z + res), 139 | // new THREE.Vector3(x, y + res, z + res / 2), 140 | // new THREE.Vector3(x, y + res / 2, z), 141 | // new THREE.Vector3(x + res, y + res / 2, z), 142 | // new THREE.Vector3(x + res, y + res / 2, z + res), 143 | // new THREE.Vector3(x, y + res / 2, z + res), 144 | ]; 145 | 146 | let state = getState( 147 | Math.ceil(field[i][j][k]), 148 | Math.ceil(field[i + 1][j][k]), 149 | Math.ceil(field[i + 1][j][k + 1]), 150 | Math.ceil(field[i][j][k + 1]), 151 | Math.ceil(field[i][j + 1][k]), 152 | Math.ceil(field[i + 1][j + 1][k]), 153 | Math.ceil(field[i + 1][j + 1][k + 1]), 154 | Math.ceil(field[i][j + 1][k + 1]) 155 | ); 156 | 157 | for (let edgeIndex of triangulationTable[state]) { 158 | if (edgeIndex !== -1) { 159 | vertices.push(edges[edgeIndex].x, edges[edgeIndex].y, edges[edgeIndex].z); 160 | } 161 | } 162 | } 163 | } 164 | } 165 | 166 | geometry = new THREE.BufferGeometry(); 167 | geometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array(vertices), 3)); 168 | geometry.computeVertexNormals(); 169 | 170 | material = new THREE.MeshPhongMaterial({ color: 0x0055ff, side: THREE.DoubleSide }); 171 | 172 | mesh = new THREE.Mesh(geometry, material); 173 | 174 | scene.add(mesh); 175 | 176 | let pointLight = new THREE.PointLight(0xffffff, 1, 0); 177 | pointLight.position.set(0, 0, 0); 178 | scene.add(pointLight); 179 | 180 | let pointLight2 = new THREE.PointLight(0xffffff, 1, 0); 181 | pointLight.position.set(50, 50, 50); 182 | scene.add(pointLight2); 183 | 184 | let ambientLight = new THREE.AmbientLight(0xffffff, 0.3); 185 | scene.add(ambientLight); 186 | 187 | camera.position.x = 25; 188 | camera.position.y = 20; 189 | camera.position.z = 100; 190 | } 191 | 192 | function draw() { 193 | requestAnimationFrame(draw); 194 | 195 | renderer.render(scene, camera); 196 | } 197 | 198 | function lerp(start, end, amt) { 199 | return (1 - amt) * start + amt * end; 200 | } 201 | 202 | function getState(a, b, c, d, e, f, g, h) { 203 | return a * 1 + b * 2 + c * 4 + d * 8 + e * 16 + f * 32 + g * 64 + h * 128; 204 | } 205 | 206 | setup(); 207 | draw(); 208 | -------------------------------------------------------------------------------- /tables.js: -------------------------------------------------------------------------------- 1 | let triangulationTable = [ 2 | [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 3 | [0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 4 | [0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 5 | [1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 6 | [1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 7 | [0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 8 | [9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 9 | [2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1], 10 | [3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 11 | [0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 12 | [1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 13 | [1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1], 14 | [3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 15 | [0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1], 16 | [3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1], 17 | [9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 18 | [4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 19 | [4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 20 | [0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 21 | [4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1], 22 | [1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 23 | [3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1], 24 | [9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1], 25 | [2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1], 26 | [8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 27 | [11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1], 28 | [9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1], 29 | [4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1], 30 | [3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1], 31 | [1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1], 32 | [4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1], 33 | [4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1], 34 | [9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 35 | [9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 36 | [0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 37 | [8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1], 38 | [1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 39 | [3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1], 40 | [5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1], 41 | [2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1], 42 | [9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 43 | [0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1], 44 | [0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1], 45 | [2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1], 46 | [10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1], 47 | [4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1], 48 | [5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1], 49 | [5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1], 50 | [9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 51 | [9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1], 52 | [0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1], 53 | [1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 54 | [9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1], 55 | [10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1], 56 | [8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1], 57 | [2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1], 58 | [7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1], 59 | [9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1], 60 | [2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1], 61 | [11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1], 62 | [9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1], 63 | [5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1], 64 | [11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1], 65 | [11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 66 | [10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 67 | [0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 68 | [9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 69 | [1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1], 70 | [1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 71 | [1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1], 72 | [9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1], 73 | [5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1], 74 | [2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 75 | [11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1], 76 | [0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1], 77 | [5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1], 78 | [6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1], 79 | [0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1], 80 | [3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1], 81 | [6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1], 82 | [5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 83 | [4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1], 84 | [1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1], 85 | [10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1], 86 | [6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1], 87 | [1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1], 88 | [8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1], 89 | [7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1], 90 | [3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1], 91 | [5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1], 92 | [0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1], 93 | [9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1], 94 | [8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1], 95 | [5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1], 96 | [0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1], 97 | [6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1], 98 | [10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 99 | [4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1], 100 | [10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1], 101 | [8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1], 102 | [1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1], 103 | [3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1], 104 | [0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 105 | [8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1], 106 | [10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1], 107 | [0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1], 108 | [3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1], 109 | [6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1], 110 | [9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1], 111 | [8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1], 112 | [3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1], 113 | [6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 114 | [7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1], 115 | [0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1], 116 | [10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1], 117 | [10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1], 118 | [1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1], 119 | [2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1], 120 | [7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1], 121 | [7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 122 | [2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1], 123 | [2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1], 124 | [1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1], 125 | [11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1], 126 | [8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1], 127 | [0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 128 | [7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1], 129 | [7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 130 | [7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 131 | [3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 132 | [0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 133 | [8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1], 134 | [10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 135 | [1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1], 136 | [2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1], 137 | [6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1], 138 | [7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 139 | [7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1], 140 | [2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1], 141 | [1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1], 142 | [10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1], 143 | [10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1], 144 | [0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1], 145 | [7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1], 146 | [6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 147 | [3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1], 148 | [8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1], 149 | [9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1], 150 | [6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1], 151 | [1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1], 152 | [4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1], 153 | [10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1], 154 | [8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1], 155 | [0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 156 | [1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1], 157 | [1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1], 158 | [8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1], 159 | [10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1], 160 | [4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1], 161 | [10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 162 | [4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 163 | [0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1], 164 | [5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1], 165 | [11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1], 166 | [9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1], 167 | [6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1], 168 | [7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1], 169 | [3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1], 170 | [7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1], 171 | [9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1], 172 | [3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1], 173 | [6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1], 174 | [9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1], 175 | [1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1], 176 | [4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1], 177 | [7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1], 178 | [6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1], 179 | [3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1], 180 | [0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1], 181 | [6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1], 182 | [1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1], 183 | [0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1], 184 | [11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1], 185 | [6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1], 186 | [5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1], 187 | [9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1], 188 | [1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1], 189 | [1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 190 | [1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1], 191 | [10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1], 192 | [0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 193 | [10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 194 | [11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 195 | [11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1], 196 | [5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1], 197 | [10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1], 198 | [11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1], 199 | [0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1], 200 | [9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1], 201 | [7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1], 202 | [2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1], 203 | [8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1], 204 | [9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1], 205 | [9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1], 206 | [1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 207 | [0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1], 208 | [9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1], 209 | [9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 210 | [5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1], 211 | [5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1], 212 | [0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1], 213 | [10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1], 214 | [2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1], 215 | [0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1], 216 | [0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1], 217 | [9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 218 | [2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1], 219 | [5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1], 220 | [3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1], 221 | [5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1], 222 | [8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1], 223 | [0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 224 | [8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1], 225 | [9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 226 | [4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1], 227 | [0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1], 228 | [1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1], 229 | [3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1], 230 | [4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1], 231 | [9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1], 232 | [11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1], 233 | [11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1], 234 | [2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1], 235 | [9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1], 236 | [3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1], 237 | [1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 238 | [4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1], 239 | [4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1], 240 | [4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 241 | [4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 242 | [9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 243 | [3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1], 244 | [0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1], 245 | [3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 246 | [1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1], 247 | [3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1], 248 | [0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 249 | [3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 250 | [2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1], 251 | [9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 252 | [2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1], 253 | [1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 254 | [1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 255 | [0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 256 | [0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 257 | [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 258 | ]; 259 | -------------------------------------------------------------------------------- /lib/OrbitControls.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author qiao / https://github.com/qiao 3 | * @author mrdoob / http://mrdoob.com 4 | * @author alteredq / http://alteredqualia.com/ 5 | * @author WestLangley / http://github.com/WestLangley 6 | * @author erich666 / http://erichaines.com 7 | */ 8 | 9 | // This set of controls performs orbiting, dollying (zooming), and panning. 10 | // Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default). 11 | // 12 | // Orbit - left mouse / touch: one finger move 13 | // Zoom - middle mouse, or mousewheel / touch: two finger spread or squish 14 | // Pan - right mouse, or arrow keys / touch: three finger swipe 15 | 16 | THREE.OrbitControls = function ( object, domElement ) { 17 | 18 | this.object = object; 19 | 20 | this.domElement = ( domElement !== undefined ) ? domElement : document; 21 | 22 | // Set to false to disable this control 23 | this.enabled = true; 24 | 25 | // "target" sets the location of focus, where the object orbits around 26 | this.target = new THREE.Vector3(); 27 | 28 | // How far you can dolly in and out ( PerspectiveCamera only ) 29 | this.minDistance = 0; 30 | this.maxDistance = Infinity; 31 | 32 | // How far you can zoom in and out ( OrthographicCamera only ) 33 | this.minZoom = 0; 34 | this.maxZoom = Infinity; 35 | 36 | // How far you can orbit vertically, upper and lower limits. 37 | // Range is 0 to Math.PI radians. 38 | this.minPolarAngle = 0; // radians 39 | this.maxPolarAngle = Math.PI; // radians 40 | 41 | // How far you can orbit horizontally, upper and lower limits. 42 | // If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ]. 43 | this.minAzimuthAngle = - Infinity; // radians 44 | this.maxAzimuthAngle = Infinity; // radians 45 | 46 | // Set to true to enable damping (inertia) 47 | // If damping is enabled, you must call controls.update() in your animation loop 48 | this.enableDamping = false; 49 | this.dampingFactor = 0.25; 50 | 51 | // This option actually enables dollying in and out; left as "zoom" for backwards compatibility. 52 | // Set to false to disable zooming 53 | this.enableZoom = true; 54 | this.zoomSpeed = 1.0; 55 | 56 | // Set to false to disable rotating 57 | this.enableRotate = true; 58 | this.rotateSpeed = 1.0; 59 | 60 | // Set to false to disable panning 61 | this.enablePan = true; 62 | this.panSpeed = 1.0; 63 | this.panningMode = THREE.ScreenSpacePanning; // alternate THREE.HorizontalPanning 64 | this.keyPanSpeed = 7.0; // pixels moved per arrow key push 65 | 66 | // Set to true to automatically rotate around the target 67 | // If auto-rotate is enabled, you must call controls.update() in your animation loop 68 | this.autoRotate = false; 69 | this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60 70 | 71 | // Set to false to disable use of the keys 72 | this.enableKeys = true; 73 | 74 | // The four arrow keys 75 | this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 }; 76 | 77 | // Mouse buttons 78 | this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT }; 79 | 80 | // for reset 81 | this.target0 = this.target.clone(); 82 | this.position0 = this.object.position.clone(); 83 | this.zoom0 = this.object.zoom; 84 | 85 | // 86 | // public methods 87 | // 88 | 89 | this.getPolarAngle = function () { 90 | 91 | return spherical.phi; 92 | 93 | }; 94 | 95 | this.getAzimuthalAngle = function () { 96 | 97 | return spherical.theta; 98 | 99 | }; 100 | 101 | this.saveState = function () { 102 | 103 | scope.target0.copy( scope.target ); 104 | scope.position0.copy( scope.object.position ); 105 | scope.zoom0 = scope.object.zoom; 106 | 107 | }; 108 | 109 | this.reset = function () { 110 | 111 | scope.target.copy( scope.target0 ); 112 | scope.object.position.copy( scope.position0 ); 113 | scope.object.zoom = scope.zoom0; 114 | 115 | scope.object.updateProjectionMatrix(); 116 | scope.dispatchEvent( changeEvent ); 117 | 118 | scope.update(); 119 | 120 | state = STATE.NONE; 121 | 122 | }; 123 | 124 | // this method is exposed, but perhaps it would be better if we can make it private... 125 | this.update = function () { 126 | 127 | var offset = new THREE.Vector3(); 128 | 129 | // so camera.up is the orbit axis 130 | var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) ); 131 | var quatInverse = quat.clone().inverse(); 132 | 133 | var lastPosition = new THREE.Vector3(); 134 | var lastQuaternion = new THREE.Quaternion(); 135 | 136 | return function update() { 137 | 138 | var position = scope.object.position; 139 | 140 | offset.copy( position ).sub( scope.target ); 141 | 142 | // rotate offset to "y-axis-is-up" space 143 | offset.applyQuaternion( quat ); 144 | 145 | // angle from z-axis around y-axis 146 | spherical.setFromVector3( offset ); 147 | 148 | if ( scope.autoRotate && state === STATE.NONE ) { 149 | 150 | rotateLeft( getAutoRotationAngle() ); 151 | 152 | } 153 | 154 | spherical.theta += sphericalDelta.theta; 155 | spherical.phi += sphericalDelta.phi; 156 | 157 | // restrict theta to be between desired limits 158 | spherical.theta = Math.max( scope.minAzimuthAngle, Math.min( scope.maxAzimuthAngle, spherical.theta ) ); 159 | 160 | // restrict phi to be between desired limits 161 | spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) ); 162 | 163 | spherical.makeSafe(); 164 | 165 | 166 | spherical.radius *= scale; 167 | 168 | // restrict radius to be between desired limits 169 | spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) ); 170 | 171 | // move target to panned location 172 | scope.target.add( panOffset ); 173 | 174 | offset.setFromSpherical( spherical ); 175 | 176 | // rotate offset back to "camera-up-vector-is-up" space 177 | offset.applyQuaternion( quatInverse ); 178 | 179 | position.copy( scope.target ).add( offset ); 180 | 181 | scope.object.lookAt( scope.target ); 182 | 183 | if ( scope.enableDamping === true ) { 184 | 185 | sphericalDelta.theta *= ( 1 - scope.dampingFactor ); 186 | sphericalDelta.phi *= ( 1 - scope.dampingFactor ); 187 | 188 | panOffset.multiplyScalar( 1 - scope.dampingFactor ); 189 | 190 | } else { 191 | 192 | sphericalDelta.set( 0, 0, 0 ); 193 | 194 | panOffset.set( 0, 0, 0 ); 195 | 196 | } 197 | 198 | scale = 1; 199 | 200 | // update condition is: 201 | // min(camera displacement, camera rotation in radians)^2 > EPS 202 | // using small-angle approximation cos(x/2) = 1 - x^2 / 8 203 | 204 | if ( zoomChanged || 205 | lastPosition.distanceToSquared( scope.object.position ) > EPS || 206 | 8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) { 207 | 208 | scope.dispatchEvent( changeEvent ); 209 | 210 | lastPosition.copy( scope.object.position ); 211 | lastQuaternion.copy( scope.object.quaternion ); 212 | zoomChanged = false; 213 | 214 | return true; 215 | 216 | } 217 | 218 | return false; 219 | 220 | }; 221 | 222 | }(); 223 | 224 | this.dispose = function () { 225 | 226 | scope.domElement.removeEventListener( 'contextmenu', onContextMenu, false ); 227 | scope.domElement.removeEventListener( 'mousedown', onMouseDown, false ); 228 | scope.domElement.removeEventListener( 'wheel', onMouseWheel, false ); 229 | 230 | scope.domElement.removeEventListener( 'touchstart', onTouchStart, false ); 231 | scope.domElement.removeEventListener( 'touchend', onTouchEnd, false ); 232 | scope.domElement.removeEventListener( 'touchmove', onTouchMove, false ); 233 | 234 | document.removeEventListener( 'mousemove', onMouseMove, false ); 235 | document.removeEventListener( 'mouseup', onMouseUp, false ); 236 | 237 | window.removeEventListener( 'keydown', onKeyDown, false ); 238 | 239 | //scope.dispatchEvent( { type: 'dispose' } ); // should this be added here? 240 | 241 | }; 242 | 243 | // 244 | // internals 245 | // 246 | 247 | var scope = this; 248 | 249 | var changeEvent = { type: 'change' }; 250 | var startEvent = { type: 'start' }; 251 | var endEvent = { type: 'end' }; 252 | 253 | var STATE = { NONE: - 1, ROTATE: 0, DOLLY: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_DOLLY: 4, TOUCH_PAN: 5 }; 254 | 255 | var state = STATE.NONE; 256 | 257 | var EPS = 0.000001; 258 | 259 | // current position in spherical coordinates 260 | var spherical = new THREE.Spherical(); 261 | var sphericalDelta = new THREE.Spherical(); 262 | 263 | var scale = 1; 264 | var panOffset = new THREE.Vector3(); 265 | var zoomChanged = false; 266 | 267 | var rotateStart = new THREE.Vector2(); 268 | var rotateEnd = new THREE.Vector2(); 269 | var rotateDelta = new THREE.Vector2(); 270 | 271 | var panStart = new THREE.Vector2(); 272 | var panEnd = new THREE.Vector2(); 273 | var panDelta = new THREE.Vector2(); 274 | 275 | var dollyStart = new THREE.Vector2(); 276 | var dollyEnd = new THREE.Vector2(); 277 | var dollyDelta = new THREE.Vector2(); 278 | 279 | function getAutoRotationAngle() { 280 | 281 | return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed; 282 | 283 | } 284 | 285 | function getZoomScale() { 286 | 287 | return Math.pow( 0.95, scope.zoomSpeed ); 288 | 289 | } 290 | 291 | function rotateLeft( angle ) { 292 | 293 | sphericalDelta.theta -= angle; 294 | 295 | } 296 | 297 | function rotateUp( angle ) { 298 | 299 | sphericalDelta.phi -= angle; 300 | 301 | } 302 | 303 | var panLeft = function () { 304 | 305 | var v = new THREE.Vector3(); 306 | 307 | return function panLeft( distance, objectMatrix ) { 308 | 309 | v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix 310 | v.multiplyScalar( - distance ); 311 | 312 | panOffset.add( v ); 313 | 314 | }; 315 | 316 | }(); 317 | 318 | var panUp = function () { 319 | 320 | var v = new THREE.Vector3(); 321 | 322 | return function panUp( distance, objectMatrix ) { 323 | 324 | switch ( scope.panningMode ) { 325 | 326 | case THREE.ScreenSpacePanning: 327 | 328 | v.setFromMatrixColumn( objectMatrix, 1 ); 329 | break; 330 | 331 | case THREE.HorizontalPanning: 332 | 333 | v.setFromMatrixColumn( objectMatrix, 0 ); 334 | v.crossVectors( scope.object.up, v ); 335 | break; 336 | 337 | } 338 | 339 | v.multiplyScalar( distance ); 340 | 341 | panOffset.add( v ); 342 | 343 | }; 344 | 345 | }(); 346 | 347 | // deltaX and deltaY are in pixels; right and down are positive 348 | var pan = function () { 349 | 350 | var offset = new THREE.Vector3(); 351 | 352 | return function pan( deltaX, deltaY ) { 353 | 354 | var element = scope.domElement === document ? scope.domElement.body : scope.domElement; 355 | 356 | if ( scope.object.isPerspectiveCamera ) { 357 | 358 | // perspective 359 | var position = scope.object.position; 360 | offset.copy( position ).sub( scope.target ); 361 | var targetDistance = offset.length(); 362 | 363 | // half of the fov is center to top of screen 364 | targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 ); 365 | 366 | // we actually don't use screenWidth, since perspective camera is fixed to screen height 367 | panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix ); 368 | panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix ); 369 | 370 | } else if ( scope.object.isOrthographicCamera ) { 371 | 372 | // orthographic 373 | panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix ); 374 | panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix ); 375 | 376 | } else { 377 | 378 | // camera neither orthographic nor perspective 379 | console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' ); 380 | scope.enablePan = false; 381 | 382 | } 383 | 384 | }; 385 | 386 | }(); 387 | 388 | function dollyIn( dollyScale ) { 389 | 390 | if ( scope.object.isPerspectiveCamera ) { 391 | 392 | scale /= dollyScale; 393 | 394 | } else if ( scope.object.isOrthographicCamera ) { 395 | 396 | scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom * dollyScale ) ); 397 | scope.object.updateProjectionMatrix(); 398 | zoomChanged = true; 399 | 400 | } else { 401 | 402 | console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' ); 403 | scope.enableZoom = false; 404 | 405 | } 406 | 407 | } 408 | 409 | function dollyOut( dollyScale ) { 410 | 411 | if ( scope.object.isPerspectiveCamera ) { 412 | 413 | scale *= dollyScale; 414 | 415 | } else if ( scope.object.isOrthographicCamera ) { 416 | 417 | scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / dollyScale ) ); 418 | scope.object.updateProjectionMatrix(); 419 | zoomChanged = true; 420 | 421 | } else { 422 | 423 | console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' ); 424 | scope.enableZoom = false; 425 | 426 | } 427 | 428 | } 429 | 430 | // 431 | // event callbacks - update the object state 432 | // 433 | 434 | function handleMouseDownRotate( event ) { 435 | 436 | //console.log( 'handleMouseDownRotate' ); 437 | 438 | rotateStart.set( event.clientX, event.clientY ); 439 | 440 | } 441 | 442 | function handleMouseDownDolly( event ) { 443 | 444 | //console.log( 'handleMouseDownDolly' ); 445 | 446 | dollyStart.set( event.clientX, event.clientY ); 447 | 448 | } 449 | 450 | function handleMouseDownPan( event ) { 451 | 452 | //console.log( 'handleMouseDownPan' ); 453 | 454 | panStart.set( event.clientX, event.clientY ); 455 | 456 | } 457 | 458 | function handleMouseMoveRotate( event ) { 459 | 460 | //console.log( 'handleMouseMoveRotate' ); 461 | 462 | rotateEnd.set( event.clientX, event.clientY ); 463 | 464 | rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );; 465 | 466 | var element = scope.domElement === document ? scope.domElement.body : scope.domElement; 467 | 468 | // rotating across whole screen goes 360 degrees around 469 | rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth ); 470 | 471 | // rotating up and down along whole screen attempts to go 360, but limited to 180 472 | rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight ); 473 | 474 | rotateStart.copy( rotateEnd ); 475 | 476 | scope.update(); 477 | 478 | } 479 | 480 | function handleMouseMoveDolly( event ) { 481 | 482 | //console.log( 'handleMouseMoveDolly' ); 483 | 484 | dollyEnd.set( event.clientX, event.clientY ); 485 | 486 | dollyDelta.subVectors( dollyEnd, dollyStart ); 487 | 488 | if ( dollyDelta.y > 0 ) { 489 | 490 | dollyIn( getZoomScale() ); 491 | 492 | } else if ( dollyDelta.y < 0 ) { 493 | 494 | dollyOut( getZoomScale() ); 495 | 496 | } 497 | 498 | dollyStart.copy( dollyEnd ); 499 | 500 | scope.update(); 501 | 502 | } 503 | 504 | function handleMouseMovePan( event ) { 505 | 506 | //console.log( 'handleMouseMovePan' ); 507 | 508 | panEnd.set( event.clientX, event.clientY ); 509 | 510 | panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed ); 511 | 512 | pan( panDelta.x, panDelta.y ); 513 | 514 | panStart.copy( panEnd ); 515 | 516 | scope.update(); 517 | 518 | } 519 | 520 | function handleMouseUp( event ) { 521 | 522 | // console.log( 'handleMouseUp' ); 523 | 524 | } 525 | 526 | function handleMouseWheel( event ) { 527 | 528 | // console.log( 'handleMouseWheel' ); 529 | 530 | if ( event.deltaY < 0 ) { 531 | 532 | dollyOut( getZoomScale() ); 533 | 534 | } else if ( event.deltaY > 0 ) { 535 | 536 | dollyIn( getZoomScale() ); 537 | 538 | } 539 | 540 | scope.update(); 541 | 542 | } 543 | 544 | function handleKeyDown( event ) { 545 | 546 | //console.log( 'handleKeyDown' ); 547 | 548 | switch ( event.keyCode ) { 549 | 550 | case scope.keys.UP: 551 | pan( 0, scope.keyPanSpeed ); 552 | scope.update(); 553 | break; 554 | 555 | case scope.keys.BOTTOM: 556 | pan( 0, - scope.keyPanSpeed ); 557 | scope.update(); 558 | break; 559 | 560 | case scope.keys.LEFT: 561 | pan( scope.keyPanSpeed, 0 ); 562 | scope.update(); 563 | break; 564 | 565 | case scope.keys.RIGHT: 566 | pan( - scope.keyPanSpeed, 0 ); 567 | scope.update(); 568 | break; 569 | 570 | } 571 | 572 | } 573 | 574 | function handleTouchStartRotate( event ) { 575 | 576 | //console.log( 'handleTouchStartRotate' ); 577 | 578 | rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); 579 | 580 | } 581 | 582 | function handleTouchStartDolly( event ) { 583 | 584 | //console.log( 'handleTouchStartDolly' ); 585 | 586 | var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; 587 | var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; 588 | 589 | var distance = Math.sqrt( dx * dx + dy * dy ); 590 | 591 | dollyStart.set( 0, distance ); 592 | 593 | } 594 | 595 | function handleTouchStartPan( event ) { 596 | 597 | //console.log( 'handleTouchStartPan' ); 598 | 599 | panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); 600 | 601 | } 602 | 603 | function handleTouchMoveRotate( event ) { 604 | 605 | //console.log( 'handleTouchMoveRotate' ); 606 | 607 | rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); 608 | 609 | rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed ); 610 | 611 | var element = scope.domElement === document ? scope.domElement.body : scope.domElement; 612 | 613 | // rotating across whole screen goes 360 degrees around 614 | rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth ); 615 | 616 | // rotating up and down along whole screen attempts to go 360, but limited to 180 617 | rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight ); 618 | 619 | rotateStart.copy( rotateEnd ); 620 | 621 | scope.update(); 622 | 623 | } 624 | 625 | function handleTouchMoveDolly( event ) { 626 | 627 | //console.log( 'handleTouchMoveDolly' ); 628 | 629 | var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX; 630 | var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY; 631 | 632 | var distance = Math.sqrt( dx * dx + dy * dy ); 633 | 634 | dollyEnd.set( 0, distance ); 635 | 636 | dollyDelta.subVectors( dollyEnd, dollyStart ); 637 | 638 | if ( dollyDelta.y > 0 ) { 639 | 640 | dollyOut( getZoomScale() ); 641 | 642 | } else if ( dollyDelta.y < 0 ) { 643 | 644 | dollyIn( getZoomScale() ); 645 | 646 | } 647 | 648 | dollyStart.copy( dollyEnd ); 649 | 650 | scope.update(); 651 | 652 | } 653 | 654 | function handleTouchMovePan( event ) { 655 | 656 | //console.log( 'handleTouchMovePan' ); 657 | 658 | panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ); 659 | 660 | panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed ); 661 | 662 | pan( panDelta.x, panDelta.y ); 663 | 664 | panStart.copy( panEnd ); 665 | 666 | scope.update(); 667 | 668 | } 669 | 670 | function handleTouchEnd( event ) { 671 | 672 | //console.log( 'handleTouchEnd' ); 673 | 674 | } 675 | 676 | // 677 | // event handlers - FSM: listen for events and reset state 678 | // 679 | 680 | function onMouseDown( event ) { 681 | 682 | if ( scope.enabled === false ) return; 683 | 684 | event.preventDefault(); 685 | 686 | switch ( event.button ) { 687 | 688 | case scope.mouseButtons.ORBIT: 689 | 690 | if ( scope.enableRotate === false ) return; 691 | 692 | handleMouseDownRotate( event ); 693 | 694 | state = STATE.ROTATE; 695 | 696 | break; 697 | 698 | case scope.mouseButtons.ZOOM: 699 | 700 | if ( scope.enableZoom === false ) return; 701 | 702 | handleMouseDownDolly( event ); 703 | 704 | state = STATE.DOLLY; 705 | 706 | break; 707 | 708 | case scope.mouseButtons.PAN: 709 | 710 | if ( scope.enablePan === false ) return; 711 | 712 | handleMouseDownPan( event ); 713 | 714 | state = STATE.PAN; 715 | 716 | break; 717 | 718 | } 719 | 720 | if ( state !== STATE.NONE ) { 721 | 722 | document.addEventListener( 'mousemove', onMouseMove, false ); 723 | document.addEventListener( 'mouseup', onMouseUp, false ); 724 | 725 | scope.dispatchEvent( startEvent ); 726 | 727 | } 728 | 729 | } 730 | 731 | function onMouseMove( event ) { 732 | 733 | if ( scope.enabled === false ) return; 734 | 735 | event.preventDefault(); 736 | 737 | switch ( state ) { 738 | 739 | case STATE.ROTATE: 740 | 741 | if ( scope.enableRotate === false ) return; 742 | 743 | handleMouseMoveRotate( event ); 744 | 745 | break; 746 | 747 | case STATE.DOLLY: 748 | 749 | if ( scope.enableZoom === false ) return; 750 | 751 | handleMouseMoveDolly( event ); 752 | 753 | break; 754 | 755 | case STATE.PAN: 756 | 757 | if ( scope.enablePan === false ) return; 758 | 759 | handleMouseMovePan( event ); 760 | 761 | break; 762 | 763 | } 764 | 765 | } 766 | 767 | function onMouseUp( event ) { 768 | 769 | if ( scope.enabled === false ) return; 770 | 771 | handleMouseUp( event ); 772 | 773 | document.removeEventListener( 'mousemove', onMouseMove, false ); 774 | document.removeEventListener( 'mouseup', onMouseUp, false ); 775 | 776 | scope.dispatchEvent( endEvent ); 777 | 778 | state = STATE.NONE; 779 | 780 | } 781 | 782 | function onMouseWheel( event ) { 783 | 784 | if ( scope.enabled === false || scope.enableZoom === false || ( state !== STATE.NONE && state !== STATE.ROTATE ) ) return; 785 | 786 | event.preventDefault(); 787 | event.stopPropagation(); 788 | 789 | scope.dispatchEvent( startEvent ); 790 | 791 | handleMouseWheel( event ); 792 | 793 | scope.dispatchEvent( endEvent ); 794 | 795 | } 796 | 797 | function onKeyDown( event ) { 798 | 799 | if ( scope.enabled === false || scope.enableKeys === false || scope.enablePan === false ) return; 800 | 801 | handleKeyDown( event ); 802 | 803 | } 804 | 805 | function onTouchStart( event ) { 806 | 807 | if ( scope.enabled === false ) return; 808 | 809 | switch ( event.touches.length ) { 810 | 811 | case 1: // one-fingered touch: rotate 812 | 813 | if ( scope.enableRotate === false ) return; 814 | 815 | handleTouchStartRotate( event ); 816 | 817 | state = STATE.TOUCH_ROTATE; 818 | 819 | break; 820 | 821 | case 2: // two-fingered touch: dolly 822 | 823 | if ( scope.enableZoom === false ) return; 824 | 825 | handleTouchStartDolly( event ); 826 | 827 | state = STATE.TOUCH_DOLLY; 828 | 829 | break; 830 | 831 | case 3: // three-fingered touch: pan 832 | 833 | if ( scope.enablePan === false ) return; 834 | 835 | handleTouchStartPan( event ); 836 | 837 | state = STATE.TOUCH_PAN; 838 | 839 | break; 840 | 841 | default: 842 | 843 | state = STATE.NONE; 844 | 845 | } 846 | 847 | if ( state !== STATE.NONE ) { 848 | 849 | scope.dispatchEvent( startEvent ); 850 | 851 | } 852 | 853 | } 854 | 855 | function onTouchMove( event ) { 856 | 857 | if ( scope.enabled === false ) return; 858 | 859 | event.preventDefault(); 860 | event.stopPropagation(); 861 | 862 | switch ( event.touches.length ) { 863 | 864 | case 1: // one-fingered touch: rotate 865 | 866 | if ( scope.enableRotate === false ) return; 867 | if ( state !== STATE.TOUCH_ROTATE ) return; // is this needed?... 868 | 869 | handleTouchMoveRotate( event ); 870 | 871 | break; 872 | 873 | case 2: // two-fingered touch: dolly 874 | 875 | if ( scope.enableZoom === false ) return; 876 | if ( state !== STATE.TOUCH_DOLLY ) return; // is this needed?... 877 | 878 | handleTouchMoveDolly( event ); 879 | 880 | break; 881 | 882 | case 3: // three-fingered touch: pan 883 | 884 | if ( scope.enablePan === false ) return; 885 | if ( state !== STATE.TOUCH_PAN ) return; // is this needed?... 886 | 887 | handleTouchMovePan( event ); 888 | 889 | break; 890 | 891 | default: 892 | 893 | state = STATE.NONE; 894 | 895 | } 896 | 897 | } 898 | 899 | function onTouchEnd( event ) { 900 | 901 | if ( scope.enabled === false ) return; 902 | 903 | handleTouchEnd( event ); 904 | 905 | scope.dispatchEvent( endEvent ); 906 | 907 | state = STATE.NONE; 908 | 909 | } 910 | 911 | function onContextMenu( event ) { 912 | 913 | if ( scope.enabled === false ) return; 914 | 915 | event.preventDefault(); 916 | 917 | } 918 | 919 | // 920 | 921 | scope.domElement.addEventListener( 'contextmenu', onContextMenu, false ); 922 | 923 | scope.domElement.addEventListener( 'mousedown', onMouseDown, false ); 924 | scope.domElement.addEventListener( 'wheel', onMouseWheel, false ); 925 | 926 | scope.domElement.addEventListener( 'touchstart', onTouchStart, false ); 927 | scope.domElement.addEventListener( 'touchend', onTouchEnd, false ); 928 | scope.domElement.addEventListener( 'touchmove', onTouchMove, false ); 929 | 930 | window.addEventListener( 'keydown', onKeyDown, false ); 931 | 932 | // force an update at start 933 | 934 | this.update(); 935 | 936 | }; 937 | 938 | THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype ); 939 | THREE.OrbitControls.prototype.constructor = THREE.OrbitControls; 940 | 941 | Object.defineProperties( THREE.OrbitControls.prototype, { 942 | 943 | center: { 944 | 945 | get: function () { 946 | 947 | console.warn( 'THREE.OrbitControls: .center has been renamed to .target' ); 948 | return this.target; 949 | 950 | } 951 | 952 | }, 953 | 954 | // backward compatibility 955 | 956 | noZoom: { 957 | 958 | get: function () { 959 | 960 | console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' ); 961 | return ! this.enableZoom; 962 | 963 | }, 964 | 965 | set: function ( value ) { 966 | 967 | console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' ); 968 | this.enableZoom = ! value; 969 | 970 | } 971 | 972 | }, 973 | 974 | noRotate: { 975 | 976 | get: function () { 977 | 978 | console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' ); 979 | return ! this.enableRotate; 980 | 981 | }, 982 | 983 | set: function ( value ) { 984 | 985 | console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' ); 986 | this.enableRotate = ! value; 987 | 988 | } 989 | 990 | }, 991 | 992 | noPan: { 993 | 994 | get: function () { 995 | 996 | console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' ); 997 | return ! this.enablePan; 998 | 999 | }, 1000 | 1001 | set: function ( value ) { 1002 | 1003 | console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' ); 1004 | this.enablePan = ! value; 1005 | 1006 | } 1007 | 1008 | }, 1009 | 1010 | noKeys: { 1011 | 1012 | get: function () { 1013 | 1014 | console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' ); 1015 | return ! this.enableKeys; 1016 | 1017 | }, 1018 | 1019 | set: function ( value ) { 1020 | 1021 | console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' ); 1022 | this.enableKeys = ! value; 1023 | 1024 | } 1025 | 1026 | }, 1027 | 1028 | staticMoving: { 1029 | 1030 | get: function () { 1031 | 1032 | console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' ); 1033 | return ! this.enableDamping; 1034 | 1035 | }, 1036 | 1037 | set: function ( value ) { 1038 | 1039 | console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' ); 1040 | this.enableDamping = ! value; 1041 | 1042 | } 1043 | 1044 | }, 1045 | 1046 | dynamicDampingFactor: { 1047 | 1048 | get: function () { 1049 | 1050 | console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' ); 1051 | return this.dampingFactor; 1052 | 1053 | }, 1054 | 1055 | set: function ( value ) { 1056 | 1057 | console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' ); 1058 | this.dampingFactor = value; 1059 | 1060 | } 1061 | 1062 | } 1063 | 1064 | } ); 1065 | 1066 | THREE.ScreenSpacePanning = 0; 1067 | THREE.HorizontalPanning = 1; 1068 | -------------------------------------------------------------------------------- /lib/OpenSimplexNoise.js: -------------------------------------------------------------------------------- 1 | // Plain JS version of Josh Forisha's implementation of opensimplex noise 2 | // https://github.com/joshforisha/open-simplex-noise-js 3 | // This version is currently posted here https://gist.github.com/PARC6502/85c99c04c9b3c6ae52c3c27605b4df0a 4 | // Will probably be cleaned up and have its own repo, at some point... 5 | 6 | "use strict"; 7 | var OpenSimplexNoise; 8 | 9 | (function () { 10 | var constants_1 = { 11 | NORM_2D: 1.0 / 47.0, 12 | NORM_3D: 1.0 / 103.0, 13 | NORM_4D: 1.0 / 30.0, 14 | SQUISH_2D: (Math.sqrt(2 + 1) - 1) / 2, 15 | SQUISH_3D: (Math.sqrt(3 + 1) - 1) / 3, 16 | SQUISH_4D: (Math.sqrt(4 + 1) - 1) / 4, 17 | STRETCH_2D: (1 / Math.sqrt(2 + 1) - 1) / 2, 18 | STRETCH_3D: (1 / Math.sqrt(3 + 1) - 1) / 3, 19 | STRETCH_4D: (1 / Math.sqrt(4 + 1) - 1) / 4, 20 | base2D: [ 21 | [1, 1, 0, 1, 0, 1, 0, 0, 0], 22 | [1, 1, 0, 1, 0, 1, 2, 1, 1], 23 | ], 24 | base3D: [ 25 | [0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1], 26 | [2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1, 3, 1, 1, 1], 27 | [1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1], 28 | ], 29 | base4D: [ 30 | [0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1], 31 | [3, 1, 1, 1, 0, 3, 1, 1, 0, 1, 3, 1, 0, 1, 1, 3, 0, 1, 1, 1, 4, 1, 1, 1, 1], 32 | [ 33 | 1, 34 | 1, 35 | 0, 36 | 0, 37 | 0, 38 | 1, 39 | 0, 40 | 1, 41 | 0, 42 | 0, 43 | 1, 44 | 0, 45 | 0, 46 | 1, 47 | 0, 48 | 1, 49 | 0, 50 | 0, 51 | 0, 52 | 1, 53 | 2, 54 | 1, 55 | 1, 56 | 0, 57 | 0, 58 | 2, 59 | 1, 60 | 0, 61 | 1, 62 | 0, 63 | 2, 64 | 1, 65 | 0, 66 | 0, 67 | 1, 68 | 2, 69 | 0, 70 | 1, 71 | 1, 72 | 0, 73 | 2, 74 | 0, 75 | 1, 76 | 0, 77 | 1, 78 | 2, 79 | 0, 80 | 0, 81 | 1, 82 | 1, 83 | ], 84 | [ 85 | 3, 86 | 1, 87 | 1, 88 | 1, 89 | 0, 90 | 3, 91 | 1, 92 | 1, 93 | 0, 94 | 1, 95 | 3, 96 | 1, 97 | 0, 98 | 1, 99 | 1, 100 | 3, 101 | 0, 102 | 1, 103 | 1, 104 | 1, 105 | 2, 106 | 1, 107 | 1, 108 | 0, 109 | 0, 110 | 2, 111 | 1, 112 | 0, 113 | 1, 114 | 0, 115 | 2, 116 | 1, 117 | 0, 118 | 0, 119 | 1, 120 | 2, 121 | 0, 122 | 1, 123 | 1, 124 | 0, 125 | 2, 126 | 0, 127 | 1, 128 | 0, 129 | 1, 130 | 2, 131 | 0, 132 | 0, 133 | 1, 134 | 1, 135 | ], 136 | ], 137 | gradients2D: [5, 2, 2, 5, -5, 2, -2, 5, 5, -2, 2, -5, -5, -2, -2, -5], 138 | gradients3D: [ 139 | -11, 140 | 4, 141 | 4, 142 | -4, 143 | 11, 144 | 4, 145 | -4, 146 | 4, 147 | 11, 148 | 11, 149 | 4, 150 | 4, 151 | 4, 152 | 11, 153 | 4, 154 | 4, 155 | 4, 156 | 11, 157 | -11, 158 | -4, 159 | 4, 160 | -4, 161 | -11, 162 | 4, 163 | -4, 164 | -4, 165 | 11, 166 | 11, 167 | -4, 168 | 4, 169 | 4, 170 | -11, 171 | 4, 172 | 4, 173 | -4, 174 | 11, 175 | -11, 176 | 4, 177 | -4, 178 | -4, 179 | 11, 180 | -4, 181 | -4, 182 | 4, 183 | -11, 184 | 11, 185 | 4, 186 | -4, 187 | 4, 188 | 11, 189 | -4, 190 | 4, 191 | 4, 192 | -11, 193 | -11, 194 | -4, 195 | -4, 196 | -4, 197 | -11, 198 | -4, 199 | -4, 200 | -4, 201 | -11, 202 | 11, 203 | -4, 204 | -4, 205 | 4, 206 | -11, 207 | -4, 208 | 4, 209 | -4, 210 | -11, 211 | ], 212 | gradients4D: [ 213 | 3, 214 | 1, 215 | 1, 216 | 1, 217 | 1, 218 | 3, 219 | 1, 220 | 1, 221 | 1, 222 | 1, 223 | 3, 224 | 1, 225 | 1, 226 | 1, 227 | 1, 228 | 3, 229 | -3, 230 | 1, 231 | 1, 232 | 1, 233 | -1, 234 | 3, 235 | 1, 236 | 1, 237 | -1, 238 | 1, 239 | 3, 240 | 1, 241 | -1, 242 | 1, 243 | 1, 244 | 3, 245 | 3, 246 | -1, 247 | 1, 248 | 1, 249 | 1, 250 | -3, 251 | 1, 252 | 1, 253 | 1, 254 | -1, 255 | 3, 256 | 1, 257 | 1, 258 | -1, 259 | 1, 260 | 3, 261 | -3, 262 | -1, 263 | 1, 264 | 1, 265 | -1, 266 | -3, 267 | 1, 268 | 1, 269 | -1, 270 | -1, 271 | 3, 272 | 1, 273 | -1, 274 | -1, 275 | 1, 276 | 3, 277 | 3, 278 | 1, 279 | -1, 280 | 1, 281 | 1, 282 | 3, 283 | -1, 284 | 1, 285 | 1, 286 | 1, 287 | -3, 288 | 1, 289 | 1, 290 | 1, 291 | -1, 292 | 3, 293 | -3, 294 | 1, 295 | -1, 296 | 1, 297 | -1, 298 | 3, 299 | -1, 300 | 1, 301 | -1, 302 | 1, 303 | -3, 304 | 1, 305 | -1, 306 | 1, 307 | -1, 308 | 3, 309 | 3, 310 | -1, 311 | -1, 312 | 1, 313 | 1, 314 | -3, 315 | -1, 316 | 1, 317 | 1, 318 | -1, 319 | -3, 320 | 1, 321 | 1, 322 | -1, 323 | -1, 324 | 3, 325 | -3, 326 | -1, 327 | -1, 328 | 1, 329 | -1, 330 | -3, 331 | -1, 332 | 1, 333 | -1, 334 | -1, 335 | -3, 336 | 1, 337 | -1, 338 | -1, 339 | -1, 340 | 3, 341 | 3, 342 | 1, 343 | 1, 344 | -1, 345 | 1, 346 | 3, 347 | 1, 348 | -1, 349 | 1, 350 | 1, 351 | 3, 352 | -1, 353 | 1, 354 | 1, 355 | 1, 356 | -3, 357 | -3, 358 | 1, 359 | 1, 360 | -1, 361 | -1, 362 | 3, 363 | 1, 364 | -1, 365 | -1, 366 | 1, 367 | 3, 368 | -1, 369 | -1, 370 | 1, 371 | 1, 372 | -3, 373 | 3, 374 | -1, 375 | 1, 376 | -1, 377 | 1, 378 | -3, 379 | 1, 380 | -1, 381 | 1, 382 | -1, 383 | 3, 384 | -1, 385 | 1, 386 | -1, 387 | 1, 388 | -3, 389 | -3, 390 | -1, 391 | 1, 392 | -1, 393 | -1, 394 | -3, 395 | 1, 396 | -1, 397 | -1, 398 | -1, 399 | 3, 400 | -1, 401 | -1, 402 | -1, 403 | 1, 404 | -3, 405 | 3, 406 | 1, 407 | -1, 408 | -1, 409 | 1, 410 | 3, 411 | -1, 412 | -1, 413 | 1, 414 | 1, 415 | -3, 416 | -1, 417 | 1, 418 | 1, 419 | -1, 420 | -3, 421 | -3, 422 | 1, 423 | -1, 424 | -1, 425 | -1, 426 | 3, 427 | -1, 428 | -1, 429 | -1, 430 | 1, 431 | -3, 432 | -1, 433 | -1, 434 | 1, 435 | -1, 436 | -3, 437 | 3, 438 | -1, 439 | -1, 440 | -1, 441 | 1, 442 | -3, 443 | -1, 444 | -1, 445 | 1, 446 | -1, 447 | -3, 448 | -1, 449 | 1, 450 | -1, 451 | -1, 452 | -3, 453 | -3, 454 | -1, 455 | -1, 456 | -1, 457 | -1, 458 | -3, 459 | -1, 460 | -1, 461 | -1, 462 | -1, 463 | -3, 464 | -1, 465 | -1, 466 | -1, 467 | -1, 468 | -3, 469 | ], 470 | lookupPairs2D: [0, 1, 1, 0, 4, 1, 17, 0, 20, 2, 21, 2, 22, 5, 23, 5, 26, 4, 39, 3, 42, 4, 43, 3], 471 | lookupPairs3D: [ 472 | 0, 473 | 2, 474 | 1, 475 | 1, 476 | 2, 477 | 2, 478 | 5, 479 | 1, 480 | 6, 481 | 0, 482 | 7, 483 | 0, 484 | 32, 485 | 2, 486 | 34, 487 | 2, 488 | 129, 489 | 1, 490 | 133, 491 | 1, 492 | 160, 493 | 5, 494 | 161, 495 | 5, 496 | 518, 497 | 0, 498 | 519, 499 | 0, 500 | 546, 501 | 4, 502 | 550, 503 | 4, 504 | 645, 505 | 3, 506 | 647, 507 | 3, 508 | 672, 509 | 5, 510 | 673, 511 | 5, 512 | 674, 513 | 4, 514 | 677, 515 | 3, 516 | 678, 517 | 4, 518 | 679, 519 | 3, 520 | 680, 521 | 13, 522 | 681, 523 | 13, 524 | 682, 525 | 12, 526 | 685, 527 | 14, 528 | 686, 529 | 12, 530 | 687, 531 | 14, 532 | 712, 533 | 20, 534 | 714, 535 | 18, 536 | 809, 537 | 21, 538 | 813, 539 | 23, 540 | 840, 541 | 20, 542 | 841, 543 | 21, 544 | 1198, 545 | 19, 546 | 1199, 547 | 22, 548 | 1226, 549 | 18, 550 | 1230, 551 | 19, 552 | 1325, 553 | 23, 554 | 1327, 555 | 22, 556 | 1352, 557 | 15, 558 | 1353, 559 | 17, 560 | 1354, 561 | 15, 562 | 1357, 563 | 17, 564 | 1358, 565 | 16, 566 | 1359, 567 | 16, 568 | 1360, 569 | 11, 570 | 1361, 571 | 10, 572 | 1362, 573 | 11, 574 | 1365, 575 | 10, 576 | 1366, 577 | 9, 578 | 1367, 579 | 9, 580 | 1392, 581 | 11, 582 | 1394, 583 | 11, 584 | 1489, 585 | 10, 586 | 1493, 587 | 10, 588 | 1520, 589 | 8, 590 | 1521, 591 | 8, 592 | 1878, 593 | 9, 594 | 1879, 595 | 9, 596 | 1906, 597 | 7, 598 | 1910, 599 | 7, 600 | 2005, 601 | 6, 602 | 2007, 603 | 6, 604 | 2032, 605 | 8, 606 | 2033, 607 | 8, 608 | 2034, 609 | 7, 610 | 2037, 611 | 6, 612 | 2038, 613 | 7, 614 | 2039, 615 | 6, 616 | ], 617 | lookupPairs4D: [ 618 | 0, 619 | 3, 620 | 1, 621 | 2, 622 | 2, 623 | 3, 624 | 5, 625 | 2, 626 | 6, 627 | 1, 628 | 7, 629 | 1, 630 | 8, 631 | 3, 632 | 9, 633 | 2, 634 | 10, 635 | 3, 636 | 13, 637 | 2, 638 | 16, 639 | 3, 640 | 18, 641 | 3, 642 | 22, 643 | 1, 644 | 23, 645 | 1, 646 | 24, 647 | 3, 648 | 26, 649 | 3, 650 | 33, 651 | 2, 652 | 37, 653 | 2, 654 | 38, 655 | 1, 656 | 39, 657 | 1, 658 | 41, 659 | 2, 660 | 45, 661 | 2, 662 | 54, 663 | 1, 664 | 55, 665 | 1, 666 | 56, 667 | 0, 668 | 57, 669 | 0, 670 | 58, 671 | 0, 672 | 59, 673 | 0, 674 | 60, 675 | 0, 676 | 61, 677 | 0, 678 | 62, 679 | 0, 680 | 63, 681 | 0, 682 | 256, 683 | 3, 684 | 258, 685 | 3, 686 | 264, 687 | 3, 688 | 266, 689 | 3, 690 | 272, 691 | 3, 692 | 274, 693 | 3, 694 | 280, 695 | 3, 696 | 282, 697 | 3, 698 | 2049, 699 | 2, 700 | 2053, 701 | 2, 702 | 2057, 703 | 2, 704 | 2061, 705 | 2, 706 | 2081, 707 | 2, 708 | 2085, 709 | 2, 710 | 2089, 711 | 2, 712 | 2093, 713 | 2, 714 | 2304, 715 | 9, 716 | 2305, 717 | 9, 718 | 2312, 719 | 9, 720 | 2313, 721 | 9, 722 | 16390, 723 | 1, 724 | 16391, 725 | 1, 726 | 16406, 727 | 1, 728 | 16407, 729 | 1, 730 | 16422, 731 | 1, 732 | 16423, 733 | 1, 734 | 16438, 735 | 1, 736 | 16439, 737 | 1, 738 | 16642, 739 | 8, 740 | 16646, 741 | 8, 742 | 16658, 743 | 8, 744 | 16662, 745 | 8, 746 | 18437, 747 | 6, 748 | 18439, 749 | 6, 750 | 18469, 751 | 6, 752 | 18471, 753 | 6, 754 | 18688, 755 | 9, 756 | 18689, 757 | 9, 758 | 18690, 759 | 8, 760 | 18693, 761 | 6, 762 | 18694, 763 | 8, 764 | 18695, 765 | 6, 766 | 18696, 767 | 9, 768 | 18697, 769 | 9, 770 | 18706, 771 | 8, 772 | 18710, 773 | 8, 774 | 18725, 775 | 6, 776 | 18727, 777 | 6, 778 | 131128, 779 | 0, 780 | 131129, 781 | 0, 782 | 131130, 783 | 0, 784 | 131131, 785 | 0, 786 | 131132, 787 | 0, 788 | 131133, 789 | 0, 790 | 131134, 791 | 0, 792 | 131135, 793 | 0, 794 | 131352, 795 | 7, 796 | 131354, 797 | 7, 798 | 131384, 799 | 7, 800 | 131386, 801 | 7, 802 | 133161, 803 | 5, 804 | 133165, 805 | 5, 806 | 133177, 807 | 5, 808 | 133181, 809 | 5, 810 | 133376, 811 | 9, 812 | 133377, 813 | 9, 814 | 133384, 815 | 9, 816 | 133385, 817 | 9, 818 | 133400, 819 | 7, 820 | 133402, 821 | 7, 822 | 133417, 823 | 5, 824 | 133421, 825 | 5, 826 | 133432, 827 | 7, 828 | 133433, 829 | 5, 830 | 133434, 831 | 7, 832 | 133437, 833 | 5, 834 | 147510, 835 | 4, 836 | 147511, 837 | 4, 838 | 147518, 839 | 4, 840 | 147519, 841 | 4, 842 | 147714, 843 | 8, 844 | 147718, 845 | 8, 846 | 147730, 847 | 8, 848 | 147734, 849 | 8, 850 | 147736, 851 | 7, 852 | 147738, 853 | 7, 854 | 147766, 855 | 4, 856 | 147767, 857 | 4, 858 | 147768, 859 | 7, 860 | 147770, 861 | 7, 862 | 147774, 863 | 4, 864 | 147775, 865 | 4, 866 | 149509, 867 | 6, 868 | 149511, 869 | 6, 870 | 149541, 871 | 6, 872 | 149543, 873 | 6, 874 | 149545, 875 | 5, 876 | 149549, 877 | 5, 878 | 149558, 879 | 4, 880 | 149559, 881 | 4, 882 | 149561, 883 | 5, 884 | 149565, 885 | 5, 886 | 149566, 887 | 4, 888 | 149567, 889 | 4, 890 | 149760, 891 | 9, 892 | 149761, 893 | 9, 894 | 149762, 895 | 8, 896 | 149765, 897 | 6, 898 | 149766, 899 | 8, 900 | 149767, 901 | 6, 902 | 149768, 903 | 9, 904 | 149769, 905 | 9, 906 | 149778, 907 | 8, 908 | 149782, 909 | 8, 910 | 149784, 911 | 7, 912 | 149786, 913 | 7, 914 | 149797, 915 | 6, 916 | 149799, 917 | 6, 918 | 149801, 919 | 5, 920 | 149805, 921 | 5, 922 | 149814, 923 | 4, 924 | 149815, 925 | 4, 926 | 149816, 927 | 7, 928 | 149817, 929 | 5, 930 | 149818, 931 | 7, 932 | 149821, 933 | 5, 934 | 149822, 935 | 4, 936 | 149823, 937 | 4, 938 | 149824, 939 | 37, 940 | 149825, 941 | 37, 942 | 149826, 943 | 36, 944 | 149829, 945 | 34, 946 | 149830, 947 | 36, 948 | 149831, 949 | 34, 950 | 149832, 951 | 37, 952 | 149833, 953 | 37, 954 | 149842, 955 | 36, 956 | 149846, 957 | 36, 958 | 149848, 959 | 35, 960 | 149850, 961 | 35, 962 | 149861, 963 | 34, 964 | 149863, 965 | 34, 966 | 149865, 967 | 33, 968 | 149869, 969 | 33, 970 | 149878, 971 | 32, 972 | 149879, 973 | 32, 974 | 149880, 975 | 35, 976 | 149881, 977 | 33, 978 | 149882, 979 | 35, 980 | 149885, 981 | 33, 982 | 149886, 983 | 32, 984 | 149887, 985 | 32, 986 | 150080, 987 | 49, 988 | 150082, 989 | 48, 990 | 150088, 991 | 49, 992 | 150098, 993 | 48, 994 | 150104, 995 | 47, 996 | 150106, 997 | 47, 998 | 151873, 999 | 46, 1000 | 151877, 1001 | 45, 1002 | 151881, 1003 | 46, 1004 | 151909, 1005 | 45, 1006 | 151913, 1007 | 44, 1008 | 151917, 1009 | 44, 1010 | 152128, 1011 | 49, 1012 | 152129, 1013 | 46, 1014 | 152136, 1015 | 49, 1016 | 152137, 1017 | 46, 1018 | 166214, 1019 | 43, 1020 | 166215, 1021 | 42, 1022 | 166230, 1023 | 43, 1024 | 166247, 1025 | 42, 1026 | 166262, 1027 | 41, 1028 | 166263, 1029 | 41, 1030 | 166466, 1031 | 48, 1032 | 166470, 1033 | 43, 1034 | 166482, 1035 | 48, 1036 | 166486, 1037 | 43, 1038 | 168261, 1039 | 45, 1040 | 168263, 1041 | 42, 1042 | 168293, 1043 | 45, 1044 | 168295, 1045 | 42, 1046 | 168512, 1047 | 31, 1048 | 168513, 1049 | 28, 1050 | 168514, 1051 | 31, 1052 | 168517, 1053 | 28, 1054 | 168518, 1055 | 25, 1056 | 168519, 1057 | 25, 1058 | 280952, 1059 | 40, 1060 | 280953, 1061 | 39, 1062 | 280954, 1063 | 40, 1064 | 280957, 1065 | 39, 1066 | 280958, 1067 | 38, 1068 | 280959, 1069 | 38, 1070 | 281176, 1071 | 47, 1072 | 281178, 1073 | 47, 1074 | 281208, 1075 | 40, 1076 | 281210, 1077 | 40, 1078 | 282985, 1079 | 44, 1080 | 282989, 1081 | 44, 1082 | 283001, 1083 | 39, 1084 | 283005, 1085 | 39, 1086 | 283208, 1087 | 30, 1088 | 283209, 1089 | 27, 1090 | 283224, 1091 | 30, 1092 | 283241, 1093 | 27, 1094 | 283256, 1095 | 22, 1096 | 283257, 1097 | 22, 1098 | 297334, 1099 | 41, 1100 | 297335, 1101 | 41, 1102 | 297342, 1103 | 38, 1104 | 297343, 1105 | 38, 1106 | 297554, 1107 | 29, 1108 | 297558, 1109 | 24, 1110 | 297562, 1111 | 29, 1112 | 297590, 1113 | 24, 1114 | 297594, 1115 | 21, 1116 | 297598, 1117 | 21, 1118 | 299365, 1119 | 26, 1120 | 299367, 1121 | 23, 1122 | 299373, 1123 | 26, 1124 | 299383, 1125 | 23, 1126 | 299389, 1127 | 20, 1128 | 299391, 1129 | 20, 1130 | 299584, 1131 | 31, 1132 | 299585, 1133 | 28, 1134 | 299586, 1135 | 31, 1136 | 299589, 1137 | 28, 1138 | 299590, 1139 | 25, 1140 | 299591, 1141 | 25, 1142 | 299592, 1143 | 30, 1144 | 299593, 1145 | 27, 1146 | 299602, 1147 | 29, 1148 | 299606, 1149 | 24, 1150 | 299608, 1151 | 30, 1152 | 299610, 1153 | 29, 1154 | 299621, 1155 | 26, 1156 | 299623, 1157 | 23, 1158 | 299625, 1159 | 27, 1160 | 299629, 1161 | 26, 1162 | 299638, 1163 | 24, 1164 | 299639, 1165 | 23, 1166 | 299640, 1167 | 22, 1168 | 299641, 1169 | 22, 1170 | 299642, 1171 | 21, 1172 | 299645, 1173 | 20, 1174 | 299646, 1175 | 21, 1176 | 299647, 1177 | 20, 1178 | 299648, 1179 | 61, 1180 | 299649, 1181 | 60, 1182 | 299650, 1183 | 61, 1184 | 299653, 1185 | 60, 1186 | 299654, 1187 | 59, 1188 | 299655, 1189 | 59, 1190 | 299656, 1191 | 58, 1192 | 299657, 1193 | 57, 1194 | 299666, 1195 | 55, 1196 | 299670, 1197 | 54, 1198 | 299672, 1199 | 58, 1200 | 299674, 1201 | 55, 1202 | 299685, 1203 | 52, 1204 | 299687, 1205 | 51, 1206 | 299689, 1207 | 57, 1208 | 299693, 1209 | 52, 1210 | 299702, 1211 | 54, 1212 | 299703, 1213 | 51, 1214 | 299704, 1215 | 56, 1216 | 299705, 1217 | 56, 1218 | 299706, 1219 | 53, 1220 | 299709, 1221 | 50, 1222 | 299710, 1223 | 53, 1224 | 299711, 1225 | 50, 1226 | 299904, 1227 | 61, 1228 | 299906, 1229 | 61, 1230 | 299912, 1231 | 58, 1232 | 299922, 1233 | 55, 1234 | 299928, 1235 | 58, 1236 | 299930, 1237 | 55, 1238 | 301697, 1239 | 60, 1240 | 301701, 1241 | 60, 1242 | 301705, 1243 | 57, 1244 | 301733, 1245 | 52, 1246 | 301737, 1247 | 57, 1248 | 301741, 1249 | 52, 1250 | 301952, 1251 | 79, 1252 | 301953, 1253 | 79, 1254 | 301960, 1255 | 76, 1256 | 301961, 1257 | 76, 1258 | 316038, 1259 | 59, 1260 | 316039, 1261 | 59, 1262 | 316054, 1263 | 54, 1264 | 316071, 1265 | 51, 1266 | 316086, 1267 | 54, 1268 | 316087, 1269 | 51, 1270 | 316290, 1271 | 78, 1272 | 316294, 1273 | 78, 1274 | 316306, 1275 | 73, 1276 | 316310, 1277 | 73, 1278 | 318085, 1279 | 77, 1280 | 318087, 1281 | 77, 1282 | 318117, 1283 | 70, 1284 | 318119, 1285 | 70, 1286 | 318336, 1287 | 79, 1288 | 318337, 1289 | 79, 1290 | 318338, 1291 | 78, 1292 | 318341, 1293 | 77, 1294 | 318342, 1295 | 78, 1296 | 318343, 1297 | 77, 1298 | 430776, 1299 | 56, 1300 | 430777, 1301 | 56, 1302 | 430778, 1303 | 53, 1304 | 430781, 1305 | 50, 1306 | 430782, 1307 | 53, 1308 | 430783, 1309 | 50, 1310 | 431000, 1311 | 75, 1312 | 431002, 1313 | 72, 1314 | 431032, 1315 | 75, 1316 | 431034, 1317 | 72, 1318 | 432809, 1319 | 74, 1320 | 432813, 1321 | 69, 1322 | 432825, 1323 | 74, 1324 | 432829, 1325 | 69, 1326 | 433032, 1327 | 76, 1328 | 433033, 1329 | 76, 1330 | 433048, 1331 | 75, 1332 | 433065, 1333 | 74, 1334 | 433080, 1335 | 75, 1336 | 433081, 1337 | 74, 1338 | 447158, 1339 | 71, 1340 | 447159, 1341 | 68, 1342 | 447166, 1343 | 71, 1344 | 447167, 1345 | 68, 1346 | 447378, 1347 | 73, 1348 | 447382, 1349 | 73, 1350 | 447386, 1351 | 72, 1352 | 447414, 1353 | 71, 1354 | 447418, 1355 | 72, 1356 | 447422, 1357 | 71, 1358 | 449189, 1359 | 70, 1360 | 449191, 1361 | 70, 1362 | 449197, 1363 | 69, 1364 | 449207, 1365 | 68, 1366 | 449213, 1367 | 69, 1368 | 449215, 1369 | 68, 1370 | 449408, 1371 | 67, 1372 | 449409, 1373 | 67, 1374 | 449410, 1375 | 66, 1376 | 449413, 1377 | 64, 1378 | 449414, 1379 | 66, 1380 | 449415, 1381 | 64, 1382 | 449416, 1383 | 67, 1384 | 449417, 1385 | 67, 1386 | 449426, 1387 | 66, 1388 | 449430, 1389 | 66, 1390 | 449432, 1391 | 65, 1392 | 449434, 1393 | 65, 1394 | 449445, 1395 | 64, 1396 | 449447, 1397 | 64, 1398 | 449449, 1399 | 63, 1400 | 449453, 1401 | 63, 1402 | 449462, 1403 | 62, 1404 | 449463, 1405 | 62, 1406 | 449464, 1407 | 65, 1408 | 449465, 1409 | 63, 1410 | 449466, 1411 | 65, 1412 | 449469, 1413 | 63, 1414 | 449470, 1415 | 62, 1416 | 449471, 1417 | 62, 1418 | 449472, 1419 | 19, 1420 | 449473, 1421 | 19, 1422 | 449474, 1423 | 18, 1424 | 449477, 1425 | 16, 1426 | 449478, 1427 | 18, 1428 | 449479, 1429 | 16, 1430 | 449480, 1431 | 19, 1432 | 449481, 1433 | 19, 1434 | 449490, 1435 | 18, 1436 | 449494, 1437 | 18, 1438 | 449496, 1439 | 17, 1440 | 449498, 1441 | 17, 1442 | 449509, 1443 | 16, 1444 | 449511, 1445 | 16, 1446 | 449513, 1447 | 15, 1448 | 449517, 1449 | 15, 1450 | 449526, 1451 | 14, 1452 | 449527, 1453 | 14, 1454 | 449528, 1455 | 17, 1456 | 449529, 1457 | 15, 1458 | 449530, 1459 | 17, 1460 | 449533, 1461 | 15, 1462 | 449534, 1463 | 14, 1464 | 449535, 1465 | 14, 1466 | 449728, 1467 | 19, 1468 | 449729, 1469 | 19, 1470 | 449730, 1471 | 18, 1472 | 449734, 1473 | 18, 1474 | 449736, 1475 | 19, 1476 | 449737, 1477 | 19, 1478 | 449746, 1479 | 18, 1480 | 449750, 1481 | 18, 1482 | 449752, 1483 | 17, 1484 | 449754, 1485 | 17, 1486 | 449784, 1487 | 17, 1488 | 449786, 1489 | 17, 1490 | 451520, 1491 | 19, 1492 | 451521, 1493 | 19, 1494 | 451525, 1495 | 16, 1496 | 451527, 1497 | 16, 1498 | 451528, 1499 | 19, 1500 | 451529, 1501 | 19, 1502 | 451557, 1503 | 16, 1504 | 451559, 1505 | 16, 1506 | 451561, 1507 | 15, 1508 | 451565, 1509 | 15, 1510 | 451577, 1511 | 15, 1512 | 451581, 1513 | 15, 1514 | 451776, 1515 | 19, 1516 | 451777, 1517 | 19, 1518 | 451784, 1519 | 19, 1520 | 451785, 1521 | 19, 1522 | 465858, 1523 | 18, 1524 | 465861, 1525 | 16, 1526 | 465862, 1527 | 18, 1528 | 465863, 1529 | 16, 1530 | 465874, 1531 | 18, 1532 | 465878, 1533 | 18, 1534 | 465893, 1535 | 16, 1536 | 465895, 1537 | 16, 1538 | 465910, 1539 | 14, 1540 | 465911, 1541 | 14, 1542 | 465918, 1543 | 14, 1544 | 465919, 1545 | 14, 1546 | 466114, 1547 | 18, 1548 | 466118, 1549 | 18, 1550 | 466130, 1551 | 18, 1552 | 466134, 1553 | 18, 1554 | 467909, 1555 | 16, 1556 | 467911, 1557 | 16, 1558 | 467941, 1559 | 16, 1560 | 467943, 1561 | 16, 1562 | 468160, 1563 | 13, 1564 | 468161, 1565 | 13, 1566 | 468162, 1567 | 13, 1568 | 468163, 1569 | 13, 1570 | 468164, 1571 | 13, 1572 | 468165, 1573 | 13, 1574 | 468166, 1575 | 13, 1576 | 468167, 1577 | 13, 1578 | 580568, 1579 | 17, 1580 | 580570, 1581 | 17, 1582 | 580585, 1583 | 15, 1584 | 580589, 1585 | 15, 1586 | 580598, 1587 | 14, 1588 | 580599, 1589 | 14, 1590 | 580600, 1591 | 17, 1592 | 580601, 1593 | 15, 1594 | 580602, 1595 | 17, 1596 | 580605, 1597 | 15, 1598 | 580606, 1599 | 14, 1600 | 580607, 1601 | 14, 1602 | 580824, 1603 | 17, 1604 | 580826, 1605 | 17, 1606 | 580856, 1607 | 17, 1608 | 580858, 1609 | 17, 1610 | 582633, 1611 | 15, 1612 | 582637, 1613 | 15, 1614 | 582649, 1615 | 15, 1616 | 582653, 1617 | 15, 1618 | 582856, 1619 | 12, 1620 | 582857, 1621 | 12, 1622 | 582872, 1623 | 12, 1624 | 582873, 1625 | 12, 1626 | 582888, 1627 | 12, 1628 | 582889, 1629 | 12, 1630 | 582904, 1631 | 12, 1632 | 582905, 1633 | 12, 1634 | 596982, 1635 | 14, 1636 | 596983, 1637 | 14, 1638 | 596990, 1639 | 14, 1640 | 596991, 1641 | 14, 1642 | 597202, 1643 | 11, 1644 | 597206, 1645 | 11, 1646 | 597210, 1647 | 11, 1648 | 597214, 1649 | 11, 1650 | 597234, 1651 | 11, 1652 | 597238, 1653 | 11, 1654 | 597242, 1655 | 11, 1656 | 597246, 1657 | 11, 1658 | 599013, 1659 | 10, 1660 | 599015, 1661 | 10, 1662 | 599021, 1663 | 10, 1664 | 599023, 1665 | 10, 1666 | 599029, 1667 | 10, 1668 | 599031, 1669 | 10, 1670 | 599037, 1671 | 10, 1672 | 599039, 1673 | 10, 1674 | 599232, 1675 | 13, 1676 | 599233, 1677 | 13, 1678 | 599234, 1679 | 13, 1680 | 599235, 1681 | 13, 1682 | 599236, 1683 | 13, 1684 | 599237, 1685 | 13, 1686 | 599238, 1687 | 13, 1688 | 599239, 1689 | 13, 1690 | 599240, 1691 | 12, 1692 | 599241, 1693 | 12, 1694 | 599250, 1695 | 11, 1696 | 599254, 1697 | 11, 1698 | 599256, 1699 | 12, 1700 | 599257, 1701 | 12, 1702 | 599258, 1703 | 11, 1704 | 599262, 1705 | 11, 1706 | 599269, 1707 | 10, 1708 | 599271, 1709 | 10, 1710 | 599272, 1711 | 12, 1712 | 599273, 1713 | 12, 1714 | 599277, 1715 | 10, 1716 | 599279, 1717 | 10, 1718 | 599282, 1719 | 11, 1720 | 599285, 1721 | 10, 1722 | 599286, 1723 | 11, 1724 | 599287, 1725 | 10, 1726 | 599288, 1727 | 12, 1728 | 599289, 1729 | 12, 1730 | 599290, 1731 | 11, 1732 | 599293, 1733 | 10, 1734 | 599294, 1735 | 11, 1736 | 599295, 1737 | 10, 1738 | ], 1739 | p2D: [0, 0, 1, -1, 0, 0, -1, 1, 0, 2, 1, 1, 1, 2, 2, 0, 1, 2, 0, 2, 1, 0, 0, 0], 1740 | p3D: [ 1741 | 0, 1742 | 0, 1743 | 1, 1744 | -1, 1745 | 0, 1746 | 0, 1747 | 1, 1748 | 0, 1749 | -1, 1750 | 0, 1751 | 0, 1752 | -1, 1753 | 1, 1754 | 0, 1755 | 0, 1756 | 0, 1757 | 1, 1758 | -1, 1759 | 0, 1760 | 0, 1761 | -1, 1762 | 0, 1763 | 1, 1764 | 0, 1765 | 0, 1766 | -1, 1767 | 1, 1768 | 0, 1769 | 2, 1770 | 1, 1771 | 1, 1772 | 0, 1773 | 1, 1774 | 1, 1775 | 1, 1776 | -1, 1777 | 0, 1778 | 2, 1779 | 1, 1780 | 0, 1781 | 1, 1782 | 1, 1783 | 1, 1784 | -1, 1785 | 1, 1786 | 0, 1787 | 2, 1788 | 0, 1789 | 1, 1790 | 1, 1791 | 1, 1792 | -1, 1793 | 1, 1794 | 1, 1795 | 1, 1796 | 3, 1797 | 2, 1798 | 1, 1799 | 0, 1800 | 3, 1801 | 1, 1802 | 2, 1803 | 0, 1804 | 1, 1805 | 3, 1806 | 2, 1807 | 0, 1808 | 1, 1809 | 3, 1810 | 1, 1811 | 0, 1812 | 2, 1813 | 1, 1814 | 3, 1815 | 0, 1816 | 2, 1817 | 1, 1818 | 3, 1819 | 0, 1820 | 1, 1821 | 2, 1822 | 1, 1823 | 1, 1824 | 1, 1825 | 0, 1826 | 0, 1827 | 2, 1828 | 2, 1829 | 0, 1830 | 0, 1831 | 1, 1832 | 1, 1833 | 0, 1834 | 1, 1835 | 0, 1836 | 2, 1837 | 0, 1838 | 2, 1839 | 0, 1840 | 1, 1841 | 1, 1842 | 0, 1843 | 0, 1844 | 1, 1845 | 2, 1846 | 0, 1847 | 0, 1848 | 2, 1849 | 2, 1850 | 0, 1851 | 0, 1852 | 0, 1853 | 0, 1854 | 1, 1855 | 1, 1856 | -1, 1857 | 1, 1858 | 2, 1859 | 0, 1860 | 0, 1861 | 0, 1862 | 0, 1863 | 1, 1864 | -1, 1865 | 1, 1866 | 1, 1867 | 2, 1868 | 0, 1869 | 0, 1870 | 0, 1871 | 0, 1872 | 1, 1873 | 1, 1874 | 1, 1875 | -1, 1876 | 2, 1877 | 3, 1878 | 1, 1879 | 1, 1880 | 1, 1881 | 2, 1882 | 0, 1883 | 0, 1884 | 2, 1885 | 2, 1886 | 3, 1887 | 1, 1888 | 1, 1889 | 1, 1890 | 2, 1891 | 2, 1892 | 0, 1893 | 0, 1894 | 2, 1895 | 3, 1896 | 1, 1897 | 1, 1898 | 1, 1899 | 2, 1900 | 0, 1901 | 2, 1902 | 0, 1903 | 2, 1904 | 1, 1905 | 1, 1906 | -1, 1907 | 1, 1908 | 2, 1909 | 0, 1910 | 0, 1911 | 2, 1912 | 2, 1913 | 1, 1914 | 1, 1915 | -1, 1916 | 1, 1917 | 2, 1918 | 2, 1919 | 0, 1920 | 0, 1921 | 2, 1922 | 1, 1923 | -1, 1924 | 1, 1925 | 1, 1926 | 2, 1927 | 0, 1928 | 0, 1929 | 2, 1930 | 2, 1931 | 1, 1932 | -1, 1933 | 1, 1934 | 1, 1935 | 2, 1936 | 0, 1937 | 2, 1938 | 0, 1939 | 2, 1940 | 1, 1941 | 1, 1942 | 1, 1943 | -1, 1944 | 2, 1945 | 2, 1946 | 0, 1947 | 0, 1948 | 2, 1949 | 1, 1950 | 1, 1951 | 1, 1952 | -1, 1953 | 2, 1954 | 0, 1955 | 2, 1956 | 0, 1957 | ], 1958 | p4D: [ 1959 | 0, 1960 | 0, 1961 | 1, 1962 | -1, 1963 | 0, 1964 | 0, 1965 | 0, 1966 | 1, 1967 | 0, 1968 | -1, 1969 | 0, 1970 | 0, 1971 | 1, 1972 | 0, 1973 | 0, 1974 | -1, 1975 | 0, 1976 | 0, 1977 | -1, 1978 | 1, 1979 | 0, 1980 | 0, 1981 | 0, 1982 | 0, 1983 | 1, 1984 | -1, 1985 | 0, 1986 | 0, 1987 | 0, 1988 | 1, 1989 | 0, 1990 | -1, 1991 | 0, 1992 | 0, 1993 | -1, 1994 | 0, 1995 | 1, 1996 | 0, 1997 | 0, 1998 | 0, 1999 | -1, 2000 | 1, 2001 | 0, 2002 | 0, 2003 | 0, 2004 | 0, 2005 | 1, 2006 | -1, 2007 | 0, 2008 | 0, 2009 | -1, 2010 | 0, 2011 | 0, 2012 | 1, 2013 | 0, 2014 | 0, 2015 | -1, 2016 | 0, 2017 | 1, 2018 | 0, 2019 | 0, 2020 | 0, 2021 | -1, 2022 | 1, 2023 | 0, 2024 | 2, 2025 | 1, 2026 | 1, 2027 | 0, 2028 | 0, 2029 | 1, 2030 | 1, 2031 | 1, 2032 | -1, 2033 | 0, 2034 | 1, 2035 | 1, 2036 | 1, 2037 | 0, 2038 | -1, 2039 | 0, 2040 | 2, 2041 | 1, 2042 | 0, 2043 | 1, 2044 | 0, 2045 | 1, 2046 | 1, 2047 | -1, 2048 | 1, 2049 | 0, 2050 | 1, 2051 | 1, 2052 | 0, 2053 | 1, 2054 | -1, 2055 | 0, 2056 | 2, 2057 | 0, 2058 | 1, 2059 | 1, 2060 | 0, 2061 | 1, 2062 | -1, 2063 | 1, 2064 | 1, 2065 | 0, 2066 | 1, 2067 | 0, 2068 | 1, 2069 | 1, 2070 | -1, 2071 | 0, 2072 | 2, 2073 | 1, 2074 | 0, 2075 | 0, 2076 | 1, 2077 | 1, 2078 | 1, 2079 | -1, 2080 | 0, 2081 | 1, 2082 | 1, 2083 | 1, 2084 | 0, 2085 | -1, 2086 | 1, 2087 | 0, 2088 | 2, 2089 | 0, 2090 | 1, 2091 | 0, 2092 | 1, 2093 | 1, 2094 | -1, 2095 | 1, 2096 | 0, 2097 | 1, 2098 | 1, 2099 | 0, 2100 | 1, 2101 | -1, 2102 | 1, 2103 | 0, 2104 | 2, 2105 | 0, 2106 | 0, 2107 | 1, 2108 | 1, 2109 | 1, 2110 | -1, 2111 | 0, 2112 | 1, 2113 | 1, 2114 | 1, 2115 | 0, 2116 | -1, 2117 | 1, 2118 | 1, 2119 | 1, 2120 | 4, 2121 | 2, 2122 | 1, 2123 | 1, 2124 | 0, 2125 | 4, 2126 | 1, 2127 | 2, 2128 | 1, 2129 | 0, 2130 | 4, 2131 | 1, 2132 | 1, 2133 | 2, 2134 | 0, 2135 | 1, 2136 | 4, 2137 | 2, 2138 | 1, 2139 | 0, 2140 | 1, 2141 | 4, 2142 | 1, 2143 | 2, 2144 | 0, 2145 | 1, 2146 | 4, 2147 | 1, 2148 | 1, 2149 | 0, 2150 | 2, 2151 | 1, 2152 | 4, 2153 | 2, 2154 | 0, 2155 | 1, 2156 | 1, 2157 | 4, 2158 | 1, 2159 | 0, 2160 | 2, 2161 | 1, 2162 | 4, 2163 | 1, 2164 | 0, 2165 | 1, 2166 | 2, 2167 | 1, 2168 | 4, 2169 | 0, 2170 | 2, 2171 | 1, 2172 | 1, 2173 | 4, 2174 | 0, 2175 | 1, 2176 | 2, 2177 | 1, 2178 | 4, 2179 | 0, 2180 | 1, 2181 | 1, 2182 | 2, 2183 | 1, 2184 | 2, 2185 | 1, 2186 | 1, 2187 | 0, 2188 | 0, 2189 | 3, 2190 | 2, 2191 | 1, 2192 | 0, 2193 | 0, 2194 | 3, 2195 | 1, 2196 | 2, 2197 | 0, 2198 | 0, 2199 | 1, 2200 | 2, 2201 | 1, 2202 | 0, 2203 | 1, 2204 | 0, 2205 | 3, 2206 | 2, 2207 | 0, 2208 | 1, 2209 | 0, 2210 | 3, 2211 | 1, 2212 | 0, 2213 | 2, 2214 | 0, 2215 | 1, 2216 | 2, 2217 | 0, 2218 | 1, 2219 | 1, 2220 | 0, 2221 | 3, 2222 | 0, 2223 | 2, 2224 | 1, 2225 | 0, 2226 | 3, 2227 | 0, 2228 | 1, 2229 | 2, 2230 | 0, 2231 | 1, 2232 | 2, 2233 | 1, 2234 | 0, 2235 | 0, 2236 | 1, 2237 | 3, 2238 | 2, 2239 | 0, 2240 | 0, 2241 | 1, 2242 | 3, 2243 | 1, 2244 | 0, 2245 | 0, 2246 | 2, 2247 | 1, 2248 | 2, 2249 | 0, 2250 | 1, 2251 | 0, 2252 | 1, 2253 | 3, 2254 | 0, 2255 | 2, 2256 | 0, 2257 | 1, 2258 | 3, 2259 | 0, 2260 | 1, 2261 | 0, 2262 | 2, 2263 | 1, 2264 | 2, 2265 | 0, 2266 | 0, 2267 | 1, 2268 | 1, 2269 | 3, 2270 | 0, 2271 | 0, 2272 | 2, 2273 | 1, 2274 | 3, 2275 | 0, 2276 | 0, 2277 | 1, 2278 | 2, 2279 | 2, 2280 | 3, 2281 | 1, 2282 | 1, 2283 | 1, 2284 | 0, 2285 | 2, 2286 | 1, 2287 | 1, 2288 | 1, 2289 | -1, 2290 | 2, 2291 | 2, 2292 | 0, 2293 | 0, 2294 | 0, 2295 | 2, 2296 | 3, 2297 | 1, 2298 | 1, 2299 | 0, 2300 | 1, 2301 | 2, 2302 | 1, 2303 | 1, 2304 | -1, 2305 | 1, 2306 | 2, 2307 | 2, 2308 | 0, 2309 | 0, 2310 | 0, 2311 | 2, 2312 | 3, 2313 | 1, 2314 | 0, 2315 | 1, 2316 | 1, 2317 | 2, 2318 | 1, 2319 | -1, 2320 | 1, 2321 | 1, 2322 | 2, 2323 | 2, 2324 | 0, 2325 | 0, 2326 | 0, 2327 | 2, 2328 | 3, 2329 | 1, 2330 | 1, 2331 | 1, 2332 | 0, 2333 | 2, 2334 | 1, 2335 | 1, 2336 | 1, 2337 | -1, 2338 | 2, 2339 | 0, 2340 | 2, 2341 | 0, 2342 | 0, 2343 | 2, 2344 | 3, 2345 | 1, 2346 | 1, 2347 | 0, 2348 | 1, 2349 | 2, 2350 | 1, 2351 | 1, 2352 | -1, 2353 | 1, 2354 | 2, 2355 | 0, 2356 | 2, 2357 | 0, 2358 | 0, 2359 | 2, 2360 | 3, 2361 | 0, 2362 | 1, 2363 | 1, 2364 | 1, 2365 | 2, 2366 | -1, 2367 | 1, 2368 | 1, 2369 | 1, 2370 | 2, 2371 | 0, 2372 | 2, 2373 | 0, 2374 | 0, 2375 | 2, 2376 | 3, 2377 | 1, 2378 | 1, 2379 | 1, 2380 | 0, 2381 | 2, 2382 | 1, 2383 | 1, 2384 | 1, 2385 | -1, 2386 | 2, 2387 | 0, 2388 | 0, 2389 | 2, 2390 | 0, 2391 | 2, 2392 | 3, 2393 | 1, 2394 | 0, 2395 | 1, 2396 | 1, 2397 | 2, 2398 | 1, 2399 | -1, 2400 | 1, 2401 | 1, 2402 | 2, 2403 | 0, 2404 | 0, 2405 | 2, 2406 | 0, 2407 | 2, 2408 | 3, 2409 | 0, 2410 | 1, 2411 | 1, 2412 | 1, 2413 | 2, 2414 | -1, 2415 | 1, 2416 | 1, 2417 | 1, 2418 | 2, 2419 | 0, 2420 | 0, 2421 | 2, 2422 | 0, 2423 | 2, 2424 | 3, 2425 | 1, 2426 | 1, 2427 | 0, 2428 | 1, 2429 | 2, 2430 | 1, 2431 | 1, 2432 | -1, 2433 | 1, 2434 | 2, 2435 | 0, 2436 | 0, 2437 | 0, 2438 | 2, 2439 | 2, 2440 | 3, 2441 | 1, 2442 | 0, 2443 | 1, 2444 | 1, 2445 | 2, 2446 | 1, 2447 | -1, 2448 | 1, 2449 | 1, 2450 | 2, 2451 | 0, 2452 | 0, 2453 | 0, 2454 | 2, 2455 | 2, 2456 | 3, 2457 | 0, 2458 | 1, 2459 | 1, 2460 | 1, 2461 | 2, 2462 | -1, 2463 | 1, 2464 | 1, 2465 | 1, 2466 | 2, 2467 | 0, 2468 | 0, 2469 | 0, 2470 | 2, 2471 | 2, 2472 | 1, 2473 | 1, 2474 | 1, 2475 | -1, 2476 | 0, 2477 | 1, 2478 | 1, 2479 | 1, 2480 | 0, 2481 | -1, 2482 | 0, 2483 | 0, 2484 | 0, 2485 | 0, 2486 | 0, 2487 | 2, 2488 | 1, 2489 | 1, 2490 | -1, 2491 | 1, 2492 | 0, 2493 | 1, 2494 | 1, 2495 | 0, 2496 | 1, 2497 | -1, 2498 | 0, 2499 | 0, 2500 | 0, 2501 | 0, 2502 | 0, 2503 | 2, 2504 | 1, 2505 | -1, 2506 | 1, 2507 | 1, 2508 | 0, 2509 | 1, 2510 | 0, 2511 | 1, 2512 | 1, 2513 | -1, 2514 | 0, 2515 | 0, 2516 | 0, 2517 | 0, 2518 | 0, 2519 | 2, 2520 | 1, 2521 | 1, 2522 | -1, 2523 | 0, 2524 | 1, 2525 | 1, 2526 | 1, 2527 | 0, 2528 | -1, 2529 | 1, 2530 | 0, 2531 | 0, 2532 | 0, 2533 | 0, 2534 | 0, 2535 | 2, 2536 | 1, 2537 | -1, 2538 | 1, 2539 | 0, 2540 | 1, 2541 | 1, 2542 | 0, 2543 | 1, 2544 | -1, 2545 | 1, 2546 | 0, 2547 | 0, 2548 | 0, 2549 | 0, 2550 | 0, 2551 | 2, 2552 | 1, 2553 | -1, 2554 | 0, 2555 | 1, 2556 | 1, 2557 | 1, 2558 | 0, 2559 | -1, 2560 | 1, 2561 | 1, 2562 | 0, 2563 | 0, 2564 | 0, 2565 | 0, 2566 | 0, 2567 | 2, 2568 | 1, 2569 | 1, 2570 | 1, 2571 | -1, 2572 | 0, 2573 | 1, 2574 | 1, 2575 | 1, 2576 | 0, 2577 | -1, 2578 | 2, 2579 | 2, 2580 | 0, 2581 | 0, 2582 | 0, 2583 | 2, 2584 | 1, 2585 | 1, 2586 | -1, 2587 | 1, 2588 | 0, 2589 | 1, 2590 | 1, 2591 | 0, 2592 | 1, 2593 | -1, 2594 | 2, 2595 | 2, 2596 | 0, 2597 | 0, 2598 | 0, 2599 | 2, 2600 | 1, 2601 | 1, 2602 | -1, 2603 | 0, 2604 | 1, 2605 | 1, 2606 | 1, 2607 | 0, 2608 | -1, 2609 | 1, 2610 | 2, 2611 | 2, 2612 | 0, 2613 | 0, 2614 | 0, 2615 | 2, 2616 | 1, 2617 | 1, 2618 | 1, 2619 | -1, 2620 | 0, 2621 | 1, 2622 | 1, 2623 | 1, 2624 | 0, 2625 | -1, 2626 | 2, 2627 | 0, 2628 | 2, 2629 | 0, 2630 | 0, 2631 | 2, 2632 | 1, 2633 | -1, 2634 | 1, 2635 | 1, 2636 | 0, 2637 | 1, 2638 | 0, 2639 | 1, 2640 | 1, 2641 | -1, 2642 | 2, 2643 | 0, 2644 | 2, 2645 | 0, 2646 | 0, 2647 | 2, 2648 | 1, 2649 | -1, 2650 | 1, 2651 | 0, 2652 | 1, 2653 | 1, 2654 | 0, 2655 | 1, 2656 | -1, 2657 | 1, 2658 | 2, 2659 | 0, 2660 | 2, 2661 | 0, 2662 | 0, 2663 | 2, 2664 | 1, 2665 | 1, 2666 | -1, 2667 | 1, 2668 | 0, 2669 | 1, 2670 | 1, 2671 | 0, 2672 | 1, 2673 | -1, 2674 | 2, 2675 | 0, 2676 | 0, 2677 | 2, 2678 | 0, 2679 | 2, 2680 | 1, 2681 | -1, 2682 | 1, 2683 | 1, 2684 | 0, 2685 | 1, 2686 | 0, 2687 | 1, 2688 | 1, 2689 | -1, 2690 | 2, 2691 | 0, 2692 | 0, 2693 | 2, 2694 | 0, 2695 | 2, 2696 | 1, 2697 | -1, 2698 | 0, 2699 | 1, 2700 | 1, 2701 | 1, 2702 | 0, 2703 | -1, 2704 | 1, 2705 | 1, 2706 | 2, 2707 | 0, 2708 | 0, 2709 | 2, 2710 | 0, 2711 | 2, 2712 | 1, 2713 | 1, 2714 | -1, 2715 | 0, 2716 | 1, 2717 | 1, 2718 | 1, 2719 | 0, 2720 | -1, 2721 | 1, 2722 | 2, 2723 | 0, 2724 | 0, 2725 | 0, 2726 | 2, 2727 | 2, 2728 | 1, 2729 | -1, 2730 | 1, 2731 | 0, 2732 | 1, 2733 | 1, 2734 | 0, 2735 | 1, 2736 | -1, 2737 | 1, 2738 | 2, 2739 | 0, 2740 | 0, 2741 | 0, 2742 | 2, 2743 | 2, 2744 | 1, 2745 | -1, 2746 | 0, 2747 | 1, 2748 | 1, 2749 | 1, 2750 | 0, 2751 | -1, 2752 | 1, 2753 | 1, 2754 | 2, 2755 | 0, 2756 | 0, 2757 | 0, 2758 | 2, 2759 | 3, 2760 | 1, 2761 | 1, 2762 | 0, 2763 | 0, 2764 | 0, 2765 | 2, 2766 | 2, 2767 | 0, 2768 | 0, 2769 | 0, 2770 | 2, 2771 | 1, 2772 | 1, 2773 | 1, 2774 | -1, 2775 | 3, 2776 | 1, 2777 | 0, 2778 | 1, 2779 | 0, 2780 | 0, 2781 | 2, 2782 | 0, 2783 | 2, 2784 | 0, 2785 | 0, 2786 | 2, 2787 | 1, 2788 | 1, 2789 | 1, 2790 | -1, 2791 | 3, 2792 | 1, 2793 | 0, 2794 | 0, 2795 | 1, 2796 | 0, 2797 | 2, 2798 | 0, 2799 | 0, 2800 | 2, 2801 | 0, 2802 | 2, 2803 | 1, 2804 | 1, 2805 | 1, 2806 | -1, 2807 | 3, 2808 | 1, 2809 | 1, 2810 | 0, 2811 | 0, 2812 | 0, 2813 | 2, 2814 | 2, 2815 | 0, 2816 | 0, 2817 | 0, 2818 | 2, 2819 | 1, 2820 | 1, 2821 | -1, 2822 | 1, 2823 | 3, 2824 | 1, 2825 | 0, 2826 | 1, 2827 | 0, 2828 | 0, 2829 | 2, 2830 | 0, 2831 | 2, 2832 | 0, 2833 | 0, 2834 | 2, 2835 | 1, 2836 | 1, 2837 | -1, 2838 | 1, 2839 | 3, 2840 | 1, 2841 | 0, 2842 | 0, 2843 | 0, 2844 | 1, 2845 | 2, 2846 | 0, 2847 | 0, 2848 | 0, 2849 | 2, 2850 | 2, 2851 | 1, 2852 | 1, 2853 | -1, 2854 | 1, 2855 | 3, 2856 | 1, 2857 | 1, 2858 | 0, 2859 | 0, 2860 | 0, 2861 | 2, 2862 | 2, 2863 | 0, 2864 | 0, 2865 | 0, 2866 | 2, 2867 | 1, 2868 | -1, 2869 | 1, 2870 | 1, 2871 | 3, 2872 | 1, 2873 | 0, 2874 | 0, 2875 | 1, 2876 | 0, 2877 | 2, 2878 | 0, 2879 | 0, 2880 | 2, 2881 | 0, 2882 | 2, 2883 | 1, 2884 | -1, 2885 | 1, 2886 | 1, 2887 | 3, 2888 | 1, 2889 | 0, 2890 | 0, 2891 | 0, 2892 | 1, 2893 | 2, 2894 | 0, 2895 | 0, 2896 | 0, 2897 | 2, 2898 | 2, 2899 | 1, 2900 | -1, 2901 | 1, 2902 | 1, 2903 | 3, 2904 | 1, 2905 | 0, 2906 | 1, 2907 | 0, 2908 | 0, 2909 | 2, 2910 | 0, 2911 | 2, 2912 | 0, 2913 | 0, 2914 | 2, 2915 | -1, 2916 | 1, 2917 | 1, 2918 | 1, 2919 | 3, 2920 | 1, 2921 | 0, 2922 | 0, 2923 | 1, 2924 | 0, 2925 | 2, 2926 | 0, 2927 | 0, 2928 | 2, 2929 | 0, 2930 | 2, 2931 | -1, 2932 | 1, 2933 | 1, 2934 | 1, 2935 | 3, 2936 | 1, 2937 | 0, 2938 | 0, 2939 | 0, 2940 | 1, 2941 | 2, 2942 | 0, 2943 | 0, 2944 | 0, 2945 | 2, 2946 | 2, 2947 | -1, 2948 | 1, 2949 | 1, 2950 | 1, 2951 | 3, 2952 | 3, 2953 | 2, 2954 | 1, 2955 | 0, 2956 | 0, 2957 | 3, 2958 | 1, 2959 | 2, 2960 | 0, 2961 | 0, 2962 | 4, 2963 | 1, 2964 | 1, 2965 | 1, 2966 | 1, 2967 | 3, 2968 | 3, 2969 | 2, 2970 | 0, 2971 | 1, 2972 | 0, 2973 | 3, 2974 | 1, 2975 | 0, 2976 | 2, 2977 | 0, 2978 | 4, 2979 | 1, 2980 | 1, 2981 | 1, 2982 | 1, 2983 | 3, 2984 | 3, 2985 | 0, 2986 | 2, 2987 | 1, 2988 | 0, 2989 | 3, 2990 | 0, 2991 | 1, 2992 | 2, 2993 | 0, 2994 | 4, 2995 | 1, 2996 | 1, 2997 | 1, 2998 | 1, 2999 | 3, 3000 | 3, 3001 | 2, 3002 | 0, 3003 | 0, 3004 | 1, 3005 | 3, 3006 | 1, 3007 | 0, 3008 | 0, 3009 | 2, 3010 | 4, 3011 | 1, 3012 | 1, 3013 | 1, 3014 | 1, 3015 | 3, 3016 | 3, 3017 | 0, 3018 | 2, 3019 | 0, 3020 | 1, 3021 | 3, 3022 | 0, 3023 | 1, 3024 | 0, 3025 | 2, 3026 | 4, 3027 | 1, 3028 | 1, 3029 | 1, 3030 | 1, 3031 | 3, 3032 | 3, 3033 | 0, 3034 | 0, 3035 | 2, 3036 | 1, 3037 | 3, 3038 | 0, 3039 | 0, 3040 | 1, 3041 | 2, 3042 | 4, 3043 | 1, 3044 | 1, 3045 | 1, 3046 | 1, 3047 | 3, 3048 | 3, 3049 | 2, 3050 | 1, 3051 | 0, 3052 | 0, 3053 | 3, 3054 | 1, 3055 | 2, 3056 | 0, 3057 | 0, 3058 | 2, 3059 | 1, 3060 | 1, 3061 | 1, 3062 | -1, 3063 | 3, 3064 | 3, 3065 | 2, 3066 | 0, 3067 | 1, 3068 | 0, 3069 | 3, 3070 | 1, 3071 | 0, 3072 | 2, 3073 | 0, 3074 | 2, 3075 | 1, 3076 | 1, 3077 | 1, 3078 | -1, 3079 | 3, 3080 | 3, 3081 | 0, 3082 | 2, 3083 | 1, 3084 | 0, 3085 | 3, 3086 | 0, 3087 | 1, 3088 | 2, 3089 | 0, 3090 | 2, 3091 | 1, 3092 | 1, 3093 | 1, 3094 | -1, 3095 | 3, 3096 | 3, 3097 | 2, 3098 | 1, 3099 | 0, 3100 | 0, 3101 | 3, 3102 | 1, 3103 | 2, 3104 | 0, 3105 | 0, 3106 | 2, 3107 | 1, 3108 | 1, 3109 | -1, 3110 | 1, 3111 | 3, 3112 | 3, 3113 | 2, 3114 | 0, 3115 | 0, 3116 | 1, 3117 | 3, 3118 | 1, 3119 | 0, 3120 | 0, 3121 | 2, 3122 | 2, 3123 | 1, 3124 | 1, 3125 | -1, 3126 | 1, 3127 | 3, 3128 | 3, 3129 | 0, 3130 | 2, 3131 | 0, 3132 | 1, 3133 | 3, 3134 | 0, 3135 | 1, 3136 | 0, 3137 | 2, 3138 | 2, 3139 | 1, 3140 | 1, 3141 | -1, 3142 | 1, 3143 | 3, 3144 | 3, 3145 | 2, 3146 | 0, 3147 | 1, 3148 | 0, 3149 | 3, 3150 | 1, 3151 | 0, 3152 | 2, 3153 | 0, 3154 | 2, 3155 | 1, 3156 | -1, 3157 | 1, 3158 | 1, 3159 | 3, 3160 | 3, 3161 | 2, 3162 | 0, 3163 | 0, 3164 | 1, 3165 | 3, 3166 | 1, 3167 | 0, 3168 | 0, 3169 | 2, 3170 | 2, 3171 | 1, 3172 | -1, 3173 | 1, 3174 | 1, 3175 | 3, 3176 | 3, 3177 | 0, 3178 | 0, 3179 | 2, 3180 | 1, 3181 | 3, 3182 | 0, 3183 | 0, 3184 | 1, 3185 | 2, 3186 | 2, 3187 | 1, 3188 | -1, 3189 | 1, 3190 | 1, 3191 | 3, 3192 | 3, 3193 | 0, 3194 | 2, 3195 | 1, 3196 | 0, 3197 | 3, 3198 | 0, 3199 | 1, 3200 | 2, 3201 | 0, 3202 | 2, 3203 | -1, 3204 | 1, 3205 | 1, 3206 | 1, 3207 | 3, 3208 | 3, 3209 | 0, 3210 | 2, 3211 | 0, 3212 | 1, 3213 | 3, 3214 | 0, 3215 | 1, 3216 | 0, 3217 | 2, 3218 | 2, 3219 | -1, 3220 | 1, 3221 | 1, 3222 | 1, 3223 | 3, 3224 | 3, 3225 | 0, 3226 | 0, 3227 | 2, 3228 | 1, 3229 | 3, 3230 | 0, 3231 | 0, 3232 | 1, 3233 | 2, 3234 | 2, 3235 | -1, 3236 | 1, 3237 | 1, 3238 | 1, 3239 | ], 3240 | }; 3241 | 3242 | var Contribution2 = /** @class */ (function () { 3243 | function Contribution2(multiplier, xsb, ysb) { 3244 | this.dx = -xsb - multiplier * constants_1.SQUISH_2D; 3245 | this.dy = -ysb - multiplier * constants_1.SQUISH_2D; 3246 | this.xsb = xsb; 3247 | this.ysb = ysb; 3248 | } 3249 | return Contribution2; 3250 | })(); 3251 | var Contribution3 = /** @class */ (function () { 3252 | function Contribution3(multiplier, xsb, ysb, zsb) { 3253 | this.dx = -xsb - multiplier * constants_1.SQUISH_3D; 3254 | this.dy = -ysb - multiplier * constants_1.SQUISH_3D; 3255 | this.dz = -zsb - multiplier * constants_1.SQUISH_3D; 3256 | this.xsb = xsb; 3257 | this.ysb = ysb; 3258 | this.zsb = zsb; 3259 | } 3260 | return Contribution3; 3261 | })(); 3262 | var Contribution4 = /** @class */ (function () { 3263 | function Contribution4(multiplier, xsb, ysb, zsb, wsb) { 3264 | this.dx = -xsb - multiplier * constants_1.SQUISH_4D; 3265 | this.dy = -ysb - multiplier * constants_1.SQUISH_4D; 3266 | this.dz = -zsb - multiplier * constants_1.SQUISH_4D; 3267 | this.dw = -wsb - multiplier * constants_1.SQUISH_4D; 3268 | this.xsb = xsb; 3269 | this.ysb = ysb; 3270 | this.zsb = zsb; 3271 | this.wsb = wsb; 3272 | } 3273 | return Contribution4; 3274 | })(); 3275 | function shuffleSeed(seed) { 3276 | var newSeed = new Uint32Array(1); 3277 | newSeed[0] = seed[0] * 1664525 + 1013904223; 3278 | return newSeed; 3279 | } 3280 | OpenSimplexNoise = /** @class */ (function () { 3281 | function OpenSimplexNoise(clientSeed) { 3282 | this.initialize(); 3283 | this.perm = new Uint8Array(256); 3284 | this.perm2D = new Uint8Array(256); 3285 | this.perm3D = new Uint8Array(256); 3286 | this.perm4D = new Uint8Array(256); 3287 | var source = new Uint8Array(256); 3288 | for (var i = 0; i < 256; i++) source[i] = i; 3289 | var seed = new Uint32Array(1); 3290 | seed[0] = clientSeed; 3291 | seed = shuffleSeed(shuffleSeed(shuffleSeed(seed))); 3292 | for (var i = 255; i >= 0; i--) { 3293 | seed = shuffleSeed(seed); 3294 | var r = new Uint32Array(1); 3295 | r[0] = (seed[0] + 31) % (i + 1); 3296 | if (r[0] < 0) r[0] += i + 1; 3297 | this.perm[i] = source[r[0]]; 3298 | this.perm2D[i] = this.perm[i] & 0x0e; 3299 | this.perm3D[i] = (this.perm[i] % 24) * 3; 3300 | this.perm4D[i] = this.perm[i] & 0xfc; 3301 | source[r[0]] = source[i]; 3302 | } 3303 | } 3304 | OpenSimplexNoise.prototype.array2D = function (width, height) { 3305 | var output = new Array(width); 3306 | for (var x = 0; x < width; x++) { 3307 | output[x] = new Array(height); 3308 | for (var y = 0; y < height; y++) { 3309 | output[x][y] = this.noise2D(x, y); 3310 | } 3311 | } 3312 | return output; 3313 | }; 3314 | OpenSimplexNoise.prototype.array3D = function (width, height, depth) { 3315 | var output = new Array(width); 3316 | for (var x = 0; x < width; x++) { 3317 | output[x] = new Array(height); 3318 | for (var y = 0; y < height; y++) { 3319 | output[x][y] = new Array(depth); 3320 | for (var z = 0; z < depth; z++) { 3321 | output[x][y][z] = this.noise3D(x, y, z); 3322 | } 3323 | } 3324 | } 3325 | return output; 3326 | }; 3327 | OpenSimplexNoise.prototype.array4D = function (width, height, depth, wLength) { 3328 | var output = new Array(width); 3329 | for (var x = 0; x < width; x++) { 3330 | output[x] = new Array(height); 3331 | for (var y = 0; y < height; y++) { 3332 | output[x][y] = new Array(depth); 3333 | for (var z = 0; z < depth; z++) { 3334 | output[x][y][z] = new Array(wLength); 3335 | for (var w = 0; w < wLength; w++) { 3336 | output[x][y][z][w] = this.noise4D(x, y, z, w); 3337 | } 3338 | } 3339 | } 3340 | } 3341 | return output; 3342 | }; 3343 | OpenSimplexNoise.prototype.noise2D = function (x, y) { 3344 | var stretchOffset = (x + y) * constants_1.STRETCH_2D; 3345 | var xs = x + stretchOffset; 3346 | var ys = y + stretchOffset; 3347 | var xsb = Math.floor(xs); 3348 | var ysb = Math.floor(ys); 3349 | var squishOffset = (xsb + ysb) * constants_1.SQUISH_2D; 3350 | var dx0 = x - (xsb + squishOffset); 3351 | var dy0 = y - (ysb + squishOffset); 3352 | var xins = xs - xsb; 3353 | var yins = ys - ysb; 3354 | var inSum = xins + yins; 3355 | var hash = (xins - yins + 1) | (inSum << 1) | ((inSum + yins) << 2) | ((inSum + xins) << 4); 3356 | var value = 0; 3357 | for (var c = this.lookup2D[hash]; c !== undefined; c = c.next) { 3358 | var dx = dx0 + c.dx; 3359 | var dy = dy0 + c.dy; 3360 | var attn = 2 - dx * dx - dy * dy; 3361 | if (attn > 0) { 3362 | var px = xsb + c.xsb; 3363 | var py = ysb + c.ysb; 3364 | var indexPartA = this.perm[px & 0xff]; 3365 | var index = this.perm2D[(indexPartA + py) & 0xff]; 3366 | var valuePart = constants_1.gradients2D[index] * dx + constants_1.gradients2D[index + 1] * dy; 3367 | value += attn * attn * attn * attn * valuePart; 3368 | } 3369 | } 3370 | return value * constants_1.NORM_2D; 3371 | }; 3372 | OpenSimplexNoise.prototype.noise3D = function (x, y, z) { 3373 | var stretchOffset = (x + y + z) * constants_1.STRETCH_3D; 3374 | var xs = x + stretchOffset; 3375 | var ys = y + stretchOffset; 3376 | var zs = z + stretchOffset; 3377 | var xsb = Math.floor(xs); 3378 | var ysb = Math.floor(ys); 3379 | var zsb = Math.floor(zs); 3380 | var squishOffset = (xsb + ysb + zsb) * constants_1.SQUISH_3D; 3381 | var dx0 = x - (xsb + squishOffset); 3382 | var dy0 = y - (ysb + squishOffset); 3383 | var dz0 = z - (zsb + squishOffset); 3384 | var xins = xs - xsb; 3385 | var yins = ys - ysb; 3386 | var zins = zs - zsb; 3387 | var inSum = xins + yins + zins; 3388 | var hash = 3389 | (yins - zins + 1) | 3390 | ((xins - yins + 1) << 1) | 3391 | ((xins - zins + 1) << 2) | 3392 | (inSum << 3) | 3393 | ((inSum + zins) << 5) | 3394 | ((inSum + yins) << 7) | 3395 | ((inSum + xins) << 9); 3396 | var value = 0; 3397 | for (var c = this.lookup3D[hash]; c !== undefined; c = c.next) { 3398 | var dx = dx0 + c.dx; 3399 | var dy = dy0 + c.dy; 3400 | var dz = dz0 + c.dz; 3401 | var attn = 2 - dx * dx - dy * dy - dz * dz; 3402 | if (attn > 0) { 3403 | var px = xsb + c.xsb; 3404 | var py = ysb + c.ysb; 3405 | var pz = zsb + c.zsb; 3406 | var indexPartA = this.perm[px & 0xff]; 3407 | var indexPartB = this.perm[(indexPartA + py) & 0xff]; 3408 | var index = this.perm3D[(indexPartB + pz) & 0xff]; 3409 | var valuePart = 3410 | constants_1.gradients3D[index] * dx + 3411 | constants_1.gradients3D[index + 1] * dy + 3412 | constants_1.gradients3D[index + 2] * dz; 3413 | value += attn * attn * attn * attn * valuePart; 3414 | } 3415 | } 3416 | return value * constants_1.NORM_3D; 3417 | }; 3418 | OpenSimplexNoise.prototype.noise4D = function (x, y, z, w) { 3419 | var stretchOffset = (x + y + z + w) * constants_1.STRETCH_4D; 3420 | var xs = x + stretchOffset; 3421 | var ys = y + stretchOffset; 3422 | var zs = z + stretchOffset; 3423 | var ws = w + stretchOffset; 3424 | var xsb = Math.floor(xs); 3425 | var ysb = Math.floor(ys); 3426 | var zsb = Math.floor(zs); 3427 | var wsb = Math.floor(ws); 3428 | var squishOffset = (xsb + ysb + zsb + wsb) * constants_1.SQUISH_4D; 3429 | var dx0 = x - (xsb + squishOffset); 3430 | var dy0 = y - (ysb + squishOffset); 3431 | var dz0 = z - (zsb + squishOffset); 3432 | var dw0 = w - (wsb + squishOffset); 3433 | var xins = xs - xsb; 3434 | var yins = ys - ysb; 3435 | var zins = zs - zsb; 3436 | var wins = ws - wsb; 3437 | var inSum = xins + yins + zins + wins; 3438 | var hash = 3439 | (zins - wins + 1) | 3440 | ((yins - zins + 1) << 1) | 3441 | ((yins - wins + 1) << 2) | 3442 | ((xins - yins + 1) << 3) | 3443 | ((xins - zins + 1) << 4) | 3444 | ((xins - wins + 1) << 5) | 3445 | (inSum << 6) | 3446 | ((inSum + wins) << 8) | 3447 | ((inSum + zins) << 11) | 3448 | ((inSum + yins) << 14) | 3449 | ((inSum + xins) << 17); 3450 | var value = 0; 3451 | for (var c = this.lookup4D[hash]; c !== undefined; c = c.next) { 3452 | var dx = dx0 + c.dx; 3453 | var dy = dy0 + c.dy; 3454 | var dz = dz0 + c.dz; 3455 | var dw = dw0 + c.dw; 3456 | var attn = 2 - dx * dx - dy * dy - dz * dz - dw * dw; 3457 | if (attn > 0) { 3458 | var px = xsb + c.xsb; 3459 | var py = ysb + c.ysb; 3460 | var pz = zsb + c.zsb; 3461 | var pw = wsb + c.wsb; 3462 | var indexPartA = this.perm[px & 0xff]; 3463 | var indexPartB = this.perm[(indexPartA + py) & 0xff]; 3464 | var indexPartC = this.perm[(indexPartB + pz) & 0xff]; 3465 | var index = this.perm4D[(indexPartC + pw) & 0xff]; 3466 | var valuePart = 3467 | constants_1.gradients4D[index] * dx + 3468 | constants_1.gradients4D[index + 1] * dy + 3469 | constants_1.gradients4D[index + 2] * dz + 3470 | constants_1.gradients4D[index + 3] * dw; 3471 | value += attn * attn * attn * attn * valuePart; 3472 | } 3473 | } 3474 | return value * constants_1.NORM_4D; 3475 | }; 3476 | OpenSimplexNoise.prototype.initialize = function () { 3477 | var contributions2D = []; 3478 | for (var i = 0; i < constants_1.p2D.length; i += 4) { 3479 | var baseSet = constants_1.base2D[constants_1.p2D[i]]; 3480 | var previous = null; 3481 | var current = null; 3482 | for (var k = 0; k < baseSet.length; k += 3) { 3483 | current = new Contribution2(baseSet[k], baseSet[k + 1], baseSet[k + 2]); 3484 | if (previous === null) contributions2D[i / 4] = current; 3485 | else previous.next = current; 3486 | previous = current; 3487 | } 3488 | current.next = new Contribution2(constants_1.p2D[i + 1], constants_1.p2D[i + 2], constants_1.p2D[i + 3]); 3489 | } 3490 | this.lookup2D = []; 3491 | for (var i = 0; i < constants_1.lookupPairs2D.length; i += 2) { 3492 | this.lookup2D[constants_1.lookupPairs2D[i]] = contributions2D[constants_1.lookupPairs2D[i + 1]]; 3493 | } 3494 | var contributions3D = []; 3495 | for (var i = 0; i < constants_1.p3D.length; i += 9) { 3496 | var baseSet = constants_1.base3D[constants_1.p3D[i]]; 3497 | var previous = null; 3498 | var current = null; 3499 | for (var k = 0; k < baseSet.length; k += 4) { 3500 | current = new Contribution3(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3]); 3501 | if (previous === null) contributions3D[i / 9] = current; 3502 | else previous.next = current; 3503 | previous = current; 3504 | } 3505 | current.next = new Contribution3( 3506 | constants_1.p3D[i + 1], 3507 | constants_1.p3D[i + 2], 3508 | constants_1.p3D[i + 3], 3509 | constants_1.p3D[i + 4] 3510 | ); 3511 | current.next.next = new Contribution3( 3512 | constants_1.p3D[i + 5], 3513 | constants_1.p3D[i + 6], 3514 | constants_1.p3D[i + 7], 3515 | constants_1.p3D[i + 8] 3516 | ); 3517 | } 3518 | this.lookup3D = []; 3519 | for (var i = 0; i < constants_1.lookupPairs3D.length; i += 2) { 3520 | this.lookup3D[constants_1.lookupPairs3D[i]] = contributions3D[constants_1.lookupPairs3D[i + 1]]; 3521 | } 3522 | var contributions4D = []; 3523 | for (var i = 0; i < constants_1.p4D.length; i += 16) { 3524 | var baseSet = constants_1.base4D[constants_1.p4D[i]]; 3525 | var previous = null; 3526 | var current = null; 3527 | for (var k = 0; k < baseSet.length; k += 5) { 3528 | current = new Contribution4(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3], baseSet[k + 4]); 3529 | if (previous === null) contributions4D[i / 16] = current; 3530 | else previous.next = current; 3531 | previous = current; 3532 | } 3533 | current.next = new Contribution4( 3534 | constants_1.p4D[i + 1], 3535 | constants_1.p4D[i + 2], 3536 | constants_1.p4D[i + 3], 3537 | constants_1.p4D[i + 4], 3538 | constants_1.p4D[i + 5] 3539 | ); 3540 | current.next.next = new Contribution4( 3541 | constants_1.p4D[i + 6], 3542 | constants_1.p4D[i + 7], 3543 | constants_1.p4D[i + 8], 3544 | constants_1.p4D[i + 9], 3545 | constants_1.p4D[i + 10] 3546 | ); 3547 | current.next.next.next = new Contribution4( 3548 | constants_1.p4D[i + 11], 3549 | constants_1.p4D[i + 12], 3550 | constants_1.p4D[i + 13], 3551 | constants_1.p4D[i + 14], 3552 | constants_1.p4D[i + 15] 3553 | ); 3554 | } 3555 | this.lookup4D = []; 3556 | for (var i = 0; i < constants_1.lookupPairs4D.length; i += 2) { 3557 | this.lookup4D[constants_1.lookupPairs4D[i]] = contributions4D[constants_1.lookupPairs4D[i + 1]]; 3558 | } 3559 | }; 3560 | return OpenSimplexNoise; 3561 | })(); 3562 | })(); 3563 | --------------------------------------------------------------------------------