2013-04-11 11:26:57 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
2012-11-22 15:32:27 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
|
|
2012-11-27 21:12:20 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
internal class EffectUDMFVertexOffset : SectorEffect {
|
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
|
public EffectUDMFVertexOffset(SectorData data) : base(data) {
|
|
|
|
|
// New effect added: This sector needs an update!
|
|
|
|
|
if(data.Mode.VisualSectorExists(data.Sector)) {
|
|
|
|
|
BaseVisualSector vs = (BaseVisualSector)data.Mode.GetVisualSector(data.Sector);
|
|
|
|
|
vs.UpdateSectorGeometry(true);
|
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-11-22 15:32:27 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
public override void Update() {
|
|
|
|
|
// Create vertices in clockwise order
|
|
|
|
|
Vector3D[] floorVerts = new Vector3D[3];
|
|
|
|
|
Vector3D[] ceilingVerts = new Vector3D[3];
|
|
|
|
|
bool floorChanged = false;
|
|
|
|
|
bool ceilingChanged = false;
|
|
|
|
|
int index = 0;
|
2012-11-22 15:32:27 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//check vertices
|
|
|
|
|
foreach(Sidedef sd in data.Sector.Sidedefs) {
|
2012-11-22 15:32:27 +00:00
|
|
|
|
Vertex v = sd.IsFront ? sd.Line.End : sd.Line.Start;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
|
|
|
|
|
//create "normal" vertices
|
|
|
|
|
floorVerts[index] = new Vector3D(v.Position);
|
|
|
|
|
ceilingVerts[index] = new Vector3D(v.Position);
|
2012-11-22 15:32:27 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//check ceiling
|
2013-07-08 13:13:28 +00:00
|
|
|
|
if(!float.IsNaN(v.ZCeiling)) {
|
2013-03-18 13:52:27 +00:00
|
|
|
|
//vertex offset is absolute
|
2013-07-08 13:13:28 +00:00
|
|
|
|
ceilingVerts[index].z = v.ZCeiling;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
ceilingChanged = true;
|
|
|
|
|
} else {
|
|
|
|
|
ceilingVerts[index].z = data.Ceiling.plane.GetZ(v.Position);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//and floor
|
2013-07-08 13:13:28 +00:00
|
|
|
|
if(!float.IsNaN(v.ZFloor)) {
|
2013-03-18 13:52:27 +00:00
|
|
|
|
//vertex offset is absolute
|
2013-07-08 13:13:28 +00:00
|
|
|
|
floorVerts[index].z = v.ZFloor;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
floorChanged = true;
|
|
|
|
|
} else {
|
|
|
|
|
floorVerts[index].z = data.Floor.plane.GetZ(v.Position);
|
|
|
|
|
}
|
2012-11-22 15:32:27 +00:00
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
|
VertexData vd = data.Mode.GetVertexData(v);
|
2013-03-25 14:49:03 +00:00
|
|
|
|
|
|
|
|
|
foreach(Linedef line in v.Linedefs) {
|
|
|
|
|
if(line.Front != null && line.Front.Sector != null)
|
|
|
|
|
vd.AddUpdateSector(line.Front.Sector, false);
|
|
|
|
|
if(line.Back != null && line.Back.Sector != null)
|
|
|
|
|
vd.AddUpdateSector(line.Back.Sector, false);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
|
data.Mode.UpdateVertexHandle(v);
|
2012-11-22 15:32:27 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
index++;
|
|
|
|
|
}
|
2012-11-22 15:32:27 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//apply changes
|
|
|
|
|
if(ceilingChanged)
|
|
|
|
|
data.Ceiling.plane = new Plane(ceilingVerts[0], ceilingVerts[2], ceilingVerts[1], false);
|
2012-11-22 15:32:27 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
if(floorChanged)
|
|
|
|
|
data.Floor.plane = new Plane(floorVerts[0], floorVerts[1], floorVerts[2], true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-22 15:32:27 +00:00
|
|
|
|
}
|