From 5a6bcaddf467846f92812b283c06ac937edb89ae Mon Sep 17 00:00:00 2001 From: TrainWrack <120750885+TrainWrack@users.noreply.github.com> Date: Mon, 19 Jan 2026 21:16:37 -0500 Subject: [PATCH 1/3] Sound checkbox --- TombEditor/Forms/FormSoundSource.Designer.cs | 236 +++++++++--------- TombEditor/Forms/FormSoundSource.cs | 5 + TombEditor/Forms/FormSoundSource.resx | 54 ++-- .../TombEngine/LevelCompilerTombEngine.cs | 3 + TombLib/TombLib/LevelData/IO/Prj2Loader.cs | 1 + TombLib/TombLib/LevelData/IO/Prj2Writer.cs | 1 + .../Instances/SoundSourceInstance.cs | 5 +- 7 files changed, 161 insertions(+), 144 deletions(-) diff --git a/TombEditor/Forms/FormSoundSource.Designer.cs b/TombEditor/Forms/FormSoundSource.Designer.cs index 8142630bbe..4530ae6760 100644 --- a/TombEditor/Forms/FormSoundSource.Designer.cs +++ b/TombEditor/Forms/FormSoundSource.Designer.cs @@ -28,151 +28,156 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.butOK = new DarkUI.Controls.DarkButton(); - this.butCancel = new DarkUI.Controls.DarkButton(); - this.optionPlaySoundFromWadGroupBox = new DarkUI.Controls.DarkGroupBox(); - this.butSearch = new DarkUI.Controls.DarkButton(); - this.tbSearch = new DarkUI.Controls.DarkTextBox(); - this.comboPlayMode = new DarkUI.Controls.DarkComboBox(); - this.darkLabel2 = new DarkUI.Controls.DarkLabel(); - this.butPlaySound = new DarkUI.Controls.DarkButton(); - this.lstSounds = new DarkUI.Controls.DarkListView(); - this.optionPlaySoundFromWadGroupBox.SuspendLayout(); - this.SuspendLayout(); + butOK = new DarkUI.Controls.DarkButton(); + butCancel = new DarkUI.Controls.DarkButton(); + optionPlaySoundFromWadGroupBox = new DarkUI.Controls.DarkGroupBox(); + cbSoundEnabled = new DarkUI.Controls.DarkCheckBox(); + butSearch = new DarkUI.Controls.DarkButton(); + tbSearch = new DarkUI.Controls.DarkTextBox(); + comboPlayMode = new DarkUI.Controls.DarkComboBox(); + darkLabel2 = new DarkUI.Controls.DarkLabel(); + butPlaySound = new DarkUI.Controls.DarkButton(); + lstSounds = new DarkUI.Controls.DarkListView(); + optionPlaySoundFromWadGroupBox.SuspendLayout(); + SuspendLayout(); // // butOK // - this.butOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.butOK.Location = new System.Drawing.Point(306, 535); - this.butOK.Name = "butOK"; - this.butOK.Size = new System.Drawing.Size(80, 23); - this.butOK.TabIndex = 0; - this.butOK.Text = "OK"; - this.butOK.Click += new System.EventHandler(this.butOK_Click); + butOK.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; + butOK.Checked = false; + butOK.Location = new System.Drawing.Point(306, 535); + butOK.Name = "butOK"; + butOK.Size = new System.Drawing.Size(80, 23); + butOK.TabIndex = 0; + butOK.Text = "OK"; + butOK.Click += butOK_Click; // // butCancel // - this.butCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.butCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.butCancel.Location = new System.Drawing.Point(392, 535); - this.butCancel.Name = "butCancel"; - this.butCancel.Size = new System.Drawing.Size(80, 23); - this.butCancel.TabIndex = 1; - this.butCancel.Text = "Cancel"; - this.butCancel.Click += new System.EventHandler(this.butCancel_Click); + butCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; + butCancel.Checked = false; + butCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + butCancel.Location = new System.Drawing.Point(392, 535); + butCancel.Name = "butCancel"; + butCancel.Size = new System.Drawing.Size(80, 23); + butCancel.TabIndex = 1; + butCancel.Text = "Cancel"; + butCancel.Click += butCancel_Click; // // optionPlaySoundFromWadGroupBox // - this.optionPlaySoundFromWadGroupBox.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.optionPlaySoundFromWadGroupBox.Controls.Add(this.butSearch); - this.optionPlaySoundFromWadGroupBox.Controls.Add(this.tbSearch); - this.optionPlaySoundFromWadGroupBox.Controls.Add(this.comboPlayMode); - this.optionPlaySoundFromWadGroupBox.Controls.Add(this.darkLabel2); - this.optionPlaySoundFromWadGroupBox.Controls.Add(this.butPlaySound); - this.optionPlaySoundFromWadGroupBox.Controls.Add(this.lstSounds); - this.optionPlaySoundFromWadGroupBox.Location = new System.Drawing.Point(12, 12); - this.optionPlaySoundFromWadGroupBox.Name = "optionPlaySoundFromWadGroupBox"; - this.optionPlaySoundFromWadGroupBox.Size = new System.Drawing.Size(460, 517); - this.optionPlaySoundFromWadGroupBox.TabIndex = 66; - this.optionPlaySoundFromWadGroupBox.TabStop = false; - this.optionPlaySoundFromWadGroupBox.Text = "Sound to play"; + optionPlaySoundFromWadGroupBox.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + optionPlaySoundFromWadGroupBox.Controls.Add(butSearch); + optionPlaySoundFromWadGroupBox.Controls.Add(tbSearch); + optionPlaySoundFromWadGroupBox.Controls.Add(comboPlayMode); + optionPlaySoundFromWadGroupBox.Controls.Add(darkLabel2); + optionPlaySoundFromWadGroupBox.Controls.Add(butPlaySound); + optionPlaySoundFromWadGroupBox.Controls.Add(lstSounds); + optionPlaySoundFromWadGroupBox.Location = new System.Drawing.Point(12, 12); + optionPlaySoundFromWadGroupBox.Name = "optionPlaySoundFromWadGroupBox"; + optionPlaySoundFromWadGroupBox.Size = new System.Drawing.Size(460, 517); + optionPlaySoundFromWadGroupBox.TabIndex = 66; + optionPlaySoundFromWadGroupBox.TabStop = false; + optionPlaySoundFromWadGroupBox.Text = "Sound to play"; + // + // cbSoundEnabled + // + cbSoundEnabled.AutoSize = true; + cbSoundEnabled.Location = new System.Drawing.Point(12, 541); + cbSoundEnabled.Name = "cbSoundEnabled"; + cbSoundEnabled.Size = new System.Drawing.Size(68, 17); + cbSoundEnabled.TabIndex = 110; + cbSoundEnabled.Text = "Enabled"; // // butSearch // - this.butSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.butSearch.Image = global::TombEditor.Properties.Resources.general_search_16; - this.butSearch.Location = new System.Drawing.Point(428, 21); - this.butSearch.Name = "butSearch"; - this.butSearch.Selectable = false; - this.butSearch.Size = new System.Drawing.Size(24, 23); - this.butSearch.TabIndex = 109; - this.butSearch.Click += new System.EventHandler(this.butSearch_Click); + butSearch.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; + butSearch.Checked = false; + butSearch.Image = Properties.Resources.general_search_16; + butSearch.Location = new System.Drawing.Point(428, 21); + butSearch.Name = "butSearch"; + butSearch.Selectable = false; + butSearch.Size = new System.Drawing.Size(24, 23); + butSearch.TabIndex = 109; + butSearch.Click += butSearch_Click; // // tbSearch // - this.tbSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.tbSearch.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.tbSearch.Location = new System.Drawing.Point(8, 21); - this.tbSearch.Name = "tbSearch"; - this.tbSearch.Size = new System.Drawing.Size(421, 23); - this.tbSearch.TabIndex = 0; - this.tbSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbSearch_KeyDown); + tbSearch.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + tbSearch.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + tbSearch.Location = new System.Drawing.Point(8, 21); + tbSearch.Name = "tbSearch"; + tbSearch.Size = new System.Drawing.Size(421, 23); + tbSearch.TabIndex = 0; + tbSearch.KeyDown += tbSearch_KeyDown; // // comboPlayMode // - this.comboPlayMode.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.comboPlayMode.FormattingEnabled = true; - this.comboPlayMode.Items.AddRange(new object[] { - "Always", - "Only when flipmaps are off", - "Only when flipmaps are on", - "Auto-decide based on room type"}); - this.comboPlayMode.Location = new System.Drawing.Point(77, 486); - this.comboPlayMode.Name = "comboPlayMode"; - this.comboPlayMode.Size = new System.Drawing.Size(277, 23); - this.comboPlayMode.TabIndex = 2; + comboPlayMode.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + comboPlayMode.FormattingEnabled = true; + comboPlayMode.Items.AddRange(new object[] { "Always", "Only when flipmaps are off", "Only when flipmaps are on", "Auto-decide based on room type" }); + comboPlayMode.Location = new System.Drawing.Point(77, 486); + comboPlayMode.Name = "comboPlayMode"; + comboPlayMode.Size = new System.Drawing.Size(277, 23); + comboPlayMode.TabIndex = 2; // // darkLabel2 // - this.darkLabel2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.darkLabel2.AutoSize = true; - this.darkLabel2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); - this.darkLabel2.Location = new System.Drawing.Point(9, 489); - this.darkLabel2.Name = "darkLabel2"; - this.darkLabel2.Size = new System.Drawing.Size(62, 13); - this.darkLabel2.TabIndex = 63; - this.darkLabel2.Text = "Play mode:"; + darkLabel2.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; + darkLabel2.AutoSize = true; + darkLabel2.ForeColor = System.Drawing.Color.FromArgb(220, 220, 220); + darkLabel2.Location = new System.Drawing.Point(9, 489); + darkLabel2.Name = "darkLabel2"; + darkLabel2.Size = new System.Drawing.Size(62, 13); + darkLabel2.TabIndex = 63; + darkLabel2.Text = "Play mode:"; // // butPlaySound // - this.butPlaySound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.butPlaySound.Image = global::TombEditor.Properties.Resources.actions_play_16; - this.butPlaySound.Location = new System.Drawing.Point(360, 486); - this.butPlaySound.Name = "butPlaySound"; - this.butPlaySound.Size = new System.Drawing.Size(92, 23); - this.butPlaySound.TabIndex = 3; - this.butPlaySound.Text = "Play sound"; - this.butPlaySound.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; - this.butPlaySound.Click += new System.EventHandler(this.butPlay_Click); + butPlaySound.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; + butPlaySound.Checked = false; + butPlaySound.Image = Properties.Resources.actions_play_16; + butPlaySound.Location = new System.Drawing.Point(360, 486); + butPlaySound.Name = "butPlaySound"; + butPlaySound.Size = new System.Drawing.Size(92, 23); + butPlaySound.TabIndex = 3; + butPlaySound.Text = "Play sound"; + butPlaySound.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; + butPlaySound.Click += butPlay_Click; // // lstSounds // - this.lstSounds.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.lstSounds.Location = new System.Drawing.Point(8, 50); - this.lstSounds.Name = "lstSounds"; - this.lstSounds.Size = new System.Drawing.Size(444, 430); - this.lstSounds.TabIndex = 1; - this.lstSounds.Text = "darkListView1"; - this.lstSounds.Click += new System.EventHandler(this.lstSounds_Click); - this.lstSounds.DoubleClick += new System.EventHandler(this.lstSounds_DoubleClick); + lstSounds.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + lstSounds.Location = new System.Drawing.Point(8, 50); + lstSounds.Name = "lstSounds"; + lstSounds.Size = new System.Drawing.Size(444, 430); + lstSounds.TabIndex = 1; + lstSounds.Text = "darkListView1"; + lstSounds.Click += lstSounds_Click; + lstSounds.DoubleClick += lstSounds_DoubleClick; // // FormSoundSource // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this.butCancel; - this.ClientSize = new System.Drawing.Size(484, 570); - this.Controls.Add(this.butOK); - this.Controls.Add(this.butCancel); - this.Controls.Add(this.optionPlaySoundFromWadGroupBox); - this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(500, 520); - this.Name = "FormSoundSource"; - this.ShowIcon = false; - this.ShowInTaskbar = false; - this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Sound source"; - this.optionPlaySoundFromWadGroupBox.ResumeLayout(false); - this.optionPlaySoundFromWadGroupBox.PerformLayout(); - this.ResumeLayout(false); - + AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + CancelButton = butCancel; + ClientSize = new System.Drawing.Size(484, 570); + Controls.Add(cbSoundEnabled); + Controls.Add(butOK); + Controls.Add(butCancel); + Controls.Add(optionPlaySoundFromWadGroupBox); + MinimizeBox = false; + MinimumSize = new System.Drawing.Size(500, 520); + Name = "FormSoundSource"; + ShowIcon = false; + ShowInTaskbar = false; + SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + Text = "Sound source"; + optionPlaySoundFromWadGroupBox.ResumeLayout(false); + optionPlaySoundFromWadGroupBox.PerformLayout(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -185,5 +190,6 @@ private void InitializeComponent() private DarkUI.Controls.DarkLabel darkLabel2; private DarkUI.Controls.DarkButton butSearch; private DarkUI.Controls.DarkTextBox tbSearch; + private DarkUI.Controls.DarkCheckBox cbSoundEnabled; } } \ No newline at end of file diff --git a/TombEditor/Forms/FormSoundSource.cs b/TombEditor/Forms/FormSoundSource.cs index 0256e5a1cf..96b12e7a5a 100644 --- a/TombEditor/Forms/FormSoundSource.cs +++ b/TombEditor/Forms/FormSoundSource.cs @@ -33,6 +33,10 @@ public FormSoundSource(SoundSourceInstance soundSource) lstSounds.Items.Add(new DarkUI.Controls.DarkListItem(sound.Id.ToString().PadLeft(4, '0') + ": " + sound.Name) { Tag = sound }); SelectSound(_soundSource.SoundId); + + bool isTEN = _editor.Level.Settings.GameVersion is TRVersion.Game.TombEngine; + cbSoundEnabled.Enabled = isTEN; + cbSoundEnabled.Visible = isTEN; } private void SelectSound(int id) @@ -70,6 +74,7 @@ private void butOK_Click(object sender, EventArgs e) { _soundSource.SoundId = _soundId; _soundSource.PlayMode = (SoundSourcePlayMode)comboPlayMode.SelectedIndex; + _soundSource.Enabled = cbSoundEnabled.Checked; DialogResult = DialogResult.OK; WadSoundPlayer.StopSample(); diff --git a/TombEditor/Forms/FormSoundSource.resx b/TombEditor/Forms/FormSoundSource.resx index 1af7de150c..8b2ff64a11 100644 --- a/TombEditor/Forms/FormSoundSource.resx +++ b/TombEditor/Forms/FormSoundSource.resx @@ -1,17 +1,17 @@  - diff --git a/TombLib/TombLib/LevelData/Compilers/TombEngine/LevelCompilerTombEngine.cs b/TombLib/TombLib/LevelData/Compilers/TombEngine/LevelCompilerTombEngine.cs index 5cec1787cd..094d4f2f13 100644 --- a/TombLib/TombLib/LevelData/Compilers/TombEngine/LevelCompilerTombEngine.cs +++ b/TombLib/TombLib/LevelData/Compilers/TombEngine/LevelCompilerTombEngine.cs @@ -204,6 +204,9 @@ private void PrepareSoundSources() flags |= 0x2000; break; } + + if (instance.Enabled) + flags |= 0x1000; Vector3 position = instance.Room.WorldPos + instance.Position; _soundSources.Add(new TombEngineSoundSource diff --git a/TombLib/TombLib/LevelData/IO/Prj2Loader.cs b/TombLib/TombLib/LevelData/IO/Prj2Loader.cs index 2dce8fb413..35c7617829 100644 --- a/TombLib/TombLib/LevelData/IO/Prj2Loader.cs +++ b/TombLib/TombLib/LevelData/IO/Prj2Loader.cs @@ -1571,6 +1571,7 @@ private static bool LoadObjects(ChunkReader chunkIO, ChunkId idOuter, LevelSetti instance.Position = chunkIO.Raw.ReadVector3(); instance.SoundId = chunkIO.Raw.ReadInt32(); instance.PlayMode = (SoundSourcePlayMode)chunkIO.Raw.ReadInt32(); + instance.Enabled = chunkIO.Raw.ReadBoolean(); instance.LuaName = chunkIO.Raw.ReadStringUTF8(); addObject(instance); newObjects.TryAdd(objectID, instance); diff --git a/TombLib/TombLib/LevelData/IO/Prj2Writer.cs b/TombLib/TombLib/LevelData/IO/Prj2Writer.cs index ebec3a9610..71dc12b5ee 100644 --- a/TombLib/TombLib/LevelData/IO/Prj2Writer.cs +++ b/TombLib/TombLib/LevelData/IO/Prj2Writer.cs @@ -740,6 +740,7 @@ private static void WriteObjects(ChunkWriter chunkIO, IEnumerable SoundId == -1; public WadSoundInfo GetSoundInfo(Level level) From a712ae103ef1accfe827772e5a2a44848f8e85af Mon Sep 17 00:00:00 2001 From: TrainWrack <120750885+TrainWrack@users.noreply.github.com> Date: Fri, 23 Jan 2026 20:11:55 -0500 Subject: [PATCH 2/3] Revert "Sound checkbox" This reverts commit cc5d70168423c9415b22b358f97ef7933e3fa811. --- TombEditor/Forms/FormSoundSource.Designer.cs | 236 +++++++++--------- TombEditor/Forms/FormSoundSource.cs | 5 - TombEditor/Forms/FormSoundSource.resx | 54 ++-- .../TombEngine/LevelCompilerTombEngine.cs | 3 - TombLib/TombLib/LevelData/IO/Prj2Loader.cs | 1 - TombLib/TombLib/LevelData/IO/Prj2Writer.cs | 1 - .../Instances/SoundSourceInstance.cs | 5 +- 7 files changed, 144 insertions(+), 161 deletions(-) diff --git a/TombEditor/Forms/FormSoundSource.Designer.cs b/TombEditor/Forms/FormSoundSource.Designer.cs index 4530ae6760..8142630bbe 100644 --- a/TombEditor/Forms/FormSoundSource.Designer.cs +++ b/TombEditor/Forms/FormSoundSource.Designer.cs @@ -28,156 +28,151 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - butOK = new DarkUI.Controls.DarkButton(); - butCancel = new DarkUI.Controls.DarkButton(); - optionPlaySoundFromWadGroupBox = new DarkUI.Controls.DarkGroupBox(); - cbSoundEnabled = new DarkUI.Controls.DarkCheckBox(); - butSearch = new DarkUI.Controls.DarkButton(); - tbSearch = new DarkUI.Controls.DarkTextBox(); - comboPlayMode = new DarkUI.Controls.DarkComboBox(); - darkLabel2 = new DarkUI.Controls.DarkLabel(); - butPlaySound = new DarkUI.Controls.DarkButton(); - lstSounds = new DarkUI.Controls.DarkListView(); - optionPlaySoundFromWadGroupBox.SuspendLayout(); - SuspendLayout(); + this.butOK = new DarkUI.Controls.DarkButton(); + this.butCancel = new DarkUI.Controls.DarkButton(); + this.optionPlaySoundFromWadGroupBox = new DarkUI.Controls.DarkGroupBox(); + this.butSearch = new DarkUI.Controls.DarkButton(); + this.tbSearch = new DarkUI.Controls.DarkTextBox(); + this.comboPlayMode = new DarkUI.Controls.DarkComboBox(); + this.darkLabel2 = new DarkUI.Controls.DarkLabel(); + this.butPlaySound = new DarkUI.Controls.DarkButton(); + this.lstSounds = new DarkUI.Controls.DarkListView(); + this.optionPlaySoundFromWadGroupBox.SuspendLayout(); + this.SuspendLayout(); // // butOK // - butOK.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; - butOK.Checked = false; - butOK.Location = new System.Drawing.Point(306, 535); - butOK.Name = "butOK"; - butOK.Size = new System.Drawing.Size(80, 23); - butOK.TabIndex = 0; - butOK.Text = "OK"; - butOK.Click += butOK_Click; + this.butOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.butOK.Location = new System.Drawing.Point(306, 535); + this.butOK.Name = "butOK"; + this.butOK.Size = new System.Drawing.Size(80, 23); + this.butOK.TabIndex = 0; + this.butOK.Text = "OK"; + this.butOK.Click += new System.EventHandler(this.butOK_Click); // // butCancel // - butCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; - butCancel.Checked = false; - butCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - butCancel.Location = new System.Drawing.Point(392, 535); - butCancel.Name = "butCancel"; - butCancel.Size = new System.Drawing.Size(80, 23); - butCancel.TabIndex = 1; - butCancel.Text = "Cancel"; - butCancel.Click += butCancel_Click; + this.butCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.butCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.butCancel.Location = new System.Drawing.Point(392, 535); + this.butCancel.Name = "butCancel"; + this.butCancel.Size = new System.Drawing.Size(80, 23); + this.butCancel.TabIndex = 1; + this.butCancel.Text = "Cancel"; + this.butCancel.Click += new System.EventHandler(this.butCancel_Click); // // optionPlaySoundFromWadGroupBox // - optionPlaySoundFromWadGroupBox.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; - optionPlaySoundFromWadGroupBox.Controls.Add(butSearch); - optionPlaySoundFromWadGroupBox.Controls.Add(tbSearch); - optionPlaySoundFromWadGroupBox.Controls.Add(comboPlayMode); - optionPlaySoundFromWadGroupBox.Controls.Add(darkLabel2); - optionPlaySoundFromWadGroupBox.Controls.Add(butPlaySound); - optionPlaySoundFromWadGroupBox.Controls.Add(lstSounds); - optionPlaySoundFromWadGroupBox.Location = new System.Drawing.Point(12, 12); - optionPlaySoundFromWadGroupBox.Name = "optionPlaySoundFromWadGroupBox"; - optionPlaySoundFromWadGroupBox.Size = new System.Drawing.Size(460, 517); - optionPlaySoundFromWadGroupBox.TabIndex = 66; - optionPlaySoundFromWadGroupBox.TabStop = false; - optionPlaySoundFromWadGroupBox.Text = "Sound to play"; - // - // cbSoundEnabled - // - cbSoundEnabled.AutoSize = true; - cbSoundEnabled.Location = new System.Drawing.Point(12, 541); - cbSoundEnabled.Name = "cbSoundEnabled"; - cbSoundEnabled.Size = new System.Drawing.Size(68, 17); - cbSoundEnabled.TabIndex = 110; - cbSoundEnabled.Text = "Enabled"; + this.optionPlaySoundFromWadGroupBox.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.optionPlaySoundFromWadGroupBox.Controls.Add(this.butSearch); + this.optionPlaySoundFromWadGroupBox.Controls.Add(this.tbSearch); + this.optionPlaySoundFromWadGroupBox.Controls.Add(this.comboPlayMode); + this.optionPlaySoundFromWadGroupBox.Controls.Add(this.darkLabel2); + this.optionPlaySoundFromWadGroupBox.Controls.Add(this.butPlaySound); + this.optionPlaySoundFromWadGroupBox.Controls.Add(this.lstSounds); + this.optionPlaySoundFromWadGroupBox.Location = new System.Drawing.Point(12, 12); + this.optionPlaySoundFromWadGroupBox.Name = "optionPlaySoundFromWadGroupBox"; + this.optionPlaySoundFromWadGroupBox.Size = new System.Drawing.Size(460, 517); + this.optionPlaySoundFromWadGroupBox.TabIndex = 66; + this.optionPlaySoundFromWadGroupBox.TabStop = false; + this.optionPlaySoundFromWadGroupBox.Text = "Sound to play"; // // butSearch // - butSearch.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; - butSearch.Checked = false; - butSearch.Image = Properties.Resources.general_search_16; - butSearch.Location = new System.Drawing.Point(428, 21); - butSearch.Name = "butSearch"; - butSearch.Selectable = false; - butSearch.Size = new System.Drawing.Size(24, 23); - butSearch.TabIndex = 109; - butSearch.Click += butSearch_Click; + this.butSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.butSearch.Image = global::TombEditor.Properties.Resources.general_search_16; + this.butSearch.Location = new System.Drawing.Point(428, 21); + this.butSearch.Name = "butSearch"; + this.butSearch.Selectable = false; + this.butSearch.Size = new System.Drawing.Size(24, 23); + this.butSearch.TabIndex = 109; + this.butSearch.Click += new System.EventHandler(this.butSearch_Click); // // tbSearch // - tbSearch.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; - tbSearch.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - tbSearch.Location = new System.Drawing.Point(8, 21); - tbSearch.Name = "tbSearch"; - tbSearch.Size = new System.Drawing.Size(421, 23); - tbSearch.TabIndex = 0; - tbSearch.KeyDown += tbSearch_KeyDown; + this.tbSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tbSearch.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.tbSearch.Location = new System.Drawing.Point(8, 21); + this.tbSearch.Name = "tbSearch"; + this.tbSearch.Size = new System.Drawing.Size(421, 23); + this.tbSearch.TabIndex = 0; + this.tbSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbSearch_KeyDown); // // comboPlayMode // - comboPlayMode.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; - comboPlayMode.FormattingEnabled = true; - comboPlayMode.Items.AddRange(new object[] { "Always", "Only when flipmaps are off", "Only when flipmaps are on", "Auto-decide based on room type" }); - comboPlayMode.Location = new System.Drawing.Point(77, 486); - comboPlayMode.Name = "comboPlayMode"; - comboPlayMode.Size = new System.Drawing.Size(277, 23); - comboPlayMode.TabIndex = 2; + this.comboPlayMode.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.comboPlayMode.FormattingEnabled = true; + this.comboPlayMode.Items.AddRange(new object[] { + "Always", + "Only when flipmaps are off", + "Only when flipmaps are on", + "Auto-decide based on room type"}); + this.comboPlayMode.Location = new System.Drawing.Point(77, 486); + this.comboPlayMode.Name = "comboPlayMode"; + this.comboPlayMode.Size = new System.Drawing.Size(277, 23); + this.comboPlayMode.TabIndex = 2; // // darkLabel2 // - darkLabel2.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; - darkLabel2.AutoSize = true; - darkLabel2.ForeColor = System.Drawing.Color.FromArgb(220, 220, 220); - darkLabel2.Location = new System.Drawing.Point(9, 489); - darkLabel2.Name = "darkLabel2"; - darkLabel2.Size = new System.Drawing.Size(62, 13); - darkLabel2.TabIndex = 63; - darkLabel2.Text = "Play mode:"; + this.darkLabel2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.darkLabel2.AutoSize = true; + this.darkLabel2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); + this.darkLabel2.Location = new System.Drawing.Point(9, 489); + this.darkLabel2.Name = "darkLabel2"; + this.darkLabel2.Size = new System.Drawing.Size(62, 13); + this.darkLabel2.TabIndex = 63; + this.darkLabel2.Text = "Play mode:"; // // butPlaySound // - butPlaySound.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; - butPlaySound.Checked = false; - butPlaySound.Image = Properties.Resources.actions_play_16; - butPlaySound.Location = new System.Drawing.Point(360, 486); - butPlaySound.Name = "butPlaySound"; - butPlaySound.Size = new System.Drawing.Size(92, 23); - butPlaySound.TabIndex = 3; - butPlaySound.Text = "Play sound"; - butPlaySound.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; - butPlaySound.Click += butPlay_Click; + this.butPlaySound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.butPlaySound.Image = global::TombEditor.Properties.Resources.actions_play_16; + this.butPlaySound.Location = new System.Drawing.Point(360, 486); + this.butPlaySound.Name = "butPlaySound"; + this.butPlaySound.Size = new System.Drawing.Size(92, 23); + this.butPlaySound.TabIndex = 3; + this.butPlaySound.Text = "Play sound"; + this.butPlaySound.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; + this.butPlaySound.Click += new System.EventHandler(this.butPlay_Click); // // lstSounds // - lstSounds.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; - lstSounds.Location = new System.Drawing.Point(8, 50); - lstSounds.Name = "lstSounds"; - lstSounds.Size = new System.Drawing.Size(444, 430); - lstSounds.TabIndex = 1; - lstSounds.Text = "darkListView1"; - lstSounds.Click += lstSounds_Click; - lstSounds.DoubleClick += lstSounds_DoubleClick; + this.lstSounds.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.lstSounds.Location = new System.Drawing.Point(8, 50); + this.lstSounds.Name = "lstSounds"; + this.lstSounds.Size = new System.Drawing.Size(444, 430); + this.lstSounds.TabIndex = 1; + this.lstSounds.Text = "darkListView1"; + this.lstSounds.Click += new System.EventHandler(this.lstSounds_Click); + this.lstSounds.DoubleClick += new System.EventHandler(this.lstSounds_DoubleClick); // // FormSoundSource // - AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - CancelButton = butCancel; - ClientSize = new System.Drawing.Size(484, 570); - Controls.Add(cbSoundEnabled); - Controls.Add(butOK); - Controls.Add(butCancel); - Controls.Add(optionPlaySoundFromWadGroupBox); - MinimizeBox = false; - MinimumSize = new System.Drawing.Size(500, 520); - Name = "FormSoundSource"; - ShowIcon = false; - ShowInTaskbar = false; - SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - Text = "Sound source"; - optionPlaySoundFromWadGroupBox.ResumeLayout(false); - optionPlaySoundFromWadGroupBox.PerformLayout(); - ResumeLayout(false); - PerformLayout(); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.butCancel; + this.ClientSize = new System.Drawing.Size(484, 570); + this.Controls.Add(this.butOK); + this.Controls.Add(this.butCancel); + this.Controls.Add(this.optionPlaySoundFromWadGroupBox); + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(500, 520); + this.Name = "FormSoundSource"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Sound source"; + this.optionPlaySoundFromWadGroupBox.ResumeLayout(false); + this.optionPlaySoundFromWadGroupBox.PerformLayout(); + this.ResumeLayout(false); + } #endregion @@ -190,6 +185,5 @@ private void InitializeComponent() private DarkUI.Controls.DarkLabel darkLabel2; private DarkUI.Controls.DarkButton butSearch; private DarkUI.Controls.DarkTextBox tbSearch; - private DarkUI.Controls.DarkCheckBox cbSoundEnabled; } } \ No newline at end of file diff --git a/TombEditor/Forms/FormSoundSource.cs b/TombEditor/Forms/FormSoundSource.cs index 96b12e7a5a..0256e5a1cf 100644 --- a/TombEditor/Forms/FormSoundSource.cs +++ b/TombEditor/Forms/FormSoundSource.cs @@ -33,10 +33,6 @@ public FormSoundSource(SoundSourceInstance soundSource) lstSounds.Items.Add(new DarkUI.Controls.DarkListItem(sound.Id.ToString().PadLeft(4, '0') + ": " + sound.Name) { Tag = sound }); SelectSound(_soundSource.SoundId); - - bool isTEN = _editor.Level.Settings.GameVersion is TRVersion.Game.TombEngine; - cbSoundEnabled.Enabled = isTEN; - cbSoundEnabled.Visible = isTEN; } private void SelectSound(int id) @@ -74,7 +70,6 @@ private void butOK_Click(object sender, EventArgs e) { _soundSource.SoundId = _soundId; _soundSource.PlayMode = (SoundSourcePlayMode)comboPlayMode.SelectedIndex; - _soundSource.Enabled = cbSoundEnabled.Checked; DialogResult = DialogResult.OK; WadSoundPlayer.StopSample(); diff --git a/TombEditor/Forms/FormSoundSource.resx b/TombEditor/Forms/FormSoundSource.resx index 8b2ff64a11..1af7de150c 100644 --- a/TombEditor/Forms/FormSoundSource.resx +++ b/TombEditor/Forms/FormSoundSource.resx @@ -1,17 +1,17 @@  - diff --git a/TombLib/TombLib/LevelData/Compilers/TombEngine/LevelCompilerTombEngine.cs b/TombLib/TombLib/LevelData/Compilers/TombEngine/LevelCompilerTombEngine.cs index 094d4f2f13..5cec1787cd 100644 --- a/TombLib/TombLib/LevelData/Compilers/TombEngine/LevelCompilerTombEngine.cs +++ b/TombLib/TombLib/LevelData/Compilers/TombEngine/LevelCompilerTombEngine.cs @@ -204,9 +204,6 @@ private void PrepareSoundSources() flags |= 0x2000; break; } - - if (instance.Enabled) - flags |= 0x1000; Vector3 position = instance.Room.WorldPos + instance.Position; _soundSources.Add(new TombEngineSoundSource diff --git a/TombLib/TombLib/LevelData/IO/Prj2Loader.cs b/TombLib/TombLib/LevelData/IO/Prj2Loader.cs index 35c7617829..2dce8fb413 100644 --- a/TombLib/TombLib/LevelData/IO/Prj2Loader.cs +++ b/TombLib/TombLib/LevelData/IO/Prj2Loader.cs @@ -1571,7 +1571,6 @@ private static bool LoadObjects(ChunkReader chunkIO, ChunkId idOuter, LevelSetti instance.Position = chunkIO.Raw.ReadVector3(); instance.SoundId = chunkIO.Raw.ReadInt32(); instance.PlayMode = (SoundSourcePlayMode)chunkIO.Raw.ReadInt32(); - instance.Enabled = chunkIO.Raw.ReadBoolean(); instance.LuaName = chunkIO.Raw.ReadStringUTF8(); addObject(instance); newObjects.TryAdd(objectID, instance); diff --git a/TombLib/TombLib/LevelData/IO/Prj2Writer.cs b/TombLib/TombLib/LevelData/IO/Prj2Writer.cs index 71dc12b5ee..ebec3a9610 100644 --- a/TombLib/TombLib/LevelData/IO/Prj2Writer.cs +++ b/TombLib/TombLib/LevelData/IO/Prj2Writer.cs @@ -740,7 +740,6 @@ private static void WriteObjects(ChunkWriter chunkIO, IEnumerable SoundId == -1; public WadSoundInfo GetSoundInfo(Level level) From e4f814dfae77ed12232a0731d51f9e685c986659 Mon Sep 17 00:00:00 2001 From: TrainWrack <120750885+TrainWrack@users.noreply.github.com> Date: Mon, 11 May 2026 21:25:10 -0400 Subject: [PATCH 3/3] Add blend mode export / import --- TombLib/TombLib/GeometryIO/IOMaterial.cs | 7 +- TombLib/TombLib/GeometryIO/IOModel.cs | 4 +- .../TombLib/GeometryIO/Importers/Assimp.cs | 18 ++-- .../GeometryIO/Importers/Metasequoia.cs | 3 +- .../GeometryIO/RoomGeometryExporter.cs | 20 ++--- TombLib/TombLib/Graphics/Material.cs | 83 ++++++++++++++++++- TombLib/TombLib/Wad/WadMesh.cs | 19 ++--- WadTool/WadActions.cs | 17 ++-- 8 files changed, 126 insertions(+), 45 deletions(-) diff --git a/TombLib/TombLib/GeometryIO/IOMaterial.cs b/TombLib/TombLib/GeometryIO/IOMaterial.cs index 9305772a9d..e11c3b929d 100644 --- a/TombLib/TombLib/GeometryIO/IOMaterial.cs +++ b/TombLib/TombLib/GeometryIO/IOMaterial.cs @@ -6,7 +6,8 @@ public class IOMaterial { public string Name { get; private set; } public Texture Texture { get; set; } - public bool AdditiveBlending { get; set; } + public BlendMode BlendMode { get; set; } + public bool AdditiveBlending => BlendMode >= BlendMode.Additive; public bool DoubleSided { get; set; } public int Shininess { get; set; } @@ -20,11 +21,11 @@ public IOMaterial(string name) Name = name; } - public IOMaterial(string name, Texture texture, string texturePath,bool additiveBlending, bool doubleSided, int shininess, int page) + public IOMaterial(string name, Texture texture, string texturePath, BlendMode blendMode, bool doubleSided, int shininess, int page) { Name = name; Texture = texture; - AdditiveBlending = additiveBlending; + BlendMode = blendMode; DoubleSided = doubleSided; Shininess = shininess; Path = texturePath; diff --git a/TombLib/TombLib/GeometryIO/IOModel.cs b/TombLib/TombLib/GeometryIO/IOModel.cs index 679caa15aa..c85e1789d7 100644 --- a/TombLib/TombLib/GeometryIO/IOModel.cs +++ b/TombLib/TombLib/GeometryIO/IOModel.cs @@ -41,12 +41,12 @@ public BoundingSphere BoundingSphere } } - public IOMaterial GetMaterial(Texture texture, bool blending, int page, bool doubleSided, int shininess) + public IOMaterial GetMaterial(Texture texture, BlendMode blendMode, int page, bool doubleSided, int shininess) { foreach (var mat in Materials) if (mat.Page == page) if (mat.Texture.Equals(texture)) - if (mat.AdditiveBlending == blending) + if (mat.BlendMode == blendMode) if (mat.DoubleSided == doubleSided) if (mat.Shininess == shininess) return mat; diff --git a/TombLib/TombLib/GeometryIO/Importers/Assimp.cs b/TombLib/TombLib/GeometryIO/Importers/Assimp.cs index 774f40b52a..881ba5e3c2 100644 --- a/TombLib/TombLib/GeometryIO/Importers/Assimp.cs +++ b/TombLib/TombLib/GeometryIO/Importers/Assimp.cs @@ -146,12 +146,18 @@ public override IOModel ImportFromFile(string filename) // Create the new material material.Texture = textures[i]; - material.AdditiveBlending = (mat.HasBlendMode && mat.BlendMode == Assimp.BlendMode.Additive) || mat.Opacity < 1.0f - || mat.Name.StartsWith(Graphics.Material.Material_AdditiveBlending) - || mat.Name.StartsWith(Graphics.Material.Material_AdditiveBlendingDoubleSided); - material.DoubleSided = (mat.HasTwoSided && mat.IsTwoSided) - || mat.Name.StartsWith(Graphics.Material.Material_OpaqueDoubleSided) - || mat.Name.StartsWith(Graphics.Material.Material_AdditiveBlendingDoubleSided); + + if (mat.Name.StartsWith("Te")) + { + material.BlendMode = Graphics.Material.GetBlendModeFromName(mat.Name); + material.DoubleSided = Graphics.Material.GetDoubleSidedFromName(mat.Name); + } + else + { + material.BlendMode = (mat.HasBlendMode && mat.BlendMode == Assimp.BlendMode.Additive) || mat.Opacity < 1.0f + ? TombLib.Utils.BlendMode.Additive : TombLib.Utils.BlendMode.Normal; + material.DoubleSided = mat.HasTwoSided && mat.IsTwoSided; + } // HACK: Ass-imp uses different numbering for shininess in different formats! diff --git a/TombLib/TombLib/GeometryIO/Importers/Metasequoia.cs b/TombLib/TombLib/GeometryIO/Importers/Metasequoia.cs index d414eb251f..593a953df2 100644 --- a/TombLib/TombLib/GeometryIO/Importers/Metasequoia.cs +++ b/TombLib/TombLib/GeometryIO/Importers/Metasequoia.cs @@ -93,7 +93,8 @@ public override IOModel ImportFromFile(string filename) if (tokens.Length == 4 && float.TryParse(tokens[3], out alpha)) { - material.AdditiveBlending = (alpha < 1.0f); + if (alpha < 1.0f) + material.BlendMode = TombLib.Utils.BlendMode.Additive; } } diff --git a/TombLib/TombLib/GeometryIO/RoomGeometryExporter.cs b/TombLib/TombLib/GeometryIO/RoomGeometryExporter.cs index ea701e662e..d4d6c44661 100644 --- a/TombLib/TombLib/GeometryIO/RoomGeometryExporter.cs +++ b/TombLib/TombLib/GeometryIO/RoomGeometryExporter.cs @@ -133,15 +133,13 @@ public static RoomExportResult ExportRooms(IEnumerable roomsToExport, stri var page = new SplitPageReference(tex, y * numXPages + x, x, y, Path.Combine(Path.GetDirectoryName(filePath), textureFileName)); splitPages.Add(page); - var matOpaque = new IOMaterial(Material.Material_Opaque + "_" + j + "_" + page.Index, tex, page.Path, false, false, 0, page.Index); - var matOpaqueDoubleSided = new IOMaterial(Material.Material_OpaqueDoubleSided + "_" + j + "_" + page.Index, tex, page.Path, false, true, 0, page.Index); - var matAdditiveBlending = new IOMaterial(Material.Material_AdditiveBlending + "_" + j + "_" + page.Index, tex, page.Path, true, false, 0, page.Index); - var matAdditiveBlendingDoubleSided = new IOMaterial(Material.Material_AdditiveBlendingDoubleSided + "_" + j + "_" + page.Index, tex, page.Path, true, true, 0, page.Index); - - model.Materials.Add(matOpaque); - model.Materials.Add(matOpaqueDoubleSided); - model.Materials.Add(matAdditiveBlending); - model.Materials.Add(matAdditiveBlendingDoubleSided); + foreach (BlendMode mode in Enum.GetValues(typeof(BlendMode))) + { + var prefix = Material.GetPrefixForBlendMode(mode); + var suffix = j + "_" + page.Index; + model.Materials.Add(new IOMaterial(prefix + "_" + suffix, tex, page.Path, mode, false, 0, page.Index)); + model.Materials.Add(new IOMaterial(prefix + Material.DoubleSidedSuffix + "_" + suffix, tex, page.Path, mode, true, 0, page.Index)); + } } } } @@ -250,7 +248,7 @@ public static RoomExportResult ExportRooms(IEnumerable roomsToExport, stri } var mat = model.GetMaterial(textureArea1.Texture, - textureArea1.BlendMode >= BlendMode.Additive, + textureArea1.BlendMode, textureAreaPage, textureArea1.DoubleSided, 0); @@ -295,7 +293,7 @@ public static RoomExportResult ExportRooms(IEnumerable roomsToExport, stri mesh.Colors.Add(new Vector4(room.RoomGeometry.VertexColors[i + 2], 1.0f)); var mat = model.GetMaterial(textureArea.Texture, - textureArea.BlendMode >= BlendMode.Additive, + textureArea.BlendMode, textureAreaPage, textureArea.DoubleSided, 0); diff --git a/TombLib/TombLib/Graphics/Material.cs b/TombLib/TombLib/Graphics/Material.cs index 259d83ce23..b1fcd89101 100644 --- a/TombLib/TombLib/Graphics/Material.cs +++ b/TombLib/TombLib/Graphics/Material.cs @@ -4,10 +4,51 @@ namespace TombLib.Graphics { public class Material { + public const string DoubleSidedSuffix = "DS"; + + // Opaque (normal) prefix. public const string Material_Opaque = "TeOp"; public const string Material_OpaqueDoubleSided = "TeOpDS"; - public const string Material_AdditiveBlending = "TeBl"; + + // Blend mode prefixes. "TeBl" is kept for backward compatibility with Additive. + public const string Material_AdditiveBlending = "TeBl"; public const string Material_AdditiveBlendingDoubleSided = "TeBlDS"; + public const string Material_AlphaTest = "TeBlAT"; + public const string Material_AlphaTestDoubleSided = "TeBlATDS"; + public const string Material_Distortion = "TeBlDis"; + public const string Material_DistortionDoubleSided = "TeBlDisDS"; + public const string Material_NoZTest = "TeBlNZ"; + public const string Material_NoZTestDoubleSided = "TeBlNZDS"; + public const string Material_Subtract = "TeBlSub"; + public const string Material_SubtractDoubleSided = "TeBlSubDS"; + public const string Material_Wireframe = "TeBlWf"; + public const string Material_WireframeDoubleSided = "TeBlWfDS"; + public const string Material_Exclude = "TeBlExc"; + public const string Material_ExcludeDoubleSided = "TeBlExcDS"; + public const string Material_Screen = "TeBlScr"; + public const string Material_ScreenDoubleSided = "TeBlScrDS"; + public const string Material_Lighten = "TeBlLig"; + public const string Material_LightenDoubleSided = "TeBlLigDS"; + public const string Material_AlphaBlend = "TeBlAB"; + public const string Material_AlphaBlendDoubleSided = "TeBlABDS"; + + // Lookup from prefix to blend mode. + // Longer (more specific) entries must precede shorter generic ones to prevent + // partial matches (e.g., "TeBlSub" must come before "TeBl"). + private static readonly (string Prefix, BlendMode Mode)[] BlendModePrefixLookup = + { + (Material_AlphaTest, BlendMode.AlphaTest), + (Material_Distortion, BlendMode.Distortion), + (Material_NoZTest, BlendMode.NoZTest), + (Material_Subtract, BlendMode.Subtract), + (Material_Wireframe, BlendMode.Wireframe), + (Material_Exclude, BlendMode.Exclude), + (Material_Screen, BlendMode.Screen), + (Material_Lighten, BlendMode.Lighten), + (Material_AlphaBlend, BlendMode.AlphaBlend), + (Material_AdditiveBlending, BlendMode.Additive), + (Material_Opaque, BlendMode.Normal), + }; public string Name { get; private set; } public Texture Texture { get; set; } @@ -43,5 +84,45 @@ public void SetStates(SharpDX.Toolkit.Graphics.GraphicsDevice device, bool trans else device.SetRasterizerState(device.RasterizerStates.CullBack); } + + // Returns the material name prefix for the given blend mode. + public static string GetPrefixForBlendMode(BlendMode mode) + { + foreach (var (prefix, blendMode) in BlendModePrefixLookup) + if (blendMode == mode) + return prefix; + return Material_Opaque; + } + + // Parses the blend mode from a material name using the Te prefix convention. + public static BlendMode GetBlendModeFromName(string name) + { + foreach (var (prefix, mode) in BlendModePrefixLookup) + if (MatchesMaterialPrefix(name, prefix)) + return mode; + return BlendMode.Normal; + } + + // Returns true if the material name indicates a double-sided surface. + public static bool GetDoubleSidedFromName(string name) + { + foreach (var (prefix, _) in BlendModePrefixLookup) + if (MatchesMaterialPrefix(name, prefix + DoubleSidedSuffix)) + return true; + return false; + } + + // Returns true if name starts with prefix and is immediately followed by "DS", "_", or end of string. + private static bool MatchesMaterialPrefix(string name, string prefix) + { + if (!name.StartsWith(prefix)) + return false; + int after = prefix.Length; + if (after >= name.Length || name[after] == '_') + return true; + if (after + 1 < name.Length && name[after] == 'D' && name[after + 1] == 'S') + return true; + return false; + } } } diff --git a/TombLib/TombLib/Wad/WadMesh.cs b/TombLib/TombLib/Wad/WadMesh.cs index ca712fd5d8..a552c49796 100644 --- a/TombLib/TombLib/Wad/WadMesh.cs +++ b/TombLib/TombLib/Wad/WadMesh.cs @@ -369,15 +369,12 @@ public static IOModel PrepareForExport(string filePath, IOGeometrySettings setti var textureFileName = name + "_" + i + ".png"; var path = Path.Combine(Path.GetDirectoryName(filePath), textureFileName); - var matOpaque = new IOMaterial(Material.Material_Opaque + "_" + i, pages[i], path, false, false, 0, i); - var matOpaqueDoubleSided = new IOMaterial(Material.Material_OpaqueDoubleSided + "_" + i, pages[i], path, false, true, 0, i); - var matAdditiveBlending = new IOMaterial(Material.Material_AdditiveBlending + "_" + i, pages[i], path, true, false, 0, i); - var matAdditiveBlendingDoubleSided = new IOMaterial(Material.Material_AdditiveBlendingDoubleSided + "_" + i, pages[i], path, true, true, 0, i); - - model.Materials.Add(matOpaque); - model.Materials.Add(matOpaqueDoubleSided); - model.Materials.Add(matAdditiveBlending); - model.Materials.Add(matAdditiveBlendingDoubleSided); + foreach (BlendMode mode in Enum.GetValues(typeof(BlendMode))) + { + var prefix = Material.GetPrefixForBlendMode(mode); + model.Materials.Add(new IOMaterial(prefix + "_" + i, pages[i], path, mode, false, 0, i)); + model.Materials.Add(new IOMaterial(prefix + Material.DoubleSidedSuffix + "_" + i, pages[i], path, mode, true, 0, i)); + } } int lastIndex = 0; @@ -449,7 +446,7 @@ public static IOModel PrepareForExport(string filePath, IOGeometrySettings setti foreach (var mt in model.Materials) if ((mergeIntoPages && mt.Page == texture.Atlas) || (!mergeIntoPages && mt.Texture == p.Texture.Texture)) - if (mt.AdditiveBlending == (p.Texture.BlendMode >= BlendMode.Additive)) + if (mt.BlendMode == p.Texture.BlendMode) if (mt.DoubleSided == p.Texture.DoubleSided) if (mt.Shininess == 0) mat = mt; @@ -663,7 +660,7 @@ public static List ImportFromExternalModel(string fileName, IOGeometryS } area.DoubleSided = tmpSubmesh.Value.Material.DoubleSided; - area.BlendMode = tmpSubmesh.Value.Material.AdditiveBlending ? BlendMode.Additive : BlendMode.Normal; + area.BlendMode = tmpSubmesh.Value.Material.BlendMode; poly.Texture = area; poly.ShineStrength = (byte)Math.Min(Math.Round(tmpSubmesh.Value.Material.Shininess / 16.0f, MidpointRounding.ToEven), 63); diff --git a/WadTool/WadActions.cs b/WadTool/WadActions.cs index afedd1a567..fede959e97 100644 --- a/WadTool/WadActions.cs +++ b/WadTool/WadActions.cs @@ -406,15 +406,12 @@ private static void UpdateBoneAbsolutePositions(List bones) var textureFileName = "Texture_" + i + ".png"; var path = Path.Combine(Path.GetDirectoryName(filePath), textureFileName); - var matOpaque = new IOMaterial(Material.Material_Opaque + "_" + i, pages[i], path, false, false, 0, i); - var matOpaqueDoubleSided = new IOMaterial(Material.Material_OpaqueDoubleSided + "_" + i, pages[i], path, false, true, 0, i); - var matAdditiveBlending = new IOMaterial(Material.Material_AdditiveBlending + "_" + i, pages[i], path, true, false, 0, i); - var matAdditiveBlendingDoubleSided = new IOMaterial(Material.Material_AdditiveBlendingDoubleSided + "_" + i, pages[i], path, true, true, 0, i); - - model.Materials.Add(matOpaque); - model.Materials.Add(matOpaqueDoubleSided); - model.Materials.Add(matAdditiveBlending); - model.Materials.Add(matAdditiveBlendingDoubleSided); + foreach (BlendMode mode in Enum.GetValues(typeof(BlendMode))) + { + var prefix = Material.GetPrefixForBlendMode(mode); + model.Materials.Add(new IOMaterial(prefix + "_" + i, pages[i], path, mode, false, 0, i)); + model.Materials.Add(new IOMaterial(prefix + Material.DoubleSidedSuffix + "_" + i, pages[i], path, mode, true, 0, i)); + } } UpdateBoneAbsolutePositions(m.Bones); @@ -499,7 +496,7 @@ private static void UpdateBoneAbsolutePositions(List bones) var mat = model.Materials[0]; foreach (var mt in model.Materials) if (mt.Page == texture.Atlas) - if (mt.AdditiveBlending == (p.Texture.BlendMode >= BlendMode.Additive)) + if (mt.BlendMode == p.Texture.BlendMode) if (mt.DoubleSided == p.Texture.DoubleSided) if (mt.Shininess == 0) mat = mt;