minor non-final changes

Reminder of TODOs:
Animation parsing, parsing animation data into visible data. ->
* Render animations in HTML client.
* Write animations to glTF2 exporter.

Considered ideas:
* Multi-format file input box (auto-detect format based off first bytes)
This commit is contained in:
yellows111 2023-12-25 08:20:58 +00:00
parent d57d9129de
commit aa53573a14
3 changed files with 87 additions and 72 deletions

View File

@ -99,13 +99,22 @@ function imf2gltf(icon = null, filename = "untitled") {
}]; // no indices because who needs indexing when you're transcoding? }]; // no indices because who needs indexing when you're transcoding?
gltfOutput.materials = [{ gltfOutput.materials = [{
"name": `Material (${filename}#${index})`, "name": `Material (${filename}#${index})`,
"pbrMetallicRoughness": { "pbrMetallicRoughness": null,
"baseColorTexture": {"index":0, "texCoord": 0}
},
"extensions": { // or we get annoying PBR and specular stuff we don't need "extensions": { // or we get annoying PBR and specular stuff we don't need
"KHR_materials_unlit": {} "KHR_materials_unlit": {}
} }
}]; }];
if(icon.textureFormat !== "N") {
gltfOutput.materials.pbrMetallicRoughness = {
"baseColorTexture": {"index":0, "texCoord": 0}
};
} else {
gltfOutput.materials.pbrMetallicRoughness = {
"baseColorFactor": [1.0, 1.0, 1.0, 1.0],
"metallicFactor": 0.0,
"roughnessFactor": 1.0
}
}
gltfOutput.buffers = [{"uri": `${filename}.bin`, "byteLength": outputFloatArray.byteLength}]; gltfOutput.buffers = [{"uri": `${filename}.bin`, "byteLength": outputFloatArray.byteLength}];
gltfOutput.bufferViews = [ gltfOutput.bufferViews = [
{ {
@ -173,16 +182,14 @@ function imf2gltf(icon = null, filename = "untitled") {
]; ];
gltfOutput.asset = {"version": "2.0", "generator": `icondumper2/${icondumper2.version}`} gltfOutput.asset = {"version": "2.0", "generator": `icondumper2/${icondumper2.version}`}
gltfOutput.extensionsUsed = ["KHR_materials_unlit"]; gltfOutput.extensionsUsed = ["KHR_materials_unlit"];
if(icon.textureFormat !== "N") {
gltfOutput.textures = [{"source": 0}]; gltfOutput.textures = [{"source": 0}];
gltfOutput.images = [{"name": `Texture (${filename}#${index})`, "uri": `${filename}.png`}] gltfOutput.images = [{"name": `Texture (${filename}#${index})`, "uri": `${filename}.png`}]
}
gltfOutputArray[index] = (gltfOutput); gltfOutputArray[index] = (gltfOutput);
} }
let texture16 = null; // Uint16Array(16384) let texture16 = null; // Uint16Array(16384)
switch(icon.textureFormat) { switch(icon.textureFormat) {
case "N": {
texture16 = (new Uint16Array(16384)).fill(0xffff);
break;
}
case "C": { case "C": {
texture16 = icondumper2.helpers.uncompressTexture(icon.texture.data); texture16 = icondumper2.helpers.uncompressTexture(icon.texture.data);
break; break;
@ -192,6 +199,7 @@ function imf2gltf(icon = null, filename = "untitled") {
break; break;
} }
} }
if(texture16 !== null) {
let texture24 = new Uint8Array(49983); let texture24 = new Uint8Array(49983);
texture24.set([ texture24.set([
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
@ -243,6 +251,9 @@ function imf2gltf(icon = null, filename = "untitled") {
0xae, 0x42, 0x60, 0x82 0xae, 0x42, 0x60, 0x82
], textureOffset); ], textureOffset);
return {objects: gltfOutputArray, buffer: outputFloatArray, texture: texture24}; return {objects: gltfOutputArray, buffer: outputFloatArray, texture: texture24};
} else {
return {objects: gltfOutputArray, buffer: outputFloatArray, texture: null};
}
} }
function loadAndConvertIcon(inputData, attemptedFilename = "-") { function loadAndConvertIcon(inputData, attemptedFilename = "-") {
@ -257,9 +268,10 @@ function loadAndConvertIcon(inputData, attemptedFilename = "-") {
} }
(require("fs")).writeFileSync(`${filename}.bin`, glTF_output.buffer); (require("fs")).writeFileSync(`${filename}.bin`, glTF_output.buffer);
console.info(`Saved glTF buffer as "${filename}.bin".`); console.info(`Saved glTF buffer as "${filename}.bin".`);
if(glTF_output.texture !== null) {
(require("fs")).writeFileSync(`${filename}.png`, glTF_output.texture); (require("fs")).writeFileSync(`${filename}.png`, glTF_output.texture);
console.info(`Saved texture as "${filename}.png".\n`); console.info(`Saved texture as "${filename}.png".\n`);
}
} }
// can anything de-dupe this code somehow? (index.js) // can anything de-dupe this code somehow? (index.js)

View File

@ -4,7 +4,7 @@
<meta charset="utf-8"></meta> <meta charset="utf-8"></meta>
<meta name="viewport" content="initial-scale=1.5"></meta> <meta name="viewport" content="initial-scale=1.5"></meta>
<meta name="description" content="A HTML client for icondumper2"></meta> <meta name="description" content="A HTML client for icondumper2"></meta>
<title>icondumper2 - HTML reference client</title> <title>icondumper2 HTML reference client</title>
<script src="icon.js"></script> <script src="icon.js"></script>
<script src="lzari.js"></script> <script src="lzari.js"></script>
<!-- If you need pako to be optional, remove/comment the bottom line. This will disable support for CBS reading, however --> <!-- If you need pako to be optional, remove/comment the bottom line. This will disable support for CBS reading, however -->
@ -756,12 +756,15 @@
if (typeof pako === "undefined") { if (typeof pako === "undefined") {
document.getElementById("cbsinput").disabled = true; document.getElementById("cbsinput").disabled = true;
} }
if (typeof decodeLzari === "undefined") {
document.getElementById("maxinput").disabled = true;
}
//todo: More than one model shape rendering, other 2 icons (technically done? NMW though), Animation parsing, animation tweening //todo: More than one model shape rendering, other 2 icons (technically done? NMW though), Animation parsing, animation tweening
</script> </script>
<span id="version">icondumper2 <a href="./documentation" id="iconjsVersion">(unknown icon.js version)</a> [C: <span id="clientVersion">Loading...</span>] &mdash; &copy; <span id="currentYear">2023</span> yellows111</span> <span id="version">icondumper2 <a href="./documentation" id="iconjsVersion">(unknown icon.js version)</a> [C: <span id="clientVersion">Loading...</span>] &mdash; &copy; <span id="currentYear">2023</span> yellows111</span>
<script> <script>
document.getElementById("iconjsVersion").textContent = exports.version; document.getElementById("iconjsVersion").textContent = exports.version;
document.getElementById("clientVersion").textContent = "0.8.0+u1"; document.getElementById("clientVersion").textContent = "0.8.0+u2";
document.getElementById("currentYear").textContent = (new Date()).getFullYear().toString(); document.getElementById("currentYear").textContent = (new Date()).getFullYear().toString();
</script> </script>
</body> </body>

View File

@ -55,7 +55,7 @@ function BinarySearchSym(x) {
let i = 1; let i = 1;
let j = 314; let j = 314;
while (i < j) { while (i < j) {
let k = ~~((i + j) / 2); let k = ((i + j) / 2)|0;
if (symbolCumulative[k] > x) { if (symbolCumulative[k] > x) {
i = k + 1; i = k + 1;
} else { } else {
@ -69,7 +69,7 @@ function BinarySearchPos(x) {
let i = 1; let i = 1;
let j = 4096; let j = 4096;
while (i < j) { while (i < j) {
let k = ~~((i + j) / 2); let k = ((i + j) / 2)|0;
if (positionCumulative[k] > x) { if (positionCumulative[k] > x) {
i = k + 1; i = k + 1;
} else { } else {
@ -81,9 +81,9 @@ function BinarySearchPos(x) {
function DecodeChar() { function DecodeChar() {
var range = high - low; var range = high - low;
var sym = BinarySearchSym(~~(((value - low + 1) * symbolCumulative[0] - 1) / range)); var sym = BinarySearchSym((((value - low + 1) * symbolCumulative[0] - 1) / range)|0);
high = low + ~~((range * symbolCumulative[sym - 1]) / symbolCumulative[0]); high = low + ((range * symbolCumulative[sym - 1]) / symbolCumulative[0])|0;
low += ~~((range * symbolCumulative[sym ]) / symbolCumulative[0]); low += ((range * symbolCumulative[sym ]) / symbolCumulative[0])|0;
for ( ; ; ) { for ( ; ; ) {
if (low >= 65536) { if (low >= 65536) {
value -= 65536; value -= 65536;
@ -132,9 +132,9 @@ function DecodeChar() {
function DecodePosition() { function DecodePosition() {
var range = high - low; var range = high - low;
var position = BinarySearchPos(~~(((value - low + 1) * positionCumulative[0] - 1) / range)); var position = BinarySearchPos((((value - low + 1) * positionCumulative[0] - 1) / range)|0);
high = low + (~~((range * positionCumulative[position ]) / positionCumulative[0])); high = low + ((range * positionCumulative[position ]) / positionCumulative[0])|0;
low += (~~((range * positionCumulative[position + 1]) / positionCumulative[0])); low += ((range * positionCumulative[position + 1]) / positionCumulative[0])|0;
for ( ; ; ) { for ( ; ; ) {
if (low >= 65536) { if (low >= 65536) {
value -= 65536; value -= 65536;
@ -203,7 +203,7 @@ function decodeLzari(input) {
symbolFrequency[0] = 0; symbolFrequency[0] = 0;
positionCumulative[4096] = 0; positionCumulative[4096] = 0;
for (let i = 4096; i >= 1; i--) { for (let i = 4096; i >= 1; i--) {
positionCumulative[i - 1] = (positionCumulative[i] + ~~(10000 / (i + 200))); positionCumulative[i - 1] = (positionCumulative[i] + (10000 / (i + 200))|0);
} }
//end transclusion //end transclusion
//normal Decode process //normal Decode process