-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
134 lines (123 loc) · 4.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,minimal-ui">
<meta name="theme-color" content="#00ffff">
<meta name="msapplication-navbutton-color" content="#00ffff">
<meta name="mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-status-bar-style" content="black-translucent">
<title>Liquid simulation JS</title>
<style type="text/css">
body { margin: 0; }
/* stats.js dependent */
.counter-caption {
width: 80px;
padding-top: 22px;
position: relative;
z-index: 10001;
color: #fff;
text-align: center;
user-select: none;
}
#info{
position: absolute;
z-index: 100000;
color: #fff;
font-size: 20px;
top: 50px;
width: 100vw;
text-align: center;
font-family: monospace;
}
/* matter-tools dependent */
.matter-demo>canvas {
border: 1px solid #777;
}
</style>
</head>
<body>
<!-- For demos using SVG -->
<script src="https://cdn.jsdelivr.net/gh/progers/pathseg/pathseg.js"></script>
<script src="https://cdn.jsdelivr.net/gh/schteppe/poly-decomp.js/build/decomp.min.js"></script>
<script src="https://mrdoob.github.io/stats.js/build/stats.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/liabru/[email protected]/build/matter.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/gh/liabru/[email protected]/build/matter-tools.min.js"></script> -->
<script src="https://cdn.jsdelivr.net/gh/liabru/[email protected]/build/matter-tools.demo.min.js"></script>
<!-- Plugin loading -->
<!-- <script src="./build/matter-liquid.js"></script> -->
<script type="module">
if(window.location.host.includes('localhost'))
await import('./src/index.ts')
else
await import('./dist/matter-liquid.js')
import examBasic from './examples/basic.js';
import examView from './examples/view.js';
import examGravity from './examples/gravity.js';
import examWrap from './examples/wrap.js';
import examBodies from './examples/bodies.js';
import examMultiLiquid from './examples/multi_liquid.js';
import examChemics from './examples/chemics.js';
let pluginName = 'matter-liquid'; // PLUGIN_NAME
let repoUrl = 'https://github.com/TheLucifurry/matter-liquid'; // PLUGIN_REPO_URL
// install plugin
Matter.use(pluginName);
const { Liquid } = Matter;
// Stats
const statsContainer = document.createElement('div');
const counter = document.createElement('div');
counter.classList.add('counter-caption');
const stats = new Stats();
stats.showPanel(0);
statsContainer.prepend(stats.dom, counter);
counter.onclick = () => stats.dom.click();
window.DEMO_LOADED = (liquid, engine, info = '') => {
Matter.Events.on(engine, 'beforeUpdate', stats.begin);
Matter.Events.on(engine, 'afterUpdate', () => {
stats.end();
counter.textContent = Liquid.getParticlesCount(liquid);
});
window.onblur = () => Liquid.setPause(liquid);
window.onfocus = () => Liquid.setPause(liquid, false);
// liquid.setPause(!document.hasFocus())
document.getElementById('info').textContent = info;
};
function example(name, init){
const id = name.toLowerCase().replace(/ /g, '_');
return { name, id, init, sourceLink: `${repoUrl}/blob/master/examples/${id}.js` };
}
// Init
MatterTools.Demo.create({
fullPage: true,
preventZoom: true,
// resetOnOrientation: true,
// routing: true,
toolbar: {
title: pluginName,
url: repoUrl,
reset: true,
source: true,
fullscreen: true,
exampleSelect: true,
// inspector: true,
// tools: true,
},
tools: {
// inspector: true,
// gui: true
},
examples: [
example('Basic', examBasic),
example('View', examView),
example('Gravity', examGravity),
example('Wrap', examWrap),
example('Bodies', examBodies),
example('Multi Liquid', examMultiLiquid),
example('Chemics', examChemics),
]
});
document.querySelector('.matter-header-outer').prepend(statsContainer);
</script>
<div id="info"></div>
</body>
</html>