This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrun.html
230 lines (217 loc) · 6.46 KB
/
run.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!doctype html>
<html>
<head>
<title>xrpackage | run</title>
<link href="index.css" rel=stylesheet>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/0735724151.js" crossorigin="anonymous"></script>
<script
src="https://rawcdn.githack.com/ethereum/web3.js/a6ddec59e65116853435f203b25cb9c55824d084/dist/web3.min.js"></script>
</head>
<body>
<header class=header id=header>
<a href="/" class="nav icon">山</a>
<nav class="selector nav bar" id=selector>
<i class="fa fa-play head"></i>
<div class=header-label id=header-label>Run mode</div>
<i class="fa fa-chevron-down tail"></i>
<div class=selections id=selections>
<a href="run.html" class="selection dim" id=run-mode>
<i class="fa fa-play"></i>
<div class=wrap>
<h3>Run mode</h3>
<p>Switch to run mode</p>
</div>
</a>
<a href="edit.html" class=selection id=edit-mode>
<i class="fa fa-pencil"></i>
<div class=wrap>
<h3>Edit mode</h3>
<p>You are currently editing this world</p>
</div>
</a>
<a href="browse.html" class=selection>
<i class="fa fa-solar-system"></i>
<div class=wrap>
<h3>Browse packages</h3>
<p>Explore the XRPackage registry</p>
</div>
</a>
<a href="help.html" class=selection>
<i class="fa fa-book"></i>
<div class=wrap>
<h3>Documentation</h3>
<p>Learn how to make packages and worlds</p>
</div>
</a>
</div>
</nav>
<nav class="nav full right hidden">
<i class="fa fa-plus"></i>
<input type=file class=hidden id=load-package-input>
<span>Load package</span>
</nav>
<nav class="nav full" id=enter-xr-button>
<i class="fa fa-vr-cardboard"></i>
<span>Enter</span>
</nav>
<form id=login-form></form>
</header>
<script type=module>
import THREE from './xrpackage/three.module.js';
window.THREE = THREE;
</script>
<script type="module">
import {XRPackage} from './xrpackage.js';
import {pe} from './run.js';
const apiHost = `https://ipfs.exokit.org/ipfs`;
const packagesEndpoint = 'https://packages.exokit.org';
(async () => {
function parseQuery(queryString) {
var query = {};
var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
}
return query;
}
const q = parseQuery(window.location.search);
if (q.p) { // package
const metadata = await fetch(packagesEndpoint + '/' + q.p)
.then(res => res.json())
const {dataHash} = metadata;
const arrayBuffer = await fetch(`${apiHost}/${dataHash}.wbn`)
.then(res => res.arrayBuffer());
const p = new XRPackage(new Uint8Array(arrayBuffer));
await pe.add(p);
} else if (q.i) { // index
const metadataHash = await contract.methods.getMetadata(parseInt(q.i, 10), 'hash').call();
const metadata = await fetch(`${apiHost}/${metadataHash}`)
.then(res => res.json());
const {dataHash} = metadata;
const arrayBuffer = await fetch(`${apiHost}/${dataHash}.wbn`)
.then(res => res.arrayBuffer());
const p = new XRPackage(new Uint8Array(arrayBuffer));
await pe.add(p);
} else if (q.u) { // url
const arrayBuffer = await fetch(q.u)
.then(res => res.arrayBuffer());
const p = new XRPackage(new Uint8Array(arrayBuffer));
await pe.add(p);
} else if (q.h) { // hash
const p = await XRPackage.download(q.h);
pe.add(p);
/* } else if (q.h) { // home
const [cubeHtml, cubeManifest] = await Promise.all([
(async () => {
const res = await fetch('examples/html/cube.html');
return await res.text();
})(),
(async () => {
const res = await fetch('examples/html/manifest.json');
return await res.text();
})(),
]);
const d = XRPackage.compileRaw(
[
{
url: '/cube.html',
type: 'text/html',
data: cubeHtml,
},
{
url: '/manifest.json',
type: 'application/json',
data: cubeManifest,
}
]
);
const p = new XRPackage(d);
await pe.add(p); */
} else { // default
const [cubeHtml, cubeManifest, modelVrm, catVox] = await Promise.all([
(async () => {
const res = await fetch('examples/html/cube.html');
return await res.text();
})(),
(async () => {
const res = await fetch('examples/html/manifest.json');
return await res.text();
})(),
(async () => {
const res = await fetch('examples/vrm/model.vrm');
return await res.arrayBuffer();
})(),
(async () => {
const res = await fetch('examples/vox/cat.vox');
return await res.arrayBuffer();
})(),
]);
{
const d = XRPackage.compileRaw(
[
{
url: '/cube.html',
type: 'text/html',
data: cubeHtml,
},
{
url: '/manifest.json',
type: 'application/json',
data: cubeManifest,
}
]
);
const p = new XRPackage(d);
await pe.add(p);
}
{
const d = XRPackage.compileRaw(
[
{
url: '/model.vrm',
type: 'application/octet-stream',
data: new Uint8Array(modelVrm),
},
{
url: '/manifest.json',
type: 'application/json',
data: JSON.stringify({
name: 'Avatar',
xr_type: '[email protected]',
start_url: 'model.vrm',
}),
}
]
);
const p = new XRPackage(d);
await pe.add(p);
}
{
const d = XRPackage.compileRaw(
[
{
url: '/cat.vox',
type: 'application/octet-stream',
data: new Uint8Array(catVox),
},
{
url: '/manifest.json',
type: 'application/json',
data: JSON.stringify({
name: 'Cat',
xr_type: '[email protected]',
start_url: 'cat.vox',
}),
}
]
);
const p = new XRPackage(d);
await pe.add(p);
}
}
})();
</script>
</body>
</html>