protected override void InitializeControl() { AddRenderModeSelectionControl(); animationComboBox = ViewerControl.AddSelection("Animation", (animation, _) => { modelSceneNode?.SetAnimation(animation); }); animationPlayPause = ViewerControl.AddCheckBox("Autoplay", true, isChecked => { if (modelSceneNode != null) { modelSceneNode.AnimationController.IsPaused = !isChecked; } }); animationTrackBar = ViewerControl.AddTrackBar("Animation Frame", frame => { if (modelSceneNode != null) { modelSceneNode.AnimationController.Frame = frame; } }); animationPlayPause.Enabled = false; animationTrackBar.Enabled = false; }
protected override void InitializeControl() { AddRenderModeSelectionControl(); worldLayersComboBox = ViewerControl.AddMultiSelection("World Layers", (worldLayers) => { SetEnabledLayers(new HashSet <string>(worldLayers)); }); savedCameraPositionsControl = new SavedCameraPositionsControl(); savedCameraPositionsControl.SaveCameraRequest += OnSaveCameraRequest; savedCameraPositionsControl.RestoreCameraRequest += OnRestoreCameraRequest; ViewerControl.AddControl(savedCameraPositionsControl); ViewerControl.AddCheckBox("Show triggers", false, v => { foreach (var n in triggerNodes) { n.Enabled = v; } }); ViewerControl.AddCheckBox("Show entity colliders", false, v => { foreach (var n in colliderNodes) { n.Enabled = v; } }); }
protected override void LoadScene() { if (world != null) { var loader = new WorldLoader(GuiContext, world); var result = loader.Load(Scene); if (result.Skybox != null) { SkyboxScene = new Scene(GuiContext); var skyboxLoader = new WorldLoader(GuiContext, result.Skybox); var skyboxResult = skyboxLoader.Load(SkyboxScene); SkyboxScale = skyboxResult.SkyboxScale; SkyboxOrigin = skyboxResult.SkyboxOrigin; ViewerControl.AddCheckBox("Show Skybox", ShowSkybox, (v) => ShowSkybox = v); } var worldLayers = Scene.AllNodes .Select(r => r.LayerName) .Distinct(); SetAvailableLayers(worldLayers); if (worldLayers.Any()) { // TODO: Since the layers are combined, has to be first in each world node? worldLayersComboBox.SetItemCheckState(0, CheckState.Checked); foreach (var worldLayer in result.DefaultEnabledLayers) { worldLayersComboBox.SetItemCheckState(worldLayersComboBox.FindStringExact(worldLayer), CheckState.Checked); } } if (result.CameraMatrices.Any()) { if (cameraComboBox == default) { cameraComboBox = ViewerControl.AddSelection("Camera", (cameraName, index) => { if (index > 0) { if (result.CameraMatrices.TryGetValue(cameraName, out var cameraMatrix)) { Scene.MainCamera.SetFromTransformMatrix(cameraMatrix); } cameraComboBox.SelectedIndex = 0; } }); cameraComboBox.Items.Add("Set view to camera..."); cameraComboBox.SelectedIndex = 0; } cameraComboBox.Items.AddRange(result.CameraMatrices.Keys.ToArray <object>()); } var physNodes = Scene.AllNodes.OfType <PhysSceneNode>().Distinct(); triggerNodes = physNodes.Where(n => n.IsTrigger); colliderNodes = physNodes.Where(n => !n.IsTrigger); } if (worldNode != null) { var loader = new WorldNodeLoader(GuiContext, worldNode); loader.Load(Scene); var worldLayers = Scene.AllNodes .Select(r => r.LayerName) .Distinct() .ToList(); SetAvailableLayers(worldLayers); for (var i = 0; i < worldLayersComboBox.Items.Count; i++) { worldLayersComboBox.SetItemChecked(i, true); } } ShowBaseGrid = false; ViewerControl.Invoke((Action)savedCameraPositionsControl.RefreshSavedPositions); }
protected override void LoadScene() { if (model != null) { modelSceneNode = new ModelSceneNode(Scene, model); SetAvailableAnimations(modelSceneNode.GetSupportedAnimationNames()); Scene.Add(modelSceneNode, false); phys = model.GetEmbeddedPhys(); if (phys == null) { var refPhysicsPaths = model.GetReferencedPhysNames(); if (refPhysicsPaths.Any()) { //TODO are there any models with more than one vphys? if (refPhysicsPaths.Count() != 1) { Console.WriteLine($"Model has more than 1 vphys ({refPhysicsPaths.Count()})." + " Please report this on https://github.com/SteamDatabase/ValveResourceFormat and provide the file that caused this."); } var newResource = Scene.GuiContext.LoadFileByAnyMeansNecessary(refPhysicsPaths.First() + "_c"); if (newResource != null) { phys = (PhysAggregateData)newResource.DataBlock; } } } var meshGroups = modelSceneNode.GetMeshGroups(); if (meshGroups.Count() > 1) { meshGroupListBox = ViewerControl.AddMultiSelection("Mesh Group", selectedGroups => { modelSceneNode.SetActiveMeshGroups(selectedGroups); }); meshGroupListBox.Items.AddRange(modelSceneNode.GetMeshGroups().ToArray <object>()); foreach (var group in modelSceneNode.GetActiveMeshGroups()) { meshGroupListBox.SetItemChecked(meshGroupListBox.FindStringExact(group), true); } } var materialGroups = model.GetMaterialGroups(); if (materialGroups.Count() > 1) { materialGroupListBox = ViewerControl.AddSelection("Material Group", (selectedGroup, _) => { modelSceneNode?.SetSkin(selectedGroup); }); materialGroupListBox.Items.AddRange(materialGroups.ToArray <object>()); materialGroupListBox.SelectedIndex = 0; } modelSceneNode.AnimationController.RegisterUpdateHandler((animation, frame) => { if (animationTrackBar.TrackBar.Value != frame) { animationTrackBar.UpdateValueSilently(frame); } var maximum = animation == null ? 1 : animation.FrameCount - 1; if (animationTrackBar.TrackBar.Maximum != maximum) { animationTrackBar.TrackBar.Maximum = maximum; } animationTrackBar.Enabled = animation != null; animationPlayPause.Enabled = animation != null; }); } else { SetAvailableAnimations(Enumerable.Empty <string>()); } if (mesh != null) { meshSceneNode = new MeshSceneNode(Scene, mesh); Scene.Add(meshSceneNode, false); } if (phys != null) { physSceneNode = new PhysSceneNode(Scene, phys); Scene.Add(physSceneNode, false); //disabled by default. Enable if viewing only phys or model without meshes physSceneNode.Enabled = (modelSceneNode == null || !modelSceneNode.RenderableMeshes.Any()); ViewerControl.AddCheckBox("Show Physics", physSceneNode.Enabled, (v) => { physSceneNode.Enabled = v; }); } }