bool calculateTransformedBound(ModelSpawn spawn) { string modelFilename = iSrcDir + spawn.name.TrimEnd('\0'); ModelPosition modelPosition = new ModelPosition(); modelPosition.iDir = spawn.iRot; modelPosition.iScale = spawn.iScale; modelPosition.init(); WorldModel_Raw raw_model = new WorldModel_Raw(); if (!raw_model.Read(modelFilename)) { return(false); } int groups = raw_model.groupsArray.Length; if (groups != 1) { Console.WriteLine($"Warning: '{modelFilename}' does not seem to be a M2 model!"); } AxisAlignedBox modelBound = AxisAlignedBox.Zero(); modelBound.merge(modelPosition.transform(raw_model.groupsArray[0].bounds.Lo)); modelBound.merge(modelPosition.transform(raw_model.groupsArray[0].bounds.Hi)); spawn.iBound = modelBound + spawn.iPos; spawn.flags |= ModelFlags.HasBound; return(true); }
bool CalculateTransformedBound(ModelSpawn spawn) { string modelFilename = sourceDirectory + spawn.name.TrimEnd('\0'); ModelPosition modelPosition = new(); modelPosition.iDir = spawn.iRot; modelPosition.iScale = spawn.iScale; modelPosition.Init(); WorldModel_Raw raw_model = new(); if (!raw_model.Read(modelFilename)) { return(false); } int groups = raw_model.groupsArray.Length; if (groups != 1) { Console.WriteLine($"Warning: '{modelFilename}' does not seem to be a M2 model!"); } AxisAlignedBox rotated_bounds = default; for (int i = 0; i < 8; ++i) { rotated_bounds.merge(modelPosition.Transform(raw_model.groupsArray[0].bounds.corner(i))); } spawn.iBound = rotated_bounds + spawn.iPos; spawn.flags |= ModelFlags.HasBound; return(true); }
bool initialize(GameObjectModelOwnerBase modelOwner) { var modelData = StaticModelList.models.LookupByKey(modelOwner.GetDisplayId()); if (modelData == null) { return(false); } AxisAlignedBox mdl_box = new AxisAlignedBox(modelData.bound); // ignore models with no bounds if (mdl_box == AxisAlignedBox.Zero()) { Log.outError(LogFilter.Server, "GameObject model {0} has zero bounds, loading skipped", modelData.name); return(false); } iModel = Global.VMapMgr.acquireModelInstance(modelData.name); if (iModel == null) { return(false); } name = modelData.name; iPos = modelOwner.GetPosition(); iScale = modelOwner.GetScale(); iInvScale = 1.0f / iScale; Matrix3 iRotation = Matrix3.fromEulerAnglesZYX(modelOwner.GetOrientation(), 0, 0); iInvRot = iRotation.inverse(); // transform bounding box: mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale); AxisAlignedBox rotated_bounds = new AxisAlignedBox(); for (int i = 0; i < 8; ++i) { rotated_bounds.merge(iRotation * mdl_box.corner(i)); } iBound = rotated_bounds + iPos; owner = modelOwner; isWmo = modelData.isWmo; return(true); }
public bool UpdatePosition() { if (iModel == null) { return(false); } var it = StaticModelList.models.LookupByKey(owner.GetDisplayId()); if (it == null) { return(false); } AxisAlignedBox mdl_box = new AxisAlignedBox(it.bound); // ignore models with no bounds if (mdl_box == AxisAlignedBox.Zero()) { Log.outError(LogFilter.Server, "GameObject model {0} has zero bounds, loading skipped", it.name); return(false); } iPos = owner.GetPosition(); Matrix3 iRotation = Matrix3.fromEulerAnglesZYX(owner.GetOrientation(), 0, 0); iInvRot = iRotation.inverse(); // transform bounding box: mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale); AxisAlignedBox rotated_bounds = new AxisAlignedBox(); for (int i = 0; i < 8; ++i) { rotated_bounds.merge(iRotation * mdl_box.corner(i)); } iBound = rotated_bounds + iPos; return(true); }