reintegrated water changes into model viewer

This commit is contained in:
Image 2020-11-06 16:59:58 -05:00
parent fa76b7df01
commit d2ff3c4c0d
5 changed files with 143 additions and 81 deletions
EQ2/devtools/EQ2ModelViewer/EQ2ModelViewer

View file

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections.Generic;
using System.IO.Compression;
using System.Xml;
using SlimDX;
using SlimDX.D3DCompiler;
@ -302,7 +303,7 @@ namespace EQ2ModelViewer
LoadZoneFile();
}
public String DirName = "";
public static String DirName = "";
private void LoadZoneFile(String filename="")
{
bool isDrawFile = false;
@ -406,7 +407,7 @@ namespace EQ2ModelViewer
Eq2Reader reader = new Eq2Reader(new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read));
VeNode venode = reader.ReadNodeObject();
CheckNode(DirName, venode, false, null, null);
CheckNode(DirName, venode, false, null, null, false);
//MessageBox.Show("Done!");
@ -420,12 +421,11 @@ namespace EQ2ModelViewer
float scale = 0;
UInt32 widgetID;
UInt32 regionMapVersion = 1;
private void toolStripMenuItemExportWater_Click(object sender, EventArgs e)
{
StreamWriter swfile = new StreamWriter(ZoneFile + ".regionread");
using (BinaryWriter file = new BinaryWriter(File.Open(ZoneFile + ".EQ2Region", FileMode.Create)))
using (BinaryWriter file = new BinaryWriter(File.Open(ZoneFile + ".EQ2Region", FileMode.Create)))
{
file.Write(ZoneFile);
file.Write(regionMapVersion);
@ -437,18 +437,26 @@ namespace EQ2ModelViewer
regionNum += 1;
Int32 node = 0;
file.Write(region.region_type);
file.Write(region.unk4[0]);
file.Write(region.unk4[1]);
file.Write(region.unk4[2]);
file.Write(region.unk5);
file.Write(region.position[0]);
file.Write(region.position[1]);
file.Write(region.position[2]);
file.Write(region.splitdistance);
file.Write(region.vert_count);
swfile.WriteLine();
swfile.WriteLine("REGION: " + region.unk4[0] + " " + region.unk4[1] + " " + region.unk4[2] + " " + region.unk5 + " - RegionType: " + region.region_type);
swfile.WriteLine("REGION: " + region.position[0] + " " + region.position[1] + " " + region.position[2] + " " + region.splitdistance + " - RegionType: " + region.region_type);
if (region.parentNode.regionDefinitionFile != null)
swfile.WriteLine("REGIONFILE: " + region.parentNode.regionDefinitionFile);
if (region.parentNode.environmentDefinitions != null)
{
foreach (string str in region.parentNode.environmentDefinitions)
swfile.WriteLine("EnvDefinition: " + str);
}
swfile.WriteLine("EnvData: " + region.unkcount + " / " + region.parentNode.unk1 + " / " + region.parentNode.unk2);
for (ushort i = 0; i < region.vert_count; ++i)
{
Int32 regiontype = 1;
Int32 special = 0;
Int32 special = region.special;
swfile.WriteLine(node + " " + region.m_normals[i, 0] + " " + region.m_normals[i, 1] + " " +
region.m_normals[i, 2] + " " + region.m_distance[i] + " " + regiontype + " " + special + " " +
region.m_childindex[i, 0] + " " + region.m_childindex[i, 1]);
@ -470,7 +478,7 @@ namespace EQ2ModelViewer
}
UInt32 GridID;
private void CheckNode(string temp, object item, bool parentXform, object next, object parentNode)
private void CheckNode(string temp, object item, bool parentXform, object next, object parentNode, bool selectNodeParent)
{
if (item is VeMeshGeometryNode)
{
@ -519,30 +527,76 @@ namespace EQ2ModelViewer
VeEnvironmentNode env = (VeEnvironmentNode)item;
if (env.regionDefinitionFile != null && env.regionDefinitionFile.Length > 0)
{
int waterType = 0;
String envFile = "";
if (env.environmentDefinitions != null)
{
foreach (string str in env.environmentDefinitions)
{
envFile = str;
envFile = envFile.Replace("/", "\\");
envFile = DirName + envFile;
waterType = LoadEnvXmlParseLiquid(envFile);
if (waterType != 0)
break;
}
}
bool watervol = env.regionDefinitionFile.Contains("watervol");
bool waterregion = env.regionDefinitionFile.Contains("waterregion");
bool waterregion2 = env.regionDefinitionFile.Contains("water_region");
bool iswater = env.regionDefinitionFile.Contains("water");
bool isocean = env.regionDefinitionFile.Contains("ocean");
if (watervol || waterregion || waterregion2 || iswater || isocean)
bool isvolume = env.regionDefinitionFile.Contains("volume");
AppendLoadFile("Region established: " + waterType + ", " + envFile
+ " WaterVol: " + watervol + " WaterRegion: " + waterregion +
" WaterRegion2: " + waterregion2 + " IsWater: " + iswater +
" IsOcean: " + isocean + " IsVolume: " + isvolume);
if (waterType > 0)
{
AppendLoadFile("Region accepted: " + waterType + ", " + envFile
+ " WaterVol: " + watervol + " WaterRegion: " + waterregion +
" WaterRegion2: " + waterregion2 + " IsWater: " + iswater +
" IsOcean: " + isocean + " IsVolume: " + isvolume);
Eq2Reader reader2 = new Eq2Reader(new System.IO.FileStream(DirName + env.regionDefinitionFile, System.IO.FileMode.Open, System.IO.FileAccess.Read));
VeRegion region = (VeRegion)reader2.ReadObject();
region.parentNode = env;
region.region_type = 0; // default water volume
if (waterregion) // 'sea'/ocean/waterregion in tutorial_island02 / qeynos_harbor
region.region_type = 1;
else if (waterregion2)
region.region_type = 2;
else if (isocean && !iswater) // ocean in frostfang(halas)
region.region_type = 0;
else if (isvolume && selectNodeParent)
region.region_type = 4;
else if ((isocean && selectNodeParent)) // ocean in antonica/commonlands/tutorial
region.region_type = 3;
else if (isocean && iswater) // caves in frostfang(halas)
region.region_type = 4;
else if (isocean)
region.region_type = 5;
region.special = waterType;
MeshClass tmpMesh = new MeshClass();
region_nodes += region.vert_count;
m_Regions.Add(region);
}
else
{
if (env.regionDefinitionFile != null)
{
AppendLoadFile("Region skipped: " + env.regionDefinitionFile);
}
else
AppendLoadFile("Region skipped: ???");
if (env.environmentDefinitions != null)
{
foreach (string str in env.environmentDefinitions)
AppendLoadFile("EnvDefinition: " + str);
}
}
}
}
else if (item is VeRoomItemNode)
@ -591,6 +645,7 @@ namespace EQ2ModelViewer
System.Collections.IEnumerator enumerator = ((VeNode)item).EnumerateChildren();
bool parentBool = item is VeXformNode;
bool parentSelect = item is VeSelectNode;
if (enumerator.MoveNext())
{
@ -613,7 +668,7 @@ namespace EQ2ModelViewer
if (prevNode != null && prevNode is VeXformNode)
parentBool = false;
CheckNode(temp, curNode, parentBool, nextNode, newParentNode);
CheckNode(temp, curNode, parentBool, nextNode, newParentNode, selectNodeParent ? true : parentSelect);
prevNode = curNode;
@ -894,5 +949,31 @@ namespace EQ2ModelViewer
if (sender != null)
MessageBox.Show("Export Complete!");
}
private int LoadEnvXmlParseLiquid(string filename)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filename);
var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace("vdl", "Vdl");
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
XmlNode atmosphereNode = xmlDoc.SelectSingleNode("/vdl:VdlFile/vdl:Environment/vdl:iAtmosphere", nsmgr);
if (atmosphereNode != null && Convert.ToInt32(atmosphereNode.InnerText) < 0)
return Convert.ToInt32(atmosphereNode.InnerText); // lava
XmlNode liquidNode = xmlDoc.SelectSingleNode("/vdl:VdlFile/vdl:Environment/vdl:nLiquid", nsmgr);
if (liquidNode != null)
return Convert.ToInt32(liquidNode.InnerText);
}
catch (Exception ex)
{
}
return 0;
}
}
}

View file

@ -111,46 +111,6 @@ namespace EQ2ModelViewer
return true;
}
public bool InitializeBuffersExt(Device device, short[,] indices_in)
{
BufferDescription vertexBufferDesc = new BufferDescription();
BufferDescription indexBufferDesc = new BufferDescription();
DataStream vertices = new DataStream(System.Runtime.InteropServices.Marshal.SizeOf(typeof(EQ2Region)) * m_VertexCount, true, true);
DataStream indices = new DataStream(sizeof(ulong) * m_IndexCount, true, true);
for (int i = 0; i < m_VertexCount; i++)
{
vertices.Write(new Vector3(m_model[i].x, m_model[i].y, m_model[i].z));
vertices.Write(new Vector3(m_model[i].tu, m_model[i].tv, 0));
indices.Write(indices_in[i, 0]);
indices.Write(indices_in[i, 1]);
}
vertices.Position = 0;
indices.Position = 0;
vertexBufferDesc.Usage = ResourceUsage.Default;
vertexBufferDesc.SizeInBytes = (int)vertices.Length;
vertexBufferDesc.BindFlags = BindFlags.VertexBuffer;
vertexBufferDesc.CpuAccessFlags = CpuAccessFlags.None;
vertexBufferDesc.OptionFlags = ResourceOptionFlags.None;
vertexBufferDesc.StructureByteStride = 0;
m_VertexBuffer = new Buffer(device, vertices, vertexBufferDesc);
vertices.Dispose();
indexBufferDesc.Usage = ResourceUsage.Default;
indexBufferDesc.SizeInBytes = (int)indices.Length;
indexBufferDesc.BindFlags = BindFlags.IndexBuffer;
indexBufferDesc.CpuAccessFlags = CpuAccessFlags.None;
indexBufferDesc.OptionFlags = ResourceOptionFlags.None;
indexBufferDesc.StructureByteStride = 0;
m_IndexBuffer = new Buffer(device, indices, indexBufferDesc);
indices.Dispose();
return true;
}
public void RenderBuffers(DeviceContext context)
{
int stride = System.Runtime.InteropServices.Marshal.SizeOf(typeof(EQ2Model));
@ -160,15 +120,6 @@ namespace EQ2ModelViewer
context.InputAssembler.SetIndexBuffer(m_IndexBuffer, Format.R32_UInt, 0);
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
}
public void RenderBuffersExt(DeviceContext context)
{
int stride = System.Runtime.InteropServices.Marshal.SizeOf(typeof(EQ2Region));
int offset = 0;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_VertexBuffer, stride, offset));
context.InputAssembler.SetIndexBuffer(m_IndexBuffer, Format.R32_UInt, 0);
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
}
public void ShutDown()
{

View file

@ -61,6 +61,25 @@ namespace EQ2ModelViewer
public bool Initialize(Device device, VeMeshGeometryNode item, String baseDir)
{
if (item.collisionMeshName == null || item.collisionMeshName.Length < 1)
{
Console.WriteLine("No collision mesh for MeshGeometryNode");
return false;
}
VeCollisionMesh collision = null;
try
{
Eq2Reader reader2 = new Eq2Reader(new System.IO.FileStream(frmMain.DirName + item.collisionMeshName, System.IO.FileMode.Open, System.IO.FileAccess.Read));
collision = (VeCollisionMesh)reader2.ReadObject();
reader2.Dispose();
}
catch (Exception ex)
{
}
ArrayList textures = new ArrayList();
string[][] meshes = ((VeMeshGeometryNode)item).renderMeshNames;

View file

@ -69,17 +69,19 @@ namespace Everquest2.Visualization
if (classVersion >= 2)
{
//4 bytes, not sure if its a float
float unk1 = reader.ReadSingle();
unk1 = reader.ReadInt32();
}
if (classVersion >= 3)
{
byte unk2 = reader.ReadByte();
unk2 = reader.ReadByte();
}
}
public string regionDefinitionFile;
public string regionDefinitionFile;
public string[] environmentDefinitions;
public int unk1 = 0;
public int unk2 = 0;
}
}

View file

@ -29,9 +29,12 @@ using System;
#endregion
namespace Everquest2.Visualization {
public class VeRegion : VeBase {
public VeRegion() {
namespace Everquest2.Visualization
{
public class VeRegion : VeBase
{
public VeRegion()
{
}
@ -40,7 +43,8 @@ namespace Everquest2.Visualization {
/// </summary>
/// <param name="reader">Reader used to read the instance data.</param>
protected VeRegion(Util.Eq2Reader reader, Util.StreamingContext context)
: base(reader, context) {
: base(reader, context)
{
byte classVersion = context.ClassVersions[typeof(VeRegion)];
if (classVersion == 0) unk0 = reader.ReadSingle();
@ -50,7 +54,8 @@ namespace Everquest2.Visualization {
m_normals = new float[count, 3];
m_distance = new float[count];
m_childindex = new short[count, 2];
for (ushort i = 0; i < count; ++i) {
for (ushort i = 0; i < count; ++i)
{
m_normals[i, 0] = reader.ReadSingle();
m_normals[i, 1] = reader.ReadSingle();
m_normals[i, 2] = reader.ReadSingle();
@ -59,11 +64,13 @@ namespace Everquest2.Visualization {
m_childindex[i, 1] = reader.ReadInt16();
}
if (classVersion >= 2) {
uint unkcount = reader.ReadUInt32();
if (classVersion >= 2)
{
unkcount = reader.ReadUInt32();
m_center = new float[unkcount, 4];
for (int i = 0; i < unkcount; i++) {
for (int i = 0; i < unkcount; i++)
{
m_center[i, 0] = reader.ReadSingle();
m_center[i, 1] = reader.ReadSingle();
m_center[i, 2] = reader.ReadSingle();
@ -71,21 +78,23 @@ namespace Everquest2.Visualization {
}
}
unk4[0] = reader.ReadSingle();
unk4[1] = reader.ReadSingle();
unk4[2] = reader.ReadSingle();
unk5 = reader.ReadSingle();
position[0] = reader.ReadSingle();
position[1] = reader.ReadSingle();
position[2] = reader.ReadSingle();
splitdistance = reader.ReadSingle();
}
public int vert_count;
public float unk0;
public uint unkcount;
public float[,] m_normals;
public float[] m_distance;
public short[,] m_childindex;
public float[] unk4 = new float[3];
public float unk5;
public float[] position = new float[3];
public float splitdistance;
public VeEnvironmentNode parentNode;
float[,] m_center; // 1-3 is vector center, 4th is radius
public int region_type;
public int special = 0;
}
}