mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
updated matter-tools
This commit is contained in:
parent
a1d4748e1d
commit
4ecad0f175
1 changed files with 14 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* matter-tools-dev.min.js 0.5.0-dev 2015-05-24
|
* matter-tools-dev.min.js 0.5.0-dev 2015-07-27
|
||||||
* https://github.com/liabru/matter-tools
|
* https://github.com/liabru/matter-tools
|
||||||
* License: MIT
|
* License: MIT
|
||||||
*/
|
*/
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
var Gui = {};
|
var Gui = {};
|
||||||
(function() {
|
(function() {
|
||||||
var _isWebkit = "WebkitAppearance" in document.documentElement.style;
|
var _isWebkit = "WebkitAppearance" in document.documentElement.style;
|
||||||
Gui.create = function(engine, options) {
|
Gui.create = function(engine, runner, options) {
|
||||||
var _datGuiSupported = window.dat && window.localStorage;
|
var _datGuiSupported = window.dat && window.localStorage;
|
||||||
if (!_datGuiSupported) {
|
if (!_datGuiSupported) {
|
||||||
console.log("Could not create GUI. Check dat.gui library is loaded first.");
|
console.log("Could not create GUI. Check dat.gui library is loaded first.");
|
||||||
|
@ -19,6 +19,7 @@
|
||||||
var datGui = new dat.GUI(options);
|
var datGui = new dat.GUI(options);
|
||||||
var gui = {
|
var gui = {
|
||||||
engine:engine,
|
engine:engine,
|
||||||
|
runner:runner,
|
||||||
datGui:datGui,
|
datGui:datGui,
|
||||||
broadphase:"grid",
|
broadphase:"grid",
|
||||||
broadphaseCache:{
|
broadphaseCache:{
|
||||||
|
@ -98,7 +99,7 @@
|
||||||
return clone;
|
return clone;
|
||||||
};
|
};
|
||||||
var _initDatGui = function(gui) {
|
var _initDatGui = function(gui) {
|
||||||
var engine = gui.engine, datGui = gui.datGui;
|
var engine = gui.engine, runner = gui.runner, datGui = gui.datGui;
|
||||||
var funcs = {
|
var funcs = {
|
||||||
addBody:function() {
|
addBody:function() {
|
||||||
_addBody(gui);
|
_addBody(gui);
|
||||||
|
@ -115,7 +116,7 @@
|
||||||
Events.trigger(gui, "load");
|
Events.trigger(gui, "load");
|
||||||
},
|
},
|
||||||
inspect:function() {
|
inspect:function() {
|
||||||
if (!Inspector.instance) gui.inspector = Inspector.create(gui.engine);
|
if (!Inspector.instance) gui.inspector = Inspector.create(gui.engine, gui.runner);
|
||||||
},
|
},
|
||||||
recordGif:function() {
|
recordGif:function() {
|
||||||
if (!gui.isRecording) {
|
if (!gui.isRecording) {
|
||||||
|
@ -152,10 +153,10 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var metrics = datGui.addFolder("Metrics");
|
var metrics = datGui.addFolder("Metrics");
|
||||||
metrics.add(engine.timing, "fps").listen();
|
metrics.add(runner, "fps").listen();
|
||||||
if (engine.metrics.extended) {
|
if (engine.metrics.extended) {
|
||||||
metrics.add(engine.timing, "delta").listen();
|
metrics.add(runner, "delta").listen();
|
||||||
metrics.add(engine.timing, "correction").listen();
|
metrics.add(runner, "correction").listen();
|
||||||
metrics.add(engine.metrics, "bodies").listen();
|
metrics.add(engine.metrics, "bodies").listen();
|
||||||
metrics.add(engine.metrics, "collisions").listen();
|
metrics.add(engine.metrics, "collisions").listen();
|
||||||
metrics.add(engine.metrics, "pairs").listen();
|
metrics.add(engine.metrics, "pairs").listen();
|
||||||
|
@ -201,7 +202,7 @@
|
||||||
physics.add(engine.timing, "timeScale", 0, 1.2).step(.05).listen();
|
physics.add(engine.timing, "timeScale", 0, 1.2).step(.05).listen();
|
||||||
physics.add(engine, "velocityIterations", 1, 10).step(1);
|
physics.add(engine, "velocityIterations", 1, 10).step(1);
|
||||||
physics.add(engine, "positionIterations", 1, 10).step(1);
|
physics.add(engine, "positionIterations", 1, 10).step(1);
|
||||||
physics.add(engine, "enabled");
|
physics.add(runner, "enabled");
|
||||||
physics.open();
|
physics.open();
|
||||||
var render = datGui.addFolder("Render");
|
var render = datGui.addFolder("Render");
|
||||||
render.add(gui, "renderer", [ "canvas", "webgl" ]).onFinishChange(function(value) {
|
render.add(gui, "renderer", [ "canvas", "webgl" ]).onFinishChange(function(value) {
|
||||||
|
@ -269,7 +270,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var engine = gui.engine, skipFrame = false;
|
var engine = gui.engine, skipFrame = false;
|
||||||
Matter.Events.on(engine, "beforeTick", function(event) {
|
Matter.Events.on(gui.runner, "beforeTick", function(event) {
|
||||||
if (gui.isRecording && !skipFrame) {
|
if (gui.isRecording && !skipFrame) {
|
||||||
gui.gif.addFrame(engine.render.context, {
|
gui.gif.addFrame(engine.render.context, {
|
||||||
copy:true,
|
copy:true,
|
||||||
|
@ -283,13 +284,14 @@
|
||||||
var Inspector = {};
|
var Inspector = {};
|
||||||
(function() {
|
(function() {
|
||||||
var _key, _isWebkit = "WebkitAppearance" in document.documentElement.style, $body;
|
var _key, _isWebkit = "WebkitAppearance" in document.documentElement.style, $body;
|
||||||
Inspector.create = function(engine, options) {
|
Inspector.create = function(engine, runner, options) {
|
||||||
if (!jQuery || !$.fn.jstree || !window.key) {
|
if (!jQuery || !$.fn.jstree || !window.key) {
|
||||||
console.log("Could not create inspector. Check keymaster, jQuery, jsTree libraries are loaded first.");
|
console.log("Could not create inspector. Check keymaster, jQuery, jsTree libraries are loaded first.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var inspector = {
|
var inspector = {
|
||||||
engine:engine,
|
engine:engine,
|
||||||
|
runner:runner,
|
||||||
isPaused:false,
|
isPaused:false,
|
||||||
selected:[],
|
selected:[],
|
||||||
selectStart:null,
|
selectStart:null,
|
||||||
|
@ -566,7 +568,7 @@
|
||||||
};
|
};
|
||||||
var _initEngineEvents = function(inspector) {
|
var _initEngineEvents = function(inspector) {
|
||||||
var engine = inspector.engine, mouse = inspector.mouse, mousePosition = _getMousePosition(inspector), controls = inspector.controls;
|
var engine = inspector.engine, mouse = inspector.mouse, mousePosition = _getMousePosition(inspector), controls = inspector.controls;
|
||||||
Events.on(engine, "tick", function() {
|
Events.on(inspector.engine, "beforeUpdate", function() {
|
||||||
mousePosition = _getMousePosition(inspector);
|
mousePosition = _getMousePosition(inspector);
|
||||||
var mouseDelta = mousePosition.x - inspector.mousePrevPosition.x, keyDelta = _key.isPressed("up") + _key.isPressed("right") - _key.isPressed("down") - _key.isPressed("left"), delta = mouseDelta + keyDelta;
|
var mouseDelta = mousePosition.x - inspector.mousePrevPosition.x, keyDelta = _key.isPressed("up") + _key.isPressed("right") - _key.isPressed("down") - _key.isPressed("left"), delta = mouseDelta + keyDelta;
|
||||||
if (engine.world.isModified) {
|
if (engine.world.isModified) {
|
||||||
|
@ -672,7 +674,7 @@
|
||||||
_updateSelectedMouseDownOffset(inspector);
|
_updateSelectedMouseDownOffset(inspector);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Events.on(engine, "afterRender", function() {
|
Events.on(inspector.engine.render, "afterRender", function() {
|
||||||
var renderController = engine.render.controller, context = engine.render.context;
|
var renderController = engine.render.controller, context = engine.render.context;
|
||||||
if (renderController.inspector) renderController.inspector(inspector, context);
|
if (renderController.inspector) renderController.inspector(inspector, context);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue