mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-04-22 05:39:54 +08:00

1. Javascript decoder is now exported as a module using DracoModule() function that needs to be instantiated on the client. 2. Updated Javascript example applications and README.md 3. Added normalization function to VectorD 4. Added support for converting a single signed value to symbol for entropy coding and vice versa 5. Minor code cleaning
124 lines
3.5 KiB
HTML
124 lines
3.5 KiB
HTML
<html>
|
|
<head>
|
|
<title>Draco Javascript Decode Timing</title>
|
|
|
|
<script type="text/javascript" src="draco_decoder.js"> </script>
|
|
|
|
<script type="text/javascript">
|
|
'use strict';
|
|
|
|
// String to hold table output.
|
|
let dt = '';
|
|
const dracoDecoder = DracoModule();
|
|
|
|
function startTable() {
|
|
dt += '<table><tr>';
|
|
dt += '<td>Filename</td>';
|
|
dt += '<td>Total milli</td>';
|
|
dt += '<td>Decode milli</td>';
|
|
dt += '<td>Size bytes</td>';
|
|
dt += '<td>Num points</td>';
|
|
}
|
|
|
|
function addCell(str, newRow) {
|
|
if (newRow)
|
|
dt += '</tr><tr>';
|
|
dt += '<td>' + str + '</td>';
|
|
}
|
|
|
|
function finishTable() {
|
|
dt += '</table>';
|
|
document.getElementById('tableOutput').innerHTML = dt;
|
|
}
|
|
|
|
function onDecodeClick() {
|
|
startTable();
|
|
const inputs = document.getElementById('u').value.split(',');
|
|
s_log('Decoding ' + inputs.length + ' files...', true, true);
|
|
TestMeshDecodingAsync(inputs, 0);
|
|
}
|
|
|
|
function onDecodeMultipleClick() {
|
|
startTable();
|
|
const inputs = document.getElementById('u').value.split(',');
|
|
const decode_count = parseInt(document.getElementById('decode_count').value);
|
|
s_log('Decoding ' + (decode_count * inputs.length) + ' files...', true, true);
|
|
|
|
let fileList = [];
|
|
for (let i = 0; i < decode_count; ++i) {
|
|
fileList = fileList.concat(inputs);
|
|
}
|
|
TestMeshDecodingAsync(fileList, 0);
|
|
}
|
|
|
|
function TestMeshDecodingAsync(filenameList, index) {
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open("GET", filenameList[index], true);
|
|
xhr.responseType = "arraybuffer";
|
|
|
|
xhr.onload = function(event) {
|
|
const arrayBuffer = xhr.response;
|
|
if (arrayBuffer) {
|
|
const byteArray = new Uint8Array(arrayBuffer);
|
|
|
|
const total_t0 = performance.now();
|
|
|
|
const buffer = new dracoDecoder.DecoderBuffer();
|
|
buffer.Init(byteArray, byteArray.length);
|
|
|
|
const wrapper = new dracoDecoder.WebIDLWrapper();
|
|
|
|
const decode_t0 = performance.now();
|
|
const geometryType = wrapper.GetEncodedGeometryType(buffer);
|
|
let outputGeometry;
|
|
if (geometryType == dracoDecoder.TRIANGULAR_MESH) {
|
|
outputGeometry = wrapper.DecodeMeshFromBuffer(buffer);
|
|
} else {
|
|
outputGeometry = wrapper.DecodePointCloudFromBuffer(buffer);
|
|
}
|
|
const t1 = performance.now();
|
|
|
|
addCell(filenameList[index], true);
|
|
addCell('' + (t1 - total_t0), false);
|
|
addCell('' + (t1 - decode_t0), false);
|
|
addCell('' + byteArray.length, false);
|
|
addCell('' + outputGeometry.num_points(), false);
|
|
|
|
dracoDecoder.destroy(outputGeometry);
|
|
dracoDecoder.destroy(wrapper);
|
|
dracoDecoder.destroy(buffer);
|
|
|
|
if (index < filenameList.length - 1) {
|
|
index = index + 1;
|
|
TestMeshDecodingAsync(filenameList, index);
|
|
} else {
|
|
finishTable();
|
|
}
|
|
}
|
|
};
|
|
|
|
xhr.send(null);
|
|
}
|
|
|
|
function s_log(str, end_line, reset) {
|
|
if (reset)
|
|
document.getElementById('status').innerHTML = '';
|
|
document.getElementById('status').innerHTML += str;
|
|
if (end_line)
|
|
document.getElementById('status').innerHTML += "<br/>";
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<H1>Draco Javascript Decode Timing</H1>
|
|
Draco file to be decoded. If more than one file, add as comma separated list. E.g. "file1.drc,file2.drc,file3.drc"</br>
|
|
<input id="u" type="text" size="80" value="input.drc"/><input type="button" value="Decode" onClick="onDecodeClick();">
|
|
<input id="decode_count" type="text" size="10" value="10"/><input type="button" value="Decode Multiple" onClick="onDecodeMultipleClick();">
|
|
<br/>
|
|
<div id="status"> </div></br>
|
|
<div id="tableOutput"> </div>
|
|
</body>
|
|
</html>
|
|
|