";
jQuery("body").append(d);
setTimeout(function() {
jQuery(".more-games-dialog-block").addClass("more-games-dialog-block-show");
setTimeout(function() {
jQuery(".more-games-dialog-content").addClass("more-games-dialog-content-show");
jQuery(".more-games-dialog-exit").addClass("more-games-dialog-exit-show")
}, 100)
}, 100)
}),
jQuery("#more-games-button").fadeIn())
*/
}
$(document).ready(function() {
jQuery(document).on("click", ".more-games-dialog-exit", function() {
jQuery(".more-games-dialog-content").removeClass("more-games-dialog-content-show");
jQuery(".more-games-dialog-exit").removeClass("more-games-dialog-exit-show");
setTimeout(function() {
jQuery(".more-games-dialog-block").removeClass("more-games-dialog-block-show");
setTimeout(function() {
jQuery(".more-games-dialog-wrapper").remove()
}, 500)
}, 100)
})
});
function getGames(m)
{
var a = [];
a.push({
img: "",
url: ""
})
return a
}
var s_fInverseScaling = 0;
(function(m) {
(jQuery.browser = jQuery.browser || {}).mobile = /android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(ad|hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|tablet|treo|up\.(browser|link)|vodafone|wap|webos|windows (ce|phone)|xda|xiino/i.test(m) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(m.substr(0, 4))
}
)(navigator.userAgent || navigator.vendor || window.opera);
function trace(m) {
console.log(m)
}
function isChrome() {
return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)
}
function isIOS() {
for (var m = "iPad Simulator;iPhone Simulator;iPod Simulator;iPad;iPhone;iPod".split(";"); m.length; )
if (navigator.platform === m.pop())
return s_bIsIphone = !0;
return s_bIsIphone = !1
}
$(window).resize(function() {
sizeHandler()
});
function getSize(m) {
var a = m.toLowerCase()
, d = window.document
, f = d.documentElement;
if (void 0 === window["inner" + m])
m = f["client" + m];
else if (window["inner" + m] != f["client" + m]) {
var c = d.createElement("body");
c.id = "vpw-test-b";
c.style.cssText = "overflow:scroll";
var e = d.createElement("div");
e.id = "vpw-test-d";
e.style.cssText = "position:absolute;top:-1000px";
e.innerHTML = "";
c.appendChild(e);
f.insertBefore(c, d.head);
m = 7 == e["offset" + m] ? f["client" + m] : window["inner" + m];
f.removeChild(c)
} else
m = window["inner" + m];
return m
}
window.addEventListener("orientationchange", onOrientationChange);
function onOrientationChange() {
window.matchMedia("(orientation: portrait)").matches && sizeHandler();
window.matchMedia("(orientation: landscape)").matches && sizeHandler()
}
function getIOSWindowHeight() {
return document.documentElement.clientWidth / window.innerWidth * window.innerHeight
}
function getHeightOfIOSToolbars() {
var m = (0 === window.orientation ? screen.height : screen.width) - getIOSWindowHeight();
return 1 < m ? m : 0
}
function sizeHandler() {
window.scrollTo(0, 1);
if ($("#canvas")) {
var m = navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? getIOSWindowHeight() : getSize("Height");
var a = getSize("Width");
_checkOrientation(a, m);
var d = Math.min(m / CANVAS_HEIGHT, a / CANVAS_WIDTH)
, f = CANVAS_WIDTH * d;
d *= CANVAS_HEIGHT;
if (d < m) {
var c = m - d;
d += c;
f += CANVAS_WIDTH / CANVAS_HEIGHT * c
} else
f < a && (c = a - f,
f += c,
d += CANVAS_HEIGHT / CANVAS_WIDTH * c);
c = m / 2 - d / 2;
var e = a / 2 - f / 2
, b = CANVAS_WIDTH / f;
if (e * b < -EDGEBOARD_X || c * b < -EDGEBOARD_Y)
d = Math.min(m / (CANVAS_HEIGHT - 2 * EDGEBOARD_Y), a / (CANVAS_WIDTH - 2 * EDGEBOARD_X)),
f = CANVAS_WIDTH * d,
d *= CANVAS_HEIGHT,
c = (m - d) / 2,
e = (a - f) / 2,
b = CANVAS_WIDTH / f;
s_fInverseScaling = b;
s_iOffsetX = -1 * e * b;
s_iOffsetY = -1 * c * b;
0 <= c && (s_iOffsetY = 0);
0 <= e && (s_iOffsetX = 0);
null !== s_oInterface && s_oInterface.refreshButtonPos(s_iOffsetX, s_iOffsetY);
null !== s_oMenu && s_oMenu.refreshButtonPos(s_iOffsetX, s_iOffsetY);
null !== s_oTeamChoose && s_oTeamChoose.refreshButtonPos(s_iOffsetX, s_iOffsetY);
s_bIsIphone ? (canvas = document.getElementById("canvas"),
s_oStage.canvas.width = 2 * f,
s_oStage.canvas.height = 2 * d,
canvas.style.width = f + "px",
canvas.style.height = d + "px",
s_oStage.scaleX = s_oStage.scaleY = 2 * Math.min(f / CANVAS_WIDTH, d / CANVAS_HEIGHT)) : s_bMobile || isChrome() ? ($("#canvas").css("width", f + "px"),
$("#canvas").css("height", d + "px")) : (s_oStage.canvas.width = f,
s_oStage.canvas.height = d,
s_iScaleFactor = Math.min(f / CANVAS_WIDTH, d / CANVAS_HEIGHT),
s_oStage.scaleX = s_oStage.scaleY = s_iScaleFactor);
0 > c ? ($("#canvas").css("top", c + "px"),
s_iCanvasOffsetHeight = c) : ($("#canvas").css("top", "0px"),
s_iCanvasOffsetHeight = 0);
$("#canvas").css("left", e + "px");
resizeCanvas3D();
s_iCanvasResizeWidth = f;
s_iCanvasResizeHeight = d;
s_iCanvasOffsetWidth = e;
fullscreenHandler()
}
}
function createBitmap(m, a, d) {
var f = new createjs.Bitmap(m)
, c = new createjs.Shape;
a && d ? c.graphics.beginFill("#fff").drawRect(0, 0, a, d) : c.graphics.beginFill("#ff0").drawRect(0, 0, m.width, m.height);
f.hitArea = c;
return f
}
function createSprite(m, a, d, f, c, e) {
m = null !== a ? new createjs.Sprite(m,a) : new createjs.Sprite(m);
a = new createjs.Shape;
a.graphics.beginFill("#000000").drawRect(-d, -f, c, e);
m.hitArea = a;
return m
}
function _checkOrientation(m, a) {
s_bMobile && ENABLE_CHECK_ORIENTATION && (m > a ? "landscape" === $(".orientation-msg-container").attr("data-orientation") ? ($(".orientation-msg-container").css("display", "none"),
s_oMain.startUpdate()) : ($(".orientation-msg-container").css("display", "block"),
s_oMain.stopUpdate()) : "portrait" === $(".orientation-msg-container").attr("data-orientation") ? ($(".orientation-msg-container").css("display", "none"),
s_oMain.startUpdate()) : ($(".orientation-msg-container").css("display", "block"),
s_oMain.stopUpdate()))
}
function randomFloatBetween(m, a, d) {
"undefined" === typeof d && (d = 2);
return parseFloat(Math.min(m + Math.random() * (a - m), a).toFixed(d))
}
function rotateVector2D(m, a) {
var d = a.getX() * Math.cos(m) + a.getY() * Math.sin(m)
, f = a.getX() * -Math.sin(m) + a.getY() * Math.cos(m);
a.set(d, f)
}
function tweenVectorsOnX(m, a, d) {
return m + d * (a - m)
}
function shuffle(m) {
for (var a = m.length, d, f; 0 !== a; )
f = Math.floor(Math.random() * a),
--a,
d = m[a],
m[a] = m[f],
m[f] = d;
return m
}
function bubbleSort(m) {
do {
var a = !1;
for (var d = 0; d < m.length - 1; d++)
m[d] > m[d + 1] && (a = m[d],
m[d] = m[d + 1],
m[d + 1] = a,
a = !0)
} while (a)
}
function compare(m, a) {
return m.index > a.index ? -1 : m.index < a.index ? 1 : 0
}
function easeLinear(m, a, d, f) {
return d * m / f + a
}
function easeInQuad(m, a, d, f) {
return d * (m /= f) * m + a
}
function easeInSine(m, a, d, f) {
return -d * Math.cos(m / f * (Math.PI / 2)) + d + a
}
function easeInCubic(m, a, d, f) {
return d * (m /= f) * m * m + a
}
function easeOutCubic(m, a, d, f) {
return d * ((m = m / f - 1) * m * m + 1) + a
}
function getTrajectoryPoint(m, a) {
var d = new createjs.Point
, f = (1 - m) * (1 - m)
, c = m * m;
d.x = f * a.start.x + 2 * (1 - m) * m * a.traj.x + c * a.end.x;
d.y = f * a.start.y + 2 * (1 - m) * m * a.traj.y + c * a.end.y;
return d
}
function formatTime(m) {
m /= 1E3;
var a = Math.floor(m / 60);
m = Math.floor(m - 60 * a);
var d = "";
d = 10 > a ? d + ("0" + a + ":") : d + (a + ":");
return 10 > m ? d + ("0" + m) : d + m
}
function degreesToRadians(m) {
return m * Math.PI / 180
}
function checkRectCollision(m, a) {
var d = getBounds(m, .9);
var f = getBounds(a, .98);
return calculateIntersection(d, f)
}
function calculateIntersection(m, a) {
var d, f, c, e;
var b = m.x + (d = m.width / 2);
var g = m.y + (f = m.height / 2);
var k = a.x + (c = a.width / 2);
var h = a.y + (e = a.height / 2);
b = Math.abs(b - k) - (d + c);
g = Math.abs(g - h) - (f + e);
return 0 > b && 0 > g ? (b = Math.min(Math.min(m.width, a.width), -b),
g = Math.min(Math.min(m.height, a.height), -g),
{
x: Math.max(m.x, a.x),
y: Math.max(m.y, a.y),
width: b,
height: g,
rect1: m,
rect2: a
}) : null
}
function getBounds(m, a) {
var d = {
x: Infinity,
y: Infinity,
width: 0,
height: 0
};
if (m instanceof createjs.Container) {
d.x2 = -Infinity;
d.y2 = -Infinity;
var f = m.children, c = f.length, e;
for (e = 0; e < c; e++) {
var b = getBounds(f[e], 1);
b.x < d.x && (d.x = b.x);
b.y < d.y && (d.y = b.y);
b.x + b.width > d.x2 && (d.x2 = b.x + b.width);
b.y + b.height > d.y2 && (d.y2 = b.y + b.height)
}
Infinity == d.x && (d.x = 0);
Infinity == d.y && (d.y = 0);
Infinity == d.x2 && (d.x2 = 0);
Infinity == d.y2 && (d.y2 = 0);
d.width = d.x2 - d.x;
d.height = d.y2 - d.y;
delete d.x2;
delete d.y2
} else {
if (m instanceof createjs.Bitmap) {
c = m.sourceRect || m.image;
e = c.width * a;
var g = c.height * a
} else if (m instanceof createjs.Sprite)
if (m.spriteSheet._frames && m.spriteSheet._frames[m.currentFrame] && m.spriteSheet._frames[m.currentFrame].image) {
c = m.spriteSheet.getFrame(m.currentFrame);
e = c.rect.width;
g = c.rect.height;
f = c.regX;
var k = c.regY
} else
d.x = m.x || 0,
d.y = m.y || 0;
else
d.x = m.x || 0,
d.y = m.y || 0;
f = f || 0;
e = e || 0;
k = k || 0;
g = g || 0;
d.regX = f;
d.regY = k;
c = m.localToGlobal(0 - f, 0 - k);
b = m.localToGlobal(e - f, g - k);
e = m.localToGlobal(e - f, 0 - k);
f = m.localToGlobal(0 - f, g - k);
d.x = Math.min(Math.min(Math.min(c.x, b.x), e.x), f.x);
d.y = Math.min(Math.min(Math.min(c.y, b.y), e.y), f.y);
d.width = Math.max(Math.max(Math.max(c.x, b.x), e.x), f.x) - d.x;
d.height = Math.max(Math.max(Math.max(c.y, b.y), e.y), f.y) - d.y
}
return d
}
function NoClickDelay(m) {
this.element = m;
window.Touch && this.element.addEventListener("touchstart", this, !1)
}
function shuffle(m) {
for (var a = m.length, d, f; 0 < a; )
f = Math.floor(Math.random() * a),
a--,
d = m[a],
m[a] = m[f],
m[f] = d;
return m
}
NoClickDelay.prototype = {
handleEvent: function(m) {
switch (m.type) {
case "touchstart":
this.onTouchStart(m);
break;
case "touchmove":
this.onTouchMove(m);
break;
case "touchend":
this.onTouchEnd(m)
}
},
onTouchStart: function(m) {
m.preventDefault();
this.moved = !1;
this.element.addEventListener("touchmove", this, !1);
this.element.addEventListener("touchend", this, !1)
},
onTouchMove: function(m) {
this.moved = !0
},
onTouchEnd: function(m) {
this.element.removeEventListener("touchmove", this, !1);
this.element.removeEventListener("touchend", this, !1);
if (!this.moved) {
m = document.elementFromPoint(m.changedTouches[0].clientX, m.changedTouches[0].clientY);
3 == m.nodeType && (m = m.parentNode);
var a = document.createEvent("MouseEvents");
a.initEvent("click", !0, !0);
m.dispatchEvent(a)
}
}
};
(function() {
function m(d) {
var m = {
focus: "visible",
focusin: "visible",
pageshow: "visible",
blur: "hidden",
focusout: "hidden",
pagehide: "hidden"
};
d = d || window.event;
d.type in m ? document.body.className = m[d.type] : (document.body.className = this[a] ? "hidden" : "visible",
"hidden" === document.body.className ? s_oMain.stopUpdate() : s_oMain.startUpdate())
}
var a = "hidden";
a in document ? document.addEventListener("visibilitychange", m) : (a = "mozHidden")in document ? document.addEventListener("mozvisibilitychange", m) : (a = "webkitHidden")in document ? document.addEventListener("webkitvisibilitychange", m) : (a = "msHidden")in document ? document.addEventListener("msvisibilitychange", m) : "onfocusin"in document ? document.onfocusin = document.onfocusout = m : window.onpageshow = window.onpagehide = window.onfocus = window.onblur = m
}
)();
function ctlArcadeResume() {
null !== s_oMain && s_oMain.startUpdate()
}
function ctlArcadePause() {
null !== s_oMain && s_oMain.stopUpdate()
}
function getParamValue(m) {
for (var a = window.location.search.substring(1).split("&"), d = 0; d < a.length; d++) {
var f = a[d].split("=");
if (f[0] == m)
return f[1]
}
}
function playSound(m, a, d) {
return !1 === DISABLE_SOUND_MOBILE || !1 === s_bMobile ? (s_aSounds[m].play(),
s_aSounds[m].volume(a),
s_aSounds[m].loop(d),
s_aSounds[m]) : null
}
function stopSound(m) {
!1 !== DISABLE_SOUND_MOBILE && !1 !== s_bMobile || s_aSounds[m].stop()
}
function setVolume(m, a) {
!1 !== DISABLE_SOUND_MOBILE && !1 !== s_bMobile || s_aSounds[m].volume(a)
}
function setMute(m, a) {
!1 !== DISABLE_SOUND_MOBILE && !1 !== s_bMobile || s_aSounds[m].mute(a)
}
function resizeCanvas3D() {
$("canvas").each(function() {
"#canvas" != $(this).attr("id") && ($(this).css("width", $("#canvas").css("width")),
$(this).css("height", $("#canvas").css("height")),
$(this).css("position", $("#canvas").css("position")),
$(this).css("left", $("#canvas").css("left")),
$(this).css("top", $("#canvas").css("top")))
})
}
function createOrthoGraphicCamera() {
var m = new THREE.PerspectiveCamera(FOV,CANVAS_WIDTH / CANVAS_HEIGHT,NEAR,FAR);
m.rotation.x = Math.PI / 180 * 90;
m.position.set(0, 0, 0);
m.updateProjectionMatrix();
m.updateMatrixWorld();
return m
}
Math.radians = function(m) {
return m * Math.PI / 180
}
;
Math.degrees = function(m) {
return 180 * m / Math.PI
}
;
function fullscreenHandler() {
ENABLE_FULLSCREEN && screenfull.enabled && (s_bFullscreen = screen.height < window.innerHeight + 3 && screen.height > window.innerHeight - 3 ? !0 : !1,
null !== s_oInterface && s_oInterface.resetFullscreenBut(),
null !== s_oMenu && s_oMenu.resetFullscreenBut(),
null !== s_oTeamChoose && s_oTeamChoose.resetFullscreenBut())
}
if (screenfull.enabled)
screenfull.on("change", function() {
s_bFullscreen = screenfull.isFullscreen;
null !== s_oInterface && s_oInterface.resetFullscreenBut();
null !== s_oMenu && s_oMenu.resetFullscreenBut();
null !== s_oTeamChoose && s_oTeamChoose.resetFullscreenBut()
});
window.GD_OPTIONS = {
gameId: "fde0ed339c1c4d358cb836f6eb8d8b58",
onEvent: function(m) {
switch (m.name) {
case "SDK_GAME_START":
s_oMain.startUpdate();
break;
case "SDK_GAME_PAUSE":
s_oMain.stopUpdate()
}
}
};/*
(function(m, a, d) {
var f = m.getElementsByTagName(a)[0];
m.getElementById(d) || (m = m.createElement(a),
m.id = d,
m.src = "https://html5.api.gamedistribution.com/main.min.js",
f.parentNode.insertBefore(m, f))
}
)(document, "script", "gamedistribution-jssdk");
*/
function CSpriteLibrary() {
var m = {}, a, d, f, c, e, b;
this.init = function(g, k, h) {
a = {};
f = d = 0;
c = g;
e = k;
b = h
}
;
this.addSprite = function(b, c) {
m.hasOwnProperty(b) || (m[b] = a[b] = {
szPath: c,
oSprite: new Image,
bLoaded: !1
},
d++)
}
;
this.getSprite = function(b) {
return m.hasOwnProperty(b) ? m[b].oSprite : null
}
;
this._onSpritesLoaded = function() {
d = 0;
e.call(b)
}
;
this._onSpriteLoaded = function(a) {
c.call(b, a);
++f === d && this._onSpritesLoaded()
}
;
this.loadSprites = function() {
for (var b in a)
a[b].oSprite.oSpriteLibrary = this,
a[b].oSprite.szKey = b,
a[b].oSprite.onload = function() {
this.oSpriteLibrary.setLoaded(this.szKey);
this.oSpriteLibrary._onSpriteLoaded(this.szKey)
}
,
a[b].oSprite.src = a[b].szPath
}
;
this.setLoaded = function(b) {
m[b].bLoaded = !0
}
;
this.isLoaded = function(b) {
return m[b].bLoaded
}
;
this.getNumSprites = function() {
return d
}
}
var CANVAS_WIDTH = 790, CANVAS_HEIGHT = 960, CANVAS_WIDTH_HALF = .5 * CANVAS_WIDTH, CANVAS_HEIGHT_HALF = .5 * CANVAS_HEIGHT, FONT = "pixel_lcd7regular", FONT2 = "arialbold", EDGEBOARD_X = 150, EDGEBOARD_Y = 0, FPS = 30, FPS_TIME = 1 / FPS, ROLL_BALL_RATE = 60 / FPS, DISABLE_SOUND_MOBILE = !1, STATE_LOADING = 0, STATE_MENU = 1, STATE_HELP = 1, STATE_GAME = 3, BATTER_MODE = 0, BOWLER_MODE = 1, TOT_TEAMS = 6, POINT_TEXT_EXCELLENT, POINT_TEXT_GREAT = 85, TEXT_EXCELLENT_COLOR = ["#fff", "#5d96fe"], PLAYER_SELECTION_FLAG_START_POS = {
x: CANVAS_WIDTH_HALF - 180,
y: CANVAS_HEIGHT_HALF - 85
}, OPPONENT_SELECTION_FLAG_START_POS = {
x: CANVAS_WIDTH_HALF + 72,
y: CANVAS_HEIGHT_HALF - 85
}, MAX_COL_FLAG = 2, FLAG_OFFSET = {
x: 110,
y: 75
}, TRAJECTORY_Y_BALL_CAUGHT = -250, BATTER_X = CANVAS_WIDTH / 2 - 140, BATTER_Y = CANVAS_HEIGHT - 620, BOWLER_X = CANVAS_WIDTH / 2 - 50, BOWLER_Y = CANVAS_HEIGHT / 2 - 475, BALL_X = BOWLER_X + 86, BALL_Y = BOWLER_Y + 50, BALL_TO_THROW, STEP_SPEED_BALL, BEAT_FORCE = .5, STEP_SPEED_STADIUM, TARGET_PREV_LUM_OFFSET = {
min: -12,
max: -5
}, LAUNCH_DIR_OFFSET_RANGE = [{
min: -90,
max: -50
}, {
min: -5,
max: 5
}, {
min: 50,
max: 90
}], POLE_POSITION = {
x: CANVAS_WIDTH_HALF,
y: CANVAS_HEIGHT - 200
}, OFFSET_FOR_HIT, OFFSET_FOR_PERFECT_HIT, PERFECT_HIT_X = BALL_X - 36, PERFECT_HIT_Y = CANVAS_HEIGHT - 410, ALMOST_MINUS, ALMOST_PLUS, END_POINT_X_THROWN = PERFECT_HIT_X, END_POINT_Y_THROWN = PERFECT_HIT_Y, END_POINT_X_MISSED_BALL = POLE_POSITION.x, END_POINT_Y_MISSED_BALL = POLE_POSITION.y, END_POINT_X_ALMOST_MINUS_LEFT = CANVAS_WIDTH / 2 - 200, END_POINT_X_ALMOST_MINUS_RIGHT = CANVAS_WIDTH / 2 + 200, END_POINT_Y_ALMOST_MINUS = 50, END_POINT_X_ALMOST_PLUS_LEFT = CANVAS_WIDTH / 2 - 300, END_POINT_X_ALMOST_PLUS_RIGHT = CANVAS_WIDTH / 2 + 300, END_POINT_Y_ALMOST_PLUS = 50, END_POINT_X_PERFECT_LEFT = CANVAS_WIDTH / 2 - 100, END_POINT_X_PERFECT_RIGHT = CANVAS_WIDTH / 2 + 100, END_POINT_Y_PERFECT = 0, MAX_FRAMES_THROWN = 40, START_POINT_STADIUM_X = CANVAS_WIDTH / 2, START_POINT_STADIUM_Y = CANVAS_HEIGHT / 2 + 250, NUM_SPRITE_PLAYERS = 40, NUM_SPRITE_BATTING = 36, NUM_SPRITE_BOWLER = 56, NUM_SPRITE_BATTER_BOWLER_MODE = 81, STEP_RATE = 1.5, PHYSICS_ACCURACY = 3, MOBILE_OFFSET_GLOVES_X = -45, MOBILE_OFFSET_GLOVES_Y = -38, BALL_VELOCITY_MULTIPLIER = 1, PHYSICS_STEP = 1 / FPS, BALL_MASS = .16, BALL_RADIUS = .6, BALL_LINEAR_DAMPING = .2, OFFSET_BALL_POS_X = 10, OBJECT, TEXT_SIZE = [50, 65, 80], TIME_TRY_TO_SHOT_BALL_OPPONENT = .7, MIN_BALL_VEL_ROTATION = .1, TIME_RESET_AFTER_GOAL = 1, TIME_RESET_AFTER_KEEPER_SAVED = 2, TIME_RESET_AFTER_PERFECT_KEEPER_SAVED = 3, TIME_BALL_IN_HAND = 1E3, FOV = 35, INTERVAL_SHOOT = 1, HAND_KEEPER_ANGLE_RATE = .15, LIMIT_HAND_RANGE_POS = {
x: 8.8,
zMax: 5.1,
zMin: -8.5
}, POSITION_BALL = {
x: 60,
y: 220,
z: 0
}, LINE_GOAL_SIZE = {
width: 17.5,
depth: 1,
height: 15.5
}, GOAL_LINE_POS = {
x: 0,
y: 10,
z: -2.7
}, GLOVE_SIZE = {
width: 1.4,
depth: 1,
height: 1.7
}, LEFT_GLOVE_POSITION = {
x: -1.5,
y: 40,
z: 0
}, RIGHT_GLOVE_POSITION = {
x: 1.5,
y: 40,
z: 0
}, LAUNCH_BALL_IMPULSE = {
x: -4.47,
y: 0,
z: 1
}, LEFT_GLOVE = 0, RIGHT_GLOVE = 1, GLOVE_REG = [{
x: 3,
y: -5
}, {
x: -3,
y: -5
}], SHOW_3D_RENDER = !1, CAMERA_TEST = !1, MOUSE_SENSIBILTY = .03, OFFSET_MOUSE_X = -75, SCORE_ERROR_MULTIPLIER = 20, INTENSITY_DISPLAY_SHOCK = [{
x: 30,
y: 20,
time: 75
}, {
x: 50,
y: 25,
time: 75
}, {
x: 70,
y: 30,
time: 75
}, {
x: 90,
y: 40,
time: 75
}], CAMERA_POSITION = {
x: 0,
y: 0,
z: 100
}, NEAR = 10, FAR = 2E3, STATE_INIT = 0, STATE_PLAY = 1, STATE_FINISH = 2, STATE_PAUSE = 3, ON_MOUSE_DOWN = 0, ON_MOUSE_UP = 1, ON_MOUSE_OVER = 2, ON_MOUSE_OUT = 3, ON_DRAG_START = 4, ON_DRAG_END = 5, HIT_LEFT = 0, HIT_CENTER = 1, HIT_RIGHT = 2, ENABLE_FULLSCREEN, ENABLE_CHECK_ORIENTATION;
TEXT_TEAM = "Australia;England;India;Pakistan;South Africa;Sri Lanka".split(";");
TEXT_GAMEOVER = "YOU RAN OUT OF BALLS.";
TEXT_SCORE = "FINAL SCORE\n";
TEXT_PAUSE = "PAUSE";
TEXT_MISSED = "MISSED!";
SCORE_TEXT = "PTS: ";
TEXT_CREDITS_DEVELOPED = "DEVELOPED BY";
TEXT_SELECT_YOUR_TEAM = "SELECT YOUR TEAM";
TEXT_SELECT_OPPONENT_TEAM = "SELECT CPU TEAM";
TEXT_ARE_SURE = "ARE YOU SURE?";
TEXT_CONGRATULATION = ["GOOD!", "GREAT!", "EXCELLENT!!!"];
TEXT_LOADING = "LOADING";
TEXT_HOW_TO_PLAY = "HOW TO PLAY";
TEXT_HELP1_PC_BOWLER = "MOVE THE MOUSE TO CONTROL THE KEEPER'S GLOVES AND DEFEND THE WICKET";
TEXT_HELP1_MOBILE_BOWLER = "MOVE THE FINGER TO CONTROL THE KEEPER'S GLOVES AND DEFEND THE WICKET";
TEXT_SHARE_IMAGE = "200x200.jpg";
TEXT_SHARE_TITLE = "Congratulations!";
TEXT_SHARE_MSG1 = "You collected ";
TEXT_SHARE_MSG2 = " points!
Share your score with your friends!";
TEXT_SHARE_SHARE1 = "My score is ";
TEXT_SHARE_SHARE2 = " points! Can you do better?";
function CPreloader() {
var m, a, d, f, c, e, b;
this._init = function() {
s_oSpriteLibrary.init(this._onImagesLoaded, this._onAllImagesLoaded, this);
s_oSpriteLibrary.addSprite("bg_menu", "./sprites/bg_menu.jpg");
s_oSpriteLibrary.addSprite("progress_bar", "./sprites/progress_bar.png");
s_oSpriteLibrary.addSprite("logo_menu", "./sprites/logo_menu.png");
s_oSpriteLibrary.loadSprites();
b = new createjs.Container;
s_oStage.addChild(b)
}
;
this.unload = function() {
b.removeAllChildren()
}
;
this.hide = function() {
var b = this;
setTimeout(function() {
createjs.Tween.get(e).to({
alpha: 1
}, 500).call(function() {
b.unload();
s_oMain.gotoMenu()
})
}, 1E3)
}
;
this._onImagesLoaded = function() {}
;
this._onAllImagesLoaded = function() {
this.attachSprites();
s_oMain.preloaderReady()
}
;
this.attachSprites = function() {
var g = createBitmap(s_oSpriteLibrary.getSprite("bg_menu"));
b.addChild(g);
g = createBitmap(s_oSpriteLibrary.getSprite("logo_menu"));
g.x = 200;
g.y = 90;
b.addChild(g);
g = s_oSpriteLibrary.getSprite("progress_bar");
f = createBitmap(g);
f.x = CANVAS_WIDTH / 2 - g.width / 2;
f.y = CANVAS_HEIGHT - 250;
b.addChild(f);
m = g.width;
a = g.height;
c = new createjs.Shape;
c.graphics.beginFill("rgba(255,255,255,0.01)").drawRect(f.x, f.y, 1, a);
b.addChild(c);
f.mask = c;
d = new createjs.Text("","30px Arial","#fff");
d.x = CANVAS_WIDTH / 2;
d.y = CANVAS_HEIGHT - 250;
d.shadow = new createjs.Shadow("#000",2,2,2);
d.textBaseline = "alphabetic";
d.textAlign = "center";
b.addChild(d);
e = new createjs.Shape;
e.graphics.beginFill("black").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
e.alpha = 0;
b.addChild(e)
}
;
this.refreshLoader = function(b) {
console.log("loading--->" + b);
d.text = b + "%";
c.graphics.clear();
b = Math.floor(b * m / 100);
c.graphics.beginFill("rgba(255,255,255,0.01)").drawRect(f.x, f.y, b, a)
}
;
this._init()
}
function CMain(m) {
var a, d = 0, f = 0, c = STATE_LOADING, e, b, g, k = [];
this.initContainer = function() {
s_oCanvas = document.getElementById("canvas");
s_oStage = new createjs.Stage(s_oCanvas);
createjs.Touch.enable(s_oStage);
s_bMobile = jQuery.browser.mobile;
!1 === s_bMobile && (s_oStage.enableMouseOver(20),
$("body").on("contextmenu", "#canvas", function(b) {
return !1
}));
s_iPrevTime = (new Date).getTime();
createjs.Ticker.addEventListener("tick", this._update);
createjs.Ticker.setFPS(30);
navigator.userAgent.match(/Windows Phone/i) && (DISABLE_SOUND_MOBILE = !0);
s_oSpriteLibrary = new CSpriteLibrary;
this.setLoadedArray();
e = new CPreloader
}
;
this.preloaderReady = function() {
this._loadImages();
!1 !== DISABLE_SOUND_MOBILE && !1 !== s_bMobile || this._initSounds();
a = !0
}
;
this.soundLoaded = function(b) {
d++;
e.refreshLoader(Math.floor(d / f * 100));
d === f && this._allResourcesLoaded()
}
;
this._initSounds = function() {
var b = [];
b.push({
path: "./sounds/",
filename: "buzzer",
loop: !1,
volume: 1,
ingamename: "buzzer"
});
b.push({
path: "./sounds/",
filename: "click",
loop: !1,
volume: 1,
ingamename: "click"
});
b.push({
path: "./sounds/",
filename: "drop_bounce_grass",
loop: !1,
volume: 1,
ingamename: "drop_bounce_grass"
});
b.push({
path: "./sounds/",
filename: "hit_ball",
loop: !1,
volume: 1,
ingamename: "hit_ball"
});
b.push({
path: "./sounds/",
filename: "crowd_cheering",
loop: !1,
volume: 1,
ingamename: "crowd_cheering"
});
b.push({
path: "./sounds/",
filename: "applauses",
loop: !1,
volume: 1,
ingamename: "applauses"
});
b.push({
path: "./sounds/",
filename: "crowd_ohhh",
loop: !1,
volume: 1,
ingamename: "crowd_ohhh"
});
b.push({
path: "./sounds/",
filename: "kick",
loop: !1,
volume: 1,
ingamename: "kick"
});
b.push({
path: "./sounds/",
filename: "soundtrack",
loop: !0,
volume: 1,
ingamename: "soundtrack"
});
f += b.length;
s_aSounds = [];
for (var a = 0; a < b.length; a++)
s_aSounds[b[a].ingamename] = new Howl({
src: [b[a].path + b[a].filename + ".mp3", b[a].path + b[a].filename + ".ogg"],
autoplay: !1,
preload: !0,
loop: b[a].loop,
volume: b[a].volume,
onload: s_oMain.soundLoaded()
})
}
;
this._loadImages = function() {
s_oSpriteLibrary.init(this._onImagesLoaded, this._onAllImagesLoaded, this);
s_oSpriteLibrary.addSprite("but_play", "./sprites/but_play.png");
s_oSpriteLibrary.addSprite("msg_box", "./sprites/msg_box.png");
s_oSpriteLibrary.addSprite("but_exit", "./sprites/but_exit.png");
s_oSpriteLibrary.addSprite("logo_menu", "./sprites/logo_menu.png");
s_oSpriteLibrary.addSprite("audio_icon", "./sprites/audio_icon.png");
s_oSpriteLibrary.addSprite("preloader_anim", "./sprites/preloader_anim.png");
s_oSpriteLibrary.addSprite("score_panel", "./sprites/score_panel.png");
s_oSpriteLibrary.addSprite("ball", "./sprites/ball.png");
s_oSpriteLibrary.addSprite("1", "./sprites/1.png");
s_oSpriteLibrary.addSprite("2", "./sprites/2.png");
s_oSpriteLibrary.addSprite("3", "./sprites/3.png");
s_oSpriteLibrary.addSprite("but_credits", "./sprites/but_credits.png");
s_oSpriteLibrary.addSprite("logo_credits", "./sprites/logo_credits.png");
s_oSpriteLibrary.addSprite("bg_select_team", "./sprites/bg_select_team.jpg");
s_oSpriteLibrary.addSprite("bg_select_mode", "./sprites/bg_select_mode.jpg");
s_oSpriteLibrary.addSprite("flag_selection", "./sprites/flag_selection.png");
s_oSpriteLibrary.addSprite("but_continue", "./sprites/but_continue.png");
s_oSpriteLibrary.addSprite("but_pause", "./sprites/but_pause.png");
s_oSpriteLibrary.addSprite("but_yes", "./sprites/but_yes.png");
s_oSpriteLibrary.addSprite("but_no", "./sprites/but_no.png");
s_oSpriteLibrary.addSprite("bg_text", "./sprites/bg_text.png");
s_oSpriteLibrary.addSprite("bowler_mode", "./sprites/bowler_mode.png");
s_oSpriteLibrary.addSprite("bg_game_bowler", "./sprites/bg_game_bowler.jpg");
s_oSpriteLibrary.addSprite("ball_game", "./sprites/ball_game.png");
s_oSpriteLibrary.addSprite("ball_shadow", "./sprites/ball_shadow.png");
s_oSpriteLibrary.addSprite("but_home", "./sprites/but_home.png");
s_oSpriteLibrary.addSprite("but_restart", "./sprites/but_restart.png");
s_oSpriteLibrary.addSprite("bg_help", "./sprites/bg_help.png");
s_oSpriteLibrary.addSprite("help_mouse", "./sprites/help_mouse.png");
s_oSpriteLibrary.addSprite("help_touch", "./sprites/help_touch.png");
s_oSpriteLibrary.addSprite("but_fullscreen", "./sprites/but_fullscreen.png");
for (var b = 0; b < TOT_TEAMS; b++)
s_oSpriteLibrary.addSprite("glove_" + b, "./sprites/glove_" + b + ".png"),
s_oSpriteLibrary.addSprite("flag_" + b, "./sprites/flag_" + b + ".png");
f += s_oSpriteLibrary.getNumSprites();
s_oSpriteLibrary.loadSprites()
}
;
this._onImagesLoaded = function() {
d++;
e.refreshLoader(Math.floor(d / f * 100));
d === f && this._allResourcesLoaded()
}
;
this._loadChoosedTeam = function(b, a) {
s_iPlayerTeam = b;
s_iOpponentTeam = a;
f = d = 0;
if (k[a])
this.gotoGame(s_iPlayerTeam, s_iOpponentTeam);
else {
s_oSpriteLibrary.init(this._onTeamsLoaded, this._onAllImagesLoaded, this);
for (var c = 0; c < NUM_SPRITE_BATTER_BOWLER_MODE; c++)
!1 === k[a] && s_oSpriteLibrary.addSprite("batter_" + a + "_" + c, "./sprites/batter_" + a + "/batter_" + a + "_" + c + ".png");
f += s_oSpriteLibrary.getNumSprites();
s_oSpriteLibrary.loadSprites()
}
}
;
this._onTeamsLoaded = function() {
d++;
d === f && this.gotoGame(s_iPlayerTeam, s_iOpponentTeam)
}
;
this._onAllImagesLoaded = function() {}
;
this._allResourcesLoaded = function() {
e.unload();
isIOS() || (s_oSoundTrack = playSound("soundtrack", 1, !0));
console.log("全部加载完毕")
window['uptap'].HideLoading();
window['uptap'].Login(function(t) {
console.log("uptap_login_end && data = ", t)
});
s_oMain.gotoMenu()
}
;
this.setLoadedArray = function() {
for (var b = 0; b < TOT_TEAMS; b++)
k[b] = !1
}
;
this.gotoMenu = function() {
new CMenu;
c = STATE_MENU;
showMoreGames()
}
;
this.gotoGame = function(a, e) {
g.unload();
k[s_iOpponentTeam] = !0;
b = new CGame(h,a,e);
c = STATE_GAME;
hideMoreGames()
}
;
this.gotoTeamChoose = function() {
g = new CTeamChoose;
c = STATE_MENU
}
;
this.stopUpdate = function() {
a = !1;
createjs.Ticker.paused = !0;
$("#block_game").css("display", "block");
!1 !== DISABLE_SOUND_MOBILE && !1 !== s_bMobile || Howler.mute(!0)
}
;
this.startUpdate = function() {
s_iPrevTime = (new Date).getTime();
a = !0;
createjs.Ticker.paused = !1;
$("#block_game").css("display", "none");
(!1 === DISABLE_SOUND_MOBILE || !1 === s_bMobile) && s_bAudioActive && Howler.mute(!1)
}
;
this._update = function(h) {
if (!1 !== a) {
var e = (new Date).getTime();
s_iTimeElaps = e - s_iPrevTime;
s_iCntTime += s_iTimeElaps;
s_iCntFps++;
s_iPrevTime = e;
1E3 <= s_iCntTime && (s_iCurFps = s_iCntFps,
s_iCntTime -= 1E3,
s_iCntFps = 0);
c === STATE_GAME && b.update();
s_oStage.update(h)
}
}
;
s_oMain = this;
var h = m;
ENABLE_FULLSCREEN = m.fullscreen;
ENABLE_CHECK_ORIENTATION = m.check_orientation;
this.initContainer()
}
var s_bMobile, s_bAudioActive = !0, s_bFullscreen = !1, s_iCntTime = 0, s_iTimeElaps = 0, s_iPrevTime = 0, s_iCntFps = 0, s_iCurFps = 0, s_iPlayerTeam, s_iOpponentTeam, s_iAdsLevel = 1, s_oStage, s_oMain, s_oBall, s_oSpriteLibrary, s_oSoundTrack = null, s_oCanvas, s_iCanvasResizeHeight, s_iCanvasResizeWidth, s_iCanvasOffsetHeight, s_iCanvasOffsetWidth, s_aSounds;
function CTextButton(m, a, d, f, c, e, b, g) {
var k, h, n, l, q, p, r = !1;
this._init = function(b, a, c, e, g, d, m, f) {
k = [];
h = [];
n = [];
var r = createBitmap(c);
p = new createjs.Text(e,f + "px " + g,m);
p.textAlign = "center";
p.textBaseline = "middle";
p.x = c.width / 2;
p.y = c.height / 2;
p.outline = 3;
q = new createjs.Text(e,f + "px " + g,d);
q.textAlign = "center";
q.textBaseline = "middle";
q.x = p.x;
q.y = p.y;
l = new createjs.Container;
l.x = b;
l.y = a;
l.regX = c.width / 2;
l.regY = c.height / 2;
l.addChild(r, p, q);
s_bMobile || (l.cursor = "pointer");
s_oStage.addChild(l);
this._initListener()
}
;
this.unload = function() {
l.off("mousedown");
l.off("pressup");
s_oStage.removeChild(l)
}
;
this.setVisible = function(b) {
l.visible = b
}
;
this._initListener = function() {
l.on("mousedown", this.buttonDown);
l.on("pressup", this.buttonRelease)
}
;
this.addEventListener = function(b, a, c) {
k[b] = a;
h[b] = c
}
;
this.addEventListenerWithParams = function(b, a, c, e) {
k[b] = a;
h[b] = c;
n = e
}
;
this.buttonRelease = function() {
r || (l.scaleX = 1,
l.scaleY = 1,
k[ON_MOUSE_UP] && k[ON_MOUSE_UP].call(h[ON_MOUSE_UP], n))
}
;
this.buttonDown = function() {
r || (l.scaleX = .9,
l.scaleY = .9,
k[ON_MOUSE_DOWN] && k[ON_MOUSE_DOWN].call(h[ON_MOUSE_DOWN], n))
}
;
this.block = function(b) {
r = b;
l.scaleX = 1;
l.scaleY = 1
}
;
this.setTextPosition = function(b) {
q.y = b;
p.y = b + 2
}
;
this.setPosition = function(b, a) {
l.x = b;
l.y = a
}
;
this.setX = function(b) {
l.x = b
}
;
this.setY = function(b) {
l.y = b
}
;
this.getButtonImage = function() {
return l
}
;
this.getX = function() {
return l.x
}
;
this.getY = function() {
return l.y
}
;
this._init(m, a, d, f, c, e, b, g);
return this
}
function CToggle(m, a, d, f, c) {
var e, b, g, k = [], h;
this._init = function(a, c, p, d) {
b = [];
g = [];
var l = new createjs.SpriteSheet({
images: [p],
frames: {
width: p.width / 2,
height: p.height,
regX: p.width / 2 / 2,
regY: p.height / 2
},
animations: {
state_true: [0],
state_false: [1]
}
});
e = d;
h = createSprite(l, "state_" + e, p.width / 2 / 2, p.height / 2, p.width / 2, p.height);
h.x = a;
h.y = c;
h.cursor = "pointer";
h.stop();
n.addChild(h);
this._initListener()
}
;
this.unload = function() {
h.off("mousedown", this.buttonDown);
h.off("pressup", this.buttonRelease);
n.removeChild(h)
}
;
this._initListener = function() {
h.on("mousedown", this.buttonDown);
h.on("pressup", this.buttonRelease)
}
;
this.addEventListener = function(a, c, e) {
b[a] = c;
g[a] = e
}
;
this.addEventListenerWithParams = function(a, c, e, h) {
b[a] = c;
g[a] = e;
k = h
}
;
this.setActive = function(b) {
e = b;
h.gotoAndStop("state_" + e)
}
;
this.buttonRelease = function() {
h.scaleX = 1;
h.scaleY = 1;
playSound("click", 1, !1);
e = !e;
h.gotoAndStop("state_" + e);
b[ON_MOUSE_UP] && b[ON_MOUSE_UP].call(g[ON_MOUSE_UP], k)
}
;
this.buttonDown = function() {
h.scaleX = .9;
h.scaleY = .9;
b[ON_MOUSE_DOWN] && b[ON_MOUSE_DOWN].call(g[ON_MOUSE_DOWN], k);
playSound("click", 1, !1)
}
;
this.setPosition = function(b, a) {
h.x = b;
h.y = a
}
;
this.setVisible = function(b) {
h.visible = b
}
;
var n = c;
this._init(m, a, d, f)
}
function CGfxButton(m, a, d, f) {
var c, e, b, g, k, h, n = !1;
this._init = function(a, g, n) {
c = [];
e = [];
b = createBitmap(n);
b.x = a;
b.y = g;
h = k = 1;
b.regX = n.width / 2;
b.regY = n.height / 2;
s_bMobile || (b.cursor = "pointer");
l.addChild(b);
this._initListener()
}
;
this.unload = function() {
b.off("mousedown", this.buttonDown);
b.off("pressup", this.buttonRelease);
l.removeChild(b)
}
;
this.setVisible = function(a) {
b.visible = a
}
;
this.setCursorType = function(a) {
b.cursor = a
}
;
this._initListener = function() {
b.on("mousedown", this.buttonDown);
b.on("pressup", this.buttonRelease)
}
;
this.addEventListener = function(b, a, h) {
c[b] = a;
e[b] = h
}
;
this.addEventListenerWithParams = function(b, a, h, l) {
c[b] = a;
e[b] = h;
g = l
}
;
this.buttonRelease = function() {
n || (b.scaleX = 0 < k ? 1 : -1,
b.scaleY = 1,
c[ON_MOUSE_UP] && c[ON_MOUSE_UP].call(e[ON_MOUSE_UP], g))
}
;
this.buttonDown = function() {
n || (b.scaleX = 0 < k ? .9 : -.9,
b.scaleY = .9,
playSound("click", 1, !1),
c[ON_MOUSE_DOWN] && c[ON_MOUSE_DOWN].call(e[ON_MOUSE_DOWN], g))
}
;
this.rotation = function(a) {
b.rotation = a
}
;
this.getButton = function() {
return b
}
;
this.setPosition = function(a, c) {
b.x = a;
b.y = c
}
;
this.setX = function(a) {
b.x = a
}
;
this.setY = function(a) {
b.y = a
}
;
this.getButtonImage = function() {
return b
}
;
this.block = function(a) {
n = a;
b.scaleX = k;
b.scaleY = h
}
;
this.setScaleX = function(a) {
k = b.scaleX = a
}
;
this.getX = function() {
return b.x
}
;
this.getY = function() {
return b.y
}
;
this.pulseAnimation = function() {
createjs.Tween.get(b).to({
scaleX: .9 * k,
scaleY: .9 * h
}, 850, createjs.Ease.quadOut).to({
scaleX: k,
scaleY: h
}, 650, createjs.Ease.quadIn).call(function() {
q.pulseAnimation()
})
}
;
this.trebleAnimation = function() {
createjs.Tween.get(b).to({
rotation: 5
}, 75, createjs.Ease.quadOut).to({
rotation: -5
}, 140, createjs.Ease.quadIn).to({
rotation: 0
}, 75, createjs.Ease.quadIn).wait(750).call(function() {
q.trebleAnimation()
})
}
;
this.removeAllTweens = function() {
createjs.Tween.removeTweens(b)
}
;
var l = void 0 === f ? s_oStage : f;
this._init(m, a, d);
var q = this;
return this
}
function CMenu() {
var m, a, d, f, c, e, b, g, k, h, n, l, q, p = null, r = null;
this._init = function() {
b = createBitmap(s_oSpriteLibrary.getSprite("bg_menu"));
s_oStage.addChild(b);
g = createBitmap(s_oSpriteLibrary.getSprite("logo_menu"));
g.x = 200;
g.y = 90;
s_oStage.addChild(g);
var u = s_oSpriteLibrary.getSprite("but_play");
k = new CGfxButton(CANVAS_WIDTH / 2 + 150,CANVAS_HEIGHT - 170,u);
k.addEventListener(ON_MOUSE_UP, this._onButPlayRelease, this);
if (!1 === DISABLE_SOUND_MOBILE || !1 === s_bMobile)
u = s_oSpriteLibrary.getSprite("audio_icon"),
c = CANVAS_WIDTH - u.height / 2 - 10,
e = u.height / 2 + 10,
n = new CToggle(c,e,u,s_bAudioActive,s_oStage),
n.addEventListener(ON_MOUSE_UP, this._onAudioToggle, this);
u = s_oSpriteLibrary.getSprite("but_credits");
d = u.height / 2 + 10;
f = u.height / 2 + 10;
l = new CGfxButton(d,f,u,s_oStage);
l.addEventListener(ON_MOUSE_UP, this._onCredits, this);
u = window.document;
var w = u.documentElement;
p = w.requestFullscreen || w.mozRequestFullScreen || w.webkitRequestFullScreen || w.msRequestFullscreen;
r = u.exitFullscreen || u.mozCancelFullScreen || u.webkitExitFullscreen || u.msExitFullscreen;
!1 === ENABLE_FULLSCREEN && (p = !1);
p && screenfull.enabled && (u = s_oSpriteLibrary.getSprite("but_fullscreen"),
m = d + u.width / 2 + 10,
a = u.height / 2 + 10,//f,
q = new CToggle(m,a,u,s_bFullscreen,s_oStage),
q.addEventListener(ON_MOUSE_UP, this._onFullscreenRelease, this));
h = new createjs.Shape;
h.graphics.beginFill("black").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
s_oStage.addChild(h);
createjs.Tween.get(h).to({
alpha: 0
}, 1E3).call(function() {
h.visible = !1
});
this.refreshButtonPos(s_iOffsetX, s_iOffsetY)
}
;
this.unload = function() {
k.unload();
k = null;
h.visible = !1;
l.unload();
if (!1 === DISABLE_SOUND_MOBILE || !1 === s_bMobile)
n.unload(),
n = null;
p && screenfull.enabled && q.unload();
s_oStage.removeAllChildren();
s_oMenu = null
}
;
this.refreshButtonPos = function(b, h) {
!1 !== DISABLE_SOUND_MOBILE && !1 !== s_bMobile || n.setPosition(c - b, h + e);
p && screenfull.enabled && q.setPosition(m + s_iOffsetX, a + s_iOffsetY);
l.setPosition(d + b, h + f)
}
;
this._onAudioToggle = function() {
Howler.mute(s_bAudioActive);
s_bAudioActive = !s_bAudioActive
}
;
this._onCredits = function() {
new CCreditsPanel
}
;
this._onButPlayRelease = function() {
console.log("玩家进入")
window.start_game++
window['uptap'].GameEvent("start_game",window.start_game);
// gdsdk.showBanner();
console.log("点击开始游戏!")
this.unload();
isIOS() && null === s_oSoundTrack && (s_oSoundTrack = playSound("soundtrack", 1, !0));
s_oMain.gotoTeamChoose()
}
;
this.resetFullscreenBut = function() {
p && screenfull.enabled && q.setActive(s_bFullscreen)
}
;
this._onFullscreenRelease = function() {
s_bFullscreen ? r.call(window.document) : p.call(window.document.documentElement);
sizeHandler()
}
;
s_oMenu = this;
this._init()
}
var s_oMenu = null;
function CInterface() {
var m, a, d, f, c, e, b, g, k, h, n, l, q, p, r, u, w, x, t, v, A, C, B, D, E = null, F = null, H, K = null, I, N = null, y = null, M;
this._init = function() {
var y = s_oSpriteLibrary.getSprite("but_exit");
b = CANVAS_WIDTH - y.height / 2 - 5;
g = y.height / 2 + 10;
w = new CGfxButton(b,g,y);
w.addEventListener(ON_MOUSE_UP, this._onExit, this);
y = s_oSpriteLibrary.getSprite("but_pause");
m = b - y.height - 5;
a = g;
x = new CGfxButton(m,a,y);
x.addEventListener(ON_MOUSE_UP, this.onButPauseRelease, this);
!1 === DISABLE_SOUND_MOBILE || !1 === s_bMobile ? (y = s_oSpriteLibrary.getSprite("audio_icon"),
c = m - y.width / 2 - 5,
e = g,
u = new CToggle(c,e,y,s_bAudioActive,s_oStage),
u.addEventListener(ON_MOUSE_UP, this._onAudioToggle, this),
y = s_oSpriteLibrary.getSprite("but_fullscreen"),
d = c - y.width / 2 - 5,
f = e) : (y = s_oSpriteLibrary.getSprite("but_fullscreen"),
d = m - y.width / 2 - 5,
f = g);
var z = window.document
, O = z.documentElement;
E = O.requestFullscreen || O.mozRequestFullScreen || O.webkitRequestFullScreen || O.msRequestFullscreen;
F = z.exitFullscreen || z.mozCancelFullScreen || z.webkitExitFullscreen || z.msExitFullscreen;
!1 === ENABLE_FULLSCREEN && (E = !1);
E && screenfull.enabled && (D = new CToggle(d,f,y,s_bFullscreen,s_oStage),
D.addEventListener(ON_MOUSE_UP, this._onFullscreenRelease, this));
t = s_oSpriteLibrary.getSprite("score_panel");
p = CANVAS_WIDTH / 2 - 260;
r = 35;
H = new CGfxButton(p,r,t,s_oStage);
n = CANVAS_WIDTH / 2 - 315;
A = new createjs.Text(SCORE_TEXT,"30px " + FONT,"#ffffff");
A.x = n;
A.y = 47;
A.textAlign = "center";
A.textBaseline = "alphabetic";
s_oStage.addChild(A);
h = CANVAS_WIDTH / 2 - 150;
C = new createjs.Text("0","30px " + FONT,"#ffffff");
C.x = h;
C.y = 47;
C.textAlign = "right";
C.textBaseline = "alphabetic";
s_oStage.addChild(C);
v = new CBallStatic(s_oStage);
l = CANVAS_WIDTH / 2 - 370;
q = 79;
v.setPosition(l, q);
k = CANVAS_WIDTH / 2 - 350;
B = new createjs.Text("x " + LIVES,"30px " + FONT2,"#143502");
B.x = k;
B.y = 88;
B.textAlign = "left";
B.textBaseline = "alphabetic";
s_oStage.addChild(B);
this.refreshButtonPos(s_iOffsetX, s_iOffsetY)
}
;
this.unload = function() {
if (!1 === DISABLE_SOUND_MOBILE || !1 === s_bMobile)
u.unload(),
u = null;
E && screenfull.enabled && D.unload();
w.unload();
s_oInterface = null
}
;
this.refreshButtonPos = function(y, z) {
w.setPosition(b - y, z + g);
!1 !== DISABLE_SOUND_MOBILE && !1 !== s_bMobile || u.setPosition(c - y, z + e);
E && screenfull.enabled && D.setPosition(d - s_iOffsetX, f + s_iOffsetY);
H.setPosition(p + y, z + r);
v.setPosition(l + y, z + q);
x.setPosition(m - y, z + a);
A.x = n + y;
C.x = h + y;
B.x = k + y;
if (null !== K) {
var O = K.getStartPositionControlLeft();
K.setPositionControlLeft(O.x + y, O.y - z);
O = K.getStartPositionControlRight();
K.setPositionControlRight(O.x - y, O.y - z)
}
}
;
this.createController = function() {
K = new CController
}
;
this.createHitArea = function() {
y = new createjs.Shape;
y.graphics.beginFill("#0f0f0f").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
y.alpha = .01;
y.on("click", function() {});
s_oStage.addChild(y)
}
;
this.setHitAreaVisible = function(b) {
null !== y && (y.visible = b)
}
;
this.createAnimText = function(b, a, c, e, h, l) {
var g = new createjs.Container;
g.scaleX = 0;
g.scaleY = 0;
var n = new createjs.Text(b,a + "px " + FONT2,"#000");
n.x = 0;
n.y = 0;
n.textAlign = "center";
n.textBaseline = "middle";
n.outline = 4;
g.addChild(n);
var p = new createjs.Text(b,a + "px " + FONT2,"#ffffff");
p.x = 0;
p.y = 0;
p.textAlign = "center";
p.textBaseline = "middle";
g.addChild(p);
g.x = CANVAS_WIDTH_HALF;
g.y = CANVAS_HEIGHT_HALF;
c && (M = 0,
s_oInterface.strobeText(p, e));
s_oStage.addChild(g);
createjs.Tween.get(g).to({
scaleX: 1,
scaleY: 1
}, h, createjs.Ease.cubicOut).call(function() {
createjs.Tween.get(g).wait(300).to({
scaleX: 0,
scaleY: 0
}, h, createjs.Ease.cubicOut).call(function() {
c && createjs.Tween.removeTweens(p);
l();
s_oStage.removeChild(g)
})
})
}
;
this.strobeText = function(b, a) {
createjs.Tween.get(b).wait(30).call(function() {
M < a.length - 1 ? M++ : M = 0;
b.color = a[M];
s_oInterface.strobeText(b, a)
})
}
;
this.animBallHit = function() {
var b = s_oSpriteLibrary.getSprite("hit_msg")
, a = createBitmap(b);
a.x = CANVAS_WIDTH_HALF;
a.y = CANVAS_HEIGHT_HALF;
a.regX = .5 * b.width;
a.regY = .5 * b.height;
a.scaleX = 0;
a.scaleY = 0;
s_oStage.addChild(a);
createjs.Tween.get(a).to({
scaleX: 1,
scaleY: 1
}, 500, createjs.Ease.cubicOut).wait(800).call(function() {
s_oGame.afterBallHit();
s_oStage.removeChild(a)
})
}
;
this.viewScore = function(b) {
C.text = b
}
;
this.refreshLivesText = function(b) {
B.text = "x " + b
}
;
this.createHelpPanel = function(b) {
N = new CHelpPanel(0,0,b,s_oSpriteLibrary.getSprite("bg_help"))
}
;
this._onButRestartRelease = function() {
s_oGame.restartGame()
}
;
this.onExitFromHelp = function() {
null !== N && N.unload()
}
;
this.unloadPause = function() {
I.unload();
I = null
}
;
this.onButPauseRelease = function() {
I = new CPause
}
;
this._onAudioToggle = function() {
Howler.mute(s_bAudioActive);
s_bAudioActive = !s_bAudioActive
}
;
this._onExit = function() {
(new CAreYouSurePanel(s_oStage)).show()
}
;
this.resetFullscreenBut = function() {
E && screenfull.enabled && D.setActive(s_bFullscreen)
}
;
this._onFullscreenRelease = function() {
s_bFullscreen ? F.call(window.document) : E.call(window.document.documentElement);
sizeHandler()
}
;
s_oInterface = this;
this._init();
return this
}
var s_oInterface = null;
function CEndPanel(m) {
var a, d, f, c, e, b;
this._init = function(g) {
playSound("buzzer", 1, !1);
a = createBitmap(g);
a.on("click", function() {});
f = new createjs.Text(""," 44px " + FONT2,"#fff");
f.x = CANVAS_WIDTH / 2;
f.y = CANVAS_HEIGHT / 2 - 190;
f.textAlign = "center";
f.textBaseline = "alphabetic";
f.lineHeight = 60;
f.lineWidth = 450;
c = new createjs.Text(""," 40px " + FONT2,"#fff");
c.x = CANVAS_WIDTH / 2;
c.y = CANVAS_HEIGHT / 2;
c.textAlign = "center";
c.textBaseline = "alphabetic";
c.lineHeight = 60;
c.lineWidth = 470;
d = new createjs.Container;
d.alpha = 0;
d.visible = !1;
d.addChild(a, c, f);
g = s_oSpriteLibrary.getSprite("but_restart");
e = new CGfxButton(CANVAS_WIDTH / 2 + 170,CANVAS_HEIGHT_HALF + 160,g,d);
g = s_oSpriteLibrary.getSprite("but_home");
b = new CGfxButton(CANVAS_WIDTH / 2 - 170,CANVAS_HEIGHT_HALF + 160,g,d);
s_oStage.addChild(d)
}
;
this.unload = function() {
a.off("click", function() {});
createjs.Tween.get(d).to({
alpha: 0
}, 500).call(function() {
b.unload();
e.unload();
s_oStage.removeChild(d)
})
}
;
this._initListener = function() {
b.addEventListener(ON_MOUSE_UP, this._onExit, this);
e.addEventListener(ON_MOUSE_UP, this._onRestart, this)
}
;
this.show = function(b) {
console.log("show ads!!")
uptap.ShowScreenVideo("重玩",function(){});
f.text = TEXT_GAMEOVER;
c.text = TEXT_SCORE + b;
d.visible = !0;
var a = this;
createjs.Tween.get(d).to({
alpha: 1
}, 500).call(function() {
a._initListener()
});
$(s_oMain).trigger("end_level", 1);
$(s_oMain).trigger("share_event", b);
$(s_oMain).trigger("save_score", b)
}
;
this._onRestart = function() {
$(s_oMain).trigger("show_interlevel_ad");
this.unload();
s_oGame.resetGame()
}
;
this._onExit = function() {
this.unload();
s_oGame.onExit()
}
;
this._init(m);
return this
}
function CCreditsPanel() {
var m, a, d, f, c, e, b, g;
this._init = function() {
g = new createjs.Container;
s_oStage.addChild(g);
var k = createBitmap(s_oSpriteLibrary.getSprite("bg_menu"));
g.addChild(k);
c = new createjs.Shape;
c.graphics.beginFill("rgba(0,0,0,0.7)").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
g.addChild(c);
k = s_oSpriteLibrary.getSprite("msg_box");
a = createBitmap(k);
a.x = CANVAS_WIDTH / 2;
a.y = CANVAS_HEIGHT / 2;
a.regX = k.width / 2;
a.regY = k.height / 2;
g.addChild(a);
e = new createjs.Shape;
e.graphics.beginFill("#0f0f0f").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
e.alpha = .01;
e.cursor = "pointer";
e.on("click", this._onLogoButRelease);
g.addChild(e);
k = s_oSpriteLibrary.getSprite("but_exit");
m = CANVAS_WIDTH / 2 + 204;
d = new CGfxButton(m,264,k,g);
d.addEventListener(ON_MOUSE_UP, this.unload, this);
f = new createjs.Text(TEXT_CREDITS_DEVELOPED,"48px " + FONT2,"#ffffff");
f.x = CANVAS_WIDTH / 2;
f.y = 350;
f.textAlign = "center";
g.addChild(f);
k = s_oSpriteLibrary.getSprite("logo_credits");
var h = createBitmap(k);
h.regX = k.width / 2;
h.regY = k.height / 2;
h.x = CANVAS_WIDTH / 2;
h.y = 470;
g.addChild(h);
b = new createjs.Text("www.codethislab.com","42px " + FONT2,"#ffffff");
b.x = CANVAS_WIDTH / 2;
b.y = 530;
b.textAlign = "center";
g.addChild(b)
}
;
this.unload = function() {
e.off("click", this._onLogoButRelease);
d.unload();
d = null;
s_oStage.removeChild(g)
}
;
this._onLogoButRelease = function() {
// window.open("http://www.codethislab.com/index.php?&l=en")
console.log("什么鬼?")
}
;
this._init()
}
function CTeamChoose() {
var m, a, d, f, c, e, b, g, k, h, n, l, q, p, r, u = null, w, x, t, v, A, C, B, D, E, F, H, K, I = null, N = null;
this._init = function() {
k = createBitmap(s_oSpriteLibrary.getSprite("bg_select_team"));
s_oStage.addChild(k);
A = new createjs.Container;
F = 0;
H = TEXT_TEAM.length - 1;
D = this.createFlagSelection(PLAYER_SELECTION_FLAG_START_POS.x, PLAYER_SELECTION_FLAG_START_POS.y, 1500, this._onButPlayerTeamChoose);
E = this.createFlagSelection(OPPONENT_SELECTION_FLAG_START_POS.x, OPPONENT_SELECTION_FLAG_START_POS.y, 1500, this._onButOppTeamChoose);
var u = s_oSpriteLibrary.getSprite("flag_selection");
t = createBitmap(u);
t.x = D[0].getX();
t.y = D[0].getY();
t.regX = .5 * u.width;
t.regY = .5 * u.height;
v = createBitmap(u);
v.x = E[TEXT_TEAM.length - 1].getX();
v.y = E[TEXT_TEAM.length - 1].getY();
v.regX = .5 * u.width;
v.regY = .5 * u.height;
s_oStage.addChild(A);
A.y = 12;
l = this.createText(TEXT_SELECT_OPPONENT_TEAM, 22, 200).container;
l.x = CANVAS_WIDTH_HALF + 130;
l.y = 304;
s_oStage.addChild(l);
n = this.createText(TEXT_SELECT_YOUR_TEAM, 22, 200).container;
n.x = CANVAS_WIDTH_HALF - 120;
n.y = 304;
s_oStage.addChild(n);
u = this.createText(TEXT_TEAM[0], 30, 500);
q = u.container;
q.x = CANVAS_WIDTH_HALF - 120;
q.y = CANVAS_HEIGHT_HALF + 132;
C = u.text;
s_oStage.addChild(q);
u = this.createText(TEXT_TEAM[TEXT_TEAM.length - 1], 30, 500);
p = u.container;
p.x = CANVAS_WIDTH_HALF + 120;
p.y = CANVAS_HEIGHT_HALF + 132;
B = u.text;
s_oStage.addChild(p);
if (!1 === DISABLE_SOUND_MOBILE || !1 === s_bMobile)
u = s_oSpriteLibrary.getSprite("audio_icon"),
b = CANVAS_WIDTH - u.width / 2 - 60,
g = u.height / 2 + 10,
w = new CToggle(b,g,u,s_bAudioActive,s_oStage),
w.addEventListener(ON_MOUSE_UP, this._onAudioToggle, this);
u = window.document;
var M = u.documentElement;
I = M.requestFullscreen || M.mozRequestFullScreen || M.webkitRequestFullScreen || M.msRequestFullscreen;
N = u.exitFullscreen || u.mozCancelFullScreen || u.webkitExitFullscreen || u.msExitFullscreen;
!1 === ENABLE_FULLSCREEN && (I = !1);
I && screenfull.enabled && (u = s_oSpriteLibrary.getSprite("but_fullscreen"),
m = u.width / 4 + 10,
a = u.height / 2 + 10,
K = new CToggle(m,a,u,s_bFullscreen,s_oStage),
K.addEventListener(ON_MOUSE_UP, this._onFullscreenRelease, this));
d = .5 * CANVAS_WIDTH + 300;
f = .5 * CANVAS_HEIGHT + 400;
u = s_oSpriteLibrary.getSprite("but_continue");
h = new CGfxButton(d,f,u,s_oStage);
h.addEventListener(ON_MOUSE_UP, this._onButContinueRelease, this);
h.pulseAnimation();
u = s_oSpriteLibrary.getSprite("but_exit");
c = CANVAS_WIDTH - u.width / 2 - 15;
e = u.height / 2 + 10;
x = new CGfxButton(c,e,u,s_oStage);
x.addEventListener(ON_MOUSE_UP, this._onExit, this);
r = new createjs.Shape;
r.graphics.beginFill("black").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
s_oStage.addChild(r);
createjs.Tween.get(r).to({
alpha: 0
}, 1E3).call(function() {
r.visible = !1;
A.addChild(t, v)
});
this.refreshButtonPos(s_iOffsetX, s_iOffsetY)
}
;
this._createFlag = function(b, a, c, h, e, l, g) {
var n = s_oSpriteLibrary.getSprite("flag_" + b);
a = new CGfxButton(a,c,n,g);
a.addEventListenerWithParams(ON_MOUSE_UP, l, this, b);
b = a.getButton();
b.scaleX = 0;
b.scaleY = 0;
createjs.Tween.get(b).wait(h).to({
scaleY: 1,
scaleX: 1
}, e, createjs.Ease.elasticOut);
return a
}
;
this.createFlagSelection = function(b, a, c, h) {
for (var e = [], l = b, g = 0; g < TOT_TEAMS; g++)
e[g] = this._createFlag(g, l, a, Math.floor(500 * Math.random()), c, h, A),
0 === g % MAX_COL_FLAG - 1 ? (l = b,
a += FLAG_OFFSET.y) : l += FLAG_OFFSET.x;
return e
}
;
this.createText = function(b, a, c) {
var e = new createjs.Container;
b = new createjs.Text(b,a + "px " + FONT2,"#ffffff");
b.textAlign = "center";
b.lineWidth = c;
b.x = 0;
b.y = 0;
e.addChild(b);
return {
container: e,
text: b
}
}
;
this.refreshButtonPos = function(l, n) {
x.setPosition(c - l, n + e);
h.setPosition(d - l, f - n);
!1 !== DISABLE_SOUND_MOBILE && !1 !== s_bMobile || w.setPosition(b - l, n + g);
I && screenfull.enabled && K.setPosition(m + s_iOffsetX, a + s_iOffsetY)
}
;
this._onButPlayerTeamChoose = function(b) {
F !== b && H !== b && (t.x = D[b].getX(),
t.y = D[b].getY(),
C.text = TEXT_TEAM[b],
F = b)
}
;
this._onButOppTeamChoose = function(b) {
H !== b && F !== b && (v.x = E[b].getX(),
v.y = E[b].getY(),
B.text = TEXT_TEAM[b],
H = b)
}
;
this.unload = function() {
for (var b = 0; b < D.length; b++)
D[b].unload(),
D[b] = null;
for (b = 0; b < E.length; b++)
E[b].unload(),
E[b] = null;
x.unload();
x = null;
h.unload();
h = null;
null !== u && (u.unload(),
u = null);
if (!1 === DISABLE_SOUND_MOBILE || !1 === s_bMobile)
w.unload(),
w = null;
I && screenfull.enabled && K.unload();
s_oStage.removeAllChildren();
createjs.Tween.removeAllTweens();
s_oTeamChoose = null
}
;
this.loadingScreen = function() {
var b = new createjs.Container;
b.alpha = 0;
u = new CLoadingScreen(b,this);
createjs.Tween.get(b).to({
alpha: 1
}, 250, createjs.Ease.cubicOut)
}
;
this._onExit = function() {
this.unload();
s_oMain.gotoMenu()
}
;
this._onAudioToggle = function() {
Howler.mute(s_bAudioActive);
s_bAudioActive = !s_bAudioActive
}
;
this._onButContinueRelease = function() {
h.block(!0);
this.loadingScreen();
s_oMain._loadChoosedTeam(F, H)
}
;
this.resetFullscreenBut = function() {
I && screenfull.enabled && K.setActive(s_bFullscreen)
}
;
this._onFullscreenRelease = function() {
s_bFullscreen ? N.call(window.document) : I.call(window.document.documentElement);
sizeHandler()
}
;
s_oTeamChoose = this;
this._init()
}
var s_oTeamChoose = null;
function CPause() {
var m, a;
this._init = function() {
var d = new createjs.Container;
d.alpha = 1;
m = new createjs.Shape;
m.graphics.beginFill("black").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
m.alpha = .5;
var f = new createjs.Shape;
f.graphics.beginFill("#0f0f0f").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
m.hitArea = f;
m.on("click", function() {});
d.addChild(m);
f = s_oSpriteLibrary.getSprite("msg_box");
var c = createBitmap(f);
c.x = CANVAS_WIDTH_HALF;
c.y = CANVAS_HEIGHT_HALF;
c.regX = .5 * f.width;
c.regY = .5 * f.height;
d.addChild(c);
f = new createjs.Text(TEXT_PAUSE,"80px " + FONT2,"#ffffff");
f.x = .5 * CANVAS_WIDTH;
f.y = .5 * CANVAS_HEIGHT - 200;
f.textAlign = "center";
f.lineWidth = 600;
d.addChild(f);
f = s_oSpriteLibrary.getSprite("but_continue");
a = new CGfxButton(.5 * CANVAS_WIDTH,.5 * CANVAS_HEIGHT + 70,f,d);
a.addEventListenerWithParams(ON_MOUSE_UP, this._onLeavePause, this, d);
a.pulseAnimation();
s_oStage.addChild(d);
s_oGame.pause(!0)
}
;
this.unload = function() {
m.removeAllEventListeners();
a.unload();
a = null;
s_oStage.removeChild(void 0)
}
;
this._onLeavePause = function(a) {
s_oGame.pause(!1);
createjs.Tween.get(a).to({
alpha: 0
}, 100, createjs.quartIn).call(function() {
s_oInterface.unloadPause()
})
}
;
this._init();
return this
}
function CAreYouSurePanel(m) {
var a, d, f, c, e, b;
this._init = function() {
e = new createjs.Container;
e.alpha = 0;
g.addChild(e);
b = new createjs.Shape;
b.graphics.beginFill("black").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
b.alpha = .5;
b.on("click", function() {});
e.addChild(b);
var k = s_oSpriteLibrary.getSprite("msg_box");
a = createBitmap(k);
a.x = CANVAS_WIDTH_HALF;
a.y = CANVAS_HEIGHT_HALF;
a.regX = .5 * k.width;
a.regY = .5 * k.height;
e.addChild(a);
d = new createjs.Text(TEXT_ARE_SURE,"70px " + FONT2,"#ffffff");
d.x = CANVAS_WIDTH / 2 + 10;
d.y = CANVAS_HEIGHT_HALF - 120;
d.textAlign = "center";
d.textBaseline = "middle";
d.lineWidth = 450;
e.addChild(d);
f = new CGfxButton(CANVAS_WIDTH / 2 + 160,.5 * CANVAS_HEIGHT + 150,s_oSpriteLibrary.getSprite("but_yes"),e);
f.addEventListener(ON_MOUSE_UP, this._onButYes, this);
c = new CGfxButton(CANVAS_WIDTH / 2 - 160,.5 * CANVAS_HEIGHT + 150,s_oSpriteLibrary.getSprite("but_no"),e);
c.addEventListener(ON_MOUSE_UP, this._onButNo, this)
}
;
this.show = function() {
createjs.Tween.get(e).to({
alpha: 1
}, 150, createjs.quartOut).call(function() {
s_oGame.pause(!0)
})
}
;
this.unload = function() {
createjs.Tween.get(e).to({
alpha: 0
}, 150, createjs.quartOut).call(function() {
g.removeChild(e, b)
})
}
;
this._onButYes = function() {
createjs.Ticker.paused = !1;
this.unload();
s_oGame.onExit();
b.removeAllEventListeners()
}
;
this._onButNo = function() {
s_oGame.pause(!1);
this.unload();
b.removeAllEventListeners()
}
;
var g = m;
this._init()
}
!function(m) {
if ("object" == typeof exports && "undefined" != typeof module)
module.exports = m();
else {
var a;
"undefined" != typeof window ? a = window : "undefined" != typeof global ? a = global : "undefined" != typeof self && (a = self);
a.CANNON = m()
}
}(function() {
return function c(a, d, f) {
function e(g, h) {
if (!d[g]) {
if (!a[g]) {
var n = "function" == typeof require && require;
if (!h && n)
return n(g, !0);
if (b)
return b(g, !0);
throw Error("Cannot find module '" + g + "'");
}
n = d[g] = {
exports: {}
};
a[g][0].call(n.exports, function(b) {
var c = a[g][1][b];
return e(c ? c : b)
}, n, n.exports, c, a, d, f)
}
return d[g].exports
}
for (var b = "function" == typeof require && require, g = 0; g < f.length; g++)
e(f[g]);
return e
}({
1: [function(a, d, f) {
d.exports = {
name: "cannon",
version: "0.6.2",
description: "A lightweight 3D physics engine written in JavaScript.",
homepage: "https://github.com/schteppe/cannon.js",
author: "Stefan Hedman (http://steffe.se)",
keywords: ["cannon.js", "cannon", "physics", "engine", "3d"],
main: "./build/cannon.js",
engines: {
node: "*"
},
repository: {
type: "git",
url: "https://github.com/schteppe/cannon.js.git"
},
bugs: {
url: "https://github.com/schteppe/cannon.js/issues"
},
licenses: [{
type: "MIT"
}],
devDependencies: {
jshint: "latest",
"uglify-js": "latest",
nodeunit: "^0.9.0",
grunt: "~0.4.0",
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-nodeunit": "^0.4.1",
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-uglify": "^0.5.1",
"grunt-browserify": "^2.1.4",
"grunt-contrib-yuidoc": "^0.5.2",
browserify: "*"
},
dependencies: {}
}
}
, {}],
2: [function(a, d, f) {
d.exports = {
version: a("../package.json").version,
AABB: a("./collision/AABB"),
ArrayCollisionMatrix: a("./collision/ArrayCollisionMatrix"),
Body: a("./objects/Body"),
Box: a("./shapes/Box"),
Broadphase: a("./collision/Broadphase"),
Constraint: a("./constraints/Constraint"),
ContactEquation: a("./equations/ContactEquation"),
Narrowphase: a("./world/Narrowphase"),
ConeTwistConstraint: a("./constraints/ConeTwistConstraint"),
ContactMaterial: a("./material/ContactMaterial"),
ConvexPolyhedron: a("./shapes/ConvexPolyhedron"),
Cylinder: a("./shapes/Cylinder"),
DistanceConstraint: a("./constraints/DistanceConstraint"),
Equation: a("./equations/Equation"),
EventTarget: a("./utils/EventTarget"),
FrictionEquation: a("./equations/FrictionEquation"),
GSSolver: a("./solver/GSSolver"),
GridBroadphase: a("./collision/GridBroadphase"),
Heightfield: a("./shapes/Heightfield"),
HingeConstraint: a("./constraints/HingeConstraint"),
LockConstraint: a("./constraints/LockConstraint"),
Mat3: a("./math/Mat3"),
Material: a("./material/Material"),
NaiveBroadphase: a("./collision/NaiveBroadphase"),
ObjectCollisionMatrix: a("./collision/ObjectCollisionMatrix"),
Pool: a("./utils/Pool"),
Particle: a("./shapes/Particle"),
Plane: a("./shapes/Plane"),
PointToPointConstraint: a("./constraints/PointToPointConstraint"),
Quaternion: a("./math/Quaternion"),
Ray: a("./collision/Ray"),
RaycastVehicle: a("./objects/RaycastVehicle"),
RaycastResult: a("./collision/RaycastResult"),
RigidVehicle: a("./objects/RigidVehicle"),
RotationalEquation: a("./equations/RotationalEquation"),
RotationalMotorEquation: a("./equations/RotationalMotorEquation"),
SAPBroadphase: a("./collision/SAPBroadphase"),
SPHSystem: a("./objects/SPHSystem"),
Shape: a("./shapes/Shape"),
Solver: a("./solver/Solver"),
Sphere: a("./shapes/Sphere"),
SplitSolver: a("./solver/SplitSolver"),
Spring: a("./objects/Spring"),
Trimesh: a("./shapes/Trimesh"),
Vec3: a("./math/Vec3"),
Vec3Pool: a("./utils/Vec3Pool"),
World: a("./world/World")
}
}
, {
"../package.json": 1,
"./collision/AABB": 3,
"./collision/ArrayCollisionMatrix": 4,
"./collision/Broadphase": 5,
"./collision/GridBroadphase": 6,
"./collision/NaiveBroadphase": 7,
"./collision/ObjectCollisionMatrix": 8,
"./collision/Ray": 9,
"./collision/RaycastResult": 10,
"./collision/SAPBroadphase": 11,
"./constraints/ConeTwistConstraint": 12,
"./constraints/Constraint": 13,
"./constraints/DistanceConstraint": 14,
"./constraints/HingeConstraint": 15,
"./constraints/LockConstraint": 16,
"./constraints/PointToPointConstraint": 17,
"./equations/ContactEquation": 19,
"./equations/Equation": 20,
"./equations/FrictionEquation": 21,
"./equations/RotationalEquation": 22,
"./equations/RotationalMotorEquation": 23,
"./material/ContactMaterial": 24,
"./material/Material": 25,
"./math/Mat3": 27,
"./math/Quaternion": 28,
"./math/Vec3": 30,
"./objects/Body": 31,
"./objects/RaycastVehicle": 32,
"./objects/RigidVehicle": 33,
"./objects/SPHSystem": 34,
"./objects/Spring": 35,
"./shapes/Box": 37,
"./shapes/ConvexPolyhedron": 38,
"./shapes/Cylinder": 39,
"./shapes/Heightfield": 40,
"./shapes/Particle": 41,
"./shapes/Plane": 42,
"./shapes/Shape": 43,
"./shapes/Sphere": 44,
"./shapes/Trimesh": 45,
"./solver/GSSolver": 46,
"./solver/Solver": 47,
"./solver/SplitSolver": 48,
"./utils/EventTarget": 49,
"./utils/Pool": 51,
"./utils/Vec3Pool": 54,
"./world/Narrowphase": 55,
"./world/World": 56
}],
3: [function(a, d, f) {
function c(b) {
b = b || {};
this.lowerBound = new e;
b.lowerBound && this.lowerBound.copy(b.lowerBound);
this.upperBound = new e;
b.upperBound && this.upperBound.copy(b.upperBound)
}
var e = a("../math/Vec3");
a("../utils/Utils");
d.exports = c;
var b = new e;
c.prototype.setFromPoints = function(a, c, e, g) {
var h = this.lowerBound
, l = this.upperBound;
h.copy(a[0]);
e && e.vmult(h, h);
l.copy(h);
for (var n = 1; n < a.length; n++) {
var d = a[n];
e && (e.vmult(d, b),
d = b);
d.x > l.x && (l.x = d.x);
d.x < h.x && (h.x = d.x);
d.y > l.y && (l.y = d.y);
d.y < h.y && (h.y = d.y);
d.z > l.z && (l.z = d.z);
d.z < h.z && (h.z = d.z)
}
c && (c.vadd(h, h),
c.vadd(l, l));
g && (h.x -= g,
h.y -= g,
h.z -= g,
l.x += g,
l.y += g,
l.z += g);
return this
}
;
c.prototype.copy = function(b) {
this.lowerBound.copy(b.lowerBound);
this.upperBound.copy(b.upperBound);
return this
}
;
c.prototype.clone = function() {
return (new c).copy(this)
}
;
c.prototype.extend = function(b) {
var a = b.lowerBound.x;
this.lowerBound.x > a && (this.lowerBound.x = a);
a = b.upperBound.x;
this.upperBound.x < a && (this.upperBound.x = a);
a = b.lowerBound.y;
this.lowerBound.y > a && (this.lowerBound.y = a);
a = b.upperBound.y;
this.upperBound.y < a && (this.upperBound.y = a);
a = b.lowerBound.z;
this.lowerBound.z > a && (this.lowerBound.z = a);
a = b.upperBound.z;
this.upperBound.z < a && (this.upperBound.z = a)
}
;
c.prototype.overlaps = function(b) {
var a = this.lowerBound
, c = this.upperBound
, e = b.lowerBound;
b = b.upperBound;
return (e.x <= c.x && c.x <= b.x || a.x <= b.x && b.x <= c.x) && (e.y <= c.y && c.y <= b.y || a.y <= b.y && b.y <= c.y) && (e.z <= c.z && c.z <= b.z || a.z <= b.z && b.z <= c.z)
}
;
c.prototype.contains = function(b) {
var a = this.lowerBound
, c = this.upperBound
, e = b.lowerBound;
b = b.upperBound;
return a.x <= e.x && c.x >= b.x && a.y <= e.y && c.y >= b.y && a.z <= e.z && c.z >= b.z
}
;
c.prototype.getCorners = function(b, a, c, e, g, d, f, u) {
var h = this.lowerBound
, l = this.upperBound;
b.copy(h);
a.set(l.x, h.y, h.z);
c.set(l.x, l.y, h.z);
e.set(h.x, l.y, l.z);
g.set(l.x, h.y, h.z);
d.set(h.x, l.y, h.z);
f.set(h.x, h.y, l.z);
u.copy(l)
}
;
var g = [new e, new e, new e, new e, new e, new e, new e, new e];
c.prototype.toLocalFrame = function(b, a) {
this.getCorners(g[0], g[1], g[2], g[3], g[4], g[5], g[6], g[7]);
for (var c = 0; 8 !== c; c++) {
var e = g[c];
b.pointToLocal(e, e)
}
return a.setFromPoints(g)
}
;
c.prototype.toWorldFrame = function(b, a) {
this.getCorners(g[0], g[1], g[2], g[3], g[4], g[5], g[6], g[7]);
for (var c = 0; 8 !== c; c++) {
var e = g[c];
b.pointToWorld(e, e)
}
return a.setFromPoints(g)
}
}
, {
"../math/Vec3": 30,
"../utils/Utils": 53
}],
4: [function(a, d, f) {
function c() {
this.matrix = []
}
d.exports = c;
c.prototype.get = function(a, b) {
a = a.index;
b = b.index;
if (b > a) {
var c = b;
b = a;
a = c
}
return this.matrix[(a * (a + 1) >> 1) + b - 1]
}
;
c.prototype.set = function(a, b, c) {
a = a.index;
b = b.index;
if (b > a) {
var e = b;
b = a;
a = e
}
this.matrix[(a * (a + 1) >> 1) + b - 1] = c ? 1 : 0
}
;
c.prototype.reset = function() {
for (var a = 0, b = this.matrix.length; a !== b; a++)
this.matrix[a] = 0
}
;
c.prototype.setNumObjects = function(a) {
this.matrix.length = a * (a - 1) >> 1
}
}
, {}],
5: [function(a, d, f) {
function c() {
this.world = null;
this.useBoundingBoxes = !1;
this.dirty = !0
}
var e = a("../objects/Body");
f = a("../math/Vec3");
var b = a("../math/Quaternion");
a("../shapes/Shape");
a("../shapes/Plane");
d.exports = c;
c.prototype.collisionPairs = function(b, a, c) {
throw Error("collisionPairs not implemented for this BroadPhase class!");
}
;
var g = e.STATIC | e.KINEMATIC;
c.prototype.needBroadphaseCollision = function(b, a) {
return 0 !== (b.collisionFilterGroup & a.collisionFilterMask) && 0 !== (a.collisionFilterGroup & b.collisionFilterMask) && (0 === (b.type & g) && b.sleepState !== e.SLEEPING || 0 === (a.type & g) && a.sleepState !== e.SLEEPING) ? !0 : !1
}
;
c.prototype.intersectionTest = function(b, a, c, e) {
this.useBoundingBoxes ? this.doBoundingBoxBroadphase(b, a, c, e) : this.doBoundingSphereBroadphase(b, a, c, e)
}
;
var k = new f;
new f;
new b;
new f;
c.prototype.doBoundingSphereBroadphase = function(b, a, c, e) {
a.position.vsub(b.position, k);
var h = Math.pow(b.boundingRadius + a.boundingRadius, 2);
k.norm2() < h && (c.push(b),
e.push(a))
}
;
c.prototype.doBoundingBoxBroadphase = function(b, a, c, e) {
b.aabbNeedsUpdate && b.computeAABB();
a.aabbNeedsUpdate && a.computeAABB();
b.aabb.overlaps(a.aabb) && (c.push(b),
e.push(a))
}
;
var h = {
keys: []
}
, n = []
, l = [];
c.prototype.makePairsUnique = function(b, a) {
for (var c = b.length, e = 0; e !== c; e++)
n[e] = b[e],
l[e] = a[e];
b.length = 0;
for (e = a.length = 0; e !== c; e++) {
var g = n[e].id
, d = l[e].id;
g = g < d ? g + "," + d : d + "," + g;
h[g] = e;
h.keys.push(g)
}
for (e = 0; e !== h.keys.length; e++)
g = h.keys.pop(),
c = h[g],
b.push(n[c]),
a.push(l[c]),
delete h[g]
}
;
c.prototype.setWorld = function(b) {}
;
var q = new f;
c.boundingSphereCheck = function(b, a) {
b.position.vsub(a.position, q);
return Math.pow(b.shape.boundingSphereRadius + a.shape.boundingSphereRadius, 2) > q.norm2()
}
;
c.prototype.aabbQuery = function(b, a, c) {
console.warn(".aabbQuery is not implemented in this Broadphase subclass.");
return []
}
}
, {
"../math/Quaternion": 28,
"../math/Vec3": 30,
"../objects/Body": 31,
"../shapes/Plane": 42,
"../shapes/Shape": 43
}],
6: [function(a, d, f) {
function c(a, c, g, d, p) {
e.apply(this);
this.nx = g || 10;
this.ny = d || 10;
this.nz = p || 10;
this.aabbMin = a || new b(100,100,100);
this.aabbMax = c || new b(-100,-100,-100);
a = this.nx * this.ny * this.nz;
if (0 >= a)
throw "GridBroadphase: Each dimension's n must be >0";
this.bins = [];
this.binLengths = [];
this.bins.length = a;
this.binLengths.length = a;
for (c = 0; c < a; c++)
this.bins[c] = [],
this.binLengths[c] = 0
}
d.exports = c;
var e = a("./Broadphase")
, b = a("../math/Vec3")
, g = a("../shapes/Shape");
c.prototype = new e;
c.prototype.constructor = c;
var k = new b;
new b;
c.prototype.collisionPairs = function(b, a, c) {
function e(b, a, c, e, h, g, l) {
b = (b - E) * K | 0;
a = (a - F) * I | 0;
c = (c - H) * N | 0;
e = G((e - E) * K);
h = G((h - F) * I);
g = G((g - H) * N);
0 > b ? b = 0 : b >= n && (b = n - 1);
0 > a ? a = 0 : a >= f && (a = f - 1);
0 > c ? c = 0 : c >= t && (c = t - 1);
0 > e ? e = 0 : e >= n && (e = n - 1);
0 > h ? h = 0 : h >= f && (h = f - 1);
0 > g ? g = 0 : g >= t && (g = t - 1);
b *= v;
a *= A;
c *= 1;
e *= v;
h *= A;
for (g *= 1; b <= e; b += v)
for (var d = a; d <= h; d += A)
for (var p = c; p <= g; p += 1) {
var k = b + d + p;
O[k][L[k]++] = l
}
}
var h = b.numObjects();
b = b.bodies;
var l = this.aabbMax
, d = this.aabbMin
, n = this.nx
, f = this.ny
, t = this.nz
, v = f * t
, A = t
, C = l.x
, B = l.y
, D = l.z
, E = d.x
, F = d.y
, H = d.z
, K = n / (C - E)
, I = f / (B - F)
, N = t / (D - H);
C = (C - E) / n;
var y = (B - F) / f;
D = (D - H) / t;
var M = .5 * Math.sqrt(C * C + y * y + D * D);
B = g.types;
var J = B.SPHERE
, z = B.PLANE
, O = this.bins
, L = this.binLengths;
B = this.bins.length;
for (d = 0; d !== B; d++)
L[d] = 0;
var G = Math.ceil;
d = Math.min;
l = Math.max;
for (d = 0; d !== h; d++) {
l = b[d];
var Q = l.shape;
switch (Q.type) {
case J:
var P = l.position.x
, U = l.position.y
, V = l.position.z;
Q = Q.radius;
e(P - Q, U - Q, V - Q, P + Q, U + Q, V + Q, l);
break;
case z:
Q.worldNormalNeedsUpdate && Q.computeWorldNormal(l.quaternion);
V = Q.worldNormal;
Q = F + .5 * y - l.position.y;
var X = H + .5 * D - l.position.z
, R = k;
R.set(E + .5 * C - l.position.x, Q, X);
for (var W = P = 0; P !== n; P++,
W += v,
R.y = Q,
R.x += C)
for (var S = U = 0; U !== f; U++,
S += A,
R.z = X,
R.y += y)
for (var Y = 0, T = 0; Y !== t; Y++,
T += 1,
R.z += D)
if (R.dot(V) < M) {
var Z = W + S + T;
O[Z][L[Z]++] = l
}
break;
default:
l.aabbNeedsUpdate && l.computeAABB(),
e(l.aabb.lowerBound.x, l.aabb.lowerBound.y, l.aabb.lowerBound.z, l.aabb.upperBound.x, l.aabb.upperBound.y, l.aabb.upperBound.z, l)
}
}
for (d = 0; d !== B; d++)
if (h = L[d],
1 < h)
for (b = O[d],
P = 0; P !== h; P++)
for (l = b[P],
U = 0; U !== P; U++)
C = b[U],
this.needBroadphaseCollision(l, C) && this.intersectionTest(l, C, a, c);
this.makePairsUnique(a, c)
}
}
, {
"../math/Vec3": 30,
"../shapes/Shape": 43,
"./Broadphase": 5
}],
7: [function(a, d, f) {
function c() {
e.apply(this)
}
d.exports = c;
var e = a("./Broadphase");
a = a("./AABB");
c.prototype = new e;
c.prototype.constructor = c;
c.prototype.collisionPairs = function(b, a, c) {
b = b.bodies;
var e = b.length, g, l;
for (g = 0; g !== e; g++)
for (l = 0; l !== g; l++) {
var d = b[g];
var p = b[l];
this.needBroadphaseCollision(d, p) && this.intersectionTest(d, p, a, c)
}
}
;
new a;
c.prototype.aabbQuery = function(b, a, c) {
c = c || [];
for (var e = 0; e < b.bodies.length; e++) {
var g = b.bodies[e];
g.aabbNeedsUpdate && g.computeAABB();
g.aabb.overlaps(a) && c.push(g)
}
return c
}
}
, {
"./AABB": 3,
"./Broadphase": 5
}],
8: [function(a, d, f) {
function c() {
this.matrix = {}
}
d.exports = c;
c.prototype.get = function(a, b) {
a = a.id;
b = b.id;
if (b > a) {
var c = b;
b = a;
a = c
}
return a + "-" + b in this.matrix
}
;
c.prototype.set = function(a, b, c) {
a = a.id;
b = b.id;
if (b > a) {
var e = b;
b = a;
a = e
}
c ? this.matrix[a + "-" + b] = !0 : delete this.matrix[a + "-" + b]
}
;
c.prototype.reset = function() {
this.matrix = {}
}
;
c.prototype.setNumObjects = function(a) {}
}
, {}],
9: [function(a, d, f) {
function c(a, e) {
this.from = a ? a.clone() : new b;
this.to = e ? e.clone() : new b;
this._direction = new b;
this.precision = 1E-4;
this.checkCollisionResponse = !0;
this.skipBackfaces = !1;
this.collisionFilterGroup = this.collisionFilterMask = -1;
this.mode = c.ANY;
this.result = new k;
this.hasHit = !1;
this.callback = function(b) {}
}
function e(b, a, c, e) {
e.vsub(a, J);
c.vsub(a, l);
b.vsub(a, q);
b = J.dot(J);
a = J.dot(l);
c = J.dot(q);
e = l.dot(l);
var h = l.dot(q), g, d;
return 0 <= (g = e * c - a * h) && 0 <= (d = b * h - a * c) && g + d < b * e - a * a
}
d.exports = c;
var b = a("../math/Vec3");
d = a("../math/Quaternion");
var g = a("../math/Transform");
a("../shapes/ConvexPolyhedron");
a("../shapes/Box");
var k = a("../collision/RaycastResult");
f = a("../shapes/Shape");
a = a("../collision/AABB");
c.prototype.constructor = c;
c.CLOSEST = 1;
c.ANY = 2;
c.ALL = 4;
var h = new a
, n = [];
c.prototype.intersectWorld = function(b, a) {
this.mode = a.mode || c.ANY;
this.result = a.result || new k;
this.skipBackfaces = !!a.skipBackfaces;
this.collisionFilterMask = "undefined" !== typeof a.collisionFilterMask ? a.collisionFilterMask : -1;
this.collisionFilterGroup = "undefined" !== typeof a.collisionFilterGroup ? a.collisionFilterGroup : -1;
a.from && this.from.copy(a.from);
a.to && this.to.copy(a.to);
this.callback = a.callback || function() {}
;
this.hasHit = !1;
this.result.reset();
this._updateDirection();
this.getAABB(h);
n.length = 0;
b.broadphase.aabbQuery(b, h, n);
this.intersectBodies(n);
return this.hasHit
}
;
var l = new b
, q = new b;
c.pointInTriangle = e;
var p = new b
, r = new d;
c.prototype.intersectBody = function(b, a) {
a && (this.result = a,
this._updateDirection());
var c = this.checkCollisionResponse;
if ((!c || b.collisionResponse) && 0 !== (this.collisionFilterGroup & b.collisionFilterMask) && 0 !== (b.collisionFilterGroup & this.collisionFilterMask))
for (var e = 0, h = b.shapes.length; e < h; e++) {
var g = b.shapes[e];
if (!c || g.collisionResponse)
if (b.quaternion.mult(b.shapeOrientations[e], r),
b.quaternion.vmult(b.shapeOffsets[e], p),
p.vadd(b.position, p),
this.intersectShape(g, r, p, b),
this.result._shouldStop)
break
}
}
;
c.prototype.intersectBodies = function(b, a) {
a && (this.result = a,
this._updateDirection());
for (var c = 0, e = b.length; !this.result._shouldStop && c < e; c++)
this.intersectBody(b[c])
}
;
c.prototype._updateDirection = function() {
this.to.vsub(this.from, this._direction);
this._direction.normalize()
}
;
c.prototype.intersectShape = function(b, a, c, e) {
var h = this.from
, g = this._direction;
c.vsub(h, J);
var l = J.dot(g);
g.mult(l, z);
z.vadd(h, z);
c.distanceTo(z) > b.boundingSphereRadius || (h = this[b.type]) && h.call(this, b, a, c, e)
}
;
new b;
new b;
var u = new b
, w = new b
, x = new b
, t = new b;
new b;
new k;
c.prototype.intersectBox = function(b, a, c, e) {
return this.intersectConvex(b.convexPolyhedronRepresentation, a, c, e)
}
;
c.prototype[f.types.BOX] = c.prototype.intersectBox;
c.prototype.intersectPlane = function(a, c, e, h) {
var g = this.from
, l = this.to
, d = this._direction
, n = new b(0,0,1);
c.vmult(n, n);
var p = new b;
g.vsub(e, p);
c = p.dot(n);
l.vsub(e, p);
p = p.dot(n);
if (!(0 < c * p || g.distanceTo(l) < c || (p = n.dot(d),
Math.abs(p) < this.precision))) {
var k = new b;
l = new b;
c = new b;
g.vsub(e, k);
e = -n.dot(k) / p;
d.scale(e, l);
g.vadd(l, c);
this.reportIntersection(n, c, a, h, -1)
}
}
;
c.prototype[f.types.PLANE] = c.prototype.intersectPlane;
c.prototype.getAABB = function(b) {
var a = this.to
, c = this.from;
b.lowerBound.x = Math.min(a.x, c.x);
b.lowerBound.y = Math.min(a.y, c.y);
b.lowerBound.z = Math.min(a.z, c.z);
b.upperBound.x = Math.max(a.x, c.x);
b.upperBound.y = Math.max(a.y, c.y);
b.upperBound.z = Math.max(a.z, c.z)
}
;
var v = {
faceList: [0]
};
c.prototype.intersectHeightfield = function(a, e, h, l) {
var d = new b
, n = new c(this.from,this.to);
g.pointToLocalFrame(h, e, n.from, n.from);
g.pointToLocalFrame(h, e, n.to, n.to);
var p = []
, k = null
, q = null
, f = null
, u = null
, r = a.getIndexOfPosition(n.from.x, n.from.y, p, !1);
r && (k = p[0],
q = p[1],
f = p[0],
u = p[1]);
if (r = a.getIndexOfPosition(n.to.x, n.to.y, p, !1)) {
if (null === k || p[0] < k)
k = p[0];
if (null === f || p[0] > f)
f = p[0];
if (null === q || p[1] < q)
q = p[1];
if (null === u || p[1] > u)
u = p[1]
}
if (null !== k)
for (a.getRectMinMax(k, q, f, u, []),
n = k; n <= f; n++)
for (p = q; p <= u; p++) {
if (this.result._shouldStop)
return;
a.getConvexTrianglePillar(n, p, !1);
g.pointToWorldFrame(h, e, a.pillarOffset, d);
this.intersectConvex(a.pillarConvex, e, d, l, v);
if (this.result._shouldStop)
return;
a.getConvexTrianglePillar(n, p, !0);
g.pointToWorldFrame(h, e, a.pillarOffset, d);
this.intersectConvex(a.pillarConvex, e, d, l, v)
}
}
;
c.prototype[f.types.HEIGHTFIELD] = c.prototype.intersectHeightfield;
var A = new b
, C = new b;
c.prototype.intersectSphere = function(b, a, c, e) {
a = this.from;
var h = this.to
, g = Math.pow(h.x - a.x, 2) + Math.pow(h.y - a.y, 2) + Math.pow(h.z - a.z, 2)
, l = 2 * ((h.x - a.x) * (a.x - c.x) + (h.y - a.y) * (a.y - c.y) + (h.z - a.z) * (a.z - c.z))
, d = Math.pow(l, 2) - 4 * g * (Math.pow(a.x - c.x, 2) + Math.pow(a.y - c.y, 2) + Math.pow(a.z - c.z, 2) - Math.pow(b.radius, 2));
if (!(0 > d))
if (0 === d)
a.lerp(h, d, A),
A.vsub(c, C),
C.normalize(),
this.reportIntersection(C, A, b, e, -1);
else {
var n = (-l - Math.sqrt(d)) / (2 * g);
g = (-l + Math.sqrt(d)) / (2 * g);
0 <= n && 1 >= n && (a.lerp(h, n, A),
A.vsub(c, C),
C.normalize(),
this.reportIntersection(C, A, b, e, -1));
!this.result._shouldStop && 0 <= g && 1 >= g && (a.lerp(h, g, A),
A.vsub(c, C),
C.normalize(),
this.reportIntersection(C, A, b, e, -1))
}
}
;
c.prototype[f.types.SPHERE] = c.prototype.intersectSphere;
var B = new b;
new b;
new b;
var D = new b;
c.prototype.intersectConvex = function(b, a, c, h, g) {
g = g && g.faceList || null;
for (var l = b.faces, d = b.vertices, n = b.faceNormals, p = this._direction, k = this.from, q = k.distanceTo(this.to), f = g ? g.length : l.length, r = this.result, z = 0; !r._shouldStop && z < f; z++) {
var G = g ? g[z] : z
, y = l[G]
, L = n[G]
, F = a
, H = c;
D.copy(d[y[0]]);
F.vmult(D, D);
D.vadd(H, D);
D.vsub(k, D);
F.vmult(L, B);
L = p.dot(B);
if (!(Math.abs(L) < this.precision || (L = B.dot(D) / L,
0 > L)))
for (p.mult(L, u),
u.vadd(k, u),
w.copy(d[y[0]]),
F.vmult(w, w),
H.vadd(w, w),
L = 1; !r._shouldStop && L < y.length - 1; L++) {
x.copy(d[y[L]]);
t.copy(d[y[L + 1]]);
F.vmult(x, x);
F.vmult(t, t);
H.vadd(x, x);
H.vadd(t, t);
var O = u.distanceTo(k);
!e(u, w, x, t) && !e(u, x, w, t) || O > q || this.reportIntersection(B, u, b, h, G)
}
}
}
;
c.prototype[f.types.CONVEXPOLYHEDRON] = c.prototype.intersectConvex;
var E = new b
, F = new b
, H = new b
, K = new b
, I = new b
, N = new b;
new a;
var y = []
, M = new g;
c.prototype.intersectTrimesh = function(b, a, c, h, l) {
l = b.indices;
var d = this.from
, n = this.to
, p = this._direction;
M.position.copy(c);
M.quaternion.copy(a);
g.vectorToLocalFrame(c, a, p, F);
g.pointToLocalFrame(c, a, d, H);
g.pointToLocalFrame(c, a, n, K);
d = H.distanceSquared(K);
b.tree.rayQuery(this, M, y);
n = 0;
for (p = y.length; !this.result._shouldStop && n !== p; n++) {
var k = y[n];
b.getNormal(k, E);
b.getVertex(l[3 * k], w);
w.vsub(H, D);
var q = F.dot(E);
q = E.dot(D) / q;
0 > q || (F.scale(q, u),
u.vadd(H, u),
b.getVertex(l[3 * k + 1], x),
b.getVertex(l[3 * k + 2], t),
q = u.distanceSquared(H),
!e(u, x, w, t) && !e(u, w, x, t) || q > d || (g.vectorToWorldFrame(a, E, I),
g.pointToWorldFrame(c, a, u, N),
this.reportIntersection(I, N, b, h, k)))
}
y.length = 0
}
;
c.prototype[f.types.TRIMESH] = c.prototype.intersectTrimesh;
c.prototype.reportIntersection = function(b, a, e, h, g) {
var l = this.from
, d = this.to
, n = l.distanceTo(a)
, p = this.result;
if (!(this.skipBackfaces && 0 < b.dot(this._direction)))
switch (p.hitFaceIndex = "undefined" !== typeof g ? g : -1,
this.mode) {
case c.ALL:
this.hasHit = !0;
p.set(l, d, b, a, e, h, n);
p.hasHit = !0;
this.callback(p);
break;
case c.CLOSEST:
if (n < p.distance || !p.hasHit)
this.hasHit = !0,
p.hasHit = !0,
p.set(l, d, b, a, e, h, n);
break;
case c.ANY:
this.hasHit = !0,
p.hasHit = !0,
p.set(l, d, b, a, e, h, n),
p._shouldStop = !0
}
}
;
var J = new b
, z = new b
}
, {
"../collision/AABB": 3,
"../collision/RaycastResult": 10,
"../math/Quaternion": 28,
"../math/Transform": 29,
"../math/Vec3": 30,
"../shapes/Box": 37,
"../shapes/ConvexPolyhedron": 38,
"../shapes/Shape": 43
}],
10: [function(a, d, f) {
function c() {
this.rayFromWorld = new e;
this.rayToWorld = new e;
this.hitNormalWorld = new e;
this.hitPointWorld = new e;
this.hasHit = !1;
this.body = this.shape = null;
this.distance = this.hitFaceIndex = -1;
this._shouldStop = !1
}
var e = a("../math/Vec3");
d.exports = c;
c.prototype.reset = function() {
this.rayFromWorld.setZero();
this.rayToWorld.setZero();
this.hitNormalWorld.setZero();
this.hitPointWorld.setZero();
this.hasHit = !1;
this.body = this.shape = null;
this.distance = this.hitFaceIndex = -1;
this._shouldStop = !1
}
;
c.prototype.abort = function() {
this._shouldStop = !0
}
;
c.prototype.set = function(b, a, c, e, d, l, q) {
this.rayFromWorld.copy(b);
this.rayToWorld.copy(a);
this.hitNormalWorld.copy(c);
this.hitPointWorld.copy(e);
this.shape = d;
this.body = l;
this.distance = q
}
}
, {
"../math/Vec3": 30
}],
11: [function(a, d, f) {
function c(b) {
e.apply(this);
this.axisList = [];
this.world = null;
this.axisIndex = 0;
var a = this.axisList;
this._addBodyHandler = function(b) {
a.push(b.body)
}
;
this._removeBodyHandler = function(b) {
b = a.indexOf(b.body);
-1 !== b && a.splice(b, 1)
}
;
b && this.setWorld(b)
}
a("../shapes/Shape");
var e = a("../collision/Broadphase");
d.exports = c;
c.prototype = new e;
c.prototype.setWorld = function(b) {
for (var a = this.axisList.length = 0; a < b.bodies.length; a++)
this.axisList.push(b.bodies[a]);
b.removeEventListener("addBody", this._addBodyHandler);
b.removeEventListener("removeBody", this._removeBodyHandler);
b.addEventListener("addBody", this._addBodyHandler);
b.addEventListener("removeBody", this._removeBodyHandler);
this.world = b;
this.dirty = !0
}
;
c.insertionSortX = function(b) {
for (var a = 1, c = b.length; a < c; a++) {
for (var e = b[a], d = a - 1; 0 <= d && !(b[d].aabb.lowerBound.x <= e.aabb.lowerBound.x); d--)
b[d + 1] = b[d];
b[d + 1] = e
}
return b
}
;
c.insertionSortY = function(b) {
for (var a = 1, c = b.length; a < c; a++) {
for (var e = b[a], d = a - 1; 0 <= d && !(b[d].aabb.lowerBound.y <= e.aabb.lowerBound.y); d--)
b[d + 1] = b[d];
b[d + 1] = e
}
return b
}
;
c.insertionSortZ = function(b) {
for (var a = 1, c = b.length; a < c; a++) {
for (var e = b[a], d = a - 1; 0 <= d && !(b[d].aabb.lowerBound.z <= e.aabb.lowerBound.z); d--)
b[d + 1] = b[d];
b[d + 1] = e
}
return b
}
;
c.prototype.collisionPairs = function(b, a, e) {
b = this.axisList;
var h = b.length, d = this.axisIndex, l, g;
this.dirty && (this.sortList(),
this.dirty = !1);
for (l = 0; l !== h; l++) {
var p = b[l];
for (g = l + 1; g < h; g++) {
var k = b[g];
if (this.needBroadphaseCollision(p, k)) {
if (!c.checkBounds(p, k, d))
break;
this.intersectionTest(p, k, a, e)
}
}
}
}
;
c.prototype.sortList = function() {
for (var b = this.axisList, a = this.axisIndex, e = b.length, h = 0; h !== e; h++) {
var d = b[h];
d.aabbNeedsUpdate && d.computeAABB()
}
0 === a ? c.insertionSortX(b) : 1 === a ? c.insertionSortY(b) : 2 === a && c.insertionSortZ(b)
}
;
c.checkBounds = function(b, a, c) {
if (0 === c) {
var e = b.position.x;
var d = a.position.x
} else
1 === c ? (e = b.position.y,
d = a.position.y) : 2 === c && (e = b.position.z,
d = a.position.z);
return d - a.boundingRadius < e + b.boundingRadius
}
;
c.prototype.autoDetectAxis = function() {
for (var a = 0, c = 0, e = 0, h = 0, d = 0, l = 0, q = this.axisList, p = q.length, f = 1 / p, u = 0; u !== p; u++) {
var w = q[u]
, x = w.position.x;
a += x;
c += x * x;
x = w.position.y;
e += x;
h += x * x;
w = w.position.z;
d += w;
l += w * w
}
a = c - a * a * f;
e = h - e * e * f;
d = l - d * d * f;
this.axisIndex = a > e ? a > d ? 0 : 2 : e > d ? 1 : 2
}
;
c.prototype.aabbQuery = function(a, c, e) {
e = e || [];
this.dirty && (this.sortList(),
this.dirty = !1);
a = this.axisList;
for (var b = 0; b < a.length; b++) {
var d = a[b];
d.aabbNeedsUpdate && d.computeAABB();
d.aabb.overlaps(c) && e.push(d)
}
return e
}
}
, {
"../collision/Broadphase": 5,
"../shapes/Shape": 43
}],
12: [function(a, d, f) {
function c(a, c, d) {
d = d || {};
var h = "undefined" !== typeof d.maxForce ? d.maxForce : 1E6
, l = d.pivotA ? d.pivotA.clone() : new k
, n = d.pivotB ? d.pivotB.clone() : new k;
this.axisA = d.axisA ? d.axisA.clone() : new k;
this.axisB = d.axisB ? d.axisB.clone() : new k;
e.call(this, a, l, c, n, h);
this.collideConnected = !!d.collideConnected;
this.angle = "undefined" !== typeof d.angle ? d.angle : 0;
l = this.coneEquation = new b(a,c,d);
a = this.twistEquation = new g(a,c,d);
this.twistAngle = "undefined" !== typeof d.twistAngle ? d.twistAngle : 0;
l.maxForce = 0;
l.minForce = -h;
a.maxForce = 0;
a.minForce = -h;
this.equations.push(l, a)
}
d.exports = c;
a("./Constraint");
var e = a("./PointToPointConstraint")
, b = a("../equations/ConeEquation")
, g = a("../equations/RotationalEquation");
a("../equations/ContactEquation");
var k = a("../math/Vec3");
c.prototype = new e;
c.constructor = c;
new k;
new k;
c.prototype.update = function() {
var a = this.bodyA
, b = this.bodyB
, c = this.coneEquation
, d = this.twistEquation;
e.prototype.update.call(this);
a.vectorToWorldFrame(this.axisA, c.axisA);
b.vectorToWorldFrame(this.axisB, c.axisB);
this.axisA.tangents(d.axisA, d.axisA);
a.vectorToWorldFrame(d.axisA, d.axisA);
this.axisB.tangents(d.axisB, d.axisB);
b.vectorToWorldFrame(d.axisB, d.axisB);
c.angle = this.angle;
d.maxAngle = this.twistAngle
}
}
, {
"../equations/ConeEquation": 18,
"../equations/ContactEquation": 19,
"../equations/RotationalEquation": 22,
"../math/Vec3": 30,
"./Constraint": 13,
"./PointToPointConstraint": 17
}],
13: [function(a, d, f) {
function c(a, d, f) {
f = e.defaults(f, {
collideConnected: !0,
wakeUpBodies: !0
});
this.equations = [];
this.bodyA = a;
this.bodyB = d;
this.id = c.idCounter++;
this.collideConnected = f.collideConnected;
f.wakeUpBodies && (a && a.wakeUp(),
d && d.wakeUp())
}
d.exports = c;
var e = a("../utils/Utils");
c.prototype.update = function() {
throw Error("method update() not implmemented in this Constraint subclass!");
}
;
c.prototype.enable = function() {
for (var a = this.equations, c = 0; c < a.length; c++)
a[c].enabled = !0
}
;
c.prototype.disable = function() {
for (var a = this.equations, c = 0; c < a.length; c++)
a[c].enabled = !1
}
;
c.idCounter = 0
}
, {
"../utils/Utils": 53
}],
14: [function(a, d, f) {
function c(a, c, d, n) {
e.call(this, a, c);
"undefined" === typeof d && (d = a.position.distanceTo(c.position));
"undefined" === typeof n && (n = 1E6);
this.distance = d;
a = this.distanceEquation = new b(a,c);
this.equations.push(a);
a.minForce = -n;
a.maxForce = n
}
d.exports = c;
var e = a("./Constraint")
, b = a("../equations/ContactEquation");
c.prototype = new e;
c.prototype.update = function() {
var a = this.distanceEquation
, b = .5 * this.distance
, c = a.ni;
this.bodyB.position.vsub(this.bodyA.position, c);
c.normalize();
c.mult(b, a.ri);
c.mult(-b, a.rj)
}
}
, {
"../equations/ContactEquation": 19,
"./Constraint": 13
}],
15: [function(a, d, f) {
function c(a, c, d) {
d = d || {};
var h = "undefined" !== typeof d.maxForce ? d.maxForce : 1E6
, l = d.pivotA ? d.pivotA.clone() : new k
, p = d.pivotB ? d.pivotB.clone() : new k;
e.call(this, a, l, c, p, h);
(this.axisA = d.axisA ? d.axisA.clone() : new k(1,0,0)).normalize();
(this.axisB = d.axisB ? d.axisB.clone() : new k(1,0,0)).normalize();
l = this.rotationalEquation1 = new b(a,c,d);
d = this.rotationalEquation2 = new b(a,c,d);
a = this.motorEquation = new g(a,c,h);
a.enabled = !1;
this.equations.push(l, d, a)
}
d.exports = c;
a("./Constraint");
var e = a("./PointToPointConstraint")
, b = a("../equations/RotationalEquation")
, g = a("../equations/RotationalMotorEquation");
a("../equations/ContactEquation");
var k = a("../math/Vec3");
c.prototype = new e;
c.constructor = c;
c.prototype.enableMotor = function() {
this.motorEquation.enabled = !0
}
;
c.prototype.disableMotor = function() {
this.motorEquation.enabled = !1
}
;
c.prototype.setMotorSpeed = function(a) {
this.motorEquation.targetVelocity = a
}
;
c.prototype.setMotorMaxForce = function(a) {
this.motorEquation.maxForce = a;
this.motorEquation.minForce = -a
}
;
var h = new k
, n = new k;
c.prototype.update = function() {
var a = this.bodyA
, b = this.bodyB
, c = this.motorEquation
, d = this.rotationalEquation1
, g = this.rotationalEquation2
, f = this.axisA
, k = this.axisB;
e.prototype.update.call(this);
a.quaternion.vmult(f, h);
b.quaternion.vmult(k, n);
h.tangents(d.axisA, g.axisA);
d.axisB.copy(n);
g.axisB.copy(n);
this.motorEquation.enabled && (a.quaternion.vmult(this.axisA, c.axisA),
b.quaternion.vmult(this.axisB, c.axisB))
}
}
, {
"../equations/ContactEquation": 19,
"../equations/RotationalEquation": 22,
"../equations/RotationalMotorEquation": 23,
"../math/Vec3": 30,
"./Constraint": 13,
"./PointToPointConstraint": 17
}],
16: [function(a, d, f) {
function c(a, c, d) {
d = d || {};
var h = "undefined" !== typeof d.maxForce ? d.maxForce : 1E6
, n = new g
, p = new g
, f = new g;
a.position.vadd(c.position, f);
f.scale(.5, f);
c.pointToLocalFrame(f, p);
a.pointToLocalFrame(f, n);
e.call(this, a, n, c, p, h);
h = this.rotationalEquation1 = new b(a,c,d);
n = this.rotationalEquation2 = new b(a,c,d);
a = this.rotationalEquation3 = new b(a,c,d);
this.equations.push(h, n, a)
}
d.exports = c;
a("./Constraint");
var e = a("./PointToPointConstraint")
, b = a("../equations/RotationalEquation");
a("../equations/RotationalMotorEquation");
a("../equations/ContactEquation");
var g = a("../math/Vec3");
c.prototype = new e;
c.constructor = c;
new g;
new g;
c.prototype.update = function() {
var a = this.bodyA
, b = this.bodyB
, c = this.rotationalEquation1
, d = this.rotationalEquation2
, f = this.rotationalEquation3;
e.prototype.update.call(this);
a.vectorToWorldFrame(g.UNIT_X, c.axisA);
b.vectorToWorldFrame(g.UNIT_Y, c.axisB);
a.vectorToWorldFrame(g.UNIT_Y, d.axisA);
b.vectorToWorldFrame(g.UNIT_Z, d.axisB);
a.vectorToWorldFrame(g.UNIT_Z, f.axisA);
b.vectorToWorldFrame(g.UNIT_X, f.axisB)
}
}
, {
"../equations/ContactEquation": 19,
"../equations/RotationalEquation": 22,
"../equations/RotationalMotorEquation": 23,
"../math/Vec3": 30,
"./Constraint": 13,
"./PointToPointConstraint": 17
}],
17: [function(a, d, f) {
function c(a, c, d, l, f) {
e.call(this, a, d);
f = "undefined" !== typeof f ? f : 1E6;
this.pivotA = c ? c.clone() : new g;
this.pivotB = l ? l.clone() : new g;
c = this.equationX = new b(a,d);
l = this.equationY = new b(a,d);
a = this.equationZ = new b(a,d);
this.equations.push(c, l, a);
c.minForce = l.minForce = a.minForce = -f;
c.maxForce = l.maxForce = a.maxForce = f;
c.ni.set(1, 0, 0);
l.ni.set(0, 1, 0);
a.ni.set(0, 0, 1)
}
d.exports = c;
var e = a("./Constraint")
, b = a("../equations/ContactEquation")
, g = a("../math/Vec3");
c.prototype = new e;
c.prototype.update = function() {
var a = this.bodyB
, b = this.equationX
, c = this.equationY
, e = this.equationZ;
this.bodyA.quaternion.vmult(this.pivotA, b.ri);
a.quaternion.vmult(this.pivotB, b.rj);
c.ri.copy(b.ri);
c.rj.copy(b.rj);
e.ri.copy(b.ri);
e.rj.copy(b.rj)
}
}
, {
"../equations/ContactEquation": 19,
"../math/Vec3": 30,
"./Constraint": 13
}],
18: [function(a, d, f) {
function c(a, c, d) {
d = d || {};
var h = "undefined" !== typeof d.maxForce ? d.maxForce : 1E6;
b.call(this, a, c, -h, h);
this.axisA = d.axisA ? d.axisA.clone() : new e(1,0,0);
this.axisB = d.axisB ? d.axisB.clone() : new e(0,1,0);
this.angle = "undefined" !== typeof d.angle ? d.angle : 0
}
d.exports = c;
var e = a("../math/Vec3");
a("../math/Mat3");
var b = a("./Equation");
c.prototype = new b;
c.prototype.constructor = c;
var g = new e
, k = new e;
c.prototype.computeB = function(a) {
var b = this.a
, c = this.b
, e = this.axisA
, d = this.axisB
, h = this.jacobianElementA
, f = this.jacobianElementB;
e.cross(d, g);
d.cross(e, k);
h.rotational.copy(k);
f.rotational.copy(g);
e = Math.cos(this.angle) - e.dot(d);
d = this.computeGW();
h = this.computeGiMf();
return -e * b - d * c - a * h
}
}
, {
"../math/Mat3": 27,
"../math/Vec3": 30,
"./Equation": 20
}],
19: [function(a, d, f) {
function c(a, c, d) {
e.call(this, a, c, 0, "undefined" !== typeof d ? d : 1E6);
this.restitution = 0;
this.ri = new b;
this.rj = new b;
this.ni = new b
}
d.exports = c;
var e = a("./Equation")
, b = a("../math/Vec3");
a("../math/Mat3");
c.prototype = new e;
c.prototype.constructor = c;
var g = new b
, k = new b
, h = new b;
c.prototype.computeB = function(a) {
var b = this.a
, c = this.b
, e = this.bi
, d = this.bj
, l = this.ri
, p = this.rj
, n = e.velocity
, f = e.angularVelocity
, q = d.velocity
, u = d.angularVelocity
, r = this.jacobianElementA
, K = this.jacobianElementB
, I = this.ni;
l.cross(I, g);
p.cross(I, k);
I.negate(r.spatial);
g.negate(r.rotational);
K.spatial.copy(I);
K.rotational.copy(k);
h.copy(d.position);
h.vadd(p, h);
h.vsub(e.position, h);
h.vsub(l, h);
e = I.dot(h);
d = this.restitution + 1;
n = d * q.dot(I) - d * n.dot(I) + u.dot(k) - f.dot(g);
f = this.computeGiMf();
return -e * b - n * c - a * f
}
;
var n = new b
, l = new b
, q = new b
, p = new b
, r = new b;
c.prototype.getImpactVelocityAlongNormal = function() {
this.bi.position.vadd(this.ri, q);
this.bj.position.vadd(this.rj, p);
this.bi.getVelocityAtWorldPoint(q, n);
this.bj.getVelocityAtWorldPoint(p, l);
n.vsub(l, r);
return this.ni.dot(r)
}
}
, {
"../math/Mat3": 27,
"../math/Vec3": 30,
"./Equation": 20
}],
20: [function(a, d, f) {
function c(a, b, d, h) {
this.id = c.id++;
this.minForce = "undefined" === typeof d ? -1E6 : d;
this.maxForce = "undefined" === typeof h ? 1E6 : h;
this.bi = a;
this.bj = b;
this.eps = this.b = this.a = 0;
this.jacobianElementA = new e;
this.jacobianElementB = new e;
this.enabled = !0;
this.setSpookParams(1E7, 4, 1 / 60)
}
d.exports = c;
var e = a("../math/JacobianElement");
a = a("../math/Vec3");
c.prototype.constructor = c;
c.id = 0;
c.prototype.setSpookParams = function(a, b, c) {
this.a = 4 / (c * (1 + 4 * b));
this.b = 4 * b / (1 + 4 * b);
this.eps = 4 / (c * c * a * (1 + 4 * b))
}
;
c.prototype.computeB = function(a, b, c) {
var e = this.computeGW()
, d = this.computeGq()
, h = this.computeGiMf();
return -d * a - e * b - h * c
}
;
c.prototype.computeGq = function() {
var a = this.jacobianElementB
, b = this.bj.position;
return this.jacobianElementA.spatial.dot(this.bi.position) + a.spatial.dot(b)
}
;
var b = new a;
c.prototype.computeGW = function() {
var a = this.jacobianElementB
, c = this.bi
, e = this.bj
, d = e.velocity;
e = e.angularVelocity || b;
return this.jacobianElementA.multiplyVectors(c.velocity, c.angularVelocity || b) + a.multiplyVectors(d, e)
}
;
c.prototype.computeGWlambda = function() {
var a = this.jacobianElementB
, c = this.bi
, e = this.bj
, d = e.vlambda;
e = e.wlambda || b;
return this.jacobianElementA.multiplyVectors(c.vlambda, c.wlambda || b) + a.multiplyVectors(d, e)
}
;
var g = new a
, k = new a
, h = new a
, n = new a;
c.prototype.computeGiMf = function() {
var a = this.jacobianElementA
, b = this.jacobianElementB
, c = this.bi
, e = this.bj
, d = c.force
, l = c.torque
, f = e.force
, q = e.torque
, C = c.invMassSolve
, B = e.invMassSolve;
c.invInertiaWorldSolve ? c.invInertiaWorldSolve.vmult(l, h) : h.set(0, 0, 0);
e.invInertiaWorldSolve ? e.invInertiaWorldSolve.vmult(q, n) : n.set(0, 0, 0);
d.mult(C, g);
f.mult(B, k);
return a.multiplyVectors(g, h) + b.multiplyVectors(k, n)
}
;
var l = new a;
c.prototype.computeGiMGt = function() {
var a = this.jacobianElementA
, b = this.jacobianElementB
, c = this.bi
, e = this.bj
, d = c.invInertiaWorldSolve
, h = e.invInertiaWorldSolve;
c = c.invMassSolve + e.invMassSolve;
d && (d.vmult(a.rotational, l),
c += l.dot(a.rotational));
h && (h.vmult(b.rotational, l),
c += l.dot(b.rotational));
return c
}
;
var q = new a;
new a;
new a;
new a;
new a;
new a;
c.prototype.addToWlambda = function(a) {
var b = this.jacobianElementA
, c = this.jacobianElementB
, e = this.bi
, d = this.bj;
b.spatial.mult(e.invMassSolve * a, q);
e.vlambda.vadd(q, e.vlambda);
c.spatial.mult(d.invMassSolve * a, q);
d.vlambda.vadd(q, d.vlambda);
e.invInertiaWorldSolve && (e.invInertiaWorldSolve.vmult(b.rotational, q),
q.mult(a, q),
e.wlambda.vadd(q, e.wlambda));
d.invInertiaWorldSolve && (d.invInertiaWorldSolve.vmult(c.rotational, q),
q.mult(a, q),
d.wlambda.vadd(q, d.wlambda))
}
;
c.prototype.computeC = function() {
return this.computeGiMGt() + this.eps
}
}
, {
"../math/JacobianElement": 26,
"../math/Vec3": 30
}],
21: [function(a, d, f) {
function c(a, c, d) {
e.call(this, a, c, -d, d);
this.ri = new b;
this.rj = new b;
this.t = new b
}
d.exports = c;
var e = a("./Equation")
, b = a("../math/Vec3");
a("../math/Mat3");
c.prototype = new e;
c.prototype.constructor = c;
var g = new b
, k = new b;
c.prototype.computeB = function(a) {
var b = this.b
, c = this.rj
, e = this.t;
this.ri.cross(e, g);
c.cross(e, k);
c = this.jacobianElementA;
var d = this.jacobianElementB;
e.negate(c.spatial);
g.negate(c.rotational);
d.spatial.copy(e);
d.rotational.copy(k);
e = this.computeGW();
c = this.computeGiMf();
return -e * b - a * c
}
}
, {
"../math/Mat3": 27,
"../math/Vec3": 30,
"./Equation": 20
}],
22: [function(a, d, f) {
function c(a, c, d) {
d = d || {};
var h = "undefined" !== typeof d.maxForce ? d.maxForce : 1E6;
b.call(this, a, c, -h, h);
this.axisA = d.axisA ? d.axisA.clone() : new e(1,0,0);
this.axisB = d.axisB ? d.axisB.clone() : new e(0,1,0);
this.maxAngle = Math.PI / 2
}
d.exports = c;
var e = a("../math/Vec3");
a("../math/Mat3");
var b = a("./Equation");
c.prototype = new b;
c.prototype.constructor = c;
var g = new e
, k = new e;
c.prototype.computeB = function(a) {
var b = this.a
, c = this.b
, e = this.axisA
, d = this.axisB
, h = this.jacobianElementA
, f = this.jacobianElementB;
e.cross(d, g);
d.cross(e, k);
h.rotational.copy(k);
f.rotational.copy(g);
e = Math.cos(this.maxAngle) - e.dot(d);
d = this.computeGW();
h = this.computeGiMf();
return -e * b - d * c - a * h
}
}
, {
"../math/Mat3": 27,
"../math/Vec3": 30,
"./Equation": 20
}],
23: [function(a, d, f) {
function c(a, c, d) {
d = "undefined" !== typeof d ? d : 1E6;
b.call(this, a, c, -d, d);
this.axisA = new e;
this.axisB = new e;
this.targetVelocity = 0
}
d.exports = c;
var e = a("../math/Vec3");
a("../math/Mat3");
var b = a("./Equation");
c.prototype = new b;
c.prototype.constructor = c;
c.prototype.computeB = function(a) {
var b = this.b
, c = this.axisB
, e = this.jacobianElementB;
this.jacobianElementA.rotational.copy(this.axisA);
c.negate(e.rotational);
c = this.computeGW() - this.targetVelocity;
e = this.computeGiMf();
return -c * b - a * e
}
}
, {
"../math/Mat3": 27,
"../math/Vec3": 30,
"./Equation": 20
}],
24: [function(a, d, f) {
function c(a, d, f) {
f = e.defaults(f, {
friction: .3,
restitution: .3,
contactEquationStiffness: 1E7,
contactEquationRelaxation: 3,
frictionEquationStiffness: 1E7,
frictionEquationRelaxation: 3
});
this.id = c.idCounter++;
this.materials = [a, d];
this.friction = f.friction;
this.restitution = f.restitution;
this.contactEquationStiffness = f.contactEquationStiffness;
this.contactEquationRelaxation = f.contactEquationRelaxation;
this.frictionEquationStiffness = f.frictionEquationStiffness;
this.frictionEquationRelaxation = f.frictionEquationRelaxation
}
var e = a("../utils/Utils");
d.exports = c;
c.idCounter = 0
}
, {
"../utils/Utils": 53
}],
25: [function(a, d, f) {
function c(a) {
var b = "";
a = a || {};
"string" === typeof a ? (b = a,
a = {}) : "object" === typeof a && (b = "");
this.name = b;
this.id = c.idCounter++;
this.friction = "undefined" !== typeof a.friction ? a.friction : -1;
this.restitution = "undefined" !== typeof a.restitution ? a.restitution : -1
}
d.exports = c;
c.idCounter = 0
}
, {}],
26: [function(a, d, f) {
function c() {
this.spatial = new e;
this.rotational = new e
}
d.exports = c;
var e = a("./Vec3");
c.prototype.multiplyElement = function(a) {
return a.spatial.dot(this.spatial) + a.rotational.dot(this.rotational)
}
;
c.prototype.multiplyVectors = function(a, c) {
return a.dot(this.spatial) + c.dot(this.rotational)
}
}
, {
"./Vec3": 30
}],
27: [function(a, d, f) {
function c(a) {
this.elements = a ? a : [0, 0, 0, 0, 0, 0, 0, 0, 0]
}
d.exports = c;
var e = a("./Vec3");
c.prototype.identity = function() {
var a = this.elements;
a[0] = 1;
a[1] = 0;
a[2] = 0;
a[3] = 0;
a[4] = 1;
a[5] = 0;
a[6] = 0;
a[7] = 0;
a[8] = 1
}
;
c.prototype.setZero = function() {
var a = this.elements;
a[0] = 0;
a[1] = 0;
a[2] = 0;
a[3] = 0;
a[4] = 0;
a[5] = 0;
a[6] = 0;
a[7] = 0;
a[8] = 0
}
;
c.prototype.setTrace = function(a) {
var b = this.elements;
b[0] = a.x;
b[4] = a.y;
b[8] = a.z
}
;
c.prototype.getTrace = function(a) {
a = a || new e;
var b = this.elements;
a.x = b[0];
a.y = b[4];
a.z = b[8]
}
;
c.prototype.vmult = function(a, c) {
c = c || new e;
var b = this.elements
, d = a.x
, g = a.y
, l = a.z;
c.x = b[0] * d + b[1] * g + b[2] * l;
c.y = b[3] * d + b[4] * g + b[5] * l;
c.z = b[6] * d + b[7] * g + b[8] * l;
return c
}
;
c.prototype.smult = function(a) {
for (var b = 0; b < this.elements.length; b++)
this.elements[b] *= a
}
;
c.prototype.mmult = function(a, e) {
for (var b = e || new c, d = 0; 3 > d; d++)
for (var g = 0; 3 > g; g++) {
for (var l = 0, f = 0; 3 > f; f++)
l += a.elements[d + 3 * f] * this.elements[f + 3 * g];
b.elements[d + 3 * g] = l
}
return b
}
;
c.prototype.scale = function(a, e) {
e = e || new c;
for (var b = this.elements, d = e.elements, g = 0; 3 !== g; g++)
d[3 * g] = a.x * b[3 * g],
d[3 * g + 1] = a.y * b[3 * g + 1],
d[3 * g + 2] = a.z * b[3 * g + 2];
return e
}
;
c.prototype.solve = function(a, c) {
c = c || new e;
for (var b = [], d = 0; 12 > d; d++)
b.push(0);
var g;
for (d = 0; 3 > d; d++)
for (g = 0; 3 > g; g++)
b[d + 4 * g] = this.elements[d + 3 * g];
b[3] = a.x;
b[7] = a.y;
b[11] = a.z;
var l = 3
, f = l;
do {
d = f - l;
if (0 === b[d + 4 * d])
for (g = d + 1; g < f; g++)
if (0 !== b[d + 4 * g]) {
var p = 4;
do {
var r = 4 - p;
b[r + 4 * d] += b[r + 4 * g]
} while (--p);break
}
if (0 !== b[d + 4 * d])
for (g = d + 1; g < f; g++) {
var u = b[d + 4 * g] / b[d + 4 * d];
p = 4;
do
r = 4 - p,
b[r + 4 * g] = r <= d ? 0 : b[r + 4 * g] - b[r + 4 * d] * u;
while (--p)
}
} while (--l);c.z = b[11] / b[10];
c.y = (b[7] - b[6] * c.z) / b[5];
c.x = (b[3] - b[2] * c.z - b[1] * c.y) / b[0];
if (isNaN(c.x) || isNaN(c.y) || isNaN(c.z) || Infinity === c.x || Infinity === c.y || Infinity === c.z)
throw "Could not solve equation! Got x=[" + c.toString() + "], b=[" + a.toString() + "], A=[" + this.toString() + "]";
return c
}
;
c.prototype.e = function(a, c, e) {
if (void 0 === e)
return this.elements[c + 3 * a];
this.elements[c + 3 * a] = e
}
;
c.prototype.copy = function(a) {
for (var b = 0; b < a.elements.length; b++)
this.elements[b] = a.elements[b];
return this
}
;
c.prototype.toString = function() {
for (var a = "", c = 0; 9 > c; c++)
a += this.elements[c] + ",";
return a
}
;
c.prototype.reverse = function(a) {
a = a || new c;
for (var b = [], e = 0; 18 > e; e++)
b.push(0);
var d;
for (e = 0; 3 > e; e++)
for (d = 0; 3 > d; d++)
b[e + 6 * d] = this.elements[e + 3 * d];
b[3] = 1;
b[9] = 0;
b[15] = 0;
b[4] = 0;
b[10] = 1;
b[16] = 0;
b[5] = 0;
b[11] = 0;
b[17] = 1;
var f = 3
, l = f;
do {
e = l - f;
if (0 === b[e + 6 * e])
for (d = e + 1; d < l; d++)
if (0 !== b[e + 6 * d]) {
var q = 6;
do {
var p = 6 - q;
b[p + 6 * e] += b[p + 6 * d]
} while (--q);break
}
if (0 !== b[e + 6 * e])
for (d = e + 1; d < l; d++) {
var r = b[e + 6 * d] / b[e + 6 * e];
q = 6;
do
p = 6 - q,
b[p + 6 * d] = p <= e ? 0 : b[p + 6 * d] - b[p + 6 * e] * r;
while (--q)
}
} while (--f);e = 2;
do {
d = e - 1;
do {
r = b[e + 6 * d] / b[e + 6 * e];
q = 6;
do
p = 6 - q,
b[p + 6 * d] -= b[p + 6 * e] * r;
while (--q)
} while (d--)
} while (--e);e = 2;
do {
r = 1 / b[e + 6 * e];
q = 6;
do
p = 6 - q,
b[p + 6 * e] *= r;
while (--q)
} while (e--);e = 2;
do {
d = 2;
do {
p = b[3 + d + 6 * e];
if (isNaN(p) || Infinity === p)
throw "Could not reverse! A=[" + this.toString() + "]";
a.e(e, d, p)
} while (d--)
} while (e--);return a
}
;
c.prototype.setRotationFromQuaternion = function(a) {
var b = a.x
, c = a.y
, e = a.z
, d = a.w
, l = b + b
, f = c + c
, p = e + e;
a = b * l;
var r = b * f;
b *= p;
var u = c * f;
c *= p;
e *= p;
l *= d;
f *= d;
d *= p;
p = this.elements;
p[0] = 1 - (u + e);
p[1] = r - d;
p[2] = b + f;
p[3] = r + d;
p[4] = 1 - (a + e);
p[5] = c - l;
p[6] = b - f;
p[7] = c + l;
p[8] = 1 - (a + u);
return this
}
;
c.prototype.transpose = function(a) {
a = a || new c;
for (var b = a.elements, e = this.elements, d = 0; 3 !== d; d++)
for (var f = 0; 3 !== f; f++)
b[3 * d + f] = e[3 * f + d];
return a
}
}
, {
"./Vec3": 30
}],
28: [function(a, d, f) {
function c(a, b, c, e) {
this.x = void 0 !== a ? a : 0;
this.y = void 0 !== b ? b : 0;
this.z = void 0 !== c ? c : 0;
this.w = void 0 !== e ? e : 1
}
d.exports = c;
var e = a("./Vec3");
c.prototype.set = function(a, b, c, e) {
this.x = a;
this.y = b;
this.z = c;
this.w = e
}
;
c.prototype.toString = function() {
return this.x + "," + this.y + "," + this.z + "," + this.w
}
;
c.prototype.toArray = function() {
return [this.x, this.y, this.z, this.w]
}
;
c.prototype.setFromAxisAngle = function(a, b) {
var c = Math.sin(.5 * b);
this.x = a.x * c;
this.y = a.y * c;
this.z = a.z * c;
this.w = Math.cos(.5 * b)
}
;
c.prototype.toAxisAngle = function(a) {
a = a || new e;
this.normalize();
var b = 2 * Math.acos(this.w)
, c = Math.sqrt(1 - this.w * this.w);
.001 > c ? (a.x = this.x,
a.y = this.y,
a.z = this.z) : (a.x = this.x / c,
a.y = this.y / c,
a.z = this.z / c);
return [a, b]
}
;
var b = new e
, g = new e;
c.prototype.setFromVectors = function(a, c) {
if (a.isAntiparallelTo(c))
a.tangents(b, g),
this.setFromAxisAngle(b, Math.PI);
else {
var e = a.cross(c);
this.x = e.x;
this.y = e.y;
this.z = e.z;
this.w = Math.sqrt(Math.pow(a.norm(), 2) * Math.pow(c.norm(), 2)) + a.dot(c);
this.normalize()
}
}
;
var k = new e
, h = new e
, n = new e;
c.prototype.mult = function(a, b) {
b = b || new c;
var e = this.w;
k.set(this.x, this.y, this.z);
h.set(a.x, a.y, a.z);
b.w = e * a.w - k.dot(h);
k.cross(h, n);
b.x = e * h.x + a.w * k.x + n.x;
b.y = e * h.y + a.w * k.y + n.y;
b.z = e * h.z + a.w * k.z + n.z;
return b
}
;
c.prototype.inverse = function(a) {
var b = this.x
, e = this.y
, d = this.z
, h = this.w;
a = a || new c;
this.conjugate(a);
b = 1 / (b * b + e * e + d * d + h * h);
a.x *= b;
a.y *= b;
a.z *= b;
a.w *= b;
return a
}
;
c.prototype.conjugate = function(a) {
a = a || new c;
a.x = -this.x;
a.y = -this.y;
a.z = -this.z;
a.w = this.w;
return a
}
;
c.prototype.normalize = function() {
var a = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
0 === a ? this.w = this.z = this.y = this.x = 0 : (a = 1 / a,
this.x *= a,
this.y *= a,
this.z *= a,
this.w *= a)
}
;
c.prototype.normalizeFast = function() {
var a = (3 - (this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w)) / 2;
0 === a ? this.w = this.z = this.y = this.x = 0 : (this.x *= a,
this.y *= a,
this.z *= a,
this.w *= a)
}
;
c.prototype.vmult = function(a, b) {
b = b || new e;
var c = a.x
, d = a.y
, h = a.z
, f = this.x
, g = this.y
, l = this.z
, n = this.w
, q = n * c + g * h - l * d
, k = n * d + l * c - f * h
, B = n * h + f * d - g * c;
c = -f * c - g * d - l * h;
b.x = q * n + c * -f + k * -l - B * -g;
b.y = k * n + c * -g + B * -f - q * -l;
b.z = B * n + c * -l + q * -g - k * -f;
return b
}
;
c.prototype.copy = function(a) {
this.x = a.x;
this.y = a.y;
this.z = a.z;
this.w = a.w;
return this
}
;
c.prototype.toEuler = function(a, b) {
b = b || "YZX";
var c = this.x
, e = this.y
, d = this.z
, h = this.w;
switch (b) {
case "YZX":
var f = c * e + d * h;
if (.499 < f) {
var g = 2 * Math.atan2(c, h);
var l = Math.PI / 2;
var n = 0
}
-.499 > f && (g = -2 * Math.atan2(c, h),
l = -Math.PI / 2,
n = 0);
isNaN(g) && (n = d * d,
g = Math.atan2(2 * e * h - 2 * c * d, 1 - 2 * e * e - 2 * n),
l = Math.asin(2 * f),
n = Math.atan2(2 * c * h - 2 * e * d, 1 - 2 * c * c - 2 * n));
break;
default:
throw Error("Euler order " + b + " not supported yet.");
}
a.y = g;
a.z = l;
a.x = n
}
;
c.prototype.setFromEuler = function(a, b, c, e) {
e = e || "XYZ";
var d = Math.cos(a / 2)
, h = Math.cos(b / 2)
, g = Math.cos(c / 2);
a = Math.sin(a / 2);
b = Math.sin(b / 2);
c = Math.sin(c / 2);
"XYZ" === e ? (this.x = a * h * g + d * b * c,
this.y = d * b * g - a * h * c,
this.z = d * h * c + a * b * g,
this.w = d * h * g - a * b * c) : "YXZ" === e ? (this.x = a * h * g + d * b * c,
this.y = d * b * g - a * h * c,
this.z = d * h * c - a * b * g,
this.w = d * h * g + a * b * c) : "ZXY" === e ? (this.x = a * h * g - d * b * c,
this.y = d * b * g + a * h * c,
this.z = d * h * c + a * b * g,
this.w = d * h * g - a * b * c) : "ZYX" === e ? (this.x = a * h * g - d * b * c,
this.y = d * b * g + a * h * c,
this.z = d * h * c - a * b * g,
this.w = d * h * g + a * b * c) : "YZX" === e ? (this.x = a * h * g + d * b * c,
this.y = d * b * g + a * h * c,
this.z = d * h * c - a * b * g,
this.w = d * h * g - a * b * c) : "XZY" === e && (this.x = a * h * g - d * b * c,
this.y = d * b * g - a * h * c,
this.z = d * h * c + a * b * g,
this.w = d * h * g + a * b * c);
return this
}
;
c.prototype.clone = function() {
return new c(this.x,this.y,this.z,this.w)
}
}
, {
"./Vec3": 30
}],
29: [function(a, d, f) {
function c(a) {
a = a || {};
this.position = new e;
a.position && this.position.copy(a.position);
this.quaternion = new b;
a.quaternion && this.quaternion.copy(a.quaternion)
}
var e = a("./Vec3")
, b = a("./Quaternion");
d.exports = c;
var g = new b;
c.pointToLocalFrame = function(a, b, c, d) {
d = d || new e;
c.vsub(a, d);
b.conjugate(g);
g.vmult(d, d);
return d
}
;
c.prototype.pointToLocal = function(a, b) {
return c.pointToLocalFrame(this.position, this.quaternion, a, b)
}
;
c.pointToWorldFrame = function(a, b, c, d) {
d = d || new e;
b.vmult(c, d);
d.vadd(a, d);
return d
}
;
c.prototype.pointToWorld = function(a, b) {
return c.pointToWorldFrame(this.position, this.quaternion, a, b)
}
;
c.prototype.vectorToWorldFrame = function(a, b) {
b = b || new e;
this.quaternion.vmult(a, b);
return b
}
;
c.vectorToWorldFrame = function(a, b, c) {
a.vmult(b, c);
return c
}
;
c.vectorToLocalFrame = function(a, b, c, d) {
d = d || new e;
b.w *= -1;
b.vmult(c, d);
b.w *= -1;
return d
}
}
, {
"./Quaternion": 28,
"./Vec3": 30
}],
30: [function(a, d, f) {
function c(a, b, c) {
this.x = a || 0;
this.y = b || 0;
this.z = c || 0
}
d.exports = c;
var e = a("./Mat3");
c.ZERO = new c(0,0,0);
c.UNIT_X = new c(1,0,0);
c.UNIT_Y = new c(0,1,0);
c.UNIT_Z = new c(0,0,1);
c.prototype.cross = function(a, b) {
var d = a.x
, e = a.y
, h = a.z
, g = this.x
, f = this.y
, n = this.z;
b = b || new c;
b.x = f * h - n * e;
b.y = n * d - g * h;
b.z = g * e - f * d;
return b
}
;
c.prototype.set = function(a, b, c) {
this.x = a;
this.y = b;
this.z = c;
return this
}
;
c.prototype.setZero = function() {
this.x = this.y = this.z = 0
}
;
c.prototype.vadd = function(a, b) {
if (b)
b.x = a.x + this.x,
b.y = a.y + this.y,
b.z = a.z + this.z;
else
return new c(this.x + a.x,this.y + a.y,this.z + a.z)
}
;
c.prototype.vsub = function(a, b) {
if (b)
b.x = this.x - a.x,
b.y = this.y - a.y,
b.z = this.z - a.z;
else
return new c(this.x - a.x,this.y - a.y,this.z - a.z)
}
;
c.prototype.crossmat = function() {
return new e([0, -this.z, this.y, this.z, 0, -this.x, -this.y, this.x, 0])
}
;
c.prototype.normalize = function() {
var a = this.x
, b = this.y
, c = this.z;
a = Math.sqrt(a * a + b * b + c * c);
0 < a ? (b = 1 / a,
this.x *= b,
this.y *= b,
this.z *= b) : this.z = this.y = this.x = 0;
return a
}
;
c.prototype.unit = function(a) {
a = a || new c;
var b = this.x
, d = this.y
, e = this.z
, h = Math.sqrt(b * b + d * d + e * e);
0 < h ? (h = 1 / h,
a.x = b * h,
a.y = d * h,
a.z = e * h) : (a.x = 1,
a.y = 0,
a.z = 0);
return a
}
;
c.prototype.norm = function() {
var a = this.x
, b = this.y
, c = this.z;
return Math.sqrt(a * a + b * b + c * c)
}
;
c.prototype.length = c.prototype.norm;
c.prototype.norm2 = function() {
return this.dot(this)
}
;
c.prototype.lengthSquared = c.prototype.norm2;
c.prototype.distanceTo = function(a) {
var b = this.x
, c = this.y
, d = this.z
, e = a.x
, h = a.y;
a = a.z;
return Math.sqrt((e - b) * (e - b) + (h - c) * (h - c) + (a - d) * (a - d))
}
;
c.prototype.distanceSquared = function(a) {
var b = this.x
, c = this.y
, d = this.z
, e = a.x
, h = a.y;
a = a.z;
return (e - b) * (e - b) + (h - c) * (h - c) + (a - d) * (a - d)
}
;
c.prototype.mult = function(a, b) {
b = b || new c;
var d = this.y
, e = this.z;
b.x = a * this.x;
b.y = a * d;
b.z = a * e;
return b
}
;
c.prototype.scale = c.prototype.mult;
c.prototype.dot = function(a) {
return this.x * a.x + this.y * a.y + this.z * a.z
}
;
c.prototype.isZero = function() {
return 0 === this.x && 0 === this.y && 0 === this.z
}
;
c.prototype.negate = function(a) {
a = a || new c;
a.x = -this.x;
a.y = -this.y;
a.z = -this.z;
return a
}
;
var b = new c
, g = new c;
c.prototype.tangents = function(a, c) {
var d = this.norm();
0 < d ? (d = 1 / d,
b.set(this.x * d, this.y * d, this.z * d),
.9 > Math.abs(b.x) ? g.set(1, 0, 0) : g.set(0, 1, 0),
b.cross(g, a),
b.cross(a, c)) : (a.set(1, 0, 0),
c.set(0, 1, 0))
}
;
c.prototype.toString = function() {
return this.x + "," + this.y + "," + this.z
}
;
c.prototype.toArray = function() {
return [this.x, this.y, this.z]
}
;
c.prototype.copy = function(a) {
this.x = a.x;
this.y = a.y;
this.z = a.z;
return this
}
;
c.prototype.lerp = function(a, b, c) {
var d = this.x
, e = this.y
, g = this.z;
c.x = d + (a.x - d) * b;
c.y = e + (a.y - e) * b;
c.z = g + (a.z - g) * b
}
;
c.prototype.almostEquals = function(a, b) {
void 0 === b && (b = 1E-6);
return Math.abs(this.x - a.x) > b || Math.abs(this.y - a.y) > b || Math.abs(this.z - a.z) > b ? !1 : !0
}
;
c.prototype.almostZero = function(a) {
void 0 === a && (a = 1E-6);
return Math.abs(this.x) > a || Math.abs(this.y) > a || Math.abs(this.z) > a ? !1 : !0
}
;
var k = new c;
c.prototype.isAntiparallelTo = function(a, b) {
this.negate(k);
return k.almostEquals(a, b)
}
;
c.prototype.clone = function() {
return new c(this.x,this.y,this.z)
}
}
, {
"./Mat3": 27
}],
31: [function(a, d, f) {
function c(a) {
a = a || {};
e.apply(this);
this.id = c.idCounter++;
this.postStep = this.preStep = this.world = null;
this.vlambda = new b;
this.collisionFilterGroup = "number" === typeof a.collisionFilterGroup ? a.collisionFilterGroup : 1;
this.collisionFilterMask = "number" === typeof a.collisionFilterMask ? a.collisionFilterMask : 1;
this.collisionResponse = !0;
this.position = new b;
a.position && this.position.copy(a.position);
this.previousPosition = new b;
this.initPosition = new b;
this.velocity = new b;
a.velocity && this.velocity.copy(a.velocity);
this.initVelocity = new b;
this.force = new b;
var d = "number" === typeof a.mass ? a.mass : 0;
this.mass = d;
this.invMass = 0 < d ? 1 / d : 0;
this.material = a.material || null;
this.linearDamping = "number" === typeof a.linearDamping ? a.linearDamping : .01;
this.type = 0 >= d ? c.STATIC : c.DYNAMIC;
typeof a.type === typeof c.STATIC && (this.type = a.type);
this.allowSleep = "undefined" !== typeof a.allowSleep ? a.allowSleep : !0;
this.sleepState = 0;
this.sleepSpeedLimit = "undefined" !== typeof a.sleepSpeedLimit ? a.sleepSpeedLimit : .1;
this.sleepTimeLimit = "undefined" !== typeof a.sleepTimeLimit ? a.sleepTimeLimit : 1;
this.timeLastSleepy = 0;
this._wakeUpAfterNarrowphase = !1;
this.torque = new b;
this.quaternion = new k;
a.quaternion && this.quaternion.copy(a.quaternion);
this.initQuaternion = new k;
this.angularVelocity = new b;
a.angularVelocity && this.angularVelocity.copy(a.angularVelocity);
this.initAngularVelocity = new b;
this.interpolatedPosition = new b;
this.interpolatedQuaternion = new k;
this.shapes = [];
this.shapeOffsets = [];
this.shapeOrientations = [];
this.inertia = new b;
this.invInertia = new b;
this.invInertiaWorld = new g;
this.invMassSolve = 0;
this.invInertiaSolve = new b;
this.invInertiaWorldSolve = new g;
this.fixedRotation = "undefined" !== typeof a.fixedRotation ? a.fixedRotation : !1;
this.angularDamping = "undefined" !== typeof a.angularDamping ? a.angularDamping : .01;
this.aabb = new h;
this.aabbNeedsUpdate = !0;
this.wlambda = new b;
a.shape && this.addShape(a.shape);
this.updateMassProperties()
}
d.exports = c;
var e = a("../utils/EventTarget");
a("../shapes/Shape");
var b = a("../math/Vec3")
, g = a("../math/Mat3")
, k = a("../math/Quaternion");
a("../material/Material");
var h = a("../collision/AABB")
, n = a("../shapes/Box");
c.prototype = new e;
c.prototype.constructor = c;
c.DYNAMIC = 1;
c.STATIC = 2;
c.KINEMATIC = 4;
c.AWAKE = 0;
c.SLEEPY = 1;
c.SLEEPING = 2;
c.idCounter = 0;
c.prototype.wakeUp = function() {
var a = this.sleepState;
this.sleepState = 0;
a === c.SLEEPING && this.dispatchEvent({
type: "wakeup"
})
}
;
c.prototype.sleep = function() {
this.sleepState = c.SLEEPING;
this.velocity.set(0, 0, 0);
this.angularVelocity.set(0, 0, 0)
}
;
c.sleepyEvent = {
type: "sleepy"
};
c.sleepEvent = {
type: "sleep"
};
c.prototype.sleepTick = function(a) {
if (this.allowSleep) {
var b = this.sleepState
, d = this.velocity.norm2() + this.angularVelocity.norm2()
, e = Math.pow(this.sleepSpeedLimit, 2);
b === c.AWAKE && d < e ? (this.sleepState = c.SLEEPY,
this.timeLastSleepy = a,
this.dispatchEvent(c.sleepyEvent)) : b === c.SLEEPY && d > e ? this.wakeUp() : b === c.SLEEPY && a - this.timeLastSleepy > this.sleepTimeLimit && (this.sleep(),
this.dispatchEvent(c.sleepEvent))
}
}
;
c.prototype.updateSolveMassProperties = function() {
this.sleepState === c.SLEEPING || this.type === c.KINEMATIC ? (this.invMassSolve = 0,
this.invInertiaSolve.setZero(),
this.invInertiaWorldSolve.setZero()) : (this.invMassSolve = this.invMass,
this.invInertiaSolve.copy(this.invInertia),
this.invInertiaWorldSolve.copy(this.invInertiaWorld))
}
;
c.prototype.pointToLocalFrame = function(a, c) {
c = c || new b;
a.vsub(this.position, c);
this.quaternion.conjugate().vmult(c, c);
return c
}
;
c.prototype.vectorToLocalFrame = function(a, c) {
c = c || new b;
this.quaternion.conjugate().vmult(a, c);
return c
}
;
c.prototype.pointToWorldFrame = function(a, c) {
c = c || new b;
this.quaternion.vmult(a, c);
c.vadd(this.position, c);
return c
}
;
c.prototype.vectorToWorldFrame = function(a, c) {
c = c || new b;
this.quaternion.vmult(a, c);
return c
}
;
var l = new b
, q = new k;
c.prototype.addShape = function(a, c, d) {
var e = new b
, g = new k;
c && e.copy(c);
d && g.copy(d);
this.shapes.push(a);
this.shapeOffsets.push(e);
this.shapeOrientations.push(g);
this.updateMassProperties();
this.updateBoundingRadius();
this.aabbNeedsUpdate = !0;
return this
}
;
c.prototype.updateBoundingRadius = function() {
for (var a = this.shapes, b = this.shapeOffsets, c = a.length, d = 0, e = 0; e !== c; e++) {
var g = a[e];
g.updateBoundingSphereRadius();
var f = b[e].norm();
g = g.boundingSphereRadius;
f + g > d && (d = f + g)
}
this.boundingRadius = d
}
;
var p = new h;
c.prototype.computeAABB = function() {
for (var a = this.shapes, b = this.shapeOffsets, c = this.shapeOrientations, d = a.length, e = this.quaternion, g = this.aabb, f = 0; f !== d; f++) {
var h = a[f];
c[f].mult(e, q);
q.vmult(b[f], l);
l.vadd(this.position, l);
h.calculateWorldAABB(l, q, p.lowerBound, p.upperBound);
0 === f ? g.copy(p) : g.extend(p)
}
this.aabbNeedsUpdate = !1
}
;
var r = new g
, u = new g;
new g;
c.prototype.updateInertiaWorld = function(a) {
var b = this.invInertia;
if (b.x !== b.y || b.y !== b.z || a)
r.setRotationFromQuaternion(this.quaternion),
r.transpose(u),
r.scale(b, r),
r.mmult(u, this.invInertiaWorld)
}
;
var w = new b
, x = new b;
c.prototype.applyForce = function(a, b) {
this.type === c.DYNAMIC && (b.vsub(this.position, w),
w.cross(a, x),
this.force.vadd(a, this.force),
this.torque.vadd(x, this.torque))
}
;
var t = new b
, v = new b;
c.prototype.applyLocalForce = function(a, b) {
this.type === c.DYNAMIC && (this.vectorToWorldFrame(a, t),
this.pointToWorldFrame(b, v),
this.applyForce(t, v))
}
;
var A = new b
, C = new b
, B = new b;
c.prototype.applyImpulse = function(a, b) {
this.type === c.DYNAMIC && (b.vsub(this.position, A),
C.copy(a),
C.mult(this.invMass, C),
this.velocity.vadd(C, this.velocity),
A.cross(a, B),
this.invInertiaWorld.vmult(B, B),
this.angularVelocity.vadd(B, this.angularVelocity))
}
;
var D = new b
, E = new b;
c.prototype.applyLocalImpulse = function(a, b) {
this.type === c.DYNAMIC && (this.vectorToWorldFrame(a, D),
this.pointToWorldFrame(b, E),
this.applyImpulse(D, E))
}
;
var F = new b;
c.prototype.updateMassProperties = function() {
this.invMass = 0 < this.mass ? 1 / this.mass : 0;
var a = this.inertia
, b = this.fixedRotation;
this.computeAABB();
F.set((this.aabb.upperBound.x - this.aabb.lowerBound.x) / 2, (this.aabb.upperBound.y - this.aabb.lowerBound.y) / 2, (this.aabb.upperBound.z - this.aabb.lowerBound.z) / 2);
n.calculateInertia(F, this.mass, a);
this.invInertia.set(0 < a.x && !b ? 1 / a.x : 0, 0 < a.y && !b ? 1 / a.y : 0, 0 < a.z && !b ? 1 / a.z : 0);
this.updateInertiaWorld(!0)
}
;
c.prototype.getVelocityAtWorldPoint = function(a, c) {
var d = new b;
a.vsub(this.position, d);
this.angularVelocity.cross(d, c);
this.velocity.vadd(c, c);
return c
}
}
, {
"../collision/AABB": 3,
"../material/Material": 25,
"../math/Mat3": 27,
"../math/Quaternion": 28,
"../math/Vec3": 30,
"../shapes/Box": 37,
"../shapes/Shape": 43,
"../utils/EventTarget": 49
}],
32: [function(a, d, f) {
function c(a) {
this.chassisBody = a.chassisBody;
this.wheelInfos = [];
this.sliding = !1;
this.world = null;
this.indexRightAxis = "undefined" !== typeof a.indexRightAxis ? a.indexRightAxis : 1;
this.indexForwardAxis = "undefined" !== typeof a.indexForwardAxis ? a.indexForwardAxis : 0;
this.indexUpAxis = "undefined" !== typeof a.indexUpAxis ? a.indexUpAxis : 2
}
function e(a, b, c) {
var d = C
, e = B
, g = D
, f = E;
b.vsub(a.position, d);
d.cross(c, e);
a.invInertiaWorld.vmult(e, f);
f.cross(d, g);
return a.invMass + c.dot(g)
}
a("./Body");
var b = a("../math/Vec3")
, g = a("../math/Quaternion");
a("../collision/RaycastResult");
f = a("../collision/Ray");
var k = a("../objects/WheelInfo");
d.exports = c;
new b;
new b;
new b;
var h = new b
, n = new b
, l = new b;
new f;
c.prototype.addWheel = function(a) {
a = a || {};
a = new k(a);
var b = this.wheelInfos.length;
this.wheelInfos.push(a);
return b
}
;
c.prototype.setSteeringValue = function(a, b) {
this.wheelInfos[b].steering = a
}
;
new b;
c.prototype.applyEngineForce = function(a, b) {
this.wheelInfos[b].engineForce = a
}
;
c.prototype.setBrake = function(a, b) {
this.wheelInfos[b].brake = a
}
;
c.prototype.addToWorld = function(a) {
a.add(this.chassisBody);
var b = this;
this.preStepCallback = function() {
b.updateVehicle(a.dt)
}
;
a.addEventListener("preStep", this.preStepCallback);
this.world = a
}
;
c.prototype.getVehicleAxisWorld = function(a, b) {
b.set(0 === a ? 1 : 0, 1 === a ? 1 : 0, 2 === a ? 1 : 0);
this.chassisBody.vectorToWorldFrame(b, b)
}
;
c.prototype.updateVehicle = function(a) {
for (var c = this.wheelInfos, d = c.length, e = this.chassisBody, g = 0; g < d; g++)
this.updateWheelTransform(g);
this.currentVehicleSpeedKmHour = 3.6 * e.velocity.norm();
g = new b;
this.getVehicleAxisWorld(this.indexForwardAxis, g);
0 > g.dot(e.velocity) && (this.currentVehicleSpeedKmHour *= -1);
for (g = 0; g < d; g++)
this.castRay(c[g]);
this.updateSuspension(a);
var f = new b
, h = new b;
for (g = 0; g < d; g++) {
var l = c[g]
, p = l.suspensionForce;
p > l.maxSuspensionForce && (p = l.maxSuspensionForce);
l.raycastResult.hitNormalWorld.scale(p * a, f);
l.raycastResult.hitPointWorld.vsub(e.position, h);
e.applyImpulse(f, l.raycastResult.hitPointWorld)
}
this.updateFriction(a);
f = new b;
h = new b;
p = new b;
for (g = 0; g < d; g++) {
l = c[g];
e.getVelocityAtWorldPoint(l.chassisConnectionPointWorld, p);
var n = 1;
switch (this.indexUpAxis) {
case 1:
n = -1
}
if (l.isInContact) {
this.getVehicleAxisWorld(this.indexForwardAxis, h);
var q = h.dot(l.raycastResult.hitNormalWorld);
l.raycastResult.hitNormalWorld.scale(q, f);
h.vsub(f, h);
q = h.dot(p);
l.deltaRotation = n * q * a / l.radius
}
!l.sliding && l.isInContact || 0 === l.engineForce || !l.useCustomSlidingRotationalSpeed || (l.deltaRotation = (0 < l.engineForce ? 1 : -1) * l.customSlidingRotationalSpeed * a);
Math.abs(l.brake) > Math.abs(l.engineForce) && (l.deltaRotation = 0);
l.rotation += l.deltaRotation;
l.deltaRotation *= .99
}
}
;
c.prototype.updateSuspension = function(a) {
a = this.chassisBody.mass;
for (var b = this.wheelInfos, c = b.length, d = 0; d < c; d++) {
var e = b[d];
if (e.isInContact) {
var g = e.suspensionStiffness * (e.suspensionRestLength - e.suspensionLength) * e.clippedInvContactDotSuspension;
var f = e.suspensionRelativeVelocity;
g -= (0 > f ? e.dampingCompression : e.dampingRelaxation) * f;
e.suspensionForce = g * a;
0 > e.suspensionForce && (e.suspensionForce = 0)
} else
e.suspensionForce = 0
}
}
;
c.prototype.removeFromWorld = function(a) {
a.remove(this.chassisBody);
a.removeEventListener("preStep", this.preStepCallback);
this.world = null
}
;
var q = new b
, p = new b;
c.prototype.castRay = function(a) {
this.updateWheelTransformWorld(a);
var c = this.chassisBody
, d = -1;
a.directionWorld.scale(a.suspensionRestLength + a.radius, q);
var e = a.chassisConnectionPointWorld;
e.vadd(q, p);
var g = a.raycastResult;
g.reset();
var f = c.collisionResponse;
c.collisionResponse = !1;
this.world.rayTest(e, p, g);
c.collisionResponse = f;
e = g.body;
a.raycastResult.groundObject = 0;
e ? (d = g.distance,
a.raycastResult.hitNormalWorld = g.hitNormalWorld,
a.isInContact = !0,
a.suspensionLength = g.distance - a.radius,
g = a.suspensionRestLength - a.maxSuspensionTravel,
e = a.suspensionRestLength + a.maxSuspensionTravel,
a.suspensionLength < g && (a.suspensionLength = g),
a.suspensionLength > e && (a.suspensionLength = e,
a.raycastResult.reset()),
g = a.raycastResult.hitNormalWorld.dot(a.directionWorld),
e = new b,
c.getVelocityAtWorldPoint(a.raycastResult.hitPointWorld, e),
c = a.raycastResult.hitNormalWorld.dot(e),
-.1 <= g ? (a.suspensionRelativeVelocity = 0,
a.clippedInvContactDotSuspension = 10) : (g = -1 / g,
a.suspensionRelativeVelocity = c * g,
a.clippedInvContactDotSuspension = g)) : (a.suspensionLength = a.suspensionRestLength + 0 * a.maxSuspensionTravel,
a.suspensionRelativeVelocity = 0,
a.directionWorld.scale(-1, a.raycastResult.hitNormalWorld),
a.clippedInvContactDotSuspension = 1);
return d
}
;
c.prototype.updateWheelTransformWorld = function(a) {
a.isInContact = !1;
var b = this.chassisBody;
b.pointToWorldFrame(a.chassisConnectionPointLocal, a.chassisConnectionPointWorld);
b.vectorToWorldFrame(a.directionLocal, a.directionWorld);
b.vectorToWorldFrame(a.axleLocal, a.axleWorld)
}
;
c.prototype.updateWheelTransform = function(a) {
a = this.wheelInfos[a];
this.updateWheelTransformWorld(a);
a.directionLocal.scale(-1, h);
n.copy(a.axleLocal);
h.cross(n, l);
l.normalize();
n.normalize();
var b = a.steering
, c = new g;
c.setFromAxisAngle(h, b);
b = new g;
b.setFromAxisAngle(n, a.rotation);
var d = a.worldTransform.quaternion;
this.chassisBody.quaternion.mult(c, d);
d.mult(b, d);
d.normalize();
c = a.worldTransform.position;
c.copy(a.directionWorld);
c.scale(a.suspensionLength, c);
c.vadd(a.chassisConnectionPointWorld, c)
}
;
var r = [new b(1,0,0), new b(0,1,0), new b(0,0,1)];
c.prototype.getWheelTransformWorld = function(a) {
return this.wheelInfos[a].worldTransform
}
;
var u = new b
, w = []
, x = [];
c.prototype.updateFriction = function(a) {
for (var c = this.wheelInfos, d = c.length, g = this.chassisBody, f = 0, h = 0; h < d; h++) {
var l = c[h]
, p = l.raycastResult.body;
p && f++;
l.sideImpulse = 0;
l.forwardImpulse = 0;
x[h] || (x[h] = new b);
w[h] || (w[h] = new b)
}
for (h = 0; h < d; h++)
if (l = c[h],
p = l.raycastResult.body) {
var n = w[h];
this.getWheelTransformWorld(h).vectorToWorldFrame(r[this.indexRightAxis], n);
f = l.raycastResult.hitNormalWorld;
var q = n.dot(f);
f.scale(q, u);
n.vsub(u, n);
n.normalize();
f.cross(n, x[h]);
x[h].normalize();
f = l;
q = g;
var k = l.raycastResult.hitPointWorld
, D = l.raycastResult.hitPointWorld;
if (1.1 < n.norm2())
p = 0;
else {
var E = F
, C = H
, B = K;
q.getVelocityAtWorldPoint(k, E);
p.getVelocityAtWorldPoint(D, C);
E.vsub(C, B);
p = -.2 * n.dot(B) * (1 / (q.invMass + p.invMass))
}
f.sideImpulse = p;
l.sideImpulse *= 1
}
this.sliding = !1;
for (h = 0; h < d; h++) {
l = c[h];
p = l.raycastResult.body;
q = 0;
l.slipInfo = 1;
if (p) {
f = l.brake ? l.brake : 0;
E = g;
k = p;
D = l.raycastResult.hitPointWorld;
n = x[h];
q = f;
C = D;
B = t;
var W = v
, S = A;
E.getVelocityAtWorldPoint(C, B);
k.getVelocityAtWorldPoint(C, W);
B.vsub(W, S);
C = n.dot(S);
E = e(E, D, n);
k = e(k, D, n);
k = 1 / (E + k) * -C;
q < k && (k = q);
k < -q && (k = -q);
q = k;
q += l.engineForce * a;
f /= q;
l.slipInfo *= f
}
l.forwardImpulse = 0;
l.skidInfo = 1;
p && (l.skidInfo = 1,
p = l.suspensionForce * a * l.frictionSlip,
f = p * p,
l.forwardImpulse = q,
q = .5 * l.forwardImpulse,
k = 1 * l.sideImpulse,
q = q * q + k * k,
l.sliding = !1,
q > f && (this.sliding = !0,
l.sliding = !0,
f = p / Math.sqrt(q),
l.skidInfo *= f))
}
if (this.sliding)
for (h = 0; h < d; h++)
l = c[h],
0 !== l.sideImpulse && 1 > l.skidInfo && (l.forwardImpulse *= l.skidInfo,
l.sideImpulse *= l.skidInfo);
for (h = 0; h < d; h++)
l = c[h],
a = new b,
a.copy(l.raycastResult.hitPointWorld),
0 !== l.forwardImpulse && (p = new b,
x[h].scale(l.forwardImpulse, p),
g.applyImpulse(p, a)),
0 !== l.sideImpulse && (p = l.raycastResult.body,
f = new b,
f.copy(l.raycastResult.hitPointWorld),
q = new b,
w[h].scale(l.sideImpulse, q),
g.pointToLocalFrame(a, a),
a["xyz"[this.indexUpAxis]] *= l.rollInfluence,
g.pointToWorldFrame(a, a),
g.applyImpulse(q, a),
q.scale(-1, q),
p.applyImpulse(q, f))
}
;
var t = new b
, v = new b
, A = new b
, C = new b
, B = new b
, D = new b
, E = new b
, F = new b
, H = new b
, K = new b
}
, {
"../collision/Ray": 9,
"../collision/RaycastResult": 10,
"../math/Quaternion": 28,
"../math/Vec3": 30,
"../objects/WheelInfo": 36,
"./Body": 31
}],
33: [function(a, d, f) {
function c(a) {
this.wheelBodies = [];
this.coordinateSystem = "undefined" === typeof a.coordinateSystem ? new k(1,2,3) : a.coordinateSystem.clone();
this.chassisBody = a.chassisBody;
this.chassisBody || (a = new g(new k(5,2,.5)),
this.chassisBody = new e(1,a));
this.constraints = [];
this.wheelAxes = [];
this.wheelForces = []
}
var e = a("./Body")
, b = a("../shapes/Sphere")
, g = a("../shapes/Box")
, k = a("../math/Vec3")
, h = a("../constraints/HingeConstraint");
d.exports = c;
c.prototype.addWheel = function(a) {
a = a || {};
var c = a.body;
c || (c = new e(1,new b(1.2)));
this.wheelBodies.push(c);
this.wheelForces.push(0);
new k;
var d = "undefined" !== typeof a.position ? a.position.clone() : new k
, g = new k;
this.chassisBody.pointToWorldFrame(d, g);
c.position.set(g.x, g.y, g.z);
a = "undefined" !== typeof a.axis ? a.axis.clone() : new k(0,1,0);
this.wheelAxes.push(a);
c = new h(this.chassisBody,c,{
pivotA: d,
axisA: a,
pivotB: k.ZERO,
axisB: a,
collideConnected: !1
});
this.constraints.push(c);
return this.wheelBodies.length - 1
}
;
c.prototype.setSteeringValue = function(a, b) {
var c = this.wheelAxes[b]
, d = Math.cos(a)
, e = Math.sin(a)
, g = c.x;
c = c.y;
this.constraints[b].axisA.set(d * g - e * c, e * g + d * c, 0)
}
;
c.prototype.setMotorSpeed = function(a, b) {
var c = this.constraints[b];
c.enableMotor();
c.motorTargetVelocity = a
}
;
c.prototype.disableMotor = function(a) {
this.constraints[a].disableMotor()
}
;
var n = new k;
c.prototype.setWheelForce = function(a, b) {
this.wheelForces[b] = a
}
;
c.prototype.applyWheelForce = function(a, b) {
var c = this.wheelBodies[b]
, d = c.torque;
this.wheelAxes[b].scale(a, n);
c.vectorToWorldFrame(n, n);
d.vadd(n, d)
}
;
c.prototype.addToWorld = function(a) {
for (var b = this.constraints, c = this.wheelBodies.concat([this.chassisBody]), d = 0; d < c.length; d++)
a.add(c[d]);
for (d = 0; d < b.length; d++)
a.addConstraint(b[d]);
a.addEventListener("preStep", this._update.bind(this))
}
;
c.prototype._update = function() {
for (var a = this.wheelForces, b = 0; b < a.length; b++)
this.applyWheelForce(a[b], b)
}
;
c.prototype.removeFromWorld = function(a) {
for (var b = this.constraints, c = this.wheelBodies.concat([this.chassisBody]), d = 0; d < c.length; d++)
a.remove(c[d]);
for (d = 0; d < b.length; d++)
a.removeConstraint(b[d])
}
;
var l = new k;
c.prototype.getWheelSpeed = function(a) {
var b = this.wheelBodies[a].angularVelocity;
this.chassisBody.vectorToWorldFrame(this.wheelAxes[a], l);
return b.dot(l)
}
}
, {
"../constraints/HingeConstraint": 15,
"../math/Vec3": 30,
"../shapes/Box": 37,
"../shapes/Sphere": 44,
"./Body": 31
}],
34: [function(a, d, f) {
function c() {
this.particles = [];
this.speedOfSound = this.smoothingRadius = this.density = 1;
this.viscosity = .01;
this.eps = 1E-6;
this.pressures = [];
this.densities = [];
this.neighbors = []
}
d.exports = c;
a("../shapes/Shape");
d = a("../math/Vec3");
a("../math/Quaternion");
a("../shapes/Particle");
a("../objects/Body");
a("../material/Material");
c.prototype.add = function(a) {
this.particles.push(a);
this.neighbors.length < this.particles.length && this.neighbors.push([])
}
;
c.prototype.remove = function(a) {
a = this.particles.indexOf(a);
-1 !== a && (this.particles.splice(a, 1),
this.neighbors.length > this.particles.length && this.neighbors.pop())
}
;
var e = new d;
c.prototype.getNeighbors = function(a, b) {
for (var c = this.particles.length, d = a.id, g = this.smoothingRadius * this.smoothingRadius, f = 0; f !== c; f++) {
var h = this.particles[f];
h.position.vsub(a.position, e);
d !== h.id && e.norm2() < g && b.push(h)
}
}
;
var b = new d
, g = new d
, k = new d
, h = new d
, n = new d
, l = new d;
c.prototype.update = function() {
for (var a = this.particles.length, c = this.speedOfSound, d = this.eps, e = 0; e !== a; e++) {
var f = this.particles[e]
, x = this.neighbors[e];
x.length = 0;
this.getNeighbors(f, x);
x.push(this.particles[e]);
for (var t = x.length, v = 0, A = 0; A !== t; A++) {
f.position.vsub(x[A].position, b);
var C = b.norm();
C = this.w(C);
v += x[A].mass * C
}
this.densities[e] = v;
this.pressures[e] = c * c * (this.densities[e] - this.density)
}
for (e = 0; e !== a; e++) {
c = this.particles[e];
g.set(0, 0, 0);
k.set(0, 0, 0);
x = this.neighbors[e];
t = x.length;
for (A = 0; A !== t; A++)
v = x[A],
c.position.vsub(v.position, n),
C = n.norm(),
f = -v.mass * (this.pressures[e] / (this.densities[e] * this.densities[e] + d) + this.pressures[A] / (this.densities[A] * this.densities[A] + d)),
this.gradw(n, h),
h.mult(f, h),
g.vadd(h, g),
v.velocity.vsub(c.velocity, l),
l.mult(1 / (1E-4 + this.densities[e] * this.densities[A]) * this.viscosity * v.mass, l),
f = this.nablaw(C),
l.mult(f, l),
k.vadd(l, k);
k.mult(c.mass, k);
g.mult(c.mass, g);
c.force.vadd(k, c.force);
c.force.vadd(g, c.force)
}
}
;
c.prototype.w = function(a) {
var b = this.smoothingRadius;
return 315 / (64 * Math.PI * Math.pow(b, 9)) * Math.pow(b * b - a * a, 3)
}
;
c.prototype.gradw = function(a, b) {
var c = a.norm()
, d = this.smoothingRadius;
a.mult(945 / (32 * Math.PI * Math.pow(d, 9)) * Math.pow(d * d - c * c, 2), b)
}
;
c.prototype.nablaw = function(a) {
var b = this.smoothingRadius;
return 945 / (32 * Math.PI * Math.pow(b, 9)) * (b * b - a * a) * (7 * a * a - 3 * b * b)
}
}
, {
"../material/Material": 25,
"../math/Quaternion": 28,
"../math/Vec3": 30,
"../objects/Body": 31,
"../shapes/Particle": 41,
"../shapes/Shape": 43
}],
35: [function(a, d, f) {
function c(a, b, c) {
c = c || {};
this.restLength = "number" === typeof c.restLength ? c.restLength : 1;
this.stiffness = c.stiffness || 100;
this.damping = c.damping || 1;
this.bodyA = a;
this.bodyB = b;
this.localAnchorA = new e;
this.localAnchorB = new e;
c.localAnchorA && this.localAnchorA.copy(c.localAnchorA);
c.localAnchorB && this.localAnchorB.copy(c.localAnchorB);
c.worldAnchorA && this.setWorldAnchorA(c.worldAnchorA);
c.worldAnchorB && this.setWorldAnchorB(c.worldAnchorB)
}
var e = a("../math/Vec3");
d.exports = c;
c.prototype.setWorldAnchorA = function(a) {
this.bodyA.pointToLocalFrame(a, this.localAnchorA)
}
;
c.prototype.setWorldAnchorB = function(a) {
this.bodyB.pointToLocalFrame(a, this.localAnchorB)
}
;
c.prototype.getWorldAnchorA = function(a) {
this.bodyA.pointToWorldFrame(this.localAnchorA, a)
}
;
c.prototype.getWorldAnchorB = function(a) {
this.bodyB.pointToWorldFrame(this.localAnchorB, a)
}
;
var b = new e
, g = new e
, k = new e
, h = new e
, n = new e
, l = new e
, q = new e
, p = new e
, r = new e
, u = new e
, w = new e;
c.prototype.applyForce = function() {
var a = this.stiffness
, c = this.damping
, d = this.restLength
, e = this.bodyA
, f = this.bodyB;
this.getWorldAnchorA(n);
this.getWorldAnchorB(l);
n.vsub(e.position, q);
l.vsub(f.position, p);
l.vsub(n, b);
var B = b.norm();
g.copy(b);
g.normalize();
f.velocity.vsub(e.velocity, k);
f.angularVelocity.cross(p, w);
k.vadd(w, k);
e.angularVelocity.cross(q, w);
k.vsub(w, k);
g.mult(-a * (B - d) - c * k.dot(g), h);
e.force.vsub(h, e.force);
f.force.vadd(h, f.force);
q.cross(h, r);
p.cross(h, u);
e.torque.vsub(r, e.torque);
f.torque.vadd(u, f.torque)
}
}
, {
"../math/Vec3": 30
}],
36: [function(a, d, f) {
function c(a) {
a = k.defaults(a, {
chassisConnectionPointLocal: new e,
chassisConnectionPointWorld: new e,
directionLocal: new e,
directionWorld: new e,
axleLocal: new e,
axleWorld: new e,
suspensionRestLength: 1,
suspensionMaxLength: 2,
radius: 1,
suspensionStiffness: 100,
dampingCompression: 10,
dampingRelaxation: 10,
frictionSlip: 1E4,
steering: 0,
rotation: 0,
deltaRotation: 0,
rollInfluence: .01,
maxSuspensionForce: Number.MAX_VALUE,
isFrontWheel: !0,
clippedInvContactDotSuspension: 1,
suspensionRelativeVelocity: 0,
suspensionForce: 0,
skidInfo: 0,
suspensionLength: 0,
maxSuspensionTravel: 1,
useCustomSlidingRotationalSpeed: !1,
customSlidingRotationalSpeed: -.1
});
this.maxSuspensionTravel = a.maxSuspensionTravel;
this.customSlidingRotationalSpeed = a.customSlidingRotationalSpeed;
this.useCustomSlidingRotationalSpeed = a.useCustomSlidingRotationalSpeed;
this.sliding = !1;
this.chassisConnectionPointLocal = a.chassisConnectionPointLocal.clone();
this.chassisConnectionPointWorld = a.chassisConnectionPointWorld.clone();
this.directionLocal = a.directionLocal.clone();
this.directionWorld = a.directionWorld.clone();
this.axleLocal = a.axleLocal.clone();
this.axleWorld = a.axleWorld.clone();
this.suspensionRestLength = a.suspensionRestLength;
this.suspensionMaxLength = a.suspensionMaxLength;
this.radius = a.radius;
this.suspensionStiffness = a.suspensionStiffness;
this.dampingCompression = a.dampingCompression;
this.dampingRelaxation = a.dampingRelaxation;
this.frictionSlip = a.frictionSlip;
this.deltaRotation = this.rotation = this.steering = 0;
this.rollInfluence = a.rollInfluence;
this.maxSuspensionForce = a.maxSuspensionForce;
this.brake = this.engineForce = 0;
this.isFrontWheel = a.isFrontWheel;
this.clippedInvContactDotSuspension = 1;
this.forwardImpulse = this.sideImpulse = this.suspensionLength = this.skidInfo = this.suspensionForce = this.suspensionRelativeVelocity = 0;
this.raycastResult = new g;
this.worldTransform = new b;
this.isInContact = !1
}
var e = a("../math/Vec3")
, b = a("../math/Transform")
, g = a("../collision/RaycastResult")
, k = a("../utils/Utils");
d.exports = c;
var h = new e
, n = new e;
h = new e;
c.prototype.updateWheel = function(a) {
var b = this.raycastResult;
if (this.isInContact) {
var c = b.hitNormalWorld.dot(b.directionWorld);
b.hitPointWorld.vsub(a.position, n);
a.getVelocityAtWorldPoint(n, h);
a = b.hitNormalWorld.dot(h);
-.1 <= c ? (this.suspensionRelativeVelocity = 0,
this.clippedInvContactDotSuspension = 10) : (c = -1 / c,
this.suspensionRelativeVelocity = a * c,
this.clippedInvContactDotSuspension = c)
} else
b.suspensionLength = this.suspensionRestLength,
this.suspensionRelativeVelocity = 0,
b.directionWorld.scale(-1, b.hitNormalWorld),
this.clippedInvContactDotSuspension = 1
}
}
, {
"../collision/RaycastResult": 10,
"../math/Transform": 29,
"../math/Vec3": 30,
"../utils/Utils": 53
}],
37: [function(a, d, f) {
function c(a) {
e.call(this);
this.type = e.types.BOX;
this.halfExtents = a;
this.convexPolyhedronRepresentation = null;
this.updateConvexPolyhedronRepresentation();
this.updateBoundingSphereRadius()
}
d.exports = c;
var e = a("./Shape")
, b = a("../math/Vec3")
, g = a("./ConvexPolyhedron");
c.prototype = new e;
c.prototype.constructor = c;
c.prototype.updateConvexPolyhedronRepresentation = function() {
var a = this.halfExtents.x
, c = this.halfExtents.y
, d = this.halfExtents.z;
a = [new b(-a,-c,-d), new b(a,-c,-d), new b(a,c,-d), new b(-a,c,-d), new b(-a,-c,d), new b(a,-c,d), new b(a,c,d), new b(-a,c,d)];
new b(0,0,1);
new b(0,1,0);
new b(1,0,0);
this.convexPolyhedronRepresentation = a = new g(a,[[3, 2, 1, 0], [4, 5, 6, 7], [5, 4, 0, 1], [2, 3, 7, 6], [0, 4, 7, 3], [1, 2, 6, 5]]);
a.material = this.material
}
;
c.prototype.calculateLocalInertia = function(a, d) {
d = d || new b;
c.calculateInertia(this.halfExtents, a, d);
return d
}
;
c.calculateInertia = function(a, b, c) {
c.x = 1 / 12 * b * (4 * a.y * a.y + 4 * a.z * a.z);
c.y = 1 / 12 * b * (4 * a.x * a.x + 4 * a.z * a.z);
c.z = 1 / 12 * b * (4 * a.y * a.y + 4 * a.x * a.x)
}
;
c.prototype.getSideNormals = function(a, b) {
var c = this.halfExtents;
a[0].set(c.x, 0, 0);
a[1].set(0, c.y, 0);
a[2].set(0, 0, c.z);
a[3].set(-c.x, 0, 0);
a[4].set(0, -c.y, 0);
a[5].set(0, 0, -c.z);
if (void 0 !== b)
for (c = 0; c !== a.length; c++)
b.vmult(a[c], a[c]);
return a
}
;
c.prototype.volume = function() {
return 8 * this.halfExtents.x * this.halfExtents.y * this.halfExtents.z
}
;
c.prototype.updateBoundingSphereRadius = function() {
this.boundingSphereRadius = this.halfExtents.norm()
}
;
var k = new b;
new b;
c.prototype.forEachWorldCorner = function(a, b, c) {
var d = this.halfExtents;
d = [[d.x, d.y, d.z], [-d.x, d.y, d.z], [-d.x, -d.y, d.z], [-d.x, -d.y, -d.z], [d.x, -d.y, -d.z], [d.x, d.y, -d.z], [-d.x, d.y, -d.z], [d.x, -d.y, d.z]];
for (var e = 0; e < d.length; e++)
k.set(d[e][0], d[e][1], d[e][2]),
b.vmult(k, k),
a.vadd(k, k),
c(k.x, k.y, k.z)
}
;
var h = [new b, new b, new b, new b, new b, new b, new b, new b];
c.prototype.calculateWorldAABB = function(a, b, c, d) {
var e = this.halfExtents;
h[0].set(e.x, e.y, e.z);
h[1].set(-e.x, e.y, e.z);
h[2].set(-e.x, -e.y, e.z);
h[3].set(-e.x, -e.y, -e.z);
h[4].set(e.x, -e.y, -e.z);
h[5].set(e.x, e.y, -e.z);
h[6].set(-e.x, e.y, -e.z);
h[7].set(e.x, -e.y, e.z);
var g = h[0];
b.vmult(g, g);
a.vadd(g, g);
d.copy(g);
c.copy(g);
for (e = 1; 8 > e; e++) {
g = h[e];
b.vmult(g, g);
a.vadd(g, g);
var f = g.x
, l = g.y;
g = g.z;
f > d.x && (d.x = f);
l > d.y && (d.y = l);
g > d.z && (d.z = g);
f < c.x && (c.x = f);
l < c.y && (c.y = l);
g < c.z && (c.z = g)
}
}
}
, {
"../math/Vec3": 30,
"./ConvexPolyhedron": 38,
"./Shape": 43
}],
38: [function(a, d, f) {
function c(a, b, c) {
e.call(this);
this.type = e.types.CONVEXPOLYHEDRON;
this.vertices = a || [];
this.worldVertices = [];
this.worldVerticesNeedsUpdate = !0;
this.faces = b || [];
this.faceNormals = [];
this.computeNormals();
this.worldFaceNormalsNeedsUpdate = !0;
this.worldFaceNormals = [];
this.uniqueEdges = [];
this.uniqueAxes = c ? c.slice() : null;
this.computeEdges();
this.updateBoundingSphereRadius()
}
d.exports = c;
var e = a("./Shape")
, b = a("../math/Vec3");
a("../math/Quaternion");
var g = a("../math/Transform");
c.prototype = new e;
c.prototype.constructor = c;
var k = new b;
c.prototype.computeEdges = function() {
for (var a = this.faces, b = this.vertices, c = this.uniqueEdges, d = c.length = 0; d !== a.length; d++)
for (var e = a[d], g = e.length, f = 0; f !== g; f++) {
b[e[f]].vsub(b[e[(f + 1) % g]], k);
k.normalize();
for (var h = !1, l = 0; l !== c.length; l++)
if (c[l].almostEquals(k) || c[l].almostEquals(k)) {
h = !0;
break
}
h || c.push(k.clone())
}
}
;
c.prototype.computeNormals = function() {
this.faceNormals.length = this.faces.length;
for (var a = 0; a < this.faces.length; a++) {
for (var c = 0; c < this.faces[a].length; c++)
if (!this.vertices[this.faces[a][c]])
throw Error("Vertex " + this.faces[a][c] + " not found!");
c = this.faceNormals[a] || new b;
this.getFaceNormal(a, c);
c.negate(c);
this.faceNormals[a] = c;
if (0 > c.dot(this.vertices[this.faces[a][0]]))
for (console.error(".faceNormals[" + a + "] = Vec3(" + c.toString() + ") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule."),
c = 0; c < this.faces[a].length; c++)
console.warn(".vertices[" + this.faces[a][c] + "] = Vec3(" + this.vertices[this.faces[a][c]].toString() + ")")
}
}
;
var h = new b
, n = new b;
c.computeNormal = function(a, b, c, d) {
b.vsub(a, n);
c.vsub(b, h);
h.cross(n, d);
d.isZero() || d.normalize()
}
;
c.prototype.getFaceNormal = function(a, b) {
var d = this.faces[a];
return c.computeNormal(this.vertices[d[0]], this.vertices[d[1]], this.vertices[d[2]], b)
}
;
var l = new b;
c.prototype.clipAgainstHull = function(a, c, d, e, g, f, h, n, p) {
for (var k = -1, q = -Number.MAX_VALUE, r = 0; r < d.faces.length; r++) {
l.copy(d.faceNormals[r]);
g.vmult(l, l);
var u = l.dot(f);
u > q && (q = u,
k = r)
}
q = [];
r = d.faces[k];
u = r.length;
for (var z = 0; z < u; z++) {
var w = d.vertices[r[z]]
, y = new b;
y.copy(w);
g.vmult(y, y);
e.vadd(y, y);
q.push(y)
}
0 <= k && this.clipFaceAgainstHull(f, a, c, q, h, n, p)
}
;
var q = new b
, p = new b
, r = new b
, u = new b
, w = new b
, x = new b;
c.prototype.findSeparatingAxis = function(a, b, c, d, e, g, f, h) {
var l = Number.MAX_VALUE
, n = 0;
if (this.uniqueAxes)
for (z = 0; z !== this.uniqueAxes.length; z++) {
c.vmult(this.uniqueAxes[z], q);
y = this.testSepAxis(q, a, b, c, d, e);
if (!1 === y)
return !1;
y < l && (l = y,
g.copy(q))
}
else
for (var k = f ? f.length : this.faces.length, z = 0; z < k; z++) {
y = f ? f[z] : z;
q.copy(this.faceNormals[y]);
c.vmult(q, q);
var y = this.testSepAxis(q, a, b, c, d, e);
if (!1 === y)
return !1;
y < l && (l = y,
g.copy(q))
}
if (a.uniqueAxes)
for (z = 0; z !== a.uniqueAxes.length; z++) {
e.vmult(a.uniqueAxes[z], p);
n++;
y = this.testSepAxis(p, a, b, c, d, e);
if (!1 === y)
return !1;
y < l && (l = y,
g.copy(p))
}
else
for (f = h ? h.length : a.faces.length,
z = 0; z < f; z++) {
y = h ? h[z] : z;
p.copy(a.faceNormals[y]);
e.vmult(p, p);
n++;
y = this.testSepAxis(p, a, b, c, d, e);
if (!1 === y)
return !1;
y < l && (l = y,
g.copy(p))
}
for (h = 0; h !== this.uniqueEdges.length; h++)
for (c.vmult(this.uniqueEdges[h], u),
n = 0; n !== a.uniqueEdges.length; n++)
if (e.vmult(a.uniqueEdges[n], w),
u.cross(w, x),
!x.almostZero()) {
x.normalize();
z = this.testSepAxis(x, a, b, c, d, e);
if (!1 === z)
return !1;
z < l && (l = z,
g.copy(x))
}
d.vsub(b, r);
0 < r.dot(g) && g.negate(g);
return !0
}
;
var t = []
, v = [];
c.prototype.testSepAxis = function(a, b, d, e, g, f) {
c.project(this, a, d, e, t);
c.project(b, a, g, f, v);
d = t[0];
a = t[1];
b = v[0];
e = v[1];
if (d < e || b < a)
return !1;
d -= e;
a = b - a;
return d < a ? d : a
}
;
var A = new b
, C = new b;
c.prototype.calculateLocalInertia = function(a, b) {
this.computeLocalAABB(A, C);
var c = C.x - A.x
, d = C.y - A.y
, e = C.z - A.z;
b.x = 1 / 12 * a * (4 * d * d + 4 * e * e);
b.y = 1 / 12 * a * (4 * c * c + 4 * e * e);
b.z = 1 / 12 * a * (4 * d * d + 4 * c * c)
}
;
c.prototype.getPlaneConstantOfFace = function(a) {
return -this.faceNormals[a].dot(this.vertices[this.faces[a][0]])
}
;
var B = new b
, D = new b
, E = new b
, F = new b
, H = new b
, K = new b
, I = new b
, N = new b;
c.prototype.clipFaceAgainstHull = function(a, b, c, d, e, g, f) {
for (var h = [], l = -1, n = Number.MAX_VALUE, p = 0; p < this.faces.length; p++) {
B.copy(this.faceNormals[p]);
c.vmult(B, B);
var k = B.dot(a);
k < n && (n = k,
l = p)
}
if (!(0 > l)) {
a = this.faces[l];
a.connectedFaces = [];
for (n = 0; n < this.faces.length; n++)
for (p = 0; p < this.faces[n].length; p++)
-1 !== a.indexOf(this.faces[n][p]) && n !== l && -1 === a.connectedFaces.indexOf(n) && a.connectedFaces.push(n);
n = a.length;
for (p = 0; p < n; p++) {
k = this.vertices[a[p]];
k.vsub(this.vertices[a[(p + 1) % n]], D);
E.copy(D);
c.vmult(E, E);
b.vadd(E, E);
F.copy(this.faceNormals[l]);
c.vmult(F, F);
b.vadd(F, F);
E.cross(F, H);
H.negate(H);
K.copy(k);
c.vmult(K, K);
b.vadd(K, K);
K.dot(H);
k = a.connectedFaces[p];
I.copy(this.faceNormals[k]);
k = this.getPlaneConstantOfFace(k);
N.copy(I);
c.vmult(N, N);
k -= N.dot(b);
for (this.clipFaceAgainstPlane(d, h, N, k); d.length; )
d.shift();
for (; h.length; )
d.push(h.shift())
}
I.copy(this.faceNormals[l]);
k = this.getPlaneConstantOfFace(l);
N.copy(I);
c.vmult(N, N);
k -= N.dot(b);
for (n = 0; n < d.length; n++)
b = N.dot(d[n]) + k,
b <= e && (console.log("clamped: depth=" + b + " to minDist=" + (e + "")),
b = e),
b <= g && (c = d[n],
0 >= b && f.push({
point: c,
normal: N,
depth: b
}))
}
}
;
c.prototype.clipFaceAgainstPlane = function(a, c, d, e) {
var g = a.length;
if (2 > g)
return c;
var f = a[a.length - 1];
var h = d.dot(f) + e;
for (var l = 0; l < g; l++) {
var n = a[l];
var p = d.dot(n) + e;
if (0 > h) {
if (0 > p) {
var k = new b;
k.copy(n)
} else
k = new b,
f.lerp(n, h / (h - p), k);
c.push(k)
} else
0 > p && (k = new b,
f.lerp(n, h / (h - p), k),
c.push(k),
c.push(n));
f = n;
h = p
}
return c
}
;
c.prototype.computeWorldVertices = function(a, c) {
for (var d = this.vertices.length; this.worldVertices.length < d; )
this.worldVertices.push(new b);
for (var e = this.vertices, g = this.worldVertices, f = 0; f !== d; f++)
c.vmult(e[f], g[f]),
a.vadd(g[f], g[f]);
this.worldVerticesNeedsUpdate = !1
}
;
new b;
c.prototype.computeLocalAABB = function(a, b) {
var c = this.vertices.length
, d = this.vertices;
a.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
b.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
for (var e = 0; e < c; e++) {
var g = d[e];
g.x < a.x ? a.x = g.x : g.x > b.x && (b.x = g.x);
g.y < a.y ? a.y = g.y : g.y > b.y && (b.y = g.y);
g.z < a.z ? a.z = g.z : g.z > b.z && (b.z = g.z)
}
}
;
c.prototype.computeWorldFaceNormals = function(a) {
for (var c = this.faceNormals.length; this.worldFaceNormals.length < c; )
this.worldFaceNormals.push(new b);
for (var d = this.faceNormals, e = this.worldFaceNormals, g = 0; g !== c; g++)
a.vmult(d[g], e[g]);
this.worldFaceNormalsNeedsUpdate = !1
}
;
c.prototype.updateBoundingSphereRadius = function() {
for (var a = 0, b = this.vertices, c = 0, d = b.length; c !== d; c++) {
var e = b[c].norm2();
e > a && (a = e)
}
this.boundingSphereRadius = Math.sqrt(a)
}
;
var y = new b;
c.prototype.calculateWorldAABB = function(a, b, c, d) {
for (var e = this.vertices.length, g = this.vertices, f, h, l, n, p, k, q = 0; q < e; q++) {
y.copy(g[q]);
b.vmult(y, y);
a.vadd(y, y);
var r = y;
if (r.x < f || void 0 === f)
f = r.x;
else if (r.x > n || void 0 === n)
n = r.x;
if (r.y < h || void 0 === h)
h = r.y;
else if (r.y > p || void 0 === p)
p = r.y;
if (r.z < l || void 0 === l)
l = r.z;
else if (r.z > k || void 0 === k)
k = r.z
}
c.set(f, h, l);
d.set(n, p, k)
}
;
c.prototype.volume = function() {
return 4 * Math.PI * this.boundingSphereRadius / 3
}
;
c.prototype.getAveragePointLocal = function(a) {
a = a || new b;
for (var c = this.vertices.length, d = this.vertices, e = 0; e < c; e++)
a.vadd(d[e], a);
a.mult(1 / c, a);
return a
}
;
c.prototype.transformAllPoints = function(a, b) {
var c = this.vertices.length
, d = this.vertices;
if (b) {
for (var e = 0; e < c; e++) {
var g = d[e];
b.vmult(g, g)
}
for (e = 0; e < this.faceNormals.length; e++)
g = this.faceNormals[e],
b.vmult(g, g)
}
if (a)
for (e = 0; e < c; e++)
g = d[e],
g.vadd(a, g)
}
;
var M = new b
, J = new b
, z = new b;
c.prototype.pointIsInside = function(a) {
var b = this.vertices
, c = this.faces
, d = this.faceNormals
, e = this.faces.length;
this.getAveragePointLocal(M);
for (var g = 0; g < e; g++) {
var f = d[g];
var h = b[c[g][0]]
, l = J;
a.vsub(h, l);
l = f.dot(l);
var n = z;
M.vsub(h, n);
f = f.dot(n);
if (0 > l && 0 < f || 0 < l && 0 > f)
return !1
}
return -1
}
;
new b;
var O = new b
, L = new b;
c.project = function(a, b, c, d, e) {
var f = a.vertices.length;
a = a.vertices;
L.setZero();
g.vectorToLocalFrame(c, d, b, O);
g.pointToLocalFrame(c, d, L, L);
d = L.dot(O);
c = b = a[0].dot(O);
for (var h = 1; h < f; h++) {
var l = a[h].dot(O);
l > b && (b = l);
l < c && (c = l)
}
c -= d;
b -= d;
c > b && (f = c,
c = b,
b = f);
e[0] = b;
e[1] = c
}
}
, {
"../math/Quaternion": 28,
"../math/Transform": 29,
"../math/Vec3": 30,
"./Shape": 43
}],
39: [function(a, d, f) {
function c(a, c, d, f) {
var h = []
, l = []
, n = []
, k = []
, w = []
, x = Math.cos
, t = Math.sin;
h.push(new b(c * x(0),c * t(0),.5 * -d));
k.push(0);
h.push(new b(a * x(0),a * t(0),.5 * d));
w.push(1);
for (var v = 0; v < f; v++) {
var A = 2 * Math.PI / f * (v + 1)
, C = 2 * Math.PI / f * (v + .5);
v < f - 1 ? (h.push(new b(c * x(A),c * t(A),.5 * -d)),
k.push(2 * v + 2),
h.push(new b(a * x(A),a * t(A),.5 * d)),
w.push(2 * v + 3),
n.push([2 * v + 2, 2 * v + 3, 2 * v + 1, 2 * v])) : n.push([0, 1, 2 * v + 1, 2 * v]);
(1 === f % 2 || v < f / 2) && l.push(new b(x(C),t(C),0))
}
n.push(w);
l.push(new b(0,0,1));
a = [];
for (v = 0; v < k.length; v++)
a.push(k[k.length - v - 1]);
n.push(a);
this.type = e.types.CONVEXPOLYHEDRON;
g.call(this, h, n, l)
}
d.exports = c;
var e = a("./Shape")
, b = a("../math/Vec3");
a("../math/Quaternion");
var g = a("./ConvexPolyhedron");
c.prototype = new g
}
, {
"../math/Quaternion": 28,
"../math/Vec3": 30,
"./ConvexPolyhedron": 38,
"./Shape": 43
}],
40: [function(a, d, f) {
function c(a, c) {
c = k.defaults(c, {
maxValue: null,
minValue: null,
elementSize: 1
});
this.data = a;
this.maxValue = c.maxValue;
this.minValue = c.minValue;
this.elementSize = c.elementSize;
null === c.minValue && this.updateMinValue();
null === c.maxValue && this.updateMaxValue();
this.cacheEnabled = !0;
e.call(this);
this.pillarConvex = new b;
this.pillarOffset = new g;
this.type = e.types.HEIGHTFIELD;
this.updateBoundingSphereRadius();
this._cachedPillars = {}
}
var e = a("./Shape")
, b = a("./ConvexPolyhedron")
, g = a("../math/Vec3")
, k = a("../utils/Utils");
d.exports = c;
c.prototype = new e;
c.prototype.update = function() {
this._cachedPillars = {}
}
;
c.prototype.updateMinValue = function() {
for (var a = this.data, b = a[0][0], c = 0; c !== a.length; c++)
for (var d = 0; d !== a[c].length; d++) {
var e = a[c][d];
e < b && (b = e)
}
this.minValue = b
}
;
c.prototype.updateMaxValue = function() {
for (var a = this.data, b = a[0][0], c = 0; c !== a.length; c++)
for (var d = 0; d !== a[c].length; d++) {
var e = a[c][d];
e > b && (b = e)
}
this.maxValue = b
}
;
c.prototype.setHeightValueAtIndex = function(a, b, c) {
this.data[a][b] = c;
this.clearCachedConvexTrianglePillar(a, b, !1);
0 < a && (this.clearCachedConvexTrianglePillar(a - 1, b, !0),
this.clearCachedConvexTrianglePillar(a - 1, b, !1));
0 < b && (this.clearCachedConvexTrianglePillar(a, b - 1, !0),
this.clearCachedConvexTrianglePillar(a, b - 1, !1));
0 < b && 0 < a && this.clearCachedConvexTrianglePillar(a - 1, b - 1, !0)
}
;
c.prototype.getRectMinMax = function(a, b, c, d, e) {
e = e || [];
for (var g = this.data, f = this.minValue; a <= c; a++)
for (var h = b; h <= d; h++) {
var l = g[a][h];
l > f && (f = l)
}
e[0] = this.minValue;
e[1] = f
}
;
c.prototype.getIndexOfPosition = function(a, b, c, d) {
var e = this.elementSize
, g = this.data;
a = Math.floor(a / e);
b = Math.floor(b / e);
c[0] = a;
c[1] = b;
d && (0 > a && (a = 0),
0 > b && (b = 0),
a >= g.length - 1 && (a = g.length - 1),
b >= g[0].length - 1 && (b = g[0].length - 1));
return 0 > a || 0 > b || a >= g.length - 1 || b >= g[0].length - 1 ? !1 : !0
}
;
c.prototype.getHeightAt = function(a, b, c) {
var d = [];
this.getIndexOfPosition(a, b, d, c);
a = [];
this.getRectMinMax(d[0], d[1] + 1, d[0], d[1] + 1, a);
return (a[0] + a[1]) / 2
}
;
c.prototype.getCacheConvexTrianglePillarKey = function(a, b, c) {
return a + "_" + b + "_" + (c ? 1 : 0)
}
;
c.prototype.getCachedConvexTrianglePillar = function(a, b, c) {
return this._cachedPillars[this.getCacheConvexTrianglePillarKey(a, b, c)]
}
;
c.prototype.setCachedConvexTrianglePillar = function(a, b, c, d, e) {
this._cachedPillars[this.getCacheConvexTrianglePillarKey(a, b, c)] = {
convex: d,
offset: e
}
}
;
c.prototype.clearCachedConvexTrianglePillar = function(a, b, c) {
delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(a, b, c)]
}
;
c.prototype.getConvexTrianglePillar = function(a, c, d) {
var e = this.pillarConvex
, f = this.pillarOffset;
if (this.cacheEnabled) {
var h = this.getCachedConvexTrianglePillar(a, c, d);
if (h) {
this.pillarConvex = h.convex;
this.pillarOffset = h.offset;
return
}
e = new b;
f = new g;
this.pillarConvex = e;
this.pillarOffset = f
}
h = this.data;
var l = this.elementSize
, k = e.faces;
e.vertices.length = 6;
for (var n = 0; 6 > n; n++)
e.vertices[n] || (e.vertices[n] = new g);
k.length = 5;
for (n = 0; 5 > n; n++)
k[n] || (k[n] = []);
n = e.vertices;
var t = (Math.min(h[a][c], h[a + 1][c], h[a][c + 1], h[a + 1][c + 1]) - this.minValue) / 2 + this.minValue;
d ? (f.set((a + .75) * l, (c + .75) * l, t),
n[0].set(.25 * l, .25 * l, h[a + 1][c + 1] - t),
n[1].set(-.75 * l, .25 * l, h[a][c + 1] - t),
n[2].set(.25 * l, -.75 * l, h[a + 1][c] - t),
n[3].set(.25 * l, .25 * l, -t - 1),
n[4].set(-.75 * l, .25 * l, -t - 1),
n[5].set(.25 * l, -.75 * l, -t - 1),
k[0][0] = 0,
k[0][1] = 1,
k[0][2] = 2,
k[1][0] = 5,
k[1][1] = 4,
k[1][2] = 3,
k[2][0] = 2,
k[2][1] = 5,
k[2][2] = 3,
k[2][3] = 0,
k[3][0] = 3,
k[3][1] = 4,
k[3][2] = 1,
k[3][3] = 0,
k[4][0] = 1,
k[4][1] = 4,
k[4][2] = 5,
k[4][3] = 2) : (f.set((a + .25) * l, (c + .25) * l, t),
n[0].set(-.25 * l, -.25 * l, h[a][c] - t),
n[1].set(.75 * l, -.25 * l, h[a + 1][c] - t),
n[2].set(-.25 * l, .75 * l, h[a][c + 1] - t),
n[3].set(-.25 * l, -.25 * l, -t - 1),
n[4].set(.75 * l, -.25 * l, -t - 1),
n[5].set(-.25 * l, .75 * l, -t - 1),
k[0][0] = 0,
k[0][1] = 1,
k[0][2] = 2,
k[1][0] = 5,
k[1][1] = 4,
k[1][2] = 3,
k[2][0] = 0,
k[2][1] = 2,
k[2][2] = 5,
k[2][3] = 3,
k[3][0] = 1,
k[3][1] = 0,
k[3][2] = 3,
k[3][3] = 4,
k[4][0] = 4,
k[4][1] = 5,
k[4][2] = 2,
k[4][3] = 1);
e.computeNormals();
e.computeEdges();
e.updateBoundingSphereRadius();
this.setCachedConvexTrianglePillar(a, c, d, e, f)
}
;
c.prototype.calculateLocalInertia = function(a, b) {
b = b || new g;
b.set(0, 0, 0);
return b
}
;
c.prototype.volume = function() {
return Number.MAX_VALUE
}
;
c.prototype.calculateWorldAABB = function(a, b, c, d) {
c.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
d.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE)
}
;
c.prototype.updateBoundingSphereRadius = function() {
var a = this.data
, b = this.elementSize;
this.boundingSphereRadius = (new g(a.length * b,a[0].length * b,Math.max(Math.abs(this.maxValue), Math.abs(this.minValue)))).norm()
}
}
, {
"../math/Vec3": 30,
"../utils/Utils": 53,
"./ConvexPolyhedron": 38,
"./Shape": 43
}],
41: [function(a, d, f) {
function c() {
e.call(this);
this.type = e.types.PARTICLE
}
d.exports = c;
var e = a("./Shape")
, b = a("../math/Vec3");
c.prototype = new e;
c.prototype.constructor = c;
c.prototype.calculateLocalInertia = function(a, c) {
c = c || new b;
c.set(0, 0, 0);
return c
}
;
c.prototype.volume = function() {
return 0
}
;
c.prototype.updateBoundingSphereRadius = function() {
this.boundingSphereRadius = 0
}
;
c.prototype.calculateWorldAABB = function(a, b, c, d) {
c.copy(a);
d.copy(a)
}
}
, {
"../math/Vec3": 30,
"./Shape": 43
}],
42: [function(a, d, f) {
function c() {
e.call(this);
this.type = e.types.PLANE;
this.worldNormal = new b;
this.worldNormalNeedsUpdate = !0;
this.boundingSphereRadius = Number.MAX_VALUE
}
d.exports = c;
var e = a("./Shape")
, b = a("../math/Vec3");
c.prototype = new e;
c.prototype.constructor = c;
c.prototype.computeWorldNormal = function(a) {
var b = this.worldNormal;
b.set(0, 0, 1);
a.vmult(b, b);
this.worldNormalNeedsUpdate = !1
}
;
c.prototype.calculateLocalInertia = function(a, c) {
return c = c || new b
}
;
c.prototype.volume = function() {
return Number.MAX_VALUE
}
;
var g = new b;
c.prototype.calculateWorldAABB = function(a, b, c, d) {
g.set(0, 0, 1);
b.vmult(g, g);
b = Number.MAX_VALUE;
c.set(-b, -b, -b);
d.set(b, b, b);
1 === g.x && (d.x = a.x);
1 === g.y && (d.y = a.y);
1 === g.z && (d.z = a.z);
-1 === g.x && (c.x = a.x);
-1 === g.y && (c.y = a.y);
-1 === g.z && (c.z = a.z)
}
;
c.prototype.updateBoundingSphereRadius = function() {
this.boundingSphereRadius = Number.MAX_VALUE
}
}
, {
"../math/Vec3": 30,
"./Shape": 43
}],
43: [function(a, d, f) {
function c() {
this.id = c.idCounter++;
this.boundingSphereRadius = this.type = 0;
this.collisionResponse = !0;
this.material = null
}
d.exports = c;
c = a("./Shape");
a("../math/Vec3");
a("../math/Quaternion");
a("../material/Material");
c.prototype.constructor = c;
c.prototype.updateBoundingSphereRadius = function() {
throw "computeBoundingSphereRadius() not implemented for shape type " + this.type;
}
;
c.prototype.volume = function() {
throw "volume() not implemented for shape type " + this.type;
}
;
c.prototype.calculateLocalInertia = function(a, b) {
throw "calculateLocalInertia() not implemented for shape type " + this.type;
}
;
c.idCounter = 0;
c.types = {
SPHERE: 1,
PLANE: 2,
BOX: 4,
COMPOUND: 8,
CONVEXPOLYHEDRON: 16,
HEIGHTFIELD: 32,
PARTICLE: 64,
CYLINDER: 128,
TRIMESH: 256
}
}
, {
"../material/Material": 25,
"../math/Quaternion": 28,
"../math/Vec3": 30,
"./Shape": 43
}],
44: [function(a, d, f) {
function c(a) {
e.call(this);
this.radius = void 0 !== a ? Number(a) : 1;
this.type = e.types.SPHERE;
if (0 > this.radius)
throw Error("The sphere radius cannot be negative.");
this.updateBoundingSphereRadius()
}
d.exports = c;
var e = a("./Shape")
, b = a("../math/Vec3");
c.prototype = new e;
c.prototype.constructor = c;
c.prototype.calculateLocalInertia = function(a, c) {
c = c || new b;
var d = 2 * a * this.radius * this.radius / 5;
c.x = d;
c.y = d;
c.z = d;
return c
}
;
c.prototype.volume = function() {
return 4 * Math.PI * this.radius / 3
}
;
c.prototype.updateBoundingSphereRadius = function() {
this.boundingSphereRadius = this.radius
}
;
c.prototype.calculateWorldAABB = function(a, b, c, d) {
b = this.radius;
for (var e = ["x", "y", "z"], g = 0; g < e.length; g++) {
var f = e[g];
c[f] = a[f] - b;
d[f] = a[f] + b
}
}
}
, {
"../math/Vec3": 30,
"./Shape": 43
}],
45: [function(a, d, f) {
function c(a, c) {
e.call(this);
this.type = e.types.TRIMESH;
this.vertices = new Float32Array(a);
this.indices = new Int16Array(c);
this.normals = new Float32Array(c.length);
this.aabb = new k;
this.edges = null;
this.scale = new b(1,1,1);
this.tree = new h;
this.updateEdges();
this.updateNormals();
this.updateAABB();
this.updateBoundingSphereRadius();
this.updateTree()
}
d.exports = c;
var e = a("./Shape")
, b = a("../math/Vec3");
a("../math/Quaternion");
var g = a("../math/Transform")
, k = a("../collision/AABB")
, h = a("../utils/Octree");
c.prototype = new e;
c.prototype.constructor = c;
var n = new b;
c.prototype.updateTree = function() {
var a = this.tree;
a.reset();
a.aabb.copy(this.aabb);
var c = this.scale;
a.aabb.lowerBound.x *= 1 / c.x;
a.aabb.lowerBound.y *= 1 / c.y;
a.aabb.lowerBound.z *= 1 / c.z;
a.aabb.upperBound.x *= 1 / c.x;
a.aabb.upperBound.y *= 1 / c.y;
a.aabb.upperBound.z *= 1 / c.z;
c = new k;
for (var d = new b, e = new b, g = new b, f = [d, e, g], h = 0; h < this.indices.length / 3; h++) {
var l = 3 * h;
this._getUnscaledVertex(this.indices[l], d);
this._getUnscaledVertex(this.indices[l + 1], e);
this._getUnscaledVertex(this.indices[l + 2], g);
c.setFromPoints(f);
a.insert(c, h)
}
a.removeEmptyNodes()
}
;
var l = new k;
c.prototype.getTrianglesInAABB = function(a, b) {
l.copy(a);
var c = this.scale
, d = c.x
, e = c.y;
c = c.z;
var g = l.lowerBound
, f = l.upperBound;
g.x /= d;
g.y /= e;
g.z /= c;
f.x /= d;
f.y /= e;
f.z /= c;
return this.tree.aabbQuery(l, b)
}
;
c.prototype.setScale = function(a) {
var b = a.x === a.y === a.z;
this.scale.x === this.scale.y === this.scale.z && b || this.updateNormals();
this.scale.copy(a);
this.updateAABB();
this.updateBoundingSphereRadius()
}
;
c.prototype.updateNormals = function() {
for (var a = this.normals, b = 0; b < this.indices.length / 3; b++) {
var d = 3 * b
, e = this.indices[d + 1]
, g = this.indices[d + 2];
this.getVertex(this.indices[d], w);
this.getVertex(e, x);
this.getVertex(g, t);
c.computeNormal(x, w, t, n);
a[d] = n.x;
a[d + 1] = n.y;
a[d + 2] = n.z
}
}
;
c.prototype.updateEdges = function() {
for (var a = {}, b = function(b, c) {
a[e < g ? e + "_" + g : g + "_" + e] = !0
}, c = 0; c < this.indices.length / 3; c++) {
var d = 3 * c
, e = this.indices[d]
, g = this.indices[d + 1];
d = this.indices[d + 2];
b(e, g);
b(g, d);
b(d, e)
}
b = Object.keys(a);
this.edges = new Int16Array(2 * b.length);
for (c = 0; c < b.length; c++)
d = b[c].split("_"),
this.edges[2 * c] = parseInt(d[0], 10),
this.edges[2 * c + 1] = parseInt(d[1], 10)
}
;
c.prototype.getEdgeVertex = function(a, b, c) {
this.getVertex(this.edges[2 * a + (b ? 1 : 0)], c)
}
;
var q = new b
, p = new b;
c.prototype.getEdgeVector = function(a, b) {
this.getEdgeVertex(a, 0, q);
this.getEdgeVertex(a, 1, p);
p.vsub(q, b)
}
;
var r = new b
, u = new b;
c.computeNormal = function(a, b, c, d) {
b.vsub(a, u);
c.vsub(b, r);
r.cross(u, d);
d.isZero() || d.normalize()
}
;
var w = new b
, x = new b
, t = new b;
c.prototype.getVertex = function(a, b) {
var c = this.scale;
this._getUnscaledVertex(a, b);
b.x *= c.x;
b.y *= c.y;
b.z *= c.z;
return b
}
;
c.prototype._getUnscaledVertex = function(a, b) {
var c = 3 * a
, d = this.vertices;
return b.set(d[c], d[c + 1], d[c + 2])
}
;
c.prototype.getWorldVertex = function(a, b, c, d) {
this.getVertex(a, d);
g.pointToWorldFrame(b, c, d, d);
return d
}
;
c.prototype.getTriangleVertices = function(a, b, c, d) {
a *= 3;
this.getVertex(this.indices[a], b);
this.getVertex(this.indices[a + 1], c);
this.getVertex(this.indices[a + 2], d)
}
;
c.prototype.getNormal = function(a, b) {
var c = 3 * a;
return b.set(this.normals[c], this.normals[c + 1], this.normals[c + 2])
}
;
var v = new k;
c.prototype.calculateLocalInertia = function(a, b) {
this.computeLocalAABB(v);
var c = v.upperBound.x - v.lowerBound.x
, d = v.upperBound.y - v.lowerBound.y
, e = v.upperBound.z - v.lowerBound.z;
return b.set(1 / 12 * a * (4 * d * d + 4 * e * e), 1 / 12 * a * (4 * c * c + 4 * e * e), 1 / 12 * a * (4 * d * d + 4 * c * c))
}
;
var A = new b;
c.prototype.computeLocalAABB = function(a) {
var b = a.lowerBound;
a = a.upperBound;
var c = this.vertices.length;
this.getVertex(0, A);
b.copy(A);
a.copy(A);
for (var d = 0; d !== c; d++)
this.getVertex(d, A),
A.x < b.x ? b.x = A.x : A.x > a.x && (a.x = A.x),
A.y < b.y ? b.y = A.y : A.y > a.y && (a.y = A.y),
A.z < b.z ? b.z = A.z : A.z > a.z && (a.z = A.z)
}
;
c.prototype.updateAABB = function() {
this.computeLocalAABB(this.aabb)
}
;
c.prototype.updateBoundingSphereRadius = function() {
var a = 0
, c = this.vertices
, d = new b
, e = 0;
for (c = c.length / 3; e !== c; e++) {
this.getVertex(e, d);
var g = d.norm2();
g > a && (a = g)
}
this.boundingSphereRadius = Math.sqrt(a)
}
;
new b;
var C = new g
, B = new k;
c.prototype.calculateWorldAABB = function(a, b, c, d) {
C.position = a;
C.quaternion = b;
this.aabb.toWorldFrame(C, B);
c.copy(B.lowerBound);
d.copy(B.upperBound)
}
;
c.prototype.volume = function() {
return 4 * Math.PI * this.boundingSphereRadius / 3
}
;
c.createTorus = function(a, b, d, e, g) {
a = a || 1;
b = b || .5;
d = d || 8;
e = e || 6;
g = g || 2 * Math.PI;
for (var f = [], h = [], l = 0; l <= d; l++)
for (var k = 0; k <= e; k++) {
var n = k / e * g
, p = l / d * Math.PI * 2;
f.push((a + b * Math.cos(p)) * Math.cos(n), (a + b * Math.cos(p)) * Math.sin(n), b * Math.sin(p))
}
for (l = 1; l <= d; l++)
for (k = 1; k <= e; k++)
a = (e + 1) * (l - 1) + k - 1,
b = (e + 1) * (l - 1) + k,
g = (e + 1) * l + k,
h.push((e + 1) * l + k - 1, a, g),
h.push(a, b, g);
return new c(f,h)
}
}
, {
"../collision/AABB": 3,
"../math/Quaternion": 28,
"../math/Transform": 29,
"../math/Vec3": 30,
"../utils/Octree": 50,
"./Shape": 43
}],
46: [function(a, d, f) {
function c() {
e.call(this);
this.iterations = 10;
this.tolerance = 1E-7
}
d.exports = c;
a("../math/Vec3");
a("../math/Quaternion");
var e = a("./Solver");
c.prototype = new e;
var b = []
, g = []
, k = [];
c.prototype.solve = function(a, c) {
var d = 0, e = this.iterations, f = this.tolerance * this.tolerance, h = this.equations, n = h.length, w = c.bodies, x = w.length, t;
if (0 !== n)
for (t = 0; t !== x; t++)
w[t].updateSolveMassProperties();
g.length = n;
k.length = n;
b.length = n;
for (t = 0; t !== n; t++) {
var v = h[t];
b[t] = 0;
k[t] = v.computeB(a);
g[t] = 1 / v.computeC()
}
if (0 !== n) {
for (t = 0; t !== x; t++)
v = w[t],
d = v.wlambda,
v.vlambda.set(0, 0, 0),
d && d.set(0, 0, 0);
for (d = 0; d !== e; d++) {
for (var A = t = 0; A !== n; A++) {
v = h[A];
var C = k[A];
var B = g[A];
var D = b[A];
var E = v.computeGWlambda();
C = B * (C - E - v.eps * D);
D + C < v.minForce ? C = v.minForce - D : D + C > v.maxForce && (C = v.maxForce - D);
b[A] += C;
t += 0 < C ? C : -C;
v.addToWlambda(C)
}
if (t * t < f)
break
}
for (t = 0; t !== x; t++)
v = w[t],
e = v.velocity,
f = v.angularVelocity,
e.vadd(v.vlambda, e),
f && f.vadd(v.wlambda, f)
}
return d
}
}
, {
"../math/Quaternion": 28,
"../math/Vec3": 30,
"./Solver": 47
}],
47: [function(a, d, f) {
function c() {
this.equations = []
}
d.exports = c;
c.prototype.solve = function(a, b) {
return 0
}
;
c.prototype.addEquation = function(a) {
a.enabled && this.equations.push(a)
}
;
c.prototype.removeEquation = function(a) {
var b = this.equations;
a = b.indexOf(a);
-1 !== a && b.splice(a, 1)
}
;
c.prototype.removeAllEquations = function() {
this.equations.length = 0
}
}
, {}],
48: [function(a, d, f) {
function c(a) {
k.call(this);
this.iterations = 10;
this.tolerance = 1E-7;
this.subsolver = a;
this.nodes = [];
for (this.nodePool = []; 128 > this.nodePool.length; )
this.nodePool.push(this.createNode())
}
function e(a) {
for (var b = a.length, c = 0; c !== b; c++) {
var d = a[c];
if (!(d.visited || d.body.type & q))
return d
}
return !1
}
function b(a, b, c) {
b.push(a.body);
b = a.eqs.length;
for (var d = 0; d !== b; d++) {
var e = a.eqs[d];
-1 === c.indexOf(e) && c.push(e)
}
}
function g(a, b) {
return b.id - a.id
}
d.exports = c;
a("../math/Vec3");
a("../math/Quaternion");
var k = a("./Solver");
a = a("../objects/Body");
c.prototype = new k;
var h = []
, n = []
, l = {
bodies: []
}
, q = a.STATIC
, p = [];
c.prototype.createNode = function() {
return {
body: null,
children: [],
eqs: [],
visited: !1
}
}
;
c.prototype.solve = function(a, c) {
for (var d = this.nodePool, f = c.bodies, k = this.equations, q = k.length, r = f.length, u = this.subsolver; d.length < r; )
d.push(this.createNode());
h.length = r;
for (var B = 0; B < r; B++)
h[B] = d[B];
for (B = 0; B !== r; B++)
d = h[B],
d.body = f[B],
d.children.length = 0,
d.eqs.length = 0,
d.visited = !1;
for (r = 0; r !== q; r++) {
d = k[r];
B = f.indexOf(d.bi);
var D = f.indexOf(d.bj);
B = h[B];
D = h[D];
B.children.push(D);
B.eqs.push(d);
D.children.push(B);
D.eqs.push(d)
}
f = 0;
k = n;
u.tolerance = this.tolerance;
for (u.iterations = this.iterations; B = e(h); ) {
k.length = 0;
l.bodies.length = 0;
d = B;
B = b;
q = l.bodies;
r = k;
p.push(d);
d.visited = !0;
for (B(d, q, r); p.length; )
for (d = p.pop(); D = e(d.children); )
D.visited = !0,
B(D, q, r),
p.push(D);
q = k.length;
k = k.sort(g);
for (B = 0; B !== q; B++)
u.addEquation(k[B]);
u.solve(a, l);
u.removeAllEquations();
f++
}
return f
}
}
, {
"../math/Quaternion": 28,
"../math/Vec3": 30,
"../objects/Body": 31,
"./Solver": 47
}],
49: [function(a, d, f) {
a = function() {}
;
d.exports = a;
a.prototype = {
constructor: a,
addEventListener: function(a, d) {
void 0 === this._listeners && (this._listeners = {});
var b = this._listeners;
void 0 === b[a] && (b[a] = []);
-1 === b[a].indexOf(d) && b[a].push(d);
return this
},
hasEventListener: function(a, d) {
if (void 0 === this._listeners)
return !1;
var b = this._listeners;
return void 0 !== b[a] && -1 !== b[a].indexOf(d) ? !0 : !1
},
removeEventListener: function(a, d) {
if (void 0 === this._listeners)
return this;
var b = this._listeners;
if (void 0 === b[a])
return this;
var c = b[a].indexOf(d);
-1 !== c && b[a].splice(c, 1);
return this
},
dispatchEvent: function(a) {
if (void 0 === this._listeners)
return this;
var c = this._listeners[a.type];
if (void 0 !== c) {
a.target = this;
for (var b = 0, d = c.length; b < d; b++)
c[b].call(this, a)
}
return this
}
}
}
, {}],
50: [function(a, d, f) {
function c(a) {
a = a || {};
this.root = a.root || null;
this.aabb = a.aabb ? a.aabb.clone() : new b;
this.data = [];
this.children = []
}
function e(a, b) {
b = b || {};
b.root = null;
b.aabb = a;
c.call(this, b);
this.maxDepth = "undefined" !== typeof b.maxDepth ? b.maxDepth : 8
}
var b = a("../collision/AABB")
, g = a("../math/Vec3");
d.exports = e;
e.prototype = new c;
c.prototype.reset = function(a, b) {
this.children.length = this.data.length = 0
}
;
c.prototype.insert = function(a, b, c) {
var d = this.data;
c = c || 0;
if (!this.aabb.contains(a))
return !1;
var e = this.children;
if (c < (this.maxDepth || this.root.maxDepth)) {
var g = !1;
e.length || (this.subdivide(),
g = !0);
for (var f = 0; 8 !== f; f++)
if (e[f].insert(a, b, c + 1))
return !0;
g && (e.length = 0)
}
d.push(b);
return !0
}
;
var k = new g;
c.prototype.subdivide = function() {
var a = this.aabb
, d = a.lowerBound
, e = a.upperBound;
a = this.children;
a.push(new c({
aabb: new b({
lowerBound: new g(0,0,0)
})
}), new c({
aabb: new b({
lowerBound: new g(1,0,0)
})
}), new c({
aabb: new b({
lowerBound: new g(1,1,0)
})
}), new c({
aabb: new b({
lowerBound: new g(1,1,1)
})
}), new c({
aabb: new b({
lowerBound: new g(0,1,1)
})
}), new c({
aabb: new b({
lowerBound: new g(0,0,1)
})
}), new c({
aabb: new b({
lowerBound: new g(1,0,1)
})
}), new c({
aabb: new b({
lowerBound: new g(0,1,0)
})
}));
e.vsub(d, k);
k.scale(.5, k);
e = this.root || this;
for (var f = 0; 8 !== f; f++) {
var h = a[f];
h.root = e;
var u = h.aabb.lowerBound;
u.x *= k.x;
u.y *= k.y;
u.z *= k.z;
u.vadd(d, u);
u.vadd(k, h.aabb.upperBound)
}
}
;
c.prototype.aabbQuery = function(a, b) {
for (var c = [this]; c.length; ) {
var d = c.pop();
d.aabb.overlaps(a) && Array.prototype.push.apply(b, d.data);
Array.prototype.push.apply(c, d.children)
}
return b
}
;
var h = new b;
c.prototype.rayQuery = function(a, b, c) {
a.getAABB(h);
h.toLocalFrame(b, h);
this.aabbQuery(h, c);
return c
}
;
c.prototype.removeEmptyNodes = function() {
for (var a = [this]; a.length; ) {
for (var b = a.pop(), c = b.children.length - 1; 0 <= c; c--)
b.children[c].data.length || b.children.splice(c, 1);
Array.prototype.push.apply(a, b.children)
}
}
}
, {
"../collision/AABB": 3,
"../math/Vec3": 30
}],
51: [function(a, d, f) {
function c() {
this.objects = [];
this.type = Object
}
d.exports = c;
c.prototype.release = function() {
for (var a = arguments.length, b = 0; b !== a; b++)
this.objects.push(arguments[b])
}
;
c.prototype.get = function() {
return 0 === this.objects.length ? this.constructObject() : this.objects.pop()
}
;
c.prototype.constructObject = function() {
throw Error("constructObject() not implemented in this Pool subclass yet!");
}
}
, {}],
52: [function(a, d, f) {
function c() {
this.data = {
keys: []
}
}
d.exports = c;
c.prototype.get = function(a, b) {
if (a > b) {
var c = b;
b = a;
a = c
}
return this.data[a + "-" + b]
}
;
c.prototype.set = function(a, b, c) {
if (a > b) {
var d = b;
b = a;
a = d
}
d = a + "-" + b;
this.get(a, b) || this.data.keys.push(d);
this.data[d] = c
}
;
c.prototype.reset = function() {
for (var a = this.data, b = a.keys; 0 < b.length; ) {
var c = b.pop();
delete a[c]
}
}
}
, {}],
53: [function(a, d, f) {
function c() {}
d.exports = c;
c.defaults = function(a, b) {
a = a || {};
for (var c in b)
c in a || (a[c] = b[c]);
return a
}
}
, {}],
54: [function(a, d, f) {
function c() {
b.call(this);
this.type = e
}
d.exports = c;
var e = a("../math/Vec3")
, b = a("./Pool");
c.prototype = new b;
c.prototype.constructObject = function() {
return new e
}
}
, {
"../math/Vec3": 30,
"./Pool": 51
}],
55: [function(a, d, f) {
function c(a) {
this.contactPointPool = [];
this.frictionEquationPool = [];
this.result = [];
this.frictionResult = [];
this.v3pool = new h;
this.world = a;
this.currentContactMaterial = null;
this.enableFrictionReduction = !1
}
d.exports = c;
d = a("../collision/AABB");
f = a("../shapes/Shape");
var e = a("../collision/Ray")
, b = a("../math/Vec3")
, g = a("../math/Transform");
a("../shapes/ConvexPolyhedron");
var k = a("../math/Quaternion");
a("../solver/Solver");
var h = a("../utils/Vec3Pool")
, n = a("../equations/ContactEquation")
, l = a("../equations/FrictionEquation");
c.prototype.createContactEquation = function(a, b, c, d, e, g) {
if (this.contactPointPool.length) {
var f = this.contactPointPool.pop();
f.bi = a;
f.bj = b
} else
f = new n(a,b);
f.enabled = a.collisionResponse && b.collisionResponse && c.collisionResponse && d.collisionResponse;
var h = this.currentContactMaterial;
f.restitution = h.restitution;
f.setSpookParams(h.contactEquationStiffness, h.contactEquationRelaxation, this.world.dt);
a = c.material || a.material;
b = d.material || b.material;
a && b && 0 <= a.restitution && 0 <= b.restitution && (f.restitution = a.restitution * b.restitution);
f.si = e || c;
f.sj = g || d;
return f
}
;
c.prototype.createFrictionEquationsFromContact = function(a, b) {
var c = a.bi
, d = a.bj
, e = this.world
, g = this.currentContactMaterial
, f = g.friction
, h = a.si.material || c.material
, k = a.sj.material || d.material;
h && k && 0 <= h.friction && 0 <= k.friction && (f = h.friction * k.friction);
if (0 < f) {
f *= e.gravity.length();
h = c.invMass + d.invMass;
0 < h && (h = 1 / h);
var n = this.frictionEquationPool;
k = n.length ? n.pop() : new l(c,d,f * h);
n = n.length ? n.pop() : new l(c,d,f * h);
k.bi = n.bi = c;
k.bj = n.bj = d;
k.minForce = n.minForce = -f * h;
k.maxForce = n.maxForce = f * h;
k.ri.copy(a.ri);
k.rj.copy(a.rj);
n.ri.copy(a.ri);
n.rj.copy(a.rj);
a.ni.tangents(k.t, n.t);
k.setSpookParams(g.frictionEquationStiffness, g.frictionEquationRelaxation, e.dt);
n.setSpookParams(g.frictionEquationStiffness, g.frictionEquationRelaxation, e.dt);
k.enabled = n.enabled = a.enabled;
b.push(k, n);
return !0
}
return !1
}
;
var q = new b
, p = new b
, r = new b;
c.prototype.createFrictionFromAverage = function(a) {
var b = this.result[this.result.length - 1];
if (this.createFrictionEquationsFromContact(b, this.frictionResult) && 1 !== a) {
var c = this.frictionResult[this.frictionResult.length - 2]
, d = this.frictionResult[this.frictionResult.length - 1];
q.setZero();
p.setZero();
r.setZero();
for (var e = b.bi, g = 0; g !== a; g++)
b = this.result[this.result.length - 1 - g],
b.bodyA !== e ? (q.vadd(b.ni, q),
p.vadd(b.ri, p),
r.vadd(b.rj, r)) : (q.vsub(b.ni, q),
p.vadd(b.rj, p),
r.vadd(b.ri, r));
a = 1 / a;
p.scale(a, c.ri);
r.scale(a, c.rj);
d.ri.copy(c.ri);
d.rj.copy(c.rj);
q.normalize();
q.tangents(c.t, d.t)
}
}
;
var u = new b
, w = new b
, x = new k
, t = new k;
c.prototype.getContacts = function(a, b, c, d, e, g, f) {
this.contactPointPool = e;
this.frictionEquationPool = f;
this.result = d;
this.frictionResult = g;
d = 0;
for (e = a.length; d !== e; d++) {
g = a[d];
f = b[d];
var h = null;
g.material && f.material && (h = c.getContactMaterial(g.material, f.material) || null);
for (var l = 0; l < g.shapes.length; l++) {
g.quaternion.mult(g.shapeOrientations[l], x);
g.quaternion.vmult(g.shapeOffsets[l], u);
u.vadd(g.position, u);
for (var k = g.shapes[l], n = 0; n < f.shapes.length; n++) {
f.quaternion.mult(f.shapeOrientations[n], t);
f.quaternion.vmult(f.shapeOffsets[n], w);
w.vadd(f.position, w);
var p = f.shapes[n];
if (!(u.distanceTo(w) > k.boundingSphereRadius + p.boundingSphereRadius)) {
var z = null;
k.material && p.material && (z = c.getContactMaterial(k.material, p.material) || null);
this.currentContactMaterial = z || h || c.defaultContactMaterial;
(z = this[k.type | p.type]) && (k.type < p.type ? z.call(this, k, p, u, w, x, t, g, f, k, p) : z.call(this, p, k, w, u, t, x, f, g, k, p))
}
}
}
}
}
;
c.prototype[f.types.BOX | f.types.BOX] = c.prototype.boxBox = function(a, b, c, d, e, g, f, h) {
a.convexPolyhedronRepresentation.material = a.material;
b.convexPolyhedronRepresentation.material = b.material;
a.convexPolyhedronRepresentation.collisionResponse = a.collisionResponse;
b.convexPolyhedronRepresentation.collisionResponse = b.collisionResponse;
this.convexConvex(a.convexPolyhedronRepresentation, b.convexPolyhedronRepresentation, c, d, e, g, f, h, a, b)
}
;
c.prototype[f.types.BOX | f.types.CONVEXPOLYHEDRON] = c.prototype.boxConvex = function(a, b, c, d, e, g, f, h) {
a.convexPolyhedronRepresentation.material = a.material;
a.convexPolyhedronRepresentation.collisionResponse = a.collisionResponse;
this.convexConvex(a.convexPolyhedronRepresentation, b, c, d, e, g, f, h, a, b)
}
;
c.prototype[f.types.BOX | f.types.PARTICLE] = c.prototype.boxParticle = function(a, b, c, d, e, g, f, h) {
a.convexPolyhedronRepresentation.material = a.material;
a.convexPolyhedronRepresentation.collisionResponse = a.collisionResponse;
this.convexParticle(a.convexPolyhedronRepresentation, b, c, d, e, g, f, h, a, b)
}
;
c.prototype[f.types.SPHERE] = c.prototype.sphereSphere = function(a, b, c, d, e, g, f, h) {
e = this.createContactEquation(f, h, a, b);
d.vsub(c, e.ni);
e.ni.normalize();
e.ri.copy(e.ni);
e.rj.copy(e.ni);
e.ri.mult(a.radius, e.ri);
e.rj.mult(-b.radius, e.rj);
e.ri.vadd(c, e.ri);
e.ri.vsub(f.position, e.ri);
e.rj.vadd(d, e.rj);
e.rj.vsub(h.position, e.rj);
this.result.push(e);
this.createFrictionEquationsFromContact(e, this.frictionResult)
}
;
var v = new b
, A = new b
, C = new b;
c.prototype[f.types.PLANE | f.types.TRIMESH] = c.prototype.planeTrimesh = function(a, c, d, e, f, h, l, k) {
var n = new b;
v.set(0, 0, 1);
f.vmult(v, v);
for (f = 0; f < c.vertices.length / 3; f++) {
c.getVertex(f, n);
var p = new b;
p.copy(n);
g.pointToWorldFrame(e, h, p, n);
p = A;
n.vsub(d, p);
if (0 >= v.dot(p)) {
var z = this.createContactEquation(l, k, a, c);
z.ni.copy(v);
var q = C;
v.scale(p.dot(v), q);
n.vsub(q, q);
z.ri.copy(q);
z.ri.vsub(l.position, z.ri);
z.rj.copy(n);
z.rj.vsub(k.position, z.rj);
this.result.push(z);
this.createFrictionEquationsFromContact(z, this.frictionResult)
}
}
}
;
var B = new b
, D = new b;
new b;
var E = new b
, F = new b
, H = new b
, K = new b
, I = new b
, N = new b
, y = new b
, M = new b
, J = new b
, z = new b
, O = new b
, L = new d
, G = [];
c.prototype[f.types.SPHERE | f.types.TRIMESH] = c.prototype.sphereTrimesh = function(a, b, c, d, f, h, l, k) {
g.pointToLocalFrame(d, h, c, y);
f = a.radius;
L.lowerBound.set(y.x - f, y.y - f, y.z - f);
L.upperBound.set(y.x + f, y.y + f, y.z + f);
b.getTrianglesInAABB(L, G);
var n = a.radius * a.radius;
for (f = 0; f < G.length; f++)
for (var p = 0; 3 > p; p++)
if (b.getVertex(b.indices[3 * G[f] + p], E),
E.vsub(y, D),
D.norm2() <= n) {
F.copy(E);
g.pointToWorldFrame(d, h, F, E);
E.vsub(c, D);
var q = this.createContactEquation(l, k, a, b);
q.ni.copy(D);
q.ni.normalize();
q.ri.copy(q.ni);
q.ri.scale(a.radius, q.ri);
q.ri.vadd(c, q.ri);
q.ri.vsub(l.position, q.ri);
q.rj.copy(E);
q.rj.vsub(k.position, q.rj);
this.result.push(q);
this.createFrictionEquationsFromContact(q, this.frictionResult)
}
for (f = 0; f < G.length; f++)
for (p = 0; 3 > p; p++)
b.getVertex(b.indices[3 * G[f] + p], H),
b.getVertex(b.indices[3 * G[f] + (p + 1) % 3], K),
K.vsub(H, I),
y.vsub(K, M),
c = M.dot(I),
y.vsub(H, M),
q = M.dot(I),
0 < q && 0 > c && (y.vsub(H, M),
N.copy(I),
N.normalize(),
q = M.dot(N),
N.scale(q, M),
M.vadd(H, M),
c = M.distanceTo(y),
c < a.radius && (q = this.createContactEquation(l, k, a, b),
M.vsub(y, q.ni),
q.ni.normalize(),
q.ni.scale(a.radius, q.ri),
g.pointToWorldFrame(d, h, M, M),
M.vsub(k.position, q.rj),
g.vectorToWorldFrame(h, q.ni, q.ni),
g.vectorToWorldFrame(h, q.ri, q.ri),
this.result.push(q),
this.createFrictionEquationsFromContact(q, this.frictionResult)));
f = 0;
for (p = G.length; f !== p; f++)
b.getTriangleVertices(G[f], J, z, O),
b.getNormal(G[f], B),
y.vsub(J, M),
c = M.dot(B),
B.scale(c, M),
y.vsub(M, M),
c = M.distanceTo(y),
e.pointInTriangle(M, J, z, O) && c < a.radius && (q = this.createContactEquation(l, k, a, b),
M.vsub(y, q.ni),
q.ni.normalize(),
q.ni.scale(a.radius, q.ri),
g.pointToWorldFrame(d, h, M, M),
M.vsub(k.position, q.rj),
g.vectorToWorldFrame(h, q.ni, q.ni),
g.vectorToWorldFrame(h, q.ri, q.ri),
this.result.push(q),
this.createFrictionEquationsFromContact(q, this.frictionResult));
G.length = 0
}
;
var Q = new b
, P = new b;
c.prototype[f.types.SPHERE | f.types.PLANE] = c.prototype.spherePlane = function(a, b, c, d, e, f, g, h) {
b = this.createContactEquation(g, h, a, b);
b.ni.set(0, 0, 1);
f.vmult(b.ni, b.ni);
b.ni.negate(b.ni);
b.ni.normalize();
b.ni.mult(a.radius, b.ri);
c.vsub(d, Q);
b.ni.mult(b.ni.dot(Q), P);
Q.vsub(P, b.rj);
-Q.dot(b.ni) <= a.radius && (a = b.ri,
f = b.rj,
a.vadd(c, a),
a.vsub(g.position, a),
f.vadd(d, f),
f.vsub(h.position, f),
this.result.push(b),
this.createFrictionEquationsFromContact(b, this.frictionResult))
}
;
var U = new b
, V = new b
, X = new b
, R = new b
, W = new b
, S = new b
, Y = new b
, T = [new b, new b, new b, new b, new b, new b]
, Z = new b
, aa = new b
, ha = new b
, na = new b;
c.prototype[f.types.SPHERE | f.types.BOX] = c.prototype.sphereBox = function(a, b, c, d, e, f, g, h) {
e = this.v3pool;
c.vsub(d, R);
b.getSideNormals(T, f);
f = a.radius;
for (var l = !1, k = null, n = 0, p = 0, q = 0, z = null, r = 0, u = T.length; r !== u && !1 === l; r++) {
var y = W;
y.copy(T[r]);
var L = y.norm();
y.normalize();
var t = R.dot(y);
if (t < L + f && 0 < t) {
var v = S
, w = Y;
v.copy(T[(r + 1) % 3]);
w.copy(T[(r + 2) % 3]);
var F = v.norm()
, x = w.norm();
v.normalize();
w.normalize();
var O = R.dot(v)
, G = R.dot(w);
O < F && O > -F && G < x && G > -x && (t = Math.abs(t - L - f),
null === z || t < z) && (z = t,
p = O,
q = G,
k = L,
aa.copy(y),
ha.copy(v),
na.copy(w),
n++)
}
}
n && (l = !0,
n = this.createContactEquation(g, h, a, b),
aa.mult(-f, n.ri),
n.ni.copy(aa),
n.ni.negate(n.ni),
aa.mult(k, aa),
ha.mult(p, ha),
aa.vadd(ha, aa),
na.mult(q, na),
aa.vadd(na, n.rj),
n.ri.vadd(c, n.ri),
n.ri.vsub(g.position, n.ri),
n.rj.vadd(d, n.rj),
n.rj.vsub(h.position, n.rj),
this.result.push(n),
this.createFrictionEquationsFromContact(n, this.frictionResult));
t = e.get();
for (k = 0; 2 !== k && !l; k++)
for (p = 0; 2 !== p && !l; p++)
for (q = 0; 2 !== q && !l; q++)
t.set(0, 0, 0),
k ? t.vadd(T[0], t) : t.vsub(T[0], t),
p ? t.vadd(T[1], t) : t.vsub(T[1], t),
q ? t.vadd(T[2], t) : t.vsub(T[2], t),
d.vadd(t, Z),
Z.vsub(c, Z),
Z.norm2() < f * f && (l = !0,
n = this.createContactEquation(g, h, a, b),
n.ri.copy(Z),
n.ri.normalize(),
n.ni.copy(n.ri),
n.ri.mult(f, n.ri),
n.rj.copy(t),
n.ri.vadd(c, n.ri),
n.ri.vsub(g.position, n.ri),
n.rj.vadd(d, n.rj),
n.rj.vsub(h.position, n.rj),
this.result.push(n),
this.createFrictionEquationsFromContact(n, this.frictionResult));
e.release(t);
z = e.get();
r = e.get();
n = e.get();
u = e.get();
t = e.get();
y = T.length;
for (k = 0; k !== y && !l; k++)
for (p = 0; p !== y && !l; p++)
if (k % 3 !== p % 3) {
T[p].cross(T[k], z);
z.normalize();
T[k].vadd(T[p], r);
n.copy(c);
n.vsub(r, n);
n.vsub(d, n);
L = n.dot(z);
z.mult(L, u);
for (q = 0; q === k % 3 || q === p % 3; )
q++;
t.copy(c);
t.vsub(u, t);
t.vsub(r, t);
t.vsub(d, t);
L = Math.abs(L);
v = t.norm();
L < T[q].norm() && v < f && (l = !0,
q = this.createContactEquation(g, h, a, b),
r.vadd(u, q.rj),
q.rj.copy(q.rj),
t.negate(q.ni),
q.ni.normalize(),
q.ri.copy(q.rj),
q.ri.vadd(d, q.ri),
q.ri.vsub(c, q.ri),
q.ri.normalize(),
q.ri.mult(f, q.ri),
q.ri.vadd(c, q.ri),
q.ri.vsub(g.position, q.ri),
q.rj.vadd(d, q.rj),
q.rj.vsub(h.position, q.rj),
this.result.push(q),
this.createFrictionEquationsFromContact(q, this.frictionResult))
}
e.release(z, r, n, u, t)
}
;
var xa = new b
, ya = new b
, za = new b
, Aa = new b
, Ba = new b
, Ca = new b
, Da = new b
, Ea = new b
, Fa = new b
, Ga = new b;
c.prototype[f.types.SPHERE | f.types.CONVEXPOLYHEDRON] = c.prototype.sphereConvex = function(a, b, c, d, e, f, g, h) {
e = this.v3pool;
c.vsub(d, xa);
for (var l = b.faceNormals, k = b.faces, n = b.vertices, p = a.radius, q = 0; q !== n.length; q++) {
var z = Ba;
f.vmult(n[q], z);
d.vadd(z, z);
var r = Aa;
z.vsub(c, r);
if (r.norm2() < p * p) {
a = this.createContactEquation(g, h, a, b);
a.ri.copy(r);
a.ri.normalize();
a.ni.copy(a.ri);
a.ri.mult(p, a.ri);
z.vsub(d, a.rj);
a.ri.vadd(c, a.ri);
a.ri.vsub(g.position, a.ri);
a.rj.vadd(d, a.rj);
a.rj.vsub(h.position, a.rj);
this.result.push(a);
this.createFrictionEquationsFromContact(a, this.frictionResult);
return
}
}
q = 0;
for (z = k.length; q !== z; q++) {
r = k[q];
var u = Ca;
f.vmult(l[q], u);
var y = Da;
f.vmult(n[r[0]], y);
y.vadd(d, y);
var L = Ea;
u.mult(-p, L);
c.vadd(L, L);
var t = Fa;
L.vsub(y, t);
L = t.dot(u);
t = Ga;
c.vsub(y, t);
if (0 > L && 0 < t.dot(u)) {
y = [];
t = 0;
for (var v = r.length; t !== v; t++) {
var w = e.get();
f.vmult(n[r[t]], w);
d.vadd(w, w);
y.push(w)
}
a: {
t = y;
v = u;
w = c;
for (var F = null, x = t.length, O = 0; O !== x; O++) {
var G = t[O]
, J = U;
t[(O + 1) % x].vsub(G, J);
var N = V;
J.cross(v, N);
J = X;
w.vsub(G, J);
G = N.dot(J);
if (null === F || 0 < G && !0 === F || 0 >= G && !1 === F)
null === F && (F = 0 < G);
else {
t = !1;
break a
}
}
t = !0
}
if (t) {
a = this.createContactEquation(g, h, a, b);
u.mult(-p, a.ri);
u.negate(a.ni);
b = e.get();
u.mult(-L, b);
f = e.get();
u.mult(-p, f);
c.vsub(d, a.rj);
a.rj.vadd(f, a.rj);
a.rj.vadd(b, a.rj);
a.rj.vadd(d, a.rj);
a.rj.vsub(h.position, a.rj);
a.ri.vadd(c, a.ri);
a.ri.vsub(g.position, a.ri);
e.release(b);
e.release(f);
this.result.push(a);
this.createFrictionEquationsFromContact(a, this.frictionResult);
t = 0;
for (r = y.length; t !== r; t++)
e.release(y[t]);
break
} else
for (t = 0; t !== r.length; t++) {
u = e.get();
L = e.get();
f.vmult(n[r[(t + 1) % r.length]], u);
f.vmult(n[r[(t + 2) % r.length]], L);
d.vadd(u, u);
d.vadd(L, L);
x = ya;
L.vsub(u, x);
F = za;
x.unit(F);
v = e.get();
w = e.get();
c.vsub(u, w);
O = w.dot(F);
F.mult(O, v);
v.vadd(u, v);
F = e.get();
v.vsub(c, F);
if (0 < O && O * O < x.norm2() && F.norm2() < p * p) {
a = this.createContactEquation(g, h, a, b);
v.vsub(d, a.rj);
v.vsub(c, a.ni);
a.ni.normalize();
a.ni.mult(p, a.ri);
a.rj.vadd(d, a.rj);
a.rj.vsub(h.position, a.rj);
a.ri.vadd(c, a.ri);
a.ri.vsub(g.position, a.ri);
this.result.push(a);
this.createFrictionEquationsFromContact(a, this.frictionResult);
t = 0;
for (r = y.length; t !== r; t++)
e.release(y[t]);
e.release(u);
e.release(L);
e.release(v);
e.release(F);
e.release(w);
return
}
e.release(u);
e.release(L);
e.release(v);
e.release(F);
e.release(w)
}
t = 0;
for (r = y.length; t !== r; t++)
e.release(y[t])
}
}
}
;
new b;
new b;
c.prototype[f.types.PLANE | f.types.BOX] = c.prototype.planeBox = function(a, b, c, d, e, f, g, h) {
b.convexPolyhedronRepresentation.material = b.material;
b.convexPolyhedronRepresentation.collisionResponse = b.collisionResponse;
this.planeConvex(a, b.convexPolyhedronRepresentation, c, d, e, f, g, h)
}
;
var ba = new b
, ca = new b
, qa = new b
, Ha = new b;
c.prototype[f.types.PLANE | f.types.CONVEXPOLYHEDRON] = c.prototype.planeConvex = function(a, b, c, d, e, f, g, h) {
ca.set(0, 0, 1);
e.vmult(ca, ca);
for (var l = e = 0; l !== b.vertices.length; l++)
if (ba.copy(b.vertices[l]),
f.vmult(ba, ba),
d.vadd(ba, ba),
ba.vsub(c, qa),
0 >= ca.dot(qa)) {
var k = this.createContactEquation(g, h, a, b)
, n = Ha;
ca.mult(ca.dot(qa), n);
ba.vsub(n, n);
n.vsub(c, k.ri);
k.ni.copy(ca);
ba.vsub(d, k.rj);
k.ri.vadd(c, k.ri);
k.ri.vsub(g.position, k.ri);
k.rj.vadd(d, k.rj);
k.rj.vsub(h.position, k.rj);
this.result.push(k);
e++;
this.enableFrictionReduction || this.createFrictionEquationsFromContact(k, this.frictionResult)
}
this.enableFrictionReduction && e && this.createFrictionFromAverage(e)
}
;
var ra = new b
, oa = new b;
c.prototype[f.types.CONVEXPOLYHEDRON] = c.prototype.convexConvex = function(a, b, c, d, e, f, g, h, l, k, n, p) {
if (!(c.distanceTo(d) > a.boundingSphereRadius + b.boundingSphereRadius) && a.findSeparatingAxis(b, c, e, d, f, ra, n, p)) {
n = [];
a.clipAgainstHull(c, e, b, d, f, ra, -100, 100, n);
for (f = e = 0; f !== n.length; f++) {
p = this.createContactEquation(g, h, a, b, l, k);
var q = p.ri
, z = p.rj;
ra.negate(p.ni);
n[f].normal.negate(oa);
oa.mult(n[f].depth, oa);
n[f].point.vadd(oa, q);
z.copy(n[f].point);
q.vsub(c, q);
z.vsub(d, z);
q.vadd(c, q);
q.vsub(g.position, q);
z.vadd(d, z);
z.vsub(h.position, z);
this.result.push(p);
e++;
this.enableFrictionReduction || this.createFrictionEquationsFromContact(p, this.frictionResult)
}
this.enableFrictionReduction && e && this.createFrictionFromAverage(e)
}
}
;
var da = new b
, ta = new b
, pa = new b;
c.prototype[f.types.PLANE | f.types.PARTICLE] = c.prototype.planeParticle = function(a, b, c, d, e, f, g, h) {
da.set(0, 0, 1);
g.quaternion.vmult(da, da);
d.vsub(g.position, ta);
0 >= da.dot(ta) && (a = this.createContactEquation(h, g, b, a),
a.ni.copy(da),
a.ni.negate(a.ni),
a.ri.set(0, 0, 0),
da.mult(da.dot(d), pa),
d.vsub(pa, pa),
a.rj.copy(pa),
this.result.push(a),
this.createFrictionEquationsFromContact(a, this.frictionResult))
}
;
var ia = new b;
c.prototype[f.types.PARTICLE | f.types.SPHERE] = c.prototype.sphereParticle = function(a, b, c, d, e, f, g, h) {
ia.set(0, 0, 1);
d.vsub(c, ia);
ia.norm2() <= a.radius * a.radius && (b = this.createContactEquation(h, g, b, a),
ia.normalize(),
b.rj.copy(ia),
b.rj.mult(a.radius, b.rj),
b.ni.copy(ia),
b.ni.negate(b.ni),
b.ri.set(0, 0, 0),
this.result.push(b),
this.createFrictionEquationsFromContact(b, this.frictionResult))
}
;
var ua = new k
, ja = new b;
new b;
var sa = new b
, va = new b
, ka = new b;
c.prototype[f.types.PARTICLE | f.types.CONVEXPOLYHEDRON] = c.prototype.convexParticle = function(a, b, c, d, e, f, g, h) {
var l = -1;
f = null;
var k = 0;
ja.copy(d);
ja.vsub(c, ja);
e.conjugate(ua);
ua.vmult(ja, ja);
if (a.pointIsInside(ja)) {
a.worldVerticesNeedsUpdate && a.computeWorldVertices(c, e);
a.worldFaceNormalsNeedsUpdate && a.computeWorldFaceNormals(e);
e = 0;
for (var n = a.faces.length; e !== n; e++) {
var p = a.worldFaceNormals[e];
d.vsub(a.worldVertices[a.faces[e][0]], va);
var q = -p.dot(va);
if (null === f || Math.abs(q) < Math.abs(f))
f = q,
l = e,
sa.copy(p),
k++
}
-1 !== l ? (a = this.createContactEquation(h, g, b, a),
sa.mult(f, ka),
ka.vadd(d, ka),
ka.vsub(c, ka),
a.rj.copy(ka),
sa.negate(a.ni),
a.ri.set(0, 0, 0),
b = a.ri,
f = a.rj,
b.vadd(d, b),
b.vsub(h.position, b),
f.vadd(c, f),
f.vsub(g.position, f),
this.result.push(a),
this.createFrictionEquationsFromContact(a, this.frictionResult)) : console.warn("Point found inside convex, but did not find penetrating face!")
}
}
;
c.prototype[f.types.BOX | f.types.HEIGHTFIELD] = c.prototype.boxHeightfield = function(a, b, c, d, e, f, g, h) {
a.convexPolyhedronRepresentation.material = a.material;
a.convexPolyhedronRepresentation.collisionResponse = a.collisionResponse;
this.convexHeightfield(a.convexPolyhedronRepresentation, b, c, d, e, f, g, h)
}
;
var ea = new b
, la = new b
, wa = [0];
c.prototype[f.types.CONVEXPOLYHEDRON | f.types.HEIGHTFIELD] = c.prototype.convexHeightfield = function(a, b, c, d, e, f, h, l) {
var k = b.data
, n = b.elementSize
, p = a.boundingSphereRadius;
g.pointToLocalFrame(d, f, c, ea);
var q = Math.floor((ea.x - p) / n) - 1
, z = Math.ceil((ea.x + p) / n) + 1
, r = Math.floor((ea.y - p) / n) - 1;
n = Math.ceil((ea.y + p) / n) + 1;
if (!(0 > z || 0 > n || q > k.length || r > k[0].length)) {
0 > q && (q = 0);
0 > z && (z = 0);
0 > r && (r = 0);
0 > n && (n = 0);
q >= k.length && (q = k.length - 1);
z >= k.length && (z = k.length - 1);
n >= k[0].length && (n = k[0].length - 1);
r >= k[0].length && (r = k[0].length - 1);
k = [];
b.getRectMinMax(q, r, z, n, k);
var u = k[0];
if (!(ea.z - p > k[1] || ea.z + p < u))
for (p = q; p < z; p++)
for (q = r; q < n; q++)
b.getConvexTrianglePillar(p, q, !1),
g.pointToWorldFrame(d, f, b.pillarOffset, la),
c.distanceTo(la) < b.pillarConvex.boundingSphereRadius + a.boundingSphereRadius && this.convexConvex(a, b.pillarConvex, c, la, e, f, h, l, null, null, wa, null),
b.getConvexTrianglePillar(p, q, !0),
g.pointToWorldFrame(d, f, b.pillarOffset, la),
c.distanceTo(la) < b.pillarConvex.boundingSphereRadius + a.boundingSphereRadius && this.convexConvex(a, b.pillarConvex, c, la, e, f, h, l, null, null, wa, null)
}
}
;
var fa = new b
, ma = new b;
c.prototype[f.types.SPHERE | f.types.HEIGHTFIELD] = c.prototype.sphereHeightfield = function(a, b, c, d, e, f, h, l) {
var k = b.data
, n = a.radius
, p = b.elementSize;
g.pointToLocalFrame(d, f, c, fa);
var q = Math.floor((fa.x - n) / p) - 1
, z = Math.ceil((fa.x + n) / p) + 1
, r = Math.floor((fa.y - n) / p) - 1;
p = Math.ceil((fa.y + n) / p) + 1;
if (!(0 > z || 0 > p || q > k.length || p > k[0].length)) {
0 > q && (q = 0);
0 > z && (z = 0);
0 > r && (r = 0);
0 > p && (p = 0);
q >= k.length && (q = k.length - 1);
z >= k.length && (z = k.length - 1);
p >= k[0].length && (p = k[0].length - 1);
r >= k[0].length && (r = k[0].length - 1);
k = [];
b.getRectMinMax(q, r, z, p, k);
var u = k[0];
if (!(fa.z - n > k[1] || fa.z + n < u))
for (n = this.result; q < z; q++)
for (k = r; k < p; k++)
if (u = n.length,
b.getConvexTrianglePillar(q, k, !1),
g.pointToWorldFrame(d, f, b.pillarOffset, ma),
c.distanceTo(ma) < b.pillarConvex.boundingSphereRadius + a.boundingSphereRadius && this.sphereConvex(a, b.pillarConvex, c, ma, e, f, h, l),
b.getConvexTrianglePillar(q, k, !0),
g.pointToWorldFrame(d, f, b.pillarOffset, ma),
c.distanceTo(ma) < b.pillarConvex.boundingSphereRadius + a.boundingSphereRadius && this.sphereConvex(a, b.pillarConvex, c, ma, e, f, h, l),
2 < n.length - u)
return
}
}
}
, {
"../collision/AABB": 3,
"../collision/Ray": 9,
"../equations/ContactEquation": 19,
"../equations/FrictionEquation": 21,
"../math/Quaternion": 28,
"../math/Transform": 29,
"../math/Vec3": 30,
"../shapes/ConvexPolyhedron": 38,
"../shapes/Shape": 43,
"../solver/Solver": 47,
"../utils/Vec3Pool": 54
}],
56: [function(a, d, f) {
function c() {
k.apply(this);
this.dt = -1;
this.allowSleep = !1;
this.contacts = [];
this.frictionEquations = [];
this.quatNormalizeSkip = 0;
this.quatNormalizeFast = !1;
this.stepnumber = this.time = 0;
this.default_dt = 1 / 60;
this.nextId = 0;
this.gravity = new e;
this.broadphase = new w;
this.bodies = [];
this.solver = new b;
this.constraints = [];
this.narrowphase = new g(this);
this.collisionMatrix = new h;
this.collisionMatrixPrevious = new h;
this.materials = [];
this.contactmaterials = [];
this.contactMaterialTable = new p;
this.defaultMaterial = new n("default");
this.defaultContactMaterial = new l(this.defaultMaterial,this.defaultMaterial,{
friction: .3,
restitution: 0
});
this.doProfiling = !1;
this.profile = {
solve: 0,
makeContactConstraints: 0,
broadphase: 0,
integrate: 0,
narrowphase: 0
};
this.subsystems = [];
this.addBodyEvent = {
type: "addBody",
body: null
};
this.removeBodyEvent = {
type: "removeBody",
body: null
}
}
d.exports = c;
a("../shapes/Shape");
var e = a("../math/Vec3");
d = a("../math/Quaternion");
var b = a("../solver/GSSolver");
a("../utils/Vec3Pool");
a("../equations/ContactEquation");
a("../equations/FrictionEquation");
var g = a("./Narrowphase")
, k = a("../utils/EventTarget")
, h = a("../collision/ArrayCollisionMatrix")
, n = a("../material/Material")
, l = a("../material/ContactMaterial")
, q = a("../objects/Body")
, p = a("../utils/TupleDictionary")
, r = a("../collision/RaycastResult");
f = a("../collision/AABB");
var u = a("../collision/Ray")
, w = a("../collision/NaiveBroadphase");
c.prototype = new k;
new f;
var x = new u;
c.prototype.getContactMaterial = function(a, b) {
return this.contactMaterialTable.get(a.id, b.id)
}
;
c.prototype.numObjects = function() {
return this.bodies.length
}
;
c.prototype.collisionMatrixTick = function() {
var a = this.collisionMatrixPrevious;
this.collisionMatrixPrevious = this.collisionMatrix;
this.collisionMatrix = a;
this.collisionMatrix.reset()
}
;
c.prototype.add = c.prototype.addBody = function(a) {
-1 === this.bodies.indexOf(a) && (a.index = this.bodies.length,
this.bodies.push(a),
a.world = this,
a.initPosition.copy(a.position),
a.initVelocity.copy(a.velocity),
a.timeLastSleepy = this.time,
a instanceof q && (a.initAngularVelocity.copy(a.angularVelocity),
a.initQuaternion.copy(a.quaternion)),
this.collisionMatrix.setNumObjects(this.bodies.length),
this.addBodyEvent.body = a,
this.dispatchEvent(this.addBodyEvent))
}
;
c.prototype.addConstraint = function(a) {
this.constraints.push(a)
}
;
c.prototype.removeConstraint = function(a) {
a = this.constraints.indexOf(a);
-1 !== a && this.constraints.splice(a, 1)
}
;
c.prototype.rayTest = function(a, b, c) {
c instanceof r ? this.raycastClosest(a, b, {
skipBackfaces: !0
}, c) : this.raycastAll(a, b, {
skipBackfaces: !0
}, c)
}
;
c.prototype.raycastAll = function(a, b, c, d) {
c.mode = u.ALL;
c.from = a;
c.to = b;
c.callback = d;
return x.intersectWorld(this, c)
}
;
c.prototype.raycastAny = function(a, b, c, d) {
c.mode = u.ANY;
c.from = a;
c.to = b;
c.result = d;
return x.intersectWorld(this, c)
}
;
c.prototype.raycastClosest = function(a, b, c, d) {
c.mode = u.CLOSEST;
c.from = a;
c.to = b;
c.result = d;
return x.intersectWorld(this, c)
}
;
c.prototype.remove = function(a) {
a.world = null;
var b = this.bodies.length - 1
, c = this.bodies
, d = c.indexOf(a);
if (-1 !== d) {
c.splice(d, 1);
for (d = 0; d !== c.length; d++)
c[d].index = d;
this.collisionMatrix.setNumObjects(b);
this.removeBodyEvent.body = a;
this.dispatchEvent(this.removeBodyEvent)
}
}
;
c.prototype.removeBody = c.prototype.remove;
c.prototype.addMaterial = function(a) {
this.materials.push(a)
}
;
c.prototype.addContactMaterial = function(a) {
this.contactmaterials.push(a);
this.contactMaterialTable.set(a.materials[0].id, a.materials[1].id, a)
}
;
"undefined" === typeof performance && (performance = {});
if (!performance.now) {
var t = Date.now();
performance.timing && performance.timing.navigationStart && (t = performance.timing.navigationStart);
performance.now = function() {
return Date.now() - t
}
}
var v = new e;
c.prototype.step = function(a, b, c) {
c = c || 10;
b = b || 0;
if (0 === b)
this.internalStep(a),
this.time += a;
else {
var d = Math.floor((this.time + b) / a) - Math.floor(this.time / a);
d = Math.min(d, c);
c = performance.now();
for (var e = 0; e !== d && !(this.internalStep(a),
performance.now() - c > 1E3 * a); e++)
;
this.time += b;
a = this.time % a / a;
b = this.bodies;
for (d = 0; d !== b.length; d++)
c = b[d],
c.type !== q.STATIC && c.sleepState !== q.SLEEPING ? (c.position.vsub(c.previousPosition, v),
v.scale(a, v),
c.position.vadd(v, c.interpolatedPosition)) : (c.interpolatedPosition.copy(c.position),
c.interpolatedQuaternion.copy(c.quaternion))
}
}
;
var A = {
type: "postStep"
}
, C = {
type: "preStep"
}
, B = {
type: "collide",
body: null,
contact: null
}
, D = []
, E = []
, F = []
, H = [];
new e;
new e;
new e;
new e;
new e;
new e;
new e;
new e;
new e;
new d;
var K = new d
, I = new d
, N = new e;
c.prototype.internalStep = function(a) {
this.dt = a;
var b = this.contacts, c = this.numObjects(), d = this.bodies, e = this.solver, f = this.gravity, g = this.doProfiling, h = this.profile, l = q.DYNAMIC, k, n = this.constraints;
f.norm();
var p = f.x
, r = f.y
, u = f.z;
g && (k = performance.now());
for (f = 0; f !== c; f++) {
var t = d[f];
if (t.type & l) {
var y = t.force;
t = t.mass;
y.x += t * p;
y.y += t * r;
y.z += t * u
}
}
f = 0;
for (t = this.subsystems.length; f !== t; f++)
this.subsystems[f].update();
g && (k = performance.now());
F.length = 0;
H.length = 0;
this.broadphase.collisionPairs(this, F, H);
g && (h.broadphase = performance.now() - k);
t = n.length;
for (f = 0; f !== t; f++)
if (p = n[f],
!p.collideConnected)
for (r = F.length - 1; 0 <= r; --r)
if (p.bodyA === F[r] && p.bodyB === H[r] || p.bodyB === F[r] && p.bodyA === H[r])
F.splice(r, 1),
H.splice(r, 1);
this.collisionMatrixTick();
g && (k = performance.now());
t = b.length;
for (f = 0; f !== t; f++)
D.push(b[f]);
b.length = 0;
t = this.frictionEquations.length;
for (f = 0; f !== t; f++)
E.push(this.frictionEquations[f]);
this.frictionEquations.length = 0;
this.narrowphase.getContacts(F, H, this, b, D, this.frictionEquations, E);
g && (h.narrowphase = performance.now() - k);
g && (k = performance.now());
for (f = 0; f < this.frictionEquations.length; f++)
e.addEquation(this.frictionEquations[f]);
f = b.length;
for (r = 0; r !== f; r++)
p = b[r],
t = p.bi,
u = p.bj,
t.material && u.material && this.getContactMaterial(t.material, u.material),
t.material && u.material && 0 <= t.material.restitution && 0 <= u.material.restitution && (p.restitution = t.material.restitution * u.material.restitution),
e.addEquation(p),
t.allowSleep && t.type === q.DYNAMIC && t.sleepState === q.SLEEPING && u.sleepState === q.AWAKE && u.type !== q.STATIC && u.velocity.norm2() + u.angularVelocity.norm2() >= 2 * Math.pow(u.sleepSpeedLimit, 2) && (t._wakeUpAfterNarrowphase = !0),
u.allowSleep && u.type === q.DYNAMIC && u.sleepState === q.SLEEPING && t.sleepState === q.AWAKE && t.type !== q.STATIC && t.velocity.norm2() + t.angularVelocity.norm2() >= 2 * Math.pow(t.sleepSpeedLimit, 2) && (u._wakeUpAfterNarrowphase = !0),
this.collisionMatrix.set(t, u, !0),
this.collisionMatrixPrevious.get(t, u) || (B.body = u,
B.contact = p,
t.dispatchEvent(B),
B.body = t,
u.dispatchEvent(B));
g && (h.makeContactConstraints = performance.now() - k,
k = performance.now());
for (f = 0; f !== c; f++)
t = d[f],
t._wakeUpAfterNarrowphase && (t.wakeUp(),
t._wakeUpAfterNarrowphase = !1);
t = n.length;
for (f = 0; f !== t; f++)
for (p = n[f],
p.update(),
r = 0,
b = p.equations.length; r !== b; r++)
e.addEquation(p.equations[r]);
e.solve(a, this);
g && (h.solve = performance.now() - k);
e.removeAllEquations();
e = Math.pow;
for (f = 0; f !== c; f++)
if (t = d[f],
t.type & l && (n = e(1 - t.linearDamping, a),
b = t.velocity,
b.mult(n, b),
n = t.angularVelocity))
b = e(1 - t.angularDamping, a),
n.mult(b, n);
this.dispatchEvent(C);
for (f = 0; f !== c; f++)
t = d[f],
t.preStep && t.preStep.call(t);
g && (k = performance.now());
l = q.DYNAMIC | q.KINEMATIC;
e = 0 === this.stepnumber % (this.quatNormalizeSkip + 1);
n = this.quatNormalizeFast;
b = .5 * a;
for (f = 0; f !== c; f++)
if (t = d[f],
p = t.force,
r = t.torque,
t.type & l && t.sleepState !== q.SLEEPING) {
u = t.velocity;
y = t.angularVelocity;
var v = t.position
, w = t.quaternion
, x = t.invMass
, ha = t.invInertiaWorld;
u.x += p.x * x * a;
u.y += p.y * x * a;
u.z += p.z * x * a;
t.angularVelocity && (ha.vmult(r, N),
N.mult(a, N),
N.vadd(y, y));
v.x += u.x * a;
v.y += u.y * a;
v.z += u.z * a;
t.angularVelocity && (K.set(y.x, y.y, y.z, 0),
K.mult(w, I),
w.x += b * I.x,
w.y += b * I.y,
w.z += b * I.z,
w.w += b * I.w,
e && (n ? w.normalizeFast() : w.normalize()));
t.aabb && (t.aabbNeedsUpdate = !0);
t.updateInertiaWorld && t.updateInertiaWorld()
}
this.clearForces();
this.broadphase.dirty = !0;
g && (h.integrate = performance.now() - k);
this.time += a;
this.stepnumber += 1;
this.dispatchEvent(A);
for (f = 0; f !== c; f++)
t = d[f],
(a = t.postStep) && a.call(t);
if (this.allowSleep)
for (f = 0; f !== c; f++)
d[f].sleepTick(this.time)
}
;
c.prototype.clearForces = function() {
for (var a = this.bodies, b = a.length, c = 0; c !== b; c++) {
var d = a[c];
d.force.set(0, 0, 0);
d.torque.set(0, 0, 0)
}
}
}
, {
"../collision/AABB": 3,
"../collision/ArrayCollisionMatrix": 4,
"../collision/NaiveBroadphase": 7,
"../collision/Ray": 9,
"../collision/RaycastResult": 10,
"../equations/ContactEquation": 19,
"../equations/FrictionEquation": 21,
"../material/ContactMaterial": 24,
"../material/Material": 25,
"../math/Quaternion": 28,
"../math/Vec3": 30,
"../objects/Body": 31,
"../shapes/Shape": 43,
"../solver/GSSolver": 46,
"../utils/EventTarget": 49,
"../utils/TupleDictionary": 52,
"../utils/Vec3Pool": 54,
"./Narrowphase": 55
}]
}, {}, [2])(2)
});
CANNON = CANNON || {};
var camera, scene, renderer;
CANNON.Demo = function(m) {
function a() {
if (v) {
for (var a in v.__controllers)
v.__controllers[a].updateDisplay();
for (var b in v.__folders)
for (a in v.__folders[b].__controllers)
v.__folders[b].__controllers[a].updateDisplay()
}
}
function d(a) {
function b(a, c) {
a.material && (a.material = c);
for (var d = 0; d < a.children.length; d++)
b(a.children[d], c)
}
if (-1 === Q.indexOf(a))
throw Error("Render mode " + a + " not found!");
switch (a) {
case "solid":
q.currentMaterial = E;
P.intensity = 1;
U.color.setHex(2236962);
break;
case "wireframe":
q.currentMaterial = F,
P.intensity = 0,
U.color.setHex(16777215)
}
for (var c = 0; c < x.length; c++)
b(x[c], q.currentMaterial);
r.rendermode = a
}
function f() {
for (var a = w.length, b = 0; b < a; b++) {
var c = w[b];
c.position.copy(c.initPosition);
c.velocity.copy(c.initVelocity);
c.initAngularVelocity && (c.angularVelocity.copy(c.initAngularVelocity),
c.quaternion.copy(c.initQuaternion))
}
}
function c(a) {
0 === a.x && (a.x = 1E-6);
0 === a.y && (a.y = 1E-6);
0 === a.z && (a.z = 1E-6)
}
function e() {
for (var a = w.length, b = 0; b < a; b++) {
var d = w[b]
, e = x[b];
e.position.copy(d.position);
d.quaternion && e.quaternion.copy(d.quaternion)
}
K.restart();
if (r.contacts)
for (b = 0; b < G.contacts.length; b++)
for (a = 0; 2 > a; a++) {
e = K.request();
var f = G.contacts[b];
d = 0 === a ? f.bi : f.bj;
var g = 0 === a ? f.ri : f.rj;
e.position.set(d.position.x + g.x, d.position.y + g.y, d.position.z + g.z)
}
K.hideCached();
I.restart();
if (r.cm2contact)
for (b = 0; b < G.contacts.length; b++)
for (a = 0; 2 > a; a++)
e = I.request(),
f = G.contacts[b],
d = 0 === a ? f.bi : f.bj,
g = 0 === a ? f.ri : f.rj,
e.scale.set(g.x, g.y, g.z),
c(e.scale),
e.position.copy(d.position);
I.hideCached();
J.restart();
z.restart();
if (r.constraints) {
for (b = 0; b < G.constraints.length; b++)
f = G.constraints[b],
f instanceof CANNON.DistanceConstraint && (d = f.equations.normal,
a = d.bi,
d = d.bj,
e = J.request(),
d = d.position ? d.position : d,
e.scale.set(d.x - a.position.x, d.y - a.position.y, d.z - a.position.z),
c(e.scale),
e.position.copy(a.position));
for (b = 0; b < G.constraints.length; b++)
if (f = G.constraints[b],
f instanceof CANNON.PointToPointConstraint) {
g = f.equations.normal;
a = g.bi;
d = g.bj;
e = z.request();
f = z.request();
var h = z.request();
e.scale.set(g.ri.x, g.ri.y, g.ri.z);
f.scale.set(g.rj.x, g.rj.y, g.rj.z);
h.scale.set(-g.penetrationVec.x, -g.penetrationVec.y, -g.penetrationVec.z);
c(e.scale);
c(f.scale);
c(h.scale);
e.position.copy(a.position);
f.position.copy(d.position);
g.bj.position.vadd(g.rj, h.position)
}
}
z.hideCached();
J.hideCached();
O.restart();
if (r.normals)
for (b = 0; b < G.contacts.length; b++)
f = G.contacts[b],
a = f.bi,
e = O.request(),
g = f.ni,
d = a,
e.scale.set(g.x, g.y, g.z),
c(e.scale),
e.position.copy(d.position),
f.ri.vadd(e.position, e.position);
O.hideCached();
L.restart();
if (r.axes)
for (a = 0; a < w.length; a++)
d = w[a],
e = L.request(),
e.position.copy(d.position),
d.quaternion && e.quaternion.copy(d.quaternion);
L.hideCached();
M.restart();
if (r.aabbs)
for (b = 0; b < w.length; b++)
d = w[b],
d.computeAABB && (d.aabbNeedsUpdate && d.computeAABB(),
isFinite(d.aabb.lowerBound.x) && isFinite(d.aabb.lowerBound.y) && isFinite(d.aabb.lowerBound.z) && isFinite(d.aabb.upperBound.x) && isFinite(d.aabb.upperBound.y) && isFinite(d.aabb.upperBound.z) && 0 != d.aabb.lowerBound.x - d.aabb.upperBound.x && 0 != d.aabb.lowerBound.y - d.aabb.upperBound.y && 0 != d.aabb.lowerBound.z - d.aabb.upperBound.z && (e = M.request(),
e.scale.set(d.aabb.lowerBound.x - d.aabb.upperBound.x, d.aabb.lowerBound.y - d.aabb.upperBound.y, d.aabb.lowerBound.z - d.aabb.upperBound.z),
e.position.set(.5 * (d.aabb.lowerBound.x + d.aabb.upperBound.x), .5 * (d.aabb.lowerBound.y + d.aabb.upperBound.y), .5 * (d.aabb.lowerBound.z + d.aabb.upperBound.z))));
M.hideCached()
}
function b() {
requestAnimationFrame(b);
r.paused || e();
CAMERA_TEST && S.update();
renderer.clear();
renderer.render(q.scene, camera);
V.update()
}
function g(a) {
mouseX = a.clientX - T;
mouseY = a.clientY - Z
}
function k(a) {
R = s_iCanvasResizeWidth + 2 * s_iCanvasOffsetWidth;
W = s_iCanvasResizeHeight + 2 * s_iCanvasOffsetHeight;
CAMERA_TEST && (S.screen.width = R,
S.screen.height = W)
}
function h(b) {
q.dispatchEvent({
type: "destroy"
});
r.paused = !1;
a();
n(b)
}
function n(b) {
for (var c = x.length, d = 0; d < c; d++) {
G.remove(w.pop());
var e = x.pop();
q.scene.remove(e)
}
for (; G.constraints.length; )
G.removeConstraint(G.constraints[0]);
t[b]();
r.iterations = G.solver.iterations;
r.gx = G.gravity.x + 0;
r.gy = G.gravity.y + 0;
r.gz = G.gravity.z + 0;
r.quatNormalizeSkip = G.quatNormalizeSkip;
r.quatNormalizeFast = G.quatNormalizeFast;
a();
K.restart();
K.hideCached();
I.restart();
I.hideCached();
J.restart();
J.hideCached();
O.restart();
O.hideCached()
}
function l(a) {
var b = []
, c = [];
this.request = function() {
geo = b.length ? b.pop() : a();
scene.add(geo);
c.push(geo);
return geo
}
;
this.restart = function() {
for (; c.length; )
b.push(c.pop())
}
;
this.hideCached = function() {
for (var a = 0; a < b.length; a++)
scene.remove(b[a])
}
}
var q = this;
this.addScene = function(a, b) {
if ("string" !== typeof a)
throw Error("1st argument of Demo.addScene(title,initfunc) must be a string!");
if ("function" !== typeof b)
throw Error("2nd argument of Demo.addScene(title,initfunc) must be a function!");
t.push(b);
var c = t.length - 1;
B[a] = function() {
h(c)
}
;
p.add(B, a)
}
;
this.restartCurrentScene = f;
this.changeScene = h;
this.start = function() {
n(0)
}
;
var p, r = this.settings = {
stepFrequency: 60,
quatNormalizeSkip: 2,
quatNormalizeFast: !0,
gx: 0,
gy: 0,
gz: 0,
iterations: 20,
tolerance: 1E-4,
k: 1E6,
d: 3,
scene: 0,
paused: !1,
rendermode: "solid",
constraints: !1,
contacts: !1,
cm2contact: !1,
normals: !1,
axes: !1,
particleSize: .1,
shadows: !1,
aabbs: !1,
profiling: !1,
maxSubSteps: 3
};
m = m || {};
for (var u in m)
u in r && (r[u] = m[u]);
if (0 !== r.stepFrequency % 60)
throw Error("stepFrequency must be a multiple of 60.");
var w = this.bodies = []
, x = this.visuals = []
, t = []
, v = null
, A = null
, C = null
, B = {}
, D = new THREE.SphereGeometry(.1,6,6);
this.particleGeo = new THREE.SphereGeometry(1,16,8);
var E = new THREE.MeshPhongMaterial({
color: 11184810,
specular: 1118481,
shininess: 100
})
, F = new THREE.MeshLambertMaterial({
color: 16777215,
wireframe: !0
});
this.currentMaterial = E;
var H = new THREE.MeshPhongMaterial({
color: 16711680
});
this.particleMaterial = new THREE.MeshLambertMaterial({
color: 16711680
});
var K = new l(function() {
return new THREE.Mesh(D,H)
}
)
, I = new l(function() {
var a = new THREE.Geometry;
a.vertices.push(new THREE.Vector3(0,0,0));
a.vertices.push(new THREE.Vector3(1,1,1));
return new THREE.Line(a,new THREE.LineBasicMaterial({
color: 16711680
}))
}
)
, N = new THREE.BoxGeometry(1,1,1)
, y = new THREE.MeshBasicMaterial({
color: 11184810,
wireframe: !0
})
, M = new l(function() {
return new THREE.Mesh(N,y)
}
)
, J = new l(function() {
var a = new THREE.Geometry;
a.vertices.push(new THREE.Vector3(0,0,0));
a.vertices.push(new THREE.Vector3(1,1,1));
return new THREE.Line(a,new THREE.LineBasicMaterial({
color: 16711680
}))
}
)
, z = new l(function() {
var a = new THREE.Geometry;
a.vertices.push(new THREE.Vector3(0,0,0));
a.vertices.push(new THREE.Vector3(1,1,1));
return new THREE.Line(a,new THREE.LineBasicMaterial({
color: 16711680
}))
}
)
, O = new l(function() {
var a = new THREE.Geometry;
a.vertices.push(new THREE.Vector3(0,0,0));
a.vertices.push(new THREE.Vector3(1,1,1));
return new THREE.Line(a,new THREE.LineBasicMaterial({
color: 65280
}))
}
)
, L = new l(function() {
var a = new THREE.Object3D
, b = new THREE.Vector3(0,0,0)
, c = new THREE.Geometry
, d = new THREE.Geometry
, e = new THREE.Geometry;
c.vertices.push(b);
d.vertices.push(b);
e.vertices.push(b);
c.vertices.push(new THREE.Vector3(1,0,0));
d.vertices.push(new THREE.Vector3(0,1,0));
e.vertices.push(new THREE.Vector3(0,0,1));
b = new THREE.Line(c,new THREE.LineBasicMaterial({
color: 16711680
}));
d = new THREE.Line(d,new THREE.LineBasicMaterial({
color: 65280
}));
e = new THREE.Line(e,new THREE.LineBasicMaterial({
color: 255
}));
a.add(b);
a.add(d);
a.add(e);
return a
}
)
, G = this.world = new CANNON.World;
G.broadphase = new CANNON.NaiveBroadphase;
var Q = ["solid", "wireframe"], P, U, V, X;
Detector.webgl || Detector.addGetWebGLMessage();
var R = s_iCanvasResizeWidth + s_iCanvasOffsetWidth, W = s_iCanvasResizeHeight + s_iCanvasOffsetHeight, S, Y, T = R / 2, Z = W / 2;
(function() {
Y = document.createElement("div");
document.body.appendChild(Y);
CAMERA_TEST ? (NEAR = 5,
camera = new THREE.PerspectiveCamera(45,R / W,NEAR,FAR),
camera.lookAt(new THREE.Vector3(0,0,0)),
camera.position.set(0, 500, 500),
camera.up.set(0, 0, 1)) : camera = createOrthoGraphicCamera();
scene = q.scene = new THREE.Scene;
scene.fog = new THREE.Fog(2236962,1E3,FAR);
U = new THREE.AmbientLight(4473924);
scene.add(U);
P = new THREE.DirectionalLight(16777164,1);
P.position.set(180, 0, 180);
P.target.position.set(0, 0, 0);
P.castShadow = !0;
P.shadow.camera.near = 10;
P.shadow.camera.far = 100;
P.shadow.camera.fov = 30;
P.shadowMapBias = .0139;
P.shadowMapDarkness = .1;
P.shadow.mapSize.width = 1024;
P.shadow.mapSize.height = 1024;
scene.add(P);
scene.add(camera);
renderer = SHOW_3D_RENDER ? new THREE.WebGLRenderer({
clearColor: 0,
clearAlpha: .5,
antialias: !1,
alpha: !0
}) : new THREE.CanvasRenderer({
clearColor: 0,
clearAlpha: .5,
antialias: !1,
alpha: !0
});
renderer.setSize(R, W);
renderer.domElement.style.position = "relative";
renderer.domElement.style.top = "0px";
renderer.domElement.style.opacity = .5;
Y.appendChild(renderer.domElement);
X = document.createElement("div");
X.style.position = "absolute";
X.style.top = "10px";
X.style.width = "100%";
X.style.textAlign = "center";
X.innerHTML = 'cannon.js - javascript 3d physics';
Y.appendChild(X);
document.addEventListener("mousemove", g);
window.addEventListener("resize", k);
renderer.setClearColor(scene.fog.color, 1);
renderer.autoClear = !1;
C = document.createElement("canvas");
C.width = R;
C.height = W;
C.style.opacity = .5;
C.style.position = "absolute";
C.style.top = "0px";
C.style.zIndex = 90;
Y.appendChild(C);
A = new SmoothieChart({
labelOffsetY: 50,
maxDataSetLength: 100,
millisPerPixel: 2,
grid: {
strokeStyle: "none",
fillStyle: "none",
lineWidth: 1,
millisPerLine: 250,
verticalSections: 6
},
labels: {
fillStyle: "rgb(180, 180, 180)"
}
});
A.streamTo(C);
var a = {}, b = [[255, 0, 0], [0, 255, 0], [0, 0, 255], [255, 255, 0], [255, 0, 255], [0, 255, 255]], c = 0, e;
for (e in G.profile) {
var f = b[c % b.length];
a[e] = new TimeSeries({
label: e,
fillStyle: "rgb(" + f[0] + "," + f[1] + "," + f[2] + ")",
maxDataLength: 500
});
c++
}
G.addEventListener("postStep", function(b) {
for (var c in G.profile)
a[c].append(1E3 * G.time, G.profile[c])
});
c = 0;
for (e in G.profile)
f = b[c % b.length],
A.addTimeSeries(a[e], {
strokeStyle: "rgb(" + f[0] + "," + f[1] + "," + f[2] + ")",
lineWidth: 2
}),
c++;
G.doProfiling = !1;
A.stop();
C.style.display = "none";
V = new Stats;
V.domElement.style.position = "absolute";
V.domElement.style.top = "0px";
V.domElement.style.zIndex = 100;
Y.appendChild(V.domElement);
void 0 != window.dat && (v = new dat.GUI,
v.domElement.parentNode.style.zIndex = 120,
b = v.addFolder("Rendering"),
b.add(r, "rendermode", {
Solid: "solid",
Wireframe: "wireframe"
}).onChange(function(a) {
d(a)
}),
b.add(r, "contacts"),
b.add(r, "cm2contact"),
b.add(r, "normals"),
b.add(r, "constraints"),
b.add(r, "axes"),
b.add(r, "particleSize").min(0).max(1).onChange(function(a) {
for (var b = 0; b < x.length; b++)
w[b]instanceof CANNON.Particle && x[b].scale.set(a, a, a)
}),
b.add(r, "shadows").onChange(function(a) {
a ? renderer.shadowMapAutoUpdate = !0 : (renderer.shadowMapAutoUpdate = !1,
renderer.clearTarget(P.shadowMap))
}),
b.add(r, "aabbs"),
b.add(r, "profiling").onChange(function(a) {
a ? (G.doProfiling = !0,
A.start(),
C.style.display = "block") : (G.doProfiling = !1,
A.stop(),
C.style.display = "none")
}),
b = v.addFolder("World"),
b.add(r, "paused").onChange(function(a) {}),
b.add(r, "stepFrequency", 60, 600).step(60),
b.add(r, "gx", -100, 100).onChange(function(a) {
isNaN(a) || G.gravity.set(a, r.gy, r.gz)
}),
b.add(r, "gy", -100, 100).onChange(function(a) {
isNaN(a) || G.gravity.set(r.gx, a, r.gz)
}),
b.add(r, "gz", -100, 100).onChange(function(a) {
isNaN(a) || G.gravity.set(r.gx, r.gy, a)
}),
b.add(r, "quatNormalizeSkip", 0, 50).step(1).onChange(function(a) {
isNaN(a) || (G.quatNormalizeSkip = a)
}),
b.add(r, "quatNormalizeFast").onChange(function(a) {
G.quatNormalizeFast = !!a
}),
b = v.addFolder("Solver"),
b.add(r, "iterations", 1, 50).step(1).onChange(function(a) {
G.solver.iterations = a
}),
b.add(r, "k", 10, 1E7).onChange(function(a) {
q.setGlobalSpookParams(r.k, r.d, 1 / r.stepFrequency)
}),
b.add(r, "d", 0, 20).step(.1).onChange(function(a) {
q.setGlobalSpookParams(r.k, r.d, 1 / r.stepFrequency)
}),
b.add(r, "tolerance", 0, 10).step(.01).onChange(function(a) {
G.solver.tolerance = a
}),
p = v.addFolder("Scenes"),
p.open());
CAMERA_TEST && (S = new THREE.TrackballControls(camera,renderer.domElement),
S.rotateSpeed = 1,
S.zoomSpeed = 1.2,
S.panSpeed = .2,
S.noZoom = !1,
S.noPan = !1,
S.staticMoving = !1,
S.dynamicDampingFactor = .3,
S.minDistance = 0,
S.maxDistance = 1E5,
S.screen.width = R,
S.screen.height = W)
}
)();
b();
document.addEventListener("keypress", function(b) {
if (b.keyCode)
switch (b.keyCode) {
case 32:
f();
break;
case 104:
"none" == V.domElement.style.display ? (V.domElement.style.display = "block",
X.style.display = "block") : (V.domElement.style.display = "none",
X.style.display = "none");
break;
case 97:
r.aabbs = !r.aabbs;
a();
break;
case 99:
r.constraints = !r.constraints;
a();
break;
case 112:
r.paused = !r.paused;
a();
break;
case 115:
G.step(1 / r.stepFrequency);
e();
break;
case 109:
b = Q.indexOf(r.rendermode);
b++;
b %= Q.length;
d(Q[b]);
a();
break;
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
t.length > b.keyCode - 49 && !document.activeElement.localName.match(/input/) && h(b.keyCode - 49)
}
})
}
;
CANNON.Demo.prototype = new CANNON.EventTarget;
CANNON.Demo.constructor = CANNON.Demo;
CANNON.Demo.prototype.setGlobalSpookParams = function(m, a, d) {
for (var f = this.world, c = 0; c < f.constraints.length; c++)
for (var e = f.constraints[c], b = 0; b < e.equations.length; b++)
e.equations[b].setSpookParams(m, a, d);
for (c = 0; c < f.contactmaterials.length; c++)
d = f.contactmaterials[c],
d.contactEquationStiffness = m,
d.frictionEquationStiffness = m,
d.contactEquationRelaxation = a,
d.frictionEquationRelaxation = a;
f.defaultContactMaterial.contactEquationStiffness = m;
f.defaultContactMaterial.frictionEquationStiffness = m;
f.defaultContactMaterial.contactEquationRelaxation = a;
f.defaultContactMaterial.frictionEquationRelaxation = a
}
;
CANNON.Demo.prototype.getWorld = function() {
return this.world
}
;
CANNON.Demo.prototype.addVisual = function(m) {
var a;
m instanceof CANNON.Body && (a = this.shape2mesh(m));
a && (this.bodies.push(m),
this.visuals.push(a),
m.visualref = a,
m.visualref.visualId = this.bodies.length - 1,
this.scene.add(a));
return a
}
;
CANNON.Demo.prototype.addVisuals = function(m) {
for (var a = 0; a < m.length; a++)
this.addVisual(m[a])
}
;
CANNON.Demo.prototype.removeVisual = function(m) {
if (m.visualref) {
for (var a = this.bodies, d = this.visuals, f = [], c = [], e = a.length, b = 0; b < e; b++)
f.unshift(a.pop()),
c.unshift(d.pop());
e = m.visualref.visualId;
for (var g = 0; g < f.length; g++)
g !== e && (b = g > e ? g - 1 : g,
a[b] = f[g],
d[b] = c[g],
a[b].visualref = f[g].visualref,
a[b].visualref.visualId = b);
m.visualref.visualId = null;
this.scene.remove(m.visualref);
m.visualref = null
}
}
;
CANNON.Demo.prototype.removeAllVisuals = function() {
for (; this.bodies.length; )
this.removeVisual(this.bodies[0])
}
;
CANNON.Demo.prototype.shape2mesh = function(m) {
for (var a = new THREE.Object3D, d = 0; d < m.shapes.length; d++) {
var f = m.shapes[d];
switch (f.type) {
case CANNON.Shape.types.SPHERE:
var c = new THREE.SphereGeometry(f.radius,8,8);
f = new THREE.Mesh(c,this.currentMaterial);
break;
case CANNON.Shape.types.PARTICLE:
f = new THREE.Mesh(this.particleGeo,this.particleMaterial);
c = this.settings;
f.scale.set(c.particleSize, c.particleSize, c.particleSize);
break;
case CANNON.Shape.types.PLANE:
var e = new THREE.PlaneGeometry(10,10,4,4);
f = new THREE.Object3D;
c = new THREE.Object3D;
e = new THREE.Mesh(e,this.currentMaterial);
e.scale.set(100, 100, 100);
c.add(e);
e.castShadow = !0;
e.receiveShadow = !0;
f.add(c);
break;
case CANNON.Shape.types.BOX:
c = new THREE.BoxGeometry(2 * f.halfExtents.x,2 * f.halfExtents.y,2 * f.halfExtents.z);
f = new THREE.Mesh(c,this.currentMaterial);
break;
case CANNON.Shape.types.CONVEXPOLYHEDRON:
e = new THREE.Geometry;
for (c = 0; c < f.vertices.length; c++) {
var b = f.vertices[c];
e.vertices.push(new THREE.Vector3(b.x,b.y,b.z))
}
for (c = 0; c < f.faces.length; c++) {
var g = f.faces[c]
, k = g[0];
for (b = 1; b < g.length - 1; b++)
e.faces.push(new THREE.Face3(k,g[b],g[b + 1]))
}
e.computeBoundingSphere();
e.computeFaceNormals();
f = new THREE.Mesh(e,this.currentMaterial);
break;
case CANNON.Shape.types.HEIGHTFIELD:
e = new THREE.Geometry;
g = new CANNON.Vec3;
k = new CANNON.Vec3;
var h = new CANNON.Vec3;
for (b = 0; b < f.data.length - 1; b++)
for (var n = 0; n < f.data[b].length - 1; n++)
for (var l = 0; 2 > l; l++)
f.getConvexTrianglePillar(b, n, 0 === l),
g.copy(f.pillarConvex.vertices[0]),
k.copy(f.pillarConvex.vertices[1]),
h.copy(f.pillarConvex.vertices[2]),
g.vadd(f.pillarOffset, g),
k.vadd(f.pillarOffset, k),
h.vadd(f.pillarOffset, h),
e.vertices.push(new THREE.Vector3(g.x,g.y,g.z), new THREE.Vector3(k.x,k.y,k.z), new THREE.Vector3(h.x,h.y,h.z)),
c = e.vertices.length - 3,
e.faces.push(new THREE.Face3(c,c + 1,c + 2));
e.computeBoundingSphere();
e.computeFaceNormals();
f = new THREE.Mesh(e,this.currentMaterial);
break;
case CANNON.Shape.types.TRIMESH:
e = new THREE.Geometry;
g = new CANNON.Vec3;
k = new CANNON.Vec3;
h = new CANNON.Vec3;
for (c = 0; c < f.indices.length / 3; c++)
f.getTriangleVertices(c, g, k, h),
e.vertices.push(new THREE.Vector3(g.x,g.y,g.z), new THREE.Vector3(k.x,k.y,k.z), new THREE.Vector3(h.x,h.y,h.z)),
b = e.vertices.length - 3,
e.faces.push(new THREE.Face3(b,b + 1,b + 2));
e.computeBoundingSphere();
e.computeFaceNormals();
f = new THREE.Mesh(e,this.currentMaterial);
break;
default:
throw "Visual type not recognized: " + f.type;
}
f.receiveShadow = !0;
f.castShadow = !0;
if (f.children)
for (c = 0; c < f.children.length; c++)
if (f.children[c].castShadow = !0,
f.children[c].receiveShadow = !0,
f.children[c])
for (b = 0; b < f.children[c].length; b++)
f.children[c].children[b].castShadow = !0,
f.children[c].children[b].receiveShadow = !0;
c = m.shapeOffsets[d];
e = m.shapeOrientations[d];
f.position.set(c.x, c.y, c.z);
f.quaternion.set(e.x, e.y, e.z, e.w);
a.add(f)
}
this.camera = function() {
return camera
}
;
this.getScene = function() {
return scene
}
;
return a
}
;
function CBall(m, a, d, f, c) {
var e, b, g, k = null, h = 0, n = 0;
this._init = function(a, c, d) {
g = new createjs.Container;
q.addChild(g);
var f = new createjs.SpriteSheet({
images: [d],
frames: {
width: d.width / 7,
height: d.height / 3,
regX: d.width / 2 / 7,
regY: d.height / 3 / 2
}
});
e = createSprite(f, 0, d.width / 2 / 7, d.height / 3 / 2, d.width / 7, d.height / 3);
e.stop();
this.scale(.98);
d = s_oSpriteLibrary.getSprite("ball_shadow");
b = createBitmap(d);
b.x = a;
b.y = c;
b.regX = .5 * d.width;
b.regY = .5 * d.height;
this.scaleShadow(.98);
g.addChild(b, e)
}
;
this.rolls = function() {
e.rotation = Math.degrees(Math.sin(.15 * l.velocity.x));
var a = Math.abs(l.angularVelocity.x)
, b = this._goToPrevFrame;
0 > l.angularVelocity.x && (b = this._goToNextFrame);
7 < a ? b() : 3 < a ? (h++,
h > 2 / ROLL_BALL_RATE && (b(),
h = 0)) : 1 < a ? (h++,
h > 3 / ROLL_BALL_RATE && (b(),
h = 0)) : a > MIN_BALL_VEL_ROTATION && (h++,
h > 4 / ROLL_BALL_RATE && (b(),
h = 0))
}
;
this._goToPrevFrame = function() {
0 === n ? n = 6 : n--;
e.gotoAndStop(n)
}
;
this._goToNextFrame = function() {
7 === n ? n = 1 : n++;
e.gotoAndStop(n)
}
;
this.unload = function() {
e.removeAllEventListeners();
q.removeChild(e)
}
;
this.setVisible = function(a) {
g.visible = a
}
;
this.getStartScale = function() {
return .98
}
;
this.startPosShadowY = function(a) {
k = a
}
;
this.getStartShadowYPos = function() {
return k
}
;
this.tweenFade = function(a, b, c) {
createjs.Tween.get(g).wait(c).to({
alpha: a
}, b).call(function() {})
}
;
this.setPositionShadow = function(a, c) {
b.x = a;
b.y = c
}
;
this.setPosition = function(a, b) {
e.x = a;
e.y = b
}
;
this.getPhysics = function() {
return l
}
;
this.setAngle = function(a) {
e.rotation = a
}
;
this.getX = function() {
return e.x
}
;
this.getY = function() {
return e.y
}
;
this.getStartScale = function() {
return .98
}
;
this.scale = function(a) {
e.scaleX = a;
e.scaleY = a
}
;
this.scaleShadow = function(a) {
.08 < a ? (b.scaleX = a,
b.scaleY = a) : (b.scaleX = .08,
b.scaleY = .08)
}
;
this.setAlphaByHeight = function(a) {
b.alpha = a
}
;
this.getScale = function() {
return e.scaleX
}
;
this.getObject = function() {
return e
}
;
this.getDepthPos = function() {
return l.position.y
}
;
var l = f;
var q = c;
this._init(m, a, d);
return this
}
function CGame(m, a, d) {
var f, c, e, b, g, k, h, n, l = null, q = null, p, r = null, u = !1, w = !1, x = !1, t, v = 0, A = 0, C, B, D, E, F, H, K = STATE_INIT, I = null;
this._init = function() {
$(s_oMain).trigger("start_session");
this.pause(!0);
B = t = 0;
H = [];
this.resetForcesValues();
playSound("crowd_cheering", .7, !0);
C = LIVES;
p = new createjs.Container;
s_oStage.addChild(p);
s_bMobile && this.velocityBall();
b = createBitmap(s_oSpriteLibrary.getSprite("bg_game_bowler"));
p.addChild(b);
g = new CScenario;
I = SHOW_3D_RENDER ? camera : createOrthoGraphicCamera();
l = new COpponent(CANVAS_WIDTH_HALF - 55,420,d,p);
var c = s_oSpriteLibrary.getSprite("ball_game");
n = new CBall(0,0,c,g.ballBody(),p);
H.push(n);
this.ballPosition();
resizeCanvas3D();
setVolume("soundtrack", .35);
e = new CInterface;
c = s_oSpriteLibrary.getSprite("glove_" + a);
k = new CGlove(-20,LEFT_GLOVE,c,g.getLeftGlovesBody(),p);
h = new CGlove(20,RIGHT_GLOVE,c,g.getRightGlovesBody(),p);
h.flip();
H.push(k);
H.push(h);
SHOW_3D_RENDER ? (this.onGlovesMove(window),
this._onExitHelpPanel()) : (e.createHelpPanel(a),
this.onGlovesMove(s_oStage))
}
;
this.velocityBall = function() {}
;
this.sortDepth = function(a, b) {
null !== a && null !== b && (a.getDepthPos() > b.getDepthPos() ? p.getChildIndex(a.getObject()) > p.getChildIndex(b.getObject()) && p.swapChildren(a.getObject(), b.getObject()) : a.getDepthPos() < b.getDepthPos() && p.getChildIndex(b.getObject()) > p.getChildIndex(a.getObject()) && p.swapChildren(b.getObject(), a.getObject()))
}
;
this._onExitHelpPanel = function() {
e.onExitFromHelp();
this.activeEventListeners();
this.pause(!1);
$(s_oMain).trigger("start_level", 1)
}
;
this.activeEventListeners = function() {
SHOW_3D_RENDER ? (window.addEventListener("mousedown", this.addBatImpulseToBall),
window.addEventListener("mousemove", this.onGlovesMove)) : null === q && (q = s_oStage.on("stagemousemove", this.onGlovesMove))
}
;
this.deactiveEventListeners = function() {
SHOW_3D_RENDER ? (window.removeEventListener("mousedown", this.addBatImpulseToBall),
window.removeEventListener("mousemove", this.onGlovesMove)) : (s_oStage.off("stagemousemove", q),
q = null)
}
;
this.resetForcesValues = function() {
E = START_BALL_FORCE_Y;
F = START_BALL_FORCE_X;
f = START_BALL_FORCE_Z;
c = START_BALL_FORCE_Z + STEP_BALL_FORCE_Z
}
;
this.increaseDifficulty = function() {
var a = E + STEP_BALL_FORCE_Y
, b = F + STEP_BALL_FORCE_X
, d = c + STEP_BALL_FORCE_Z;
F = b > MAX_BALL_FORCE_X ? MAX_BALL_FORCE_X : b;
E = a > MAX_BALL_FORCE_Y ? MAX_BALL_FORCE_Y : a;
c = d > MAX_BALL_FORCE_Z ? MAX_BALL_FORCE_Z : d
}
;
this.ballPosition = function() {
var a = g.ballBody()
, b = this.convert3dPosTo2dScreen(a.position, I)
, c = n.getStartScale() - b.z;
this.shadowBall(a, c);
n.scale(c);
n.setPosition(b.x, b.y)
}
;
this.shadowBall = function(a, b) {
var c = g.getFieldBody()
, d = this.convert3dPosTo2dScreen({
x: a.position.x,
y: a.position.y,
z: c.position.z
}, I)
, e = a.position.z - c.position.z;
1 > e && (e = 1);
n.scaleShadow(b / e);
n.setAlphaByHeight(.1 * (-a.position.z - .1 * c.position.z));
n.setPositionShadow(d.x, d.y)
}
;
this.unload = function() {
s_oStage.removeAllChildren();
e.unload();
g.destroyWorld();
g = null;
this.deactiveEventListeners()
}
;
this.resetValues = function() {
C = LIVES;
t = 0;
this.resetForcesValues();
e.viewScore(t);
e.refreshLivesText(C)
}
;
this.ballNotCaught = function() {
u || (u = !0,
D = TIME_RESET_AFTER_GOAL,
e.createAnimText(TEXT_MISSED, 80, !1, null, 300, function() {}),
C--,
e.refreshLivesText(C),
A = 0,
playSound("crowd_ohhh", 1, !1))
}
;
this.launchBallImpulse = function() {
g.setElementVelocity(n.getPhysics(), {
x: 0,
y: 0,
z: 0
});
g.addImpulse(n.getPhysics(), LAUNCH_BALL_IMPULSE);
g.setElementAngularVelocity(n.getPhysics(), {
x: 0,
y: 0,
z: 0
})
}
;
this.ballCaught = function(a, b) {
u || w || (a.x > -BALL_SAVED_POINT.x && a.x < BALL_SAVED_POINT.x && a.z > -BALL_SAVED_POINT.z && a.z < BALL_SAVED_POINT.z ? (b === LEFT_GLOVE ? k.changeState("perfect") : h.changeState("perfect"),
D = TIME_RESET_AFTER_KEEPER_SAVED,
createjs.Tween.get(p).wait(100).call(function() {
u || s_oGame.textSave()
}),
this.calculateScore(a),
w = !0,
this.resetBallPosition(),
n.setVisible(!1),
this.increaseDifficulty()) : this.ballNotCaught(),
playSound("kick", 1, !1),
playSound("applauses", 1, !1))
}
;
this.ballVisible = function(a) {
n.setVisible(a)
}
;
this.calculateScore = function(a) {
t += SCORE_BALL_CAUGHT - Math.floor((a.x + a.z) * SCORE_ERROR_MULTIPLIER);
e.viewScore(t)
}
;
this.addBatImpulseToBall = function() {
if (!x && K === STATE_PLAY) {
var a = {
x: Math.random() * (F + F) - F,
y: -E,
z: Math.random() * (c - f) + f
}
, b = g.ballBody();
b.position.x = 0;
g.setElementVelocity(b, {
x: 0,
y: 0,
z: 0
});
g.addImpulse(b, a);
g.setElementAngularVelocity(b, {
x: 0,
y: 0,
z: 0
});
x = !0;
playSound("hit_ball", 1, !1)
}
}
;
this.pause = function(a) {
a ? (K = STATE_PAUSE,
this.deactiveEventListeners()) : (K = STATE_PLAY,
this.activeEventListeners());
createjs.Ticker.paused = a
}
;
this.startOpponentShot = function() {
l.hideBowler(B);
B = 0
}
;
this.onExit = function() {
this.unload();
stopSound("crowd_cheering");
$(s_oMain).trigger("show_interlevel_ad");
$(s_oMain).trigger("end_session");
setVolume("soundtrack", 1);
s_oMain.gotoMenu()
}
;
this.resetGame = function() {
this.resetValues();
this.resetScene();
this.activeEventListeners();
K = STATE_PLAY;
this.startOpponentShot();
$(s_oMain).trigger("restart_level", 1)
}
;
this.resetBallPosition = function() {
var a = g.ballBody();
a.position.set(POSITION_BALL.x, POSITION_BALL.y, POSITION_BALL.z);
g.setElementVelocity(a, {
x: 0,
y: 0,
z: 0
});
g.setElementAngularVelocity(a, {
x: 0,
y: 0,
z: 0
});
n.setVisible(!0)
}
;
this._updateInit = function() {
g.update();
this._updateBall2DPosition();
K = STATE_PLAY
}
;
this.onGlovesMove = function(a) {
var b = k.getPhysics()
, c = h.getPhysics();
var d = SHOW_3D_RENDER ? {
x: a.clientX - s_iCanvasOffsetWidth + OFFSET_MOUSE_X,
y: a.clientY - s_iCanvasOffsetHeight
} : {
x: a.stageX / s_fInverseScaling + OFFSET_MOUSE_X,
y: a.stageY / s_fInverseScaling
};
s_bMobile && (d.x += MOBILE_OFFSET_GLOVES_X,
d.y += MOBILE_OFFSET_GLOVES_Y);
a = 2 * RIGHT_GLOVE_POSITION.x;
d = s_oGame.convert2dScreenPosTo3d(d, b);
var e = d.x + a;
e < LIMIT_HAND_RANGE_POS.x && d.x > -LIMIT_HAND_RANGE_POS.x ? (b.position.x = d.x,
c.position.x = e) : e < LIMIT_HAND_RANGE_POS.x ? (b.position.x = -LIMIT_HAND_RANGE_POS.x,
c.position.x = -LIMIT_HAND_RANGE_POS.x + a) : (b.position.x = LIMIT_HAND_RANGE_POS.x - a,
c.position.x = LIMIT_HAND_RANGE_POS.x);
d.z > LIMIT_HAND_RANGE_POS.zMin && d.z < LIMIT_HAND_RANGE_POS.zMax ? (b.position.z = d.z,
c.position.z = d.z) : d.z > LIMIT_HAND_RANGE_POS.zMin ? (b.position.z = LIMIT_HAND_RANGE_POS.zMax,
c.position.z = LIMIT_HAND_RANGE_POS.zMax) : (b.position.z = LIMIT_HAND_RANGE_POS.zMin,
c.position.z = LIMIT_HAND_RANGE_POS.zMin);
b = s_oGame.convert3dPosTo2dScreen(b.position, I);
c = s_oGame.convert3dPosTo2dScreen(c.position, I);
k.setPosition(b.x, b.y);
h.setPosition(c.x, c.y)
}
;
this.convert2dScreenPosTo3d = function(a) {
a = new THREE.Vector3(a.x / s_iCanvasResizeWidth * 2 - 1,2 * -(a.y / s_iCanvasResizeHeight) + 1,-1);
a.unproject(I);
a.sub(I.position);
a.normalize();
a.multiply(new THREE.Vector3(34,1,34));
return a
}
;
this.convert3dPosTo2dScreen = function(a, b) {
var c = (new THREE.Vector3(a.x,a.y,a.z)).project(b)
, d = .5 * Math.floor(s_iCanvasResizeWidth)
, e = .5 * Math.floor(s_iCanvasResizeHeight);
c.x = (c.x * d + d) * s_fInverseScaling;
c.y = (-(c.y * e) + e) * s_fInverseScaling;
return c
}
;
this.timeReset = function() {
0 < D ? D -= FPS_TIME : (v++,
k.changeState("normal"),
h.changeState("normal"),
0 < C ? (this.resetScene(),
this.startOpponentShot()) : (this.gameOver(),
K = STATE_FINISH,
$(s_oMain).trigger("end_level", 1),
this.deactiveEventListeners()),
x = !1)
}
;
this.textSave = function() {
if (A < TEXT_CONGRATULATION.length) {
var a = !1;
A >= TEXT_CONGRATULATION.length - 1 && (a = !0);
e.createAnimText(TEXT_CONGRATULATION[A], TEXT_SIZE[A], a, TEXT_EXCELLENT_COLOR, 300, function() {});
A++
} else {
a = !1;
var b = Math.floor(Math.random() * (TEXT_CONGRATULATION.length - 1)) + 1;
b >= TEXT_CONGRATULATION.length - 1 && (a = !0);
e.createAnimText(TEXT_CONGRATULATION[b], TEXT_SIZE[b], a, TEXT_EXCELLENT_COLOR, 300, function() {})
}
}
;
this.gameOver = function() {
r = CEndPanel(s_oSpriteLibrary.getSprite("msg_box"));
r.show(t)
}
;
this.resetScene = function() {
w = u = !1;
this.resetBallPosition()
}
;
this._onEnd = function() {
this.onExit()
}
;
this.swapChildrenIndex = function() {
for (var a = 0; a < H.length - 1; a++)
for (var b = a + 1; b < H.length; b++)
this.sortDepth(H[a], H[b])
}
;
this.rotateGloves = function() {
var a = (k.getX() - CANVAS_WIDTH_HALF) * HAND_KEEPER_ANGLE_RATE
, b = (h.getX() - CANVAS_WIDTH_HALF) * HAND_KEEPER_ANGLE_RATE;
k.setRotation(a);
h.setRotation(b)
}
;
this._updatePlay = function() {
for (var a = 0; a < PHYSICS_ACCURACY; a++)
g.update();
this._updateBall2DPosition();
(w || u) && this.timeReset();
this.rotateGloves();
this.batterAnimation();
this.swapChildrenIndex()
}
;
this.batterAnimation = function() {
l.hideBowler(B);
B + 1 < NUM_SPRITE_BATTER_BOWLER_MODE ? (l.viewBowler(B + 1),
B++) : l.viewBowler(B);
20 === B && (this.resetBallPosition(),
this.launchBallImpulse());
52 === B && this.addBatImpulseToBall()
}
;
this.update = function() {
switch (K) {
case STATE_INIT:
this._updateInit();
break;
case STATE_PLAY:
this._updatePlay()
}
}
;
this._updateBall2DPosition = function() {
this.ballPosition();
n.rolls();
I.updateProjectionMatrix();
I.updateMatrixWorld()
}
;
s_oGame = this;
LIVES = m.lives;
SCORE_BALL_CAUGHT = m.score_ball_caught;
START_BALL_FORCE_X = m.ball_force_left_right_start;
STEP_BALL_FORCE_X = m.ball_force_left_right_step;
MAX_BALL_FORCE_X = m.ball_force_left_right_max;
START_BALL_FORCE_Z = m.ball_force_up_start;
STEP_BALL_FORCE_Z = m.ball_force_up_step;
MAX_BALL_FORCE_Z = m.ball_force_up_max;
START_BALL_FORCE_Y = m.ball_start_velocity;
STEP_BALL_FORCE_Y = m.ball_step_velocity;
MAX_BALL_FORCE_Y = m.ball_max_velocity;
SCORE_PERFECT_BALL_SAVED = m.score_perfect_ball_saved;
BALL_SAVED_POINT = m.perfect_ball_saved_point;
NUM_LEVEL_FOR_ADS = m.num_levels_for_ads;
this._init()
}
var s_oGame;
function CGlove(m, a, d, f, c) {
var e, b;
this._init = function(a, c, d) {
var f = new createjs.SpriteSheet({
images: [d],
frames: {
width: d.width / 2,
height: d.height,
regX: d.width / 2 / 2 + GLOVE_REG[c].x,
regY: d.height / 2 + GLOVE_REG[c].y
},
animations: {
normal: [0],
perfect: [1]
}
});
e = createSprite(f, "normal", d.width / 2 / 2 + GLOVE_REG[c].x, d.height / 2 + GLOVE_REG[c].y, d.width / 2, d.height);
b = c;
this.setPosition(CANVAS_WIDTH_HALF + a, CANVAS_HEIGHT_HALF);
k.addChild(e)
}
;
this.unload = function() {
k.removeChild(e)
}
;
this.setPosition = function(a, b) {
e.x = a;
e.y = b
}
;
this.getObject = function() {
return e
}
;
this.getDepthPos = function() {
return g.position.y
}
;
this.getX = function() {
return e.x
}
;
this.getY = function() {
return e.y
}
;
this.changeState = function(a) {
e.gotoAndStop(a)
}
;
this.getDir = function() {
return b
}
;
this.getPhysics = function() {
return g
}
;
this.setScale = function(a) {
e.scaleX = e.scaleY = a
}
;
this.flip = function() {
e.scaleX = -e.scaleX
}
;
this.setRotation = function(a) {
e.rotation = a
}
;
var g = f;
var k = c;
this._init(m, a, d);
return this
}
function CScenario() {
var m, a, d, f, c, e, b, g, k, h, n, l, q, p;
if (SHOW_3D_RENDER)
var r = new CANNON.Demo;
this.getDemo = function() {
return r
}
;
this._init = function() {
m = SHOW_3D_RENDER ? r.getWorld() : new CANNON.World;
m.gravity.set(0, 0, -9.81);
m.broadphase = new CANNON.NaiveBroadphase;
m.solver.iterations = 25;
m.solver.tolerance = 1E-5;
a = new CANNON.Material;
d = new CANNON.Material;
f = new CANNON.Material;
c = new CANNON.Material;
var b = new CANNON.ContactMaterial(d,f,{
friction: .1,
restitution: .5
})
, e = new CANNON.ContactMaterial(d,a,{
friction: .2,
restitution: .6
})
, g = new CANNON.ContactMaterial(d,c,{
friction: .5,
restitution: .1
});
m.addContactMaterial(b);
m.addContactMaterial(e);
m.addContactMaterial(g);
s_oScenario._createBallBody();
s_oScenario._createFieldBody();
s_oScenario.createLineOfGoal();
q = s_oScenario.createHandGoalKeeper(LEFT_GLOVE_POSITION, LEFT_GLOVE);
p = s_oScenario.createHandGoalKeeper(RIGHT_GLOVE_POSITION, RIGHT_GLOVE)
}
;
this._createFieldBody = function() {
k = new CANNON.Plane;
h = new CANNON.Body({
mass: 0,
material: a
});
h.addShape(k);
h.position.z = -10;
h.addEventListener("collide", function(a) {
s_oScenario.fieldCollision()
});
m.addBody(h);
SHOW_3D_RENDER && r.addVisual(h)
}
;
this.createLineOfGoal = function() {
n = new CANNON.Box(new CANNON.Vec3(LINE_GOAL_SIZE.width,LINE_GOAL_SIZE.depth,LINE_GOAL_SIZE.height));
l = new CANNON.Body({
mass: 0
});
l.addShape(n);
l.position.set(GOAL_LINE_POS.x, GOAL_LINE_POS.y, GOAL_LINE_POS.z);
l.addEventListener("collide", function(a) {
s_oScenario.lineGoalCollision()
});
m.addBody(l)
}
;
this.createHandGoalKeeper = function(a, b) {
var d = new CANNON.Box(new CANNON.Vec3(GLOVE_SIZE.width,GLOVE_SIZE.depth,GLOVE_SIZE.height));
var e = new CANNON.Body({
mass: 0,
material: c
});
e.addShape(d);
e.position.set(a.x, a.y, a.z);
e.addEventListener("collide", function(a) {
s_oScenario.handCollision(a, b)
});
m.addBody(e);
SHOW_3D_RENDER && r.addVisual(e);
return e
}
;
this._createBallBody = function() {
e = new CANNON.Sphere(BALL_RADIUS);
b = new CANNON.Body({
mass: BALL_MASS,
material: d,
linearDamping: BALL_LINEAR_DAMPING,
angularDamping: 2 * BALL_LINEAR_DAMPING
});
var a = new CANNON.Vec3(POSITION_BALL.x,POSITION_BALL.y,POSITION_BALL.z);
b.position.copy(a);
b.addShape(e);
m.add(b);
SHOW_3D_RENDER && (g = r.addVisual(b))
}
;
this.addImpulse = function(a, b) {
var c = new CANNON.Vec3(0,0,BALL_RADIUS)
, d = new CANNON.Vec3(b.x,b.y,b.z);
a.applyImpulse(d, c)
}
;
this.addForce = function(a, b) {
var c = new CANNON.Vec3(0,0,0)
, d = new CANNON.Vec3(b.x,b.y,b.z);
a.applyForce(d, c)
}
;
this.getBodyVelocity = function(a) {
return a.velocity
}
;
this.ballBody = function() {
return b
}
;
this.ballMesh = function() {
return g
}
;
this.getCamera = function() {
return r.camera()
}
;
this.fieldCollision = function() {}
;
this.collisionWithBall = function() {
s_oGame.lineGoalCollision()
}
;
this.setElementAngularVelocity = function(a, b) {
a.angularVelocity.set(b.x, b.y, b.z)
}
;
this.setElementVelocity = function(a, b) {
var c = new CANNON.Vec3(b.x,b.y,b.z);
a.velocity = c
}
;
this.setElementLinearDamping = function(a, b) {
a.linearDamping = b
}
;
this.getFieldBody = function() {
return h
}
;
this.lineGoalCollision = function() {
s_oGame.resetBallPosition();
s_oGame.ballVisible(!1);
s_oGame.ballNotCaught()
}
;
this.handCollision = function(a, b) {
s_oGame.ballCaught(a.contact.rj, b)
}
;
this.update = function() {
m.step(PHYSICS_STEP)
}
;
this.getLeftGlovesBody = function() {
return q
}
;
this.getRightGlovesBody = function() {
return p
}
;
this.poleCollision = function() {
playSound("kick", 1, 0)
}
;
this.destroyWorld = function() {
for (var a = m.bodies, b = 0; b < a.length; b++)
m.remove(a[b]);
m = null
}
;
s_oScenario = this;
SHOW_3D_RENDER ? (r.addScene("Cricket Bowler Mode", this._init),
r.start()) : this._init()
}
var s_oScenario, dat = dat || {};
dat.gui = dat.gui || {};
dat.utils = dat.utils || {};
dat.controllers = dat.controllers || {};
dat.dom = dat.dom || {};
dat.color = dat.color || {};
dat.utils.css = function() {
return {
load: function(m, a) {
a = a || document;
var d = a.createElement("link");
d.type = "text/css";
d.rel = "stylesheet";
d.href = m;
a.getElementsByTagName("head")[0].appendChild(d)
},
inject: function(m, a) {
a = a || document;
var d = document.createElement("style");
d.type = "text/css";
d.innerHTML = m;
a.getElementsByTagName("head")[0].appendChild(d)
}
}
}();
dat.utils.common = function() {
var m = Array.prototype.forEach
, a = Array.prototype.slice;
return {
BREAK: {},
extend: function(d) {
this.each(a.call(arguments, 1), function(a) {
for (var c in a)
this.isUndefined(a[c]) || (d[c] = a[c])
}, this);
return d
},
defaults: function(d) {
this.each(a.call(arguments, 1), function(a) {
for (var c in a)
this.isUndefined(d[c]) && (d[c] = a[c])
}, this);
return d
},
compose: function() {
var d = a.call(arguments);
return function() {
for (var f = a.call(arguments), c = d.length - 1; 0 <= c; c--)
f = [d[c].apply(this, f)];
return f[0]
}
},
each: function(a, f, c) {
if (m && a.forEach === m)
a.forEach(f, c);
else if (a.length === a.length + 0)
for (var d = 0, b = a.length; d < b && !(d in a && f.call(c, a[d], d) === this.BREAK); d++)
;
else
for (d in a)
if (f.call(c, a[d], d) === this.BREAK)
break
},
defer: function(a) {
setTimeout(a, 0)
},
toArray: function(d) {
return d.toArray ? d.toArray() : a.call(d)
},
isUndefined: function(a) {
return void 0 === a
},
isNull: function(a) {
return null === a
},
isNaN: function(a) {
return a !== a
},
isArray: Array.isArray || function(a) {
return a.constructor === Array
}
,
isObject: function(a) {
return a === Object(a)
},
isNumber: function(a) {
return a === a + 0
},
isString: function(a) {
return a === a + ""
},
isBoolean: function(a) {
return !1 === a || !0 === a
},
isFunction: function(a) {
return "[object Function]" === Object.prototype.toString.call(a)
}
}
}();
dat.controllers.Controller = function(m) {
var a = function(a, f) {
this.initialValue = a[f];
this.domElement = document.createElement("div");
this.object = a;
this.property = f;
this.__onFinishChange = this.__onChange = void 0
};
m.extend(a.prototype, {
onChange: function(a) {
this.__onChange = a;
return this
},
onFinishChange: function(a) {
this.__onFinishChange = a;
return this
},
setValue: function(a) {
this.object[this.property] = a;
this.__onChange && this.__onChange.call(this, a);
this.updateDisplay();
return this
},
getValue: function() {
return this.object[this.property]
},
updateDisplay: function() {
return this
},
isModified: function() {
return this.initialValue !== this.getValue()
}
});
return a
}(dat.utils.common);
dat.dom.dom = function(m) {
function a(a) {
if ("0" === a || m.isUndefined(a))
return 0;
a = a.match(f);
return m.isNull(a) ? 0 : parseFloat(a[1])
}
var d = {};
m.each({
HTMLEvents: ["change"],
MouseEvents: ["click", "mousemove", "mousedown", "mouseup", "mouseover"],
KeyboardEvents: ["keydown"]
}, function(a, b) {
m.each(a, function(a) {
d[a] = b
})
});
var f = /(\d+(\.\d+)?)px/
, c = {
makeSelectable: function(a, b) {
void 0 !== a && void 0 !== a.style && (a.onselectstart = b ? function() {
return !1
}
: function() {}
,
a.style.MozUserSelect = b ? "auto" : "none",
a.style.KhtmlUserSelect = b ? "auto" : "none",
a.unselectable = b ? "on" : "off")
},
makeFullscreen: function(a, b, c) {
m.isUndefined(b) && (b = !0);
m.isUndefined(c) && (c = !0);
a.style.position = "absolute";
b && (a.style.left = 0,
a.style.right = 0);
c && (a.style.top = 0,
a.style.bottom = 0)
},
fakeEvent: function(a, b, c, f) {
c = c || {};
var e = d[b];
if (!e)
throw Error("Event type " + b + " not supported.");
var g = document.createEvent(e);
switch (e) {
case "MouseEvents":
g.initMouseEvent(b, c.bubbles || !1, c.cancelable || !0, window, c.clickCount || 1, 0, 0, c.x || c.clientX || 0, c.y || c.clientY || 0, !1, !1, !1, !1, 0, null);
break;
case "KeyboardEvents":
e = g.initKeyboardEvent || g.initKeyEvent;
m.defaults(c, {
cancelable: !0,
ctrlKey: !1,
altKey: !1,
shiftKey: !1,
metaKey: !1,
keyCode: void 0,
charCode: void 0
});
e(b, c.bubbles || !1, c.cancelable, window, c.ctrlKey, c.altKey, c.shiftKey, c.metaKey, c.keyCode, c.charCode);
break;
default:
g.initEvent(b, c.bubbles || !1, c.cancelable || !0)
}
m.defaults(g, f);
a.dispatchEvent(g)
},
bind: function(a, b, d, f) {
a.addEventListener ? a.addEventListener(b, d, f || !1) : a.attachEvent && a.attachEvent("on" + b, d);
return c
},
unbind: function(a, b, d, f) {
a.removeEventListener ? a.removeEventListener(b, d, f || !1) : a.detachEvent && a.detachEvent("on" + b, d);
return c
},
addClass: function(a, b) {
if (void 0 === a.className)
a.className = b;
else if (a.className !== b) {
var d = a.className.split(/ +/);
-1 == d.indexOf(b) && (d.push(b),
a.className = d.join(" ").replace(/^\s+/, "").replace(/\s+$/, ""))
}
return c
},
removeClass: function(a, b) {
if (b) {
if (void 0 !== a.className)
if (a.className === b)
a.removeAttribute("class");
else {
var d = a.className.split(/ +/)
, e = d.indexOf(b);
-1 != e && (d.splice(e, 1),
a.className = d.join(" "))
}
} else
a.className = void 0;
return c
},
hasClass: function(a, b) {
return (new RegExp("(?:^|\\s+)" + b + "(?:\\s+|$)")).test(a.className) || !1
},
getWidth: function(c) {
c = getComputedStyle(c);
return a(c["border-left-width"]) + a(c["border-right-width"]) + a(c["padding-left"]) + a(c["padding-right"]) + a(c.width)
},
getHeight: function(c) {
c = getComputedStyle(c);
return a(c["border-top-width"]) + a(c["border-bottom-width"]) + a(c["padding-top"]) + a(c["padding-bottom"]) + a(c.height)
},
getOffset: function(a) {
var b = {
left: 0,
top: 0
};
if (a.offsetParent) {
do
b.left += a.offsetLeft,
b.top += a.offsetTop;
while (a = a.offsetParent)
}
return b
},
isActive: function(a) {
return a === document.activeElement && (a.type || a.href)
}
};
return c
}(dat.utils.common);
dat.controllers.OptionController = function(m, a, d) {
var f = function(c, e, b) {
f.superclass.call(this, c, e);
var g = this;
this.__select = document.createElement("select");
if (d.isArray(b)) {
var k = {};
d.each(b, function(a) {
k[a] = a
});
b = k
}
d.each(b, function(a, b) {
var c = document.createElement("option");
c.innerHTML = b;
c.setAttribute("value", a);
g.__select.appendChild(c)
});
this.updateDisplay();
a.bind(this.__select, "change", function() {
g.setValue(this.options[this.selectedIndex].value)
});
this.domElement.appendChild(this.__select)
};
f.superclass = m;
d.extend(f.prototype, m.prototype, {
setValue: function(a) {
a = f.superclass.prototype.setValue.call(this, a);
this.__onFinishChange && this.__onFinishChange.call(this, this.getValue());
return a
},
updateDisplay: function() {
this.__select.value = this.getValue();
return f.superclass.prototype.updateDisplay.call(this)
}
});
return f
}(dat.controllers.Controller, dat.dom.dom, dat.utils.common);
dat.controllers.NumberController = function(m, a) {
var d = function(f, c, e) {
d.superclass.call(this, f, c);
e = e || {};
this.__min = e.min;
this.__max = e.max;
this.__step = e.step;
a.isUndefined(this.__step) ? this.__impliedStep = 0 == this.initialValue ? 1 : Math.pow(10, Math.floor(Math.log(this.initialValue) / Math.LN10)) / 10 : this.__impliedStep = this.__step;
f = this.__impliedStep;
f = f.toString();
f = -1 < f.indexOf(".") ? f.length - f.indexOf(".") - 1 : 0;
this.__precision = f
};
d.superclass = m;
a.extend(d.prototype, m.prototype, {
setValue: function(a) {
void 0 !== this.__min && a < this.__min ? a = this.__min : void 0 !== this.__max && a > this.__max && (a = this.__max);
void 0 !== this.__step && 0 != a % this.__step && (a = Math.round(a / this.__step) * this.__step);
return d.superclass.prototype.setValue.call(this, a)
},
min: function(a) {
this.__min = a;
return this
},
max: function(a) {
this.__max = a;
return this
},
step: function(a) {
this.__step = a;
return this
}
});
return d
}(dat.controllers.Controller, dat.utils.common);
dat.controllers.NumberControllerBox = function(m, a, d) {
var f = function(c, e, b) {
function g() {
var a = parseFloat(m.__input.value);
d.isNaN(a) || m.setValue(a)
}
function k(a) {
var b = l - a.clientY;
m.setValue(m.getValue() + b * m.__impliedStep);
l = a.clientY
}
function h() {
a.unbind(window, "mousemove", k);
a.unbind(window, "mouseup", h)
}
this.__truncationSuspended = !1;
f.superclass.call(this, c, e, b);
var m = this, l;
this.__input = document.createElement("input");
this.__input.setAttribute("type", "text");
a.bind(this.__input, "change", g);
a.bind(this.__input, "blur", function() {
g();
m.__onFinishChange && m.__onFinishChange.call(m, m.getValue())
});
a.bind(this.__input, "mousedown", function(b) {
a.bind(window, "mousemove", k);
a.bind(window, "mouseup", h);
l = b.clientY
});
a.bind(this.__input, "keydown", function(a) {
13 === a.keyCode && (m.__truncationSuspended = !0,
this.blur(),
m.__truncationSuspended = !1)
});
this.updateDisplay();
this.domElement.appendChild(this.__input)
};
f.superclass = m;
d.extend(f.prototype, m.prototype, {
updateDisplay: function() {
var a = this.__input;
if (this.__truncationSuspended)
var d = this.getValue();
else {
d = this.getValue();
var b = Math.pow(10, this.__precision);
d = Math.round(d * b) / b
}
a.value = d;
return f.superclass.prototype.updateDisplay.call(this)
}
});
return f
}(dat.controllers.NumberController, dat.dom.dom, dat.utils.common);
dat.controllers.NumberControllerSlider = function(m, a, d, f, c) {
function e(a, b, c, d, e) {
return d + (a - b) / (c - b) * (e - d)
}
var b = function(c, d, f, m, l) {
function g(b) {
b.preventDefault();
var c = a.getOffset(k.__background)
, d = a.getWidth(k.__background);
k.setValue(e(b.clientX, c.left, c.left + d, k.__min, k.__max));
return !1
}
function h() {
a.unbind(window, "mousemove", g);
a.unbind(window, "mouseup", h);
k.__onFinishChange && k.__onFinishChange.call(k, k.getValue())
}
b.superclass.call(this, c, d, {
min: f,
max: m,
step: l
});
var k = this;
this.__background = document.createElement("div");
this.__foreground = document.createElement("div");
a.bind(this.__background, "mousedown", function(b) {
a.bind(window, "mousemove", g);
a.bind(window, "mouseup", h);
g(b)
});
a.addClass(this.__background, "slider");
a.addClass(this.__foreground, "slider-fg");
this.updateDisplay();
this.__background.appendChild(this.__foreground);
this.domElement.appendChild(this.__background)
};
b.superclass = m;
b.useDefaultStyles = function() {
d.inject(c)
}
;
f.extend(b.prototype, m.prototype, {
updateDisplay: function() {
var a = (this.getValue() - this.__min) / (this.__max - this.__min);
this.__foreground.style.width = 100 * a + "%";
return b.superclass.prototype.updateDisplay.call(this)
}
});
return b
}(dat.controllers.NumberController, dat.dom.dom, dat.utils.css, dat.utils.common, ".slider {\n box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);\n height: 1em;\n border-radius: 1em;\n background-color: #eee;\n padding: 0 0.5em;\n overflow: hidden;\n}\n\n.slider-fg {\n padding: 1px 0 2px 0;\n background-color: #aaa;\n height: 1em;\n margin-left: -0.5em;\n padding-right: 0.5em;\n border-radius: 1em 0 0 1em;\n}\n\n.slider-fg:after {\n display: inline-block;\n border-radius: 1em;\n background-color: #fff;\n border: 1px solid #aaa;\n content: '';\n float: right;\n margin-right: -1em;\n margin-top: -1px;\n height: 0.9em;\n width: 0.9em;\n}");
dat.controllers.FunctionController = function(m, a, d) {
var f = function(c, d, b) {
f.superclass.call(this, c, d);
var e = this;
this.__button = document.createElement("div");
this.__button.innerHTML = void 0 === b ? "Fire" : b;
a.bind(this.__button, "click", function(a) {
a.preventDefault();
e.fire();
return !1
});
a.addClass(this.__button, "button");
this.domElement.appendChild(this.__button)
};
f.superclass = m;
d.extend(f.prototype, m.prototype, {
fire: function() {
this.__onChange && this.__onChange.call(this);
this.__onFinishChange && this.__onFinishChange.call(this, this.getValue());
this.getValue().call(this.object)
}
});
return f
}(dat.controllers.Controller, dat.dom.dom, dat.utils.common);
dat.controllers.BooleanController = function(m, a, d) {
var f = function(c, d) {
f.superclass.call(this, c, d);
var b = this;
this.__prev = this.getValue();
this.__checkbox = document.createElement("input");
this.__checkbox.setAttribute("type", "checkbox");
a.bind(this.__checkbox, "change", function() {
b.setValue(!b.__prev)
}, !1);
this.domElement.appendChild(this.__checkbox);
this.updateDisplay()
};
f.superclass = m;
d.extend(f.prototype, m.prototype, {
setValue: function(a) {
a = f.superclass.prototype.setValue.call(this, a);
this.__onFinishChange && this.__onFinishChange.call(this, this.getValue());
this.__prev = this.getValue();
return a
},
updateDisplay: function() {
!0 === this.getValue() ? (this.__checkbox.setAttribute("checked", "checked"),
this.__checkbox.checked = !0) : this.__checkbox.checked = !1;
return f.superclass.prototype.updateDisplay.call(this)
}
});
return f
}(dat.controllers.Controller, dat.dom.dom, dat.utils.common);
dat.color.toString = function(m) {
return function(a) {
if (1 == a.a || m.isUndefined(a.a)) {
for (a = a.hex.toString(16); 6 > a.length; )
a = "0" + a;
return "#" + a
}
return "rgba(" + Math.round(a.r) + "," + Math.round(a.g) + "," + Math.round(a.b) + "," + a.a + ")"
}
}(dat.utils.common);
dat.color.interpret = function(m, a) {
var d, f, c = [{
litmus: a.isString,
conversions: {
THREE_CHAR_HEX: {
read: function(a) {
a = a.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);
return null === a ? !1 : {
space: "HEX",
hex: parseInt("0x" + a[1].toString() + a[1].toString() + a[2].toString() + a[2].toString() + a[3].toString() + a[3].toString())
}
},
write: m
},
SIX_CHAR_HEX: {
read: function(a) {
a = a.match(/^#([A-F0-9]{6})$/i);
return null === a ? !1 : {
space: "HEX",
hex: parseInt("0x" + a[1].toString())
}
},
write: m
},
CSS_RGB: {
read: function(a) {
a = a.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);
return null === a ? !1 : {
space: "RGB",
r: parseFloat(a[1]),
g: parseFloat(a[2]),
b: parseFloat(a[3])
}
},
write: m
},
CSS_RGBA: {
read: function(a) {
a = a.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);
return null === a ? !1 : {
space: "RGB",
r: parseFloat(a[1]),
g: parseFloat(a[2]),
b: parseFloat(a[3]),
a: parseFloat(a[4])
}
},
write: m
}
}
}, {
litmus: a.isNumber,
conversions: {
HEX: {
read: function(a) {
return {
space: "HEX",
hex: a,
conversionName: "HEX"
}
},
write: function(a) {
return a.hex
}
}
}
}, {
litmus: a.isArray,
conversions: {
RGB_ARRAY: {
read: function(a) {
return 3 != a.length ? !1 : {
space: "RGB",
r: a[0],
g: a[1],
b: a[2]
}
},
write: function(a) {
return [a.r, a.g, a.b]
}
},
RGBA_ARRAY: {
read: function(a) {
return 4 != a.length ? !1 : {
space: "RGB",
r: a[0],
g: a[1],
b: a[2],
a: a[3]
}
},
write: function(a) {
return [a.r, a.g, a.b, a.a]
}
}
}
}, {
litmus: a.isObject,
conversions: {
RGBA_OBJ: {
read: function(c) {
return a.isNumber(c.r) && a.isNumber(c.g) && a.isNumber(c.b) && a.isNumber(c.a) ? {
space: "RGB",
r: c.r,
g: c.g,
b: c.b,
a: c.a
} : !1
},
write: function(a) {
return {
r: a.r,
g: a.g,
b: a.b,
a: a.a
}
}
},
RGB_OBJ: {
read: function(c) {
return a.isNumber(c.r) && a.isNumber(c.g) && a.isNumber(c.b) ? {
space: "RGB",
r: c.r,
g: c.g,
b: c.b
} : !1
},
write: function(a) {
return {
r: a.r,
g: a.g,
b: a.b
}
}
},
HSVA_OBJ: {
read: function(c) {
return a.isNumber(c.h) && a.isNumber(c.s) && a.isNumber(c.v) && a.isNumber(c.a) ? {
space: "HSV",
h: c.h,
s: c.s,
v: c.v,
a: c.a
} : !1
},
write: function(a) {
return {
h: a.h,
s: a.s,
v: a.v,
a: a.a
}
}
},
HSV_OBJ: {
read: function(c) {
return a.isNumber(c.h) && a.isNumber(c.s) && a.isNumber(c.v) ? {
space: "HSV",
h: c.h,
s: c.s,
v: c.v
} : !1
},
write: function(a) {
return {
h: a.h,
s: a.s,
v: a.v
}
}
}
}
}];
return function() {
f = !1;
var e = 1 < arguments.length ? a.toArray(arguments) : arguments[0];
a.each(c, function(b) {
if (b.litmus(e))
return a.each(b.conversions, function(b, c) {
d = b.read(e);
if (!1 === f && !1 !== d)
return f = d,
d.conversionName = c,
d.conversion = b,
a.BREAK
}),
a.BREAK
});
return f
}
}(dat.color.toString, dat.utils.common);
dat.GUI = dat.gui.GUI = function(m, a, d, f, c, e, b, g, k, h, n, l, q, p, r) {
function u(a, b, d, e) {
if (void 0 === b[d])
throw Error("Object " + b + ' has no property "' + d + '"');
e.color ? b = new n(b,d) : (b = [b, d].concat(e.factoryArgs),
b = f.apply(a, b));
e.before instanceof c && (e.before = e.before.__li);
t(a, b);
p.addClass(b.domElement, "c");
d = document.createElement("span");
p.addClass(d, "property-name");
d.innerHTML = b.property;
var g = document.createElement("div");
g.appendChild(d);
g.appendChild(b.domElement);
e = w(a, g, e.before);
p.addClass(e, J.CLASS_CONTROLLER_ROW);
p.addClass(e, typeof b.getValue());
x(a, e, b);
a.__controllers.push(b);
return b
}
function w(a, b, c) {
var d = document.createElement("li");
b && d.appendChild(b);
c ? a.__ul.insertBefore(d, params.before) : a.__ul.appendChild(d);
a.onResize();
return d
}
function x(a, c, d) {
d.__li = c;
d.__gui = a;
r.extend(d, {
options: function(b) {
if (1 < arguments.length)
return d.remove(),
u(a, d.object, d.property, {
before: d.__li.nextElementSibling,
factoryArgs: [r.toArray(arguments)]
});
if (r.isArray(b) || r.isObject(b))
return d.remove(),
u(a, d.object, d.property, {
before: d.__li.nextElementSibling,
factoryArgs: [b]
})
},
name: function(a) {
d.__li.firstElementChild.firstElementChild.innerHTML = a;
return d
},
listen: function() {
d.__gui.listen(d);
return d
},
remove: function() {
d.__gui.remove(d);
return d
}
});
if (d instanceof k) {
var f = new g(d.object,d.property,{
min: d.__min,
max: d.__max,
step: d.__step
});
r.each(["updateDisplay", "onChange", "onFinishChange"], function(a) {
var b = d[a]
, c = f[a];
d[a] = f[a] = function() {
var a = Array.prototype.slice.call(arguments);
b.apply(d, a);
return c.apply(f, a)
}
});
p.addClass(c, "has-slider");
d.domElement.insertBefore(f.domElement, d.domElement.firstElementChild)
} else if (d instanceof g) {
var h = function(b) {
return r.isNumber(d.__min) && r.isNumber(d.__max) ? (d.remove(),
u(a, d.object, d.property, {
before: d.__li.nextElementSibling,
factoryArgs: [d.__min, d.__max, d.__step]
})) : b
};
d.min = r.compose(h, d.min);
d.max = r.compose(h, d.max)
} else
d instanceof e ? (p.bind(c, "click", function() {
p.fakeEvent(d.__checkbox, "click")
}),
p.bind(d.__checkbox, "click", function(a) {
a.stopPropagation()
})) : d instanceof b ? (p.bind(c, "click", function() {
p.fakeEvent(d.__button, "click")
}),
p.bind(c, "mouseover", function() {
p.addClass(d.__button, "hover")
}),
p.bind(c, "mouseout", function() {
p.removeClass(d.__button, "hover")
})) : d instanceof n && (p.addClass(c, "color"),
d.updateDisplay = r.compose(function(a) {
c.style.borderLeftColor = d.__color.toString();
return a
}, d.updateDisplay),
d.updateDisplay());
d.setValue = r.compose(function(b) {
a.getRoot().__preset_select && d.isModified() && E(a.getRoot(), !0);
return b
}, d.setValue)
}
function t(a, b) {
var c = a.getRoot()
, d = c.__rememberedObjects.indexOf(b.object);
if (-1 != d) {
var e = c.__rememberedObjectIndecesToControllers[d];
void 0 === e && (e = {},
c.__rememberedObjectIndecesToControllers[d] = e);
e[b.property] = b;
if (c.load && c.load.remembered) {
c = c.load.remembered;
if (c[a.preset])
c = c[a.preset];
else if (c.Default)
c = c.Default;
else
return;
c[d] && void 0 !== c[d][b.property] && (d = c[d][b.property],
b.initialValue = d,
b.setValue(d))
}
}
}
function v(a) {
var b = a.__save_row = document.createElement("li");
p.addClass(a.domElement, "has-save");
a.__ul.insertBefore(b, a.__ul.firstChild);
p.addClass(b, "save-row");
var c = document.createElement("span");
c.innerHTML = " ";
p.addClass(c, "button gears");
var d = document.createElement("span");
d.innerHTML = "Save";
p.addClass(d, "button");
p.addClass(d, "save");
var e = document.createElement("span");
e.innerHTML = "New";
p.addClass(e, "button");
p.addClass(e, "save-as");
var f = document.createElement("span");
f.innerHTML = "Revert";
p.addClass(f, "button");
p.addClass(f, "revert");
var g = a.__preset_select = document.createElement("select");
a.load && a.load.remembered ? r.each(a.load.remembered, function(b, c) {
D(a, c, c == a.preset)
}) : D(a, "Default", !1);
p.bind(g, "change", function() {
for (var b = 0; b < a.__preset_select.length; b++)
a.__preset_select[b].innerHTML = a.__preset_select[b].value;
a.preset = this.value
});
b.appendChild(g);
b.appendChild(c);
b.appendChild(d);
b.appendChild(e);
b.appendChild(f);
if (H) {
var h = function() {
l.style.display = a.useLocalStorage ? "block" : "none"
};
b = document.getElementById("dg-save-locally");
var l = document.getElementById("dg-local-explain");
b.style.display = "block";
b = document.getElementById("dg-local-storage");
"true" === localStorage.getItem(document.location.href + ".isLocal") && b.setAttribute("checked", "checked");
h();
p.bind(b, "change", function() {
a.useLocalStorage = !a.useLocalStorage;
h()
})
}
var k = document.getElementById("dg-new-constructor");
p.bind(k, "keydown", function(a) {
!a.metaKey || 67 !== a.which && 67 != a.keyCode || K.hide()
});
p.bind(c, "click", function() {
k.innerHTML = JSON.stringify(a.getSaveObject(), void 0, 2);
K.show();
k.focus();
k.select()
});
p.bind(d, "click", function() {
a.save()
});
p.bind(e, "click", function() {
var b = prompt("Enter a new preset name.");
b && a.saveAs(b)
});
p.bind(f, "click", function() {
a.revert()
})
}
function A(a) {
function b(b) {
b.preventDefault();
e = b.clientX;
p.addClass(a.__closeButton, J.CLASS_DRAG);
p.bind(window, "mousemove", c);
p.bind(window, "mouseup", d);
return !1
}
function c(b) {
b.preventDefault();
a.width += e - b.clientX;
a.onResize();
e = b.clientX;
return !1
}
function d() {
p.removeClass(a.__closeButton, J.CLASS_DRAG);
p.unbind(window, "mousemove", c);
p.unbind(window, "mouseup", d)
}
a.__resize_handle = document.createElement("div");
r.extend(a.__resize_handle.style, {
width: "6px",
marginLeft: "-3px",
height: "200px",
cursor: "ew-resize",
position: "absolute"
});
var e;
p.bind(a.__resize_handle, "mousedown", b);
p.bind(a.__closeButton, "mousedown", b);
a.domElement.insertBefore(a.__resize_handle, a.domElement.firstElementChild)
}
function C(a, b) {
a.domElement.style.width = b + "px";
a.__save_row && a.autoPlace && (a.__save_row.style.width = b + "px");
a.__closeButton && (a.__closeButton.style.width = b + "px")
}
function B(a, b) {
var c = {};
r.each(a.__rememberedObjects, function(d, e) {
var f = {};
r.each(a.__rememberedObjectIndecesToControllers[e], function(a, c) {
f[c] = b ? a.initialValue : a.getValue()
});
c[e] = f
});
return c
}
function D(a, b, c) {
var d = document.createElement("option");
d.innerHTML = b;
d.value = b;
a.__preset_select.appendChild(d);
c && (a.__preset_select.selectedIndex = a.__preset_select.length - 1)
}
function E(a, b) {
var c = a.__preset_select[a.__preset_select.selectedIndex];
c.innerHTML = b ? c.value + "*" : c.value
}
function F(a) {
0 != a.length && l(function() {
F(a)
});
r.each(a, function(a) {
a.updateDisplay()
})
}
m.inject(d);
try {
var H = "localStorage"in window && null !== window.localStorage
} catch (z) {
H = !1
}
var K, I = !0, N, y = !1, M = [], J = function(a) {
function b() {
localStorage.setItem(document.location.href + ".gui", JSON.stringify(d.getSaveObject()))
}
function c() {
var a = d.getRoot();
a.width += 1;
r.defer(function() {
--a.width
})
}
var d = this;
this.domElement = document.createElement("div");
this.__ul = document.createElement("ul");
this.domElement.appendChild(this.__ul);
p.addClass(this.domElement, "dg");
this.__folders = {};
this.__controllers = [];
this.__rememberedObjects = [];
this.__rememberedObjectIndecesToControllers = [];
this.__listening = [];
a = a || {};
a = r.defaults(a, {
autoPlace: !0,
width: J.DEFAULT_WIDTH
});
a = r.defaults(a, {
resizable: a.autoPlace,
hideable: a.autoPlace
});
r.isUndefined(a.load) ? a.load = {
preset: "Default"
} : a.preset && (a.load.preset = a.preset);
r.isUndefined(a.parent) && a.hideable && M.push(this);
a.resizable = r.isUndefined(a.parent) && a.resizable;
a.autoPlace && r.isUndefined(a.scrollable) && (a.scrollable = !0);
var e = H && "true" === localStorage.getItem(document.location.href + ".isLocal");
Object.defineProperties(this, {
parent: {
get: function() {
return a.parent
}
},
scrollable: {
get: function() {
return a.scrollable
}
},
autoPlace: {
get: function() {
return a.autoPlace
}
},
preset: {
get: function() {
return d.parent ? d.getRoot().preset : a.load.preset
},
set: function(b) {
d.parent ? d.getRoot().preset = b : a.load.preset = b;
for (b = 0; b < this.__preset_select.length; b++)
this.__preset_select[b].value == this.preset && (this.__preset_select.selectedIndex = b);
d.revert()
}
},
width: {
get: function() {
return a.width
},
set: function(b) {
a.width = b;
C(d, b)
}
},
name: {
get: function() {
return a.name
},
set: function(b) {
a.name = b;
g && (g.innerHTML = a.name)
}
},
closed: {
get: function() {
return a.closed
},
set: function(b) {
a.closed = b;
a.closed ? p.addClass(d.__ul, J.CLASS_CLOSED) : p.removeClass(d.__ul, J.CLASS_CLOSED);
this.onResize();
d.__closeButton && (d.__closeButton.innerHTML = b ? J.TEXT_OPEN : J.TEXT_CLOSED)
}
},
load: {
get: function() {
return a.load
}
},
useLocalStorage: {
get: function() {
return e
},
set: function(a) {
H && ((e = a) ? p.bind(window, "unload", b) : p.unbind(window, "unload", b),
localStorage.setItem(document.location.href + ".isLocal", a))
}
}
});
if (r.isUndefined(a.parent)) {
a.closed = !1;
p.addClass(this.domElement, J.CLASS_MAIN);
p.makeSelectable(this.domElement, !1);
if (H && e) {
d.useLocalStorage = !0;
var f = localStorage.getItem(document.location.href + ".gui");
f && (a.load = JSON.parse(f))
}
this.__closeButton = document.createElement("div");
this.__closeButton.innerHTML = J.TEXT_CLOSED;
p.addClass(this.__closeButton, J.CLASS_CLOSE_BUTTON);
this.domElement.appendChild(this.__closeButton);
p.bind(this.__closeButton, "click", function() {
d.closed = !d.closed
})
} else {
void 0 === a.closed && (a.closed = !0);
var g = document.createTextNode(a.name);
p.addClass(g, "controller-name");
f = w(d, g);
p.addClass(this.__ul, J.CLASS_CLOSED);
p.addClass(f, "title");
p.bind(f, "click", function(a) {
a.preventDefault();
d.closed = !d.closed;
return !1
});
a.closed || (this.closed = !1)
}
a.autoPlace && (r.isUndefined(a.parent) && (I && (N = document.createElement("div"),
p.addClass(N, "dg"),
p.addClass(N, J.CLASS_AUTO_PLACE_CONTAINER),
document.body.appendChild(N),
I = !1),
N.appendChild(this.domElement),
p.addClass(this.domElement, J.CLASS_AUTO_PLACE)),
this.parent || C(d, a.width));
p.bind(window, "resize", function() {
d.onResize()
});
p.bind(this.__ul, "webkitTransitionEnd", function() {
d.onResize()
});
p.bind(this.__ul, "transitionend", function() {
d.onResize()
});
p.bind(this.__ul, "oTransitionEnd", function() {
d.onResize()
});
this.onResize();
a.resizable && A(this);
d.getRoot();
a.parent || c()
};
J.toggleHide = function() {
y = !y;
r.each(M, function(a) {
a.domElement.style.zIndex = y ? -999 : 999;
a.domElement.style.opacity = y ? 0 : 1
})
}
;
J.CLASS_AUTO_PLACE = "a";
J.CLASS_AUTO_PLACE_CONTAINER = "ac";
J.CLASS_MAIN = "main";
J.CLASS_CONTROLLER_ROW = "cr";
J.CLASS_TOO_TALL = "taller-than-window";
J.CLASS_CLOSED = "closed";
J.CLASS_CLOSE_BUTTON = "close-button";
J.CLASS_DRAG = "drag";
J.DEFAULT_WIDTH = 245;
J.TEXT_CLOSED = "Close Controls";
J.TEXT_OPEN = "Open Controls";
p.bind(window, "keydown", function(a) {
"text" === document.activeElement.type || 72 !== a.which && 72 != a.keyCode || J.toggleHide()
}, !1);
r.extend(J.prototype, {
add: function(a, b) {
return u(this, a, b, {
factoryArgs: Array.prototype.slice.call(arguments, 2)
})
},
addColor: function(a, b) {
return u(this, a, b, {
color: !0
})
},
remove: function(a) {
this.__ul.removeChild(a.__li);
this.__controllers.slice(this.__controllers.indexOf(a), 1);
var b = this;
r.defer(function() {
b.onResize()
})
},
destroy: function() {
this.autoPlace && N.removeChild(this.domElement)
},
addFolder: function(a) {
if (void 0 !== this.__folders[a])
throw Error('You already have a folder in this GUI by the name "' + a + '"');
var b = {
name: a,
parent: this
};
b.autoPlace = this.autoPlace;
this.load && this.load.folders && this.load.folders[a] && (b.closed = this.load.folders[a].closed,
b.load = this.load.folders[a]);
b = new J(b);
this.__folders[a] = b;
a = w(this, b.domElement);
p.addClass(a, "folder");
return b
},
open: function() {
this.closed = !1
},
close: function() {
this.closed = !0
},
onResize: function() {
var a = this.getRoot();
if (a.scrollable) {
var b = p.getOffset(a.__ul).top
, c = 0;
r.each(a.__ul.childNodes, function(b) {
a.autoPlace && b === a.__save_row || (c += p.getHeight(b))
});
window.innerHeight - b - 20 < c ? (p.addClass(a.domElement, J.CLASS_TOO_TALL),
a.__ul.style.height = window.innerHeight - b - 20 + "px") : (p.removeClass(a.domElement, J.CLASS_TOO_TALL),
a.__ul.style.height = "auto")
}
a.__resize_handle && r.defer(function() {
a.__resize_handle.style.height = a.__ul.offsetHeight + "px"
});
a.__closeButton && (a.__closeButton.style.width = a.width + "px")
},
remember: function() {
r.isUndefined(K) && (K = new q,
K.domElement.innerHTML = a);
if (this.parent)
throw Error("You can only call remember on a top level GUI.");
var b = this;
r.each(Array.prototype.slice.call(arguments), function(a) {
0 == b.__rememberedObjects.length && v(b);
-1 == b.__rememberedObjects.indexOf(a) && b.__rememberedObjects.push(a)
});
this.autoPlace && C(this, this.width)
},
getRoot: function() {
for (var a = this; a.parent; )
a = a.parent;
return a
},
getSaveObject: function() {
var a = this.load;
a.closed = this.closed;
0 < this.__rememberedObjects.length && (a.preset = this.preset,
a.remembered || (a.remembered = {}),
a.remembered[this.preset] = B(this));
a.folders = {};
r.each(this.__folders, function(b, c) {
a.folders[c] = b.getSaveObject()
});
return a
},
save: function() {
this.load.remembered || (this.load.remembered = {});
this.load.remembered[this.preset] = B(this);
E(this, !1)
},
saveAs: function(a) {
this.load.remembered || (this.load.remembered = {},
this.load.remembered.Default = B(this, !0));
this.load.remembered[a] = B(this);
this.preset = a;
D(this, a, !0)
},
revert: function(a) {
r.each(this.__controllers, function(b) {
this.getRoot().load.remembered ? t(a || this.getRoot(), b) : b.setValue(b.initialValue)
}, this);
r.each(this.__folders, function(a) {
a.revert(a)
});
a || E(this.getRoot(), !1)
},
listen: function(a) {
var b = 0 == this.__listening.length;
this.__listening.push(a);
b && F(this.__listening)
}
});
return J
}(dat.utils.css, '
\n\n Here\'s the new load parameter for your GUI\'s constructor:\n\n \n\n
\n\n Automatically save\n values to localStorage on exit.\n\n
The values saved to localStorage will\n override those passed to dat.GUI\'s constructor. This makes it\n easier to work incrementally, but localStorage is fragile,\n and your friends may not see the same values you do.\n \n
\n \n
\n\n
', ".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity 0.1s linear;-o-transition:opacity 0.1s linear;-moz-transition:opacity 0.1s linear;transition:opacity 0.1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity 0.1s linear;-o-transition:opacity 0.1s linear;-moz-transition:opacity 0.1s linear;transition:opacity 0.1s linear;border:0;position:absolute;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-x:hidden}.dg.a.has-save ul{margin-top:27px}.dg.a.has-save ul.closed{margin-top:0}.dg.a .save-row{position:fixed;top:0;z-index:1002}.dg li{-webkit-transition:height 0.1s ease-out;-o-transition:height 0.1s ease-out;-moz-transition:height 0.1s ease-out;transition:height 0.1s ease-out}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;overflow:hidden;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li > *{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:9px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2fa1d6}.dg .cr.number input[type=text]{color:#2fa1d6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2fa1d6}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n", dat.controllers.factory = function(m, a, d, f, c, e, b) {
return function(g, k, h, n) {
var l = g[k];
if (b.isArray(h) || b.isObject(h))
return new m(g,k,h);
if (b.isNumber(l))
return b.isNumber(h) && b.isNumber(n) ? new d(g,k,h,n) : new a(g,k,{
min: h,
max: n
});
if (b.isString(l))
return new f(g,k);
if (b.isFunction(l))
return new c(g,k,"");
if (b.isBoolean(l))
return new e(g,k)
}
}(dat.controllers.OptionController, dat.controllers.NumberControllerBox, dat.controllers.NumberControllerSlider, dat.controllers.StringController = function(m, a, d) {
var f = function(c, d) {
function b() {
e.setValue(e.__input.value)
}
f.superclass.call(this, c, d);
var e = this;
this.__input = document.createElement("input");
this.__input.setAttribute("type", "text");
a.bind(this.__input, "keyup", b);
a.bind(this.__input, "change", b);
a.bind(this.__input, "blur", function() {
e.__onFinishChange && e.__onFinishChange.call(e, e.getValue())
});
a.bind(this.__input, "keydown", function(a) {
13 === a.keyCode && this.blur()
});
this.updateDisplay();
this.domElement.appendChild(this.__input)
};
f.superclass = m;
d.extend(f.prototype, m.prototype, {
updateDisplay: function() {
a.isActive(this.__input) || (this.__input.value = this.getValue());
return f.superclass.prototype.updateDisplay.call(this)
}
});
return f
}(dat.controllers.Controller, dat.dom.dom, dat.utils.common), dat.controllers.FunctionController, dat.controllers.BooleanController, dat.utils.common), dat.controllers.Controller, dat.controllers.BooleanController, dat.controllers.FunctionController, dat.controllers.NumberControllerBox, dat.controllers.NumberControllerSlider, dat.controllers.OptionController, dat.controllers.ColorController = function(m, a, d, f, c) {
function e(a, b, d, e) {
a.style.background = "";
c.each(k, function(c) {
a.style.cssText += "background: " + c + "linear-gradient(" + b + ", " + d + " 0%, " + e + " 100%); "
})
}
function b(a) {
a.style.background = "";
a.style.cssText += "background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);";
a.style.cssText += "background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";
a.style.cssText += "background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";
a.style.cssText += "background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";
a.style.cssText += "background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);"
}
var g = function(h, k) {
function l(b) {
u(b);
a.bind(window, "mousemove", u);
a.bind(window, "mouseup", m)
}
function m() {
a.unbind(window, "mousemove", u);
a.unbind(window, "mouseup", m)
}
function n() {
var a = f(this.value);
!1 !== a ? (x.__color.__state = a,
x.setValue(x.__color.toOriginal())) : this.value = x.__color.toString()
}
function r() {
a.unbind(window, "mousemove", w);
a.unbind(window, "mouseup", r)
}
function u(b) {
b.preventDefault();
var c = a.getWidth(x.__saturation_field)
, d = a.getOffset(x.__saturation_field)
, e = (b.clientX - d.left + document.body.scrollLeft) / c;
b = 1 - (b.clientY - d.top + document.body.scrollTop) / c;
1 < b ? b = 1 : 0 > b && (b = 0);
1 < e ? e = 1 : 0 > e && (e = 0);
x.__color.v = b;
x.__color.s = e;
x.setValue(x.__color.toOriginal());
return !1
}
function w(b) {
b.preventDefault();
var c = a.getHeight(x.__hue_field)
, d = a.getOffset(x.__hue_field);
b = 1 - (b.clientY - d.top + document.body.scrollTop) / c;
1 < b ? b = 1 : 0 > b && (b = 0);
x.__color.h = 360 * b;
x.setValue(x.__color.toOriginal());
return !1
}
g.superclass.call(this, h, k);
this.__color = new d(this.getValue());
this.__temp = new d(0);
var x = this;
this.domElement = document.createElement("div");
a.makeSelectable(this.domElement, !1);
this.__selector = document.createElement("div");
this.__selector.className = "selector";
this.__saturation_field = document.createElement("div");
this.__saturation_field.className = "saturation-field";
this.__field_knob = document.createElement("div");
this.__field_knob.className = "field-knob";
this.__field_knob_border = "2px solid ";
this.__hue_knob = document.createElement("div");
this.__hue_knob.className = "hue-knob";
this.__hue_field = document.createElement("div");
this.__hue_field.className = "hue-field";
this.__input = document.createElement("input");
this.__input.type = "text";
this.__input_textShadow = "0 1px 1px ";
a.bind(this.__input, "keydown", function(a) {
13 === a.keyCode && n.call(this)
});
a.bind(this.__input, "blur", n);
a.bind(this.__selector, "mousedown", function(b) {
a.addClass(this, "drag").bind(window, "mouseup", function(b) {
a.removeClass(x.__selector, "drag")
})
});
var t = document.createElement("div");
c.extend(this.__selector.style, {
width: "122px",
height: "102px",
padding: "3px",
backgroundColor: "#222",
boxShadow: "0px 1px 3px rgba(0,0,0,0.3)"
});
c.extend(this.__field_knob.style, {
position: "absolute",
width: "12px",
height: "12px",
border: this.__field_knob_border + (.5 > this.__color.v ? "#fff" : "#000"),
boxShadow: "0px 1px 3px rgba(0,0,0,0.5)",
borderRadius: "12px",
zIndex: 1
});
c.extend(this.__hue_knob.style, {
position: "absolute",
width: "15px",
height: "2px",
borderRight: "4px solid #fff",
zIndex: 1
});
c.extend(this.__saturation_field.style, {
width: "100px",
height: "100px",
border: "1px solid #555",
marginRight: "3px",
display: "inline-block",
cursor: "pointer"
});
c.extend(t.style, {
width: "100%",
height: "100%",
background: "none"
});
e(t, "top", "rgba(0,0,0,0)", "#000");
c.extend(this.__hue_field.style, {
width: "15px",
height: "100px",
display: "inline-block",
border: "1px solid #555",
cursor: "ns-resize"
});
b(this.__hue_field);
c.extend(this.__input.style, {
outline: "none",
textAlign: "center",
color: "#fff",
border: 0,
fontWeight: "bold",
textShadow: this.__input_textShadow + "rgba(0,0,0,0.7)"
});
a.bind(this.__saturation_field, "mousedown", l);
a.bind(this.__field_knob, "mousedown", l);
a.bind(this.__hue_field, "mousedown", function(b) {
w(b);
a.bind(window, "mousemove", w);
a.bind(window, "mouseup", r)
});
this.__saturation_field.appendChild(t);
this.__selector.appendChild(this.__field_knob);
this.__selector.appendChild(this.__saturation_field);
this.__selector.appendChild(this.__hue_field);
this.__hue_field.appendChild(this.__hue_knob);
this.domElement.appendChild(this.__input);
this.domElement.appendChild(this.__selector);
this.updateDisplay()
};
g.superclass = m;
c.extend(g.prototype, m.prototype, {
updateDisplay: function() {
var a = f(this.getValue());
if (!1 !== a) {
var b = !1;
c.each(d.COMPONENTS, function(d) {
if (!c.isUndefined(a[d]) && !c.isUndefined(this.__color.__state[d]) && a[d] !== this.__color.__state[d])
return b = !0,
{}
}, this);
b && c.extend(this.__color.__state, a)
}
c.extend(this.__temp.__state, this.__color.__state);
this.__temp.a = 1;
var g = .5 > this.__color.v || .5 < this.__color.s ? 255 : 0
, k = 255 - g;
c.extend(this.__field_knob.style, {
marginLeft: 100 * this.__color.s - 7 + "px",
marginTop: 100 * (1 - this.__color.v) - 7 + "px",
backgroundColor: this.__temp.toString(),
border: this.__field_knob_border + "rgb(" + g + "," + g + "," + g + ")"
});
this.__hue_knob.style.marginTop = 100 * (1 - this.__color.h / 360) + "px";
this.__temp.s = 1;
this.__temp.v = 1;
e(this.__saturation_field, "left", "#fff", this.__temp.toString());
c.extend(this.__input.style, {
backgroundColor: this.__input.value = this.__color.toString(),
color: "rgb(" + g + "," + g + "," + g + ")",
textShadow: this.__input_textShadow + "rgba(" + k + "," + k + "," + k + ",.7)"
})
}
});
var k = ["-moz-", "-o-", "-webkit-", "-ms-", ""];
return g
}(dat.controllers.Controller, dat.dom.dom, dat.color.Color = function(m, a, d, f) {
function c(a, c, d) {
Object.defineProperty(a, c, {
get: function() {
if ("RGB" === this.__state.space)
return this.__state[c];
b(this, c, d);
return this.__state[c]
},
set: function(a) {
"RGB" !== this.__state.space && (b(this, c, d),
this.__state.space = "RGB");
this.__state[c] = a
}
})
}
function e(a, b) {
Object.defineProperty(a, b, {
get: function() {
if ("HSV" === this.__state.space)
return this.__state[b];
g(this);
return this.__state[b]
},
set: function(a) {
"HSV" !== this.__state.space && (g(this),
this.__state.space = "HSV");
this.__state[b] = a
}
})
}
function b(b, c, d) {
if ("HEX" === b.__state.space)
b.__state[c] = a.component_from_hex(b.__state.hex, d);
else if ("HSV" === b.__state.space)
f.extend(b.__state, a.hsv_to_rgb(b.__state.h, b.__state.s, b.__state.v));
else
throw "Corrupted color state";
}
function g(b) {
var c = a.rgb_to_hsv(b.r, b.g, b.b);
f.extend(b.__state, {
s: c.s,
v: c.v
});
f.isNaN(c.h) ? f.isUndefined(b.__state.h) && (b.__state.h = 0) : b.__state.h = c.h
}
var k = function() {
this.__state = m.apply(this, arguments);
if (!1 === this.__state)
throw "Failed to interpret color arguments";
this.__state.a = this.__state.a || 1
};
k.COMPONENTS = "r g b h s v hex a".split(" ");
f.extend(k.prototype, {
toString: function() {
return d(this)
},
toOriginal: function() {
return this.__state.conversion.write(this)
}
});
c(k.prototype, "r", 2);
c(k.prototype, "g", 1);
c(k.prototype, "b", 0);
e(k.prototype, "h");
e(k.prototype, "s");
e(k.prototype, "v");
Object.defineProperty(k.prototype, "a", {
get: function() {
return this.__state.a
},
set: function(a) {
this.__state.a = a
}
});
Object.defineProperty(k.prototype, "hex", {
get: function() {
this.__state.hex = a.rgb_to_hex(this.r, this.g, this.b);
return this.__state.hex
},
set: function(a) {
this.__state.space = "HEX";
this.__state.hex = a
}
});
return k
}(dat.color.interpret, dat.color.math = function() {
var m;
return {
hsv_to_rgb: function(a, d, f) {
var c = a / 60 - Math.floor(a / 60)
, e = f * (1 - d)
, b = f * (1 - c * d);
d = f * (1 - (1 - c) * d);
a = [[f, d, e], [b, f, e], [e, f, d], [e, b, f], [d, e, f], [f, e, b]][Math.floor(a / 60) % 6];
return {
r: 255 * a[0],
g: 255 * a[1],
b: 255 * a[2]
}
},
rgb_to_hsv: function(a, d, f) {
var c = Math.max(a, d, f)
, e = c - Math.min(a, d, f);
if (0 == c)
return {
h: NaN,
s: 0,
v: 0
};
a = (a == c ? (d - f) / e : d == c ? 2 + (f - a) / e : 4 + (a - d) / e) / 6;
0 > a && (a += 1);
return {
h: 360 * a,
s: e / c,
v: c / 255
}
},
rgb_to_hex: function(a, d, f) {
a = this.hex_with_component(0, 2, a);
a = this.hex_with_component(a, 1, d);
return a = this.hex_with_component(a, 0, f)
},
component_from_hex: function(a, d) {
return a >> 8 * d & 255
},
hex_with_component: function(a, d, f) {
return f << (m = 8 * d) | a & ~(255 << m)
}
}
}(), dat.color.toString, dat.utils.common), dat.color.interpret, dat.utils.common), dat.utils.requestAnimationFrame = function() {
return window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(m, a) {
window.setTimeout(m, 1E3 / 60)
}
}(), dat.dom.CenteredDiv = function(m, a) {
var d = function() {
this.backgroundElement = document.createElement("div");
a.extend(this.backgroundElement.style, {
backgroundColor: "rgba(0,0,0,0.8)",
top: 0,
left: 0,
display: "none",
zIndex: "1000",
opacity: 0,
WebkitTransition: "opacity 0.2s linear"
});
m.makeFullscreen(this.backgroundElement);
this.backgroundElement.style.position = "fixed";
this.domElement = document.createElement("div");
a.extend(this.domElement.style, {
position: "fixed",
display: "none",
zIndex: "1001",
opacity: 0,
WebkitTransition: "-webkit-transform 0.2s ease-out, opacity 0.2s linear"
});
document.body.appendChild(this.backgroundElement);
document.body.appendChild(this.domElement);
var d = this;
m.bind(this.backgroundElement, "click", function() {
d.hide()
})
};
d.prototype.show = function() {
var d = this;
this.backgroundElement.style.display = "block";
this.domElement.style.display = "block";
this.domElement.style.opacity = 0;
this.domElement.style.webkitTransform = "scale(1.1)";
this.layout();
a.defer(function() {
d.backgroundElement.style.opacity = 1;
d.domElement.style.opacity = 1;
d.domElement.style.webkitTransform = "scale(1)"
})
}
;
d.prototype.hide = function() {
var a = this
, c = function() {
a.domElement.style.display = "none";
a.backgroundElement.style.display = "none";
m.unbind(a.domElement, "webkitTransitionEnd", c);
m.unbind(a.domElement, "transitionend", c);
m.unbind(a.domElement, "oTransitionEnd", c)
};
m.bind(this.domElement, "webkitTransitionEnd", c);
m.bind(this.domElement, "transitionend", c);
m.bind(this.domElement, "oTransitionEnd", c);
this.backgroundElement.style.opacity = 0;
this.domElement.style.opacity = 0;
this.domElement.style.webkitTransform = "scale(1.1)"
}
;
d.prototype.layout = function() {
this.domElement.style.left = window.innerWidth / 2 - m.getWidth(this.domElement) / 2 + "px";
this.domElement.style.top = window.innerHeight / 2 - m.getHeight(this.domElement) / 2 + "px"
}
;
return d
}(dat.dom.dom, dat.utils.common), dat.dom.dom, dat.utils.common);
Detector = {
canvas: !!window.CanvasRenderingContext2D,
webgl: function() {
try {
return !!window.WebGLRenderingContext && !!document.createElement("canvas").getContext("experimental-webgl")
} catch (m) {
return !1
}
}(),
workers: !!window.Worker,
fileapi: window.File && window.FileReader && window.FileList && window.Blob,
getWebGLErrorMessage: function() {
var m = document.createElement("div");
m.id = "webgl-error-message";
m.style.fontFamily = "monospace";
m.style.fontSize = "13px";
m.style.fontWeight = "normal";
m.style.textAlign = "center";
m.style.background = "#fff";
m.style.color = "#000";
m.style.padding = "1.5em";
m.style.width = "400px";
m.style.margin = "5em auto 0";
this.webgl || (m.innerHTML = window.WebGLRenderingContext ? 'Your graphics card does not seem to support WebGL. \nFind out how to get it here.' : 'Your browser does not seem to support WebGL. \nFind out how to get it here.');
return m
},
addGetWebGLMessage: function(m) {
m = m || {};
var a = void 0 !== m.parent ? m.parent : document.body;
m = void 0 !== m.id ? m.id : "oldie";
var d = Detector.getWebGLErrorMessage();
d.id = m;
a.appendChild(d)
}
};
function TimeSeries(m) {
m = m || {};
m.resetBoundsInterval = m.resetBoundsInterval || 3E3;
m.resetBounds = void 0 === m.resetBounds ? !0 : m.resetBounds;
this.options = m;
this.data = [];
this.label = m.label || "";
this.maxDataLength = m.maxDataLength || 1E3;
this.dataPool = [];
this.minValue = this.maxValue = Number.NaN;
m.resetBounds && (this.boundsTimer = setInterval(function(a) {
return function() {
a.resetBounds()
}
}(this), m.resetBoundsInterval))
}
TimeSeries.prototype.resetBounds = function() {
this.minValue = this.maxValue = Number.NaN;
for (var m = 0; m < this.data.length; m++)
this.maxValue = isNaN(this.maxValue) ? this.data[m][1] : Math.max(this.maxValue, this.data[m][1]),
this.minValue = isNaN(this.minValue) ? this.data[m][1] : Math.min(this.minValue, this.data[m][1])
}
;
TimeSeries.prototype.append = function(m, a) {
this.lastTimeStamp = m;
var d = this.dataPool.length ? this.dataPool.pop() : [m, a];
d[0] = m;
d[1] = a;
this.data.push(d);
this.maxValue = isNaN(this.maxValue) ? a : Math.max(this.maxValue, a);
for (this.minValue = isNaN(this.minValue) ? a : Math.min(this.minValue, a); this.data.length > this.maxDataLength; )
this.dataPool.push(this.data.shift())
}
;
function SmoothieChart(m) {
m = m || {};
m.grid = m.grid || {
fillStyle: "#000000",
strokeStyle: "#777777",
lineWidth: 1,
millisPerLine: 1E3,
verticalSections: 2
};
m.millisPerPixel = m.millisPerPixel || 20;
m.fps = m.fps || 50;
m.maxValueScale = m.maxValueScale || 1;
m.minValue = m.minValue;
m.maxValue = m.maxValue;
m.labels = m.labels || {
fillStyle: "#ffffff"
};
m.interpolation = m.interpolation || "bezier";
m.scaleSmoothing = m.scaleSmoothing || .125;
m.maxDataSetLength = m.maxDataSetLength || 2;
m.timestampFormatter = m.timestampFormatter || null;
this.options = m;
this.seriesSet = [];
this.currentValueRange = 1;
this.currentVisMinValue = 0
}
SmoothieChart.prototype.addTimeSeries = function(m, a) {
this.seriesSet.push({
timeSeries: m,
options: a || {}
})
}
;
SmoothieChart.prototype.removeTimeSeries = function(m) {
this.seriesSet.splice(this.seriesSet.indexOf(m), 1)
}
;
SmoothieChart.prototype.streamTo = function(m, a) {
var d = this;
this.render_on_tick = function() {
d.render(m, d.seriesSet[0].timeSeries.lastTimeStamp)
}
;
this.start()
}
;
SmoothieChart.prototype.start = function() {
this.timer || (this.timer = setInterval(this.render_on_tick, 1E3 / this.options.fps))
}
;
SmoothieChart.prototype.stop = function() {
this.timer && (clearInterval(this.timer),
this.timer = void 0)
}
;
SmoothieChart.timeFormatter = function(m) {
function a(a) {
return (10 > a ? "0" : "") + a
}
return a(m.getHours()) + ":" + a(m.getMinutes()) + ":" + a(m.getSeconds())
}
;
SmoothieChart.prototype.render = function(m, a) {
var d = m.getContext("2d")
, f = this.options
, c = m.clientWidth
, e = m.clientHeight;
d.save();
a -= a % f.millisPerPixel;
d.translate(0, 0);
d.beginPath();
d.rect(0, 0, c, e);
d.clip();
d.save();
d.fillStyle = f.grid.fillStyle;
d.clearRect(0, 0, c, e);
d.fillRect(0, 0, c, e);
d.restore();
d.save();
d.lineWidth = f.grid.lineWidth || 1;
d.strokeStyle = f.grid.strokeStyle || "#ffffff";
if (0 < f.grid.millisPerLine)
for (var b = a - a % f.grid.millisPerLine; b >= a - c * f.millisPerPixel; b -= f.grid.millisPerLine) {
d.beginPath();
var g = Math.round(c - (a - b) / f.millisPerPixel);
d.moveTo(g, 0);
d.lineTo(g, e);
d.stroke();
if (f.timestampFormatter) {
var k = f.timestampFormatter(new Date(b))
, h = d.measureText(k).width / 2 + d.measureText(t).width + 4;
g < c - h && (d.fillStyle = f.labels.fillStyle,
d.fillText(k, g - d.measureText(k).width / 2, e - 2))
}
d.closePath()
}
for (t = 1; t < f.grid.verticalSections; t++)
b = Math.round(t * e / f.grid.verticalSections),
d.beginPath(),
d.moveTo(0, b),
d.lineTo(c, b),
d.stroke(),
d.closePath();
d.beginPath();
d.strokeRect(0, 0, c, e);
d.closePath();
d.restore();
t = g = Number.NaN;
for (k = 0; k < this.seriesSet.length; k++) {
var n = this.seriesSet[k].timeSeries;
isNaN(n.maxValue) || (g = isNaN(g) ? n.maxValue : Math.max(g, n.maxValue));
isNaN(n.minValue) || (t = isNaN(t) ? n.minValue : Math.min(t, n.minValue))
}
if (!isNaN(g) || !isNaN(t)) {
g = null != f.maxValue ? f.maxValue : g * f.maxValueScale;
null != f.minValue && (t = f.minValue);
this.currentValueRange += f.scaleSmoothing * (g - t - this.currentValueRange);
this.currentVisMinValue += f.scaleSmoothing * (t - this.currentVisMinValue);
h = this.currentValueRange;
var l = this.currentVisMinValue;
for (k = 0; k < this.seriesSet.length; k++) {
d.save();
n = this.seriesSet[k].timeSeries;
n = n.data;
for (var q = this.seriesSet[k].options; n.length >= f.maxDataSetLength && n[1][0] < a - c * f.millisPerPixel; )
n.splice(0, 1);
d.lineWidth = q.lineWidth || 1;
d.fillStyle = q.fillStyle;
d.strokeStyle = q.strokeStyle || "#ffffff";
d.beginPath();
var p = 0
, r = 0
, u = 0;
for (b = 0; b < n.length; b++) {
var w = Math.round(c - (a - n[b][0]) / f.millisPerPixel)
, x = n[b][1] - l;
x = Math.max(Math.min(e - (h ? Math.round(x / h * e) : 0), e - 1), 1);
if (0 == b)
p = w,
d.moveTo(w, x);
else
switch (f.interpolation) {
case "line":
d.lineTo(w, x);
break;
default:
d.bezierCurveTo(Math.round((r + w) / 2), u, Math.round(r + w) / 2, x, w, x)
}
r = w;
u = x
}
0 < n.length && q.fillStyle && (d.lineTo(c + q.lineWidth + 1, u),
d.lineTo(c + q.lineWidth + 1, e + q.lineWidth + 1),
d.lineTo(p, e + q.lineWidth),
d.fill());
d.stroke();
d.closePath();
d.restore()
}
if (!f.labels.disabled) {
f.labelOffsetY || (f.labelOffsetY = 0);
d.fillStyle = f.labels.fillStyle;
b = parseFloat(g).toFixed(2);
var t = parseFloat(t).toFixed(2);
d.fillText(b, c - d.measureText(b).width - 2, 10);
d.fillText(t, c - d.measureText(t).width - 2, e - 2);
for (b = 0; b < this.seriesSet.length; b++)
n = this.seriesSet[b].timeSeries,
c = n.label,
d.fillStyle = n.options.fillStyle || "rgb(255,255,255)",
c && d.fillText(c, 2, 10 * (b + 1) + f.labelOffsetY)
}
}
d.restore()
}
;
var Stats = function() {
var m = 0
, a = 0
, d = Date.now()
, f = d
, c = d
, e = 0
, b = 1E3
, g = 0
, k = [[16, 16, 48], [0, 255, 255]]
, h = 0
, n = 1E3
, l = 0
, q = [[16, 48, 16], [0, 255, 0]];
var p = document.createElement("div");
p.style.cursor = "pointer";
p.style.width = "80px";
p.style.opacity = "0.9";
p.style.zIndex = "10001";
p.addEventListener("mousedown", function(a) {
a.preventDefault();
m = (m + 1) % 2;
0 == m ? (r.style.display = "block",
t.style.display = "none") : (r.style.display = "none",
t.style.display = "block")
}, !1);
var r = document.createElement("div");
r.style.textAlign = "left";
r.style.lineHeight = "1.2em";
r.style.backgroundColor = "rgb(" + Math.floor(k[0][0] / 2) + "," + Math.floor(k[0][1] / 2) + "," + Math.floor(k[0][2] / 2) + ")";
r.style.padding = "0 0 3px 3px";
p.appendChild(r);
var u = document.createElement("div");
u.style.fontFamily = "Helvetica, Arial, sans-serif";
u.style.fontSize = "9px";
u.style.color = "rgb(" + k[1][0] + "," + k[1][1] + "," + k[1][2] + ")";
u.style.fontWeight = "bold";
u.innerHTML = "FPS";
r.appendChild(u);
var w = document.createElement("div");
w.style.position = "relative";
w.style.width = "74px";
w.style.height = "30px";
w.style.backgroundColor = "rgb(" + k[1][0] + "," + k[1][1] + "," + k[1][2] + ")";
for (r.appendChild(w); 74 > w.children.length; ) {
var x = document.createElement("span");
x.style.width = "1px";
x.style.height = "30px";
x.style.cssFloat = "left";
x.style.backgroundColor = "rgb(" + k[0][0] + "," + k[0][1] + "," + k[0][2] + ")";
w.appendChild(x)
}
var t = document.createElement("div");
t.style.textAlign = "left";
t.style.lineHeight = "1.2em";
t.style.backgroundColor = "rgb(" + Math.floor(q[0][0] / 2) + "," + Math.floor(q[0][1] / 2) + "," + Math.floor(q[0][2] / 2) + ")";
t.style.padding = "0 0 3px 3px";
t.style.display = "none";
p.appendChild(t);
var v = document.createElement("div");
v.style.fontFamily = "Helvetica, Arial, sans-serif";
v.style.fontSize = "9px";
v.style.color = "rgb(" + q[1][0] + "," + q[1][1] + "," + q[1][2] + ")";
v.style.fontWeight = "bold";
v.innerHTML = "MS";
t.appendChild(v);
var A = document.createElement("div");
A.style.position = "relative";
A.style.width = "74px";
A.style.height = "30px";
A.style.backgroundColor = "rgb(" + q[1][0] + "," + q[1][1] + "," + q[1][2] + ")";
for (t.appendChild(A); 74 > A.children.length; )
x = document.createElement("span"),
x.style.width = "1px",
x.style.height = 30 * Math.random() + "px",
x.style.cssFloat = "left",
x.style.backgroundColor = "rgb(" + q[0][0] + "," + q[0][1] + "," + q[0][2] + ")",
A.appendChild(x);
return {
domElement: p,
update: function() {
d = Date.now();
h = d - f;
n = Math.min(n, h);
l = Math.max(l, h);
v.textContent = h + " MS (" + n + "-" + l + ")";
var k = Math.min(30, 30 - h / 200 * 30);
A.appendChild(A.firstChild).style.height = k + "px";
f = d;
a++;
d > c + 1E3 && (e = Math.round(1E3 * a / (d - c)),
b = Math.min(b, e),
g = Math.max(g, e),
u.textContent = e + " FPS (" + b + "-" + g + ")",
k = Math.min(30, 30 - e / 100 * 30),
w.appendChild(w.firstChild).style.height = k + "px",
c = d,
a = 0)
}
}
};
THREE.TrackballControls = function(m, a) {
function d(a) {
!1 !== b.enabled && (window.removeEventListener("keydown", d),
n = h,
h === g.NONE) && (a.keyCode !== b.keys[g.ROTATE] || b.noRotate ? a.keyCode !== b.keys[g.ZOOM] || b.noZoom ? a.keyCode !== b.keys[g.PAN] || b.noPan || (h = g.PAN) : h = g.ZOOM : h = g.ROTATE)
}
function f(a) {
!1 !== b.enabled && (a.preventDefault(),
a.stopPropagation(),
h !== g.ROTATE || b.noRotate ? h !== g.ZOOM || b.noZoom ? h !== g.PAN || b.noPan || v.copy(D(a.pageX, a.pageY)) : u.copy(D(a.pageX, a.pageY)) : p.copy(E(a.pageX, a.pageY)))
}
function c(a) {
!1 !== b.enabled && (a.preventDefault(),
a.stopPropagation(),
h = g.NONE,
document.removeEventListener("mousemove", f),
document.removeEventListener("mouseup", c),
b.dispatchEvent(B))
}
function e(a) {
if (!1 !== b.enabled) {
a.preventDefault();
a.stopPropagation();
var c = 0;
a.wheelDelta ? c = a.wheelDelta / 40 : a.detail && (c = -a.detail / 3);
r.y += .01 * c;
b.dispatchEvent(C);
b.dispatchEvent(B)
}
}
var b = this
, g = {
NONE: -1,
ROTATE: 0,
ZOOM: 1,
PAN: 2,
TOUCH_ROTATE: 3,
TOUCH_ZOOM_PAN: 4
};
this.object = m;
this.domElement = void 0 !== a ? a : document;
this.enabled = !0;
this.screen = {
left: 0,
top: 0,
width: 0,
height: 0
};
this.rotateSpeed = 1;
this.zoomSpeed = 1.2;
this.panSpeed = .3;
this.staticMoving = this.noRoll = this.noPan = this.noZoom = this.noRotate = !1;
this.dynamicDampingFactor = .2;
this.minDistance = 0;
this.maxDistance = Infinity;
this.keys = [65, 83, 68];
this.target = new THREE.Vector3;
var k = new THREE.Vector3
, h = g.NONE
, n = g.NONE
, l = new THREE.Vector3
, q = new THREE.Vector3
, p = new THREE.Vector3
, r = new THREE.Vector2
, u = new THREE.Vector2
, w = 0
, x = 0
, t = new THREE.Vector2
, v = new THREE.Vector2;
this.target0 = this.target.clone();
this.position0 = this.object.position.clone();
this.up0 = this.object.up.clone();
var A = {
type: "change"
}
, C = {
type: "start"
}
, B = {
type: "end"
};
this.handleResize = function() {
if (this.domElement === document)
this.screen.left = 0,
this.screen.top = 0,
this.screen.width = window.innerWidth,
this.screen.height = window.innerHeight;
else {
var a = this.domElement.getBoundingClientRect()
, b = this.domElement.ownerDocument.documentElement;
this.screen.left = a.left + window.pageXOffset - b.clientLeft;
this.screen.top = a.top + window.pageYOffset - b.clientTop;
this.screen.width = a.width;
this.screen.height = a.height
}
}
;
this.handleEvent = function(a) {
if ("function" == typeof this[a.type])
this[a.type](a)
}
;
var D = function() {
var a = new THREE.Vector2;
return function(c, d) {
a.set((c - b.screen.left) / b.screen.width, (d - b.screen.top) / b.screen.height);
return a
}
}()
, E = function() {
var a = new THREE.Vector3
, c = new THREE.Vector3
, d = new THREE.Vector3;
return function(e, f) {
d.set((e - .5 * b.screen.width - b.screen.left) / (.5 * b.screen.width), (.5 * b.screen.height + b.screen.top - f) / (.5 * b.screen.height), 0);
var g = d.length();
b.noRoll ? d.z = g < Math.SQRT1_2 ? Math.sqrt(1 - g * g) : .5 / g : 1 < g ? d.normalize() : d.z = Math.sqrt(1 - g * g);
l.copy(b.object.position).sub(b.target);
a.copy(b.object.up).setLength(d.y);
a.add(c.copy(b.object.up).cross(l).setLength(d.x));
a.add(l.setLength(d.z));
return a
}
}();
this.rotateCamera = function() {
var a = new THREE.Vector3
, c = new THREE.Quaternion;
return function() {
var d = Math.acos(q.dot(p) / q.length() / p.length());
d && (a.crossVectors(q, p).normalize(),
d *= b.rotateSpeed,
c.setFromAxisAngle(a, -d),
l.applyQuaternion(c),
b.object.up.applyQuaternion(c),
p.applyQuaternion(c),
b.staticMoving ? q.copy(p) : (c.setFromAxisAngle(a, d * (b.dynamicDampingFactor - 1)),
q.applyQuaternion(c)))
}
}();
this.zoomCamera = function() {
if (h === g.TOUCH_ZOOM_PAN) {
var a = w / x;
w = x;
l.multiplyScalar(a)
} else
a = 1 + (u.y - r.y) * b.zoomSpeed,
1 !== a && 0 < a && (l.multiplyScalar(a),
b.staticMoving ? r.copy(u) : r.y += (u.y - r.y) * this.dynamicDampingFactor)
}
;
this.panCamera = function() {
var a = new THREE.Vector2
, c = new THREE.Vector3
, d = new THREE.Vector3;
return function() {
a.copy(v).sub(t);
a.lengthSq() && (a.multiplyScalar(l.length() * b.panSpeed),
d.copy(l).cross(b.object.up).setLength(a.x),
d.add(c.copy(b.object.up).setLength(a.y)),
b.object.position.add(d),
b.target.add(d),
b.staticMoving ? t.copy(v) : t.add(a.subVectors(v, t).multiplyScalar(b.dynamicDampingFactor)))
}
}();
this.checkDistances = function() {
b.noZoom && b.noPan || (l.lengthSq() > b.maxDistance * b.maxDistance && b.object.position.addVectors(b.target, l.setLength(b.maxDistance)),
l.lengthSq() < b.minDistance * b.minDistance && b.object.position.addVectors(b.target, l.setLength(b.minDistance)))
}
;
this.update = function() {
l.subVectors(b.object.position, b.target);
b.noRotate || b.rotateCamera();
b.noZoom || b.zoomCamera();
b.noPan || b.panCamera();
b.object.position.addVectors(b.target, l);
b.checkDistances();
b.object.lookAt(b.target);
1E-6 < k.distanceToSquared(b.object.position) && (b.dispatchEvent(A),
k.copy(b.object.position))
}
;
this.reset = function() {
n = h = g.NONE;
b.target.copy(b.target0);
b.object.position.copy(b.position0);
b.object.up.copy(b.up0);
l.subVectors(b.object.position, b.target);
b.object.lookAt(b.target);
b.dispatchEvent(A);
k.copy(b.object.position)
}
;
this.domElement.addEventListener("contextmenu", function(a) {
a.preventDefault()
}, !1);
this.domElement.addEventListener("mousedown", function(a) {
!1 !== b.enabled && (a.preventDefault(),
a.stopPropagation(),
h === g.NONE && (h = a.button),
h !== g.ROTATE || b.noRotate ? h !== g.ZOOM || b.noZoom ? h !== g.PAN || b.noPan || (t.copy(D(a.pageX, a.pageY)),
v.copy(t)) : (r.copy(D(a.pageX, a.pageY)),
u.copy(r)) : (q.copy(E(a.pageX, a.pageY)),
p.copy(q)),
document.addEventListener("mousemove", f, !1),
document.addEventListener("mouseup", c, !1),
b.dispatchEvent(C))
}, !1);
this.domElement.addEventListener("mousewheel", e, !1);
this.domElement.addEventListener("DOMMouseScroll", e, !1);
this.domElement.addEventListener("touchstart", function(a) {
if (!1 !== b.enabled) {
switch (a.touches.length) {
case 1:
h = g.TOUCH_ROTATE;
q.copy(E(a.touches[0].pageX, a.touches[0].pageY));
p.copy(q);
break;
case 2:
h = g.TOUCH_ZOOM_PAN;
var c = a.touches[0].pageX - a.touches[1].pageX
, d = a.touches[0].pageY - a.touches[1].pageY;
x = w = Math.sqrt(c * c + d * d);
t.copy(D((a.touches[0].pageX + a.touches[1].pageX) / 2, (a.touches[0].pageY + a.touches[1].pageY) / 2));
v.copy(t);
break;
default:
h = g.NONE
}
b.dispatchEvent(C)
}
}, !1);
this.domElement.addEventListener("touchend", function(a) {
if (!1 !== b.enabled) {
switch (a.touches.length) {
case 1:
p.copy(E(a.touches[0].pageX, a.touches[0].pageY));
q.copy(p);
break;
case 2:
w = x = 0,
v.copy(D((a.touches[0].pageX + a.touches[1].pageX) / 2, (a.touches[0].pageY + a.touches[1].pageY) / 2)),
t.copy(v)
}
h = g.NONE;
b.dispatchEvent(B)
}
}, !1);
this.domElement.addEventListener("touchmove", function(a) {
if (!1 !== b.enabled)
switch (a.preventDefault(),
a.stopPropagation(),
a.touches.length) {
case 1:
p.copy(E(a.touches[0].pageX, a.touches[0].pageY));
break;
case 2:
var c = a.touches[0].pageX - a.touches[1].pageX
, d = a.touches[0].pageY - a.touches[1].pageY;
x = Math.sqrt(c * c + d * d);
v.copy(D((a.touches[0].pageX + a.touches[1].pageX) / 2, (a.touches[0].pageY + a.touches[1].pageY) / 2));
break;
default:
h = g.NONE
}
}, !1);
window.addEventListener("keydown", d, !1);
window.addEventListener("keyup", function(a) {
!1 !== b.enabled && (h = n,
window.addEventListener("keydown", d, !1))
}, !1);
this.handleResize();
this.update()
}
;
THREE.TrackballControls.prototype = Object.create(THREE.EventDispatcher.prototype);
function COpponent(m, a, d, f) {
var c;
this._init = function(a, b, d, f) {
c = [];
for (var e = 0; e < NUM_SPRITE_BATTER_BOWLER_MODE; e++)
c.push(createBitmap(s_oSpriteLibrary.getSprite("batter_" + d + "_" + e))),
c[e].x = a,
c[e].y = b,
c[e].rotation = 0,
c[e].visible = !1,
f.addChild(c[e]);
c[0].visible = !0
}
;
this.viewBowler = function(a) {
c[a].visible = !0
}
;
this.hideBowler = function(a) {
c[a].visible = !1
}
;
this.onFinishAnimation = function() {
var a = this;
_oOpponent.on("animationend", function() {
s_oGame.addImpulseToBall();
playSound("kick", .3, !1);
_oOpponent.removeAllEventListeners();
a.fadeAnimation(0)
})
}
;
this._init(m, a, d, f);
return this
}
function CHelpPanel(m, a, d, f) {
var c, e, b, g, k, h, n, l, q, p = !1, r;
this._init = function(a, d, f, m) {
k = new createjs.Container;
k.x = a;
k.y = d;
s_oStage.addChild(k);
g = new createjs.Shape;
g.graphics.beginFill("black").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
g.alpha = .5;
k.addChild(g);
b = createBitmap(m);
b.x = CANVAS_WIDTH_HALF;
b.y = CANVAS_HEIGHT_HALF;
b.regX = .5 * m.width;
b.regY = .5 * m.height;
k.addChild(b);
c = new createjs.Text(TEXT_HOW_TO_PLAY,"50px " + FONT2,"#ffffff");
c.textAlign = "center";
c.lineWidth = 500;
c.x = .5 * CANVAS_WIDTH;
c.y = .5 * CANVAS_HEIGHT - 240;
k.addChild(c);
q = new createjs.Container;
q.y = -70;
a = s_oSpriteLibrary.getSprite("glove_" + f);
n = new CGlove(-50,LEFT_GLOVE,a,null,q);
l = new CGlove(50,RIGHT_GLOVE,a,null,q);
n.setScale(.7);
l.setScale(.7);
l.flip();
s_bMobile ? (a = TEXT_HELP1_MOBILE_BOWLER,
d = "help_touch") : (a = TEXT_HELP1_PC_BOWLER,
d = "help_mouse");
d = s_oSpriteLibrary.getSprite(d);
r = createBitmap(d);
r.x = CANVAS_WIDTH_HALF + 6;
r.y = 390;
r.regX = .5 * d.width;
r.regY = .5 * d.height;
q.addChild(r);
k.addChild(q);
createjs.Ticker.paused = !1;
this.animGloves();
e = new createjs.Text(a,"28px " + FONT2,"#ffffff");
e.textAlign = "center";
e.lineWidth = 450;
e.x = .5 * CANVAS_WIDTH;
e.y = .5 * CANVAS_HEIGHT + 20;
k.addChild(e);
a = s_oSpriteLibrary.getSprite("but_continue");
h = new CGfxButton(CANVAS_WIDTH / 2,CANVAS_HEIGHT_HALF + 180,a,k);
h.addEventListener(ON_MOUSE_UP, this._onExitHelp, this);
h.pulseAnimation();
var p = this;
k.on("pressup", function() {
p._onExitHelp()
})
}
;
this.animGloves = function() {
var a = this;
createjs.Tween.get(q).to({
x: 100
}, 1E3, createjs.Ease.cubicInOut).call(function() {
createjs.Tween.get(q).to({
x: -100
}, 1E3, createjs.Ease.cubicInOut).call(function() {
a.animGloves()
})
})
}
;
this.unload = function() {
createjs.Tween.removeTweens(q);
createjs.Tween.get(k).to({
alpha: 0
}, 500, createjs.Ease.cubicIn).call(function() {
s_oStage.removeChild(k)
});
var a = this;
k.off("pressup", function() {
a._onExitHelp()
})
}
;
this._onExitHelp = function() {
p || (p = !0,
this.unload(),
s_oGame._onExitHelpPanel())
}
;
this._init(m, a, d, f)
}
function CLoadingScreen(m, a) {
var d = null, f;
this._init = function() {
d = new createjs.Shape;
d.graphics.beginFill("black").drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
d.on("click", function() {});
m.addChild(d);
var c = a.createText(TEXT_LOADING, 36).container;
c.x = CANVAS_WIDTH_HALF;
c.y = CANVAS_HEIGHT_HALF - 30;
m.addChild(c);
c = s_oSpriteLibrary.getSprite("preloader_anim");
f = createBitmap(c);
f.x = CANVAS_WIDTH_HALF;
f.y = CANVAS_HEIGHT_HALF + 30;
f.regX = .5 * c.width;
f.regY = .5 * c.height;
m.addChild(f);
s_oStage.addChild(m);
this.animLoad()
}
;
this.animLoad = function() {
var a = this;
createjs.Tween.get(f).to({
rotation: f.rotation + 360
}, 1E3).call(function() {
a.animLoad()
})
}
;
this.unload = function() {
d.removeAllEventListeners();
s_oStage.removeChild(m)
}
;
this._init();
return this
}
function CBallStatic(m) {
var a;
this._init = function() {
var d = s_oSpriteLibrary.getSprite("ball");
a = createBitmap(d);
a.regX = .5 * d.width;
a.regY = .5 * d.height;
m.addChild(a)
}
;
this.setPosition = function(d, f) {
a.x = d;
a.y = f
}
;
this._init();
return this
}
;