Tools/vmap_extractor: Move information about model type from spawns in vmap tiles to model file itself

Port From (https://github.com/TrinityCore/TrinityCore/commit/a70e758ba5eef1e8aa966cbabaee020630d2c872)
This commit is contained in:
hondacrx
2024-03-12 22:12:00 -04:00
parent 6b25d4b9b6
commit 5f0608739d
6 changed files with 36 additions and 25 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ namespace Framework.Constants
public const uint mmapMagic = 0x4D4D4150; // 'MMAP' public const uint mmapMagic = 0x4D4D4150; // 'MMAP'
public const int mmapVersion = 15; public const int mmapVersion = 15;
public const string VMapMagic = "VMAP_4.B"; public const string VMapMagic = "VMAP_4.C";
public const float VMAPInvalidHeightValue = -200000.0f; public const float VMAPInvalidHeightValue = -200000.0f;
public const uint MaxDungeonEncountersPerBoss = 4; public const uint MaxDungeonEncountersPerBoss = 4;
@@ -229,7 +229,7 @@ namespace Game.Collision
return data; return data;
} }
public WorldModel AcquireModelInstance(string filename, uint flags = 0) public WorldModel AcquireModelInstance(string filename)
{ {
lock (LoadedModelFilesLock) lock (LoadedModelFilesLock)
{ {
@@ -245,7 +245,6 @@ namespace Game.Collision
} }
Log.outDebug(LogFilter.Maps, "VMapManager: loading file '{0}'", filename); Log.outDebug(LogFilter.Maps, "VMapManager: loading file '{0}'", filename);
model.GetModel().Flags = flags;
iLoadedModelFiles.Add(filename, model); iLoadedModelFiles.Add(filename, model);
} }
+1 -1
View File
@@ -127,7 +127,7 @@ namespace Game.Collision
if (ModelSpawn.ReadFromFile(reader, out ModelSpawn spawn)) if (ModelSpawn.ReadFromFile(reader, out ModelSpawn spawn))
{ {
// acquire model instance // acquire model instance
WorldModel model = vm.AcquireModelInstance(spawn.name, spawn.flags); WorldModel model = vm.AcquireModelInstance(spawn.name);
if (model == null) if (model == null)
Log.outError(LogFilter.Server, "StaticMapTree.LoadMapTile() : could not acquire WorldModel [{0}, {1}]", tileX, tileY); Log.outError(LogFilter.Server, "StaticMapTree.LoadMapTile() : could not acquire WorldModel [{0}, {1}]", tileX, tileY);
@@ -61,7 +61,6 @@ namespace Game.Collision
iBound = rotated_bounds + iPos; iBound = rotated_bounds + iPos;
owner = modelOwner; owner = modelOwner;
isWmo = modelData.isWmo;
return true; return true;
} }
@@ -74,6 +73,12 @@ namespace Game.Collision
return mdl; return mdl;
} }
public bool IsMapObject()
{
return !iModel.IsM2();
}
public override bool IntersectRay(Ray ray, ref float maxDist, bool stopAtFirstHit, PhaseShift phaseShift, ModelIgnoreFlags ignoreFlags) public override bool IntersectRay(Ray ray, ref float maxDist, bool stopAtFirstHit, PhaseShift phaseShift, ModelIgnoreFlags ignoreFlags)
{ {
if (!IsCollisionEnabled() || !owner.IsSpawned()) if (!IsCollisionEnabled() || !owner.IsSpawned())
@@ -210,7 +215,6 @@ namespace Game.Collision
public void EnableCollision(bool enable) { _collisionEnabled = enable; } public void EnableCollision(bool enable) { _collisionEnabled = enable; }
bool IsCollisionEnabled() { return _collisionEnabled; } bool IsCollisionEnabled() { return _collisionEnabled; }
public bool IsMapObject() { return isWmo; }
public byte GetNameSetId() { return owner.GetNameSetId(); } public byte GetNameSetId() { return owner.GetNameSetId(); }
public static bool LoadGameObjectModelList() public static bool LoadGameObjectModelList()
@@ -239,13 +243,12 @@ namespace Game.Collision
break; break;
uint displayId = reader.ReadUInt32(); uint displayId = reader.ReadUInt32();
bool isWmo = reader.ReadBoolean();
int name_length = reader.ReadInt32(); int name_length = reader.ReadInt32();
string name = reader.ReadString(name_length); string name = reader.ReadString(name_length);
Vector3 v1 = reader.Read<Vector3>(); Vector3 v1 = reader.Read<Vector3>();
Vector3 v2 = reader.Read<Vector3>(); Vector3 v2 = reader.Read<Vector3>();
StaticModelList.models.Add(displayId, new GameobjectModelData(name, v1, v2, isWmo)); StaticModelList.models.Add(displayId, new GameobjectModelData(name, v1, v2));
} }
} }
catch (EndOfStreamException ex) catch (EndOfStreamException ex)
@@ -265,20 +268,17 @@ namespace Game.Collision
float iScale; float iScale;
WorldModel iModel; WorldModel iModel;
GameObjectModelOwnerBase owner; GameObjectModelOwnerBase owner;
bool isWmo;
} }
public class GameobjectModelData public class GameobjectModelData
{ {
public GameobjectModelData(string name_, Vector3 lowBound, Vector3 highBound, bool isWmo_) public GameobjectModelData(string name_, Vector3 lowBound, Vector3 highBound)
{ {
bound = new AxisAlignedBox(lowBound, highBound); bound = new AxisAlignedBox(lowBound, highBound);
name = name_; name = name_;
isWmo = isWmo_;
} }
public AxisAlignedBox bound; public AxisAlignedBox bound;
public string name; public string name;
public bool isWmo;
} }
} }
+10 -7
View File
@@ -9,11 +9,10 @@ using System.Numerics;
namespace Game.Collision namespace Game.Collision
{ {
public enum ModelFlags public enum ModelInstanceFlags
{ {
M2 = 1, HasBound = 1 << 0,
HasBound = 1 << 1, ParentSpawn = 1 << 1
ParentSpawn = 1 << 2
} }
public class ModelMinimalData public class ModelMinimalData
@@ -56,7 +55,7 @@ namespace Game.Collision
spawn.iRot = reader.Read<Vector3>(); spawn.iRot = reader.Read<Vector3>();
spawn.iScale = reader.ReadSingle(); spawn.iScale = reader.ReadSingle();
bool has_bound = Convert.ToBoolean(spawn.flags & (uint)ModelFlags.HasBound); bool has_bound = Convert.ToBoolean(spawn.flags & (uint)ModelInstanceFlags.HasBound);
if (has_bound) // only WMOs have bound in MPQ, only available after computation if (has_bound) // only WMOs have bound in MPQ, only available after computation
{ {
Vector3 bLow = reader.Read<Vector3>(); Vector3 bLow = reader.Read<Vector3>();
@@ -127,10 +126,12 @@ namespace Game.Collision
return; return;
// M2 files don't contain area info, only WMO files // M2 files don't contain area info, only WMO files
if (Convert.ToBoolean(flags & (uint)ModelFlags.M2)) if (iModel.IsM2())
return; return;
if (!iBound.contains(p)) if (!iBound.contains(p))
return; return;
// child bounds are defined in object space: // child bounds are defined in object space:
Vector3 pModel = iInvRot.Multiply(p - iPos) * iInvScale; Vector3 pModel = iInvRot.Multiply(p - iPos) * iInvScale;
Vector3 zDirModel = iInvRot.Multiply(new Vector3(0.0f, 0.0f, -1.0f)); Vector3 zDirModel = iInvRot.Multiply(new Vector3(0.0f, 0.0f, -1.0f));
@@ -172,10 +173,12 @@ namespace Game.Collision
return false; return false;
// M2 files don't contain area info, only WMO files // M2 files don't contain area info, only WMO files
if (Convert.ToBoolean(flags & (uint)ModelFlags.M2)) if (iModel.IsM2())
return false; return false;
if (!iBound.contains(p)) if (!iBound.contains(p))
return false; return false;
// child bounds are defined in object space: // child bounds are defined in object space:
Vector3 pModel = iInvRot.Multiply(p - iPos) * iInvScale; Vector3 pModel = iInvRot.Multiply(p - iPos) * iInvScale;
Vector3 zDirModel = iInvRot.Multiply(new Vector3(0.0f, 0.0f, -1.0f)); Vector3 zDirModel = iInvRot.Multiply(new Vector3(0.0f, 0.0f, -1.0f));
+12 -3
View File
@@ -290,8 +290,7 @@ namespace Game.Collision
public class WorldModel : IModel public class WorldModel : IModel
{ {
public uint Flags; ModelFlags Flags;
uint RootWMOID; uint RootWMOID;
List<GroupModel> groupModels = new(); List<GroupModel> groupModels = new();
BIH groupTree = new(); BIH groupTree = new();
@@ -302,7 +301,7 @@ namespace Game.Collision
if ((ignoreFlags & ModelIgnoreFlags.M2) != ModelIgnoreFlags.Nothing) if ((ignoreFlags & ModelIgnoreFlags.M2) != ModelIgnoreFlags.Nothing)
{ {
// M2 models are not taken into account for LoS calculation if caller requested their ignoring. // M2 models are not taken into account for LoS calculation if caller requested their ignoring.
if ((Flags & (uint)ModelFlags.M2) != 0) if (Flags.HasFlag(ModelFlags.None))
return false; return false;
} }
@@ -371,6 +370,7 @@ namespace Game.Collision
return false; return false;
reader.ReadUInt32(); //chunkSize notused reader.ReadUInt32(); //chunkSize notused
Flags = (ModelFlags)reader.ReadUInt32();
RootWMOID = reader.ReadUInt32(); RootWMOID = reader.ReadUInt32();
// read group models // read group models
@@ -391,5 +391,14 @@ namespace Game.Collision
return groupTree.ReadFromFile(reader); return groupTree.ReadFromFile(reader);
} }
public bool IsM2() { return Flags.HasFlag(ModelFlags.IsM2); }
}
[Flags]
enum ModelFlags
{
None = 0x0,
IsM2 = 0x1
} }
} }