Skip to content

Commit

Permalink
Autumn cleaning (#5)
Browse files Browse the repository at this point in the history
* Various automatic modernizations

* We do have access to .NET Standard 1.3

* Remove remnants of support for older .NET Standards

* Remove unused helper functions

* Eradicate `.ToArray` calls

* Replace structs with record structs where appropriate

* Apply changes from main
  • Loading branch information
Saalvage authored Nov 26, 2024
1 parent 78fe44f commit c09379a
Show file tree
Hide file tree
Showing 70 changed files with 1,458 additions and 4,985 deletions.
4 changes: 2 additions & 2 deletions AssimpNet.Sample/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static byte[] ReadEmbeddedAssetBytes(string name)
}
}

public static Shader LoadShader(ResourceFactory factory, String set, ShaderStages stage, String entryPoint)
public static Shader LoadShader(ResourceFactory factory, string set, ShaderStages stage, string entryPoint)
{
string name = $"{set}-{stage.ToString().ToLower()}.{GetExtension(factory.BackendType)}";
return factory.CreateShader(new ShaderDescription(stage, ReadEmbeddedAssetBytes(name), entryPoint));
Expand Down Expand Up @@ -133,7 +133,7 @@ public static void ToNumerics(in SN.Vector3 vIn, out SN.Vector3 vOut)
vOut.Z = vIn.Z;
}

public static Texture LoadTextureFromFile(String filePath, GraphicsDevice gd, ResourceFactory factory)
public static Texture LoadTextureFromFile(string filePath, GraphicsDevice gd, ResourceFactory factory)
{
if(!File.Exists(filePath) || gd == null || factory == null)
return null;
Expand Down
2 changes: 1 addition & 1 deletion AssimpNet.Sample/SampleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Run()
m_cmdList = m_graphicsDevice.ResourceFactory.CreateCommandList();

//NOTICE: This is the duck model we load for the sample, replace this line with a path to your own model to see it imported!
String fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Assets", "duck.dae");
string fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Assets", "duck.dae");

//Veldrid defaults to Clockwise winding order, assimp defaults to CCW. We also do some processing + generate normals if missing.
SimpleModel model = SimpleModel.LoadFromFile(fileName, m_graphicsDevice, PostProcessPreset.TargetRealTimeQuality | PostProcessSteps.FlipWindingOrder,
Expand Down
14 changes: 7 additions & 7 deletions AssimpNet.Sample/SimpleModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public sealed class SimpleModel : IDisposable
public SN.Matrix4x4 WorldMatrix { get; set; }
public SN.Vector3 LightPosition { get; set; }

public SN.Vector3 SceneCenter { get { return m_sceneCenter; } }
public SN.Vector3 SceneMin { get { return m_sceneMin; } }
public SN.Vector3 SceneMax { get { return m_sceneMax; } }
public SN.Vector3 SceneCenter => m_sceneCenter;
public SN.Vector3 SceneMin => m_sceneMin;
public SN.Vector3 SceneMax => m_sceneMax;

public static SimpleModel LoadFromFile(String filePath, GraphicsDevice gd, PostProcessSteps ppSteps, params PropertyConfig[] configs)
public static SimpleModel LoadFromFile(string filePath, GraphicsDevice gd, PostProcessSteps ppSteps, params PropertyConfig[] configs)
{
if(!File.Exists(filePath) || gd == null)
return null;
Expand Down Expand Up @@ -140,7 +140,7 @@ private void GatherVertexCounts(Scene scene, out int vertexCount, out int indexC
}
}

private bool CreateVertexBuffer(Scene scene, GraphicsDevice gd, String baseDir)
private bool CreateVertexBuffer(Scene scene, GraphicsDevice gd, string baseDir)
{
int vCount, iCount;
GatherVertexCounts(scene, out vCount, out iCount);
Expand Down Expand Up @@ -215,7 +215,7 @@ private bool CreateVertexBuffer(Scene scene, GraphicsDevice gd, String baseDir)
if(m.HasColorDiffuse)
diffuseColor = m.ColorDiffuse;

String filePath = String.Empty;
string filePath = string.Empty;
if(m.HasTextureDiffuse)
filePath = Path.Combine(baseDir, m.TextureDiffuse.FilePath);

Expand Down Expand Up @@ -415,7 +415,7 @@ public sealed class SimpleMaterial : IDisposable
private TextureView m_texView;
private DeviceBuffer m_materialConstantBuffer;

public SimpleMaterial(GraphicsDevice gd, SN.Vector4 diffuseColor, String texPath, ResourceLayout layout)
public SimpleMaterial(GraphicsDevice gd, SN.Vector4 diffuseColor, string texPath, ResourceLayout layout)
{
m_materialConstantBuffer = gd.ResourceFactory.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer));
gd.UpdateBuffer<SN.Vector4>(m_materialConstantBuffer, 0, ref diffuseColor);
Expand Down
54 changes: 27 additions & 27 deletions AssimpNet.Test/AssimpContextTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public class AssimpContextTestFixture
[OneTimeSetUp]
public void Setup()
{
String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/output");
string outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/output");

if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);

IEnumerable<String> filePaths = Directory.GetFiles(outputPath);
IEnumerable<string> filePaths = Directory.GetFiles(outputPath);

foreach(String filePath in filePaths)
foreach(string filePath in filePaths)
{
if (File.Exists(filePath))
File.Delete(filePath);
Expand Down Expand Up @@ -78,7 +78,7 @@ public void TestExportBadFormatId()
[Test]
public void TestExportToBlob()
{
String colladaPath = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string colladaPath = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");

AssimpContext context = new AssimpContext();
Scene ducky = context.ImportFile(colladaPath);
Expand All @@ -92,8 +92,8 @@ public void TestExportToBlob()
[Test]
public void TestImportExportFile()
{
String colladaPath = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
String plyPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/duck.ply");
string colladaPath = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string plyPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/duck.ply");

AssimpContext context = new AssimpContext();
Scene ducky = context.ImportFile(colladaPath);
Expand All @@ -103,8 +103,8 @@ public void TestImportExportFile()
[Test]
public void TestImportExportImportFile()
{
String colladaPath = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
String plyPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/duck2.dae");
string colladaPath = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string plyPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/duck2.dae");

AssimpContext context = new AssimpContext();
Scene ducky = context.ImportFile(colladaPath);
Expand All @@ -117,7 +117,7 @@ public void TestImportExportImportFile()
[Test]
public void TestExportToFile()
{
String path = Path.Combine(TestHelper.RootPath, "TestFiles/ExportedTriangle.obj");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/ExportedTriangle.obj");

//Create a very simple scene a single node with a mesh that has a single face, a triangle and a default material
Scene scene = new Scene();
Expand Down Expand Up @@ -192,7 +192,7 @@ public void TestFreeLogStreams()
[Test]
public void TestImportFromFile()
{
String path = Path.Combine(TestHelper.RootPath, "TestFiles/sphere.obj");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/sphere.obj");

AssimpContext importer = new AssimpContext();

Expand Down Expand Up @@ -225,14 +225,14 @@ public void TestImportFromFile()
[Test]
public void TestImportFromStream()
{
String path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");

FileStream fs = File.OpenRead(path);

AssimpContext importer = new AssimpContext();
LogStream.IsVerboseLoggingEnabled = true;

LogStream logstream = new LogStream(delegate(String msg, String userData)
LogStream logstream = new LogStream(delegate(string msg, string userData)
{
Console.WriteLine(msg);
});
Expand All @@ -250,21 +250,21 @@ public void TestImportFromStream()
[Test]
public void TestImportFromStreamNoFormatHint()
{
String path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");

FileStream fs = File.OpenRead(path);

AssimpContext importer = new AssimpContext();
LogStream.IsVerboseLoggingEnabled = true;

LogStream logstream = new LogStream(delegate (String msg, String userData)
LogStream logstream = new LogStream(delegate (string msg, string userData)
{
Console.WriteLine(msg);
});

logstream.Attach();

Scene scene = importer.ImportFileFromStream(fs, String.Empty); //null also seems to work well
Scene scene = importer.ImportFileFromStream(fs, string.Empty); //null also seems to work well

fs.Close();

Expand Down Expand Up @@ -295,7 +295,7 @@ public void TestSupportedFormats()
AssimpContext importer = new AssimpContext();
ExportFormatDescription[] exportDescs = importer.GetSupportedExportFormats();

String[] importFormats = importer.GetSupportedImportFormats();
string[] importFormats = importer.GetSupportedImportFormats();

Assert.That(exportDescs, Is.Not.Null);
Assert.That(importFormats, Is.Not.Null);
Expand All @@ -312,8 +312,8 @@ public void TestSupportedFormats()
[Test]
public void TestConvertFromFile()
{
String path = Path.Combine(TestHelper.RootPath, "TestFiles/Bob.md5mesh");
String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/Bob.dae");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/Bob.md5mesh");
string outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/Bob.dae");

AssimpContext importer = new AssimpContext();
importer.ConvertFromFileToFile(path, outputPath, "collada");
Expand All @@ -324,8 +324,8 @@ public void TestConvertFromFile()
[Test]
public void TestConvertFromStreamNoFormatHint()
{
String path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/duckNoHint.obj");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/duckNoHint.obj");

if (File.Exists(outputPath))
File.Delete(outputPath);
Expand All @@ -344,9 +344,9 @@ public void TestConvertFromStreamNoFormatHint()
[Test]
public void TestConvertFromStream()
{
String path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/duck.obj");
String outputPath2 = Path.Combine(TestHelper.RootPath, "TestFiles/output/duck-fromBlob.obj");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/output/duck.obj");
string outputPath2 = Path.Combine(TestHelper.RootPath, "TestFiles/output/duck-fromBlob.obj");

FileStream fs = File.OpenRead(path);

Expand Down Expand Up @@ -403,7 +403,7 @@ private void LoadSceneA()
{
Console.WriteLine("Thread A: Starting import.");
AssimpContext importer = new AssimpContext();
String path = Path.Combine(TestHelper.RootPath, "TestFiles/Bob.md5mesh");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/Bob.md5mesh");

new ConsoleLogStream("Thread A:").Attach();
Console.WriteLine("Thread A: Importing");
Expand All @@ -415,7 +415,7 @@ private void LoadSceneB()
{
Console.WriteLine("Thread B: Starting import.");
AssimpContext importer = new AssimpContext();
String path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");

new ConsoleLogStream("Thread B:").Attach();
importer.SetConfig(new NormalSmoothingAngleConfig(55.0f));
Expand All @@ -428,8 +428,8 @@ private void ConvertSceneC()
{
Console.WriteLine("Thread C: Starting convert.");
AssimpContext importer = new AssimpContext();
String path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/duck2.obj");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/duck2.obj");

new ConsoleLogStream("Thread C:").Attach();
importer.SetConfig(new NormalSmoothingAngleConfig(55.0f));
Expand Down
3 changes: 1 addition & 2 deletions AssimpNet.Test/ExportDataBlobTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* THE SOFTWARE.
*/

using System;
using System.IO;
using NUnit.Framework;

Expand All @@ -32,7 +31,7 @@ public class ExportDataBlobTestFixture
[Test]
public void TestToStream()
{
String path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/duck.dae");

AssimpContext importer = new AssimpContext();
ExportDataBlob blob = importer.ConvertFromFileToBlob(path, "obj");
Expand Down
17 changes: 8 additions & 9 deletions AssimpNet.Test/IOSystem_TestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* THE SOFTWARE.
*/

using System;
using System.IO;
using NUnit.Framework;

Expand All @@ -32,8 +31,8 @@ public class IOSystem_TestFixture
[Test]
public void TestMultiSearchDirectoryLoad()
{
String fileName = "fenris.lws";
String[] searchPaths = { Path.Combine(TestHelper.RootPath, "TestFiles/fenris/scenes"), Path.Combine(TestHelper.RootPath, "TestFiles/fenris/objects") };
string fileName = "fenris.lws";
string[] searchPaths = { Path.Combine(TestHelper.RootPath, "TestFiles/fenris/scenes"), Path.Combine(TestHelper.RootPath, "TestFiles/fenris/objects") };
FileIOSystem ioSystem = new FileIOSystem(searchPaths);

AssimpContext importer = new AssimpContext();
Expand All @@ -47,23 +46,23 @@ public void TestMultiSearchDirectoryLoad()
[Test]
public void TestMultiSearchDirectoryConvert()
{
String fileName = Path.Combine(TestHelper.RootPath, "TestFiles/fenris/scenes/fenris.lws");
String[] searchPaths = { Path.Combine(TestHelper.RootPath, "TestFiles/fenris/objects") };
string fileName = Path.Combine(TestHelper.RootPath, "TestFiles/fenris/scenes/fenris.lws");
string[] searchPaths = { Path.Combine(TestHelper.RootPath, "TestFiles/fenris/objects") };
FileIOSystem ioSystem = new FileIOSystem(searchPaths);

AssimpContext importer = new AssimpContext();
importer.SetIOSystem(ioSystem);

//Output path has to be specified fully, since we may be creating the file
String outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/fenris/fenris2.obj");
string outputPath = Path.Combine(TestHelper.RootPath, "TestFiles/fenris/fenris2.obj");
importer.ConvertFromFileToFile(fileName, PostProcessSteps.None, outputPath, "obj", PostProcessSteps.None);
}

[Test]
public void TestIOSystemError()
{
String fileName = "duckduck.dae"; //GOOSE!
String[] searchPaths = { Path.Combine(TestHelper.RootPath, "TestFiles") };
string fileName = "duckduck.dae"; //GOOSE!
string[] searchPaths = { Path.Combine(TestHelper.RootPath, "TestFiles") };
FileIOSystem ioSystem = new FileIOSystem(searchPaths);

AssimpContext importer = new AssimpContext();
Expand All @@ -77,7 +76,7 @@ public void TestIOSystemError()
[Test]
public void TestIOSystem_ImportObj()
{
String dir = Path.Combine(TestHelper.RootPath, "TestFiles");
string dir = Path.Combine(TestHelper.RootPath, "TestFiles");
LogStream.IsVerboseLoggingEnabled = true;
ConsoleLogStream log = new ConsoleLogStream();
log.Attach();
Expand Down
2 changes: 1 addition & 1 deletion AssimpNet.Test/Matrix3x3TestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void TestIndexer()
float value = values[(i * 3) + j];
//Matrix indices are one-based.
m[i + 1, j + 1] = value;
TestHelper.AssertEquals(value, m[i + 1, j + 1], String.Format("Testing [{0},{1}] indexer.", i + 1, j + 1));
TestHelper.AssertEquals(value, m[i + 1, j + 1], $"Testing [{i + 1},{j + 1}] indexer.");
}
}
}
Expand Down
1 change: 0 additions & 1 deletion AssimpNet.Test/MiscDefectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* THE SOFTWARE.
*/

using System;
using NUnit.Framework;

namespace Assimp.Test
Expand Down
3 changes: 1 addition & 2 deletions AssimpNet.Test/ObjSameFolderMtl_TestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* THE SOFTWARE.
*/

using System;
using System.IO;
using NUnit.Framework;

Expand All @@ -32,7 +31,7 @@ public class ObjSameFolderMtl_TestFixture
[Test]
public void TestObjLoad()
{
String path = Path.Combine(TestHelper.RootPath, "TestFiles/sphere.obj");
string path = Path.Combine(TestHelper.RootPath, "TestFiles/sphere.obj");

AssimpContext importer = new AssimpContext();
Scene scene = importer.ImportFile(path);
Expand Down
Loading

0 comments on commit c09379a

Please sign in to comment.