mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 14:31:50 +00:00
@ work on (G)ZDoom Editing plugin
This commit is contained in:
parent
4b0c30cad2
commit
c502b02aa6
9 changed files with 290 additions and 258 deletions
|
@ -2443,16 +2443,15 @@ hexen
|
|||
arg1
|
||||
{
|
||||
title = "Type";
|
||||
type = 11;
|
||||
type = 12;
|
||||
enum
|
||||
{
|
||||
0 = "Vavoom-Style";
|
||||
1 = "Solid";
|
||||
2 = "Swimmable";
|
||||
3 = "Non-Solid";
|
||||
4 = "Render-Inside";
|
||||
16 = "Inverted Visibility Rules";
|
||||
32 = "Shootability Rules";
|
||||
4 = "Render inside";
|
||||
16 = "Inverted visibility rules";
|
||||
32 = "Inverted shootability rules";
|
||||
}
|
||||
}
|
||||
arg2
|
||||
|
|
|
@ -108,7 +108,49 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
u_ray = pickrayu;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// This slices a polygon with a plane and keeps only a certain part of the polygon
|
||||
protected void SlicePoly(List<Vector3D> poly, Plane p, bool keepfront)
|
||||
{
|
||||
const float NEAR_ZERO = 0.01f;
|
||||
|
||||
// TODO: We can optimize this by making a list of vertices in the first iteration which
|
||||
// indicates which vertices are on the back side. Then we don't need to calculate p.Distance(v)
|
||||
// again in the second iteration.
|
||||
|
||||
// First split lines that cross the plane so that we have vertices on the plane where the lines cross
|
||||
for(int i = 0; i < poly.Count; i++)
|
||||
{
|
||||
Vector3D v1 = poly[i];
|
||||
Vector3D v2 = (i == (poly.Count - 1)) ? poly[0] : poly[i+1];
|
||||
|
||||
// Determine side of plane
|
||||
float side0 = p.Distance(v1);
|
||||
float side1 = p.Distance(v2);
|
||||
|
||||
// Vertices on different side of plane?
|
||||
if((side0 < -NEAR_ZERO) && (side1 > NEAR_ZERO) ||
|
||||
(side0 > NEAR_ZERO) && (side1 < -NEAR_ZERO))
|
||||
{
|
||||
// Split line with plane and insert the vertex
|
||||
float u = 0.0f;
|
||||
p.GetIntersection(v1, v2, ref u);
|
||||
Vector3D v3 = v1 + (v2 - v1) * u;
|
||||
poly.Insert(++i, v3);
|
||||
}
|
||||
}
|
||||
|
||||
// Now we discard all vertices on the back side of the plane
|
||||
int k = poly.Count - 1;
|
||||
while(k >= 0)
|
||||
{
|
||||
float side = p.Distance(poly[k]);
|
||||
if(((side < -NEAR_ZERO) && keepfront) || ((side > NEAR_ZERO) && !keepfront))
|
||||
poly.RemoveAt(k);
|
||||
k--;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Events
|
||||
|
|
|
@ -118,6 +118,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
if(isbuilding) return;
|
||||
isbuilding = true;
|
||||
|
||||
levels.Clear();
|
||||
|
||||
foreach(Linedef l in linedefs)
|
||||
{
|
||||
// ========== Plane Align (see http://zdoom.org/wiki/Plane_Align) ==========
|
||||
|
@ -199,11 +201,18 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
SectorLevel f = new SectorLevel(sd.Floor);
|
||||
SectorLevel c = new SectorLevel(sd.Ceiling);
|
||||
|
||||
// For non-vavoom types, we must switch the level types
|
||||
if((l.Args[1] & 0x03) != 0)
|
||||
{
|
||||
f.type = SectorLevelType.Ceiling;
|
||||
c.type = SectorLevelType.Floor;
|
||||
}
|
||||
|
||||
// A 3D floor's color is always that of the sector it is placed in
|
||||
f.color = 0;
|
||||
|
||||
// Do not adjust light?
|
||||
if((l.Args[2] & 1) != 0)
|
||||
// Do not adjust light? (works only for non-vavoom types)
|
||||
if(((l.Args[2] & 1) != 0) && ((l.Args[1] & 0x03) != 0))
|
||||
{
|
||||
f.brightnessbelow = -1;
|
||||
f.colorbelow = PixelColor.FromInt(0);
|
||||
|
@ -297,6 +306,10 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
|
||||
// Sort the levels
|
||||
levels.Sort();
|
||||
|
||||
// Floor is always first, ceiling always last
|
||||
levels.Add(ceiling);
|
||||
levels.Insert(0, floor);
|
||||
|
||||
// Now that we know the levels in this sector (and in the right order) we
|
||||
// can determine the lighting in between and on the levels.
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
Vector3D v31 = vrb - vlt;
|
||||
Vector3D v21 = vrt - vlt;
|
||||
Vector3D vp1 = p - vlt;
|
||||
|
||||
|
||||
// Compute dot products
|
||||
float d00 = Vector3D.DotProduct(v31, v31);
|
||||
float d01 = Vector3D.DotProduct(v31, v21);
|
||||
|
|
|
@ -174,9 +174,10 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// This performs a fast test in object picking
|
||||
public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir)
|
||||
{
|
||||
/*
|
||||
if(level.plane.Distance(from) < 0.0f)
|
||||
// Check if our ray starts at the correct side of the plane
|
||||
if(level.plane.Distance(from) > 0.0f)
|
||||
{
|
||||
// Calculate the intersection
|
||||
if(level.plane.GetIntersection(from, to, ref pickrayu))
|
||||
{
|
||||
if(pickrayu > 0.0f)
|
||||
|
@ -190,7 +191,6 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -61,10 +61,25 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
||||
// This builds the geometry. Returns false when no geometry created.
|
||||
public override bool Setup()
|
||||
{
|
||||
Vector2D vl, vr;
|
||||
|
||||
// Left and right vertices for this sidedef
|
||||
if(Sidedef.IsFront)
|
||||
{
|
||||
vl = new Vector2D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y);
|
||||
vr = new Vector2D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
vl = new Vector2D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y);
|
||||
vr = new Vector2D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y);
|
||||
}
|
||||
|
||||
// Load sector data
|
||||
SectorData sd = Sector.Data;
|
||||
SectorData osd = mode.GetSectorData(Sidedef.Other.Sector);
|
||||
if(!osd.Built) osd.BuildLevels(mode);
|
||||
|
@ -91,7 +106,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
base.Texture = General.Map.Data.MissingTexture3D;
|
||||
setuponloadedtexture = 0;
|
||||
}
|
||||
|
||||
|
||||
// Get texture scaled size
|
||||
Vector2D tsz = new Vector2D(base.Texture.ScaledWidth, base.Texture.ScaledHeight);
|
||||
|
||||
|
@ -99,15 +114,18 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// We can then use this plane to find any texture coordinate we need.
|
||||
// The logic here is the same as in the original VisualMiddleSingle (except that
|
||||
// the values are stored in a TexturePlane)
|
||||
// NOTE: I use a small bias for the floor height, because if the difference in
|
||||
// height is 0 then the TexturePlane doesn't work!
|
||||
TexturePlane tp = new TexturePlane();
|
||||
float floorbias = (Sidedef.Other.Sector.FloorHeight == Sidedef.Sector.FloorHeight) ? 1.0f : 0.0f;
|
||||
if(Sidedef.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag))
|
||||
{
|
||||
// When lower unpegged is set, the lower texture is bound to the bottom
|
||||
tp.tlt.y = (float)Sidedef.Sector.CeilHeight - (float)Sidedef.Other.Sector.FloorHeight;
|
||||
}
|
||||
tp.trb.x = tp.tlt.x + Sidedef.Line.Length;
|
||||
tp.trb.y = tp.tlt.y + (float)(Sidedef.Other.Sector.FloorHeight - Sidedef.Sector.FloorHeight);
|
||||
|
||||
tp.trb.y = tp.tlt.y + ((float)Sidedef.Other.Sector.FloorHeight - ((float)Sidedef.Sector.FloorHeight + floorbias));
|
||||
|
||||
// Apply texture offset
|
||||
if (General.Map.Config.ScaledTextureOffsets && !base.Texture.WorldPanning)
|
||||
{
|
||||
|
@ -119,64 +137,48 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
tp.tlt += new Vector2D(Sidedef.OffsetX, Sidedef.OffsetY);
|
||||
tp.trb += new Vector2D(Sidedef.OffsetX, Sidedef.OffsetY);
|
||||
}
|
||||
|
||||
|
||||
// Transform pixel coordinates to texture coordinates
|
||||
tp.tlt /= tsz;
|
||||
tp.trb /= tsz;
|
||||
|
||||
|
||||
// Left top and right bottom of the geometry that
|
||||
if(Sidedef.IsFront)
|
||||
{
|
||||
tp.vlt = new Vector3D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y, Sidedef.Other.Sector.FloorHeight);
|
||||
tp.vrb = new Vector3D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y, Sidedef.Sector.FloorHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
tp.vlt = new Vector3D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y, Sidedef.Other.Sector.FloorHeight);
|
||||
tp.vrb = new Vector3D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y, Sidedef.Sector.FloorHeight);
|
||||
}
|
||||
tp.vlt = new Vector3D(vl.x, vl.y, (float)Sidedef.Other.Sector.FloorHeight);
|
||||
tp.vrb = new Vector3D(vr.x, vr.y, (float)Sidedef.Sector.FloorHeight + floorbias);
|
||||
|
||||
// Make the right-top coordinates
|
||||
tp.trt = new Vector2D(tp.trb.x, tp.tlt.y);
|
||||
tp.vrt = new Vector3D(tp.vrb.x, tp.vrb.y, tp.vlt.z);
|
||||
|
||||
// Heights of the floor on the other side
|
||||
float ol = osd.Floor.plane.GetZ(tp.vlt);
|
||||
float or = osd.Floor.plane.GetZ(tp.vrt);
|
||||
Vector3D vol = new Vector3D(tp.vlt.x, tp.vlt.y, ol);
|
||||
Vector3D vor = new Vector3D(tp.vrt.x, tp.vrt.y, or);
|
||||
|
||||
if(Sidedef.Index == 215)
|
||||
{
|
||||
int g = 5;
|
||||
}
|
||||
|
||||
// Go for all levels to build geometry
|
||||
List<WorldVertex> verts = new List<WorldVertex>();
|
||||
for(int i = 0; i < (sd.Levels.Count - 1); i++)
|
||||
for(int i = 1; i < sd.Levels.Count; i++)
|
||||
{
|
||||
SectorLevel lb = sd.Levels[i];
|
||||
SectorLevel lt = sd.Levels[i + 1];
|
||||
SectorLevel l = sd.Levels[i];
|
||||
|
||||
PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lt.brightnessbelow));
|
||||
PixelColor wallcolor = PixelColor.Modulate(lt.colorbelow, wallbrightness);
|
||||
PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(l.brightnessbelow));
|
||||
PixelColor wallcolor = PixelColor.Modulate(l.colorbelow, wallbrightness);
|
||||
int c = wallcolor.WithAlpha(255).ToInt();
|
||||
|
||||
// Create initial polygon between the two planes
|
||||
// Create initial polygon, which is just a quad between floor and ceiling
|
||||
List<Vector3D> poly = new List<Vector3D>();
|
||||
poly.Add(new Vector3D(tp.vlt.x, tp.vlt.y, lb.plane.GetZ(tp.vlt)));
|
||||
poly.Add(new Vector3D(tp.vlt.x, tp.vlt.y, lt.plane.GetZ(tp.vlt)));
|
||||
poly.Add(new Vector3D(tp.vrt.x, tp.vrt.y, lt.plane.GetZ(tp.vrt)));
|
||||
poly.Add(new Vector3D(tp.vrb.x, tp.vrb.y, lb.plane.GetZ(tp.vrt)));
|
||||
poly.Add(new Vector3D(vl.x, vl.y, sd.Floor.plane.GetZ(vl)));
|
||||
poly.Add(new Vector3D(vl.x, vl.y, sd.Ceiling.plane.GetZ(vl)));
|
||||
poly.Add(new Vector3D(vr.x, vr.y, sd.Ceiling.plane.GetZ(vr)));
|
||||
poly.Add(new Vector3D(vr.x, vr.y, sd.Floor.plane.GetZ(vr)));
|
||||
|
||||
// Slice off the part above the other plane
|
||||
SlicePoly(poly, osd.Floor.plane, false);
|
||||
SlicePoly(poly, osd.Ceiling.plane, true);
|
||||
|
||||
// Now we go for all planes to splice this polygon
|
||||
// Now we go for all light planes to splice this polygon
|
||||
for(int k = 0; k < sd.Levels.Count; k++)
|
||||
{
|
||||
if((k != i) && (k != (i + 1)))
|
||||
SlicePoly(poly, sd.Levels[k].plane, (k > i) || (sd.Levels[k].type == SectorLevelType.Floor));
|
||||
SectorLevel ol = sd.Levels[k];
|
||||
if((ol != sd.Floor) && (ol != sd.Ceiling) && (ol.type != SectorLevelType.Floor))
|
||||
{
|
||||
SlicePoly(poly, ol.plane, (k >= i));
|
||||
}
|
||||
}
|
||||
|
||||
// Find texture coordinates for each vertex in the polygon
|
||||
|
@ -184,7 +186,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
foreach(Vector3D v in poly)
|
||||
texc.Add(tp.GetTextureCoordsAt(v));
|
||||
|
||||
// Now we create triangles from the polygon
|
||||
// Now we create triangles from the polygon.
|
||||
// The polygon is convex and clockwise, so this is a piece of cake.
|
||||
if(poly.Count >= 3)
|
||||
{
|
||||
for(int k = 1; k < (poly.Count - 1); k++)
|
||||
|
@ -207,48 +210,6 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
}
|
||||
}
|
||||
|
||||
// This slices a polygon with a plane and keeps only a certain part of the polygon
|
||||
private void SlicePoly(List<Vector3D> poly, Plane p, bool keepfront)
|
||||
{
|
||||
const float NEAR_ZERO = 0.0001f;
|
||||
|
||||
// TODO: We can optimize this by making a list of vertices in the first iteration which
|
||||
// indicates which vertices are on the back side. Then we don't need to calculate p.Distance(v)
|
||||
// again in the second iteration.
|
||||
|
||||
// First split lines that cross the plane so that we have vertices on the plane where the lines cross
|
||||
for(int i = 0; i < poly.Count; i++)
|
||||
{
|
||||
Vector3D v1 = poly[i];
|
||||
Vector3D v2 = (i == (poly.Count - 1)) ? poly[0] : poly[i+1];
|
||||
|
||||
// Determine side of plane
|
||||
float side0 = p.Distance(v1);
|
||||
float side1 = p.Distance(v2);
|
||||
|
||||
// Vertices on different side of plane?
|
||||
if((side0 < -NEAR_ZERO) && (side1 > NEAR_ZERO) ||
|
||||
(side0 > NEAR_ZERO) && (side1 < -NEAR_ZERO))
|
||||
{
|
||||
// Split line with plane and insert the vertex
|
||||
float u = 0.0f;
|
||||
p.GetIntersection(v1, v2, ref u);
|
||||
Vector3D v3 = v1 + (v2 - v1) * u;
|
||||
poly.Insert(++i, v3);
|
||||
}
|
||||
}
|
||||
|
||||
// Now we discard all vertices on the back side of the plane
|
||||
int k = poly.Count - 1;
|
||||
while(k >= 0)
|
||||
{
|
||||
float side = p.Distance(poly[k]);
|
||||
if(((side < -NEAR_ZERO) && keepfront) || ((side > NEAR_ZERO) && !keepfront))
|
||||
poly.RemoveAt(k);
|
||||
k--;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
|
|
@ -65,6 +65,21 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// This builds the geometry. Returns false when no geometry created.
|
||||
public override bool Setup()
|
||||
{
|
||||
Vector2D vl, vr;
|
||||
|
||||
// Left and right vertices for this sidedef
|
||||
if(Sidedef.IsFront)
|
||||
{
|
||||
vl = new Vector2D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y);
|
||||
vr = new Vector2D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
vl = new Vector2D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y);
|
||||
vr = new Vector2D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y);
|
||||
}
|
||||
|
||||
// Load sector data
|
||||
SectorData sd = mode.GetSectorData(Sidedef.Sector);
|
||||
|
||||
// Texture given?
|
||||
|
@ -97,14 +112,17 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// We can then use this plane to find any texture coordinate we need.
|
||||
// The logic here is the same as in the original VisualMiddleSingle (except that
|
||||
// the values are stored in a TexturePlane)
|
||||
// NOTE: I use a small bias for the floor height, because if the difference in
|
||||
// height is 0 then the TexturePlane doesn't work!
|
||||
TexturePlane tp = new TexturePlane();
|
||||
float floorbias = (Sidedef.Sector.CeilHeight == Sidedef.Sector.FloorHeight) ? 1.0f : 0.0f;
|
||||
if(Sidedef.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag))
|
||||
{
|
||||
// When lower unpegged is set, the middle texture is bound to the bottom
|
||||
tp.tlt.y = tsz.y - (float)(Sidedef.Sector.CeilHeight - Sidedef.Sector.FloorHeight);
|
||||
}
|
||||
tp.trb.x = tp.tlt.x + Sidedef.Line.Length;
|
||||
tp.trb.y = tp.tlt.y + (float)(Sidedef.Sector.CeilHeight - Sidedef.Sector.FloorHeight);
|
||||
tp.trb.y = tp.tlt.y + ((float)Sidedef.Sector.CeilHeight - ((float)Sidedef.Sector.FloorHeight + floorbias));
|
||||
|
||||
// Apply texture offset
|
||||
if (General.Map.Config.ScaledTextureOffsets && !base.Texture.WorldPanning)
|
||||
|
@ -123,94 +141,54 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
tp.trb /= tsz;
|
||||
|
||||
// Left top and right bottom of the geometry that
|
||||
if(Sidedef.IsFront)
|
||||
{
|
||||
tp.vlt = new Vector3D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y, Sidedef.Sector.CeilHeight);
|
||||
tp.vrb = new Vector3D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y, Sidedef.Sector.FloorHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
tp.vlt = new Vector3D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y, Sidedef.Sector.CeilHeight);
|
||||
tp.vrb = new Vector3D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y, Sidedef.Sector.FloorHeight);
|
||||
}
|
||||
tp.vlt = new Vector3D(vl.x, vl.y, (float)Sidedef.Sector.CeilHeight);
|
||||
tp.vrb = new Vector3D(vr.x, vr.y, (float)Sidedef.Sector.FloorHeight + floorbias);
|
||||
|
||||
// Make the right-top coordinates
|
||||
tp.trt = new Vector2D(tp.trb.x, tp.tlt.y);
|
||||
tp.vrt = new Vector3D(tp.vrb.x, tp.vrb.y, tp.vlt.z);
|
||||
|
||||
//
|
||||
// - Geometry is horizontally split and ranges from one layer down to the next layer.
|
||||
// This is repeated for all layers.
|
||||
//
|
||||
// - When the two layers intersect over Z, the geometry should not span the entire
|
||||
// width, but only up to the split position. The back side will handle the other
|
||||
// side of the split, if needed.
|
||||
//
|
||||
|
||||
// Go for all levels to build geometry
|
||||
List<WorldVertex> verts = new List<WorldVertex>();
|
||||
for(int i = 0; i < (sd.Levels.Count - 1); i++)
|
||||
for(int i = 1; i < sd.Levels.Count; i++)
|
||||
{
|
||||
SectorLevel lb = sd.Levels[i];
|
||||
SectorLevel lt = sd.Levels[i + 1];
|
||||
if(lt.type != SectorLevelType.Floor)
|
||||
SectorLevel l = sd.Levels[i];
|
||||
|
||||
PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(l.brightnessbelow));
|
||||
PixelColor wallcolor = PixelColor.Modulate(l.colorbelow, wallbrightness);
|
||||
int c = wallcolor.WithAlpha(255).ToInt();
|
||||
|
||||
// Create initial polygon, which is just a quad between floor and ceiling
|
||||
List<Vector3D> poly = new List<Vector3D>();
|
||||
poly.Add(new Vector3D(vl.x, vl.y, sd.Floor.plane.GetZ(vl)));
|
||||
poly.Add(new Vector3D(vl.x, vl.y, sd.Ceiling.plane.GetZ(vl)));
|
||||
poly.Add(new Vector3D(vr.x, vr.y, sd.Ceiling.plane.GetZ(vr)));
|
||||
poly.Add(new Vector3D(vr.x, vr.y, sd.Floor.plane.GetZ(vr)));
|
||||
|
||||
// Now we go for all light planes to splice this polygon
|
||||
for(int k = 0; k < sd.Levels.Count; k++)
|
||||
{
|
||||
PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lt.brightnessbelow));
|
||||
PixelColor wallcolor = PixelColor.Modulate(lt.colorbelow, wallbrightness);
|
||||
int c = wallcolor.WithAlpha(255).ToInt();
|
||||
|
||||
// Get corner heights on the two planes
|
||||
float lbl = lb.plane.GetZ(tp.vlt);
|
||||
float lbr = lb.plane.GetZ(tp.vrt);
|
||||
float ltl = lt.plane.GetZ(tp.vlt);
|
||||
float ltr = lt.plane.GetZ(tp.vrt);
|
||||
|
||||
// Make coordinates for the corners
|
||||
Vector3D vlb = new Vector3D(tp.vlt.x, tp.vlt.y, lbl);
|
||||
Vector3D vlt = new Vector3D(tp.vlt.x, tp.vlt.y, ltl);
|
||||
Vector3D vrb = new Vector3D(tp.vrb.x, tp.vrb.y, lbr);
|
||||
Vector3D vrt = new Vector3D(tp.vrt.x, tp.vrt.y, ltr);
|
||||
|
||||
// Compare corner heights to see if we should split
|
||||
if((lbl < ltl) && (lbr >= ltr))
|
||||
SectorLevel ol = sd.Levels[k];
|
||||
if((ol != sd.Floor) && (ol != sd.Ceiling) && (ol.type != SectorLevelType.Floor))
|
||||
{
|
||||
// Split vertically with geometry on the left
|
||||
float u_ray = 1.0f;
|
||||
lb.plane.GetIntersection(vlt, vrt, ref u_ray);
|
||||
Vector3D vs = vlt + (vrt - vlt) * u_ray;
|
||||
Vector2D tlb = tp.GetTextureCoordsAt(vlb);
|
||||
Vector2D tlt = tp.GetTextureCoordsAt(vlt);
|
||||
Vector2D ts = tp.GetTextureCoordsAt(vs);
|
||||
verts.Add(new WorldVertex(vlb.x, vlb.y, vlb.z, c, tlb.x, tlb.y));
|
||||
verts.Add(new WorldVertex(vlt.x, vlt.y, vlt.z, c, tlt.x, tlt.y));
|
||||
verts.Add(new WorldVertex(vs.x, vs.y, vs.z, c, ts.x, ts.y));
|
||||
SlicePoly(poly, ol.plane, (k >= i));
|
||||
}
|
||||
else if((lbl >= ltl) && (lbr < ltr))
|
||||
}
|
||||
|
||||
// Find texture coordinates for each vertex in the polygon
|
||||
List<Vector2D> texc = new List<Vector2D>(poly.Count);
|
||||
foreach(Vector3D v in poly)
|
||||
texc.Add(tp.GetTextureCoordsAt(v));
|
||||
|
||||
// Now we create triangles from the polygon.
|
||||
// The polygon is convex and clockwise, so this is a piece of cake.
|
||||
if(poly.Count >= 3)
|
||||
{
|
||||
for(int k = 1; k < (poly.Count - 1); k++)
|
||||
{
|
||||
// Split vertically with geometry on the right
|
||||
float u_ray = 0.0f;
|
||||
lb.plane.GetIntersection(vlt, vrt, ref u_ray);
|
||||
Vector3D vs = vlt + (vrt - vlt) * u_ray;
|
||||
Vector2D trb = tp.GetTextureCoordsAt(vrb);
|
||||
Vector2D trt = tp.GetTextureCoordsAt(vrt);
|
||||
Vector2D ts = tp.GetTextureCoordsAt(vs);
|
||||
verts.Add(new WorldVertex(vs.x, vs.y, vs.z, c, ts.x, ts.y));
|
||||
verts.Add(new WorldVertex(vrt.x, vrt.y, vrt.z, c, trt.x, trt.y));
|
||||
verts.Add(new WorldVertex(vrb.x, vrb.y, vrb.z, c, trb.x, trb.y));
|
||||
}
|
||||
else if((lbl < ltl) && (lbr < ltr))
|
||||
{
|
||||
// Span entire width
|
||||
Vector2D tlb = tp.GetTextureCoordsAt(vlb);
|
||||
Vector2D tlt = tp.GetTextureCoordsAt(vlt);
|
||||
Vector2D trb = tp.GetTextureCoordsAt(vrb);
|
||||
Vector2D trt = tp.GetTextureCoordsAt(vrt);
|
||||
verts.Add(new WorldVertex(vlb.x, vlb.y, vlb.z, c, tlb.x, tlb.y));
|
||||
verts.Add(new WorldVertex(vlt.x, vlt.y, vlt.z, c, tlt.x, tlt.y));
|
||||
verts.Add(new WorldVertex(vrt.x, vrt.y, vrt.z, c, trt.x, trt.y));
|
||||
verts.Add(new WorldVertex(vlb.x, vlb.y, vlb.z, c, tlb.x, tlb.y));
|
||||
verts.Add(new WorldVertex(vrt.x, vrt.y, vrt.z, c, trt.x, trt.y));
|
||||
verts.Add(new WorldVertex(vrb.x, vrb.y, vrb.z, c, trb.x, trb.y));
|
||||
verts.Add(new WorldVertex(poly[0], c, texc[0]));
|
||||
verts.Add(new WorldVertex(poly[k], c, texc[k]));
|
||||
verts.Add(new WorldVertex(poly[k + 1], c, texc[k + 1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,107 +66,146 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// This builds the geometry. Returns false when no geometry created.
|
||||
public override bool Setup()
|
||||
{
|
||||
int brightness = mode.CalculateBrightness(Sidedef.Sector.Brightness);
|
||||
|
||||
// Calculate size of this wall part
|
||||
float geotop = (float)Sidedef.Sector.CeilHeight;
|
||||
float geobottom = (float)Sidedef.Other.Sector.CeilHeight;
|
||||
float geoheight = geotop - geobottom;
|
||||
if(geoheight > 0.001f)
|
||||
Vector2D vl, vr;
|
||||
|
||||
// Left and right vertices for this sidedef
|
||||
if(Sidedef.IsFront)
|
||||
{
|
||||
Vector2D t1 = new Vector2D();
|
||||
Vector2D t2 = new Vector2D();
|
||||
|
||||
// Texture given?
|
||||
if((Sidedef.HighTexture.Length > 0) && (Sidedef.HighTexture[0] != '-'))
|
||||
vl = new Vector2D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y);
|
||||
vr = new Vector2D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
vl = new Vector2D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y);
|
||||
vr = new Vector2D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y);
|
||||
}
|
||||
|
||||
// Load sector data
|
||||
SectorData sd = Sector.Data;
|
||||
SectorData osd = mode.GetSectorData(Sidedef.Other.Sector);
|
||||
if(!osd.Built) osd.BuildLevels(mode);
|
||||
|
||||
// Texture given?
|
||||
if((Sidedef.HighTexture.Length > 0) && (Sidedef.HighTexture[0] != '-'))
|
||||
{
|
||||
// Load texture
|
||||
base.Texture = General.Map.Data.GetTextureImage(Sidedef.LongHighTexture);
|
||||
if(base.Texture == null)
|
||||
{
|
||||
// Load texture
|
||||
base.Texture = General.Map.Data.GetTextureImage(Sidedef.LongHighTexture);
|
||||
if(base.Texture == null)
|
||||
{
|
||||
base.Texture = General.Map.Data.MissingTexture3D;
|
||||
setuponloadedtexture = Sidedef.LongHighTexture;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!base.Texture.IsImageLoaded)
|
||||
setuponloadedtexture = Sidedef.LongHighTexture;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use missing texture
|
||||
base.Texture = General.Map.Data.MissingTexture3D;
|
||||
setuponloadedtexture = 0;
|
||||
}
|
||||
|
||||
// Get texture scaled size
|
||||
Vector2D tsz = new Vector2D(base.Texture.ScaledWidth, base.Texture.ScaledHeight);
|
||||
|
||||
// Determine texture coordinates
|
||||
// See http://doom.wikia.com/wiki/Texture_alignment
|
||||
// We just use pixels for coordinates for now
|
||||
if(!Sidedef.Line.IsFlagSet(General.Map.Config.UpperUnpeggedFlag))
|
||||
{
|
||||
// When upper unpegged is NOT set, the upper texture is bound to the bottom
|
||||
t1.y = tsz.y - geoheight;
|
||||
}
|
||||
t2.x = t1.x + Sidedef.Line.Length;
|
||||
t2.y = t1.y + geoheight;
|
||||
|
||||
// Apply texture offset
|
||||
if (General.Map.Config.ScaledTextureOffsets && !base.Texture.WorldPanning)
|
||||
{
|
||||
t1 += new Vector2D(Sidedef.OffsetX * base.Texture.Scale.x, Sidedef.OffsetY * base.Texture.Scale.y);
|
||||
t2 += new Vector2D(Sidedef.OffsetX * base.Texture.Scale.x, Sidedef.OffsetY * base.Texture.Scale.y);
|
||||
setuponloadedtexture = Sidedef.LongHighTexture;
|
||||
}
|
||||
else
|
||||
{
|
||||
t1 += new Vector2D(Sidedef.OffsetX, Sidedef.OffsetY);
|
||||
t2 += new Vector2D(Sidedef.OffsetX, Sidedef.OffsetY);
|
||||
if(!base.Texture.IsImageLoaded)
|
||||
setuponloadedtexture = Sidedef.LongHighTexture;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use missing texture
|
||||
base.Texture = General.Map.Data.MissingTexture3D;
|
||||
setuponloadedtexture = 0;
|
||||
}
|
||||
|
||||
// Transform pixel coordinates to texture coordinates
|
||||
t1 /= tsz;
|
||||
t2 /= tsz;
|
||||
|
||||
// Get world coordinates for geometry
|
||||
Vector2D v1, v2;
|
||||
if(Sidedef.IsFront)
|
||||
{
|
||||
v1 = Sidedef.Line.Start.Position;
|
||||
v2 = Sidedef.Line.End.Position;
|
||||
}
|
||||
else
|
||||
{
|
||||
v1 = Sidedef.Line.End.Position;
|
||||
v2 = Sidedef.Line.Start.Position;
|
||||
}
|
||||
|
||||
// Make vertices
|
||||
WorldVertex[] verts = new WorldVertex[6];
|
||||
verts[0] = new WorldVertex(v1.x, v1.y, geobottom, brightness, t1.x, t2.y);
|
||||
verts[1] = new WorldVertex(v1.x, v1.y, geotop, brightness, t1.x, t1.y);
|
||||
verts[2] = new WorldVertex(v2.x, v2.y, geotop, brightness, t2.x, t1.y);
|
||||
verts[3] = verts[0];
|
||||
verts[4] = verts[2];
|
||||
verts[5] = new WorldVertex(v2.x, v2.y, geobottom, brightness, t2.x, t2.y);
|
||||
// Get texture scaled size
|
||||
Vector2D tsz = new Vector2D(base.Texture.ScaledWidth, base.Texture.ScaledHeight);
|
||||
|
||||
// Determine texture coordinates plane as they would be in normal circumstances.
|
||||
// We can then use this plane to find any texture coordinate we need.
|
||||
// The logic here is the same as in the original VisualMiddleSingle (except that
|
||||
// the values are stored in a TexturePlane)
|
||||
// NOTE: I use a small bias for the floor height, because if the difference in
|
||||
// height is 0 then the TexturePlane doesn't work!
|
||||
TexturePlane tp = new TexturePlane();
|
||||
float ceilbias = (Sidedef.Other.Sector.CeilHeight == Sidedef.Sector.CeilHeight) ? 1.0f : 0.0f;
|
||||
if(!Sidedef.Line.IsFlagSet(General.Map.Config.UpperUnpeggedFlag))
|
||||
{
|
||||
// When lower unpegged is set, the lower texture is bound to the bottom
|
||||
tp.tlt.y = tsz.y - ((float)Sidedef.Sector.CeilHeight - (float)Sidedef.Other.Sector.CeilHeight);
|
||||
}
|
||||
tp.trb.x = tp.tlt.x + Sidedef.Line.Length;
|
||||
tp.trb.y = tp.tlt.y + ((float)Sidedef.Sector.CeilHeight - ((float)Sidedef.Other.Sector.CeilHeight + ceilbias));
|
||||
|
||||
// Apply texture offset
|
||||
if (General.Map.Config.ScaledTextureOffsets && !base.Texture.WorldPanning)
|
||||
{
|
||||
tp.tlt += new Vector2D(Sidedef.OffsetX * base.Texture.Scale.x, Sidedef.OffsetY * base.Texture.Scale.y);
|
||||
tp.trb += new Vector2D(Sidedef.OffsetX * base.Texture.Scale.x, Sidedef.OffsetY * base.Texture.Scale.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
tp.tlt += new Vector2D(Sidedef.OffsetX, Sidedef.OffsetY);
|
||||
tp.trb += new Vector2D(Sidedef.OffsetX, Sidedef.OffsetY);
|
||||
}
|
||||
|
||||
// Transform pixel coordinates to texture coordinates
|
||||
tp.tlt /= tsz;
|
||||
tp.trb /= tsz;
|
||||
|
||||
// Left top and right bottom of the geometry that
|
||||
tp.vlt = new Vector3D(vl.x, vl.y, (float)Sidedef.Sector.CeilHeight);
|
||||
tp.vrb = new Vector3D(vr.x, vr.y, (float)Sidedef.Other.Sector.CeilHeight + ceilbias);
|
||||
|
||||
// Make the right-top coordinates
|
||||
tp.trt = new Vector2D(tp.trb.x, tp.tlt.y);
|
||||
tp.vrt = new Vector3D(tp.vrb.x, tp.vrb.y, tp.vlt.z);
|
||||
|
||||
// Go for all levels to build geometry
|
||||
List<WorldVertex> verts = new List<WorldVertex>();
|
||||
for(int i = 1; i < sd.Levels.Count; i++)
|
||||
{
|
||||
SectorLevel l = sd.Levels[i];
|
||||
|
||||
// Keep properties
|
||||
base.top = geotop;
|
||||
base.bottom = geobottom;
|
||||
PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(l.brightnessbelow));
|
||||
PixelColor wallcolor = PixelColor.Modulate(l.colorbelow, wallbrightness);
|
||||
int c = wallcolor.WithAlpha(255).ToInt();
|
||||
|
||||
// Apply vertices
|
||||
// Create initial polygon, which is just a quad between floor and ceiling
|
||||
List<Vector3D> poly = new List<Vector3D>();
|
||||
poly.Add(new Vector3D(vl.x, vl.y, sd.Floor.plane.GetZ(vl)));
|
||||
poly.Add(new Vector3D(vl.x, vl.y, sd.Ceiling.plane.GetZ(vl)));
|
||||
poly.Add(new Vector3D(vr.x, vr.y, sd.Ceiling.plane.GetZ(vr)));
|
||||
poly.Add(new Vector3D(vr.x, vr.y, sd.Floor.plane.GetZ(vr)));
|
||||
|
||||
// Slice off the part below the other plane
|
||||
SlicePoly(poly, osd.Ceiling.plane, false);
|
||||
|
||||
// Now we go for all light planes to splice this polygon
|
||||
for(int k = 0; k < sd.Levels.Count; k++)
|
||||
{
|
||||
SectorLevel ol = sd.Levels[k];
|
||||
if((ol != sd.Floor) && (ol != sd.Ceiling) && (ol.type != SectorLevelType.Floor))
|
||||
{
|
||||
SlicePoly(poly, ol.plane, (k >= i));
|
||||
}
|
||||
}
|
||||
|
||||
// Find texture coordinates for each vertex in the polygon
|
||||
List<Vector2D> texc = new List<Vector2D>(poly.Count);
|
||||
foreach(Vector3D v in poly)
|
||||
texc.Add(tp.GetTextureCoordsAt(v));
|
||||
|
||||
// Now we create triangles from the polygon.
|
||||
// The polygon is convex and clockwise, so this is a piece of cake.
|
||||
if(poly.Count >= 3)
|
||||
{
|
||||
for(int k = 1; k < (poly.Count - 1); k++)
|
||||
{
|
||||
verts.Add(new WorldVertex(poly[0], c, texc[0]));
|
||||
verts.Add(new WorldVertex(poly[k], c, texc[k]));
|
||||
verts.Add(new WorldVertex(poly[k + 1], c, texc[k + 1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(verts.Count > 0)
|
||||
{
|
||||
base.SetVertices(verts);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No geometry for invisible wall
|
||||
base.top = geotop;
|
||||
base.bottom = geobottom;
|
||||
WorldVertex[] verts = new WorldVertex[0];
|
||||
base.SetVertices(verts);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue