// Constructor public ThingData(BaseVisualMode mode, Thing t) { // Initialize this.mode = mode; this.thing = t; this.updatesectors = new Dictionary <Sector, bool>(2); }
// Constructor public VisualMiddleDouble(BaseVisualMode mode, VisualSector vs, Sidedef s) : base(mode, vs, s) { // Set render pass this.RenderPass = RenderPass.Mask; // We have no destructor GC.SuppressFinalize(this); }
public VisualSidedefSlope(BaseVisualMode mode, SectorLevel level, Sidedef sidedef, bool up) : base(mode, level, up) { this.sidedef = sidedef; type = VisualSlopeType.Line; Update(); // We have no destructor GC.SuppressFinalize(this); }
// Constructor for sidedefs public BaseVisualGeometrySidedef(BaseVisualMode mode, VisualSector vs, Sidedef sd) : base(vs, sd) { this.mode = mode; this.deltaz = new Vector3D(0.0f, 0.0f, 1.0f); this.deltaxy = (sd.Line.End.Position - sd.Line.Start.Position) * sd.Line.LengthInv; if (!sd.IsFront) { this.deltaxy = -this.deltaxy; } }
public static void ApplySlope(SectorLevel level, Plane plane, BaseVisualMode mode) { bool applytoceiling = false; Vector2D center = new Vector2D(level.sector.BBox.X + level.sector.BBox.Width / 2, level.sector.BBox.Y + level.sector.BBox.Height / 2); if (level.extrafloor) { // The top side of 3D floors is the ceiling of the sector, but it's a "floor" in UDB, so the // ceiling of the control sector has to be modified if (level.type == SectorLevelType.Floor) { applytoceiling = true; } } else { if (level.type == SectorLevelType.Ceiling) { applytoceiling = true; } } if (applytoceiling) { Plane downplane = plane.GetInverted(); level.sector.CeilSlope = downplane.Normal; level.sector.CeilSlopeOffset = downplane.Offset; level.sector.CeilHeight = (int)new Plane(level.sector.CeilSlope, level.sector.CeilSlopeOffset).GetZ(center); } else { level.sector.FloorSlope = plane.Normal; level.sector.FloorSlopeOffset = plane.Offset; level.sector.FloorHeight = (int)new Plane(level.sector.FloorSlope, level.sector.FloorSlopeOffset).GetZ(center); } // Rebuild sector BaseVisualSector vs; if (mode.VisualSectorExists(level.sector)) { vs = (BaseVisualSector)mode.GetVisualSector(level.sector); } else { vs = mode.CreateBaseVisualSector(level.sector); } if (vs != null) { vs.UpdateSectorGeometry(true); } }
// Constructor public BaseVisualSector(BaseVisualMode mode, Sector s) : base(s) { this.mode = mode; this.extrafloors = new List <VisualFloor>(2); this.extraceilings = new List <VisualCeiling>(2); // Initialize Rebuild(); // We have no destructor GC.SuppressFinalize(this); }
public VisualVertexSlope(BaseVisualMode mode, SectorLevel level, Vertex vertex, Sector sector, bool up) : base(mode, level, up) { this.vertex = vertex; this.sector = sector; type = VisualSlopeType.Vertex; ComputeAngle(); Update(); GC.SuppressFinalize(this); }
public VisualSidedefSlope(BaseVisualMode mode, SectorLevel level, Sidedef sidedef, bool up) : base() { this.mode = mode; this.sidedef = sidedef; this.level = level; this.up = up; // length = sidedef.Line.Length; Update(); // We have no destructor GC.SuppressFinalize(this); }
// Constructor public BaseVisualThing(BaseVisualMode mode, Thing t) : base(t) { this.mode = mode; // Find thing information info = General.Map.Data.GetThingInfo(Thing.Type); // Find sprite texture if (info.Sprite.Length > 0) { sprite = General.Map.Data.GetSpriteImage(info.Sprite); if (sprite != null) { sprite.AddReference(); } } // We have no destructor GC.SuppressFinalize(this); }
// Constructor public SectorData(BaseVisualMode mode, Sector s) { // Initialize this.mode = mode; this.sector = s; this.updated = false; this.floorchanged = false; this.ceilingchanged = false; this.lightlevels = new List <SectorLevel>(2); this.extrafloors = new List <Effect3DFloor>(1); this.alleffects = new List <SectorEffect>(1); this.updatesectors = new Dictionary <Sector, bool>(2); this.floor = new SectorLevel(sector, SectorLevelType.Floor); this.ceiling = new SectorLevel(sector, SectorLevelType.Ceiling); BasicSetup(); // Add ceiling and floor lightlevels.Add(floor); lightlevels.Add(ceiling); }
// Constructor public VisualCeiling(BaseVisualMode mode, VisualSector vs) : base(mode, vs) { // We have no destructor GC.SuppressFinalize(this); }
// Constructor public VisualMiddle3D(BaseVisualMode mode, VisualSector vs, Sidedef s) : base(mode, vs, s) { // We have no destructor GC.SuppressFinalize(this); }
public BaseVisualSlope(BaseVisualMode mode, SectorLevel level, bool up) { this.mode = mode; this.level = level; this.up = up; }
private static void CreateObjFromSelection(ICollection <Sector> sectors, ref WavefrontExportSettings data) { BaseVisualMode mode = new BaseVisualMode(); bool renderingEffectsDisabled = false; if (!General.Settings.GZDoomRenderingEffects) { renderingEffectsDisabled = true; mode.ToggleGZDoomRenderingEffects(); } mode.RebuildElementData(); List <BaseVisualSector> visualSectors = new List <BaseVisualSector>(); //create visual geometry foreach (Sector s in sectors) { BaseVisualSector bvs = mode.CreateBaseVisualSector(s); if (bvs != null) { visualSectors.Add(bvs); } } if (visualSectors.Count == 0) { General.ErrorLogger.Add(ErrorType.Error, "OBJ Exporter: no visual sectors to export!"); return; } //sort geometry List <Dictionary <string, List <WorldVertex[]> > > geometryByTexture = SortGeometry(visualSectors); //restore vm settings if (renderingEffectsDisabled) { mode.ToggleGZDoomRenderingEffects(); } mode.Dispose(); //create obj StringBuilder obj = CreateObjGeometry(geometryByTexture, data); if (obj.Length == 0) { General.ErrorLogger.Add(ErrorType.Error, "OBJ Exporter: failed to create geometry!"); return; } //add header obj.Insert(0, "o " + General.Map.Options.LevelName + Environment.NewLine); //name obj.Insert(0, "# Created by 3DGE Builder " + Application.ProductVersion + Environment.NewLine + Environment.NewLine); obj.Insert(0, "# " + General.Map.FileTitle + ", map " + General.Map.Options.LevelName + Environment.NewLine); data.Obj = obj.ToString(); string[] textures = new string[geometryByTexture[0].Keys.Count]; geometryByTexture[0].Keys.CopyTo(textures, 0); Array.Sort(textures); data.Textures = textures; string[] flats = new string[geometryByTexture[1].Keys.Count]; geometryByTexture[1].Keys.CopyTo(flats, 0); Array.Sort(flats); data.Flats = flats; data.Valid = true; }
public override void OnActionEnd(CodeImp.DoomBuilder.Actions.Action action) { base.OnActionEnd(action); if (!updateafteraction && action.Name != updateafteractionname) { return; } updateafteraction = false; Dictionary <SlopeVertexGroup, int> updatesvgs = new Dictionary <SlopeVertexGroup, int>(); // Find SVGs that needs to be updated, and change the SV z positions foreach (SlopeVertexGroup svg in slopevertexgroups) { bool update = false; Dictionary <int, List <Sector> > newheights = new Dictionary <int, List <Sector> >(); foreach (Sector s in svg.Sectors) { if (s.Fields == null) { continue; } if ((svg.SectorPlanes[s] & PlaneType.Floor) == PlaneType.Floor) { if (s.Fields.ContainsKey("user_floorplane_id") && s.Fields.GetValue("user_floorplane_id", -1) == svg.Id) { if (svg.Height != s.FloorHeight) { int diff = s.FloorHeight - svg.Height; if (!newheights.ContainsKey(diff)) { newheights.Add(diff, new List <Sector>() { s }); } else { newheights[diff].Add(s); } update = true; //break; } } } if ((svg.SectorPlanes[s] & PlaneType.Ceiling) == PlaneType.Ceiling) { if (s.Fields.ContainsKey("user_ceilingplane_id") && s.Fields.GetValue("user_ceilingplane_id", -1) == svg.Id) { if (svg.Height != s.CeilHeight) { int diff = s.CeilHeight - svg.Height; if (!newheights.ContainsKey(diff)) { newheights.Add(diff, new List <Sector>() { s }); } else { newheights[diff].Add(s); } update = true; //break; } } } } // Debug.WriteLine(String.Format("floordiff: {0} / ceilingdiff: {1} / height: {2}", floordiff, ceilingdiff, svg.Height)); if (update) { if (newheights.Count > 1) { Debug.WriteLine(String.Format("Slope: multiple new heights, doing nothing. Your map is f****d!")); } else if (!updatesvgs.ContainsKey(svg)) { updatesvgs.Add(svg, newheights.First().Key); } } } // Update the slopes, and also update the view if in visual mode foreach (SlopeVertexGroup svg in updatesvgs.Keys) { foreach (SlopeVertex sv in svg.Vertices) { sv.Z += updatesvgs[svg]; } svg.ComputeHeight(); foreach (Sector s in svg.Sectors) { UpdateSlopes(s); } // Save the updated data in the sector svg.StoreInSector(slopedatasector); if (General.Editing.Mode is BaseVisualMode) { List <Sector> sectors = new List <Sector>(); List <VisualSector> visualsectors = new List <VisualSector>(); BaseVisualMode mode = ((BaseVisualMode)General.Editing.Mode); foreach (Sector s in svg.Sectors) { sectors.Add(s); // Get neighbouring sectors and add them to the list foreach (Sidedef sd in s.Sidedefs) { if (sd.Other != null && !sectors.Contains(sd.Other.Sector)) { sectors.Add(sd.Other.Sector); } } } foreach (Sector s in svg.TaggedSectors) { if (!sectors.Contains(s)) { sectors.Add(s); } // Get neighbouring sectors and add them to the list foreach (Sidedef sd in s.Sidedefs) { if (sd.Other != null && !sectors.Contains(sd.Other.Sector)) { sectors.Add(sd.Other.Sector); } } } foreach (Sector s in sectors) { visualsectors.Add(mode.GetVisualSector(s)); } foreach (VisualSector vs in visualsectors) { vs.UpdateSectorGeometry(true); } foreach (VisualSector vs in visualsectors) { vs.UpdateSectorData(); } } } }
public static void ApplySlope(SectorLevel level, Plane plane, BaseVisualMode mode) { bool applytoceiling = false; bool reset = false; int height = 0; Vector2D center = new Vector2D(level.sector.BBox.X + level.sector.BBox.Width / 2, level.sector.BBox.Y + level.sector.BBox.Height / 2); if (level.extrafloor) { // The top side of 3D floors is the ceiling of the sector, but it's a "floor" in UDB, so the // ceiling of the control sector has to be modified if (level.type == SectorLevelType.Floor) { applytoceiling = true; } } else { if (level.type == SectorLevelType.Ceiling) { applytoceiling = true; } } // If the plane horizontal remove the slope and set the sector height instead // Rounding errors can result in offsets of horizontal planes to be a tiny, tiny bit off a whole number, // assume we want to remove the plane in this case double diff = Math.Abs(Math.Round(plane.d) - plane.d); if (plane.Normal.z == 1.0 && diff < 0.000000001) { reset = true; height = -Convert.ToInt32(plane.d); } if (applytoceiling) { if (reset) { level.sector.CeilHeight = height; level.sector.CeilSlope = new Vector3D(); level.sector.CeilSlopeOffset = double.NaN; } else { Plane downplane = plane.GetInverted(); level.sector.CeilSlope = downplane.Normal; level.sector.CeilSlopeOffset = downplane.Offset; } } else { if (reset) { level.sector.FloorHeight = height; level.sector.FloorSlope = new Vector3D(); level.sector.FloorSlopeOffset = double.NaN; } else { level.sector.FloorSlope = plane.Normal; level.sector.FloorSlopeOffset = plane.Offset; } } // Rebuild sector BaseVisualSector vs; if (mode.VisualSectorExists(level.sector)) { vs = (BaseVisualSector)mode.GetVisualSector(level.sector); } else { vs = mode.CreateBaseVisualSector(level.sector); } if (vs != null) { vs.UpdateSectorGeometry(true); } }
// Constructor protected BaseVisualGeometrySector(BaseVisualMode mode, VisualSector vs) : base(vs) { this.mode = mode; }
private static void CreateObjFromSelection(ICollection <Sector> sectors, ref WavefrontExportSettings data) { BaseVisualMode mode = new BaseVisualMode(); bool renderingEffectsDisabled = false; if (!General.Settings.EnhancedRenderingEffects) { renderingEffectsDisabled = true; mode.ToggleEnhancedRendering(); } mode.RebuildElementData(); List <BaseVisualSector> visualSectors = new List <BaseVisualSector>(); //create visual geometry foreach (Sector s in sectors) { bool addvs = true; // Check if the sector has, or shares a line with a 3D floor control sector, and ignore it if necessary if (data.ExportForGZDoom && data.IgnoreControlSectors) { foreach (Sidedef sd in s.Sidedefs) { if (sd.Line.Action == 160) { addvs = false; break; } } } if (addvs) { BaseVisualSector bvs = mode.CreateBaseVisualSector(s); if (bvs != null) { visualSectors.Add(bvs); } } } if (visualSectors.Count == 0) { General.ErrorLogger.Add(ErrorType.Error, "OBJ Exporter: no visual sectors to export!"); return; } //sort geometry List <Dictionary <string, List <WorldVertex[]> > > geometryByTexture = SortGeometry(visualSectors, data.SkipTextures, !data.ExportForGZDoom); //restore vm settings if (renderingEffectsDisabled) { mode.ToggleEnhancedRendering(); } mode.Dispose(); //create obj StringBuilder obj = CreateObjGeometry(geometryByTexture, ref data); if (obj.Length == 0) { General.ErrorLogger.Add(ErrorType.Error, "OBJ Exporter: failed to create geometry!"); return; } //add header obj.Insert(0, "o " + General.Map.Options.LevelName + Environment.NewLine); //name obj.Insert(0, "# Created by Ultimate Doom Builder " + Application.ProductVersion + Environment.NewLine + Environment.NewLine); obj.Insert(0, "# " + General.Map.FileTitle + ", map " + General.Map.Options.LevelName + Environment.NewLine); data.Obj = obj.ToString(); string[] textures = new string[geometryByTexture[0].Keys.Count]; geometryByTexture[0].Keys.CopyTo(textures, 0); Array.Sort(textures); data.Textures = textures; string[] flats = new string[geometryByTexture[1].Keys.Count]; geometryByTexture[1].Keys.CopyTo(flats, 0); Array.Sort(flats); data.Flats = flats; data.Valid = true; }
/// <summary> /// Tries to find a slope handle to pivot around. If possible if finds the handle belonging to a line that has the /// same angle as the start handle, and is the furthest away. If such a handle does not exist it finds one that's /// closest to those specs /// </summary> /// <param name="starthandle">The slope handle to start from (the one we need to find a pivot handle for)</param> /// <returns></returns> public static VisualSidedefSlope GetSmartPivotHandle(VisualSidedefSlope starthandle, BaseVisualMode mode) { VisualSidedefSlope handle = starthandle; List <VisualSidedefSlope> potentialhandles = new List <VisualSidedefSlope>(); List <IVisualEventReceiver> selectedsectors = mode.GetSelectedObjects(true, false, false, false, false); if (selectedsectors.Count == 0) { // No sectors selected, so find all handles that belong to the same level foreach (VisualSidedefSlope checkhandle in mode.AllSlopeHandles[starthandle.Sidedef.Sector]) { if (checkhandle != starthandle && checkhandle.Level == starthandle.Level) { potentialhandles.Add(checkhandle); } } } else { // Sectors are selected, get all handles from those sectors that have the same level HashSet <Sector> sectors = new HashSet <Sector>(); foreach (BaseVisualGeometrySector bvgs in selectedsectors) { sectors.Add(bvgs.Sector.Sector); } foreach (Sector s in sectors) { foreach (VisualSidedefSlope checkhandle in mode.AllSlopeHandles[s]) { if (checkhandle != starthandle) { foreach (BaseVisualGeometrySector bvgs in selectedsectors) { if (bvgs.Level == checkhandle.Level) { potentialhandles.Add(checkhandle); } } } } } } foreach (KeyValuePair <Sector, List <VisualSlope> > kvp in mode.AllSlopeHandles) { foreach (VisualSidedefSlope checkhandle in kvp.Value) { checkhandle.SmartPivot = false; } } // Sort potential handles by their angle difference to the start handle. That means that handles with less angle difference will be at the beginning of the list List <VisualSidedefSlope> anglediffsortedhandles = potentialhandles.OrderBy(h => Math.Abs(starthandle.NormalizedAngleDeg - h.NormalizedAngleDeg)).ToList(); // Get all potential handles that have to same angle as the one that's closest to the start handle, then sort them by distance, and take the one that's furthest away if (anglediffsortedhandles.Count > 0) { handle = anglediffsortedhandles.Where(h => h.NormalizedAngleDeg == anglediffsortedhandles[0].NormalizedAngleDeg).OrderByDescending(h => Math.Abs(starthandle.Sidedef.Line.Line.GetDistanceToLine(h.sidedef.Line.GetCenterPoint(), false))).First(); } if (handle == starthandle) { return(null); } return(handle); }