index.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  6. <meta name="description" content="Model 3D, file format, triangle mesh, validator, validation">
  7. <meta name="author" content="bzt">
  8. <title>Model 3D Validator</title>
  9. <link href="../logo.png" rel="shortcut icon">
  10. <style>
  11. select, option, input[type=file] { font-family: monospace,fixed; }
  12. #jserr { color:white; background:red; font-weight:bold; font-size: 150%; text-align:center; padding: 32px; }
  13. </style>
  14. </head>
  15. <body>
  16. <h1>Model 3D Validator</h1>
  17. <div id="jserr">Please enable JavaScript</div>
  18. <p>This tool provides the same functionality as <a href="https://gitlab.com/bztsrc/model3d/tree/master/m3dconv" target="new">converter</a> utility's dump feature.
  19. It is using the same M3D SDK in C, but compiled as WebAssembly and outputs to HTML DOM, so <em>considerably</em> slower than the native <samp>m3dconv</samp> command line tool.
  20. If everything went well, you should see "<samp>Model parsed OK.</samp>" as the last line of the output.</p>
  21. <table>
  22. <tr><td><samp>-d</samp></td><td>dump uncompressed chunks, do basic verification</td></tr>
  23. <tr><td><samp>-dd</samp></td><td>verify and dump summary of uncompressed chunks</td></tr>
  24. <tr><td><samp>-ddd</samp></td><td>verify and dump detailed chunk contents too</td></tr>
  25. <tr><td><samp>-D</samp></td><td>dump parsed, in-memory C struct representation</td></tr>
  26. <tr><td><samp>-v, -vv, -vvv&nbsp;&nbsp;</samp></td><td>set verbosity level of parsing (only useful with <samp>-D</samp>)</td></tr>
  27. </table>
  28. <h3>Command</h3>
  29. <p><samp>m3dconv</samp>&nbsp;
  30. <select id="dump">
  31. <option value=1 default>-d</option>
  32. <option value=2>-dd</option>
  33. <option value=3>-ddd</option>
  34. <option value=99>-D</option>
  35. </select>&nbsp;
  36. <select id="verbose">
  37. <option value=0 default>&nbsp;</option>
  38. <option value=1>-v</option>
  39. <option value=2>-vv</option>
  40. <option value=3>-vvv</option>
  41. </select>&nbsp;
  42. <input type="file" id="input" onchange="execute()">&nbsp;
  43. <input type="button" id="enter" onclick="execute()" value="&#8626;&nbsp;Enter">
  44. </p>
  45. <h3>Output</h3>
  46. <pre id="output"></pre>
  47. <script src="validator.js"></script>
  48. <script>
  49. var outbuf, outpre = document.getElementById("output");
  50. const decoder = new TextDecoder();
  51. document.getElementById("jserr").style.display = "none";
  52. outpre.innerText = "";
  53. function output(len) {
  54. /* let's waste some precious resources! Copy and convert uint8array to string! */
  55. const view = new Uint8Array(Module.HEAPU8.buffer,outbuf,len);
  56. const str = decoder.decode(view);
  57. /* refreshing the updated pre element on screen won't happen unless it's async */
  58. setTimeout(function () {
  59. if(str.charCodeAt(0) == 3) {
  60. document.getElementById("enter").disabled = false;
  61. document.body.style.cursor = "default";
  62. } else
  63. outpre.innerText += str;
  64. }, 1);
  65. }
  66. function execute() {
  67. var verb=document.getElementById("verbose").value;
  68. var dump=document.getElementById("dump").value;
  69. var input=document.getElementById("input");
  70. outpre.innerText = "";
  71. if(input.files.length<1) {
  72. alert("No file given.");
  73. } else {
  74. var reader = new FileReader();
  75. document.getElementById("enter").disabled = true;
  76. document.body.style.cursor = "wait";
  77. reader.onloadend = function() {
  78. var data = new Uint8Array(reader.result);
  79. var validator = Module.cwrap("m3d_validate", "number", [ "number", "number", "number", "number" ]);
  80. const buf = Module._malloc(data.length);
  81. outbuf = Module._malloc(4096);
  82. Module.HEAPU8.set(data, buf);
  83. validator(buf, data.length, dump, verb, outbuf);
  84. Module._free(buf);
  85. Module._free(outbuf);
  86. };
  87. reader.readAsArrayBuffer(input.files[0]);
  88. }
  89. }
  90. </script>
  91. </body>
  92. </html>