From 66b498738a863f73e06eee4429f30089cc100f83 Mon Sep 17 00:00:00 2001 From: dexy Date: Sat, 12 Jan 2019 13:49:31 +1100 Subject: [PATCH] Fixing carcols file loading, VehicleForm tools panel added --- .../GameFiles/FileTypes/CarColsFile.cs | 12 +- CodeWalker.Core/GameFiles/GameFileCache.cs | 12 +- .../GameFiles/MetaTypes/XmlMeta.cs | 3 +- Vehicles/VehicleForm.Designer.cs | 601 +++++++++++++++ Vehicles/VehicleForm.cs | 698 +++++++++++++++++- 5 files changed, 1303 insertions(+), 23 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/CarColsFile.cs b/CodeWalker.Core/GameFiles/FileTypes/CarColsFile.cs index 34b1bbc..70e2961 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/CarColsFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/CarColsFile.cs @@ -785,8 +785,8 @@ namespace CodeWalker.GameFiles public bool turnOffExtra { get; set; } public bool disableBonnetCamera { get; set; } public bool allowBonnetSlide { get; set; } - public byte weaponSlot { get; set; } //SByte? - public byte Unk_2656206330 { get; set; } //SByte? + public sbyte weaponSlot { get; set; } + public sbyte Unk_2656206330 { get; set; } public bool disableProjectileDriveby { get; set; } public bool disableDriveby { get; set; } public int Unk_161724223 { get; set; } @@ -832,12 +832,12 @@ namespace CodeWalker.GameFiles turnOffExtra = Xml.GetChildBoolAttribute(node, "turnOffExtra", "value"); disableBonnetCamera = Xml.GetChildBoolAttribute(node, "disableBonnetCamera", "value"); allowBonnetSlide = Xml.GetChildBoolAttribute(node, "allowBonnetSlide", "value"); - weaponSlot = (byte)Xml.GetChildIntAttribute(node, "weaponSlot", "value"); - Unk_2656206330 = (byte)Xml.GetChildIntAttribute(node, "Unk_2656206330", "value"); + weaponSlot = (sbyte)Xml.GetChildIntAttribute(node, "weaponSlot", "value"); + Unk_2656206330 = (sbyte)Xml.GetChildIntAttribute(node, "hash_9E527DFA", "value");//TODO: fix disableProjectileDriveby = Xml.GetChildBoolAttribute(node, "disableProjectileDriveby", "value"); disableDriveby = Xml.GetChildBoolAttribute(node, "disableDriveby", "value"); - Unk_161724223 = Xml.GetChildIntAttribute(node, "Unk_161724223", "value"); - Unk_484538291 = Xml.GetChildIntAttribute(node, "Unk_484538291", "value"); + Unk_161724223 = Xml.GetChildIntAttribute(node, "hash_09A3B73F", "value");//TODO: fix + Unk_484538291 = Xml.GetChildIntAttribute(node, "hash_1CE177B3", "value");//TODO: fix } public override string ToString() diff --git a/CodeWalker.Core/GameFiles/GameFileCache.cs b/CodeWalker.Core/GameFiles/GameFileCache.cs index 54aa4f2..95acf3a 100644 --- a/CodeWalker.Core/GameFiles/GameFileCache.cs +++ b/CodeWalker.Core/GameFiles/GameFileCache.cs @@ -1482,6 +1482,7 @@ namespace CodeWalker.GameFiles var allCarCols = new List(); var allCarModCols = new List(); var allCarVariations = new List(); + var allCarVariationsDict = new Dictionary(); var allVehicleLayouts = new List(); var addVehicleFiles = new Action>((from) => @@ -1527,8 +1528,15 @@ namespace CodeWalker.GameFiles if ((entry.NameLower == "carvariations.ymt") || (entry.NameLower == "carvariations.meta")) { var cf = RpfMan.GetFile(entry); - if (cf.VehicleModelInfo != null) - { } + if (cf.VehicleModelInfo?.variationData != null) + { + foreach (var variation in cf.VehicleModelInfo.variationData) + { + var name = variation.modelName.ToLowerInvariant(); + var hash = JenkHash.GenHash(name); + allCarVariationsDict[hash] = variation; + } + } allCarVariations.Add(cf); } if (entry.NameLower.StartsWith("vehiclelayouts") && entry.NameLower.EndsWith(".meta")) diff --git a/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs b/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs index 2d5c8ef..7ee5150 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs @@ -696,13 +696,14 @@ namespace CodeWalker.GameFiles public static MetaHash GetHash(string str) { - if (str == null) return 0; + if (string.IsNullOrEmpty(str)) return 0; if (str.StartsWith("hash_")) { return (MetaHash) Convert.ToUInt32(str.Substring(5), 16); } else { + JenkIndex.Ensure(str); return JenkHash.GenHash(str); } } diff --git a/Vehicles/VehicleForm.Designer.cs b/Vehicles/VehicleForm.Designer.cs index 35ebed0..2bcf081 100644 --- a/Vehicles/VehicleForm.Designer.cs +++ b/Vehicles/VehicleForm.Designer.cs @@ -35,7 +35,55 @@ this.MousedLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.StatsLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.StatsUpdateTimer = new System.Windows.Forms.Timer(this.components); + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.ToolsTabControl = new System.Windows.Forms.TabControl(); + this.ToolsModelsTabPage = new System.Windows.Forms.TabPage(); + this.ToolsTexturesTabPage = new System.Windows.Forms.TabPage(); + this.TextureViewerButton = new System.Windows.Forms.Button(); + this.TexturesTreeView = new CodeWalker.WinForms.TreeViewFix(); + this.ToolsDetailsTabPage = new System.Windows.Forms.TabPage(); + this.DetailsPropertyGrid = new CodeWalker.WinForms.ReadOnlyPropertyGrid(); + this.ToolsOptionsTabPage = new System.Windows.Forms.TabPage(); + this.HDTexturesCheckBox = new System.Windows.Forms.CheckBox(); + this.SkeletonsCheckBox = new System.Windows.Forms.CheckBox(); + this.TimeOfDayLabel = new System.Windows.Forms.Label(); + this.label19 = new System.Windows.Forms.Label(); + this.TimeOfDayTrackBar = new System.Windows.Forms.TrackBar(); + this.ControlLightDirCheckBox = new System.Windows.Forms.CheckBox(); + this.ShowCollisionMeshesCheckBox = new System.Windows.Forms.CheckBox(); + this.GridCheckBox = new System.Windows.Forms.CheckBox(); + this.GridCountComboBox = new System.Windows.Forms.ComboBox(); + this.label2 = new System.Windows.Forms.Label(); + this.GridSizeComboBox = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.StatusBarCheckBox = new System.Windows.Forms.CheckBox(); + this.ErrorConsoleCheckBox = new System.Windows.Forms.CheckBox(); + this.HDRRenderingCheckBox = new System.Windows.Forms.CheckBox(); + this.SkydomeCheckBox = new System.Windows.Forms.CheckBox(); + this.ShadowsCheckBox = new System.Windows.Forms.CheckBox(); + this.WireframeCheckBox = new System.Windows.Forms.CheckBox(); + this.RenderModeComboBox = new System.Windows.Forms.ComboBox(); + this.label11 = new System.Windows.Forms.Label(); + this.TextureSamplerComboBox = new System.Windows.Forms.ComboBox(); + this.TextureCoordsComboBox = new System.Windows.Forms.ComboBox(); + this.label10 = new System.Windows.Forms.Label(); + this.AnisotropicFilteringCheckBox = new System.Windows.Forms.CheckBox(); + this.label14 = new System.Windows.Forms.Label(); + this.ToolsPanelHideButton = new System.Windows.Forms.Button(); + this.ToolsDragPanel = new System.Windows.Forms.Panel(); + this.ModelsTreeView = new CodeWalker.WinForms.TreeViewFix(); + this.ToolsPanelShowButton = new System.Windows.Forms.Button(); + this.ConsolePanel = new System.Windows.Forms.Panel(); + this.ConsoleTextBox = new CodeWalker.WinForms.TextBoxFix(); this.StatusStrip.SuspendLayout(); + this.ToolsPanel.SuspendLayout(); + this.ToolsTabControl.SuspendLayout(); + this.ToolsModelsTabPage.SuspendLayout(); + this.ToolsTexturesTabPage.SuspendLayout(); + this.ToolsDetailsTabPage.SuspendLayout(); + this.ToolsOptionsTabPage.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.TimeOfDayTrackBar)).BeginInit(); + this.ConsolePanel.SuspendLayout(); this.SuspendLayout(); // // StatusStrip @@ -80,14 +128,517 @@ this.StatsUpdateTimer.Interval = 500; this.StatsUpdateTimer.Tick += new System.EventHandler(this.StatsUpdateTimer_Tick); // + // ToolsPanel + // + this.ToolsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.ToolsPanel.BackColor = System.Drawing.SystemColors.ControlDark; + this.ToolsPanel.Controls.Add(this.ToolsTabControl); + this.ToolsPanel.Controls.Add(this.ToolsPanelHideButton); + this.ToolsPanel.Controls.Add(this.ToolsDragPanel); + this.ToolsPanel.Location = new System.Drawing.Point(12, 12); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(233, 666); + this.ToolsPanel.TabIndex = 3; + this.ToolsPanel.Visible = false; + // + // ToolsTabControl + // + this.ToolsTabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ToolsTabControl.Controls.Add(this.ToolsModelsTabPage); + this.ToolsTabControl.Controls.Add(this.ToolsTexturesTabPage); + this.ToolsTabControl.Controls.Add(this.ToolsDetailsTabPage); + this.ToolsTabControl.Controls.Add(this.ToolsOptionsTabPage); + this.ToolsTabControl.Location = new System.Drawing.Point(2, 30); + this.ToolsTabControl.Name = "ToolsTabControl"; + this.ToolsTabControl.SelectedIndex = 0; + this.ToolsTabControl.Size = new System.Drawing.Size(228, 633); + this.ToolsTabControl.TabIndex = 1; + // + // ToolsModelsTabPage + // + this.ToolsModelsTabPage.Controls.Add(this.ModelsTreeView); + this.ToolsModelsTabPage.Location = new System.Drawing.Point(4, 22); + this.ToolsModelsTabPage.Name = "ToolsModelsTabPage"; + this.ToolsModelsTabPage.Padding = new System.Windows.Forms.Padding(3); + this.ToolsModelsTabPage.Size = new System.Drawing.Size(220, 607); + this.ToolsModelsTabPage.TabIndex = 0; + this.ToolsModelsTabPage.Text = "Models"; + this.ToolsModelsTabPage.UseVisualStyleBackColor = true; + // + // ToolsTexturesTabPage + // + this.ToolsTexturesTabPage.Controls.Add(this.TextureViewerButton); + this.ToolsTexturesTabPage.Controls.Add(this.TexturesTreeView); + this.ToolsTexturesTabPage.Location = new System.Drawing.Point(4, 22); + this.ToolsTexturesTabPage.Name = "ToolsTexturesTabPage"; + this.ToolsTexturesTabPage.Padding = new System.Windows.Forms.Padding(3); + this.ToolsTexturesTabPage.Size = new System.Drawing.Size(220, 607); + this.ToolsTexturesTabPage.TabIndex = 1; + this.ToolsTexturesTabPage.Text = "Textures"; + this.ToolsTexturesTabPage.UseVisualStyleBackColor = true; + // + // TextureViewerButton + // + this.TextureViewerButton.Location = new System.Drawing.Point(6, 6); + this.TextureViewerButton.Name = "TextureViewerButton"; + this.TextureViewerButton.Size = new System.Drawing.Size(113, 23); + this.TextureViewerButton.TabIndex = 2; + this.TextureViewerButton.Text = "Open texture viewer"; + this.TextureViewerButton.UseVisualStyleBackColor = true; + this.TextureViewerButton.Click += new System.EventHandler(this.TextureViewerButton_Click); + // + // TexturesTreeView + // + this.TexturesTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.TexturesTreeView.Location = new System.Drawing.Point(0, 34); + this.TexturesTreeView.Name = "TexturesTreeView"; + this.TexturesTreeView.ShowRootLines = false; + this.TexturesTreeView.Size = new System.Drawing.Size(220, 573); + this.TexturesTreeView.TabIndex = 1; + // + // ToolsDetailsTabPage + // + this.ToolsDetailsTabPage.Controls.Add(this.DetailsPropertyGrid); + this.ToolsDetailsTabPage.Location = new System.Drawing.Point(4, 22); + this.ToolsDetailsTabPage.Name = "ToolsDetailsTabPage"; + this.ToolsDetailsTabPage.Size = new System.Drawing.Size(220, 607); + this.ToolsDetailsTabPage.TabIndex = 2; + this.ToolsDetailsTabPage.Text = "Details"; + this.ToolsDetailsTabPage.UseVisualStyleBackColor = true; + // + // DetailsPropertyGrid + // + this.DetailsPropertyGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.DetailsPropertyGrid.HelpVisible = false; + this.DetailsPropertyGrid.Location = new System.Drawing.Point(0, 3); + this.DetailsPropertyGrid.Name = "DetailsPropertyGrid"; + this.DetailsPropertyGrid.PropertySort = System.Windows.Forms.PropertySort.NoSort; + this.DetailsPropertyGrid.ReadOnly = true; + this.DetailsPropertyGrid.Size = new System.Drawing.Size(220, 604); + this.DetailsPropertyGrid.TabIndex = 1; + this.DetailsPropertyGrid.ToolbarVisible = false; + // + // ToolsOptionsTabPage + // + this.ToolsOptionsTabPage.Controls.Add(this.HDTexturesCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.SkeletonsCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.TimeOfDayLabel); + this.ToolsOptionsTabPage.Controls.Add(this.label19); + this.ToolsOptionsTabPage.Controls.Add(this.TimeOfDayTrackBar); + this.ToolsOptionsTabPage.Controls.Add(this.ControlLightDirCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.ShowCollisionMeshesCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.GridCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.GridCountComboBox); + this.ToolsOptionsTabPage.Controls.Add(this.label2); + this.ToolsOptionsTabPage.Controls.Add(this.GridSizeComboBox); + this.ToolsOptionsTabPage.Controls.Add(this.label1); + this.ToolsOptionsTabPage.Controls.Add(this.StatusBarCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.ErrorConsoleCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.HDRRenderingCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.SkydomeCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.ShadowsCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.WireframeCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.RenderModeComboBox); + this.ToolsOptionsTabPage.Controls.Add(this.label11); + this.ToolsOptionsTabPage.Controls.Add(this.TextureSamplerComboBox); + this.ToolsOptionsTabPage.Controls.Add(this.TextureCoordsComboBox); + this.ToolsOptionsTabPage.Controls.Add(this.label10); + this.ToolsOptionsTabPage.Controls.Add(this.AnisotropicFilteringCheckBox); + this.ToolsOptionsTabPage.Controls.Add(this.label14); + this.ToolsOptionsTabPage.Location = new System.Drawing.Point(4, 22); + this.ToolsOptionsTabPage.Name = "ToolsOptionsTabPage"; + this.ToolsOptionsTabPage.Size = new System.Drawing.Size(220, 607); + this.ToolsOptionsTabPage.TabIndex = 3; + this.ToolsOptionsTabPage.Text = "Options"; + this.ToolsOptionsTabPage.UseVisualStyleBackColor = true; + // + // HDTexturesCheckBox + // + this.HDTexturesCheckBox.AutoSize = true; + this.HDTexturesCheckBox.Checked = true; + this.HDTexturesCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.HDTexturesCheckBox.Location = new System.Drawing.Point(19, 242); + this.HDTexturesCheckBox.Name = "HDTexturesCheckBox"; + this.HDTexturesCheckBox.Size = new System.Drawing.Size(82, 17); + this.HDTexturesCheckBox.TabIndex = 10; + this.HDTexturesCheckBox.Text = "HD textures"; + this.HDTexturesCheckBox.UseVisualStyleBackColor = true; + this.HDTexturesCheckBox.CheckedChanged += new System.EventHandler(this.HDTexturesCheckBox_CheckedChanged); + // + // SkeletonsCheckBox + // + this.SkeletonsCheckBox.AutoSize = true; + this.SkeletonsCheckBox.Location = new System.Drawing.Point(19, 444); + this.SkeletonsCheckBox.Name = "SkeletonsCheckBox"; + this.SkeletonsCheckBox.Size = new System.Drawing.Size(103, 17); + this.SkeletonsCheckBox.TabIndex = 22; + this.SkeletonsCheckBox.Text = "Show Skeletons"; + this.SkeletonsCheckBox.UseVisualStyleBackColor = true; + this.SkeletonsCheckBox.CheckedChanged += new System.EventHandler(this.SkeletonsCheckBox_CheckedChanged); + // + // TimeOfDayLabel + // + this.TimeOfDayLabel.AutoSize = true; + this.TimeOfDayLabel.Location = new System.Drawing.Point(78, 109); + this.TimeOfDayLabel.Name = "TimeOfDayLabel"; + this.TimeOfDayLabel.Size = new System.Drawing.Size(34, 13); + this.TimeOfDayLabel.TabIndex = 5; + this.TimeOfDayLabel.Text = "12:00"; + // + // label19 + // + this.label19.AutoSize = true; + this.label19.Location = new System.Drawing.Point(7, 109); + this.label19.Name = "label19"; + this.label19.Size = new System.Drawing.Size(65, 13); + this.label19.TabIndex = 4; + this.label19.Text = "Time of day:"; + // + // TimeOfDayTrackBar + // + this.TimeOfDayTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.TimeOfDayTrackBar.BackColor = System.Drawing.SystemColors.ControlLightLight; + this.TimeOfDayTrackBar.LargeChange = 60; + this.TimeOfDayTrackBar.Location = new System.Drawing.Point(9, 125); + this.TimeOfDayTrackBar.Maximum = 1440; + this.TimeOfDayTrackBar.Name = "TimeOfDayTrackBar"; + this.TimeOfDayTrackBar.Size = new System.Drawing.Size(203, 45); + this.TimeOfDayTrackBar.TabIndex = 6; + this.TimeOfDayTrackBar.TickFrequency = 60; + this.TimeOfDayTrackBar.Value = 720; + this.TimeOfDayTrackBar.Scroll += new System.EventHandler(this.TimeOfDayTrackBar_Scroll); + // + // ControlLightDirCheckBox + // + this.ControlLightDirCheckBox.AutoSize = true; + this.ControlLightDirCheckBox.Location = new System.Drawing.Point(19, 83); + this.ControlLightDirCheckBox.Name = "ControlLightDirCheckBox"; + this.ControlLightDirCheckBox.Size = new System.Drawing.Size(124, 17); + this.ControlLightDirCheckBox.TabIndex = 3; + this.ControlLightDirCheckBox.Text = "Control light direction"; + this.ControlLightDirCheckBox.UseVisualStyleBackColor = true; + this.ControlLightDirCheckBox.CheckedChanged += new System.EventHandler(this.ControlLightDirCheckBox_CheckedChanged); + // + // ShowCollisionMeshesCheckBox + // + this.ShowCollisionMeshesCheckBox.AutoSize = true; + this.ShowCollisionMeshesCheckBox.Location = new System.Drawing.Point(19, 173); + this.ShowCollisionMeshesCheckBox.Name = "ShowCollisionMeshesCheckBox"; + this.ShowCollisionMeshesCheckBox.Size = new System.Drawing.Size(132, 17); + this.ShowCollisionMeshesCheckBox.TabIndex = 7; + this.ShowCollisionMeshesCheckBox.Text = "Show collision meshes"; + this.ShowCollisionMeshesCheckBox.UseVisualStyleBackColor = true; + this.ShowCollisionMeshesCheckBox.CheckedChanged += new System.EventHandler(this.ShowCollisionMeshesCheckBox_CheckedChanged); + // + // GridCheckBox + // + this.GridCheckBox.AutoSize = true; + this.GridCheckBox.Location = new System.Drawing.Point(19, 364); + this.GridCheckBox.Name = "GridCheckBox"; + this.GridCheckBox.Size = new System.Drawing.Size(45, 17); + this.GridCheckBox.TabIndex = 17; + this.GridCheckBox.Text = "Grid"; + this.GridCheckBox.UseVisualStyleBackColor = true; + this.GridCheckBox.CheckedChanged += new System.EventHandler(this.GridCheckBox_CheckedChanged); + // + // GridCountComboBox + // + this.GridCountComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.GridCountComboBox.FormattingEnabled = true; + this.GridCountComboBox.Items.AddRange(new object[] { + "20", + "40", + "60", + "100"}); + this.GridCountComboBox.Location = new System.Drawing.Point(83, 411); + this.GridCountComboBox.Name = "GridCountComboBox"; + this.GridCountComboBox.Size = new System.Drawing.Size(114, 21); + this.GridCountComboBox.TabIndex = 21; + this.GridCountComboBox.SelectedIndexChanged += new System.EventHandler(this.GridCountComboBox_SelectedIndexChanged); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(7, 414); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(59, 13); + this.label2.TabIndex = 20; + this.label2.Text = "Grid count:"; + // + // GridSizeComboBox + // + this.GridSizeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.GridSizeComboBox.FormattingEnabled = true; + this.GridSizeComboBox.Items.AddRange(new object[] { + "0.1", + "1.0", + "10", + "100"}); + this.GridSizeComboBox.Location = new System.Drawing.Point(83, 384); + this.GridSizeComboBox.Name = "GridSizeComboBox"; + this.GridSizeComboBox.Size = new System.Drawing.Size(114, 21); + this.GridSizeComboBox.TabIndex = 19; + this.GridSizeComboBox.SelectedIndexChanged += new System.EventHandler(this.GridSizeComboBox_SelectedIndexChanged); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(7, 387); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(70, 13); + this.label1.TabIndex = 18; + this.label1.Text = "Grid unit size:"; + // + // StatusBarCheckBox + // + this.StatusBarCheckBox.AutoSize = true; + this.StatusBarCheckBox.Checked = true; + this.StatusBarCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.StatusBarCheckBox.Location = new System.Drawing.Point(19, 480); + this.StatusBarCheckBox.Name = "StatusBarCheckBox"; + this.StatusBarCheckBox.Size = new System.Drawing.Size(74, 17); + this.StatusBarCheckBox.TabIndex = 23; + this.StatusBarCheckBox.Text = "Status bar"; + this.StatusBarCheckBox.UseVisualStyleBackColor = true; + this.StatusBarCheckBox.CheckedChanged += new System.EventHandler(this.StatusBarCheckBox_CheckedChanged); + // + // ErrorConsoleCheckBox + // + this.ErrorConsoleCheckBox.AutoSize = true; + this.ErrorConsoleCheckBox.Location = new System.Drawing.Point(105, 480); + this.ErrorConsoleCheckBox.Name = "ErrorConsoleCheckBox"; + this.ErrorConsoleCheckBox.Size = new System.Drawing.Size(88, 17); + this.ErrorConsoleCheckBox.TabIndex = 24; + this.ErrorConsoleCheckBox.Text = "Error console"; + this.ErrorConsoleCheckBox.UseVisualStyleBackColor = true; + this.ErrorConsoleCheckBox.CheckedChanged += new System.EventHandler(this.ErrorConsoleCheckBox_CheckedChanged); + // + // HDRRenderingCheckBox + // + this.HDRRenderingCheckBox.AutoSize = true; + this.HDRRenderingCheckBox.Checked = true; + this.HDRRenderingCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.HDRRenderingCheckBox.Location = new System.Drawing.Point(19, 14); + this.HDRRenderingCheckBox.Name = "HDRRenderingCheckBox"; + this.HDRRenderingCheckBox.Size = new System.Drawing.Size(97, 17); + this.HDRRenderingCheckBox.TabIndex = 0; + this.HDRRenderingCheckBox.Text = "HDR rendering"; + this.HDRRenderingCheckBox.UseVisualStyleBackColor = true; + this.HDRRenderingCheckBox.CheckedChanged += new System.EventHandler(this.HDRRenderingCheckBox_CheckedChanged); + // + // SkydomeCheckBox + // + this.SkydomeCheckBox.AutoSize = true; + this.SkydomeCheckBox.Location = new System.Drawing.Point(19, 60); + this.SkydomeCheckBox.Name = "SkydomeCheckBox"; + this.SkydomeCheckBox.Size = new System.Drawing.Size(70, 17); + this.SkydomeCheckBox.TabIndex = 2; + this.SkydomeCheckBox.Text = "Skydome"; + this.SkydomeCheckBox.UseVisualStyleBackColor = true; + this.SkydomeCheckBox.CheckedChanged += new System.EventHandler(this.SkydomeCheckBox_CheckedChanged); + // + // ShadowsCheckBox + // + this.ShadowsCheckBox.AutoSize = true; + this.ShadowsCheckBox.Checked = true; + this.ShadowsCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.ShadowsCheckBox.Location = new System.Drawing.Point(19, 37); + this.ShadowsCheckBox.Name = "ShadowsCheckBox"; + this.ShadowsCheckBox.Size = new System.Drawing.Size(70, 17); + this.ShadowsCheckBox.TabIndex = 1; + this.ShadowsCheckBox.Text = "Shadows"; + this.ShadowsCheckBox.UseVisualStyleBackColor = true; + this.ShadowsCheckBox.CheckedChanged += new System.EventHandler(this.ShadowsCheckBox_CheckedChanged); + // + // WireframeCheckBox + // + this.WireframeCheckBox.AutoSize = true; + this.WireframeCheckBox.Location = new System.Drawing.Point(19, 196); + this.WireframeCheckBox.Name = "WireframeCheckBox"; + this.WireframeCheckBox.Size = new System.Drawing.Size(74, 17); + this.WireframeCheckBox.TabIndex = 8; + this.WireframeCheckBox.Text = "Wireframe"; + this.WireframeCheckBox.UseVisualStyleBackColor = true; + this.WireframeCheckBox.CheckedChanged += new System.EventHandler(this.WireframeCheckBox_CheckedChanged); + // + // RenderModeComboBox + // + this.RenderModeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.RenderModeComboBox.FormattingEnabled = true; + this.RenderModeComboBox.Items.AddRange(new object[] { + "Default", + "Single texture", + "Vertex normals", + "Vertex tangents", + "Vertex colour 1", + "Vertex colour 2", + "Texture coord 1", + "Texture coord 2", + "Texture coord 3"}); + this.RenderModeComboBox.Location = new System.Drawing.Point(83, 274); + this.RenderModeComboBox.Name = "RenderModeComboBox"; + this.RenderModeComboBox.Size = new System.Drawing.Size(114, 21); + this.RenderModeComboBox.TabIndex = 12; + this.RenderModeComboBox.SelectedIndexChanged += new System.EventHandler(this.RenderModeComboBox_SelectedIndexChanged); + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(7, 304); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(67, 13); + this.label11.TabIndex = 13; + this.label11.Text = "Tex sampler:"; + // + // TextureSamplerComboBox + // + this.TextureSamplerComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.TextureSamplerComboBox.Enabled = false; + this.TextureSamplerComboBox.FormattingEnabled = true; + this.TextureSamplerComboBox.Location = new System.Drawing.Point(83, 301); + this.TextureSamplerComboBox.Name = "TextureSamplerComboBox"; + this.TextureSamplerComboBox.Size = new System.Drawing.Size(114, 21); + this.TextureSamplerComboBox.TabIndex = 14; + this.TextureSamplerComboBox.SelectedIndexChanged += new System.EventHandler(this.TextureSamplerComboBox_SelectedIndexChanged); + // + // TextureCoordsComboBox + // + this.TextureCoordsComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.TextureCoordsComboBox.Enabled = false; + this.TextureCoordsComboBox.FormattingEnabled = true; + this.TextureCoordsComboBox.Items.AddRange(new object[] { + "Texture coord 1", + "Texture coord 2", + "Texture coord 3"}); + this.TextureCoordsComboBox.Location = new System.Drawing.Point(83, 328); + this.TextureCoordsComboBox.Name = "TextureCoordsComboBox"; + this.TextureCoordsComboBox.Size = new System.Drawing.Size(114, 21); + this.TextureCoordsComboBox.TabIndex = 16; + this.TextureCoordsComboBox.SelectedIndexChanged += new System.EventHandler(this.TextureCoordsComboBox_SelectedIndexChanged); + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(7, 277); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(74, 13); + this.label10.TabIndex = 11; + this.label10.Text = "Render mode:"; + // + // AnisotropicFilteringCheckBox + // + this.AnisotropicFilteringCheckBox.AutoSize = true; + this.AnisotropicFilteringCheckBox.Checked = true; + this.AnisotropicFilteringCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.AnisotropicFilteringCheckBox.Location = new System.Drawing.Point(19, 219); + this.AnisotropicFilteringCheckBox.Name = "AnisotropicFilteringCheckBox"; + this.AnisotropicFilteringCheckBox.Size = new System.Drawing.Size(114, 17); + this.AnisotropicFilteringCheckBox.TabIndex = 9; + this.AnisotropicFilteringCheckBox.Text = "Anisotropic filtering"; + this.AnisotropicFilteringCheckBox.UseVisualStyleBackColor = true; + this.AnisotropicFilteringCheckBox.CheckedChanged += new System.EventHandler(this.AnisotropicFilteringCheckBox_CheckedChanged); + // + // label14 + // + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(7, 331); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(63, 13); + this.label14.TabIndex = 15; + this.label14.Text = "Tex coords:"; + // + // ToolsPanelHideButton + // + this.ToolsPanelHideButton.Location = new System.Drawing.Point(3, 3); + this.ToolsPanelHideButton.Name = "ToolsPanelHideButton"; + this.ToolsPanelHideButton.Size = new System.Drawing.Size(30, 23); + this.ToolsPanelHideButton.TabIndex = 0; + this.ToolsPanelHideButton.Text = "<<"; + this.ToolsPanelHideButton.UseVisualStyleBackColor = true; + this.ToolsPanelHideButton.Click += new System.EventHandler(this.ToolsPanelHideButton_Click); + // + // ToolsDragPanel + // + this.ToolsDragPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.ToolsDragPanel.Cursor = System.Windows.Forms.Cursors.VSplit; + this.ToolsDragPanel.Location = new System.Drawing.Point(230, 0); + this.ToolsDragPanel.Name = "ToolsDragPanel"; + this.ToolsDragPanel.Size = new System.Drawing.Size(4, 666); + this.ToolsDragPanel.TabIndex = 17; + this.ToolsDragPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ToolsDragPanel_MouseDown); + this.ToolsDragPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ToolsDragPanel_MouseMove); + this.ToolsDragPanel.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ToolsDragPanel_MouseUp); + // + // ModelsTreeView + // + this.ModelsTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ModelsTreeView.CheckBoxes = true; + this.ModelsTreeView.Location = new System.Drawing.Point(0, 3); + this.ModelsTreeView.Name = "ModelsTreeView"; + this.ModelsTreeView.ShowRootLines = false; + this.ModelsTreeView.Size = new System.Drawing.Size(220, 604); + this.ModelsTreeView.TabIndex = 2; + this.ModelsTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.ModelsTreeView_AfterCheck); + this.ModelsTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.ModelsTreeView_NodeMouseDoubleClick); + this.ModelsTreeView.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ModelsTreeView_KeyPress); + // + // ToolsPanelShowButton + // + this.ToolsPanelShowButton.Location = new System.Drawing.Point(15, 15); + this.ToolsPanelShowButton.Name = "ToolsPanelShowButton"; + this.ToolsPanelShowButton.Size = new System.Drawing.Size(30, 23); + this.ToolsPanelShowButton.TabIndex = 4; + this.ToolsPanelShowButton.Text = ">>"; + this.ToolsPanelShowButton.UseVisualStyleBackColor = true; + this.ToolsPanelShowButton.Click += new System.EventHandler(this.ToolsPanelShowButton_Click); + // + // ConsolePanel + // + this.ConsolePanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ConsolePanel.BackColor = System.Drawing.SystemColors.Control; + this.ConsolePanel.Controls.Add(this.ConsoleTextBox); + this.ConsolePanel.Location = new System.Drawing.Point(252, 577); + this.ConsolePanel.Name = "ConsolePanel"; + this.ConsolePanel.Size = new System.Drawing.Size(720, 101); + this.ConsolePanel.TabIndex = 5; + this.ConsolePanel.Visible = false; + // + // ConsoleTextBox + // + this.ConsoleTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ConsoleTextBox.Location = new System.Drawing.Point(3, 3); + this.ConsoleTextBox.Multiline = true; + this.ConsoleTextBox.Name = "ConsoleTextBox"; + this.ConsoleTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.ConsoleTextBox.Size = new System.Drawing.Size(714, 95); + this.ConsoleTextBox.TabIndex = 0; + // // VehicleForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.MidnightBlue; this.ClientSize = new System.Drawing.Size(984, 711); + this.Controls.Add(this.ConsolePanel); + this.Controls.Add(this.ToolsPanel); this.Controls.Add(this.StatusStrip); + this.Controls.Add(this.ToolsPanelShowButton); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.KeyPreview = true; this.Name = "VehicleForm"; this.Text = "Vehicle Viewer - CodeWalker by dexyfex"; this.Deactivate += new System.EventHandler(this.VehicleForm_Deactivate); @@ -99,6 +650,16 @@ this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.VehicleForm_MouseUp); this.StatusStrip.ResumeLayout(false); this.StatusStrip.PerformLayout(); + this.ToolsPanel.ResumeLayout(false); + this.ToolsTabControl.ResumeLayout(false); + this.ToolsModelsTabPage.ResumeLayout(false); + this.ToolsTexturesTabPage.ResumeLayout(false); + this.ToolsDetailsTabPage.ResumeLayout(false); + this.ToolsOptionsTabPage.ResumeLayout(false); + this.ToolsOptionsTabPage.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.TimeOfDayTrackBar)).EndInit(); + this.ConsolePanel.ResumeLayout(false); + this.ConsolePanel.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -111,5 +672,45 @@ private System.Windows.Forms.ToolStripStatusLabel MousedLabel; private System.Windows.Forms.ToolStripStatusLabel StatsLabel; private System.Windows.Forms.Timer StatsUpdateTimer; + private System.Windows.Forms.Panel ToolsPanel; + private System.Windows.Forms.TabControl ToolsTabControl; + private System.Windows.Forms.TabPage ToolsModelsTabPage; + private System.Windows.Forms.TabPage ToolsTexturesTabPage; + private System.Windows.Forms.Button TextureViewerButton; + private WinForms.TreeViewFix TexturesTreeView; + private System.Windows.Forms.TabPage ToolsDetailsTabPage; + private WinForms.ReadOnlyPropertyGrid DetailsPropertyGrid; + private System.Windows.Forms.TabPage ToolsOptionsTabPage; + private System.Windows.Forms.CheckBox HDTexturesCheckBox; + private System.Windows.Forms.CheckBox SkeletonsCheckBox; + private System.Windows.Forms.Label TimeOfDayLabel; + private System.Windows.Forms.Label label19; + private System.Windows.Forms.TrackBar TimeOfDayTrackBar; + private System.Windows.Forms.CheckBox ControlLightDirCheckBox; + private System.Windows.Forms.CheckBox ShowCollisionMeshesCheckBox; + private System.Windows.Forms.CheckBox GridCheckBox; + private System.Windows.Forms.ComboBox GridCountComboBox; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox GridSizeComboBox; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.CheckBox StatusBarCheckBox; + private System.Windows.Forms.CheckBox ErrorConsoleCheckBox; + private System.Windows.Forms.CheckBox HDRRenderingCheckBox; + private System.Windows.Forms.CheckBox SkydomeCheckBox; + private System.Windows.Forms.CheckBox ShadowsCheckBox; + private System.Windows.Forms.CheckBox WireframeCheckBox; + private System.Windows.Forms.ComboBox RenderModeComboBox; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.ComboBox TextureSamplerComboBox; + private System.Windows.Forms.ComboBox TextureCoordsComboBox; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.CheckBox AnisotropicFilteringCheckBox; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.Button ToolsPanelHideButton; + private System.Windows.Forms.Panel ToolsDragPanel; + private WinForms.TreeViewFix ModelsTreeView; + private System.Windows.Forms.Button ToolsPanelShowButton; + private System.Windows.Forms.Panel ConsolePanel; + private WinForms.TextBoxFix ConsoleTextBox; } } \ No newline at end of file diff --git a/Vehicles/VehicleForm.cs b/Vehicles/VehicleForm.cs index bd49827..0dcd051 100644 --- a/Vehicles/VehicleForm.cs +++ b/Vehicles/VehicleForm.cs @@ -4,6 +4,7 @@ using CodeWalker.Rendering; using CodeWalker.World; using SharpDX; using SharpDX.Direct3D11; +using SharpDX.XInput; using System; using System.Collections.Generic; using System.ComponentModel; @@ -15,6 +16,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using Color = SharpDX.Color; namespace CodeWalker.Vehicles { @@ -57,6 +59,23 @@ namespace CodeWalker.Vehicles + bool toolsPanelResizing = false; + int toolsPanelResizeStartX = 0; + int toolsPanelResizeStartLeft = 0; + int toolsPanelResizeStartRight = 0; + + Dictionary DrawableDrawFlags = new Dictionary(); + + bool enableGrid = false; + float gridSize = 1.0f; + int gridCount = 40; + List gridVerts = new List(); + object gridSyncRoot = new object(); + + + + + public VehicleForm() { @@ -109,7 +128,7 @@ namespace CodeWalker.Vehicles camera.CurrentRotation.X = 0.5f * (float)Math.PI; - //LoadSettings(); + LoadSettings(); formopen = true; @@ -141,7 +160,7 @@ namespace CodeWalker.Vehicles if (!Monitor.TryEnter(Renderer.RenderSyncRoot, 50)) { return; } //couldn't get a lock, try again next time - //UpdateControlInputs(elapsed); + UpdateControlInputs(elapsed); //space.Update(elapsed); @@ -178,7 +197,7 @@ namespace CodeWalker.Vehicles //RenderSelection(); - //RenderGrid(context); + RenderGrid(context); Renderer.RenderQueued(); @@ -229,6 +248,21 @@ namespace CodeWalker.Vehicles } + + MetaName[] texsamplers = RenderableGeometry.GetTextureSamplerList(); + foreach (var texsampler in texsamplers) + { + TextureSamplerComboBox.Items.Add(texsampler); + } + //TextureSamplerComboBox.SelectedIndex = 0;//LoadSettings will do this.. + + + UpdateGridVerts(); + GridSizeComboBox.SelectedIndex = 1; + GridCountComboBox.SelectedIndex = 1; + + + Input.Init(); @@ -305,6 +339,25 @@ namespace CodeWalker.Vehicles + private void LoadSettings() + { + var s = Settings.Default; + //WindowState = s.WindowMaximized ? FormWindowState.Maximized : WindowState; + //FullScreenCheckBox.Checked = s.FullScreen; + WireframeCheckBox.Checked = s.Wireframe; + HDRRenderingCheckBox.Checked = s.HDR; + ShadowsCheckBox.Checked = s.Shadows; + SkydomeCheckBox.Checked = s.Skydome; + RenderModeComboBox.SelectedIndex = Math.Max(RenderModeComboBox.FindString(s.RenderMode), 0); + TextureSamplerComboBox.SelectedIndex = Math.Max(TextureSamplerComboBox.FindString(s.RenderTextureSampler), 0); + TextureCoordsComboBox.SelectedIndex = Math.Max(TextureCoordsComboBox.FindString(s.RenderTextureSamplerCoord), 0); + AnisotropicFilteringCheckBox.Checked = s.AnisotropicFiltering; + //ErrorConsoleCheckBox.Checked = s.ShowErrorConsole; + //StatusBarCheckBox.Checked = s.ShowStatusBar; + } + + + private void LoadWorld() { UpdateStatus("Loading timecycles..."); @@ -355,7 +408,7 @@ namespace CodeWalker.Vehicles else { //TODO: error logging.. - //ConsoleTextBox.AppendText(text + "\r\n"); + ConsoleTextBox.AppendText(text + "\r\n"); //StatusLabel.Text = text; //MessageBox.Show(text); } @@ -378,6 +431,364 @@ namespace CodeWalker.Vehicles camera.MouseRotate(dx, dy); } + private void MoveCameraToView(Vector3 pos, float rad) + { + //move the camera to a default place where the given sphere is fully visible. + + rad = Math.Max(0.5f, rad); + + camera.FollowEntity.Position = pos; + camera.TargetDistance = rad * 1.6f; + camera.CurrentDistance = rad * 1.6f; + + } + + + private void AddDrawableTreeNode(DrawableBase drawable, uint hash, bool check) + { + MetaHash mhash = new MetaHash(hash); + + var dnode = ModelsTreeView.Nodes.Add(mhash.ToString()); + dnode.Tag = drawable; + dnode.Checked = check; + + AddDrawableModelsTreeNodes(drawable.DrawableModelsHigh, "High Detail", true, dnode); + AddDrawableModelsTreeNodes(drawable.DrawableModelsMedium, "Medium Detail", false, dnode); + AddDrawableModelsTreeNodes(drawable.DrawableModelsLow, "Low Detail", false, dnode); + AddDrawableModelsTreeNodes(drawable.DrawableModelsVeryLow, "Very Low Detail", false, dnode); + //AddSelectionDrawableModelsTreeNodes(item.Drawable.DrawableModelsX, "X Detail", false, dnode); + + } + private void AddDrawableModelsTreeNodes(ResourcePointerList64 models, string prefix, bool check, TreeNode parentDrawableNode = null) + { + if (models == null) return; + if (models.data_items == null) return; + + for (int mi = 0; mi < models.data_items.Length; mi++) + { + var tnc = (parentDrawableNode != null) ? parentDrawableNode.Nodes : ModelsTreeView.Nodes; + + var model = models.data_items[mi]; + string mprefix = prefix + " " + (mi + 1).ToString(); + var mnode = tnc.Add(mprefix + " " + model.ToString()); + mnode.Tag = model; + mnode.Checked = check; + + var tmnode = TexturesTreeView.Nodes.Add(mprefix + " " + model.ToString()); + tmnode.Tag = model; + + if (!check) + { + Renderer.SelectionModelDrawFlags[model] = false; + } + + if ((model.Geometries == null) || (model.Geometries.data_items == null)) continue; + + foreach (var geom in model.Geometries.data_items) + { + var gname = geom.ToString(); + var gnode = mnode.Nodes.Add(gname); + gnode.Tag = geom; + gnode.Checked = true;// check; + + var tgnode = tmnode.Nodes.Add(gname); + tgnode.Tag = geom; + + if ((geom.Shader != null) && (geom.Shader.ParametersList != null) && (geom.Shader.ParametersList.Hashes != null)) + { + var pl = geom.Shader.ParametersList; + var h = pl.Hashes; + var p = pl.Parameters; + for (int ip = 0; ip < h.Length; ip++) + { + var hash = pl.Hashes[ip]; + var parm = pl.Parameters[ip]; + var tex = parm.Data as TextureBase; + if (tex != null) + { + var t = tex as Texture; + var tstr = tex.Name.Trim(); + if (t != null) + { + tstr = string.Format("{0} ({1}x{2}, embedded)", tex.Name, t.Width, t.Height); + } + var tnode = tgnode.Nodes.Add(hash.ToString().Trim() + ": " + tstr); + tnode.Tag = tex; + } + } + tgnode.Expand(); + } + + } + + mnode.Expand(); + tmnode.Expand(); + } + } + private void UpdateSelectionDrawFlags(TreeNode node) + { + //update the selection draw flags depending on tag and checked/unchecked + var drwbl = node.Tag as DrawableBase; + var model = node.Tag as DrawableModel; + var geom = node.Tag as DrawableGeometry; + bool rem = node.Checked; + lock (Renderer.RenderSyncRoot) + { + if (drwbl != null) + { + if (rem) + { + if (DrawableDrawFlags.ContainsKey(drwbl)) + { + DrawableDrawFlags.Remove(drwbl); + } + } + else + { + DrawableDrawFlags[drwbl] = false; + } + } + if (model != null) + { + if (rem) + { + if (Renderer.SelectionModelDrawFlags.ContainsKey(model)) + { + Renderer.SelectionModelDrawFlags.Remove(model); + } + } + else + { + Renderer.SelectionModelDrawFlags[model] = false; + } + } + if (geom != null) + { + if (rem) + { + if (Renderer.SelectionGeometryDrawFlags.ContainsKey(geom)) + { + Renderer.SelectionGeometryDrawFlags.Remove(geom); + } + } + else + { + Renderer.SelectionGeometryDrawFlags[geom] = false; + } + } + //updateArchetypeStatus = true; + } + } + + private void UpdateModelsUI(DrawableBase drawable) + { + DetailsPropertyGrid.SelectedObject = drawable; + + DrawableDrawFlags.Clear(); + Renderer.SelectionModelDrawFlags.Clear(); + Renderer.SelectionGeometryDrawFlags.Clear(); + ModelsTreeView.Nodes.Clear(); + ModelsTreeView.ShowRootLines = false; + TexturesTreeView.Nodes.Clear(); + if (drawable != null) + { + AddDrawableModelsTreeNodes(drawable.DrawableModelsHigh, "High Detail", true); + AddDrawableModelsTreeNodes(drawable.DrawableModelsMedium, "Medium Detail", false); + AddDrawableModelsTreeNodes(drawable.DrawableModelsLow, "Low Detail", false); + AddDrawableModelsTreeNodes(drawable.DrawableModelsVeryLow, "Very Low Detail", false); + //AddSelectionDrawableModelsTreeNodes(item.Drawable.DrawableModelsX, "X Detail", false); + } + } + + public void LoadModel(YftFile yft) + { + if (yft == null) return; + + //FileName = yft.Name; + //Yft = yft; + + var dr = yft.Fragment?.Drawable; + if (dr != null) + { + MoveCameraToView(dr.BoundingCenter, dr.BoundingSphereRadius); + } + + UpdateModelsUI(yft.Fragment.Drawable); + } + + + + private void UpdateTimeOfDayLabel() + { + int v = TimeOfDayTrackBar.Value; + float fh = v / 60.0f; + int ih = (int)fh; + int im = v - (ih * 60); + if (ih == 24) ih = 0; + TimeOfDayLabel.Text = string.Format("{0:00}:{1:00}", ih, im); + } + + + private void UpdateControlInputs(float elapsed) + { + if (elapsed > 0.1f) elapsed = 0.1f; + + var s = Settings.Default; + + float moveSpeed = 2.0f; + + + Input.Update(elapsed); + + if (Input.xbenable) + { + //if (ControllerButtonJustPressed(GamepadButtonFlags.Start)) + //{ + // SetControlMode(ControlMode == WorldControlMode.Free ? WorldControlMode.Ped : WorldControlMode.Free); + //} + } + + + + if (Input.ShiftPressed) + { + moveSpeed *= 5.0f; + } + if (Input.CtrlPressed) + { + moveSpeed *= 0.2f; + } + + Vector3 movevec = Input.KeyboardMoveVec(false); + + + //if (MapViewEnabled == true) + //{ + // movevec *= elapsed * 100.0f * Math.Min(camera.OrthographicTargetSize * 0.01f, 30.0f); + // float mapviewscale = 1.0f / camera.Height; + // float fdx = MapViewDragX * mapviewscale; + // float fdy = MapViewDragY * mapviewscale; + // movevec.X -= fdx * camera.OrthographicSize; + // movevec.Y += fdy * camera.OrthographicSize; + //} + //else + { + //normal movement + movevec *= elapsed * moveSpeed * Math.Min(camera.TargetDistance, 50.0f); + } + + + Vector3 movewvec = camera.ViewInvQuaternion.Multiply(movevec); + camEntity.Position += movewvec; + + //MapViewDragX = 0; + //MapViewDragY = 0; + + + + + if (Input.xbenable) + { + camera.ControllerRotate(Input.xblx + Input.xbrx, Input.xbly + Input.xbry); + + float zoom = 0.0f; + float zoomspd = s.XInputZoomSpeed; + float zoomamt = zoomspd * elapsed; + if (Input.ControllerButtonPressed(GamepadButtonFlags.DPadUp)) zoom += zoomamt; + if (Input.ControllerButtonPressed(GamepadButtonFlags.DPadDown)) zoom -= zoomamt; + + camera.ControllerZoom(zoom); + + float acc = 0.0f; + float accspd = s.XInputMoveSpeed;//actually accel speed... + acc += Input.xbrt * accspd; + acc -= Input.xblt * accspd; + + Vector3 newdir = camera.ViewDirection; //maybe use the "vehicle" direction...? + Input.xbcontrolvelocity += (acc * elapsed); + + if (Input.ControllerButtonPressed(GamepadButtonFlags.A | GamepadButtonFlags.RightShoulder)) //handbrake... + { + Input.xbcontrolvelocity *= Math.Max(0.75f - elapsed, 0);//not ideal for low fps... + //xbcontrolvelocity = 0.0f; + if (Math.Abs(Input.xbcontrolvelocity) < 0.001f) Input.xbcontrolvelocity = 0.0f; + } + + camEntity.Velocity = newdir * Input.xbcontrolvelocity; + camEntity.Position += camEntity.Velocity * elapsed; + + + //fire! + //if (ControllerButtonJustPressed(GamepadButtonFlags.LeftShoulder)) + //{ + // SpawnTestEntity(true); + //} + + } + + + + } + + + + private void UpdateGridVerts() + { + lock (gridSyncRoot) + { + gridVerts.Clear(); + + float s = gridSize * gridCount * 0.5f; + uint cblack = (uint)Color.Black.ToRgba(); + uint cgray = (uint)Color.DimGray.ToRgba(); + uint cred = (uint)Color.DarkRed.ToRgba(); + uint cgrn = (uint)Color.DarkGreen.ToRgba(); + int interval = 10; + + for (int i = 0; i <= gridCount; i++) + { + float o = (gridSize * i) - s; + if ((i % interval) != 0) + { + gridVerts.Add(new VertexTypePC() { Position = new Vector3(o, -s, 0), Colour = cgray }); + gridVerts.Add(new VertexTypePC() { Position = new Vector3(o, s, 0), Colour = cgray }); + gridVerts.Add(new VertexTypePC() { Position = new Vector3(-s, o, 0), Colour = cgray }); + gridVerts.Add(new VertexTypePC() { Position = new Vector3(s, o, 0), Colour = cgray }); + } + } + for (int i = 0; i <= gridCount; i++) //draw main lines last, so they are on top + { + float o = (gridSize * i) - s; + if ((i % interval) == 0) + { + var cx = (o == 0) ? cred : cblack; + var cy = (o == 0) ? cgrn : cblack; + gridVerts.Add(new VertexTypePC() { Position = new Vector3(o, -s, 0), Colour = cy }); + gridVerts.Add(new VertexTypePC() { Position = new Vector3(o, s, 0), Colour = cy }); + gridVerts.Add(new VertexTypePC() { Position = new Vector3(-s, o, 0), Colour = cx }); + gridVerts.Add(new VertexTypePC() { Position = new Vector3(s, o, 0), Colour = cx }); + } + } + + } + } + + private void RenderGrid(DeviceContext context) + { + if (!enableGrid) return; + + lock (gridSyncRoot) + { + if (gridVerts.Count > 0) + { + Renderer.RenderLines(gridVerts); + } + } + } + + + + @@ -394,10 +805,10 @@ namespace CodeWalker.Vehicles case MouseButtons.Right: MouseRButtonDown = true; break; } - //if (!ToolsPanelShowButton.Focused) - //{ - // ToolsPanelShowButton.Focus(); //make sure no textboxes etc are focused! - //} + if (!ToolsPanelShowButton.Focused) + { + ToolsPanelShowButton.Focus(); //make sure no textboxes etc are focused! + } MouseDownPoint = e.Location; MouseLastPoint = MouseDownPoint; @@ -462,9 +873,9 @@ namespace CodeWalker.Vehicles timecycle.SetTime(tod); Renderer.timeofday = tod; - //float fv = tod * 60.0f; - //TimeOfDayTrackBar.Value = (int)fv; - //UpdateTimeOfDayLabel(); + float fv = tod * 60.0f; + TimeOfDayTrackBar.Value = (int)fv; + UpdateTimeOfDayLabel(); } } @@ -598,12 +1009,271 @@ namespace CodeWalker.Vehicles if (Renderer.timerunning) { - //float fv = Renderer.timeofday * 60.0f; - ////TimeOfDayTrackBar.Value = (int)fv; - //UpdateTimeOfDayLabel(); + float fv = Renderer.timeofday * 60.0f; + //TimeOfDayTrackBar.Value = (int)fv; + UpdateTimeOfDayLabel(); } //CameraPositionTextBox.Text = FloatUtil.GetVector3String(camera.Position, "0.##"); } + + private void ToolsPanelShowButton_Click(object sender, EventArgs e) + { + ToolsPanel.Visible = true; + } + + private void ToolsPanelHideButton_Click(object sender, EventArgs e) + { + ToolsPanel.Visible = false; + } + + private void ToolsDragPanel_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + toolsPanelResizing = true; + toolsPanelResizeStartX = e.X + ToolsPanel.Left + ToolsDragPanel.Left; + toolsPanelResizeStartLeft = ToolsPanel.Left; + toolsPanelResizeStartRight = ToolsPanel.Right; + } + } + + private void ToolsDragPanel_MouseUp(object sender, MouseEventArgs e) + { + toolsPanelResizing = false; + } + + private void ToolsDragPanel_MouseMove(object sender, MouseEventArgs e) + { + if (toolsPanelResizing) + { + int rx = e.X + ToolsPanel.Left + ToolsDragPanel.Left; + int dx = rx - toolsPanelResizeStartX; + ToolsPanel.Width = toolsPanelResizeStartRight - toolsPanelResizeStartLeft + dx; + } + } + + private void ModelsTreeView_AfterCheck(object sender, TreeViewEventArgs e) + { + if (e.Node != null) + { + UpdateSelectionDrawFlags(e.Node); + } + } + + private void ModelsTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + if (e.Node != null) + { + e.Node.Checked = !e.Node.Checked; + //UpdateSelectionDrawFlags(e.Node); + } + } + + private void ModelsTreeView_KeyPress(object sender, KeyPressEventArgs e) + { + e.Handled = true; //stops annoying ding sound... + } + + private void HDRRenderingCheckBox_CheckedChanged(object sender, EventArgs e) + { + lock (Renderer.RenderSyncRoot) + { + Renderer.shaders.hdr = HDRRenderingCheckBox.Checked; + } + } + + private void ShadowsCheckBox_CheckedChanged(object sender, EventArgs e) + { + lock (Renderer.RenderSyncRoot) + { + Renderer.shaders.shadows = ShadowsCheckBox.Checked; + } + } + + private void SkydomeCheckBox_CheckedChanged(object sender, EventArgs e) + { + Renderer.renderskydome = SkydomeCheckBox.Checked; + //Renderer.controllightdir = !Renderer.renderskydome; + } + + private void ControlLightDirCheckBox_CheckedChanged(object sender, EventArgs e) + { + Renderer.controllightdir = ControlLightDirCheckBox.Checked; + } + + private void TimeOfDayTrackBar_Scroll(object sender, EventArgs e) + { + int v = TimeOfDayTrackBar.Value; + float fh = v / 60.0f; + UpdateTimeOfDayLabel(); + lock (Renderer.RenderSyncRoot) + { + Renderer.timeofday = fh; + timecycle.SetTime(Renderer.timeofday); + } + } + + private void ShowCollisionMeshesCheckBox_CheckedChanged(object sender, EventArgs e) + { + Renderer.rendercollisionmeshes = ShowCollisionMeshesCheckBox.Checked; + Renderer.rendercollisionmeshlayerdrawable = ShowCollisionMeshesCheckBox.Checked; + } + + private void WireframeCheckBox_CheckedChanged(object sender, EventArgs e) + { + Renderer.shaders.wireframe = WireframeCheckBox.Checked; + } + + private void AnisotropicFilteringCheckBox_CheckedChanged(object sender, EventArgs e) + { + Renderer.shaders.AnisotropicFiltering = AnisotropicFilteringCheckBox.Checked; + } + + private void HDTexturesCheckBox_CheckedChanged(object sender, EventArgs e) + { + Renderer.renderhdtextures = HDTexturesCheckBox.Checked; + } + + private void RenderModeComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + TextureSamplerComboBox.Enabled = false; + TextureCoordsComboBox.Enabled = false; + switch (RenderModeComboBox.Text) + { + default: + case "Default": + Renderer.shaders.RenderMode = WorldRenderMode.Default; + break; + case "Single texture": + Renderer.shaders.RenderMode = WorldRenderMode.SingleTexture; + TextureSamplerComboBox.Enabled = true; + TextureCoordsComboBox.Enabled = true; + break; + case "Vertex normals": + Renderer.shaders.RenderMode = WorldRenderMode.VertexNormals; + break; + case "Vertex tangents": + Renderer.shaders.RenderMode = WorldRenderMode.VertexTangents; + break; + case "Vertex colour 1": + Renderer.shaders.RenderMode = WorldRenderMode.VertexColour; + Renderer.shaders.RenderVertexColourIndex = 1; + break; + case "Vertex colour 2": + Renderer.shaders.RenderMode = WorldRenderMode.VertexColour; + Renderer.shaders.RenderVertexColourIndex = 2; + break; + case "Vertex colour 3": + Renderer.shaders.RenderMode = WorldRenderMode.VertexColour; + Renderer.shaders.RenderVertexColourIndex = 3; + break; + case "Texture coord 1": + Renderer.shaders.RenderMode = WorldRenderMode.TextureCoord; + Renderer.shaders.RenderTextureCoordIndex = 1; + break; + case "Texture coord 2": + Renderer.shaders.RenderMode = WorldRenderMode.TextureCoord; + Renderer.shaders.RenderTextureCoordIndex = 2; + break; + case "Texture coord 3": + Renderer.shaders.RenderMode = WorldRenderMode.TextureCoord; + Renderer.shaders.RenderTextureCoordIndex = 3; + break; + } + } + + private void TextureSamplerComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + if (TextureSamplerComboBox.SelectedItem is MetaName) + { + Renderer.shaders.RenderTextureSampler = (MetaName)TextureSamplerComboBox.SelectedItem; + } + } + + private void TextureCoordsComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + switch (TextureCoordsComboBox.Text) + { + default: + case "Texture coord 1": + Renderer.shaders.RenderTextureSamplerCoord = 1; + break; + case "Texture coord 2": + Renderer.shaders.RenderTextureSamplerCoord = 2; + break; + case "Texture coord 3": + Renderer.shaders.RenderTextureSamplerCoord = 3; + break; + } + } + + private void GridCheckBox_CheckedChanged(object sender, EventArgs e) + { + enableGrid = GridCheckBox.Checked; + } + + private void GridSizeComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + float newgs; + float.TryParse(GridSizeComboBox.Text, out newgs); + if (newgs != gridSize) + { + gridSize = newgs; + UpdateGridVerts(); + } + } + + private void GridCountComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + int newgc; + int.TryParse(GridCountComboBox.Text, out newgc); + if (newgc != gridCount) + { + gridCount = newgc; + UpdateGridVerts(); + } + } + + private void SkeletonsCheckBox_CheckedChanged(object sender, EventArgs e) + { + Renderer.renderskeletons = SkeletonsCheckBox.Checked; + } + + private void ErrorConsoleCheckBox_CheckedChanged(object sender, EventArgs e) + { + ConsolePanel.Visible = ErrorConsoleCheckBox.Checked; + } + + private void StatusBarCheckBox_CheckedChanged(object sender, EventArgs e) + { + StatusStrip.Visible = StatusBarCheckBox.Checked; + } + + private void TextureViewerButton_Click(object sender, EventArgs e) + { + //TextureDictionary td = null; + + //if ((Ydr != null) && (Ydr.Loaded)) + //{ + // td = Ydr.Drawable?.ShaderGroup?.TextureDictionary; + //} + //else if ((Yft != null) && (Yft.Loaded)) + //{ + // td = Yft.Fragment?.Drawable?.ShaderGroup?.TextureDictionary; + //} + + //if (td != null) + //{ + // YtdForm f = new YtdForm(); + // f.Show(); + // f.LoadTexDict(td, fileName); + // //f.LoadYtd(ytd); + //} + //else + //{ + // MessageBox.Show("Couldn't find embedded texture dict."); + //} + } } }