diff --git a/dice.css b/dice.css new file mode 100644 index 0000000..c2d81fe --- /dev/null +++ b/dice.css @@ -0,0 +1,71 @@ +.center_field { + position: absolute; + text-align: center; + height: 100%; + width: 100%; +} + +.center_field * { + position: relative; + font-family: Trebuchet MS; + background-color: rgba(255, 255, 255, 0.6); + padding: 5px 15px; +} + +.center_field br { + background-color: rgba(0, 0, 0, 0); +} + +.bottom_field { + position: absolute; + text-align: center; + bottom: 5px; + width: inherit; + padding: 0px; +} + +#label { + font-size: 32pt; + word-spacing: 0.5em; + padding: 5px 15px; + color: rgba(21, 26, 26, 0.6); + top: 45%; +} + +#labelhelp { + font-size: 12pt; + padding: 5px 15px; + color: rgba(21, 26, 26, 0.5); + bottom: 50px; +} + +#set { + text-align: center; + font-size: 26pt; + border: none; + color: rgba(0, 0, 0, 0.8); + background-color: rgba(255, 255, 255, 0); + top: 60%; +} + +#sethelp { + font-size: 12pt; + color: rgba(21, 26, 26, 0.5); + background: none; + top: 25%; +} + +#selector_div button { + font-size: 20pt; + color: rgb(255, 255, 255); + background-color: rgba(0, 0, 0, 0.6); + cursor: pointer; + border: none; + width: 5em; + top: 62%; +} + +.dice_place { + position: absolute; + border: solid black 1px; +} diff --git a/dice.js b/dice.js new file mode 100644 index 0000000..6b9bc56 --- /dev/null +++ b/dice.js @@ -0,0 +1,826 @@ +"use strict"; + +(function(dice) { + + var random_storage = []; + this.use_true_random = true; + this.frame_rate = 1 / 60; + + function prepare_rnd(callback) { + if (!random_storage.length && $t.dice.use_true_random) { + try { + $t.rpc({ method: "random", n: 512 }, + function(random_responce) { + if (!random_responce.error) + random_storage = random_responce.result.random.data; + else $t.dice.use_true_random = false; + callback(); + }); + return; + } + catch (e) { $t.dice.use_true_random = false; } + } + callback(); + } + + function rnd() { + return random_storage.length ? random_storage.pop() : Math.random(); + } + + function create_shape(vertices, faces, radius) { + var cv = new Array(vertices.length), cf = new Array(faces.length); + for (var i = 0; i < vertices.length; ++i) { + var v = vertices[i]; + cv[i] = new CANNON.Vec3(v.x * radius, v.y * radius, v.z * radius); + } + for (var i = 0; i < faces.length; ++i) { + cf[i] = faces[i].slice(0, faces[i].length - 1); + } + return new CANNON.ConvexPolyhedron(cv, cf); + } + + function make_geom(vertices, faces, radius, tab, af) { + var geom = new THREE.Geometry(); + for (var i = 0; i < vertices.length; ++i) { + var vertex = vertices[i].multiplyScalar(radius); + vertex.index = geom.vertices.push(vertex) - 1; + } + for (var i = 0; i < faces.length; ++i) { + var ii = faces[i], fl = ii.length - 1; + var aa = Math.PI * 2 / fl; + for (var j = 0; j < fl - 2; ++j) { + geom.faces.push(new THREE.Face3(ii[0], ii[j + 1], ii[j + 2], [geom.vertices[ii[0]], + geom.vertices[ii[j + 1]], geom.vertices[ii[j + 2]]], 0, ii[fl] + 1)); + geom.faceVertexUvs[0].push([ + new THREE.Vector2((Math.cos(af) + 1 + tab) / 2 / (1 + tab), + (Math.sin(af) + 1 + tab) / 2 / (1 + tab)), + new THREE.Vector2((Math.cos(aa * (j + 1) + af) + 1 + tab) / 2 / (1 + tab), + (Math.sin(aa * (j + 1) + af) + 1 + tab) / 2 / (1 + tab)), + new THREE.Vector2((Math.cos(aa * (j + 2) + af) + 1 + tab) / 2 / (1 + tab), + (Math.sin(aa * (j + 2) + af) + 1 + tab) / 2 / (1 + tab))]); + } + } + geom.computeFaceNormals(); + geom.boundingSphere = new THREE.Sphere(new THREE.Vector3(), radius); + return geom; + } + + function chamfer_geom(vectors, faces, chamfer) { + var chamfer_vectors = [], chamfer_faces = [], corner_faces = new Array(vectors.length); + for (var i = 0; i < vectors.length; ++i) corner_faces[i] = []; + for (var i = 0; i < faces.length; ++i) { + var ii = faces[i], fl = ii.length - 1; + var center_point = new THREE.Vector3(); + var face = new Array(fl); + for (var j = 0; j < fl; ++j) { + var vv = vectors[ii[j]].clone(); + center_point.add(vv); + corner_faces[ii[j]].push(face[j] = chamfer_vectors.push(vv) - 1); + } + center_point.divideScalar(fl); + for (var j = 0; j < fl; ++j) { + var vv = chamfer_vectors[face[j]]; + vv.subVectors(vv, center_point).multiplyScalar(chamfer).addVectors(vv, center_point); + } + face.push(ii[fl]); + chamfer_faces.push(face); + } + for (var i = 0; i < faces.length - 1; ++i) { + for (var j = i + 1; j < faces.length; ++j) { + var pairs = [], lastm = -1; + for (var m = 0; m < faces[i].length - 1; ++m) { + var n = faces[j].indexOf(faces[i][m]); + if (n >= 0 && n < faces[j].length - 1) { + if (lastm >= 0 && m != lastm + 1) pairs.unshift([i, m], [j, n]); + else pairs.push([i, m], [j, n]); + lastm = m; + } + } + if (pairs.length != 4) continue; + chamfer_faces.push([chamfer_faces[pairs[0][0]][pairs[0][1]], + chamfer_faces[pairs[1][0]][pairs[1][1]], + chamfer_faces[pairs[3][0]][pairs[3][1]], + chamfer_faces[pairs[2][0]][pairs[2][1]], -1]); + } + } + for (var i = 0; i < corner_faces.length; ++i) { + var cf = corner_faces[i], face = [cf[0]], count = cf.length - 1; + while (count) { + for (var m = faces.length; m < chamfer_faces.length; ++m) { + var index = chamfer_faces[m].indexOf(face[face.length - 1]); + if (index >= 0 && index < 4) { + if (--index == -1) index = 3; + var next_vertex = chamfer_faces[m][index]; + if (cf.indexOf(next_vertex) >= 0) { + face.push(next_vertex); + break; + } + } + } + --count; + } + face.push(-1); + chamfer_faces.push(face); + } + return { vectors: chamfer_vectors, faces: chamfer_faces }; + } + + function create_geom(vertices, faces, radius, tab, af, chamfer) { + var vectors = new Array(vertices.length); + for (var i = 0; i < vertices.length; ++i) { + vectors[i] = (new THREE.Vector3).fromArray(vertices[i]).normalize(); + } + var cg = chamfer_geom(vectors, faces, chamfer); + var geom = make_geom(cg.vectors, cg.faces, radius, tab, af); + //var geom = make_geom(vectors, faces, radius, tab, af); // Without chamfer + geom.cannon_shape = create_shape(vectors, faces, radius); + return geom; + } + + this.standart_d20_dice_face_labels = [' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20']; + this.standart_d100_dice_face_labels = [' ', '00', '10', '20', '30', '40', '50', + '60', '70', '80', '90']; + + function calc_texture_size(approx) { + return Math.pow(2, Math.floor(Math.log(approx) / Math.log(2))); + } + + this.create_dice_materials = function(face_labels, size, margin) { + function create_text_texture(text, color, back_color) { + if (text == undefined) return null; + var canvas = document.createElement("canvas"); + var context = canvas.getContext("2d"); + var ts = calc_texture_size(size + size * 2 * margin) * 2; + canvas.width = canvas.height = ts; + context.font = ts / (1 + 2 * margin) + "pt Arial"; + context.fillStyle = back_color; + context.fillRect(0, 0, canvas.width, canvas.height); + context.textAlign = "center"; + context.textBaseline = "middle"; + context.fillStyle = color; + context.fillText(text, canvas.width / 2, canvas.height / 2); + if (text == '6' || text == '9') { + context.fillText(' .', canvas.width / 2, canvas.height / 2); + } + var texture = new THREE.Texture(canvas); + texture.needsUpdate = true; + return texture; + } + var materials = []; + for (var i = 0; i < face_labels.length; ++i) + materials.push(new THREE.MeshPhongMaterial($t.copyto(this.material_options, + { map: create_text_texture(face_labels[i], this.label_color, this.dice_color) }))); + return materials; + } + + var d4_labels = [ + [[], [0, 0, 0], [2, 4, 3], [1, 3, 4], [2, 1, 4], [1, 2, 3]], + [[], [0, 0, 0], [2, 3, 4], [3, 1, 4], [2, 4, 1], [3, 2, 1]], + [[], [0, 0, 0], [4, 3, 2], [3, 4, 1], [4, 2, 1], [3, 1, 2]], + [[], [0, 0, 0], [4, 2, 3], [1, 4, 3], [4, 1, 2], [1, 3, 2]] + ]; + + this.create_d4_materials = function(size, margin, labels) { + function create_d4_text(text, color, back_color) { + var canvas = document.createElement("canvas"); + var context = canvas.getContext("2d"); + var ts = calc_texture_size(size + margin) * 2; + canvas.width = canvas.height = ts; + context.font = (ts - margin) / 1.5 + "pt Arial"; + context.fillStyle = back_color; + context.fillRect(0, 0, canvas.width, canvas.height); + context.textAlign = "center"; + context.textBaseline = "middle"; + context.fillStyle = color; + for (var i in text) { + context.fillText(text[i], canvas.width / 2, + canvas.height / 2 - ts * 0.3); + context.translate(canvas.width / 2, canvas.height / 2); + context.rotate(Math.PI * 2 / 3); + context.translate(-canvas.width / 2, -canvas.height / 2); + } + var texture = new THREE.Texture(canvas); + texture.needsUpdate = true; + return texture; + } + var materials = []; + for (var i = 0; i < labels.length; ++i) + materials.push(new THREE.MeshPhongMaterial($t.copyto(this.material_options, + { map: create_d4_text(labels[i], this.label_color, this.dice_color) }))); + return materials; + } + + this.create_d4_geometry = function(radius) { + var vertices = [[1, 1, 1], [-1, -1, 1], [-1, 1, -1], [1, -1, -1]]; + var faces = [[1, 0, 2, 1], [0, 1, 3, 2], [0, 3, 2, 3], [1, 2, 3, 4]]; + return create_geom(vertices, faces, radius, -0.1, Math.PI * 7 / 6, 0.96); + } + + this.create_d6_geometry = function(radius) { + var vertices = [[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], + [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]]; + var faces = [[0, 3, 2, 1, 1], [1, 2, 6, 5, 2], [0, 1, 5, 4, 3], + [3, 7, 6, 2, 4], [0, 4, 7, 3, 5], [4, 5, 6, 7, 6]]; + return create_geom(vertices, faces, radius, 0.1, Math.PI / 4, 0.96); + } + + this.create_d8_geometry = function(radius) { + var vertices = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]]; + var faces = [[0, 2, 4, 1], [0, 4, 3, 2], [0, 3, 5, 3], [0, 5, 2, 4], [1, 3, 4, 5], + [1, 4, 2, 6], [1, 2, 5, 7], [1, 5, 3, 8]]; + return create_geom(vertices, faces, radius, 0, -Math.PI / 4 / 2, 0.965); + } + + this.create_d10_geometry = function(radius) { + var a = Math.PI * 2 / 10, k = Math.cos(a), h = 0.105, v = -1; + var vertices = []; + for (var i = 0, b = 0; i < 10; ++i, b += a) + vertices.push([Math.cos(b), Math.sin(b), h * (i % 2 ? 1 : -1)]); + vertices.push([0, 0, -1]); vertices.push([0, 0, 1]); + var faces = [[5, 7, 11, 0], [4, 2, 10, 1], [1, 3, 11, 2], [0, 8, 10, 3], [7, 9, 11, 4], + [8, 6, 10, 5], [9, 1, 11, 6], [2, 0, 10, 7], [3, 5, 11, 8], [6, 4, 10, 9], + [1, 0, 2, v], [1, 2, 3, v], [3, 2, 4, v], [3, 4, 5, v], [5, 4, 6, v], + [5, 6, 7, v], [7, 6, 8, v], [7, 8, 9, v], [9, 8, 0, v], [9, 0, 1, v]]; + return create_geom(vertices, faces, radius, 0, Math.PI * 6 / 5, 0.945); + } + + this.create_d12_geometry = function(radius) { + var p = (1 + Math.sqrt(5)) / 2, q = 1 / p; + var vertices = [[0, q, p], [0, q, -p], [0, -q, p], [0, -q, -p], [p, 0, q], + [p, 0, -q], [-p, 0, q], [-p, 0, -q], [q, p, 0], [q, -p, 0], [-q, p, 0], + [-q, -p, 0], [1, 1, 1], [1, 1, -1], [1, -1, 1], [1, -1, -1], [-1, 1, 1], + [-1, 1, -1], [-1, -1, 1], [-1, -1, -1]]; + var faces = [[2, 14, 4, 12, 0, 1], [15, 9, 11, 19, 3, 2], [16, 10, 17, 7, 6, 3], [6, 7, 19, 11, 18, 4], + [6, 18, 2, 0, 16, 5], [18, 11, 9, 14, 2, 6], [1, 17, 10, 8, 13, 7], [1, 13, 5, 15, 3, 8], + [13, 8, 12, 4, 5, 9], [5, 4, 14, 9, 15, 10], [0, 12, 8, 10, 16, 11], [3, 19, 7, 17, 1, 12]]; + return create_geom(vertices, faces, radius, 0.2, -Math.PI / 4 / 2, 0.968); + } + + this.create_d20_geometry = function(radius) { + var t = (1 + Math.sqrt(5)) / 2; + var vertices = [[-1, t, 0], [1, t, 0 ], [-1, -t, 0], [1, -t, 0], + [0, -1, t], [0, 1, t], [0, -1, -t], [0, 1, -t], + [t, 0, -1], [t, 0, 1], [-t, 0, -1], [-t, 0, 1]]; + var faces = [[0, 11, 5, 1], [0, 5, 1, 2], [0, 1, 7, 3], [0, 7, 10, 4], [0, 10, 11, 5], + [1, 5, 9, 6], [5, 11, 4, 7], [11, 10, 2, 8], [10, 7, 6, 9], [7, 1, 8, 10], + [3, 9, 4, 11], [3, 4, 2, 12], [3, 2, 6, 13], [3, 6, 8, 14], [3, 8, 9, 15], + [4, 9, 5, 16], [2, 4, 11, 17], [6, 2, 10, 18], [8, 6, 7, 19], [9, 8, 1, 20]]; + return create_geom(vertices, faces, radius, -0.2, -Math.PI / 4 / 2, 0.955); + } + + this.material_options = { + specular: 0x172022, + color: 0xf0f0f0, + shininess: 40, + shading: THREE.FlatShading, + }; + this.label_color = '#aaaaaa'; + this.dice_color = '#202020'; + this.ambient_light_color = 0xf0f5fb; + this.spot_light_color = 0xefdfd5; + this.selector_back_colors = { color: 0x404040, shininess: 0, emissive: 0x858787 }; + this.desk_color = 0xdfdfdf; + this.use_shadows = true; + + this.known_types = ['d4', 'd6', 'd8', 'd10', 'd12', 'd20', 'd100']; + this.dice_face_range = { 'd4': [1, 4], 'd6': [1, 6], 'd8': [1, 8], 'd10': [0, 9], + 'd12': [1, 12], 'd20': [1, 20], 'd100': [0, 9] }; + this.dice_mass = { 'd4': 300, 'd6': 300, 'd8': 340, 'd10': 350, 'd12': 350, 'd20': 400, 'd100': 350 }; + this.dice_inertia = { 'd4': 5, 'd6': 13, 'd8': 10, 'd10': 9, 'd12': 8, 'd20': 6, 'd100': 9 }; + + this.scale = 50; + + this.create_d4 = function() { + if (!this.d4_geometry) this.d4_geometry = this.create_d4_geometry(this.scale * 1.2); + if (!this.d4_material) this.d4_material = new THREE.MeshFaceMaterial( + this.create_d4_materials(this.scale / 2, this.scale * 2, d4_labels[0])); + return new THREE.Mesh(this.d4_geometry, this.d4_material); + } + + this.create_d6 = function() { + if (!this.d6_geometry) this.d6_geometry = this.create_d6_geometry(this.scale * 0.9); + if (!this.dice_material) this.dice_material = new THREE.MeshFaceMaterial( + this.create_dice_materials(this.standart_d20_dice_face_labels, this.scale / 2, 1.0)); + return new THREE.Mesh(this.d6_geometry, this.dice_material); + } + + this.create_d8 = function() { + if (!this.d8_geometry) this.d8_geometry = this.create_d8_geometry(this.scale); + if (!this.dice_material) this.dice_material = new THREE.MeshFaceMaterial( + this.create_dice_materials(this.standart_d20_dice_face_labels, this.scale / 2, 1.2)); + return new THREE.Mesh(this.d8_geometry, this.dice_material); + } + + this.create_d10 = function() { + if (!this.d10_geometry) this.d10_geometry = this.create_d10_geometry(this.scale * 0.9); + if (!this.dice_material) this.dice_material = new THREE.MeshFaceMaterial( + this.create_dice_materials(this.standart_d20_dice_face_labels, this.scale / 2, 1.0)); + return new THREE.Mesh(this.d10_geometry, this.dice_material); + } + + this.create_d12 = function() { + if (!this.d12_geometry) this.d12_geometry = this.create_d12_geometry(this.scale * 0.9); + if (!this.dice_material) this.dice_material = new THREE.MeshFaceMaterial( + this.create_dice_materials(this.standart_d20_dice_face_labels, this.scale / 2, 1.0)); + return new THREE.Mesh(this.d12_geometry, this.dice_material); + } + + this.create_d20 = function() { + if (!this.d20_geometry) this.d20_geometry = this.create_d20_geometry(this.scale); + if (!this.dice_material) this.dice_material = new THREE.MeshFaceMaterial( + this.create_dice_materials(this.standart_d20_dice_face_labels, this.scale / 2, 1.0)); + return new THREE.Mesh(this.d20_geometry, this.dice_material); + } + + this.create_d100 = function() { + if (!this.d10_geometry) this.d10_geometry = this.create_d10_geometry(this.scale * 0.9); + if (!this.d100_material) this.d100_material = new THREE.MeshFaceMaterial( + this.create_dice_materials(this.standart_d100_dice_face_labels, this.scale / 2, 1.5)); + return new THREE.Mesh(this.d10_geometry, this.d100_material); + } + + this.parse_notation = function(notation) { + var no = notation.split('@'); + var dr0 = /\s*(\d*)([a-z]+)(\d+)(\s*(\+|\-)\s*(\d+)){0,1}\s*(\+|$)/gi; + var dr1 = /(\b)*(\d+)(\b)*/gi; + var ret = { set: [], constant: 0, result: [], error: false }, res; + while (res = dr0.exec(no[0])) { + var command = res[2]; + if (command != 'd') { ret.error = true; continue; } + var count = parseInt(res[1]); + if (res[1] == '') count = 1; + var type = 'd' + res[3]; + if (this.known_types.indexOf(type) == -1) { ret.error = true; continue; } + while (count--) ret.set.push(type); + if (res[5] && res[6]) { + if (res[5] == '+') ret.constant += parseInt(res[6]); + else ret.constant -= parseInt(res[6]); + } + } + while (res = dr1.exec(no[1])) { + ret.result.push(parseInt(res[2])); + } + return ret; + } + + this.stringify_notation = function(nn) { + var dict = {}, notation = ''; + for (var i in nn.set) + if (!dict[nn.set[i]]) dict[nn.set[i]] = 1; else ++dict[nn.set[i]]; + for (var i in dict) { + if (notation.length) notation += ' + '; + notation += (dict[i] > 1 ? dict[i] : '') + i; + } + if (nn.constant) { + if (nn.constant > 0) notation += ' + ' + nn.constant; + else notation += ' - ' + Math.abs(nn.constant); + } + return notation; + } + + var that = this; + + this.dice_box = function(container, dimentions) { + this.use_adapvite_timestep = true; + this.animate_selector = true; + + this.dices = []; + this.scene = new THREE.Scene(); + this.world = new CANNON.World(); + + this.renderer = window.WebGLRenderingContext + ? new THREE.WebGLRenderer({ antialias: true }) + : new THREE.CanvasRenderer({ antialias: true }); + container.appendChild(this.renderer.domElement); + this.renderer.shadowMap.enabled = true; + this.renderer.shadowMap.type = THREE.PCFShadowMap; + this.renderer.setClearColor(0xffffff, 1); + + this.reinit(container, dimentions); + + this.world.gravity.set(0, 0, -9.8 * 800); + this.world.broadphase = new CANNON.NaiveBroadphase(); + this.world.solver.iterations = 16; + + var ambientLight = new THREE.AmbientLight(that.ambient_light_color); + this.scene.add(ambientLight); + + this.dice_body_material = new CANNON.Material(); + var desk_body_material = new CANNON.Material(); + var barrier_body_material = new CANNON.Material(); + this.world.addContactMaterial(new CANNON.ContactMaterial( + desk_body_material, this.dice_body_material, 0.01, 0.5)); + this.world.addContactMaterial(new CANNON.ContactMaterial( + barrier_body_material, this.dice_body_material, 0, 1.0)); + this.world.addContactMaterial(new CANNON.ContactMaterial( + this.dice_body_material, this.dice_body_material, 0, 0.5)); + + this.world.add(new CANNON.RigidBody(0, new CANNON.Plane(), desk_body_material)); + var barrier; + barrier = new CANNON.RigidBody(0, new CANNON.Plane(), barrier_body_material); + barrier.quaternion.setFromAxisAngle(new CANNON.Vec3(1, 0, 0), Math.PI / 2); + barrier.position.set(0, this.h * 0.93, 0); + this.world.add(barrier); + + barrier = new CANNON.RigidBody(0, new CANNON.Plane(), barrier_body_material); + barrier.quaternion.setFromAxisAngle(new CANNON.Vec3(1, 0, 0), -Math.PI / 2); + barrier.position.set(0, -this.h * 0.93, 0); + this.world.add(barrier); + + barrier = new CANNON.RigidBody(0, new CANNON.Plane(), barrier_body_material); + barrier.quaternion.setFromAxisAngle(new CANNON.Vec3(0, 1, 0), -Math.PI / 2); + barrier.position.set(this.w * 0.93, 0, 0); + this.world.add(barrier); + + barrier = new CANNON.RigidBody(0, new CANNON.Plane(), barrier_body_material); + barrier.quaternion.setFromAxisAngle(new CANNON.Vec3(0, 1, 0), Math.PI / 2); + barrier.position.set(-this.w * 0.93, 0, 0); + this.world.add(barrier); + + this.last_time = 0; + this.running = false; + + this.renderer.render(this.scene, this.camera); + } + + this.dice_box.prototype.reinit = function(container, dimentions) { + this.cw = container.clientWidth / 2; + this.ch = container.clientHeight / 2; + if (dimentions) { + this.w = dimentions.w; + this.h = dimentions.h; + } + else { + this.w = this.cw; + this.h = this.ch; + } + this.aspect = Math.min(this.cw / this.w, this.ch / this.h); + that.scale = Math.sqrt(this.w * this.w + this.h * this.h) / 13; + + this.renderer.setSize(this.cw * 2, this.ch * 2); + + this.wh = this.ch / this.aspect / Math.tan(10 * Math.PI / 180); + if (this.camera) this.scene.remove(this.camera); + this.camera = new THREE.PerspectiveCamera(20, this.cw / this.ch, 1, this.wh * 1.3); + this.camera.position.z = this.wh; + + var mw = Math.max(this.w, this.h); + if (this.light) this.scene.remove(this.light); + this.light = new THREE.SpotLight(that.spot_light_color, 2.0); + this.light.position.set(-mw / 2, mw / 2, mw * 2); + this.light.target.position.set(0, 0, 0); + this.light.distance = mw * 5; + this.light.castShadow = true; + this.light.shadowCameraNear = mw / 10; + this.light.shadowCameraFar = mw * 5; + this.light.shadowCameraFov = 50; + this.light.shadowBias = 0.001; + this.light.shadowDarkness = 1.1; + this.light.shadowMapWidth = 1024; + this.light.shadowMapHeight = 1024; + this.scene.add(this.light); + + if (this.desk) this.scene.remove(this.desk); + this.desk = new THREE.Mesh(new THREE.PlaneGeometry(this.w * 2, this.h * 2, 1, 1), + new THREE.MeshPhongMaterial({ color: that.desk_color })); + this.desk.receiveShadow = that.use_shadows; + this.scene.add(this.desk); + + this.renderer.render(this.scene, this.camera); + } + + function make_random_vector(vector) { + var random_angle = rnd() * Math.PI / 5 - Math.PI / 5 / 2; + var vec = { + x: vector.x * Math.cos(random_angle) - vector.y * Math.sin(random_angle), + y: vector.x * Math.sin(random_angle) + vector.y * Math.cos(random_angle) + }; + if (vec.x == 0) vec.x = 0.01; + if (vec.y == 0) vec.y = 0.01; + return vec; + } + + this.dice_box.prototype.generate_vectors = function(notation, vector, boost) { + var vectors = []; + for (var i in notation.set) { + var vec = make_random_vector(vector); + var pos = { + x: this.w * (vec.x > 0 ? -1 : 1) * 0.9, + y: this.h * (vec.y > 0 ? -1 : 1) * 0.9, + z: rnd() * 200 + 200 + }; + var projector = Math.abs(vec.x / vec.y); + if (projector > 1.0) pos.y /= projector; else pos.x *= projector; + var velvec = make_random_vector(vector); + var velocity = { x: velvec.x * boost, y: velvec.y * boost, z: -10 }; + var inertia = that.dice_inertia[notation.set[i]]; + var angle = { + x: -(rnd() * vec.y * 5 + inertia * vec.y), + y: rnd() * vec.x * 5 + inertia * vec.x, + z: 0 + }; + var axis = { x: rnd(), y: rnd(), z: rnd(), a: rnd() }; + vectors.push({ set: notation.set[i], pos: pos, velocity: velocity, angle: angle, axis: axis }); + } + return vectors; + } + + this.dice_box.prototype.create_dice = function(type, pos, velocity, angle, axis) { + var dice = that['create_' + type](); + dice.castShadow = true; + dice.dice_type = type; + dice.body = new CANNON.RigidBody(that.dice_mass[type], + dice.geometry.cannon_shape, this.dice_body_material); + dice.body.position.set(pos.x, pos.y, pos.z); + dice.body.quaternion.setFromAxisAngle(new CANNON.Vec3(axis.x, axis.y, axis.z), axis.a * Math.PI * 2); + dice.body.angularVelocity.set(angle.x, angle.y, angle.z); + dice.body.velocity.set(velocity.x, velocity.y, velocity.z); + dice.body.linearDamping = 0.1; + dice.body.angularDamping = 0.1; + this.scene.add(dice); + this.dices.push(dice); + this.world.add(dice.body); + } + + this.dice_box.prototype.check_if_throw_finished = function() { + var res = true; + var e = 6; + if (this.iteration < 10 / that.frame_rate) { + for (var i = 0; i < this.dices.length; ++i) { + var dice = this.dices[i]; + if (dice.dice_stopped === true) continue; + var a = dice.body.angularVelocity, v = dice.body.velocity; + if (Math.abs(a.x) < e && Math.abs(a.y) < e && Math.abs(a.z) < e && + Math.abs(v.x) < e && Math.abs(v.y) < e && Math.abs(v.z) < e) { + if (dice.dice_stopped) { + if (this.iteration - dice.dice_stopped > 3) { + dice.dice_stopped = true; + continue; + } + } + else dice.dice_stopped = this.iteration; + res = false; + } + else { + dice.dice_stopped = undefined; + res = false; + } + } + } + return res; + } + + function get_dice_value(dice) { + var vector = new THREE.Vector3(0, 0, dice.dice_type == 'd4' ? -1 : 1); + var closest_face, closest_angle = Math.PI * 2; + for (var i = 0, l = dice.geometry.faces.length; i < l; ++i) { + var face = dice.geometry.faces[i]; + if (face.materialIndex == 0) continue; + var angle = face.normal.clone().applyQuaternion(dice.body.quaternion).angleTo(vector); + if (angle < closest_angle) { + closest_angle = angle; + closest_face = face; + } + } + var matindex = closest_face.materialIndex - 1; + if (dice.dice_type == 'd100') matindex *= 10; + if (dice.dice_type == 'd10' && matindex == 0) matindex = 10; + return matindex; + } + + function get_dice_values(dices) { + var values = []; + for (var i = 0, l = dices.length; i < l; ++i) { + values.push(get_dice_value(dices[i])); + } + return values; + } + + this.dice_box.prototype.emulate_throw = function() { + while (!this.check_if_throw_finished()) { + ++this.iteration; + this.world.step(that.frame_rate); + } + return get_dice_values(this.dices); + } + + this.dice_box.prototype.__animate = function(threadid) { + var time = (new Date()).getTime(); + var time_diff = (time - this.last_time) / 1000; + if (time_diff > 3) time_diff = that.frame_rate; + ++this.iteration; + if (this.use_adapvite_timestep) { + while (time_diff > that.frame_rate * 1.1) { + this.world.step(that.frame_rate); + time_diff -= that.frame_rate; + } + this.world.step(time_diff); + } + else { + this.world.step(that.frame_rate); + } + for (var i in this.scene.children) { + var interact = this.scene.children[i]; + if (interact.body != undefined) { + interact.position.copy(interact.body.position); + interact.quaternion.copy(interact.body.quaternion); + } + } + this.renderer.render(this.scene, this.camera); + this.last_time = this.last_time ? time : (new Date()).getTime(); + if (this.running == threadid && this.check_if_throw_finished()) { + this.running = false; + if (this.callback) this.callback.call(this, get_dice_values(this.dices)); + } + if (this.running == threadid) { + (function(t, tid, uat) { + if (!uat && time_diff < that.frame_rate) { + setTimeout(function() { requestAnimationFrame(function() { t.__animate(tid); }); }, + (that.frame_rate - time_diff) * 1000); + } + else requestAnimationFrame(function() { t.__animate(tid); }); + })(this, threadid, this.use_adapvite_timestep); + } + } + + this.dice_box.prototype.clear = function() { + this.running = false; + var dice; + while (dice = this.dices.pop()) { + this.scene.remove(dice); + if (dice.body) this.world.remove(dice.body); + } + if (this.pane) this.scene.remove(this.pane); + this.renderer.render(this.scene, this.camera); + var box = this; + setTimeout(function() { box.renderer.render(box.scene, box.camera); }, 100); + } + + this.dice_box.prototype.prepare_dices_for_roll = function(vectors) { + this.clear(); + this.iteration = 0; + for (var i in vectors) { + this.create_dice(vectors[i].set, vectors[i].pos, vectors[i].velocity, + vectors[i].angle, vectors[i].axis); + } + } + + function shift_dice_faces(dice, value, res) { + var r = that.dice_face_range[dice.dice_type]; + if (dice.dice_type == 'd10' && value == 10) value = 0; + if (!(value >= r[0] && value <= r[1])) return; + var num = value - res; + var geom = dice.geometry.clone(); + for (var i = 0, l = geom.faces.length; i < l; ++i) { + var matindex = geom.faces[i].materialIndex; + if (matindex == 0) continue; + matindex += num - 1; + while (matindex > r[1]) matindex -= r[1]; + while (matindex < r[0]) matindex += r[1]; + geom.faces[i].materialIndex = matindex + 1; + } + if (dice.dice_type == 'd4' && num != 0) { + if (num < 0) num += 4; + dice.material = new THREE.MeshFaceMaterial( + that.create_d4_materials(that.scale / 2, that.scale * 2, d4_labels[num])); + } + dice.geometry = geom; + } + + this.dice_box.prototype.roll = function(vectors, values, callback) { + this.prepare_dices_for_roll(vectors); + if (values != undefined && values.length) { + this.use_adapvite_timestep = false; + var res = this.emulate_throw(); + this.prepare_dices_for_roll(vectors); + for (var i in res) + shift_dice_faces(this.dices[i], values[i], res[i]); + } + this.callback = callback; + this.running = (new Date()).getTime(); + this.last_time = 0; + this.__animate(this.running); + } + + this.dice_box.prototype.__selector_animate = function(threadid) { + var time = (new Date()).getTime(); + var time_diff = (time - this.last_time) / 1000; + if (time_diff > 3) time_diff = that.frame_rate; + var angle_change = 0.3 * time_diff * Math.PI * Math.min(24000 + threadid - time, 6000) / 6000; + if (angle_change < 0) this.running = false; + for (var i in this.dices) { + this.dices[i].rotation.y += angle_change; + this.dices[i].rotation.x += angle_change / 4; + this.dices[i].rotation.z += angle_change / 10; + } + this.last_time = time; + this.renderer.render(this.scene, this.camera); + if (this.running == threadid) { + (function(t, tid) { + requestAnimationFrame(function() { t.__selector_animate(tid); }); + })(this, threadid); + } + } + + this.dice_box.prototype.search_dice_by_mouse = function(ev) { + var m = $t.get_mouse_coords(ev); + var intersects = (new THREE.Raycaster(this.camera.position, + (new THREE.Vector3((m.x - this.cw) / this.aspect, + 1 - (m.y - this.ch) / this.aspect, this.w / 9)) + .sub(this.camera.position).normalize())).intersectObjects(this.dices); + if (intersects.length) return intersects[0].object.userData; + } + + this.dice_box.prototype.draw_selector = function() { + this.clear(); + var step = this.w / 4.5; + this.pane = new THREE.Mesh(new THREE.PlaneGeometry(this.w * 6, this.h * 6, 1, 1), + new THREE.MeshPhongMaterial(that.selector_back_colors)); + this.pane.receiveShadow = true; + this.pane.position.set(0, 0, 1); + this.scene.add(this.pane); + + var mouse_captured = false; + + for (var i = 0, pos = -3; i < that.known_types.length; ++i, ++pos) { + var dice = $t.dice['create_' + that.known_types[i]](); + dice.position.set(pos * step, 0, step * 0.5); + dice.castShadow = true; + dice.userData = that.known_types[i]; + this.dices.push(dice); this.scene.add(dice); + } + + this.running = (new Date()).getTime(); + this.last_time = 0; + if (this.animate_selector) this.__selector_animate(this.running); + else this.renderer.render(this.scene, this.camera); + } + + function throw_dices(box, vector, boost, dist, notation_getter, before_roll, after_roll) { + var uat = $t.dice.use_adapvite_timestep; + function roll(request_results) { + if (after_roll) { + box.clear(); + box.roll(vectors, request_results || notation.result, function(result) { + if (after_roll) after_roll.call(box, notation, result); + box.rolling = false; + $t.dice.use_adapvite_timestep = uat; + }); + } + } + vector.x /= dist; vector.y /= dist; + var notation = notation_getter.call(box); + if (notation.set.length == 0) return; + var vectors = box.generate_vectors(notation, vector, boost); + box.rolling = true; + if (before_roll) before_roll.call(box, vectors, notation, roll); + else roll(); + } + + this.dice_box.prototype.bind_mouse = function(container, notation_getter, before_roll, after_roll) { + var box = this; + $t.bind(container, ['mousedown', 'touchstart'], function(ev) { + ev.preventDefault(); + box.mouse_time = (new Date()).getTime(); + box.mouse_start = $t.get_mouse_coords(ev); + }); + $t.bind(container, ['mouseup', 'touchend'], function(ev) { + if (box.rolling) return; + if (box.mouse_start == undefined) return; + ev.stopPropagation(); + var m = $t.get_mouse_coords(ev); + var vector = { x: m.x - box.mouse_start.x, y: -(m.y - box.mouse_start.y) }; + box.mouse_start = undefined; + var dist = Math.sqrt(vector.x * vector.x + vector.y * vector.y); + if (dist < Math.sqrt(box.w * box.h * 0.01)) return; + var time_int = (new Date()).getTime() - box.mouse_time; + if (time_int > 2000) time_int = 2000; + var boost = Math.sqrt((2500 - time_int) / 2500) * dist * 2; + prepare_rnd(function() { + throw_dices(box, vector, boost, dist, notation_getter, before_roll, after_roll); + }); + }); + } + + this.dice_box.prototype.bind_throw = function(button, notation_getter, before_roll, after_roll) { + var box = this; + $t.bind(button, ['mouseup', 'touchend'], function(ev) { + ev.stopPropagation(); + box.start_throw(notation_getter, before_roll, after_roll); + }); + } + + this.dice_box.prototype.start_throw = function(notation_getter, before_roll, after_roll) { + var box = this; + if (box.rolling) return; + prepare_rnd(function() { + var vector = { x: (rnd() * 2 - 1) * box.w, y: -(rnd() * 2 - 1) * box.h }; + var dist = Math.sqrt(vector.x * vector.x + vector.y * vector.y); + var boost = (rnd() + 3) * dist; + throw_dices(box, vector, boost, dist, notation_getter, before_roll, after_roll); + }); + } + +}).apply(teal.dice = teal.dice || {}); + diff --git a/dice.py b/dice.py new file mode 100644 index 0000000..e198b59 --- /dev/null +++ b/dice.py @@ -0,0 +1,38 @@ +import webapp2 +import logging +import json +from google.appengine.api import urlfetch + +root = '/dice/' + +class DiceHandler(webapp2.RequestHandler): + def post(self): + self.response.headers['Content-Type'] = 'application/json-rpc' + data = json.loads(self.request.body) + if data['method'] == 'random': + req = { + "jsonrpc": "2.0", + "method": "generateDecimalFractions", + "params": { + 'apiKey': 'f6e74d7b-070e-4f85-865d-d859fc0d078b', + 'n': data['n'], + 'decimalPlaces': 2, + }, + "id": 1 + } + result = urlfetch.fetch( + url = 'https://api.random.org/json-rpc/1/invoke', + payload = json.dumps(req), + method = urlfetch.POST, + headers = { 'Content-Type': 'application/json-rpc' }, + validate_certificate = False + ) + self.response.write(result.content) + return + + self.response.write('{}') + +app = webapp2.WSGIApplication([ + (root + 'f', DiceHandler), + ], debug = True) + diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..9324d4a Binary files /dev/null and b/favicon.ico differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..f212bee --- /dev/null +++ b/index.html @@ -0,0 +1,59 @@ + + + + + + + +3D Dice Roller + + + + + + + +
+ +

Loading libraries, please wait a bit...

+ +

Original Source

+ + +
+ + +
+ + + + + + + + + + diff --git a/libs/cannon.min.js b/libs/cannon.min.js new file mode 100644 index 0000000..b676f77 --- /dev/null +++ b/libs/cannon.min.js @@ -0,0 +1,3 @@ +(function(){var t=t||{};this.Int32Array||(this.Int32Array=Array,this.Float32Array=Array),t.Mat3=function(t){this.elements=t?t:[0,0,0,0,0,0,0,0,0]},t.Mat3.prototype.identity=function(){this.elements[0]=1,this.elements[1]=0,this.elements[2]=0,this.elements[3]=0,this.elements[4]=1,this.elements[5]=0,this.elements[6]=0,this.elements[7]=0,this.elements[8]=1},t.Mat3.prototype.setZero=function(){var t=this.elements;t[0]=0,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=0,t[6]=0,t[7]=0,t[8]=0},t.Mat3.prototype.setTrace=function(t){var e=this.elements;e[0]=t.x,e[4]=t.y,e[8]=t.z},t.Mat3.prototype.vmult=function(e,i){i=i||new t.Vec3;var n=this.elements,o=e.x,a=e.y,s=e.z;return i.x=n[0]*o+n[1]*a+n[2]*s,i.y=n[3]*o+n[4]*a+n[5]*s,i.z=n[6]*o+n[7]*a+n[8]*s,i},t.Mat3.prototype.smult=function(t){for(var e=0;this.elements.length>e;e++)this.elements[e]*=t},t.Mat3.prototype.mmult=function(e){for(var i=new t.Mat3,n=0;3>n;n++)for(var o=0;3>o;o++){for(var a=0,s=0;3>s;s++)a+=e.elements[n+3*s]*this.elements[s+3*o];i.elements[n+3*o]=a}return i},t.Mat3.prototype.solve=function(e,i){i=i||new t.Vec3;for(var n=3,o=4,a=[],s=0;n*o>s;s++)a.push(0);var s,r;for(s=0;3>s;s++)for(r=0;3>r;r++)a[s+o*r]=this.elements[s+3*r];a[3]=e.x,a[7]=e.y,a[11]=e.z;var h,c,l=3,u=l,p=4;do{if(s=u-l,0===a[s+o*s])for(r=s+1;u>r;r++)if(0!==a[s+o*r]){h=p;do c=p-h,a[c+o*s]+=a[c+o*r];while(--h);break}if(0!==a[s+o*s])for(r=s+1;u>r;r++){var d=a[s+o*r]/a[s+o*s];h=p;do c=p-h,a[c+o*r]=s>=c?0:a[c+o*r]-a[c+o*s]*d;while(--h)}}while(--l);if(i.z=a[2*o+3]/a[2*o+2],i.y=(a[1*o+3]-a[1*o+2]*i.z)/a[1*o+1],i.x=(a[0*o+3]-a[0*o+2]*i.z-a[0*o+1]*i.y)/a[0*o+0],isNaN(i.x)||isNaN(i.y)||isNaN(i.z)||1/0===i.x||1/0===i.y||1/0===i.z)throw"Could not solve equation! Got x=["+(""+i)+"], b=["+(""+e)+"], A=["+(""+this)+"]";return i},t.Mat3.prototype.e=function(t,e,i){return void 0===i?this.elements[e+3*t]:(this.elements[e+3*t]=i,void 0)},t.Mat3.prototype.copy=function(e){e=e||new t.Mat3;for(var i=0;this.elements.length>i;i++)e.elements[i]=this.elements[i];return e},t.Mat3.prototype.toString=function(){for(var t="",e=",",i=0;9>i;i++)t+=this.elements[i]+e;return t},t.Mat3.prototype.reverse=function(e){e=e||new t.Mat3;for(var i=3,n=6,o=[],a=0;i*n>a;a++)o.push(0);var a,s;for(a=0;3>a;a++)for(s=0;3>s;s++)o[a+n*s]=this.elements[a+3*s];o[3]=1,o[9]=0,o[15]=0,o[4]=0,o[10]=1,o[16]=0,o[5]=0,o[11]=0,o[17]=1;var r,h,c=3,l=c,u=n;do{if(a=l-c,0===o[a+n*a])for(s=a+1;l>s;s++)if(0!==o[a+n*s]){r=u;do h=u-r,o[h+n*a]+=o[h+n*s];while(--r);break}if(0!==o[a+n*a])for(s=a+1;l>s;s++){var p=o[a+n*s]/o[a+n*a];r=u;do h=u-r,o[h+n*s]=a>=h?0:o[h+n*s]-o[h+n*a]*p;while(--r)}}while(--c);a=2;do{s=a-1;do{var p=o[a+n*s]/o[a+n*a];r=n;do h=n-r,o[h+n*s]=o[h+n*s]-o[h+n*a]*p;while(--r)}while(s--)}while(--a);a=2;do{var p=1/o[a+n*a];r=n;do h=n-r,o[h+n*a]=o[h+n*a]*p;while(--r)}while(a--);a=2;do{s=2;do{if(h=o[i+s+n*a],isNaN(h)||1/0===h)throw"Could not reverse! A=["+(""+this)+"]";e.e(a,s,h)}while(s--)}while(a--);return e},t.Vec3=function(t,e,i){this.x=t||0,this.y=e||0,this.z=i||0},t.Vec3.prototype.cross=function(e,i){var n=e.x,o=e.y,a=e.z,s=this.x,r=this.y,h=this.z;return i=i||new t.Vec3,i.x=r*a-h*o,i.y=h*n-s*a,i.z=s*o-r*n,i},t.Vec3.prototype.set=function(t,e,i){return this.x=t,this.y=e,this.z=i,this},t.Vec3.prototype.vadd=function(e,i){return i?(i.x=e.x+this.x,i.y=e.y+this.y,i.z=e.z+this.z,void 0):new t.Vec3(this.x+e.x,this.y+e.y,this.z+e.z)},t.Vec3.prototype.vsub=function(e,i){return i?(i.x=this.x-e.x,i.y=this.y-e.y,i.z=this.z-e.z,void 0):new t.Vec3(this.x-e.x,this.y-e.y,this.z-e.z)},t.Vec3.prototype.crossmat=function(){return new t.Mat3([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},t.Vec3.prototype.normalize=function(){var t=this.x,e=this.y,i=this.z,n=Math.sqrt(t*t+e*e+i*i);if(n>0){var o=1/n;this.x*=o,this.y*=o,this.z*=o}else this.x=0,this.y=0,this.z=0;return n},t.Vec3.prototype.unit=function(e){e=e||new t.Vec3;var i=this.x,n=this.y,o=this.z,a=Math.sqrt(i*i+n*n+o*o);return a>0?(a=1/a,e.x=i*a,e.y=n*a,e.z=o*a):(e.x=1,e.y=0,e.z=0),e},t.Vec3.prototype.norm=function(){var t=this.x,e=this.y,i=this.z;return Math.sqrt(t*t+e*e+i*i)},t.Vec3.prototype.norm2=function(){return this.dot(this)},t.Vec3.prototype.distanceTo=function(t){var e=this.x,i=this.y,n=this.z,o=t.x,a=t.y,s=t.z;return Math.sqrt((o-e)*(o-e)+(a-i)*(a-i)+(s-n)*(s-n))},t.Vec3.prototype.mult=function(e,i){i=i||new t.Vec3;var n=this.x,o=this.y,a=this.z;return i.x=e*n,i.y=e*o,i.z=e*a,i},t.Vec3.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},t.Vec3.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},t.Vec3.prototype.negate=function(e){return e=e||new t.Vec3,e.x=-this.x,e.y=-this.y,e.z=-this.z,e};var e=new t.Vec3,i=new t.Vec3;t.Vec3.prototype.tangents=function(t,n){var o=this.norm();if(o>0){var a=e,s=1/o;a.set(this.x*s,this.y*s,this.z*s);var r=i;.9>Math.abs(a.x)?(r.set(1,0,0),a.cross(r,t)):(r.set(0,1,0),a.cross(r,t)),a.cross(t,n)}else t.set(1,0,0).normalize(),n.set(0,1,0).normalize()},t.Vec3.prototype.toString=function(){return this.x+","+this.y+","+this.z},t.Vec3.prototype.copy=function(e){return e=e||new t.Vec3,e.x=this.x,e.y=this.y,e.z=this.z,e},t.Vec3.prototype.lerp=function(t,e,i){var n=this.x,o=this.y,a=this.z;i.x=n+(t.x-n)*e,i.y=o+(t.y-o)*e,i.z=a+(t.z-a)*e},t.Vec3.prototype.almostEquals=function(t,e){return void 0===e&&(e=1e-6),Math.abs(this.x-t.x)>e||Math.abs(this.y-t.y)>e||Math.abs(this.z-t.z)>e?!1:!0},t.Vec3.prototype.almostZero=function(t){return void 0===t&&(t=1e-6),Math.abs(this.x)>t||Math.abs(this.y)>t||Math.abs(this.z)>t?!1:!0},t.Quaternion=function(t,e,i,n){this.x=void 0!==t?t:0,this.y=void 0!==e?e:0,this.z=void 0!==i?i:0,this.w=void 0!==n?n:1},t.Quaternion.prototype.set=function(t,e,i,n){this.x=t,this.y=e,this.z=i,this.w=n},t.Quaternion.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},t.Quaternion.prototype.setFromAxisAngle=function(t,e){var i=Math.sin(.5*e);this.x=t.x*i,this.y=t.y*i,this.z=t.z*i,this.w=Math.cos(.5*e)},t.Quaternion.prototype.toAxisAngle=function(e){e=e||new t.Vec3,this.normalize();var i=2*Math.acos(this.w),n=Math.sqrt(1-this.w*this.w);return.001>n?(e.x=this.x,e.y=this.y,e.z=this.z):(e.x=this.x/n,e.y=this.y/n,e.z=this.z/n),[e,i]},t.Quaternion.prototype.setFromVectors=function(t,e){var i=t.cross(e);this.x=i.x,this.y=i.y,this.z=i.z,this.w=Math.sqrt(Math.pow(t.norm(),2)*Math.pow(e.norm(),2))+t.dot(e),this.normalize()};var n=new t.Vec3,o=new t.Vec3,a=new t.Vec3;t.Quaternion.prototype.mult=function(e,i){i=i||new t.Quaternion;var s=this.w,r=n,h=o,c=a;return r.set(this.x,this.y,this.z),h.set(e.x,e.y,e.z),i.w=s*e.w-r.dot(h),r.cross(h,c),i.x=s*h.x+e.w*r.x+c.x,i.y=s*h.y+e.w*r.y+c.y,i.z=s*h.z+e.w*r.z+c.z,i},t.Quaternion.prototype.inverse=function(e){var i=this.x,n=this.y,o=this.z,a=this.w;e=e||new t.Quaternion,this.conjugate(e);var s=1/(i*i+n*n+o*o+a*a);return e.x*=s,e.y*=s,e.z*=s,e.w*=s,e},t.Quaternion.prototype.conjugate=function(e){return e=e||new t.Quaternion,e.x=-this.x,e.y=-this.y,e.z=-this.z,e.w=this.w,e},t.Quaternion.prototype.normalize=function(){var t=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(t=1/t,this.x*=t,this.y*=t,this.z*=t,this.w*=t)},t.Quaternion.prototype.normalizeFast=function(){var t=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=t,this.y*=t,this.z*=t,this.w*=t)},t.Quaternion.prototype.vmult=function(e,i){if(i=i||new t.Vec3,0===this.w)i.x=e.x,i.y=e.y,i.z=e.z;else{var n=e.x,o=e.y,a=e.z,s=this.x,r=this.y,h=this.z,c=this.w,l=c*n+r*a-h*o,u=c*o+h*n-s*a,p=c*a+s*o-r*n,d=-s*n-r*o-h*a;i.x=l*c+d*-s+u*-h-p*-r,i.y=u*c+d*-r+p*-s-l*-h,i.z=p*c+d*-h+l*-r-u*-s}return i},t.Quaternion.prototype.copy=function(t){t.x=this.x,t.y=this.y,t.z=this.z,t.w=this.w},t.Quaternion.prototype.toEuler=function(t,e){e=e||"YZX";var i,n,o,a=this.x,s=this.y,r=this.z,h=this.w;switch(e){case"YZX":var c=a*s+r*h;if(c>.499&&(i=2*Math.atan2(a,h),n=Math.PI/2,o=0),-.499>c&&(i=-2*Math.atan2(a,h),n=-Math.PI/2,o=0),isNaN(i)){var l=a*a,u=s*s,p=r*r;i=Math.atan2(2*s*h-2*a*r,1-2*u-2*p),n=Math.asin(2*c),o=Math.atan2(2*a*h-2*s*r,1-2*l-2*p)}break;default:throw Error("Euler order "+e+" not supported yet.")}t.y=i,t.z=n,t.x=o},t.EventTarget=function(){var t={};this.addEventListener=function(e,i){void 0===t[e]&&(t[e]=[]),-1===t[e].indexOf(i)&&t[e].push(i)},this.dispatchEvent=function(e){for(var i in t[e.type])t[e.type][i](e)},this.removeEventListener=function(e,i){var n=t[e].indexOf(i);-1!==n&&t[e].splice(n,1)}},t.ObjectPool=function(){this.objects=[],this.type=Object},t.ObjectPool.prototype.release=function(){for(var t=arguments.length,e=0;e!==t;e++)this.objects.push(arguments[e])},t.ObjectPool.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},t.ObjectPool.prototype.constructObject=function(){throw Error("constructObject() not implemented in this ObjectPool subclass yet!")},t.Vec3Pool=function(){t.ObjectPool.call(this),this.type=t.Vec3},t.Vec3Pool.prototype=new t.ObjectPool,t.Vec3Pool.prototype.constructObject=function(){return new t.Vec3},t.Shape=function(){this.type=0,this.aabbmin=new t.Vec3,this.aabbmax=new t.Vec3,this.boundingSphereRadius=0,this.boundingSphereRadiusNeedsUpdate=!0},t.Shape.prototype.constructor=t.Shape,t.Shape.prototype.computeBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},t.Shape.prototype.getBoundingSphereRadius=function(){return this.boundingSphereRadiusNeedsUpdate&&this.computeBoundingSphereRadius(),this.boundingSphereRadius},t.Shape.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},t.Shape.prototype.calculateLocalInertia=function(){throw"calculateLocalInertia() not implemented for shape type "+this.type};var s=new t.Vec3,r=new t.Vec3;t.Shape.prototype.calculateTransformedInertia=function(e,i,n){n=n||new t.Vec3;var o=s,a=r;return this.calculateLocalInertia(e,o),i.vmult(o,a),n.x=Math.abs(a.x),n.y=Math.abs(a.y),n.z=Math.abs(a.z),n},t.Shape.calculateLocalAABB=function(){throw Error(".calculateLocalAABB is not implemented for this Shape yet!")},t.Shape.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16},t.Body=function(e){t.EventTarget.apply(this),this.type=e,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new t.Vec3,this.collisionFilterGroup=1,this.collisionFilterMask=1},t.Body.DYNAMIC=1,t.Body.STATIC=2,t.Body.KINEMATIC=4,t.Particle=function(e,i){if("number"!=typeof e)throw Error("Argument 1 (mass) must be a number.");if(i!==void 0&&!(i instanceof t.Material))throw Error("Argument 3 (material) must be an instance of CANNON.Material.");t.Body.call(this,"particle"),this.position=new t.Vec3,this.initPosition=new t.Vec3,this.velocity=new t.Vec3,this.initVelocity=new t.Vec3,this.force=new t.Vec3,this.mass=e,this.invMass=e>0?1/e:0,this.material=i,this.linearDamping=.01,this.motionstate=0>=e?t.Body.STATIC:t.Body.DYNAMIC,this.allowSleep=!0,this.sleepState=0,this.sleepSpeedLimit=.1,this.sleepTimeLimit=1,this.timeLastSleepy=0},t.Particle.prototype=new t.Body,t.Particle.prototype.constructor=t.Particle,t.Particle.prototype.isAwake=function(){return 0===this.sleepState},t.Particle.prototype.isSleepy=function(){return 1===this.sleepState},t.Particle.prototype.isSleeping=function(){return 2===this.sleepState},t.Particle.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=0,2===t&&this.dispatchEvent({type:"wakeup"})},t.Particle.prototype.sleep=function(){this.sleepState=2},t.Particle.prototype.sleepTick=function(t){if(this.allowSleep){var e=this.sleepState,i=this.velocity.norm2(),n=Math.pow(this.sleepSpeedLimit,2);0===e&&n>i?(this.sleepState=1,this.timeLastSleepy=t,this.dispatchEvent({type:"sleepy"})):1===e&&i>n?this.wakeUp():1===e&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleepState=2,this.dispatchEvent({type:"sleep"}))}},t.RigidBody=function(e,i,n){if("number"!=typeof e)throw Error("Argument 1 (mass) must be a number.");if(n!==void 0&&!(n instanceof t.Material))throw Error("Argument 3 (material) must be an instance of CANNON.Material.");t.Particle.call(this,e,n),this.tau=new t.Vec3,this.quaternion=new t.Quaternion,this.initQuaternion=new t.Quaternion,this.angularVelocity=new t.Vec3,this.initAngularVelocity=new t.Vec3,this.shape=i,this.inertia=new t.Vec3,i.calculateLocalInertia(e,this.inertia),this.inertiaWorld=new t.Vec3,this.inertia.copy(this.inertiaWorld),this.inertiaWorldAutoUpdate=!1,this.invInertia=new t.Vec3(this.inertia.x>0?1/this.inertia.x:0,this.inertia.y>0?1/this.inertia.y:0,this.inertia.z>0?1/this.inertia.z:0),this.invInertiaWorld=new t.Vec3,this.invInertia.copy(this.invInertiaWorld),this.invInertiaWorldAutoUpdate=!1,this.angularDamping=.01,this.aabbmin=new t.Vec3,this.aabbmax=new t.Vec3,this.aabbNeedsUpdate=!0,this.wlambda=new t.Vec3},t.RigidBody.prototype=new t.Particle(0),t.RigidBody.prototype.constructor=t.RigidBody,t.RigidBody.prototype.computeAABB=function(){this.shape.calculateWorldAABB(this.position,this.quaternion,this.aabbmin,this.aabbmax),this.aabbNeedsUpdate=!1};var h=new t.Vec3,c=new t.Vec3;t.RigidBody.prototype.applyForce=function(t,e){var i=h;e.vsub(this.position,i);var n=c;i.cross(t,n),this.force.vadd(t,this.force),this.tau.vadd(n,this.tau)};var l=new t.Vec3,u=new t.Vec3,p=new t.Vec3;t.RigidBody.prototype.applyImpulse=function(t,e){var i=l;e.vsub(this.position,i);var n=u;t.copy(n),n.mult(this.invMass,n),this.velocity.vadd(n,this.velocity);var o=p;i.cross(t,o),o.x*=this.invInertia.x,o.y*=this.invInertia.y,o.z*=this.invInertia.z,this.angularVelocity.vadd(o,this.angularVelocity)},t.Sphere=function(e){t.Shape.call(this),this.radius=void 0!==e?Number(e):1,this.type=t.Shape.types.SPHERE},t.Sphere.prototype=new t.Shape,t.Sphere.prototype.constructor=t.Sphere,t.Sphere.prototype.calculateLocalInertia=function(e,i){i=i||new t.Vec3;var n=2*e*this.radius*this.radius/5;return i.x=n,i.y=n,i.z=n,i},t.Sphere.prototype.volume=function(){return 4*Math.PI*this.radius/3},t.Sphere.prototype.computeBoundingSphereRadius=function(){this.boundingSphereRadiusNeedsUpdate=!1,this.boundingSphereRadius=this.radius},t.Sphere.prototype.calculateWorldAABB=function(t,e,i,n){for(var o=this.radius,a=["x","y","z"],s=0;a.length>s;s++){var r=a[s];i[r]=t[r]-o,n[r]=t[r]+o}},t.SPHSystem=function(){this.particles=[],this.density=1,this.smoothingRadius=1,this.speedOfSound=1,this.viscosity=.01,this.eps=1e-6,this.pressures=[],this.densities=[],this.neighbors=[]},t.SPHSystem.prototype.add=function(t){this.particles.push(t),this.neighbors.lengththis.particles.length&&this.neighbors.pop())};var d=new t.Vec3;t.SPHSystem.prototype.getNeighbors=function(t,e){for(var i=this.particles.length,n=t.id,o=this.smoothingRadius*this.smoothingRadius,a=d,s=0;s!==i;s++){var r=this.particles[s];r.position.vsub(t.position,a),n!==r.id&&o>a.norm2()&&e.push(r)}};var v=new t.Vec3,y=new t.Vec3,f=new t.Vec3,m=new t.Vec3,w=new t.Vec3,b=new t.Vec3;t.SPHSystem.prototype.update=function(){for(var t=this.particles.length,e=v,i=this.speedOfSound,n=this.eps,o=0;o!==t;o++){var a=this.particles[o],s=this.neighbors[o];s.length=0,this.getNeighbors(a,s),s.push(this.particles[o]);for(var r=s.length,h=0,c=0;c!==r;c++){a.position.vsub(s[c].position,e);var l=e.norm(),u=this.w(l);h+=s[c].mass*u}this.densities[o]=h,this.pressures[o]=i*i*(this.densities[o]-this.density)}for(var p=y,d=f,x=m,g=w,V=b,o=0;o!==t;o++){var z=this.particles[o];p.set(0,0,0),d.set(0,0,0);for(var E,S,s=this.neighbors[o],r=s.length,c=0;c!==r;c++){var N=s[c];z.position.vsub(N.position,g);var M=g.norm();E=-N.mass*(this.pressures[o]/(this.densities[o]*this.densities[o]+n)+this.pressures[c]/(this.densities[c]*this.densities[c]+n)),this.gradw(g,x),x.mult(E,x),p.vadd(x,p),N.velocity.vsub(z.velocity,V),V.mult(1/(1e-4+this.densities[o]*this.densities[c])*this.viscosity*N.mass,V),S=this.nablaw(M),V.mult(S,V),d.vadd(V,d)}d.mult(z.mass,d),p.mult(z.mass,p),z.force.vadd(d,z.force),z.force.vadd(p,z.force)}},t.SPHSystem.prototype.w=function(t){var e=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(e,9))*Math.pow(e*e-t*t,3)},t.SPHSystem.prototype.gradw=function(t,e){var i=t.norm(),n=this.smoothingRadius;t.mult(945/(32*Math.PI*Math.pow(n,9))*Math.pow(n*n-i*i,2),e)},t.SPHSystem.prototype.nablaw=function(t){var e=this.smoothingRadius,i=945/(32*Math.PI*Math.pow(e,9))*(e*e-t*t)*(7*t*t-3*e*e);return i},t.Box=function(e){t.Shape.call(this),this.halfExtents=e,this.type=t.Shape.types.BOX,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation()},t.Box.prototype=new t.Shape,t.Box.prototype.constructor=t.Box,t.Box.prototype.updateConvexPolyhedronRepresentation=function(){var e=this.halfExtents.x,i=this.halfExtents.y,n=this.halfExtents.z,o=t.Vec3,a=new t.ConvexPolyhedron([new o(-e,-i,-n),new o(e,-i,-n),new o(e,i,-n),new o(-e,i,-n),new o(-e,-i,n),new o(e,-i,n),new o(e,i,n),new o(-e,i,n)],[[3,2,1,0],[4,5,6,7],[5,4,1,0],[2,3,6,7],[0,4,7,3],[1,2,5,6]],[new o(0,0,-1),new o(0,0,1),new o(0,-1,0),new o(0,1,0),new o(-1,0,0),new o(1,0,0)]);this.convexPolyhedronRepresentation=a},t.Box.prototype.calculateLocalInertia=function(e,i){i=i||new t.Vec3;var n=this.halfExtents;return i.x=1/12*e*(2*2*n.y*n.y+2*2*n.z*n.z),i.y=1/12*e*(2*2*n.x*n.x+2*2*n.z*n.z),i.z=1/12*e*(2*2*n.y*n.y+2*2*n.x*n.x),i},t.Box.prototype.getSideNormals=function(t,e){var i=t,n=this.halfExtents;if(i[0].set(n.x,0,0),i[1].set(0,n.y,0),i[2].set(0,0,n.z),i[3].set(-n.x,0,0),i[4].set(0,-n.y,0),i[5].set(0,0,-n.z),void 0!==e)for(var o=0;o!==i.length;o++)e.vmult(i[o],i[o]);return i},t.Box.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},t.Box.prototype.computeBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm(),this.boundingSphereRadiusNeedsUpdate=!1};var x=new t.Vec3;new t.Vec3,t.Box.prototype.forEachWorldCorner=function(t,e,i){for(var n=this.halfExtents,o=[[n.x,n.y,n.z],[-n.x,n.y,n.z],[-n.x,-n.y,n.z],[-n.x,-n.y,-n.z],[n.x,-n.y,-n.z],[n.x,n.y,-n.z],[-n.x,n.y,-n.z],[n.x,-n.y,n.z]],a=0;o.length>a;a++)x.set(o[a][0],o[a][1],o[a][2]),e.vmult(x,x),t.vadd(x,x),i(x.x,x.y,x.z)},t.Box.prototype.calculateWorldAABB=function(t,e,i,n){i.set(1/0,1/0,1/0),n.set(-1/0,-1/0,-1/0),this.forEachWorldCorner(t,e,function(t,e,o){t>n.x&&(n.x=t),e>n.y&&(n.y=e),o>n.z&&(n.z=o),i.x>t&&(i.x=t),i.y>e&&(i.y=e),i.z>o&&(i.z=o)})},t.Plane=function(){t.Shape.call(this),this.type=t.Shape.types.PLANE,this.worldNormal=new t.Vec3,this.worldNormalNeedsUpdate=!0},t.Plane.prototype=new t.Shape,t.Plane.prototype.constructor=t.Plane,t.Plane.prototype.computeWorldNormal=function(t){var e=this.worldNormal;e.set(0,0,1),t.vmult(e,e),this.worldNormalNeedsUpdate=!1},t.Plane.prototype.calculateLocalInertia=function(e,i){return i=i||new t.Vec3},t.Plane.prototype.volume=function(){return 1/0};var g=new t.Vec3;t.Plane.prototype.calculateWorldAABB=function(t,e,i,n){g.set(0,0,1),e.vmult(g,g),i.set(-1/0,-1/0,-1/0),n.set(1/0,1/0,1/0),1===g.x&&(n.x=t.x),1===g.y&&(n.y=t.y),1===g.z&&(n.z=t.z),-1===g.x&&(i.x=t.x),-1===g.y&&(i.y=t.y),-1===g.z&&(i.z=t.z)},t.Compound=function(){t.Shape.call(this),this.type=t.Shape.types.COMPOUND,this.childShapes=[],this.childOffsets=[],this.childOrientations=[]},t.Compound.prototype=new t.Shape,t.Compound.prototype.constructor=t.Compound,t.Compound.prototype.addChild=function(e,i,n){i=i||new t.Vec3,n=n||new t.Quaternion,this.childShapes.push(e),this.childOffsets.push(i),this.childOrientations.push(n)},t.Compound.prototype.volume=function(){for(var t=0,e=this.childShapes.length,i=0;i!==e;i++)t+=this.childShapes[i].volume();return t};var V=new t.Vec3,z=new t.Vec3;t.Compound.prototype.calculateLocalInertia=function(e,i){i=i||new t.Vec3;for(var n=this.volume(),o=z,a=0,s=this.childShapes.length;a!==s;a++){var r=this.childShapes[a],h=this.childOffsets[a];this.childOrientations[a];var c=r.volume()/n*e;r.calculateLocalInertia(c,o),i.vadd(o,i);var l=V;l.set(c*h.x*h.x,c*h.y*h.y,c*h.z*h.z),i.vadd(l,i)}return i},t.Compound.prototype.computeBoundingSphereRadius=function(){for(var t=0,e=0;this.childShapes.length>e;e++){var i=this.childShapes[e];i.boundingSphereRadiusNeedsUpdate&&i.computeBoundingSphereRadius();var n=this.childOffsets[e].norm()+i.boundingSphereRadius;n>t&&(t=n)}this.boundingSphereRadius=t,this.boundingSphereRadiusNeedsUpdate=!1};var E=new t.Vec3,S=new t.Vec3,N=new t.Vec3,M=new t.Quaternion;t.Compound.prototype.calculateWorldAABB=function(t,e,i,n){var o=this.childShapes.length;i.set(1/0,1/0,1/0),n.set(-1/0,-1/0,-1/0);for(var a=0;a!==o;a++)this.childOffsets[a].copy(N),e.vmult(N,N),t.vadd(N,N),e.mult(this.childOrientations[a],M),this.childShapes[a].calculateWorldAABB(N,M,S,E),S.xn.x&&(n.x=E.x),E.y>n.y&&(n.y=E.y),E.z>n.z&&(n.z=E.z)},t.ConvexPolyhedron=function(e,i){function n(t,e,i,n){e.vsub(t,c),i.vsub(e,h),h.cross(c,n),n.isZero()||n.normalize()}function o(t,e,i,n,o){for(var a=t.vertices.length,s=null,r=null,h=t.vertices,c=0;a>c;c++){h[c].copy(V),n.vmult(V,V),V.vadd(i,V);var l=V.dot(e);(null===s||l>s)&&(s=l),(null===r||r>l)&&(r=l)}if(r>s){var u=r;r=s,s=u}o[0]=s,o[1]=r}function a(t,e){var i=r.faces[t],o=r.vertices[i[0]],a=r.vertices[i[1]],s=r.vertices[i[2]];return n(o,a,s,e)}function s(t){var e=r.faces[t],i=r.faceNormals[t],n=r.vertices[e[0]],o=-i.dot(n);return o}var r=this;t.Shape.call(this),this.type=t.Shape.types.CONVEXPOLYHEDRON;var h=new t.Vec3,c=new t.Vec3;this.vertices=e||[],this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.faces=i||[],this.faceNormals=[];for(var l=0;this.faces.length>l;l++){for(var u=0;this.faces[l].length>u;u++)if(!this.vertices[this.faces[l][u]])throw Error("Vertex "+this.faces[l][u]+" not found!");var p=new t.Vec3;a(l,p),p.negate(p),this.faceNormals.push(p);var d=this.vertices[this.faces[l][0]];if(0>p.dot(d)){console.warn("Face normal "+l+" ("+(""+p)+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");for(var u=0;this.faces[l].length>u;u++)console.warn("Vertex "+this.faces[l][u]+": ("+(""+this.vertices[i[l][u]])+")")}}this.worldFaceNormalsNeedsUpdate=!0,this.worldFaceNormals=[],this.uniqueEdges=[];for(var v=this.vertices.length,y=0;v>y;y++){var f=this.vertices[y];if(!(f instanceof t.Vec3))throw"Argument 1 must be instance of CANNON.Vec3";this.uniqueEdges.push(f)}for(var l=0;this.faces.length>l;l++)for(var m=this.faces[l].length,w=m,u=0;w>u;u++){var b=(u+1)%m,x=new t.Vec3;this.vertices[this.faces[l][u]].vsub(this.vertices[this.faces[l][b]],x),x.normalize();for(var g=!1,f=0;this.uniqueEdges.length>f;f++)if(this.uniqueEdges[f].almostEquals(x)||this.uniqueEdges[f].almostEquals(x)){g=!0;break}g||this.uniqueEdges.push(x),x&&(x.face1=l)}var V=new t.Vec3;this.testSepAxis=function(t,e,i,n,a,s){var r=[],h=[],c=this;o(c,t,i,n,r),o(e,t,a,s,h);var l=r[0],u=r[1],p=h[0],d=h[1];if(d>l||u>p)return!1;var v=l-d,y=p-u,f=y>v?v:y;return f};var z=new t.Vec3,E=new t.Vec3,S=new t.Vec3,N=new t.Vec3,M=new t.Vec3,P=new t.Vec3;this.findSeparatingAxis=function(t,e,i,n,o,a){for(var s=1/0,r=this,h=0,c=r.faces.length,l=0;c>l;l++){r.faceNormals[l].copy(z),i.vmult(z,z);var u=r.testSepAxis(z,t,e,i,n,o);if(u===!1)return!1;s>u&&(s=u,z.copy(a))}for(var p=t.faces.length,l=0;p>l;l++){t.faceNormals[l].copy(E),o.vmult(E,E),h++;var u=r.testSepAxis(E,t,e,i,n,o);if(u===!1)return!1;s>u&&(s=u,E.copy(a))}for(var d=0,v=0;r.uniqueEdges.length>v;v++){r.uniqueEdges[v].copy(N),i.vmult(N,N);for(var y=0;t.uniqueEdges.length>y;y++)if(t.uniqueEdges[y].copy(M),o.vmult(M,M),N.cross(M,P),d++,!P.almostZero()){P.normalize();var f=r.testSepAxis(P,t,e,i,n,o);if(f===!1)return!1;s>f&&(s=f,P.copy(a))}}return n.vsub(e,S),S.dot(a)>0&&a.negate(a),!0};var q=new t.Vec3;this.clipAgainstHull=function(e,i,n,o,a,s,r,h,c){if(!(e instanceof t.Vec3))throw Error("posA must be Vec3");if(!(i instanceof t.Quaternion))throw Error("quatA must be Quaternion");for(var l=-1,u=-1/0,p=0;n.faces.length>p;p++){n.faceNormals[p].copy(q),a.vmult(q,q);var d=q.dot(s);d>u&&(u=d,l=p)}for(var v=[],y=n.faces[l],f=y.length,m=0;f>m;m++){var w=n.vertices[y[m]],b=new t.Vec3;w.copy(b),a.vmult(b,b),o.vadd(b,b),v.push(b)}l>=0&&this.clipFaceAgainstHull(s,e,i,v,r,h,c)};var j=new t.Vec3,C=new t.Vec3,B=new t.Vec3,I=new t.Vec3,R=new t.Vec3,O=new t.Vec3,A=new t.Vec3,T=new t.Vec3;this.clipFaceAgainstHull=function(e,i,n,o,a,r,h){if(!(e instanceof t.Vec3))throw Error("sep normal must be vector");if(!(o instanceof Array))throw Error("world verts must be array");a=Number(a),r=Number(r);for(var c=this,l=[],u=o,p=l,d=-1,v=1/0,y=0;c.faces.length>y;y++){c.faceNormals[y].copy(j),n.vmult(j,j);var f=j.dot(e);v>f&&(v=f,d=y)}if(0>d)return console.log("--- did not find any closest face... ---"),void 0;var m=c.faces[d];m.connectedFaces=[];for(var w=0;c.faces.length>w;w++)for(var b=0;c.faces[w].length>b;b++)-1!==m.indexOf(c.faces[w][b])&&w!==d&&-1===m.connectedFaces.indexOf(w)&&m.connectedFaces.push(w);u.length;for(var x=m.length,g=0;x>g;g++){var V=c.vertices[m[g]],z=c.vertices[m[(g+1)%x]];V.vsub(z,C),C.copy(B),n.vmult(B,B),i.vadd(B,B),this.faceNormals[d].copy(I),n.vmult(I,I),i.vadd(I,I),B.cross(I,R),R.negate(R),V.copy(O),n.vmult(O,O),i.vadd(O,O);var E,S=(-O.dot(R),m.connectedFaces[g]);this.faceNormals[S].copy(A);var N=s(S);A.copy(T),n.vmult(T,T);var E=N-T.dot(i);for(this.clipFaceAgainstPlane(u,p,T,E);u.length;)u.shift();for(;p.length;)u.push(p.shift())}this.faceNormals[d].copy(A);var N=s(d);A.copy(T),n.vmult(T,T);for(var E=N-T.dot(i),w=0;u.length>w;w++){var M=T.dot(u[w])+E;if(a>=M&&(console.log("clamped: depth="+M+" to minDist="+(a+"")),M=a),r>=M){var P=u[w];if(0>=M){var q={point:P,normal:T,depth:M};h.push(q)}}}},this.clipFaceAgainstPlane=function(e,i,n,o){if(!(n instanceof t.Vec3))throw Error("planeNormal must be Vec3, "+n+" given");if(!(e instanceof Array))throw Error("invertices must be Array, "+e+" given");if(!(i instanceof Array))throw Error("outvertices must be Array, "+i+" given");var a,s,r=e.length;if(2>r)return i;var h=e[e.length-1],c=e[0];a=n.dot(h)+o;for(var l=0;r>l;l++){if(c=e[l],s=n.dot(c)+o,0>a)if(0>s){var u=new t.Vec3;c.copy(u),i.push(u)}else{var u=new t.Vec3;h.lerp(c,a/(a-s),u),i.push(u)}else if(0>s){var u=new t.Vec3;h.lerp(c,a/(a-s),u),i.push(u),i.push(c)}h=c,a=s}return i};var r=this;this.calculateLocalInertia=function(t,e){r.computeAABB();var i=this.aabbmax.x-this.aabbmin.x,n=this.aabbmax.y-this.aabbmin.y,o=this.aabbmax.z-this.aabbmin.z;e.x=1/12*t*(2*2*n*n+2*2*o*o),e.y=1/12*t*(2*2*i*i+2*2*o*o),e.z=1/12*t*(2*2*n*n+2*2*i*i)},new t.Vec3,this.computeAABB=function(){var t=this.vertices.length,e=this.aabbmin,i=this.aabbmax,n=this.vertices;e.set(1/0,1/0,1/0),i.set(-1/0,-1/0,-1/0);for(var o=0;t>o;o++){var a=n[o];a.xi.x&&(i.x=a.x),a.yi.y&&(i.y=a.y),a.zi.z&&(i.z=a.z)}}},t.ConvexPolyhedron.prototype=new t.Shape,t.ConvexPolyhedron.prototype.constructor=t.ConvexPolyhedron,t.ConvexPolyhedron.prototype.computeWorldVertices=function(e,i){for(var n=this.vertices.length;n>this.worldVertices.length;)this.worldVertices.push(new t.Vec3);for(var o=this.vertices,a=this.worldVertices,s=0;s!==n;s++)i.vmult(o[s],a[s]),e.vadd(a[s],a[s]);this.worldVerticesNeedsUpdate=!1},t.ConvexPolyhedron.prototype.computeWorldFaceNormals=function(e){for(var i=this.faceNormals.length;i>this.worldFaceNormals.length;)this.worldFaceNormals.push(new t.Vec3);for(var n=this.faceNormals,o=this.worldFaceNormals,a=0;a!==i;a++)e.vmult(n[a],o[a]);this.worldFaceNormalsNeedsUpdate=!1},t.ConvexPolyhedron.prototype.computeBoundingSphereRadius=function(){for(var t=0,e=this.vertices,i=0,n=e.length;i!==n;i++){var o=e[i].norm2();o>t&&(t=o)}this.boundingSphereRadius=Math.sqrt(t),this.boundingSphereRadiusNeedsUpdate=!1};var P=new t.Vec3;t.ConvexPolyhedron.prototype.calculateWorldAABB=function(t,e,i,n){for(var o,a,s,r,h,c,l=this.vertices.length,u=this.vertices,p=0;l>p;p++){u[p].copy(P),e.vmult(P,P),t.vadd(P,P);var d=P;o>d.x||void 0===o?o=d.x:(d.x>r||void 0===r)&&(r=d.x),a>d.y||void 0===a?a=d.y:(d.y>h||void 0===h)&&(h=d.y),s>d.z||void 0===s?s=d.z:(d.z>c||void 0===c)&&(c=d.z)}i.set(o,a,s),n.set(r,h,c)},t.ConvexPolyhedron.prototype.volume=function(){return this.boundingSphereRadiusNeedsUpdate&&this.computeBoundingSphereRadius(),4*Math.PI*this.boundingSphereRadius/3},t.ConvexPolyhedron.prototype.getAveragePointLocal=function(e){e=e||new t.Vec3;for(var i=this.vertices.length,n=this.vertices,o=0;i>o;o++)e.vadd(n[o],e);return e.mult(1/i,e),e},t.ConvexPolyhedron.prototype.transformAllPoints=function(t,e){var i=this.vertices.length,n=this.vertices;if(e){for(var o=0;i>o;o++){var a=n[o];e.vmult(a,a)}for(var o=0;this.faceNormals.length>o;o++){var a=this.faceNormals[o];e.vmult(a,a)}}if(t)for(var o=0;i>o;o++){var a=n[o];a.vadd(t,a)}};var q=new t.Vec3,j=new t.Vec3,C=new t.Vec3;t.ConvexPolyhedron.prototype.pointIsInside=function(t){var e=this.vertices.length,i=this.vertices,n=this.faces,o=this.faceNormals,a=null,s=this.faces.length,r=q;this.getAveragePointLocal(r);for(var h=0;s>h;h++){this.faces[h].length;var e=o[h],c=i[n[h][0]],l=j;t.vsub(c,l);var u=e.dot(l),p=C;r.vsub(c,p);var d=e.dot(p);if(0>u&&d>0||u>0&&0>d)return!1}return a?1:-1},t.Cylinder=function(e,i,n,o){var a=o,s=[],r=[],h=[],c=[],l=[],u=Math.cos,p=Math.sin;s.push(new t.Vec3(i*u(0),i*p(0),.5*-n)),c.push(0),s.push(new t.Vec3(e*u(0),e*p(0),.5*n)),l.push(1);for(var d=0;a>d;d++){var v=2*Math.PI/a*(d+1),y=2*Math.PI/a*(d+.5);a-1>d?(s.push(new t.Vec3(i*u(v),i*p(v),.5*-n)),c.push(2*d+2),s.push(new t.Vec3(e*u(v),e*p(v),.5*n)),l.push(2*d+3),r.push(new t.Vec3(u(y),p(y),0)),h.push([2*d+2,2*d+3,2*d+1,2*d])):(h.push([0,1,2*d+1,2*d]),r.push(new t.Vec3(u(y),p(y),0)))}h.push(l),r.push(new t.Vec3(0,0,1));for(var f=[],d=0;c.length>d;d++)f.push(c[c.length-d-1]);h.push(f),r.push(new t.Vec3(0,0,-1)),this.type=t.Shape.types.CONVEXPOLYHEDRON,t.ConvexPolyhedron.call(this,s,h,r)},t.Cylinder.prototype=new t.ConvexPolyhedron,t.Ray=function(e,i){function n(t,e,i){return i.vsub(t,V),p=V.dot(e),e.mult(p,z),z.vadd(t,z),d=i.distanceTo(z)}function o(t,e,i,n){return n.vsub(e,V),i.vsub(e,E),t.vsub(e,S),v=V.dot(V),y=V.dot(E),f=V.dot(S),m=E.dot(E),w=E.dot(S),b=1/(v*m-y*y),x=(m*f-y*w)*b,g=(v*w-y*f)*b,x>=0&&g>=0&&1>x+g}this.origin=e||new t.Vec3,this.direction=i||new t.Vec3;var a=1e-4;this.setPrecision=function(t){a=t};var s=new t.Vec3,r=new t.Vec3,h=new t.Vec3;new t.Vec3,new t.Vec3;var c=new t.Vec3,l=new t.Vec3,u=new t.Vec3;this.intersectBody=function(e){return e.shape instanceof t.ConvexPolyhedron?this.intersectShape(e.shape,e.quaternion,e.position,e):e.shape instanceof t.Box?this.intersectShape(e.shape.convexPolyhedronRepresentation,e.quaternion,e.position,e):(console.warn("Ray intersection is this far only implemented for ConvexPolyhedron and Box shapes."),void 0)},this.intersectShape=function(e,i,p,d){var v,y=[];if(e instanceof t.ConvexPolyhedron){var f=n(this.origin,this.direction,p);if(f>e.getBoundingSphereRadius())return y;for(var m,w,b=e.faces,x=e.vertices,g=e.faceNormals,V=0;b.length>V;V++){var z=b[V],E=g[V],S=i,N=p;if(x[z[0]].copy(c),S.vmult(c,c),c.vadd(N,c),c.vsub(this.origin,c),S.vmult(E,l),m=this.direction.dot(l),!(a>Math.abs(m))&&(w=l.dot(c)/m,!(0>w)&&0>m)){this.direction.mult(w,u),u.vadd(this.origin,u),x[z[0]].copy(s),S.vmult(s,s),N.vadd(s,s);for(var M=1;z.length-1>M;M++)if(x[z[M]].copy(r),x[z[M+1]].copy(h),S.vmult(r,r),S.vmult(h,h),N.vadd(r,r),N.vadd(h,h),o(u,s,r,h)){v={distance:this.origin.distanceTo(u),point:u.copy(),face:z,body:d},y.push(v);break}}}}return y},this.intersectBodies=function(t){for(var e=[],i=0,n=t.length;n>i;i++){var o=this.intersectBody(t[i]);Array.prototype.push.apply(e,o)}return e.sort(function(t,e){return t.distance-e.distance}),e};var p,d,v,y,f,m,w,b,x,g,V=new t.Vec3,z=new t.Vec3,E=new t.Vec3,S=new t.Vec3},t.Ray.prototype.constructor=t.Ray,t.Broadphase=function(){this.world=null,this.useBoundingBoxes=!1},t.Broadphase.prototype.constructor=t.BroadPhase,t.Broadphase.prototype.collisionPairs=function(){throw Error("collisionPairs not implemented for this BroadPhase class!") +};var B=t.Body.STATIC|t.Body.KINEMATIC;t.Broadphase.prototype.needBroadphaseCollision=function(e,i){return 0===(e.collisionFilterGroup&i.collisionFilterMask)||0===(i.collisionFilterGroup&e.collisionFilterMask)?!1:0===(e.motionstate&B)&&!e.isSleeping()||0===(i.motionstate&B)&&!i.isSleeping()?e.shape||i.shape?e.shape instanceof t.Plane&&i.shape instanceof t.Plane?!1:!0:!1:!1},t.Broadphase.prototype.intersectionTest=function(t,e,i,n){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,i,n):this.doBoundingSphereBroadphase(t,e,i,n)};var I=new t.Vec3,R=new t.Vec3,O=(new t.Quaternion,new t.Vec3);t.Broadphase.prototype.doBoundingSphereBroadphase=function(e,i,n,o){var a=t.Shape.types,s=a.SPHERE|a.BOX|a.COMPOUND|a.CONVEXPOLYHEDRON,r=a.PLANE;t.Body.STATIC|t.Body.KINEMATIC;var h=I,c=R,l=O,u=e.shape,p=i.shape;if(u&&p){var d=u.type,v=p.type;if(d&s&&v&s){i.position.vsub(e.position,h),u.boundingSphereRadiusNeedsUpdate&&u.computeBoundingSphereRadius(),p.boundingSphereRadiusNeedsUpdate&&p.computeBoundingSphereRadius();var y=u.boundingSphereRadius+p.boundingSphereRadius;y*y>h.norm2()&&(n.push(e),o.push(i))}else if(d&s&&v&a.PLANE||v&s&&d&a.PLANE){var f=d===r?e:i,m=d!==r?e:i,w=m.shape,b=f.shape;m.position.vsub(f.position,h),b.worldNormalNeedsUpdate&&b.computeWorldNormal(f.quaternion),c=b.worldNormal,w.boundingSphereRadiusNeedsUpdate&&w.computeBoundingSphereRadius();var x=h.dot(c)-w.boundingSphereRadius;0>x&&(n.push(e),o.push(i))}}else if(u||p){var g=u?i:e,V=u?e:i,w=V.shape,z=w.type;if(z&s){if(z===a.SPHERE)g.position.vsub(V.position,l),w.radius*w.radius>=l.norm2()&&(n.push(g),o.push(V));else if(z===a.CONVEXPOLYHEDRON||z===a.BOX||z===a.COMPOUND){w.boundingSphereRadiusNeedsUpdate&&w.computeBoundingSphereRadius();var E=w.boundingSphereRadius;g.position.vsub(V.position,l),E*E>=l.norm2()&&(n.push(g),o.push(V))}}else if(z===a.PLANE){var S=V;c.set(0,0,1),S.quaternion.vmult(c,c),g.position.vsub(S.position,l),0>=c.dot(l)&&(n.push(g),o.push(V))}}else;},t.Broadphase.prototype.doBoundingBoxBroadphase=function(e,i,n,o){var a=e.shape,s=i.shape;if(e.aabbNeedsUpdate&&e.computeAABB(),i.aabbNeedsUpdate&&i.computeAABB(),a&&s)e.aabbmax.xi.aabbmax.x||e.aabbmin.y>i.aabbmax.y||e.aabbmin.z>i.aabbmax.z||(n.push(e),o.push(i));else if(a||s){var r=a?i:e,h=a?e:i;h.shape instanceof t.Plane,r.position.xh.aabbmax.x||r.position.y>h.aabbmax.y||r.position.z>h.aabbmax.z||(n.push(e),o.push(i))}else;};var A={},T=[],F=[];t.Broadphase.prototype.makePairsUnique=function(t,e){for(var i=A,n=T,o=F,a=t.length,s=0;s!==a;s++)n[s]=t[s],o[s]=e[s];t.length=0,e.length=0;for(var s=0;s!==a;s++){var r=n[s].id,h=o[s].id,c=h>r?r+","+h:h+","+r;i[c]=s}for(var c in i){var s=i[c];t.push(n[s]),e.push(o[s]),delete i[c]}},t.NaiveBroadphase=function(){t.Broadphase.apply(this)},t.NaiveBroadphase.prototype=new t.Broadphase,t.NaiveBroadphase.prototype.constructor=t.NaiveBroadphase,t.NaiveBroadphase.prototype.collisionPairs=function(t,e,i){var n,o,a,s,r=t.bodies,h=r.length;for(n=0;n!==h;n++)for(o=0;o!==n;o++)a=r[n],s=r[o],this.needBroadphaseCollision(a,s)&&this.intersectionTest(a,s,e,i)},t.GridBroadphase=function(e,i,n,o,a){t.Broadphase.apply(this),this.nx=n||10,this.ny=o||10,this.nz=a||10,this.aabbMin=e||new t.Vec3(100,100,100),this.aabbMax=i||new t.Vec3(-100,-100,-100),this.bins=[]},t.GridBroadphase.prototype=new t.Broadphase,t.GridBroadphase.prototype.constructor=t.GridBroadphase;var k=new t.Vec3,U=new t.Vec3;t.GridBroadphase.prototype.collisionPairs=function(e,i,n){var o=e.numObjects(),a=e.bodies,s=this.aabbMax,r=this.aabbMin,h=this.nx,c=this.ny,l=this.nz,u=s.x,p=s.y,d=s.z,v=r.x,y=r.y,f=r.z,m=h/(u-v),w=c/(p-y),b=l/(d-f),x=(u-v)/h,g=(p-y)/c,V=(d-f)/l,z=t.Shape.types,E=z.SPHERE,S=z.PLANE;z.BOX,z.COMPOUND,z.CONVEXPOLYHEDRON;for(var N=this.bins,M=h*c*l,P=N.length-1;P!==M;P++)N.push([]);for(var P=0;P!==M;P++)N[P].length=0;for(var q=Math.floor,P=0;P!==o;P++){var j=a[P],C=j.shape;switch(C.type){case E:for(var B=j.position.x,I=j.position.y,R=j.position.z,O=C.radius,A=q(m*(B-O-v)),T=q(w*(I-O-y)),F=q(b*(R-O-f)),W=q(m*(B+O-v)),L=q(w*(I+O-y)),D=q(b*(R+O-f)),H=A;H!==W+1;H++)for(var Q=T;Q!==L+1;Q++)for(var X=F;X!==D+1;X++){var G=H,Y=Q,Z=X,_=G*(c-1)*(l-1)+Y*(l-1)+Z;_>=0&&M>_&&N[_].push(j)}break;case S:var K=k,J=U,$=.25*(x*x+g*g+V*V),te=C.worldNormal;C.worldNormalNeedsUpdate&&C.computeWorldNormal(j.quaternion);for(var H=0;H!==h;H++)for(var Q=0;Q!==c;Q++)for(var X=0;X!==l;X++){var G=H,Y=Q,Z=X;if(J.set(G*x+v,Y*g+y,Z*V+f),J.vsub(j.position,K),$>K.dot(te)){var _=G*(c-1)*(l-1)+Y*(l-1)+Z;N[_].push(j)}}break;default:console.warn("Shape "+C.type+" not supported in GridBroadphase!")}}for(var P=0;P!==M;P++)for(var ee=N[P],H=0,ie=ee.length;H!==ie;H++)for(var j=ee[H],Q=0;Q!==H;Q++){var ne=ee[Q];this.needBroadphaseCollision(j,ne)&&this.intersectionTest(j,ne,i,n)}this.makePairsUnique(i,n)},t.Solver=function(){this.equations=[]},t.Solver.prototype.solve=function(){return 0},t.Solver.prototype.addEquation=function(t){this.equations.push(t)},t.Solver.prototype.removeEquation=function(t){var e=this.equations,i=e.indexOf(t);-1!==i&&e.splice(i,1)},t.Solver.prototype.removeAllEquations=function(){this.equations.length=0},t.GSSolver=function(){t.Solver.call(this),this.iterations=10,this.tolerance=0},t.GSSolver.prototype=new t.Solver;var W=[],L=[],D=[];t.GSSolver.prototype.solve=function(t,e){var i,n,o,a,s,r,h=(this.d,this.k,0),c=this.iterations,l=this.tolerance*this.tolerance,u=(this.a,this.b),p=this.equations,d=p.length,v=e.bodies,y=v.length,f=t,m=L,w=D,b=W;m.length=0,w.length=0,b.length=0;for(var x=0;x!==d;x++){var g=p[x];g.spookParamsNeedsUpdate&&(g.updateSpookParams(f),g.spookParamsNeedsUpdate=!1),b[x]=0,w[x]=g.computeB(f),m[x]=1/g.computeC()}if(0!==d){for(var x=0;x!==y;x++){var u=v[x],V=u.vlambda,z=u.wlambda;V.set(0,0,0),z&&z.set(0,0,0)}for(h=0;h!==c;h++){a=0;for(var E=0;E!==d;E++){var g=p[E];i=w[E],n=m[E],r=b[E],s=g.computeGWlambda(),o=n*(i-s-g.eps*r),g.minForce>r+o?o=g.minForce-r:r+o>g.maxForce&&(o=g.maxForce-r),b[E]+=o,a+=o>0?o:-o,g.addToWlambda(o)}if(l>a*a)break}for(var x=0;x!==y;x++){var u=v[x],S=u.velocity,N=u.angularVelocity;S.vadd(u.vlambda,S),N&&N.vadd(u.wlambda,N)}}return h},t.SplitSolver=function(e){t.Solver.call(this),this.subsolver=e},t.SplitSolver.prototype=new t.Solver;var H=[],Q=[],X=[],G={bodies:null};t.SplitSolver.prototype.solve=function(e,i){function n(t){for(var e=t.length,i=0;i!==e;i++){var n=t[i];if(!(n.visited||n.body.motionstate&x))return n}return!1}function o(t,e){var i=[];for(i.push(t),t.visited=!0,e(t);i.length;)for(var o,a=i.pop();o=n(a.children);)o.visited=!0,e(o),i.push(o)}function a(t){z.push(t.body);for(var e=t.eqs.length,i=0;i!==e;i++){var n=t.eqs[i];-1===V.indexOf(n)&&V.push(n)}}for(var s=H,r=i.bodies,h=this.equations,c=h.length,l=r.length,u=this.subsolver,p=s.length;p!==l;p++)s.push({body:r[p],children:[],eqs:[],visited:!1});for(var p=0;p!==l;p++){var d=s[p];d.body=r[p],d.children.length=0,d.eqs.length=0,d.visited=!1}for(var v=0;v!==c;v++){var y=h[v],p=r.indexOf(y.bi),f=r.indexOf(y.bj),m=s[p],w=s[f];m.children.push(w),m.eqs.push(y),w.children.push(m),w.eqs.push(y)}for(var b,x=t.Body.STATIC,g=0,V=Q,z=X,E=G;b=n(s);){V.length=0,z.length=0,o(b,a);for(var S=V.length,p=0;p!==S;p++)u.addEquation(V[p]);E.bodies=z,u.solve(e,E),u.removeAllEquations(),g++}return g},t.Material=function(t){this.name=t,this.id=-1},t.ContactMaterial=function(t,e,i,n){this.id=-1,this.materials=[t,e],this.friction=void 0!==i?Number(i):.3,this.restitution=void 0!==n?Number(n):.3,this.contactEquationStiffness=1e7,this.contactEquationRegularizationTime=3,this.frictionEquationStiffness=1e7,this.frictionEquationRegularizationTime=3},t.World=function(){t.EventTarget.apply(this),this.allowSleep=!1,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=0,this.quatNormalizeFast=!1,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.last_dt=this.default_dt,this.nextId=0,this.gravity=new t.Vec3,this.broadphase=null,this.bodies=[],this.solver=new t.GSSolver,this.constraints=[],this.contactgen=new t.ContactGenerator,this.collisionMatrix=[],this.collisionMatrixPrevious=[],this.materials=[],this.contactmaterials=[],this.mats2cmat=[],this.defaultMaterial=new t.Material("default"),this.defaultContactMaterial=new t.ContactMaterial(this.defaultMaterial,this.defaultMaterial,.3,0),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,nearphase:0},this.subsystems=[]},t.World.prototype.getContactMaterial=function(e,i){if(e instanceof t.Material&&i instanceof t.Material){var n=e.id,o=i.id;if(o>n){var a=n;n=o,o=a}return this.contactmaterials[this.mats2cmat[n+o*this.materials.length]]}},t.World.prototype.numObjects=function(){return this.bodies.length},t.World.prototype.collisionMatrixGet=function(t,e,i){if(e>t){var n=e;e=t,t=n}return t=(t*(t+1)>>1)+e-1,i===void 0||i?this.collisionMatrix[t]:this.collisionMatrixPrevious[t]},t.World.prototype.collisionMatrixSet=function(t,e,i,n){if(e>t){var o=e;e=t,t=o}t=(t*(t+1)>>1)+e-1,n===void 0||n?this.collisionMatrix[t]=i:this.collisionMatrixPrevious[t]=i},t.World.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t;for(var e=0,i=this.collisionMatrix.length;e!==i;e++)this.collisionMatrix[e]=0},t.World.prototype.add=function(e){e.id=this.id(),e.index=this.bodies.length,this.bodies.push(e),e.world=this,e.position.copy(e.initPosition),e.velocity.copy(e.initVelocity),e.timeLastSleepy=this.time,e instanceof t.RigidBody&&(e.angularVelocity.copy(e.initAngularVelocity),e.quaternion.copy(e.initQuaternion));var i=this.numObjects();this.collisionMatrix.length=i*(i-1)>>1},t.World.prototype.addConstraint=function(t){this.constraints.push(t),t.id=this.id()},t.World.prototype.removeConstraint=function(t){var e=this.constraints.indexOf(t);-1!==e&&this.constraints.splice(e,1)},t.World.prototype.id=function(){return this.nextId++},t.World.prototype.remove=function(t){t.world=null;var e=this.numObjects()-1,i=this.bodies;i.splice(t.index,1);for(var n=t.index;e>n;n++)i[n].index=n;this.collisionMatrixPrevious.length=this.collisionMatrix.length=e*(e-1)>>1},t.World.prototype.addMaterial=function(t){if(-1===t.id){var e=this.materials.length;this.materials.push(t),t.id=this.materials.length-1;for(var i=0;i!==2*e+1;i++)this.mats2cmat.push(-1)}},t.World.prototype.addContactMaterial=function(t){this.addMaterial(t.materials[0]),this.addMaterial(t.materials[1]);var e,i;t.materials[0].id>t.materials[1].id?(e=t.materials[0].id,i=t.materials[1].id):(i=t.materials[0].id,e=t.materials[1].id),this.contactmaterials.push(t),t.id=this.contactmaterials.length-1,this.mats2cmat[e+this.materials.length*i]=t.id},t.World.prototype._now=function(){return window.performance.webkitNow?window.performance.webkitNow():Date.now()};var Y={type:"postStep"},Z={type:"collide","with":null,contact:null},_=[],K=[],J=[],$=[],te=new t.Vec3,ee=(new t.Vec3,new t.Vec3,new t.Vec3,new t.Vec3,new t.Vec3,new t.Vec3,new t.Vec3,new t.Vec3,new t.Quaternion,new t.Quaternion),ie=new t.Quaternion;t.World.prototype.step=function(e){var i,n=this.contacts,o=J,a=$,s=this.numObjects(),r=this.bodies,h=this.solver,c=this.gravity,l=this.doProfiling,u=this.profile,p=t.Body.DYNAMIC,d=this._now,v=this.constraints,y=t.FrictionEquation,f=K,m=c.norm(),w=c.x,b=c.y,x=c.z,g=0;for(l&&(i=d()),void 0===e&&(e=this.last_dt||this.default_dt),g=0;g!==s;g++){var V=r[g];if(V.motionstate&p){var z=V.force,E=V.mass;z.x+=E*w,z.y+=E*b,z.z+=E*x}}for(var g=0,S=this.subsystems.length;g!==S;g++)this.subsystems[g].update();l&&(i=d()),o.length=0,a.length=0,this.broadphase.collisionPairs(this,o,a),l&&(u.broadphase=d()-i),this.collisionMatrixTick(),l&&(i=d());var N=_,M=n.length;for(g=0;g!==M;g++)N.push(n[g]);n.length=0,this.contactgen.getContacts(o,a,this,n,N),l&&(u.nearphase=d()-i),l&&(i=d());var P=n.length,q=this.frictionEquations.length;for(g=0;g!==q;g++)f.push(this.frictionEquations[g]);this.frictionEquations.length=0;for(var j=0;j!==P;j++){var C=n[j],V=C.bi,B=C.bj,g=r.indexOf(V),I=r.indexOf(B),R=this.getContactMaterial(V.material,B.material)||this.defaultContactMaterial,O=R.friction;R.restitution;var A=te;A.set(B.position.x+C.rj.x-V.position.x-C.ri.x,B.position.y+C.rj.y-V.position.y-C.ri.y,B.position.z+C.rj.z-V.position.z-C.ri.z);var T=A.dot(C.ni);if(0>T){if(C.restitution=R.restitution,C.penetration=T,C.stiffness=R.contactEquationStiffness,C.regularizationTime=R.contactEquationRegularizationTime,h.addEquation(C),O>0){var F=O*m,k=V.invMass+B.invMass;k>0&&(k=1/k);var U=f,W=U.length?U.pop():new y(V,B,F*k),L=U.length?U.pop():new y(V,B,F*k);this.frictionEquations.push(W),this.frictionEquations.push(L),W.bi=L.bi=V,W.bj=L.bj=B,W.minForce=L.minForce=-F*k,W.maxForce=L.maxForce=F*k,C.ri.copy(W.ri),C.rj.copy(W.rj),C.ri.copy(L.ri),C.rj.copy(L.rj),C.ni.tangents(W.t,L.t),h.addEquation(W),h.addEquation(L)}this.collisionMatrixSet(g,I,1,!0),this.collisionMatrixGet(g,I,!0)!==this.collisionMatrixGet(g,I,!1)&&(Z.with=B,Z.contact=C,V.dispatchEvent(Z),Z.with=V,B.dispatchEvent(Z),V.wakeUp(),B.wakeUp())}}l&&(u.makeContactConstraints=d()-i),l&&(i=d());var D=v.length;for(g=0;g!==D;g++){var C=v[g];C.update();for(var I=0,H=C.equations.length;I!==H;I++){var Q=C.equations[I];h.addEquation(Q)}}h.solve(e,this),l&&(u.solve=d()-i),h.removeAllEquations();var X=Math.pow;for(g=0;g!==s;g++){var V=r[g];if(V.motionstate&p){var G=X(1-V.linearDamping,e),ne=V.velocity;ne.mult(G,ne);var oe=V.angularVelocity;if(oe){var ae=X(1-V.angularDamping,e);oe.mult(ae,oe)}}}for(this.dispatchEvent(Y),g=0;g!==s;g++){var V=r[g];V.preStep&&V.preStep.call(V)}l&&(i=d());var se=ee,re=ie,he=this.stepnumber,ce=t.Body.DYNAMIC|t.Body.KINEMATIC,le=0===he%(this.quatNormalizeSkip+1),ue=this.quatNormalizeFast,pe=.5*e,de=t.Shape.types.PLANE,ve=t.Shape.types.CONVEXPOLYHEDRON;for(g=0;g!==s;g++){var ye=r[g],fe=ye.shape,me=ye.force,we=ye.tau;if(ye.motionstate&ce){var be=ye.velocity,xe=ye.angularVelocity,ge=ye.position,Ve=ye.quaternion,ze=ye.invMass,Ee=ye.invInertia;if(be.x+=me.x*ze*e,be.y+=me.y*ze*e,be.z+=me.z*ze*e,ye.angularVelocity&&(xe.x+=we.x*Ee.x*e,xe.y+=we.y*Ee.y*e,xe.z+=we.z*Ee.z*e),ye.isSleeping()||(ge.x+=be.x*e,ge.y+=be.y*e,ge.z+=be.z*e,ye.angularVelocity&&(se.set(xe.x,xe.y,xe.z,0),se.mult(Ve,re),Ve.x+=pe*re.x,Ve.y+=pe*re.y,Ve.z+=pe*re.z,Ve.w+=pe*re.w,le&&(ue?Ve.normalizeFast():Ve.normalize())),ye.aabbmin&&(ye.aabbNeedsUpdate=!0)),fe)switch(fe.type){case de:fe.worldNormalNeedsUpdate=!0;break;case ve:fe.worldFaceNormalsNeedsUpdate=!0,fe.worldVerticesNeedsUpdate=!0}}ye.force.set(0,0,0),ye.tau&&ye.tau.set(0,0,0)}for(l&&(u.integrate=d()-i),this.time+=e,this.stepnumber+=1,this.dispatchEvent(Y),g=0;g!==s;g++){var V=r[g],Se=V.postStep;Se&&Se.call(V)}for(g=0;g!==s;g++){var ye=r[g];ye.inertiaWorldAutoUpdate&&ye.quaternion.vmult(ye.inertia,ye.inertiaWorld),ye.invInertiaWorldAutoUpdate&&ye.quaternion.vmult(ye.invInertia,ye.invInertiaWorld)}if(this.allowSleep)for(g=0;g!==s;g++)r[g].sleepTick(this.time)},t.ContactGenerator=function(){function e(e,i){if(f.length){var n=f.pop();return n.bi=e,n.bj=i,n}return new t.ContactEquation(e,i)}function i(t){var e;e=t.ri,t.ri=t.rj,t.rj=e,t.ni.negate(t.ni),e=t.bi,t.bi=t.bj,t.bj=e}function n(t,i,n,o,a,s,r,h,c){var l=e(h,c);c.position.vsub(o,l.ni),l.ni.normalize(),l.ni.copy(l.ri),l.ni.copy(l.rj),l.ri.mult(i.radius,l.ri),l.rj.mult(-n.radius,l.rj),t.push(l)}function o(t,i,n,o,a,s,r,h,c){var l=e(h,c);l.ni.set(0,0,1),r.vmult(l.ni,l.ni),l.ni.negate(l.ni),l.ni.normalize(),l.ni.mult(i.radius,l.ri),o.vsub(a,w),l.ni.mult(l.ni.dot(w),b),w.vsub(b,l.rj),b.norm2()<=i.radius*i.radius&&t.push(l)}function a(t,e,i){for(var n=null,o=t.length,a=0;a!==o;a++){var s=t[a],r=x;t[(a+1)%o].vsub(s,r);var h=g;r.cross(e,h);var c=V;i.vsub(s,c);var l=h.dot(c);if(!(null===n||l>0&&n===!0||0>=l&&n===!1))return!1;null===n&&(n=l>0)}return!0}function s(t,i,n,o,a,s,r,h,c){var l=M;o.vsub(a,z),n.getSideNormals(l,r);for(var u=i.radius,p=!1,d=q,v=j,y=C,f=null,w=0,b=0,x=0,g=null,V=0,B=l.length;V!==B&&p===!1;V++){var I=E;l[V].copy(I);var R=I.norm();I.normalize();var O=z.dot(I);if(R+u>O&&O>0){var A=S,T=N;l[(V+1)%3].copy(A),l[(V+2)%3].copy(T);var F=A.norm(),k=T.norm();A.normalize(),T.normalize();var U=z.dot(A),W=z.dot(T);if(F>U&&U>-F&&k>W&&W>-k){var L=Math.abs(O-R-u);(null===g||g>L)&&(g=L,b=U,x=W,f=R,I.copy(d),A.copy(v),T.copy(y),w++)}}}if(w){p=!0;var D=e(h,c);d.mult(-u,D.ri),d.copy(D.ni),D.ni.negate(D.ni),d.mult(f,d),v.mult(b,v),d.vadd(v,d),y.mult(x,y),d.vadd(y,D.rj),t.push(D)}for(var H=m.get(),Q=P,X=0;2!==X&&!p;X++)for(var G=0;2!==G&&!p;G++)for(var Y=0;2!==Y&&!p;Y++)if(H.set(0,0,0),X?H.vadd(l[0],H):H.vsub(l[0],H),G?H.vadd(l[1],H):H.vsub(l[1],H),Y?H.vadd(l[2],H):H.vsub(l[2],H),a.vadd(H,Q),Q.vsub(o,Q),u*u>Q.norm2()){p=!0;var D=e(h,c);Q.copy(D.ri),D.ri.normalize(),D.ri.copy(D.ni),D.ri.mult(u,D.ri),H.copy(D.rj),t.push(D)}m.release(H),H=null;for(var Z=m.get(),_=m.get(),D=m.get(),K=m.get(),L=m.get(),J=l.length,X=0;X!==J&&!p;X++)for(var G=0;G!==J&&!p;G++)if(X%3!==G%3){l[G].cross(l[X],Z),Z.normalize(),l[X].vadd(l[G],_),o.copy(D),D.vsub(_,D),D.vsub(a,D);var $=D.dot(Z);Z.mult($,K);for(var Y=0;Y===X%3||Y===G%3;)Y++;o.copy(L),L.vsub(K,L),L.vsub(_,L),L.vsub(a,L);var te=Math.abs($),ee=L.norm();if(l[Y].norm()>te&&u>ee){p=!0;var ie=e(h,c);_.vadd(K,ie.rj),ie.rj.copy(ie.rj),L.negate(ie.ni),ie.ni.normalize(),ie.rj.copy(ie.ri),ie.ri.vadd(a,ie.ri),ie.ri.vsub(o,ie.ri),ie.ri.normalize(),ie.ri.mult(u,ie.ri),t.push(ie)}}m.release(Z,_,D,K,L)}function r(t,i,n,o,s,r,h,c,l){o.vsub(s,B);for(var u=n.faceNormals,p=n.faces,d=n.vertices,v=i.radius,y=0;y!==d.length;y++){var f=d[y],w=A;h.vmult(f,w),s.vadd(w,w);var b=O;if(w.vsub(o,b),v*v>b.norm2()){g=!0;var x=e(c,l);return b.copy(x.ri),x.ri.normalize(),x.ri.copy(x.ni),x.ri.mult(v,x.ri),w.vsub(s,x.rj),t.push(x),void 0}}for(var g=!1,y=0,V=p.length;y!==V&&g===!1;y++){var z=u[y],E=p[y],S=T;h.vmult(z,S);var N=F;h.vmult(d[E[0]],N),N.vadd(s,N);var M=k;S.mult(-v,M),o.vadd(M,M);var P=U;M.vsub(N,P);var q=P.dot(S),j=W;if(o.vsub(N,j),0>q&&j.dot(S)>0){for(var C=[],L=0,D=E.length;L!==D;L++){var H=m.get();h.vmult(d[E[L]],H),s.vadd(H,H),C.push(H)}if(a(C,S,o)){g=!0;var x=e(c,l);S.mult(-v,x.ri),S.negate(x.ni);var Q=m.get();S.mult(-q,Q);var X=m.get();S.mult(-v,X),o.vsub(s,x.rj),x.rj.vadd(X,x.rj),x.rj.vadd(Q,x.rj),m.release(Q),m.release(X),t.push(x);for(var L=0,G=C.length;L!==G;L++)m.release(C[L]);return}for(var L=0;L!==E.length;L++){var Y=m.get(),Z=m.get();h.vmult(d[E[(L+1)%E.length]],Y),h.vmult(d[E[(L+2)%E.length]],Z),s.vadd(Y,Y),s.vadd(Z,Z);var _=I;Z.vsub(Y,_);var K=R;_.unit(K);var J=m.get(),$=m.get();o.vsub(Y,$);var te=$.dot(K);K.mult(te,J),J.vadd(Y,J);var ee=m.get();if(J.vsub(o,ee),te>0&&_.norm2()>te*te&&v*v>ee.norm2()){var x=e(c,l);J.vsub(s,x.rj),J.vsub(o,x.ni),x.ni.normalize(),x.ni.mult(v,x.ri),t.push(x);for(var L=0,G=C.length;L!==G;L++)m.release(C[L]);return m.release(Y),m.release(Z),m.release(J),m.release(ee),m.release($),void 0}m.release(Y),m.release(Z),m.release(J),m.release(ee),m.release($)}for(var L=0,G=C.length;L!==G;L++)m.release(C[L])}}}function h(t,e,i,n,o,a,s,r,h){l(t,e,i.convexPolyhedronRepresentation,n,o,a,s,r,h)}function c(e,i,n,o,a,s,r,h,c){for(var l=L,u=D,p=0,d=0,v=n.childShapes.length;d!==v;d++){var f=[],m=u.pop()||new t.Quaternion,w=l.pop()||new t.Vec3;r.mult(n.childOrientations[d],m),m.normalize(),r.vmult(n.childOffsets[d],w),a.vadd(w,w),y(f,i,n.childShapes[d],o,w,s,m,h,c),u.push(m);var b=w;i||(p+=f.length);for(var x=0;x!==f.length;x++)r.vmult(n.childOffsets[d],b),f[x].rj.vadd(b,f[x].rj),e.push(f[x]);l.push(w)}}function l(t,i,n,o,a,s,r,h,c){var l=H,u=Q;u.set(0,0,1),s.vmult(u,u);for(var p=X,d=0;d!==n.vertices.length;d++){n.vertices[d].copy(l),r.vmult(l,l),a.vadd(l,l),l.vsub(o,p);var v=u.dot(p);if(0>=v){var y=G;u.mult(u.dot(l),y),l.vsub(y,y);var f=e(h,c);u.copy(f.ni),y.copy(f.ri),l.vsub(a,f.rj),t.push(f)}}}function u(t,i,n,o,a,s,r,h,c){var l=Y;if(i.findSeparatingAxis(n,o,s,a,r,l)){var u=[],p=Z;i.clipAgainstHull(o,s,n,a,r,l,-100,100,u);for(var d=0;d!==u.length;d++){var v=e(h,c);l.negate(v.ni),u[d].normal.negate(p),p.mult(u[d].depth,p),u[d].point.vadd(p,v.ri),u[d].point.copy(v.rj),v.rj.vsub(a,v.rj),v.ri.vsub(o,v.ri),t.push(v)}}}function p(t,i,n,o,a,s,r,h,c){var l=_;l.set(0,0,1),c.quaternion.vmult(l,l);var u=K;o.vsub(c.position,u);var p=l.dot(u);if(0>=p){var d=e(h,c);l.copy(d.ni),d.ni.negate(d.ni),d.ri.set(0,0,0);var v=J;l.mult(l.dot(o),v),o.vsub(v,v),v.copy(d.rj),t.push(d)}}function d(t,i,n,o,a,s,r,h,c){var l=$;l.set(0,0,1),o.vsub(a,l);var u=l.norm2();if(n.radius*n.radius>=u){var p=e(h,c);l.normalize(),l.copy(p.rj),p.rj.mult(n.radius,p.rj),l.copy(p.ni),p.ni.negate(p.ni),p.ri.set(0,0,0),t.push(p)}}function v(t,i,n,o,a,s,r,h,c){var l=-1,u=ie,p=oe,d=null,v=0,y=ee;if(o.copy(y),y.vsub(a,y),r.conjugate(te),te.vmult(y,y),n.pointIsInside(y)){n.worldVerticesNeedsUpdate&&n.computeWorldVertices(a,r),n.worldFaceNormalsNeedsUpdate&&n.computeWorldFaceNormals(r);for(var f=0,m=n.faces.length;f!==m;f++){var w=[n.worldVertices[n.faces[f][0]]],b=n.worldFaceNormals[f];o.vsub(w[0],ne);var x=-b.dot(ne);(null===d||Math.abs(x)f.type){var j;j=f,f=a,a=j,j=w,w=m,m=j,j=x,x=b,b=j,j=V,V=g,g=j,z=!0}}else if(a&&!f){var j;j=f,f=a,a=j,j=w,w=m,m=j,j=x,x=b,b=j,j=V,V=g,g=j,z=!0}if(a&&f){if(a.type===S)switch(f.type){case S:n(e,a,f,m,w,b,x,g,V);break;case N:o(e,a,f,m,w,b,x,g,V);break;case M:s(e,a,f,m,w,b,x,g,V);break;case P:c(e,a,f,m,w,b,x,g,V);break;case q:r(e,a,f,m,w,b,x,g,V);break;default:console.warn("Collision between CANNON.Shape.types.SPHERE and "+f.type+" not implemented yet.")}else if(a.type===E.PLANE)switch(f.type){case E.PLANE:throw Error("Plane-plane collision... wait, you did WHAT?");case E.BOX:h(e,a,f,m,w,b,x,g,V);break;case E.COMPOUND:c(e,a,f,m,w,b,x,g,V);break;case E.CONVEXPOLYHEDRON:l(e,a,f,m,w,b,x,g,V);break;default:console.warn("Collision between CANNON.Shape.types.PLANE and "+f.type+" not implemented yet.")}else if(a.type===E.BOX)switch(f.type){case E.BOX:y(e,a.convexPolyhedronRepresentation,f.convexPolyhedronRepresentation,m,w,b,x,g,V);break;case E.COMPOUND:c(e,a,f,m,w,b,x,g,V);break;case E.CONVEXPOLYHEDRON:y(e,a.convexPolyhedronRepresentation,f,m,w,b,x,g,V);break;default:console.warn("Collision between CANNON.Shape.types.BOX and "+f.type+" not implemented yet.")}else if(a.type===E.COMPOUND)switch(f.type){case E.COMPOUND:c(e,a,f,m,w,b,x,g,V);break;case E.CONVEXPOLYHEDRON:var C=[];c(C,f,a,w,m,x,b,V,g);for(var B=0;B!==C.length;B++)i(C[B]),e.push(C[B]);break;default:console.warn("Collision between CANNON.Shape.types.COMPOUND and "+f.type+" not implemented yet.")}else if(a.type===E.CONVEXPOLYHEDRON)switch(f.type){case E.CONVEXPOLYHEDRON:u(e,a,f,m,w,b,x,g,V);break;default:console.warn("Collision between CANNON.Shape.types.CONVEXPOLYHEDRON and "+f.type+" not implemented yet.")}}else switch(f.type){case E.PLANE:p(e,a,f,m,w,b,x,g,V);break;case E.SPHERE:d(e,a,f,m,w,b,x,g,V);break;case E.BOX:v(e,a,f.convexPolyhedronRepresentation,m,w,b,x,g,V);break;case E.CONVEXPOLYHEDRON:v(e,a,f,m,w,b,x,g,V);break;case E.COMPOUND:c(e,a,f,m,w,b,x,g,V);break;default:console.warn("Collision between CANNON.Particle and "+f.type+" not implemented yet.")}for(var I=0,R=e.length;z&&I!==R;I++)i(e[I])}this.contactReduction=!1;var f=[],m=new t.Vec3Pool,w=new t.Vec3,b=new t.Vec3,x=new t.Vec3,g=new t.Vec3,V=new t.Vec3,z=new t.Vec3,E=new t.Vec3,S=new t.Vec3,N=new t.Vec3,M=[new t.Vec3,new t.Vec3,new t.Vec3,new t.Vec3,new t.Vec3,new t.Vec3],P=new t.Vec3,q=new t.Vec3,j=new t.Vec3,C=new t.Vec3,B=new t.Vec3,I=new t.Vec3,R=new t.Vec3,O=new t.Vec3,A=new t.Vec3,T=new t.Vec3,F=new t.Vec3,k=new t.Vec3,U=new t.Vec3,W=new t.Vec3;new t.Vec3,new t.Vec3;var L=[],D=[],H=new t.Vec3,Q=new t.Vec3,X=new t.Vec3,G=new t.Vec3,Y=new t.Vec3,Z=new t.Vec3,_=new t.Vec3,K=new t.Vec3,J=new t.Vec3,$=new t.Vec3,te=new t.Quaternion,ee=new t.Vec3;new t.Vec3;var ie=new t.Vec3,ne=new t.Vec3,oe=new t.Vec3;this.reduceContacts=function(){},this.getContacts=function(t,e,i,n,o){f=o;for(var a=0,s=t.length;a!==s;a++){var r=t[a],h=e[a];y(n,r.shape,h.shape,r.position,h.position,r.quaternion,h.quaternion,r,h)}}},t.Equation=function(t,e,i,n){this.id=-1,this.minForce=i===void 0?-1e6:i,this.maxForce=n===void 0?1e6:n,this.bi=t,this.bj=e,this.stiffness=1e7,this.regularizationTime=5,this.a=0,this.b=0,this.eps=0,this.spookParamsNeedsUpdate=!0},t.Equation.prototype.constructor=t.Equation,t.Equation.prototype.updateSpookParams=function(t){var e=this.regularizationTime,i=this.stiffness;this.a=4/(t*(1+4*e)),this.b=4*e/(1+4*e),this.eps=4/(t*t*i*(1+4*e))},t.ContactEquation=function(e,i){t.Equation.call(this,e,i,0,1e6),this.restitution=0,this.ri=new t.Vec3,this.rj=new t.Vec3,this.penetrationVec=new t.Vec3,this.ni=new t.Vec3,this.rixn=new t.Vec3,this.rjxn=new t.Vec3,this.invIi=new t.Mat3,this.invIj=new t.Mat3,this.biInvInertiaTimesRixn=new t.Vec3,this.bjInvInertiaTimesRjxn=new t.Vec3},t.ContactEquation.prototype=new t.Equation,t.ContactEquation.prototype.constructor=t.ContactEquation,t.ContactEquation.prototype.reset=function(){this.invInertiaTimesRxnNeedsUpdate=!0};var ne=new t.Vec3,oe=new t.Vec3,ae=new t.Vec3;t.ContactEquation.prototype.computeB=function(t){var e=this.a,i=this.b,n=this.bi,o=this.bj,a=this.ri,s=this.rj,r=this.rixn,h=this.rjxn,c=ae,l=n.velocity,u=n.angularVelocity?n.angularVelocity:c,p=n.force,d=n.tau?n.tau:c,v=o.velocity,y=o.angularVelocity?o.angularVelocity:c,f=o.force,m=o.tau?o.tau:c,w=this.penetrationVec,b=n.invMass,x=o.invMass,g=this.invIi,V=this.invIj;n.invInertia?g.setTrace(n.invInertia):g.identity(),o.invInertia?V.setTrace(o.invInertia):V.identity();var z=this.ni;a.cross(z,r),s.cross(z,h);var w=this.penetrationVec;w.set(0,0,0),w.vadd(o.position,w),w.vadd(s,w),w.vsub(n.position,w),w.vsub(a,w);var E=z.dot(w),S=ne,N=oe;g.vmult(d,S),V.vmult(m,N);var M=this.restitution+1,P=M*v.dot(z)-M*l.dot(z)+y.dot(h)-u.dot(r),q=f.dot(z)*x-p.dot(z)*b+h.dot(N)-r.dot(S),j=-E*e-P*i-t*q;return j},new t.Vec3,new t.Vec3,t.ContactEquation.prototype.computeC=function(){var t=this.bi,e=this.bj,i=this.rixn,n=this.rjxn,o=t.invMass,a=e.invMass,s=o+a+this.eps,r=this.invIi,h=this.invIj;return r.vmult(i,this.biInvInertiaTimesRixn),h.vmult(n,this.bjInvInertiaTimesRjxn),s+=this.biInvInertiaTimesRixn.dot(i),s+=this.bjInvInertiaTimesRjxn.dot(n)};var se=new t.Vec3;t.ContactEquation.prototype.computeGWlambda=function(){var t=this.bi,e=this.bj,i=se,n=0;return e.vlambda.vsub(t.vlambda,i),n+=i.dot(this.ni),t.wlambda&&(n-=t.wlambda.dot(this.rixn)),e.wlambda&&(n+=e.wlambda.dot(this.rjxn)),n};var re=new t.Vec3,he=new t.Vec3;t.ContactEquation.prototype.addToWlambda=function(t){var e=this.bi,i=this.bj,n=(this.rixn,this.rjxn,e.invMass),o=i.invMass,a=this.ni,s=re,r=he;a.mult(n*t,r),e.vlambda.vsub(r,e.vlambda),a.mult(o*t,r),i.vlambda.vadd(r,i.vlambda),void 0!==e.wlambda&&(this.biInvInertiaTimesRixn.mult(t,s),e.wlambda.vsub(s,e.wlambda)),void 0!==i.wlambda&&(this.bjInvInertiaTimesRjxn.mult(t,s),i.wlambda.vadd(s,i.wlambda))},t.FrictionEquation=function(e,i,n){t.Equation.call(this,e,i,-n,n),this.ri=new t.Vec3,this.rj=new t.Vec3,this.t=new t.Vec3,this.rixt=new t.Vec3,this.rjxt=new t.Vec3,this.wixri=new t.Vec3,this.wjxrj=new t.Vec3,this.invIi=new t.Mat3,this.invIj=new t.Mat3,this.relVel=new t.Vec3,this.relForce=new t.Vec3,this.biInvInertiaTimesRixt=new t.Vec3,this.bjInvInertiaTimesRjxt=new t.Vec3},t.FrictionEquation.prototype=new t.Equation,t.FrictionEquation.prototype.constructor=t.FrictionEquation;var ce=new t.Vec3,le=new t.Vec3,ue=new t.Vec3;t.FrictionEquation.prototype.computeB=function(t){var e=this.a,i=this.b,n=this.bi,o=this.bj,a=this.ri,s=this.rj,r=this.rixt,h=this.rjxt,c=this.wixri,l=this.wjxrj,u=ue,p=n.velocity,d=n.angularVelocity?n.angularVelocity:u,v=n.force,y=n.tau?n.tau:u,f=o.velocity,m=o.angularVelocity?o.angularVelocity:u,w=o.force,b=o.tau?o.tau:u,x=(this.relVel,this.relForce,n.invMass),g=o.invMass,V=this.invIi,z=this.invIj,E=this.t,S=ce,N=le;n.invInertia&&V.setTrace(n.invInertia),o.invInertia&&z.setTrace(o.invInertia),a.cross(E,r),s.cross(E,h),d.cross(a,c),m.cross(s,l),V.vmult(y,S),z.vmult(b,N);var M=0,P=f.dot(E)-p.dot(E)+l.dot(E)-c.dot(E),q=w.dot(E)*g-v.dot(E)*x+h.dot(N)-r.dot(S),j=-M*e-P*i-t*q;return j},t.FrictionEquation.prototype.computeC=function(){var t=this.bi,e=this.bj,i=this.rixt,n=this.rjxt,o=t.invMass,a=e.invMass,s=o+a+this.eps,r=this.invIi,h=this.invIj;return r.vmult(i,this.biInvInertiaTimesRixt),h.vmult(n,this.bjInvInertiaTimesRjxt),s+=this.biInvInertiaTimesRixt.dot(i),s+=this.bjInvInertiaTimesRjxt.dot(n)};var pe=new t.Vec3;t.FrictionEquation.prototype.computeGWlambda=function(){var t=this.bi,e=this.bj,i=0,n=pe;return e.vlambda.vsub(t.vlambda,n),i+=n.dot(this.t),t.wlambda&&(i-=t.wlambda.dot(this.rixt)),e.wlambda&&(i+=e.wlambda.dot(this.rjxt)),i};var de=new t.Vec3;t.FrictionEquation.prototype.addToWlambda=function(t){var e=this.bi,i=this.bj,n=(this.rixt,this.rjxt,e.invMass),o=i.invMass,a=this.t,s=de,r=e.wlambda,h=i.wlambda;a.mult(n*t,s),e.vlambda.vsub(s,e.vlambda),a.mult(o*t,s),i.vlambda.vadd(s,i.vlambda),r&&(this.biInvInertiaTimesRixt.mult(t,s),r.vsub(s,r)),h&&(this.bjInvInertiaTimesRjxt.mult(t,s),h.vadd(s,h))},t.RotationalEquation=function(e,i){t.Equation.call(this,e,i,-1e6,1e6),this.ni=new t.Vec3,this.nj=new t.Vec3,this.nixnj=new t.Vec3,this.njxni=new t.Vec3,this.invIi=new t.Mat3,this.invIj=new t.Mat3,this.relVel=new t.Vec3,this.relForce=new t.Vec3},t.RotationalEquation.prototype=new t.Equation,t.RotationalEquation.prototype.constructor=t.RotationalEquation,t.RotationalEquation.prototype.computeB=function(e){var i=this.a,n=this.b,o=this.bi,a=this.bj,s=this.ni,r=this.nj,h=this.nixnj,c=this.njxni;o.velocity;var l=o.angularVelocity?o.angularVelocity:new t.Vec3;o.force,o.tau?o.tau:new t.Vec3,a.velocity;var u=a.angularVelocity?a.angularVelocity:new t.Vec3;a.force,a.tau?a.tau:new t.Vec3,o.invMass,a.invMass;var p=this.invIi,d=this.invIj;o.invInertia?p.setTrace(o.invInertia):p.identity(),a.invInertia?d.setTrace(a.invInertia):d.identity(),s.cross(r,h),r.cross(s,c);var v=-s.dot(r),y=c.dot(l)+h.dot(u),f=0,m=-v*i-y*n-e*f;return m},t.RotationalEquation.prototype.computeC=function(){var t=this.bi,e=this.bj,i=this.nixnj,n=this.njxni;t.invMass,e.invMass;var o=this.eps,a=this.invIi,s=this.invIj;return t.invInertia?a.setTrace(t.invInertia):a.identity(),e.invInertia?s.setTrace(e.invInertia):s.identity(),o+=a.vmult(n).dot(n),o+=s.vmult(i).dot(i)};var se=new t.Vec3;t.RotationalEquation.prototype.computeGWlambda=function(){var t=this.bi,e=this.bj,i=0;return t.wlambda&&(i+=t.wlambda.dot(this.njxni)),e.wlambda&&(i+=e.wlambda.dot(this.nixnj)),i},t.RotationalEquation.prototype.addToWlambda=function(t){var e=this.bi,i=this.bj,n=this.nixnj;if(this.njxni,e.invMass,i.invMass,e.wlambda){var o=this.invIi;e.wlambda.vsub(o.vmult(n).mult(t),e.wlambda)}if(i.wlambda){var o=this.invIj;i.wlambda.vadd(o.vmult(n).mult(t),i.wlambda)}},t.Constraint=function(t,e){this.equations=[],this.bodyA=t,this.bodyB=e},t.Constraint.prototype.update=function(){throw Error("method update() not implmemented in this Constraint subclass!")},t.DistanceConstraint=function(e,i,n,o){t.Constraint.call(this,e,i),o===void 0&&(o=1e6);var a=this.equations=[new t.ContactEquation(e,i)],s=a[0];s.minForce=-o,s.maxForce=o,this.update=function(){i.position.vsub(e.position,s.ni),s.ni.normalize(),s.ni.mult(.5*n,s.ri),s.ni.mult(.5*-n,s.rj)}},t.DistanceConstraint.prototype=new t.Constraint,t.RotationalMotorEquation=function(e,i,n){n=n||1e6,t.Equation.call(this,e,i,-n,n),this.axisA=new t.Vec3,this.axisB=new t.Vec3,this.invIi=new t.Mat3,this.invIj=new t.Mat3,this.targetVelocity=0},t.RotationalMotorEquation.prototype=new t.Equation,t.RotationalMotorEquation.prototype.constructor=t.RotationalMotorEquation,t.RotationalMotorEquation.prototype.computeB=function(e){var i=this.a,n=this.b,o=this.bi,a=this.bj,s=this.axisA,r=this.axisB; +o.velocity;var h=o.angularVelocity?o.angularVelocity:new t.Vec3;o.force,o.tau?o.tau:new t.Vec3,a.velocity;var c=a.angularVelocity?a.angularVelocity:new t.Vec3;a.force,a.tau?a.tau:new t.Vec3,o.invMass,a.invMass;var l=this.invIi,u=this.invIj;o.invInertia?l.setTrace(o.invInertia):l.identity(),a.invInertia?u.setTrace(a.invInertia):u.identity();var p=0,d=s.dot(h)+r.dot(c)+this.targetVelocity,v=0,y=-p*i-d*n-e*v;return y},t.RotationalMotorEquation.prototype.computeC=function(){var t=this.bi,e=this.bj,i=this.axisA,n=this.axisB;t.invMass,e.invMass;var o=this.eps,a=this.invIi,s=this.invIj;return t.invInertia?a.setTrace(t.invInertia):a.identity(),e.invInertia?s.setTrace(e.invInertia):s.identity(),o+=a.vmult(i).dot(n),o+=s.vmult(n).dot(n)};var se=new t.Vec3;t.RotationalMotorEquation.prototype.computeGWlambda=function(){var t=this.bi,e=this.bj,i=this.axisA,n=this.axisB,o=0;return t.wlambda&&(o+=t.wlambda.dot(i)),e.wlambda&&(o+=e.wlambda.dot(n)),o},t.RotationalMotorEquation.prototype.addToWlambda=function(t){var e=this.bi,i=this.bj,n=this.axisA,o=this.axisB;if(e.invMass,i.invMass,e.wlambda){var a=this.invIi;e.wlambda.vsub(a.vmult(n).mult(t),e.wlambda)}if(i.wlambda){var a=this.invIj;i.wlambda.vadd(a.vmult(o).mult(t),i.wlambda)}},t.HingeConstraint=function(e,i,n,o,a,s,r){t.Constraint.call(this,e,o),r=r||1e6;var h=this,c=this.equations=[new t.RotationalEquation(e,o),new t.RotationalEquation(e,o),new t.ContactEquation(e,o),new t.ContactEquation(e,o),new t.ContactEquation(e,o)];this.getRotationalEquation1=function(){return c[0]},this.getRotationalEquation2=function(){return c[1]},this.getPointToPointEquation1=function(){return c[2]},this.getPointToPointEquation2=function(){return c[3]},this.getPointToPointEquation3=function(){return c[4]};var l,u=this.getRotationalEquation1(),p=this.getRotationalEquation2(),d=this.getPointToPointEquation1(),v=this.getPointToPointEquation2(),y=this.getPointToPointEquation3();v.minForce=y.minForce=d.minForce=-r,v.maxForce=y.maxForce=d.maxForce=r;var f=i.unit(),m=a.unit(),w=new t.Vec3,b=new t.Vec3,x=new t.Vec3;n.cross(f,w),n.cross(w,b),s.cross(m,x),w.normalize(),x.normalize();var g=!1;this.motorTargetVelocity=0,this.motorMinForce=-r,this.motorMaxForce=r,this.enableMotor=function(){g||(l=new t.RotationalMotorEquation(e,o,r),c.push(l),g=!0)},this.disableMotor=function(){g&&(g=!1,l=null,c.pop())},this.update=function(){d.ni.set(1,0,0),v.ni.set(0,1,0),y.ni.set(0,0,1),e.quaternion.vmult(i,d.ri),o.quaternion.vmult(a,d.rj),d.ri.copy(v.ri),d.rj.copy(v.rj),d.ri.copy(y.ri),d.rj.copy(y.rj),e.quaternion.vmult(w,u.ni),o.quaternion.vmult(s,u.nj),e.quaternion.vmult(b,p.ni),o.quaternion.vmult(s,p.nj),g&&(e.quaternion.vmult(n,l.axisA),o.quaternion.vmult(s,l.axisB),l.targetVelocity=h.motorTargetVelocity,l.maxForce=h.motorMaxForce,l.minForce=h.motorMinForce)}},t.HingeConstraint.prototype=new t.Constraint,t.PointToPointConstraint=function(e,i,n,o,a){t.Constraint.call(this,e,n);var s=this.equations=[new t.ContactEquation(e,n),new t.ContactEquation(e,n),new t.ContactEquation(e,n)],r=s[0],h=s[1],c=s[2];h.minForce=c.minForce=r.minForce=-a,h.maxForce=c.maxForce=r.maxForce=a,this.update=function(){n.position.vsub(e.position,r.ni),r.ni.normalize(),e.quaternion.vmult(i,r.ri),n.quaternion.vmult(o,r.rj),r.ni.tangents(h.ni,c.ni),r.ri.copy(h.ri),r.rj.copy(h.rj),r.ri.copy(c.ri),r.rj.copy(c.rj)}},t.PointToPointConstraint.prototype=new t.Constraint,"undefined"!=typeof module?module.exports=t:this.CANNON=t}).apply(this); \ No newline at end of file diff --git a/libs/three.min.js b/libs/three.min.js new file mode 100644 index 0000000..bd820fe --- /dev/null +++ b/libs/three.min.js @@ -0,0 +1,870 @@ +// threejs.org/license +'use strict';var THREE={REVISION:"73"};"function"===typeof define&&define.amd?define("three",THREE):"undefined"!==typeof exports&&"undefined"!==typeof module&&(module.exports=THREE); +void 0!==self.requestAnimationFrame&&void 0!==self.cancelAnimationFrame||function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;ca?-1:0>16&255)/255;this.g=(a>>8&255)/255;this.b=(a&255)/255;return this},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;return this},setHSL:function(){function a(a,c,d){0>d&&(d+=1);1d?c:d<2/3?a+6*(c-a)*(2/3-d):a}return function(b, +c,d){b=THREE.Math.euclideanModulo(b,1);c=THREE.Math.clamp(c,0,1);d=THREE.Math.clamp(d,0,1);0===c?this.r=this.g=this.b=d:(c=.5>=d?d*(1+c):d+c-d*c,d=2*d-c,this.r=a(d,c,b+1/3),this.g=a(d,c,b),this.b=a(d,c,b-1/3));return this}}(),setStyle:function(a){function b(b){void 0!==b&&1>parseFloat(b)&&console.warn("THREE.Color: Alpha component of "+a+" will be ignored.")}var c;if(c=/^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(a)){var d=c[2];switch(c[1]){case "rgb":case "rgba":if(c=/^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(d))return this.r= +Math.min(255,parseInt(c[1],10))/255,this.g=Math.min(255,parseInt(c[2],10))/255,this.b=Math.min(255,parseInt(c[3],10))/255,b(c[5]),this;if(c=/^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(d))return this.r=Math.min(100,parseInt(c[1],10))/100,this.g=Math.min(100,parseInt(c[2],10))/100,this.b=Math.min(100,parseInt(c[3],10))/100,b(c[5]),this;break;case "hsl":case "hsla":if(c=/^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(d)){var d=parseFloat(c[1])/ +360,e=parseInt(c[2],10)/100,g=parseInt(c[3],10)/100;b(c[5]);return this.setHSL(d,e,g)}}}else if(c=/^\#([A-Fa-f0-9]+)$/.exec(a)){c=c[1];d=c.length;if(3===d)return this.r=parseInt(c.charAt(0)+c.charAt(0),16)/255,this.g=parseInt(c.charAt(1)+c.charAt(1),16)/255,this.b=parseInt(c.charAt(2)+c.charAt(2),16)/255,this;if(6===d)return this.r=parseInt(c.charAt(0)+c.charAt(1),16)/255,this.g=parseInt(c.charAt(2)+c.charAt(3),16)/255,this.b=parseInt(c.charAt(4)+c.charAt(5),16)/255,this}a&&0=h?l/(e+g): +l/(2-e-g);switch(e){case b:f=(c-d)/l+(cg&&c>b?(c=2*Math.sqrt(1+c-g-b),this._w=(l-f)/c,this._x=.25*c,this._y=(a+e)/c,this._z=(d+h)/c):g>b?(c=2*Math.sqrt(1+g-c-b),this._w=(d-h)/c,this._x=(a+e)/c,this._y= +.25*c,this._z=(f+l)/c):(c=2*Math.sqrt(1+b-c-g),this._w=(e-a)/c,this._x=(d+h)/c,this._y=(f+l)/c,this._z=.25*c);this.onChangeCallback();return this},setFromUnitVectors:function(){var a,b;return function(c,d){void 0===a&&(a=new THREE.Vector3);b=c.dot(d)+1;1E-6>b?(b=0,Math.abs(c.x)>Math.abs(c.z)?a.set(-c.y,c.x,0):a.set(0,-c.z,c.y)):a.crossVectors(c,d);this._x=a.x;this._y=a.y;this._z=a.z;this._w=b;this.normalize();return this}}(),inverse:function(){this.conjugate().normalize();return this},conjugate:function(){this._x*= +-1;this._y*=-1;this._z*=-1;this.onChangeCallback();return this},dot:function(a){return this._x*a._x+this._y*a._y+this._z*a._z+this._w*a._w},lengthSq:function(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w},length:function(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)},normalize:function(){var a=this.length();0===a?(this._z=this._y=this._x=0,this._w=1):(a=1/a,this._x*=a,this._y*=a,this._z*=a,this._w*=a);this.onChangeCallback();return this}, +multiply:function(a,b){return void 0!==b?(console.warn("THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead."),this.multiplyQuaternions(a,b)):this.multiplyQuaternions(this,a)},multiplyQuaternions:function(a,b){var c=a._x,d=a._y,e=a._z,g=a._w,f=b._x,h=b._y,l=b._z,k=b._w;this._x=c*k+g*f+d*l-e*h;this._y=d*k+g*h+e*f-c*l;this._z=e*k+g*l+c*h-d*f;this._w=g*k-c*f-d*h-e*l;this.onChangeCallback();return this},multiplyVector3:function(a){console.warn("THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead."); +return a.applyQuaternion(this)},slerp:function(a,b){if(0===b)return this;if(1===b)return this.copy(a);var c=this._x,d=this._y,e=this._z,g=this._w,f=g*a._w+c*a._x+d*a._y+e*a._z;0>f?(this._w=-a._w,this._x=-a._x,this._y=-a._y,this._z=-a._z,f=-f):this.copy(a);if(1<=f)return this._w=g,this._x=c,this._y=d,this._z=e,this;var h=Math.acos(f),l=Math.sqrt(1-f*f);if(.001>Math.abs(l))return this._w=.5*(g+this._w),this._x=.5*(c+this._x),this._y=.5*(d+this._y),this._z=.5*(e+this._z),this;f=Math.sin((1-b)*h)/l;h= +Math.sin(b*h)/l;this._w=g*f+this._w*h;this._x=c*f+this._x*h;this._y=d*f+this._y*h;this._z=e*f+this._z*h;this.onChangeCallback();return this},equals:function(a){return a._x===this._x&&a._y===this._y&&a._z===this._z&&a._w===this._w},fromArray:function(a,b){void 0===b&&(b=0);this._x=a[b];this._y=a[b+1];this._z=a[b+2];this._w=a[b+3];this.onChangeCallback();return this},toArray:function(a,b){void 0===a&&(a=[]);void 0===b&&(b=0);a[b]=this._x;a[b+1]=this._y;a[b+2]=this._z;a[b+3]=this._w;return a},onChange:function(a){this.onChangeCallback= +a;return this},onChangeCallback:function(){}};THREE.Quaternion.slerp=function(a,b,c,d){return c.copy(a).slerp(b,d)};THREE.Vector2=function(a,b){this.x=a||0;this.y=b||0}; +THREE.Vector2.prototype={constructor:THREE.Vector2,get width(){return this.x},set width(a){this.x=a},get height(){return this.y},set height(a){this.y=a},set:function(a,b){this.x=a;this.y=b;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setComponent:function(a,b){switch(a){case 0:this.x=b;break;case 1:this.y=b;break;default:throw Error("index is out of range: "+a);}},getComponent:function(a){switch(a){case 0:return this.x;case 1:return this.y;default:throw Error("index is out of range: "+ +a);}},clone:function(){return new this.constructor(this.x,this.y)},copy:function(a){this.x=a.x;this.y=a.y;return this},add:function(a,b){if(void 0!==b)return console.warn("THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(a,b);this.x+=a.x;this.y+=a.y;return this},addScalar:function(a){this.x+=a;this.y+=a;return this},addVectors:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addScaledVector:function(a,b){this.x+=a.x*b;this.y+=a.y*b;return this}, +sub:function(a,b){if(void 0!==b)return console.warn("THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(a,b);this.x-=a.x;this.y-=a.y;return this},subScalar:function(a){this.x-=a;this.y-=a;return this},subVectors:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},multiply:function(a){this.x*=a.x;this.y*=a.y;return this},multiplyScalar:function(a){isFinite(a)?(this.x*=a,this.y*=a):this.y=this.x=0;return this},divide:function(a){this.x/=a.x; +this.y/=a.y;return this},divideScalar:function(a){return this.multiplyScalar(1/a)},min:function(a){this.x=Math.min(this.x,a.x);this.y=Math.min(this.y,a.y);return this},max:function(a){this.x=Math.max(this.x,a.x);this.y=Math.max(this.y,a.y);return this},clamp:function(a,b){this.x=Math.max(a.x,Math.min(b.x,this.x));this.y=Math.max(a.y,Math.min(b.y,this.y));return this},clampScalar:function(){var a,b;return function(c,d){void 0===a&&(a=new THREE.Vector2,b=new THREE.Vector2);a.set(c,c);b.set(d,d);return this.clamp(a, +b)}}(),clampLength:function(a,b){var c=this.length();this.multiplyScalar(Math.max(a,Math.min(b,c))/c);return this},floor:function(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);return this},ceil:function(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);return this},round:function(){this.x=Math.round(this.x);this.y=Math.round(this.y);return this},roundToZero:function(){this.x=0>this.x?Math.ceil(this.x):Math.floor(this.x);this.y=0>this.y?Math.ceil(this.y):Math.floor(this.y);return this},negate:function(){this.x= +-this.x;this.y=-this.y;return this},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x;a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.multiplyScalar(a/ +this.length())},lerp:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;return this},lerpVectors:function(a,b,c){this.subVectors(b,a).multiplyScalar(c).add(a);return this},equals:function(a){return a.x===this.x&&a.y===this.y},fromArray:function(a,b){void 0===b&&(b=0);this.x=a[b];this.y=a[b+1];return this},toArray:function(a,b){void 0===a&&(a=[]);void 0===b&&(b=0);a[b]=this.x;a[b+1]=this.y;return a},fromAttribute:function(a,b,c){void 0===c&&(c=0);b=b*a.itemSize+c;this.x=a.array[b];this.y= +a.array[b+1];return this},rotateAround:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=this.x-a.x,g=this.y-a.y;this.x=e*c-g*d+a.x;this.y=e*d+g*c+a.y;return this}};THREE.Vector3=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0}; +THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},setComponent:function(a,b){switch(a){case 0:this.x=b;break;case 1:this.y=b;break;case 2:this.z=b;break;default:throw Error("index is out of range: "+a);}},getComponent:function(a){switch(a){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw Error("index is out of range: "+ +a);}},clone:function(){return new this.constructor(this.x,this.y,this.z)},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){if(void 0!==b)return console.warn("THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(a,b);this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},addVectors:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addScaledVector:function(a, +b){this.x+=a.x*b;this.y+=a.y*b;this.z+=a.z*b;return this},sub:function(a,b){if(void 0!==b)return console.warn("THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(a,b);this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},subScalar:function(a){this.x-=a;this.y-=a;this.z-=a;return this},subVectors:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},multiply:function(a,b){if(void 0!==b)return console.warn("THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead."), +this.multiplyVectors(a,b);this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){isFinite(a)?(this.x*=a,this.y*=a,this.z*=a):this.z=this.y=this.x=0;return this},multiplyVectors:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},applyEuler:function(){var a;return function(b){!1===b instanceof THREE.Euler&&console.error("THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.");void 0===a&&(a=new THREE.Quaternion);this.applyQuaternion(a.setFromEuler(b)); +return this}}(),applyAxisAngle:function(){var a;return function(b,c){void 0===a&&(a=new THREE.Quaternion);this.applyQuaternion(a.setFromAxisAngle(b,c));return this}}(),applyMatrix3:function(a){var b=this.x,c=this.y,d=this.z;a=a.elements;this.x=a[0]*b+a[3]*c+a[6]*d;this.y=a[1]*b+a[4]*c+a[7]*d;this.z=a[2]*b+a[5]*c+a[8]*d;return this},applyMatrix4:function(a){var b=this.x,c=this.y,d=this.z;a=a.elements;this.x=a[0]*b+a[4]*c+a[8]*d+a[12];this.y=a[1]*b+a[5]*c+a[9]*d+a[13];this.z=a[2]*b+a[6]*c+a[10]*d+a[14]; +return this},applyProjection:function(a){var b=this.x,c=this.y,d=this.z;a=a.elements;var e=1/(a[3]*b+a[7]*c+a[11]*d+a[15]);this.x=(a[0]*b+a[4]*c+a[8]*d+a[12])*e;this.y=(a[1]*b+a[5]*c+a[9]*d+a[13])*e;this.z=(a[2]*b+a[6]*c+a[10]*d+a[14])*e;return this},applyQuaternion:function(a){var b=this.x,c=this.y,d=this.z,e=a.x,g=a.y,f=a.z;a=a.w;var h=a*b+g*d-f*c,l=a*c+f*b-e*d,k=a*d+e*c-g*b,b=-e*b-g*c-f*d;this.x=h*a+b*-e+l*-f-k*-g;this.y=l*a+b*-g+k*-e-h*-f;this.z=k*a+b*-f+h*-g-l*-e;return this},project:function(){var a; +return function(b){void 0===a&&(a=new THREE.Matrix4);a.multiplyMatrices(b.projectionMatrix,a.getInverse(b.matrixWorld));return this.applyProjection(a)}}(),unproject:function(){var a;return function(b){void 0===a&&(a=new THREE.Matrix4);a.multiplyMatrices(b.matrixWorld,a.getInverse(b.projectionMatrix));return this.applyProjection(a)}}(),transformDirection:function(a){var b=this.x,c=this.y,d=this.z;a=a.elements;this.x=a[0]*b+a[4]*c+a[8]*d;this.y=a[1]*b+a[5]*c+a[9]*d;this.z=a[2]*b+a[6]*c+a[10]*d;this.normalize(); +return this},divide:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;return this},divideScalar:function(a){return this.multiplyScalar(1/a)},min:function(a){this.x=Math.min(this.x,a.x);this.y=Math.min(this.y,a.y);this.z=Math.min(this.z,a.z);return this},max:function(a){this.x=Math.max(this.x,a.x);this.y=Math.max(this.y,a.y);this.z=Math.max(this.z,a.z);return this},clamp:function(a,b){this.x=Math.max(a.x,Math.min(b.x,this.x));this.y=Math.max(a.y,Math.min(b.y,this.y));this.z=Math.max(a.z,Math.min(b.z, +this.z));return this},clampScalar:function(){var a,b;return function(c,d){void 0===a&&(a=new THREE.Vector3,b=new THREE.Vector3);a.set(c,c,c);b.set(d,d,d);return this.clamp(a,b)}}(),clampLength:function(a,b){var c=this.length();this.multiplyScalar(Math.max(a,Math.min(b,c))/c);return this},floor:function(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);this.z=Math.floor(this.z);return this},ceil:function(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);this.z=Math.ceil(this.z);return this}, +round:function(){this.x=Math.round(this.x);this.y=Math.round(this.y);this.z=Math.round(this.z);return this},roundToZero:function(){this.x=0>this.x?Math.ceil(this.x):Math.floor(this.x);this.y=0>this.y?Math.ceil(this.y):Math.floor(this.y);this.z=0>this.z?Math.ceil(this.z):Math.floor(this.z);return this},negate:function(){this.x=-this.x;this.y=-this.y;this.z=-this.z;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z}, +length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.multiplyScalar(a/this.length())},lerp:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;return this},lerpVectors:function(a,b,c){this.subVectors(b,a).multiplyScalar(c).add(a);return this},cross:function(a,b){if(void 0!== +b)return console.warn("THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead."),this.crossVectors(a,b);var c=this.x,d=this.y,e=this.z;this.x=d*a.z-e*a.y;this.y=e*a.x-c*a.z;this.z=c*a.y-d*a.x;return this},crossVectors:function(a,b){var c=a.x,d=a.y,e=a.z,g=b.x,f=b.y,h=b.z;this.x=d*h-e*f;this.y=e*g-c*h;this.z=c*f-d*g;return this},projectOnVector:function(){var a,b;return function(c){void 0===a&&(a=new THREE.Vector3);a.copy(c).normalize();b=this.dot(a);return this.copy(a).multiplyScalar(b)}}(), +projectOnPlane:function(){var a;return function(b){void 0===a&&(a=new THREE.Vector3);a.copy(this).projectOnVector(b);return this.sub(a)}}(),reflect:function(){var a;return function(b){void 0===a&&(a=new THREE.Vector3);return this.sub(a.copy(b).multiplyScalar(2*this.dot(b)))}}(),angleTo:function(a){a=this.dot(a)/(this.length()*a.length());return Math.acos(THREE.Math.clamp(a,-1,1))},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,c= +this.y-a.y;a=this.z-a.z;return b*b+c*c+a*a},setEulerFromRotationMatrix:function(a,b){console.error("THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.")},setEulerFromQuaternion:function(a,b){console.error("THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.")},getPositionFromMatrix:function(a){console.warn("THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().");return this.setFromMatrixPosition(a)}, +getScaleFromMatrix:function(a){console.warn("THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().");return this.setFromMatrixScale(a)},getColumnFromMatrix:function(a,b){console.warn("THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().");return this.setFromMatrixColumn(a,b)},setFromMatrixPosition:function(a){this.x=a.elements[12];this.y=a.elements[13];this.z=a.elements[14];return this},setFromMatrixScale:function(a){var b=this.set(a.elements[0], +a.elements[1],a.elements[2]).length(),c=this.set(a.elements[4],a.elements[5],a.elements[6]).length();a=this.set(a.elements[8],a.elements[9],a.elements[10]).length();this.x=b;this.y=c;this.z=a;return this},setFromMatrixColumn:function(a,b){var c=4*a,d=b.elements;this.x=d[c];this.y=d[c+1];this.z=d[c+2];return this},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},fromArray:function(a,b){void 0===b&&(b=0);this.x=a[b];this.y=a[b+1];this.z=a[b+2];return this},toArray:function(a,b){void 0=== +a&&(a=[]);void 0===b&&(b=0);a[b]=this.x;a[b+1]=this.y;a[b+2]=this.z;return a},fromAttribute:function(a,b,c){void 0===c&&(c=0);b=b*a.itemSize+c;this.x=a.array[b];this.y=a.array[b+1];this.z=a.array[b+2];return this}};THREE.Vector4=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=void 0!==d?d:1}; +THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},setW:function(a){this.w=a;return this},setComponent:function(a,b){switch(a){case 0:this.x=b;break;case 1:this.y=b;break;case 2:this.z=b;break;case 3:this.w=b;break;default:throw Error("index is out of range: "+a);}},getComponent:function(a){switch(a){case 0:return this.x; +case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw Error("index is out of range: "+a);}},clone:function(){return new this.constructor(this.x,this.y,this.z,this.w)},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=void 0!==a.w?a.w:1;return this},add:function(a,b){if(void 0!==b)return console.warn("THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(a,b);this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this}, +addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;this.w+=a;return this},addVectors:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addScaledVector:function(a,b){this.x+=a.x*b;this.y+=a.y*b;this.z+=a.z*b;this.w+=a.w*b;return this},sub:function(a,b){if(void 0!==b)return console.warn("THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(a,b);this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},subScalar:function(a){this.x-= +a;this.y-=a;this.z-=a;this.w-=a;return this},subVectors:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},multiplyScalar:function(a){isFinite(a)?(this.x*=a,this.y*=a,this.z*=a,this.w*=a):this.w=this.z=this.y=this.x=0;return this},applyMatrix4:function(a){var b=this.x,c=this.y,d=this.z,e=this.w;a=a.elements;this.x=a[0]*b+a[4]*c+a[8]*d+a[12]*e;this.y=a[1]*b+a[5]*c+a[9]*d+a[13]*e;this.z=a[2]*b+a[6]*c+a[10]*d+a[14]*e;this.w=a[3]*b+a[7]*c+a[11]*d+a[15]*e;return this}, +divideScalar:function(a){return this.multiplyScalar(1/a)},setAxisAngleFromQuaternion:function(a){this.w=2*Math.acos(a.w);var b=Math.sqrt(1-a.w*a.w);1E-4>b?(this.x=1,this.z=this.y=0):(this.x=a.x/b,this.y=a.y/b,this.z=a.z/b);return this},setAxisAngleFromRotationMatrix:function(a){var b,c,d;a=a.elements;var e=a[0];d=a[4];var g=a[8],f=a[1],h=a[5],l=a[9];c=a[2];b=a[6];var k=a[10];if(.01>Math.abs(d-f)&&.01>Math.abs(g-c)&&.01>Math.abs(l-b)){if(.1>Math.abs(d+f)&&.1>Math.abs(g+c)&&.1>Math.abs(l+b)&&.1>Math.abs(e+ +h+k-3))return this.set(1,0,0,0),this;a=Math.PI;e=(e+1)/2;h=(h+1)/2;k=(k+1)/2;d=(d+f)/4;g=(g+c)/4;l=(l+b)/4;e>h&&e>k?.01>e?(b=0,d=c=.707106781):(b=Math.sqrt(e),c=d/b,d=g/b):h>k?.01>h?(b=.707106781,c=0,d=.707106781):(c=Math.sqrt(h),b=d/c,d=l/c):.01>k?(c=b=.707106781,d=0):(d=Math.sqrt(k),b=g/d,c=l/d);this.set(b,c,d,a);return this}a=Math.sqrt((b-l)*(b-l)+(g-c)*(g-c)+(f-d)*(f-d));.001>Math.abs(a)&&(a=1);this.x=(b-l)/a;this.y=(g-c)/a;this.z=(f-d)/a;this.w=Math.acos((e+h+k-1)/2);return this},min:function(a){this.x= +Math.min(this.x,a.x);this.y=Math.min(this.y,a.y);this.z=Math.min(this.z,a.z);this.w=Math.min(this.w,a.w);return this},max:function(a){this.x=Math.max(this.x,a.x);this.y=Math.max(this.y,a.y);this.z=Math.max(this.z,a.z);this.w=Math.max(this.w,a.w);return this},clamp:function(a,b){this.x=Math.max(a.x,Math.min(b.x,this.x));this.y=Math.max(a.y,Math.min(b.y,this.y));this.z=Math.max(a.z,Math.min(b.z,this.z));this.w=Math.max(a.w,Math.min(b.w,this.w));return this},clampScalar:function(){var a,b;return function(c, +d){void 0===a&&(a=new THREE.Vector4,b=new THREE.Vector4);a.set(c,c,c,c);b.set(d,d,d,d);return this.clamp(a,b)}}(),floor:function(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);this.z=Math.floor(this.z);this.w=Math.floor(this.w);return this},ceil:function(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);this.z=Math.ceil(this.z);this.w=Math.ceil(this.w);return this},round:function(){this.x=Math.round(this.x);this.y=Math.round(this.y);this.z=Math.round(this.z);this.w=Math.round(this.w);return this}, +roundToZero:function(){this.x=0>this.x?Math.ceil(this.x):Math.floor(this.x);this.y=0>this.y?Math.ceil(this.y):Math.floor(this.y);this.z=0>this.z?Math.ceil(this.z):Math.floor(this.z);this.w=0>this.w?Math.ceil(this.w):Math.floor(this.w);return this},negate:function(){this.x=-this.x;this.y=-this.y;this.z=-this.z;this.w=-this.w;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},length:function(){return Math.sqrt(this.x* +this.x+this.y*this.y+this.z*this.z+this.w*this.w)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.multiplyScalar(a/this.length())},lerp:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b;return this},lerpVectors:function(a,b,c){this.subVectors(b,a).multiplyScalar(c).add(a);return this},equals:function(a){return a.x=== +this.x&&a.y===this.y&&a.z===this.z&&a.w===this.w},fromArray:function(a,b){void 0===b&&(b=0);this.x=a[b];this.y=a[b+1];this.z=a[b+2];this.w=a[b+3];return this},toArray:function(a,b){void 0===a&&(a=[]);void 0===b&&(b=0);a[b]=this.x;a[b+1]=this.y;a[b+2]=this.z;a[b+3]=this.w;return a},fromAttribute:function(a,b,c){void 0===c&&(c=0);b=b*a.itemSize+c;this.x=a.array[b];this.y=a.array[b+1];this.z=a.array[b+2];this.w=a.array[b+3];return this}}; +THREE.Euler=function(a,b,c,d){this._x=a||0;this._y=b||0;this._z=c||0;this._order=d||THREE.Euler.DefaultOrder};THREE.Euler.RotationOrders="XYZ YZX ZXY XZY YXZ ZYX".split(" ");THREE.Euler.DefaultOrder="XYZ"; +THREE.Euler.prototype={constructor:THREE.Euler,get x(){return this._x},set x(a){this._x=a;this.onChangeCallback()},get y(){return this._y},set y(a){this._y=a;this.onChangeCallback()},get z(){return this._z},set z(a){this._z=a;this.onChangeCallback()},get order(){return this._order},set order(a){this._order=a;this.onChangeCallback()},set:function(a,b,c,d){this._x=a;this._y=b;this._z=c;this._order=d||this._order;this.onChangeCallback();return this},clone:function(){return new this.constructor(this._x, +this._y,this._z,this._order)},copy:function(a){this._x=a._x;this._y=a._y;this._z=a._z;this._order=a._order;this.onChangeCallback();return this},setFromRotationMatrix:function(a,b,c){var d=THREE.Math.clamp,e=a.elements;a=e[0];var g=e[4],f=e[8],h=e[1],l=e[5],k=e[9],m=e[2],p=e[6],e=e[10];b=b||this._order;"XYZ"===b?(this._y=Math.asin(d(f,-1,1)),.99999>Math.abs(f)?(this._x=Math.atan2(-k,e),this._z=Math.atan2(-g,a)):(this._x=Math.atan2(p,l),this._z=0)):"YXZ"===b?(this._x=Math.asin(-d(k,-1,1)),.99999>Math.abs(k)? +(this._y=Math.atan2(f,e),this._z=Math.atan2(h,l)):(this._y=Math.atan2(-m,a),this._z=0)):"ZXY"===b?(this._x=Math.asin(d(p,-1,1)),.99999>Math.abs(p)?(this._y=Math.atan2(-m,e),this._z=Math.atan2(-g,l)):(this._y=0,this._z=Math.atan2(h,a))):"ZYX"===b?(this._y=Math.asin(-d(m,-1,1)),.99999>Math.abs(m)?(this._x=Math.atan2(p,e),this._z=Math.atan2(h,a)):(this._x=0,this._z=Math.atan2(-g,l))):"YZX"===b?(this._z=Math.asin(d(h,-1,1)),.99999>Math.abs(h)?(this._x=Math.atan2(-k,l),this._y=Math.atan2(-m,a)):(this._x= +0,this._y=Math.atan2(f,e))):"XZY"===b?(this._z=Math.asin(-d(g,-1,1)),.99999>Math.abs(g)?(this._x=Math.atan2(p,l),this._y=Math.atan2(f,a)):(this._x=Math.atan2(-k,e),this._y=0)):console.warn("THREE.Euler: .setFromRotationMatrix() given unsupported order: "+b);this._order=b;if(!1!==c)this.onChangeCallback();return this},setFromQuaternion:function(){var a;return function(b,c,d){void 0===a&&(a=new THREE.Matrix4);a.makeRotationFromQuaternion(b);this.setFromRotationMatrix(a,c,d);return this}}(),setFromVector3:function(a, +b){return this.set(a.x,a.y,a.z,b||this._order)},reorder:function(){var a=new THREE.Quaternion;return function(b){a.setFromEuler(this);this.setFromQuaternion(a,b)}}(),equals:function(a){return a._x===this._x&&a._y===this._y&&a._z===this._z&&a._order===this._order},fromArray:function(a){this._x=a[0];this._y=a[1];this._z=a[2];void 0!==a[3]&&(this._order=a[3]);this.onChangeCallback();return this},toArray:function(a,b){void 0===a&&(a=[]);void 0===b&&(b=0);a[b]=this._x;a[b+1]=this._y;a[b+2]=this._z;a[b+ +3]=this._order;return a},toVector3:function(a){return a?a.set(this._x,this._y,this._z):new THREE.Vector3(this._x,this._y,this._z)},onChange:function(a){this.onChangeCallback=a;return this},onChangeCallback:function(){}};THREE.Line3=function(a,b){this.start=void 0!==a?a:new THREE.Vector3;this.end=void 0!==b?b:new THREE.Vector3}; +THREE.Line3.prototype={constructor:THREE.Line3,set:function(a,b){this.start.copy(a);this.end.copy(b);return this},clone:function(){return(new this.constructor).copy(this)},copy:function(a){this.start.copy(a.start);this.end.copy(a.end);return this},center:function(a){return(a||new THREE.Vector3).addVectors(this.start,this.end).multiplyScalar(.5)},delta:function(a){return(a||new THREE.Vector3).subVectors(this.end,this.start)},distanceSq:function(){return this.start.distanceToSquared(this.end)},distance:function(){return this.start.distanceTo(this.end)}, +at:function(a,b){var c=b||new THREE.Vector3;return this.delta(c).multiplyScalar(a).add(this.start)},closestPointToPointParameter:function(){var a=new THREE.Vector3,b=new THREE.Vector3;return function(c,d){a.subVectors(c,this.start);b.subVectors(this.end,this.start);var e=b.dot(b),e=b.dot(a)/e;d&&(e=THREE.Math.clamp(e,0,1));return e}}(),closestPointToPoint:function(a,b,c){a=this.closestPointToPointParameter(a,b);c=c||new THREE.Vector3;return this.delta(c).multiplyScalar(a).add(this.start)},applyMatrix4:function(a){this.start.applyMatrix4(a); +this.end.applyMatrix4(a);return this},equals:function(a){return a.start.equals(this.start)&&a.end.equals(this.end)}};THREE.Box2=function(a,b){this.min=void 0!==a?a:new THREE.Vector2(Infinity,Infinity);this.max=void 0!==b?b:new THREE.Vector2(-Infinity,-Infinity)}; +THREE.Box2.prototype={constructor:THREE.Box2,set:function(a,b){this.min.copy(a);this.max.copy(b);return this},setFromPoints:function(a){this.makeEmpty();for(var b=0,c=a.length;bthis.max.x||a.ythis.max.y?!1:!0},containsBox:function(a){return this.min.x<=a.min.x&&a.max.x<=this.max.x&&this.min.y<=a.min.y&&a.max.y<=this.max.y?!0:!1},getParameter:function(a,b){return(b||new THREE.Vector2).set((a.x-this.min.x)/(this.max.x-this.min.x),(a.y-this.min.y)/(this.max.y-this.min.y))},isIntersectionBox:function(a){return a.max.xthis.max.x||a.max.y +this.max.y?!1:!0},clampPoint:function(a,b){return(b||new THREE.Vector2).copy(a).clamp(this.min,this.max)},distanceToPoint:function(){var a=new THREE.Vector2;return function(b){return a.copy(b).clamp(this.min,this.max).sub(b).length()}}(),intersect:function(a){this.min.max(a.min);this.max.min(a.max);return this},union:function(a){this.min.min(a.min);this.max.max(a.max);return this},translate:function(a){this.min.add(a);this.max.add(a);return this},equals:function(a){return a.min.equals(this.min)&& +a.max.equals(this.max)}};THREE.Box3=function(a,b){this.min=void 0!==a?a:new THREE.Vector3(Infinity,Infinity,Infinity);this.max=void 0!==b?b:new THREE.Vector3(-Infinity,-Infinity,-Infinity)}; +THREE.Box3.prototype={constructor:THREE.Box3,set:function(a,b){this.min.copy(a);this.max.copy(b);return this},setFromPoints:function(a){this.makeEmpty();for(var b=0,c=a.length;bthis.max.x||a.ythis.max.y||a.zthis.max.z?!1:!0},containsBox:function(a){return this.min.x<=a.min.x&&a.max.x<=this.max.x&&this.min.y<=a.min.y&&a.max.y<=this.max.y&&this.min.z<=a.min.z&&a.max.z<=this.max.z?!0:!1},getParameter:function(a,b){return(b||new THREE.Vector3).set((a.x-this.min.x)/(this.max.x- +this.min.x),(a.y-this.min.y)/(this.max.y-this.min.y),(a.z-this.min.z)/(this.max.z-this.min.z))},isIntersectionBox:function(a){return a.max.xthis.max.x||a.max.ythis.max.y||a.max.zthis.max.z?!1:!0},clampPoint:function(a,b){return(b||new THREE.Vector3).copy(a).clamp(this.min,this.max)},distanceToPoint:function(){var a=new THREE.Vector3;return function(b){return a.copy(b).clamp(this.min,this.max).sub(b).length()}}(),getBoundingSphere:function(){var a= +new THREE.Vector3;return function(b){b=b||new THREE.Sphere;b.center=this.center();b.radius=.5*this.size(a).length();return b}}(),intersect:function(a){this.min.max(a.min);this.max.min(a.max);return this},union:function(a){this.min.min(a.min);this.max.max(a.max);return this},applyMatrix4:function(){var a=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];return function(b){a[0].set(this.min.x,this.min.y, +this.min.z).applyMatrix4(b);a[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(b);a[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(b);a[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(b);a[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(b);a[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(b);a[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(b);a[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(b);this.makeEmpty();this.setFromPoints(a);return this}}(),translate:function(a){this.min.add(a); +this.max.add(a);return this},equals:function(a){return a.min.equals(this.min)&&a.max.equals(this.max)}};THREE.Matrix3=function(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1]);0this.determinant()&&(f=-f);c.x=g[12];c.y=g[13];c.z=g[14];b.elements.set(this.elements);c=1/f;var g=1/h,k=1/l;b.elements[0]*=c;b.elements[1]*= +c;b.elements[2]*=c;b.elements[4]*=g;b.elements[5]*=g;b.elements[6]*=g;b.elements[8]*=k;b.elements[9]*=k;b.elements[10]*=k;d.setFromRotationMatrix(b);e.x=f;e.y=h;e.z=l;return this}}(),makeFrustum:function(a,b,c,d,e,g){var f=this.elements;f[0]=2*e/(b-a);f[4]=0;f[8]=(b+a)/(b-a);f[12]=0;f[1]=0;f[5]=2*e/(d-c);f[9]=(d+c)/(d-c);f[13]=0;f[2]=0;f[6]=0;f[10]=-(g+e)/(g-e);f[14]=-2*g*e/(g-e);f[3]=0;f[7]=0;f[11]=-1;f[15]=0;return this},makePerspective:function(a,b,c,d){a=c*Math.tan(THREE.Math.degToRad(.5*a)); +var e=-a;return this.makeFrustum(e*b,a*b,e,a,c,d)},makeOrthographic:function(a,b,c,d,e,g){var f=this.elements,h=b-a,l=c-d,k=g-e;f[0]=2/h;f[4]=0;f[8]=0;f[12]=-((b+a)/h);f[1]=0;f[5]=2/l;f[9]=0;f[13]=-((c+d)/l);f[2]=0;f[6]=0;f[10]=-2/k;f[14]=-((g+e)/k);f[3]=0;f[7]=0;f[11]=0;f[15]=1;return this},equals:function(a){var b=this.elements;a=a.elements;for(var c=0;16>c;c++)if(b[c]!==a[c])return!1;return!0},fromArray:function(a){this.elements.set(a);return this},toArray:function(){var a=this.elements;return[a[0], +a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]]}};THREE.Ray=function(a,b){this.origin=void 0!==a?a:new THREE.Vector3;this.direction=void 0!==b?b:new THREE.Vector3}; +THREE.Ray.prototype={constructor:THREE.Ray,set:function(a,b){this.origin.copy(a);this.direction.copy(b);return this},clone:function(){return(new this.constructor).copy(this)},copy:function(a){this.origin.copy(a.origin);this.direction.copy(a.direction);return this},at:function(a,b){return(b||new THREE.Vector3).copy(this.direction).multiplyScalar(a).add(this.origin)},recast:function(){var a=new THREE.Vector3;return function(b){this.origin.copy(this.at(b,a));return this}}(),closestPointToPoint:function(a, +b){var c=b||new THREE.Vector3;c.subVectors(a,this.origin);var d=c.dot(this.direction);return 0>d?c.copy(this.origin):c.copy(this.direction).multiplyScalar(d).add(this.origin)},distanceToPoint:function(a){return Math.sqrt(this.distanceSqToPoint(a))},distanceSqToPoint:function(){var a=new THREE.Vector3;return function(b){var c=a.subVectors(b,this.origin).dot(this.direction);if(0>c)return this.origin.distanceToSquared(b);a.copy(this.direction).multiplyScalar(c).add(this.origin);return a.distanceToSquared(b)}}(), +distanceSqToSegment:function(){var a=new THREE.Vector3,b=new THREE.Vector3,c=new THREE.Vector3;return function(d,e,g,f){a.copy(d).add(e).multiplyScalar(.5);b.copy(e).sub(d).normalize();c.copy(this.origin).sub(a);var h=.5*d.distanceTo(e),l=-this.direction.dot(b),k=c.dot(this.direction),m=-c.dot(b),p=c.lengthSq(),n=Math.abs(1-l*l),q;0=-q?e<=q?(h=1/n,d*=h,e*=h,l=d*(d+l*e+2*k)+e*(l*d+e+2*m)+p):(e=h,d=Math.max(0,-(l*e+k)),l=-d*d+e*(e+2*m)+p):(e=-h,d=Math.max(0,-(l*e+k)), +l=-d*d+e*(e+2*m)+p):e<=-q?(d=Math.max(0,-(-l*h+k)),e=0g)return null;g=Math.sqrt(g-e);e=d-g;d+=g;return 0>e&&0>d?null:0>e?this.at(d,c):this.at(e,c)}}(),isIntersectionPlane:function(a){var b=a.distanceToPoint(this.origin);return 0===b||0>a.normal.dot(this.direction)*b?!0:!1},distanceToPlane:function(a){var b=a.normal.dot(this.direction);if(0===b)return 0===a.distanceToPoint(this.origin)?0:null;a=-(this.origin.dot(a.normal)+ +a.constant)/b;return 0<=a?a:null},intersectPlane:function(a,b){var c=this.distanceToPlane(a);return null===c?null:this.at(c,b)},isIntersectionBox:function(){var a=new THREE.Vector3;return function(b){return null!==this.intersectBox(b,a)}}(),intersectBox:function(a,b){var c,d,e,g,f;d=1/this.direction.x;g=1/this.direction.y;f=1/this.direction.z;var h=this.origin;0<=d?(c=(a.min.x-h.x)*d,d*=a.max.x-h.x):(c=(a.max.x-h.x)*d,d*=a.min.x-h.x);0<=g?(e=(a.min.y-h.y)*g,g*=a.max.y-h.y):(e=(a.max.y-h.y)*g,g*=a.min.y- +h.y);if(c>g||e>d)return null;if(e>c||c!==c)c=e;if(gf||e>d)return null;if(e>c||c!==c)c=e;if(fd?null:this.at(0<=c?c:d,b)},intersectTriangle:function(){var a=new THREE.Vector3,b=new THREE.Vector3,c=new THREE.Vector3,d=new THREE.Vector3;return function(e,g,f,h,l){b.subVectors(g,e);c.subVectors(f,e);d.crossVectors(b,c);g=this.direction.dot(d);if(0g)h=-1, +g=-g;else return null;a.subVectors(this.origin,e);e=h*this.direction.dot(c.crossVectors(a,c));if(0>e)return null;f=h*this.direction.dot(b.cross(a));if(0>f||e+f>g)return null;e=-h*a.dot(d);return 0>e?null:this.at(e/g,l)}}(),applyMatrix4:function(a){this.direction.add(this.origin).applyMatrix4(a);this.origin.applyMatrix4(a);this.direction.sub(this.origin);this.direction.normalize();return this},equals:function(a){return a.origin.equals(this.origin)&&a.direction.equals(this.direction)}}; +THREE.Sphere=function(a,b){this.center=void 0!==a?a:new THREE.Vector3;this.radius=void 0!==b?b:0}; +THREE.Sphere.prototype={constructor:THREE.Sphere,set:function(a,b){this.center.copy(a);this.radius=b;return this},setFromPoints:function(){var a=new THREE.Box3;return function(b,c){var d=this.center;void 0!==c?d.copy(c):a.setFromPoints(b).center(d);for(var e=0,g=0,f=b.length;g=this.radius},containsPoint:function(a){return a.distanceToSquared(this.center)<=this.radius*this.radius},distanceToPoint:function(a){return a.distanceTo(this.center)-this.radius},intersectsSphere:function(a){var b=this.radius+a.radius;return a.center.distanceToSquared(this.center)<=b*b},clampPoint:function(a,b){var c=this.center.distanceToSquared(a),d=b||new THREE.Vector3;d.copy(a);c>this.radius*this.radius&&(d.sub(this.center).normalize(),d.multiplyScalar(this.radius).add(this.center)); +return d},getBoundingBox:function(a){a=a||new THREE.Box3;a.set(this.center,this.center);a.expandByScalar(this.radius);return a},applyMatrix4:function(a){this.center.applyMatrix4(a);this.radius*=a.getMaxScaleOnAxis();return this},translate:function(a){this.center.add(a);return this},equals:function(a){return a.center.equals(this.center)&&a.radius===this.radius}}; +THREE.Frustum=function(a,b,c,d,e,g){this.planes=[void 0!==a?a:new THREE.Plane,void 0!==b?b:new THREE.Plane,void 0!==c?c:new THREE.Plane,void 0!==d?d:new THREE.Plane,void 0!==e?e:new THREE.Plane,void 0!==g?g:new THREE.Plane]}; +THREE.Frustum.prototype={constructor:THREE.Frustum,set:function(a,b,c,d,e,g){var f=this.planes;f[0].copy(a);f[1].copy(b);f[2].copy(c);f[3].copy(d);f[4].copy(e);f[5].copy(g);return this},clone:function(){return(new this.constructor).copy(this)},copy:function(a){for(var b=this.planes,c=0;6>c;c++)b[c].copy(a.planes[c]);return this},setFromMatrix:function(a){var b=this.planes,c=a.elements;a=c[0];var d=c[1],e=c[2],g=c[3],f=c[4],h=c[5],l=c[6],k=c[7],m=c[8],p=c[9],n=c[10],q=c[11],s=c[12],t=c[13],v=c[14], +c=c[15];b[0].setComponents(g-a,k-f,q-m,c-s).normalize();b[1].setComponents(g+a,k+f,q+m,c+s).normalize();b[2].setComponents(g+d,k+h,q+p,c+t).normalize();b[3].setComponents(g-d,k-h,q-p,c-t).normalize();b[4].setComponents(g-e,k-l,q-n,c-v).normalize();b[5].setComponents(g+e,k+l,q+n,c+v).normalize();return this},intersectsObject:function(){var a=new THREE.Sphere;return function(b){var c=b.geometry;null===c.boundingSphere&&c.computeBoundingSphere();a.copy(c.boundingSphere);a.applyMatrix4(b.matrixWorld); +return this.intersectsSphere(a)}}(),intersectsSphere:function(a){var b=this.planes,c=a.center;a=-a.radius;for(var d=0;6>d;d++)if(b[d].distanceToPoint(c)e;e++){var g=d[e];a.x=0f&&0>g)return!1}return!0}}(),containsPoint:function(a){for(var b=this.planes,c=0;6>c;c++)if(0>b[c].distanceToPoint(a))return!1;return!0}};THREE.Plane=function(a,b){this.normal=void 0!==a?a:new THREE.Vector3(1,0,0);this.constant=void 0!==b?b:0}; +THREE.Plane.prototype={constructor:THREE.Plane,set:function(a,b){this.normal.copy(a);this.constant=b;return this},setComponents:function(a,b,c,d){this.normal.set(a,b,c);this.constant=d;return this},setFromNormalAndCoplanarPoint:function(a,b){this.normal.copy(a);this.constant=-b.dot(this.normal);return this},setFromCoplanarPoints:function(){var a=new THREE.Vector3,b=new THREE.Vector3;return function(c,d,e){d=a.subVectors(e,d).cross(b.subVectors(c,d)).normalize();this.setFromNormalAndCoplanarPoint(d, +c);return this}}(),clone:function(){return(new this.constructor).copy(this)},copy:function(a){this.normal.copy(a.normal);this.constant=a.constant;return this},normalize:function(){var a=1/this.normal.length();this.normal.multiplyScalar(a);this.constant*=a;return this},negate:function(){this.constant*=-1;this.normal.negate();return this},distanceToPoint:function(a){return this.normal.dot(a)+this.constant},distanceToSphere:function(a){return this.distanceToPoint(a.center)-a.radius},projectPoint:function(a, +b){return this.orthoPoint(a,b).sub(a).negate()},orthoPoint:function(a,b){var c=this.distanceToPoint(a);return(b||new THREE.Vector3).copy(this.normal).multiplyScalar(c)},isIntersectionLine:function(a){var b=this.distanceToPoint(a.start);a=this.distanceToPoint(a.end);return 0>b&&0a&&0g||1e;e++)8===e||13===e||18===e||23===e?b[e]="-":14===e?b[e]="4":(2>=c&&(c=33554432+16777216*Math.random()|0),d=c&15,c>>=4,b[e]=a[19===e?d&3|8:d]);return b.join("")}}(),clamp:function(a,b,c){return Math.max(b,Math.min(c,a))},euclideanModulo:function(a,b){return(a%b+b)%b},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},smoothstep:function(a, +b,c){if(a<=b)return 0;if(a>=c)return 1;a=(a-b)/(c-b);return a*a*(3-2*a)},smootherstep:function(a,b,c){if(a<=b)return 0;if(a>=c)return 1;a=(a-b)/(c-b);return a*a*a*(a*(6*a-15)+10)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(.5-Math.random())},degToRad:function(){var a=Math.PI/180;return function(b){return b*a}}(), +radToDeg:function(){var a=180/Math.PI;return function(b){return b*a}}(),isPowerOfTwo:function(a){return 0===(a&a-1)&&0!==a},nearestPowerOfTwo:function(a){return Math.pow(2,Math.round(Math.log(a)/Math.LN2))},nextPowerOfTwo:function(a){a--;a|=a>>1;a|=a>>2;a|=a>>4;a|=a>>8;a|=a>>16;a++;return a}}; +THREE.Spline=function(a){function b(a,b,c,d,e,g,f){a=.5*(c-a);d=.5*(d-b);return(2*(b-c)+a+d)*f+(-3*(b-c)-2*a-d)*g+a*e+b}this.points=a;var c=[],d={x:0,y:0,z:0},e,g,f,h,l,k,m,p,n;this.initFromArray=function(a){this.points=[];for(var b=0;bthis.points.length-2?this.points.length-1:g+1;c[3]=g>this.points.length-3?this.points.length-1:g+ +2;k=this.points[c[0]];m=this.points[c[1]];p=this.points[c[2]];n=this.points[c[3]];h=f*f;l=f*h;d.x=b(k.x,m.x,p.x,n.x,f,h,l);d.y=b(k.y,m.y,p.y,n.y,f,h,l);d.z=b(k.z,m.z,p.z,n.z,f,h,l);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;a=b.x+b.y}}(); +THREE.Triangle.prototype={constructor:THREE.Triangle,set:function(a,b,c){this.a.copy(a);this.b.copy(b);this.c.copy(c);return this},setFromPointsAndIndices:function(a,b,c,d){this.a.copy(a[b]);this.b.copy(a[c]);this.c.copy(a[d]);return this},clone:function(){return(new this.constructor).copy(this)},copy:function(a){this.a.copy(a.a);this.b.copy(a.b);this.c.copy(a.c);return this},area:function(){var a=new THREE.Vector3,b=new THREE.Vector3;return function(){a.subVectors(this.c,this.b);b.subVectors(this.a, +this.b);return.5*a.cross(b).length()}}(),midpoint:function(a){return(a||new THREE.Vector3).addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)},normal:function(a){return THREE.Triangle.normal(this.a,this.b,this.c,a)},plane:function(a){return(a||new THREE.Plane).setFromCoplanarPoints(this.a,this.b,this.c)},barycoordFromPoint:function(a,b){return THREE.Triangle.barycoordFromPoint(a,this.a,this.b,this.c,b)},containsPoint:function(a){return THREE.Triangle.containsPoint(a,this.a,this.b,this.c)}, +equals:function(a){return a.a.equals(this.a)&&a.b.equals(this.b)&&a.c.equals(this.c)}};THREE.Channels=function(){this.mask=1};THREE.Channels.prototype={constructor:THREE.Channels,set:function(a){this.mask=1<d;d++)if(e[d]===e[(d+1)%3]){a.push(g);break}for(g=a.length-1;0<=g;g--)for(e=a[g],this.faces.splice(e, +1),c=0,f=this.faceVertexUvs.length;cthis.duration)for(a=0;a=e.referenceCount&&(e.unbind(),delete this.propertyBindingMap[d])}return this},findActionByName:function(a){for(var b=0;b=c.weight)&&c.enabled)for(var g=0;gc?a:b},lerp_boolean_immediate:function(a,b,c){return a},lerp_string:function(a,b,c){return.5>c?a:b},lerp_string_immediate:function(a,b,c){return a},getLerpFunc:function(a,b){if(void 0===a||null===a)throw Error("examplarValue is null");switch(typeof a){case "object":if(a.lerp)return THREE.AnimationUtils.lerp_object;if(a.slerp)return THREE.AnimationUtils.slerp_object;break;case "number":return THREE.AnimationUtils.lerp_number;case "boolean":return b?THREE.AnimationUtils.lerp_boolean:THREE.AnimationUtils.lerp_boolean_immediate; +case "string":return b?THREE.AnimationUtils.lerp_string:THREE.AnimationUtils.lerp_string_immediate}}};THREE.KeyframeTrack=function(a,b){if(void 0===a)throw Error("track name is undefined");if(void 0===b||0===b.length)throw Error("no keys in track named "+a);this.name=a;this.keys=b;this.lastIndex=0;this.validate();this.optimize()}; +THREE.KeyframeTrack.prototype={constructor:THREE.KeyframeTrack,getAt:function(a){for(;this.lastIndex=this.keys[this.lastIndex].time;)this.lastIndex++;for(;0=this.keys.length)return this.setResult(this.keys[this.keys.length-1].value),this.result;if(0===this.lastIndex)return this.setResult(this.keys[0].value),this.result;var b=this.keys[this.lastIndex-1];this.setResult(b.value);if(b.constantToNext)return this.result; +var c=this.keys[this.lastIndex];return this.result=this.lerpValues(this.result,c.value,(a-b.time)/(c.time-b.time))},shift:function(a){if(0!==a)for(var b=0;b=b)e++;else break;0c.time){console.error(" key.time is less than previous key time, out of order keys", +this,b,c,a);return}a=c}return this}},optimize:function(){var a=[],b=this.keys[0];a.push(b);THREE.AnimationUtils.getEqualsFunc(b.value);for(var c=1;cthis.cumulativeWeight){var a= +1-this.cumulativeWeight;this.cumulativeValue=this.lerpValue(this.cumulativeValue,this.originalValue,a/(this.cumulativeWeight+a))}this.setValue(this.cumulativeValue)&&this.triggerDirty&&this.triggerDirty();this.cumulativeValue=null;this.cumulativeWeight=0}}}; +THREE.PropertyBinding.parseTrackName=function(a){var b=/^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/,c=b.exec(a);if(!c)throw Error("cannot parse trackName at all: "+a);c.index===b.lastIndex&&b.lastIndex++;b={directoryName:c[1],nodeName:c[3],objectName:c[5],objectIndex:c[7],propertyName:c[9],propertyIndex:c[11]};if(null===b.propertyName||0===b.propertyName.length)throw Error("can not parse propertyName from trackName: "+a);return b}; +THREE.PropertyBinding.findNode=function(a,b){function c(a){for(var c=0;cc?a:b};THREE.StringKeyframeTrack.prototype.compareValues=function(a,b){return a===b};THREE.StringKeyframeTrack.prototype.clone=function(){for(var a=[],b=0;bc?a:b};THREE.BooleanKeyframeTrack.prototype.compareValues=function(a,b){return a===b};THREE.BooleanKeyframeTrack.prototype.clone=function(){for(var a=[],b=0;bl.opacity&&(l.transparent=!0);c.setTextures(h);return c.parse(l)}}()};THREE.Loader.Handlers={handlers:[],add:function(a,b){this.handlers.push(a,b)},get:function(a){for(var b=this.handlers,c=0,d=b.length;cf;f++)n=w[l++],u=v[2*n],n=v[2*n+1],u=new THREE.Vector2(u,n),2!==f&&c.faceVertexUvs[d][h].push(u),0!==f&&c.faceVertexUvs[d][h+1].push(u);p&&(p=3*w[l++],q.normal.set(D[p++],D[p++],D[p]),t.normal.copy(q.normal));if(s)for(d=0;4>d;d++)p=3*w[l++],s=new THREE.Vector3(D[p++],D[p++],D[p]),2!==d&&q.vertexNormals.push(s),0!==d&&t.vertexNormals.push(s); +m&&(m=w[l++],m=x[m],q.color.setHex(m),t.color.setHex(m));if(b)for(d=0;4>d;d++)m=w[l++],m=x[m],2!==d&&q.vertexColors.push(new THREE.Color(m)),0!==d&&t.vertexColors.push(new THREE.Color(m));c.faces.push(q);c.faces.push(t)}else{q=new THREE.Face3;q.a=w[l++];q.b=w[l++];q.c=w[l++];h&&(h=w[l++],q.materialIndex=h);h=c.faces.length;if(d)for(d=0;df;f++)n=w[l++],u=v[2*n],n=v[2*n+1],u=new THREE.Vector2(u,n),c.faceVertexUvs[d][h].push(u);p&&(p=3*w[l++],q.normal.set(D[p++], +D[p++],D[p]));if(s)for(d=0;3>d;d++)p=3*w[l++],s=new THREE.Vector3(D[p++],D[p++],D[p]),q.vertexNormals.push(s);m&&(m=w[l++],q.color.setHex(x[m]));if(b)for(d=0;3>d;d++)m=w[l++],q.vertexColors.push(new THREE.Color(x[m]));c.faces.push(q)}})(d);(function(){var b=void 0!==a.influencesPerVertex?a.influencesPerVertex:2;if(a.skinWeights)for(var d=0,f=a.skinWeights.length;dthis.opacity&&(b.opacity=this.opacity);!0===this.transparent&&(b.transparent=this.transparent);0a.x||1a.x?0:1;break;case THREE.MirroredRepeatWrapping:1===Math.abs(Math.floor(a.x)%2)?a.x=Math.ceil(a.x)-a.x:a.x-=Math.floor(a.x)}if(0>a.y||1a.y?0:1;break;case THREE.MirroredRepeatWrapping:1===Math.abs(Math.floor(a.y)% +2)?a.y=Math.ceil(a.y)-a.y:a.y-=Math.floor(a.y)}this.flipY&&(a.y=1-a.y)}}};THREE.EventDispatcher.prototype.apply(THREE.Texture.prototype);THREE.TextureIdCount=0;THREE.CanvasTexture=function(a,b,c,d,e,g,f,h,l){THREE.Texture.call(this,a,b,c,d,e,g,f,h,l);this.needsUpdate=!0};THREE.CanvasTexture.prototype=Object.create(THREE.Texture.prototype);THREE.CanvasTexture.prototype.constructor=THREE.CanvasTexture; +THREE.CubeTexture=function(a,b,c,d,e,g,f,h,l){b=void 0!==b?b:THREE.CubeReflectionMapping;THREE.Texture.call(this,a,b,c,d,e,g,f,h,l);this.images=a;this.flipY=!1};THREE.CubeTexture.prototype=Object.create(THREE.Texture.prototype);THREE.CubeTexture.prototype.constructor=THREE.CubeTexture;THREE.CubeTexture.prototype.copy=function(a){THREE.Texture.prototype.copy.call(this,a);this.images=a.images;return this}; +THREE.CompressedTexture=function(a,b,c,d,e,g,f,h,l,k,m){THREE.Texture.call(this,null,g,f,h,l,k,d,e,m);this.image={width:b,height:c};this.mipmaps=a;this.generateMipmaps=this.flipY=!1};THREE.CompressedTexture.prototype=Object.create(THREE.Texture.prototype);THREE.CompressedTexture.prototype.constructor=THREE.CompressedTexture; +THREE.DataTexture=function(a,b,c,d,e,g,f,h,l,k,m){THREE.Texture.call(this,null,g,f,h,l,k,d,e,m);this.image={data:a,width:b,height:c};this.magFilter=void 0!==l?l:THREE.NearestFilter;this.minFilter=void 0!==k?k:THREE.NearestFilter;this.generateMipmaps=this.flipY=!1};THREE.DataTexture.prototype=Object.create(THREE.Texture.prototype);THREE.DataTexture.prototype.constructor=THREE.DataTexture; +THREE.VideoTexture=function(a,b,c,d,e,g,f,h,l){function k(){requestAnimationFrame(k);a.readyState===a.HAVE_ENOUGH_DATA&&(m.needsUpdate=!0)}THREE.Texture.call(this,a,b,c,d,e,g,f,h,l);this.generateMipmaps=!1;var m=this;k()};THREE.VideoTexture.prototype=Object.create(THREE.Texture.prototype);THREE.VideoTexture.prototype.constructor=THREE.VideoTexture;THREE.Group=function(){THREE.Object3D.call(this);this.type="Group"};THREE.Group.prototype=Object.create(THREE.Object3D.prototype); +THREE.Group.prototype.constructor=THREE.Group;THREE.Points=function(a,b){THREE.Object3D.call(this);this.type="Points";this.geometry=void 0!==a?a:new THREE.Geometry;this.material=void 0!==b?b:new THREE.PointsMaterial({color:16777215*Math.random()})};THREE.Points.prototype=Object.create(THREE.Object3D.prototype);THREE.Points.prototype.constructor=THREE.Points; +THREE.Points.prototype.raycast=function(){var a=new THREE.Matrix4,b=new THREE.Ray;return function(c,d){function e(a,e){var f=b.distanceSqToPoint(a);if(fc.far||d.push({distance:k,distanceToRay:Math.sqrt(f),point:h.clone(),index:e,face:null,object:g})}}var g=this,f=g.geometry,h=c.params.Points.threshold;a.getInverse(this.matrixWorld);b.copy(c.ray).applyMatrix4(a);if(null===f.boundingBox||!1!== +b.isIntersectionBox(f.boundingBox)){var h=h/((this.scale.x+this.scale.y+this.scale.z)/3),l=h*h,h=new THREE.Vector3;if(f instanceof THREE.BufferGeometry){var k=f.index,f=f.attributes.position.array;if(null!==k)for(var m=k.array,k=0,p=m.length;kg||(m.applyMatrix4(this.matrixWorld),t=d.ray.origin.distanceTo(m),td.far||e.push({distance:t,point:k.clone().applyMatrix4(this.matrixWorld),index:n,face:null,faceIndex:null,object:this}))}else for(q=q.position.array,n=0,s=q.length/3-1;ng||(m.applyMatrix4(this.matrixWorld),t=d.ray.origin.distanceTo(m),td.far||e.push({distance:t,point:k.clone().applyMatrix4(this.matrixWorld),index:n,face:null,faceIndex:null,object:this}))}else if(f instanceof THREE.Geometry)for(h=f.vertices,l=h.length,n=0;ng||(m.applyMatrix4(this.matrixWorld),t=d.ray.origin.distanceTo(m),td.far||e.push({distance:t,point:k.clone().applyMatrix4(this.matrixWorld), +index:n,face:null,faceIndex:null,object:this}))}}}();THREE.Line.prototype.clone=function(){return(new this.constructor(this.geometry,this.material)).copy(this)};THREE.LineStrip=0;THREE.LinePieces=1;THREE.LineSegments=function(a,b){THREE.Line.call(this,a,b);this.type="LineSegments"};THREE.LineSegments.prototype=Object.create(THREE.Line.prototype);THREE.LineSegments.prototype.constructor=THREE.LineSegments; +THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.type="Mesh";this.geometry=void 0!==a?a:new THREE.Geometry;this.material=void 0!==b?b:new THREE.MeshBasicMaterial({color:16777215*Math.random()});this.updateMorphTargets()};THREE.Mesh.prototype=Object.create(THREE.Object3D.prototype);THREE.Mesh.prototype.constructor=THREE.Mesh; +THREE.Mesh.prototype.updateMorphTargets=function(){if(void 0!==this.geometry.morphTargets&&0b.far?null:{distance:c,point:u.clone(), +object:a}}function c(c,d,e,g,k,m,p,u){f.fromArray(g,3*m);h.fromArray(g,3*p);l.fromArray(g,3*u);if(c=b(c,d,e,f,h,l,v))k&&(n.fromArray(k,2*m),q.fromArray(k,2*p),s.fromArray(k,2*u),c.uv=a(v,f,h,l,n,q,s)),c.face=new THREE.Face3(m,p,u,THREE.Triangle.normal(f,h,l)),c.faceIndex=m;return c}var d=new THREE.Matrix4,e=new THREE.Ray,g=new THREE.Sphere,f=new THREE.Vector3,h=new THREE.Vector3,l=new THREE.Vector3,k=new THREE.Vector3,m=new THREE.Vector3,p=new THREE.Vector3,n=new THREE.Vector2,q=new THREE.Vector2, +s=new THREE.Vector2,t=new THREE.Vector3,v=new THREE.Vector3,u=new THREE.Vector3;return function(u,t){var x=this.geometry,B=this.material;if(void 0!==B){null===x.boundingSphere&&x.computeBoundingSphere();var y=this.matrixWorld;g.copy(x.boundingSphere);g.applyMatrix4(y);if(!1!==u.ray.isIntersectionSphere(g)&&(d.getInverse(y),e.copy(u.ray).applyMatrix4(d),null===x.boundingBox||!1!==e.isIntersectionBox(x.boundingBox))){var z,A;if(x instanceof THREE.BufferGeometry){var J,F,B=x.index,y=x.attributes,x=y.position.array; +void 0!==y.uv&&(z=y.uv.array);if(null!==B)for(var y=B.array,C=0,N=y.length;C=d[e].distance)d[e-1].object.visible=!1,d[e].object.visible=!0;else break;for(;ethis.scale.x*this.scale.y||c.push({distance:Math.sqrt(d),point:this.position,face:null,object:this})}}();THREE.Sprite.prototype.clone=function(){return(new this.constructor(this.material)).copy(this)};THREE.Particle=THREE.Sprite; +THREE.LensFlare=function(a,b,c,d,e){THREE.Object3D.call(this);this.lensFlares=[];this.positionScreen=new THREE.Vector3;this.customUpdateCallback=void 0;void 0!==a&&this.add(a,b,c,d,e)};THREE.LensFlare.prototype=Object.create(THREE.Object3D.prototype);THREE.LensFlare.prototype.constructor=THREE.LensFlare; +THREE.LensFlare.prototype.add=function(a,b,c,d,e,g){void 0===b&&(b=-1);void 0===c&&(c=0);void 0===g&&(g=1);void 0===e&&(e=new THREE.Color(16777215));void 0===d&&(d=THREE.NormalBlending);c=Math.min(c,Math.max(0,c));this.lensFlares.push({texture:a,size:b,distance:c,x:0,y:0,z:0,scale:1,rotation:0,opacity:g,color:e,blending:d})}; +THREE.LensFlare.prototype.updateLensFlares=function(){var a,b=this.lensFlares.length,c,d=2*-this.positionScreen.x,e=2*-this.positionScreen.y;for(a=0;a dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );", +THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.color_fragment,"\toutgoingLight = diffuseColor.rgb;",THREE.ShaderChunk.fog_fragment,"\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n}"].join("\n")},depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3},opacity:{type:"f",value:1}},vertexShader:[THREE.ShaderChunk.common,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.begin_vertex,THREE.ShaderChunk.morphtarget_vertex, +THREE.ShaderChunk.project_vertex,THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:["uniform float mNear;\nuniform float mFar;\nuniform float opacity;",THREE.ShaderChunk.common,THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {",THREE.ShaderChunk.logdepthbuf_fragment,"\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tfloat depth = gl_FragDepthEXT / gl_FragCoord.w;\n\t#else\n\t\tfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n\t#endif\n\tfloat color = 1.0 - smoothstep( mNear, mFar, depth );\n\tgl_FragColor = vec4( vec3( color ), opacity );\n}"].join("\n")}, +normal:{uniforms:{opacity:{type:"f",value:1}},vertexShader:["varying vec3 vNormal;",THREE.ShaderChunk.common,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {\n\tvNormal = normalize( normalMatrix * normal );",THREE.ShaderChunk.begin_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.project_vertex,THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:["uniform float opacity;\nvarying vec3 vNormal;",THREE.ShaderChunk.common, +THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {\n\tgl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",THREE.ShaderChunk.logdepthbuf_fragment,"}"].join("\n")},cube:{uniforms:{tCube:{type:"t",value:null},tFlip:{type:"f",value:-1}},vertexShader:["varying vec3 vWorldPosition;",THREE.ShaderChunk.common,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", +THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:["uniform samplerCube tCube;\nuniform float tFlip;\nvarying vec3 vWorldPosition;",THREE.ShaderChunk.common,THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {\n\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",THREE.ShaderChunk.logdepthbuf_fragment,"}"].join("\n")},equirect:{uniforms:{tEquirect:{type:"t",value:null},tFlip:{type:"f",value:-1}},vertexShader:["varying vec3 vWorldPosition;", +THREE.ShaderChunk.common,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:["uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;",THREE.ShaderChunk.common,THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {\nvec3 direction = normalize( vWorldPosition );\nvec2 sampleUV;\nsampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\nsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\ngl_FragColor = texture2D( tEquirect, sampleUV );", +THREE.ShaderChunk.logdepthbuf_fragment,"}"].join("\n")},depthRGBA:{uniforms:{},vertexShader:[THREE.ShaderChunk.common,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.begin_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.project_vertex,THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:[THREE.ShaderChunk.common, +THREE.ShaderChunk.logdepthbuf_pars_fragment,"vec4 pack_depth( const in float depth ) {\n\tconst vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\n\tconst vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\n\tvec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );\n\tres -= res.xxyz * bit_mask;\n\treturn res;\n}\nvoid main() {",THREE.ShaderChunk.logdepthbuf_fragment,"\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tgl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );\n\t#else\n\t\tgl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );\n\t#endif\n}"].join("\n")}, +distanceRGBA:{uniforms:{lightPos:{type:"v3",value:new THREE.Vector3(0,0,0)}},vertexShader:["varying vec4 vWorldPosition;",THREE.ShaderChunk.common,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,"void main() {",THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.begin_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.project_vertex,THREE.ShaderChunk.worldpos_vertex,"vWorldPosition = worldPosition;\n}"].join("\n"),fragmentShader:["uniform vec3 lightPos;\nvarying vec4 vWorldPosition;", +THREE.ShaderChunk.common,"vec4 pack1K ( float depth ) {\n depth /= 1000.0;\n const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\n\tconst vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\n\tvec4 res = fract( depth * bitSh );\n\tres -= res.xxyz * bitMsk;\n\treturn res; \n}\nfloat unpack1K ( vec4 color ) {\n\tconst vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n\treturn dot( color, bitSh ) * 1000.0;\n}\nvoid main () {\n\tgl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );\n}"].join("\n")}}; +THREE.WebGLRenderer=function(a){function b(a,b,c,d){!0===G&&(a*=d,b*=d,c*=d);r.clearColor(a,b,c,d)}function c(){I.init();r.viewport(na,oa,pa,qa);b(U.r,U.g,U.b,X)}function d(){ra=Aa=null;sa="";ta=-1;wa=!0;I.reset()}function e(a){a.preventDefault();d();c();W.clear()}function g(a){a=a.target;a.removeEventListener("dispose",g);a:{var b=W.get(a);if(a.image&&b.__image__webglTextureCube)r.deleteTexture(b.__image__webglTextureCube);else{if(void 0===b.__webglInit)break a;r.deleteTexture(b.__webglTexture)}W.delete(a)}la.textures--} +function f(a){a=a.target;a.removeEventListener("dispose",f);var b=W.get(a),c=W.get(a.texture);if(a&&void 0!==c.__webglTexture){r.deleteTexture(c.__webglTexture);if(a instanceof THREE.WebGLRenderTargetCube)for(c=0;6>c;c++)r.deleteFramebuffer(b.__webglFramebuffer[c]),r.deleteRenderbuffer(b.__webglRenderbuffer[c]);else r.deleteFramebuffer(b.__webglFramebuffer),r.deleteRenderbuffer(b.__webglRenderbuffer);W.delete(a.texture);W.delete(a)}la.textures--}function h(a){a=a.target;a.removeEventListener("dispose", +h);l(a);W.delete(a)}function l(a){var b=W.get(a).program;a.program=void 0;void 0!==b&&ua.releaseProgram(b)}function k(a,b){return b[0]-a[0]}function m(a,b){return a.object.renderOrder!==b.object.renderOrder?a.object.renderOrder-b.object.renderOrder:a.material.id!==b.material.id?a.material.id-b.material.id:a.z!==b.z?a.z-b.z:a.id-b.id}function p(a,b){return a.object.renderOrder!==b.object.renderOrder?a.object.renderOrder-b.object.renderOrder:a.z!==b.z?b.z-a.z:a.id-b.id}function n(a,b,c,d,e){var f;c.transparent? +(d=Z,f=++fa):(d=ca,f=++ga);f=d[f];void 0!==f?(f.id=a.id,f.object=a,f.geometry=b,f.material=c,f.z=V.z,f.group=e):(f={id:a.id,object:a,geometry:b,material:c,z:V.z,group:e},d.push(f))}function q(a,b){if(!1!==a.visible){if(0!==(a.channels.mask&b.channels.mask))if(a instanceof THREE.Light)da.push(a);else if(a instanceof THREE.Sprite)ea.push(a);else if(a instanceof THREE.LensFlare)ja.push(a);else if(a instanceof THREE.ImmediateRenderObject)!0===aa.sortObjects&&(V.setFromMatrixPosition(a.matrixWorld),V.applyProjection(xa)), +n(a,null,a.material,V.z,null);else if(a instanceof THREE.Mesh||a instanceof THREE.Line||a instanceof THREE.Points)if(a instanceof THREE.SkinnedMesh&&a.skeleton.update(),!1===a.frustumCulled||!0===Ba.intersectsObject(a)){var c=a.material;if(!0===c.visible){!0===aa.sortObjects&&(V.setFromMatrixPosition(a.matrixWorld),V.applyProjection(xa));var d=va.update(a);if(c instanceof THREE.MeshFaceMaterial)for(var e=d.groups,f=c.materials,c=0,g=e.length;c=ha.maxTextures&&console.warn("WebGLRenderer: trying to use "+a+" texture units while this GPU supports only "+ha.maxTextures);ya+=1;return a}function D(a,b,c,d){a[b+0]=c.r*d;a[b+1]=c.g*d;a[b+2]=c.b*d}function x(a,b,c){c?(r.texParameteri(a,r.TEXTURE_WRAP_S,N(b.wrapS)),r.texParameteri(a,r.TEXTURE_WRAP_T,N(b.wrapT)),r.texParameteri(a,r.TEXTURE_MAG_FILTER, +N(b.magFilter)),r.texParameteri(a,r.TEXTURE_MIN_FILTER,N(b.minFilter))):(r.texParameteri(a,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(a,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),b.wrapS===THREE.ClampToEdgeWrapping&&b.wrapT===THREE.ClampToEdgeWrapping||console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.",b),r.texParameteri(a,r.TEXTURE_MAG_FILTER,C(b.magFilter)),r.texParameteri(a,r.TEXTURE_MIN_FILTER,C(b.minFilter)), +b.minFilter!==THREE.NearestFilter&&b.minFilter!==THREE.LinearFilter&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.",b));!(c=S.get("EXT_texture_filter_anisotropic"))||b.type===THREE.FloatType&&null===S.get("OES_texture_float_linear")||b.type===THREE.HalfFloatType&&null===S.get("OES_texture_half_float_linear")||!(1b||a.height>b){var c=b/Math.max(a.width,a.height),d=document.createElement("canvas");d.width=Math.floor(a.width*c);d.height=Math.floor(a.height*c);d.getContext("2d").drawImage(a,0,0,a.width,a.height,0,0,d.width,d.height);console.warn("THREE.WebGLRenderer: image is too big ("+a.width+"x"+a.height+"). Resized to "+d.width+"x"+d.height,a);return d}return a}function y(a){return THREE.Math.isPowerOfTwo(a.width)&& +THREE.Math.isPowerOfTwo(a.height)}function z(a,b){var c=W.get(a);if(6===a.image.length)if(0h;h++)f[h]=!aa.autoScaleCubemaps|| +d||e?e?a.image[h].image:a.image[h]:B(a.image[h],ha.maxCubemapSize);var k=y(f[0]),l=N(a.format),n=N(a.type);x(r.TEXTURE_CUBE_MAP,a,k);for(h=0;6>h;h++)if(d)for(var m,q=f[h].mipmaps,p=0,s=q.length;pd;d++)c.__webglFramebuffer[d]=r.createFramebuffer(),c.__webglRenderbuffer[d]=r.createRenderbuffer(),I.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+d,0,g,a.width,a.height,0,g,h,null),J(c.__webglFramebuffer[d],a,r.TEXTURE_CUBE_MAP_POSITIVE_X+d),F(c.__webglRenderbuffer[d],a);a.texture.generateMipmaps&&e&&r.generateMipmap(r.TEXTURE_CUBE_MAP)}else c.__webglFramebuffer=r.createFramebuffer(),c.__webglRenderbuffer=a.shareDepthFrom?a.shareDepthFrom.__webglRenderbuffer: +r.createRenderbuffer(),I.bindTexture(r.TEXTURE_2D,d.__webglTexture),x(r.TEXTURE_2D,a.texture,e),I.texImage2D(r.TEXTURE_2D,0,g,a.width,a.height,0,g,h,null),J(c.__webglFramebuffer,a,r.TEXTURE_2D),a.shareDepthFrom?a.depthBuffer&&!a.stencilBuffer?r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,c.__webglRenderbuffer):a.depthBuffer&&a.stencilBuffer&&r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.RENDERBUFFER,c.__webglRenderbuffer):F(c.__webglRenderbuffer, +a),a.texture.generateMipmaps&&e&&r.generateMipmap(r.TEXTURE_2D);b?I.bindTexture(r.TEXTURE_CUBE_MAP,null):I.bindTexture(r.TEXTURE_2D,null);r.bindRenderbuffer(r.RENDERBUFFER,null);r.bindFramebuffer(r.FRAMEBUFFER,null)}a?(c=W.get(a),d=b?c.__webglFramebuffer[a.activeCubeFace]:c.__webglFramebuffer,c=a.width,e=a.height,h=g=0):(d=null,c=pa,e=qa,g=na,h=oa);d!==za&&(r.bindFramebuffer(r.FRAMEBUFFER,d),r.viewport(g,h,c,e),za=d);b&&(d=W.get(a.texture),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0, +r.TEXTURE_CUBE_MAP_POSITIVE_X+a.activeCubeFace,d.__webglTexture,0));Da=c;Ea=e};this.readRenderTargetPixels=function(a,b,c,d,e,f){if(!1===a instanceof THREE.WebGLRenderTarget)console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");else{var g=W.get(a).__webglFramebuffer;if(g){var h=!1;g!==za&&(r.bindFramebuffer(r.FRAMEBUFFER,g),h=!0);try{var k=a.texture;k.format!==THREE.RGBAFormat&&N(k.format)!==r.getParameter(r.IMPLEMENTATION_COLOR_READ_FORMAT)?console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format."): +k.type===THREE.UnsignedByteType||N(k.type)===r.getParameter(r.IMPLEMENTATION_COLOR_READ_TYPE)||k.type===THREE.FloatType&&S.get("WEBGL_color_buffer_float")||k.type===THREE.HalfFloatType&&S.get("EXT_color_buffer_half_float")?r.checkFramebufferStatus(r.FRAMEBUFFER)===r.FRAMEBUFFER_COMPLETE?r.readPixels(b,c,d,e,N(k.format),N(k.type),f):console.error("THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete."):console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.")}finally{h&& +r.bindFramebuffer(r.FRAMEBUFFER,za)}}}};this.supportsFloatTextures=function(){console.warn("THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( 'OES_texture_float' ).");return S.get("OES_texture_float")};this.supportsHalfFloatTextures=function(){console.warn("THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( 'OES_texture_half_float' ).");return S.get("OES_texture_half_float")};this.supportsStandardDerivatives=function(){console.warn("THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( 'OES_standard_derivatives' )."); +return S.get("OES_standard_derivatives")};this.supportsCompressedTextureS3TC=function(){console.warn("THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( 'WEBGL_compressed_texture_s3tc' ).");return S.get("WEBGL_compressed_texture_s3tc")};this.supportsCompressedTexturePVRTC=function(){console.warn("THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( 'WEBGL_compressed_texture_pvrtc' ).");return S.get("WEBGL_compressed_texture_pvrtc")};this.supportsBlendMinMax= +function(){console.warn("THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( 'EXT_blend_minmax' ).");return S.get("EXT_blend_minmax")};this.supportsVertexTextures=function(){return ha.vertexTextures};this.supportsInstancedArrays=function(){console.warn("THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( 'ANGLE_instanced_arrays' ).");return S.get("ANGLE_instanced_arrays")};this.initMaterial=function(){console.warn("THREE.WebGLRenderer: .initMaterial() has been removed.")}; +this.addPrePlugin=function(){console.warn("THREE.WebGLRenderer: .addPrePlugin() has been removed.")};this.addPostPlugin=function(){console.warn("THREE.WebGLRenderer: .addPostPlugin() has been removed.")};this.updateShadowMap=function(){console.warn("THREE.WebGLRenderer: .updateShadowMap() has been removed.")};Object.defineProperties(this,{shadowMapEnabled:{get:function(){return $.enabled},set:function(a){console.warn("THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.");$.enabled=a}}, +shadowMapType:{get:function(){return $.type},set:function(a){console.warn("THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.");$.type=a}},shadowMapCullFace:{get:function(){return $.cullFace},set:function(a){console.warn("THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.");$.cullFace=a}},shadowMapDebug:{get:function(){return $.debug},set:function(a){console.warn("THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.");$.debug=a}}})}; +THREE.WebGLRenderTarget=function(a,b,c){this.uuid=THREE.Math.generateUUID();this.width=a;this.height=b;c=c||{};void 0===c.minFilter&&(c.minFilter=THREE.LinearFilter);this.texture=new THREE.Texture(void 0,void 0,c.wrapS,c.wrapT,c.magFilter,c.minFilter,c.format,c.type,c.anisotropy);this.depthBuffer=void 0!==c.depthBuffer?c.depthBuffer:!0;this.stencilBuffer=void 0!==c.stencilBuffer?c.stencilBuffer:!0;this.shareDepthFrom=void 0!==c.shareDepthFrom?c.shareDepthFrom:null}; +THREE.WebGLRenderTarget.prototype={constructor:THREE.WebGLRenderTarget,get wrapS(){console.warn("THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.");return this.texture.wrapS},set wrapS(a){console.warn("THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.");this.texture.wrapS=a},get wrapT(){console.warn("THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.");return this.texture.wrapT},set wrapT(a){console.warn("THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.");this.texture.wrapT=a}, +get magFilter(){console.warn("THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.");return this.texture.magFilter},set magFilter(a){console.warn("THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.");this.texture.magFilter=a},get minFilter(){console.warn("THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.");return this.texture.minFilter},set minFilter(a){console.warn("THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.");this.texture.minFilter=a},get anisotropy(){console.warn("THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy."); +return this.texture.anisotropy},set anisotropy(a){console.warn("THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.");this.texture.anisotropy=a},get offset(){console.warn("THREE.WebGLRenderTarget: .offset is now .texture.offset.");return this.texture.offset},set offset(a){console.warn("THREE.WebGLRenderTarget: .offset is now .texture.offset.");this.texture.offset=a},get repeat(){console.warn("THREE.WebGLRenderTarget: .repeat is now .texture.repeat.");return this.texture.repeat},set repeat(a){console.warn("THREE.WebGLRenderTarget: .repeat is now .texture.repeat."); +this.texture.repeat=a},get format(){console.warn("THREE.WebGLRenderTarget: .format is now .texture.format.");return this.texture.format},set format(a){console.warn("THREE.WebGLRenderTarget: .format is now .texture.format.");this.texture.format=a},get type(){console.warn("THREE.WebGLRenderTarget: .type is now .texture.type.");return this.texture.type},set type(a){console.warn("THREE.WebGLRenderTarget: .type is now .texture.type.");this.texture.type=a},get generateMipmaps(){console.warn("THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps."); +return this.texture.generateMipmaps},set generateMipmaps(a){console.warn("THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.");this.texture.generateMipmaps=a},setSize:function(a,b){if(this.width!==a||this.height!==b)this.width=a,this.height=b,this.dispose()},clone:function(){return(new this.constructor).copy(this)},copy:function(a){this.width=a.width;this.height=a.height;this.texture=a.texture.clone();this.depthBuffer=a.depthBuffer;this.stencilBuffer=a.stencilBuffer;this.shareDepthFrom= +a.shareDepthFrom;return this},dispose:function(){this.dispatchEvent({type:"dispose"})}};THREE.EventDispatcher.prototype.apply(THREE.WebGLRenderTarget.prototype);THREE.WebGLRenderTargetCube=function(a,b,c){THREE.WebGLRenderTarget.call(this,a,b,c);this.activeCubeFace=0};THREE.WebGLRenderTargetCube.prototype=Object.create(THREE.WebGLRenderTarget.prototype);THREE.WebGLRenderTargetCube.prototype.constructor=THREE.WebGLRenderTargetCube; +THREE.WebGLBufferRenderer=function(a,b,c){var d;this.setMode=function(a){d=a};this.render=function(b,g){a.drawArrays(d,b,g);c.calls++;c.vertices+=g;d===a.TRIANGLES&&(c.faces+=g/3)};this.renderInstances=function(a){var c=b.get("ANGLE_instanced_arrays");if(null===c)console.error("THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.");else{var f=a.attributes.position;f instanceof THREE.InterleavedBufferAttribute?c.drawArraysInstancedANGLE(d, +0,f.data.count,a.maxInstancedCount):c.drawArraysInstancedANGLE(d,0,f.count,a.maxInstancedCount)}}}; +THREE.WebGLIndexedBufferRenderer=function(a,b,c){var d,e,g;this.setMode=function(a){d=a};this.setIndex=function(c){c.array instanceof Uint32Array&&b.get("OES_element_index_uint")?(e=a.UNSIGNED_INT,g=4):(e=a.UNSIGNED_SHORT,g=2)};this.render=function(b,h){a.drawElements(d,h,e,b*g);c.calls++;c.vertices+=h;d===a.TRIANGLES&&(c.faces+=h/3)};this.renderInstances=function(a){var c=b.get("ANGLE_instanced_arrays");null===c?console.error("THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays."): +c.drawElementsInstancedANGLE(d,a.index.array.length,e,0,a.maxInstancedCount)}}; +THREE.WebGLExtensions=function(a){var b={};this.get=function(c){if(void 0!==b[c])return b[c];var d;switch(c){case "EXT_texture_filter_anisotropic":d=a.getExtension("EXT_texture_filter_anisotropic")||a.getExtension("MOZ_EXT_texture_filter_anisotropic")||a.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case "WEBGL_compressed_texture_s3tc":d=a.getExtension("WEBGL_compressed_texture_s3tc")||a.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||a.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"); +break;case "WEBGL_compressed_texture_pvrtc":d=a.getExtension("WEBGL_compressed_texture_pvrtc")||a.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:d=a.getExtension(c)}null===d&&console.warn("THREE.WebGLRenderer: "+c+" extension not supported.");return b[c]=d}}; +THREE.WebGLCapabilities=function(a,b,c){function d(b){if("highp"===b){if(0c){var d=b;b=c;c=d}d=a[b];return void 0===d?(a[b]=[c],!0):-1===d.indexOf(c)?(d.push(c),!0):!1}var g=new THREE.WebGLGeometries(a,b,c);this.getAttributeBuffer=function(a){return a instanceof THREE.InterleavedBufferAttribute?b.get(a.data).__webglBuffer:b.get(a).__webglBuffer};this.getWireframeAttribute= +function(c){var g=b.get(c);if(void 0!==g.wireframe)return g.wireframe;var l=[],k=c.index,m=c.attributes;c=m.position;if(null!==k)for(var m={},k=k.array,p=0,n=k.length;p 0 ) {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat fogFactor = 0.0;\nif ( fogType == 1 ) {\nfogFactor = smoothstep( fogNear, fogFar, depth );\n} else {\nconst float LOG2 = 1.442695;\nfogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n}\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n}\n}"].join("\n")); +x.compileShader(K);x.compileShader(E);x.attachShader(M,K);x.attachShader(M,E);x.linkProgram(M);A=M;u=x.getAttribLocation(A,"position");w=x.getAttribLocation(A,"uv");c=x.getUniformLocation(A,"uvOffset");d=x.getUniformLocation(A,"uvScale");e=x.getUniformLocation(A,"rotation");g=x.getUniformLocation(A,"scale");f=x.getUniformLocation(A,"color");h=x.getUniformLocation(A,"map");l=x.getUniformLocation(A,"opacity");k=x.getUniformLocation(A,"modelViewMatrix");m=x.getUniformLocation(A,"projectionMatrix");p= +x.getUniformLocation(A,"fogType");n=x.getUniformLocation(A,"fogDensity");q=x.getUniformLocation(A,"fogNear");s=x.getUniformLocation(A,"fogFar");t=x.getUniformLocation(A,"fogColor");v=x.getUniformLocation(A,"alphaTest");M=document.createElement("canvas");M.width=8;M.height=8;K=M.getContext("2d");K.fillStyle="white";K.fillRect(0,0,8,8);J=new THREE.Texture(M);J.needsUpdate=!0}x.useProgram(A);B.initAttributes();B.enableAttribute(u);B.enableAttribute(w);B.disableUnusedAttributes();B.disable(x.CULL_FACE); +B.enable(x.BLEND);x.bindBuffer(x.ARRAY_BUFFER,y);x.vertexAttribPointer(u,2,x.FLOAT,!1,16,0);x.vertexAttribPointer(w,2,x.FLOAT,!1,16,8);x.bindBuffer(x.ELEMENT_ARRAY_BUFFER,z);x.uniformMatrix4fv(m,!1,Q.projectionMatrix.elements);B.activeTexture(x.TEXTURE0);x.uniform1i(h,0);K=M=0;(E=L.fog)?(x.uniform3f(t,E.color.r,E.color.g,E.color.b),E instanceof THREE.Fog?(x.uniform1f(q,E.near),x.uniform1f(s,E.far),x.uniform1i(p,1),K=M=1):E instanceof THREE.FogExp2&&(x.uniform1f(n,E.density),x.uniform1i(p,2),K=M=2)): +(x.uniform1i(p,0),K=M=0);for(var E=0,O=b.length;Ec)return null;var d=[],e=[],g=[],f,h,l;if(0=k--){console.warn("THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()");break}f=h;c<=f&&(f=0);h=f+1;c<=h&&(h=0);l=h+1;c<=l&&(l=0);var m;a:{var p= +m=void 0,n=void 0,q=void 0,s=void 0,t=void 0,v=void 0,u=void 0,w=void 0,p=a[e[f]].x,n=a[e[f]].y,q=a[e[h]].x,s=a[e[h]].y,t=a[e[l]].x,v=a[e[l]].y;if(Number.EPSILON>(q-p)*(v-n)-(s-n)*(t-p))m=!1;else{var D=void 0,x=void 0,B=void 0,y=void 0,z=void 0,A=void 0,J=void 0,F=void 0,C=void 0,N=void 0,C=F=J=w=u=void 0,D=t-q,x=v-s,B=p-t,y=n-v,z=q-p,A=s-n;for(m=0;m=-Number.EPSILON&& +F>=-Number.EPSILON&&J>=-Number.EPSILON)){m=!1;break a}m=!0}}if(m){d.push([a[e[f]],a[e[h]],a[e[l]]]);g.push([e[f],e[h],e[l]]);f=h;for(l=h+1;lNumber.EPSILON){if(0A||A> +z)return[];k=l*m-k*p;if(0>k||k>z)return[]}else{if(0d?[]:k===d?f?[]:[g]:a<=d?[g,h]:[g,l]}function e(a,b,c,d){var e=b.x-a.x,f=b.y-a.y;b=c.x-a.x;c=c.y-a.y;var g=d.x-a.x;d=d.y-a.y;a=e*c-f*b;e=e*d-f*g;return Math.abs(a)>Number.EPSILON?(b=g*c-d*b,0f&&(f=d);var g=a+1;g>d&&(g=0);d=e(h[a],h[f],h[g],k[b]);if(!d)return!1;d=k.length-1;f=b-1;0>f&&(f=d);g=b+1;g>d&&(g=0);return(d=e(k[b],k[f],k[g],h[a]))?!0:!1}function f(a,b){var c,e;for(c=0;cQ){console.log("Infinite Loop! Holes left:"+l.length+", Probably Hole outside Shape!");break}for(p=F;ph;h++)k=l[h].x+":"+l[h].y,k=m[k],void 0!==k&&(l[h]=k);return p.concat()},isClockWise:function(a){return 0>THREE.ShapeUtils.area(a)},b2:function(){return function(a,b,c,d){var e=1-a;return e*e*b+2*(1-a)*a*c+a*a*d}}(),b3:function(){return function(a,b,c,d,e){var g= +1-a,f=1-a;return g*g*g*b+3*f*f*a*c+3*(1-a)*a*a*d+a*a*a*e}}()};THREE.Audio=function(a){THREE.Object3D.call(this);this.type="Audio";this.context=a.context;this.source=this.context.createBufferSource();this.source.onended=this.onEnded.bind(this);this.gain=this.context.createGain();this.gain.connect(this.context.destination);this.panner=this.context.createPanner();this.panner.connect(this.gain);this.autoplay=!1;this.startTime=0;this.playbackRate=1;this.isPlaying=!1};THREE.Audio.prototype=Object.create(THREE.Object3D.prototype); +THREE.Audio.prototype.constructor=THREE.Audio;THREE.Audio.prototype.load=function(a){var b=this,c=new XMLHttpRequest;c.open("GET",a,!0);c.responseType="arraybuffer";c.onload=function(a){b.context.decodeAudioData(this.response,function(a){b.source.buffer=a;b.autoplay&&b.play()})};c.send();return this}; +THREE.Audio.prototype.play=function(){if(!0===this.isPlaying)console.warn("THREE.Audio: Audio is already playing.");else{var a=this.context.createBufferSource();a.buffer=this.source.buffer;a.loop=this.source.loop;a.onended=this.source.onended;a.start(0,this.startTime);a.playbackRate.value=this.playbackRate;this.isPlaying=!0;this.source=a;this.connect()}};THREE.Audio.prototype.pause=function(){this.source.stop();this.startTime=this.context.currentTime}; +THREE.Audio.prototype.stop=function(){this.source.stop();this.startTime=0};THREE.Audio.prototype.connect=function(){void 0!==this.filter?(this.source.connect(this.filter),this.filter.connect(this.panner)):this.source.connect(this.panner)};THREE.Audio.prototype.disconnect=function(){void 0!==this.filter?(this.source.disconnect(this.filter),this.filter.disconnect(this.panner)):this.source.disconnect(this.panner)}; +THREE.Audio.prototype.setFilter=function(a){!0===this.isPlaying?(this.disconnect(),this.filter=a,this.connect()):this.filter=a};THREE.Audio.prototype.getFilter=function(){return this.filter};THREE.Audio.prototype.setPlaybackRate=function(a){this.playbackRate=a;!0===this.isPlaying&&(this.source.playbackRate.value=this.playbackRate)};THREE.Audio.prototype.getPlaybackRate=function(){return this.playbackRate};THREE.Audio.prototype.onEnded=function(){this.isPlaying=!1}; +THREE.Audio.prototype.setLoop=function(a){this.source.loop=a};THREE.Audio.prototype.getLoop=function(){return this.source.loop};THREE.Audio.prototype.setRefDistance=function(a){this.panner.refDistance=a};THREE.Audio.prototype.getRefDistance=function(){return this.panner.refDistance};THREE.Audio.prototype.setRolloffFactor=function(a){this.panner.rolloffFactor=a};THREE.Audio.prototype.getRolloffFactor=function(){return this.panner.rolloffFactor}; +THREE.Audio.prototype.setVolume=function(a){this.gain.gain.value=a};THREE.Audio.prototype.getVolume=function(){return this.gain.gain.value};THREE.Audio.prototype.updateMatrixWorld=function(){var a=new THREE.Vector3;return function(b){THREE.Object3D.prototype.updateMatrixWorld.call(this,b);a.setFromMatrixPosition(this.matrixWorld);this.panner.setPosition(a.x,a.y,a.z)}}();THREE.AudioListener=function(){THREE.Object3D.call(this);this.type="AudioListener";this.context=new (window.AudioContext||window.webkitAudioContext)}; +THREE.AudioListener.prototype=Object.create(THREE.Object3D.prototype);THREE.AudioListener.prototype.constructor=THREE.AudioListener; +THREE.AudioListener.prototype.updateMatrixWorld=function(){var a=new THREE.Vector3,b=new THREE.Quaternion,c=new THREE.Vector3,d=new THREE.Vector3;return function(e){THREE.Object3D.prototype.updateMatrixWorld.call(this,e);e=this.context.listener;var g=this.up;this.matrixWorld.decompose(a,b,c);d.set(0,0,-1).applyQuaternion(b);e.setPosition(a.x,a.y,a.z);e.setOrientation(d.x,d.y,d.z,g.x,g.y,g.z)}}();THREE.Curve=function(){}; +THREE.Curve.prototype={constructor:THREE.Curve,getPoint:function(a){console.warn("THREE.Curve: Warning, getPoint() not implemented!");return null},getPointAt:function(a){a=this.getUtoTmapping(a);return this.getPoint(a)},getPoints:function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPoint(b/a));return c},getSpacedPoints:function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPointAt(b/a));return c},getLength:function(){var a=this.getLengths();return a[a.length-1]},getLengths:function(a){a|| +(a=this.__arcLengthDivisions?this.__arcLengthDivisions:200);if(this.cacheArcLengths&&this.cacheArcLengths.length===a+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var b=[],c,d=this.getPoint(0),e,g=0;b.push(0);for(e=1;e<=a;e++)c=this.getPoint(e/a),g+=c.distanceTo(d),b.push(g),d=c;return this.cacheArcLengths=b},updateArcLengths:function(){this.needsUpdate=!0;this.getLengths()},getUtoTmapping:function(a,b){var c=this.getLengths(),d=0,e=c.length,g;g=b?b:a*c[e-1];for(var f=0,h=e- +1,l;f<=h;)if(d=Math.floor(f+(h-f)/2),l=c[d]-g,0>l)f=d+1;else if(0b&&(b=0);1=b)return a=this.curves[d],b=1-(c[d]-b)/a.getLength(),a.getPointAt(b);d++}return null};THREE.CurvePath.prototype.getLength=function(){var a=this.getCurveLengths();return a[a.length-1]}; +THREE.CurvePath.prototype.getCurveLengths=function(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;for(var a=[],b=0,c=0,d=this.curves.length;cNumber.EPSILON){if(0>l&&(g=b[f],k=-k,h=b[e],l=-l),!(a.yh.y))if(a.y===g.y){if(a.x===g.x)return!0}else{e=l*(a.x-g.x)-k*(a.y-g.y);if(0===e)return!0;0>e||(d=!d)}}else if(a.y===g.y&&(h.x<=a.x&&a.x<=g.x|| +g.x<=a.x&&a.x<=h.x))return!0}return d}var e=THREE.ShapeUtils.isClockWise,g=function(a){for(var b=[],c=new THREE.Path,d=0,e=a.length;db.length-2?b.length-1:c+1],b=b[c>b.length-3?b.length-1:c+2],c=THREE.CurveUtils.interpolate;return new THREE.Vector2(c(d.x,e.x,g.x,b.x,a),c(d.y,e.y,g.y,b.y,a))};THREE.EllipseCurve=function(a,b,c,d,e,g,f,h){this.aX=a;this.aY=b;this.xRadius=c;this.yRadius=d;this.aStartAngle=e;this.aEndAngle=g;this.aClockwise=f;this.aRotation=h||0};THREE.EllipseCurve.prototype=Object.create(THREE.Curve.prototype); +THREE.EllipseCurve.prototype.constructor=THREE.EllipseCurve; +THREE.EllipseCurve.prototype.getPoint=function(a){var b=this.aEndAngle-this.aStartAngle;0>b&&(b+=2*Math.PI);b>2*Math.PI&&(b-=2*Math.PI);b=!0===this.aClockwise?this.aEndAngle+(1-a)*(2*Math.PI-b):this.aStartAngle+a*b;a=this.aX+this.xRadius*Math.cos(b);var c=this.aY+this.yRadius*Math.sin(b);if(0!==this.aRotation){var b=Math.cos(this.aRotation),d=Math.sin(this.aRotation),e=a;a=(e-this.aX)*b-(c-this.aY)*d+this.aX;c=(e-this.aX)*d+(c-this.aY)*b+this.aY}return new THREE.Vector2(a,c)}; +THREE.ArcCurve=function(a,b,c,d,e,g){THREE.EllipseCurve.call(this,a,b,c,c,d,e,g)};THREE.ArcCurve.prototype=Object.create(THREE.EllipseCurve.prototype);THREE.ArcCurve.prototype.constructor=THREE.ArcCurve;THREE.LineCurve3=THREE.Curve.create(function(a,b){this.v1=a;this.v2=b},function(a){var b=new THREE.Vector3;b.subVectors(this.v2,this.v1);b.multiplyScalar(a);b.add(this.v1);return b}); +THREE.QuadraticBezierCurve3=THREE.Curve.create(function(a,b,c){this.v0=a;this.v1=b;this.v2=c},function(a){var b=THREE.ShapeUtils.b2;return new THREE.Vector3(b(a,this.v0.x,this.v1.x,this.v2.x),b(a,this.v0.y,this.v1.y,this.v2.y),b(a,this.v0.z,this.v1.z,this.v2.z))}); +THREE.CubicBezierCurve3=THREE.Curve.create(function(a,b,c,d){this.v0=a;this.v1=b;this.v2=c;this.v3=d},function(a){var b=THREE.ShapeUtils.b3;return new THREE.Vector3(b(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x),b(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y),b(a,this.v0.z,this.v1.z,this.v2.z,this.v3.z))}); +THREE.SplineCurve3=THREE.Curve.create(function(a){console.warn("THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3");this.points=void 0==a?[]:a},function(a){var b=this.points;a*=b.length-1;var c=Math.floor(a);a-=c;var d=b[0==c?c:c-1],e=b[c],g=b[c>b.length-2?b.length-1:c+1],b=b[c>b.length-3?b.length-1:c+2],c=THREE.CurveUtils.interpolate;return new THREE.Vector3(c(d.x,e.x,g.x,b.x,a),c(d.y,e.y,g.y,b.y,a),c(d.z,e.z,g.z,b.z,a))}); +THREE.CatmullRomCurve3=function(){function a(){}var b=new THREE.Vector3,c=new a,d=new a,e=new a;a.prototype.init=function(a,b,c,d){this.c0=a;this.c1=c;this.c2=-3*a+3*b-2*c-d;this.c3=2*a-2*b+c+d};a.prototype.initNonuniformCatmullRom=function(a,b,c,d,e,m,p){a=((b-a)/e-(c-a)/(e+m)+(c-b)/m)*m;d=((c-b)/m-(d-b)/(m+p)+(d-c)/p)*m;this.init(b,c,a,d)};a.prototype.initCatmullRom=function(a,b,c,d,e){this.init(b,c,e*(c-a),e*(d-b))};a.prototype.calc=function(a){var b=a*a;return this.c0+this.c1*a+this.c2*b+this.c3* +b*a};return THREE.Curve.create(function(a){this.points=a||[]},function(a){var f=this.points,h,l;l=f.length;2>l&&console.log("duh, you need at least 2 points");a*=l-1;h=Math.floor(a);a-=h;0===a&&h===l-1&&(h=l-2,a=1);var k,m,p;0===h?(b.subVectors(f[0],f[1]).add(f[0]),k=b):k=f[h-1];m=f[h];p=f[h+1];h+2h&&(h=1);1E-4>l&&(l=h);1E-4>n&&(n=h);c.initNonuniformCatmullRom(k.x,m.x,p.x,f.x,l,h,n);d.initNonuniformCatmullRom(k.y,m.y,p.y,f.y,l,h,n);e.initNonuniformCatmullRom(k.z,m.z,p.z,f.z,l,h,n)}else"catmullrom"===this.type&&(l=void 0!==this.tension?this.tension:.5,c.initCatmullRom(k.x,m.x,p.x,f.x,l),d.initCatmullRom(k.y,m.y,p.y,f.y,l),e.initCatmullRom(k.z,m.z,p.z,f.z,l));return new THREE.Vector3(c.calc(a),d.calc(a),e.calc(a))})}(); +THREE.ClosedSplineCurve3=THREE.Curve.create(function(a){this.points=void 0==a?[]:a},function(a){var b=this.points;a*=b.length-0;var c=Math.floor(a);a-=c;var c=c+(0n;n++){e[0]=p[f[n]];e[1]=p[f[(n+1)%3]];e.sort(c);var q=e.toString();void 0===g[q]?g[q]={vert1:e[0],vert2:e[1],face1:k, +face2:void 0}:g[q].face2=k}e=[];for(q in g)if(f=g[q],void 0===f.face2||h[f.face1].normal.dot(h[f.face2].normal)<=d)k=l[f.vert1],e.push(k.x),e.push(k.y),e.push(k.z),k=l[f.vert2],e.push(k.x),e.push(k.y),e.push(k.z);this.addAttribute("position",new THREE.BufferAttribute(new Float32Array(e),3))};THREE.EdgesGeometry.prototype=Object.create(THREE.BufferGeometry.prototype);THREE.EdgesGeometry.prototype.constructor=THREE.EdgesGeometry; +THREE.ExtrudeGeometry=function(a,b){"undefined"!==typeof a&&(THREE.Geometry.call(this),this.type="ExtrudeGeometry",a=Array.isArray(a)?a:[a],this.addShapeList(a,b),this.computeFaceNormals())};THREE.ExtrudeGeometry.prototype=Object.create(THREE.Geometry.prototype);THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;THREE.ExtrudeGeometry.prototype.addShapeList=function(a,b){for(var c=a.length,d=0;dNumber.EPSILON){var k=Math.sqrt(h),l=Math.sqrt(f*f+g*g),h=b.x-e/k;b=b.y+d/k;f=((c.x-g/l-h)*g-(c.y+f/l-b)*f)/(d*g-e*f);c=h+d*f-a.x;a=b+e*f-a.y;d=c*c+a*a;if(2>=d)return new THREE.Vector2(c,a);d=Math.sqrt(d/2)}else a=!1,d>Number.EPSILON? +f>Number.EPSILON&&(a=!0):d<-Number.EPSILON?f<-Number.EPSILON&&(a=!0):Math.sign(e)===Math.sign(g)&&(a=!0),a?(c=-e,a=d,d=Math.sqrt(h)):(c=d,a=e,d=Math.sqrt(h/2));return new THREE.Vector2(c/d,a/d)}function e(a,b){var c,d;for(G=a.length;0<=--G;){c=G;d=G-1;0>d&&(d=a.length-1);for(var e=0,f=q+2*m,e=0;eMath.abs(b.y-c.y)?[new THREE.Vector2(b.x,1-b.z),new THREE.Vector2(c.x,1-c.z),new THREE.Vector2(d.x,1-d.z),new THREE.Vector2(e.x,1-e.z)]:[new THREE.Vector2(b.y,1-b.z),new THREE.Vector2(c.y,1-c.z),new THREE.Vector2(d.y, +1-d.z),new THREE.Vector2(e.y,1-e.z)]}};THREE.ShapeGeometry=function(a,b){THREE.Geometry.call(this);this.type="ShapeGeometry";!1===Array.isArray(a)&&(a=[a]);this.addShapeList(a,b);this.computeFaceNormals()};THREE.ShapeGeometry.prototype=Object.create(THREE.Geometry.prototype);THREE.ShapeGeometry.prototype.constructor=THREE.ShapeGeometry;THREE.ShapeGeometry.prototype.addShapeList=function(a,b){for(var c=0,d=a.length;cNumber.EPSILON&&(h.normalize(),d=Math.acos(THREE.Math.clamp(e[k-1].dot(e[k]),-1,1)),g[k].applyMatrix4(l.makeRotationAxis(h,d))),f[k].crossVectors(e[k],g[k]);if(c)for(d=Math.acos(THREE.Math.clamp(g[0].dot(g[b-1]),-1,1)),d/=b-1,0c&&1===a.x&&(a=new THREE.Vector2(a.x-1,a.y));0===b.x&&0===b.z&&(a=new THREE.Vector2(c/ +2/Math.PI+.5,a.y));return a.clone()}THREE.Geometry.call(this);this.type="PolyhedronGeometry";this.parameters={vertices:a,indices:b,radius:c,detail:d};c=c||1;d=d||0;for(var l=this,k=0,m=a.length;kq&&(.2>d&&(b[0].x+=1),.2>a&&(b[1].x+=1),.2>p&&(b[2].x+=1));k=0;for(m=this.vertices.length;kp;p++){c[0]=m[e[p]];c[1]=m[e[(p+1)%3]];c.sort(b);var n=c.toString();void 0===d[n]&&(l[2*h]=c[0],l[2*h+1]=c[1],d[n]=!0,h++)}c=new Float32Array(6*h);a=0;for(k=h;ap;p++)d=g[l[2*a+p]],h=6*a+3*p,c[h+0]=d.x,c[h+1]=d.y, +c[h+2]=d.z;this.addAttribute("position",new THREE.BufferAttribute(c,3))}else if(a instanceof THREE.BufferGeometry){if(null!==a.index){k=a.index.array;g=a.attributes.position;e=a.drawcalls;h=0;0===e.length&&a.addGroup(0,k.length);l=new Uint32Array(2*k.length);f=0;for(m=e.length;fp;p++)c[0]=k[a+p],c[1]=k[a+(p+1)%3],c.sort(b),n=c.toString(),void 0===d[n]&&(l[2*h]=c[0],l[2*h+1]=c[1],d[n]=!0,h++)}c=new Float32Array(6*h);a=0;for(k= +h;ap;p++)h=6*a+3*p,d=l[2*a+p],c[h+0]=g.getX(d),c[h+1]=g.getY(d),c[h+2]=g.getZ(d)}else for(g=a.attributes.position.array,h=g.length/3,l=h/3,c=new Float32Array(6*h),a=0,k=l;ap;p++)h=18*a+6*p,l=9*a+3*p,c[h+0]=g[l],c[h+1]=g[l+1],c[h+2]=g[l+2],d=9*a+(p+1)%3*3,c[h+3]=g[d],c[h+4]=g[d+1],c[h+5]=g[d+2];this.addAttribute("position",new THREE.BufferAttribute(c,3))}};THREE.WireframeGeometry.prototype=Object.create(THREE.BufferGeometry.prototype); +THREE.WireframeGeometry.prototype.constructor=THREE.WireframeGeometry;THREE.AxisHelper=function(a){a=a||1;var b=new Float32Array([0,0,0,a,0,0,0,0,0,0,a,0,0,0,0,0,0,a]),c=new Float32Array([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1]);a=new THREE.BufferGeometry;a.addAttribute("position",new THREE.BufferAttribute(b,3));a.addAttribute("color",new THREE.BufferAttribute(c,3));b=new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors});THREE.LineSegments.call(this,a,b)};THREE.AxisHelper.prototype=Object.create(THREE.LineSegments.prototype); +THREE.AxisHelper.prototype.constructor=THREE.AxisHelper; +THREE.ArrowHelper=function(){var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(0,0,0),new THREE.Vector3(0,1,0));var b=new THREE.CylinderGeometry(0,.5,1,5,1);b.translate(0,-.5,0);return function(c,d,e,g,f,h){THREE.Object3D.call(this);void 0===g&&(g=16776960);void 0===e&&(e=1);void 0===f&&(f=.2*e);void 0===h&&(h=.2*f);this.position.copy(d);fc.y?this.quaternion.set(1,0,0,0):(a.set(c.z,0,-c.x).normalize(),b=Math.acos(c.y),this.quaternion.setFromAxisAngle(a,b))}}(); +THREE.ArrowHelper.prototype.setLength=function(a,b,c){void 0===b&&(b=.2*a);void 0===c&&(c=.2*b);bd;d++)c.faces[d].color=this.colors[4>d?0:1];d=new THREE.MeshBasicMaterial({vertexColors:THREE.FaceColors,wireframe:!0});this.lightSphere=new THREE.Mesh(c,d);this.add(this.lightSphere);this.update()}; +THREE.HemisphereLightHelper.prototype=Object.create(THREE.Object3D.prototype);THREE.HemisphereLightHelper.prototype.constructor=THREE.HemisphereLightHelper;THREE.HemisphereLightHelper.prototype.dispose=function(){this.lightSphere.geometry.dispose();this.lightSphere.material.dispose()}; +THREE.HemisphereLightHelper.prototype.update=function(){var a=new THREE.Vector3;return function(){this.colors[0].copy(this.light.color).multiplyScalar(this.light.intensity);this.colors[1].copy(this.light.groundColor).multiplyScalar(this.light.intensity);this.lightSphere.lookAt(a.setFromMatrixPosition(this.light.matrixWorld).negate());this.lightSphere.geometry.colorsNeedUpdate=!0}}(); +THREE.PointLightHelper=function(a,b){this.light=a;this.light.updateMatrixWorld();var c=new THREE.SphereGeometry(b,4,2),d=new THREE.MeshBasicMaterial({wireframe:!0,fog:!1});d.color.copy(this.light.color).multiplyScalar(this.light.intensity);THREE.Mesh.call(this,c,d);this.matrix=this.light.matrixWorld;this.matrixAutoUpdate=!1};THREE.PointLightHelper.prototype=Object.create(THREE.Mesh.prototype);THREE.PointLightHelper.prototype.constructor=THREE.PointLightHelper; +THREE.PointLightHelper.prototype.dispose=function(){this.geometry.dispose();this.material.dispose()};THREE.PointLightHelper.prototype.update=function(){this.material.color.copy(this.light.color).multiplyScalar(this.light.intensity)}; +THREE.SkeletonHelper=function(a){this.bones=this.getBoneList(a);for(var b=new THREE.Geometry,c=0;ch.end&&(h.end=g);c||(c=l)}}for(l in d)h=d[l],this.createAnimation(l,h.start,h.end,a);this.firstAnimation=c}; +THREE.MorphBlendMesh.prototype.setAnimationDirectionForward=function(a){if(a=this.animationsMap[a])a.direction=1,a.directionBackwards=!1};THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward=function(a){if(a=this.animationsMap[a])a.direction=-1,a.directionBackwards=!0};THREE.MorphBlendMesh.prototype.setAnimationFPS=function(a,b){var c=this.animationsMap[a];c&&(c.fps=b,c.duration=(c.end-c.start)/c.fps)}; +THREE.MorphBlendMesh.prototype.setAnimationDuration=function(a,b){var c=this.animationsMap[a];c&&(c.duration=b,c.fps=(c.end-c.start)/c.duration)};THREE.MorphBlendMesh.prototype.setAnimationWeight=function(a,b){var c=this.animationsMap[a];c&&(c.weight=b)};THREE.MorphBlendMesh.prototype.setAnimationTime=function(a,b){var c=this.animationsMap[a];c&&(c.time=b)};THREE.MorphBlendMesh.prototype.getAnimationTime=function(a){var b=0;if(a=this.animationsMap[a])b=a.time;return b}; +THREE.MorphBlendMesh.prototype.getAnimationDuration=function(a){var b=-1;if(a=this.animationsMap[a])b=a.duration;return b};THREE.MorphBlendMesh.prototype.playAnimation=function(a){var b=this.animationsMap[a];b?(b.time=0,b.active=!0):console.warn("THREE.MorphBlendMesh: animation["+a+"] undefined in .playAnimation()")};THREE.MorphBlendMesh.prototype.stopAnimation=function(a){if(a=this.animationsMap[a])a.active=!1}; +THREE.MorphBlendMesh.prototype.update=function(a){for(var b=0,c=this.animationsList.length;bd.duration||0>d.time)d.direction*=-1,d.time>d.duration&&(d.time=d.duration,d.directionBackwards=!0),0>d.time&&(d.time=0,d.directionBackwards=!1)}else d.time%=d.duration,0>d.time&&(d.time+=d.duration);var g=d.start+THREE.Math.clamp(Math.floor(d.time/e),0,d.length-1),f=d.weight;g!==d.currentFrame&& +(this.morphTargetInfluences[d.lastFrame]=0,this.morphTargetInfluences[d.currentFrame]=1*f,this.morphTargetInfluences[g]=0,d.lastFrame=d.currentFrame,d.currentFrame=g);e=d.time%e/e;d.directionBackwards&&(e=1-e);d.currentFrame!==d.lastFrame?(this.morphTargetInfluences[d.currentFrame]=e*f,this.morphTargetInfluences[d.lastFrame]=(1-e)*f):this.morphTargetInfluences[d.currentFrame]=f}}}; diff --git a/main.css b/main.css new file mode 100644 index 0000000..b54ad30 --- /dev/null +++ b/main.css @@ -0,0 +1,50 @@ +#svg *, .svg * { + -moz-user-select: none; + -webkit-user-select: none; + -khtml-user-select: none; + -o-user-select: none; + user-select: none; +} + +#waitform { + position: absolute; + width: 100%; + height: 100%; + z-index: 10000; + cursor: wait; +} + +a { + color: gray; +} + +em { + border: 1px rgba(0, 0, 0, 0.2) solid; + font-style: normal; + padding: 0px 3px; + background-color: rgba(0, 0, 0, 0.08); + border-radius: 3px; +} + +body { + font-family: Georgia; +} + +h6 { + font-size: 100%; + font-weight: normal; + margin: 0px; +} + +p { + font-size: 80%; + margin-top: 5px; + margin-bottom: 0px; +} + +.control_panel { + padding: 15px; + padding-bottom: 0px; + position: absolute; + z-index: 10; +} \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..fd06422 --- /dev/null +++ b/main.js @@ -0,0 +1,114 @@ +"use strict"; + +function dice_initialize(container) { + $t.remove($t.id('loading_text')); + + var canvas = $t.id('canvas'); + canvas.style.width = window.innerWidth - 1 + 'px'; + canvas.style.height = window.innerHeight - 1 + 'px'; + var label = $t.id('label'); + var set = $t.id('set'); + var selector_div = $t.id('selector_div'); + var info_div = $t.id('info_div'); + on_set_change(); + + $t.dice.use_true_random = false; + + function on_set_change(ev) { set.style.width = set.value.length + 3 + 'ex'; } + $t.bind(set, 'keyup', on_set_change); + $t.bind(set, 'mousedown', function(ev) { ev.stopPropagation(); }); + $t.bind(set, 'mouseup', function(ev) { ev.stopPropagation(); }); + $t.bind(set, 'focus', function(ev) { $t.set(container, { class: '' }); }); + $t.bind(set, 'blur', function(ev) { $t.set(container, { class: 'noselect' }); }); + + $t.bind($t.id('clear'), ['mouseup', 'touchend'], function(ev) { + ev.stopPropagation(); + set.value = '0'; + on_set_change(); + }); + + var params = $t.get_url_params(); + + if (params.chromakey) { + $t.dice.desk_color = 0x00ff00; + info_div.style.display = 'none'; + $t.id('control_panel').style.display = 'none'; + } + if (params.shadows == 0) { + $t.dice.use_shadows = false; + } + if (params.color == 'white') { + $t.dice.dice_color = '#808080'; + $t.dice.label_color = '#202020'; + } + + var box = new $t.dice.dice_box(canvas, { w: 500, h: 300 }); + box.animate_selector = false; + + $t.bind(window, 'resize', function() { + canvas.style.width = window.innerWidth - 1 + 'px'; + canvas.style.height = window.innerHeight - 1 + 'px'; + box.reinit(canvas, { w: 500, h: 300 }); + }); + + function show_selector() { + info_div.style.display = 'none'; + selector_div.style.display = 'inline-block'; + box.draw_selector(); + } + + function before_roll(vectors, notation, callback) { + info_div.style.display = 'none'; + selector_div.style.display = 'none'; + // do here rpc call or whatever to get your own result of throw. + // then callback with array of your result, example: + // callback([2, 2, 2, 2]); // for 4d6 where all dice values are 2. + callback(); + } + + function notation_getter() { + return $t.dice.parse_notation(set.value); + } + + function after_roll(notation, result) { + if (params.chromakey || params.noresult) return; + var res = result.join(' '); + if (notation.constant) { + if (notation.constant > 0) res += ' +' + notation.constant; + else res += ' -' + Math.abs(notation.constant); + } + if (result.length > 1) res += ' = ' + + (result.reduce(function(s, a) { return s + a; }) + notation.constant); + label.innerHTML = res; + info_div.style.display = 'inline-block'; + } + + box.bind_mouse(container, notation_getter, before_roll, after_roll); + box.bind_throw($t.id('throw'), notation_getter, before_roll, after_roll); + + $t.bind(container, ['mouseup', 'touchend'], function(ev) { + ev.stopPropagation(); + if (selector_div.style.display == 'none') { + if (!box.rolling) show_selector(); + box.rolling = false; + return; + } + var name = box.search_dice_by_mouse(ev); + if (name != undefined) { + var notation = $t.dice.parse_notation(set.value); + notation.set.push(name); + set.value = $t.dice.stringify_notation(notation); + on_set_change(); + } + }); + + if (params.notation) { + set.value = params.notation; + } + if (params.roll) { + $t.raise_event($t.id('throw'), 'mouseup'); + } + else { + show_selector(); + } +} diff --git a/teal.js b/teal.js new file mode 100644 index 0000000..5dccca3 --- /dev/null +++ b/teal.js @@ -0,0 +1,223 @@ +"use strict"; + +window.teal = {}; +window.$t = window.teal; + +teal.copyto = function(obj, res) { + if (obj == null || typeof obj !== 'object') return obj; + if (obj instanceof Array) { + for (var i = obj.length - 1; i >= 0; --i) + res[i] = $t.copy(obj[i]); + } + else { + for (var i in obj) { + if (obj.hasOwnProperty(i)) + res[i] = $t.copy(obj[i]); + } + } + return res; +} + +teal.copy = function(obj) { + if (!obj) return obj; + return teal.copyto(obj, new obj.constructor()); +} + +teal.element = function(name, props, place, content) { + var dom = document.createElement(name); + if (props) for (var i in props) dom.setAttribute(i, props[i]); + if (place) place.appendChild(dom); + if (content !== undefined) $t.inner(content, dom); + return dom; +} + +teal.inner = function(obj, sel) { + sel.appendChild(obj.nodeName != undefined ? obj : document.createTextNode(obj)); + return sel; +} + +teal.id = function(id) { + return document.getElementById(id); +} + +teal.set = function(sel, props) { + for (var i in props) sel.setAttribute(i, props[i]); + return sel; +} + +teal.clas = function(sel, oldclass, newclass) { + var oc = oldclass ? oldclass.split(/\s+/) : [], + nc = newclass ? newclass.split(/\s+/) : [], + classes = (sel.getAttribute('class') || '').split(/\s+/); + if (!classes[0]) classes = []; + for (var i in oc) { + var ind = classes.indexOf(oc[i]); + if (ind >= 0) classes.splice(ind, 1); + } + for (var i in nc) { + if (nc[i] && classes.indexOf(nc[i]) < 0) classes.push(nc[i]); + } + sel.setAttribute('class', classes.join(' ')); +} + +teal.empty = function(sel) { + if (sel.childNodes) + while (sel.childNodes.length) + sel.removeChild(sel.firstChild); +} + +teal.remove = function(sel) { + if (sel) { + if (sel.parentNode) sel.parentNode.removeChild(sel); + else for (var i = sel.length - 1; i >= 0; --i) + sel[i].parentNode.removeChild(sel[i]); + } +} + +teal.bind = function(sel, eventname, func, bubble) { + if (!sel) return; + if (eventname.constructor === Array) { + for (var i in eventname) + sel.addEventListener(eventname[i], func, bubble ? bubble : false); + } + else + sel.addEventListener(eventname, func, bubble ? bubble : false); +} + +teal.unbind = function(sel, eventname, func, bubble) { + if (eventname.constructor === Array) { + for (var i in eventname) + sel.removeEventListener(eventname[i], func, bubble ? bubble : false); + } + else + sel.removeEventListener(eventname, func, bubble ? bubble : false); +} + +teal.one = function(sel, eventname, func, bubble) { + var one_func = function(e) { + func.call(this, e); + teal.unbind(sel, eventname, one_func, bubble); + }; + teal.bind(sel, eventname, one_func, bubble); +} + +teal.raise_event = function(sel, eventname, bubble, cancelable) { + var evt = document.createEvent('UIEvents'); + evt.initEvent(eventname, bubble == undefined ? true : bubble, + cancelable == undefined ? true : cancelable); + sel.dispatchEvent(evt); +} + +teal.raise = function(sel, eventname, params, bubble, cancelable) { + var ev = document.createEvent("CustomEvent"); + ev.initCustomEvent(eventname, bubble, cancelable, params); + sel.dispatchEvent(ev); +} + +if (!document.getElementsByClassName) { + teal.get_elements_by_class = function(classes, node) { + var node = node || document, + list = node.getElementsByTagName('*'), + cl = classes.split(/\s+/), + result = []; + + for (var i = list.length - 1; i >= 0; --i) { + for (var j = cl.length - 1; j >= 0; --j) { + var clas = list[i].getAttribute('class'); + if (clas && clas.search('\\b' + cl[j] + '\\b') != -1) { + result.push(list[i]); + break; + } + } + } + return result; + } +} +else { + teal.get_elements_by_class = function(classes, node) { + return (node || document).getElementsByClassName(classes); + } +} + +teal.rpc = function(params, callback, noparse) { + var ajax = new XMLHttpRequest(); + ajax.open("post", 'f', true); + ajax.onreadystatechange = function() { + if (ajax.readyState == 4) + callback.call(ajax, noparse ? ajax.responseText : JSON.parse(ajax.responseText)); + }; + ajax.send(JSON.stringify(params)); +} + +teal.uuid = function() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); +} + +teal.get_url_params = function() { + var params = window.location.search.substring(1).split("&"); + var res = {}; + for (var i in params) { + var keyvalue = params[i].split("="); + res[keyvalue[0]] = decodeURI(keyvalue[1]); + } + return res; +} + +teal.get_mouse_coords = function(ev) { + var touches = ev.changedTouches; + if (touches) return { x: touches[0].clientX, y: touches[0].clientY }; + return { x: ev.clientX, y: ev.clientY }; +} + +teal.deferred = function() { + var solved = false, callbacks = [], args = []; + function solve() { + while (callbacks.length) { + callbacks.shift().apply(this, args); + } + } + return { + promise: function() { + return { + then: function(callback) { + var deferred = teal.deferred(), promise = deferred.promise(); + callbacks.push(function() { + var res = callback.apply(this, arguments); + if (res && 'done' in res) res.done(deferred.resolve); + else deferred.resolve.apply(this, arguments); + }); + return promise; + }, + done: function(callback) { + callbacks.push(callback); + if (solved) solve(); + return this; + }, + cancel: function() { + callbacks = []; + } + }; + }, + resolve: function() { + solved = true; + args = Array.prototype.slice.call(arguments, 0); + solve(); + } + }; +} + +teal.when = function(promises) { + var deferred = teal.deferred(); + var count = promises.length, ind = 0; + if (count == 0) deferred.resolve(); + for (var i = 0; i < count; ++i) { + promises[i].done(function() { + if (++ind == count) deferred.resolve(); + }); + } + return deferred.promise(); +} +