/// <summary> /// Creates a new editor presenter /// </summary> /// <param name="engine">The engine to use for rendering</param> /// <param name="universe">The universe to display</param> /// <param name="lighting">Shall lighting be used for rendering?</param> public EditorPresenter(Engine engine, Universe universe, bool lighting) : base(engine, universe) { #region Sanity checks if (engine == null) { throw new ArgumentNullException(nameof(engine)); } if (universe == null) { throw new ArgumentNullException(nameof(universe)); } #endregion Lighting = lighting; // Restore previous camera position (or default to center of terrain) var mainCamera = CreateCamera(universe.CurrentCamera); View = new View(Scene, mainCamera) { Name = "Editor", BackgroundColor = universe.FogColor }; // Floating axis-arrows for easier orientation var axisArrows = new FloatingModel(XMesh.Get(engine, "Engine/AxisArrows.x")) { Name = "AxisArrows", Alpha = 160, Position = new DoubleVector3(-16, -12, 40), Rotation = Quaternion.RotationYawPitchRoll(0, 0, 0) }; axisArrows.SetScale(0.03f); View.FloatingModels.Add(axisArrows); }
/// <inheritdoc/> public override void Initialize() { base.Initialize(); // Prepare painting brush meshes Scene.Positionables.Add(_terrainPaintingBrushCircle = new Model(XMesh.Get(Engine, "Engine/Circle.x")) { Visible = false }); Scene.Positionables.Add(_terrainPaintingBrushSquare = new Model(XMesh.Get(Engine, "Engine/Rectangle.x")) { Visible = false }); }
/// <inheritdoc/> public override void Initialize() { base.Initialize(); if (_preCachedAssets == null) { // Preload selection highlighting meshes _preCachedAssets = new Asset[] { XMesh.Get(Engine, "Engine/Circle.x"), XMesh.Get(Engine, "Engine/Rectangle.x") }; foreach (var asset in _preCachedAssets) { asset.HoldReference(); } } _selectionsSync.Register <Entity, PositionableRenderable>(GetSelectionHighlighting, UpdateRepresentationShifted); _selectionsSync.Initialize(); }
/// <summary> /// Adds the selection highlighting for a <see cref="EntityBase{TCoordinates,TTemplate}"/> /// </summary> /// <param name="entity">The <see cref="EntityBase{TCoordinates,TTemplate}"/> to add the selection highlighting for</param> private Model GetSelectionHighlighting(Entity entity) { if (entity.TemplateData.Collision == null) { return(null); } var selectionHighlight = new PerTypeDispatcher <Collision <Vector2>, Model>(ignoreMissing: true) { (Circle circle) => { // Create a circle around the entity based on the radius var hightlight = new Model(XMesh.Get(Engine, "Engine/Circle.x")); float scale = circle.Radius / 20 + 1; hightlight.PreTransform = Matrix.Scaling(scale, 1, scale); return(hightlight); }, (Box box) => { // Create a rectangle around the entity based on the box corners var highlight = new Model(XMesh.Get(Engine, "Engine/Rectangle.x")); // Determine the component-wise minimums and maxmimums and the absolute difference var min = new Vector2( Math.Min(box.Minimum.X, box.Maximum.X), Math.Min(box.Minimum.Y, box.Maximum.Y)); var max = new Vector2( Math.Max(box.Minimum.X, box.Maximum.X), Math.Max(box.Minimum.Y, box.Maximum.Y)); var diff = max - min; highlight.PreTransform = Matrix.Scaling(diff.X, 1, diff.Y) * Matrix.Translation(min.X, 0, -min.Y); return(highlight); } }.Dispatch(entity.TemplateData.Collision); if (selectionHighlight != null) { selectionHighlight.Name = entity.Name + " Selection"; } return(selectionHighlight); }
/// <inheritdoc/> protected override void RegisterRenderablesSync() { base.RegisterRenderablesSync(); RenderablesSync.Register( (Waypoint waypoint) => new Model(XMesh.Get(Engine, "Engine/Waypoint.x")) { Scale = new Vector3(100) }, UpdateRepresentation); RenderablesSync.Register( (Trigger trigger) => { var area = Model.Cylinder(Engine, XTexture.Get(Engine, "flag.png"), radiusBottom: trigger.Range, radiusTop: trigger.Range, length: 150); area.Rotation = Quaternion.RotationYawPitchRoll(0, (float)Math.PI / 2, 0); area.Alpha = 160; return(area); }, UpdateRepresentation); }
/// <inheritdoc/> protected override void RegisterRenderablesSync() { RegisterWater(); RegisterRenderComponentLight(); RegisterRenderComponent <StaticMesh>((entity, component) => { if (string.IsNullOrEmpty(component.Filename)) { return(null); } var model = new Model(XMesh.Get(Engine, component.Filename)) { Name = entity.Name }; ConfigureModel(model, component); return(model); }); RegisterRenderComponent <AnimatedMesh>((entity, component) => { if (string.IsNullOrEmpty(component.Filename)) { return(null); } var model = new AnimatedModel(XAnimatedMesh.Get(Engine, component.Filename)) { Name = entity.Name }; ConfigureModel(model, component); return(model); }); RegisterRenderComponent <TestSphere>((entity, component) => { var model = Model.Sphere(Engine, XTexture.Get(Engine, component.Texture), component.Radius, component.Slices, component.Stacks); model.Name = entity.Name; ConfigureModel(model, component); return(model); }); RegisterRenderComponent <CpuParticleSystem>((entity, component) => { if (string.IsNullOrEmpty(component.Filename)) { return(null); } var particleSystem = new OmegaEngine.Graphics.Renderables.CpuParticleSystem(CpuParticlePreset.FromContent(component.Filename)); ConfigureParticleSystem(entity, particleSystem, component); return(particleSystem); }); RegisterRenderComponent <GpuParticleSystem>((entity, component) => { if (string.IsNullOrEmpty(component.Filename)) { return(null); } var particleSystem = new OmegaEngine.Graphics.Renderables.GpuParticleSystem(GpuParticlePreset.FromContent(component.Filename)); ConfigureParticleSystem(entity, particleSystem, component); return(particleSystem); }); }