3D floor slopes are now maintained when dragging their control sectors (#1057)

This commit is contained in:
9sphere 2024-06-16 11:47:38 +02:00 committed by GitHub
parent 6c9b3b5d91
commit 8f7104c23d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -432,7 +432,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd. Update floor/ceiling texture offsets and slopes? //mxd. Update floor/ceiling texture offsets and slopes?
if (General.Map.UDMF) if (General.Map.UDMF)
{ {
Dictionary<Sector, List<Sector>> threedfloorcontrolsectors = new Dictionary<Sector, List<Sector>>();
Vector2D offset = dragitem.Position - dragitemposition; Vector2D offset = dragitem.Position - dragitemposition;
// Sectors may've been created/removed when applying dragging... // Sectors may've been created/removed when applying dragging...
@ -441,6 +440,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Sectors that have to be updated. They contain the dragged sectors, but also 3D floor control sectors // Sectors that have to be updated. They contain the dragged sectors, but also 3D floor control sectors
HashSet<Sector> updatesectors = new HashSet<Sector>(draggedsectors); HashSet<Sector> updatesectors = new HashSet<Sector>(draggedsectors);
// Keep track of control sectors in general, and control sectors relevant to other dragged sectors
HashSet<Sector> controlsectors = new HashSet<Sector>();
HashSet<Sector> addcontrolsectors = new HashSet<Sector>();
// Check if the dragged sectors are referenced as 3D floors, and add the control sectors to the list of // Check if the dragged sectors are referenced as 3D floors, and add the control sectors to the list of
// sectors that need updating // sectors that need updating
@ -449,12 +451,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
if (ld.Action != 160) // Action 160 defines a 3D floor if (ld.Action != 160) // Action 160 defines a 3D floor
continue; continue;
if (ld.Args[0] == 0) // First argument of the action is the sector tag. 0 is not a valid value
continue;
controlsectors.Add(ld.Front.Sector);
foreach (Sector s in draggedsectors) foreach (Sector s in draggedsectors)
{ {
if (ld.Args[0] == 0 || !s.Tags.Contains(ld.Args[0])) // First argument of the action is the sector tag. 0 is not a valid value if (!s.Tags.Contains(ld.Args[0]))
continue; continue;
updatesectors.Add(ld.Front.Sector); updatesectors.Add(ld.Front.Sector);
addcontrolsectors.Add(ld.Front.Sector);
} }
} }
@ -462,6 +470,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
foreach (Sector s in updatesectors) foreach (Sector s in updatesectors)
{ {
bool updateoffsets = (draggedsectors.Contains(s) && BuilderPlug.Me.LockSectorTextureOffsetsWhileDragging) || (!draggedsectors.Contains(s) && BuilderPlug.Me.Lock3DFloorSectorTextureOffsetsWhileDragging); bool updateoffsets = (draggedsectors.Contains(s) && BuilderPlug.Me.LockSectorTextureOffsetsWhileDragging) || (!draggedsectors.Contains(s) && BuilderPlug.Me.Lock3DFloorSectorTextureOffsetsWhileDragging);
bool updateslopes = !((controlsectors.Contains(s) ^ addcontrolsectors.Contains(s)) && draggedsectors.Contains(s));
// Update texture offsets // Update texture offsets
if (updateoffsets) if (updateoffsets)
@ -524,20 +533,23 @@ namespace CodeImp.DoomBuilder.BuilderModes
} }
} }
// Update floor slope? if (updateslopes)
if (s.FloorSlope.GetLengthSq() > 0 && !double.IsNaN(s.FloorSlopeOffset / s.FloorSlope.z))
{ {
Plane floor = new Plane(s.FloorSlope, s.FloorSlopeOffset); // Update floor slope?
Vector2D center = new Vector2D(s.BBox.X + s.BBox.Width / 2, s.BBox.Y + s.BBox.Height / 2); if (s.FloorSlope.GetLengthSq() > 0 && !double.IsNaN(s.FloorSlopeOffset / s.FloorSlope.z))
s.FloorSlopeOffset = -Vector3D.DotProduct(s.FloorSlope, new Vector3D(center + offset, floor.GetZ(center))); {
} Plane floor = new Plane(s.FloorSlope, s.FloorSlopeOffset);
Vector2D center = new Vector2D(s.BBox.X + s.BBox.Width / 2, s.BBox.Y + s.BBox.Height / 2);
s.FloorSlopeOffset = -Vector3D.DotProduct(s.FloorSlope, new Vector3D(center + offset, floor.GetZ(center)));
}
// Update ceiling slope? // Update ceiling slope?
if (s.CeilSlope.GetLengthSq() > 0 && !double.IsNaN(s.CeilSlopeOffset / s.CeilSlope.z)) if (s.CeilSlope.GetLengthSq() > 0 && !double.IsNaN(s.CeilSlopeOffset / s.CeilSlope.z))
{ {
Plane ceiling = new Plane(s.CeilSlope, s.CeilSlopeOffset); Plane ceiling = new Plane(s.CeilSlope, s.CeilSlopeOffset);
Vector2D center = new Vector2D(s.BBox.X + s.BBox.Width / 2, s.BBox.Y + s.BBox.Height / 2); Vector2D center = new Vector2D(s.BBox.X + s.BBox.Width / 2, s.BBox.Y + s.BBox.Height / 2);
s.CeilSlopeOffset = -Vector3D.DotProduct(s.CeilSlope, new Vector3D(center + offset, ceiling.GetZ(center))); s.CeilSlopeOffset = -Vector3D.DotProduct(s.CeilSlope, new Vector3D(center + offset, ceiling.GetZ(center)));
}
} }
} }
} }