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); } }
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; }
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); } }
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; }