-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdemo.js
27 lines (26 loc) · 853 Bytes
/
demo.js
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
var mca2json = require('./')
var crunch = require('voxel-crunch')
var chunks = []
window.chunks = chunks
function handleFileSelect(evt) {
var files = evt.target.files
var file = files[0]
var parts = file.name.split('.')
if (parts[0] !== 'r' && parts[3] !== 'mca') return
var reader = new FileReader()
reader.onloadend = function() {
var converter = mca2json({ distance: 1 })
console.time('load')
converter.on('data', function(chunk) {
var rle = crunch.encode(chunk.voxels)
chunks.push(rle)
// crunch.decode(rle, new Uint32Array(chunk.voxels.length))
})
converter.on('end', function(){
console.timeEnd('load')
})
converter.convert(reader.result, parts[1], parts[2])
}
reader.readAsArrayBuffer(file)
}
document.getElementById('file').addEventListener('change', handleFileSelect, false)