Skip to content

Commit

Permalink
Add WIP VO page and WIP model info
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlamin committed Jul 22, 2024
1 parent adeb531 commit 6dd7d4c
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 5 deletions.
142 changes: 142 additions & 0 deletions Controllers/ModelController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using Microsoft.AspNetCore.Mvc;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using wow.tools.local.Services;
using WoWFormatLib.FileProviders;
using WoWFormatLib.FileReaders;
using WoWFormatLib.Structs.WMO;

namespace wow.tools.local.Controllers
{
[Route("model/")]
public class ModelController(IDBCManager dbcManager) : Controller
{
private readonly DBCManager dbcManager = (DBCManager)dbcManager;

[Route("info")]
[HttpGet]
public string Info(int fileDataID)
{
if(!FileProvider.HasProvider(CASC.BuildName))
{
var casc = new CASCFileProvider();
casc.InitCasc(CASC.cascHandler);
FileProvider.SetProvider(casc, CASC.BuildName);
}

FileProvider.SetDefaultBuild(CASC.BuildName);

var returnString = "";

var type = CASC.Types[fileDataID];
if (type == "wmo")
{
var wmoReader = new WMOReader();
var wmo = wmoReader.LoadWMO((uint)fileDataID);

returnString += "<h3>Groups</h3>";
returnString += "<table class='table table-striped'>";
for (var i = 0; i < wmo.groupInfo.Length; i++)
{
var group = wmo.groupInfo[i];
returnString += "<tr>";
returnString += "<td><b>Group</b></td>";
returnString += "<td>Flags: " + group.flags + "</td>";
returnString += "<td>Flags2: " + wmo.groupInfo2[i].flags2 + "</td>";
returnString += "<td>'lodIndex' " + wmo.groupInfo2[i].lodIndex + "</td>";
returnString += "</tr>";
}

returnString += "</table>";

returnString += "<h3>Group names</h3>";
returnString += "<table class='table table-striped'>";
for (var gn = 0; gn < wmo.groupNames.Length; gn++)
{
returnString += "<tr><td>" + wmo.groupNames[gn].name + "</td></tr>";
}
returnString += "</table>";

returnString += "<h3>Group FileDataIDs</h3>";
returnString += "<table class='table table-striped table-sm'>";
foreach (var gfdid in wmo.groupFileDataIDs)
{
returnString += "<tr>";
var groupFilename = CASC.Listfile.TryGetValue((int)gfdid, out var gfilename) ? gfilename.ToString() : "";
returnString += "<td>" + gfdid + "</td><td>" + groupFilename + "</td>";
returnString += "</tr>";
}
returnString += "</table>";

returnString += "<h3>Materials</h3>";
returnString += "<table class='table table-striped'>";
for (var i = 0; i < wmo.materials.Length; i++)
{
var material = wmo.materials[i];

returnString += "<tr>";
returnString += "<td><b>Material " + i + "</b></td>";
returnString += "<td>Flags: " + material.flags + "</td>";
returnString += "<td>BlendMode: " + material.blendMode + "</td>";
returnString += "<td>GroundType: " + material.groundType + "</td>";
returnString += "<td>Shader: " + GetEnumMemberAttrValue<MOMTShader>(material.shader) + "</td></tr>";
returnString += "<tr><td colspan=5>";
returnString += "<table class='table table-striped'>";
returnString += "<tr><td>Texture1</td><td>" + material.texture1 + "</td><td>" + (CASC.Listfile.TryGetValue((int)material.texture1, out var texture1Filename) ? texture1Filename : "Unknown filename") + "</td></tr>";
returnString += "<tr><td>Color (<attr title='Self Illuminated Day Night'>SIDN</attr>)</td><td>" + material.color1 + "</td><td>" + ARGBToDiv(material.color1) + "</td></tr>";
returnString += "<tr><td>Frame color (<attr title='Self Illuminated Day Night'>SIDN</attr>)</td><td>" + material.color1b + "</td><td>" + ARGBToDiv(material.color1b) + "</td></tr>";
returnString += "<tr><td>Texture 2</td><td>" + material.texture2 + "</td><td>" + (CASC.Listfile.TryGetValue((int)material.texture2, out var texture2Filename) ? texture2Filename : "Unknown filename") + "</td></tr>";
returnString += "<tr><td>Diff color</td><td>" + material.color2 + "</td><td>" + ARGBToDiv(material.color2) + "</td></tr>";
returnString += "<tr><td>Texture 3</td><td>" + material.texture3 + "</td><td>" + (CASC.Listfile.TryGetValue((int)material.texture3, out var texture3Filename) ? texture3Filename : "Unknown filename") + "</td></tr>";

if ((uint)material.shader == 23)
{
returnString += "<tr><td>Texture 4</td><td>" + material.color3 + "</td><td>" + (CASC.Listfile.TryGetValue((int)material.color3, out var t4n) ? t4n : "Unknown filename") + "</td></tr>";
returnString += "<tr><td>Texture 5</td><td>" + material.flags3 + "</td><td>" + (CASC.Listfile.TryGetValue((int)material.flags3, out var t5n) ? t5n : "Unknown filename") + "</td></tr>";
returnString += "<tr><td>Texture 6</td><td>" + material.runtimeData0 + "</td><td>" + (CASC.Listfile.TryGetValue((int)material.runtimeData0, out var t6n) ? t6n : "Unknown filename") + "</td></tr>";
returnString += "<tr><td>Texture 7</td><td>" + material.runtimeData1 + "</td><td>" + (CASC.Listfile.TryGetValue((int)material.runtimeData1, out var t7n) ? t7n : "Unknown filename") + "</td></tr>";
returnString += "<tr><td>Texture 8</td><td>" + material.runtimeData2 + "</td><td>" + (CASC.Listfile.TryGetValue((int)material.runtimeData2, out var t8n) ? t8n : "Unknown filename") + "</td></tr>";
returnString += "<tr><td>Texture 9</td><td>" + material.runtimeData3 + "</td><td>" + (CASC.Listfile.TryGetValue((int)material.runtimeData3, out var t9n) ? t9n : "Unknown filename") + "</td></tr>";
}
else
{
returnString += "<tr><td>Unk color</td><td>" + material.color3 + "</td><td>" + ARGBToDiv(material.color3) + "</td></tr>";
returnString += "<tr><td>Flags 2</td><td>" + material.flags3 + "</td></tr>";
returnString += "<tr><td>Runtime data 0</td><td>" + material.runtimeData0 + "</td><td></td></tr>";
returnString += "<tr><td>Runtime data 1</td><td>" + material.runtimeData1 + "</td><td></td></tr>";
returnString += "<tr><td>Runtime data 2</td><td>" + material.runtimeData2 + "</td><td></td></tr>";
returnString += "<tr><td>Runtime data 3</td><td>" + material.runtimeData3 + "</td><td></td></tr>";
}

returnString += "</table></td>";
returnString += "</tr>";
}
returnString += "</table>";
}
return returnString;
}

private string GetEnumMemberAttrValue<T>(T enumVal)
{
var enumType = typeof(T);
var memInfo = enumType.GetMember(enumVal.ToString());
var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType<EnumMemberAttribute>().FirstOrDefault();
if (attr != null)
{
return attr.Value;
}

return null;
}

private string ARGBToDiv(uint argb)
{
var a = (byte)(argb >> 24);
var r = (byte)(argb >> 16);
var g = (byte)(argb >> 8);
var b = (byte)(argb >> 0);

return "<div style='width: 50px; background-color: rgba(" + r + "," + g + "," + b + "," + a + ")'>&nbsp;</div>";
}
}
}
2 changes: 1 addition & 1 deletion Services/FileLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static void LinkWMO(uint fileDataID, bool forceRecheck = false, bool need
insertEntry(insertCmd, material.texture3, "wmo texture");
}

if (material.shader == 23)
if ((uint)material.shader == 23)
{
if (material.color3 != 0 && !inserted.Contains(material.color3))
{
Expand Down
2 changes: 1 addition & 1 deletion WoWFormatLib
2 changes: 1 addition & 1 deletion WoWNamingLib
2 changes: 1 addition & 1 deletion wow.tools.local.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RepositoryUrl>https://github.com/Marlamin/wow.tools.local</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>0.4.6</Version>
<Version>0.4.7</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion wwwroot/db/broadcasttext.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<nav class="navbar navbar-expand-lg" id="navbar"></nav>
<div class='container-fluid'>
<h3>NPC VO lines</h3>
<p>Note: The data backing this page only update when VO naming is run on the naming page. Restart required after.</p>
<p>Note: Some of the data backing this page only update when VO naming is run on the naming page. Restart required after.</p>
<table class='table table-striped' id='voLines'>
<thead><tr><th style='width: 4%;'>SKIT ID</th><th style='max-width: 48%; width: 48%;'>Files&nbsp;&nbsp;&nbsp;&nbsp;<small><i>Note: only FDIDs and filenames are searchable</i></small></th><th style='max-width: 48%; width: 48%;'>BroadcastText</th></tr>
</table>
Expand Down
23 changes: 23 additions & 0 deletions wwwroot/js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,35 @@ function fillPreviewModal(buildconfig, filedataid, type) {
}
html += "<audio autoplay=\"\" controls=\"\"><source src=\"" + url + "\" type=\"" + mimeType + "\"></audio>";
} else if (type == "m2" || type == "wmo") {
html += "<ul class=\"nav nav-tabs\" role=\"tablist\">";
html += "<li class=\"nav-item\"><a class=\"nav-link active\" id=\"modelviewer-tab\" data-toggle=\"tab\" href=\"#modelviewer\" role=\"tab\" aria-controls=\"modelviewer\" aria-selected=\"true\">Modelviewer</a></li>";
html += "<li class=\"nav-item\"><a class=\"nav-link\" id=\"modelinfo-tab\" data-toggle=\"tab\" href=\"#modelinfo\" role=\"tab\" aria-controls=\"modelinfo\" aria-selected=\"false\">Model info</a></li>";
html += "<li class=\"nav-item\"><a class=\"nav-link\" id=\"json-tab\" data-toggle=\"tab\" href=\"#json\" role=\"tab\" aria-controls=\"json\" aria-selected=\"false\">JSON</a></li>";
html += "</ul>";
html += "<div class=\"tab-content\">";
html += "<div class=\"tab-pane fade show active\" id=\"modelviewer\" role=\"tabpanel\" aria-labelledby=\"modelviewer-tab\">";
html += "<iframe style=\"border:0px;width:100%;min-height: 75vh\" src=\"/mv/?embed=true&filedataid=" + filedataid + "&type=" + type + "\"></iframe>";
if (type == "m2") {
html += "<div class='modal-mvlink' style='text-align:right;'><a href='/mv/?filedataid=" + filedataid + "' target='_blank'>Open in modelviewer</a></div>";
}else if(type == "wmo"){
html += "<div class='modal-mvlink' style='text-align:right;'><a href='/mv/?filedataid=" + filedataid + "&type=wmo' target='_blank'>Open in modelviewer</a></div>";
}
html += "</div>";
html += "<div class=\"tab-pane fade\" id=\"json\" role=\"tabpanel\" aria-labelledby=\"json-tab\">";
html += "<pre style='max-height: 80vh' id='jsonHolder'></pre>";
html += "</div>";
html += "<div class=\"tab-pane fade\" id=\"modelinfo\" role=\"tabpanel\" aria-labelledby=\"modelinfo-tab\">";
html += "<div id='modelinfoHolder'></div>";
html += "</div>";
html += "</div>";

fetch("/casc/json?fileDataID=" + filedataid).then((response) => response.text()).then((text) => {
document.getElementById('jsonHolder').innerHTML = text;
});

fetch("/model/info?fileDataID=" + filedataid).then((response) => response.text()).then((text) => {
document.getElementById('modelinfoHolder').innerHTML = text;
});
} else if (type == "xml" || type == "lua" || type == "txt" || type == "srt" || type == "toc") {
fetch(url).then((response) => response.text()).then((text) => {
document.getElementById('codeHolder').innerHTML = text;
Expand Down

0 comments on commit 6dd7d4c

Please sign in to comment.