@ work on (G)ZDoom Editing plugin

This commit is contained in:
codeimp 2010-09-04 14:51:35 +00:00
parent 939bceaa37
commit 605f795747
8 changed files with 99 additions and 31 deletions

View file

@ -128,8 +128,8 @@ namespace CodeImp.DoomBuilder.Geometry
/// </summary>
public Vector3D ClosestOnPlane(Vector3D p)
{
float d = Vector3D.DotProduct(p, normal) + offset;
return p - normal * d;
float w = Vector3D.DotProduct(p, normal) + offset;
return p - normal * w;
}
/// <summary>
@ -137,7 +137,7 @@ namespace CodeImp.DoomBuilder.Geometry
/// </summary>
public float GetZ(Vector2D pos)
{
return (d + a * pos.x + b * pos.y) / c;
return (offset + normal.x * pos.x + normal.y * pos.y) / normal.z;
}
/// <summary>
@ -145,7 +145,7 @@ namespace CodeImp.DoomBuilder.Geometry
/// </summary>
public float GetZ(float x, float y)
{
return (d + a * x + b * y) / c;
return (offset + normal.x * x + normal.y * y) / normal.z;
}
/// <summary>

View file

@ -425,14 +425,26 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
}
// This rebuilds the sector data
// This requires that the blockmap is up-to-date!
internal void RebuildSectorData()
{
Dictionary<int, List<Sector>> sectortags = new Dictionary<int, List<Sector>>();
sectordata = new Dictionary<Sector, SectorData>(General.Map.Map.Sectors.Count);
// Find all sector who's tag is not 0 and hash them so that we can find them quicly
foreach(Sector s in General.Map.Map.Sectors)
{
if(s.Tag != 0)
{
if(!sectortags.ContainsKey(s.Tag)) sectortags[s.Tag] = new List<Sector>();
sectortags[s.Tag].Add(s);
}
}
// Find interesting linedefs (such as line slopes)
foreach(Linedef l in General.Map.Map.Linedefs)
{
// Plane Align (see http://zdoom.org/wiki/Plane_Align)
// ========== Plane Align (see http://zdoom.org/wiki/Plane_Align) ==========
if(l.Action == 181)
{
// Slope front
@ -449,11 +461,34 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
sd.AddLinedef(l);
}
}
// ========== Sector 3D floor (see http://zdoom.org/wiki/Sector_Set3dFloor) ==========
else if(l.Action == 160)
{
if(sectortags.ContainsKey(l.Args[0]))
{
List<Sector> sectors = sectortags[l.Args[0]];
foreach(Sector s in sectors)
{
SectorData sd = GetSectorData(s);
sd.AddLinedef(l);
}
}
}
}
// Find interesting things (such as vertex and sector slopes)
foreach(Thing t in General.Map.Map.Things)
{
// ========== Copy floor slope ==========
if(t.Type == 9510)
{
t.DetermineSector(blockmap);
if(t.Sector != null)
{
SectorData sd = GetSectorData(t.Sector);
sd.AddThing(t);
}
}
}
}

View file

@ -146,15 +146,27 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
data = mode.GetSectorData(this.Sector);
if(!data.Built) data.BuildLevels(mode);
// Create floor
if(floor == null) floor = new VisualFloor(mode, this, data.Floor);
floor.Setup();
base.AddGeometry(floor);
// Create ceiling
if(ceiling == null) ceiling = new VisualCeiling(mode, this, data.Ceiling);
ceiling.Setup();
base.AddGeometry(ceiling);
// Create levels
foreach(SectorLevel lvl in data.Levels)
{
if(lvl.type == SectorLevelType.Floor)
{
// Create a floor
VisualFloor g = new VisualFloor(mode, this, lvl);
g.Setup();
base.AddGeometry(g);
}
else if(lvl.type == SectorLevelType.Ceiling)
{
// Create a ceiling
VisualCeiling g = new VisualCeiling(mode, this, lvl);
g.Setup();
base.AddGeometry(g);
}
}
// NOTE: Because we no longer use the Floor and Ceiling members, these are now null.
// They need to be replaced with a different system that works for all levels in the sector.
// Go for all sidedefs
Dictionary<Sidedef, VisualSidedefParts> oldsides = sides ?? new Dictionary<Sidedef, VisualSidedefParts>(1);

View file

@ -118,7 +118,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
foreach(Linedef l in linedefs)
{
// Plane Align (see http://zdoom.org/wiki/Plane_Align)
// ========== Plane Align (see http://zdoom.org/wiki/Plane_Align) ==========
if(l.Action == 181)
{
// Find the vertex furthest from the line
@ -181,11 +181,24 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
ceiling.plane = new Plane(v2, v1, v3, false);
}
}
// ========== Sector 3D floor (see http://zdoom.org/wiki/Sector_Set3dFloor) ==========
else if(l.Action == 160)
{
if(l.Front != null)
{
SectorData sd = mode.GetSectorData(l.Front.Sector);
if(!sd.Built) sd.BuildLevels(mode);
// Add floor and ceiling of control sector
levels.Add(sd.Floor);
levels.Add(sd.Ceiling);
}
}
}
foreach(Thing t in things)
{
// Copy floor slope
// ========== Copy floor slope ==========
if(t.Type == 9510)
{
// Find tagged sector

View file

@ -21,6 +21,9 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Type of level
public SectorLevelType type;
// Original sector
public Sector sector;
// Plane in the sector
public Plane plane;
@ -34,6 +37,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Constructor
public SectorLevel(Sector s, SectorLevelType type)
{
this.sector = s;
this.type = type;
this.center = new Vector2D(s.BBox.Left + s.BBox.Width / 2, s.BBox.Top + s.BBox.Height / 2);
}

View file

@ -19,6 +19,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
@ -68,7 +69,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
{
WorldVertex[] verts;
WorldVertex v;
Sector s = base.Sector.Sector;
Sector s = level.sector;
float xpan, ypan, xscale, yscale, rotate;
int color, light;
bool absolute;
@ -118,19 +119,20 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
color = finalcolor.WithAlpha(255).ToInt();
// Make vertices
verts = new WorldVertex[s.Triangles.Vertices.Count];
for(int i = 0; i < s.Triangles.Vertices.Count; i++)
ReadOnlyCollection<Vector2D> triverts = base.Sector.Sector.Triangles.Vertices;
verts = new WorldVertex[triverts.Count];
for(int i = 0; i < triverts.Count; i++)
{
// Color shading
verts[i].c = color;
// Vertex coordinates
verts[i].x = s.Triangles.Vertices[i].x;
verts[i].y = s.Triangles.Vertices[i].y;
verts[i].z = Sector.Data.Ceiling.plane.GetZ(s.Triangles.Vertices[i]); //(float)s.CeilHeight;
verts[i].x = triverts[i].x;
verts[i].y = triverts[i].y;
verts[i].z = level.plane.GetZ(triverts[i]); //(float)s.CeilHeight;
// Texture coordinates
Vector2D pos = s.Triangles.Vertices[i];
Vector2D pos = triverts[i];
pos = pos.GetRotated(rotate);
pos.y = -pos.y;
pos = (pos + offset) * scale * texscale;

View file

@ -19,6 +19,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
@ -67,7 +68,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
public override bool Setup()
{
WorldVertex[] verts;
Sector s = base.Sector.Sector;
Sector s = level.sector;
float xpan, ypan, xscale, yscale, rotate;
int color, light;
bool absolute;
@ -115,21 +116,22 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
PixelColor brightness = PixelColor.FromInt(mode.CalculateBrightness(light));
PixelColor finalcolor = PixelColor.Modulate(lightcolor, brightness);
color = finalcolor.WithAlpha(255).ToInt();
// Make vertices
verts = new WorldVertex[s.Triangles.Vertices.Count];
for(int i = 0; i < s.Triangles.Vertices.Count; i++)
ReadOnlyCollection<Vector2D> triverts = base.Sector.Sector.Triangles.Vertices;
verts = new WorldVertex[triverts.Count];
for(int i = 0; i < triverts.Count; i++)
{
// Color shading
verts[i].c = color;
// Vertex coordinates
verts[i].x = s.Triangles.Vertices[i].x;
verts[i].y = s.Triangles.Vertices[i].y;
verts[i].z = Sector.Data.Floor.plane.GetZ(s.Triangles.Vertices[i]); //(float)s.FloorHeight;
verts[i].x = triverts[i].x;
verts[i].y = triverts[i].y;
verts[i].z = level.plane.GetZ(triverts[i]); //(float)s.FloorHeight;
// Texture coordinates
Vector2D pos = s.Triangles.Vertices[i];
Vector2D pos = triverts[i];
pos = pos.GetRotated(rotate);
pos.y = -pos.y;
pos = (pos + offset) * scale * texscale;

Binary file not shown.