protected BspFaceGroupRenderable(BspFile bsp, Environment environment, int mipTexture, IEnumerable <Face> faces) { Bsp = bsp; Environment = environment; _texture = bsp.Textures[mipTexture]; _faces = faces.ToList(); _textureResources = new List <ResourceSet>(); }
public BspEntityRenderable(BspFile bsp, Environment env, EntityData entity, Model model) { _bsp = bsp; _env = env; _entity = entity; _model = model; _children = new List <IRenderable>(); _colour = GetColour(); var origin = _model.Origin + entity.GetVector3("origin", Vector3.Zero); var entityFaces = new List <Face>(); var nodes = new Queue <Node>(); nodes.Enqueue(bsp.Nodes[_model.HeadNodes[0]]); while (nodes.Any()) { var node = nodes.Dequeue(); foreach (var child in node.Children) { if (child >= 0) { nodes.Enqueue(_bsp.Nodes[child]); } else { var leaf = _bsp.Leaves[-1 - child]; if (leaf.Contents == Contents.Sky) { continue; } for (var ms = 0; ms < leaf.NumMarkSurfaces; ms++) { var faceidx = _bsp.MarkSurfaces[ms + leaf.FirstMarkSurface]; var face = _bsp.Faces[faceidx]; if (face.Styles[0] != byte.MaxValue) { entityFaces.Add(face); } } } } } foreach (var group in entityFaces.GroupBy(x => _bsp.TextureInfos[x.TextureInfo].MipTexture)) { _children.Add(new BspEntityFaceGroupRenderable(_bsp, _env, group.Key, group) { Origin = origin, Colour = _colour }); } }
private void LoadModels(BspFile bsp, Environment env) { var loadedModels = new Dictionary <string, MdlFile>(StringComparer.InvariantCultureIgnoreCase); foreach (var ent in bsp.Entities.Where(x => EntityModelMap.ContainsKey(x.ClassName))) { var model = EntityModelMap[ent.ClassName]; if (model == "") { // Use model from the entity if (!ent.KeyValues.ContainsKey("model")) { continue; } model = ent.KeyValues["model"]; } if (ent.KeyValues.ContainsKey("targetname")) { var targetters = bsp.Entities.Where(x => x.KeyValues.ContainsKey("target") && x.KeyValues["target"] == ent.KeyValues["targetname"]).ToList(); } var file = env.GetFile(model); if (file != null) { file = file.Replace('/', '\\'); // normalise path try { MdlFile mdl; if (loadedModels.ContainsKey(file)) { mdl = loadedModels[file]; } else { mdl = MdlFile.FromFile(file); loadedModels[file] = mdl; } _scene.AddRenderable(new MdlRenderable(mdl, ent.GetVector3("origin", Vector3.Zero))); } catch { continue; } } } }
public void Open(Environment environment, string path) { var options = new GraphicsDeviceOptions() { HasMainSwapchain = false, ResourceBindingModel = ResourceBindingModel.Improved, SwapchainDepthFormat = PixelFormat.R32_Float, }; //_graphicsDevice = GraphicsDevice.CreateVulkan(options); _graphicsDevice = GraphicsDevice.CreateD3D11(options); _view = new VeldridControl(_graphicsDevice, options) { Dock = DockStyle.Fill, }; _panel.Controls.Add(_view); _panel.Controls.Add(_settingsPanel); _camera = new RotationCamera(_view.Width, _view.Height); _view.Camera = _camera; _sc = new SceneContext(_graphicsDevice); _sc.AddRenderTarget(_view); _scene = new Scene(); _mdl = MdlFile.FromFile(path); var(min, max) = GetBbox(_mdl, 0); _camera.SetBoundingBox(min, max); _renderable = new MdlRenderable(_mdl, Vector3.Zero); _scene.AddRenderable(_renderable); _sc.Scene = _scene; _sc.Start(); _settingsPanel.SetModel(_mdl); _settingsPanel.BodyPartModelSelected += BodyPartSelected; _settingsPanel.SequenceSelected += SequenceSelected; }
public void Open(Environment environment, string path) { var options = new GraphicsDeviceOptions() { HasMainSwapchain = false, ResourceBindingModel = ResourceBindingModel.Improved, SwapchainDepthFormat = PixelFormat.R32_Float, }; //_graphicsDevice = GraphicsDevice.CreateVulkan(options); _graphicsDevice = GraphicsDevice.CreateD3D11(options); _view = new VeldridControl(_graphicsDevice, options) { Dock = DockStyle.Fill }; _panel.Controls.Add(_view); _sc = new SceneContext(_graphicsDevice); _sc.AddRenderTarget(_view); _scene = new Scene(); BspFile bsp; using (var stream = File.OpenRead(path)) { bsp = new BspFile(stream); } _scene.AddRenderableSource(new BspRenderable(bsp, environment)); LoadModels(bsp, environment); _sc.Scene = _scene; _sc.Start(); }
private void OpenFile(string path, bool switchEnvironment) { CloseCurrentFile(); _currentFile = path; if (switchEnvironment || _currentEnvironment == null) { _currentEnvironment = Environment.FromFile(path); RefreshTree(); } var vis = _visualisers.FirstOrDefault(x => x.Supports(path)); if (vis == null) { return; } vis.Container.Dock = DockStyle.Fill; VisualiserPanel.Controls.Add(vis.Container); vis.Open(_currentEnvironment, path); _currentVisualiser = vis; }
public SkyboxRenderable(Environment env, string skyboxName) { _env = env; _skyboxName = skyboxName; }
public BspRenderable(BspFile bsp, Environment env) { _bsp = bsp; _env = env; _children = new List <IRenderable>(); var skybox = "desert"; var worldspawn = _bsp.Entities.FirstOrDefault(x => x.ClassName == "worldspawn"); if (worldspawn != null) { var wads = worldspawn.Get("wad", ""); _env.LoadWads(wads.Split(';').Where(x => !String.IsNullOrWhiteSpace(x)).Select(Path.GetFileName)); skybox = worldspawn.Get("skyname", skybox); } // Load the skybox _children.Add(new SkyboxRenderable(_env, skybox)); // Collect the static faces in the BSP (no need for special entity treatment) var staticFaces = new List <Face>(); var nodes = new Queue <Node>(_bsp.Nodes.Take(1)); while (nodes.Any()) { var node = nodes.Dequeue(); foreach (var child in node.Children) { if (child >= 0) { nodes.Enqueue(_bsp.Nodes[child]); } else { var leaf = _bsp.Leaves[-1 - child]; if (leaf.Contents == Contents.Sky) { continue; } for (var ms = 0; ms < leaf.NumMarkSurfaces; ms++) { var faceidx = _bsp.MarkSurfaces[ms + leaf.FirstMarkSurface]; var face = _bsp.Faces[faceidx]; if (face.Styles[0] != byte.MaxValue) { staticFaces.Add(face); } } } } } foreach (var group in staticFaces.GroupBy(x => _bsp.TextureInfos[x.TextureInfo].MipTexture)) { _children.Add(new BspStaticFaceGroupRenderable(_bsp, _env, group.Key, group)); } // Collect entity faces - these have special treatment foreach (var ent in _bsp.Entities) { if (ent.Model <= 0) { continue; } var model = _bsp.Models[ent.Model]; _children.Add(new BspEntityRenderable(_bsp, _env, ent, model)); } }