From 41a603e7123498d2e1abc1497bd7bf544cc43c39 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 1 Apr 2024 13:30:13 -0400 Subject: [PATCH 001/104] Added VimMesh to replace IMesh eventually --- src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs | 8 ++ src/cs/g3d/Vim.G3dNext/G3dChunk.cs | 62 +++++++++++++++ src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs | 61 +++++++++++++++ src/cs/g3d/Vim.G3dNext/G3dVim.cs | 45 +++++++++++ .../util/Vim.Util.Tests/VimFormatRepoPaths.cs | 2 +- src/cs/vim/Vim.Format.Core/Document.cs | 3 + .../Vim.Format.Core/SerializableDocument.cs | 75 ++---------------- .../SerializableEntityTable.cs | 70 +++++++++++++++-- .../Vim.Format.Core/Vim.Format.Core.csproj | 1 + .../SerializableDocumentTests.cs | 75 +++++++++++++++--- .../vim/Vim.Format/SceneBuilder/Validation.cs | 76 ++++++++++++++++++- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 10 ++- src/cs/vim/Vim.Format/Vim.Format.csproj | 1 + 13 files changed, 401 insertions(+), 88 deletions(-) diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs b/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs index 5724b22f..59cd7b22 100644 --- a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs +++ b/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs @@ -113,6 +113,14 @@ public bool Equals({entity.ClassName} other ) ); }} + public int CountOf(string name) + {{ + {string.Join("\n \t\t\t", entity.Buffers.Select(c => { + return $"if(name == \"{c.BufferName}\") return {c.MemberName}?.Length ?? -1;"; + }))} + return -1; + }} + public void Validate() {{ // Ensure all the indices are either -1 or within the bounds of the attributes they are indexing into. diff --git a/src/cs/g3d/Vim.G3dNext/G3dChunk.cs b/src/cs/g3d/Vim.G3dNext/G3dChunk.cs index 8ad82bd3..b445ba11 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dChunk.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dChunk.cs @@ -1,8 +1,33 @@ using System; +using System.Linq; using Vim.Math3d; namespace Vim.G3dNext { + public class VimMesh : ITransformable3D + { + public int[] indices; + public Vector3[] vertices; + public int[] submeshes; + public int[] submeshMaterials; + + public VimMesh Transform(Matrix4x4 mat) + { + var mesh = new VimMesh(); + mesh.indices = indices.ToArray(); + mesh.vertices = new Vector3[vertices.Length]; + mesh.submeshes = submeshes.ToArray(); + mesh.submeshMaterials = submeshMaterials.ToArray(); + + for(var i =0; i < vertices.Length;i++ ) + { + mesh.vertices[i] = vertices[i].Transform(mat); + } + return mesh; + } + } + + public partial class G3dChunk { void ISetup.Setup() @@ -10,6 +35,43 @@ void ISetup.Setup() // empty } + public VimMesh GetMesh(int index) + { + var mesh = new VimMesh(); + + var vStart = GetMeshVertexStart(index, MeshSection.All); + var vEnd = GetMeshVertexEnd(index, MeshSection.All); + mesh.vertices = new Vector3[vEnd - vStart]; + for (var i = 0; i < mesh.vertices.Length; i++) + { + var v = vStart + i; + mesh.vertices[i] = Positions[v]; + } + + var iStart = GetMeshIndexStart(index, MeshSection.All); + var iEnd = GetMeshIndexEnd(index, MeshSection.All); + mesh.indices = new int[iEnd - iStart]; + for (var i = 0; i < mesh.indices.Length; i++) + { + var j = iStart + i; + mesh.indices[i] = Indices[j] - vStart; + } + + var sStart = GetMeshSubmeshStart(index, MeshSection.All); + var sEnd = GetMeshSubmeshEnd(index, MeshSection.All); + mesh.submeshes = new int[sEnd - sStart]; + mesh.submeshMaterials = new int[sEnd - sStart]; + + for (var i =0; i < mesh.submeshMaterials.Length; i++) + { + var s = sStart + i; + mesh.submeshes[i] = SubmeshIndexOffsets[s] - vStart; + mesh.submeshMaterials[i] = SubmeshMaterials[s]; + } + + return mesh; + } + public int GetSubmeshCount() => SubmeshIndexOffsets?.Length ?? 0; public int getMeshCount() => MeshSubmeshOffset?.Length ?? 0; diff --git a/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs b/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs index 5d2a7b8d..5a2a9801 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs @@ -151,6 +151,27 @@ public G3dVim Merge(G3dVim other) ); } + public int CountOf(string name) + { + if(name == "g3d:corner:index:0:int32:1") return Indices?.Length ?? -1; + if(name == "g3d:vertex:position:0:float32:3") return Positions?.Length ?? -1; + if(name == "g3d:instance:transform:0:float32:16") return InstanceTransforms?.Length ?? -1; + if(name == "g3d:instance:parent:0:int32:1") return InstanceParents?.Length ?? -1; + if(name == "g3d:instance:flags:0:uint16:1") return InstanceFlags?.Length ?? -1; + if(name == "g3d:instance:mesh:0:int32:1") return InstanceMeshes?.Length ?? -1; + if(name == "g3d:mesh:submeshoffset:0:int32:1") return MeshSubmeshOffsets?.Length ?? -1; + if(name == "g3d:submesh:indexoffset:0:int32:1") return SubmeshIndexOffsets?.Length ?? -1; + if(name == "g3d:submesh:material:0:int32:1") return SubmeshMaterials?.Length ?? -1; + if(name == "g3d:material:color:0:float32:4") return MaterialColors?.Length ?? -1; + if(name == "g3d:material:glossiness:0:float32:1") return MaterialGlossiness?.Length ?? -1; + if(name == "g3d:material:smoothness:0:float32:1") return MaterialSmoothness?.Length ?? -1; + if(name == "g3d:shapevertex:position:0:float32:3") return ShapeVertices?.Length ?? -1; + if(name == "g3d:shape:vertexoffset:0:int32:1") return ShapeVertexOffsets?.Length ?? -1; + if(name == "g3d:shape:color:0:float32:4") return ShapeColors?.Length ?? -1; + if(name == "g3d:shape:width:0:float32:1") return ShapeWidths?.Length ?? -1; + return -1; + } + public void Validate() { // Ensure all the indices are either -1 or within the bounds of the attributes they are indexing into. @@ -248,6 +269,18 @@ public G3dChunk Merge(G3dChunk other) ); } + public int CountOf(string name) + { + if(name == "g3d:mesh:opaquesubmeshcount:0:int32:1") return MeshOpaqueSubmeshCounts?.Length ?? -1; + if(name == "g3d:mesh:submeshoffset:0:int32:1") return MeshSubmeshOffset?.Length ?? -1; + if(name == "g3d:submesh:indexoffset:0:int32:1") return SubmeshIndexOffsets?.Length ?? -1; + if(name == "g3d:submesh:vertexoffset:0:int32:1") return SubmeshVertexOffsets?.Length ?? -1; + if(name == "g3d:submesh:material:0:int32:1") return SubmeshMaterials?.Length ?? -1; + if(name == "g3d:vertex:position:0:float32:3") return Positions?.Length ?? -1; + if(name == "g3d:corner:index:0:int32:1") return Indices?.Length ?? -1; + return -1; + } + public void Validate() { // Ensure all the indices are either -1 or within the bounds of the attributes they are indexing into. @@ -314,6 +347,14 @@ public G3dMaterials Merge(G3dMaterials other) ); } + public int CountOf(string name) + { + if(name == "g3d:material:color:0:float32:4") return MaterialColors?.Length ?? -1; + if(name == "g3d:material:glossiness:0:float32:1") return MaterialGlossiness?.Length ?? -1; + if(name == "g3d:material:smoothness:0:float32:1") return MaterialSmoothness?.Length ?? -1; + return -1; + } + public void Validate() { // Ensure all the indices are either -1 or within the bounds of the attributes they are indexing into. @@ -461,6 +502,26 @@ public G3dScene Merge(G3dScene other) ); } + public int CountOf(string name) + { + if(name == "g3d:chunk:count:0:int32:1") return ChunkCount?.Length ?? -1; + if(name == "g3d:instance:mesh:0:int32:1") return InstanceMeshes?.Length ?? -1; + if(name == "g3d:instance:transform:0:float32:16") return InstanceTransformData?.Length ?? -1; + if(name == "g3d:instance:node:0:int32:1") return InstanceNodes?.Length ?? -1; + if(name == "g3d:instance:group:0:int32:1") return InstanceGroups?.Length ?? -1; + if(name == "g3d:instance:tag:0:int64:1") return InstanceTags?.Length ?? -1; + if(name == "g3d:instance:flags:0:uint16:1") return InstanceFlags?.Length ?? -1; + if(name == "g3d:instance:min:0:float32:3") return InstanceMins?.Length ?? -1; + if(name == "g3d:instance:max:0:float32:3") return InstanceMaxs?.Length ?? -1; + if(name == "g3d:mesh:chunk:0:int32:1") return MeshChunks?.Length ?? -1; + if(name == "g3d:mesh:chunkindex:0:int32:1") return MeshChunkIndices?.Length ?? -1; + if(name == "g3d:mesh:vertexcount:0:int32:1") return MeshVertexCounts?.Length ?? -1; + if(name == "g3d:mesh:indexcount:0:int32:1") return MeshIndexCounts?.Length ?? -1; + if(name == "g3d:mesh:opaquevertexcount:0:int32:1") return MeshOpaqueVertexCounts?.Length ?? -1; + if(name == "g3d:mesh:opaqueindexcount:0:int32:1") return MeshOpaqueIndexCounts?.Length ?? -1; + return -1; + } + public void Validate() { // Ensure all the indices are either -1 or within the bounds of the attributes they are indexing into. diff --git a/src/cs/g3d/Vim.G3dNext/G3dVim.cs b/src/cs/g3d/Vim.G3dNext/G3dVim.cs index 3ddb9885..0801564d 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dVim.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dVim.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; using Vim.BFastLib; +using Vim.Math3d; namespace Vim.G3dNext { @@ -10,6 +12,49 @@ public partial class G3dVim public int[] MeshVertexOffsets; private List[] _meshInstances; + + public VimMesh GetMesh(int index) + { + var mesh = new VimMesh(); + + var vStart = GetMeshVertexStart(index); + var vEnd = GetMeshVertexEnd(index); + mesh.vertices = new Vector3[vEnd - vStart]; + for (var i = 0; i < mesh.vertices.Length; i++) + { + var v = vStart + i; + mesh.vertices[i] = Positions[v]; + } + + var iStart = GetMeshIndexStart(index); + var iEnd = GetMeshIndexEnd(index); + mesh.indices = new int[iEnd - iStart]; + for (var i = 0; i < mesh.indices.Length; i++) + { + var j = iStart + i; + mesh.indices[i] = Indices[j] - vStart; + } + + var sStart = GetMeshSubmeshStart(index); + var sEnd = GetMeshSubmeshEnd(index); + mesh.submeshes = new int[sEnd - sStart]; + mesh.submeshMaterials = new int[sEnd - sStart]; + + for (var i = 0; i < mesh.submeshMaterials.Length; i++) + { + var s = sStart + i; + mesh.submeshes[i] = SubmeshIndexOffsets[s] - iStart; + mesh.submeshMaterials[i] = SubmeshMaterials[s]; + } + + return mesh; + } + + public IEnumerable GetAllMeshes() + { + return Enumerable.Range(0, GetMeshCount()).Select(i => GetMesh(i)); + } + public IReadOnlyList GetMeshInstances(int mesh) { return _meshInstances[mesh]; diff --git a/src/cs/util/Vim.Util.Tests/VimFormatRepoPaths.cs b/src/cs/util/Vim.Util.Tests/VimFormatRepoPaths.cs index 2a76d8b7..5816c16f 100644 --- a/src/cs/util/Vim.Util.Tests/VimFormatRepoPaths.cs +++ b/src/cs/util/Vim.Util.Tests/VimFormatRepoPaths.cs @@ -26,7 +26,7 @@ public static class VimFormatRepoPaths /// public static string GetLatestWolfordResidenceVim() { - var matchingVim = Directory.GetFiles(DataDir, "Wolford_Residence*.vim", SearchOption.AllDirectories).FirstOrDefault(); + var matchingVim = Directory.GetFiles(DataDir, "Wolford_Residence*.vim", SearchOption.AllDirectories).OrderByDescending(p => p).FirstOrDefault(); if (matchingVim == null) throw new FileNotFoundException($"Could not find the latest Wolford Residence VIM."); diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index 8465ea7d..eecebb48 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -1,5 +1,6 @@ using Vim.LinqArray; using Vim.BFastLib; +using Vim.G3dNext; namespace Vim.Format { @@ -11,6 +12,7 @@ public Document(SerializableDocument document) _Document = document; Header = _Document.Header; Geometry = _Document.Geometry; + GeometryNext = _Document.GeometryNext; StringTable = _Document.StringTable.ToIArray(); EntityTables = _Document.EntityTables.ToLookup( et => et.Name, @@ -26,5 +28,6 @@ public Document(SerializableDocument document) public IArray StringTable { get; } public string GetString(int index) => StringTable.ElementAtOrDefault(index); public G3d.G3D Geometry { get; } + public G3dVim GeometryNext { get; } } } diff --git a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs index 3a9ae487..99318a01 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Text; using Vim.BFastLib; using Vim.BFastLib.Core; using Vim.G3d; +using Vim.G3dNext; namespace Vim.Format { @@ -54,6 +54,11 @@ public class SerializableDocument /// public G3d.G3D Geometry; + /// + /// The uninstanced / untransformed geometry + /// + public G3dVim GeometryNext; + /// /// The originating file name (if provided) /// @@ -123,6 +128,7 @@ public static SerializableDocument FromBFast(BFast bfast, LoadOptions options = { var geo = bfast.GetBFast(BufferNames.Geometry); doc.Geometry = G3D.Read(geo); + doc.GeometryNext = new G3dVim(geo); } var entities = bfast.GetBFast(BufferNames.Entities); @@ -141,75 +147,10 @@ private static IEnumerable GetEntityTables( foreach (var entry in bfast.Entries) { var b = bfast.GetBFast(entry); - var table = ReadEntityTable(b, schemaOnly); + var table = SerializableEntityTable.FromBFast(b, schemaOnly); table.Name = entry; yield return table; } } - - /// - /// Returns a SerializableEntityTable based on the given buffer reader. - /// - public static SerializableEntityTable ReadEntityTable( - BFast bfast, - bool schemaOnly - ) - { - var et = new SerializableEntityTable(); - foreach (var entry in bfast.Entries) - { - var typePrefix = SerializableEntityTable.GetTypeFromName(entry); - - switch (typePrefix) - { - case VimConstants.IndexColumnNameTypePrefix: - { - //TODO: replace named buffer with arrays - var col = schemaOnly ? new int[0] : bfast.GetArray(entry); - et.IndexColumns.Add(col.ToNamedBuffer(entry)); - break; - } - case VimConstants.StringColumnNameTypePrefix: - { - var col = schemaOnly ? new int[0] : bfast.GetArray(entry); - et.StringColumns.Add(col.ToNamedBuffer(entry)); - break; - } - case VimConstants.IntColumnNameTypePrefix: - { - var col = schemaOnly ? new int[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); - break; - } - case VimConstants.LongColumnNameTypePrefix: - { - var col = schemaOnly ? new long[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); - break; - } - case VimConstants.DoubleColumnNameTypePrefix: - { - var col = schemaOnly ? new double[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); - break; - } - case VimConstants.FloatColumnNameTypePrefix: - { - var col = schemaOnly ? new float[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); - break; - } - case VimConstants.ByteColumnNameTypePrefix: - { - var col = schemaOnly ? new byte[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); - break; - } - // For flexibility, we ignore the columns which do not contain a recognized prefix. - } - } - - return et; - } } } diff --git a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs index dd724bb9..4b86268c 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs @@ -43,11 +43,6 @@ public IEnumerable AllColumns .Concat(StringColumns) .Concat(DataColumns); - public static SerializableEntityTable FromBfast(string name, BFast bfast) - { - return null; - } - private readonly static Regex TypePrefixRegex = new Regex(@"(\w+:).*"); public static string GetTypeFromName(string name) @@ -56,6 +51,71 @@ public static string GetTypeFromName(string name) return match.Success ? match.Groups[1].Value : ""; } + /// + /// Returns a SerializableEntityTable based on the given buffer reader. + /// + public static SerializableEntityTable FromBFast( + BFast bfast, + bool schemaOnly + ) + { + var et = new SerializableEntityTable(); + foreach (var entry in bfast.Entries) + { + var typePrefix = SerializableEntityTable.GetTypeFromName(entry); + + switch (typePrefix) + { + case VimConstants.IndexColumnNameTypePrefix: + { + //TODO: replace named buffer with arrays + var col = schemaOnly ? new int[0] : bfast.GetArray(entry); + et.IndexColumns.Add(col.ToNamedBuffer(entry)); + break; + } + case VimConstants.StringColumnNameTypePrefix: + { + var col = schemaOnly ? new int[0] : bfast.GetArray(entry); + et.StringColumns.Add(col.ToNamedBuffer(entry)); + break; + } + case VimConstants.IntColumnNameTypePrefix: + { + var col = schemaOnly ? new int[0] : bfast.GetArray(entry); + et.DataColumns.Add(col.ToNamedBuffer(entry)); + break; + } + case VimConstants.LongColumnNameTypePrefix: + { + var col = schemaOnly ? new long[0] : bfast.GetArray(entry); + et.DataColumns.Add(col.ToNamedBuffer(entry)); + break; + } + case VimConstants.DoubleColumnNameTypePrefix: + { + var col = schemaOnly ? new double[0] : bfast.GetArray(entry); + et.DataColumns.Add(col.ToNamedBuffer(entry)); + break; + } + case VimConstants.FloatColumnNameTypePrefix: + { + var col = schemaOnly ? new float[0] : bfast.GetArray(entry); + et.DataColumns.Add(col.ToNamedBuffer(entry)); + break; + } + case VimConstants.ByteColumnNameTypePrefix: + { + var col = schemaOnly ? new byte[0] : bfast.GetArray(entry); + et.DataColumns.Add(col.ToNamedBuffer(entry)); + break; + } + // For flexibility, we ignore the columns which do not contain a recognized prefix. + } + } + + return et; + } + public BFast ToBFast() { var bfast = new BFast(); diff --git a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj index 382777aa..f02d4460 100644 --- a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj +++ b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj @@ -12,6 +12,7 @@ + diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 497180d5..2f2eeec8 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -1,16 +1,10 @@ using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Vim.Util.Tests; - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using NUnit.Framework; using Vim.Util.Tests; +using Vim.Format.SceneBuilder; +using Vim.G3dNext; +using Vim.Format.Geometry; +using Vim.LinqArray; +using Vim.Math3d; namespace Vim.Format.Tests; @@ -25,5 +19,64 @@ public static void TestEmpty() var doc = new SerializableDocument(); Assert.DoesNotThrow(() => doc.ToBFast()); } + + [Test] + public static void CanOpenVim() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + scene.Validate(); + } + + [Test] + public static void MaterialColor_IsSame() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + for(var i=0; i < scene.GetMaterialCount(); i++) + { + Assert.AreEqual(scene.GetMaterialColor(i),scene.GetMaterialColorNext(i)); + } + } + + [Test] + public static void GetMesh_IsSameMesh() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + for (var i = 0; i < scene.GetMeshCount(); i++) + { + var mesh = scene.Meshes[i]; + var next = scene.MeshesNext[i]; + MeshesAreSame(mesh, next); + } + } + + [Test] + public static void GetMesh_Transform_IsSame() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + for (var i = 0; i < scene.GetMeshCount(); i++) + { + var mat = Matrix4x4.CreateWorld( + new Vector3(1, -2, 3), + new Vector3(0, 0, 1), + new Vector3(0, 1, 0) + ); + var mesh = scene.Meshes[i].Transform(mat); + var next = scene.MeshesNext[i].Transform(mat); + MeshesAreSame(mesh, next); + } + } + + private static void MeshesAreSame(IMesh mesh, VimMesh next) + { + + Assert.That(mesh.Indices.SequenceEquals(next.indices.ToIArray())); + Assert.That(mesh.Vertices.SequenceEquals(next.vertices.ToIArray())); + Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.submeshes.ToIArray())); + Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.submeshMaterials.ToIArray())); + } } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index 66365bb4..a1eaa15f 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -9,6 +9,7 @@ using Vim.Util; using Vim.LinqArray; using Vim.Math3d; +using Vim.G3d; namespace Vim.Format.SceneBuilder { @@ -28,19 +29,27 @@ public static void ValidateGeometry(this VimScene vim) { // Validate the packed geometry. vim.Document.Geometry.ToIMesh().Validate(); + var errors = new List(); + + G3d.Validation.Validate(vim.Document.Geometry); + // Validate the individual meshes. foreach (var g in vim.Meshes.ToEnumerable()) g.Validate(); } + public static void ValidateGeometryNext(this VimScene vim) + { + //TODO: Sronger validation maybe. + vim.Document.GeometryNext.Validate(); + } + public static void ValidateDocumentModelToG3dInvariants(this VimScene vim) { var g3d = vim._SerializableDocument.Geometry; var errors = new List(); - errors.AddRange(Vim.G3d.Validation.Validate(g3d).Select(e => e.ToString("G"))); - var entityTypesWithG3dReferences = new HashSet<(Type, G3dAttributeReferenceAttribute[])>( ObjectModelReflection.GetEntityTypes() .Select(t => ( @@ -94,6 +103,65 @@ public static void ValidateDocumentModelToG3dInvariants(this VimScene vim) } } + + + public static void ValidateDocumentModelToG3dInvariantsNext(this VimScene vim) + { + var g3d = vim.Document.GeometryNext; + var errors = new List(); + + var entityTypesWithG3dReferences = new HashSet<(Type, G3dAttributeReferenceAttribute[])>( + ObjectModelReflection.GetEntityTypes() + .Select(t => ( + type: t, + attrs: t.GetCustomAttributes(typeof(G3dAttributeReferenceAttribute)) + .Select(a => a as G3dAttributeReferenceAttribute) + .ToArray())) + .Where(tuple => tuple.attrs.Length != 0)); + + var dm = vim.DocumentModel; + + foreach (var tuple in entityTypesWithG3dReferences) + { + var (type, attrs) = tuple; + var propertyName = type.Name + "List"; + if (dm.GetPropertyValue(propertyName) is IArray arr) + { + var numEntities = arr.Count; + + foreach (var attr in attrs) + { + var attributeName = attr.AttributeName; + var isOptional = attr.AttributeIsOptional; + + var count = g3d.CountOf(attributeName); + + // We don't check the relation if the attribute is optional and absent (null). + if (isOptional && count < 0) + continue; + + var mult = attr.AttributeReferenceMultiplicity; + + // Validate one-to-one relationships + if (mult == G3dAttributeReferenceMultiplicity.OneToOne && numEntities != count) + { + errors.Add($"Multiplicity Error ({mult}); the number of entities of type \"{type.Name}\" ({numEntities}) is not equal to the number of elements in the g3d attribute \"{attributeName}\" ({count})"); + } + } + } + else + { + throw new VimValidationException($"DocumentModel.{propertyName} not found"); + } + } + + if (errors.Count > 0) + { + throw new VimValidationException( + $"DocumentModel to G3d invariant error(s):{Environment.NewLine}{string.Join(Environment.NewLine, errors)}"); + } + } + public static void ValidateNodes(this VimScene vim) { if (vim.VimNodes.Count != vim.DocumentModel.NumNode) @@ -138,7 +206,11 @@ public static void Validate(this VimScene vim, VimValidationOptions options = nu vim.Document.Validate(); vim.DocumentModel.Validate(options.ObjectModelValidationOptions); vim.ValidateGeometry(); + vim.ValidateGeometryNext(); + vim.ValidateDocumentModelToG3dInvariants(); + vim.ValidateDocumentModelToG3dInvariantsNext(); + vim.ValidateNodes(); vim.ValidateShapes(); } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index a502aaa8..ce3e7c51 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -11,6 +11,7 @@ using Vim.Math3d; using IVimSceneProgress = System.IProgress<(string, double)>; using Vim.BFastLib; +using Vim.G3dNext; namespace Vim { @@ -59,6 +60,7 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, public int VimIndex { get; set; } public IArray Meshes { get; private set; } + public VimMesh[] MeshesNext { get; private set; } public IArray Nodes { get; private set; } public IArray VimNodes { get; private set; } public IArray VimShapes { get; private set; } @@ -71,12 +73,15 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, public string PersistingId => Document.Header.PersistingId; - public Material GetMaterial(int materialIndex) - => DocumentModel.MaterialList.ElementAtOrDefault(materialIndex); + public int GetMeshCount() => Meshes.Count; + public int GetMaterialCount() => Materials.Count; public Vector4 GetMaterialColor(int materialIndex) => _SerializableDocument.Geometry.MaterialColors[materialIndex]; + public Vector4 GetMaterialColorNext(int materialIndex) + => _SerializableDocument.GeometryNext.MaterialColors[materialIndex]; + public static IMesh ToIMesh(G3dMesh g3d) => Primitives.TriMesh( g3d.Vertices.ToPositionAttribute(), @@ -200,6 +205,7 @@ private void CreateMeshes(bool inParallel) : inParallel ? tmp.EvaluateInParallel() : tmp.Evaluate(); + MeshesNext = _SerializableDocument.GeometryNext.GetAllMeshes().ToArray(); } private void CreateShapes(bool inParallel) diff --git a/src/cs/vim/Vim.Format/Vim.Format.csproj b/src/cs/vim/Vim.Format/Vim.Format.csproj index 8fa44b7a..6f385377 100644 --- a/src/cs/vim/Vim.Format/Vim.Format.csproj +++ b/src/cs/vim/Vim.Format/Vim.Format.csproj @@ -35,6 +35,7 @@ true true + From 9b169ea520242c27c513155559045b20171ee002 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 1 Apr 2024 13:34:04 -0400 Subject: [PATCH 002/104] removed unused methods --- .../Geometry/SceneExtensions.cs | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs b/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs index 8f6e2f9a..d760f734 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs @@ -13,50 +13,16 @@ public static IMesh TransformedMesh(this ISceneNode node) public static IEnumerable TransformedMeshes(this IScene scene) => scene.Nodes.Where(n => n.GetMesh() != null).Select(TransformedMesh); - - public static IMesh ToIMesh(this IScene scene) - => scene.TransformedMeshes().Merge(); - - public static bool HasLoop(this ISceneNode n) - { - if (n == null) return false; - var visited = new HashSet(); - for (; n != null; n = n.Parent) - { - if (visited.Contains(n)) - return true; - visited.Add(n); - } - - return false; - } - + public static IMesh MergedGeometry(this IScene scene) => scene.Nodes.ToEnumerable().MergedGeometry(); public static IMesh MergedGeometry(this IEnumerable nodes) => nodes.Where(n => n.GetMesh() != null).Select(TransformedMesh).Merge(); - public static Matrix4x4 LocalTransform(this ISceneNode node) - => node.Parent != null - ? node.Transform * node.Parent.Transform.Inverse() - : node.Transform; - - public static IEnumerable AllDistinctMeshes(this IScene scene) - => scene.UntransformedMeshes().Where(x => x != null).Distinct(); - - public static IndexedSet GeometryLookup(this IScene scene) - => scene.Meshes.ToEnumerable().ToIndexedSet(); - public static IArray UntransformedMeshes(this IScene scene) => scene.Nodes.Select(n => n.GetMesh()); - public static bool HasGeometry(this IScene scene) - => scene.Nodes.Any(n => n.GetMesh() != null); - - public static Dictionary GeometryCounts(this IScene scene) - => scene.Nodes.ToEnumerable().CountInstances(x => x.GetMesh()); - public static IEnumerable AllVertices(this IScene scene) => scene.TransformedMeshes().SelectMany(g => g.Vertices.ToEnumerable()); @@ -69,15 +35,9 @@ public static IArray Transforms(this IScene scene) public static IArray NodePositions(this IScene scene) => scene.Transforms().Select(m => m.Translation); - public static AABox NodePositionBoundingBox(this IScene scene) - => AABox.Create(scene.NodePositions().ToEnumerable()); - public static Sphere BoundingSphere(this IScene scene) => scene.BoundingBox().ToSphere(); - public static float BoundingRadius(this IScene scene) - => scene.BoundingSphere().Radius; - public static IArray TransformedVertices(this ISceneNode node) => node.TransformedMesh()?.Vertices; From e84b315cef04d09c594f876cd15765994d6eeb6d Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 1 Apr 2024 13:36:33 -0400 Subject: [PATCH 003/104] removed more unused methods --- .../vim/Vim.Format.Core/Geometry/SceneExtensions.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs b/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs index d760f734..555baefa 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs @@ -20,24 +20,12 @@ public static IMesh MergedGeometry(this IScene scene) public static IMesh MergedGeometry(this IEnumerable nodes) => nodes.Where(n => n.GetMesh() != null).Select(TransformedMesh).Merge(); - public static IArray UntransformedMeshes(this IScene scene) - => scene.Nodes.Select(n => n.GetMesh()); - public static IEnumerable AllVertices(this IScene scene) => scene.TransformedMeshes().SelectMany(g => g.Vertices.ToEnumerable()); public static AABox BoundingBox(this IScene scene) => AABox.Create(scene.AllVertices()); - public static IArray Transforms(this IScene scene) - => scene.Nodes.Select(n => n.Transform); - - public static IArray NodePositions(this IScene scene) - => scene.Transforms().Select(m => m.Translation); - - public static Sphere BoundingSphere(this IScene scene) - => scene.BoundingBox().ToSphere(); - public static IArray TransformedVertices(this ISceneNode node) => node.TransformedMesh()?.Vertices; From f617135e1c4d4034799632f0048cbbbce08b5991 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 1 Apr 2024 13:51:20 -0400 Subject: [PATCH 004/104] removed unused code --- .../Geometry/MeshOptimization.cs | 78 ------------------- 1 file changed, 78 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs index 6efb92f3..4db387a7 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs @@ -58,87 +58,9 @@ public override int GetHashCode() => Hash.Combine(NumFaces, NumVertices, TopologyHash, BoxMin.GetHashCode(), BoxExtents.GetHashCode()); } - public class IntegerPositionColorNormal - { - public Int3 Position; - public Int3 Color; - public Int3 Normal; - - public IntegerPositionColorNormal(Int3 pos, Int3 color, Int3 normal) - => (Position, Color, Normal) = (pos, color, normal); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override int GetHashCode() - => Hash.Combine(Position.GetHashCode(), Color.GetHashCode(), Normal.GetHashCode()); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override bool Equals(object obj) - => Equals(obj as IntegerPositionColorNormal); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(IntegerPositionColorNormal other) - => other != null && Position.Equals(other.Position) && Color.Equals(other.Color) && Normal.Equals(other.Normal); - } - public static class Optimization { - public static Dictionary> GroupMeshesByHash(this IArray meshes, float tolerance) - => meshes.ToEnumerable().GroupMeshesByHash(tolerance); - public static Dictionary> GroupMeshesByHash(this IEnumerable meshes, float tolerance) => meshes.AsParallel().GroupBy(m => new MeshHash(m, tolerance)).ToDictionary(grp => grp.Key, grp => grp.ToList()); - - /// - /// Merges vertices that are within a certain distance and have similar normals and colors. - /// - public static IMesh WeldVertices(this IMesh g, float threshold = (float)Math3d.Constants.MmToFeet) - { - var positions = g.Vertices; - var normals = g.GetOrComputeVertexNormals().ToArray(); - var colors = g.VertexColors ?? Vector4.Zero.Repeat(positions.Count); - - // Vertex indices by color, and then by normal - var d = new Dictionary(); - - // The mapping of old indices to new ones - var indexRemap = new int[g.Vertices.Count]; - - // This is a list of vertex indices that we are keeping - var vertRemap = new List(); - - // Local helper function - Int3 ToInt3(Vector3 v) - => new Int3((int)v.X, (int)v.Y, (int)v.Z); - - for (var i = 0; i < g.NumVertices; ++i) - { - var p = ToInt3(positions[i] * (1 / threshold)); - var c = ToInt3(colors[i].ToVector3() * 10000); - var n = ToInt3(normals[i] * 10000); - - var pcn = new IntegerPositionColorNormal(p, c, n); - - if (d.TryGetValue(pcn, out var index)) - { - indexRemap[i] = index; - continue; - } - - var newVertIndex = vertRemap.Count; - indexRemap[i] = newVertIndex; - vertRemap.Add(i); - - d.Add(pcn, newVertIndex); - } - - Debug.Assert(vertRemap.Count <= g.NumVertices); - for (var i = 1; i < vertRemap.Count; ++i) - Debug.Assert(vertRemap[i - 1] < vertRemap[i]); - - return g.RemapVertices( - vertRemap.ToIArray(), - g.Indices.Select(i => indexRemap[i])) - .ToIMesh(); - } } } From 6f058a6f14c60feff846f4741aa9d810c3aa1e48 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 1 Apr 2024 14:14:02 -0400 Subject: [PATCH 005/104] removed unused methods --- .../Geometry/MeshExtensions.cs | 254 +----------------- .../Geometry/PerimeterProjection.cs | 59 ---- 2 files changed, 2 insertions(+), 311 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs index 506cb3d3..f9a3610f 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs @@ -32,30 +32,9 @@ public static IMesh ToIMesh(this IGeometryAttributes g) => g is IMesh m ? m : g is QuadMesh q ? q.ToIMesh() : g.Attributes.ToIMesh(); #endregion - // Computes the topology: this is a slow O(N) operation - public static Topology ComputeTopology(this IMesh mesh) - => new Topology(mesh); - public static double Area(this IMesh mesh) => mesh.Triangles().Sum(t => t.Area); - #region validation - public static bool IsDegenerateVertexIndices(this Int3 vertexIndices) - => vertexIndices.X == vertexIndices.Y || vertexIndices.X == vertexIndices.Z || vertexIndices.Y == vertexIndices.Z; - - public static bool HasDegenerateFaceVertexIndices(this IMesh self) - => self.AllFaceVertexIndices().Any(IsDegenerateVertexIndices); - #endregion - - // TODO: find a better location for this function. DotNetUtilties doesn't know about IArray unfortunately, so maybe this project needs its own Utility class. - public static DictionaryOfLists GroupBy(this IArray xs, Func groupingFunc) - { - var r = new DictionaryOfLists(); - for (var i = 0; i < xs.Count; ++i) - r.Add(groupingFunc(i), xs[i]); - return r; - } - public static IArray GetFaceMaterials(this IMesh mesh) { // SubmeshIndexOffsets: [0, A, B] @@ -70,15 +49,6 @@ public static IArray GetFaceMaterials(this IMesh mesh) .ToIArray(); } - public static IEnumerable DisctinctMaterials(this IMesh mesh) - => mesh.GetFaceMaterials().ToEnumerable().Distinct(); - - public static DictionaryOfLists IndicesByMaterial(this IMesh mesh) - { - var faceMaterials = mesh.GetFaceMaterials(); - return mesh.Indices.GroupBy(i => faceMaterials[i / 3]); - } - public static IMesh Merge(this IArray meshes) => meshes.Select(m => (IGeometryAttributes)m).Merge().ToIMesh(); @@ -107,7 +77,7 @@ public static IMesh Merge(this IMesh mesh, params IMesh[] others) submeshMaterials.Count <= 1 || submeshIndexOffets.Count <= 1 || submeshIndexCounts.Count <= 1) { // Base case: only one submesh material. - return new [] { (submeshMaterials[0], mesh) }; + return new[] { (submeshMaterials[0], mesh) }; } // Example: @@ -161,7 +131,7 @@ public static IMesh Merge(this IMesh mesh, params IMesh[] others) var newSubmeshIndexOffsets = 0.Repeat(1).ToSubmeshIndexOffsetAttribute(); var newSubmeshMaterials = submeshMaterial.Repeat(1).ToSubmeshMaterialAttribute(); - + return newVertexAttributes .Concat(mesh.NoneAttributes()) .Concat(mesh.WholeGeometryAttributes()) @@ -176,50 +146,12 @@ public static IMesh Merge(this IMesh mesh, params IMesh[] others) return meshes.Select(m => (material, m)); }); } - - public static IGeometryAttributes DeleteUnusedVertices(this IMesh mesh) - { - var tmp = new bool[mesh.Vertices.Count]; - for (var i = 0; i < mesh.Indices.Count; ++i) - tmp[mesh.Indices[i]] = true; - - var remap = new List(); - for (var i = 0; i < tmp.Length; ++i) - { - if (tmp[i]) - remap.Add(i); - } - - return mesh.RemapVertices(remap.ToIArray()); - } - public static bool GeometryEquals(this IMesh mesh, IMesh other, float tolerance = Math3d.Constants.Tolerance) { if (mesh.NumFaces != other.NumFaces) return false; return mesh.Triangles().Zip(other.Triangles(), (t1, t2) => t1.AlmostEquals(t2, tolerance)).All(x => x); } - - public static IMesh SimplePolygonTessellate(this IEnumerable points) - { - var pts = points.ToList(); - var cnt = pts.Count; - var sum = Vector3.Zero; - var idxs = new List(pts.Count * 3); - for (var i = 0; i < pts.Count; ++i) - { - idxs.Add(i); - idxs.Add(i + 1 % cnt); - idxs.Add(cnt); - sum += pts[i]; - } - - var midPoint = sum / pts.Count; - pts.Add(midPoint); - - return Primitives.TriMesh(pts.ToIArray(), idxs.ToIArray()); - } - public static IGeometryAttributes ReverseWindingOrder(this IMesh mesh) { var n = mesh.Indices.Count; @@ -233,125 +165,16 @@ public static IGeometryAttributes ReverseWindingOrder(this IMesh mesh) return mesh.SetAttribute(r.ToIArray().ToIndexAttribute()); } - /// - /// Returns the closest point in a sequence of points - /// - public static Vector3 NearestPoint(this IEnumerable points, Vector3 x) - => points.Minimize(float.MaxValue, p => p.DistanceSquared(x)); - - /// - /// Returns the closest point in a sequence of points - /// - public static Vector3 NearestPoint(this IArray points, Vector3 x) - => points.ToEnumerable().NearestPoint(x); - - /// - /// Returns the closest point in a geometry - /// - public static Vector3 NearestPoint(this IMesh mesh, Vector3 x) - => mesh.Vertices.NearestPoint(x); - - public static Vector3 FurthestPoint(this IMesh mesh, Vector3 x0, Vector3 x1) - => mesh.Vertices.FurthestPoint(x0, x1); - - public static Vector3 FurthestPoint(this IArray points, Vector3 x0, Vector3 x1) - => points.ToEnumerable().FurthestPoint(x0, x1); - - public static Vector3 FurthestPoint(this IEnumerable points, Vector3 x0, Vector3 x1) - => points.Maximize(float.MinValue, v => v.Distance(x0).Min(v.Distance(x1))); - - public static Vector3 FurthestPoint(this IMesh mesh, Vector3 x) - => mesh.Vertices.FurthestPoint(x); - - public static Vector3 FurthestPoint(this IArray points, Vector3 x) - => points.ToEnumerable().FurthestPoint(x); - - public static Vector3 FurthestPoint(this IEnumerable points, Vector3 x) - => points.Maximize(float.MinValue, v => v.Distance(x)); - - public static IGeometryAttributes SnapPoints(this IMesh mesh, float snapSize) - => snapSize.Abs() >= Math3d.Constants.Tolerance - ? mesh.Deform(v => (v * snapSize.Inverse()).Truncate() * snapSize) - : mesh.Deform(v => Vector3.Zero); - - /// - /// Returns the vertices organized by face corner. - /// - public static IArray VerticesByIndex(this IMesh mesh) - => mesh.Vertices.SelectByIndex(mesh.Indices); - - /// - /// Returns the vertices organized by face corner, normalized to the first position. - /// This is useful for detecting if two meshes are the same except offset by - /// position. - /// - public static IArray NormalizedVerticesByCorner(this IMesh m) - { - if (m.NumCorners == 0) - return Vector3.Zero.Repeat(0); - var firstVertex = m.Vertices[m.Indices[0]]; - return m.VerticesByIndex().Select(v => v - firstVertex); - } - - /// - /// Compares the face positions of two meshes normalized by the vertex buffer, returning the maximum distance, or null - /// if the meshes have different topology. - /// - public static float? MaxNormalizedDistance(this IMesh mesh, IMesh other) - { - var xs = mesh.NormalizedVerticesByCorner(); - var ys = other.NormalizedVerticesByCorner(); - if (xs.Count != ys.Count) - return null; - return xs.Zip(ys, (x, y) => x.Distance(y)).Max(); - } public static AABox BoundingBox(this IMesh mesh) => AABox.Create(mesh.Vertices.ToEnumerable()); - public static Sphere BoundingSphere(this IMesh mesh) - => mesh.BoundingBox().ToSphere(); - - public static float BoundingRadius(this IMesh mesh) - => mesh.BoundingSphere().Radius; public static Vector3 Center(this IMesh mesh) => mesh.BoundingBox().Center; - public static Vector3 Centroid(this IMesh mesh) - => mesh.Vertices.Aggregate(Vector3.Zero, (x, y) => x + y) / mesh.Vertices.Count; - - public static bool AreIndicesValid(this IMesh mesh) - => mesh.Indices.All(i => i >= 0 && i < mesh.Vertices.Count); - - public static bool AreAllVerticesUsed(this IMesh mesh) - { - var used = new bool[mesh.Vertices.Count]; - mesh.Indices.ForEach(idx => used[idx] = true); - return used.All(b => b); - } - - public static IMesh ResetPivot(this IMesh mesh) - => mesh.Translate(-mesh.BoundingBox().CenterBottom); - #region Face operations - /// - /// Given an array of face data, creates an array of indexed data to match vertices - /// - public static IArray FaceDataToVertexData(this IMesh mesh, IArray data) - { - if (data.Count != mesh.NumFaces) - throw new Exception("Cannot match input Face data to existing faces"); - - var vertexData = new T[mesh.NumVertices]; - for (var i = 0; i < mesh.Indices.Count; ++i) - vertexData[mesh.Indices[i]] = data[i / 3]; - return vertexData.ToIArray(); - } - - public static IArray AllFaceVertexIndices(this IMesh mesh) - => mesh.NumFaces.Select(mesh.FaceVertexIndices); public static Int3 FaceVertexIndices(this IMesh mesh, int faceIndex) => new Int3(mesh.Indices[faceIndex * 3], mesh.Indices[faceIndex * 3 + 1], mesh.Indices[faceIndex * 3 + 2]); @@ -365,9 +188,6 @@ public static Triangle Triangle(this IMesh mesh, int face) public static IArray Triangles(this IMesh mesh) => mesh.NumFaces.Select(mesh.Triangle); - public static IArray GetAllEdgesAsLines(this IMesh mesh) - => mesh.Triangles().SelectMany(tri => Tuple.Create(tri.AB, tri.BC, tri.CA)); - public static IArray ComputedNormals(this IMesh mesh) => mesh.Triangles().Select(t => t.Normal); @@ -378,76 +198,6 @@ public static bool Planar(this IMesh mesh, float tolerance = Math3d.Constants.To return mesh.ComputedNormals().All(n => n.AlmostEquals(normal, tolerance)); } - public static IArray MidPoints(this IMesh mesh) - => mesh.Triangles().Select(t => t.MidPoint); - - public static IArray FacesToCorners(this IMesh mesh) - => mesh.NumFaces.Select(i => i * 3); - - public static IArray FaceDataToCornerData(this IMesh mesh, IArray data) - => mesh.NumCorners.Select(i => data[i / 3]); - - public static IArray GetOrComputeFaceNormals(this IMesh mesh) - => mesh.GetAttributeFaceNormal()?.Data ?? mesh.ComputedNormals(); - - public static IArray GetOrComputeVertexNormals(this IMesh mesh) - => mesh.VertexNormals ?? mesh.ComputeTopology().GetOrComputeVertexNormals(); - - /// - /// Returns vertex normals if present, otherwise computes vertex normals naively by averaging them. - /// Given a pre-computed topology, will-leverage that. - /// A more sophisticated algorithm would compute the weighted normal - /// based on an angle. - /// - public static IArray GetOrComputeVertexNormals(this Topology topo) - { - var mesh = topo.Mesh; - var r = mesh.VertexNormals; - if (r != null) return r; - var faceNormals = mesh.GetOrComputeFaceNormals().ToArray(); - return mesh - .NumVertices - .Select(vi => - { - var tmp = topo - .FacesFromVertexIndex(vi) - .Select(fi => faceNormals[fi]) - .Average(); - if (tmp.IsNaN()) - return Vector3.Zero; - return tmp.SafeNormalize(); - }); - } - - public static IMesh CopyFaces(this IMesh mesh, Func predicate) - => (mesh as IGeometryAttributes).CopyFaces(predicate).ToIMesh(); - - public static IMesh CopyFaces(this IMesh mesh, IArray keep) - => mesh.CopyFaces(i => keep[i]); - - public static IMesh CopyFaces(this IMesh mesh, IArray keep) - => mesh.RemapFaces(keep).ToIMesh(); - - public static IMesh DeleteFaces(this IMesh mesh, Func predicate) - => mesh.CopyFaces(f => !predicate(f)); #endregion - - #region Corner extensions - /// - /// Given an array of data associated with corners, return an array of data associated with - /// vertices. If a vertex is not referenced, no data is returned. If a vertex is referenced - /// multiple times, the last reference is used. - /// TODO: supplement with a proper interpolation system. - /// - public static IArray CornerDataToVertexData(this IMesh mesh, IArray data) - { - var vertexData = new T[mesh.NumVertices]; - for (var i = 0; i < data.Count; ++i) - vertexData[mesh.Indices[i]] = data[i]; - return vertexData.ToIArray(); - } - #endregion - - } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs index 854e7292..8ea41c6b 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs @@ -11,65 +11,6 @@ namespace Vim.Format.Geometry { public static class PerimeterProjection { - public static Int2 ToXYApproximation(this Vector3 v, float tolerance) - => new Int2((int)(v.X / tolerance), (int)(v.Y / tolerance)); - - public static Vector2 FromXYApproximation(this Int2 v, float tolerance) - => new Vector2(v.X * tolerance, v.Y * tolerance); - - public static LineApprox ToXYApproximation(this Line line, float tolerance) - => Tuple.Create(line.A.ToXYApproximation(tolerance), line.B.ToXYApproximation(tolerance)); - - public static double Angle(this Int2 v) - => Math.Atan2(v.Y, v.X); - - public static double Angle(this Int2 a, Int2 b) - => (a - b).Angle(); - - public static IEnumerable PerimeterXY(this IMesh mesh, float tolerance = 0.001f) - { - var srcLines = mesh.GetAllEdgesAsLines(); - var approxLines = srcLines.Select(line => line.ToXYApproximation(tolerance)); - var lineSet = new HashSet(approxLines.ToArrayInParallel()); - Debug.WriteLine($"Went from {srcLines.Count} to {lineSet.Count}"); - var d = new DictionaryOfLists(); - foreach (var ab in lineSet) - { - d.Add(ab.Item1, ab); - d.Add(ab.Item2, ab); - } - var r = new List(); - if (d.Count == 0) - return r; - - var firstKey = d.Keys.Minimize(int.MaxValue, ab => ab.X.Min(ab.Y)); - var currentKey = firstKey; - var prevAngle = 0.0; - - // If we can't find the point in the dictionary we have completed - while (d.ContainsKey(currentKey)) - { - // Find the candidate points; - var candidates = d[currentKey].Select(line => line.Item1 == currentKey ? line.Item2 : line.Item1); - - // Find the best match by maximizing angle - var bestMatch = candidates.Maximize(0.0, c => currentKey.Angle(c) - prevAngle); - - // Update the return set - r.Add(bestMatch.FromXYApproximation(tolerance)); - - // Now save the angle for the next stage. - prevAngle = currentKey.Angle(bestMatch); - - // Remove this key from the dictionary - d.Remove(currentKey); - - // Now we are at a new point - currentKey = bestMatch; - } - - return r; - } public static List> GeneratePerimeter(this IMesh mesh, Vector3 planeNormal, float degenerateSegmentEpsilon = 10.0f, float edgeLoopThreshold = 1e-6f) { From 63dc31e406bbdb9d38a81e6b46bea55956c4e235 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 1 Apr 2024 15:36:06 -0400 Subject: [PATCH 006/104] Created IMeshCommon interface that respond to most of IMesh --- src/cs/g3d/Vim.G3dNext/G3dChunk.cs | 58 ---------- src/cs/g3d/Vim.G3dNext/G3dVim.cs | 41 ------- src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs | 21 +++- .../Geometry/PerimeterProjection.cs | 1 - .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 101 ++++++++++++++++++ .../SerializableDocumentTests.cs | 10 +- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 4 +- 7 files changed, 126 insertions(+), 110 deletions(-) create mode 100644 src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs diff --git a/src/cs/g3d/Vim.G3dNext/G3dChunk.cs b/src/cs/g3d/Vim.G3dNext/G3dChunk.cs index b445ba11..b89414dd 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dChunk.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dChunk.cs @@ -4,28 +4,6 @@ namespace Vim.G3dNext { - public class VimMesh : ITransformable3D - { - public int[] indices; - public Vector3[] vertices; - public int[] submeshes; - public int[] submeshMaterials; - - public VimMesh Transform(Matrix4x4 mat) - { - var mesh = new VimMesh(); - mesh.indices = indices.ToArray(); - mesh.vertices = new Vector3[vertices.Length]; - mesh.submeshes = submeshes.ToArray(); - mesh.submeshMaterials = submeshMaterials.ToArray(); - - for(var i =0; i < vertices.Length;i++ ) - { - mesh.vertices[i] = vertices[i].Transform(mat); - } - return mesh; - } - } public partial class G3dChunk @@ -35,42 +13,6 @@ void ISetup.Setup() // empty } - public VimMesh GetMesh(int index) - { - var mesh = new VimMesh(); - - var vStart = GetMeshVertexStart(index, MeshSection.All); - var vEnd = GetMeshVertexEnd(index, MeshSection.All); - mesh.vertices = new Vector3[vEnd - vStart]; - for (var i = 0; i < mesh.vertices.Length; i++) - { - var v = vStart + i; - mesh.vertices[i] = Positions[v]; - } - - var iStart = GetMeshIndexStart(index, MeshSection.All); - var iEnd = GetMeshIndexEnd(index, MeshSection.All); - mesh.indices = new int[iEnd - iStart]; - for (var i = 0; i < mesh.indices.Length; i++) - { - var j = iStart + i; - mesh.indices[i] = Indices[j] - vStart; - } - - var sStart = GetMeshSubmeshStart(index, MeshSection.All); - var sEnd = GetMeshSubmeshEnd(index, MeshSection.All); - mesh.submeshes = new int[sEnd - sStart]; - mesh.submeshMaterials = new int[sEnd - sStart]; - - for (var i =0; i < mesh.submeshMaterials.Length; i++) - { - var s = sStart + i; - mesh.submeshes[i] = SubmeshIndexOffsets[s] - vStart; - mesh.submeshMaterials[i] = SubmeshMaterials[s]; - } - - return mesh; - } public int GetSubmeshCount() => SubmeshIndexOffsets?.Length ?? 0; diff --git a/src/cs/g3d/Vim.G3dNext/G3dVim.cs b/src/cs/g3d/Vim.G3dNext/G3dVim.cs index 0801564d..c0ddeb67 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dVim.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dVim.cs @@ -13,47 +13,6 @@ public partial class G3dVim private List[] _meshInstances; - public VimMesh GetMesh(int index) - { - var mesh = new VimMesh(); - - var vStart = GetMeshVertexStart(index); - var vEnd = GetMeshVertexEnd(index); - mesh.vertices = new Vector3[vEnd - vStart]; - for (var i = 0; i < mesh.vertices.Length; i++) - { - var v = vStart + i; - mesh.vertices[i] = Positions[v]; - } - - var iStart = GetMeshIndexStart(index); - var iEnd = GetMeshIndexEnd(index); - mesh.indices = new int[iEnd - iStart]; - for (var i = 0; i < mesh.indices.Length; i++) - { - var j = iStart + i; - mesh.indices[i] = Indices[j] - vStart; - } - - var sStart = GetMeshSubmeshStart(index); - var sEnd = GetMeshSubmeshEnd(index); - mesh.submeshes = new int[sEnd - sStart]; - mesh.submeshMaterials = new int[sEnd - sStart]; - - for (var i = 0; i < mesh.submeshMaterials.Length; i++) - { - var s = sStart + i; - mesh.submeshes[i] = SubmeshIndexOffsets[s] - iStart; - mesh.submeshMaterials[i] = SubmeshMaterials[s]; - } - - return mesh; - } - - public IEnumerable GetAllMeshes() - { - return Enumerable.Range(0, GetMeshCount()).Select(i => GetMesh(i)); - } public IReadOnlyList GetMeshInstances(int mesh) { diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs index f330d0e4..42865e0c 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs @@ -13,12 +13,27 @@ public interface IMesh : { IArray Vertices { get; } IArray Indices { get; } - IArray VertexColors { get; } - IArray VertexNormals { get; } - IArray VertexUvs { get; } IArray SubmeshMaterials { get; } IArray SubmeshIndexOffsets { get; } IArray SubmeshIndexCount { get; } } + + public interface IMeshCommon : ITransformable3D + { + IArray Vertices { get; } + IArray Indices { get; } + + IArray SubmeshMaterials { get; } + IArray SubmeshIndexOffsets { get; } + IArray SubmeshIndexCount { get; } + int NumCornersPerFace { get; } + int NumVertices { get; } + int NumCorners { get; } + int NumFaces { get; } + int NumInstances { get; } + int NumMeshes { get; } + int NumShapeVertices { get; } + int NumShapes { get; } + } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs index 8ea41c6b..9d249161 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs @@ -5,7 +5,6 @@ using Vim.Util; using Vim.LinqArray; using Vim.Math3d; -using LineApprox = System.Tuple; namespace Vim.Format.Geometry { diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs new file mode 100644 index 00000000..0c172db6 --- /dev/null +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -0,0 +1,101 @@ +using System.Collections.Generic; +using System.Linq; +using Vim.G3d; +using Vim.G3dNext; +using Vim.LinqArray; +using Vim.Math3d; + +namespace Vim.Format.Geometry +{ + public class VimMesh : IMeshCommon + { + public IArray Vertices => vertices.ToIArray(); + + public IArray Indices => indices.ToIArray(); + + public IArray SubmeshMaterials =>submeshMaterials.ToIArray(); + public IArray SubmeshIndexOffsets => submeshes.ToIArray(); + public IArray SubmeshIndexCount => submeshSizes.ToIArray(); + + public int NumCornersPerFace => 3; + + public int NumVertices => vertices.Length; + + public int NumCorners => indices.Length; + + public int NumFaces => indices.Length / 3; + + public int NumInstances => 0; + + public int NumMeshes => 1; + + public int NumShapeVertices => 0; + + public int NumShapes => 0; + + public int[] indices; + public Vector3[] vertices; + public int[] submeshes; + public int[] submeshMaterials; + public int[] submeshSizes; + + public IMeshCommon Transform(Matrix4x4 mat) + { + var mesh = new VimMesh(); + mesh.indices = indices.ToArray(); + mesh.vertices = new Vector3[vertices.Length]; + mesh.submeshes = submeshes.ToArray(); + mesh.submeshMaterials = submeshMaterials.ToArray(); + + for (var i = 0; i < vertices.Length; i++) + { + mesh.vertices[i] = vertices[i].Transform(mat); + } + return mesh; + } + + public static VimMesh FromG3d(G3dVim g3d, int index) + { + var mesh = new VimMesh(); + + var vStart = g3d.GetMeshVertexStart(index); + var vEnd = g3d.GetMeshVertexEnd(index); + mesh.vertices = new Vector3[vEnd - vStart]; + for (var i = 0; i < mesh.vertices.Length; i++) + { + var v = vStart + i; + mesh.vertices[i] = g3d.Positions[v]; + } + + var iStart = g3d.GetMeshIndexStart(index); + var iEnd = g3d.GetMeshIndexEnd(index); + mesh.indices = new int[iEnd - iStart]; + for (var i = 0; i < mesh.indices.Length; i++) + { + var j = iStart + i; + mesh.indices[i] = g3d.Indices[j] - vStart; + } + + var sStart = g3d.GetMeshSubmeshStart(index); + var sEnd = g3d.GetMeshSubmeshEnd(index); + mesh.submeshes = new int[sEnd - sStart]; + mesh.submeshMaterials = new int[sEnd - sStart]; + mesh.submeshSizes = new int[sEnd - sStart]; + + for (var i = 0; i < mesh.submeshMaterials.Length; i++) + { + var s = sStart + i; + mesh.submeshes[i] = g3d.SubmeshIndexOffsets[s] - iStart; + mesh.submeshMaterials[i] = g3d.SubmeshMaterials[s]; + mesh.submeshSizes[i] = g3d.GetSubmeshIndexCount(s); + } + + return mesh; + } + + public static IEnumerable GetAllMeshes(G3dVim g3d) + { + return Enumerable.Range(0, g3d.GetMeshCount()).Select(i => FromG3d(g3d, i)); + } + } +} diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 2f2eeec8..9e9ea552 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -70,13 +70,13 @@ public static void GetMesh_Transform_IsSame() } } - private static void MeshesAreSame(IMesh mesh, VimMesh next) + private static void MeshesAreSame(IMesh mesh, IMeshCommon next) { - Assert.That(mesh.Indices.SequenceEquals(next.indices.ToIArray())); - Assert.That(mesh.Vertices.SequenceEquals(next.vertices.ToIArray())); - Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.submeshes.ToIArray())); - Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.submeshMaterials.ToIArray())); + Assert.That(mesh.Indices.SequenceEquals(next.Indices)); + Assert.That(mesh.Vertices.SequenceEquals(next.Vertices)); + Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.SubmeshIndexOffsets)); + Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.SubmeshMaterials)); } } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index ce3e7c51..aa63dcc2 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -60,7 +60,7 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, public int VimIndex { get; set; } public IArray Meshes { get; private set; } - public VimMesh[] MeshesNext { get; private set; } + public IMeshCommon[] MeshesNext { get; private set; } public IArray Nodes { get; private set; } public IArray VimNodes { get; private set; } public IArray VimShapes { get; private set; } @@ -205,7 +205,7 @@ private void CreateMeshes(bool inParallel) : inParallel ? tmp.EvaluateInParallel() : tmp.Evaluate(); - MeshesNext = _SerializableDocument.GeometryNext.GetAllMeshes().ToArray(); + MeshesNext = VimMesh.GetAllMeshes(_SerializableDocument.GeometryNext).ToArray(); } private void CreateShapes(bool inParallel) From de587da8ac70fe4606990723a020ce3b64b8b7cc Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 4 Apr 2024 15:18:58 -0400 Subject: [PATCH 007/104] removed unused method --- src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs | 3 --- src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs index f9a3610f..deacbe26 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs @@ -32,9 +32,6 @@ public static IMesh ToIMesh(this IGeometryAttributes g) => g is IMesh m ? m : g is QuadMesh q ? q.ToIMesh() : g.Attributes.ToIMesh(); #endregion - public static double Area(this IMesh mesh) - => mesh.Triangles().Sum(t => t.Area); - public static IArray GetFaceMaterials(this IMesh mesh) { // SubmeshIndexOffsets: [0, A, B] diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 62cdac6f..5eb5ea40 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -130,7 +130,6 @@ public static void BasicTests() Assert.AreEqual(3, XYTriangle.Vertices.Count); Assert.AreEqual(3, XYTriangle.Indices.Count); Assert.AreEqual(1, XYTriangle.Triangles().Count); - Assert.AreEqual(0.5, XYTriangle.Area(), SmallTolerance); Assert.IsTrue(XYTriangle.Planar()); Assert.AreEqual(new[] { 0, 1, 2 }, XYTriangle.Indices.ToArray()); @@ -163,7 +162,6 @@ public static void BasicTests() Assert.AreEqual(6, XYTriangleTwice.Vertices.Count); Assert.AreEqual(6, XYTriangleTwice.Indices.Count); Assert.AreEqual(2, XYTriangleTwice.Triangles().Count); - Assert.AreEqual(1.0, XYTriangleTwice.Area(), SmallTolerance); Assert.IsTrue(XYTriangleTwice.Planar()); Assert.AreEqual(new[] { 0, 1, 2, 3, 4, 5 }, XYTriangleTwice.Indices.ToArray()); } From 95d16490a3632e09f1f8f9c41cbda06af776dafc Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 4 Apr 2024 15:20:46 -0400 Subject: [PATCH 008/104] Added IMeshCommon as an intermediate step to removing g3d Implemented chunky IMesh methods in IMeshCommon --- src/cs/g3d/Vim.G3d/G3dMesh.cs | 102 ++++++-- src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs | 17 -- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 226 ++++++++++++++-- .../SerializableDocumentTests.cs | 244 +++++++++++++++++- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 8 +- 5 files changed, 531 insertions(+), 66 deletions(-) diff --git a/src/cs/g3d/Vim.G3d/G3dMesh.cs b/src/cs/g3d/Vim.G3d/G3dMesh.cs index 689122c5..837ac11f 100644 --- a/src/cs/g3d/Vim.G3d/G3dMesh.cs +++ b/src/cs/g3d/Vim.G3d/G3dMesh.cs @@ -5,11 +5,39 @@ namespace Vim.G3d { + + public interface IMeshCommon : ITransformable3D + { + IMeshCommon Clone(); + void SetVertices(Vector3[] vertices); + void SetIndices(int[] indices); + + // To be compatible with IMesh + IArray Vertices { get; } + IArray Indices { get; } + + IArray SubmeshMaterials { get; } + IArray SubmeshIndexOffsets { get; } + IArray SubmeshIndexCounts { get; } + + + + // To be compatible with IGeometryAttributes + int NumCornersPerFace { get; } + int NumVertices { get; } + int NumCorners { get; } + int NumFaces { get; } + int NumInstances { get; } + int NumMeshes { get; } + int NumShapeVertices { get; } + int NumShapes { get; } + } + /// /// A G3dMesh is a section of the G3D data that defines a mesh. /// This does not implement IGeometryAttributes for performance reasons. /// - public class G3dMesh + public class G3dMesh : IMeshCommon { public G3D G3D { get; } public int Index { get; } @@ -22,18 +50,28 @@ public class G3dMesh public int NumFaces => NumCorners / NumCornersPerFace; public int NumCornersPerFace => G3D.NumCornersPerFace; + + // Fillers to fullfil IGeometryAttributes for now + public int NumInstances => 0; + public int NumMeshes => 1; + public int NumShapeVertices => 0; + public int NumShapes => 0; + + // Data + public IArray Vertices { get; private set; } + public IArray Indices { get; private set; } + public IArray SubmeshMaterials { get; private set; } + public IArray SubmeshIndexOffsets { get; private set; } + public IArray SubmeshIndexCounts { get; private set; } + + public G3dMesh(G3D parent, int index) { (G3D, Index) = (parent, index); Vertices = G3D.Vertices?.SubArray(VertexOffset, NumVertices); var offset = VertexOffset; Indices = G3D.Indices?.SubArray(IndexOffset, NumCorners).Select(i => i - offset); - VertexUvs = G3D.VertexUvs?.SubArray(VertexOffset, NumVertices); - VertexNormals = G3D.VertexNormals?.SubArray(VertexOffset, NumVertices); - VertexColors = G3D.VertexColors?.SubArray(VertexOffset, NumVertices); - VertexTangents = G3D.VertexTangents?.SubArray(VertexOffset, NumVertices); - FaceNormals = G3D.FaceNormals?.SubArray(FaceOffset, NumFaces); - + // TODO: Remove need for this. var submeshArray = (G3D.SubmeshIndexOffsets as ArrayAdapter).Array; var submeshIndex = Array.BinarySearch(submeshArray, IndexOffset); @@ -45,28 +83,38 @@ public G3dMesh(G3D parent, int index) break; submeshCount++; } - SubmeshMaterials = G3D.SubmeshMaterials?.SubArray(submeshIndex, submeshCount); - SubmeshIndexOffsets = G3D.SubmeshIndexOffsets?.SubArray(submeshIndex, submeshCount).Select(i => i-IndexOffset); - MeshSubmeshOffset = new List() {0}.ToIArray(); + SubmeshMaterials = G3D.SubmeshMaterials?.SubArray(submeshIndex, submeshCount).Evaluate(); + SubmeshIndexOffsets = G3D.SubmeshIndexOffsets?.SubArray(submeshIndex, submeshCount).Select(i => i - IndexOffset).Evaluate(); + + var last = NumCorners - SubmeshIndexOffsets.Last(); + SubmeshIndexCounts = SubmeshIndexOffsets.AdjacentDifferences().Append(last).Evaluate(); } - // Vertex buffer. Usually present. - public IArray Vertices { get; } - - // Index buffer (one index per corner, and per half-edge) - public IArray Indices { get; } - - // Vertex associated data - public IArray VertexUvs { get; } - public IArray VertexNormals { get; } - public IArray VertexColors { get; } - public IArray VertexTangents { get; } - - // Face associated data. - public IArray FaceNormals { get; } + public IMeshCommon Transform(Matrix4x4 mat) + { + var mesh = Clone(); + mesh.Vertices = mesh.Vertices.Select(v => v.Transform(mat)).Evaluate(); + return mesh; + } - public IArray SubmeshMaterials { get; } - public IArray SubmeshIndexOffsets { get; } - public IArray MeshSubmeshOffset { get; } + public G3dMesh Clone() + { + var mesh = new G3dMesh(G3D, Index); + mesh.Vertices = mesh.Vertices; + mesh.Indices = mesh.Indices; + mesh.SubmeshMaterials = mesh.SubmeshMaterials; + mesh.SubmeshIndexOffsets = mesh.SubmeshIndexOffsets; + mesh.SubmeshIndexCounts = mesh.SubmeshIndexCounts; + return mesh; + } + IMeshCommon IMeshCommon.Clone() => Clone(); + public void SetVertices(Vector3[] vertices) + { + Vertices = vertices.ToIArray(); + } + public void SetIndices(int[] indices) + { + Indices = indices.ToIArray(); + } } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs index 42865e0c..4e98afd8 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs @@ -19,21 +19,4 @@ public interface IMesh : IArray SubmeshIndexCount { get; } } - public interface IMeshCommon : ITransformable3D - { - IArray Vertices { get; } - IArray Indices { get; } - - IArray SubmeshMaterials { get; } - IArray SubmeshIndexOffsets { get; } - IArray SubmeshIndexCount { get; } - int NumCornersPerFace { get; } - int NumVertices { get; } - int NumCorners { get; } - int NumFaces { get; } - int NumInstances { get; } - int NumMeshes { get; } - int NumShapeVertices { get; } - int NumShapes { get; } - } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 0c172db6..47fbdfb9 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -1,9 +1,12 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Vim.G3d; using Vim.G3dNext; using Vim.LinqArray; using Vim.Math3d; +using Vim.Util; +using static Vim.Format.DocumentBuilder; namespace Vim.Format.Geometry { @@ -13,9 +16,9 @@ public class VimMesh : IMeshCommon public IArray Indices => indices.ToIArray(); - public IArray SubmeshMaterials =>submeshMaterials.ToIArray(); - public IArray SubmeshIndexOffsets => submeshes.ToIArray(); - public IArray SubmeshIndexCount => submeshSizes.ToIArray(); + public IArray SubmeshMaterials => submeshMaterials.ToIArray(); + public IArray SubmeshIndexOffsets => submeshIndexOffsets.ToIArray(); + public IArray SubmeshIndexCounts => submeshIndexCounts.ToIArray(); public int NumCornersPerFace => 3; @@ -35,22 +38,44 @@ public class VimMesh : IMeshCommon public int[] indices; public Vector3[] vertices; - public int[] submeshes; + public int[] submeshIndexOffsets; public int[] submeshMaterials; - public int[] submeshSizes; + public int[] submeshIndexCounts; - public IMeshCommon Transform(Matrix4x4 mat) + public VimMesh() + { + + } + public VimMesh(int indexCount, int vertexCount, int submeshCount) + { + indices = new int[indexCount]; + vertices = new Vector3[vertexCount]; + submeshIndexOffsets = new int[submeshCount]; + submeshMaterials = new int[submeshCount]; + submeshIndexCounts = new int[submeshCount]; + } + + public VimMesh Clone() { var mesh = new VimMesh(); - mesh.indices = indices.ToArray(); - mesh.vertices = new Vector3[vertices.Length]; - mesh.submeshes = submeshes.ToArray(); - mesh.submeshMaterials = submeshMaterials.ToArray(); + mesh.indices = indices; + mesh.vertices = vertices; + mesh.submeshIndexOffsets = submeshIndexOffsets; + mesh.submeshMaterials = submeshMaterials; + mesh.submeshIndexCounts = submeshIndexCounts; + return mesh; + } + IMeshCommon IMeshCommon.Clone() => Clone(); + + public IMeshCommon Transform(Matrix4x4 mat) + { + var mesh = Clone(); for (var i = 0; i < vertices.Length; i++) { mesh.vertices[i] = vertices[i].Transform(mat); } + return mesh; } @@ -78,16 +103,16 @@ public static VimMesh FromG3d(G3dVim g3d, int index) var sStart = g3d.GetMeshSubmeshStart(index); var sEnd = g3d.GetMeshSubmeshEnd(index); - mesh.submeshes = new int[sEnd - sStart]; + mesh.submeshIndexOffsets = new int[sEnd - sStart]; mesh.submeshMaterials = new int[sEnd - sStart]; - mesh.submeshSizes = new int[sEnd - sStart]; + mesh.submeshIndexCounts = new int[sEnd - sStart]; for (var i = 0; i < mesh.submeshMaterials.Length; i++) { var s = sStart + i; - mesh.submeshes[i] = g3d.SubmeshIndexOffsets[s] - iStart; + mesh.submeshIndexOffsets[i] = g3d.SubmeshIndexOffsets[s] - iStart; mesh.submeshMaterials[i] = g3d.SubmeshMaterials[s]; - mesh.submeshSizes[i] = g3d.GetSubmeshIndexCount(s); + mesh.submeshIndexCounts[i] = g3d.GetSubmeshIndexCount(s); } return mesh; @@ -97,5 +122,176 @@ public static IEnumerable GetAllMeshes(G3dVim g3d) { return Enumerable.Range(0, g3d.GetMeshCount()).Select(i => FromG3d(g3d, i)); } + + public void SetVertices(Vector3[] vertices) + { + this.vertices = vertices; + } + public void SetIndices(int[] indices) + { + this.indices = indices; + } + } + + public static class MeshCommonExtensions + { + public static IMeshCommon ReverseWindingOrder(this IMeshCommon mesh) + { + var result = mesh.Clone(); + var count = mesh.Indices.Count; + var indices = new int[count]; + for (var i = 0; i < count; i += 3) + { + indices[i + 0] = mesh.Indices[i + 2]; + indices[i + 1] = mesh.Indices[i + 1]; + indices[i + 2] = mesh.Indices[i + 0]; + } + result.SetIndices(indices); + return result; + } + + + public static IArray GetFaceMaterials(this IMeshCommon mesh) + { + // SubmeshIndexOffsets: [0, A, B] + // SubmeshIndexCount: [X, Y, Z] + // SubmeshMaterials: [L, M, N] + // --- + // FaceMaterials: [...Repeat(L, X / 3), ...Repeat(M, Y / 3), ...Repeat(N, Z / 3)] <-- divide by 3 for the number of corners per Triangular face + var numCornersPerFace = mesh.NumCornersPerFace; + return mesh.SubmeshIndexCounts + .ToEnumerable() + .SelectMany((indexCount, i) => Enumerable.Repeat(mesh.SubmeshMaterials[i], indexCount / numCornersPerFace)) + .ToIArray(); + } + + public static IMeshCommon Merge2(this IMeshCommon mesh, params IMeshCommon[] others) + { + var meshes = Enumerable.Empty() + .Append(mesh) + .Append(others) + .ToArray(); + + return meshes.Merge(); + } + + public static IMeshCommon Merge(this IMeshCommon[] meshes) + { + void Merge(IArray from, int[] to, int offset, int increment) + { + for (var i = 0; i < from.Count; i++) + { + to[i + offset] = from[i] + increment; + } + } + + // Init arrays + var indexCount = meshes.Sum(m => m.Indices.Count); + var vertexCount = meshes.Sum(m => m.Vertices.Count); + var submeshCount = meshes.Sum(m => m.SubmeshIndexOffsets.Count); + var result = new VimMesh(indexCount, vertexCount, submeshCount); + + var indexOffset = 0; + var vertexOffset = 0; + var submeshOffset = 0; + // Copy and merge meshes + for (var m = 0; m < meshes.Length; m++) + { + var mesh = meshes[m]; + + Merge(mesh.Indices, result.indices, indexOffset, vertexOffset); + mesh.Vertices.CopyTo(result.vertices, vertexOffset); + mesh.SubmeshMaterials.CopyTo(result.submeshMaterials, submeshOffset); + mesh.SubmeshIndexCounts.CopyTo(result.submeshIndexCounts, submeshOffset); + Merge(mesh.SubmeshIndexOffsets, result.submeshIndexOffsets, submeshOffset, indexOffset); + + indexOffset += mesh.Indices.Count; + vertexOffset += mesh.Vertices.Count; + submeshOffset += mesh.SubmeshIndexOffsets.Count; + + } + return result; + } + + public static VimMesh[] SplitSubmeshes(this IMeshCommon mesh) + { + return null; + } + + public static (int, List)[] GroupSubmeshesByMaterials(this IMeshCommon mesh) + { + var submeshCount = mesh.SubmeshIndexOffsets.Count; + var map = new Dictionary>(); + for (var i = 0; i < submeshCount; i++) + { + var mat = mesh.SubmeshMaterials[i]; + if (map.ContainsKey(mat)) + { + map[mat].Add(i); + } + else + { + map.Add(mat, new List() { i }); + } + } + return map.Select(kvp => (kvp.Key, kvp.Value)).ToArray(); + } + + + public static (int mat, IMeshCommon mesh)[] SplitByMaterial(this IMeshCommon mesh) + { + var map = mesh.GroupSubmeshesByMaterials(); + + var result = new (int, IMeshCommon)[map.Length]; + if (map.Length == 1) + { + result[0] = (mesh.SubmeshMaterials[0], mesh); + return result; + } + + for (var i =0; i < map.Length; i++) + { + var (mat, subs) = map[i]; + var pick = mesh.PickSubmeshes(subs); + result[i] = (mat, pick); + } + return result; + } + + public static VimMesh PickSubmeshes(this IMeshCommon mesh, IList submeshes) + { + var map = mesh.GroupSubmeshesByMaterials(); + + // Allocate arrays of the final sizes + var indexCount = submeshes.Sum(s => mesh.SubmeshIndexCounts[s]); + var result = new VimMesh(indexCount, indexCount, submeshes.Count); + + var indexOffset = 0; + var index = 0; + for (var s = 0; s < submeshes.Count; s++) + { + var submesh = submeshes[s]; + + // copy indices at their new positions + var indexStart = mesh.SubmeshIndexOffsets[submesh]; + var indexEnd = indexStart + mesh.SubmeshIndexCounts[submesh]; + for (var i = indexStart; i < indexEnd; i++) + { + result.indices[index] = indexOffset + i - indexStart; + result.vertices[index] = mesh.Vertices[mesh.Indices[i]]; + index++; + } + + // submesh data is mostly the same + result.submeshIndexCounts[s] = mesh.SubmeshIndexCounts[submesh]; + result.submeshMaterials[s] = mesh.SubmeshMaterials[submesh]; + result.submeshIndexOffsets[s] = indexOffset; + + // Update offset for next submesh + indexOffset += indexEnd - indexStart; + } + + return result; + } } } diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 9e9ea552..2ff6240a 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -5,6 +5,13 @@ using Vim.Format.Geometry; using Vim.LinqArray; using Vim.Math3d; +using Vim.G3d; +using System.Linq; +using System.Diagnostics; +using System; +using Newtonsoft.Json.Linq; +using static System.Net.Mime.MediaTypeNames; +using static Vim.Format.DocumentBuilder; namespace Vim.Format.Tests; @@ -33,9 +40,9 @@ public static void MaterialColor_IsSame() { var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); var scene = VimScene.LoadVim(path); - for(var i=0; i < scene.GetMaterialCount(); i++) + for (var i = 0; i < scene.GetMaterialCount(); i++) { - Assert.AreEqual(scene.GetMaterialColor(i),scene.GetMaterialColorNext(i)); + Assert.AreEqual(scene.GetMaterialColor(i), scene.GetMaterialColorNext(i)); } } @@ -48,7 +55,9 @@ public static void GetMesh_IsSameMesh() { var mesh = scene.Meshes[i]; var next = scene.MeshesNext[i]; + var raw = scene.MeshesRaw[i]; MeshesAreSame(mesh, next); + MeshesAreSame(mesh, raw); } } @@ -66,17 +75,246 @@ public static void GetMesh_Transform_IsSame() ); var mesh = scene.Meshes[i].Transform(mat); var next = scene.MeshesNext[i].Transform(mat); + var raw = scene.MeshesRaw[i].Transform(mat); MeshesAreSame(mesh, next); + MeshesAreSame(mesh, raw); } } - private static void MeshesAreSame(IMesh mesh, IMeshCommon next) + [Test] + public static void ReverseWindingOrder_IsSame() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + for (var i = 0; i < scene.GetMeshCount(); i++) + { + + var mesh = scene.Meshes[i].ReverseWindingOrder().ToIMesh(); + var next = scene.MeshesNext[i].ReverseWindingOrder(); + var raw = scene.MeshesRaw[i].ReverseWindingOrder(); + MeshesAreSame(mesh, next); + MeshesAreSame(mesh, raw); + } + } + + [Test] + public static void FaceMaterial_IsSame() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + for (var i = 0; i < scene.GetMeshCount(); i++) + { + var mesh = scene.Meshes[i].GetFaceMaterials(); + var next = scene.MeshesNext[i].GetFaceMaterials(); + var raw = scene.MeshesRaw[i].GetFaceMaterials(); + Assert.That(mesh.SequenceEquals(next)); + Assert.That(next.SequenceEquals(raw)); + } + } + + [Test] + public static void Merge_ByPair_IsSame() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + for (var i = 1; i < scene.GetMeshCount(); i++) + { + var mesh = scene.Meshes[i].Merge(scene.Meshes[i - 1]); + var next = scene.MeshesNext[i].Merge2(scene.MeshesNext[i - 1]); + var raw = scene.MeshesRaw[i].Merge2(scene.MeshesRaw[i - 1]); + MeshesAreSame(mesh, next); + MeshesAreSame(mesh, raw); + } + } + + [Test] + public static void Merge_All_IsSame() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + + var mesh = scene.Meshes[0].Merge(scene.Meshes.Skip(1).ToArray()); + var next = scene.MeshesNext[0].Merge2(scene.MeshesNext.Skip(1).ToArray()); + var raw = scene.MeshesRaw[0].Merge2(scene.MeshesRaw.Skip(1).ToArray()); + MeshesAreSame(mesh, next); + MeshesAreSame(mesh, raw); + } + + [Test] + public static void SplitByMaterials_IsSame() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + for (var i = 0; i < scene.GetMeshCount(); i++) + { + var mesh = scene.Meshes[i].SplitByMaterial().ToArray(); + var next = scene.MeshesNext[i].SplitByMaterial(); + var raw = scene.MeshesRaw[i].SplitByMaterial(); + Assert.AreEqual(mesh.Length, next.Length); + Assert.AreEqual(mesh.Length, raw.Length); + + for (var j = 0; j < mesh.Length; j++) + { + MeshesAreSame(mesh[j].Mesh, next[j].mesh); + MeshesAreSame(mesh[j].Mesh, raw[j].mesh); + } + } + } + + + [Test] + public static void SplitByMaterials_Benchmark() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + var sw = new Stopwatch(); + + long time = 0; + long consumeTime =0; + long consumeAgain = 0; + for (var j=0; j < 100; j++) + { + for (var i = 0; i < scene.GetMeshCount(); i++) + { + sw.Restart(); + var mesh = scene.Meshes[i].SplitByMaterial().ToArray(); + sw.Stop(); + time += sw.ElapsedTicks; + + sw.Restart(); + foreach (var (mat, m) in mesh) + { + Consume(m); + } + sw.Stop(); + consumeTime += sw.ElapsedTicks; + + sw.Restart(); + foreach (var (mat, m) in mesh) + { + Consume(m); + } + sw.Stop(); + consumeAgain += sw.ElapsedTicks; + } + } + + Console.WriteLine("==Meshes=="); + Console.WriteLine("Split:" + (time * 1.0) / Stopwatch.Frequency); + Console.WriteLine("Consume:" + (consumeTime * 1.0) / Stopwatch.Frequency); + Console.WriteLine("Consume Again:" + (consumeAgain * 1.0) / Stopwatch.Frequency); + Console.WriteLine("Total:" + (time + consumeTime + consumeAgain * 1.0) / Stopwatch.Frequency); + + time = 0; + consumeTime = 0; + consumeAgain = 0; + for (var j = 0; j < 100; j++) + { + for (var i = 0; i < scene.GetMeshCount(); i++) + { + sw.Restart(); + var next = scene.MeshesNext[i].SplitByMaterial(); + sw.Stop(); + time += sw.ElapsedTicks; + + sw.Restart(); + foreach (var (mat, mesh) in next) + { + Consume(mesh); + } + sw.Stop(); + consumeTime += sw.ElapsedTicks; + + sw.Restart(); + foreach (var (mat, m) in next) + { + Consume(m); + } + sw.Stop(); + consumeAgain += sw.ElapsedTicks; + } + } + Console.WriteLine("==Next=="); + Console.WriteLine("Split:" + (time * 1.0) / Stopwatch.Frequency); + Console.WriteLine("Consume:" + (consumeTime * 1.0) / Stopwatch.Frequency); + Console.WriteLine("Consume Again:" + (consumeAgain * 1.0) / Stopwatch.Frequency); + Console.WriteLine("Total:" + (time + consumeTime + consumeAgain * 1.0) / Stopwatch.Frequency); + + time =0; + consumeTime = 0; + consumeAgain = 0; + for (var j = 0; j < 100; j++) + { + for (var i = 0; i < scene.GetMeshCount(); i++) + { + sw.Restart(); + var raw = scene.MeshesRaw[i].SplitByMaterial(); + sw.Stop(); + time += sw.ElapsedTicks; + + sw.Restart(); + foreach (var (mat, mesh) in raw) + { + Consume(mesh); + } + sw.Stop(); + consumeTime += sw.ElapsedTicks; + + sw.Restart(); + foreach (var (mat, m) in raw) + { + Consume(m); + } + sw.Stop(); + consumeAgain += sw.ElapsedTicks; + } + } + Console.WriteLine("==Raw=="); + Console.WriteLine("Split:" + (time *1.0) / Stopwatch.Frequency); + Console.WriteLine("Consume:" + (consumeTime * 1.0) / Stopwatch.Frequency); + Console.WriteLine("Consume Again:" + (consumeAgain * 1.0) / Stopwatch.Frequency); + Console.WriteLine("Total:" + (time + consumeTime + consumeAgain * 1.0) / Stopwatch.Frequency); + + } + + private static void Consume(IMesh mesh) { + mesh.Indices.Sum(); + mesh.Vertices.Sum(v => v.X); + mesh.SubmeshIndexOffsets.Sum(); + mesh.SubmeshIndexCount.Sum(); + mesh.SubmeshMaterials.Sum(); + } + private static void Consume(IMeshCommon mesh) + { + mesh.Indices.Sum(); + mesh.Vertices.Sum(v => v.X); + mesh.SubmeshIndexOffsets.Sum(); + mesh.SubmeshIndexCounts.Sum(); + mesh.SubmeshMaterials.Sum(); + } + + + private static void MeshesAreSame(IMesh mesh, IMeshCommon next) + { Assert.That(mesh.Indices.SequenceEquals(next.Indices)); Assert.That(mesh.Vertices.SequenceEquals(next.Vertices)); Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.SubmeshIndexOffsets)); Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.SubmeshMaterials)); + Assert.That(mesh.SubmeshIndexCount.SequenceEquals(next.SubmeshIndexCounts)); } + private static void MeshesAreSame(IMeshCommon mesh, IMeshCommon next) + { + Assert.That(mesh.Indices.SequenceEquals(next.Indices)); + Assert.That(mesh.Vertices.SequenceEquals(next.Vertices)); + Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.SubmeshIndexOffsets)); + Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.SubmeshMaterials)); + Assert.That(mesh.SubmeshIndexCounts.SequenceEquals(next.SubmeshIndexCounts)); + } + + + + } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index aa63dcc2..1e57e383 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -60,7 +60,8 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, public int VimIndex { get; set; } public IArray Meshes { get; private set; } - public IMeshCommon[] MeshesNext { get; private set; } + public VimMesh[] MeshesNext { get; private set; } + public G3dMesh[] MeshesRaw { get; private set; } public IArray Nodes { get; private set; } public IArray VimNodes { get; private set; } public IArray VimShapes { get; private set; } @@ -86,10 +87,8 @@ public static IMesh ToIMesh(G3dMesh g3d) => Primitives.TriMesh( g3d.Vertices.ToPositionAttribute(), g3d.Indices.ToIndexAttribute(), - g3d.VertexUvs?.ToVertexUvAttribute(), g3d.SubmeshIndexOffsets?.ToSubmeshIndexOffsetAttribute(), - g3d.SubmeshMaterials?.ToSubmeshMaterialAttribute(), - g3d.MeshSubmeshOffset?.ToMeshSubmeshOffsetAttribute() + g3d.SubmeshMaterials?.ToSubmeshMaterialAttribute() ); private VimScene(SerializableDocument doc) @@ -206,6 +205,7 @@ private void CreateMeshes(bool inParallel) ? tmp.EvaluateInParallel() : tmp.Evaluate(); MeshesNext = VimMesh.GetAllMeshes(_SerializableDocument.GeometryNext).ToArray(); + MeshesRaw = srcGeo?.Meshes.ToArray(); } private void CreateShapes(bool inParallel) From 60d87261ccc4155092d252936cfbc108b3d97e40 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 4 Apr 2024 15:36:03 -0400 Subject: [PATCH 009/104] replace VimScene.Meshes with the G3dMesh --- src/cs/vim/Vim.Format.Core/Geometry/IScene.cs | 3 +- .../SerializableDocumentTests.cs | 144 ++---------------- .../vim/Vim.Format/SceneBuilder/Validation.cs | 4 +- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 10 +- 4 files changed, 23 insertions(+), 138 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs index eb2e5821..d87f6a7a 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Vim.G3d; using Vim.LinqArray; using Vim.Math3d; @@ -10,7 +11,7 @@ namespace Vim.Format.Geometry public interface IScene { IArray Nodes { get; } - IArray Meshes { get; } + IArray Meshes { get; } } /// diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 2ff6240a..e40de3ca 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -53,9 +53,9 @@ public static void GetMesh_IsSameMesh() var scene = VimScene.LoadVim(path); for (var i = 0; i < scene.GetMeshCount(); i++) { - var mesh = scene.Meshes[i]; + var mesh = scene.MeshesOld[i]; var next = scene.MeshesNext[i]; - var raw = scene.MeshesRaw[i]; + var raw = scene.Meshes[i]; MeshesAreSame(mesh, next); MeshesAreSame(mesh, raw); } @@ -73,9 +73,9 @@ public static void GetMesh_Transform_IsSame() new Vector3(0, 0, 1), new Vector3(0, 1, 0) ); - var mesh = scene.Meshes[i].Transform(mat); + var mesh = scene.MeshesOld[i].Transform(mat); var next = scene.MeshesNext[i].Transform(mat); - var raw = scene.MeshesRaw[i].Transform(mat); + var raw = scene.Meshes[i].Transform(mat); MeshesAreSame(mesh, next); MeshesAreSame(mesh, raw); } @@ -89,9 +89,9 @@ public static void ReverseWindingOrder_IsSame() for (var i = 0; i < scene.GetMeshCount(); i++) { - var mesh = scene.Meshes[i].ReverseWindingOrder().ToIMesh(); + var mesh = scene.MeshesOld[i].ReverseWindingOrder().ToIMesh(); var next = scene.MeshesNext[i].ReverseWindingOrder(); - var raw = scene.MeshesRaw[i].ReverseWindingOrder(); + var raw = scene.Meshes[i].ReverseWindingOrder(); MeshesAreSame(mesh, next); MeshesAreSame(mesh, raw); } @@ -104,9 +104,9 @@ public static void FaceMaterial_IsSame() var scene = VimScene.LoadVim(path); for (var i = 0; i < scene.GetMeshCount(); i++) { - var mesh = scene.Meshes[i].GetFaceMaterials(); + var mesh = scene.MeshesOld[i].GetFaceMaterials(); var next = scene.MeshesNext[i].GetFaceMaterials(); - var raw = scene.MeshesRaw[i].GetFaceMaterials(); + var raw = scene.Meshes[i].GetFaceMaterials(); Assert.That(mesh.SequenceEquals(next)); Assert.That(next.SequenceEquals(raw)); } @@ -119,9 +119,9 @@ public static void Merge_ByPair_IsSame() var scene = VimScene.LoadVim(path); for (var i = 1; i < scene.GetMeshCount(); i++) { - var mesh = scene.Meshes[i].Merge(scene.Meshes[i - 1]); + var mesh = scene.MeshesOld[i].Merge(scene.MeshesOld[i - 1]); var next = scene.MeshesNext[i].Merge2(scene.MeshesNext[i - 1]); - var raw = scene.MeshesRaw[i].Merge2(scene.MeshesRaw[i - 1]); + var raw = scene.Meshes[i].Merge2(scene.Meshes[i - 1]); MeshesAreSame(mesh, next); MeshesAreSame(mesh, raw); } @@ -133,9 +133,9 @@ public static void Merge_All_IsSame() var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); var scene = VimScene.LoadVim(path); - var mesh = scene.Meshes[0].Merge(scene.Meshes.Skip(1).ToArray()); + var mesh = scene.MeshesOld[0].Merge(scene.MeshesOld.Skip(1).ToArray()); var next = scene.MeshesNext[0].Merge2(scene.MeshesNext.Skip(1).ToArray()); - var raw = scene.MeshesRaw[0].Merge2(scene.MeshesRaw.Skip(1).ToArray()); + var raw = scene.Meshes[0].Merge2(scene.Meshes.Skip(1).ToArray()); MeshesAreSame(mesh, next); MeshesAreSame(mesh, raw); } @@ -147,9 +147,9 @@ public static void SplitByMaterials_IsSame() var scene = VimScene.LoadVim(path); for (var i = 0; i < scene.GetMeshCount(); i++) { - var mesh = scene.Meshes[i].SplitByMaterial().ToArray(); + var mesh = scene.MeshesOld[i].SplitByMaterial().ToArray(); var next = scene.MeshesNext[i].SplitByMaterial(); - var raw = scene.MeshesRaw[i].SplitByMaterial(); + var raw = scene.Meshes[i].SplitByMaterial(); Assert.AreEqual(mesh.Length, next.Length); Assert.AreEqual(mesh.Length, raw.Length); @@ -161,122 +161,6 @@ public static void SplitByMaterials_IsSame() } } - - [Test] - public static void SplitByMaterials_Benchmark() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - var sw = new Stopwatch(); - - long time = 0; - long consumeTime =0; - long consumeAgain = 0; - for (var j=0; j < 100; j++) - { - for (var i = 0; i < scene.GetMeshCount(); i++) - { - sw.Restart(); - var mesh = scene.Meshes[i].SplitByMaterial().ToArray(); - sw.Stop(); - time += sw.ElapsedTicks; - - sw.Restart(); - foreach (var (mat, m) in mesh) - { - Consume(m); - } - sw.Stop(); - consumeTime += sw.ElapsedTicks; - - sw.Restart(); - foreach (var (mat, m) in mesh) - { - Consume(m); - } - sw.Stop(); - consumeAgain += sw.ElapsedTicks; - } - } - - Console.WriteLine("==Meshes=="); - Console.WriteLine("Split:" + (time * 1.0) / Stopwatch.Frequency); - Console.WriteLine("Consume:" + (consumeTime * 1.0) / Stopwatch.Frequency); - Console.WriteLine("Consume Again:" + (consumeAgain * 1.0) / Stopwatch.Frequency); - Console.WriteLine("Total:" + (time + consumeTime + consumeAgain * 1.0) / Stopwatch.Frequency); - - time = 0; - consumeTime = 0; - consumeAgain = 0; - for (var j = 0; j < 100; j++) - { - for (var i = 0; i < scene.GetMeshCount(); i++) - { - sw.Restart(); - var next = scene.MeshesNext[i].SplitByMaterial(); - sw.Stop(); - time += sw.ElapsedTicks; - - sw.Restart(); - foreach (var (mat, mesh) in next) - { - Consume(mesh); - } - sw.Stop(); - consumeTime += sw.ElapsedTicks; - - sw.Restart(); - foreach (var (mat, m) in next) - { - Consume(m); - } - sw.Stop(); - consumeAgain += sw.ElapsedTicks; - } - } - Console.WriteLine("==Next=="); - Console.WriteLine("Split:" + (time * 1.0) / Stopwatch.Frequency); - Console.WriteLine("Consume:" + (consumeTime * 1.0) / Stopwatch.Frequency); - Console.WriteLine("Consume Again:" + (consumeAgain * 1.0) / Stopwatch.Frequency); - Console.WriteLine("Total:" + (time + consumeTime + consumeAgain * 1.0) / Stopwatch.Frequency); - - time =0; - consumeTime = 0; - consumeAgain = 0; - for (var j = 0; j < 100; j++) - { - for (var i = 0; i < scene.GetMeshCount(); i++) - { - sw.Restart(); - var raw = scene.MeshesRaw[i].SplitByMaterial(); - sw.Stop(); - time += sw.ElapsedTicks; - - sw.Restart(); - foreach (var (mat, mesh) in raw) - { - Consume(mesh); - } - sw.Stop(); - consumeTime += sw.ElapsedTicks; - - sw.Restart(); - foreach (var (mat, m) in raw) - { - Consume(m); - } - sw.Stop(); - consumeAgain += sw.ElapsedTicks; - } - } - Console.WriteLine("==Raw=="); - Console.WriteLine("Split:" + (time *1.0) / Stopwatch.Frequency); - Console.WriteLine("Consume:" + (consumeTime * 1.0) / Stopwatch.Frequency); - Console.WriteLine("Consume Again:" + (consumeAgain * 1.0) / Stopwatch.Frequency); - Console.WriteLine("Total:" + (time + consumeTime + consumeAgain * 1.0) / Stopwatch.Frequency); - - } - private static void Consume(IMesh mesh) { mesh.Indices.Sum(); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index a1eaa15f..ddf0713f 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -35,7 +35,7 @@ public static void ValidateGeometry(this VimScene vim) // Validate the individual meshes. - foreach (var g in vim.Meshes.ToEnumerable()) + foreach (var g in vim.MeshesOld.ToEnumerable()) g.Validate(); } @@ -230,7 +230,7 @@ public static void ValidateEquality(this DocumentBuilder db, VimScene vim) if (!db.Geometry.GetMesh(i).IsEquivalentTo(vimGeoBuilders[i])) throw new VimValidationException($"{nameof(DocumentBuilder)} mesh {i} is not equivalent to {nameof(VimScene)} mesh {i}"); - if (!db.Geometry.GetMesh(i).ToIMesh().GeometryEquals(vim.Meshes[i])) + if (!db.Geometry.GetMesh(i).ToIMesh().GeometryEquals(vim.MeshesOld[i])) throw new VimValidationException($"{nameof(DocumentBuilder)} mesh {i} geometry is not equal to {nameof(VimScene)} mesh {i}"); } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 1e57e383..b5704969 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -59,9 +59,9 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, => LoadVim(stream, new LoadOptions { SkipGeometry = skipGeometry, SkipAssets = skipAssets}, progress, inParallel); public int VimIndex { get; set; } - public IArray Meshes { get; private set; } + public IArray MeshesOld { get; private set; } public VimMesh[] MeshesNext { get; private set; } - public G3dMesh[] MeshesRaw { get; private set; } + public IArray Meshes { get; private set; } public IArray Nodes { get; private set; } public IArray VimNodes { get; private set; } public IArray VimShapes { get; private set; } @@ -199,13 +199,13 @@ private void CreateMeshes(bool inParallel) var srcGeo = _SerializableDocument.Geometry; var tmp = srcGeo?.Meshes.Select(ToIMesh); - Meshes = (tmp == null) + MeshesOld = (tmp == null) ? LinqArray.LinqArray.Empty() : inParallel ? tmp.EvaluateInParallel() : tmp.Evaluate(); MeshesNext = VimMesh.GetAllMeshes(_SerializableDocument.GeometryNext).ToArray(); - MeshesRaw = srcGeo?.Meshes.ToArray(); + Meshes = srcGeo?.Meshes.Select(m => m as IMeshCommon); } private void CreateShapes(bool inParallel) @@ -256,7 +256,7 @@ public void Save(string filePath) public string FileName => _SerializableDocument.FileName; - public void TransformSceneInPlace(Func meshTransform = null, Func nodeTransform = null) + public void TransformSceneInPlace(Func meshTransform = null, Func nodeTransform = null) { if (meshTransform != null) Meshes = Meshes.Select(meshTransform).EvaluateInParallel(); From 5cb0f05547a3084a4952c35138a1882ba0352928 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 4 Apr 2024 16:12:35 -0400 Subject: [PATCH 010/104] missing IMeshCommon stuff --- src/cs/vim/Vim.Format.Core/Geometry/IScene.cs | 6 +++--- .../vim/Vim.Format.Core/Geometry/SceneExtensions.cs | 11 ++++++----- src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs index d87f6a7a..4f7208cd 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs @@ -23,7 +23,7 @@ public interface ISceneNode IScene Scene { get; } Matrix4x4 Transform { get; } int MeshIndex { get; } - IMesh GetMesh(); + IMeshCommon GetMesh(); ISceneNode Parent { get; } // TODO: DEPRECATE: this needs to be removed, currently only used in Vim.Max.Bridge. @@ -52,7 +52,7 @@ public class NullNode : ISceneNode public int MeshIndex => 0; public ISceneNode Parent => null; public IArray Children => null; - public IMesh GetMesh() => null; + public IMeshCommon GetMesh() => null; } public class IdNode : ISceneNode @@ -63,6 +63,6 @@ public class IdNode : ISceneNode public int MeshIndex => 0; public ISceneNode Parent => null; public IArray Children => null; - public IMesh GetMesh() => null; + public IMeshCommon GetMesh() => null; } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs b/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs index 555baefa..d59455aa 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs @@ -3,22 +3,23 @@ using Vim.Util; using Vim.LinqArray; using Vim.Math3d; +using Vim.G3d; namespace Vim.Format.Geometry { public static class SceneExtensions { - public static IMesh TransformedMesh(this ISceneNode node) + public static IMeshCommon TransformedMesh(this ISceneNode node) => node.GetMesh()?.Transform(node.Transform); - public static IEnumerable TransformedMeshes(this IScene scene) + public static IEnumerable TransformedMeshes(this IScene scene) => scene.Nodes.Where(n => n.GetMesh() != null).Select(TransformedMesh); - public static IMesh MergedGeometry(this IScene scene) + public static IMeshCommon MergedGeometry(this IScene scene) => scene.Nodes.ToEnumerable().MergedGeometry(); - public static IMesh MergedGeometry(this IEnumerable nodes) - => nodes.Where(n => n.GetMesh() != null).Select(TransformedMesh).Merge(); + public static IMeshCommon MergedGeometry(this IEnumerable nodes) + => nodes.Where(n => n.GetMesh() != null).Select(TransformedMesh).ToArray().Merge(); public static IEnumerable AllVertices(this IScene scene) => scene.TransformedMeshes().SelectMany(g => g.Vertices.ToEnumerable()); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 9bb7a754..9dcf686a 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -36,7 +36,7 @@ public bool HideByDefault public int VimIndex { get; } = -1; public int NodeIndex { get; } = -1; - public IMesh GetMesh() + public IMeshCommon GetMesh() => _Scene.Meshes.ElementAtOrDefault(MeshIndex); public int MeshIndex { get; } From 7bf7b9a78f8ff3774bc45a325ffb5b8da5614898 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 4 Apr 2024 16:52:37 -0400 Subject: [PATCH 011/104] implemented hash for meshcommon --- .../Geometry/MeshOptimization.cs | 53 +++++++++++++++++++ .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 29 ++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs index 4db387a7..a7a4691e 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs @@ -58,9 +58,62 @@ public override int GetHashCode() => Hash.Combine(NumFaces, NumVertices, TopologyHash, BoxMin.GetHashCode(), BoxExtents.GetHashCode()); } + /// + /// This class is used to compare quickly two meshes within a lookup table (e.g. Dictionary, HashTable). + /// it looks at the positions of each corner, and the number of faces, and assures that the object ID + /// and material IDs are the same. + /// When using a class within a dictionary or hash table, the equals operator is called frequently. + /// By converting an IMesh to a MeshHash we minimize the amount of comparisons done. It becomes + /// possible, but highly unlikely that two different meshes would have the same hash. + /// + public class MeshCommonHash + { + public IMeshCommon Mesh; + public float Tolerance; + public int NumFaces; + public int NumVertices; + public int TopologyHash; + public Int3 BoxExtents; + public Int3 BoxMin; + + public int Round(float f) + => (int)(f / Tolerance); + + public Int3 Round(Vector3 v) + => new Int3(Round(v.X), Round(v.Y), Round(v.Z)); + + public MeshCommonHash(IMeshCommon mesh, float tolerance) + { + Mesh = mesh; + Tolerance = tolerance; + NumFaces = mesh.NumFaces; + NumVertices = mesh.NumVertices; + TopologyHash = Hash.Combine(mesh.Indices.ToArray()); + var box = mesh.BoundingBox(); + BoxMin = Round(box.Min); + BoxExtents = Round(box.Extent); + } + + public override bool Equals(object obj) + => obj is MeshHash other && Equals(other); + + public bool Equals(MeshCommonHash other) + => NumFaces == other.NumFaces + && NumVertices == other.NumVertices + && BoxMin.Equals(other.BoxMin) + && BoxExtents.Equals(other.BoxExtents) + && Mesh.GeometryEquals(other.Mesh); + + public override int GetHashCode() + => Hash.Combine(NumFaces, NumVertices, TopologyHash, BoxMin.GetHashCode(), BoxExtents.GetHashCode()); + } + public static class Optimization { public static Dictionary> GroupMeshesByHash(this IEnumerable meshes, float tolerance) => meshes.AsParallel().GroupBy(m => new MeshHash(m, tolerance)).ToDictionary(grp => grp.Key, grp => grp.ToList()); + + public static Dictionary> GroupMeshesByHash(this IEnumerable meshes, float tolerance) + => meshes.AsParallel().GroupBy(m => new MeshCommonHash(m, tolerance)).ToDictionary(grp => grp.Key, grp => grp.ToList()); } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 47fbdfb9..b38fb6a9 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -6,6 +6,7 @@ using Vim.LinqArray; using Vim.Math3d; using Vim.Util; +using static System.Net.Mime.MediaTypeNames; using static Vim.Format.DocumentBuilder; namespace Vim.Format.Geometry @@ -237,6 +238,34 @@ public static (int, List)[] GroupSubmeshesByMaterials(this IMeshCommon mesh return map.Select(kvp => (kvp.Key, kvp.Value)).ToArray(); } + public static AABox BoundingBox(this IMeshCommon mesh) + => AABox.Create(mesh.Vertices.ToEnumerable()); + + public static bool GeometryEquals(this IMeshCommon mesh, IMeshCommon other, float tolerance = Math3d.Constants.Tolerance) + { + if (!mesh.Indices.SequenceEquals(other.Indices)) + return false; + + if (!mesh.SubmeshIndexOffsets.SequenceEquals(other.SubmeshIndexOffsets)) + return false; + + if (!mesh.SubmeshMaterials.SequenceEquals(other.SubmeshMaterials)) + return false; + + if (!mesh.SubmeshIndexCounts.SequenceEquals(other.SubmeshIndexCounts)) + return false; + + if (mesh.Vertices.Count != other.Vertices.Count) + return false; + + for(var i = 0; i < mesh.Vertices.Count; i++) + { + if(!mesh.Vertices[i].AlmostEquals(other.Vertices[i], tolerance)) + return false; + } + + return true; + } public static (int mat, IMeshCommon mesh)[] SplitByMaterial(this IMeshCommon mesh) { From 311ba673920a2bf6cf2ab22214d99c143379e3db Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 4 Apr 2024 17:09:49 -0400 Subject: [PATCH 012/104] added meshcommon toDocumentbuildersubdividedMesh --- src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index 77c0d209..9ffdd818 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -30,8 +30,12 @@ public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this IMesh m) m.SubmeshIndexOffsets.ToList(), m.SubmeshMaterials.ToList()); - public static void AddMesh(this DocumentBuilder db, IMesh m) - => db.AddMesh(m.ToDocumentBuilderSubdividedMesh()); + public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this IMeshCommon m) + => new SubdividedMesh( + m.Indices.ToList(), + m.Vertices.ToList(), + m.SubmeshIndexOffsets.ToList(), + m.SubmeshMaterials.ToList()); public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, EntityTable table, List nodeIndexRemapping = null) { From 510e4dc6130e253b60d06d252826cf54720a9c9a Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 4 Apr 2024 22:32:35 -0400 Subject: [PATCH 013/104] added meshcommon version of method --- src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index b38fb6a9..bb4107dc 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -241,6 +241,10 @@ public static (int, List)[] GroupSubmeshesByMaterials(this IMeshCommon mesh public static AABox BoundingBox(this IMeshCommon mesh) => AABox.Create(mesh.Vertices.ToEnumerable()); + public static Int3 FaceVertexIndices(this IMeshCommon mesh, int faceIndex) + => new Int3(mesh.Indices[faceIndex * 3], mesh.Indices[faceIndex * 3 + 1], mesh.Indices[faceIndex * 3 + 2]); + + public static bool GeometryEquals(this IMeshCommon mesh, IMeshCommon other, float tolerance = Math3d.Constants.Tolerance) { if (!mesh.Indices.SequenceEquals(other.Indices)) From 47c180c883bf6374d3794a55706de2ed3d585db6 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 10:05:33 -0400 Subject: [PATCH 014/104] added center for meshcommon --- src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index bb4107dc..e5f2f8c4 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -238,6 +238,9 @@ public static (int, List)[] GroupSubmeshesByMaterials(this IMeshCommon mesh return map.Select(kvp => (kvp.Key, kvp.Value)).ToArray(); } + public static Vector3 Center(this IMesh mesh) + => mesh.BoundingBox().Center; + public static AABox BoundingBox(this IMeshCommon mesh) => AABox.Create(mesh.Vertices.ToEnumerable()); From 2362b4299c717a1340eeb68b3c5e704bf10d8ac5 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 10:09:44 -0400 Subject: [PATCH 015/104] wrong type --- src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index e5f2f8c4..424f765f 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -238,7 +238,7 @@ public static (int, List)[] GroupSubmeshesByMaterials(this IMeshCommon mesh return map.Select(kvp => (kvp.Key, kvp.Value)).ToArray(); } - public static Vector3 Center(this IMesh mesh) + public static Vector3 Center(this IMeshCommon mesh) => mesh.BoundingBox().Center; public static AABox BoundingBox(this IMeshCommon mesh) From a521e21041051cfeb4e489f37b118e1d5cdeed2a Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 13:21:09 -0400 Subject: [PATCH 016/104] Added quad method to vimmesh --- .../Vim.G3d/GeometryAttributesExtensions.cs | 1 + .../Vim.Format.Core/Geometry/Primitives.cs | 4 +- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 45 +++++++++++++++++++ .../SerializableDocumentTests.cs | 20 +++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs b/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs index ba7c1cfa..5d7e07d5 100644 --- a/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs +++ b/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs @@ -311,6 +311,7 @@ public static IEnumerable SetFaceSizeAttribute(this IEnumerab /// public static IGeometryAttributes RemapFacesAndCorners(this IGeometryAttributes g, IArray faceRemap, IArray cornerRemap, int numCornersPerFace = -1) => g.VertexAttributes() + .Concat(g.SubMeshAttributes()) .Concat(g.NoneAttributes()) .Concat(g.FaceAttributes().Select(attr => attr.Remap(faceRemap))) .Concat(g.EdgeAttributes().Select(attr => attr.Remap(cornerRemap))) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index 4a0e5a63..570d9dda 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -49,7 +49,9 @@ public static IMesh QuadMesh(this IArray vertices, IArray indices vertices.ToPositionAttribute(), indices?.ToIndexAttribute(), uvs?.ToVertexUvAttribute(), - materials?.ToFaceMaterialAttribute() + materials?.ToFaceMaterialAttribute(), + (new int[] {0}).ToSubmeshIndexOffsetAttribute(), + (new int[] { -1 }).ToSubmeshMaterialAttribute() ); public static IMesh QuadMesh(Vector3 a, Vector3 b, Vector3 c, Vector3 d) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 424f765f..96c0681d 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -47,6 +47,15 @@ public VimMesh() { } + + public VimMesh(int[] indices, Vector3[] vertices, int[] submeshIndexOffsets = null, int[] submeshMaterials = null, int[] submeshIndexCounts = null) + { + this.indices = indices; + this.vertices = vertices; + this.submeshIndexOffsets = submeshIndexOffsets ?? new int[1] { 0 }; + this.submeshMaterials = submeshMaterials ?? new int[1] { -1}; + this.submeshIndexCounts = submeshIndexCounts ?? new int[1] { indices.Length }; + } public VimMesh(int indexCount, int vertexCount, int submeshCount) { indices = new int[indexCount]; @@ -119,6 +128,27 @@ public static VimMesh FromG3d(G3dVim g3d, int index) return mesh; } + public static VimMesh FromQuad(int[] indices, Vector3[] vertices) + { + if(indices.Length % 4 != 0) + { + throw new ArgumentException("Indices count should be a multiple of 4."); + } + var faceCount = indices.Length / 4; + var triIndices = new int[faceCount * 6]; + var cur = 0; + for (var i = 0; i < faceCount; ++i) + { + triIndices[cur++] = indices[i * 4 + 0]; + triIndices[cur++] = indices[i * 4 + 1]; + triIndices[cur++] = indices[i * 4 + 2]; + triIndices[cur++] = indices[i * 4 + 0]; + triIndices[cur++] = indices[i * 4 + 2]; + triIndices[cur++] = indices[i * 4 + 3]; + } + return new VimMesh(triIndices, vertices); + } + public static IEnumerable GetAllMeshes(G3dVim g3d) { return Enumerable.Range(0, g3d.GetMeshCount()).Select(i => FromG3d(g3d, i)); @@ -247,6 +277,21 @@ public static AABox BoundingBox(this IMeshCommon mesh) public static Int3 FaceVertexIndices(this IMeshCommon mesh, int faceIndex) => new Int3(mesh.Indices[faceIndex * 3], mesh.Indices[faceIndex * 3 + 1], mesh.Indices[faceIndex * 3 + 2]); + /// + /// Low-level remap function. Maps faces and corners at the same time. + /// In some cases, this is important (e.g. triangulating quads). + /// Note: meshes are lost. + /// + public static IGeometryAttributes RemapFacesAndCorners(this IGeometryAttributes g, IArray faceRemap, IArray cornerRemap, int numCornersPerFace = -1) + => g.VertexAttributes() + .Concat(g.NoneAttributes()) + .Concat(g.FaceAttributes().Select(attr => attr.Remap(faceRemap))) + .Concat(g.EdgeAttributes().Select(attr => attr.Remap(cornerRemap))) + .Concat(g.CornerAttributes().Select(attr => attr.Remap(cornerRemap))) + .Concat(g.WholeGeometryAttributes()) + .SetFaceSizeAttribute(numCornersPerFace) + .ToGeometryAttributes(); + public static bool GeometryEquals(this IMeshCommon mesh, IMeshCommon other, float tolerance = Math3d.Constants.Tolerance) { diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index e40de3ca..e44959b1 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -127,6 +127,26 @@ public static void Merge_ByPair_IsSame() } } + [Test] + public static void QuadToTri_IsSame() + { + var indices = new int[] { 0, 1, 4, 3, 1, 2, 5, 4 }; + var vertices = new Vector3[] + { + new Vector3(1,0,0), + new Vector3(1,1,0), + new Vector3(1,2,0), + new Vector3(0,0,0), + new Vector3(0,1,0), + new Vector3(0,2,0), + }; + + var mesh = Primitives.QuadMesh(vertices.ToIArray(), indices.ToIArray()); + var next = VimMesh.FromQuad(indices, vertices); + + MeshesAreSame(mesh, next); + } + [Test] public static void Merge_All_IsSame() { From e8138d0b0c74cf241cbb0f2b0ec7403c985d7523 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 14:23:05 -0400 Subject: [PATCH 017/104] Added FromG3d to turn whole g3d into a vimMesh --- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 52 +++++++++++++++---- .../SerializableDocumentTests.cs | 11 ++++ 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 96c0681d..aaac9cf3 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -6,8 +6,6 @@ using Vim.LinqArray; using Vim.Math3d; using Vim.Util; -using static System.Net.Mime.MediaTypeNames; -using static Vim.Format.DocumentBuilder; namespace Vim.Format.Geometry { @@ -48,14 +46,34 @@ public VimMesh() } - public VimMesh(int[] indices, Vector3[] vertices, int[] submeshIndexOffsets = null, int[] submeshMaterials = null, int[] submeshIndexCounts = null) + public VimMesh( + int[] indices, + Vector3[] vertices, + int[] submeshIndexOffsets = null, + int[] submeshMaterials = null, + int[] submeshIndexCounts = null + ) { this.indices = indices; this.vertices = vertices; + this.submeshIndexOffsets = submeshIndexOffsets ?? new int[1] { 0 }; - this.submeshMaterials = submeshMaterials ?? new int[1] { -1}; - this.submeshIndexCounts = submeshIndexCounts ?? new int[1] { indices.Length }; + this.submeshMaterials = submeshMaterials ?? new int[1] { -1 }; + this.submeshIndexCounts = submeshIndexCounts ?? ComputeCounts(this.submeshIndexOffsets, this.indices.Length); + } + + private static int[] ComputeCounts(int[] offsets, int max) + { + var result = new int[offsets.Length]; + for (var i = 0; i < result.Length - 1; i++) + { + result[i] = offsets[i + 1] - offsets[i]; + } + var last = result.Length - 1; + result[last] = max - offsets[last]; + return result; } + public VimMesh(int indexCount, int vertexCount, int submeshCount) { indices = new int[indexCount]; @@ -67,12 +85,12 @@ public VimMesh(int indexCount, int vertexCount, int submeshCount) public VimMesh Clone() { - var mesh = new VimMesh(); - mesh.indices = indices; - mesh.vertices = vertices; - mesh.submeshIndexOffsets = submeshIndexOffsets; - mesh.submeshMaterials = submeshMaterials; - mesh.submeshIndexCounts = submeshIndexCounts; + var mesh = new VimMesh( + indices, + vertices, + submeshIndexOffsets, + submeshMaterials + ); return mesh; } IMeshCommon IMeshCommon.Clone() => Clone(); @@ -128,6 +146,18 @@ public static VimMesh FromG3d(G3dVim g3d, int index) return mesh; } + public static VimMesh FromG3d(G3dVim g3d) + { + var mesh = new VimMesh( + g3d.Indices, + g3d.Positions, + g3d.SubmeshIndexOffsets, + g3d.SubmeshMaterials + ); + + return mesh; + } + public static VimMesh FromQuad(int[] indices, Vector3[] vertices) { if(indices.Length % 4 != 0) diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index e44959b1..23c3d8b0 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -147,6 +147,17 @@ public static void QuadToTri_IsSame() MeshesAreSame(mesh, next); } + [Test] + public static void FromG3d_Equals_ToIMesh() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + var mesh = scene.Document.Geometry.ToIMesh(); + var next = VimMesh.FromG3d(scene.Document.GeometryNext); + MeshesAreSame(mesh, next); + + } + [Test] public static void Merge_All_IsSame() { From 745da752fd0c00299da73fc27f503617a81b3aea Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 14:31:48 -0400 Subject: [PATCH 018/104] removed unused code --- .../vim/Vim.Format.Core/Geometry/Topology.cs | 236 ------------------ 1 file changed, 236 deletions(-) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/Topology.cs diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Topology.cs b/src/cs/vim/Vim.Format.Core/Geometry/Topology.cs deleted file mode 100644 index f7ef75c5..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/Topology.cs +++ /dev/null @@ -1,236 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Vim.G3d; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - /// - /// The base class of topology face, topology edge, topology vertex, and topology element - /// - public class TopoElement - { - public TopoElement(Topology topology, int index) - => (Topology, Index) = (topology, index); - public Topology Topology { get; } - public int Index { get; } - } - - /// - /// A topological face. - /// - public class TopoFace : TopoElement - { - public TopoFace(Topology topology, int index) - : base(topology, index) - => Debug.Assert(index >= 0 && index < topology.Mesh.NumFaces); - } - - /// - /// A directed edge around a polygon (aka a half-edge). There is exactly one half-edge per "corner" in a mesh. - /// A non-border edge in a manifold mesh has exactly two half-edges, and a border edge has one edge. - /// - public class TopoEdge : TopoElement - { - public TopoEdge(Topology topology, int index) - : base(topology, index) - => Debug.Assert(index >= 0 && index < topology.Mesh.NumCorners); - } - - /// - /// A vertex in the mesh. - /// - public class TopoVertex : TopoElement - { - public TopoVertex(Topology topology, int index) - : base(topology, index) - => Debug.Assert(index >= 0 && index < topology.Mesh.NumVertices); - } - - /// - /// Also called a "face-corner". Associated with exactly one face, and one vertex. - /// A vertex may be associated with multiple corners - /// - public class TopoCorner : TopoElement - { - public TopoCorner(Topology topology, int index) - : base(topology, index) - => Debug.Assert(index >= 0 && index < topology.Mesh.NumCorners); - } - - /// - /// This class is used to make efficient topological queries for an IGeometry. - /// Construction is a O(N) operation, so it is not created automatically. - /// - public class Topology - { - public TopoFace Face(int f) - => new TopoFace(this, f); - - public TopoEdge Edge(int e) - => new TopoEdge(this, e); - - public Topology(IMesh m) - { - Mesh = m; - Corners = Mesh.Indices.Indices(); - Faces = Mesh.NumFaces.Range(); - Vertices = Mesh.Vertices.Indices(); - - // Compute the mapping from vertex indices to faces that reference them - VerticesToFaces = new List[m.Vertices.Count]; - for (var c = 0; c < m.Indices.Count; ++c) - { - var v = m.Indices[c]; - var f = m.CornerToFace(c); - - Debug.Assert(f.Within(0, m.NumFaces)); - Debug.Assert(v.Within(0, m.NumVertices)); - Debug.Assert(c.Within(0, m.NumCorners)); - - if (VerticesToFaces[v] == null) - VerticesToFaces[v] = new List { f }; - else - VerticesToFaces[v].Add(f); - } - - // NOTE: the same edge can occur in more than two faces, only in non-manifold meshes - - // Compute the face on the other side of an edge - EdgeToOtherFace = (-1).Repeat(Mesh.NumCorners).ToArray(); - for (var c = 0; c < Mesh.NumCorners; ++c) - { - var c2 = NextCorner(c); - var f0 = CornerToFace(c); - foreach (var f1 in FacesFromCorner(c).ToEnumerable()) - { - if (f1 != f0) - { - foreach (var f2 in FacesFromCorner(c2).ToEnumerable()) - { - if (f2 == f1) - { - if (EdgeToOtherFace[c] != -1) - NonManifold = true; - EdgeToOtherFace[c] = f2; - } - } - } - } - } - - // TODO: there is some serious validation I coudl be doing doing here. - } - - public IMesh Mesh { get; } - - public List[] VerticesToFaces { get; } - public int[] EdgeToOtherFace { get; } // Assumes manifold meshes - public bool NonManifold { get; } - public IArray Corners { get; } - public IArray Vertices { get; } - public IArray Edges => Corners; - public IArray Faces { get; } - - public int CornerToFace(int i) - => Mesh.CornerToFace(i); - - public IArray FacesFromVertexIndex(int v) - => VerticesToFaces[v]?.ToIArray() ?? 0.Repeat(0); - - public IArray FacesFromCorner(int c) - => FacesFromVertexIndex(Mesh.Indices[c]); - - public int VertexIndexFromCorner(int c) - => Mesh.Indices[c]; - - /// - /// Differs from neighbour faces in that the faces have to share an edge, not just a vertex. - /// An alternative construction would have been to getNeighbourFaces and filter out those that don't share - /// - public IEnumerable BorderingFacesFromFace(int f) - => EdgesFromFace(f).Select(BorderFace).Where(bf => bf >= 0); - - public int BorderFace(int e) - => EdgeToOtherFace[e]; - - public bool IsBorderEdge(int e) - => EdgeToOtherFace[e] < 0; - - public bool IsBorderFace(int f) - => EdgesFromFace(f).Any(IsBorderEdge); - - public IArray CornersFromFace(int f) - => Mesh.NumCornersPerFace.Range().Add(FirstCornerInFace(f)); - - public IArray EdgesFromFace(int f) - => CornersFromFace(f); - - public int FirstCornerInFace(int f) - => f * Mesh.NumCornersPerFace; - - public bool FaceHasCorner(int f, int c) - => CornersFromFace(f).Contains(c); - - public int NextCorner(int c) - { - var f = CornerToFace(c); - var begin = FirstCornerInFace(f); - var end = begin + Mesh.NumCornersPerFace; - Debug.Assert(c >= begin); - Debug.Assert(c < end); - var c2 = c + 1; - if (c2 < end) - return c2; - Debug.Assert(c2 == end); - return begin; - } - - public IArray CornersFromEdge(int e) - => LinqArray.LinqArray.Create(e, NextCorner(e)); - - public IArray VertexIndicesFromEdge(int e) - => CornersFromEdge(e).Select(VertexIndexFromCorner); - - public IArray VertexIndicesFromFace(int f) - => Mesh.Indices.SelectByIndex(LinqArray.LinqArray.Create(f * 3, f * 3 + 1, f * 3 + 2)); - - public IEnumerable NeighbourVertices(int v) - => FacesFromVertexIndex(v).SelectMany(f => VertexIndicesFromFace(f)).Where(v2 => v2 != v).Distinct(); - - public IEnumerable BorderEdges - => Edges.Where(IsBorderEdge); - - public IEnumerable BorderFaces - => Faces.Where(IsBorderFace); - - public int EdgeFirstCorner(int e) - => e; - - public int EdgeNextCorner(int e) - => NextCorner(e); - - public int EdgeFirstVertex(int e) - => VertexIndexFromCorner(EdgeFirstCorner(e)); - - public int EdgeNextVertex(int e) - => VertexIndexFromCorner(EdgeFirstCorner(e)); - - public IArray EdgeVertices(int e) - => LinqArray.LinqArray.Create(EdgeFirstVertex(e), EdgeNextVertex(e)); - - public Vector3 PointFromVertex(int v) - => Mesh.Vertices[v]; - - public IArray EdgePoints(int e) - => EdgeVertices(e).Select(PointFromVertex); - } - - public static class TopologyExtensions - { - public static IMesh Mesh(this TopoElement self) - => self.Topology.Mesh; - } -} From 66df4c71ecda18f065345eba263611835d1e144f Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 14:35:32 -0400 Subject: [PATCH 019/104] removed redundant check --- src/cs/vim/Vim.Format/SceneBuilder/Validation.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index ddf0713f..282ad544 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -229,9 +229,6 @@ public static void ValidateEquality(this DocumentBuilder db, VimScene vim) { if (!db.Geometry.GetMesh(i).IsEquivalentTo(vimGeoBuilders[i])) throw new VimValidationException($"{nameof(DocumentBuilder)} mesh {i} is not equivalent to {nameof(VimScene)} mesh {i}"); - - if (!db.Geometry.GetMesh(i).ToIMesh().GeometryEquals(vim.MeshesOld[i])) - throw new VimValidationException($"{nameof(DocumentBuilder)} mesh {i} geometry is not equal to {nameof(VimScene)} mesh {i}"); } // Test the assets. From c464aae6e66ff580b1c90b5ec2a09714a73e4d42 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 14:37:02 -0400 Subject: [PATCH 020/104] remove unused code --- .../vim/Vim.Format.Core/DocumentBuilderExtensions.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index 9ffdd818..abdfeb48 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -10,11 +10,6 @@ namespace Vim.Format { public static class DocumentBuilderExtensions { - public static IMesh ToIMesh(this SubdividedMesh gb) - => gb.Vertices.ToIArray().TriMesh( - gb.Indices.ToIArray(), - submeshMaterials: gb.SubmeshMaterials.ToIArray()); - public static Material ToDocumentBuilderMaterial(this G3dMaterial g3dMaterial) => new Material { @@ -23,13 +18,6 @@ public static Material ToDocumentBuilderMaterial(this G3dMaterial g3dMaterial) Smoothness = g3dMaterial.Smoothness, }; - public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this IMesh m) - => new SubdividedMesh( - m.Indices.ToList(), - m.Vertices.ToList(), - m.SubmeshIndexOffsets.ToList(), - m.SubmeshMaterials.ToList()); - public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this IMeshCommon m) => new SubdividedMesh( m.Indices.ToList(), From 5db4640a8161bd04f2809ff15dcbde84f60c3265 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 14:40:06 -0400 Subject: [PATCH 021/104] imesh -> imeshcommon --- .../vim/Vim.Format.Core/Geometry/CatmullClark.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs b/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs index 4ffbd54a..2f0da338 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Vim.G3d; using Vim.LinqArray; using Vim.Math3d; @@ -39,7 +40,7 @@ public class GeometryEdge public static class CatmullClarkSmoothing { - public static Dictionary CreateEdgeMap(this IMesh geometry) + public static Dictionary CreateEdgeMap(this IMeshCommon geometry) { var globalEdgeIndex = 0; var edgeMap = new Dictionary(); @@ -68,7 +69,7 @@ public static Dictionary CreateEdgeMap(this IMesh return edgeMap; } - public static IMesh CatmullClark(this IMesh geometry, float smoothing = 0.0f) + public static IMeshCommon CatmullClark(this IMeshCommon geometry, float smoothing = 0.0f) { var edgeMap = geometry.CreateEdgeMap(); @@ -129,7 +130,7 @@ public static IMesh CatmullClark(this IMesh geometry, float smoothing = 0.0f) return GenerateMesh(geometry, newVertices, newIndices, edgeMap, facePointStartIndex, edgePointStartIndex, numQuads); } - public static void CalculateFaceCentroidPoints(IMesh geometry, Vector3[] outFacePoints, float[] outVertexNumFaces, Vector3[] outVertexFPoints) + public static void CalculateFaceCentroidPoints(IMeshCommon geometry, Vector3[] outFacePoints, float[] outVertexNumFaces, Vector3[] outVertexFPoints) { var currentVertexIndex = 0; for (var faceIndex = 0; faceIndex < geometry.NumFaces; faceIndex++) @@ -159,7 +160,7 @@ public static void CalculateFaceCentroidPoints(IMesh geometry, Vector3[] outFace } } - public static void CalculateEdgePoints(IMesh geometry, Dictionary edgeMap, Vector3[] facePoints, float[] outVertexNumEdges, Vector3[] outVertexRPoints, float smoothing) + public static void CalculateEdgePoints(IMeshCommon geometry, Dictionary edgeMap, Vector3[] facePoints, float[] outVertexNumEdges, Vector3[] outVertexRPoints, float smoothing) { foreach (var edge in edgeMap) { @@ -186,7 +187,7 @@ public static void CalculateEdgePoints(IMesh geometry, Dictionary edgeMap, int facePointStartIndex, int edgePointStartIndex, int numQuads) + public static IMeshCommon GenerateMesh(IMeshCommon geometry, Vector3[] newVertices, int[] newIndices, Dictionary edgeMap, int facePointStartIndex, int edgePointStartIndex, int numQuads) { var currentNewVertexIndex = 0; var currentOldVertexIndex = 0; @@ -224,7 +225,7 @@ public static IMesh GenerateMesh(IMesh geometry, Vector3[] newVertices, int[] ne currentOldVertexIndex += faceSize; } - return Primitives.QuadMesh(newVertices.ToIArray(), newIndices.ToIArray()); + return new VimMesh(newIndices, newVertices); } } } From a6c08b3e312c9868e40f22c049889faee6fb5f6e Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 14:44:53 -0400 Subject: [PATCH 022/104] removed old imesh version of meshhash --- .../Geometry/MeshOptimization.cs | 53 ------------------- 1 file changed, 53 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs index a7a4691e..5e858acb 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs @@ -7,56 +7,6 @@ using Vim.Math3d; namespace Vim.Format.Geometry -{ - /// - /// This class is used to compare quickly two meshes within a lookup table (e.g. Dictionary, HashTable). - /// it looks at the positions of each corner, and the number of faces, and assures that the object ID - /// and material IDs are the same. - /// When using a class within a dictionary or hash table, the equals operator is called frequently. - /// By converting an IMesh to a MeshHash we minimize the amount of comparisons done. It becomes - /// possible, but highly unlikely that two different meshes would have the same hash. - /// - public class MeshHash - { - public IMesh Mesh; - public float Tolerance; - public int NumFaces; - public int NumVertices; - public int TopologyHash; - public Int3 BoxExtents; - public Int3 BoxMin; - - public int Round(float f) - => (int)(f / Tolerance); - - public Int3 Round(Vector3 v) - => new Int3(Round(v.X), Round(v.Y), Round(v.Z)); - - public MeshHash(IMesh mesh, float tolerance) - { - Mesh = mesh; - Tolerance = tolerance; - NumFaces = mesh.NumFaces; - NumVertices = mesh.NumVertices; - TopologyHash = Hash.Combine(mesh.Indices.ToArray()); - var box = mesh.BoundingBox(); - BoxMin = Round(box.Min); - BoxExtents = Round(box.Extent); - } - - public override bool Equals(object obj) - => obj is MeshHash other && Equals(other); - - public bool Equals(MeshHash other) - => NumFaces == other.NumFaces - && NumVertices == other.NumVertices - && BoxMin.Equals(other.BoxMin) - && BoxExtents.Equals(other.BoxExtents) - && Mesh.GeometryEquals(other.Mesh); - - public override int GetHashCode() - => Hash.Combine(NumFaces, NumVertices, TopologyHash, BoxMin.GetHashCode(), BoxExtents.GetHashCode()); - } /// /// This class is used to compare quickly two meshes within a lookup table (e.g. Dictionary, HashTable). @@ -110,9 +60,6 @@ public override int GetHashCode() public static class Optimization { - public static Dictionary> GroupMeshesByHash(this IEnumerable meshes, float tolerance) - => meshes.AsParallel().GroupBy(m => new MeshHash(m, tolerance)).ToDictionary(grp => grp.Key, grp => grp.ToList()); - public static Dictionary> GroupMeshesByHash(this IEnumerable meshes, float tolerance) => meshes.AsParallel().GroupBy(m => new MeshCommonHash(m, tolerance)).ToDictionary(grp => grp.Key, grp => grp.ToList()); } From 07019fccf7056226093307e31a23565cd36e0161 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 14:45:03 -0400 Subject: [PATCH 023/104] imesh -> imeshcommon --- .../vim/Vim.Format.Core/Geometry/PerimeterProjection.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs index 9d249161..d232a460 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs @@ -2,16 +2,16 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Vim.Util; using Vim.LinqArray; using Vim.Math3d; +using Vim.G3d; namespace Vim.Format.Geometry { public static class PerimeterProjection { - public static List> GeneratePerimeter(this IMesh mesh, Vector3 planeNormal, float degenerateSegmentEpsilon = 10.0f, float edgeLoopThreshold = 1e-6f) + public static List> GeneratePerimeter(this IMeshCommon mesh, Vector3 planeNormal, float degenerateSegmentEpsilon = 10.0f, float edgeLoopThreshold = 1e-6f) { var q = GetClusterRotation(planeNormal.Normalize(), Vector3.UnitZ); @@ -307,7 +307,7 @@ public int GetHashCode(Tuple obj) => obj.Item1.GetHashCode() ^ obj.Item2.GetHashCode(); } - public static Dictionary, int> BuildEdgeDictionary(this IMesh mesh) + public static Dictionary, int> BuildEdgeDictionary(this IMeshCommon mesh) { var edges = new Dictionary, int>(new EdgeEqualityComparer()); @@ -327,7 +327,7 @@ public static Dictionary, int> BuildEdgeDictionary(this IMesh me return edges; } - public static List> BuildBoundarySegments(this IMesh mesh, Dictionary, int> edgeDictionary, Func transform) + public static List> BuildBoundarySegments(this IMeshCommon mesh, Dictionary, int> edgeDictionary, Func transform) { var segments = new List>(); From 17f488e8bd8c0fa89262bc91de06716d49caf041 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 14:46:53 -0400 Subject: [PATCH 024/104] minor mistakes --- src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs index 5e858acb..fac1c90b 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs @@ -1,12 +1,11 @@ using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using System.Runtime.CompilerServices; using Vim.G3d; using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Geometry +{ /// /// This class is used to compare quickly two meshes within a lookup table (e.g. Dictionary, HashTable). @@ -45,7 +44,7 @@ public MeshCommonHash(IMeshCommon mesh, float tolerance) } public override bool Equals(object obj) - => obj is MeshHash other && Equals(other); + => obj is MeshCommonHash other && Equals(other); public bool Equals(MeshCommonHash other) => NumFaces == other.NumFaces From 8e0419fbbd80ec6767944f604d7900a79e068820 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 14:47:51 -0400 Subject: [PATCH 025/104] removed unused file --- .../Vim.Format.Core/Geometry/MeshDebugView.cs | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/MeshDebugView.cs diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshDebugView.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshDebugView.cs deleted file mode 100644 index 54a216e3..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshDebugView.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - public class MeshDebugView - { - IMesh Interface { get; } - - public int NumCorners => Interface.NumCorners; - public int NumFaces => Interface.NumFaces; - public int NumMeshes => Interface.NumMeshes; - public int NumInstances => Interface.NumInstances; - - public Vector3[] Vertices => Interface.Vertices.ToArray(); - public int[] Indices => Interface.Indices.ToArray(); - - public MeshDebugView(IMesh g) - => Interface = g; - } -} From 54abe40d184e3fa603b4ce7d50b9bc17fc4f4776 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 16:57:02 -0400 Subject: [PATCH 026/104] replacing more Imesh --- src/cs/g3d/Vim.G3dNext/G3dVim.cs | 5 +- .../Vim.Format.Core/Geometry/Primitives.cs | 201 +++++++----------- .../Vim.Format.Core/Geometry/Validation.cs | 4 +- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 40 ++++ .../Geometry/GeometryTests.cs | 163 +++++--------- .../SerializableDocumentTests.cs | 20 -- .../vim/Vim.Format/SceneBuilder/Validation.cs | 7 +- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 14 -- 8 files changed, 174 insertions(+), 280 deletions(-) diff --git a/src/cs/g3d/Vim.G3dNext/G3dVim.cs b/src/cs/g3d/Vim.G3dNext/G3dVim.cs index c0ddeb67..dd2af2c6 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dVim.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dVim.cs @@ -1,19 +1,16 @@ using System; using System.Collections.Generic; -using System.Linq; using Vim.BFastLib; -using Vim.Math3d; namespace Vim.G3dNext { public partial class G3dVim { + // Computed field public int[] MeshVertexOffsets; private List[] _meshInstances; - - public IReadOnlyList GetMeshInstances(int mesh) { return _meshInstances[mesh]; diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index 570d9dda..a0c737d8 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -10,129 +10,77 @@ namespace Vim.Format.Geometry // TODO: plane, cylinder, cone, ruled face, public static class Primitives { - public static IMesh TriMesh(IEnumerable attributes) - => attributes.Where(x => x != null).ToIMesh(); - - public static IMesh TriMesh(params GeometryAttribute[] attributes) - => TriMesh(attributes.AsEnumerable()); - - public static IMesh TriMesh( - this IArray vertices, - IArray indices = null, - IArray uvs = null, - IArray colors = null, - IArray materials = null, - IArray submeshMaterials = null) - => TriMesh( - vertices?.ToPositionAttribute(), - indices?.ToIndexAttribute(), - uvs?.ToVertexUvAttribute(), - materials?.ToFaceMaterialAttribute(), - colors?.ToVertexColorAttribute(), - submeshMaterials?.ToSubmeshMaterialAttribute() - ); - - public static IMesh TriMesh(this IArray vertices, IArray indices = null, params GeometryAttribute[] attributes) - => new GeometryAttribute[] { - vertices?.ToPositionAttribute(), - indices?.ToIndexAttribute(), - }.Concat(attributes).ToIMesh(); - - public static IMesh QuadMesh(params GeometryAttribute[] attributes) - => QuadMesh(attributes.AsEnumerable()); - - public static IMesh QuadMesh(this IEnumerable attributes) - => new QuadMesh(attributes.Where(x => x != null)).ToTriMesh(); - - public static IMesh QuadMesh(this IArray vertices, IArray indices = null, IArray uvs = null, IArray materials = null, IArray objectIds = null) - => QuadMesh( - vertices.ToPositionAttribute(), - indices?.ToIndexAttribute(), - uvs?.ToVertexUvAttribute(), - materials?.ToFaceMaterialAttribute(), - (new int[] {0}).ToSubmeshIndexOffsetAttribute(), - (new int[] { -1 }).ToSubmeshMaterialAttribute() - ); - - public static IMesh QuadMesh(Vector3 a, Vector3 b, Vector3 c, Vector3 d) - => QuadMesh(new[] { a, b, c, d }.ToIArray()); - - public static IMesh Cube + public static IMeshCommon CreateCube() { - get - { - var vertices = new[] { - // front - new Vector3(-0.5f, -0.5f, 0.5f), - new Vector3(0.5f, -0.5f, 0.5f), - new Vector3(0.5f, 0.5f, 0.5f), - new Vector3(-0.5f, 0.5f, 0.5f), - // back - new Vector3(-0.5f, -0.5f, -0.5f), - new Vector3(0.5f, -0.5f, -0.5f), - new Vector3(0.5f, 0.5f, -0.5f), - new Vector3(-0.5f, 0.5f, -0.5f) - }.ToIArray(); - - var indices = new[] { - // front - 0, 1, 2, - 2, 3, 0, - // right - 1, 5, 6, - 6, 2, 1, - // back - 7, 6, 5, - 5, 4, 7, - // left - 4, 0, 3, - 3, 7, 4, - // bottom - 4, 5, 1, - 1, 0, 4, - // top - 3, 2, 6, - 6, 7, 3 - }.ToIArray(); - - return vertices.TriMesh(indices); - } + var vertices = new[] { + // front + new Vector3(-0.5f, -0.5f, 0.5f), + new Vector3(0.5f, -0.5f, 0.5f), + new Vector3(0.5f, 0.5f, 0.5f), + new Vector3(-0.5f, 0.5f, 0.5f), + // back + new Vector3(-0.5f, -0.5f, -0.5f), + new Vector3(0.5f, -0.5f, -0.5f), + new Vector3(0.5f, 0.5f, -0.5f), + new Vector3(-0.5f, 0.5f, -0.5f) + }; + + var indices = new[] { + // front + 0, 1, 2, + 2, 3, 0, + // right + 1, 5, 6, + 6, 2, 1, + // back + 7, 6, 5, + 5, 4, 7, + // left + 4, 0, 3, + 3, 7, 4, + // bottom + 4, 5, 1, + 1, 0, 4, + // top + 3, 2, 6, + 6, 7, 3 + }; + + return new VimMesh(indices, vertices); } - public static IMesh CubeFaceted + public static IMeshCommon CreateCube(AABox box) { - get - { - var cube = Cube; - return cube.Indices.Select(i => cube.Vertices[i]).TriMesh(cube.Indices.Count.Range()); - } + return CreateCube().Scale(box.Extent).Translate(box.Center); } - public static IMesh ToIMesh(this AABox box) - => Cube.Scale(box.Extent).Translate(box.Center); - - public static float Sqrt2 = 2.0f.Sqrt(); - - public static readonly IMesh Tetrahedron - = TriMesh(LinqArray.LinqArray.Create( + private static float Sqrt2 = 2.0f.Sqrt(); + public static IMeshCommon CreateTetrahedron() + { + var vertices = new[] + { new Vector3(1f, 0.0f, -1f / Sqrt2), new Vector3(-1f, 0.0f, -1f / Sqrt2), new Vector3(0.0f, 1f, 1f / Sqrt2), - new Vector3(0.0f, -1f, 1f / Sqrt2)), - LinqArray.LinqArray.Create(0, 1, 2, 1, 0, 3, 0, 2, 3, 1, 3, 2)); - - public static readonly IMesh Square - = LinqArray.LinqArray.Create( - new Vector2(-0.5f, -0.5f), - new Vector2(-0.5f, 0.5f), - new Vector2(0.5f, 0.5f), - new Vector2(0.5f, -0.5f)).Select(x => x.ToVector3()).QuadMesh(); - - public static readonly IMesh Octahedron - = Square.Vertices.Append(Vector3.UnitZ, -Vector3.UnitZ).Normalize().TriMesh( - LinqArray.LinqArray.Create( - 0, 1, 4, 1, 2, 4, 2, 3, 4, - 3, 2, 5, 2, 1, 5, 1, 0, 5)); + new Vector3(0.0f, -1f, 1f / Sqrt2) + }; + var indices = new[] { 0, 1, 2, 1, 0, 3, 0, 2, 3, 1, 3, 2 }; + return new VimMesh(indices, vertices); + } + public static IMeshCommon CreateSquare() + { + var vertices = new[] + { + new Vector3(-0.5f, -0.5f, 0f), + new Vector3(-0.5f, 0.5f, 0f), + new Vector3(0.5f, 0.5f, 0f), + new Vector3(0.5f, -0.5f, 0f) + }; + + var indices = new[] { 0, 1, 2, 2, 3, 0 }; + + return new VimMesh(indices, vertices); + } // see: https://github.com/mrdoob/three.js/blob/9ef27d1af7809fa4d9943f8d4c4644e365ab6d2d/src/geometries/TorusBufferGeometry.js#L52 public static Vector3 TorusFunction(Vector2 uv, float radius, float tube) @@ -144,7 +92,7 @@ public static Vector3 TorusFunction(Vector2 uv, float radius, float tube) tube * uv.Y.Sin()); } - public static IMesh Torus(float radius, float tubeRadius, int uSegs, int vSegs) + public static IMeshCommon Torus(float radius, float tubeRadius, int uSegs, int vSegs) => QuadMesh(uv => TorusFunction(uv, radius, tubeRadius), uSegs, vSegs); // see: https://github.com/mrdoob/three.js/blob/9ef27d1af7809fa4d9943f8d4c4644e365ab6d2d/src/geometries/SphereBufferGeometry.js#L76 @@ -154,17 +102,9 @@ public static Vector3 SphereFunction(Vector2 uv, float radius) (float)(radius * Math.Cos(uv.Y * Math3d.Constants.Pi)), (float)(radius * Math.Sin(uv.X * Math3d.Constants.TwoPi) * Math.Sin(uv.Y * Math3d.Constants.Pi))); - public static IMesh Sphere(float radius, int uSegs, int vSegs) + public static IMeshCommon Sphere(float radius, int uSegs, int vSegs) => QuadMesh(uv => SphereFunction(uv, radius), uSegs, vSegs); - /// - /// Creates a TriMesh from four points. - /// - public static IMesh TriMeshFromQuad(Vector3 a, Vector3 b, Vector3 c, Vector3 d) - => TriMesh(new[] { a, b, c, c, d, a }.ToIArray()); - - // Icosahedron, Dodecahedron, - /// /// Returns a collection of circular points. /// @@ -316,13 +256,13 @@ public static IArray TriMeshCylinderCapIndices(int numEdgeVertices) /// /// Creates a quad mesh given a mapping from 2 space to 3 space /// - public static IMesh QuadMesh(this Func f, int segs) + public static IMeshCommon QuadMesh(this Func f, int segs) => QuadMesh(f, segs, segs); /// /// Creates a quad mesh given a mapping from 2 space to 3 space /// - public static IMesh QuadMesh(this Func f, int usegs, int vsegs, bool wrapUSegs = false, bool wrapVSegs = false) + public static IMeshCommon QuadMesh(this Func f, int usegs, int vsegs, bool wrapUSegs = false, bool wrapVSegs = false) { var verts = new List(); var maxUSegs = wrapUSegs ? usegs : usegs + 1; @@ -337,14 +277,15 @@ public static IMesh QuadMesh(this Func f, int usegs, int vsegs verts.Add(f(new Vector2(u, v))); } } + var indices = ComputeQuadMeshStripIndices(usegs, vsegs, wrapUSegs, wrapVSegs); - return QuadMesh(verts.ToIArray(), ComputeQuadMeshStripIndices(usegs, vsegs, wrapUSegs, wrapVSegs)); + return VimMesh.FromQuad(indices.ToArray(), verts.ToArray()); } /// /// Creates a revolved face ... note that the last points are on top of the original /// - public static IMesh RevolveAroundAxis(this IArray points, Vector3 axis, int segments = 4) + public static IMeshCommon RevolveAroundAxis(this IArray points, Vector3 axis, int segments = 4) { var verts = new List(); for (var i = 0; i < segments; ++i) @@ -352,8 +293,8 @@ public static IMesh RevolveAroundAxis(this IArray points, Vector3 axis, var angle = Math3d.Constants.TwoPi / segments; points.Rotate(axis, angle).AddTo(verts); } - - return QuadMesh(verts.ToIArray(), ComputeQuadMeshStripIndices(segments - 1, points.Count - 1)); + var indices = ComputeQuadMeshStripIndices(segments - 1, points.Count - 1); + return new VimMesh(indices.ToArray(), verts.ToArray()); } } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index abf23eef..ef12f052 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -89,7 +89,7 @@ public static void Validate(this Document doc) // TODO: ValidateShapes() to validate VIM files which contain optional 2d data (shapes/overlays). - public static void ValidateIndices(this IMesh mesh) + public static void ValidateIndices(this IMeshCommon mesh) { foreach (var index in mesh.Indices.ToEnumerable()) { @@ -98,7 +98,7 @@ public static void ValidateIndices(this IMesh mesh) } } - public static void Validate(this IMesh mesh) + public static void Validate(this IMeshCommon mesh) { mesh.ValidateIndices(); } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index aaac9cf3..25b5414b 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -62,6 +62,27 @@ public VimMesh( this.submeshIndexCounts = submeshIndexCounts ?? ComputeCounts(this.submeshIndexOffsets, this.indices.Length); } + public G3dVim ToG3d() + { + return new G3dVim( + indices: indices, + positions: vertices, + instanceMeshes: new[] {0}, + instanceTransforms: new[] { Matrix4x4.Identity }, + instanceParents: null, + instanceFlags: null, + meshSubmeshOffsets: new[] { 0 }, + submeshIndexOffsets: new[] { 0 }, + submeshMaterials: new[] { -1 }, + materialColors: null, + materialGlossiness: null, + materialSmoothness: null, + shapeVertices: null, + shapeColors: null, + shapeVertexOffsets: null, + shapeWidths: null); + } + private static int[] ComputeCounts(int[] offsets, int max) { var result = new int[offsets.Length]; @@ -298,6 +319,25 @@ public static (int, List)[] GroupSubmeshesByMaterials(this IMeshCommon mesh return map.Select(kvp => (kvp.Key, kvp.Value)).ToArray(); } + public static Triangle VertexIndicesToTriangle(this IMeshCommon mesh, Int3 indices) + => new Triangle(mesh.Vertices[indices.X], mesh.Vertices[indices.Y], mesh.Vertices[indices.Z]); + + public static bool Planar(this IMeshCommon mesh, float tolerance = Math3d.Constants.Tolerance) + { + if (mesh.NumFaces <= 1) return true; + var normal = mesh.Triangle(0).Normal; + return mesh.ComputedNormals().All(n => n.AlmostEquals(normal, tolerance)); + } + + public static IArray ComputedNormals(this IMeshCommon mesh) + => mesh.Triangles().Select(t => t.Normal); + + public static Triangle Triangle(this IMeshCommon mesh, int face) + => mesh.VertexIndicesToTriangle(mesh.FaceVertexIndices(face)); + + public static IArray Triangles(this IMeshCommon mesh) + => mesh.NumFaces.Select(mesh.Triangle); + public static Vector3 Center(this IMeshCommon mesh) => mesh.BoundingBox().Center; diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 5eb5ea40..13092f28 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -3,6 +3,7 @@ using NUnit.Framework; using Vim.Format.Geometry; using Vim.G3d; +using Vim.G3dNext; using Vim.LinqArray; using Vim.Math3d; @@ -10,26 +11,41 @@ namespace Vim.Format.Tests.Geometry { public static class GeometryTests { - public static IMesh XYTriangle = new[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(1f, 0f, 0f) }.ToIArray().TriMesh(3.Range()); - public static IMesh XYQuad = new[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(1f, 1f, 0f), new Vector3(1f, 0f, 0f) }.ToIArray().QuadMesh(4.Range()); - public static IMesh XYQuadFromFunc = Primitives.QuadMesh(uv => uv.ToVector3(), 1, 1); - public static IMesh XYQuad2x2 = Primitives.QuadMesh(uv => uv.ToVector3(), 2, 2); - public static IMesh XYTriangleTwice = XYTriangle.Merge(XYTriangle.Translate(new Vector3(1, 0, 0))); - - public static readonly Vector3[] TestTetrahedronVertices = { Vector3.Zero, Vector3.UnitX, Vector3.UnitY, Vector3.UnitZ }; - public static readonly int[] TestTetrahedronIndices = { 0, 1, 2, 0, 3, 1, 1, 3, 2, 2, 3, 0 }; - - public static IMesh Tetrahedron = - TestTetrahedronVertices.ToIArray().TriMesh(TestTetrahedronIndices.ToIArray()); - - public static IMesh Torus = Primitives.Torus(10, 0.2f, 10, 24); - - static IMesh RevolvedVerticalCylinder(float height, float radius, int verticalSegments, int radialSegments) + public static IMeshCommon XYTriangle = new VimMesh( + new[] { 0, 1, 2 }, new[] { + new Vector3(0f, 0f, 0f), + new Vector3(0f, 1f, 0f), + new Vector3(1f, 0f, 0f) + }); + + public static IMeshCommon XYQuad = VimMesh.FromQuad( + new int[] { 0, 1, 2, 3 }, new[]{ + new Vector3(0f, 0f, 0f), + new Vector3(0f, 1f, 0f), + new Vector3(1f, 1f, 0f), + new Vector3(1f, 0f, 0f) + }); + + public static IMeshCommon XYQuadFromFunc = Primitives.QuadMesh(uv => uv.ToVector3(), 1, 1); + public static IMeshCommon XYQuad2x2 = Primitives.QuadMesh(uv => uv.ToVector3(), 2, 2); + public static IMeshCommon XYTriangleTwice = XYTriangle.Merge2(XYTriangle.Translate(new Vector3(1, 0, 0))); + + public static IMeshCommon Tetrahedron = new VimMesh( + new[] { 0, 1, 2, 0, 3, 1, 1, 3, 2, 2, 3, 0 }, new[] { + Vector3.Zero, + Vector3.UnitX, + Vector3.UnitY, + Vector3.UnitZ + }); + + public static IMeshCommon Torus = Primitives.Torus(10, 0.2f, 10, 24); + + static IMeshCommon RevolvedVerticalCylinder(float height, float radius, int verticalSegments, int radialSegments) => (Vector3.UnitZ * height).ToLine().Interpolate(verticalSegments).Add(-radius.AlongX()).RevolveAroundAxis(Vector3.UnitZ, radialSegments); - public static IMesh Cylinder = RevolvedVerticalCylinder(5, 1, 4, 12); + public static IMeshCommon Cylinder = RevolvedVerticalCylinder(5, 1, 4, 12); - public static IMesh[] AllMeshes = { + public static IMeshCommon[] AllMeshes = { XYTriangle, // 0 XYQuad, // 1 XYQuadFromFunc, // 2 @@ -44,6 +60,7 @@ static IMesh RevolvedVerticalCylinder(float height, float radius, int verticalSe public static void AssertEquals(IMesh g1, IMesh g2) { + Assert.AreEqual(g1.NumFaces, g2.NumFaces); Assert.AreEqual(g1.NumCorners, g2.NumCorners); Assert.AreEqual(g1.NumVertices, g2.NumVertices); @@ -55,65 +72,14 @@ public static void AssertEquals(IMesh g1, IMesh g2) } } - public static void AssertEqualsWithAttributes(IMesh g1, IMesh g2) - { - AssertEquals(g1, g2); - - Assert.AreEqual( - g1.Attributes.Select(attr => attr.Name).ToArray(), - g2.Attributes.Select(attr => attr.Name).ToArray()); - - Assert.AreEqual( - g1.Attributes.Select(attr => attr.ElementCount).ToArray(), - g2.Attributes.Select(attr => attr.ElementCount).ToArray()); - } - - public static void OutputTriangleStats(Triangle t) + public static void GeometryNullOps(IMeshCommon g) { - Console.WriteLine($"Vertices: {t.A} {t.B} {t.C}"); - Console.WriteLine($"Area: {t.Area} Perimeter: {t.Perimeter} Midpoint: {t.MidPoint}"); - Console.WriteLine($"Bounding box: {t.BoundingBox}"); - Console.WriteLine($"Bounding sphere: {t.BoundingSphere}"); - Console.WriteLine($"Normal: {t.Normal}, normal direction {t.NormalDirection}"); - Console.WriteLine($"Lengths: {t.LengthA} {t.LengthB} {t.LengthC}"); + g.GeometryEquals(g); + g.Translate(Vector3.Zero).GeometryEquals(g); + g.Scale(Vector3.Zero).GeometryEquals(g); + g.Transform(Matrix4x4.Identity).GeometryEquals(g); } - public static void OutputTriangleStatsSummary(IMesh g) - { - var triangles = g.Triangles(); - for (var i = 0; i < Math.Min(3, triangles.Count); ++i) - { - Console.WriteLine($"Triangle {i}"); - OutputTriangleStats(triangles[i]); - } - - if (triangles.Count > 3) - { - Console.WriteLine("..."); - Console.WriteLine($"Triangle {triangles.Count - 1}"); - OutputTriangleStats(triangles.Last()); - } - } - - public static void OutputIMeshStats(IMesh g) - { - g.Validate(); - foreach (var attr in g.Attributes.ToEnumerable()) - Console.WriteLine($"{attr.Descriptor} elementCount={attr.ElementCount}"); - } - - public static void GeometryNullOps(IMesh g) - { - AssertEqualsWithAttributes(g, g); - AssertEqualsWithAttributes(g, g.Attributes.ToIMesh()); - AssertEqualsWithAttributes(g, g.Translate(Vector3.Zero)); - AssertEqualsWithAttributes(g, g.Scale(1.0f)); - AssertEqualsWithAttributes(g, g.Transform(Matrix4x4.Identity)); - - AssertEquals(g, g.CopyFaces(0, g.NumFaces).ToIMesh()); - } - - [Test] public static void BasicTests() { @@ -155,7 +121,6 @@ public static void BasicTests() Assert.AreEqual(4, Tetrahedron.NumFaces); Assert.AreEqual(4, Tetrahedron.Vertices.Count); Assert.AreEqual(12, Tetrahedron.Indices.Count); - Assert.AreEqual(TestTetrahedronIndices, Tetrahedron.Indices.ToArray()); Assert.AreEqual(3, XYTriangleTwice.NumCornersPerFace); Assert.AreEqual(2, XYTriangleTwice.NumFaces); @@ -277,40 +242,30 @@ public static void StripIndicesTests() [Test] public static void TriangleSerializationTest() { - // Serialize a triangle g3d to a bfast as bytes and read it back. - var vertices = new[] + //TODO: Check the need for this test. + // Serializing a triangle is that a use case ? + + var mesh = new VimMesh(new [] { 0, 1, 2 }, new[] { new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 1) - }; - - var indices = new[] { 0, 1, 2 }; - var submeshIndexOffsets = new[] { 0 }; - var submeshMaterials = new[] { 0 }; - - var g3d = new G3DBuilder() - .AddVertices(vertices.ToIArray()) - .AddIndices(indices.ToIArray()) - .Add(submeshIndexOffsets.ToIArray().ToSubmeshIndexOffsetAttribute()) - .Add(submeshMaterials.ToIArray().ToSubmeshMaterialAttribute()) - .ToG3D(); - - var bfast = g3d.ToBFast(); - var readG3d = G3D.Read(bfast); - - Assert.IsNotNull(readG3d); - var mesh = readG3d.ToIMesh(); - mesh.Validate(); - - Assert.AreEqual(3, mesh.NumVertices); - Assert.AreEqual(new Vector3(0, 0, 0), mesh.Vertices[0]); - Assert.AreEqual(new Vector3(0, 1, 0), mesh.Vertices[1]); - Assert.AreEqual(new Vector3(0, 1, 1), mesh.Vertices[2]); - Assert.AreEqual(1, mesh.NumFaces); - Assert.AreEqual(0, mesh.SubmeshIndexOffsets.ToEnumerable().Single()); - Assert.AreEqual(0, mesh.SubmeshMaterials.ToEnumerable().Single()); - Assert.AreEqual(0, mesh.GetFaceMaterials().First()); + }); + + var bfast = mesh.ToG3d().ToBFast(); + var result = VimMesh.FromG3d(new G3dVim(bfast)); + + Assert.IsNotNull(mesh); + result.Validate(); + + Assert.AreEqual(3, result.NumVertices); + Assert.AreEqual(new Vector3(0, 0, 0), result.Vertices[0]); + Assert.AreEqual(new Vector3(0, 1, 0), result.Vertices[1]); + Assert.AreEqual(new Vector3(0, 1, 1), result.Vertices[2]); + Assert.AreEqual(1, result.NumFaces); + Assert.AreEqual(0, result.SubmeshIndexOffsets.ToEnumerable().Single()); + Assert.AreEqual(-1, result.SubmeshMaterials.ToEnumerable().Single()); + Assert.AreEqual(-1, result.GetFaceMaterials().First()); } } } diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 23c3d8b0..40ad87bb 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -127,26 +127,6 @@ public static void Merge_ByPair_IsSame() } } - [Test] - public static void QuadToTri_IsSame() - { - var indices = new int[] { 0, 1, 4, 3, 1, 2, 5, 4 }; - var vertices = new Vector3[] - { - new Vector3(1,0,0), - new Vector3(1,1,0), - new Vector3(1,2,0), - new Vector3(0,0,0), - new Vector3(0,1,0), - new Vector3(0,2,0), - }; - - var mesh = Primitives.QuadMesh(vertices.ToIArray(), indices.ToIArray()); - var next = VimMesh.FromQuad(indices, vertices); - - MeshesAreSame(mesh, next); - } - [Test] public static void FromG3d_Equals_ToIMesh() { diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index 282ad544..dcde1a3b 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -28,15 +28,10 @@ public VimValidationException(string message) : base(message) { } public static void ValidateGeometry(this VimScene vim) { // Validate the packed geometry. - vim.Document.Geometry.ToIMesh().Validate(); + VimMesh.FromG3d(vim.Document.GeometryNext).Validate(); var errors = new List(); G3d.Validation.Validate(vim.Document.Geometry); - - - // Validate the individual meshes. - foreach (var g in vim.MeshesOld.ToEnumerable()) - g.Validate(); } public static void ValidateGeometryNext(this VimScene vim) diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index b5704969..83f115a8 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -83,14 +83,6 @@ public Vector4 GetMaterialColor(int materialIndex) public Vector4 GetMaterialColorNext(int materialIndex) => _SerializableDocument.GeometryNext.MaterialColors[materialIndex]; - public static IMesh ToIMesh(G3dMesh g3d) - => Primitives.TriMesh( - g3d.Vertices.ToPositionAttribute(), - g3d.Indices.ToIndexAttribute(), - g3d.SubmeshIndexOffsets?.ToSubmeshIndexOffsetAttribute(), - g3d.SubmeshMaterials?.ToSubmeshMaterialAttribute() - ); - private VimScene(SerializableDocument doc) => _SerializableDocument = doc; @@ -198,12 +190,6 @@ private void CreateMeshes(bool inParallel) } var srcGeo = _SerializableDocument.Geometry; - var tmp = srcGeo?.Meshes.Select(ToIMesh); - MeshesOld = (tmp == null) - ? LinqArray.LinqArray.Empty() - : inParallel - ? tmp.EvaluateInParallel() - : tmp.Evaluate(); MeshesNext = VimMesh.GetAllMeshes(_SerializableDocument.GeometryNext).ToArray(); Meshes = srcGeo?.Meshes.Select(m => m as IMeshCommon); } From 10dc6c9218244a2a1ab65ed32fca34000da70a38 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 17:01:51 -0400 Subject: [PATCH 027/104] added unindex method --- src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 25b5414b..b9dada16 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -46,6 +46,12 @@ public VimMesh() } + public VimMesh(Vector3[] vertices) + : this(Enumerable.Range(0,vertices.Length).ToArray(), vertices) + { + + } + public VimMesh( int[] indices, Vector3[] vertices, @@ -95,6 +101,7 @@ private static int[] ComputeCounts(int[] offsets, int max) return result; } + public VimMesh(int indexCount, int vertexCount, int submeshCount) { indices = new int[indexCount]; @@ -329,6 +336,12 @@ public static bool Planar(this IMeshCommon mesh, float tolerance = Math3d.Consta return mesh.ComputedNormals().All(n => n.AlmostEquals(normal, tolerance)); } + public static VimMesh Unindex(this IMeshCommon mesh) + { + var vertices = mesh.Indices.Select(i => mesh.Vertices[i]); + return new VimMesh(vertices.ToArray()); + } + public static IArray ComputedNormals(this IMeshCommon mesh) => mesh.Triangles().Select(t => t.Normal); From 24a8ddf28d0b3233e7a3167ad9dc054fc7a2f1b1 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Apr 2024 17:14:53 -0400 Subject: [PATCH 028/104] removing more imesh --- .../Geometry/MeshExtensions.cs | 26 ++----------------- .../vim/Vim.Format.Core/Geometry/QuadMesh.cs | 21 --------------- .../vim/Vim.Format.Core/Geometry/TriMesh.cs | 20 -------------- .../Geometry/GeometryTests.cs | 14 ---------- .../SerializableDocumentTests.cs | 4 +-- 5 files changed, 4 insertions(+), 81 deletions(-) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/QuadMesh.cs delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/TriMesh.cs diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs index deacbe26..56d1dc00 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs @@ -10,28 +10,6 @@ namespace Vim.Format.Geometry { public static class MeshExtensions { - #region constructors - public static IMesh ToIMesh(this IArray self) - => self.ToEnumerable().ToIMesh(); - - public static IMesh ToIMesh(this IEnumerable self) - { - var tmp = new GeometryAttributes(self); - switch (tmp.NumCornersPerFace) - { - case 3: - return new TriMesh(tmp.Attributes.ToEnumerable()); - case 4: - return new QuadMesh(tmp.Attributes.ToEnumerable()).ToTriMesh(); - default: - throw new Exception($"Can not convert a geometry with {tmp.NumCornersPerFace} to a triangle mesh: only quad meshes"); - } - } - - public static IMesh ToIMesh(this IGeometryAttributes g) - => g is IMesh m ? m : g is QuadMesh q ? q.ToIMesh() : g.Attributes.ToIMesh(); - #endregion - public static IArray GetFaceMaterials(this IMesh mesh) { // SubmeshIndexOffsets: [0, A, B] @@ -47,7 +25,7 @@ public static IArray GetFaceMaterials(this IMesh mesh) } public static IMesh Merge(this IArray meshes) - => meshes.Select(m => (IGeometryAttributes)m).Merge().ToIMesh(); + => meshes.Select(m => (IGeometryAttributes)m).Merge() as IMesh; public static IMesh Merge(this IEnumerable meshes) => meshes.ToIArray().Merge(); @@ -137,7 +115,7 @@ public static IMesh Merge(this IMesh mesh, params IMesh[] others) .Append(newSubmeshIndexOffsets) .Append(newSubmeshMaterials) .ToGeometryAttributes() - .ToIMesh(); + as IMesh; }); return meshes.Select(m => (material, m)); diff --git a/src/cs/vim/Vim.Format.Core/Geometry/QuadMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/QuadMesh.cs deleted file mode 100644 index deb3af9f..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/QuadMesh.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics; -using Vim.Util; -using Vim.G3d; - -namespace Vim.Format.Geometry -{ - /// - /// This is a quadrilateral mesh. Note that it does not implement the IMesh interface, - /// but does implement IGeometryAttributes and inherits from a G3D. - /// - public class QuadMesh : G3D, IGeometryAttributes - { - public QuadMesh(IEnumerable attributes) - : base(attributes.Append(new[] { 4 }.ToObjectFaceSizeAttribute())) - => Debug.Assert(NumCornersPerFace == 4); - - public IMesh ToTriMesh() - => this.TriangulateQuadMesh().ToIMesh(); - } -} diff --git a/src/cs/vim/Vim.Format.Core/Geometry/TriMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/TriMesh.cs deleted file mode 100644 index 17678088..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/TriMesh.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics; -using Vim.G3d; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - /// - /// A triangular mesh data structure. - /// - public class TriMesh : G3D, IMesh - { - public TriMesh(IEnumerable attributes) - : base(attributes) - => Debug.Assert(NumCornersPerFace == 3); - - public IMesh Transform(Matrix4x4 mat) - => ((IGeometryAttributes)this).Transform(mat).ToIMesh(); - } -} diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 13092f28..22945f35 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -58,20 +58,6 @@ static IMeshCommon RevolvedVerticalCylinder(float height, float radius, int vert public static double SmallTolerance = 0.0001; - public static void AssertEquals(IMesh g1, IMesh g2) - { - - Assert.AreEqual(g1.NumFaces, g2.NumFaces); - Assert.AreEqual(g1.NumCorners, g2.NumCorners); - Assert.AreEqual(g1.NumVertices, g2.NumVertices); - for (var i = 0; i < g1.Indices.Count; i++) - { - var v1 = g1.Vertices[g1.Indices[i]]; - var v2 = g2.Vertices[g2.Indices[i]]; - Assert.IsTrue(v1.AlmostEquals(v2, (float)SmallTolerance)); - } - } - public static void GeometryNullOps(IMeshCommon g) { g.GeometryEquals(g); diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 40ad87bb..bb6ddb11 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -89,7 +89,7 @@ public static void ReverseWindingOrder_IsSame() for (var i = 0; i < scene.GetMeshCount(); i++) { - var mesh = scene.MeshesOld[i].ReverseWindingOrder().ToIMesh(); + var mesh = scene.MeshesOld[i].ReverseWindingOrder() as IMesh; var next = scene.MeshesNext[i].ReverseWindingOrder(); var raw = scene.Meshes[i].ReverseWindingOrder(); MeshesAreSame(mesh, next); @@ -132,7 +132,7 @@ public static void FromG3d_Equals_ToIMesh() { var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); var scene = VimScene.LoadVim(path); - var mesh = scene.Document.Geometry.ToIMesh(); + var mesh = scene.Document.Geometry as IMesh; var next = VimMesh.FromG3d(scene.Document.GeometryNext); MeshesAreSame(mesh, next); From f7753a092ff06dca5169cc1fa3b23e5694f573b3 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 9 Apr 2024 14:54:38 -0400 Subject: [PATCH 029/104] removed imesh --- src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs | 22 -- .../Geometry/MeshExtensions.cs | 178 ----------- .../SerializableDocumentTests.cs | 284 +++++++++--------- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 1 - 4 files changed, 142 insertions(+), 343 deletions(-) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs deleted file mode 100644 index 4e98afd8..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Vim.G3d; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - /// - /// This is the interface for triangle meshes. - /// - public interface IMesh : - IGeometryAttributes, - ITransformable3D - { - IArray Vertices { get; } - IArray Indices { get; } - - IArray SubmeshMaterials { get; } - IArray SubmeshIndexOffsets { get; } - IArray SubmeshIndexCount { get; } - } - -} diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs deleted file mode 100644 index 56d1dc00..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs +++ /dev/null @@ -1,178 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Vim.G3d; -using Vim.LinqArray; -using Vim.Math3d; -using Vim.Util; - -namespace Vim.Format.Geometry -{ - public static class MeshExtensions - { - public static IArray GetFaceMaterials(this IMesh mesh) - { - // SubmeshIndexOffsets: [0, A, B] - // SubmeshIndexCount: [X, Y, Z] - // SubmeshMaterials: [L, M, N] - // --- - // FaceMaterials: [...Repeat(L, X / 3), ...Repeat(M, Y / 3), ...Repeat(N, Z / 3)] <-- divide by 3 for the number of corners per Triangular face - var numCornersPerFace = mesh.NumCornersPerFace; - return mesh.SubmeshIndexCount - .ToEnumerable() - .SelectMany((indexCount, i) => Enumerable.Repeat(mesh.SubmeshMaterials[i], indexCount / numCornersPerFace)) - .ToIArray(); - } - - public static IMesh Merge(this IArray meshes) - => meshes.Select(m => (IGeometryAttributes)m).Merge() as IMesh; - - public static IMesh Merge(this IEnumerable meshes) - => meshes.ToIArray().Merge(); - - public static IMesh Merge(this IMesh mesh, params IMesh[] others) - { - var gs = others.ToList(); - gs.Insert(0, mesh); - return gs.Merge(); - } - - public static IEnumerable<(int Material, IMesh Mesh)> SplitByMaterial(this IMesh mesh) - { - var submeshMaterials = mesh.SubmeshMaterials; - if (submeshMaterials == null || submeshMaterials.Count == 0) - { - // Base case: no submesh materials are defined on the mesh. - return new[] { (-1, mesh) }; - } - - var submeshIndexOffets = mesh.SubmeshIndexOffsets; - var submeshIndexCounts = mesh.SubmeshIndexCount; - if (submeshIndexOffets == null || submeshIndexCounts == null || - submeshMaterials.Count <= 1 || submeshIndexOffets.Count <= 1 || submeshIndexCounts.Count <= 1) - { - // Base case: only one submesh material. - return new[] { (submeshMaterials[0], mesh) }; - } - - // Example: - // - // ------------ - // INPUT MESH: - // ------------ - // Vertices [Va, Vb, Vc, Vd, Ve, Vf, Vg] <-- 7 vertices - // Indices [0 (Va), 1 (Vb), 2 (Vc), 1 (Vb), 2 (Vc), 3 (Vd), 4 (Ve), 5 (Vf), 6 (Vg)] <-- 3 triangles referencing the 7 vertices - // SubmeshIndexOffsets [0, 3, 6] - // SubmeshIndexCount [3, 3, 3] (computed) - // SubmeshMaterials [Ma, Mb, Mc] - // - // ------------ - // OUTPUT MESHES - // ------------ - // - MESH FOR MATERIAL Ma - // Vertices: [Va, Vb, Vc] - // Indices: [0, 1, 2] - // SubmeshIndexOffsets: [0] - // SubmeshMaterials: [Ma] - // - //- MESH FOR MATERIAL Mb - // Vertices: [Vb, Vc, Vd] - // Indices: [0, 1, 2] - // SubmeshIndexOffsets: [0] - // SubmeshMaterials: [Mb] - // - //- MESH FOR MATERIAL Mc - // Vertices: [Ve, Vf, Vg] - // Indices: [0, 1, 2] - // SubmeshIndexOffsets: [0] - // SubmeshMaterials: [Mc] - - return mesh.SubmeshMaterials - .Select((submeshMaterial, submeshIndex) => (submeshMaterial, submeshIndex)) - .GroupBy(t => t.submeshMaterial) - .SelectMany(g => - { - var material = g.Key; - var meshes = g.Select((t, _) => - { - var submeshMaterial = t.submeshMaterial; - var submeshStartIndex = submeshIndexOffets[t.submeshIndex]; - var submeshIndexCount = submeshIndexCounts[t.submeshIndex]; - - var indexSlice = mesh.Indices.Slice(submeshStartIndex, submeshStartIndex + submeshIndexCount); - - var newVertexAttributes = mesh.VertexAttributes().Select(attr => attr.Remap(indexSlice)); - var newIndexAttribute = indexSlice.Count.Select(i => i).ToIndexAttribute(); - - var newSubmeshIndexOffsets = 0.Repeat(1).ToSubmeshIndexOffsetAttribute(); - var newSubmeshMaterials = submeshMaterial.Repeat(1).ToSubmeshMaterialAttribute(); - - return newVertexAttributes - .Concat(mesh.NoneAttributes()) - .Concat(mesh.WholeGeometryAttributes()) - // TODO: TECH DEBT - face, edge, and corner attributes are ignored for now. - .Append(newIndexAttribute) - .Append(newSubmeshIndexOffsets) - .Append(newSubmeshMaterials) - .ToGeometryAttributes() - as IMesh; - }); - - return meshes.Select(m => (material, m)); - }); - } - public static bool GeometryEquals(this IMesh mesh, IMesh other, float tolerance = Math3d.Constants.Tolerance) - { - if (mesh.NumFaces != other.NumFaces) - return false; - return mesh.Triangles().Zip(other.Triangles(), (t1, t2) => t1.AlmostEquals(t2, tolerance)).All(x => x); - } - public static IGeometryAttributes ReverseWindingOrder(this IMesh mesh) - { - var n = mesh.Indices.Count; - var r = new int[n]; - for (var i = 0; i < n; i += 3) - { - r[i + 0] = mesh.Indices[i + 2]; - r[i + 1] = mesh.Indices[i + 1]; - r[i + 2] = mesh.Indices[i + 0]; - } - return mesh.SetAttribute(r.ToIArray().ToIndexAttribute()); - } - - - public static AABox BoundingBox(this IMesh mesh) - => AABox.Create(mesh.Vertices.ToEnumerable()); - - - public static Vector3 Center(this IMesh mesh) - => mesh.BoundingBox().Center; - - #region Face operations - - - public static Int3 FaceVertexIndices(this IMesh mesh, int faceIndex) - => new Int3(mesh.Indices[faceIndex * 3], mesh.Indices[faceIndex * 3 + 1], mesh.Indices[faceIndex * 3 + 2]); - - public static Triangle VertexIndicesToTriangle(this IMesh mesh, Int3 indices) - => new Triangle(mesh.Vertices[indices.X], mesh.Vertices[indices.Y], mesh.Vertices[indices.Z]); - - public static Triangle Triangle(this IMesh mesh, int face) - => mesh.VertexIndicesToTriangle(mesh.FaceVertexIndices(face)); - - public static IArray Triangles(this IMesh mesh) - => mesh.NumFaces.Select(mesh.Triangle); - - public static IArray ComputedNormals(this IMesh mesh) - => mesh.Triangles().Select(t => t.Normal); - - public static bool Planar(this IMesh mesh, float tolerance = Math3d.Constants.Tolerance) - { - if (mesh.NumFaces <= 1) return true; - var normal = mesh.Triangle(0).Normal; - return mesh.ComputedNormals().All(n => n.AlmostEquals(normal, tolerance)); - } - - #endregion - } -} diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index bb6ddb11..b4cd0c6b 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -46,140 +46,140 @@ public static void MaterialColor_IsSame() } } - [Test] - public static void GetMesh_IsSameMesh() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - var mesh = scene.MeshesOld[i]; - var next = scene.MeshesNext[i]; - var raw = scene.Meshes[i]; - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - } - - [Test] - public static void GetMesh_Transform_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - var mat = Matrix4x4.CreateWorld( - new Vector3(1, -2, 3), - new Vector3(0, 0, 1), - new Vector3(0, 1, 0) - ); - var mesh = scene.MeshesOld[i].Transform(mat); - var next = scene.MeshesNext[i].Transform(mat); - var raw = scene.Meshes[i].Transform(mat); - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - } - - [Test] - public static void ReverseWindingOrder_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - - var mesh = scene.MeshesOld[i].ReverseWindingOrder() as IMesh; - var next = scene.MeshesNext[i].ReverseWindingOrder(); - var raw = scene.Meshes[i].ReverseWindingOrder(); - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - } - - [Test] - public static void FaceMaterial_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - var mesh = scene.MeshesOld[i].GetFaceMaterials(); - var next = scene.MeshesNext[i].GetFaceMaterials(); - var raw = scene.Meshes[i].GetFaceMaterials(); - Assert.That(mesh.SequenceEquals(next)); - Assert.That(next.SequenceEquals(raw)); - } - } - - [Test] - public static void Merge_ByPair_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 1; i < scene.GetMeshCount(); i++) - { - var mesh = scene.MeshesOld[i].Merge(scene.MeshesOld[i - 1]); - var next = scene.MeshesNext[i].Merge2(scene.MeshesNext[i - 1]); - var raw = scene.Meshes[i].Merge2(scene.Meshes[i - 1]); - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - } - - [Test] - public static void FromG3d_Equals_ToIMesh() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - var mesh = scene.Document.Geometry as IMesh; - var next = VimMesh.FromG3d(scene.Document.GeometryNext); - MeshesAreSame(mesh, next); - - } - - [Test] - public static void Merge_All_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - - var mesh = scene.MeshesOld[0].Merge(scene.MeshesOld.Skip(1).ToArray()); - var next = scene.MeshesNext[0].Merge2(scene.MeshesNext.Skip(1).ToArray()); - var raw = scene.Meshes[0].Merge2(scene.Meshes.Skip(1).ToArray()); - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - - [Test] - public static void SplitByMaterials_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - var mesh = scene.MeshesOld[i].SplitByMaterial().ToArray(); - var next = scene.MeshesNext[i].SplitByMaterial(); - var raw = scene.Meshes[i].SplitByMaterial(); - Assert.AreEqual(mesh.Length, next.Length); - Assert.AreEqual(mesh.Length, raw.Length); - - for (var j = 0; j < mesh.Length; j++) - { - MeshesAreSame(mesh[j].Mesh, next[j].mesh); - MeshesAreSame(mesh[j].Mesh, raw[j].mesh); - } - } - } - - private static void Consume(IMesh mesh) - { - mesh.Indices.Sum(); - mesh.Vertices.Sum(v => v.X); - mesh.SubmeshIndexOffsets.Sum(); - mesh.SubmeshIndexCount.Sum(); - mesh.SubmeshMaterials.Sum(); - } + //[Test] + //public static void GetMesh_IsSameMesh() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + // var mesh = scene.MeshesOld[i]; + // var next = scene.MeshesNext[i]; + // var raw = scene.Meshes[i]; + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + // } + //} + + //[Test] + //public static void GetMesh_Transform_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + // var mat = Matrix4x4.CreateWorld( + // new Vector3(1, -2, 3), + // new Vector3(0, 0, 1), + // new Vector3(0, 1, 0) + // ); + // var mesh = scene.MeshesOld[i].Transform(mat); + // var next = scene.MeshesNext[i].Transform(mat); + // var raw = scene.Meshes[i].Transform(mat); + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + // } + //} + + //[Test] + //public static void ReverseWindingOrder_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + + // var mesh = scene.MeshesOld[i].ReverseWindingOrder() as IMesh; + // var next = scene.MeshesNext[i].ReverseWindingOrder(); + // var raw = scene.Meshes[i].ReverseWindingOrder(); + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + // } + //} + + //[Test] + //public static void FaceMaterial_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + // var mesh = scene.MeshesOld[i].GetFaceMaterials(); + // var next = scene.MeshesNext[i].GetFaceMaterials(); + // var raw = scene.Meshes[i].GetFaceMaterials(); + // Assert.That(mesh.SequenceEquals(next)); + // Assert.That(next.SequenceEquals(raw)); + // } + //} + + //[Test] + //public static void Merge_ByPair_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 1; i < scene.GetMeshCount(); i++) + // { + // var mesh = scene.MeshesOld[i].Merge(scene.MeshesOld[i - 1]); + // var next = scene.MeshesNext[i].Merge2(scene.MeshesNext[i - 1]); + // var raw = scene.Meshes[i].Merge2(scene.Meshes[i - 1]); + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + // } + //} + + //[Test] + //public static void FromG3d_Equals_ToIMesh() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // var mesh = scene.Document.Geometry as IMesh; + // var next = VimMesh.FromG3d(scene.Document.GeometryNext); + // MeshesAreSame(mesh, next); + + //} + + //[Test] + //public static void Merge_All_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + + // var mesh = scene.MeshesOld[0].Merge(scene.MeshesOld.Skip(1).ToArray()); + // var next = scene.MeshesNext[0].Merge2(scene.MeshesNext.Skip(1).ToArray()); + // var raw = scene.Meshes[0].Merge2(scene.Meshes.Skip(1).ToArray()); + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + //} + + //[Test] + //public static void SplitByMaterials_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + // var mesh = scene.MeshesOld[i].SplitByMaterial().ToArray(); + // var next = scene.MeshesNext[i].SplitByMaterial(); + // var raw = scene.Meshes[i].SplitByMaterial(); + // Assert.AreEqual(mesh.Length, next.Length); + // Assert.AreEqual(mesh.Length, raw.Length); + + // for (var j = 0; j < mesh.Length; j++) + // { + // MeshesAreSame(mesh[j].Mesh, next[j].mesh); + // MeshesAreSame(mesh[j].Mesh, raw[j].mesh); + // } + // } + //} + + //private static void Consume(IMesh mesh) + //{ + // mesh.Indices.Sum(); + // mesh.Vertices.Sum(v => v.X); + // mesh.SubmeshIndexOffsets.Sum(); + // mesh.SubmeshIndexCount.Sum(); + // mesh.SubmeshMaterials.Sum(); + //} private static void Consume(IMeshCommon mesh) { @@ -191,14 +191,14 @@ private static void Consume(IMeshCommon mesh) } - private static void MeshesAreSame(IMesh mesh, IMeshCommon next) - { - Assert.That(mesh.Indices.SequenceEquals(next.Indices)); - Assert.That(mesh.Vertices.SequenceEquals(next.Vertices)); - Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.SubmeshIndexOffsets)); - Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.SubmeshMaterials)); - Assert.That(mesh.SubmeshIndexCount.SequenceEquals(next.SubmeshIndexCounts)); - } + //private static void MeshesAreSame(IMesh mesh, IMeshCommon next) + //{ + // Assert.That(mesh.Indices.SequenceEquals(next.Indices)); + // Assert.That(mesh.Vertices.SequenceEquals(next.Vertices)); + // Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.SubmeshIndexOffsets)); + // Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.SubmeshMaterials)); + // Assert.That(mesh.SubmeshIndexCount.SequenceEquals(next.SubmeshIndexCounts)); + //} private static void MeshesAreSame(IMeshCommon mesh, IMeshCommon next) { Assert.That(mesh.Indices.SequenceEquals(next.Indices)); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 83f115a8..145975e3 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -59,7 +59,6 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, => LoadVim(stream, new LoadOptions { SkipGeometry = skipGeometry, SkipAssets = skipAssets}, progress, inParallel); public int VimIndex { get; set; } - public IArray MeshesOld { get; private set; } public VimMesh[] MeshesNext { get; private set; } public IArray Meshes { get; private set; } public IArray Nodes { get; private set; } From bd36088de7108dca7a3382a6ad583d4381d03de9 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 9 Apr 2024 14:54:38 -0400 Subject: [PATCH 030/104] removed imesh --- src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs | 22 -- .../Geometry/MeshExtensions.cs | 178 ----------- .../SerializableDocumentTests.cs | 284 +++++++++--------- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 1 - 4 files changed, 142 insertions(+), 343 deletions(-) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs deleted file mode 100644 index 4e98afd8..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/IMesh.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Vim.G3d; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - /// - /// This is the interface for triangle meshes. - /// - public interface IMesh : - IGeometryAttributes, - ITransformable3D - { - IArray Vertices { get; } - IArray Indices { get; } - - IArray SubmeshMaterials { get; } - IArray SubmeshIndexOffsets { get; } - IArray SubmeshIndexCount { get; } - } - -} diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs deleted file mode 100644 index 56d1dc00..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshExtensions.cs +++ /dev/null @@ -1,178 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Vim.G3d; -using Vim.LinqArray; -using Vim.Math3d; -using Vim.Util; - -namespace Vim.Format.Geometry -{ - public static class MeshExtensions - { - public static IArray GetFaceMaterials(this IMesh mesh) - { - // SubmeshIndexOffsets: [0, A, B] - // SubmeshIndexCount: [X, Y, Z] - // SubmeshMaterials: [L, M, N] - // --- - // FaceMaterials: [...Repeat(L, X / 3), ...Repeat(M, Y / 3), ...Repeat(N, Z / 3)] <-- divide by 3 for the number of corners per Triangular face - var numCornersPerFace = mesh.NumCornersPerFace; - return mesh.SubmeshIndexCount - .ToEnumerable() - .SelectMany((indexCount, i) => Enumerable.Repeat(mesh.SubmeshMaterials[i], indexCount / numCornersPerFace)) - .ToIArray(); - } - - public static IMesh Merge(this IArray meshes) - => meshes.Select(m => (IGeometryAttributes)m).Merge() as IMesh; - - public static IMesh Merge(this IEnumerable meshes) - => meshes.ToIArray().Merge(); - - public static IMesh Merge(this IMesh mesh, params IMesh[] others) - { - var gs = others.ToList(); - gs.Insert(0, mesh); - return gs.Merge(); - } - - public static IEnumerable<(int Material, IMesh Mesh)> SplitByMaterial(this IMesh mesh) - { - var submeshMaterials = mesh.SubmeshMaterials; - if (submeshMaterials == null || submeshMaterials.Count == 0) - { - // Base case: no submesh materials are defined on the mesh. - return new[] { (-1, mesh) }; - } - - var submeshIndexOffets = mesh.SubmeshIndexOffsets; - var submeshIndexCounts = mesh.SubmeshIndexCount; - if (submeshIndexOffets == null || submeshIndexCounts == null || - submeshMaterials.Count <= 1 || submeshIndexOffets.Count <= 1 || submeshIndexCounts.Count <= 1) - { - // Base case: only one submesh material. - return new[] { (submeshMaterials[0], mesh) }; - } - - // Example: - // - // ------------ - // INPUT MESH: - // ------------ - // Vertices [Va, Vb, Vc, Vd, Ve, Vf, Vg] <-- 7 vertices - // Indices [0 (Va), 1 (Vb), 2 (Vc), 1 (Vb), 2 (Vc), 3 (Vd), 4 (Ve), 5 (Vf), 6 (Vg)] <-- 3 triangles referencing the 7 vertices - // SubmeshIndexOffsets [0, 3, 6] - // SubmeshIndexCount [3, 3, 3] (computed) - // SubmeshMaterials [Ma, Mb, Mc] - // - // ------------ - // OUTPUT MESHES - // ------------ - // - MESH FOR MATERIAL Ma - // Vertices: [Va, Vb, Vc] - // Indices: [0, 1, 2] - // SubmeshIndexOffsets: [0] - // SubmeshMaterials: [Ma] - // - //- MESH FOR MATERIAL Mb - // Vertices: [Vb, Vc, Vd] - // Indices: [0, 1, 2] - // SubmeshIndexOffsets: [0] - // SubmeshMaterials: [Mb] - // - //- MESH FOR MATERIAL Mc - // Vertices: [Ve, Vf, Vg] - // Indices: [0, 1, 2] - // SubmeshIndexOffsets: [0] - // SubmeshMaterials: [Mc] - - return mesh.SubmeshMaterials - .Select((submeshMaterial, submeshIndex) => (submeshMaterial, submeshIndex)) - .GroupBy(t => t.submeshMaterial) - .SelectMany(g => - { - var material = g.Key; - var meshes = g.Select((t, _) => - { - var submeshMaterial = t.submeshMaterial; - var submeshStartIndex = submeshIndexOffets[t.submeshIndex]; - var submeshIndexCount = submeshIndexCounts[t.submeshIndex]; - - var indexSlice = mesh.Indices.Slice(submeshStartIndex, submeshStartIndex + submeshIndexCount); - - var newVertexAttributes = mesh.VertexAttributes().Select(attr => attr.Remap(indexSlice)); - var newIndexAttribute = indexSlice.Count.Select(i => i).ToIndexAttribute(); - - var newSubmeshIndexOffsets = 0.Repeat(1).ToSubmeshIndexOffsetAttribute(); - var newSubmeshMaterials = submeshMaterial.Repeat(1).ToSubmeshMaterialAttribute(); - - return newVertexAttributes - .Concat(mesh.NoneAttributes()) - .Concat(mesh.WholeGeometryAttributes()) - // TODO: TECH DEBT - face, edge, and corner attributes are ignored for now. - .Append(newIndexAttribute) - .Append(newSubmeshIndexOffsets) - .Append(newSubmeshMaterials) - .ToGeometryAttributes() - as IMesh; - }); - - return meshes.Select(m => (material, m)); - }); - } - public static bool GeometryEquals(this IMesh mesh, IMesh other, float tolerance = Math3d.Constants.Tolerance) - { - if (mesh.NumFaces != other.NumFaces) - return false; - return mesh.Triangles().Zip(other.Triangles(), (t1, t2) => t1.AlmostEquals(t2, tolerance)).All(x => x); - } - public static IGeometryAttributes ReverseWindingOrder(this IMesh mesh) - { - var n = mesh.Indices.Count; - var r = new int[n]; - for (var i = 0; i < n; i += 3) - { - r[i + 0] = mesh.Indices[i + 2]; - r[i + 1] = mesh.Indices[i + 1]; - r[i + 2] = mesh.Indices[i + 0]; - } - return mesh.SetAttribute(r.ToIArray().ToIndexAttribute()); - } - - - public static AABox BoundingBox(this IMesh mesh) - => AABox.Create(mesh.Vertices.ToEnumerable()); - - - public static Vector3 Center(this IMesh mesh) - => mesh.BoundingBox().Center; - - #region Face operations - - - public static Int3 FaceVertexIndices(this IMesh mesh, int faceIndex) - => new Int3(mesh.Indices[faceIndex * 3], mesh.Indices[faceIndex * 3 + 1], mesh.Indices[faceIndex * 3 + 2]); - - public static Triangle VertexIndicesToTriangle(this IMesh mesh, Int3 indices) - => new Triangle(mesh.Vertices[indices.X], mesh.Vertices[indices.Y], mesh.Vertices[indices.Z]); - - public static Triangle Triangle(this IMesh mesh, int face) - => mesh.VertexIndicesToTriangle(mesh.FaceVertexIndices(face)); - - public static IArray Triangles(this IMesh mesh) - => mesh.NumFaces.Select(mesh.Triangle); - - public static IArray ComputedNormals(this IMesh mesh) - => mesh.Triangles().Select(t => t.Normal); - - public static bool Planar(this IMesh mesh, float tolerance = Math3d.Constants.Tolerance) - { - if (mesh.NumFaces <= 1) return true; - var normal = mesh.Triangle(0).Normal; - return mesh.ComputedNormals().All(n => n.AlmostEquals(normal, tolerance)); - } - - #endregion - } -} diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index bb6ddb11..b4cd0c6b 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -46,140 +46,140 @@ public static void MaterialColor_IsSame() } } - [Test] - public static void GetMesh_IsSameMesh() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - var mesh = scene.MeshesOld[i]; - var next = scene.MeshesNext[i]; - var raw = scene.Meshes[i]; - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - } - - [Test] - public static void GetMesh_Transform_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - var mat = Matrix4x4.CreateWorld( - new Vector3(1, -2, 3), - new Vector3(0, 0, 1), - new Vector3(0, 1, 0) - ); - var mesh = scene.MeshesOld[i].Transform(mat); - var next = scene.MeshesNext[i].Transform(mat); - var raw = scene.Meshes[i].Transform(mat); - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - } - - [Test] - public static void ReverseWindingOrder_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - - var mesh = scene.MeshesOld[i].ReverseWindingOrder() as IMesh; - var next = scene.MeshesNext[i].ReverseWindingOrder(); - var raw = scene.Meshes[i].ReverseWindingOrder(); - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - } - - [Test] - public static void FaceMaterial_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - var mesh = scene.MeshesOld[i].GetFaceMaterials(); - var next = scene.MeshesNext[i].GetFaceMaterials(); - var raw = scene.Meshes[i].GetFaceMaterials(); - Assert.That(mesh.SequenceEquals(next)); - Assert.That(next.SequenceEquals(raw)); - } - } - - [Test] - public static void Merge_ByPair_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 1; i < scene.GetMeshCount(); i++) - { - var mesh = scene.MeshesOld[i].Merge(scene.MeshesOld[i - 1]); - var next = scene.MeshesNext[i].Merge2(scene.MeshesNext[i - 1]); - var raw = scene.Meshes[i].Merge2(scene.Meshes[i - 1]); - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - } - - [Test] - public static void FromG3d_Equals_ToIMesh() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - var mesh = scene.Document.Geometry as IMesh; - var next = VimMesh.FromG3d(scene.Document.GeometryNext); - MeshesAreSame(mesh, next); - - } - - [Test] - public static void Merge_All_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - - var mesh = scene.MeshesOld[0].Merge(scene.MeshesOld.Skip(1).ToArray()); - var next = scene.MeshesNext[0].Merge2(scene.MeshesNext.Skip(1).ToArray()); - var raw = scene.Meshes[0].Merge2(scene.Meshes.Skip(1).ToArray()); - MeshesAreSame(mesh, next); - MeshesAreSame(mesh, raw); - } - - [Test] - public static void SplitByMaterials_IsSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMeshCount(); i++) - { - var mesh = scene.MeshesOld[i].SplitByMaterial().ToArray(); - var next = scene.MeshesNext[i].SplitByMaterial(); - var raw = scene.Meshes[i].SplitByMaterial(); - Assert.AreEqual(mesh.Length, next.Length); - Assert.AreEqual(mesh.Length, raw.Length); - - for (var j = 0; j < mesh.Length; j++) - { - MeshesAreSame(mesh[j].Mesh, next[j].mesh); - MeshesAreSame(mesh[j].Mesh, raw[j].mesh); - } - } - } - - private static void Consume(IMesh mesh) - { - mesh.Indices.Sum(); - mesh.Vertices.Sum(v => v.X); - mesh.SubmeshIndexOffsets.Sum(); - mesh.SubmeshIndexCount.Sum(); - mesh.SubmeshMaterials.Sum(); - } + //[Test] + //public static void GetMesh_IsSameMesh() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + // var mesh = scene.MeshesOld[i]; + // var next = scene.MeshesNext[i]; + // var raw = scene.Meshes[i]; + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + // } + //} + + //[Test] + //public static void GetMesh_Transform_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + // var mat = Matrix4x4.CreateWorld( + // new Vector3(1, -2, 3), + // new Vector3(0, 0, 1), + // new Vector3(0, 1, 0) + // ); + // var mesh = scene.MeshesOld[i].Transform(mat); + // var next = scene.MeshesNext[i].Transform(mat); + // var raw = scene.Meshes[i].Transform(mat); + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + // } + //} + + //[Test] + //public static void ReverseWindingOrder_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + + // var mesh = scene.MeshesOld[i].ReverseWindingOrder() as IMesh; + // var next = scene.MeshesNext[i].ReverseWindingOrder(); + // var raw = scene.Meshes[i].ReverseWindingOrder(); + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + // } + //} + + //[Test] + //public static void FaceMaterial_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + // var mesh = scene.MeshesOld[i].GetFaceMaterials(); + // var next = scene.MeshesNext[i].GetFaceMaterials(); + // var raw = scene.Meshes[i].GetFaceMaterials(); + // Assert.That(mesh.SequenceEquals(next)); + // Assert.That(next.SequenceEquals(raw)); + // } + //} + + //[Test] + //public static void Merge_ByPair_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 1; i < scene.GetMeshCount(); i++) + // { + // var mesh = scene.MeshesOld[i].Merge(scene.MeshesOld[i - 1]); + // var next = scene.MeshesNext[i].Merge2(scene.MeshesNext[i - 1]); + // var raw = scene.Meshes[i].Merge2(scene.Meshes[i - 1]); + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + // } + //} + + //[Test] + //public static void FromG3d_Equals_ToIMesh() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // var mesh = scene.Document.Geometry as IMesh; + // var next = VimMesh.FromG3d(scene.Document.GeometryNext); + // MeshesAreSame(mesh, next); + + //} + + //[Test] + //public static void Merge_All_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + + // var mesh = scene.MeshesOld[0].Merge(scene.MeshesOld.Skip(1).ToArray()); + // var next = scene.MeshesNext[0].Merge2(scene.MeshesNext.Skip(1).ToArray()); + // var raw = scene.Meshes[0].Merge2(scene.Meshes.Skip(1).ToArray()); + // MeshesAreSame(mesh, next); + // MeshesAreSame(mesh, raw); + //} + + //[Test] + //public static void SplitByMaterials_IsSame() + //{ + // var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + // var scene = VimScene.LoadVim(path); + // for (var i = 0; i < scene.GetMeshCount(); i++) + // { + // var mesh = scene.MeshesOld[i].SplitByMaterial().ToArray(); + // var next = scene.MeshesNext[i].SplitByMaterial(); + // var raw = scene.Meshes[i].SplitByMaterial(); + // Assert.AreEqual(mesh.Length, next.Length); + // Assert.AreEqual(mesh.Length, raw.Length); + + // for (var j = 0; j < mesh.Length; j++) + // { + // MeshesAreSame(mesh[j].Mesh, next[j].mesh); + // MeshesAreSame(mesh[j].Mesh, raw[j].mesh); + // } + // } + //} + + //private static void Consume(IMesh mesh) + //{ + // mesh.Indices.Sum(); + // mesh.Vertices.Sum(v => v.X); + // mesh.SubmeshIndexOffsets.Sum(); + // mesh.SubmeshIndexCount.Sum(); + // mesh.SubmeshMaterials.Sum(); + //} private static void Consume(IMeshCommon mesh) { @@ -191,14 +191,14 @@ private static void Consume(IMeshCommon mesh) } - private static void MeshesAreSame(IMesh mesh, IMeshCommon next) - { - Assert.That(mesh.Indices.SequenceEquals(next.Indices)); - Assert.That(mesh.Vertices.SequenceEquals(next.Vertices)); - Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.SubmeshIndexOffsets)); - Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.SubmeshMaterials)); - Assert.That(mesh.SubmeshIndexCount.SequenceEquals(next.SubmeshIndexCounts)); - } + //private static void MeshesAreSame(IMesh mesh, IMeshCommon next) + //{ + // Assert.That(mesh.Indices.SequenceEquals(next.Indices)); + // Assert.That(mesh.Vertices.SequenceEquals(next.Vertices)); + // Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.SubmeshIndexOffsets)); + // Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.SubmeshMaterials)); + // Assert.That(mesh.SubmeshIndexCount.SequenceEquals(next.SubmeshIndexCounts)); + //} private static void MeshesAreSame(IMeshCommon mesh, IMeshCommon next) { Assert.That(mesh.Indices.SequenceEquals(next.Indices)); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 83f115a8..145975e3 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -59,7 +59,6 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, => LoadVim(stream, new LoadOptions { SkipGeometry = skipGeometry, SkipAssets = skipAssets}, progress, inParallel); public int VimIndex { get; set; } - public IArray MeshesOld { get; private set; } public VimMesh[] MeshesNext { get; private set; } public IArray Meshes { get; private set; } public IArray Nodes { get; private set; } From a7c2e00425e9f25bacd2b265892c451ef44be2be Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 09:36:16 -0400 Subject: [PATCH 031/104] updating vimscene to g3dnext --- src/cs/g3d/Vim.G3dNext/G3dVim.cs | 18 +++++- .../Geometry/VimMaterialNext.cs | 30 +++++++++ .../Vim.Format.Core/Geometry/VimShapeNext.cs | 33 ++++++++++ .../Vim.Format.Core/SerializableDocument.cs | 6 +- .../SerializableDocumentTests.cs | 43 ++++++++++++- .../vim/Vim.Format/SceneBuilder/Validation.cs | 62 ------------------- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 15 ++--- 7 files changed, 131 insertions(+), 76 deletions(-) create mode 100644 src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs create mode 100644 src/cs/vim/Vim.Format.Core/Geometry/VimShapeNext.cs diff --git a/src/cs/g3d/Vim.G3dNext/G3dVim.cs b/src/cs/g3d/Vim.G3dNext/G3dVim.cs index dd2af2c6..b6447235 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dVim.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dVim.cs @@ -178,9 +178,25 @@ public int GetSubmeshIndexCount(int submesh) /// public int GetShapeCount() => ShapeVertexOffsets?.Length ?? 0; + + public int GetShapeVertexStart(int index) + { + return ShapeVertexOffsets[index]; + } + public int GetShapeVertexEnd(int index) + { + if (index + 1 >= ShapeVertexOffsets.Length) + { + return ShapeVertices.Length; + } + return ShapeVertexOffsets[index + 1]; + } /// /// The total number of shape vertices. /// - public int GetShapeVertexCount() => ShapeVertices?.Length ?? 0; + public int GetShapeVertexCount(int index) + { + return GetShapeVertexEnd(index) - GetShapeVertexStart(index); + } } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs new file mode 100644 index 00000000..f359876e --- /dev/null +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using Vim.G3dNext; +using Vim.Math3d; + +namespace Vim.Format.Geometry +{ + public class VimMaterialNext + { + public G3dVim g3d; + public int index; + + public static IEnumerable FromG3d(G3dVim g3d) + { + for(var i =0; i < g3d.GetMaterialCount(); i++) + { + yield return new VimMaterialNext(g3d, i); + } + } + + public Vector4 Color => g3d.MaterialColors[index]; + public float Smoothness => g3d.MaterialSmoothness[index]; + public float Glossiness => g3d.MaterialGlossiness[index]; + public VimMaterialNext(G3dVim g3d, int index) + { + this.g3d = g3d; + this.index = index; + } + } +} diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimShapeNext.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimShapeNext.cs new file mode 100644 index 00000000..10dcf2f3 --- /dev/null +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimShapeNext.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using Vim.G3dNext; +using Vim.Math3d; + +namespace Vim.Format.Geometry +{ + public class VimShapeNext + { + public readonly G3dVim g3d; + public readonly int Index; + public readonly ArraySegment Vertices; + + public Vector4 Color => g3d.ShapeColors[Index]; + public float Width => g3d.ShapeWidths[Index]; + + public static IEnumerable FromG3d(G3dVim g3d) + { + for(var i =0; i < g3d.GetShapeCount(); i++) + { + yield return new VimShapeNext(g3d, i); + } + } + + public VimShapeNext(G3dVim g3d, int index) + { + var start = g3d.GetShapeVertexStart(index); + var count = g3d.GetShapeVertexCount(index); + + Vertices = new ArraySegment(g3d.ShapeVertices, start, count); + } + } +} diff --git a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs index 99318a01..31f1772e 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs @@ -96,9 +96,9 @@ public BFast ToBFast() bfast.SetArray(BufferNames.Strings, BFastStrings.Pack(StringTable)); } - if(Geometry != null) + if(GeometryNext != null) { - bfast.SetBFast(BufferNames.Geometry, Geometry?.ToBFast()); + bfast.SetBFast(BufferNames.Geometry, GeometryNext.ToBFast()); } return bfast; @@ -127,8 +127,8 @@ public static SerializableDocument FromBFast(BFast bfast, LoadOptions options = if (!doc.Options.SkipGeometry) { var geo = bfast.GetBFast(BufferNames.Geometry); - doc.Geometry = G3D.Read(geo); doc.GeometryNext = new G3dVim(geo); + doc.Geometry = G3D.Read(geo); } var entities = bfast.GetBFast(BufferNames.Entities); diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index b4cd0c6b..39198891 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -36,16 +36,39 @@ public static void CanOpenVim() } [Test] - public static void MaterialColor_IsSame() + public static void ShapesAreSame() { var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); var scene = VimScene.LoadVim(path); - for (var i = 0; i < scene.GetMaterialCount(); i++) + + var shapes = scene.VimShapes; + var next = scene.VimShapesNext; + Assert.AreEqual(shapes.Count, next.Length); + for (var i = 0; i < shapes.Count; i++) + { + ShapesAreSame(shapes[i], next[i]); + } + } + + + + [Test] + public static void Materials_AreSame() + { + var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); + var scene = VimScene.LoadVim(path); + + var mats = scene.Materials; + var next = scene.MaterialsNext; + Assert.AreEqual(mats.Count, next.Length); + for (var i = 0; i < mats.Count; i++) { - Assert.AreEqual(scene.GetMaterialColor(i), scene.GetMaterialColorNext(i)); + MaterialsAreSame(mats[i], next[i]); } + } + //[Test] //public static void GetMesh_IsSameMesh() //{ @@ -208,6 +231,20 @@ private static void MeshesAreSame(IMeshCommon mesh, IMeshCommon next) Assert.That(mesh.SubmeshIndexCounts.SequenceEquals(next.SubmeshIndexCounts)); } + private static void ShapesAreSame(VimShape mesh, VimShapeNext next) + { + Assert.That(mesh.Vertices.ToEnumerable().SequenceEqual(next.Vertices)); + Assert.AreEqual(mesh.Color, next.Color); + Assert.AreEqual(mesh.Width, next.Width); + } + + private static void MaterialsAreSame(IMaterial mesh, VimMaterialNext next) + { + Assert.AreEqual(mesh.Color, next.Color); + Assert.AreEqual(mesh.Glossiness, next.Glossiness); + Assert.AreEqual(mesh.Smoothness, next.Smoothness); + } + diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index dcde1a3b..d9d81843 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -24,7 +24,6 @@ public class VimValidationException : Exception { public VimValidationException(string message) : base(message) { } } - public static void ValidateGeometry(this VimScene vim) { // Validate the packed geometry. @@ -40,66 +39,6 @@ public static void ValidateGeometryNext(this VimScene vim) vim.Document.GeometryNext.Validate(); } - public static void ValidateDocumentModelToG3dInvariants(this VimScene vim) - { - var g3d = vim._SerializableDocument.Geometry; - var errors = new List(); - - var entityTypesWithG3dReferences = new HashSet<(Type, G3dAttributeReferenceAttribute[])>( - ObjectModelReflection.GetEntityTypes() - .Select(t => ( - type: t, - attrs: t.GetCustomAttributes(typeof(G3dAttributeReferenceAttribute)) - .Select(a => a as G3dAttributeReferenceAttribute) - .ToArray())) - .Where(tuple => tuple.attrs.Length != 0)); - - var dm = vim.DocumentModel; - - foreach (var tuple in entityTypesWithG3dReferences) - { - var (type, attrs) = tuple; - var propertyName = type.Name + "List"; - if (dm.GetPropertyValue(propertyName) is IArray arr) - { - var numEntities = arr.Count; - - foreach (var attr in attrs) - { - var attributeName = attr.AttributeName; - var isOptional = attr.AttributeIsOptional; - - var g3dAttribute = g3d.GetAttribute(attributeName); - - // We don't check the relation if the attribute is optional and absent (null). - if (isOptional && g3dAttribute == null) - continue; - - var g3dElementCount = g3dAttribute?.ElementCount ?? 0; - var mult = attr.AttributeReferenceMultiplicity; - - // Validate one-to-one relationships - if (mult == G3dAttributeReferenceMultiplicity.OneToOne && numEntities != g3dElementCount) - { - errors.Add($"Multiplicity Error ({mult}); the number of entities of type \"{type.Name}\" ({numEntities}) is not equal to the number of elements in the g3d attribute \"{attributeName}\" ({g3dElementCount})"); - } - } - } - else - { - throw new VimValidationException($"DocumentModel.{propertyName} not found"); - } - } - - if (errors.Count > 0) - { - throw new VimValidationException( - $"DocumentModel to G3d invariant error(s):{Environment.NewLine}{string.Join(Environment.NewLine, errors)}"); - } - } - - - public static void ValidateDocumentModelToG3dInvariantsNext(this VimScene vim) { var g3d = vim.Document.GeometryNext; @@ -203,7 +142,6 @@ public static void Validate(this VimScene vim, VimValidationOptions options = nu vim.ValidateGeometry(); vim.ValidateGeometryNext(); - vim.ValidateDocumentModelToG3dInvariants(); vim.ValidateDocumentModelToG3dInvariantsNext(); vim.ValidateNodes(); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 145975e3..40c98e50 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -64,7 +64,9 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, public IArray Nodes { get; private set; } public IArray VimNodes { get; private set; } public IArray VimShapes { get; private set; } + public VimShapeNext[] VimShapesNext { get; private set; } public IArray Materials { get; private set; } + public VimMaterialNext[] MaterialsNext { get; private set; } public SerializableDocument _SerializableDocument { get; } public Document Document { get; private set; } @@ -75,10 +77,7 @@ public string PersistingId public int GetMeshCount() => Meshes.Count; public int GetMaterialCount() => Materials.Count; - - public Vector4 GetMaterialColor(int materialIndex) - => _SerializableDocument.Geometry.MaterialColors[materialIndex]; - + public Vector4 GetMaterialColorNext(int materialIndex) => _SerializableDocument.GeometryNext.MaterialColors[materialIndex]; @@ -183,7 +182,7 @@ private IStep[] GetInitSteps(bool inParallel) private void CreateMeshes(bool inParallel) { - if (_SerializableDocument.Geometry == null) + if (_SerializableDocument.GeometryNext == null) { return; } @@ -195,13 +194,13 @@ private void CreateMeshes(bool inParallel) private void CreateShapes(bool inParallel) { - if (_SerializableDocument.Geometry == null) + if (_SerializableDocument.GeometryNext == null) { return; } - var r = _SerializableDocument.Geometry.Shapes.Select((s, i) => new VimShape(this, i)); VimShapes = inParallel ? r.EvaluateInParallel() : r.Evaluate(); + VimShapesNext = VimShapeNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); } private void CreateScene(bool inParallel) @@ -224,6 +223,8 @@ private void CreateMaterials(bool inParallel) var query = _SerializableDocument.Geometry.Materials.Select(m => new VimMaterial(m) as IMaterial); Materials = inParallel ? query.EvaluateInParallel() : query.Evaluate(); + MaterialsNext = VimMaterialNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); + } public static IArray CreateVimSceneNodes(VimScene scene, G3D g3d, bool inParallel) From b6930ee736e6496cd5a9e9ce980ec029075aa243 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 10:20:58 -0400 Subject: [PATCH 032/104] removing conversions of materials --- src/cs/vim/Vim.Format.Core/DocumentBuilder.cs | 3 ++- src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs | 8 -------- src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs | 9 +++++---- src/cs/vim/Vim.Format.Core/G3dBuilder.cs | 5 +++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs index d90c1d6a..6d408df5 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs @@ -6,6 +6,7 @@ using Vim.BFastLib; using System.IO; using Vim.Util; +using Vim.Format.Geometry; namespace Vim.Format { @@ -84,7 +85,7 @@ public DocumentBuilder AddInstance(Matrix4x4 transform, int meshIndex, int paren return this; } - public DocumentBuilder AddMaterials(IEnumerable materials) + public DocumentBuilder AddMaterials(IEnumerable materials) { foreach (var material in materials) { diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index abdfeb48..02ae2464 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -10,14 +10,6 @@ namespace Vim.Format { public static class DocumentBuilderExtensions { - public static Material ToDocumentBuilderMaterial(this G3dMaterial g3dMaterial) - => new Material - { - Color = g3dMaterial.Color, - Glossiness = g3dMaterial.Glossiness, - Smoothness = g3dMaterial.Smoothness, - }; - public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this IMeshCommon m) => new SubdividedMesh( m.Indices.ToList(), diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs index 497c4ffa..a93c5543 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Vim.Format.Geometry; using Vim.G3d; using Vim.Math3d; @@ -23,12 +24,12 @@ public class Shape public float Width; } - public class Material + public class Material : IMaterial { //RGBA - public Vector4 Color; - public float Glossiness; - public float Smoothness; + public Vector4 Color { get; private set; } + public float Glossiness { get; private set; } + public float Smoothness { get; private set; } } /// diff --git a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs index 258e1f52..3d4ce2f8 100644 --- a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs @@ -4,6 +4,7 @@ using Vim.BFastLib; using static Vim.Format.DocumentBuilder; using Vim.Math3d; +using Vim.Format.Geometry; namespace Vim.Format { @@ -12,7 +13,7 @@ public class G3dBuilder private readonly List _meshes = new List(); private readonly List _instances = new List(); private readonly List _shapes = new List(); - private readonly List _materials = new List(); + private readonly List _materials = new List(); public void AddMesh(SubdividedMesh mesh) { @@ -29,7 +30,7 @@ public void AddShape(Shape shape) _shapes.Add(shape); } - public void AddMaterial(Material material) + public void AddMaterial(IMaterial material) { _materials.Add(material); } From 293ed9e60fc065ae4ae94315f878ee0da278ec28 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 10:20:58 -0400 Subject: [PATCH 033/104] removing conversions of materials --- src/cs/vim/Vim.Format.Core/DocumentBuilder.cs | 3 ++- src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs | 8 -------- src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs | 9 +++++---- src/cs/vim/Vim.Format.Core/G3dBuilder.cs | 5 +++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs index d90c1d6a..6d408df5 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs @@ -6,6 +6,7 @@ using Vim.BFastLib; using System.IO; using Vim.Util; +using Vim.Format.Geometry; namespace Vim.Format { @@ -84,7 +85,7 @@ public DocumentBuilder AddInstance(Matrix4x4 transform, int meshIndex, int paren return this; } - public DocumentBuilder AddMaterials(IEnumerable materials) + public DocumentBuilder AddMaterials(IEnumerable materials) { foreach (var material in materials) { diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index abdfeb48..02ae2464 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -10,14 +10,6 @@ namespace Vim.Format { public static class DocumentBuilderExtensions { - public static Material ToDocumentBuilderMaterial(this G3dMaterial g3dMaterial) - => new Material - { - Color = g3dMaterial.Color, - Glossiness = g3dMaterial.Glossiness, - Smoothness = g3dMaterial.Smoothness, - }; - public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this IMeshCommon m) => new SubdividedMesh( m.Indices.ToList(), diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs index 497c4ffa..a93c5543 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Vim.Format.Geometry; using Vim.G3d; using Vim.Math3d; @@ -23,12 +24,12 @@ public class Shape public float Width; } - public class Material + public class Material : IMaterial { //RGBA - public Vector4 Color; - public float Glossiness; - public float Smoothness; + public Vector4 Color { get; private set; } + public float Glossiness { get; private set; } + public float Smoothness { get; private set; } } /// diff --git a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs index 258e1f52..3d4ce2f8 100644 --- a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs @@ -4,6 +4,7 @@ using Vim.BFastLib; using static Vim.Format.DocumentBuilder; using Vim.Math3d; +using Vim.Format.Geometry; namespace Vim.Format { @@ -12,7 +13,7 @@ public class G3dBuilder private readonly List _meshes = new List(); private readonly List _instances = new List(); private readonly List _shapes = new List(); - private readonly List _materials = new List(); + private readonly List _materials = new List(); public void AddMesh(SubdividedMesh mesh) { @@ -29,7 +30,7 @@ public void AddShape(Shape shape) _shapes.Add(shape); } - public void AddMaterial(Material material) + public void AddMaterial(IMaterial material) { _materials.Add(material); } From b3c63206edae49fdfc18e3c1ef1fda3c364f181d Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 12:54:11 -0400 Subject: [PATCH 034/104] materialnext: imaterial --- src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs index f359876e..fd915fc8 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs @@ -5,7 +5,7 @@ namespace Vim.Format.Geometry { - public class VimMaterialNext + public class VimMaterialNext : IMaterial { public G3dVim g3d; public int index; From 1d19d3b7147ce458a8ec12de3b4559362cd31799 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 13:01:36 -0400 Subject: [PATCH 035/104] added shape count --- src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 40c98e50..c335462f 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -76,7 +76,9 @@ public string PersistingId => Document.Header.PersistingId; public int GetMeshCount() => Meshes.Count; - public int GetMaterialCount() => Materials.Count; + public int GetMaterialCount() => MaterialsNext.Length; + + public int GetShapeCount() => VimShapesNext.Length; public Vector4 GetMaterialColorNext(int materialIndex) => _SerializableDocument.GeometryNext.MaterialColors[materialIndex]; From e4b04c0e9a942759dd8f9e0b54a18c8b6f0ca77b Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 13:40:11 -0400 Subject: [PATCH 036/104] Renamed shapes and materials to old --- .../SerializableDocumentTests.cs | 8 ++++---- .../vim/Vim.Format/SceneBuilder/Validation.cs | 2 +- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 20 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 585d5783..49814ab1 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -37,8 +37,8 @@ public static void ShapesAreSame() var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); var scene = VimScene.LoadVim(path); - var shapes = scene.VimShapes; - var next = scene.VimShapesNext; + var shapes = scene.ShapesOld; + var next = scene.Shapes; Assert.AreEqual(shapes.Count, next.Length); for (var i = 0; i < shapes.Count; i++) { @@ -54,8 +54,8 @@ public static void Materials_AreSame() var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); var scene = VimScene.LoadVim(path); - var mats = scene.Materials; - var next = scene.MaterialsNext; + var mats = scene.MaterialsOld; + var next = scene.Materials; Assert.AreEqual(mats.Count, next.Length); for (var i = 0; i < mats.Count; i++) { diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index d9d81843..98d3f658 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -104,7 +104,7 @@ public static void ValidateNodes(this VimScene vim) public static void ValidateShapes(this VimScene vim) { - var shapes = vim.VimShapes; + var shapes = vim.ShapesOld; var numShapes = vim.DocumentModel.NumShape; if (shapes.Count != numShapes) throw new VimValidationException($"The number of {nameof(VimShape)} ({shapes.Count}) does not match the number of shape entities ({numShapes})"); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index c335462f..2626bcc9 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -63,10 +63,10 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, public IArray Meshes { get; private set; } public IArray Nodes { get; private set; } public IArray VimNodes { get; private set; } - public IArray VimShapes { get; private set; } - public VimShapeNext[] VimShapesNext { get; private set; } - public IArray Materials { get; private set; } - public VimMaterialNext[] MaterialsNext { get; private set; } + public IArray ShapesOld { get; private set; } + public VimShapeNext[] Shapes { get; private set; } + public IArray MaterialsOld { get; private set; } + public VimMaterialNext[] Materials { get; private set; } public SerializableDocument _SerializableDocument { get; } public Document Document { get; private set; } @@ -76,9 +76,9 @@ public string PersistingId => Document.Header.PersistingId; public int GetMeshCount() => Meshes.Count; - public int GetMaterialCount() => MaterialsNext.Length; + public int GetMaterialCount() => Materials.Length; - public int GetShapeCount() => VimShapesNext.Length; + public int GetShapeCount() => Shapes.Length; public Vector4 GetMaterialColorNext(int materialIndex) => _SerializableDocument.GeometryNext.MaterialColors[materialIndex]; @@ -201,8 +201,8 @@ private void CreateShapes(bool inParallel) return; } var r = _SerializableDocument.Geometry.Shapes.Select((s, i) => new VimShape(this, i)); - VimShapes = inParallel ? r.EvaluateInParallel() : r.Evaluate(); - VimShapesNext = VimShapeNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); + ShapesOld = inParallel ? r.EvaluateInParallel() : r.Evaluate(); + Shapes = VimShapeNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); } private void CreateScene(bool inParallel) @@ -224,8 +224,8 @@ private void CreateMaterials(bool inParallel) } var query = _SerializableDocument.Geometry.Materials.Select(m => new VimMaterial(m) as IMaterial); - Materials = inParallel ? query.EvaluateInParallel() : query.Evaluate(); - MaterialsNext = VimMaterialNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); + MaterialsOld = inParallel ? query.EvaluateInParallel() : query.Evaluate(); + Materials = VimMaterialNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); } From f54b8416172293804743076680fb8860968eb0de Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 13:49:49 -0400 Subject: [PATCH 037/104] explicit implementation of transform --- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 19 ++++++++++--------- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index b9dada16..2a73975f 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -47,7 +47,7 @@ public VimMesh() } public VimMesh(Vector3[] vertices) - : this(Enumerable.Range(0,vertices.Length).ToArray(), vertices) + : this(Enumerable.Range(0, vertices.Length).ToArray(), vertices) { } @@ -73,7 +73,7 @@ public G3dVim ToG3d() return new G3dVim( indices: indices, positions: vertices, - instanceMeshes: new[] {0}, + instanceMeshes: new[] { 0 }, instanceTransforms: new[] { Matrix4x4.Identity }, instanceParents: null, instanceFlags: null, @@ -123,7 +123,8 @@ public VimMesh Clone() } IMeshCommon IMeshCommon.Clone() => Clone(); - public IMeshCommon Transform(Matrix4x4 mat) + IMeshCommon ITransformable3D.Transform(Matrix4x4 mat) => Transform(mat); + public VimMesh Transform(Matrix4x4 mat) { var mesh = Clone(); @@ -188,7 +189,7 @@ public static VimMesh FromG3d(G3dVim g3d) public static VimMesh FromQuad(int[] indices, Vector3[] vertices) { - if(indices.Length % 4 != 0) + if (indices.Length % 4 != 0) { throw new ArgumentException("Indices count should be a multiple of 4."); } @@ -260,10 +261,10 @@ public static IMeshCommon Merge2(this IMeshCommon mesh, params IMeshCommon[] oth .Append(mesh) .Append(others) .ToArray(); - + return meshes.Merge(); } - + public static IMeshCommon Merge(this IMeshCommon[] meshes) { void Merge(IArray from, int[] to, int offset, int increment) @@ -393,9 +394,9 @@ public static bool GeometryEquals(this IMeshCommon mesh, IMeshCommon other, floa if (mesh.Vertices.Count != other.Vertices.Count) return false; - for(var i = 0; i < mesh.Vertices.Count; i++) + for (var i = 0; i < mesh.Vertices.Count; i++) { - if(!mesh.Vertices[i].AlmostEquals(other.Vertices[i], tolerance)) + if (!mesh.Vertices[i].AlmostEquals(other.Vertices[i], tolerance)) return false; } @@ -413,7 +414,7 @@ public static (int mat, IMeshCommon mesh)[] SplitByMaterial(this IMeshCommon mes return result; } - for (var i =0; i < map.Length; i++) + for (var i = 0; i < map.Length; i++) { var (mat, subs) = map[i]; var pick = mesh.PickSubmeshes(subs); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 2626bcc9..1e30bf3e 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -244,10 +244,10 @@ public void Save(string filePath) public string FileName => _SerializableDocument.FileName; - public void TransformSceneInPlace(Func meshTransform = null, Func nodeTransform = null) + public void TransformSceneInPlace(Func meshTransform = null, Func nodeTransform = null) { if (meshTransform != null) - Meshes = Meshes.Select(meshTransform).EvaluateInParallel(); + MeshesNext = MeshesNext.Select(meshTransform).ToArray(); if (nodeTransform != null) VimNodes = VimNodes.Select(nodeTransform).EvaluateInParallel(); } From a36dcd57bb5beb796c210fdd61b1bd3f14790550 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 15:03:07 -0400 Subject: [PATCH 038/104] removing builder types --- src/cs/g3d/Vim.G3dNext/Constants.cs | 7 +++ src/cs/vim/Vim.Format.Core/DocumentBuilder.cs | 4 +- .../Vim.Format.Core/DocumentBuilderTypes.cs | 43 ++++++++++++++++--- src/cs/vim/Vim.Format.Core/G3dBuilder.cs | 20 ++++----- src/cs/vim/Vim.Format.Core/Geometry/IScene.cs | 2 +- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 2 + .../ObjectModel/ObjectModelStore.cs | 8 ---- .../vim/Vim.Format/SceneBuilder/Validation.cs | 25 +++-------- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 19 ++++---- .../Vim.Format/SceneBuilder/VimSceneNode.cs | 3 +- 10 files changed, 77 insertions(+), 56 deletions(-) diff --git a/src/cs/g3d/Vim.G3dNext/Constants.cs b/src/cs/g3d/Vim.G3dNext/Constants.cs index c8cc2282..8442d63a 100644 --- a/src/cs/g3d/Vim.G3dNext/Constants.cs +++ b/src/cs/g3d/Vim.G3dNext/Constants.cs @@ -29,6 +29,13 @@ public static bool SafeEqual(this T[] a, T[] b) } return true; } + + public static T SafeGet(this T[] a, int i) where T : class + { + if (i < 0) return null; + if (i >= a.Length) return null; + return a[i]; + } } public static class Constants diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs index 6d408df5..c5b1e68b 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilder.cs @@ -49,13 +49,13 @@ public DocumentBuilder AddAsset(string name, byte[] asset) return this; } - public DocumentBuilder AddMesh(SubdividedMesh mesh) + public DocumentBuilder AddMesh(VimMesh mesh) { Geometry.AddMesh(mesh); return this; } - public DocumentBuilder AddMeshes(IEnumerable meshes) + public DocumentBuilder AddMeshes(IEnumerable meshes) { foreach (var m in meshes) { diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs index a93c5543..ca2c4f94 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs @@ -4,6 +4,7 @@ using Vim.Format.Geometry; using Vim.G3d; using Vim.Math3d; +using static Vim.Format.DocumentBuilder; namespace Vim.Format { @@ -27,9 +28,9 @@ public class Shape public class Material : IMaterial { //RGBA - public Vector4 Color { get; private set; } - public float Glossiness { get; private set; } - public float Smoothness { get; private set; } + public Vector4 Color { get; set; } + public float Glossiness { get; set; } + public float Smoothness { get; set; } } /// @@ -72,6 +73,7 @@ public Mesh(List vertices = null, List indices = null, List f _uvs = uvs ?? new List(); } + public void SetMeshMaterial(int material) => _faceMaterials = Enumerable.Repeat(material, _indices.Count / 3).ToList(); @@ -101,8 +103,39 @@ public void AppendVertices(IEnumerable vertices) public void AppendUVs(IEnumerable uvs) => _uvs.AddRange(uvs); - public SubdividedMesh Subdivide() - => new SubdividedMesh(this); + public VimMesh Subdivide() + { + if (Indices.Any(i => i < 0 && i >= Vertices.Count)) + throw new Exception($"Invalid mesh. Indices out of vertex range."); + + var facesByMats = FaceMaterials + .Select((face, index) => (face, index)) + .GroupBy(pair => pair.face, pair => pair.index); + + var submeshIndexOffsets = new List(); + var submeshMaterials = new List(); + var indicesRemap = new List(); + + foreach (var group in facesByMats) + { + submeshIndexOffsets.Add(indicesRemap.Count); + submeshMaterials.Add(group.Key); + foreach (var face in group) + { + var f = face * 3; + indicesRemap.Add(Indices[f]); + indicesRemap.Add(Indices[f + 1]); + indicesRemap.Add(Indices[f + 2]); + } + } + return new VimMesh( + indicesRemap.ToArray(), + Vertices.ToArray(), + submeshIndexOffsets.ToArray(), + submeshMaterials.ToArray() + ); + + } } /// diff --git a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs index 3d4ce2f8..76a4304c 100644 --- a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs @@ -10,12 +10,12 @@ namespace Vim.Format { public class G3dBuilder { - private readonly List _meshes = new List(); + private readonly List _meshes = new List(); private readonly List _instances = new List(); private readonly List _shapes = new List(); private readonly List _materials = new List(); - public void AddMesh(SubdividedMesh mesh) + public void AddMesh(VimMesh mesh) { _meshes.Add(mesh); } @@ -40,10 +40,10 @@ public void AddMaterial(IMaterial material) public int MaterialCount => _materials.Count; public int ShapeCount => _shapes.Count; - public SubdividedMesh GetMesh(int index) => _meshes[index]; + public IMeshCommon GetMesh(int index) => _meshes[index]; public AABox GetBox(int meshIndex) { - return AABox.Create(_meshes[meshIndex].Vertices); + return AABox.Create(_meshes[meshIndex].vertices); } public int[] GetVertexCounts() @@ -60,7 +60,7 @@ public int[] GetFaceCounts() public BFast ToBFast() { var bfast = new BFast(); - var totalSubmeshCount = _meshes.Select(s => s.SubmeshesIndexOffset.Count).Sum(); + var totalSubmeshCount = _meshes.Select(s => s.SubmeshCount).Sum(); // Compute the Vertex offsets and index offsets var meshVertexOffsets = new int[_meshes.Count]; @@ -74,14 +74,14 @@ public BFast ToBFast() { meshVertexOffsets[i] = meshVertexOffsets[i - 1] + _meshes[i - 1].Vertices.Count; meshIndexOffsets[i] = meshIndexOffsets[i - 1] + _meshes[i - 1].Indices.Count; - meshSubmeshOffset[i] = meshSubmeshOffset[i - 1] + _meshes[i - 1].SubmeshesIndexOffset.Count; + meshSubmeshOffset[i] = meshSubmeshOffset[i - 1] + _meshes[i - 1].SubmeshCount; } var subIndex = 0; var previousIndexCount = 0; foreach (var geo in _meshes) { - foreach (var sub in geo.SubmeshesIndexOffset) + foreach (var sub in geo.submeshIndexOffsets) { submeshIndexOffsets[subIndex++] = sub + previousIndexCount; } @@ -96,11 +96,11 @@ public BFast ToBFast() shapeVertexOffsets[i] = shapeVertexOffsets[i - 1] + _shapes[i - 1].Vertices.Count; } - bfast.SetEnumerable(CommonAttributes.Position, () => _meshes.SelectMany(m => m.Vertices)); - bfast.SetEnumerable(CommonAttributes.Index, () => _meshes.SelectMany(m => m.Indices)); + bfast.SetEnumerable(CommonAttributes.Position, () => _meshes.SelectMany(m => m.vertices)); + bfast.SetEnumerable(CommonAttributes.Index, () => _meshes.SelectMany(m => m.indices)); bfast.SetEnumerable(CommonAttributes.MeshSubmeshOffset, () => meshSubmeshOffset); bfast.SetEnumerable(CommonAttributes.SubmeshIndexOffset, () => submeshIndexOffsets); - bfast.SetEnumerable(CommonAttributes.SubmeshMaterial, () => _meshes.SelectMany(s => s.SubmeshMaterials)); + bfast.SetEnumerable(CommonAttributes.SubmeshMaterial, () => _meshes.SelectMany(s => s.submeshMaterials)); bfast.SetEnumerable(CommonAttributes.InstanceFlags, () => _instances.Select(i => (ushort)i.InstanceFlags)); bfast.SetEnumerable(CommonAttributes.InstanceParent, () => _instances.Select(i => i.ParentIndex)); bfast.SetEnumerable(CommonAttributes.InstanceMesh, () => _instances.Select(i => i.MeshIndex)); diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs index 4f7208cd..a618151c 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs @@ -11,7 +11,7 @@ namespace Vim.Format.Geometry public interface IScene { IArray Nodes { get; } - IArray Meshes { get; } + IArray MeshesOld { get; } } /// diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 2a73975f..03516d76 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -19,6 +19,8 @@ public class VimMesh : IMeshCommon public IArray SubmeshIndexOffsets => submeshIndexOffsets.ToIArray(); public IArray SubmeshIndexCounts => submeshIndexCounts.ToIArray(); + public int SubmeshCount => submeshIndexCounts.Length; + public int NumCornersPerFace => 3; public int NumVertices => vertices.Length; diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelStore.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelStore.cs index b2fa3243..4cb5d0e5 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelStore.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelStore.cs @@ -28,14 +28,6 @@ public DocumentBuilder ToDocumentBuilder(string generator, string versionString) .AddMaterials(CreateMaterialBuilders()); } - private IEnumerable CreateMaterialBuilders() - => ObjectModelBuilder.GetEntities().Select(m => new DocumentBuilder.Material() - { - Color = new Vector4((float) m.Color.X, (float) m.Color.Y, (float) m.Color.Z, (float)(1 - m.Transparency)), - Glossiness = (float) m.Glossiness, - Smoothness = (float) m.Smoothness - }); - /// /// Mutates the Meshes and Instances to remove any meshes which are not referenced by at least one instance. /// diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index 98d3f658..6fda7aaf 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -104,10 +104,9 @@ public static void ValidateNodes(this VimScene vim) public static void ValidateShapes(this VimScene vim) { - var shapes = vim.ShapesOld; - var numShapes = vim.DocumentModel.NumShape; - if (shapes.Count != numShapes) - throw new VimValidationException($"The number of {nameof(VimShape)} ({shapes.Count}) does not match the number of shape entities ({numShapes})"); + var shapes = vim.Shapes; + if (vim.GetShapeCount() != vim.DocumentModel.NumShape) + throw new VimValidationException($"The number of {nameof(VimShape)} ({vim.GetShapeCount()}) does not match the number of shape entities ({vim.DocumentModel.NumShape})"); void ValidateColorDomain(string label, Vector4 value, Vector4 lowerInclusive, Vector4 upperInclusive, int index) { @@ -124,10 +123,10 @@ void ValidateColorDomain(string label, Vector4 value, Vector4 lowerInclusive, Ve } } - Parallel.For(0, numShapes, shapeIndex => + Parallel.For(0, vim.GetShapeCount(), shapeIndex => { var shape = shapes[shapeIndex]; - if (shape.ElementIndex < 0) + if (vim.DocumentModel.GetShapeElementIndex(shapeIndex) < 0) throw new VimValidationException($"{nameof(Element)} is null for {nameof(VimShape)} {shape.ShapeIndex}"); ValidateColorDomain($"{nameof(VimShape)} color", shape.Color, Vector4.Zero, Vector4.One, shape.ShapeIndex); }); @@ -150,20 +149,6 @@ public static void Validate(this VimScene vim, VimValidationOptions options = nu public static void ValidateEquality(this DocumentBuilder db, VimScene vim) { - // Test the geometry both ways - var vimGeoBuilders = vim.Meshes.Select(g => new DocumentBuilder.SubdividedMesh( - g.Indices.ToList(), - g.Vertices.ToList(), - g.SubmeshIndexOffsets.ToList(), - g.SubmeshMaterials.ToList() - )).ToList(); - - for (var i = 0; i < db.Geometry.MeshCount; ++i) - { - if (!db.Geometry.GetMesh(i).IsEquivalentTo(vimGeoBuilders[i])) - throw new VimValidationException($"{nameof(DocumentBuilder)} mesh {i} is not equivalent to {nameof(VimScene)} mesh {i}"); - } - // Test the assets. var dbAssetDictionary = db.Assets; var vimAssetDictionary = vim._SerializableDocument.Assets.ToDictionary(a => a.Name, a => a.ToBytes()); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 1e30bf3e..fca310d2 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -59,15 +59,17 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, => LoadVim(stream, new LoadOptions { SkipGeometry = skipGeometry, SkipAssets = skipAssets}, progress, inParallel); public int VimIndex { get; set; } - public VimMesh[] MeshesNext { get; private set; } - public IArray Meshes { get; private set; } public IArray Nodes { get; private set; } public IArray VimNodes { get; private set; } - public IArray ShapesOld { get; private set; } + + public VimMesh[] Meshes { get; private set; } public VimShapeNext[] Shapes { get; private set; } - public IArray MaterialsOld { get; private set; } public VimMaterialNext[] Materials { get; private set; } + public IArray ShapesOld { get; private set; } + public IArray MaterialsOld { get; private set; } + public IArray MeshesOld { get; private set; } + public SerializableDocument _SerializableDocument { get; } public Document Document { get; private set; } public DocumentModel DocumentModel { get; private set; } @@ -75,9 +77,8 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, public string PersistingId => Document.Header.PersistingId; - public int GetMeshCount() => Meshes.Count; + public int GetMeshCount() => Meshes.Length; public int GetMaterialCount() => Materials.Length; - public int GetShapeCount() => Shapes.Length; public Vector4 GetMaterialColorNext(int materialIndex) @@ -190,8 +191,8 @@ private void CreateMeshes(bool inParallel) } var srcGeo = _SerializableDocument.Geometry; - MeshesNext = VimMesh.GetAllMeshes(_SerializableDocument.GeometryNext).ToArray(); - Meshes = srcGeo?.Meshes.Select(m => m as IMeshCommon); + Meshes = VimMesh.GetAllMeshes(_SerializableDocument.GeometryNext).ToArray(); + MeshesOld = srcGeo?.Meshes.Select(m => m as IMeshCommon); } private void CreateShapes(bool inParallel) @@ -247,7 +248,7 @@ public void Save(string filePath) public void TransformSceneInPlace(Func meshTransform = null, Func nodeTransform = null) { if (meshTransform != null) - MeshesNext = MeshesNext.Select(meshTransform).ToArray(); + Meshes = Meshes.Select(meshTransform).ToArray(); if (nodeTransform != null) VimNodes = VimNodes.Select(nodeTransform).EvaluateInParallel(); } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 9dcf686a..0d90c895 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -1,6 +1,7 @@ using Vim.Format.Geometry; using Vim.Format.ObjectModel; using Vim.G3d; +using Vim.G3dNext; using Vim.LinqArray; using Vim.Math3d; @@ -37,7 +38,7 @@ public bool HideByDefault public int NodeIndex { get; } = -1; public IMeshCommon GetMesh() - => _Scene.Meshes.ElementAtOrDefault(MeshIndex); + => _Scene.Meshes.SafeGet(MeshIndex); public int MeshIndex { get; } From e2ae306a4cfd44eda3bd0aa3366794c52512daca Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 15:41:13 -0400 Subject: [PATCH 039/104] meshcommon -> vimmesh --- .../Vim.Format.Core/Geometry/MeshOptimization.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs index fac1c90b..ee3b002a 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs @@ -5,7 +5,7 @@ using Vim.Math3d; namespace Vim.Format.Geometry -{ +{ /// /// This class is used to compare quickly two meshes within a lookup table (e.g. Dictionary, HashTable). @@ -15,9 +15,9 @@ namespace Vim.Format.Geometry /// By converting an IMesh to a MeshHash we minimize the amount of comparisons done. It becomes /// possible, but highly unlikely that two different meshes would have the same hash. /// - public class MeshCommonHash + public class MeshHash { - public IMeshCommon Mesh; + public VimMesh Mesh; public float Tolerance; public int NumFaces; public int NumVertices; @@ -31,7 +31,7 @@ public int Round(float f) public Int3 Round(Vector3 v) => new Int3(Round(v.X), Round(v.Y), Round(v.Z)); - public MeshCommonHash(IMeshCommon mesh, float tolerance) + public MeshHash(VimMesh mesh, float tolerance) { Mesh = mesh; Tolerance = tolerance; @@ -44,9 +44,9 @@ public MeshCommonHash(IMeshCommon mesh, float tolerance) } public override bool Equals(object obj) - => obj is MeshCommonHash other && Equals(other); + => obj is MeshHash other && Equals(other); - public bool Equals(MeshCommonHash other) + public bool Equals(MeshHash other) => NumFaces == other.NumFaces && NumVertices == other.NumVertices && BoxMin.Equals(other.BoxMin) @@ -59,7 +59,7 @@ public override int GetHashCode() public static class Optimization { - public static Dictionary> GroupMeshesByHash(this IEnumerable meshes, float tolerance) - => meshes.AsParallel().GroupBy(m => new MeshCommonHash(m, tolerance)).ToDictionary(grp => grp.Key, grp => grp.ToList()); + public static Dictionary> GroupMeshesByHash(this IEnumerable meshes, float tolerance) + => meshes.AsParallel().GroupBy(m => new MeshHash(m, tolerance)).ToDictionary(grp => grp.Key, grp => grp.ToList()); } } From fc7bab61094a113019d0d4e283b775cae07df5c9 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 15:50:27 -0400 Subject: [PATCH 040/104] renames --- src/cs/vim/Vim.Format/SceneBuilder/Validation.cs | 7 ++++--- src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index 6fda7aaf..bba370e1 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -126,9 +126,10 @@ void ValidateColorDomain(string label, Vector4 value, Vector4 lowerInclusive, Ve Parallel.For(0, vim.GetShapeCount(), shapeIndex => { var shape = shapes[shapeIndex]; - if (vim.DocumentModel.GetShapeElementIndex(shapeIndex) < 0) - throw new VimValidationException($"{nameof(Element)} is null for {nameof(VimShape)} {shape.ShapeIndex}"); - ValidateColorDomain($"{nameof(VimShape)} color", shape.Color, Vector4.Zero, Vector4.One, shape.ShapeIndex); + var element = vim.DocumentModel.GetShapeElementIndex(shapeIndex); + if (element < 0) + throw new VimValidationException($"{nameof(Element)} is null for {nameof(VimShape)} {shape.Index}"); + ValidateColorDomain($"{nameof(VimShape)} color", shape.Color, Vector4.Zero, Vector4.One, shape.Index); }); } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index fca310d2..4bf943b5 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -81,7 +81,7 @@ public string PersistingId public int GetMaterialCount() => Materials.Length; public int GetShapeCount() => Shapes.Length; - public Vector4 GetMaterialColorNext(int materialIndex) + public Vector4 GetMaterialColor(int materialIndex) => _SerializableDocument.GeometryNext.MaterialColors[materialIndex]; private VimScene(SerializableDocument doc) From d98be27d98e36dd82007fb4c6938aae60e84c954 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 10 Apr 2024 15:53:46 -0400 Subject: [PATCH 041/104] node.mesh is now vimmesh --- src/cs/vim/Vim.Format.Core/Geometry/IScene.cs | 6 +++--- src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs index a618151c..c4a6cfbf 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs @@ -23,7 +23,7 @@ public interface ISceneNode IScene Scene { get; } Matrix4x4 Transform { get; } int MeshIndex { get; } - IMeshCommon GetMesh(); + VimMesh GetMesh(); ISceneNode Parent { get; } // TODO: DEPRECATE: this needs to be removed, currently only used in Vim.Max.Bridge. @@ -52,7 +52,7 @@ public class NullNode : ISceneNode public int MeshIndex => 0; public ISceneNode Parent => null; public IArray Children => null; - public IMeshCommon GetMesh() => null; + public VimMesh GetMesh() => null; } public class IdNode : ISceneNode @@ -63,6 +63,6 @@ public class IdNode : ISceneNode public int MeshIndex => 0; public ISceneNode Parent => null; public IArray Children => null; - public IMeshCommon GetMesh() => null; + public VimMesh GetMesh() => null; } } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 0d90c895..4c4c042b 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -37,7 +37,7 @@ public bool HideByDefault public int VimIndex { get; } = -1; public int NodeIndex { get; } = -1; - public IMeshCommon GetMesh() + public VimMesh GetMesh() => _Scene.Meshes.SafeGet(MeshIndex); public int MeshIndex { get; } From 50a2be1a512665f2dfc6f88c73912e3606331733 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 11 Apr 2024 11:05:45 -0400 Subject: [PATCH 042/104] replaced scene extension with methods --- src/cs/vim/Vim.Format.Core/Geometry/IScene.cs | 2 +- .../Geometry/SceneExtensions.cs | 36 ------------------- .../ObjectModel/ObjectModelStore.cs | 8 +++++ .../vim/Vim.Format/SceneBuilder/VimScene.cs | 15 +++++++- .../Vim.Format/SceneBuilder/VimSceneNode.cs | 21 +++++++++-- 5 files changed, 42 insertions(+), 40 deletions(-) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs index c4a6cfbf..e92a45d1 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs @@ -11,7 +11,7 @@ namespace Vim.Format.Geometry public interface IScene { IArray Nodes { get; } - IArray MeshesOld { get; } + VimMesh[] Meshes { get; } } /// diff --git a/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs b/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs deleted file mode 100644 index d59455aa..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/SceneExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Vim.Util; -using Vim.LinqArray; -using Vim.Math3d; -using Vim.G3d; - -namespace Vim.Format.Geometry -{ - public static class SceneExtensions - { - public static IMeshCommon TransformedMesh(this ISceneNode node) - => node.GetMesh()?.Transform(node.Transform); - - public static IEnumerable TransformedMeshes(this IScene scene) - => scene.Nodes.Where(n => n.GetMesh() != null).Select(TransformedMesh); - - public static IMeshCommon MergedGeometry(this IScene scene) - => scene.Nodes.ToEnumerable().MergedGeometry(); - - public static IMeshCommon MergedGeometry(this IEnumerable nodes) - => nodes.Where(n => n.GetMesh() != null).Select(TransformedMesh).ToArray().Merge(); - - public static IEnumerable AllVertices(this IScene scene) - => scene.TransformedMeshes().SelectMany(g => g.Vertices.ToEnumerable()); - - public static AABox BoundingBox(this IScene scene) - => AABox.Create(scene.AllVertices()); - - public static IArray TransformedVertices(this ISceneNode node) - => node.TransformedMesh()?.Vertices; - - public static AABox TransformedBoundingBox(this ISceneNode node) - => AABox.Create(node.TransformedVertices()?.ToEnumerable()); - } -} diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelStore.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelStore.cs index 4cb5d0e5..b2fa3243 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelStore.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelStore.cs @@ -28,6 +28,14 @@ public DocumentBuilder ToDocumentBuilder(string generator, string versionString) .AddMaterials(CreateMaterialBuilders()); } + private IEnumerable CreateMaterialBuilders() + => ObjectModelBuilder.GetEntities().Select(m => new DocumentBuilder.Material() + { + Color = new Vector4((float) m.Color.X, (float) m.Color.Y, (float) m.Color.Z, (float)(1 - m.Transparency)), + Glossiness = (float) m.Glossiness, + Smoothness = (float) m.Smoothness + }); + /// /// Mutates the Meshes and Instances to remove any meshes which are not referenced by at least one instance. /// diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 4bf943b5..f08a3fc9 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -12,6 +12,7 @@ using IVimSceneProgress = System.IProgress<(string, double)>; using Vim.BFastLib; using Vim.G3dNext; +using System.Collections.Generic; namespace Vim { @@ -80,7 +81,19 @@ public string PersistingId public int GetMeshCount() => Meshes.Length; public int GetMaterialCount() => Materials.Length; public int GetShapeCount() => Shapes.Length; - + + public IEnumerable TransformedMeshes() + => VimNodes.Where(n => n.GetMesh() != null).Select(n => n.TransformedMesh()); + + public IMeshCommon MergedGeometry() + => VimNodes.ToEnumerable().MergedGeometry(); + + public IEnumerable AllVertices() + => TransformedMeshes().SelectMany(g => g.Vertices.ToEnumerable()); + + public AABox BoundingBox() + => AABox.Create(AllVertices()); + public Vector4 GetMaterialColor(int materialIndex) => _SerializableDocument.GeometryNext.MaterialColors[materialIndex]; diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 4c4c042b..b1fb8704 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -1,4 +1,6 @@ -using Vim.Format.Geometry; +using System.Collections.Generic; +using System.Linq; +using Vim.Format.Geometry; using Vim.Format.ObjectModel; using Vim.G3d; using Vim.G3dNext; @@ -37,7 +39,7 @@ public bool HideByDefault public int VimIndex { get; } = -1; public int NodeIndex { get; } = -1; - public VimMesh GetMesh() + public VimMesh GetMesh() => _Scene.Meshes.SafeGet(MeshIndex); public int MeshIndex { get; } @@ -55,5 +57,20 @@ public VimMesh GetMesh() VimSceneNode ITransformable3D.Transform(Matrix4x4 mat) => new VimSceneNode(_Scene, Id, MeshIndex, mat * Transform); + + public IMeshCommon TransformedMesh() + => GetMesh()?.Transform(Transform); + + public IArray TransformedVertices() + => TransformedMesh()?.Vertices; + + public AABox TransformedBoundingBox() + => AABox.Create(TransformedVertices()?.ToEnumerable()); + } + + public static class NodeExtensions + { + public static IMeshCommon MergedGeometry(this IEnumerable nodes) + => nodes.Where(n => n.GetMesh() != null).Select(n => n.TransformedMesh()).ToArray().Merge(); } } From 24e7639bdc8ebd450122488be77d785e51b5d10a Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 11 Apr 2024 14:23:12 -0400 Subject: [PATCH 043/104] concrete types instead of interfaces --- src/cs/vim/Vim.Format/SceneBuilder/IScene.cs | 68 +++++++++++++++++++ .../vim/Vim.Format/SceneBuilder/Validation.cs | 4 +- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 21 +++--- .../Vim.Format/SceneBuilder/VimSceneNode.cs | 22 +++--- 4 files changed, 90 insertions(+), 25 deletions(-) create mode 100644 src/cs/vim/Vim.Format/SceneBuilder/IScene.cs diff --git a/src/cs/vim/Vim.Format/SceneBuilder/IScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/IScene.cs new file mode 100644 index 00000000..6001a574 --- /dev/null +++ b/src/cs/vim/Vim.Format/SceneBuilder/IScene.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using Vim.G3d; +using Vim.LinqArray; +using Vim.Math3d; + +namespace Vim.Format.Geometry +{ + /// + /// An IScene is a generic representation of a 3D scene graph. + /// + public interface IScene + { + VimSceneNode[] Nodes { get; } + VimMesh[] Meshes { get; } + } + + /// + /// A node in a scene graph. + /// + public interface ISceneNode + { + int Id { get; } + VimScene Scene { get; } + Matrix4x4 Transform { get; } + int MeshIndex { get; } + VimMesh GetMesh(); + VimSceneNode Parent { get; } + + // TODO: DEPRECATE: this needs to be removed, currently only used in Vim.Max.Bridge. + VimSceneNode[] Children { get; } + } + + public class SceneNodeComparer : EqualityComparer, IComparer + { + public static readonly SceneNodeComparer Instance = new SceneNodeComparer(); + + public int Compare(VimSceneNode x, VimSceneNode y) + => x.Id - y.Id; + public override bool Equals(VimSceneNode x, VimSceneNode y) + => x.Id == y.Id; + public override int GetHashCode(VimSceneNode obj) + => obj.Id; + } + + public class NullNode : ISceneNode + { + public static NullNode Instance = new NullNode(); + public static List ListInstance = new List() { Instance }; + public int Id => -1; + public VimScene Scene => null; + public Matrix4x4 Transform => Matrix4x4.Identity; + public int MeshIndex => 0; + public VimSceneNode Parent => null; + public VimSceneNode[] Children => null; + public VimMesh GetMesh() => null; + } + + public class IdNode : ISceneNode + { + public int Id { get; set; } + public VimScene Scene => null; + public Matrix4x4 Transform => Matrix4x4.Identity; + public int MeshIndex => 0; + public VimSceneNode Parent => null; + public VimSceneNode[] Children => null; + public VimMesh GetMesh() => null; + } +} diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index bba370e1..5eaaf8d1 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -98,8 +98,8 @@ public static void ValidateDocumentModelToG3dInvariantsNext(this VimScene vim) public static void ValidateNodes(this VimScene vim) { - if (vim.VimNodes.Count != vim.DocumentModel.NumNode) - throw new VimValidationException($"The number of {nameof(VimSceneNode)} ({vim.VimNodes.Count}) does not match the number of node entities ({vim.DocumentModel.NumNode})"); + if (vim.GetNodeCount() != vim.DocumentModel.NumNode) + throw new VimValidationException($"The number of {nameof(VimSceneNode)} ({vim.GetNodeCount()}) does not match the number of node entities ({vim.DocumentModel.NumNode})"); } public static void ValidateShapes(this VimScene vim) diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index f08a3fc9..567c8b95 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -60,8 +60,7 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, => LoadVim(stream, new LoadOptions { SkipGeometry = skipGeometry, SkipAssets = skipAssets}, progress, inParallel); public int VimIndex { get; set; } - public IArray Nodes { get; private set; } - public IArray VimNodes { get; private set; } + public VimSceneNode[] Nodes { get; private set; } public VimMesh[] Meshes { get; private set; } public VimShapeNext[] Shapes { get; private set; } @@ -81,12 +80,13 @@ public string PersistingId public int GetMeshCount() => Meshes.Length; public int GetMaterialCount() => Materials.Length; public int GetShapeCount() => Shapes.Length; + public int GetNodeCount() => Nodes.Length; public IEnumerable TransformedMeshes() - => VimNodes.Where(n => n.GetMesh() != null).Select(n => n.TransformedMesh()); + => Nodes.Where(n => n.GetMesh() != null).Select(n => n.TransformedMesh()); public IMeshCommon MergedGeometry() - => VimNodes.ToEnumerable().MergedGeometry(); + => Nodes.MergedGeometry(); public IEnumerable AllVertices() => TransformedMeshes().SelectMany(g => g.Vertices.ToEnumerable()); @@ -226,8 +226,7 @@ private void CreateScene(bool inParallel) return; } - VimNodes = CreateVimSceneNodes(this, _SerializableDocument.Geometry, inParallel); - Nodes = VimNodes.Select(n => n as ISceneNode); + Nodes = CreateVimSceneNodes(this, _SerializableDocument.Geometry, inParallel); } private void CreateMaterials(bool inParallel) @@ -243,14 +242,12 @@ private void CreateMaterials(bool inParallel) } - public static IArray CreateVimSceneNodes(VimScene scene, G3D g3d, bool inParallel) + public static VimSceneNode[] CreateVimSceneNodes(VimScene scene, G3D g3d, bool inParallel) { Matrix4x4 GetMatrix(int i) => i >= 0 ? g3d.InstanceTransforms[i] : Matrix4x4.Identity; - var r = g3d.InstanceTransforms.Select((_, i) => - new VimSceneNode(scene, i, g3d.InstanceMeshes[i], GetMatrix(i))); - - return inParallel ? r.EvaluateInParallel() : r.Evaluate(); + return g3d.InstanceTransforms.Select((_, i) => + new VimSceneNode(scene, i, g3d.InstanceMeshes[i], GetMatrix(i))).ToArray(); } public void Save(string filePath) @@ -263,7 +260,7 @@ public void TransformSceneInPlace(Func meshTransform = null, F if (meshTransform != null) Meshes = Meshes.Select(meshTransform).ToArray(); if (nodeTransform != null) - VimNodes = VimNodes.Select(nodeTransform).EvaluateInParallel(); + Nodes = Nodes.Select(nodeTransform).ToArray(); } public string GetElementName(int elementIndex, string missing = "") diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index b1fb8704..47bed5a6 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Vim.Format.Geometry; using Vim.Format.ObjectModel; @@ -15,15 +16,14 @@ public VimSceneNode(VimScene scene, int nodeIndex, int geometryIndex, Matrix4x4 : base(scene.DocumentModel, scene.DocumentModel.GetNodeElementIndex(nodeIndex)) { VimIndex = scene.VimIndex; - _Scene = scene; + Scene = scene; Transform = transform; MeshIndex = geometryIndex; NodeIndex = nodeIndex; } - public VimScene _Scene { get; } + public VimScene Scene { get; } - public IScene Scene => _Scene; public int Id => NodeIndex; public Matrix4x4 Transform { get; } @@ -31,7 +31,7 @@ public bool HideByDefault { get { - var instanceFlags = (InstanceFlags)_Scene.Document.Geometry.InstanceFlags.ElementAtOrDefault(NodeIndex); + var instanceFlags = (InstanceFlags)Scene.Document.Geometry.InstanceFlags.ElementAtOrDefault(NodeIndex); return (instanceFlags & InstanceFlags.Hidden) == InstanceFlags.Hidden; } } @@ -40,23 +40,23 @@ public bool HideByDefault public int NodeIndex { get; } = -1; public VimMesh GetMesh() - => _Scene.Meshes.SafeGet(MeshIndex); + => Scene.Meshes.SafeGet(MeshIndex); public int MeshIndex { get; } public bool HasMesh => MeshIndex != -1; - public Node NodeModel => _Scene.DocumentModel.GetNode(Id); - public Geometry GeometryModel => _Scene.DocumentModel.GetGeometry(MeshIndex); + public Node NodeModel => Scene.DocumentModel.GetNode(Id); + public Geometry GeometryModel => Scene.DocumentModel.GetGeometry(MeshIndex); // TODO: I think this should be "IEnumerable" in the interface - public ISceneNode Parent => null; - public IArray Children => LinqArray.LinqArray.Empty(); + public VimSceneNode Parent => null; + public VimSceneNode[] Children => Array.Empty(); public string DisciplineName => VimSceneHelpers.GetDisiplineFromCategory(CategoryName); VimSceneNode ITransformable3D.Transform(Matrix4x4 mat) - => new VimSceneNode(_Scene, Id, MeshIndex, mat * Transform); + => new VimSceneNode(Scene, Id, MeshIndex, mat * Transform); public IMeshCommon TransformedMesh() => GetMesh()?.Transform(Transform); From f7ce65b990d9ebc522b77cdfa6a1cc93fe52b668 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 11 Apr 2024 15:21:17 -0400 Subject: [PATCH 044/104] removing iscene and iscenenode --- src/cs/vim/Vim.Format.Core/Geometry/IScene.cs | 68 ------------------- src/cs/vim/Vim.Format/SceneBuilder/IScene.cs | 68 ------------------- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 2 +- .../Vim.Format/SceneBuilder/VimSceneNode.cs | 2 +- 4 files changed, 2 insertions(+), 138 deletions(-) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/IScene.cs delete mode 100644 src/cs/vim/Vim.Format/SceneBuilder/IScene.cs diff --git a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs b/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs deleted file mode 100644 index e92a45d1..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/IScene.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Collections.Generic; -using Vim.G3d; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - /// - /// An IScene is a generic representation of a 3D scene graph. - /// - public interface IScene - { - IArray Nodes { get; } - VimMesh[] Meshes { get; } - } - - /// - /// A node in a scene graph. - /// - public interface ISceneNode - { - int Id { get; } - IScene Scene { get; } - Matrix4x4 Transform { get; } - int MeshIndex { get; } - VimMesh GetMesh(); - ISceneNode Parent { get; } - - // TODO: DEPRECATE: this needs to be removed, currently only used in Vim.Max.Bridge. - IArray Children { get; } - } - - public class SceneNodeComparer : EqualityComparer, IComparer - { - public static readonly SceneNodeComparer Instance = new SceneNodeComparer(); - - public int Compare(ISceneNode x, ISceneNode y) - => x.Id - y.Id; - public override bool Equals(ISceneNode x, ISceneNode y) - => x.Id == y.Id; - public override int GetHashCode(ISceneNode obj) - => obj.Id; - } - - public class NullNode : ISceneNode - { - public static NullNode Instance = new NullNode(); - public static List ListInstance = new List() { Instance }; - public int Id => -1; - public IScene Scene => null; - public Matrix4x4 Transform => Matrix4x4.Identity; - public int MeshIndex => 0; - public ISceneNode Parent => null; - public IArray Children => null; - public VimMesh GetMesh() => null; - } - - public class IdNode : ISceneNode - { - public int Id { get; set; } - public IScene Scene => null; - public Matrix4x4 Transform => Matrix4x4.Identity; - public int MeshIndex => 0; - public ISceneNode Parent => null; - public IArray Children => null; - public VimMesh GetMesh() => null; - } -} diff --git a/src/cs/vim/Vim.Format/SceneBuilder/IScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/IScene.cs deleted file mode 100644 index 6001a574..00000000 --- a/src/cs/vim/Vim.Format/SceneBuilder/IScene.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Collections.Generic; -using Vim.G3d; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - /// - /// An IScene is a generic representation of a 3D scene graph. - /// - public interface IScene - { - VimSceneNode[] Nodes { get; } - VimMesh[] Meshes { get; } - } - - /// - /// A node in a scene graph. - /// - public interface ISceneNode - { - int Id { get; } - VimScene Scene { get; } - Matrix4x4 Transform { get; } - int MeshIndex { get; } - VimMesh GetMesh(); - VimSceneNode Parent { get; } - - // TODO: DEPRECATE: this needs to be removed, currently only used in Vim.Max.Bridge. - VimSceneNode[] Children { get; } - } - - public class SceneNodeComparer : EqualityComparer, IComparer - { - public static readonly SceneNodeComparer Instance = new SceneNodeComparer(); - - public int Compare(VimSceneNode x, VimSceneNode y) - => x.Id - y.Id; - public override bool Equals(VimSceneNode x, VimSceneNode y) - => x.Id == y.Id; - public override int GetHashCode(VimSceneNode obj) - => obj.Id; - } - - public class NullNode : ISceneNode - { - public static NullNode Instance = new NullNode(); - public static List ListInstance = new List() { Instance }; - public int Id => -1; - public VimScene Scene => null; - public Matrix4x4 Transform => Matrix4x4.Identity; - public int MeshIndex => 0; - public VimSceneNode Parent => null; - public VimSceneNode[] Children => null; - public VimMesh GetMesh() => null; - } - - public class IdNode : ISceneNode - { - public int Id { get; set; } - public VimScene Scene => null; - public Matrix4x4 Transform => Matrix4x4.Identity; - public int MeshIndex => 0; - public VimSceneNode Parent => null; - public VimSceneNode[] Children => null; - public VimMesh GetMesh() => null; - } -} diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 567c8b95..9a890d64 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -21,7 +21,7 @@ namespace Vim /// /// This is the top-level class of a loaded VIM file. /// - public class VimScene : IScene + public class VimScene { /// /// Returns the VIM file's header schema version. Returns null if the Vim has no header. diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 47bed5a6..9d2eba2b 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -10,7 +10,7 @@ namespace Vim { - public sealed class VimSceneNode : ElementInfo, ISceneNode, ITransformable3D + public sealed class VimSceneNode : ElementInfo, ITransformable3D { public VimSceneNode(VimScene scene, int nodeIndex, int geometryIndex, Matrix4x4 transform) : base(scene.DocumentModel, scene.DocumentModel.GetNodeElementIndex(nodeIndex)) From 4f75adb4ab45e17ca3c32613bee026c9530bd5b5 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 11 Apr 2024 16:19:13 -0400 Subject: [PATCH 045/104] removed assimp project --- .../Vim.G3d.AssimpWrapper/AssimpExtensions.cs | 103 ------------------ .../g3d/Vim.G3d.AssimpWrapper/AssimpLoader.cs | 36 ------ .../Vim.G3d.AssimpWrapper.csproj | 21 ---- src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj | 1 - src/cs/vim-format.sln | 9 +- 5 files changed, 1 insertion(+), 169 deletions(-) delete mode 100644 src/cs/g3d/Vim.G3d.AssimpWrapper/AssimpExtensions.cs delete mode 100644 src/cs/g3d/Vim.G3d.AssimpWrapper/AssimpLoader.cs delete mode 100644 src/cs/g3d/Vim.G3d.AssimpWrapper/Vim.G3d.AssimpWrapper.csproj diff --git a/src/cs/g3d/Vim.G3d.AssimpWrapper/AssimpExtensions.cs b/src/cs/g3d/Vim.G3d.AssimpWrapper/AssimpExtensions.cs deleted file mode 100644 index 80e26239..00000000 --- a/src/cs/g3d/Vim.G3d.AssimpWrapper/AssimpExtensions.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.Linq; -using Assimp; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.G3d.AssimpWrapper -{ - public static class AssimpExtensions - { - public static Vector2 ToMath3D(this Vector2D v) - => new Vector2(v.X, v.Y); - - public static Vector3 ToMath3D(this Vector3D v) - => new Vector3(v.X, v.Y, v.Z); - - public static Vector3 ToMath3D(this Color3D v) - => new Vector3(v.R, v.G, v.B); - - public static Vector4 ToMath3D(this Color4D v) - => new Vector4(v.R, v.G, v.B, v.A); - - public static Math3d.Matrix4x4 ToMath3D(this Assimp.Matrix4x4 m) - => new Math3d.Matrix4x4( - m.A1, m.A2, m.A3, m.A4, - m.B1, m.B2, m.B3, m.B4, - m.C1, m.C2, m.C3, m.C4, - m.D1, m.D2, m.D3, m.D4); - - public static bool IsTriangular(this Mesh mesh) - => mesh.Faces.All(f => f.IndexCount == 3); - - public static G3D ToG3d(this Scene scene) - { - var meshes = scene.Meshes.Select(m => m.ToG3D()).ToIArray(); - var nodes = scene.GetNodes().ToIArray(); - if (nodes.Count == 0 || nodes.Count == 1) - return meshes.Count > 0 ? meshes[0] : G3D.Empty; - - var mergedAttributes = meshes.Merge().Attributes.ToList(); - - var subGeoTransforms = nodes.Select(n => n.Transform.ToMath3D()).ToInstanceTransformAttribute(); - mergedAttributes.Add(subGeoTransforms); - - var meshIndices = nodes.Select(n => n.MeshIndex).ToInstanceMeshAttribute(); - mergedAttributes.Add(meshIndices); - - return mergedAttributes.ToG3d(); - } - - public static G3D ToG3D(this Mesh mesh) - { - // The Assimp mesh must be triangulated - if (mesh.FaceCount == 0) - return G3D.Empty; - - var bldr = new G3DBuilder(); - - // Note: should be at most 3 for meses, but could 2 for lines, or 1 for point clouds - var numCornersPerFace = mesh.Faces[0].IndexCount; - if (numCornersPerFace > 3) - throw new Exception("The Assimp mesh must be triangulated as a post-process"); - if (numCornersPerFace <= 0) - throw new Exception("The Assimp mesh has faces without indices"); - foreach (var f in mesh.Faces) - { - if (f.IndexCount != numCornersPerFace) - throw new Exception($"Each face of the assimp mesh must have {numCornersPerFace} corners, but found one with {f.IndexCount}"); - } - bldr.SetObjectFaceSize(numCornersPerFace); - - var indices = mesh.GetIndices(); - if (indices.Length % numCornersPerFace != 0) - throw new Exception($"The mesh index buffer length {indices.Length} is not divisible by {numCornersPerFace}"); - - bldr.AddVertices(mesh.Vertices.ToIArray().Select(ToMath3D)); - bldr.AddIndices(indices); - - if (mesh.HasTangentBasis) - bldr.Add(mesh.BiTangents.ToIArray().Select(ToMath3D).ToVertexBitangentAttribute()); - - if (mesh.HasTangentBasis) - bldr.Add(mesh.Tangents.ToIArray().Select(x => ToMath3D(x).ToVector4()).ToVertexTangentAttribute()); - - if (mesh.HasNormals) - bldr.Add(mesh.Normals.ToIArray().Select(ToMath3D).ToVertexNormalAttribute()); - - for (var i = 0; i < mesh.TextureCoordinateChannelCount; ++i) - { - var uvChannel = mesh.TextureCoordinateChannels[i]; - bldr.Add(uvChannel.ToIArray().Select(ToMath3D).ToVertexUvwAttribute(i)); - } - - for (var i = 0; i < mesh.VertexColorChannelCount; ++i) - { - var vcChannel = mesh.VertexColorChannels[i]; - bldr.Add(vcChannel.ToIArray().Select(ToMath3D).ToVertexColorAttribute(i)); - } - - return bldr.ToG3D(); - } - } -} diff --git a/src/cs/g3d/Vim.G3d.AssimpWrapper/AssimpLoader.cs b/src/cs/g3d/Vim.G3d.AssimpWrapper/AssimpLoader.cs deleted file mode 100644 index bb0387be..00000000 --- a/src/cs/g3d/Vim.G3d.AssimpWrapper/AssimpLoader.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Assimp; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Vim.LinqArray; - -namespace Vim.G3d.AssimpWrapper -{ - public static class AssimpLoader - { - public static AssimpContext Context = new AssimpContext(); - - public class AssimpNode - { - public int MeshIndex { get; } - public Matrix4x4 Transform { get; } - public AssimpNode(int index, Matrix4x4 transform) - => (MeshIndex, Transform) = (index, transform); - } - - public static IEnumerable GetNodes(this Scene scene) - => scene == null || scene.RootNode == null - ? Enumerable.Empty() - : GetNodes(scene, scene.RootNode, scene.RootNode.Transform); - - public static IEnumerable GetNodes(this Scene scene, Node node, Matrix4x4 transform) - => node.MeshIndices.Select(idx => new AssimpNode(idx, node.Transform)) - .Concat(node.Children.SelectMany(c => GetNodes(scene, c, transform * c.Transform))); - - public static Scene Load(string filePath, bool triangulate = true) - => Context.ImportFile(filePath, triangulate ? PostProcessSteps.Triangulate : PostProcessSteps.None); - - public static bool CanLoad(string filePath) - => Context.IsImportFormatSupported(Path.GetExtension(filePath)); - } -} diff --git a/src/cs/g3d/Vim.G3d.AssimpWrapper/Vim.G3d.AssimpWrapper.csproj b/src/cs/g3d/Vim.G3d.AssimpWrapper/Vim.G3d.AssimpWrapper.csproj deleted file mode 100644 index 3b567b9f..00000000 --- a/src/cs/g3d/Vim.G3d.AssimpWrapper/Vim.G3d.AssimpWrapper.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - netstandard2.0 - Vim.G3d.AssimpWrapper - - - - - - - - - - - - True - - - - diff --git a/src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj b/src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj index ae2d33e9..af8be97d 100644 --- a/src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj +++ b/src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj @@ -12,7 +12,6 @@ - diff --git a/src/cs/vim-format.sln b/src/cs/vim-format.sln index a75b5a5b..d003f17e 100644 --- a/src/cs/vim-format.sln +++ b/src/cs/vim-format.sln @@ -27,8 +27,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3d.Tests", "g3d\Vim.G3 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3d", "g3d\Vim.G3d\Vim.G3d.csproj", "{F1EC1E94-C74C-4C37-961C-305CAE7C4707}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3d.AssimpWrapper", "g3d\Vim.G3d.AssimpWrapper\Vim.G3d.AssimpWrapper.csproj", "{16DBF49F-3E0C-4CD3-BB6C-1BBAF0D89AC6}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Format.CodeGen", "vim\Vim.Format.CodeGen\Vim.Format.CodeGen.csproj", "{762E8B1A-9182-4C5D-A25C-0C0F6219BA4E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Format.Tests", "vim\Vim.Format.Tests\Vim.Format.Tests.csproj", "{2CB4CF73-0CA8-4595-910C-EDA244EA5983}" @@ -57,7 +55,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.BFast.Tests", "bfast\Vi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Format.Vimx.Conversion", "vim\Vim.Format.Vimx.Conversion\Vim.Format.Vimx.Conversion.csproj", "{4C4F9826-0DEF-4A39-BFC8-A834522694A0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vim.G3dNext.Tests", "Vim.G3dNext.Tests\Vim.G3dNext.Tests.csproj", "{AD1A2A9F-18E9-4430-A192-3CD1A17DDA0D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3dNext.Tests", "Vim.G3dNext.Tests\Vim.G3dNext.Tests.csproj", "{AD1A2A9F-18E9-4430-A192-3CD1A17DDA0D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -93,10 +91,6 @@ Global {F1EC1E94-C74C-4C37-961C-305CAE7C4707}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1EC1E94-C74C-4C37-961C-305CAE7C4707}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1EC1E94-C74C-4C37-961C-305CAE7C4707}.Release|Any CPU.Build.0 = Release|Any CPU - {16DBF49F-3E0C-4CD3-BB6C-1BBAF0D89AC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {16DBF49F-3E0C-4CD3-BB6C-1BBAF0D89AC6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {16DBF49F-3E0C-4CD3-BB6C-1BBAF0D89AC6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {16DBF49F-3E0C-4CD3-BB6C-1BBAF0D89AC6}.Release|Any CPU.Build.0 = Release|Any CPU {762E8B1A-9182-4C5D-A25C-0C0F6219BA4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {762E8B1A-9182-4C5D-A25C-0C0F6219BA4E}.Debug|Any CPU.Build.0 = Debug|Any CPU {762E8B1A-9182-4C5D-A25C-0C0F6219BA4E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -165,7 +159,6 @@ Global {22278D91-27D7-4A84-8170-5FFB77A70C1F} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} {DFC8DC5E-377D-4CCC-A498-5894D891A471} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} {F1EC1E94-C74C-4C37-961C-305CAE7C4707} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} - {16DBF49F-3E0C-4CD3-BB6C-1BBAF0D89AC6} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} {762E8B1A-9182-4C5D-A25C-0C0F6219BA4E} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} {2CB4CF73-0CA8-4595-910C-EDA244EA5983} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} {2C798994-518D-4EA5-8F8A-3EAA30269F9E} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} From ede5f3367e33105d7056ffaf1c5ca385854b86ca Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 11 Apr 2024 16:19:26 -0400 Subject: [PATCH 046/104] removed g3dtest project --- src/cs/g3d/Vim.G3d.Tests/G3dTests.cs | 315 ------------------ .../Properties/Resources.Designer.cs | 73 ---- .../Vim.G3d.Tests/Properties/Resources.resx | 124 ------- src/cs/g3d/Vim.G3d.Tests/Resources/.gitignore | 1 - src/cs/g3d/Vim.G3d.Tests/Util.cs | 76 ----- src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj | 44 --- 6 files changed, 633 deletions(-) delete mode 100644 src/cs/g3d/Vim.G3d.Tests/G3dTests.cs delete mode 100644 src/cs/g3d/Vim.G3d.Tests/Properties/Resources.Designer.cs delete mode 100644 src/cs/g3d/Vim.G3d.Tests/Properties/Resources.resx delete mode 100644 src/cs/g3d/Vim.G3d.Tests/Resources/.gitignore delete mode 100644 src/cs/g3d/Vim.G3d.Tests/Util.cs delete mode 100644 src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj diff --git a/src/cs/g3d/Vim.G3d.Tests/G3dTests.cs b/src/cs/g3d/Vim.G3d.Tests/G3dTests.cs deleted file mode 100644 index fa9f38ed..00000000 --- a/src/cs/g3d/Vim.G3d.Tests/G3dTests.cs +++ /dev/null @@ -1,315 +0,0 @@ -using Assimp; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Vim.BFastLib; -using Vim.G3d.AssimpWrapper; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.G3d.Tests -{ - [TestFixture] - public static class G3dTests - { - public class FileLoadData - { - public FileLoadData(string filePath) - => SourceFile = new FileInfo(filePath); - - public string ShortName => Path.GetFileName(SourceFile.FullName); - public int NumMeshes => Scene?.MeshCount ?? 0; - public FileInfo SourceFile; - public FileInfo G3DFile; - public long MSecToOpen; - public long MSecToSaveG3d; - public long MSecToOpenG3d; - public long MSecToConvert; - public long MemoryConsumption; - public long MemoryConsumptionG3d; - public Exception Error; - public Scene Scene; - public G3D G3d; - } - - public static readonly string ProjectFolder = new DirectoryInfo(Properties.Resources.ProjDir.Trim()).FullName; - public static string RootFolder = Path.Combine(ProjectFolder, "..", "..", "..", ".."); - public static string TestInputFolder = Path.Combine(RootFolder, "data", "g3d-test-data", "models"); - public static string TestOutputFolder = Path.Combine(RootFolder, "data", "g3d-test-data", "output"); - - [SetUp] - public static void Setup() - { - if (!Directory.Exists(RootFolder)) - { - Directory.CreateDirectory(RootFolder); - } - if (!Directory.Exists(TestInputFolder)) - { - Directory.CreateDirectory(TestInputFolder); - } - if (!Directory.Exists(TestOutputFolder)) - { - Directory.CreateDirectory(TestOutputFolder); - } - } - - public static IEnumerable GetInputFiles() - => Directory.GetFiles(TestInputFolder, "*.*", SearchOption.AllDirectories); - - public static void ValidateSame(Object a, Object b, string name = "") - { - if (!a.Equals(b)) - throw new Exception($"Values {a} and {b} are different {name}"); - } - - public static void ValidateSameG3D(G3D g1, G3D g2) - { - ValidateSame(g1.NumCornersPerFace, g2.NumCornersPerFace, "NumCornersPerFace"); - ValidateSame(g1.NumFaces, g2.NumFaces, "NumFaces"); - ValidateSame(g1.NumCorners, g2.NumCorners, "NumCorners"); - ValidateSame(g1.NumVertices, g2.NumVertices, "NumVertices"); - ValidateSame(g1.NumInstances, g2.NumInstances, "NumInstances"); - ValidateSame(g1.NumMeshes, g2.NumMeshes, "NumMeshes"); - ValidateSame(g1.Attributes.Count, g2.Attributes.Count, "NumAttributes"); - for (var i = 0; i < g1.Attributes.Count; ++i) - { - var attr1 = g1.Attributes[i]; - var attr2 = g2.Attributes[i]; - ValidateSame(attr1.Name, attr2.Name, $"Attribute[{i}].Name"); - ValidateSame(attr1.GetByteSize(), attr2.GetByteSize(), $"Attribute[{i}].ByteSize"); - ValidateSame(attr1.ElementCount, attr2.ElementCount, $"Attribute[{i}].ElementCount"); - } - } - - [Test] - [Platform(Exclude = "Linux,Unix", Reason = "AssimpNet is failing to load its dependency on 'libdl.so'.")] - public static void OpenAndConvertAssimpFiles() - { - var files = GetInputFiles() - .Where(AssimpLoader.CanLoad) - .Select(f => new FileLoadData(f)) - .ToArray(); - - // Load all the files - foreach (var f in files) - { - try - { - (f.MemoryConsumption, f.MSecToOpen) = - Util.GetMemoryConsumptionAndMSecElapsed(() => - f.Scene = AssimpLoader.Load(f.SourceFile.FullName)); - } - catch (Exception e) - { - f.Error = e; - } - } - - // Convert all the Assimp scenes to G3D - foreach (var f in files) - { - if (f.Scene == null) continue; - - try - { - f.MSecToConvert = Util.GetMSecElapsed(() => - f.G3d = f.Scene.ToG3d()); - } - catch (Exception e) - { - f.Error = e; - } - } - - // Save all the G3D scenes - Util.CreateAndClearDirectory(TestOutputFolder); - foreach (var f in files) - { - if (f.G3d == null) continue; - - try - { - var outputFilePath = Path.Combine(TestOutputFolder, f.ShortName + ".g3d"); - f.G3DFile = new FileInfo(outputFilePath); - - f.MSecToSaveG3d = Util.GetMSecElapsed(() => - f.G3d.ToBFast().Write(outputFilePath)); - } - catch (Exception e) - { - f.Error = e; - } - } - - // Try reading back in all of the G3D scenes, measure load times and the memory consumption - foreach (var f in files) - { - if (f.G3DFile == null) continue; - - try - { - G3D localG3d = null; - - (f.MemoryConsumptionG3d, f.MSecToOpenG3d) = - Util.GetMemoryConsumptionAndMSecElapsed(() => - localG3d = G3D.Read(f.G3DFile.FullName)); - - ValidateSameG3D(f.G3d, localG3d); - } - catch (Exception e) - { - f.Error = e; - } - } - - // Output the header for data - Console.WriteLine( - "Importer," + - "Extension," + - "File Name," + - "File Size(KB)," + - "Load Time(s)," + - "Memory(KB)," + - "# Meshes," + - "Time to Convert," + - "Time to Write G3D," + - "G3D File Size(KB)," + - "G3D Memory(KB)", - "G3D Load Time(s)", - "Error"); - - // Output the data rows - foreach (var f in files) - { - Console.WriteLine( - "Assimp," + - $"{Path.GetExtension(f.ShortName)}," + - $"{f.ShortName}," + - $"{f.SourceFile?.Length / 1000}," + - $"{f.MSecToOpen / 100f}," + - $"{f.MemoryConsumption / 1000}," + - $"{f.NumMeshes}," + - $"{f.MSecToConvert / 100f}," + - $"{f.MSecToSaveG3d / 100f}," + - $"{f.G3DFile?.Length / 1000}," + - $"{f.MemoryConsumptionG3d / 1000}," + - $"{f.MSecToOpenG3d / 100f}," + - $"{f.Error}"); - } - - Assert.AreEqual(0, files.Count(f => f.Error != null), "Errors occurred"); - } - - [Test] - public static void TriangleTest() - { - // Serialize a triangle g3d as bytes and read it back. - var vertices = new[] - { - new Vector3(0, 0, 0), - new Vector3(0, 1, 0), - new Vector3(0, 1, 1) - }; - - var indices = new[] { 0, 1, 2 }; - var materialIndices = new[] { 5 }; - - var g3d = new G3DBuilder() - .AddVertices(vertices.ToIArray()) - .AddIndices(indices.ToIArray()) - .Add(materialIndices.ToIArray().ToFaceMaterialAttribute()) - .ToG3D(); - - var bfast = g3d.ToBFast(); - var g = G3D.Read(bfast); - - Assert.IsNotNull(g); - - Assert.AreEqual(3, g.NumVertices); - Assert.AreEqual(3, g.NumCorners); - Assert.AreEqual(1, g.NumFaces); - Assert.AreEqual(3, g.NumCornersPerFace); - Assert.AreEqual(0, g.NumMeshes); - Assert.AreEqual(0, g.NumInstances); - - Assert.AreEqual(vertices, g.Vertices.ToArray()); - Assert.AreEqual(indices, g.Indices.ToArray()); - Assert.AreEqual(materialIndices, g.FaceMaterials.ToArray()); - } - - [Test] - public static void UnexpectedAttributes_Are_Ignored() - { - var bfast = new BFast(); - bfast.SetArray("g3d:instance:potato:0:int32:1", new int[] { 5 }); - - var g = G3D.Read(bfast); - var parsedInstanceAttrs = g.Attributes.Where(ga => ga.Descriptor.Association == Association.assoc_instance).ToArray(); - var parsedPotatoAttr = parsedInstanceAttrs.Single(ga => ga.Descriptor.Semantic == "potato"); - Assert.AreEqual(new [] { 5 }, parsedPotatoAttr.AsType().Data.ToArray()); - } - - public static G3D LoadAssimpFile(string filePath) - { - using (var context = new AssimpContext()) - { - var scene = context.ImportFile(filePath); - Assert.AreEqual(1, scene.Meshes.Count); - return scene.Meshes[0].ToG3D(); - } - } - - // NOTE: can't be run as part of NUnit because it requires the GC - public static void BigFileTest() - { - var nVerts = (300 * 1000 * 1000); // 300 * 12 = 3.6 GB - var vertices = nVerts.Select(i => new Vector3(i, i, i)); - var bldr = new G3DBuilder(); - bldr.AddVertices(vertices); - - var expectedG3d = bldr.ToG3D(); - Assert.AreEqual(nVerts, expectedG3d.NumVertices); - var bfast = expectedG3d.ToBFast(); - var resultG3d = G3D.Read(bfast); - - ValidateSameG3D(expectedG3d, resultG3d); - } - - [Test, Explicit] - [Platform(Exclude = "Linux,Unix", Reason = "AssimpNet is failing to load its dependency on 'libdl.so'.")] - public static void TestWriters() - { - var fileName = Path.Combine(TestInputFolder, "PLY", "Wuson.ply"); - - var outputFileName = @"test"; - outputFileName = Path.Combine(TestOutputFolder, outputFileName); - - var g3d = LoadAssimpFile(fileName); - - g3d.WritePly(outputFileName + ".ply"); - g3d.WriteObj(outputFileName + ".obj"); - - // TODO compare the PLY, the OBJ and the original file. - - var g3dFromPly = LoadAssimpFile(outputFileName + ".ply"); - //var g3dFromObj = LoadAssimpFile(outputFileName + ".obj"); - - { - var g1 = g3d; - var g2 = g3dFromPly; - Assert.AreEqual(g1.NumCornersPerFace, g2.NumCornersPerFace); - Assert.AreEqual(g1.NumFaces, g2.NumFaces); - Assert.AreEqual(g1.NumCorners, g2.NumCorners); - Assert.AreEqual(g1.NumVertices, g2.NumVertices); - Assert.AreEqual(g1.NumInstances, g2.NumInstances); - Assert.AreEqual(g1.NumMeshes, g2.NumMeshes); - } - - // BUG: Assimp ignores the OBJ index buffer. God knows why. - //CompareG3D(g3d, g3dFromObj); - } - } -} diff --git a/src/cs/g3d/Vim.G3d.Tests/Properties/Resources.Designer.cs b/src/cs/g3d/Vim.G3d.Tests/Properties/Resources.Designer.cs deleted file mode 100644 index dba826c3..00000000 --- a/src/cs/g3d/Vim.G3d.Tests/Properties/Resources.Designer.cs +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Vim.G3d.Tests.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Vim.G3d.Tests.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to C:\Users\Rober\Desktop\Vim\vim-format\src\cs\g3d\Vim.G3d.Tests\ - ///. - /// - internal static string ProjDir { - get { - return ResourceManager.GetString("ProjDir", resourceCulture); - } - } - } -} diff --git a/src/cs/g3d/Vim.G3d.Tests/Properties/Resources.resx b/src/cs/g3d/Vim.G3d.Tests/Properties/Resources.resx deleted file mode 100644 index 579dd3b6..00000000 --- a/src/cs/g3d/Vim.G3d.Tests/Properties/Resources.resx +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - ..\Resources\ProjDir.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - \ No newline at end of file diff --git a/src/cs/g3d/Vim.G3d.Tests/Resources/.gitignore b/src/cs/g3d/Vim.G3d.Tests/Resources/.gitignore deleted file mode 100644 index d8fff56a..00000000 --- a/src/cs/g3d/Vim.G3d.Tests/Resources/.gitignore +++ /dev/null @@ -1 +0,0 @@ -ProjDir.txt \ No newline at end of file diff --git a/src/cs/g3d/Vim.G3d.Tests/Util.cs b/src/cs/g3d/Vim.G3d.Tests/Util.cs deleted file mode 100644 index 2ff62684..00000000 --- a/src/cs/g3d/Vim.G3d.Tests/Util.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Linq; - -namespace Vim.G3d.Tests -{ - public static class Util - { - public static (long, long) GetMemoryConsumptionAndMSecElapsed(Action action) - { - var time = 0L; - var mem = GetMemoryConsumption( - () => time = GetMSecElapsed(action)); - return (mem, time); - } - - public static long GetMSecElapsed(Action action) - { - var sw = Stopwatch.StartNew(); - action(); - return sw.ElapsedMilliseconds; - } - - /// - /// Creates a directory if needed, or clears all of its contents otherwise - /// - public static string CreateAndClearDirectory(string dirPath) - { - if (!Directory.Exists(dirPath)) - Directory.CreateDirectory(dirPath); - else - DeleteFolderContents(dirPath); - return dirPath; - } - - /// - /// Deletes all contents in a folder - /// - /// - /// https://stackoverflow.com/questions/1288718/how-to-delete-all-files-and-folders-in-a-directory - /// - private static void DeleteFolderContents(string folderPath) - { - var di = new DirectoryInfo(folderPath); - foreach (var dir in di.EnumerateDirectories().AsParallel()) - DeleteFolderAndAllContents(dir.FullName); - foreach (var file in di.EnumerateFiles().AsParallel()) - file.Delete(); - } - - /// - /// Deletes everything in a folder and then the folder. - /// - private static void DeleteFolderAndAllContents(string folderPath) - { - if (!Directory.Exists(folderPath)) - return; - - DeleteFolderContents(folderPath); - Directory.Delete(folderPath); - } - - // NOTE: Calling a function generates additional memory - private static long GetMemoryConsumption(Action action) - { - GC.Collect(); - GC.WaitForPendingFinalizers(); - var memBefore = GC.GetTotalMemory(true); - action(); - GC.Collect(); - GC.WaitForPendingFinalizers(); - return GC.GetTotalMemory(true) - memBefore; - } - } -} \ No newline at end of file diff --git a/src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj b/src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj deleted file mode 100644 index af8be97d..00000000 --- a/src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj +++ /dev/null @@ -1,44 +0,0 @@ - - - - net6.0 - false - - - - - - - - - - - - - - - - - True - True - Resources.resx - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - - - - - True - - - - From 068c522216a58ef34e8206ba12b1f57327670cb0 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 11 Apr 2024 16:59:43 -0400 Subject: [PATCH 047/104] removed g3d builder --- src/cs/g3d/Vim.G3d/G3DBuilder.cs | 39 -------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/cs/g3d/Vim.G3d/G3DBuilder.cs diff --git a/src/cs/g3d/Vim.G3d/G3DBuilder.cs b/src/cs/g3d/Vim.G3d/G3DBuilder.cs deleted file mode 100644 index 6d68cb99..00000000 --- a/src/cs/g3d/Vim.G3d/G3DBuilder.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Collections.Generic; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.G3d -{ - /// - /// This is a helper class for constructing a G3D from individual attributes - /// - public class G3DBuilder - { - public readonly List Attributes = new List(); - - public G3D ToG3D(G3dHeader? header = null) - => new G3D(Attributes, header ?? G3dHeader.Default); - - public G3DBuilder Add(GeometryAttribute attr) - { - Attributes.Add(attr); - return this; - } - - public G3DBuilder AddIndices(int[] indices) - => Add(indices.ToIndexAttribute()); - - public G3DBuilder AddIndices(IArray indices) - => Add(indices.ToIndexAttribute()); - - public G3DBuilder SetObjectFaceSize(int objectFaceSize) - => Add(new[] { objectFaceSize }.ToIArray().ToObjectFaceSizeAttribute()); - - public G3DBuilder AddVertices(IArray vertices) - => Add(vertices.ToPositionAttribute()); - - public IGeometryAttributes ToIGeometryAttributes() - => new GeometryAttributes(Attributes); - } -} - From 621e50e850cfb9d339d66b59da791f579941d01b Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 10:40:10 -0400 Subject: [PATCH 048/104] removed g3d serialization --- src/cs/g3d/Vim.G3d/G3dSerialization.cs | 35 -------------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/cs/g3d/Vim.G3d/G3dSerialization.cs diff --git a/src/cs/g3d/Vim.G3d/G3dSerialization.cs b/src/cs/g3d/Vim.G3d/G3dSerialization.cs deleted file mode 100644 index 4f47b27d..00000000 --- a/src/cs/g3d/Vim.G3d/G3dSerialization.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.IO; -using Vim.BFastLib; -using Vim.LinqArray; -using System.Collections.Generic; - -namespace Vim.G3d -{ - public static partial class G3DExtension - { - public static void WriteAttribute(Stream stream, GeometryAttribute attribute, string name, long size) - { - var buffer = attribute.ToBuffer(); - if (buffer.NumBytes() != size) - throw new Exception($"Internal error while writing attribute, expected number of bytes was {size} but instead was {buffer.NumBytes()}"); - if (buffer.Name != name) - throw new Exception($"Internal error while writing attribute, expected name was {name} but instead was {buffer.Name}"); - stream.Write(buffer); - } - - public static BFast ToBFast(this IGeometryAttributes self, G3dHeader? header = null) - { - var bfast = new BFast(); - bfast.SetArray("meta", (header ?? G3dHeader.Default).ToBytes()); - foreach(var attribute in self.Attributes.ToEnumerable()) - { - attribute.AddTo(bfast); - } - return bfast; - } - - - - } -} From f1a31eb11dc09679617a4c207662c0883eaaf72e Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 10:40:10 -0400 Subject: [PATCH 049/104] removed g3d serialization --- src/cs/g3d/Vim.G3d/G3dSerialization.cs | 35 -------------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/cs/g3d/Vim.G3d/G3dSerialization.cs diff --git a/src/cs/g3d/Vim.G3d/G3dSerialization.cs b/src/cs/g3d/Vim.G3d/G3dSerialization.cs deleted file mode 100644 index 4f47b27d..00000000 --- a/src/cs/g3d/Vim.G3d/G3dSerialization.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.IO; -using Vim.BFastLib; -using Vim.LinqArray; -using System.Collections.Generic; - -namespace Vim.G3d -{ - public static partial class G3DExtension - { - public static void WriteAttribute(Stream stream, GeometryAttribute attribute, string name, long size) - { - var buffer = attribute.ToBuffer(); - if (buffer.NumBytes() != size) - throw new Exception($"Internal error while writing attribute, expected number of bytes was {size} but instead was {buffer.NumBytes()}"); - if (buffer.Name != name) - throw new Exception($"Internal error while writing attribute, expected name was {name} but instead was {buffer.Name}"); - stream.Write(buffer); - } - - public static BFast ToBFast(this IGeometryAttributes self, G3dHeader? header = null) - { - var bfast = new BFast(); - bfast.SetArray("meta", (header ?? G3dHeader.Default).ToBytes()); - foreach(var attribute in self.Attributes.ToEnumerable()) - { - attribute.AddTo(bfast); - } - return bfast; - } - - - - } -} From 140b12e1ebd0e16efa6397f8b9b6840e14e29868 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 11:02:39 -0400 Subject: [PATCH 050/104] removed lots of unused attribute code --- src/cs/g3d/Vim.G3d/AttributeExtensions.cs | 24 - .../Vim.G3d/GeometryAttributesExtensions.cs | 494 +----------------- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 16 - 3 files changed, 1 insertion(+), 533 deletions(-) diff --git a/src/cs/g3d/Vim.G3d/AttributeExtensions.cs b/src/cs/g3d/Vim.G3d/AttributeExtensions.cs index 98fb02fa..aedfed52 100644 --- a/src/cs/g3d/Vim.G3d/AttributeExtensions.cs +++ b/src/cs/g3d/Vim.G3d/AttributeExtensions.cs @@ -9,21 +9,6 @@ namespace Vim.G3d { public static class AttributeExtensions { - public static GeometryAttribute CheckArity(this GeometryAttribute self, int arity) where T : unmanaged - => self?.Descriptor?.DataArity == arity ? self : null; - - public static GeometryAttribute CheckAssociation(this GeometryAttribute self, Association assoc) where T : unmanaged - => self?.Descriptor?.Association == assoc ? self : null; - - public static GeometryAttribute CheckArityAndAssociation(this GeometryAttribute self, int arity, Association assoc) where T : unmanaged - => self?.CheckArity(arity)?.CheckAssociation(assoc); - - public static GeometryAttribute ToAttribute(this IList self, string desc) where T : unmanaged - => self.ToIArray().ToAttribute(desc); - - public static GeometryAttribute ToAttribute(this IList self, AttributeDescriptor desc) where T : unmanaged - => self.ToIArray().ToAttribute(desc); - public static GeometryAttribute ToAttribute(this IArray self, AttributeDescriptor desc) where T : unmanaged => new GeometryAttribute(self, desc); @@ -137,14 +122,5 @@ public static GeometryAttribute ToDefaultAttribute(this AttributeDescriptor desc throw new Exception($"Could not create a default attribute for {desc}"); } - - public static long GetByteSize(this GeometryAttribute attribute) - => (long)attribute.ElementCount * attribute.Descriptor.DataElementSize; - - public static GeometryAttribute Merge(this IEnumerable attributes) - => attributes.FirstOrDefault()?.Merge(attributes.Skip(1)); - - public static GeometryAttribute Merge(this IArray attributes) - => attributes.ToEnumerable().Merge(); } } diff --git a/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs b/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs index 5d7e07d5..a378b94f 100644 --- a/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs +++ b/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs @@ -8,507 +8,15 @@ namespace Vim.G3d { public static class GeometryAttributesExtensions { - public static int ExpectedElementCount(this IGeometryAttributes self, AttributeDescriptor desc) - { - switch (desc.Association) - { - case Association.assoc_all: - return 1; - case Association.assoc_none: - return 0; - case Association.assoc_vertex: - return self.NumVertices; - case Association.assoc_face: - return self.NumFaces; - case Association.assoc_corner: - return self.NumCorners; - case Association.assoc_edge: - return self.NumCorners; - case Association.assoc_mesh: - return self.NumMeshes; - case Association.assoc_instance: - return self.NumInstances; - case Association.assoc_shapevertex: - return self.NumShapeVertices; - case Association.assoc_shape: - return self.NumShapes; - } - return -1; - } - - public static IArray AttributeNames(this IGeometryAttributes g) - => g.Attributes.Select(attr => attr.Name); - public static GeometryAttribute GetAttribute(this IGeometryAttributes g, string attributeName) where T : unmanaged => g.GetAttribute(attributeName)?.AsType(); - public static GeometryAttribute DefaultAttribute(this IGeometryAttributes self, string name) - => self.DefaultAttribute(AttributeDescriptor.Parse(name)); - - public static GeometryAttribute DefaultAttribute(this IGeometryAttributes self, AttributeDescriptor desc) - => desc.ToDefaultAttribute(self.ExpectedElementCount(desc)); - - public static GeometryAttribute GetOrDefaultAttribute(this IGeometryAttributes self, AttributeDescriptor desc) - => self.GetAttribute(desc.ToString()) ?? desc.ToDefaultAttribute(self.ExpectedElementCount(desc)); - - public static IEnumerable NoneAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_none); - - public static IEnumerable CornerAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_corner); - - public static IEnumerable EdgeAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_edge); - - public static IEnumerable FaceAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_face); - - public static IEnumerable VertexAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_vertex); - - public static IEnumerable InstanceAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_instance); - - public static IEnumerable MeshAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_mesh); - - public static IEnumerable SubMeshAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_submesh); - - public static IEnumerable WholeGeometryAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_all); - - public static IEnumerable ShapeVertexAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_shapevertex); - - public static IEnumerable ShapeAttributes(this IGeometryAttributes g) - => g.Attributes.Where(a => a.Descriptor.Association == Association.assoc_shape); - - public static bool HasSameAttributes(this IGeometryAttributes g1, IGeometryAttributes g2) - => g1.Attributes.Count == g2.Attributes.Count && g1.Attributes.Indices().All(i => g1.Attributes[i].Name == g2.Attributes[i].Name); - - public static int FaceToCorner(this IGeometryAttributes g, int f) - => f * g.NumCornersPerFace; - - /// - /// Given a set of face indices, creates an array of corner indices - /// - public static IArray FaceIndicesToCornerIndices(this IGeometryAttributes g, IArray faceIndices) - => (faceIndices.Count * g.NumCornersPerFace) - .Select(i => g.FaceToCorner(faceIndices[i / g.NumCornersPerFace]) + i % g.NumCornersPerFace); - - /// - /// Given a set of face indices, creates an array of indices of the first corner in each face - /// - public static IArray FaceIndicesToFirstCornerIndices(this IGeometryAttributes g, IArray faceIndices) - => faceIndices.Select(f => f * g.NumCornersPerFace); - - public static int CornerToFace(this IGeometryAttributes g, int c) - => c / g.NumCornersPerFace; - - public static IArray CornersToFaces(this IGeometryAttributes g) - => g.NumCorners.Select(g.CornerToFace); - - public static int CornerNumber(this IGeometryAttributes g, int c) - => c % g.NumCornersPerFace; - public static IGeometryAttributes ToGeometryAttributes(this IEnumerable attributes) => new GeometryAttributes(attributes); - - public static IGeometryAttributes ToGeometryAttributes(this IArray attributes) - => attributes.ToEnumerable().ToGeometryAttributes(); - + public static IGeometryAttributes AddAttributes(this IGeometryAttributes attributes, params GeometryAttribute[] newAttributes) => attributes.Attributes.ToEnumerable().Concat(newAttributes).ToGeometryAttributes(); - public static GeometryAttribute GetAttributeOrDefault(this IGeometryAttributes g, string name) - => g.GetAttribute(name) ?? g.DefaultAttribute(name); - - public static IGeometryAttributes Merge(this IArray gs) - => gs.Select(x => (IGeometryAttributes)x).Merge(); - - public static IGeometryAttributes Merge(this IGeometryAttributes self, params IGeometryAttributes[] gs) - => gs.ToIArray().Prepend(self).Merge(); - - public static IGeometryAttributes Merge(this IArray geometryAttributesArray) - { - if (geometryAttributesArray.Count == 0) - return GeometryAttributes.Empty; - - var first = geometryAttributesArray[0]; - - if (geometryAttributesArray.Count == 1) - return first; - var corners = first.NumCornersPerFace; - if (!geometryAttributesArray.All(g => g.NumCornersPerFace == corners)) - throw new Exception("Cannot merge meshes with different numbers of corners per faces"); - - // Merge all of the attributes of the different geometries - // Except: indices, group indexes, subgeo, and instance attributes - var attributes = first.VertexAttributes() - .Concat(first.CornerAttributes()) - .Concat(first.EdgeAttributes()) - .Concat(first.NoneAttributes()) - .Concat(first.FaceAttributes()) - .Append(first.GetAttributeSubmeshMaterial()) - // Skip the index semantic because things get re-ordered - .Where(attr => attr != null && attr.Descriptor.Semantic != Semantic.Index) - .ToArray(); - - // Merge the non-indexed attributes - var others = geometryAttributesArray.Skip(1).ToEnumerable(); - var attributeList = attributes.Select( - attr => attr.Merge(others.Select(g => g.GetAttributeOrDefault(attr.Name)))).ToList(); - - // Merge the index attribute - // numVertices: [X], [Y], [Z], ... - // valueOffsets: [0], [X], [X+Y], ... - // indices: [A, B, C], [D, E, F], [G, H, I], ... - // mergedIndices: [A, B, C], [X+D, X+E, X+F], [X+Y+G, X+Y+H, X+Y+I], ... - var mergedIndexAttribute = geometryAttributesArray.MergeIndexedAttribute( - ga => ga.GetAttributeIndex(), - ga => ga.NumVertices) - ?.ToIndexAttribute(); - - if (mergedIndexAttribute != null) - attributeList.Add(mergedIndexAttribute); - - // Merge the submesh index offset attribute - // numCorners: [X], [Y], [Z], ... - // valueOffsets: [0] [X], [X+Y], ... - // submeshIndexOffsets: [0, A, B], [0, C, D], [0, E, F], ... - // mergedSubmeshIndexOffsets: [0, A, B], [X, X+C, X+D], [X+Y, X+Y+E, X+Y+F], ... - var mergedSubmeshIndexOffsetAttribute = geometryAttributesArray.MergeIndexedAttribute( - ga => ga.GetAttributeSubmeshIndexOffset(), - ga => ga.NumCorners) - ?.ToSubmeshIndexOffsetAttribute(); - - if (mergedSubmeshIndexOffsetAttribute != null) - attributeList.Add(mergedSubmeshIndexOffsetAttribute); - - return attributeList.ToGeometryAttributes(); - } - - /// - /// Merges the indexed attributes based on the given transformations and returns an array of integers - /// representing the merged and offset values. - /// - public static int[] MergeIndexedAttribute( - this IArray geometryAttributesArray, - Func> getIndexedAttributeFunc, - Func getValueOffsetFunc, - int initialValueOffset = 0) - { - var first = geometryAttributesArray.FirstOrDefault(); - if (first == null) - return null; - - var firstAttribute = getIndexedAttributeFunc(first); - if (firstAttribute == null) - return null; - - return geometryAttributesArray.MergeAttributes( - getIndexedAttributeFunc, - tuples => - { - var valueOffset = initialValueOffset; - var mergedCount = 0; - - var merged = new int[tuples.Sum(t => t.Attribute.Data.Count)]; - - foreach (var (parent, attr) in tuples) - { - var attrData = attr.Data; - var attrDataCount = attr.Data.Count; - - for (var i = 0; i < attrDataCount; ++i) - merged[mergedCount + i] = attrData[i] + valueOffset; - - mergedCount += attrDataCount; - valueOffset += getValueOffsetFunc(parent); - } - - return merged; - }); - } - - /// - /// Merges the attributes based on the given transformations and returns an array of merged values. - /// - public static T[] MergeAttributes( - this IArray geometryAttributesArray, - Func> getAttributeFunc, - Func<(IGeometryAttributes Parent, GeometryAttribute Attribute)[], T[]> mergeFunc) where T : unmanaged - { - var tuples = geometryAttributesArray - .Select(ga => (Parent: ga, GeometryAttribute: getAttributeFunc(ga))) - .Where(tuple => tuple.GeometryAttribute != null) - .ToArray(); - - if (tuples.Length != geometryAttributesArray.Count) - throw new Exception("The geometry attributes array do not all contain the same attribute"); - - return mergeFunc(tuples); - } - - /// - /// Applies a transformation function to position attributes and another to normal attributes. When deforming, we may want to - /// apply a similar deformation to the normals. For example a matrix can change the position, rotation, and scale of a geometry, - /// but the only changes should be to the direction of the normal, not the length. - /// - public static IGeometryAttributes Deform(this IGeometryAttributes g, Func positionTransform, Func normalTransform) - => g.Attributes.Select( - a => - (a.Descriptor.Semantic == Semantic.Position && a is GeometryAttribute p) ? p.Data.Select(positionTransform).ToAttribute(a.Descriptor) : - (a.Descriptor.Semantic == Semantic.Normal && a is GeometryAttribute n) ? n.Data.Select(normalTransform).ToAttribute(a.Descriptor) : - a) - .ToGeometryAttributes(); - - /// - /// Applies a deformation to points, without changing the normals. For some transformation functions this can result in incorrect normals. - /// - public static IGeometryAttributes Deform(this IGeometryAttributes g, Func positionTransform) - => g.Attributes.Select( - a => - (a.Descriptor.Semantic == Semantic.Position && a is GeometryAttribute p) ? p.Data.Select(positionTransform).ToAttribute(a.Descriptor) : - a) - .ToGeometryAttributes(); - - /// - /// Applies a transformation matrix - /// - public static IGeometryAttributes Transform(this IGeometryAttributes g, Matrix4x4 matrix) - => g.Deform(v => v.Transform(matrix), v => v.TransformNormal(matrix)); - - public static IGeometryAttributes SetPosition(this IGeometryAttributes g, IArray points) - => g.SetAttribute(points.ToPositionAttribute()); - - public static IGeometryAttributes SetAttribute(this IGeometryAttributes self, GeometryAttribute attr) - => self.Attributes.Where(a => !a.Descriptor.Equals(attr.Descriptor)).Append(attr).ToGeometryAttributes(); - - public static IGeometryAttributes SetAttribute(this IGeometryAttributes self, IArray values, AttributeDescriptor desc) where ValueT : unmanaged - => self.SetAttribute(values.ToAttribute(desc)); - - /// - /// Leaves the vertex buffer intact and creates a new geometry that remaps all of the group, corner, and face data. - /// The newFaces array is a list of indices into the old face array. - /// Note: meshes are lost. - /// - public static IGeometryAttributes RemapFaces(this IGeometryAttributes g, IArray faceRemap) - => g.RemapFacesAndCorners(faceRemap, g.FaceIndicesToCornerIndices(faceRemap)); - - public static IEnumerable SetFaceSizeAttribute(this IEnumerable attributes, int numCornersPerFaces) - => (numCornersPerFaces <= 0) - ? attributes - : attributes - .Where(attr => attr.Descriptor.Semantic != Semantic.FaceSize) - .Append(new[] { numCornersPerFaces }.ToObjectFaceSizeAttribute()); - - /// - /// Low-level remap function. Maps faces and corners at the same time. - /// In some cases, this is important (e.g. triangulating quads). - /// Note: meshes are lost. - /// - public static IGeometryAttributes RemapFacesAndCorners(this IGeometryAttributes g, IArray faceRemap, IArray cornerRemap, int numCornersPerFace = -1) - => g.VertexAttributes() - .Concat(g.SubMeshAttributes()) - .Concat(g.NoneAttributes()) - .Concat(g.FaceAttributes().Select(attr => attr.Remap(faceRemap))) - .Concat(g.EdgeAttributes().Select(attr => attr.Remap(cornerRemap))) - .Concat(g.CornerAttributes().Select(attr => attr.Remap(cornerRemap))) - .Concat(g.WholeGeometryAttributes()) - .SetFaceSizeAttribute(numCornersPerFace) - .ToGeometryAttributes(); - - /// - /// Converts a quadrilateral mesh into a triangular mesh carrying over all attributes. - /// - public static IGeometryAttributes TriangulateQuadMesh(this IGeometryAttributes g) - { - if (g.NumCornersPerFace != 4) throw new Exception("Not a quad mesh"); - - var cornerRemap = new int[g.NumFaces * 6]; - var faceRemap = new int[g.NumFaces * 2]; - var cur = 0; - for (var i = 0; i < g.NumFaces; ++i) - { - cornerRemap[cur++] = i * 4 + 0; - cornerRemap[cur++] = i * 4 + 1; - cornerRemap[cur++] = i * 4 + 2; - cornerRemap[cur++] = i * 4 + 0; - cornerRemap[cur++] = i * 4 + 2; - cornerRemap[cur++] = i * 4 + 3; - - faceRemap[i * 2 + 0] = i; - faceRemap[i * 2 + 1] = i; - } - - return g.RemapFacesAndCorners(faceRemap.ToIArray(), cornerRemap.ToIArray(), 3); - } - - public static IGeometryAttributes CopyFaces(this IGeometryAttributes g, IArray keep) - => g.CopyFaces(i => keep[i]); - - public static IGeometryAttributes CopyFaces(this IGeometryAttributes g, IArray keep) - => g.RemapFaces(keep); - - public static IGeometryAttributes CopyFaces(this IGeometryAttributes self, Func predicate) - => self.RemapFaces(self.NumFaces.Select(i => i).IndicesWhere(predicate).ToIArray()); - - public static IGeometryAttributes DeleteFaces(this IGeometryAttributes g, Func predicate) - => g.CopyFaces(i => !predicate(i)); - - public static IGeometryAttributes CopyFaces(this IGeometryAttributes g, int from, int count) - => g.CopyFaces(i => i >= from && i < from + count); - - /// - /// Updates the vertex buffer (e.g. after identifying unwanted faces) and the index - /// buffer. Vertices are either re-ordered, removed, or deleted. Does not affect any other - /// - public static IGeometryAttributes RemapVertices(this IGeometryAttributes g, IArray newVertices, IArray newIndices) - => (new[] { newIndices.ToIndexAttribute() } - .Concat( - g.VertexAttributes() - .Select(attr => attr.Remap(newVertices))) - .Concat(g.NoneAttributes()) - .Concat(g.FaceAttributes()) - .Concat(g.EdgeAttributes()) - .Concat(g.CornerAttributes()) - .Concat(g.WholeGeometryAttributes()) - ) - .ToGeometryAttributes(); - - /// - /// The vertRemap is a list of vertices in the new vertex buffer, and where they came from. - /// This could be a reordering of the original vertex buffer, it could even be a repetition. - /// It could also be some vertices were deleted, BUT if those vertices are still referenced - /// then this will throw an exception. - /// The values in the index buffer will change, but it will stay the same length. - /// - public static IGeometryAttributes RemapVertices(this IGeometryAttributes g, IArray vertRemap) - { - var vertLookup = (-1).Repeat(g.NumVertices).ToArray(); - for (var i = 0; i < vertRemap.Count; ++i) - { - var oldVert = vertRemap[i]; - vertLookup[oldVert] = i; - } - - var oldIndices = g.GetAttributeIndex()?.Data ?? g.NumVertices.Range(); - var newIndices = oldIndices.Select(i => vertLookup[i]).Evaluate(); - - if (newIndices.Any(x => x == -1)) - throw new Exception("At least one of the indices references a vertex that no longer exists"); - - return g.RemapVertices(vertRemap, newIndices); - } - - /// - /// For mesh g, create a new mesh from the passed selected faces, - /// discarding un-referenced data and generating new index, vertex & face buffers. - /// - public static IGeometryAttributes SelectFaces(this IGeometryAttributes g, IArray faces) - { - // Early exit, if all selected no need to do anything - if (g.NumFaces == faces.Count) - return g; - - // Early exit, if none selected no need to do anything - if (faces.Count == 0) - return null; - - // First, get all the indices for this array of faces - var oldIndices = g.GetAttributeIndex(); - var oldSelIndices = new int[faces.Count * g.NumCornersPerFace]; - // var oldIndices = faces.SelectMany(f => f.Indices()); - for (var i = 0; i < faces.Count; i++) - { - for (var t = 0; t < 3; t++) - oldSelIndices[i * 3 + t] = oldIndices.Data[faces[i] * g.NumCornersPerFace + t]; - } - - // We need to create list of newIndices, and remapping - // of oldVertices to newVertices - var newIndices = (-1).Repeat(oldSelIndices.Length).ToArray(); - // Each index could potentially be in the new mesh - var indexLookup = (-1).Repeat(oldIndices.ElementCount).ToArray(); - - // Build mapping. For each index, if the vertex it has - // already been referred to has been mapped, use the - // mapped index. Otherwise, remember that we need this vertex - var numUsedVertices = 0; - // remapping from old vert array => new vert array - // Cache built of the old indices of vertices that are used - // should be equivalent to indexLookup.Where(i => i != -1) - var oldVertices = g.GetAttributePosition(); - var usedVertices = (-1).Repeat(oldVertices.ElementCount).ToArray(); - for (var i = 0; i < oldSelIndices.Length; ++i) - { - var oldIndex = oldSelIndices[i]; - var newIndex = indexLookup[oldIndex]; - if (newIndex < 0) - { - // remapping from old vert array => new vert array - usedVertices[numUsedVertices] = oldIndex; - newIndex = indexLookup[oldIndex] = numUsedVertices++; - } - newIndices[i] = newIndex; - } - - //var faceRemapping = faces.Select(f => f.Index); - var vertRemapping = usedVertices.Take(numUsedVertices).ToIArray(); - var cornerRemapping = g.FaceIndicesToCornerIndices(faces); - - return g.VertexAttributes() - .Select(attr => attr.Remap(vertRemapping)) - .Concat(g.NoneAttributes()) - .Concat(g.FaceAttributes().Select(attr => attr.Remap(faces))) - .Concat(g.EdgeAttributes().Select(attr => attr.Remap(cornerRemapping))) - .Concat(g.CornerAttributes().Select(attr => attr.Remap(cornerRemapping))) - .Concat(g.WholeGeometryAttributes()) - .ToGeometryAttributes() - .SetAttribute(newIndices.ToIndexAttribute()); - } - - public static G3D ToG3d(this IEnumerable attributes, G3dHeader? header = null) - => new G3D(attributes, header); - - public static G3D ToG3d(this IArray attributes, G3dHeader? header = null) - => attributes.ToEnumerable().ToG3d(header); - - public static IArray IndexFlippedRemapping(this IGeometryAttributes g) - => g.NumCorners.Select(c => ((c / g.NumCornersPerFace) + 1) * g.NumCornersPerFace - 1 - c % g.NumCornersPerFace); - - public static bool IsNormalAttribute(this GeometryAttribute attr) - => attr.IsType() && attr.Descriptor.Semantic == "normal"; - - public static IEnumerable FlipNormalAttributes(this IEnumerable self) - => self.Select(attr => attr.IsNormalAttribute() - ? attr.AsType().Data.Select(v => v.Inverse()).ToAttribute(attr.Descriptor) - : attr); - - public static IGeometryAttributes FlipWindingOrder(this IGeometryAttributes g) - => g.VertexAttributes() - .Concat(g.NoneAttributes()) - .Concat(g.FaceAttributes()) - .Concat(g.EdgeAttributes().Select(attr => attr.Remap(g.IndexFlippedRemapping()))) - .Concat(g.CornerAttributes().Select(attr => attr.Remap(g.IndexFlippedRemapping()))) - .Concat(g.WholeGeometryAttributes()) - .FlipNormalAttributes() - .ToGeometryAttributes(); - - public static IGeometryAttributes DoubleSided(this IGeometryAttributes g) - => g.Merge(g.FlipWindingOrder()); - - public static IArray DefaultMaterials(this IGeometryAttributes self) - => (-1).Repeat(self.NumFaces); - - public static IArray DefaultColors(this IGeometryAttributes self) - => Vector4.Zero.Repeat(self.NumVertices); - - public static IArray DefaultUvs(this IGeometryAttributes self) - => Vector2.Zero.Repeat(self.NumVertices); - public static IGeometryAttributes Replace(this IGeometryAttributes self, Func selector, GeometryAttribute attribute) => self.Attributes.Where(a => !selector(a.Descriptor)).Append(attribute).ToGeometryAttributes(); diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 03516d76..b194b53c 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -363,22 +363,6 @@ public static AABox BoundingBox(this IMeshCommon mesh) public static Int3 FaceVertexIndices(this IMeshCommon mesh, int faceIndex) => new Int3(mesh.Indices[faceIndex * 3], mesh.Indices[faceIndex * 3 + 1], mesh.Indices[faceIndex * 3 + 2]); - /// - /// Low-level remap function. Maps faces and corners at the same time. - /// In some cases, this is important (e.g. triangulating quads). - /// Note: meshes are lost. - /// - public static IGeometryAttributes RemapFacesAndCorners(this IGeometryAttributes g, IArray faceRemap, IArray cornerRemap, int numCornersPerFace = -1) - => g.VertexAttributes() - .Concat(g.NoneAttributes()) - .Concat(g.FaceAttributes().Select(attr => attr.Remap(faceRemap))) - .Concat(g.EdgeAttributes().Select(attr => attr.Remap(cornerRemap))) - .Concat(g.CornerAttributes().Select(attr => attr.Remap(cornerRemap))) - .Concat(g.WholeGeometryAttributes()) - .SetFaceSizeAttribute(numCornersPerFace) - .ToGeometryAttributes(); - - public static bool GeometryEquals(this IMeshCommon mesh, IMeshCommon other, float tolerance = Math3d.Constants.Tolerance) { if (!mesh.Indices.SequenceEquals(other.Indices)) From f318a8716e9c43e63d3aa4937874b2ac3b01878f Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 11:14:57 -0400 Subject: [PATCH 051/104] removed more --- src/cs/g3d/Vim.G3d/ObjExporter.cs | 59 -------------- src/cs/g3d/Vim.G3d/PlyExporter.cs | 78 ------------------- src/cs/g3d/Vim.G3d/Validation.cs | 76 ------------------ .../Vim.Format.Core/Geometry/Validation.cs | 1 + .../vim/Vim.Format/SceneBuilder/Validation.cs | 20 +---- 5 files changed, 4 insertions(+), 230 deletions(-) delete mode 100644 src/cs/g3d/Vim.G3d/ObjExporter.cs delete mode 100644 src/cs/g3d/Vim.G3d/PlyExporter.cs delete mode 100644 src/cs/g3d/Vim.G3d/Validation.cs diff --git a/src/cs/g3d/Vim.G3d/ObjExporter.cs b/src/cs/g3d/Vim.G3d/ObjExporter.cs deleted file mode 100644 index b76184dd..00000000 --- a/src/cs/g3d/Vim.G3d/ObjExporter.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Collections.Generic; -using System.Text; -using System.IO; -using Vim.LinqArray; - -namespace Vim.G3d -{ - /// - /// This is a simple ObjExporter for the purposes of testing. - /// - public static class ObjExporter - { - public static IEnumerable ObjLines(G3D g3d) - { - // Write the vertices - var vertices = g3d.Vertices; - var uvs = g3d.VertexUvs; - foreach (var v in vertices.ToEnumerable()) - yield return ($"v {v.X} {v.Y} {v.Z}"); - if (uvs != null) - { - for (var v = 0; v < uvs.Count; v++) - yield return ($"vt {uvs[v].X} {uvs[v].Y}"); - } - - var indices = g3d.Indices; - var sb = new StringBuilder(); - var i = 0; - var faceSize = g3d.NumCornersPerFace; - while (i < indices.Count) - { - sb.Append("f"); - - if (uvs == null) - { - for (var j = 0; j < faceSize; ++j) - { - var index = g3d.Indices[i++] + 1; - sb.Append(" ").Append(index); - } - } - else - { - for (var j = 0; j < faceSize; ++j) - { - var index = g3d.Indices[i++] + 1; - sb.Append(" ").Append(index).Append("/").Append(index); - } - } - - yield return sb.ToString(); - sb.Clear(); - } - } - - public static void WriteObj(this G3D g3d, string filePath) - => File.WriteAllLines(filePath, ObjLines(g3d)); - } -} diff --git a/src/cs/g3d/Vim.G3d/PlyExporter.cs b/src/cs/g3d/Vim.G3d/PlyExporter.cs deleted file mode 100644 index 1b2f3425..00000000 --- a/src/cs/g3d/Vim.G3d/PlyExporter.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Collections.Generic; -using System.Text; -using System.IO; -using Vim.Math3d; - -namespace Vim.G3d -{ - /// - /// A very simple .ply file exporter - /// - public static class PlyExporter - { - public static void WritePly(this G3D g, string filePath) - => File.WriteAllLines(filePath, PlyStrings(g)); - - public static IEnumerable PlyStrings(G3D g) - { - var vertices = g.Vertices; - var indices = g.Indices; - var colors = g.VertexColors; - - //Write the header - yield return "ply"; - yield return "format ascii 1.0"; - yield return "element vertex " + vertices.Count + ""; - yield return "property float x"; - yield return "property float y"; - yield return "property float z"; - if (colors != null) - { - yield return "property uint8 red"; - yield return "property uint8 green"; - yield return "property uint8 blue"; - } - yield return "element face " + g.NumFaces; - yield return "property list uint8 int32 vertex_index"; - yield return "end_header"; - - // Write the vertices - if (colors != null) - { - for (var i = 0; i < vertices.Count; i++) - { - var v = vertices[i]; - var c = (colors[i] * 255f).Clamp(Vector4.Zero, new Vector4(255, 255, 255, 255)); - - yield return - $"{v.X} {v.Y} {v.Z} {(byte)c.X} {(byte)c.Y} {(byte)c.Z}"; - } - } - else - { - for (var i = 0; i < vertices.Count; i++) - { - var v = vertices[i]; - yield return - $"{v.X} {v.Y} {v.Z}"; - } - } - - // Write the face indices - var index = 0; - var sb = new StringBuilder(); - var faceSize = g.NumCornersPerFace; - for (var i = 0; i < g.NumFaces; i++) - { - sb.Append(faceSize); - for (var j = 0; j < faceSize; j++) - { - sb.Append(" ").Append(indices[index++]); - } - - yield return sb.ToString(); - sb.Clear(); - } - } - } -} diff --git a/src/cs/g3d/Vim.G3d/Validation.cs b/src/cs/g3d/Vim.G3d/Validation.cs deleted file mode 100644 index b1fde949..00000000 --- a/src/cs/g3d/Vim.G3d/Validation.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.Collections.Generic; -using Vim.LinqArray; - -namespace Vim.G3d -{ - public enum G3dErrors - { - NodesCountMismatch, - MaterialsCountMismatch, - IndicesInvalidCount, - IndicesOutOfRange, - - //Submeshes - SubmeshesCountMismatch, - SubmeshesIndesxOffsetInvalidIndex, - SubmeshesIndexOffsetOutOfRange, - SubmeshesNonPositive, - SubmeshesMaterialOutOfRange, - - //Meshes - MeshesSubmeshOffsetOutOfRange, - MeshesSubmeshCountNonPositive, - - // Instances - InstancesCountMismatch, - InstancesParentOutOfRange, - InstancesMeshOutOfRange, - } - - public static class Validation - { - public static IEnumerable Validate(G3D g3d) - { - var errors = new List(); - - void Validate(bool value, G3dErrors error) - { - if (!value) errors.Add(error); - } - - //Indices - Validate(g3d.Indices.Count % 3 == 0, G3dErrors.IndicesInvalidCount); - Validate(g3d.Indices.All(i => i >= 0 && i < g3d.NumVertices), G3dErrors.IndicesOutOfRange); - //Triangle should have 3 distinct vertices - //Assert.That(g3d.Indices.SubArrays(3).Select(face => face.ToEnumerable().Distinct().Count()).All(c => c == 3)); - - //Submeshes - Validate(g3d.NumSubmeshes >= g3d.NumMeshes, G3dErrors.SubmeshesCountMismatch); - Validate(g3d.NumSubmeshes == g3d.SubmeshMaterials.Count, G3dErrors.SubmeshesCountMismatch); - Validate(g3d.NumSubmeshes == g3d.SubmeshIndexOffsets.Count, G3dErrors.SubmeshesCountMismatch); - Validate(g3d.SubmeshIndexOffsets.All(i => i % 3 == 0), G3dErrors.SubmeshesIndesxOffsetInvalidIndex); - Validate(g3d.SubmeshIndexOffsets.All(i => i >= 0 && i < g3d.NumCorners), G3dErrors.SubmeshesIndexOffsetOutOfRange); - Validate(g3d.SubmeshIndexCount.All(i => i > 0), G3dErrors.SubmeshesNonPositive); - Validate(g3d.SubmeshMaterials.All(m => m < g3d.NumMaterials), G3dErrors.SubmeshesMaterialOutOfRange); - - //Mesh - Validate(g3d.MeshSubmeshOffset.All(i => i >= 0 && i < g3d.NumSubmeshes), G3dErrors.MeshesSubmeshOffsetOutOfRange); - Validate(g3d.MeshSubmeshCount.All(i => i > 0), G3dErrors.MeshesSubmeshCountNonPositive); - - //Instances - Validate(g3d.NumInstances == g3d.InstanceParents.Count, G3dErrors.InstancesCountMismatch); - Validate(g3d.NumInstances == g3d.InstanceMeshes.Count, G3dErrors.InstancesCountMismatch); - Validate(g3d.NumInstances == g3d.InstanceTransforms.Count, G3dErrors.InstancesCountMismatch); - Validate(g3d.NumInstances == g3d.InstanceFlags.Count, G3dErrors.InstancesCountMismatch); - Validate(g3d.InstanceParents.All(i => i < g3d.NumInstances), G3dErrors.InstancesParentOutOfRange); - Validate(g3d.InstanceMeshes.All(i => i < g3d.NumMeshes), G3dErrors.InstancesMeshOutOfRange); - - //Materials - Validate(g3d.NumMaterials == g3d.MaterialColors.Count, G3dErrors.MaterialsCountMismatch); - Validate(g3d.NumMaterials == g3d.MaterialGlossiness.Count, G3dErrors.MaterialsCountMismatch); - Validate(g3d.NumMaterials == g3d.MaterialSmoothness.Count, G3dErrors.MaterialsCountMismatch); - - return errors; - } - } -} diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index ef12f052..79c1c5b5 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -100,6 +100,7 @@ public static void ValidateIndices(this IMeshCommon mesh) public static void Validate(this IMeshCommon mesh) { + //TODO: Validate better mesh.ValidateIndices(); } } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index 5eaaf8d1..eb9cddbb 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -24,21 +24,7 @@ public class VimValidationException : Exception { public VimValidationException(string message) : base(message) { } } - public static void ValidateGeometry(this VimScene vim) - { - // Validate the packed geometry. - VimMesh.FromG3d(vim.Document.GeometryNext).Validate(); - var errors = new List(); - - G3d.Validation.Validate(vim.Document.Geometry); - } - - public static void ValidateGeometryNext(this VimScene vim) - { - //TODO: Sronger validation maybe. - vim.Document.GeometryNext.Validate(); - } - + public static void ValidateDocumentModelToG3dInvariantsNext(this VimScene vim) { var g3d = vim.Document.GeometryNext; @@ -139,8 +125,8 @@ public static void Validate(this VimScene vim, VimValidationOptions options = nu vim.Document.Validate(); vim.DocumentModel.Validate(options.ObjectModelValidationOptions); - vim.ValidateGeometry(); - vim.ValidateGeometryNext(); + + VimMesh.FromG3d(vim.Document.GeometryNext).Validate(); vim.ValidateDocumentModelToG3dInvariantsNext(); From 528f882d94ac293fd6116cc8e80c6deb68d73281 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 11:49:13 -0400 Subject: [PATCH 052/104] added clone method --- src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs | 5 +++++ src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs b/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs index 59cd7b22..7d04fec4 100644 --- a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs +++ b/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs @@ -85,6 +85,11 @@ public BFast ToBFast() return bfast; }} + public {entity.ClassName} Clone() + {{ + return this.MemberwiseClone() as {entity.ClassName}; + }} + public bool Equals({entity.ClassName} other ) {{ return {string.Join(" && \n \t\t\t", entity.Buffers.Select(b => diff --git a/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs b/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs index 5a2a9801..1a822426 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs @@ -109,6 +109,11 @@ public BFast ToBFast() return bfast; } + public G3dVim Clone() + { + return this.MemberwiseClone() as G3dVim; + } + public bool Equals(G3dVim other ) { return BufferMethods.SafeEquals(Indices, other.Indices) && @@ -245,6 +250,11 @@ public BFast ToBFast() return bfast; } + public G3dChunk Clone() + { + return this.MemberwiseClone() as G3dChunk; + } + public bool Equals(G3dChunk other ) { return BufferMethods.SafeEquals(MeshOpaqueSubmeshCounts, other.MeshOpaqueSubmeshCounts) && @@ -331,6 +341,11 @@ public BFast ToBFast() return bfast; } + public G3dMaterials Clone() + { + return this.MemberwiseClone() as G3dMaterials; + } + public bool Equals(G3dMaterials other ) { return BufferMethods.SafeEquals(MaterialColors, other.MaterialColors) && @@ -462,6 +477,11 @@ public BFast ToBFast() return bfast; } + public G3dScene Clone() + { + return this.MemberwiseClone() as G3dScene; + } + public bool Equals(G3dScene other ) { return BufferMethods.SafeEquals(ChunkCount, other.ChunkCount) && From df1016df5b9c9131606eb3d51cd26be823ae98ed Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 14:45:33 -0400 Subject: [PATCH 053/104] added hasflag --- src/cs/g3d/Vim.G3dNext/G3dVim.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/cs/g3d/Vim.G3dNext/G3dVim.cs b/src/cs/g3d/Vim.G3dNext/G3dVim.cs index b6447235..8cd88443 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dVim.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dVim.cs @@ -4,6 +4,21 @@ namespace Vim.G3dNext { + [Flags] + public enum InstanceFlags + { + /// + /// Default - no instance options defined. + /// + None = 0, + + /// + /// When enabled, indicates that the renderer (or the consuming application) should hide + /// the instance by default. + /// + Hidden = 1, + } + public partial class G3dVim { @@ -21,6 +36,11 @@ public int GetApproxSize(int mesh) return GetMeshVertexCount(mesh) * 12 + GetMeshIndexCount(mesh) * 4; } + public bool InstanceHasFlag(int index, InstanceFlags flag) + { + return InstanceFlags[index] == (int)flag; + } + void ISetup.Setup() { MeshVertexOffsets = ComputeMeshVertexOffsets(); From d2bc28696d3d3e9c39a28045def5ae58a1f139c0 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 15:02:19 -0400 Subject: [PATCH 054/104] added remove shapes --- src/cs/g3d/Vim.G3dNext/G3dVim.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cs/g3d/Vim.G3dNext/G3dVim.cs b/src/cs/g3d/Vim.G3dNext/G3dVim.cs index 8cd88443..b21fed00 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dVim.cs +++ b/src/cs/g3d/Vim.G3dNext/G3dVim.cs @@ -87,9 +87,14 @@ private List[] ComputeMeshInstances() return result; } - public int GetTriangleCount() + public G3dVim RemoveShapes() { - return GetIndexCount() / 3; + var result = Clone(); + result.ShapeVertexOffsets = null; + result.ShapeWidths = null; + result.ShapeColors = null; + result.ShapeVertices = null; + return result; } /// From f6086450b98237ff1dc7489c75b34d66704adbe9 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 15:02:32 -0400 Subject: [PATCH 055/104] added test for clone --- src/cs/Vim.G3dNext.Tests/VimG3dNextTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cs/Vim.G3dNext.Tests/VimG3dNextTests.cs b/src/cs/Vim.G3dNext.Tests/VimG3dNextTests.cs index 2d357abd..a8505b66 100644 --- a/src/cs/Vim.G3dNext.Tests/VimG3dNextTests.cs +++ b/src/cs/Vim.G3dNext.Tests/VimG3dNextTests.cs @@ -40,6 +40,8 @@ public static void Can_Write_And_Read() Assert.IsTrue(g3d.Equals(expected)); } + + [Test] public static void Can_Merge_two_g3d() { @@ -66,6 +68,14 @@ public static void Can_Merge_two_g3d() ); Assert.IsTrue(merged.Equals(expected)); } + + + [Test] + public static void Clone_IsEqual() + { + var g3d = G3dNextTestUtils.CreateTestG3d(); + Assert.IsTrue(g3d.Equals(g3d.Clone())); + } } } From d1a31d5f2851542ecc61fe0fd2bdb5aa08b42853 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 15:02:49 -0400 Subject: [PATCH 056/104] removed geometry usage --- src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 9a890d64..85675c93 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -51,13 +51,13 @@ public static VimScene LoadVim(string f, LoadOptions loadOptions, IVimSceneProgr => new VimScene(SerializableDocument.FromPath(f, loadOptions), progress, inParallel, vimIndex); public static VimScene LoadVim(string f, IVimSceneProgress progress = null, bool skipGeometry = false, bool skipAssets = false, bool skipNodes = false, bool inParallel = false) - => LoadVim(f, new LoadOptions { SkipGeometry = skipGeometry, SkipAssets = skipAssets}, progress, inParallel); + => LoadVim(f, new LoadOptions { SkipGeometry = skipGeometry, SkipAssets = skipAssets }, progress, inParallel); public static VimScene LoadVim(Stream stream, LoadOptions loadOptions, IVimSceneProgress progress = null, bool inParallel = false) => new VimScene(SerializableDocument.FromBFast(new BFast(stream), loadOptions), progress, inParallel); public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, bool skipGeometry = false, bool skipAssets = false, bool skipNodes = false, bool inParallel = false) - => LoadVim(stream, new LoadOptions { SkipGeometry = skipGeometry, SkipAssets = skipAssets}, progress, inParallel); + => LoadVim(stream, new LoadOptions { SkipGeometry = skipGeometry, SkipAssets = skipAssets }, progress, inParallel); public int VimIndex { get; set; } public VimSceneNode[] Nodes { get; private set; } @@ -203,9 +203,8 @@ private void CreateMeshes(bool inParallel) return; } - var srcGeo = _SerializableDocument.Geometry; Meshes = VimMesh.GetAllMeshes(_SerializableDocument.GeometryNext).ToArray(); - MeshesOld = srcGeo?.Meshes.Select(m => m as IMeshCommon); + MeshesOld = _SerializableDocument.Geometry?.Meshes.Select(m => m as IMeshCommon); } private void CreateShapes(bool inParallel) @@ -216,12 +215,12 @@ private void CreateShapes(bool inParallel) } var r = _SerializableDocument.Geometry.Shapes.Select((s, i) => new VimShape(this, i)); ShapesOld = inParallel ? r.EvaluateInParallel() : r.Evaluate(); - Shapes = VimShapeNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); + Shapes = VimShapeNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); } private void CreateScene(bool inParallel) { - if (_SerializableDocument.Geometry == null) + if (_SerializableDocument.GeometryNext == null) { return; } @@ -231,7 +230,7 @@ private void CreateScene(bool inParallel) private void CreateMaterials(bool inParallel) { - if (_SerializableDocument.Geometry == null) + if (_SerializableDocument.GeometryNext == null) { return; } @@ -245,7 +244,7 @@ private void CreateMaterials(bool inParallel) public static VimSceneNode[] CreateVimSceneNodes(VimScene scene, G3D g3d, bool inParallel) { Matrix4x4 GetMatrix(int i) => i >= 0 ? g3d.InstanceTransforms[i] : Matrix4x4.Identity; - + return g3d.InstanceTransforms.Select((_, i) => new VimSceneNode(scene, i, g3d.InstanceMeshes[i], GetMatrix(i))).ToArray(); } From f1bd33e68e37924adbb17db96d8fa904e4f6d797 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 15:52:46 -0400 Subject: [PATCH 057/104] removed most imeshcommon --- .../DocumentBuilderExtensions.cs | 2 +- src/cs/vim/Vim.Format.Core/G3dBuilder.cs | 2 +- .../Vim.Format.Core/Geometry/CatmullClark.cs | 14 ++--- .../Geometry/PerimeterProjection.cs | 6 +- .../Vim.Format.Core/Geometry/Primitives.cs | 18 +++--- .../Vim.Format.Core/Geometry/Validation.cs | 18 ------ .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 59 +++++++++++-------- .../Geometry/GeometryTests.cs | 22 +++---- .../SerializableDocumentTests.cs | 26 -------- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 4 +- .../Vim.Format/SceneBuilder/VimSceneNode.cs | 12 +--- 11 files changed, 71 insertions(+), 112 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index 02ae2464..6ca4fc9b 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -10,7 +10,7 @@ namespace Vim.Format { public static class DocumentBuilderExtensions { - public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this IMeshCommon m) + public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this VimMesh m) => new SubdividedMesh( m.Indices.ToList(), m.Vertices.ToList(), diff --git a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs index 76a4304c..082e957f 100644 --- a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs @@ -40,7 +40,7 @@ public void AddMaterial(IMaterial material) public int MaterialCount => _materials.Count; public int ShapeCount => _shapes.Count; - public IMeshCommon GetMesh(int index) => _meshes[index]; + public VimMesh GetMesh(int index) => _meshes[index]; public AABox GetBox(int meshIndex) { return AABox.Create(_meshes[meshIndex].vertices); diff --git a/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs b/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs index 2f0da338..48c2ac77 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using Vim.G3d; -using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Geometry @@ -40,7 +38,7 @@ public class GeometryEdge public static class CatmullClarkSmoothing { - public static Dictionary CreateEdgeMap(this IMeshCommon geometry) + public static Dictionary CreateEdgeMap(this VimMesh geometry) { var globalEdgeIndex = 0; var edgeMap = new Dictionary(); @@ -69,7 +67,7 @@ public static Dictionary CreateEdgeMap(this IMesh return edgeMap; } - public static IMeshCommon CatmullClark(this IMeshCommon geometry, float smoothing = 0.0f) + public static VimMesh CatmullClark(this VimMesh geometry, float smoothing = 0.0f) { var edgeMap = geometry.CreateEdgeMap(); @@ -130,7 +128,7 @@ public static IMeshCommon CatmullClark(this IMeshCommon geometry, float smoothin return GenerateMesh(geometry, newVertices, newIndices, edgeMap, facePointStartIndex, edgePointStartIndex, numQuads); } - public static void CalculateFaceCentroidPoints(IMeshCommon geometry, Vector3[] outFacePoints, float[] outVertexNumFaces, Vector3[] outVertexFPoints) + public static void CalculateFaceCentroidPoints(VimMesh geometry, Vector3[] outFacePoints, float[] outVertexNumFaces, Vector3[] outVertexFPoints) { var currentVertexIndex = 0; for (var faceIndex = 0; faceIndex < geometry.NumFaces; faceIndex++) @@ -160,7 +158,7 @@ public static void CalculateFaceCentroidPoints(IMeshCommon geometry, Vector3[] o } } - public static void CalculateEdgePoints(IMeshCommon geometry, Dictionary edgeMap, Vector3[] facePoints, float[] outVertexNumEdges, Vector3[] outVertexRPoints, float smoothing) + public static void CalculateEdgePoints(VimMesh geometry, Dictionary edgeMap, Vector3[] facePoints, float[] outVertexNumEdges, Vector3[] outVertexRPoints, float smoothing) { foreach (var edge in edgeMap) { @@ -187,7 +185,7 @@ public static void CalculateEdgePoints(IMeshCommon geometry, Dictionary edgeMap, int facePointStartIndex, int edgePointStartIndex, int numQuads) + public static VimMesh GenerateMesh(VimMesh geometry, Vector3[] newVertices, int[] newIndices, Dictionary edgeMap, int facePointStartIndex, int edgePointStartIndex, int numQuads) { var currentNewVertexIndex = 0; var currentOldVertexIndex = 0; diff --git a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs index d232a460..b6427d01 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs @@ -11,7 +11,7 @@ namespace Vim.Format.Geometry public static class PerimeterProjection { - public static List> GeneratePerimeter(this IMeshCommon mesh, Vector3 planeNormal, float degenerateSegmentEpsilon = 10.0f, float edgeLoopThreshold = 1e-6f) + public static List> GeneratePerimeter(this VimMesh mesh, Vector3 planeNormal, float degenerateSegmentEpsilon = 10.0f, float edgeLoopThreshold = 1e-6f) { var q = GetClusterRotation(planeNormal.Normalize(), Vector3.UnitZ); @@ -307,7 +307,7 @@ public int GetHashCode(Tuple obj) => obj.Item1.GetHashCode() ^ obj.Item2.GetHashCode(); } - public static Dictionary, int> BuildEdgeDictionary(this IMeshCommon mesh) + public static Dictionary, int> BuildEdgeDictionary(this VimMesh mesh) { var edges = new Dictionary, int>(new EdgeEqualityComparer()); @@ -327,7 +327,7 @@ public static Dictionary, int> BuildEdgeDictionary(this IMeshCom return edges; } - public static List> BuildBoundarySegments(this IMeshCommon mesh, Dictionary, int> edgeDictionary, Func transform) + public static List> BuildBoundarySegments(this VimMesh mesh, Dictionary, int> edgeDictionary, Func transform) { var segments = new List>(); diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index a0c737d8..01b15b0d 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -10,7 +10,7 @@ namespace Vim.Format.Geometry // TODO: plane, cylinder, cone, ruled face, public static class Primitives { - public static IMeshCommon CreateCube() + public static VimMesh CreateCube() { var vertices = new[] { // front @@ -49,13 +49,13 @@ public static IMeshCommon CreateCube() return new VimMesh(indices, vertices); } - public static IMeshCommon CreateCube(AABox box) + public static VimMesh CreateCube(AABox box) { return CreateCube().Scale(box.Extent).Translate(box.Center); } private static float Sqrt2 = 2.0f.Sqrt(); - public static IMeshCommon CreateTetrahedron() + public static VimMesh CreateTetrahedron() { var vertices = new[] { @@ -67,7 +67,7 @@ public static IMeshCommon CreateTetrahedron() var indices = new[] { 0, 1, 2, 1, 0, 3, 0, 2, 3, 1, 3, 2 }; return new VimMesh(indices, vertices); } - public static IMeshCommon CreateSquare() + public static VimMesh CreateSquare() { var vertices = new[] { @@ -92,7 +92,7 @@ public static Vector3 TorusFunction(Vector2 uv, float radius, float tube) tube * uv.Y.Sin()); } - public static IMeshCommon Torus(float radius, float tubeRadius, int uSegs, int vSegs) + public static VimMesh Torus(float radius, float tubeRadius, int uSegs, int vSegs) => QuadMesh(uv => TorusFunction(uv, radius, tubeRadius), uSegs, vSegs); // see: https://github.com/mrdoob/three.js/blob/9ef27d1af7809fa4d9943f8d4c4644e365ab6d2d/src/geometries/SphereBufferGeometry.js#L76 @@ -102,7 +102,7 @@ public static Vector3 SphereFunction(Vector2 uv, float radius) (float)(radius * Math.Cos(uv.Y * Math3d.Constants.Pi)), (float)(radius * Math.Sin(uv.X * Math3d.Constants.TwoPi) * Math.Sin(uv.Y * Math3d.Constants.Pi))); - public static IMeshCommon Sphere(float radius, int uSegs, int vSegs) + public static VimMesh Sphere(float radius, int uSegs, int vSegs) => QuadMesh(uv => SphereFunction(uv, radius), uSegs, vSegs); /// @@ -256,13 +256,13 @@ public static IArray TriMeshCylinderCapIndices(int numEdgeVertices) /// /// Creates a quad mesh given a mapping from 2 space to 3 space /// - public static IMeshCommon QuadMesh(this Func f, int segs) + public static VimMesh QuadMesh(this Func f, int segs) => QuadMesh(f, segs, segs); /// /// Creates a quad mesh given a mapping from 2 space to 3 space /// - public static IMeshCommon QuadMesh(this Func f, int usegs, int vsegs, bool wrapUSegs = false, bool wrapVSegs = false) + public static VimMesh QuadMesh(this Func f, int usegs, int vsegs, bool wrapUSegs = false, bool wrapVSegs = false) { var verts = new List(); var maxUSegs = wrapUSegs ? usegs : usegs + 1; @@ -285,7 +285,7 @@ public static IMeshCommon QuadMesh(this Func f, int usegs, int /// /// Creates a revolved face ... note that the last points are on top of the original /// - public static IMeshCommon RevolveAroundAxis(this IArray points, Vector3 axis, int segments = 4) + public static VimMesh RevolveAroundAxis(this IArray points, Vector3 axis, int segments = 4) { var verts = new List(); for (var i = 0; i < segments; ++i) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index 79c1c5b5..88cf5f9f 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -83,25 +83,7 @@ public static void Validate(this Document doc) { doc.ValidateTableRows(); doc.ValidateIndexColumns(); - doc.ValidateGeometryAttributes(); doc.ValidateAssets(); } - - // TODO: ValidateShapes() to validate VIM files which contain optional 2d data (shapes/overlays). - - public static void ValidateIndices(this IMeshCommon mesh) - { - foreach (var index in mesh.Indices.ToEnumerable()) - { - if (index < 0 || index >= mesh.NumVertices) - throw new Exception($"Invalid mesh index: {index}. Expected a value greater or equal to 0 and less than {mesh.NumVertices}"); - } - } - - public static void Validate(this IMeshCommon mesh) - { - //TODO: Validate better - mesh.ValidateIndices(); - } } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index b194b53c..43ec0313 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -9,7 +9,7 @@ namespace Vim.Format.Geometry { - public class VimMesh : IMeshCommon + public class VimMesh : ITransformable3D { public IArray Vertices => vertices.ToIArray(); @@ -123,9 +123,6 @@ public VimMesh Clone() ); return mesh; } - IMeshCommon IMeshCommon.Clone() => Clone(); - - IMeshCommon ITransformable3D.Transform(Matrix4x4 mat) => Transform(mat); public VimMesh Transform(Matrix4x4 mat) { var mesh = Clone(); @@ -223,11 +220,25 @@ public void SetIndices(int[] indices) { this.indices = indices; } + + public void Validate() + { + //TODO: Validate better + ValidateIndices(); + } + private void ValidateIndices() + { + foreach (var index in Indices.ToEnumerable()) + { + if (index < 0 || index >= NumVertices) + throw new Exception($"Invalid mesh index: {index}. Expected a value greater or equal to 0 and less than {NumVertices}"); + } + } } public static class MeshCommonExtensions { - public static IMeshCommon ReverseWindingOrder(this IMeshCommon mesh) + public static VimMesh ReverseWindingOrder(this VimMesh mesh) { var result = mesh.Clone(); var count = mesh.Indices.Count; @@ -243,7 +254,7 @@ public static IMeshCommon ReverseWindingOrder(this IMeshCommon mesh) } - public static IArray GetFaceMaterials(this IMeshCommon mesh) + public static IArray GetFaceMaterials(this VimMesh mesh) { // SubmeshIndexOffsets: [0, A, B] // SubmeshIndexCount: [X, Y, Z] @@ -257,9 +268,9 @@ public static IArray GetFaceMaterials(this IMeshCommon mesh) .ToIArray(); } - public static IMeshCommon Merge2(this IMeshCommon mesh, params IMeshCommon[] others) + public static VimMesh Merge2(this VimMesh mesh, params VimMesh[] others) { - var meshes = Enumerable.Empty() + var meshes = Enumerable.Empty() .Append(mesh) .Append(others) .ToArray(); @@ -267,7 +278,7 @@ public static IMeshCommon Merge2(this IMeshCommon mesh, params IMeshCommon[] oth return meshes.Merge(); } - public static IMeshCommon Merge(this IMeshCommon[] meshes) + public static VimMesh Merge(this VimMesh[] meshes) { void Merge(IArray from, int[] to, int offset, int increment) { @@ -305,12 +316,12 @@ void Merge(IArray from, int[] to, int offset, int increment) return result; } - public static VimMesh[] SplitSubmeshes(this IMeshCommon mesh) + public static VimMesh[] SplitSubmeshes(this VimMesh mesh) { return null; } - public static (int, List)[] GroupSubmeshesByMaterials(this IMeshCommon mesh) + public static (int, List)[] GroupSubmeshesByMaterials(this VimMesh mesh) { var submeshCount = mesh.SubmeshIndexOffsets.Count; var map = new Dictionary>(); @@ -329,41 +340,41 @@ public static (int, List)[] GroupSubmeshesByMaterials(this IMeshCommon mesh return map.Select(kvp => (kvp.Key, kvp.Value)).ToArray(); } - public static Triangle VertexIndicesToTriangle(this IMeshCommon mesh, Int3 indices) + public static Triangle VertexIndicesToTriangle(this VimMesh mesh, Int3 indices) => new Triangle(mesh.Vertices[indices.X], mesh.Vertices[indices.Y], mesh.Vertices[indices.Z]); - public static bool Planar(this IMeshCommon mesh, float tolerance = Math3d.Constants.Tolerance) + public static bool Planar(this VimMesh mesh, float tolerance = Math3d.Constants.Tolerance) { if (mesh.NumFaces <= 1) return true; var normal = mesh.Triangle(0).Normal; return mesh.ComputedNormals().All(n => n.AlmostEquals(normal, tolerance)); } - public static VimMesh Unindex(this IMeshCommon mesh) + public static VimMesh Unindex(this VimMesh mesh) { var vertices = mesh.Indices.Select(i => mesh.Vertices[i]); return new VimMesh(vertices.ToArray()); } - public static IArray ComputedNormals(this IMeshCommon mesh) + public static IArray ComputedNormals(this VimMesh mesh) => mesh.Triangles().Select(t => t.Normal); - public static Triangle Triangle(this IMeshCommon mesh, int face) + public static Triangle Triangle(this VimMesh mesh, int face) => mesh.VertexIndicesToTriangle(mesh.FaceVertexIndices(face)); - public static IArray Triangles(this IMeshCommon mesh) + public static IArray Triangles(this VimMesh mesh) => mesh.NumFaces.Select(mesh.Triangle); - public static Vector3 Center(this IMeshCommon mesh) + public static Vector3 Center(this VimMesh mesh) => mesh.BoundingBox().Center; - public static AABox BoundingBox(this IMeshCommon mesh) + public static AABox BoundingBox(this VimMesh mesh) => AABox.Create(mesh.Vertices.ToEnumerable()); - public static Int3 FaceVertexIndices(this IMeshCommon mesh, int faceIndex) + public static Int3 FaceVertexIndices(this VimMesh mesh, int faceIndex) => new Int3(mesh.Indices[faceIndex * 3], mesh.Indices[faceIndex * 3 + 1], mesh.Indices[faceIndex * 3 + 2]); - public static bool GeometryEquals(this IMeshCommon mesh, IMeshCommon other, float tolerance = Math3d.Constants.Tolerance) + public static bool GeometryEquals(this VimMesh mesh, VimMesh other, float tolerance = Math3d.Constants.Tolerance) { if (!mesh.Indices.SequenceEquals(other.Indices)) return false; @@ -389,11 +400,11 @@ public static bool GeometryEquals(this IMeshCommon mesh, IMeshCommon other, floa return true; } - public static (int mat, IMeshCommon mesh)[] SplitByMaterial(this IMeshCommon mesh) + public static (int mat, VimMesh mesh)[] SplitByMaterial(this VimMesh mesh) { var map = mesh.GroupSubmeshesByMaterials(); - var result = new (int, IMeshCommon)[map.Length]; + var result = new (int, VimMesh)[map.Length]; if (map.Length == 1) { result[0] = (mesh.SubmeshMaterials[0], mesh); @@ -409,7 +420,7 @@ public static (int mat, IMeshCommon mesh)[] SplitByMaterial(this IMeshCommon mes return result; } - public static VimMesh PickSubmeshes(this IMeshCommon mesh, IList submeshes) + public static VimMesh PickSubmeshes(this VimMesh mesh, IList submeshes) { var map = mesh.GroupSubmeshesByMaterials(); diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 22945f35..7863f425 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -11,14 +11,14 @@ namespace Vim.Format.Tests.Geometry { public static class GeometryTests { - public static IMeshCommon XYTriangle = new VimMesh( + public static VimMesh XYTriangle = new VimMesh( new[] { 0, 1, 2 }, new[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(1f, 0f, 0f) }); - public static IMeshCommon XYQuad = VimMesh.FromQuad( + public static VimMesh XYQuad = VimMesh.FromQuad( new int[] { 0, 1, 2, 3 }, new[]{ new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f), @@ -26,11 +26,11 @@ public static class GeometryTests new Vector3(1f, 0f, 0f) }); - public static IMeshCommon XYQuadFromFunc = Primitives.QuadMesh(uv => uv.ToVector3(), 1, 1); - public static IMeshCommon XYQuad2x2 = Primitives.QuadMesh(uv => uv.ToVector3(), 2, 2); - public static IMeshCommon XYTriangleTwice = XYTriangle.Merge2(XYTriangle.Translate(new Vector3(1, 0, 0))); + public static VimMesh XYQuadFromFunc = Primitives.QuadMesh(uv => uv.ToVector3(), 1, 1); + public static VimMesh XYQuad2x2 = Primitives.QuadMesh(uv => uv.ToVector3(), 2, 2); + public static VimMesh XYTriangleTwice = XYTriangle.Merge2(XYTriangle.Translate(new Vector3(1, 0, 0))); - public static IMeshCommon Tetrahedron = new VimMesh( + public static VimMesh Tetrahedron = new VimMesh( new[] { 0, 1, 2, 0, 3, 1, 1, 3, 2, 2, 3, 0 }, new[] { Vector3.Zero, Vector3.UnitX, @@ -38,14 +38,14 @@ public static class GeometryTests Vector3.UnitZ }); - public static IMeshCommon Torus = Primitives.Torus(10, 0.2f, 10, 24); + public static VimMesh Torus = Primitives.Torus(10, 0.2f, 10, 24); - static IMeshCommon RevolvedVerticalCylinder(float height, float radius, int verticalSegments, int radialSegments) + static VimMesh RevolvedVerticalCylinder(float height, float radius, int verticalSegments, int radialSegments) => (Vector3.UnitZ * height).ToLine().Interpolate(verticalSegments).Add(-radius.AlongX()).RevolveAroundAxis(Vector3.UnitZ, radialSegments); - public static IMeshCommon Cylinder = RevolvedVerticalCylinder(5, 1, 4, 12); + public static VimMesh Cylinder = RevolvedVerticalCylinder(5, 1, 4, 12); - public static IMeshCommon[] AllMeshes = { + public static VimMesh[] AllMeshes = { XYTriangle, // 0 XYQuad, // 1 XYQuadFromFunc, // 2 @@ -58,7 +58,7 @@ static IMeshCommon RevolvedVerticalCylinder(float height, float radius, int vert public static double SmallTolerance = 0.0001; - public static void GeometryNullOps(IMeshCommon g) + public static void GeometryNullOps(VimMesh g) { g.GeometryEquals(g); g.Translate(Vector3.Zero).GeometryEquals(g); diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 49814ab1..9c09387e 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -200,32 +200,6 @@ public static void Materials_AreSame() // mesh.SubmeshMaterials.Sum(); //} - private static void Consume(IMeshCommon mesh) - { - mesh.Indices.Sum(); - mesh.Vertices.Sum(v => v.X); - mesh.SubmeshIndexOffsets.Sum(); - mesh.SubmeshIndexCounts.Sum(); - mesh.SubmeshMaterials.Sum(); - } - - - //private static void MeshesAreSame(IMesh mesh, IMeshCommon next) - //{ - // Assert.That(mesh.Indices.SequenceEquals(next.Indices)); - // Assert.That(mesh.Vertices.SequenceEquals(next.Vertices)); - // Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.SubmeshIndexOffsets)); - // Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.SubmeshMaterials)); - // Assert.That(mesh.SubmeshIndexCount.SequenceEquals(next.SubmeshIndexCounts)); - //} - private static void MeshesAreSame(IMeshCommon mesh, IMeshCommon next) - { - Assert.That(mesh.Indices.SequenceEquals(next.Indices)); - Assert.That(mesh.Vertices.SequenceEquals(next.Vertices)); - Assert.That(mesh.SubmeshIndexOffsets.SequenceEquals(next.SubmeshIndexOffsets)); - Assert.That(mesh.SubmeshMaterials.SequenceEquals(next.SubmeshMaterials)); - Assert.That(mesh.SubmeshIndexCounts.SequenceEquals(next.SubmeshIndexCounts)); - } private static void ShapesAreSame(VimShape mesh, VimShapeNext next) { diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 85675c93..74da76ab 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -82,10 +82,10 @@ public string PersistingId public int GetShapeCount() => Shapes.Length; public int GetNodeCount() => Nodes.Length; - public IEnumerable TransformedMeshes() + public IEnumerable TransformedMeshes() => Nodes.Where(n => n.GetMesh() != null).Select(n => n.TransformedMesh()); - public IMeshCommon MergedGeometry() + public VimMesh MergedGeometry() => Nodes.MergedGeometry(); public IEnumerable AllVertices() diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 9d2eba2b..28e37b5f 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -28,13 +28,7 @@ public VimSceneNode(VimScene scene, int nodeIndex, int geometryIndex, Matrix4x4 public Matrix4x4 Transform { get; } public bool HideByDefault - { - get - { - var instanceFlags = (InstanceFlags)Scene.Document.Geometry.InstanceFlags.ElementAtOrDefault(NodeIndex); - return (instanceFlags & InstanceFlags.Hidden) == InstanceFlags.Hidden; - } - } + => Scene.Document.GeometryNext.InstanceHasFlag(NodeIndex, G3dNext.InstanceFlags.Hidden); public int VimIndex { get; } = -1; public int NodeIndex { get; } = -1; @@ -58,7 +52,7 @@ public VimMesh GetMesh() VimSceneNode ITransformable3D.Transform(Matrix4x4 mat) => new VimSceneNode(Scene, Id, MeshIndex, mat * Transform); - public IMeshCommon TransformedMesh() + public VimMesh TransformedMesh() => GetMesh()?.Transform(Transform); public IArray TransformedVertices() @@ -70,7 +64,7 @@ public AABox TransformedBoundingBox() public static class NodeExtensions { - public static IMeshCommon MergedGeometry(this IEnumerable nodes) + public static VimMesh MergedGeometry(this IEnumerable nodes) => nodes.Where(n => n.GetMesh() != null).Select(n => n.TransformedMesh()).ToArray().Merge(); } } From 29e340172948ab68859c2d9a49baad769a1571ee Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 12 Apr 2024 16:12:02 -0400 Subject: [PATCH 058/104] removing g3d using --- .../DocumentBuilderExtensions.cs | 1 - .../Vim.Format.Core/DocumentBuilderTypes.cs | 3 +- .../Geometry/PerimeterProjection.cs | 1 - .../Vim.Format.Core/Geometry/Primitives.cs | 1 - .../Vim.Format.Core/Geometry/Validation.cs | 30 ------------------- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 1 - src/cs/vim/Vim.Format.Core/Validation.cs | 30 ------------------- .../Geometry/GeometryTests.cs | 5 ++-- .../SerializableDocumentTests.cs | 11 +++---- .../vim/Vim.Format/SceneBuilder/Validation.cs | 3 +- .../Vim.Format/SceneBuilder/VimSceneNode.cs | 1 - 11 files changed, 8 insertions(+), 79 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index 6ca4fc9b..27597945 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -2,7 +2,6 @@ using System.Linq; using Vim.BFastLib; using Vim.Format.Geometry; -using Vim.G3d; using Vim.LinqArray; using static Vim.Format.DocumentBuilder; diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs index ca2c4f94..7d48f289 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs @@ -2,9 +2,8 @@ using System.Collections.Generic; using System.Linq; using Vim.Format.Geometry; -using Vim.G3d; +using Vim.G3dNext; using Vim.Math3d; -using static Vim.Format.DocumentBuilder; namespace Vim.Format { diff --git a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs index b6427d01..d4418352 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs @@ -4,7 +4,6 @@ using System.Linq; using Vim.LinqArray; using Vim.Math3d; -using Vim.G3d; namespace Vim.Format.Geometry { diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index 01b15b0d..97e09d20 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Vim.G3d; using Vim.LinqArray; using Vim.Math3d; diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index 88cf5f9f..e987282a 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using Vim.G3d; using Vim.LinqArray; using Vim.BFastLib; @@ -45,34 +43,6 @@ public static void ValidateIndexColumns(this Document doc) } } - public static string[] RequiredAttributeNames => new [] - { - // Vertices - CommonAttributes.Position, - CommonAttributes.Index, - - // Meshes - CommonAttributes.MeshSubmeshOffset, - - // Submeshes - CommonAttributes.SubmeshIndexOffset, - - // Instances - CommonAttributes.InstanceMesh, - CommonAttributes.InstanceTransform, - }; - - public static void ValidateGeometryAttributes(this Document doc) - { - var attributes = doc.Geometry.Attributes; - var attributeNameSet = new HashSet(attributes.Select(a => a.Name).ToEnumerable()); - foreach (var attributeName in RequiredAttributeNames) - { - if (!attributeNameSet.Contains(attributeName)) - throw new Exception($"Required attribute {attributeName} was not found."); - } - } - public static void ValidateAssets(this Document doc) { foreach (var asset in doc.Assets.Values.ToEnumerable()) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 43ec0313..719d9a8f 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Vim.G3d; using Vim.G3dNext; using Vim.LinqArray; using Vim.Math3d; diff --git a/src/cs/vim/Vim.Format.Core/Validation.cs b/src/cs/vim/Vim.Format.Core/Validation.cs index 5419ef54..e44b2d1c 100644 --- a/src/cs/vim/Vim.Format.Core/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Validation.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Vim.BFastLib; -using Vim.G3d; using Vim.LinqArray; namespace Vim.Format @@ -45,34 +44,6 @@ public static void ValidateIndexColumns(this Document doc) } } - public static string[] RequiredAttributeNames => new [] - { - // Vertices - CommonAttributes.Position, - CommonAttributes.Index, - - // Meshes - CommonAttributes.MeshSubmeshOffset, - - // Submeshes - CommonAttributes.SubmeshIndexOffset, - - // Instances - CommonAttributes.InstanceMesh, - CommonAttributes.InstanceTransform, - }; - - public static void ValidateGeometryAttributes(this Document doc) - { - var attributes = doc.Geometry.Attributes; - var attributeNameSet = new HashSet(attributes.Select(a => a.Name).ToEnumerable()); - foreach (var attributeName in RequiredAttributeNames) - { - if (!attributeNameSet.Contains(attributeName)) - throw new Exception($"Required attribute {attributeName} was not found."); - } - } - public static void ValidateAssets(this Document doc) { foreach (var asset in doc.Assets.Values.ToEnumerable()) @@ -83,7 +54,6 @@ public static void Validate(this Document doc) { doc.ValidateTableRows(); doc.ValidateIndexColumns(); - doc.ValidateGeometryAttributes(); doc.ValidateAssets(); } diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 7863f425..334c882c 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -1,8 +1,7 @@ -using System; +using NUnit.Framework; +using System; using System.Linq; -using NUnit.Framework; using Vim.Format.Geometry; -using Vim.G3d; using Vim.G3dNext; using Vim.LinqArray; using Vim.Math3d; diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 9c09387e..676a99f0 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -1,13 +1,10 @@ using NUnit.Framework; -using Vim.Util.Tests; -using Vim.Format.SceneBuilder; -using Vim.G3dNext; +using System; +using System.Linq; using Vim.Format.Geometry; +using Vim.Format.SceneBuilder; using Vim.LinqArray; -using Vim.Math3d; -using Vim.G3d; -using System.Linq; -using System; +using Vim.Util.Tests; namespace Vim.Format.Tests; diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index eb9cddbb..b969efe3 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -6,10 +6,9 @@ using Vim.BFastLib; using Vim.Format.Geometry; using Vim.Format.ObjectModel; -using Vim.Util; using Vim.LinqArray; using Vim.Math3d; -using Vim.G3d; +using Vim.Util; namespace Vim.Format.SceneBuilder { diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 28e37b5f..28e34077 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -3,7 +3,6 @@ using System.Linq; using Vim.Format.Geometry; using Vim.Format.ObjectModel; -using Vim.G3d; using Vim.G3dNext; using Vim.LinqArray; using Vim.Math3d; From 2fa516ff7e69b09a193cf1936ddae862bac1ff66 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 15 Apr 2024 14:37:20 -0400 Subject: [PATCH 059/104] removed old geometry --- src/cs/vim/Vim.Format.Core/Document.cs | 2 - .../Vim.Format.Core/SerializableDocument.cs | 6 --- .../SerializableDocumentTests.cs | 42 ------------------- .../vim/Vim.Format/SceneBuilder/Validation.cs | 6 +-- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 15 +------ .../vim/Vim.Format/SceneBuilder/VimShape.cs | 25 ----------- 6 files changed, 5 insertions(+), 91 deletions(-) delete mode 100644 src/cs/vim/Vim.Format/SceneBuilder/VimShape.cs diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index eecebb48..27a4d978 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -11,7 +11,6 @@ public Document(SerializableDocument document) { _Document = document; Header = _Document.Header; - Geometry = _Document.Geometry; GeometryNext = _Document.GeometryNext; StringTable = _Document.StringTable.ToIArray(); EntityTables = _Document.EntityTables.ToLookup( @@ -27,7 +26,6 @@ public Document(SerializableDocument document) public ILookup Assets { get; } public IArray StringTable { get; } public string GetString(int index) => StringTable.ElementAtOrDefault(index); - public G3d.G3D Geometry { get; } public G3dVim GeometryNext { get; } } } diff --git a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs index 31f1772e..94364b97 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs @@ -49,11 +49,6 @@ public class SerializableDocument /// public INamedBuffer[] Assets = Array.Empty(); - /// - /// The uninstanced / untransformed geometry - /// - public G3d.G3D Geometry; - /// /// The uninstanced / untransformed geometry /// @@ -128,7 +123,6 @@ public static SerializableDocument FromBFast(BFast bfast, LoadOptions options = { var geo = bfast.GetBFast(BufferNames.Geometry); doc.GeometryNext = new G3dVim(geo); - doc.Geometry = G3D.Read(geo); } var entities = bfast.GetBFast(BufferNames.Entities); diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 676a99f0..409323e5 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -28,40 +28,6 @@ public static void CanOpenVim() scene.Validate(); } - [Test] - public static void ShapesAreSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - - var shapes = scene.ShapesOld; - var next = scene.Shapes; - Assert.AreEqual(shapes.Count, next.Length); - for (var i = 0; i < shapes.Count; i++) - { - ShapesAreSame(shapes[i], next[i]); - } - } - - - - [Test] - public static void Materials_AreSame() - { - var path = VimFormatRepoPaths.GetLatestWolfordResidenceVim(); - var scene = VimScene.LoadVim(path); - - var mats = scene.MaterialsOld; - var next = scene.Materials; - Assert.AreEqual(mats.Count, next.Length); - for (var i = 0; i < mats.Count; i++) - { - MaterialsAreSame(mats[i], next[i]); - } - - } - - //[Test] //public static void GetMesh_IsSameMesh() //{ @@ -197,14 +163,6 @@ public static void Materials_AreSame() // mesh.SubmeshMaterials.Sum(); //} - - private static void ShapesAreSame(VimShape mesh, VimShapeNext next) - { - Assert.That(mesh.Vertices.ToEnumerable().SequenceEqual(next.Vertices)); - Assert.AreEqual(mesh.Color, next.Color); - Assert.AreEqual(mesh.Width, next.Width); - } - private static void MaterialsAreSame(IMaterial mesh, VimMaterialNext next) { Assert.AreEqual(mesh.Color, next.Color); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index b969efe3..ceb34e38 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -91,7 +91,7 @@ public static void ValidateShapes(this VimScene vim) { var shapes = vim.Shapes; if (vim.GetShapeCount() != vim.DocumentModel.NumShape) - throw new VimValidationException($"The number of {nameof(VimShape)} ({vim.GetShapeCount()}) does not match the number of shape entities ({vim.DocumentModel.NumShape})"); + throw new VimValidationException($"The number of {nameof(VimShapeNext)} ({vim.GetShapeCount()}) does not match the number of shape entities ({vim.DocumentModel.NumShape})"); void ValidateColorDomain(string label, Vector4 value, Vector4 lowerInclusive, Vector4 upperInclusive, int index) { @@ -113,8 +113,8 @@ void ValidateColorDomain(string label, Vector4 value, Vector4 lowerInclusive, Ve var shape = shapes[shapeIndex]; var element = vim.DocumentModel.GetShapeElementIndex(shapeIndex); if (element < 0) - throw new VimValidationException($"{nameof(Element)} is null for {nameof(VimShape)} {shape.Index}"); - ValidateColorDomain($"{nameof(VimShape)} color", shape.Color, Vector4.Zero, Vector4.One, shape.Index); + throw new VimValidationException($"{nameof(Element)} is null for {nameof(VimShapeNext)} {shape.Index}"); + ValidateColorDomain($"{nameof(VimShapeNext)} color", shape.Color, Vector4.Zero, Vector4.One, shape.Index); }); } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 74da76ab..ec11608c 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -66,10 +66,6 @@ public static VimScene LoadVim(Stream stream, IVimSceneProgress progress = null, public VimShapeNext[] Shapes { get; private set; } public VimMaterialNext[] Materials { get; private set; } - public IArray ShapesOld { get; private set; } - public IArray MaterialsOld { get; private set; } - public IArray MeshesOld { get; private set; } - public SerializableDocument _SerializableDocument { get; } public Document Document { get; private set; } public DocumentModel DocumentModel { get; private set; } @@ -204,7 +200,6 @@ private void CreateMeshes(bool inParallel) } Meshes = VimMesh.GetAllMeshes(_SerializableDocument.GeometryNext).ToArray(); - MeshesOld = _SerializableDocument.Geometry?.Meshes.Select(m => m as IMeshCommon); } private void CreateShapes(bool inParallel) @@ -213,8 +208,6 @@ private void CreateShapes(bool inParallel) { return; } - var r = _SerializableDocument.Geometry.Shapes.Select((s, i) => new VimShape(this, i)); - ShapesOld = inParallel ? r.EvaluateInParallel() : r.Evaluate(); Shapes = VimShapeNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); } @@ -225,7 +218,7 @@ private void CreateScene(bool inParallel) return; } - Nodes = CreateVimSceneNodes(this, _SerializableDocument.Geometry, inParallel); + Nodes = CreateVimSceneNodes(this, _SerializableDocument.GeometryNext, inParallel); } private void CreateMaterials(bool inParallel) @@ -234,14 +227,10 @@ private void CreateMaterials(bool inParallel) { return; } - - var query = _SerializableDocument.Geometry.Materials.Select(m => new VimMaterial(m) as IMaterial); - MaterialsOld = inParallel ? query.EvaluateInParallel() : query.Evaluate(); Materials = VimMaterialNext.FromG3d(_SerializableDocument.GeometryNext).ToArray(); - } - public static VimSceneNode[] CreateVimSceneNodes(VimScene scene, G3D g3d, bool inParallel) + public static VimSceneNode[] CreateVimSceneNodes(VimScene scene, G3dVim g3d, bool inParallel) { Matrix4x4 GetMatrix(int i) => i >= 0 ? g3d.InstanceTransforms[i] : Matrix4x4.Identity; diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimShape.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimShape.cs deleted file mode 100644 index 112a6a13..00000000 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimShape.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Vim.Format.ObjectModel; -using Vim.G3d; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim -{ - public class VimShape : ElementInfo - { - public readonly VimScene Scene; - public readonly int ShapeIndex; - - public G3dShape G3dShape => Scene.Document.Geometry.Shapes[ShapeIndex]; - public IArray Vertices => G3dShape.Vertices; - public Vector4 Color => G3dShape.Color; - public float Width => G3dShape.Width; - - public VimShape(VimScene scene, int shapeIndex) - : base(scene.DocumentModel, scene.DocumentModel.GetShapeElementIndex(shapeIndex)) - { - Scene = scene; - ShapeIndex = shapeIndex; - } - } -} From 75749ba96ef4d152cd68ec3e07a8ab16776d538a Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 15 Apr 2024 15:03:22 -0400 Subject: [PATCH 060/104] removed g3d --- src/cs/g3d/Vim.G3d/AttributeDescriptor.cs | 158 -------- src/cs/g3d/Vim.G3d/AttributeExtensions.cs | 126 ------- src/cs/g3d/Vim.G3d/CommonAttributes.cs | 231 ------------ src/cs/g3d/Vim.G3d/CommonAttributes.tt | 95 ----- src/cs/g3d/Vim.G3d/Enums.cs | 98 ----- src/cs/g3d/Vim.G3d/G3D.cs | 345 ------------------ src/cs/g3d/Vim.G3d/G3dMaterial.cs | 20 - src/cs/g3d/Vim.G3d/G3dMesh.cs | 120 ------ src/cs/g3d/Vim.G3d/G3dShape.cs | 23 -- src/cs/g3d/Vim.G3d/GeometryAttribute.cs | 245 ------------- src/cs/g3d/Vim.G3d/GeometryAttributes.cs | 164 --------- .../Vim.G3d/GeometryAttributesExtensions.cs | 29 -- src/cs/g3d/Vim.G3d/Header.cs | 81 ---- src/cs/g3d/Vim.G3d/IGeometryAttributes.cs | 22 -- src/cs/g3d/Vim.G3dNext/Constants.cs | 34 +- src/cs/vim-format.sln | 14 - src/cs/vim/Vim.Format.Core/G3dBuilder.cs | 2 +- .../Geometry/MeshOptimization.cs | 1 - .../Vim.Format.Core/Geometry/VimMaterial.cs | 21 -- .../Geometry/VimMaterialNext.cs | 8 + .../Vim.Format.Core/SerializableDocument.cs | 1 - .../Vim.Format.Core/Vim.Format.Core.csproj | 1 - .../vim/Vim.Format/SceneBuilder/VimScene.cs | 9 +- src/cs/vim/Vim.Format/Vim.Format.csproj | 1 - 24 files changed, 46 insertions(+), 1803 deletions(-) delete mode 100644 src/cs/g3d/Vim.G3d/AttributeDescriptor.cs delete mode 100644 src/cs/g3d/Vim.G3d/AttributeExtensions.cs delete mode 100644 src/cs/g3d/Vim.G3d/CommonAttributes.cs delete mode 100644 src/cs/g3d/Vim.G3d/CommonAttributes.tt delete mode 100644 src/cs/g3d/Vim.G3d/Enums.cs delete mode 100644 src/cs/g3d/Vim.G3d/G3D.cs delete mode 100644 src/cs/g3d/Vim.G3d/G3dMaterial.cs delete mode 100644 src/cs/g3d/Vim.G3d/G3dMesh.cs delete mode 100644 src/cs/g3d/Vim.G3d/G3dShape.cs delete mode 100644 src/cs/g3d/Vim.G3d/GeometryAttribute.cs delete mode 100644 src/cs/g3d/Vim.G3d/GeometryAttributes.cs delete mode 100644 src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs delete mode 100644 src/cs/g3d/Vim.G3d/Header.cs delete mode 100644 src/cs/g3d/Vim.G3d/IGeometryAttributes.cs delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/VimMaterial.cs diff --git a/src/cs/g3d/Vim.G3d/AttributeDescriptor.cs b/src/cs/g3d/Vim.G3d/AttributeDescriptor.cs deleted file mode 100644 index a2f48840..00000000 --- a/src/cs/g3d/Vim.G3d/AttributeDescriptor.cs +++ /dev/null @@ -1,158 +0,0 @@ -using System; - -namespace Vim.G3d -{ - /// - /// Provides information about identifying the role and parsing the data within an attribute data buffer. - /// This is encoded using a string in a particular URN form. - /// - public class AttributeDescriptor - { - public Association Association { get; } - public string Semantic { get; } - public DataType DataType { get; } - public int DataArity { get; } - public int Index { get; } - - public int DataElementSize { get; } - public int DataTypeSize { get; } - public string Name { get; } - - public AttributeDescriptor(Association association, string semantic, DataType dataType, int dataArity, int index = 0) - { - Association = association; - if (semantic.Contains(":")) - throw new Exception("The semantic must not contain a semicolon"); - Semantic = semantic; - DataType = dataType; - DataArity = dataArity; - Index = index; - DataTypeSize = GetDataTypeSize(DataType); - DataElementSize = DataTypeSize * DataArity; - Name = $"g3d:{AssociationString}:{Semantic}:{Index}:{DataTypeString}:{DataArity}"; - } - - /// - /// Generates a URN representation of the attribute descriptor - /// - public override string ToString() - => Name; - - /// - /// Returns true if the attribute descriptor has been successfully parsed. - /// - public static bool TryParse(string urn, out AttributeDescriptor attributeDescriptor) - { - attributeDescriptor = null; - try - { - attributeDescriptor = Parse(urn); - } - catch - { - // do nothing. - } - - return attributeDescriptor != null; - } - - /// - /// Parses a URN representation of the attribute descriptor to generate an actual attribute descriptor - /// - public static AttributeDescriptor Parse(string urn) - { - var vals = urn.Split(':'); - if (vals.Length != 6) throw new Exception("Expected 6 parts to the attribute descriptor URN"); - if (vals[0] != "g3d") throw new Exception("First part of URN must be g3d"); - return new AttributeDescriptor( - ParseAssociation(vals[1]), - vals[2], - ParseDataType(vals[4]), - int.Parse(vals[5]), - int.Parse(vals[3]) - ); - } - - public bool Validate() - { - var urn = ToString(); - var tmp = Parse(urn); - if (!Equals(tmp)) - throw new Exception("Invalid attribute descriptor (or internal error in the parsing/string conversion"); - return true; - } - - public bool Equals(AttributeDescriptor other) - => ToString() == other.ToString(); - - public static int GetDataTypeSize(DataType dt) - { - switch (dt) - { - case DataType.dt_uint8: - case DataType.dt_int8: - return 1; - case DataType.dt_uint16: - case DataType.dt_int16: - return 2; - case DataType.dt_uint32: - case DataType.dt_int32: - return 4; - case DataType.dt_uint64: - case DataType.dt_int64: - return 8; - case DataType.dt_float32: - return 4; - case DataType.dt_float64: - return 8; - default: - throw new ArgumentOutOfRangeException(nameof(dt), dt, null); - } - } - - public string AssociationString - => Association.ToString().Substring("assoc_".Length); - - public static Association ParseAssociation(string s) - { - switch (s) - { - case "all": - return Association.assoc_all; - case "corner": - return Association.assoc_corner; - case "edge": - return Association.assoc_edge; - case "face": - return Association.assoc_face; - case "instance": - return Association.assoc_instance; - case "vertex": - return Association.assoc_vertex; - case "shapevertex": - return Association.assoc_shapevertex; - case "shape": - return Association.assoc_shape; - case "material": - return Association.assoc_material; - case "mesh": - return Association.assoc_mesh; - case "submesh": - return Association.assoc_submesh; - - // Anything else we just treat as unknown - default: - return Association.assoc_none; - } - } - - public string DataTypeString - => DataType.ToString()?.Substring("dt_".Length) ?? null; - - public static DataType ParseDataType(string s) - => (DataType)Enum.Parse(typeof(DataType), "dt_" + s); - - public AttributeDescriptor SetIndex(int index) - => new AttributeDescriptor(Association, Semantic, DataType, DataArity, index); - } -} diff --git a/src/cs/g3d/Vim.G3d/AttributeExtensions.cs b/src/cs/g3d/Vim.G3d/AttributeExtensions.cs deleted file mode 100644 index aedfed52..00000000 --- a/src/cs/g3d/Vim.G3d/AttributeExtensions.cs +++ /dev/null @@ -1,126 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.G3d -{ - public static class AttributeExtensions - { - public static GeometryAttribute ToAttribute(this IArray self, AttributeDescriptor desc) where T : unmanaged - => new GeometryAttribute(self, desc); - - public static GeometryAttribute ToAttribute(this IArray self, string desc) where T : unmanaged - => self.ToAttribute(AttributeDescriptor.Parse(desc)); - - public static GeometryAttribute ToAttribute(this IArray self, string desc, int index) where T : unmanaged - => self.ToAttribute(AttributeDescriptor.Parse(desc).SetIndex(index)); - - public static IArray AttributeToColors(this GeometryAttribute attr) - { - var desc = attr.Descriptor; - if (desc.DataType == DataType.dt_float32) - { - if (desc.DataArity == 4) - return attr.AsType().Data; - if (desc.DataArity == 3) - return attr.AsType().Data.Select(vc => new Vector4(vc, 1f)); - if (desc.DataArity == 2) - return attr.AsType().Data.Select(vc => new Vector4(vc.X, vc.Y, 0, 1f)); - if (desc.DataArity == 1) - return attr.AsType().Data.Select(vc => new Vector4(vc, vc, vc, 1f)); - } - if (desc.DataType == DataType.dt_int8) - { - if (desc.DataArity == 4) - return attr.AsType().Data.Select(b => new Vector4(b.X / 255f, b.Y / 255f, b.Z / 255f, b.W / 255f)); - if (desc.DataArity == 3) - return attr.AsType().Data.Select(b => new Vector4(b.X / 255f, b.Y / 255f, b.Z / 255f, 1f)); - if (desc.DataArity == 2) - return attr.AsType().Data.Select(b => new Vector4(b.X / 255f, b.Y / 255f, 0f, 1f)); - if (desc.DataArity == 1) - return attr.AsType().Data.Select(b => new Vector4(b / 255f, b / 255f, b / 255f, 1f)); - } - Debug.WriteLine($"Failed to recongize color format {attr.Descriptor}"); - return null; - } - - public static GeometryAttribute ToDefaultAttribute(this AttributeDescriptor desc, int count) - { - switch (desc.DataType) - { - // TODO: TECH DEBT - Add unsigned tuple objects to Math3d - case DataType.dt_uint8: - if (desc.DataArity == 1) - return default(byte).Repeat(count).ToAttribute(desc); - break; - case DataType.dt_int8: - if (desc.DataArity == 1) - return default(byte).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 2) - return default(Byte2).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 3) - return default(Byte3).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 4) - return default(Byte4).Repeat(count).ToAttribute(desc); - break; - case DataType.dt_uint16: - if (desc.DataArity == 1) - return default(ushort).Repeat(count).ToAttribute(desc); - break; - case DataType.dt_int16: - if (desc.DataArity == 1) - return default(short).Repeat(count).ToAttribute(desc); - break; - case DataType.dt_uint32: - if (desc.DataArity == 1) - return default(uint).Repeat(count).ToAttribute(desc); - break; - case DataType.dt_int32: - if (desc.DataArity == 1) - return default(int).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 2) - return default(Int2).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 3) - return default(Int3).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 4) - return default(Int4).Repeat(count).ToAttribute(desc); - break; - case DataType.dt_uint64: - if (desc.DataArity == 1) - return default(ulong).Repeat(count).ToAttribute(desc); - break; - case DataType.dt_int64: - if (desc.DataArity == 1) - return default(long).Repeat(count).ToAttribute(desc); - break; - case DataType.dt_float32: - if (desc.DataArity == 1) - return default(float).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 2) - return default(Vector2).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 3) - return default(Vector3).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 4) - return default(Vector4).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 16) - return default(Matrix4x4).Repeat(count).ToAttribute(desc); - break; - case DataType.dt_float64: - if (desc.DataArity == 1) - return default(double).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 2) - return default(DVector2).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 3) - return default(DVector3).Repeat(count).ToAttribute(desc); - if (desc.DataArity == 4) - return default(DVector4).Repeat(count).ToAttribute(desc); - break; - } - - throw new Exception($"Could not create a default attribute for {desc}"); - } - } -} diff --git a/src/cs/g3d/Vim.G3d/CommonAttributes.cs b/src/cs/g3d/Vim.G3d/CommonAttributes.cs deleted file mode 100644 index da835913..00000000 --- a/src/cs/g3d/Vim.G3d/CommonAttributes.cs +++ /dev/null @@ -1,231 +0,0 @@ - -// AUTOGENERATED FILE: DO NOT EDIT -// This file is generated from CommonAttributeExtensions.tt - - -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.G3d -{ - public static class CommonAttributes - { - - public const string ObjectFaceSize = "g3d:all:facesize:0:int32:1"; - public const string Index = "g3d:corner:index:0:int32:1"; - public const string Position = "g3d:vertex:position:0:float32:3"; - public const string VertexUv = "g3d:vertex:uv:0:float32:2"; - public const string VertexUvw = "g3d:vertex:uv:0:float32:3"; - public const string VertexNormal = "g3d:vertex:normal:0:float32:3"; - public const string VertexColor = "g3d:vertex:color:0:float32:4"; - public const string VertexColor8Bit = "g3d:vertex:color:0:int8:4"; - public const string VertexBitangent = "g3d:vertex:bitangent:0:float32:3"; - public const string VertexTangent = "g3d:vertex:tangent:0:float32:4"; - public const string VertexSelectionWeight = "g3d:vertex:weight:0:float32:1"; - public const string FaceColor = "g3d:face:color:0:float32:4"; - public const string FaceMaterial = "g3d:face:material:0:int32:1"; - public const string FaceNormal = "g3d:face:normal:0:float32:3"; - public const string MeshSubmeshOffset = "g3d:mesh:submeshoffset:0:int32:1"; - public const string InstanceTransform = "g3d:instance:transform:0:float32:16"; - public const string InstanceParent = "g3d:instance:parent:0:int32:1"; - public const string InstanceMesh = "g3d:instance:mesh:0:int32:1"; - public const string InstanceFlags = "g3d:instance:flags:0:uint16:1"; - public const string LineTangentIn = "g3d:vertex:tangent:0:float32:3"; - public const string LineTangentOut = "g3d:vertex:tangent:1:float32:3"; - public const string ShapeVertex = "g3d:shapevertex:position:0:float32:3"; - public const string ShapeVertexOffset = "g3d:shape:vertexoffset:0:int32:1"; - public const string ShapeColor = "g3d:shape:color:0:float32:4"; - public const string ShapeWidth = "g3d:shape:width:0:float32:1"; - public const string MaterialColor = "g3d:material:color:0:float32:4"; - public const string MaterialGlossiness = "g3d:material:glossiness:0:float32:1"; - public const string MaterialSmoothness = "g3d:material:smoothness:0:float32:1"; - public const string SubmeshIndexOffset = "g3d:submesh:indexoffset:0:int32:1"; - public const string SubmeshMaterial = "g3d:submesh:material:0:int32:1"; - } - - public static class CommonAttributeExtensions - { - - public static GeometryAttribute ToObjectFaceSizeAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.ObjectFaceSize, index); - public static GeometryAttribute ToObjectFaceSizeAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.ObjectFaceSize); - public static GeometryAttribute ToObjectFaceSizeAttribute(this int[] xs, int index) => xs.ToIArray().ToObjectFaceSizeAttribute(index); - public static GeometryAttribute ToObjectFaceSizeAttribute(this int[] xs) => xs.ToIArray().ToObjectFaceSizeAttribute(); - public static GeometryAttribute GetAttributeObjectFaceSize(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.ObjectFaceSize); - public static IArray GetAttributeDataObjectFaceSize(this IGeometryAttributes self) => self.GetAttributeObjectFaceSize()?.Data; - public static GeometryAttribute ToIndexAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.Index, index); - public static GeometryAttribute ToIndexAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.Index); - public static GeometryAttribute ToIndexAttribute(this int[] xs, int index) => xs.ToIArray().ToIndexAttribute(index); - public static GeometryAttribute ToIndexAttribute(this int[] xs) => xs.ToIArray().ToIndexAttribute(); - public static GeometryAttribute GetAttributeIndex(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.Index); - public static IArray GetAttributeDataIndex(this IGeometryAttributes self) => self.GetAttributeIndex()?.Data; - public static GeometryAttribute ToPositionAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.Position, index); - public static GeometryAttribute ToPositionAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.Position); - public static GeometryAttribute ToPositionAttribute(this Vector3[] xs, int index) => xs.ToIArray().ToPositionAttribute(index); - public static GeometryAttribute ToPositionAttribute(this Vector3[] xs) => xs.ToIArray().ToPositionAttribute(); - public static GeometryAttribute GetAttributePosition(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.Position); - public static IArray GetAttributeDataPosition(this IGeometryAttributes self) => self.GetAttributePosition()?.Data; - public static GeometryAttribute ToVertexUvAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.VertexUv, index); - public static GeometryAttribute ToVertexUvAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.VertexUv); - public static GeometryAttribute ToVertexUvAttribute(this Vector2[] xs, int index) => xs.ToIArray().ToVertexUvAttribute(index); - public static GeometryAttribute ToVertexUvAttribute(this Vector2[] xs) => xs.ToIArray().ToVertexUvAttribute(); - public static GeometryAttribute GetAttributeVertexUv(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.VertexUv); - public static IArray GetAttributeDataVertexUv(this IGeometryAttributes self) => self.GetAttributeVertexUv()?.Data; - public static GeometryAttribute ToVertexUvwAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.VertexUvw, index); - public static GeometryAttribute ToVertexUvwAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.VertexUvw); - public static GeometryAttribute ToVertexUvwAttribute(this Vector3[] xs, int index) => xs.ToIArray().ToVertexUvwAttribute(index); - public static GeometryAttribute ToVertexUvwAttribute(this Vector3[] xs) => xs.ToIArray().ToVertexUvwAttribute(); - public static GeometryAttribute GetAttributeVertexUvw(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.VertexUvw); - public static IArray GetAttributeDataVertexUvw(this IGeometryAttributes self) => self.GetAttributeVertexUvw()?.Data; - public static GeometryAttribute ToVertexNormalAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.VertexNormal, index); - public static GeometryAttribute ToVertexNormalAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.VertexNormal); - public static GeometryAttribute ToVertexNormalAttribute(this Vector3[] xs, int index) => xs.ToIArray().ToVertexNormalAttribute(index); - public static GeometryAttribute ToVertexNormalAttribute(this Vector3[] xs) => xs.ToIArray().ToVertexNormalAttribute(); - public static GeometryAttribute GetAttributeVertexNormal(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.VertexNormal); - public static IArray GetAttributeDataVertexNormal(this IGeometryAttributes self) => self.GetAttributeVertexNormal()?.Data; - public static GeometryAttribute ToVertexColorAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.VertexColor, index); - public static GeometryAttribute ToVertexColorAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.VertexColor); - public static GeometryAttribute ToVertexColorAttribute(this Vector4[] xs, int index) => xs.ToIArray().ToVertexColorAttribute(index); - public static GeometryAttribute ToVertexColorAttribute(this Vector4[] xs) => xs.ToIArray().ToVertexColorAttribute(); - public static GeometryAttribute GetAttributeVertexColor(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.VertexColor); - public static IArray GetAttributeDataVertexColor(this IGeometryAttributes self) => self.GetAttributeVertexColor()?.Data; - public static GeometryAttribute ToVertexColor8BitAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.VertexColor8Bit, index); - public static GeometryAttribute ToVertexColor8BitAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.VertexColor8Bit); - public static GeometryAttribute ToVertexColor8BitAttribute(this Byte4[] xs, int index) => xs.ToIArray().ToVertexColor8BitAttribute(index); - public static GeometryAttribute ToVertexColor8BitAttribute(this Byte4[] xs) => xs.ToIArray().ToVertexColor8BitAttribute(); - public static GeometryAttribute GetAttributeVertexColor8Bit(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.VertexColor8Bit); - public static IArray GetAttributeDataVertexColor8Bit(this IGeometryAttributes self) => self.GetAttributeVertexColor8Bit()?.Data; - public static GeometryAttribute ToVertexBitangentAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.VertexBitangent, index); - public static GeometryAttribute ToVertexBitangentAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.VertexBitangent); - public static GeometryAttribute ToVertexBitangentAttribute(this Vector3[] xs, int index) => xs.ToIArray().ToVertexBitangentAttribute(index); - public static GeometryAttribute ToVertexBitangentAttribute(this Vector3[] xs) => xs.ToIArray().ToVertexBitangentAttribute(); - public static GeometryAttribute GetAttributeVertexBitangent(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.VertexBitangent); - public static IArray GetAttributeDataVertexBitangent(this IGeometryAttributes self) => self.GetAttributeVertexBitangent()?.Data; - public static GeometryAttribute ToVertexTangentAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.VertexTangent, index); - public static GeometryAttribute ToVertexTangentAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.VertexTangent); - public static GeometryAttribute ToVertexTangentAttribute(this Vector4[] xs, int index) => xs.ToIArray().ToVertexTangentAttribute(index); - public static GeometryAttribute ToVertexTangentAttribute(this Vector4[] xs) => xs.ToIArray().ToVertexTangentAttribute(); - public static GeometryAttribute GetAttributeVertexTangent(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.VertexTangent); - public static IArray GetAttributeDataVertexTangent(this IGeometryAttributes self) => self.GetAttributeVertexTangent()?.Data; - public static GeometryAttribute ToVertexSelectionWeightAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.VertexSelectionWeight, index); - public static GeometryAttribute ToVertexSelectionWeightAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.VertexSelectionWeight); - public static GeometryAttribute ToVertexSelectionWeightAttribute(this float[] xs, int index) => xs.ToIArray().ToVertexSelectionWeightAttribute(index); - public static GeometryAttribute ToVertexSelectionWeightAttribute(this float[] xs) => xs.ToIArray().ToVertexSelectionWeightAttribute(); - public static GeometryAttribute GetAttributeVertexSelectionWeight(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.VertexSelectionWeight); - public static IArray GetAttributeDataVertexSelectionWeight(this IGeometryAttributes self) => self.GetAttributeVertexSelectionWeight()?.Data; - public static GeometryAttribute ToFaceColorAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.FaceColor, index); - public static GeometryAttribute ToFaceColorAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.FaceColor); - public static GeometryAttribute ToFaceColorAttribute(this Vector4[] xs, int index) => xs.ToIArray().ToFaceColorAttribute(index); - public static GeometryAttribute ToFaceColorAttribute(this Vector4[] xs) => xs.ToIArray().ToFaceColorAttribute(); - public static GeometryAttribute GetAttributeFaceColor(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.FaceColor); - public static IArray GetAttributeDataFaceColor(this IGeometryAttributes self) => self.GetAttributeFaceColor()?.Data; - public static GeometryAttribute ToFaceMaterialAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.FaceMaterial, index); - public static GeometryAttribute ToFaceMaterialAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.FaceMaterial); - public static GeometryAttribute ToFaceMaterialAttribute(this int[] xs, int index) => xs.ToIArray().ToFaceMaterialAttribute(index); - public static GeometryAttribute ToFaceMaterialAttribute(this int[] xs) => xs.ToIArray().ToFaceMaterialAttribute(); - public static GeometryAttribute GetAttributeFaceMaterial(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.FaceMaterial); - public static IArray GetAttributeDataFaceMaterial(this IGeometryAttributes self) => self.GetAttributeFaceMaterial()?.Data; - public static GeometryAttribute ToFaceNormalAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.FaceNormal, index); - public static GeometryAttribute ToFaceNormalAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.FaceNormal); - public static GeometryAttribute ToFaceNormalAttribute(this Vector3[] xs, int index) => xs.ToIArray().ToFaceNormalAttribute(index); - public static GeometryAttribute ToFaceNormalAttribute(this Vector3[] xs) => xs.ToIArray().ToFaceNormalAttribute(); - public static GeometryAttribute GetAttributeFaceNormal(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.FaceNormal); - public static IArray GetAttributeDataFaceNormal(this IGeometryAttributes self) => self.GetAttributeFaceNormal()?.Data; - public static GeometryAttribute ToMeshSubmeshOffsetAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.MeshSubmeshOffset, index); - public static GeometryAttribute ToMeshSubmeshOffsetAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.MeshSubmeshOffset); - public static GeometryAttribute ToMeshSubmeshOffsetAttribute(this int[] xs, int index) => xs.ToIArray().ToMeshSubmeshOffsetAttribute(index); - public static GeometryAttribute ToMeshSubmeshOffsetAttribute(this int[] xs) => xs.ToIArray().ToMeshSubmeshOffsetAttribute(); - public static GeometryAttribute GetAttributeMeshSubmeshOffset(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.MeshSubmeshOffset); - public static IArray GetAttributeDataMeshSubmeshOffset(this IGeometryAttributes self) => self.GetAttributeMeshSubmeshOffset()?.Data; - public static GeometryAttribute ToInstanceTransformAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.InstanceTransform, index); - public static GeometryAttribute ToInstanceTransformAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.InstanceTransform); - public static GeometryAttribute ToInstanceTransformAttribute(this Matrix4x4[] xs, int index) => xs.ToIArray().ToInstanceTransformAttribute(index); - public static GeometryAttribute ToInstanceTransformAttribute(this Matrix4x4[] xs) => xs.ToIArray().ToInstanceTransformAttribute(); - public static GeometryAttribute GetAttributeInstanceTransform(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.InstanceTransform); - public static IArray GetAttributeDataInstanceTransform(this IGeometryAttributes self) => self.GetAttributeInstanceTransform()?.Data; - public static GeometryAttribute ToInstanceParentAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.InstanceParent, index); - public static GeometryAttribute ToInstanceParentAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.InstanceParent); - public static GeometryAttribute ToInstanceParentAttribute(this int[] xs, int index) => xs.ToIArray().ToInstanceParentAttribute(index); - public static GeometryAttribute ToInstanceParentAttribute(this int[] xs) => xs.ToIArray().ToInstanceParentAttribute(); - public static GeometryAttribute GetAttributeInstanceParent(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.InstanceParent); - public static IArray GetAttributeDataInstanceParent(this IGeometryAttributes self) => self.GetAttributeInstanceParent()?.Data; - public static GeometryAttribute ToInstanceMeshAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.InstanceMesh, index); - public static GeometryAttribute ToInstanceMeshAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.InstanceMesh); - public static GeometryAttribute ToInstanceMeshAttribute(this int[] xs, int index) => xs.ToIArray().ToInstanceMeshAttribute(index); - public static GeometryAttribute ToInstanceMeshAttribute(this int[] xs) => xs.ToIArray().ToInstanceMeshAttribute(); - public static GeometryAttribute GetAttributeInstanceMesh(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.InstanceMesh); - public static IArray GetAttributeDataInstanceMesh(this IGeometryAttributes self) => self.GetAttributeInstanceMesh()?.Data; - public static GeometryAttribute ToInstanceFlagsAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.InstanceFlags, index); - public static GeometryAttribute ToInstanceFlagsAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.InstanceFlags); - public static GeometryAttribute ToInstanceFlagsAttribute(this ushort[] xs, int index) => xs.ToIArray().ToInstanceFlagsAttribute(index); - public static GeometryAttribute ToInstanceFlagsAttribute(this ushort[] xs) => xs.ToIArray().ToInstanceFlagsAttribute(); - public static GeometryAttribute GetAttributeInstanceFlags(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.InstanceFlags); - public static IArray GetAttributeDataInstanceFlags(this IGeometryAttributes self) => self.GetAttributeInstanceFlags()?.Data; - public static GeometryAttribute ToLineTangentInAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.LineTangentIn, index); - public static GeometryAttribute ToLineTangentInAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.LineTangentIn); - public static GeometryAttribute ToLineTangentInAttribute(this Vector3[] xs, int index) => xs.ToIArray().ToLineTangentInAttribute(index); - public static GeometryAttribute ToLineTangentInAttribute(this Vector3[] xs) => xs.ToIArray().ToLineTangentInAttribute(); - public static GeometryAttribute GetAttributeLineTangentIn(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.LineTangentIn); - public static IArray GetAttributeDataLineTangentIn(this IGeometryAttributes self) => self.GetAttributeLineTangentIn()?.Data; - public static GeometryAttribute ToLineTangentOutAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.LineTangentOut, index); - public static GeometryAttribute ToLineTangentOutAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.LineTangentOut); - public static GeometryAttribute ToLineTangentOutAttribute(this Vector3[] xs, int index) => xs.ToIArray().ToLineTangentOutAttribute(index); - public static GeometryAttribute ToLineTangentOutAttribute(this Vector3[] xs) => xs.ToIArray().ToLineTangentOutAttribute(); - public static GeometryAttribute GetAttributeLineTangentOut(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.LineTangentOut); - public static IArray GetAttributeDataLineTangentOut(this IGeometryAttributes self) => self.GetAttributeLineTangentOut()?.Data; - public static GeometryAttribute ToShapeVertexAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.ShapeVertex, index); - public static GeometryAttribute ToShapeVertexAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.ShapeVertex); - public static GeometryAttribute ToShapeVertexAttribute(this Vector3[] xs, int index) => xs.ToIArray().ToShapeVertexAttribute(index); - public static GeometryAttribute ToShapeVertexAttribute(this Vector3[] xs) => xs.ToIArray().ToShapeVertexAttribute(); - public static GeometryAttribute GetAttributeShapeVertex(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.ShapeVertex); - public static IArray GetAttributeDataShapeVertex(this IGeometryAttributes self) => self.GetAttributeShapeVertex()?.Data; - public static GeometryAttribute ToShapeVertexOffsetAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.ShapeVertexOffset, index); - public static GeometryAttribute ToShapeVertexOffsetAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.ShapeVertexOffset); - public static GeometryAttribute ToShapeVertexOffsetAttribute(this int[] xs, int index) => xs.ToIArray().ToShapeVertexOffsetAttribute(index); - public static GeometryAttribute ToShapeVertexOffsetAttribute(this int[] xs) => xs.ToIArray().ToShapeVertexOffsetAttribute(); - public static GeometryAttribute GetAttributeShapeVertexOffset(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.ShapeVertexOffset); - public static IArray GetAttributeDataShapeVertexOffset(this IGeometryAttributes self) => self.GetAttributeShapeVertexOffset()?.Data; - public static GeometryAttribute ToShapeColorAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.ShapeColor, index); - public static GeometryAttribute ToShapeColorAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.ShapeColor); - public static GeometryAttribute ToShapeColorAttribute(this Vector4[] xs, int index) => xs.ToIArray().ToShapeColorAttribute(index); - public static GeometryAttribute ToShapeColorAttribute(this Vector4[] xs) => xs.ToIArray().ToShapeColorAttribute(); - public static GeometryAttribute GetAttributeShapeColor(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.ShapeColor); - public static IArray GetAttributeDataShapeColor(this IGeometryAttributes self) => self.GetAttributeShapeColor()?.Data; - public static GeometryAttribute ToShapeWidthAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.ShapeWidth, index); - public static GeometryAttribute ToShapeWidthAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.ShapeWidth); - public static GeometryAttribute ToShapeWidthAttribute(this float[] xs, int index) => xs.ToIArray().ToShapeWidthAttribute(index); - public static GeometryAttribute ToShapeWidthAttribute(this float[] xs) => xs.ToIArray().ToShapeWidthAttribute(); - public static GeometryAttribute GetAttributeShapeWidth(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.ShapeWidth); - public static IArray GetAttributeDataShapeWidth(this IGeometryAttributes self) => self.GetAttributeShapeWidth()?.Data; - public static GeometryAttribute ToMaterialColorAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.MaterialColor, index); - public static GeometryAttribute ToMaterialColorAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.MaterialColor); - public static GeometryAttribute ToMaterialColorAttribute(this Vector4[] xs, int index) => xs.ToIArray().ToMaterialColorAttribute(index); - public static GeometryAttribute ToMaterialColorAttribute(this Vector4[] xs) => xs.ToIArray().ToMaterialColorAttribute(); - public static GeometryAttribute GetAttributeMaterialColor(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.MaterialColor); - public static IArray GetAttributeDataMaterialColor(this IGeometryAttributes self) => self.GetAttributeMaterialColor()?.Data; - public static GeometryAttribute ToMaterialGlossinessAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.MaterialGlossiness, index); - public static GeometryAttribute ToMaterialGlossinessAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.MaterialGlossiness); - public static GeometryAttribute ToMaterialGlossinessAttribute(this float[] xs, int index) => xs.ToIArray().ToMaterialGlossinessAttribute(index); - public static GeometryAttribute ToMaterialGlossinessAttribute(this float[] xs) => xs.ToIArray().ToMaterialGlossinessAttribute(); - public static GeometryAttribute GetAttributeMaterialGlossiness(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.MaterialGlossiness); - public static IArray GetAttributeDataMaterialGlossiness(this IGeometryAttributes self) => self.GetAttributeMaterialGlossiness()?.Data; - public static GeometryAttribute ToMaterialSmoothnessAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.MaterialSmoothness, index); - public static GeometryAttribute ToMaterialSmoothnessAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.MaterialSmoothness); - public static GeometryAttribute ToMaterialSmoothnessAttribute(this float[] xs, int index) => xs.ToIArray().ToMaterialSmoothnessAttribute(index); - public static GeometryAttribute ToMaterialSmoothnessAttribute(this float[] xs) => xs.ToIArray().ToMaterialSmoothnessAttribute(); - public static GeometryAttribute GetAttributeMaterialSmoothness(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.MaterialSmoothness); - public static IArray GetAttributeDataMaterialSmoothness(this IGeometryAttributes self) => self.GetAttributeMaterialSmoothness()?.Data; - public static GeometryAttribute ToSubmeshIndexOffsetAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.SubmeshIndexOffset, index); - public static GeometryAttribute ToSubmeshIndexOffsetAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.SubmeshIndexOffset); - public static GeometryAttribute ToSubmeshIndexOffsetAttribute(this int[] xs, int index) => xs.ToIArray().ToSubmeshIndexOffsetAttribute(index); - public static GeometryAttribute ToSubmeshIndexOffsetAttribute(this int[] xs) => xs.ToIArray().ToSubmeshIndexOffsetAttribute(); - public static GeometryAttribute GetAttributeSubmeshIndexOffset(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.SubmeshIndexOffset); - public static IArray GetAttributeDataSubmeshIndexOffset(this IGeometryAttributes self) => self.GetAttributeSubmeshIndexOffset()?.Data; - public static GeometryAttribute ToSubmeshMaterialAttribute(this IArray xs, int index) => xs.ToAttribute(CommonAttributes.SubmeshMaterial, index); - public static GeometryAttribute ToSubmeshMaterialAttribute(this IArray xs) => xs.ToAttribute(CommonAttributes.SubmeshMaterial); - public static GeometryAttribute ToSubmeshMaterialAttribute(this int[] xs, int index) => xs.ToIArray().ToSubmeshMaterialAttribute(index); - public static GeometryAttribute ToSubmeshMaterialAttribute(this int[] xs) => xs.ToIArray().ToSubmeshMaterialAttribute(); - public static GeometryAttribute GetAttributeSubmeshMaterial(this IGeometryAttributes self) => self.GetAttribute(CommonAttributes.SubmeshMaterial); - public static IArray GetAttributeDataSubmeshMaterial(this IGeometryAttributes self) => self.GetAttributeSubmeshMaterial()?.Data; - - } -} diff --git a/src/cs/g3d/Vim.G3d/CommonAttributes.tt b/src/cs/g3d/Vim.G3d/CommonAttributes.tt deleted file mode 100644 index fad9970c..00000000 --- a/src/cs/g3d/Vim.G3d/CommonAttributes.tt +++ /dev/null @@ -1,95 +0,0 @@ -<#@ template language="C#" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Text" #> -<#@ import namespace="System.Collections.Generic" #> - -// AUTOGENERATED FILE: DO NOT EDIT -// This file is generated from CommonAttributeExtensions.tt - -<# -string[] namesDescriptorAndTypes = { - "ObjectFaceSize", "g3d:all:facesize:0:int32:1","int", - "Index", "g3d:corner:index:0:int32:1","int", - "Position", "g3d:vertex:position:0:float32:3","Vector3", - "VertexUv", "g3d:vertex:uv:0:float32:2","Vector2", - "VertexUvw", "g3d:vertex:uv:0:float32:3","Vector3", - "VertexNormal", "g3d:vertex:normal:0:float32:3","Vector3", - "VertexColor", "g3d:vertex:color:0:float32:4","Vector4", - "VertexColor8Bit", "g3d:vertex:color:0:int8:4","Byte4", - "VertexBitangent", "g3d:vertex:bitangent:0:float32:3","Vector3", - "VertexTangent", "g3d:vertex:tangent:0:float32:4","Vector4", - "VertexSelectionWeight", "g3d:vertex:weight:0:float32:1","float", - "FaceColor", "g3d:face:color:0:float32:4","Vector4", - "FaceMaterial", "g3d:face:material:0:int32:1","int", - "FaceNormal", "g3d:face:normal:0:float32:3","Vector3", - - "MeshSubmeshOffset", "g3d:mesh:submeshoffset:0:int32:1", "int", - - "InstanceTransform", "g3d:instance:transform:0:float32:16", "Matrix4x4", - "InstanceParent", "g3d:instance:parent:0:int32:1", "int", - "InstanceMesh", "g3d:instance:mesh:0:int32:1", "int", - "InstanceFlags", "g3d:instance:flags:0:uint16:1", "ushort", - - "LineTangentIn", "g3d:vertex:tangent:0:float32:3","Vector3", - "LineTangentOut", "g3d:vertex:tangent:1:float32:3","Vector3", - "ShapeVertex", "g3d:shapevertex:position:0:float32:3", "Vector3", // We're using a distinct "shapevertex" association here because the "vertex" association is coupled to mesh geometry (there is a lot of logic related to face remapping and merging). - "ShapeVertexOffset", "g3d:shape:vertexoffset:0:int32:1", "int", - "ShapeColor", "g3d:shape:color:0:float32:4", "Vector4", - "ShapeWidth", "g3d:shape:width:0:float32:1", "float", - - "MaterialColor", "g3d:material:color:0:float32:4","Vector4", - "MaterialGlossiness", "g3d:material:glossiness:0:float32:1","float", - "MaterialSmoothness", "g3d:material:smoothness:0:float32:1","float", - - "SubmeshIndexOffset", "g3d:submesh:indexoffset:0:int32:1","int", - "SubmeshMaterial", "g3d:submesh:material:0:int32:1","int", - -}; -#> - -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.G3d -{ - public static class CommonAttributes - { - -<# - for (var i=0; i < namesDescriptorAndTypes.Length; i += 3) - { - var name = namesDescriptorAndTypes[i]; - var desc = namesDescriptorAndTypes[i + 1]; - var type = namesDescriptorAndTypes[i + 2]; -#> - public const string <#= name #> = "<#= desc #>"; -<# - } -#> - } - - public static class CommonAttributeExtensions - { - -<# - for (var i=0; i < namesDescriptorAndTypes.Length; i += 3) - { - var name = namesDescriptorAndTypes[i]; - var desc = namesDescriptorAndTypes[i + 1]; - var type = namesDescriptorAndTypes[i + 2]; - var codeName = "CommonAttributes." + name; -#> - public static GeometryAttribute<<#= type #>> To<#= name #>Attribute(this IArray<<#= type #>> xs, int index) => xs.ToAttribute(<#= codeName #>, index); - public static GeometryAttribute<<#= type #>> To<#= name #>Attribute(this IArray<<#= type #>> xs) => xs.ToAttribute(<#= codeName #>); - public static GeometryAttribute<<#= type #>> To<#= name #>Attribute(this <#= type #>[] xs, int index) => xs.ToIArray().To<#= name #>Attribute(index); - public static GeometryAttribute<<#= type #>> To<#= name #>Attribute(this <#= type #>[] xs) => xs.ToIArray().To<#= name #>Attribute(); - public static GeometryAttribute<<#= type #>> GetAttribute<#= name #>(this IGeometryAttributes self) => self.GetAttribute<<#= type #>>(<#= codeName #>); - public static IArray<<#= type #>> GetAttributeData<#= name #>(this IGeometryAttributes self) => self.GetAttribute<#= name #>()?.Data; -<# - } -#> - - } -} diff --git a/src/cs/g3d/Vim.G3d/Enums.cs b/src/cs/g3d/Vim.G3d/Enums.cs deleted file mode 100644 index a3e1db1f..00000000 --- a/src/cs/g3d/Vim.G3d/Enums.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; - -namespace Vim.G3d -{ - /// - /// The different types of data types that can be used as elements. - /// - public enum DataType - { - dt_uint8, - dt_int8, - dt_uint16, - dt_int16, - dt_uint32, - dt_int32, - dt_uint64, - dt_int64, - dt_float32, - dt_float64, - dt_string, - }; - - /// - /// What element or component of a mesh each attribute is associated with. - /// - public enum Association - { - assoc_all, // associated with all data in G3d - assoc_none, // no association - assoc_vertex, // vertex or point data - assoc_face, // face associated data - assoc_corner, // corner (aka face-vertex) data. A corner is associated with one vertex, but a vertex may be shared between multiple corners - assoc_edge, // half-edge data. Each face consists of n half-edges, one per corner. A half-edge, is a directed edge - assoc_instance, // instance information - assoc_shapevertex, // flattened shape vertex collection. - assoc_shape, // shape instance - assoc_material, // material properties - assoc_mesh, - assoc_submesh - } - - [Flags] - public enum InstanceFlags - { - /// - /// Default - no instance options defined. - /// - None = 0, - - /// - /// When enabled, indicates that the renderer (or the consuming application) should hide - /// the instance by default. - /// - Hidden = 1, - } - - /// - /// Common semantic names. - /// - public static class Semantic - { - public const string Position = "position"; - public const string Index = "index"; - public const string FaceSize = "facesize"; - public const string Uv = "uv"; - public const string Normal = "normal"; - public const string Color = "color"; - public const string Bitangent = "bitangent"; - public const string Tangent = "tangent"; - public const string Weight = "weight"; - public const string Width = "width"; - - // Usually associated with face. - public const string Material = "material"; - - // Usually associated with material. - public const string Glossiness = "glossiness"; - - public const string Smoothness = "smoothness"; - - // Usually associated with meshes and submeshes - public const string IndexOffset = "indexoffset"; - public const string VertexOffset = "vertexoffset"; - - // Usually associated with instances - public const string Subgeometry = "subgeometry"; - public const string Mesh = "mesh"; - public const string Parent = "parent"; - public const string Transform = "transform"; - public const string Flags = "flags"; - - public const string TangentInt = "tangentin"; - public const string TangentOut = "tangentout"; - - public const string SubMeshOffset = "submeshoffset"; - - } -} diff --git a/src/cs/g3d/Vim.G3d/G3D.cs b/src/cs/g3d/Vim.G3d/G3D.cs deleted file mode 100644 index 36e90ca7..00000000 --- a/src/cs/g3d/Vim.G3d/G3D.cs +++ /dev/null @@ -1,345 +0,0 @@ -/* - G3D Geometry Format Library - Copyright 2019, VIMaec LLC. - Copyright 2018, Ara 3D Inc. - Usage licensed under terms of MIT License -*/ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Vim.LinqArray; -using Vim.Math3d; -using Vim.BFastLib; -using System.Diagnostics; - -namespace Vim.G3d -{ - /// - /// Represents a basic single-precision G3D in memory, with access to common attributes. - /// The G3D format can be double precision, but this data structure won't provide access to all of the attributes. - /// In the case of G3D formats that are non-conformant to the expected semantics you can use GeometryAttributes. - /// This class is inspired heavily by the structure of FBX and Assimp. - /// - public class G3D : GeometryAttributes - { - public new static G3D Empty = Create(); - - public G3dHeader Header { get; } - - // These are the values of the most common attributes. Some are retrieved directly from data, others are computed on demand, or coerced. - - // Vertex buffer. Usually present. - public IArray Vertices { get; } - - // Index buffer (one index per corner, and per half-edge). Computed if absent. - public IArray Indices { get; } - - // Vertex associated data, provided or null - public List> AllVertexUvs { get; } = new List>(); - public List> AllVertexColors { get; } = new List>(); - public IArray VertexUvs => AllVertexUvs?.ElementAtOrDefault(0); - public IArray VertexColors => AllVertexColors?.ElementAtOrDefault(0); - public IArray VertexNormals { get; } - public IArray VertexTangents { get; } - - // Faces - public IArray FaceMaterials { get; } // Material indices per face, - public IArray FaceNormals { get; } // If not provided, are computed dynamically as the average of all vertex normals, - - // Meshes - public IArray MeshIndexOffsets { get; } // Offset into the index buffer for each Mesh - public IArray MeshVertexOffsets { get; } // Offset into the vertex buffer for each Mesh - public IArray MeshIndexCounts { get; } // Computed - public IArray MeshVertexCounts { get; } // Computed - public IArray MeshSubmeshOffset { get; } - public IArray MeshSubmeshCount { get; } // Computed - public IArray Meshes { get; } - - // Instances - public IArray InstanceParents { get; } // Index of the parent transform - public IArray InstanceTransforms { get; } // A 4x4 matrix in row-column order defining the transormed - public IArray InstanceMeshes { get; } // The SubGeometry associated with the index - public IArray InstanceFlags { get; } // The instance flags associated with the index. - - // Shapes - public IArray ShapeVertices { get; } - public IArray ShapeVertexOffsets { get; } - public IArray ShapeColors { get; } - public IArray ShapeWidths { get; } - public IArray ShapeVertexCounts { get; } // Computed - public IArray Shapes { get; } // Computed - - // Materials - public IArray MaterialColors { get; } // RGBA with transparency. - public IArray MaterialGlossiness { get; } - public IArray MaterialSmoothness { get; } - public IArray Materials { get; } - - - // Submeshes - public IArray SubmeshIndexOffsets { get; } - public IArray SubmeshIndexCount { get; } - public IArray SubmeshMaterials { get; } - - public G3D(IEnumerable attributes, G3dHeader? header = null, int numCornersPerFaceOverride = -1) - : base(attributes, numCornersPerFaceOverride) - { - Header = header ?? new G3dHeader(); - - foreach (var attr in Attributes.ToEnumerable()) - { - var desc = attr.Descriptor; - switch (desc.Semantic) - { - case Semantic.Index: - if (attr.IsTypeAndAssociation(Association.assoc_corner)) - Indices = Indices ?? attr.AsType().Data; - if (attr.IsTypeAndAssociation(Association.assoc_corner)) - Indices = Indices ?? attr.AsType().Data.Select(x => (int)x); - break; - - case Semantic.Position: - if (attr.IsTypeAndAssociation(Association.assoc_vertex)) - Vertices = Vertices ?? attr.AsType().Data; - if (attr.IsTypeAndAssociation(Association.assoc_corner)) - Vertices = Vertices ?? attr.AsType().Data; // TODO: is this used? - if (attr.IsTypeAndAssociation(Association.assoc_shapevertex)) - ShapeVertices = ShapeVertices ?? attr.AsType().Data; - break; - - case Semantic.Tangent: - if (attr.IsTypeAndAssociation(Association.assoc_vertex)) - VertexTangents = VertexTangents ?? attr.AsType().Data.Select(v => v.ToVector4()); - if (attr.IsTypeAndAssociation(Association.assoc_vertex)) - VertexTangents = VertexTangents ?? attr.AsType().Data; - break; - - case Semantic.Uv: - if (attr.IsTypeAndAssociation(Association.assoc_vertex)) - AllVertexUvs.Add(attr.AsType().Data.Select(uv => uv.ToVector2())); - if (attr.IsTypeAndAssociation(Association.assoc_vertex)) - AllVertexUvs.Add(attr.AsType().Data); - break; - - case Semantic.Color: - if (desc.Association == Association.assoc_vertex) - AllVertexColors.Add(attr.AttributeToColors()); - if (desc.Association == Association.assoc_shape) - ShapeColors = ShapeColors ?? attr.AttributeToColors(); - if (desc.Association == Association.assoc_material) - MaterialColors = MaterialColors ?? attr.AttributeToColors(); - break; - - case Semantic.VertexOffset: - if (attr.IsTypeAndAssociation(Association.assoc_mesh)) - MeshVertexOffsets = MeshVertexOffsets ?? attr.AsType().Data; - if (attr.IsTypeAndAssociation(Association.assoc_shape)) - ShapeVertexOffsets = ShapeVertexOffsets ?? attr.AsType().Data; - break; - - case Semantic.IndexOffset: - if (attr.IsTypeAndAssociation(Association.assoc_mesh)) - MeshIndexOffsets = MeshIndexOffsets ?? attr.AsType().Data; - if (attr.IsTypeAndAssociation(Association.assoc_submesh)) - SubmeshIndexOffsets = SubmeshIndexOffsets ?? attr.AsType().Data; - break; - - case Semantic.Normal: - if (attr.IsTypeAndAssociation(Association.assoc_face)) - FaceNormals = FaceNormals ?? attr.AsType().Data; - if (attr.IsTypeAndAssociation(Association.assoc_vertex)) - VertexNormals = VertexNormals ?? attr.AsType().Data; - break; - - case Semantic.Material: - if (attr.IsTypeAndAssociation(Association.assoc_face)) - FaceMaterials = FaceMaterials ?? attr.AsType().Data; - if (attr.IsTypeAndAssociation(Association.assoc_submesh)) - SubmeshMaterials = SubmeshMaterials ?? attr.AsType().Data; - break; - - case Semantic.Parent: - if (attr.IsTypeAndAssociation(Association.assoc_instance)) - InstanceParents = InstanceParents ?? attr.AsType().Data; - break; - - case Semantic.Mesh: - if (attr.IsTypeAndAssociation(Association.assoc_instance)) - InstanceMeshes = InstanceMeshes ?? attr.AsType().Data; - break; - - case Semantic.Transform: - if (attr.IsTypeAndAssociation(Association.assoc_instance)) - InstanceTransforms = InstanceTransforms ?? attr.AsType().Data; - break; - - case Semantic.Width: - if (attr.IsTypeAndAssociation(Association.assoc_shape)) - ShapeWidths = ShapeWidths ?? attr.AsType().Data; - break; - - case Semantic.Glossiness: - if (attr.IsTypeAndAssociation(Association.assoc_material)) - MaterialGlossiness = attr.AsType().Data; - break; - - case Semantic.Smoothness: - if (attr.IsTypeAndAssociation(Association.assoc_material)) - MaterialSmoothness = attr.AsType().Data; - break; - - case Semantic.SubMeshOffset: - if (attr.IsTypeAndAssociation(Association.assoc_mesh)) - MeshSubmeshOffset = attr.AsType().Data; - break; - - case Semantic.Flags: - if (attr.IsTypeAndAssociation(Association.assoc_instance)) - InstanceFlags = attr.AsType().Data; - break; - } - } - - // If no vertices are provided, we are going to generate a list of zero vertices. - if (Vertices == null) - Vertices = Vector3.Zero.Repeat(0); - - // If no indices are provided then we are going to have to treat the index buffer as indices - if (Indices == null) - Indices = Vertices.Indices(); - - // Compute face normals if possible - if (FaceNormals == null && VertexNormals != null) - FaceNormals = NumFaces.Select(ComputeFaceNormal); - - if (NumMeshes > 0) - { - // Mesh offset is the same as the offset of its first submesh. - if(MeshSubmeshOffset != null) - { - MeshIndexOffsets = MeshSubmeshOffset.Select(submesh => SubmeshIndexOffsets[submesh]); - MeshSubmeshCount = GetSubArrayCounts(MeshSubmeshOffset.Count, MeshSubmeshOffset, NumSubmeshes).Evaluate(); - } - - if(MeshIndexOffsets != null) - { - MeshIndexCounts = GetSubArrayCounts(NumMeshes, MeshIndexOffsets, NumCorners); - MeshVertexOffsets = MeshIndexOffsets - .Zip(MeshIndexCounts, (start, count) => (start, count)) - .Select(range => Indices.SubArray(range.start, range.count).Min()); - } - - if (MeshVertexOffsets != null) - MeshVertexCounts = GetSubArrayCounts(NumMeshes, MeshVertexOffsets, NumVertices); - } - else - { - MeshSubmeshCount = Array.Empty().ToIArray(); - } - - if (SubmeshIndexOffsets != null) - SubmeshIndexCount = GetSubArrayCounts(SubmeshIndexOffsets.Count, SubmeshIndexOffsets, NumCorners).Evaluate(); - - // Compute all meshes - Meshes = NumMeshes.Select(i => new G3dMesh(this, i)); - - if (MaterialColors != null) - Materials = MaterialColors.Count.Select(i => new G3dMaterial(this, i)); - - // Process the shape data - if (ShapeVertices == null) - ShapeVertices = Vector3.Zero.Repeat(0); - - if (ShapeVertexOffsets == null) - ShapeVertexOffsets = Array.Empty().ToIArray(); - - if (ShapeColors == null) - ShapeColors = Vector4.Zero.Repeat(0); - - if (ShapeWidths == null) - ShapeWidths = Array.Empty().ToIArray(); - - // Update the instance options - if (InstanceFlags == null) - InstanceFlags = ((ushort) 0).Repeat(NumInstances); - - ShapeVertexCounts = GetSubArrayCounts(NumShapes, ShapeVertexOffsets, ShapeVertices.Count); - ValidateSubArrayCounts(ShapeVertexCounts, nameof(ShapeVertexCounts)); - - Shapes = NumShapes.Select(i => new G3dShape(this, i)); - } - - private static IArray GetSubArrayCounts(int numItems, IArray offsets, int totalCount) - => numItems.Select(i => i < (numItems - 1) - ? offsets[i + 1] - offsets[i] - : totalCount - offsets[i]); - - private static void ValidateSubArrayCounts(IArray subArrayCounts, string memberName) - { - for (var i = 0; i < subArrayCounts.Count; ++i) - { - if (subArrayCounts[i] < 0) - throw new Exception($"{memberName}[{i}] is a negative sub array count."); - } - } - - public static Vector3 Average(IArray xs) - => xs.Aggregate(Vector3.Zero, (a, b) => a + b) / xs.Count; - - public Vector3 ComputeFaceNormal(int nFace) - => Average(NumCornersPerFace.Select(c => VertexNormals[nFace * NumCornersPerFace + c])); - - public static G3D Read(string filePath) - { - using (var stream = File.OpenRead(filePath)) - { - var bfast = new BFast(stream); - return Read(bfast); - } - } - - - public static G3D Read(BFast bfast) - { - var header = G3dHeader.FromBytesOrDefault(bfast.GetArray("meta")); - var attributes = new List(); - foreach (var name in bfast.Entries) - { - if (name == "meta") continue; - var attribute = GetEmptyAttribute(name); - if (attribute == null) continue; - var a = attribute.Read(bfast); - attributes.Add(a); - } - - return new G3D(attributes, header); - } - private static GeometryAttribute GetEmptyAttribute(string name) - { - if (!AttributeDescriptor.TryParse(name, out var attributeDescriptor)) - { - Debug.WriteLine("G3D Error: Could not parse attribute " + name); - return null; - } - try - { - return attributeDescriptor.ToDefaultAttribute(0); - } - catch - { - Debug.WriteLine("G3D Error: Could not parse attribute " + name); - return null; - } - } - - - public static G3D Create(params GeometryAttribute[] attributes) - => new G3D(attributes); - - public static G3D Create(G3dHeader header, params GeometryAttribute[] attributes) - => new G3D(attributes, header); - - } -} diff --git a/src/cs/g3d/Vim.G3d/G3dMaterial.cs b/src/cs/g3d/Vim.G3d/G3dMaterial.cs deleted file mode 100644 index 9dc3b5bf..00000000 --- a/src/cs/g3d/Vim.G3d/G3dMaterial.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Vim.Math3d; - -namespace Vim.G3d -{ - public class G3dMaterial - { - public readonly G3D G3d; - public readonly int Index; - - public G3dMaterial(G3D g3D, int index) - { - G3d = g3D; - Index = index; - } - - public Vector4 Color => G3d.MaterialColors[Index]; - public float Glossiness => G3d?.MaterialGlossiness[Index] ?? 0f; - public float Smoothness => G3d?.MaterialSmoothness[Index] ?? 0f; - } -} diff --git a/src/cs/g3d/Vim.G3d/G3dMesh.cs b/src/cs/g3d/Vim.G3d/G3dMesh.cs deleted file mode 100644 index 837ac11f..00000000 --- a/src/cs/g3d/Vim.G3d/G3dMesh.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using System.Collections.Generic; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.G3d -{ - - public interface IMeshCommon : ITransformable3D - { - IMeshCommon Clone(); - void SetVertices(Vector3[] vertices); - void SetIndices(int[] indices); - - // To be compatible with IMesh - IArray Vertices { get; } - IArray Indices { get; } - - IArray SubmeshMaterials { get; } - IArray SubmeshIndexOffsets { get; } - IArray SubmeshIndexCounts { get; } - - - - // To be compatible with IGeometryAttributes - int NumCornersPerFace { get; } - int NumVertices { get; } - int NumCorners { get; } - int NumFaces { get; } - int NumInstances { get; } - int NumMeshes { get; } - int NumShapeVertices { get; } - int NumShapes { get; } - } - - /// - /// A G3dMesh is a section of the G3D data that defines a mesh. - /// This does not implement IGeometryAttributes for performance reasons. - /// - public class G3dMesh : IMeshCommon - { - public G3D G3D { get; } - public int Index { get; } - - public int VertexOffset => G3D.MeshVertexOffsets[Index]; - public int NumVertices => G3D.MeshVertexCounts[Index]; - public int IndexOffset => G3D.MeshIndexOffsets[Index]; - public int NumCorners => G3D.MeshIndexCounts[Index]; - public int FaceOffset => IndexOffset / NumCornersPerFace; - public int NumFaces => NumCorners / NumCornersPerFace; - public int NumCornersPerFace => G3D.NumCornersPerFace; - - - // Fillers to fullfil IGeometryAttributes for now - public int NumInstances => 0; - public int NumMeshes => 1; - public int NumShapeVertices => 0; - public int NumShapes => 0; - - // Data - public IArray Vertices { get; private set; } - public IArray Indices { get; private set; } - public IArray SubmeshMaterials { get; private set; } - public IArray SubmeshIndexOffsets { get; private set; } - public IArray SubmeshIndexCounts { get; private set; } - - - public G3dMesh(G3D parent, int index) - { - (G3D, Index) = (parent, index); - Vertices = G3D.Vertices?.SubArray(VertexOffset, NumVertices); - var offset = VertexOffset; - Indices = G3D.Indices?.SubArray(IndexOffset, NumCorners).Select(i => i - offset); - - // TODO: Remove need for this. - var submeshArray = (G3D.SubmeshIndexOffsets as ArrayAdapter).Array; - var submeshIndex = Array.BinarySearch(submeshArray, IndexOffset); - var submeshCount = 0; - for(var i = submeshIndex; i < submeshArray.Length; i++) - { - var indexOffset = submeshArray[i]; - if (indexOffset - IndexOffset >= NumCorners) - break; - submeshCount++; - } - SubmeshMaterials = G3D.SubmeshMaterials?.SubArray(submeshIndex, submeshCount).Evaluate(); - SubmeshIndexOffsets = G3D.SubmeshIndexOffsets?.SubArray(submeshIndex, submeshCount).Select(i => i - IndexOffset).Evaluate(); - - var last = NumCorners - SubmeshIndexOffsets.Last(); - SubmeshIndexCounts = SubmeshIndexOffsets.AdjacentDifferences().Append(last).Evaluate(); - } - - public IMeshCommon Transform(Matrix4x4 mat) - { - var mesh = Clone(); - mesh.Vertices = mesh.Vertices.Select(v => v.Transform(mat)).Evaluate(); - return mesh; - } - - public G3dMesh Clone() - { - var mesh = new G3dMesh(G3D, Index); - mesh.Vertices = mesh.Vertices; - mesh.Indices = mesh.Indices; - mesh.SubmeshMaterials = mesh.SubmeshMaterials; - mesh.SubmeshIndexOffsets = mesh.SubmeshIndexOffsets; - mesh.SubmeshIndexCounts = mesh.SubmeshIndexCounts; - return mesh; - } - IMeshCommon IMeshCommon.Clone() => Clone(); - public void SetVertices(Vector3[] vertices) - { - Vertices = vertices.ToIArray(); - } - public void SetIndices(int[] indices) - { - Indices = indices.ToIArray(); - } - } -} diff --git a/src/cs/g3d/Vim.G3d/G3dShape.cs b/src/cs/g3d/Vim.G3d/G3dShape.cs deleted file mode 100644 index 9cd220ad..00000000 --- a/src/cs/g3d/Vim.G3d/G3dShape.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.G3d -{ - public class G3dShape - { - public readonly G3D G3D; - public readonly int Index; - public readonly IArray Vertices; - - public int ShapeVertexOffset => G3D.ShapeVertexOffsets[Index]; - public int NumVertices => G3D.ShapeVertexCounts[Index]; - public Vector4 Color => G3D.ShapeColors[Index]; - public float Width => G3D.ShapeWidths[Index]; - - public G3dShape(G3D parent, int index) - { - (G3D, Index) = (parent, index); - Vertices = G3D.ShapeVertices?.SubArray(ShapeVertexOffset, NumVertices); - } - } -} diff --git a/src/cs/g3d/Vim.G3d/GeometryAttribute.cs b/src/cs/g3d/Vim.G3d/GeometryAttribute.cs deleted file mode 100644 index 9b2030f9..00000000 --- a/src/cs/g3d/Vim.G3d/GeometryAttribute.cs +++ /dev/null @@ -1,245 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Vim.LinqArray; -using Vim.Math3d; -using Vim.BFastLib; -using Vim.BFastLib.Core; - -namespace Vim.G3d -{ - /// - /// A mesh attribute is an array of data associated with some component of a mesh. - /// It could be vertices, corners, faces, face groups, sub-meshes, instances or the entire mesh. - /// This is the base class of a typed MeshAttribute. - /// It provides two core operations we are the foundation for mesh manipulation: - /// 1. concatenation with like-typed attributes - /// 2. remapping - /// - public abstract class GeometryAttribute - { - /// - /// The descriptor contains information about the data contained in the attribute: - /// * the primitive data type - /// * the arity - /// * the association - /// * the semantic - /// - public AttributeDescriptor Descriptor { get; } - - /// - /// A "name" is a string encoding of the attribute descriptor. - /// - public string Name - => Descriptor.Name; - - /// - /// This is the number of data elements in the attribute. This is equal to - /// the number of primitives times the arity. All mesh attributes associated - /// with the same mesh component (e.g. vertices) must have the same element count. - /// - public int ElementCount { get; } - - /// - /// Constructor. - /// - protected GeometryAttribute(AttributeDescriptor descriptor, int count) - => (Descriptor, ElementCount) = (descriptor, count); - - /// - /// Multiple mesh attributes can be merged together if they have the same - /// underlying descriptor and data type. - /// - public abstract GeometryAttribute Merge(IEnumerable others); - - /// - /// A mesh attribute can be remapped, using the given indices. - /// - public abstract GeometryAttribute Remap(IArray indices); - - /// - /// Converted to an INamedBuffer which consists of a name and an array of unmanaged types. - /// - public abstract INamedBuffer ToBuffer(); - - /// - /// Convenience function to check if this object is a mesh attribute of the given type. - /// - public bool IsType() where T : unmanaged - => this is GeometryAttribute; - - /// - /// Convenience function to check if this object is a mesh attribute of the given type, and the association matches. - /// - public bool IsTypeAndAssociation(Association assoc) where T : unmanaged - => Descriptor.Association == assoc && this is GeometryAttribute; - - /// - /// Convenience function to cast this object into a mesh attribute of the given type, throwing an exception if not possible, - /// - public GeometryAttribute AsType() where T : unmanaged - => this as GeometryAttribute ?? throw new Exception($"The type of the attribute is {GetType()} not MeshAttribute<{typeof(T)}>"); - - /// - /// Loads the correct typed data from a Stream. - /// - public abstract GeometryAttribute Read(Stream stream, long byteCount); - - /// - /// Loads the correct typed data from a BFastNext. - /// - public abstract GeometryAttribute Read(BFast bfast); - - public abstract void AddTo(BFast bfast); - - /// - /// Creates a new GeometryAttribute with the same data, but with a different index. Useful when constructing attributes - /// - public abstract GeometryAttribute SetIndex(int index); - } - - /// - /// This is a typed attribute associated with some part of the mesh. - /// The underlying data is an IArray which means that it can be - /// computed on demand. - /// - public class GeometryAttribute : GeometryAttribute where T : unmanaged - { - public IArray Data; - - public GeometryAttribute(IArray data, AttributeDescriptor descriptor) - : base(descriptor, data.Count) - { - Data = data; - int arity; - DataType dataType; - // TODO: TECH DEBT - Support unsigned tuples in Math3d - if (typeof(T) == typeof(byte)) - (arity, dataType) = (1, DataType.dt_uint8); - else if (typeof(T) == typeof(sbyte)) - (arity, dataType) = (1, DataType.dt_int8); - else if (typeof(T) == typeof(Byte2)) - (arity, dataType) = (2, DataType.dt_int8); - else if (typeof(T) == typeof(Byte3)) - (arity, dataType) = (3, DataType.dt_int8); - else if (typeof(T) == typeof(Byte4)) - (arity, dataType) = (4, DataType.dt_int8); - else if (typeof(T) == typeof(ushort)) - (arity, dataType) = (1, DataType.dt_uint16); - else if (typeof(T) == typeof(short)) - (arity, dataType) = (1, DataType.dt_int16); - else if (typeof(T) == typeof(uint)) - (arity, dataType) = (1, DataType.dt_uint32); - else if (typeof(T) == typeof(int)) - (arity, dataType) = (1, DataType.dt_int32); - else if (typeof(T) == typeof(Int2)) - (arity, dataType) = (2, DataType.dt_int32); - else if (typeof(T) == typeof(Int3)) - (arity, dataType) = (3, DataType.dt_int32); - else if (typeof(T) == typeof(Int4)) - (arity, dataType) = (4, DataType.dt_int32); - else if (typeof(T) == typeof(ulong)) - (arity, dataType) = (1, DataType.dt_uint64); - else if (typeof(T) == typeof(long)) - (arity, dataType) = (1, DataType.dt_int64); - else if (typeof(T) == typeof(float)) - (arity, dataType) = (1, DataType.dt_float32); - else if (typeof(T) == typeof(Vector2)) - (arity, dataType) = (2, DataType.dt_float32); - else if (typeof(T) == typeof(Vector3)) - (arity, dataType) = (3, DataType.dt_float32); - else if (typeof(T) == typeof(Vector4)) - (arity, dataType) = (4, DataType.dt_float32); - else if (typeof(T) == typeof(Matrix4x4)) - (arity, dataType) = (16, DataType.dt_float32); - else if (typeof(T) == typeof(double)) - (arity, dataType) = (1, DataType.dt_float64); - else if (typeof(T) == typeof(DVector2)) - (arity, dataType) = (2, DataType.dt_float64); - else if (typeof(T) == typeof(DVector3)) - (arity, dataType) = (3, DataType.dt_float64); - else if (typeof(T) == typeof(DVector4)) - (arity, dataType) = (4, DataType.dt_float64); - else - throw new Exception($"Unsupported data type {typeof(T)}"); - - // Check that the computed data type is consistent with the descriptor - if (dataType != Descriptor.DataType) - throw new Exception($"DataType was {dataType} but expected {Descriptor.DataType}"); - - // Check that the computed data arity is consistent with the descriptor - if (arity != Descriptor.DataArity) - throw new Exception($"DatArity was {arity} but expected {Descriptor.DataArity}"); - } - - public override GeometryAttribute Merge(IEnumerable others) - { - if (!others.Any()) - return this; - - // Check that all attributes have the same descriptor - if (!others.All(ma => ma.Descriptor.Equals(Descriptor))) - throw new Exception($"All attributes have to have same descriptor {Descriptor} to be concatenated"); - - // Check that all attributes have the same type - if (!others.All(ma => ma is GeometryAttribute)) - throw new Exception($"All attributes have to have the same type {typeof(T)} to be concatenated"); - - // Given multiple attributes associated with "all" or with "nothing", the first one takes precedence - if (Descriptor.Association == Association.assoc_all || Descriptor.Association == Association.assoc_none) - return this; - - // Sub-geometry attributes can't be merged - if (Descriptor.Association == Association.assoc_mesh) - throw new Exception("Can't merge sub-geometry attributes"); - - // Instance attributes can't be merged - if (Descriptor.Association == Association.assoc_instance) - throw new Exception("Can't merge instance attributes"); - - // Index attributes can't be merged - if (Descriptor.Semantic == Semantic.Index) - throw new Exception("Can't merge index attributes"); - - return others - .Select(ma => ma as GeometryAttribute) - .Prepend(this) - .ToIArray() - .Select(attr => attr.Data) - .Flatten() - .ToAttribute(Descriptor); - } - - public override GeometryAttribute Remap(IArray indices) - => Data.SelectByIndex(indices).ToAttribute(Descriptor); - - public override INamedBuffer ToBuffer() - => Data.ToArray().ToNamedBuffer(Name); - - public override GeometryAttribute Read(Stream stream, long byteCount) - { - if (byteCount % Descriptor.DataElementSize != 0) - throw new Exception($"The number of bytes to read {byteCount} does not divide cleanly by the size of the elements {Descriptor.DataElementSize}"); - var nElements = byteCount / Descriptor.DataElementSize; - if (nElements > int.MaxValue) - throw new Exception($"Trying to read {nElements} which is more than the maximum number of elements in a C# array"); - var data = stream.ReadArray((int)nElements); - return new GeometryAttribute(data.ToIArray(), Descriptor); - } - - public override GeometryAttribute Read(BFast bfast) - { - var array = bfast.GetArray(Name); - return new GeometryAttribute(array.ToIArray(), Descriptor); - } - - public override void AddTo(BFast bfast) - { - bfast.SetArray(Name, Data.ToArray()); - } - - public override GeometryAttribute SetIndex(int index) - => index == Descriptor.Index ? this : new GeometryAttribute(Data, Descriptor.SetIndex(index)); - } -} diff --git a/src/cs/g3d/Vim.G3d/GeometryAttributes.cs b/src/cs/g3d/Vim.G3d/GeometryAttributes.cs deleted file mode 100644 index ac799c07..00000000 --- a/src/cs/g3d/Vim.G3d/GeometryAttributes.cs +++ /dev/null @@ -1,164 +0,0 @@ -/* - G3D Geometry Format Library - Copyright 2019, VIMaec LLC. - Copyright 2018, Ara 3D Inc. - Usage licensed under terms of MIT License -*/ - -using System; -using System.Collections.Generic; -using System.Linq; -using Vim.LinqArray; - -namespace Vim.G3d -{ - /// - /// This is the most generic representation of a G3D, which is a bag of attributes, and the observed size of each component. - /// - public class GeometryAttributes : IGeometryAttributes - { - public int NumCornersPerFace { get; } = -1; - - public int NumVertices { get; } = -1; - public int NumFaces { get; } = -1; - public int NumCorners { get; } = -1; - public int NumMeshes { get; } = -1; - public int NumInstances { get; } = -1; - public int NumMaterials { get; } = -1; - public int NumSubmeshes { get; } = -1; - - public int NumShapeVertices { get; } = -1; - public int NumShapes { get; } = -1; - - public IArray Attributes { get; } - - public GeometryAttribute GetAttribute(string name) - => Lookup.TryGetValue(name, out var val) ? val : null; - - public Dictionary Lookup - = new Dictionary(); - - public int ValidateAttribute(GeometryAttribute attr, int expectedCount) - { - if (expectedCount >= 0 && attr.ElementCount != expectedCount) - throw new Exception($"Attribute {attr.Descriptor.Name} size {attr.ElementCount} not match the expected size {expectedCount}"); - return attr.ElementCount; - } - - public GeometryAttributes(IEnumerable attributes, int numCornersPerFaceOverride = -1) - { - foreach (var attr in attributes) - { - if (attr != null && !Lookup.ContainsKey(attr.Name)) - Lookup.Add(attr.Name, attr); - } - - foreach (var attr in Lookup.Values) - { - var desc = attr.Descriptor; - - switch (desc.Association) - { - case Association.assoc_none: - break; - case Association.assoc_vertex: - NumVertices = ValidateAttribute(attr, NumVertices); - break; - case Association.assoc_edge: - case Association.assoc_corner: - NumCorners = ValidateAttribute(attr, NumCorners); - break; - case Association.assoc_face: - NumFaces = ValidateAttribute(attr, NumFaces); - break; - case Association.assoc_instance: - NumInstances = ValidateAttribute(attr, NumInstances); - break; - case Association.assoc_submesh: - NumSubmeshes = ValidateAttribute(attr, NumSubmeshes); - break; - case Association.assoc_material: - NumMaterials = ValidateAttribute(attr, NumMaterials); - break; - case Association.assoc_mesh: - NumMeshes = ValidateAttribute(attr, NumMeshes); - break; - case Association.assoc_shapevertex: - NumShapeVertices = ValidateAttribute(attr, NumShapeVertices); - break; - case Association.assoc_shape: - NumShapes = ValidateAttribute(attr, NumShapes); - break; - } - - if (desc.Semantic == Semantic.FaceSize) - { - if (desc.Association != Association.assoc_all) - throw new Exception($"The face size semantic has to be associated with entire geometry set, not {desc.Association}"); - if (desc.DataArity != 1) - throw new Exception($"The face size semantic has to have arity of 1, not {desc.DataArity}"); - - if (desc.DataType == DataType.dt_int8) - NumCornersPerFace = attr.AsType().Data[0]; - else if (desc.DataType == DataType.dt_int16) - NumCornersPerFace = attr.AsType().Data[0]; - else if (desc.DataType == DataType.dt_int32) - NumCornersPerFace = attr.AsType().Data[0]; - else - throw new Exception($"The face size semantic has to be an int8, int16, or int32"); - } - } - - if (NumVertices < 0) NumVertices = 0; - - // If the index attribute is missing we will have to add it. - if (!Lookup.ContainsKey(CommonAttributes.Index)) - { - if (NumCorners < 0) NumCorners = NumVertices; - Lookup.Add(CommonAttributes.Index, NumCorners.Range().ToIndexAttribute()); - } - - // Now we create the public ordered list of attributes - Attributes = Lookup.Values.OrderBy(attr => attr.Name).ToIArray(); - - - // If the number of corner and faces are observed, one has to be a multiple of the other - if (NumCorners > 0 && NumFaces > 0) - { - if (NumCorners % NumFaces != 0) - throw new Exception($"The number of corners {NumCorners} to be divisible by the number of faces {NumFaces}"); - } - - // Try to compute the number of corners per face - if (NumCornersPerFace < 0) - { - if (NumCorners > 0 && NumFaces > 0) - { - // We compute the number of corners per face by dividing the observed number of faces by the observed number of corners - NumCornersPerFace = NumCorners / NumFaces; - } - else - { - // By default we assume a triangular mesh - NumCornersPerFace = 3; - } - } - - if (numCornersPerFaceOverride >= 0) - { - NumCornersPerFace = numCornersPerFaceOverride; - } - - if (NumCorners < 0) NumCorners = NumVertices; - if (NumInstances < 0) NumInstances = 0; - if (NumMeshes < 0) NumMeshes = 0; - if (NumFaces < 0) NumFaces = NumCorners / NumCornersPerFace; - - if (NumShapeVertices < 0) NumShapeVertices = 0; - if (NumShapes < 0) NumShapes = 0; - } - - public static GeometryAttributes Empty - => new GeometryAttributes(new GeometryAttribute[] { }); - } -} diff --git a/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs b/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs deleted file mode 100644 index a378b94f..00000000 --- a/src/cs/g3d/Vim.G3d/GeometryAttributesExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.G3d -{ - public static class GeometryAttributesExtensions - { - public static GeometryAttribute GetAttribute(this IGeometryAttributes g, string attributeName) where T : unmanaged - => g.GetAttribute(attributeName)?.AsType(); - - public static IGeometryAttributes ToGeometryAttributes(this IEnumerable attributes) - => new GeometryAttributes(attributes); - - public static IGeometryAttributes AddAttributes(this IGeometryAttributes attributes, params GeometryAttribute[] newAttributes) - => attributes.Attributes.ToEnumerable().Concat(newAttributes).ToGeometryAttributes(); - - public static IGeometryAttributes Replace(this IGeometryAttributes self, Func selector, GeometryAttribute attribute) - => self.Attributes.Where(a => !selector(a.Descriptor)).Append(attribute).ToGeometryAttributes(); - - public static IGeometryAttributes Remove(this IGeometryAttributes self, Func selector) - => self.Attributes.Where(a => !selector(a.Descriptor)).ToGeometryAttributes(); - - public static G3D ToG3d(this IGeometryAttributes self) - => G3D.Create(self.Attributes.ToArray()); - } -} diff --git a/src/cs/g3d/Vim.G3d/Header.cs b/src/cs/g3d/Vim.G3d/Header.cs deleted file mode 100644 index 60d4bb09..00000000 --- a/src/cs/g3d/Vim.G3d/Header.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Text; - -namespace Vim.G3d -{ - // http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/index.html?url=files/GUID-CC93340E-C4A1-49EE-B048-E898F856CFBF.htm,topicNumber=d30e8478 - // https://twitter.com/FreyaHolmer/status/644881436982575104 - // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#coordinate-system-and-units - - // The header is 7 bytes + 1 bytes padding. - public struct G3dHeader - { - public const byte MagicA = 0x63; - public const byte MagicB = 0xD0; - - public byte magicA; // 0x63 - public byte magicB; // 0xD0 - public byte unitA; // with unitB could be: 'ft', 'yd', 'mi', 'km', 'mm', 'in', 'cm', 'm', - public byte unitB; - public byte upAxis; // e.g. 1=y or 2=z (could be 0=x, if you hate people) - public byte forwardVector; // e.g. 0=x, 1=y, 2=z, 3=-x, 4=-y, 5=-z - public byte handedness; // 0=left-handed, 1=right-handed - public byte padding; // 0 - - public string Unit => Encoding.ASCII.GetString(new byte[] { unitA, unitB }); - - public byte[] ToBytes() - => new[] { magicA, magicB, unitA, unitB, upAxis, forwardVector, handedness, padding }; - - public static G3dHeader FromBytes(byte[] bytes) - => new G3dHeader - { - magicA = bytes[0], - magicB = bytes[1], - unitA = bytes[2], - unitB = bytes[3], - upAxis = bytes[4], - forwardVector = bytes[5], - handedness = bytes[6], - } - .Validate(); - - public static G3dHeader FromBytesOrDefault(byte[] bytes) - { - try - { - return FromBytes(bytes).Validate(); - } - catch (Exception) - { - return Default; - } - } - - public static G3dHeader Default - = new G3dHeader - { - magicA = 0x63, - magicB = 0xD0, - unitA = (byte)'m', - unitB = 0, - upAxis = 2, - forwardVector = 0, - handedness = 0, - padding = 0 - }; - - public static readonly string[] SupportedUnits = { "mm", "cm", "m\0", "km", "in", "ft", "yd", "mi" }; - - public G3dHeader Validate() - { - if (magicA != 0x63) throw new Exception($"First magic number must be 0x63 not {magicA}"); - if (magicB != 0xD0) throw new Exception($"Second magic number must be 0xD0 not {magicB}"); - if (Array.IndexOf(SupportedUnits, Unit) < 0) throw new Exception($"Unit {Unit} is not a supported unit: {string.Join(", ", SupportedUnits)}"); - if (upAxis < 0 || upAxis > 2) throw new Exception("Up axis must be 0(x), 1(y), or 2(z)"); - if (forwardVector < 0 || forwardVector > 5) throw new Exception("Front vector must be 0 (x), 1(y), 2(z), 3(-x), 4(-y), or 5(-z)"); - if (handedness < 0 || handedness > 1) throw new Exception("Handedness must be 0 (left) or 1 (right"); - return this; - } - } -} diff --git a/src/cs/g3d/Vim.G3d/IGeometryAttributes.cs b/src/cs/g3d/Vim.G3d/IGeometryAttributes.cs deleted file mode 100644 index e25da638..00000000 --- a/src/cs/g3d/Vim.G3d/IGeometryAttributes.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Vim.LinqArray; - -namespace Vim.G3d -{ - /// - /// This is a read-only collection of G3D attributes. - /// - public interface IGeometryAttributes - { - int NumCornersPerFace { get; } - int NumVertices { get; } - int NumCorners { get; } - int NumFaces { get; } - int NumInstances { get; } - int NumMeshes { get; } - int NumShapeVertices { get; } - int NumShapes { get; } - - IArray Attributes { get; } - GeometryAttribute GetAttribute(string name); - } -} diff --git a/src/cs/g3d/Vim.G3dNext/Constants.cs b/src/cs/g3d/Vim.G3dNext/Constants.cs index 8442d63a..047a6081 100644 --- a/src/cs/g3d/Vim.G3dNext/Constants.cs +++ b/src/cs/g3d/Vim.G3dNext/Constants.cs @@ -14,7 +14,39 @@ public enum MeshSection Transparent, All } - + public static class CommonAttributes + { + public const string ObjectFaceSize = "g3d:all:facesize:0:int32:1"; + public const string Index = "g3d:corner:index:0:int32:1"; + public const string Position = "g3d:vertex:position:0:float32:3"; + public const string VertexUv = "g3d:vertex:uv:0:float32:2"; + public const string VertexUvw = "g3d:vertex:uv:0:float32:3"; + public const string VertexNormal = "g3d:vertex:normal:0:float32:3"; + public const string VertexColor = "g3d:vertex:color:0:float32:4"; + public const string VertexColor8Bit = "g3d:vertex:color:0:int8:4"; + public const string VertexBitangent = "g3d:vertex:bitangent:0:float32:3"; + public const string VertexTangent = "g3d:vertex:tangent:0:float32:4"; + public const string VertexSelectionWeight = "g3d:vertex:weight:0:float32:1"; + public const string FaceColor = "g3d:face:color:0:float32:4"; + public const string FaceMaterial = "g3d:face:material:0:int32:1"; + public const string FaceNormal = "g3d:face:normal:0:float32:3"; + public const string MeshSubmeshOffset = "g3d:mesh:submeshoffset:0:int32:1"; + public const string InstanceTransform = "g3d:instance:transform:0:float32:16"; + public const string InstanceParent = "g3d:instance:parent:0:int32:1"; + public const string InstanceMesh = "g3d:instance:mesh:0:int32:1"; + public const string InstanceFlags = "g3d:instance:flags:0:uint16:1"; + public const string LineTangentIn = "g3d:vertex:tangent:0:float32:3"; + public const string LineTangentOut = "g3d:vertex:tangent:1:float32:3"; + public const string ShapeVertex = "g3d:shapevertex:position:0:float32:3"; + public const string ShapeVertexOffset = "g3d:shape:vertexoffset:0:int32:1"; + public const string ShapeColor = "g3d:shape:color:0:float32:4"; + public const string ShapeWidth = "g3d:shape:width:0:float32:1"; + public const string MaterialColor = "g3d:material:color:0:float32:4"; + public const string MaterialGlossiness = "g3d:material:glossiness:0:float32:1"; + public const string MaterialSmoothness = "g3d:material:smoothness:0:float32:1"; + public const string SubmeshIndexOffset = "g3d:submesh:indexoffset:0:int32:1"; + public const string SubmeshMaterial = "g3d:submesh:material:0:int32:1"; + } public static class Utils { public static bool SafeEqual(this T[] a, T[] b) diff --git a/src/cs/vim-format.sln b/src/cs/vim-format.sln index d003f17e..6939a1f3 100644 --- a/src/cs/vim-format.sln +++ b/src/cs/vim-format.sln @@ -23,10 +23,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Format", "vim\Vim.Forma EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "g3d", "g3d", "{705B8FB2-D707-4527-91FC-0AADEDBA4D80}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3d.Tests", "g3d\Vim.G3d.Tests\Vim.G3d.Tests.csproj", "{DFC8DC5E-377D-4CCC-A498-5894D891A471}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3d", "g3d\Vim.G3d\Vim.G3d.csproj", "{F1EC1E94-C74C-4C37-961C-305CAE7C4707}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Format.CodeGen", "vim\Vim.Format.CodeGen\Vim.Format.CodeGen.csproj", "{762E8B1A-9182-4C5D-A25C-0C0F6219BA4E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Format.Tests", "vim\Vim.Format.Tests\Vim.Format.Tests.csproj", "{2CB4CF73-0CA8-4595-910C-EDA244EA5983}" @@ -83,14 +79,6 @@ Global {22278D91-27D7-4A84-8170-5FFB77A70C1F}.Debug|Any CPU.Build.0 = Debug|Any CPU {22278D91-27D7-4A84-8170-5FFB77A70C1F}.Release|Any CPU.ActiveCfg = Release|Any CPU {22278D91-27D7-4A84-8170-5FFB77A70C1F}.Release|Any CPU.Build.0 = Release|Any CPU - {DFC8DC5E-377D-4CCC-A498-5894D891A471}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DFC8DC5E-377D-4CCC-A498-5894D891A471}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DFC8DC5E-377D-4CCC-A498-5894D891A471}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DFC8DC5E-377D-4CCC-A498-5894D891A471}.Release|Any CPU.Build.0 = Release|Any CPU - {F1EC1E94-C74C-4C37-961C-305CAE7C4707}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F1EC1E94-C74C-4C37-961C-305CAE7C4707}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F1EC1E94-C74C-4C37-961C-305CAE7C4707}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F1EC1E94-C74C-4C37-961C-305CAE7C4707}.Release|Any CPU.Build.0 = Release|Any CPU {762E8B1A-9182-4C5D-A25C-0C0F6219BA4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {762E8B1A-9182-4C5D-A25C-0C0F6219BA4E}.Debug|Any CPU.Build.0 = Debug|Any CPU {762E8B1A-9182-4C5D-A25C-0C0F6219BA4E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -157,8 +145,6 @@ Global {1086F24E-32C8-4261-9B06-A364EEE71DEF} = {9BD3CC85-97FD-4093-AA11-58FE405B0F65} {1CC20AA4-11F1-4548-9285-FD24D42190FB} = {9BD3CC85-97FD-4093-AA11-58FE405B0F65} {22278D91-27D7-4A84-8170-5FFB77A70C1F} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} - {DFC8DC5E-377D-4CCC-A498-5894D891A471} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} - {F1EC1E94-C74C-4C37-961C-305CAE7C4707} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} {762E8B1A-9182-4C5D-A25C-0C0F6219BA4E} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} {2CB4CF73-0CA8-4595-910C-EDA244EA5983} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} {2C798994-518D-4EA5-8F8A-3EAA30269F9E} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} diff --git a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs index 082e957f..daca69a3 100644 --- a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Linq; -using Vim.G3d; +using Vim.G3dNext; using Vim.BFastLib; using static Vim.Format.DocumentBuilder; using Vim.Math3d; diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs index ee3b002a..851a93d4 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Vim.G3d; using Vim.LinqArray; using Vim.Math3d; diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMaterial.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMaterial.cs deleted file mode 100644 index 4799219f..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMaterial.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Vim.G3d; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - public interface IMaterial - { - Vector4 Color { get; } - float Smoothness { get; } - float Glossiness { get; } - } - - public class VimMaterial : IMaterial - { - public G3dMaterial Material; - public VimMaterial(G3dMaterial material) => Material = material; - public Vector4 Color => Material.Color; - public float Smoothness => Material.Smoothness; - public float Glossiness => Material.Glossiness; - } -} diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs index fd915fc8..0d0a1740 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs @@ -5,6 +5,14 @@ namespace Vim.Format.Geometry { + public interface IMaterial + { + Vector4 Color { get; } + float Smoothness { get; } + float Glossiness { get; } + } + + public class VimMaterialNext : IMaterial { public G3dVim g3d; diff --git a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs index 94364b97..013ce98f 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs @@ -4,7 +4,6 @@ using System.Text; using Vim.BFastLib; using Vim.BFastLib.Core; -using Vim.G3d; using Vim.G3dNext; namespace Vim.Format diff --git a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj index f02d4460..00b498be 100644 --- a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj +++ b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj @@ -8,7 +8,6 @@ - diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index ec11608c..6c0ecc96 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -1,18 +1,17 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using Vim.BFastLib; using Vim.Format; using Vim.Format.Geometry; using Vim.Format.ObjectModel; -using Vim.Util; -using Vim.G3d; +using Vim.G3dNext; using Vim.LinqArray; using Vim.Math3d; +using Vim.Util; using IVimSceneProgress = System.IProgress<(string, double)>; -using Vim.BFastLib; -using Vim.G3dNext; -using System.Collections.Generic; namespace Vim { diff --git a/src/cs/vim/Vim.Format/Vim.Format.csproj b/src/cs/vim/Vim.Format/Vim.Format.csproj index 6f385377..a3ae53d8 100644 --- a/src/cs/vim/Vim.Format/Vim.Format.csproj +++ b/src/cs/vim/Vim.Format/Vim.Format.csproj @@ -18,7 +18,6 @@ - From 48e3459968d5ebd547e296b6d60d744ae9c78aec Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 15 Apr 2024 15:55:53 -0400 Subject: [PATCH 061/104] removed geometry utils --- .../Vim.Format.Core/Geometry/GeometryUtil.cs | 60 +------------------ .../Vim.Format.Core/Geometry/Primitives.cs | 15 ----- .../Geometry/GeometryTests.cs | 8 +-- 3 files changed, 2 insertions(+), 81 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/GeometryUtil.cs b/src/cs/vim/Vim.Format.Core/Geometry/GeometryUtil.cs index db8d33e7..6d6f1b71 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/GeometryUtil.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/GeometryUtil.cs @@ -6,63 +6,5 @@ namespace Vim.Format.Geometry { - // TODO: many of these functions should live in other places - public static class GeometryUtil - { - public static IArray Normalize(this IArray vectors) - => vectors.Select(v => v.Normalize()); - - public static bool SequenceAlmostEquals(this IArray vs1, IArray vs2, float tolerance = Math3d.Constants.Tolerance) - => vs1.Count == vs2.Count && vs1.Indices().All(i => vs1[i].AlmostEquals(vs2[i], tolerance)); - - public static bool AreColinear(this IEnumerable vectors, Vector3 reference, float tolerance = (float)Math3d.Constants.OneTenthOfADegree) - => !reference.IsNaN() && vectors.All(v => v.Colinear(reference, tolerance)); - - public static bool AreColinear(this IEnumerable vectors, float tolerance = (float)Math3d.Constants.OneTenthOfADegree) - => vectors.ToList().AreColinear(tolerance); - - public static bool AreColinear(this IList vectors, float tolerance = (float)Math3d.Constants.OneTenthOfADegree) - => vectors.Count <= 1 || vectors.Skip(1).AreColinear(vectors[0], tolerance); - - public static AABox BoundingBox(this IArray vertices) - => AABox.Create(vertices.ToEnumerable()); - - public static IArray SampleZeroToOneInclusive(this int count) - => (count + 1).Select(i => i / (float)count); - - public static IArray SampleZeroToOneExclusive(this int count) - => count.Select(i => i / (float)count); - - public static IArray InterpolateInclusive(this int count, Func function) - => count.SampleZeroToOneInclusive().Select(function); - - public static IArray Interpolate(this Line self, int count) - => count.InterpolateInclusive(self.Lerp); - - public static IArray Rotate(this IArray self, Vector3 axis, float angle) - => self.Transform(Matrix4x4.CreateFromAxisAngle(axis, angle)); - - public static IArray Transform(this IArray self, Matrix4x4 matrix) - => self.Select(x => x.Transform(matrix)); - - public static Int3 Sort(this Int3 v) - { - if (v.X < v.Y) - { - return (v.Y < v.Z) - ? new Int3(v.X, v.Y, v.Z) - : (v.X < v.Z) - ? new Int3(v.X, v.Z, v.Y) - : new Int3(v.Z, v.X, v.Y); - } - else - { - return (v.X < v.Z) - ? new Int3(v.Y, v.X, v.Z) - : (v.Y < v.Z) - ? new Int3(v.Y, v.Z, v.X) - : new Int3(v.Z, v.Y, v.X); - } - } - } + } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index 97e09d20..3c97bbfd 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -280,20 +280,5 @@ public static VimMesh QuadMesh(this Func f, int usegs, int vse return VimMesh.FromQuad(indices.ToArray(), verts.ToArray()); } - - /// - /// Creates a revolved face ... note that the last points are on top of the original - /// - public static VimMesh RevolveAroundAxis(this IArray points, Vector3 axis, int segments = 4) - { - var verts = new List(); - for (var i = 0; i < segments; ++i) - { - var angle = Math3d.Constants.TwoPi / segments; - points.Rotate(axis, angle).AddTo(verts); - } - var indices = ComputeQuadMeshStripIndices(segments - 1, points.Count - 1); - return new VimMesh(indices.ToArray(), verts.ToArray()); - } } } diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 334c882c..4e16f6b5 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -38,12 +38,7 @@ public static class GeometryTests }); public static VimMesh Torus = Primitives.Torus(10, 0.2f, 10, 24); - - static VimMesh RevolvedVerticalCylinder(float height, float radius, int verticalSegments, int radialSegments) - => (Vector3.UnitZ * height).ToLine().Interpolate(verticalSegments).Add(-radius.AlongX()).RevolveAroundAxis(Vector3.UnitZ, radialSegments); - - public static VimMesh Cylinder = RevolvedVerticalCylinder(5, 1, 4, 12); - + public static VimMesh[] AllMeshes = { XYTriangle, // 0 XYQuad, // 1 @@ -51,7 +46,6 @@ static VimMesh RevolvedVerticalCylinder(float height, float radius, int vertical XYQuad2x2, // 3 Tetrahedron, // 4 Torus, // 5 - Cylinder, // 6 XYTriangleTwice, // 7 }; From 8a55f41230ce975148000589e4d7c0f4cd7f55b7 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 15 Apr 2024 16:13:05 -0400 Subject: [PATCH 062/104] removing dead code --- .../Geometry/GeometryCuttingUtils.cs | 46 ------------- .../Vim.Format.Core/Geometry/GeometryUtil.cs | 68 ------------------- .../Vim.Format.Core/Geometry/Primitives.cs | 8 +-- .../Geometry/GeometryTests.cs | 8 +-- 4 files changed, 5 insertions(+), 125 deletions(-) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/GeometryUtil.cs diff --git a/src/cs/vim/Vim.Format.Core/Geometry/GeometryCuttingUtils.cs b/src/cs/vim/Vim.Format.Core/Geometry/GeometryCuttingUtils.cs index 338f7776..b35ac47d 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/GeometryCuttingUtils.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/GeometryCuttingUtils.cs @@ -123,51 +123,5 @@ public static float LinePointDistance(Vector2 v, Vector2 w, Vector2 p, out float var closestPoint = v + t * (w - v); // Projection falls on the segment return (p - closestPoint).Length(); } - - - - // Apply a surface function that projects a 2d triangulation in UV space into a 3d triangulation - /* public static IGeometry ApplySurfaceFunction(this List triangulations, Func surfaceFunction) - { - var allIndices = new List(); - var allVertices = new List(); - - foreach (var triangulation in triangulations) - { - var vertices = triangulation.Points.ToList(); - var indices = triangulation.TriangleIndices; - - while (true) - { - List outIndices; - List outVertices; - bool done = SubdivideLargeTriangles(vertices, indices, out outVertices, out outIndices, 0.3f); - - vertices = outVertices; - indices = outIndices; - - if (done) - { - break; - } - } - - // Apply surface function - var vertices3d = vertices.Select(x => surfaceFunction(x.ToVector())); - - // Merge all triangulations - int startIndex = allVertices.Count; - allVertices.AddRange(vertices3d); - allIndices.AddRange(indices.Select(x => x + startIndex)); - } - - var cutGeometry = new G3D( - allVertices.ToIArray().ToVertexAttribute(), - allIndices.ToIArray().ToIndexAttribute(), - new FunctionalArray(allIndices.Count / 3, x => 3).ToFaceSizeAttribute() - ).ToIMesh(); - - return cutGeometry; - }*/ } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/GeometryUtil.cs b/src/cs/vim/Vim.Format.Core/Geometry/GeometryUtil.cs deleted file mode 100644 index db8d33e7..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/GeometryUtil.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - // TODO: many of these functions should live in other places - public static class GeometryUtil - { - public static IArray Normalize(this IArray vectors) - => vectors.Select(v => v.Normalize()); - - public static bool SequenceAlmostEquals(this IArray vs1, IArray vs2, float tolerance = Math3d.Constants.Tolerance) - => vs1.Count == vs2.Count && vs1.Indices().All(i => vs1[i].AlmostEquals(vs2[i], tolerance)); - - public static bool AreColinear(this IEnumerable vectors, Vector3 reference, float tolerance = (float)Math3d.Constants.OneTenthOfADegree) - => !reference.IsNaN() && vectors.All(v => v.Colinear(reference, tolerance)); - - public static bool AreColinear(this IEnumerable vectors, float tolerance = (float)Math3d.Constants.OneTenthOfADegree) - => vectors.ToList().AreColinear(tolerance); - - public static bool AreColinear(this IList vectors, float tolerance = (float)Math3d.Constants.OneTenthOfADegree) - => vectors.Count <= 1 || vectors.Skip(1).AreColinear(vectors[0], tolerance); - - public static AABox BoundingBox(this IArray vertices) - => AABox.Create(vertices.ToEnumerable()); - - public static IArray SampleZeroToOneInclusive(this int count) - => (count + 1).Select(i => i / (float)count); - - public static IArray SampleZeroToOneExclusive(this int count) - => count.Select(i => i / (float)count); - - public static IArray InterpolateInclusive(this int count, Func function) - => count.SampleZeroToOneInclusive().Select(function); - - public static IArray Interpolate(this Line self, int count) - => count.InterpolateInclusive(self.Lerp); - - public static IArray Rotate(this IArray self, Vector3 axis, float angle) - => self.Transform(Matrix4x4.CreateFromAxisAngle(axis, angle)); - - public static IArray Transform(this IArray self, Matrix4x4 matrix) - => self.Select(x => x.Transform(matrix)); - - public static Int3 Sort(this Int3 v) - { - if (v.X < v.Y) - { - return (v.Y < v.Z) - ? new Int3(v.X, v.Y, v.Z) - : (v.X < v.Z) - ? new Int3(v.X, v.Z, v.Y) - : new Int3(v.Z, v.X, v.Y); - } - else - { - return (v.X < v.Z) - ? new Int3(v.Y, v.X, v.Z) - : (v.Y < v.Z) - ? new Int3(v.Y, v.Z, v.X) - : new Int3(v.Z, v.Y, v.X); - } - } - } -} diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index 97e09d20..24ca7bf3 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -119,7 +119,7 @@ public static Vector2 CirclePoint(int i, int numPoints) /// /// Computes the indices of a quad mesh astrip. /// - public static IArray ComputeQuadMeshStripIndices(int usegs, int vsegs, bool wrapUSegs = false, bool wrapVSegs = false) + public static int[] ComputeQuadMeshStripIndices(int usegs, int vsegs, bool wrapUSegs = false, bool wrapVSegs = false) { var indices = new List(); @@ -143,7 +143,7 @@ public static IArray ComputeQuadMeshStripIndices(int usegs, int vsegs, bool } } - return indices.ToIArray(); + return indices.ToArray(); } /// @@ -278,7 +278,7 @@ public static VimMesh QuadMesh(this Func f, int usegs, int vse } var indices = ComputeQuadMeshStripIndices(usegs, vsegs, wrapUSegs, wrapVSegs); - return VimMesh.FromQuad(indices.ToArray(), verts.ToArray()); + return VimMesh.FromQuad(indices, verts.ToArray()); } /// @@ -293,7 +293,7 @@ public static VimMesh RevolveAroundAxis(this IArray points, Vector3 axi points.Rotate(axis, angle).AddTo(verts); } var indices = ComputeQuadMeshStripIndices(segments - 1, points.Count - 1); - return new VimMesh(indices.ToArray(), verts.ToArray()); + return new VimMesh(indices, verts.ToArray()); } } } diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 334c882c..26a82403 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -39,11 +39,6 @@ public static class GeometryTests public static VimMesh Torus = Primitives.Torus(10, 0.2f, 10, 24); - static VimMesh RevolvedVerticalCylinder(float height, float radius, int verticalSegments, int radialSegments) - => (Vector3.UnitZ * height).ToLine().Interpolate(verticalSegments).Add(-radius.AlongX()).RevolveAroundAxis(Vector3.UnitZ, radialSegments); - - public static VimMesh Cylinder = RevolvedVerticalCylinder(5, 1, 4, 12); - public static VimMesh[] AllMeshes = { XYTriangle, // 0 XYQuad, // 1 @@ -51,7 +46,6 @@ static VimMesh RevolvedVerticalCylinder(float height, float radius, int vertical XYQuad2x2, // 3 Tetrahedron, // 4 Torus, // 5 - Cylinder, // 6 XYTriangleTwice, // 7 }; @@ -230,7 +224,7 @@ public static void TriangleSerializationTest() //TODO: Check the need for this test. // Serializing a triangle is that a use case ? - var mesh = new VimMesh(new [] { 0, 1, 2 }, new[] + var mesh = new VimMesh(new[] { 0, 1, 2 }, new[] { new Vector3(0, 0, 0), new Vector3(0, 1, 0), From dbfcfdd697873b8eb8760229479a2f5dfcc4a02d Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 15 Apr 2024 16:13:21 -0400 Subject: [PATCH 063/104] iarray -> array --- src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs b/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs index f8f40bac..df7755cb 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Vim.LinqArray; namespace Vim.Format.ObjectModel @@ -29,8 +30,8 @@ public int FamilyInstanceIndex } } - private IArray _parameterIndices; - public IArray ParameterIndices + private int[] _parameterIndices; + public int[] ParameterIndices { get { @@ -39,7 +40,7 @@ public IArray ParameterIndices _parameterIndices = (DocumentModel.ElementIndexMaps.ParameterIndicesFromElementIndex .TryGetValue(ElementIndex, out var parameterIndices) ? parameterIndices : new List()) - .ToIArray(); + .ToArray(); return _parameterIndices; } @@ -108,7 +109,7 @@ public bool IsSystem public Family Family => DocumentModel.FamilyList.ElementAtOrDefault(FamilyIndex); public System System => DocumentModel.SystemList.ElementAtOrDefault(SystemIndex); public Element SystemElement => DocumentModel.ElementList.ElementAtOrDefault(SystemElementIndex); - public IEnumerable Parameters => DocumentModel.ParameterList.SelectByIndex(ParameterIndices).ToEnumerable(); + public IEnumerable Parameters => ParameterIndices.Select(i => DocumentModel.ParameterList[i]); [Flags] public enum ParameterScope From 2908d93166c0fcf1a20a61829846179bea68cbd6 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 15 Apr 2024 16:32:39 -0400 Subject: [PATCH 064/104] iarray -> array --- src/cs/vim/Vim.Format/ObjectModel/Validation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs index 24fb6399..1e6167da 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs @@ -265,7 +265,7 @@ void ValidateDVector3Domain(string label, DVector3 value, DVector3 lowerInclusiv } public static Dictionary> GetViewToElementsMap( - this IArray elementInViewList) + this ElementInView[] elementInViewList) => elementInViewList .Select(eiv => (viewIndex: eiv._View?.Index ?? -1, elementIndex: eiv._Element?.Index ?? -1)) .GroupBy(t => t.viewIndex) @@ -275,7 +275,7 @@ public static Dictionary> GetViewToElementsMap( public static void ValidateShapesInView(this DocumentModel dm) { - var viewToElementsMap = dm.ElementInViewList.GetViewToElementsMap(); + var viewToElementsMap = dm.ElementInViewList.ToArray().GetViewToElementsMap(); // Validate that the shapes in view have an element which is also in the same view. foreach (var item in dm.ShapeInViewList.ToEnumerable()) From 169a31a9f5789819bb4574c3cca3fee530b12cbd Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 15 Apr 2024 16:32:48 -0400 Subject: [PATCH 065/104] removed dead code --- src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index 24ca7bf3..6dcc346e 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -280,20 +280,5 @@ public static VimMesh QuadMesh(this Func f, int usegs, int vse return VimMesh.FromQuad(indices, verts.ToArray()); } - - /// - /// Creates a revolved face ... note that the last points are on top of the original - /// - public static VimMesh RevolveAroundAxis(this IArray points, Vector3 axis, int segments = 4) - { - var verts = new List(); - for (var i = 0; i < segments; ++i) - { - var angle = Math3d.Constants.TwoPi / segments; - points.Rotate(axis, angle).AddTo(verts); - } - var indices = ComputeQuadMeshStripIndices(segments - 1, points.Count - 1); - return new VimMesh(indices, verts.ToArray()); - } } } From 6f1f9ff3a28ceb2564d12f2a940e6c84c6da4c16 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 07:22:06 -0400 Subject: [PATCH 066/104] iarray -> array --- .../DocumentBuilderExtensions.cs | 8 +- src/cs/vim/Vim.Format.Core/G3dBuilder.cs | 10 +- .../Vim.Format.Core/Geometry/CatmullClark.cs | 36 +++--- .../Geometry/MeshOptimization.cs | 2 +- .../Geometry/PerimeterProjection.cs | 10 +- .../Vim.Format.Core/Geometry/Primitives.cs | 16 +-- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 112 ++++++++---------- .../Geometry/GeometryTests.cs | 76 ++++++------ .../vim/Vim.Format/SceneBuilder/VimScene.cs | 2 +- .../Vim.Format/SceneBuilder/VimSceneNode.cs | 6 +- 10 files changed, 133 insertions(+), 145 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index 27597945..a8bf6e51 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -11,10 +11,10 @@ public static class DocumentBuilderExtensions { public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this VimMesh m) => new SubdividedMesh( - m.Indices.ToList(), - m.Vertices.ToList(), - m.SubmeshIndexOffsets.ToList(), - m.SubmeshMaterials.ToList()); + m.indices, + m.vertices, + m.submeshIndexOffsets, + m.submeshMaterials); public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, EntityTable table, List nodeIndexRemapping = null) { diff --git a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs index daca69a3..f2cd62d4 100644 --- a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs @@ -48,12 +48,12 @@ public AABox GetBox(int meshIndex) public int[] GetVertexCounts() { - return _meshes.Select(m => m.Vertices.Count).ToArray(); + return _meshes.Select(m => m.vertices.Length).ToArray(); } public int[] GetFaceCounts() { - return _meshes.Select(m => m.Indices.Count / 3).ToArray(); + return _meshes.Select(m => m.NumFaces).ToArray(); } @@ -72,8 +72,8 @@ public BFast ToBFast() for (var i = 1; i < n; ++i) { - meshVertexOffsets[i] = meshVertexOffsets[i - 1] + _meshes[i - 1].Vertices.Count; - meshIndexOffsets[i] = meshIndexOffsets[i - 1] + _meshes[i - 1].Indices.Count; + meshVertexOffsets[i] = meshVertexOffsets[i - 1] + _meshes[i - 1].vertices.Length; + meshIndexOffsets[i] = meshIndexOffsets[i - 1] + _meshes[i - 1].indices.Length; meshSubmeshOffset[i] = meshSubmeshOffset[i - 1] + _meshes[i - 1].SubmeshCount; } @@ -85,7 +85,7 @@ public BFast ToBFast() { submeshIndexOffsets[subIndex++] = sub + previousIndexCount; } - previousIndexCount += geo.Indices.Count; + previousIndexCount += geo.indices.Length; } // Compute the shape vertex offsets diff --git a/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs b/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs index 48c2ac77..30142230 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/CatmullClark.cs @@ -48,7 +48,7 @@ public static Dictionary CreateEdgeMap(this VimMe var faceSize = 3; for (var edgeIndex = 0; edgeIndex < faceSize; edgeIndex++) { - var geometryEdgeKey = new GeometryEdgeKey(geometry.Indices[currentIndex + edgeIndex], geometry.Indices[currentIndex + (edgeIndex + 1) % faceSize]); + var geometryEdgeKey = new GeometryEdgeKey(geometry.indices[currentIndex + edgeIndex], geometry.indices[currentIndex + (edgeIndex + 1) % faceSize]); if (edgeMap.ContainsKey(geometryEdgeKey)) { edgeMap[geometryEdgeKey].Face1 = faceIndex; @@ -72,16 +72,16 @@ public static VimMesh CatmullClark(this VimMesh geometry, float smoothing = 0.0f var edgeMap = geometry.CreateEdgeMap(); var numQuads = geometry.NumFaces * 3; - var numVertices = geometry.Vertices.Count + edgeMap.Count + geometry.NumFaces; + var numVertices = geometry.vertices.Length + edgeMap.Count + geometry.NumFaces; var facePoints = new Vector3[geometry.NumFaces]; - var vertexFPoints = new Vector3[geometry.Vertices.Count]; - var vertexRPoints = new Vector3[geometry.Vertices.Count]; - var vertexNumFaces = new float[geometry.Vertices.Count]; - var vertexNumEdges = new float[geometry.Vertices.Count]; + var vertexFPoints = new Vector3[geometry.vertices.Length]; + var vertexRPoints = new Vector3[geometry.vertices.Length]; + var vertexNumFaces = new float[geometry.vertices.Length]; + var vertexNumEdges = new float[geometry.vertices.Length]; var newVertices = new Vector3[numVertices]; var newIndices = new int[numQuads * 4]; - var edgeVertices = new bool[geometry.Vertices.Count]; + var edgeVertices = new bool[geometry.vertices.Length]; foreach (var edge in edgeMap) { @@ -112,7 +112,7 @@ public static VimMesh CatmullClark(this VimMesh geometry, float smoothing = 0.0f CalculateEdgePoints(geometry, edgeMap, facePoints, vertexNumEdges, vertexRPoints, smoothing); CalculateVertexPoints(geometry, vertexNumFaces, vertexFPoints, vertexNumEdges, vertexRPoints, newVertices, edgeVertices, smoothing); - var facePointStartIndex = geometry.Vertices.Count; + var facePointStartIndex = geometry.vertices.Length; var edgePointStartIndex = facePointStartIndex + facePoints.Length; // Copy all points into a single buffer @@ -139,8 +139,8 @@ public static void CalculateFaceCentroidPoints(VimMesh geometry, Vector3[] outFa for (var edgeIndex = 0; edgeIndex < faceSize; edgeIndex++) { - var vertexIndex = geometry.Indices[currentVertexIndex + edgeIndex]; - facePoint += geometry.Vertices[vertexIndex]; + var vertexIndex = geometry.indices[currentVertexIndex + edgeIndex]; + facePoint += geometry.vertices[vertexIndex]; } facePoint /= faceSize; @@ -149,7 +149,7 @@ public static void CalculateFaceCentroidPoints(VimMesh geometry, Vector3[] outFa for (var edgeIndex = 0; edgeIndex < faceSize; edgeIndex++) { - var vertexIndex = geometry.Indices[currentVertexIndex + edgeIndex]; + var vertexIndex = geometry.indices[currentVertexIndex + edgeIndex]; outVertexNumFaces[vertexIndex]++; outVertexFPoints[vertexIndex] += facePoint; } @@ -163,7 +163,7 @@ public static void CalculateEdgePoints(VimMesh geometry, Dictionary= 0 && edge.Value.Face1 >= 0) @@ -187,13 +187,13 @@ public static void CalculateEdgePoints(VimMesh geometry, Dictionary, int> BuildEdgeDictionary(this VimMesh { var edges = new Dictionary, int>(new EdgeEqualityComparer()); - var indices = mesh.Indices; + var indices = mesh.indices; - for (var i = 0; i < indices.Count; i += 3) + for (var i = 0; i < indices.Length; i += 3) { var i0 = indices[i + 0]; var i1 = indices[i + 1]; @@ -330,10 +330,10 @@ public static List> BuildBoundarySegments(this VimMesh mesh, Dicti { var segments = new List>(); - var indices = mesh.Indices; - var vertices = mesh.Vertices; + var indices = mesh.indices; + var vertices = mesh.vertices; - for (var i = 0; i < indices.Count; i += 3) + for (var i = 0; i < indices.Length; i += 3) { var i0 = indices[i + 0]; var i1 = indices[i + 1]; diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index 6dcc346e..efd44cd3 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -107,11 +107,11 @@ public static VimMesh Sphere(float radius, int uSegs, int vSegs) /// /// Returns a collection of circular points. /// - public static IArray CirclePoints(float radius, int numPoints) - => CirclePoints(numPoints).Select(x => x * radius); + public static Vector2[] CirclePoints(float radius, int numPoints) + => CirclePoints(numPoints).Select(x => x * radius).ToArray(); - public static IArray CirclePoints(int numPoints) - => numPoints.Select(i => CirclePoint(i, numPoints)); + public static Vector2[] CirclePoints(int numPoints) + => numPoints.Select(i => CirclePoint(i, numPoints)).ToArray(); public static Vector2 CirclePoint(int i, int numPoints) => new Vector2((i * (Math3d.Constants.TwoPi / numPoints)).Cos(), (i * (Math3d.Constants.TwoPi / numPoints)).Sin()); @@ -150,7 +150,7 @@ public static int[] ComputeQuadMeshStripIndices(int usegs, int vsegs, bool wrapU /// Returns the index buffer of a quad mesh strip. /// Returns an empty array if either numRowPoints or numPointsPerRow is less than 2. /// - public static IArray QuadMeshStripIndicesFromPointRows( + public static int[] QuadMeshStripIndicesFromPointRows( int numPointRows, int numPointsPerRow, bool clockwise = false) @@ -206,10 +206,10 @@ public static IArray QuadMeshStripIndicesFromPointRows( } } - return indices.ToIArray(); + return indices.ToArray(); } - public static IArray TriMeshCylinderCapIndices(int numEdgeVertices) + public static int[] TriMeshCylinderCapIndices(int numEdgeVertices) { // Example cap where numEdgeVertices is 6: // @@ -249,7 +249,7 @@ public static IArray TriMeshCylinderCapIndices(int numEdgeVertices) indices.Add(lastTriangleIndex1); indices.Add(lastTriangleIndex2); - return indices.ToIArray(); + return indices.ToArray(); } /// diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 719d9a8f..0f1989a3 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -10,14 +10,6 @@ namespace Vim.Format.Geometry { public class VimMesh : ITransformable3D { - public IArray Vertices => vertices.ToIArray(); - - public IArray Indices => indices.ToIArray(); - - public IArray SubmeshMaterials => submeshMaterials.ToIArray(); - public IArray SubmeshIndexOffsets => submeshIndexOffsets.ToIArray(); - public IArray SubmeshIndexCounts => submeshIndexCounts.ToIArray(); - public int SubmeshCount => submeshIndexCounts.Length; public int NumCornersPerFace => 3; @@ -28,13 +20,6 @@ public class VimMesh : ITransformable3D public int NumFaces => indices.Length / 3; - public int NumInstances => 0; - - public int NumMeshes => 1; - - public int NumShapeVertices => 0; - - public int NumShapes => 0; public int[] indices; public Vector3[] vertices; @@ -42,6 +27,10 @@ public class VimMesh : ITransformable3D public int[] submeshMaterials; public int[] submeshIndexCounts; + public int GetIndexCount() => indices.Length; + public int GetVertexCount() => vertices.Length; + + public VimMesh() { @@ -227,7 +216,7 @@ public void Validate() } private void ValidateIndices() { - foreach (var index in Indices.ToEnumerable()) + foreach (var index in indices) { if (index < 0 || index >= NumVertices) throw new Exception($"Invalid mesh index: {index}. Expected a value greater or equal to 0 and less than {NumVertices}"); @@ -240,20 +229,20 @@ public static class MeshCommonExtensions public static VimMesh ReverseWindingOrder(this VimMesh mesh) { var result = mesh.Clone(); - var count = mesh.Indices.Count; + var count = mesh.indices.Length; var indices = new int[count]; for (var i = 0; i < count; i += 3) { - indices[i + 0] = mesh.Indices[i + 2]; - indices[i + 1] = mesh.Indices[i + 1]; - indices[i + 2] = mesh.Indices[i + 0]; + indices[i + 0] = mesh.indices[i + 2]; + indices[i + 1] = mesh.indices[i + 1]; + indices[i + 2] = mesh.indices[i + 0]; } result.SetIndices(indices); return result; } - public static IArray GetFaceMaterials(this VimMesh mesh) + public static int[] GetFaceMaterials(this VimMesh mesh) { // SubmeshIndexOffsets: [0, A, B] // SubmeshIndexCount: [X, Y, Z] @@ -261,10 +250,9 @@ public static IArray GetFaceMaterials(this VimMesh mesh) // --- // FaceMaterials: [...Repeat(L, X / 3), ...Repeat(M, Y / 3), ...Repeat(N, Z / 3)] <-- divide by 3 for the number of corners per Triangular face var numCornersPerFace = mesh.NumCornersPerFace; - return mesh.SubmeshIndexCounts - .ToEnumerable() - .SelectMany((indexCount, i) => Enumerable.Repeat(mesh.SubmeshMaterials[i], indexCount / numCornersPerFace)) - .ToIArray(); + return mesh.submeshIndexCounts + .SelectMany((indexCount, i) => Enumerable.Repeat(mesh.submeshMaterials[i], indexCount / numCornersPerFace)) + .ToArray(); } public static VimMesh Merge2(this VimMesh mesh, params VimMesh[] others) @@ -279,18 +267,18 @@ public static VimMesh Merge2(this VimMesh mesh, params VimMesh[] others) public static VimMesh Merge(this VimMesh[] meshes) { - void Merge(IArray from, int[] to, int offset, int increment) + void Merge(int[] from, int[] to, int offset, int increment) { - for (var i = 0; i < from.Count; i++) + for (var i = 0; i < from.Length; i++) { to[i + offset] = from[i] + increment; } } // Init arrays - var indexCount = meshes.Sum(m => m.Indices.Count); - var vertexCount = meshes.Sum(m => m.Vertices.Count); - var submeshCount = meshes.Sum(m => m.SubmeshIndexOffsets.Count); + var indexCount = meshes.Sum(m => m.indices.Length); + var vertexCount = meshes.Sum(m => m.vertices.Length); + var submeshCount = meshes.Sum(m => m.submeshIndexOffsets.Length); var result = new VimMesh(indexCount, vertexCount, submeshCount); var indexOffset = 0; @@ -301,15 +289,15 @@ void Merge(IArray from, int[] to, int offset, int increment) { var mesh = meshes[m]; - Merge(mesh.Indices, result.indices, indexOffset, vertexOffset); - mesh.Vertices.CopyTo(result.vertices, vertexOffset); - mesh.SubmeshMaterials.CopyTo(result.submeshMaterials, submeshOffset); - mesh.SubmeshIndexCounts.CopyTo(result.submeshIndexCounts, submeshOffset); - Merge(mesh.SubmeshIndexOffsets, result.submeshIndexOffsets, submeshOffset, indexOffset); + Merge(mesh.indices, result.indices, indexOffset, vertexOffset); + mesh.vertices.CopyTo(result.vertices, vertexOffset); + mesh.submeshMaterials.CopyTo(result.submeshMaterials, submeshOffset); + mesh.submeshIndexCounts.CopyTo(result.submeshIndexCounts, submeshOffset); + Merge(mesh.submeshIndexOffsets, result.submeshIndexOffsets, submeshOffset, indexOffset); - indexOffset += mesh.Indices.Count; - vertexOffset += mesh.Vertices.Count; - submeshOffset += mesh.SubmeshIndexOffsets.Count; + indexOffset += mesh.indices.Length; + vertexOffset += mesh.vertices.Length; + submeshOffset += mesh.submeshIndexOffsets.Length; } return result; @@ -322,11 +310,11 @@ public static VimMesh[] SplitSubmeshes(this VimMesh mesh) public static (int, List)[] GroupSubmeshesByMaterials(this VimMesh mesh) { - var submeshCount = mesh.SubmeshIndexOffsets.Count; + var submeshCount = mesh.submeshIndexOffsets.Length; var map = new Dictionary>(); for (var i = 0; i < submeshCount; i++) { - var mat = mesh.SubmeshMaterials[i]; + var mat = mesh.submeshMaterials[i]; if (map.ContainsKey(mat)) { map[mat].Add(i); @@ -340,7 +328,7 @@ public static (int, List)[] GroupSubmeshesByMaterials(this VimMesh mesh) } public static Triangle VertexIndicesToTriangle(this VimMesh mesh, Int3 indices) - => new Triangle(mesh.Vertices[indices.X], mesh.Vertices[indices.Y], mesh.Vertices[indices.Z]); + => new Triangle(mesh.vertices[indices.X], mesh.vertices[indices.Y], mesh.vertices[indices.Z]); public static bool Planar(this VimMesh mesh, float tolerance = Math3d.Constants.Tolerance) { @@ -351,48 +339,48 @@ public static bool Planar(this VimMesh mesh, float tolerance = Math3d.Constants. public static VimMesh Unindex(this VimMesh mesh) { - var vertices = mesh.Indices.Select(i => mesh.Vertices[i]); + var vertices = mesh.indices.Select(i => mesh.vertices[i]); return new VimMesh(vertices.ToArray()); } - public static IArray ComputedNormals(this VimMesh mesh) - => mesh.Triangles().Select(t => t.Normal); + public static Vector3[] ComputedNormals(this VimMesh mesh) + => mesh.Triangles().Select(t => t.Normal).ToArray(); public static Triangle Triangle(this VimMesh mesh, int face) => mesh.VertexIndicesToTriangle(mesh.FaceVertexIndices(face)); - public static IArray Triangles(this VimMesh mesh) - => mesh.NumFaces.Select(mesh.Triangle); + public static Triangle[] Triangles(this VimMesh mesh) + => Enumerable.Range(0, mesh.NumFaces).Select(mesh.Triangle).ToArray(); public static Vector3 Center(this VimMesh mesh) => mesh.BoundingBox().Center; public static AABox BoundingBox(this VimMesh mesh) - => AABox.Create(mesh.Vertices.ToEnumerable()); + => AABox.Create(mesh.vertices); public static Int3 FaceVertexIndices(this VimMesh mesh, int faceIndex) - => new Int3(mesh.Indices[faceIndex * 3], mesh.Indices[faceIndex * 3 + 1], mesh.Indices[faceIndex * 3 + 2]); + => new Int3(mesh.indices[faceIndex * 3], mesh.indices[faceIndex * 3 + 1], mesh.indices[faceIndex * 3 + 2]); public static bool GeometryEquals(this VimMesh mesh, VimMesh other, float tolerance = Math3d.Constants.Tolerance) { - if (!mesh.Indices.SequenceEquals(other.Indices)) + if (!mesh.indices.SequenceEqual(other.indices)) return false; - if (!mesh.SubmeshIndexOffsets.SequenceEquals(other.SubmeshIndexOffsets)) + if (!mesh.submeshIndexOffsets.SequenceEqual(other.submeshIndexOffsets)) return false; - if (!mesh.SubmeshMaterials.SequenceEquals(other.SubmeshMaterials)) + if (!mesh.submeshMaterials.SequenceEqual(other.submeshMaterials)) return false; - if (!mesh.SubmeshIndexCounts.SequenceEquals(other.SubmeshIndexCounts)) + if (!mesh.submeshIndexCounts.SequenceEqual(other.submeshIndexCounts)) return false; - if (mesh.Vertices.Count != other.Vertices.Count) + if (mesh.vertices.Length != other.vertices.Length) return false; - for (var i = 0; i < mesh.Vertices.Count; i++) + for (var i = 0; i < mesh.vertices.Length; i++) { - if (!mesh.Vertices[i].AlmostEquals(other.Vertices[i], tolerance)) + if (!mesh.vertices[i].AlmostEquals(other.vertices[i], tolerance)) return false; } @@ -406,7 +394,7 @@ public static (int mat, VimMesh mesh)[] SplitByMaterial(this VimMesh mesh) var result = new (int, VimMesh)[map.Length]; if (map.Length == 1) { - result[0] = (mesh.SubmeshMaterials[0], mesh); + result[0] = (mesh.submeshMaterials[0], mesh); return result; } @@ -424,7 +412,7 @@ public static VimMesh PickSubmeshes(this VimMesh mesh, IList submeshes) var map = mesh.GroupSubmeshesByMaterials(); // Allocate arrays of the final sizes - var indexCount = submeshes.Sum(s => mesh.SubmeshIndexCounts[s]); + var indexCount = submeshes.Sum(s => mesh.submeshIndexCounts[s]); var result = new VimMesh(indexCount, indexCount, submeshes.Count); var indexOffset = 0; @@ -434,18 +422,18 @@ public static VimMesh PickSubmeshes(this VimMesh mesh, IList submeshes) var submesh = submeshes[s]; // copy indices at their new positions - var indexStart = mesh.SubmeshIndexOffsets[submesh]; - var indexEnd = indexStart + mesh.SubmeshIndexCounts[submesh]; + var indexStart = mesh.submeshIndexOffsets[submesh]; + var indexEnd = indexStart + mesh.submeshIndexCounts[submesh]; for (var i = indexStart; i < indexEnd; i++) { result.indices[index] = indexOffset + i - indexStart; - result.vertices[index] = mesh.Vertices[mesh.Indices[i]]; + result.vertices[index] = mesh.vertices[mesh.indices[i]]; index++; } // submesh data is mostly the same - result.submeshIndexCounts[s] = mesh.SubmeshIndexCounts[submesh]; - result.submeshMaterials[s] = mesh.SubmeshMaterials[submesh]; + result.submeshIndexCounts[s] = mesh.submeshIndexCounts[submesh]; + result.submeshMaterials[s] = mesh.submeshMaterials[submesh]; result.submeshIndexOffsets[s] = indexOffset; // Update offset for next submesh diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 26a82403..7dc3c74a 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -72,42 +72,42 @@ public static void BasicTests() Assert.AreEqual(3, XYTriangle.NumCornersPerFace); Assert.AreEqual(1, XYTriangle.NumFaces); - Assert.AreEqual(3, XYTriangle.Vertices.Count); - Assert.AreEqual(3, XYTriangle.Indices.Count); + Assert.AreEqual(3, XYTriangle.vertices.Length); + Assert.AreEqual(3, XYTriangle.indices.Length); Assert.AreEqual(1, XYTriangle.Triangles().Count); Assert.IsTrue(XYTriangle.Planar()); - Assert.AreEqual(new[] { 0, 1, 2 }, XYTriangle.Indices.ToArray()); + Assert.AreEqual(new[] { 0, 1, 2 }, XYTriangle.indices.Length); Assert.AreEqual(3, XYQuad.NumCornersPerFace); Assert.AreEqual(2, XYQuad.NumFaces); - Assert.AreEqual(4, XYQuad.Vertices.Count); - Assert.AreEqual(6, XYQuad.Indices.Count); + Assert.AreEqual(4, XYQuad.vertices.Length); + Assert.AreEqual(6, XYQuad.indices.Length); Assert.IsTrue(XYQuad.Planar()); - Assert.AreEqual(new[] { 0, 1, 2, 0, 2, 3 }, XYQuad.Indices.ToArray()); + Assert.AreEqual(new[] { 0, 1, 2, 0, 2, 3 }, XYQuad.indices.ToArray()); Assert.AreEqual(3, XYQuadFromFunc.NumCornersPerFace); Assert.AreEqual(2, XYQuadFromFunc.NumFaces); - Assert.AreEqual(4, XYQuadFromFunc.Vertices.Count); - Assert.AreEqual(6, XYQuadFromFunc.Indices.Count); + Assert.AreEqual(4, XYQuadFromFunc.vertices.Length); + Assert.AreEqual(6, XYQuadFromFunc.indices.Length); Assert.AreEqual(3, XYQuad2x2.NumCornersPerFace); Assert.AreEqual(8, XYQuad2x2.NumFaces); - Assert.AreEqual(9, XYQuad2x2.Vertices.Count); - Assert.AreEqual(24, XYQuad2x2.Indices.Count); + Assert.AreEqual(9, XYQuad2x2.vertices.Length); + Assert.AreEqual(24, XYQuad2x2.indices.Length); Assert.AreEqual(3, Tetrahedron.NumCornersPerFace); Assert.AreEqual(4, Tetrahedron.NumFaces); - Assert.AreEqual(4, Tetrahedron.Vertices.Count); - Assert.AreEqual(12, Tetrahedron.Indices.Count); + Assert.AreEqual(4, Tetrahedron.vertices.Length); + Assert.AreEqual(12, Tetrahedron.indices.Length); Assert.AreEqual(3, XYTriangleTwice.NumCornersPerFace); Assert.AreEqual(2, XYTriangleTwice.NumFaces); - Assert.AreEqual(6, XYTriangleTwice.Vertices.Count); - Assert.AreEqual(6, XYTriangleTwice.Indices.Count); + Assert.AreEqual(6, XYTriangleTwice.vertices.Length); + Assert.AreEqual(6, XYTriangleTwice.indices.Length); Assert.AreEqual(2, XYTriangleTwice.Triangles().Count); Assert.IsTrue(XYTriangleTwice.Planar()); - Assert.AreEqual(new[] { 0, 1, 2, 3, 4, 5 }, XYTriangleTwice.Indices.ToArray()); + Assert.AreEqual(new[] { 0, 1, 2, 3, 4, 5 }, XYTriangleTwice.indices); } [Test] @@ -124,16 +124,16 @@ public static void OutputGeometryData() foreach (var g in AllMeshes) { Console.WriteLine($"Geometry {n++}"); - for (var i = 0; i < g.Vertices.Count && i < 10; ++i) + for (var i = 0; i < g.vertices.Length && i < 10; ++i) { - Console.WriteLine($"Vertex {i} {g.Vertices[i]}"); + Console.WriteLine($"Vertex {i} {g.vertices[i]}"); } - if (g.Vertices.Count > 10) + if (g.vertices.Length > 10) { - var last = g.Vertices.Count - 1; + var last = g.vertices.Length - 1; Console.WriteLine("..."); - Console.WriteLine($"Vertex {last} {g.Vertices[last]}"); + Console.WriteLine($"Vertex {last} {g.vertices[last]}"); } for (var i = 0; i < g.NumFaces && i < 10; ++i) @@ -141,7 +141,7 @@ public static void OutputGeometryData() Console.WriteLine($"Face {i}: {g.Triangle(i)}"); } - if (g.Vertices.Count > 10) + if (g.vertices.Length > 10) { var last = g.NumFaces - 1; Console.WriteLine("..."); @@ -154,22 +154,22 @@ public static void OutputGeometryData() public static void StripIndicesTests() { var emptyStrip00 = Primitives.QuadMeshStripIndicesFromPointRows(0, 0); - Assert.AreEqual(0, emptyStrip00.Count); + Assert.AreEqual(0, emptyStrip00.Length); var emptyStrip01 = Primitives.QuadMeshStripIndicesFromPointRows(0, 1); - Assert.AreEqual(0, emptyStrip01.Count); + Assert.AreEqual(0, emptyStrip01.Length); var emptyStrip10 = Primitives.QuadMeshStripIndicesFromPointRows(1, 0); - Assert.AreEqual(0, emptyStrip10.Count); + Assert.AreEqual(0, emptyStrip10.Length); var emptyStrip11 = Primitives.QuadMeshStripIndicesFromPointRows(1, 1); - Assert.AreEqual(0, emptyStrip11.Count); + Assert.AreEqual(0, emptyStrip11.Length); var emptyStrip12 = Primitives.QuadMeshStripIndicesFromPointRows(1, 2); - Assert.AreEqual(0, emptyStrip12.Count); + Assert.AreEqual(0, emptyStrip12.Length); var emptyStrip21 = Primitives.QuadMeshStripIndicesFromPointRows(2, 1); - Assert.AreEqual(0, emptyStrip21.Count); + Assert.AreEqual(0, emptyStrip21.Length); // COUNTER-CLOCKWISE TEST (DEFAULT) // 2------3 <--- row 1: [2,3] @@ -177,7 +177,7 @@ public static void StripIndicesTests() // | | // 0------1 <--- row 0: [0,1] var strip22 = Primitives.QuadMeshStripIndicesFromPointRows(2, 2); - Assert.AreEqual(4, strip22.Count); + Assert.AreEqual(4, strip22.Length); Assert.AreEqual(0, strip22[0]); Assert.AreEqual(1, strip22[1]); Assert.AreEqual(3, strip22[2]); @@ -189,13 +189,13 @@ public static void StripIndicesTests() // | | // 0------1 <--- row 0: [0,1] var clockwiseStrip22 = Primitives.QuadMeshStripIndicesFromPointRows(2, 2, true); - Assert.AreEqual(4, clockwiseStrip22.Count); + Assert.AreEqual(4, clockwiseStrip22.Length); Assert.AreEqual(2, clockwiseStrip22[0]); Assert.AreEqual(3, clockwiseStrip22[1]); Assert.AreEqual(1, clockwiseStrip22[2]); Assert.AreEqual(0, clockwiseStrip22[3]); - var reversed22 = clockwiseStrip22.Reverse(); - for (var i = 0; i < strip22.Count; ++i) + var reversed22 = clockwiseStrip22.Reverse().ToArray(); + for (var i = 0; i < strip22.Length; ++i) { Assert.AreEqual(strip22[i], reversed22[i]); } @@ -205,7 +205,7 @@ public static void StripIndicesTests() // | | | // *------*------* var strip23 = Primitives.QuadMeshStripIndicesFromPointRows(2, 3); - Assert.AreEqual(4 * 2, strip23.Count); + Assert.AreEqual(4 * 2, strip23.Length); // *------*------*------* // | | | | @@ -215,7 +215,7 @@ public static void StripIndicesTests() // | | | | // *------*------*------* var strip34 = Primitives.QuadMeshStripIndicesFromPointRows(3, 4); - Assert.AreEqual(4 * 6, strip34.Count); + Assert.AreEqual(4 * 6, strip34.Length); } [Test] @@ -238,12 +238,12 @@ public static void TriangleSerializationTest() result.Validate(); Assert.AreEqual(3, result.NumVertices); - Assert.AreEqual(new Vector3(0, 0, 0), result.Vertices[0]); - Assert.AreEqual(new Vector3(0, 1, 0), result.Vertices[1]); - Assert.AreEqual(new Vector3(0, 1, 1), result.Vertices[2]); + Assert.AreEqual(new Vector3(0, 0, 0), result.vertices[0]); + Assert.AreEqual(new Vector3(0, 1, 0), result.vertices[1]); + Assert.AreEqual(new Vector3(0, 1, 1), result.vertices[2]); Assert.AreEqual(1, result.NumFaces); - Assert.AreEqual(0, result.SubmeshIndexOffsets.ToEnumerable().Single()); - Assert.AreEqual(-1, result.SubmeshMaterials.ToEnumerable().Single()); + Assert.AreEqual(0, result.submeshIndexOffsets.Single()); + Assert.AreEqual(-1, result.submeshMaterials.Single()); Assert.AreEqual(-1, result.GetFaceMaterials().First()); } } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 6c0ecc96..005ea2d6 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -84,7 +84,7 @@ public VimMesh MergedGeometry() => Nodes.MergedGeometry(); public IEnumerable AllVertices() - => TransformedMeshes().SelectMany(g => g.Vertices.ToEnumerable()); + => TransformedMeshes().SelectMany(g => g.vertices); public AABox BoundingBox() => AABox.Create(AllVertices()); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 28e34077..76c0e3f4 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -54,11 +54,11 @@ VimSceneNode ITransformable3D.Transform(Matrix4x4 mat) public VimMesh TransformedMesh() => GetMesh()?.Transform(Transform); - public IArray TransformedVertices() - => TransformedMesh()?.Vertices; + public Vector3[] TransformedVertices() + => TransformedMesh()?.vertices; public AABox TransformedBoundingBox() - => AABox.Create(TransformedVertices()?.ToEnumerable()); + => AABox.Create(TransformedVertices()); } public static class NodeExtensions From 033a466cf61ce6c1a555eed15cfcf531baaa19b8 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 08:24:55 -0400 Subject: [PATCH 067/104] iarray -> array --- src/cs/util/Vim.Util/LinqExtensions.cs | 2 +- .../ObjectModelGenerator.cs | 17 +- .../ColumnExtensions.Buffer.cs | 4 +- src/cs/vim/Vim.Format.Core/Document.cs | 5 +- .../vim/Vim.Format.Core/DocumentExtensions.cs | 4 +- src/cs/vim/Vim.Format.Core/EntityTable.cs | 21 +- .../vim/Vim.Format.Core/Geometry/ArrayOps.cs | 1 - .../Geometry/GeometryTests.cs | 4 +- .../ObjectModel/ObjectModelExtensions.cs | 12 +- .../ObjectModel/ObjectModelGenerated.cs | 1625 +++++++++-------- .../vim/Vim.Format/ObjectModel/Validation.cs | 17 +- .../SceneBuilder/VimSceneHelpers.cs | 2 +- 12 files changed, 859 insertions(+), 855 deletions(-) diff --git a/src/cs/util/Vim.Util/LinqExtensions.cs b/src/cs/util/Vim.Util/LinqExtensions.cs index ae41cd0e..56800bb0 100644 --- a/src/cs/util/Vim.Util/LinqExtensions.cs +++ b/src/cs/util/Vim.Util/LinqExtensions.cs @@ -33,7 +33,7 @@ public static T OneOrDefault(this IEnumerable values) public static IEnumerable Append(this IEnumerable xs, params T[] x) => xs.Concat(x); - public static T ElementAtOrDefault(this IReadOnlyList items, int index, T @default) + public static T ElementAtOrDefault(this IReadOnlyList items, int index, T @default = default(T)) => index < 0 || index >= items.Count ? @default : items[index]; /// diff --git a/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs b/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs index d386e613..49ce077a 100644 --- a/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs +++ b/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs @@ -71,7 +71,7 @@ private static CodeBuilder WriteDocumentEntityData(Type t, CodeBuilder cb, Entit var dataColumnGetter = $"{t.Name}EntityTable?.{functionName}(\"{eci.SerializedValueColumnName}\")"; if (eci.EntityColumnAttribute.SerializedType != fieldType) { - dataColumnGetter += $"?.Select(v => ({fieldTypeName}) v)"; + dataColumnGetter += $"?.Select(v => ({fieldTypeName}) v).ToArray()"; } return dataColumnGetter; }).ToArray(); @@ -80,9 +80,9 @@ private static CodeBuilder WriteDocumentEntityData(Type t, CodeBuilder cb, Entit ? $"({string.Join(" ?? ", dataColumnGetters)})" : dataColumnGetters[0]; - cb.AppendLine($"public IArray<{fieldTypeName}> {t.Name}{fieldName} {{ get; }}"); + cb.AppendLine($"public {fieldTypeName}[] {t.Name}{fieldName} {{ get; }}"); constructor.ArraysInitializers - .Add($"{t.Name}{fieldName} = {dataColumnGetterString} ?? Array.Empty<{fieldTypeName}>().ToIArray();"); + .Add($"{t.Name}{fieldName} = {dataColumnGetterString} ?? Array.Empty<{fieldTypeName}>();"); // Safe accessor. var defaultValue = baseStrategy == ValueSerializationStrategy.SerializeAsStringColumn ? "\"\"" : "default"; @@ -94,9 +94,9 @@ private static CodeBuilder WriteDocumentEntityData(Type t, CodeBuilder cb, Entit { var (indexColumnName, localFieldName) = fieldInfo.GetIndexColumnInfo(); - cb.AppendLine($"public IArray {t.Name}{localFieldName}Index {{ get; }}"); + cb.AppendLine($"public int[] {t.Name}{localFieldName}Index {{ get; }}"); constructor.RelationalColumns - .Add($"{t.Name}{localFieldName}Index = {t.Name}EntityTable?.GetIndexColumnValues(\"{indexColumnName}\") ?? Array.Empty().ToIArray();"); + .Add($"{t.Name}{localFieldName}Index = {t.Name}EntityTable?.GetIndexColumnValues(\"{indexColumnName}\") ?? Array.Empty();"); cb.AppendLine($"public int Get{t.Name}{localFieldName}Index(int index) => {t.Name}{localFieldName}Index?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None;"); } @@ -105,7 +105,7 @@ private static CodeBuilder WriteDocumentEntityData(Type t, CodeBuilder cb, Entit cb.AppendLine($"public int Num{t.Name} => {t.Name}EntityTable?.NumRows ?? 0;"); // Entity lists - cb.AppendLine($"public IArray<{t.Name}> {t.Name}List {{ get; }}"); + cb.AppendLine($"public {t.Name}[] {t.Name}List {{ get; }}"); // Element getter function cb.AppendLine($"public {t.Name} Get{t.Name}(int n)"); @@ -231,7 +231,7 @@ private static CodeBuilder WriteDocument(CodeBuilder cb = null) cb.AppendLine("// All entity collections"); cb.AppendLine("public Dictionary> AllEntities => new Dictionary>() {"); foreach (var t in entityTypes) - cb.AppendLine($"{{\"{t.GetEntityTableName()}\", {t.Name}List.ToEnumerable()}},"); + cb.AppendLine($"{{\"{t.GetEntityTableName()}\", {t.Name}List}},"); cb.AppendLine("};"); cb.AppendLine(); @@ -265,7 +265,7 @@ private static CodeBuilder WriteDocument(CodeBuilder cb = null) cb.AppendLine("// Initialize entity collections"); foreach (var t in entityTypes) - cb.AppendLine($"{t.Name}List = Num{t.Name}.Select(i => Get{t.Name}(i));"); + cb.AppendLine($"{t.Name}List = Enumerable.Range(0, Num{t.Name}).Select(i => Get{t.Name}(i)).ToArray();"); cb.AppendLine(); cb.AppendLine("// Initialize element index maps"); @@ -352,6 +352,7 @@ public static void WriteDocument(string file) cb.AppendLine("using Vim.Math3d;"); cb.AppendLine("using Vim.LinqArray;"); cb.AppendLine("using Vim.Format.ObjectModel;"); + cb.AppendLine("using Vim.Util;"); cb.AppendLine(); diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs index 0b213bd8..69133ef5 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs @@ -196,8 +196,8 @@ public static SerializableEntityTable Concat(this SerializableEntityTable thisTa DataColumns = thisTable.DataColumns.ConcatDataColumns(otherTable.DataColumns), }.ValidateColumnRowsAreAligned(); - public static IArray GetColumnValues(this INamedBuffer nb) where T : unmanaged - => nb.AsArray().ToIArray(); + public static T[] GetColumnValues(this INamedBuffer nb) where T : unmanaged + => nb.AsArray(); /// /// Returns a new collection of index columns in which the designated column names have repeated values of VimConstants.NoEntityRelation. diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index 27a4d978..9a529d6e 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -1,6 +1,7 @@ using Vim.LinqArray; using Vim.BFastLib; using Vim.G3dNext; +using Vim.Util; namespace Vim.Format { @@ -12,7 +13,7 @@ public Document(SerializableDocument document) _Document = document; Header = _Document.Header; GeometryNext = _Document.GeometryNext; - StringTable = _Document.StringTable.ToIArray(); + StringTable = _Document.StringTable; EntityTables = _Document.EntityTables.ToLookup( et => et.Name, et => et.ToEntityTable(this)); @@ -24,7 +25,7 @@ public Document(SerializableDocument document) public SerializableHeader Header { get; } public ILookup EntityTables { get; } public ILookup Assets { get; } - public IArray StringTable { get; } + public string[] StringTable { get; } public string GetString(int index) => StringTable.ElementAtOrDefault(index); public G3dVim GeometryNext { get; } } diff --git a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs index 9d7a9cfd..3ab52296 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs @@ -13,8 +13,8 @@ public static Document ToDocument(this SerializableDocument document) public static EntityTable ToEntityTable(this SerializableEntityTable entityTable, Document document) => new EntityTable(document, entityTable); - public static IArray GetColumnNames(this EntityTable table) - => table.Columns.Select(b => b.Name); + public static string[] GetColumnNames(this EntityTable table) + => table.Columns.Select(b => b.Name).ToArray(); public static void ValidateRelations(this Document doc) { diff --git a/src/cs/vim/Vim.Format.Core/EntityTable.cs b/src/cs/vim/Vim.Format.Core/EntityTable.cs index d35097cc..51551e09 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTable.cs @@ -1,6 +1,7 @@ using System; using Vim.LinqArray; using Vim.BFastLib; +using System.Linq; namespace Vim.Format { @@ -17,7 +18,7 @@ public EntityTable(Document document, SerializableEntityTable entityTable) StringColumns = LinqArray.LinqArray.ToLookup(_EntityTable.StringColumns, c => c.Name, c => c); NumRows = Columns.FirstOrDefault()?.NumElements() ?? 0; - Columns.ToEnumerable().ValidateColumnRowsAreAligned(); + Columns.ValidateColumnRowsAreAligned(); } private SerializableEntityTable _EntityTable { get; } @@ -27,20 +28,21 @@ public EntityTable(Document document, SerializableEntityTable entityTable) public LinqArray.ILookup DataColumns { get; } public LinqArray.ILookup> StringColumns { get; } public LinqArray.ILookup> IndexColumns { get; } - public IArray Columns + public INamedBuffer[] Columns => DataColumns.Values .Concatenate(IndexColumns.Values.Select(x => (INamedBuffer)x)) - .Concatenate(StringColumns.Values.Select(x => (INamedBuffer)x)); + .Concatenate(StringColumns.Values.Select(x => (INamedBuffer)x)) + .ToArray(); - public IArray GetIndexColumnValues(string columnName) + public int[] GetIndexColumnValues(string columnName) => IndexColumns.GetOrDefault(columnName)?.GetColumnValues(); - public IArray GetStringColumnValues(string columnName) + public string[] GetStringColumnValues(string columnName) => StringColumns.GetOrDefault(columnName) ?.GetColumnValues() - ?.Select(Document.GetString); + ?.Select(Document.GetString).ToArray(); - public IArray GetDataColumnValues(string columnName) where T : unmanaged + public T[] GetDataColumnValues(string columnName) where T : unmanaged { var type = typeof(T); @@ -52,11 +54,10 @@ public IArray GetDataColumnValues(string columnName) where T : unmanaged return null; if (type == typeof(short)) - return namedBuffer.GetColumnValues().Select(i => (short)i) as IArray; + return namedBuffer.GetColumnValues().Select(i => (short)i) as T[]; if (type == typeof(bool)) - return namedBuffer.GetColumnValues().Select(b => b != 0) as IArray; - + return namedBuffer.GetColumnValues().Select(b => b != 0) as T[]; return namedBuffer.GetColumnValues(); } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs b/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs index 55bbcedb..d77a7f5a 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs @@ -10,7 +10,6 @@ namespace Vim.Format.Geometry { public static class ArrayOps { - public static IArray< int > Add(this IArray< int > self, IArray< int > other) => self.Zip(other, MathOps.Add); public static IArray< int > Add(this IArray< int > self, int scalar) => self.Select(x => MathOps.Add(x, scalar)); public static IArray< int > Add(this int self, IArray< int > vector) => vector.Select(x => MathOps.Add(self, x)); diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 7dc3c74a..3850be40 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -74,7 +74,7 @@ public static void BasicTests() Assert.AreEqual(1, XYTriangle.NumFaces); Assert.AreEqual(3, XYTriangle.vertices.Length); Assert.AreEqual(3, XYTriangle.indices.Length); - Assert.AreEqual(1, XYTriangle.Triangles().Count); + Assert.AreEqual(1, XYTriangle.Triangles().Length); Assert.IsTrue(XYTriangle.Planar()); Assert.AreEqual(new[] { 0, 1, 2 }, XYTriangle.indices.Length); @@ -105,7 +105,7 @@ public static void BasicTests() Assert.AreEqual(2, XYTriangleTwice.NumFaces); Assert.AreEqual(6, XYTriangleTwice.vertices.Length); Assert.AreEqual(6, XYTriangleTwice.indices.Length); - Assert.AreEqual(2, XYTriangleTwice.Triangles().Count); + Assert.AreEqual(2, XYTriangleTwice.Triangles().Length); Assert.IsTrue(XYTriangleTwice.Planar()); Assert.AreEqual(new[] { 0, 1, 2, 3, 4, 5 }, XYTriangleTwice.indices); } diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs index c66023cf..6174db7f 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs @@ -40,22 +40,22 @@ public static DictionaryOfLists GetAssetsInViewOrderedByViewIn public static string GetBimDocumentFileName(this DocumentModel dm, int bimDocumentIndex) => Path.GetFileName(dm.GetBimDocumentPathName(bimDocumentIndex)); - public static IArray GetBimDocumentDisplayUnits(this DocumentModel dm, BimDocument bd) + public static DisplayUnit[] GetBimDocumentDisplayUnits(this DocumentModel dm, BimDocument bd) => dm.DisplayUnitInBimDocumentList .Where(item => item.BimDocument.Index == bd.Index) .Select(item => item.DisplayUnit) - .ToIArray(); + .ToArray(); - public static IArray GetBimDocumentPhases(this DocumentModel dm, BimDocument bd) + public static Phase[] GetBimDocumentPhases(this DocumentModel dm, BimDocument bd) => dm.PhaseOrderInBimDocumentList .Where(item => item.BimDocument.Index == bd.Index) .Select(item => item.Phase) - .ToIArray(); + .ToArray(); public const string LengthSpecLegacyPrefix = "UT_Length"; public const string LengthSpecPrefix = "autodesk.spec.aec:length"; - public static DisplayUnit GetLengthDisplayUnit(this IArray displayUnits) + public static DisplayUnit GetLengthDisplayUnit(this DisplayUnit[] displayUnits) => displayUnits.FirstOrDefault(du => { var spec = du.Spec; @@ -153,7 +153,7 @@ public static DataTable GetScheduleAsDataTable(this DocumentModel dm, int schedu var columnSet = new HashSet(columns.Select(c => c.Index)); - var cellRecords = dm.ScheduleCellScheduleColumnIndex + var cellRecords = dm.ScheduleCellScheduleColumnIndex.ToIArray() .IndicesWhere((colIndex, _) => columnSet.Contains(colIndex)) .Select(cellIndex => new CellData( dm.GetScheduleCellValue(cellIndex), diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs index 1a176ad1..6a5a980d 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs @@ -6,6 +6,7 @@ using Vim.Math3d; using Vim.LinqArray; using Vim.Format.ObjectModel; +using Vim.Util; namespace Vim.Format.ObjectModel { // AUTO-GENERATED @@ -1888,10 +1889,10 @@ public partial class DocumentModel public EntityTable AssetEntityTable { get; } - public IArray AssetBufferName { get; } + public String[] AssetBufferName { get; } public String GetAssetBufferName(int index, String defaultValue = "") => AssetBufferName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; public int NumAsset => AssetEntityTable?.NumRows ?? 0; - public IArray AssetList { get; } + public Asset[] AssetList { get; } public Asset GetAsset(int n) { if (n < 0) return null; @@ -1907,14 +1908,14 @@ public Asset GetAsset(int n) public EntityTable DisplayUnitEntityTable { get; } - public IArray DisplayUnitSpec { get; } + public String[] DisplayUnitSpec { get; } public String GetDisplayUnitSpec(int index, String defaultValue = "") => DisplayUnitSpec?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray DisplayUnitType { get; } + public String[] DisplayUnitType { get; } public String GetDisplayUnitType(int index, String defaultValue = "") => DisplayUnitType?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray DisplayUnitLabel { get; } + public String[] DisplayUnitLabel { get; } public String GetDisplayUnitLabel(int index, String defaultValue = "") => DisplayUnitLabel?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; public int NumDisplayUnit => DisplayUnitEntityTable?.NumRows ?? 0; - public IArray DisplayUnitList { get; } + public DisplayUnit[] DisplayUnitList { get; } public DisplayUnit GetDisplayUnit(int n) { if (n < 0) return null; @@ -1932,26 +1933,26 @@ public DisplayUnit GetDisplayUnit(int n) public EntityTable ParameterDescriptorEntityTable { get; } - public IArray ParameterDescriptorName { get; } + public String[] ParameterDescriptorName { get; } public String GetParameterDescriptorName(int index, String defaultValue = "") => ParameterDescriptorName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ParameterDescriptorGroup { get; } + public String[] ParameterDescriptorGroup { get; } public String GetParameterDescriptorGroup(int index, String defaultValue = "") => ParameterDescriptorGroup?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ParameterDescriptorParameterType { get; } + public String[] ParameterDescriptorParameterType { get; } public String GetParameterDescriptorParameterType(int index, String defaultValue = "") => ParameterDescriptorParameterType?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ParameterDescriptorIsInstance { get; } + public Boolean[] ParameterDescriptorIsInstance { get; } public Boolean GetParameterDescriptorIsInstance(int index, Boolean defaultValue = default) => ParameterDescriptorIsInstance?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ParameterDescriptorIsShared { get; } + public Boolean[] ParameterDescriptorIsShared { get; } public Boolean GetParameterDescriptorIsShared(int index, Boolean defaultValue = default) => ParameterDescriptorIsShared?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ParameterDescriptorIsReadOnly { get; } + public Boolean[] ParameterDescriptorIsReadOnly { get; } public Boolean GetParameterDescriptorIsReadOnly(int index, Boolean defaultValue = default) => ParameterDescriptorIsReadOnly?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ParameterDescriptorFlags { get; } + public Int32[] ParameterDescriptorFlags { get; } public Int32 GetParameterDescriptorFlags(int index, Int32 defaultValue = default) => ParameterDescriptorFlags?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ParameterDescriptorGuid { get; } + public String[] ParameterDescriptorGuid { get; } public String GetParameterDescriptorGuid(int index, String defaultValue = "") => ParameterDescriptorGuid?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ParameterDescriptorDisplayUnitIndex { get; } + public int[] ParameterDescriptorDisplayUnitIndex { get; } public int GetParameterDescriptorDisplayUnitIndex(int index) => ParameterDescriptorDisplayUnitIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumParameterDescriptor => ParameterDescriptorEntityTable?.NumRows ?? 0; - public IArray ParameterDescriptorList { get; } + public ParameterDescriptor[] ParameterDescriptorList { get; } public ParameterDescriptor GetParameterDescriptor(int n) { if (n < 0) return null; @@ -1975,14 +1976,14 @@ public ParameterDescriptor GetParameterDescriptor(int n) public EntityTable ParameterEntityTable { get; } - public IArray ParameterValue { get; } + public String[] ParameterValue { get; } public String GetParameterValue(int index, String defaultValue = "") => ParameterValue?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ParameterParameterDescriptorIndex { get; } + public int[] ParameterParameterDescriptorIndex { get; } public int GetParameterParameterDescriptorIndex(int index) => ParameterParameterDescriptorIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ParameterElementIndex { get; } + public int[] ParameterElementIndex { get; } public int GetParameterElementIndex(int index) => ParameterElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumParameter => ParameterEntityTable?.NumRows ?? 0; - public IArray ParameterList { get; } + public Parameter[] ParameterList { get; } public Parameter GetParameter(int n) { if (n < 0) return null; @@ -2000,48 +2001,48 @@ public Parameter GetParameter(int n) public EntityTable ElementEntityTable { get; } - public IArray ElementId { get; } + public Int64[] ElementId { get; } public Int64 GetElementId(int index, Int64 defaultValue = default) => ElementId?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementType { get; } + public String[] ElementType { get; } public String GetElementType(int index, String defaultValue = "") => ElementType?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementName { get; } + public String[] ElementName { get; } public String GetElementName(int index, String defaultValue = "") => ElementName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementUniqueId { get; } + public String[] ElementUniqueId { get; } public String GetElementUniqueId(int index, String defaultValue = "") => ElementUniqueId?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementLocation_X { get; } + public Single[] ElementLocation_X { get; } public Single GetElementLocation_X(int index, Single defaultValue = default) => ElementLocation_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementLocation_Y { get; } + public Single[] ElementLocation_Y { get; } public Single GetElementLocation_Y(int index, Single defaultValue = default) => ElementLocation_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementLocation_Z { get; } + public Single[] ElementLocation_Z { get; } public Single GetElementLocation_Z(int index, Single defaultValue = default) => ElementLocation_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementFamilyName { get; } + public String[] ElementFamilyName { get; } public String GetElementFamilyName(int index, String defaultValue = "") => ElementFamilyName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementIsPinned { get; } + public Boolean[] ElementIsPinned { get; } public Boolean GetElementIsPinned(int index, Boolean defaultValue = default) => ElementIsPinned?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementLevelIndex { get; } + public int[] ElementLevelIndex { get; } public int GetElementLevelIndex(int index) => ElementLevelIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementPhaseCreatedIndex { get; } + public int[] ElementPhaseCreatedIndex { get; } public int GetElementPhaseCreatedIndex(int index) => ElementPhaseCreatedIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementPhaseDemolishedIndex { get; } + public int[] ElementPhaseDemolishedIndex { get; } public int GetElementPhaseDemolishedIndex(int index) => ElementPhaseDemolishedIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementCategoryIndex { get; } + public int[] ElementCategoryIndex { get; } public int GetElementCategoryIndex(int index) => ElementCategoryIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementWorksetIndex { get; } + public int[] ElementWorksetIndex { get; } public int GetElementWorksetIndex(int index) => ElementWorksetIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementDesignOptionIndex { get; } + public int[] ElementDesignOptionIndex { get; } public int GetElementDesignOptionIndex(int index) => ElementDesignOptionIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementOwnerViewIndex { get; } + public int[] ElementOwnerViewIndex { get; } public int GetElementOwnerViewIndex(int index) => ElementOwnerViewIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementGroupIndex { get; } + public int[] ElementGroupIndex { get; } public int GetElementGroupIndex(int index) => ElementGroupIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementAssemblyInstanceIndex { get; } + public int[] ElementAssemblyInstanceIndex { get; } public int GetElementAssemblyInstanceIndex(int index) => ElementAssemblyInstanceIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementBimDocumentIndex { get; } + public int[] ElementBimDocumentIndex { get; } public int GetElementBimDocumentIndex(int index) => ElementBimDocumentIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementRoomIndex { get; } + public int[] ElementRoomIndex { get; } public int GetElementRoomIndex(int index) => ElementRoomIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumElement => ElementEntityTable?.NumRows ?? 0; - public IArray ElementList { get; } + public Element[] ElementList { get; } public Element GetElement(int n) { if (n < 0) return null; @@ -2076,24 +2077,24 @@ public Element GetElement(int n) public EntityTable WorksetEntityTable { get; } - public IArray WorksetId { get; } + public Int32[] WorksetId { get; } public Int32 GetWorksetId(int index, Int32 defaultValue = default) => WorksetId?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WorksetName { get; } + public String[] WorksetName { get; } public String GetWorksetName(int index, String defaultValue = "") => WorksetName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WorksetKind { get; } + public String[] WorksetKind { get; } public String GetWorksetKind(int index, String defaultValue = "") => WorksetKind?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WorksetIsOpen { get; } + public Boolean[] WorksetIsOpen { get; } public Boolean GetWorksetIsOpen(int index, Boolean defaultValue = default) => WorksetIsOpen?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WorksetIsEditable { get; } + public Boolean[] WorksetIsEditable { get; } public Boolean GetWorksetIsEditable(int index, Boolean defaultValue = default) => WorksetIsEditable?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WorksetOwner { get; } + public String[] WorksetOwner { get; } public String GetWorksetOwner(int index, String defaultValue = "") => WorksetOwner?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WorksetUniqueId { get; } + public String[] WorksetUniqueId { get; } public String GetWorksetUniqueId(int index, String defaultValue = "") => WorksetUniqueId?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WorksetBimDocumentIndex { get; } + public int[] WorksetBimDocumentIndex { get; } public int GetWorksetBimDocumentIndex(int index) => WorksetBimDocumentIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumWorkset => WorksetEntityTable?.NumRows ?? 0; - public IArray WorksetList { get; } + public Workset[] WorksetList { get; } public Workset GetWorkset(int n) { if (n < 0) return null; @@ -2116,18 +2117,18 @@ public Workset GetWorkset(int n) public EntityTable AssemblyInstanceEntityTable { get; } - public IArray AssemblyInstanceAssemblyTypeName { get; } + public String[] AssemblyInstanceAssemblyTypeName { get; } public String GetAssemblyInstanceAssemblyTypeName(int index, String defaultValue = "") => AssemblyInstanceAssemblyTypeName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray AssemblyInstancePosition_X { get; } + public Single[] AssemblyInstancePosition_X { get; } public Single GetAssemblyInstancePosition_X(int index, Single defaultValue = default) => AssemblyInstancePosition_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray AssemblyInstancePosition_Y { get; } + public Single[] AssemblyInstancePosition_Y { get; } public Single GetAssemblyInstancePosition_Y(int index, Single defaultValue = default) => AssemblyInstancePosition_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray AssemblyInstancePosition_Z { get; } + public Single[] AssemblyInstancePosition_Z { get; } public Single GetAssemblyInstancePosition_Z(int index, Single defaultValue = default) => AssemblyInstancePosition_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray AssemblyInstanceElementIndex { get; } + public int[] AssemblyInstanceElementIndex { get; } public int GetAssemblyInstanceElementIndex(int index) => AssemblyInstanceElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumAssemblyInstance => AssemblyInstanceEntityTable?.NumRows ?? 0; - public IArray AssemblyInstanceList { get; } + public AssemblyInstance[] AssemblyInstanceList { get; } public AssemblyInstance GetAssemblyInstance(int n) { if (n < 0) return null; @@ -2147,18 +2148,18 @@ public AssemblyInstance GetAssemblyInstance(int n) public EntityTable GroupEntityTable { get; } - public IArray GroupGroupType { get; } + public String[] GroupGroupType { get; } public String GetGroupGroupType(int index, String defaultValue = "") => GroupGroupType?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GroupPosition_X { get; } + public Single[] GroupPosition_X { get; } public Single GetGroupPosition_X(int index, Single defaultValue = default) => GroupPosition_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GroupPosition_Y { get; } + public Single[] GroupPosition_Y { get; } public Single GetGroupPosition_Y(int index, Single defaultValue = default) => GroupPosition_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GroupPosition_Z { get; } + public Single[] GroupPosition_Z { get; } public Single GetGroupPosition_Z(int index, Single defaultValue = default) => GroupPosition_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GroupElementIndex { get; } + public int[] GroupElementIndex { get; } public int GetGroupElementIndex(int index) => GroupElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumGroup => GroupEntityTable?.NumRows ?? 0; - public IArray GroupList { get; } + public Group[] GroupList { get; } public Group GetGroup(int n) { if (n < 0) return null; @@ -2178,12 +2179,12 @@ public Group GetGroup(int n) public EntityTable DesignOptionEntityTable { get; } - public IArray DesignOptionIsPrimary { get; } + public Boolean[] DesignOptionIsPrimary { get; } public Boolean GetDesignOptionIsPrimary(int index, Boolean defaultValue = default) => DesignOptionIsPrimary?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray DesignOptionElementIndex { get; } + public int[] DesignOptionElementIndex { get; } public int GetDesignOptionElementIndex(int index) => DesignOptionElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumDesignOption => DesignOptionEntityTable?.NumRows ?? 0; - public IArray DesignOptionList { get; } + public DesignOption[] DesignOptionList { get; } public DesignOption GetDesignOption(int n) { if (n < 0) return null; @@ -2200,16 +2201,16 @@ public DesignOption GetDesignOption(int n) public EntityTable LevelEntityTable { get; } - public IArray LevelElevation { get; } + public Double[] LevelElevation { get; } public Double GetLevelElevation(int index, Double defaultValue = default) => LevelElevation?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray LevelFamilyTypeIndex { get; } + public int[] LevelFamilyTypeIndex { get; } public int GetLevelFamilyTypeIndex(int index) => LevelFamilyTypeIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray LevelBuildingIndex { get; } + public int[] LevelBuildingIndex { get; } public int GetLevelBuildingIndex(int index) => LevelBuildingIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray LevelElementIndex { get; } + public int[] LevelElementIndex { get; } public int GetLevelElementIndex(int index) => LevelElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumLevel => LevelEntityTable?.NumRows ?? 0; - public IArray LevelList { get; } + public Level[] LevelList { get; } public Level GetLevel(int n) { if (n < 0) return null; @@ -2228,10 +2229,10 @@ public Level GetLevel(int n) public EntityTable PhaseEntityTable { get; } - public IArray PhaseElementIndex { get; } + public int[] PhaseElementIndex { get; } public int GetPhaseElementIndex(int index) => PhaseElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumPhase => PhaseEntityTable?.NumRows ?? 0; - public IArray PhaseList { get; } + public Phase[] PhaseList { get; } public Phase GetPhase(int n) { if (n < 0) return null; @@ -2247,26 +2248,26 @@ public Phase GetPhase(int n) public EntityTable RoomEntityTable { get; } - public IArray RoomBaseOffset { get; } + public Double[] RoomBaseOffset { get; } public Double GetRoomBaseOffset(int index, Double defaultValue = default) => RoomBaseOffset?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray RoomLimitOffset { get; } + public Double[] RoomLimitOffset { get; } public Double GetRoomLimitOffset(int index, Double defaultValue = default) => RoomLimitOffset?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray RoomUnboundedHeight { get; } + public Double[] RoomUnboundedHeight { get; } public Double GetRoomUnboundedHeight(int index, Double defaultValue = default) => RoomUnboundedHeight?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray RoomVolume { get; } + public Double[] RoomVolume { get; } public Double GetRoomVolume(int index, Double defaultValue = default) => RoomVolume?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray RoomPerimeter { get; } + public Double[] RoomPerimeter { get; } public Double GetRoomPerimeter(int index, Double defaultValue = default) => RoomPerimeter?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray RoomArea { get; } + public Double[] RoomArea { get; } public Double GetRoomArea(int index, Double defaultValue = default) => RoomArea?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray RoomNumber { get; } + public String[] RoomNumber { get; } public String GetRoomNumber(int index, String defaultValue = "") => RoomNumber?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray RoomUpperLimitIndex { get; } + public int[] RoomUpperLimitIndex { get; } public int GetRoomUpperLimitIndex(int index) => RoomUpperLimitIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray RoomElementIndex { get; } + public int[] RoomElementIndex { get; } public int GetRoomElementIndex(int index) => RoomElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumRoom => RoomEntityTable?.NumRows ?? 0; - public IArray RoomList { get; } + public Room[] RoomList { get; } public Room GetRoom(int n) { if (n < 0) return null; @@ -2290,72 +2291,72 @@ public Room GetRoom(int n) public EntityTable BimDocumentEntityTable { get; } - public IArray BimDocumentTitle { get; } + public String[] BimDocumentTitle { get; } public String GetBimDocumentTitle(int index, String defaultValue = "") => BimDocumentTitle?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentIsMetric { get; } + public Boolean[] BimDocumentIsMetric { get; } public Boolean GetBimDocumentIsMetric(int index, Boolean defaultValue = default) => BimDocumentIsMetric?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentGuid { get; } + public String[] BimDocumentGuid { get; } public String GetBimDocumentGuid(int index, String defaultValue = "") => BimDocumentGuid?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentNumSaves { get; } + public Int32[] BimDocumentNumSaves { get; } public Int32 GetBimDocumentNumSaves(int index, Int32 defaultValue = default) => BimDocumentNumSaves?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentIsLinked { get; } + public Boolean[] BimDocumentIsLinked { get; } public Boolean GetBimDocumentIsLinked(int index, Boolean defaultValue = default) => BimDocumentIsLinked?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentIsDetached { get; } + public Boolean[] BimDocumentIsDetached { get; } public Boolean GetBimDocumentIsDetached(int index, Boolean defaultValue = default) => BimDocumentIsDetached?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentIsWorkshared { get; } + public Boolean[] BimDocumentIsWorkshared { get; } public Boolean GetBimDocumentIsWorkshared(int index, Boolean defaultValue = default) => BimDocumentIsWorkshared?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentPathName { get; } + public String[] BimDocumentPathName { get; } public String GetBimDocumentPathName(int index, String defaultValue = "") => BimDocumentPathName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentLatitude { get; } + public Double[] BimDocumentLatitude { get; } public Double GetBimDocumentLatitude(int index, Double defaultValue = default) => BimDocumentLatitude?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentLongitude { get; } + public Double[] BimDocumentLongitude { get; } public Double GetBimDocumentLongitude(int index, Double defaultValue = default) => BimDocumentLongitude?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentTimeZone { get; } + public Double[] BimDocumentTimeZone { get; } public Double GetBimDocumentTimeZone(int index, Double defaultValue = default) => BimDocumentTimeZone?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentPlaceName { get; } + public String[] BimDocumentPlaceName { get; } public String GetBimDocumentPlaceName(int index, String defaultValue = "") => BimDocumentPlaceName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentWeatherStationName { get; } + public String[] BimDocumentWeatherStationName { get; } public String GetBimDocumentWeatherStationName(int index, String defaultValue = "") => BimDocumentWeatherStationName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentElevation { get; } + public Double[] BimDocumentElevation { get; } public Double GetBimDocumentElevation(int index, Double defaultValue = default) => BimDocumentElevation?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentProjectLocation { get; } + public String[] BimDocumentProjectLocation { get; } public String GetBimDocumentProjectLocation(int index, String defaultValue = "") => BimDocumentProjectLocation?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentIssueDate { get; } + public String[] BimDocumentIssueDate { get; } public String GetBimDocumentIssueDate(int index, String defaultValue = "") => BimDocumentIssueDate?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentStatus { get; } + public String[] BimDocumentStatus { get; } public String GetBimDocumentStatus(int index, String defaultValue = "") => BimDocumentStatus?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentClientName { get; } + public String[] BimDocumentClientName { get; } public String GetBimDocumentClientName(int index, String defaultValue = "") => BimDocumentClientName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentAddress { get; } + public String[] BimDocumentAddress { get; } public String GetBimDocumentAddress(int index, String defaultValue = "") => BimDocumentAddress?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentName { get; } + public String[] BimDocumentName { get; } public String GetBimDocumentName(int index, String defaultValue = "") => BimDocumentName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentNumber { get; } + public String[] BimDocumentNumber { get; } public String GetBimDocumentNumber(int index, String defaultValue = "") => BimDocumentNumber?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentAuthor { get; } + public String[] BimDocumentAuthor { get; } public String GetBimDocumentAuthor(int index, String defaultValue = "") => BimDocumentAuthor?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentBuildingName { get; } + public String[] BimDocumentBuildingName { get; } public String GetBimDocumentBuildingName(int index, String defaultValue = "") => BimDocumentBuildingName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentOrganizationName { get; } + public String[] BimDocumentOrganizationName { get; } public String GetBimDocumentOrganizationName(int index, String defaultValue = "") => BimDocumentOrganizationName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentOrganizationDescription { get; } + public String[] BimDocumentOrganizationDescription { get; } public String GetBimDocumentOrganizationDescription(int index, String defaultValue = "") => BimDocumentOrganizationDescription?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentProduct { get; } + public String[] BimDocumentProduct { get; } public String GetBimDocumentProduct(int index, String defaultValue = "") => BimDocumentProduct?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentVersion { get; } + public String[] BimDocumentVersion { get; } public String GetBimDocumentVersion(int index, String defaultValue = "") => BimDocumentVersion?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentUser { get; } + public String[] BimDocumentUser { get; } public String GetBimDocumentUser(int index, String defaultValue = "") => BimDocumentUser?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BimDocumentActiveViewIndex { get; } + public int[] BimDocumentActiveViewIndex { get; } public int GetBimDocumentActiveViewIndex(int index) => BimDocumentActiveViewIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray BimDocumentOwnerFamilyIndex { get; } + public int[] BimDocumentOwnerFamilyIndex { get; } public int GetBimDocumentOwnerFamilyIndex(int index) => BimDocumentOwnerFamilyIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray BimDocumentParentIndex { get; } + public int[] BimDocumentParentIndex { get; } public int GetBimDocumentParentIndex(int index) => BimDocumentParentIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray BimDocumentElementIndex { get; } + public int[] BimDocumentElementIndex { get; } public int GetBimDocumentElementIndex(int index) => BimDocumentElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumBimDocument => BimDocumentEntityTable?.NumRows ?? 0; - public IArray BimDocumentList { get; } + public BimDocument[] BimDocumentList { get; } public BimDocument GetBimDocument(int n) { if (n < 0) return null; @@ -2402,12 +2403,12 @@ public BimDocument GetBimDocument(int n) public EntityTable DisplayUnitInBimDocumentEntityTable { get; } - public IArray DisplayUnitInBimDocumentDisplayUnitIndex { get; } + public int[] DisplayUnitInBimDocumentDisplayUnitIndex { get; } public int GetDisplayUnitInBimDocumentDisplayUnitIndex(int index) => DisplayUnitInBimDocumentDisplayUnitIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray DisplayUnitInBimDocumentBimDocumentIndex { get; } + public int[] DisplayUnitInBimDocumentBimDocumentIndex { get; } public int GetDisplayUnitInBimDocumentBimDocumentIndex(int index) => DisplayUnitInBimDocumentBimDocumentIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumDisplayUnitInBimDocument => DisplayUnitInBimDocumentEntityTable?.NumRows ?? 0; - public IArray DisplayUnitInBimDocumentList { get; } + public DisplayUnitInBimDocument[] DisplayUnitInBimDocumentList { get; } public DisplayUnitInBimDocument GetDisplayUnitInBimDocument(int n) { if (n < 0) return null; @@ -2424,14 +2425,14 @@ public DisplayUnitInBimDocument GetDisplayUnitInBimDocument(int n) public EntityTable PhaseOrderInBimDocumentEntityTable { get; } - public IArray PhaseOrderInBimDocumentOrderIndex { get; } + public Int32[] PhaseOrderInBimDocumentOrderIndex { get; } public Int32 GetPhaseOrderInBimDocumentOrderIndex(int index, Int32 defaultValue = default) => PhaseOrderInBimDocumentOrderIndex?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray PhaseOrderInBimDocumentPhaseIndex { get; } + public int[] PhaseOrderInBimDocumentPhaseIndex { get; } public int GetPhaseOrderInBimDocumentPhaseIndex(int index) => PhaseOrderInBimDocumentPhaseIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray PhaseOrderInBimDocumentBimDocumentIndex { get; } + public int[] PhaseOrderInBimDocumentBimDocumentIndex { get; } public int GetPhaseOrderInBimDocumentBimDocumentIndex(int index) => PhaseOrderInBimDocumentBimDocumentIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumPhaseOrderInBimDocument => PhaseOrderInBimDocumentEntityTable?.NumRows ?? 0; - public IArray PhaseOrderInBimDocumentList { get; } + public PhaseOrderInBimDocument[] PhaseOrderInBimDocumentList { get; } public PhaseOrderInBimDocument GetPhaseOrderInBimDocument(int n) { if (n < 0) return null; @@ -2449,26 +2450,26 @@ public PhaseOrderInBimDocument GetPhaseOrderInBimDocument(int n) public EntityTable CategoryEntityTable { get; } - public IArray CategoryName { get; } + public String[] CategoryName { get; } public String GetCategoryName(int index, String defaultValue = "") => CategoryName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CategoryId { get; } + public Int64[] CategoryId { get; } public Int64 GetCategoryId(int index, Int64 defaultValue = default) => CategoryId?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CategoryCategoryType { get; } + public String[] CategoryCategoryType { get; } public String GetCategoryCategoryType(int index, String defaultValue = "") => CategoryCategoryType?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CategoryLineColor_X { get; } + public Double[] CategoryLineColor_X { get; } public Double GetCategoryLineColor_X(int index, Double defaultValue = default) => CategoryLineColor_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CategoryLineColor_Y { get; } + public Double[] CategoryLineColor_Y { get; } public Double GetCategoryLineColor_Y(int index, Double defaultValue = default) => CategoryLineColor_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CategoryLineColor_Z { get; } + public Double[] CategoryLineColor_Z { get; } public Double GetCategoryLineColor_Z(int index, Double defaultValue = default) => CategoryLineColor_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CategoryBuiltInCategory { get; } + public String[] CategoryBuiltInCategory { get; } public String GetCategoryBuiltInCategory(int index, String defaultValue = "") => CategoryBuiltInCategory?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CategoryParentIndex { get; } + public int[] CategoryParentIndex { get; } public int GetCategoryParentIndex(int index) => CategoryParentIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray CategoryMaterialIndex { get; } + public int[] CategoryMaterialIndex { get; } public int GetCategoryMaterialIndex(int index) => CategoryMaterialIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumCategory => CategoryEntityTable?.NumRows ?? 0; - public IArray CategoryList { get; } + public Category[] CategoryList { get; } public Category GetCategory(int n) { if (n < 0) return null; @@ -2492,20 +2493,20 @@ public Category GetCategory(int n) public EntityTable FamilyEntityTable { get; } - public IArray FamilyStructuralMaterialType { get; } + public String[] FamilyStructuralMaterialType { get; } public String GetFamilyStructuralMaterialType(int index, String defaultValue = "") => FamilyStructuralMaterialType?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyStructuralSectionShape { get; } + public String[] FamilyStructuralSectionShape { get; } public String GetFamilyStructuralSectionShape(int index, String defaultValue = "") => FamilyStructuralSectionShape?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyIsSystemFamily { get; } + public Boolean[] FamilyIsSystemFamily { get; } public Boolean GetFamilyIsSystemFamily(int index, Boolean defaultValue = default) => FamilyIsSystemFamily?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyIsInPlace { get; } + public Boolean[] FamilyIsInPlace { get; } public Boolean GetFamilyIsInPlace(int index, Boolean defaultValue = default) => FamilyIsInPlace?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyFamilyCategoryIndex { get; } + public int[] FamilyFamilyCategoryIndex { get; } public int GetFamilyFamilyCategoryIndex(int index) => FamilyFamilyCategoryIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray FamilyElementIndex { get; } + public int[] FamilyElementIndex { get; } public int GetFamilyElementIndex(int index) => FamilyElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumFamily => FamilyEntityTable?.NumRows ?? 0; - public IArray FamilyList { get; } + public Family[] FamilyList { get; } public Family GetFamily(int n) { if (n < 0) return null; @@ -2526,16 +2527,16 @@ public Family GetFamily(int n) public EntityTable FamilyTypeEntityTable { get; } - public IArray FamilyTypeIsSystemFamilyType { get; } + public Boolean[] FamilyTypeIsSystemFamilyType { get; } public Boolean GetFamilyTypeIsSystemFamilyType(int index, Boolean defaultValue = default) => FamilyTypeIsSystemFamilyType?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyTypeFamilyIndex { get; } + public int[] FamilyTypeFamilyIndex { get; } public int GetFamilyTypeFamilyIndex(int index) => FamilyTypeFamilyIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray FamilyTypeCompoundStructureIndex { get; } + public int[] FamilyTypeCompoundStructureIndex { get; } public int GetFamilyTypeCompoundStructureIndex(int index) => FamilyTypeCompoundStructureIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray FamilyTypeElementIndex { get; } + public int[] FamilyTypeElementIndex { get; } public int GetFamilyTypeElementIndex(int index) => FamilyTypeElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumFamilyType => FamilyTypeEntityTable?.NumRows ?? 0; - public IArray FamilyTypeList { get; } + public FamilyType[] FamilyTypeList { get; } public FamilyType GetFamilyType(int n) { if (n < 0) return null; @@ -2554,64 +2555,64 @@ public FamilyType GetFamilyType(int n) public EntityTable FamilyInstanceEntityTable { get; } - public IArray FamilyInstanceFacingFlipped { get; } + public Boolean[] FamilyInstanceFacingFlipped { get; } public Boolean GetFamilyInstanceFacingFlipped(int index, Boolean defaultValue = default) => FamilyInstanceFacingFlipped?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceFacingOrientation_X { get; } + public Single[] FamilyInstanceFacingOrientation_X { get; } public Single GetFamilyInstanceFacingOrientation_X(int index, Single defaultValue = default) => FamilyInstanceFacingOrientation_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceFacingOrientation_Y { get; } + public Single[] FamilyInstanceFacingOrientation_Y { get; } public Single GetFamilyInstanceFacingOrientation_Y(int index, Single defaultValue = default) => FamilyInstanceFacingOrientation_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceFacingOrientation_Z { get; } + public Single[] FamilyInstanceFacingOrientation_Z { get; } public Single GetFamilyInstanceFacingOrientation_Z(int index, Single defaultValue = default) => FamilyInstanceFacingOrientation_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceHandFlipped { get; } + public Boolean[] FamilyInstanceHandFlipped { get; } public Boolean GetFamilyInstanceHandFlipped(int index, Boolean defaultValue = default) => FamilyInstanceHandFlipped?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceMirrored { get; } + public Boolean[] FamilyInstanceMirrored { get; } public Boolean GetFamilyInstanceMirrored(int index, Boolean defaultValue = default) => FamilyInstanceMirrored?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceHasModifiedGeometry { get; } + public Boolean[] FamilyInstanceHasModifiedGeometry { get; } public Boolean GetFamilyInstanceHasModifiedGeometry(int index, Boolean defaultValue = default) => FamilyInstanceHasModifiedGeometry?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceScale { get; } + public Single[] FamilyInstanceScale { get; } public Single GetFamilyInstanceScale(int index, Single defaultValue = default) => FamilyInstanceScale?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceBasisX_X { get; } + public Single[] FamilyInstanceBasisX_X { get; } public Single GetFamilyInstanceBasisX_X(int index, Single defaultValue = default) => FamilyInstanceBasisX_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceBasisX_Y { get; } + public Single[] FamilyInstanceBasisX_Y { get; } public Single GetFamilyInstanceBasisX_Y(int index, Single defaultValue = default) => FamilyInstanceBasisX_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceBasisX_Z { get; } + public Single[] FamilyInstanceBasisX_Z { get; } public Single GetFamilyInstanceBasisX_Z(int index, Single defaultValue = default) => FamilyInstanceBasisX_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceBasisY_X { get; } + public Single[] FamilyInstanceBasisY_X { get; } public Single GetFamilyInstanceBasisY_X(int index, Single defaultValue = default) => FamilyInstanceBasisY_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceBasisY_Y { get; } + public Single[] FamilyInstanceBasisY_Y { get; } public Single GetFamilyInstanceBasisY_Y(int index, Single defaultValue = default) => FamilyInstanceBasisY_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceBasisY_Z { get; } + public Single[] FamilyInstanceBasisY_Z { get; } public Single GetFamilyInstanceBasisY_Z(int index, Single defaultValue = default) => FamilyInstanceBasisY_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceBasisZ_X { get; } + public Single[] FamilyInstanceBasisZ_X { get; } public Single GetFamilyInstanceBasisZ_X(int index, Single defaultValue = default) => FamilyInstanceBasisZ_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceBasisZ_Y { get; } + public Single[] FamilyInstanceBasisZ_Y { get; } public Single GetFamilyInstanceBasisZ_Y(int index, Single defaultValue = default) => FamilyInstanceBasisZ_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceBasisZ_Z { get; } + public Single[] FamilyInstanceBasisZ_Z { get; } public Single GetFamilyInstanceBasisZ_Z(int index, Single defaultValue = default) => FamilyInstanceBasisZ_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceTranslation_X { get; } + public Single[] FamilyInstanceTranslation_X { get; } public Single GetFamilyInstanceTranslation_X(int index, Single defaultValue = default) => FamilyInstanceTranslation_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceTranslation_Y { get; } + public Single[] FamilyInstanceTranslation_Y { get; } public Single GetFamilyInstanceTranslation_Y(int index, Single defaultValue = default) => FamilyInstanceTranslation_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceTranslation_Z { get; } + public Single[] FamilyInstanceTranslation_Z { get; } public Single GetFamilyInstanceTranslation_Z(int index, Single defaultValue = default) => FamilyInstanceTranslation_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceHandOrientation_X { get; } + public Single[] FamilyInstanceHandOrientation_X { get; } public Single GetFamilyInstanceHandOrientation_X(int index, Single defaultValue = default) => FamilyInstanceHandOrientation_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceHandOrientation_Y { get; } + public Single[] FamilyInstanceHandOrientation_Y { get; } public Single GetFamilyInstanceHandOrientation_Y(int index, Single defaultValue = default) => FamilyInstanceHandOrientation_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceHandOrientation_Z { get; } + public Single[] FamilyInstanceHandOrientation_Z { get; } public Single GetFamilyInstanceHandOrientation_Z(int index, Single defaultValue = default) => FamilyInstanceHandOrientation_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray FamilyInstanceFamilyTypeIndex { get; } + public int[] FamilyInstanceFamilyTypeIndex { get; } public int GetFamilyInstanceFamilyTypeIndex(int index) => FamilyInstanceFamilyTypeIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray FamilyInstanceHostIndex { get; } + public int[] FamilyInstanceHostIndex { get; } public int GetFamilyInstanceHostIndex(int index) => FamilyInstanceHostIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray FamilyInstanceFromRoomIndex { get; } + public int[] FamilyInstanceFromRoomIndex { get; } public int GetFamilyInstanceFromRoomIndex(int index) => FamilyInstanceFromRoomIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray FamilyInstanceToRoomIndex { get; } + public int[] FamilyInstanceToRoomIndex { get; } public int GetFamilyInstanceToRoomIndex(int index) => FamilyInstanceToRoomIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray FamilyInstanceElementIndex { get; } + public int[] FamilyInstanceElementIndex { get; } public int GetFamilyInstanceElementIndex(int index) => FamilyInstanceElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumFamilyInstance => FamilyInstanceEntityTable?.NumRows ?? 0; - public IArray FamilyInstanceList { get; } + public FamilyInstance[] FamilyInstanceList { get; } public FamilyInstance GetFamilyInstance(int n) { if (n < 0) return null; @@ -2654,60 +2655,60 @@ public FamilyInstance GetFamilyInstance(int n) public EntityTable ViewEntityTable { get; } - public IArray ViewTitle { get; } + public String[] ViewTitle { get; } public String GetViewTitle(int index, String defaultValue = "") => ViewTitle?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewViewType { get; } + public String[] ViewViewType { get; } public String GetViewViewType(int index, String defaultValue = "") => ViewViewType?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewUp_X { get; } + public Double[] ViewUp_X { get; } public Double GetViewUp_X(int index, Double defaultValue = default) => ViewUp_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewUp_Y { get; } + public Double[] ViewUp_Y { get; } public Double GetViewUp_Y(int index, Double defaultValue = default) => ViewUp_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewUp_Z { get; } + public Double[] ViewUp_Z { get; } public Double GetViewUp_Z(int index, Double defaultValue = default) => ViewUp_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewRight_X { get; } + public Double[] ViewRight_X { get; } public Double GetViewRight_X(int index, Double defaultValue = default) => ViewRight_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewRight_Y { get; } + public Double[] ViewRight_Y { get; } public Double GetViewRight_Y(int index, Double defaultValue = default) => ViewRight_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewRight_Z { get; } + public Double[] ViewRight_Z { get; } public Double GetViewRight_Z(int index, Double defaultValue = default) => ViewRight_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewOrigin_X { get; } + public Double[] ViewOrigin_X { get; } public Double GetViewOrigin_X(int index, Double defaultValue = default) => ViewOrigin_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewOrigin_Y { get; } + public Double[] ViewOrigin_Y { get; } public Double GetViewOrigin_Y(int index, Double defaultValue = default) => ViewOrigin_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewOrigin_Z { get; } + public Double[] ViewOrigin_Z { get; } public Double GetViewOrigin_Z(int index, Double defaultValue = default) => ViewOrigin_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewViewDirection_X { get; } + public Double[] ViewViewDirection_X { get; } public Double GetViewViewDirection_X(int index, Double defaultValue = default) => ViewViewDirection_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewViewDirection_Y { get; } + public Double[] ViewViewDirection_Y { get; } public Double GetViewViewDirection_Y(int index, Double defaultValue = default) => ViewViewDirection_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewViewDirection_Z { get; } + public Double[] ViewViewDirection_Z { get; } public Double GetViewViewDirection_Z(int index, Double defaultValue = default) => ViewViewDirection_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewViewPosition_X { get; } + public Double[] ViewViewPosition_X { get; } public Double GetViewViewPosition_X(int index, Double defaultValue = default) => ViewViewPosition_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewViewPosition_Y { get; } + public Double[] ViewViewPosition_Y { get; } public Double GetViewViewPosition_Y(int index, Double defaultValue = default) => ViewViewPosition_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewViewPosition_Z { get; } + public Double[] ViewViewPosition_Z { get; } public Double GetViewViewPosition_Z(int index, Double defaultValue = default) => ViewViewPosition_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewScale { get; } + public Double[] ViewScale { get; } public Double GetViewScale(int index, Double defaultValue = default) => ViewScale?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewOutline_Min_X { get; } + public Double[] ViewOutline_Min_X { get; } public Double GetViewOutline_Min_X(int index, Double defaultValue = default) => ViewOutline_Min_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewOutline_Min_Y { get; } + public Double[] ViewOutline_Min_Y { get; } public Double GetViewOutline_Min_Y(int index, Double defaultValue = default) => ViewOutline_Min_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewOutline_Max_X { get; } + public Double[] ViewOutline_Max_X { get; } public Double GetViewOutline_Max_X(int index, Double defaultValue = default) => ViewOutline_Max_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewOutline_Max_Y { get; } + public Double[] ViewOutline_Max_Y { get; } public Double GetViewOutline_Max_Y(int index, Double defaultValue = default) => ViewOutline_Max_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewDetailLevel { get; } + public Int32[] ViewDetailLevel { get; } public Int32 GetViewDetailLevel(int index, Int32 defaultValue = default) => ViewDetailLevel?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ViewCameraIndex { get; } + public int[] ViewCameraIndex { get; } public int GetViewCameraIndex(int index) => ViewCameraIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ViewFamilyTypeIndex { get; } + public int[] ViewFamilyTypeIndex { get; } public int GetViewFamilyTypeIndex(int index) => ViewFamilyTypeIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ViewElementIndex { get; } + public int[] ViewElementIndex { get; } public int GetViewElementIndex(int index) => ViewElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumView => ViewEntityTable?.NumRows ?? 0; - public IArray ViewList { get; } + public View[] ViewList { get; } public View GetView(int n) { if (n < 0) return null; @@ -2748,12 +2749,12 @@ public View GetView(int n) public EntityTable ElementInViewEntityTable { get; } - public IArray ElementInViewViewIndex { get; } + public int[] ElementInViewViewIndex { get; } public int GetElementInViewViewIndex(int index) => ElementInViewViewIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementInViewElementIndex { get; } + public int[] ElementInViewElementIndex { get; } public int GetElementInViewElementIndex(int index) => ElementInViewElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumElementInView => ElementInViewEntityTable?.NumRows ?? 0; - public IArray ElementInViewList { get; } + public ElementInView[] ElementInViewList { get; } public ElementInView GetElementInView(int n) { if (n < 0) return null; @@ -2770,12 +2771,12 @@ public ElementInView GetElementInView(int n) public EntityTable ShapeInViewEntityTable { get; } - public IArray ShapeInViewShapeIndex { get; } + public int[] ShapeInViewShapeIndex { get; } public int GetShapeInViewShapeIndex(int index) => ShapeInViewShapeIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ShapeInViewViewIndex { get; } + public int[] ShapeInViewViewIndex { get; } public int GetShapeInViewViewIndex(int index) => ShapeInViewViewIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumShapeInView => ShapeInViewEntityTable?.NumRows ?? 0; - public IArray ShapeInViewList { get; } + public ShapeInView[] ShapeInViewList { get; } public ShapeInView GetShapeInView(int n) { if (n < 0) return null; @@ -2792,12 +2793,12 @@ public ShapeInView GetShapeInView(int n) public EntityTable AssetInViewEntityTable { get; } - public IArray AssetInViewAssetIndex { get; } + public int[] AssetInViewAssetIndex { get; } public int GetAssetInViewAssetIndex(int index) => AssetInViewAssetIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray AssetInViewViewIndex { get; } + public int[] AssetInViewViewIndex { get; } public int GetAssetInViewViewIndex(int index) => AssetInViewViewIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumAssetInView => AssetInViewEntityTable?.NumRows ?? 0; - public IArray AssetInViewList { get; } + public AssetInView[] AssetInViewList { get; } public AssetInView GetAssetInView(int n) { if (n < 0) return null; @@ -2814,12 +2815,12 @@ public AssetInView GetAssetInView(int n) public EntityTable AssetInViewSheetEntityTable { get; } - public IArray AssetInViewSheetAssetIndex { get; } + public int[] AssetInViewSheetAssetIndex { get; } public int GetAssetInViewSheetAssetIndex(int index) => AssetInViewSheetAssetIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray AssetInViewSheetViewSheetIndex { get; } + public int[] AssetInViewSheetViewSheetIndex { get; } public int GetAssetInViewSheetViewSheetIndex(int index) => AssetInViewSheetViewSheetIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumAssetInViewSheet => AssetInViewSheetEntityTable?.NumRows ?? 0; - public IArray AssetInViewSheetList { get; } + public AssetInViewSheet[] AssetInViewSheetList { get; } public AssetInViewSheet GetAssetInViewSheet(int n) { if (n < 0) return null; @@ -2836,24 +2837,24 @@ public AssetInViewSheet GetAssetInViewSheet(int n) public EntityTable LevelInViewEntityTable { get; } - public IArray LevelInViewExtents_Min_X { get; } + public Double[] LevelInViewExtents_Min_X { get; } public Double GetLevelInViewExtents_Min_X(int index, Double defaultValue = default) => LevelInViewExtents_Min_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray LevelInViewExtents_Min_Y { get; } + public Double[] LevelInViewExtents_Min_Y { get; } public Double GetLevelInViewExtents_Min_Y(int index, Double defaultValue = default) => LevelInViewExtents_Min_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray LevelInViewExtents_Min_Z { get; } + public Double[] LevelInViewExtents_Min_Z { get; } public Double GetLevelInViewExtents_Min_Z(int index, Double defaultValue = default) => LevelInViewExtents_Min_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray LevelInViewExtents_Max_X { get; } + public Double[] LevelInViewExtents_Max_X { get; } public Double GetLevelInViewExtents_Max_X(int index, Double defaultValue = default) => LevelInViewExtents_Max_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray LevelInViewExtents_Max_Y { get; } + public Double[] LevelInViewExtents_Max_Y { get; } public Double GetLevelInViewExtents_Max_Y(int index, Double defaultValue = default) => LevelInViewExtents_Max_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray LevelInViewExtents_Max_Z { get; } + public Double[] LevelInViewExtents_Max_Z { get; } public Double GetLevelInViewExtents_Max_Z(int index, Double defaultValue = default) => LevelInViewExtents_Max_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray LevelInViewLevelIndex { get; } + public int[] LevelInViewLevelIndex { get; } public int GetLevelInViewLevelIndex(int index) => LevelInViewLevelIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray LevelInViewViewIndex { get; } + public int[] LevelInViewViewIndex { get; } public int GetLevelInViewViewIndex(int index) => LevelInViewViewIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumLevelInView => LevelInViewEntityTable?.NumRows ?? 0; - public IArray LevelInViewList { get; } + public LevelInView[] LevelInViewList { get; } public LevelInView GetLevelInView(int n) { if (n < 0) return null; @@ -2876,26 +2877,26 @@ public LevelInView GetLevelInView(int n) public EntityTable CameraEntityTable { get; } - public IArray CameraId { get; } + public Int32[] CameraId { get; } public Int32 GetCameraId(int index, Int32 defaultValue = default) => CameraId?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CameraIsPerspective { get; } + public Int32[] CameraIsPerspective { get; } public Int32 GetCameraIsPerspective(int index, Int32 defaultValue = default) => CameraIsPerspective?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CameraVerticalExtent { get; } + public Double[] CameraVerticalExtent { get; } public Double GetCameraVerticalExtent(int index, Double defaultValue = default) => CameraVerticalExtent?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CameraHorizontalExtent { get; } + public Double[] CameraHorizontalExtent { get; } public Double GetCameraHorizontalExtent(int index, Double defaultValue = default) => CameraHorizontalExtent?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CameraFarDistance { get; } + public Double[] CameraFarDistance { get; } public Double GetCameraFarDistance(int index, Double defaultValue = default) => CameraFarDistance?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CameraNearDistance { get; } + public Double[] CameraNearDistance { get; } public Double GetCameraNearDistance(int index, Double defaultValue = default) => CameraNearDistance?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CameraTargetDistance { get; } + public Double[] CameraTargetDistance { get; } public Double GetCameraTargetDistance(int index, Double defaultValue = default) => CameraTargetDistance?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CameraRightOffset { get; } + public Double[] CameraRightOffset { get; } public Double GetCameraRightOffset(int index, Double defaultValue = default) => CameraRightOffset?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CameraUpOffset { get; } + public Double[] CameraUpOffset { get; } public Double GetCameraUpOffset(int index, Double defaultValue = default) => CameraUpOffset?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; public int NumCamera => CameraEntityTable?.NumRows ?? 0; - public IArray CameraList { get; } + public Camera[] CameraList { get; } public Camera GetCamera(int n) { if (n < 0) return null; @@ -2919,48 +2920,48 @@ public Camera GetCamera(int n) public EntityTable MaterialEntityTable { get; } - public IArray MaterialName { get; } + public String[] MaterialName { get; } public String GetMaterialName(int index, String defaultValue = "") => MaterialName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialMaterialCategory { get; } + public String[] MaterialMaterialCategory { get; } public String GetMaterialMaterialCategory(int index, String defaultValue = "") => MaterialMaterialCategory?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialColor_X { get; } + public Double[] MaterialColor_X { get; } public Double GetMaterialColor_X(int index, Double defaultValue = default) => MaterialColor_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialColor_Y { get; } + public Double[] MaterialColor_Y { get; } public Double GetMaterialColor_Y(int index, Double defaultValue = default) => MaterialColor_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialColor_Z { get; } + public Double[] MaterialColor_Z { get; } public Double GetMaterialColor_Z(int index, Double defaultValue = default) => MaterialColor_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialColorUvScaling_X { get; } + public Double[] MaterialColorUvScaling_X { get; } public Double GetMaterialColorUvScaling_X(int index, Double defaultValue = default) => MaterialColorUvScaling_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialColorUvScaling_Y { get; } + public Double[] MaterialColorUvScaling_Y { get; } public Double GetMaterialColorUvScaling_Y(int index, Double defaultValue = default) => MaterialColorUvScaling_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialColorUvOffset_X { get; } + public Double[] MaterialColorUvOffset_X { get; } public Double GetMaterialColorUvOffset_X(int index, Double defaultValue = default) => MaterialColorUvOffset_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialColorUvOffset_Y { get; } + public Double[] MaterialColorUvOffset_Y { get; } public Double GetMaterialColorUvOffset_Y(int index, Double defaultValue = default) => MaterialColorUvOffset_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialNormalUvScaling_X { get; } + public Double[] MaterialNormalUvScaling_X { get; } public Double GetMaterialNormalUvScaling_X(int index, Double defaultValue = default) => MaterialNormalUvScaling_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialNormalUvScaling_Y { get; } + public Double[] MaterialNormalUvScaling_Y { get; } public Double GetMaterialNormalUvScaling_Y(int index, Double defaultValue = default) => MaterialNormalUvScaling_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialNormalUvOffset_X { get; } + public Double[] MaterialNormalUvOffset_X { get; } public Double GetMaterialNormalUvOffset_X(int index, Double defaultValue = default) => MaterialNormalUvOffset_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialNormalUvOffset_Y { get; } + public Double[] MaterialNormalUvOffset_Y { get; } public Double GetMaterialNormalUvOffset_Y(int index, Double defaultValue = default) => MaterialNormalUvOffset_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialNormalAmount { get; } + public Double[] MaterialNormalAmount { get; } public Double GetMaterialNormalAmount(int index, Double defaultValue = default) => MaterialNormalAmount?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialGlossiness { get; } + public Double[] MaterialGlossiness { get; } public Double GetMaterialGlossiness(int index, Double defaultValue = default) => MaterialGlossiness?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialSmoothness { get; } + public Double[] MaterialSmoothness { get; } public Double GetMaterialSmoothness(int index, Double defaultValue = default) => MaterialSmoothness?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialTransparency { get; } + public Double[] MaterialTransparency { get; } public Double GetMaterialTransparency(int index, Double defaultValue = default) => MaterialTransparency?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialColorTextureFileIndex { get; } + public int[] MaterialColorTextureFileIndex { get; } public int GetMaterialColorTextureFileIndex(int index) => MaterialColorTextureFileIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray MaterialNormalTextureFileIndex { get; } + public int[] MaterialNormalTextureFileIndex { get; } public int GetMaterialNormalTextureFileIndex(int index) => MaterialNormalTextureFileIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray MaterialElementIndex { get; } + public int[] MaterialElementIndex { get; } public int GetMaterialElementIndex(int index) => MaterialElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumMaterial => MaterialEntityTable?.NumRows ?? 0; - public IArray MaterialList { get; } + public Material[] MaterialList { get; } public Material GetMaterial(int n) { if (n < 0) return null; @@ -2995,18 +2996,18 @@ public Material GetMaterial(int n) public EntityTable MaterialInElementEntityTable { get; } - public IArray MaterialInElementArea { get; } + public Double[] MaterialInElementArea { get; } public Double GetMaterialInElementArea(int index, Double defaultValue = default) => MaterialInElementArea?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialInElementVolume { get; } + public Double[] MaterialInElementVolume { get; } public Double GetMaterialInElementVolume(int index, Double defaultValue = default) => MaterialInElementVolume?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialInElementIsPaint { get; } + public Boolean[] MaterialInElementIsPaint { get; } public Boolean GetMaterialInElementIsPaint(int index, Boolean defaultValue = default) => MaterialInElementIsPaint?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray MaterialInElementMaterialIndex { get; } + public int[] MaterialInElementMaterialIndex { get; } public int GetMaterialInElementMaterialIndex(int index) => MaterialInElementMaterialIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray MaterialInElementElementIndex { get; } + public int[] MaterialInElementElementIndex { get; } public int GetMaterialInElementElementIndex(int index) => MaterialInElementElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumMaterialInElement => MaterialInElementEntityTable?.NumRows ?? 0; - public IArray MaterialInElementList { get; } + public MaterialInElement[] MaterialInElementList { get; } public MaterialInElement GetMaterialInElement(int n) { if (n < 0) return null; @@ -3026,18 +3027,18 @@ public MaterialInElement GetMaterialInElement(int n) public EntityTable CompoundStructureLayerEntityTable { get; } - public IArray CompoundStructureLayerOrderIndex { get; } + public Int32[] CompoundStructureLayerOrderIndex { get; } public Int32 GetCompoundStructureLayerOrderIndex(int index, Int32 defaultValue = default) => CompoundStructureLayerOrderIndex?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CompoundStructureLayerWidth { get; } + public Double[] CompoundStructureLayerWidth { get; } public Double GetCompoundStructureLayerWidth(int index, Double defaultValue = default) => CompoundStructureLayerWidth?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CompoundStructureLayerMaterialFunctionAssignment { get; } + public String[] CompoundStructureLayerMaterialFunctionAssignment { get; } public String GetCompoundStructureLayerMaterialFunctionAssignment(int index, String defaultValue = "") => CompoundStructureLayerMaterialFunctionAssignment?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CompoundStructureLayerMaterialIndex { get; } + public int[] CompoundStructureLayerMaterialIndex { get; } public int GetCompoundStructureLayerMaterialIndex(int index) => CompoundStructureLayerMaterialIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray CompoundStructureLayerCompoundStructureIndex { get; } + public int[] CompoundStructureLayerCompoundStructureIndex { get; } public int GetCompoundStructureLayerCompoundStructureIndex(int index) => CompoundStructureLayerCompoundStructureIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumCompoundStructureLayer => CompoundStructureLayerEntityTable?.NumRows ?? 0; - public IArray CompoundStructureLayerList { get; } + public CompoundStructureLayer[] CompoundStructureLayerList { get; } public CompoundStructureLayer GetCompoundStructureLayer(int n) { if (n < 0) return null; @@ -3057,12 +3058,12 @@ public CompoundStructureLayer GetCompoundStructureLayer(int n) public EntityTable CompoundStructureEntityTable { get; } - public IArray CompoundStructureWidth { get; } + public Double[] CompoundStructureWidth { get; } public Double GetCompoundStructureWidth(int index, Double defaultValue = default) => CompoundStructureWidth?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray CompoundStructureStructuralLayerIndex { get; } + public int[] CompoundStructureStructuralLayerIndex { get; } public int GetCompoundStructureStructuralLayerIndex(int index) => CompoundStructureStructuralLayerIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumCompoundStructure => CompoundStructureEntityTable?.NumRows ?? 0; - public IArray CompoundStructureList { get; } + public CompoundStructure[] CompoundStructureList { get; } public CompoundStructure GetCompoundStructure(int n) { if (n < 0) return null; @@ -3079,10 +3080,10 @@ public CompoundStructure GetCompoundStructure(int n) public EntityTable NodeEntityTable { get; } - public IArray NodeElementIndex { get; } + public int[] NodeElementIndex { get; } public int GetNodeElementIndex(int index) => NodeElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumNode => NodeEntityTable?.NumRows ?? 0; - public IArray NodeList { get; } + public Node[] NodeList { get; } public Node GetNode(int n) { if (n < 0) return null; @@ -3098,24 +3099,24 @@ public Node GetNode(int n) public EntityTable GeometryEntityTable { get; } - public IArray GeometryBox_Min_X { get; } + public Single[] GeometryBox_Min_X { get; } public Single GetGeometryBox_Min_X(int index, Single defaultValue = default) => GeometryBox_Min_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GeometryBox_Min_Y { get; } + public Single[] GeometryBox_Min_Y { get; } public Single GetGeometryBox_Min_Y(int index, Single defaultValue = default) => GeometryBox_Min_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GeometryBox_Min_Z { get; } + public Single[] GeometryBox_Min_Z { get; } public Single GetGeometryBox_Min_Z(int index, Single defaultValue = default) => GeometryBox_Min_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GeometryBox_Max_X { get; } + public Single[] GeometryBox_Max_X { get; } public Single GetGeometryBox_Max_X(int index, Single defaultValue = default) => GeometryBox_Max_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GeometryBox_Max_Y { get; } + public Single[] GeometryBox_Max_Y { get; } public Single GetGeometryBox_Max_Y(int index, Single defaultValue = default) => GeometryBox_Max_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GeometryBox_Max_Z { get; } + public Single[] GeometryBox_Max_Z { get; } public Single GetGeometryBox_Max_Z(int index, Single defaultValue = default) => GeometryBox_Max_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GeometryVertexCount { get; } + public Int32[] GeometryVertexCount { get; } public Int32 GetGeometryVertexCount(int index, Int32 defaultValue = default) => GeometryVertexCount?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GeometryFaceCount { get; } + public Int32[] GeometryFaceCount { get; } public Int32 GetGeometryFaceCount(int index, Int32 defaultValue = default) => GeometryFaceCount?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; public int NumGeometry => GeometryEntityTable?.NumRows ?? 0; - public IArray GeometryList { get; } + public Geometry[] GeometryList { get; } public Geometry GetGeometry(int n) { if (n < 0) return null; @@ -3138,10 +3139,10 @@ public Geometry GetGeometry(int n) public EntityTable ShapeEntityTable { get; } - public IArray ShapeElementIndex { get; } + public int[] ShapeElementIndex { get; } public int GetShapeElementIndex(int index) => ShapeElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumShape => ShapeEntityTable?.NumRows ?? 0; - public IArray ShapeList { get; } + public Shape[] ShapeList { get; } public Shape GetShape(int n) { if (n < 0) return null; @@ -3157,10 +3158,10 @@ public Shape GetShape(int n) public EntityTable ShapeCollectionEntityTable { get; } - public IArray ShapeCollectionElementIndex { get; } + public int[] ShapeCollectionElementIndex { get; } public int GetShapeCollectionElementIndex(int index) => ShapeCollectionElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumShapeCollection => ShapeCollectionEntityTable?.NumRows ?? 0; - public IArray ShapeCollectionList { get; } + public ShapeCollection[] ShapeCollectionList { get; } public ShapeCollection GetShapeCollection(int n) { if (n < 0) return null; @@ -3176,12 +3177,12 @@ public ShapeCollection GetShapeCollection(int n) public EntityTable ShapeInShapeCollectionEntityTable { get; } - public IArray ShapeInShapeCollectionShapeIndex { get; } + public int[] ShapeInShapeCollectionShapeIndex { get; } public int GetShapeInShapeCollectionShapeIndex(int index) => ShapeInShapeCollectionShapeIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ShapeInShapeCollectionShapeCollectionIndex { get; } + public int[] ShapeInShapeCollectionShapeCollectionIndex { get; } public int GetShapeInShapeCollectionShapeCollectionIndex(int index) => ShapeInShapeCollectionShapeCollectionIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumShapeInShapeCollection => ShapeInShapeCollectionEntityTable?.NumRows ?? 0; - public IArray ShapeInShapeCollectionList { get; } + public ShapeInShapeCollection[] ShapeInShapeCollectionList { get; } public ShapeInShapeCollection GetShapeInShapeCollection(int n) { if (n < 0) return null; @@ -3198,14 +3199,14 @@ public ShapeInShapeCollection GetShapeInShapeCollection(int n) public EntityTable SystemEntityTable { get; } - public IArray SystemSystemType { get; } + public Int32[] SystemSystemType { get; } public Int32 GetSystemSystemType(int index, Int32 defaultValue = default) => SystemSystemType?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray SystemFamilyTypeIndex { get; } + public int[] SystemFamilyTypeIndex { get; } public int GetSystemFamilyTypeIndex(int index) => SystemFamilyTypeIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray SystemElementIndex { get; } + public int[] SystemElementIndex { get; } public int GetSystemElementIndex(int index) => SystemElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumSystem => SystemEntityTable?.NumRows ?? 0; - public IArray SystemList { get; } + public System[] SystemList { get; } public System GetSystem(int n) { if (n < 0) return null; @@ -3223,14 +3224,14 @@ public System GetSystem(int n) public EntityTable ElementInSystemEntityTable { get; } - public IArray ElementInSystemRoles { get; } + public Int32[] ElementInSystemRoles { get; } public Int32 GetElementInSystemRoles(int index, Int32 defaultValue = default) => ElementInSystemRoles?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ElementInSystemSystemIndex { get; } + public int[] ElementInSystemSystemIndex { get; } public int GetElementInSystemSystemIndex(int index) => ElementInSystemSystemIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementInSystemElementIndex { get; } + public int[] ElementInSystemElementIndex { get; } public int GetElementInSystemElementIndex(int index) => ElementInSystemElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumElementInSystem => ElementInSystemEntityTable?.NumRows ?? 0; - public IArray ElementInSystemList { get; } + public ElementInSystem[] ElementInSystemList { get; } public ElementInSystem GetElementInSystem(int n) { if (n < 0) return null; @@ -3248,16 +3249,16 @@ public ElementInSystem GetElementInSystem(int n) public EntityTable WarningEntityTable { get; } - public IArray WarningGuid { get; } + public String[] WarningGuid { get; } public String GetWarningGuid(int index, String defaultValue = "") => WarningGuid?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WarningSeverity { get; } + public String[] WarningSeverity { get; } public String GetWarningSeverity(int index, String defaultValue = "") => WarningSeverity?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WarningDescription { get; } + public String[] WarningDescription { get; } public String GetWarningDescription(int index, String defaultValue = "") => WarningDescription?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray WarningBimDocumentIndex { get; } + public int[] WarningBimDocumentIndex { get; } public int GetWarningBimDocumentIndex(int index) => WarningBimDocumentIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumWarning => WarningEntityTable?.NumRows ?? 0; - public IArray WarningList { get; } + public Warning[] WarningList { get; } public Warning GetWarning(int n) { if (n < 0) return null; @@ -3276,12 +3277,12 @@ public Warning GetWarning(int n) public EntityTable ElementInWarningEntityTable { get; } - public IArray ElementInWarningWarningIndex { get; } + public int[] ElementInWarningWarningIndex { get; } public int GetElementInWarningWarningIndex(int index) => ElementInWarningWarningIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ElementInWarningElementIndex { get; } + public int[] ElementInWarningElementIndex { get; } public int GetElementInWarningElementIndex(int index) => ElementInWarningElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumElementInWarning => ElementInWarningEntityTable?.NumRows ?? 0; - public IArray ElementInWarningList { get; } + public ElementInWarning[] ElementInWarningList { get; } public ElementInWarning GetElementInWarning(int n) { if (n < 0) return null; @@ -3298,24 +3299,24 @@ public ElementInWarning GetElementInWarning(int n) public EntityTable BasePointEntityTable { get; } - public IArray BasePointIsSurveyPoint { get; } + public Boolean[] BasePointIsSurveyPoint { get; } public Boolean GetBasePointIsSurveyPoint(int index, Boolean defaultValue = default) => BasePointIsSurveyPoint?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BasePointPosition_X { get; } + public Double[] BasePointPosition_X { get; } public Double GetBasePointPosition_X(int index, Double defaultValue = default) => BasePointPosition_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BasePointPosition_Y { get; } + public Double[] BasePointPosition_Y { get; } public Double GetBasePointPosition_Y(int index, Double defaultValue = default) => BasePointPosition_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BasePointPosition_Z { get; } + public Double[] BasePointPosition_Z { get; } public Double GetBasePointPosition_Z(int index, Double defaultValue = default) => BasePointPosition_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BasePointSharedPosition_X { get; } + public Double[] BasePointSharedPosition_X { get; } public Double GetBasePointSharedPosition_X(int index, Double defaultValue = default) => BasePointSharedPosition_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BasePointSharedPosition_Y { get; } + public Double[] BasePointSharedPosition_Y { get; } public Double GetBasePointSharedPosition_Y(int index, Double defaultValue = default) => BasePointSharedPosition_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BasePointSharedPosition_Z { get; } + public Double[] BasePointSharedPosition_Z { get; } public Double GetBasePointSharedPosition_Z(int index, Double defaultValue = default) => BasePointSharedPosition_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BasePointElementIndex { get; } + public int[] BasePointElementIndex { get; } public int GetBasePointElementIndex(int index) => BasePointElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumBasePoint => BasePointEntityTable?.NumRows ?? 0; - public IArray BasePointList { get; } + public BasePoint[] BasePointList { get; } public BasePoint GetBasePoint(int n) { if (n < 0) return null; @@ -3338,18 +3339,18 @@ public BasePoint GetBasePoint(int n) public EntityTable PhaseFilterEntityTable { get; } - public IArray PhaseFilterNew { get; } + public Int32[] PhaseFilterNew { get; } public Int32 GetPhaseFilterNew(int index, Int32 defaultValue = default) => PhaseFilterNew?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray PhaseFilterExisting { get; } + public Int32[] PhaseFilterExisting { get; } public Int32 GetPhaseFilterExisting(int index, Int32 defaultValue = default) => PhaseFilterExisting?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray PhaseFilterDemolished { get; } + public Int32[] PhaseFilterDemolished { get; } public Int32 GetPhaseFilterDemolished(int index, Int32 defaultValue = default) => PhaseFilterDemolished?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray PhaseFilterTemporary { get; } + public Int32[] PhaseFilterTemporary { get; } public Int32 GetPhaseFilterTemporary(int index, Int32 defaultValue = default) => PhaseFilterTemporary?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray PhaseFilterElementIndex { get; } + public int[] PhaseFilterElementIndex { get; } public int GetPhaseFilterElementIndex(int index) => PhaseFilterElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumPhaseFilter => PhaseFilterEntityTable?.NumRows ?? 0; - public IArray PhaseFilterList { get; } + public PhaseFilter[] PhaseFilterList { get; } public PhaseFilter GetPhaseFilter(int n) { if (n < 0) return null; @@ -3369,38 +3370,38 @@ public PhaseFilter GetPhaseFilter(int n) public EntityTable GridEntityTable { get; } - public IArray GridStartPoint_X { get; } + public Double[] GridStartPoint_X { get; } public Double GetGridStartPoint_X(int index, Double defaultValue = default) => GridStartPoint_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridStartPoint_Y { get; } + public Double[] GridStartPoint_Y { get; } public Double GetGridStartPoint_Y(int index, Double defaultValue = default) => GridStartPoint_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridStartPoint_Z { get; } + public Double[] GridStartPoint_Z { get; } public Double GetGridStartPoint_Z(int index, Double defaultValue = default) => GridStartPoint_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridEndPoint_X { get; } + public Double[] GridEndPoint_X { get; } public Double GetGridEndPoint_X(int index, Double defaultValue = default) => GridEndPoint_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridEndPoint_Y { get; } + public Double[] GridEndPoint_Y { get; } public Double GetGridEndPoint_Y(int index, Double defaultValue = default) => GridEndPoint_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridEndPoint_Z { get; } + public Double[] GridEndPoint_Z { get; } public Double GetGridEndPoint_Z(int index, Double defaultValue = default) => GridEndPoint_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridIsCurved { get; } + public Boolean[] GridIsCurved { get; } public Boolean GetGridIsCurved(int index, Boolean defaultValue = default) => GridIsCurved?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridExtents_Min_X { get; } + public Double[] GridExtents_Min_X { get; } public Double GetGridExtents_Min_X(int index, Double defaultValue = default) => GridExtents_Min_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridExtents_Min_Y { get; } + public Double[] GridExtents_Min_Y { get; } public Double GetGridExtents_Min_Y(int index, Double defaultValue = default) => GridExtents_Min_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridExtents_Min_Z { get; } + public Double[] GridExtents_Min_Z { get; } public Double GetGridExtents_Min_Z(int index, Double defaultValue = default) => GridExtents_Min_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridExtents_Max_X { get; } + public Double[] GridExtents_Max_X { get; } public Double GetGridExtents_Max_X(int index, Double defaultValue = default) => GridExtents_Max_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridExtents_Max_Y { get; } + public Double[] GridExtents_Max_Y { get; } public Double GetGridExtents_Max_Y(int index, Double defaultValue = default) => GridExtents_Max_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridExtents_Max_Z { get; } + public Double[] GridExtents_Max_Z { get; } public Double GetGridExtents_Max_Z(int index, Double defaultValue = default) => GridExtents_Max_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray GridFamilyTypeIndex { get; } + public int[] GridFamilyTypeIndex { get; } public int GetGridFamilyTypeIndex(int index) => GridFamilyTypeIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray GridElementIndex { get; } + public int[] GridElementIndex { get; } public int GetGridElementIndex(int index) => GridElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumGrid => GridEntityTable?.NumRows ?? 0; - public IArray GridList { get; } + public Grid[] GridList { get; } public Grid GetGrid(int n) { if (n < 0) return null; @@ -3430,20 +3431,20 @@ public Grid GetGrid(int n) public EntityTable AreaEntityTable { get; } - public IArray AreaValue { get; } + public Double[] AreaValue { get; } public Double GetAreaValue(int index, Double defaultValue = default) => AreaValue?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray AreaPerimeter { get; } + public Double[] AreaPerimeter { get; } public Double GetAreaPerimeter(int index, Double defaultValue = default) => AreaPerimeter?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray AreaNumber { get; } + public String[] AreaNumber { get; } public String GetAreaNumber(int index, String defaultValue = "") => AreaNumber?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray AreaIsGrossInterior { get; } + public Boolean[] AreaIsGrossInterior { get; } public Boolean GetAreaIsGrossInterior(int index, Boolean defaultValue = default) => AreaIsGrossInterior?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray AreaAreaSchemeIndex { get; } + public int[] AreaAreaSchemeIndex { get; } public int GetAreaAreaSchemeIndex(int index) => AreaAreaSchemeIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray AreaElementIndex { get; } + public int[] AreaElementIndex { get; } public int GetAreaElementIndex(int index) => AreaElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumArea => AreaEntityTable?.NumRows ?? 0; - public IArray AreaList { get; } + public Area[] AreaList { get; } public Area GetArea(int n) { if (n < 0) return null; @@ -3464,12 +3465,12 @@ public Area GetArea(int n) public EntityTable AreaSchemeEntityTable { get; } - public IArray AreaSchemeIsGrossBuildingArea { get; } + public Boolean[] AreaSchemeIsGrossBuildingArea { get; } public Boolean GetAreaSchemeIsGrossBuildingArea(int index, Boolean defaultValue = default) => AreaSchemeIsGrossBuildingArea?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray AreaSchemeElementIndex { get; } + public int[] AreaSchemeElementIndex { get; } public int GetAreaSchemeElementIndex(int index) => AreaSchemeElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumAreaScheme => AreaSchemeEntityTable?.NumRows ?? 0; - public IArray AreaSchemeList { get; } + public AreaScheme[] AreaSchemeList { get; } public AreaScheme GetAreaScheme(int n) { if (n < 0) return null; @@ -3486,10 +3487,10 @@ public AreaScheme GetAreaScheme(int n) public EntityTable ScheduleEntityTable { get; } - public IArray ScheduleElementIndex { get; } + public int[] ScheduleElementIndex { get; } public int GetScheduleElementIndex(int index) => ScheduleElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumSchedule => ScheduleEntityTable?.NumRows ?? 0; - public IArray ScheduleList { get; } + public Schedule[] ScheduleList { get; } public Schedule GetSchedule(int n) { if (n < 0) return null; @@ -3505,14 +3506,14 @@ public Schedule GetSchedule(int n) public EntityTable ScheduleColumnEntityTable { get; } - public IArray ScheduleColumnName { get; } + public String[] ScheduleColumnName { get; } public String GetScheduleColumnName(int index, String defaultValue = "") => ScheduleColumnName?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ScheduleColumnColumnIndex { get; } + public Int32[] ScheduleColumnColumnIndex { get; } public Int32 GetScheduleColumnColumnIndex(int index, Int32 defaultValue = default) => ScheduleColumnColumnIndex?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ScheduleColumnScheduleIndex { get; } + public int[] ScheduleColumnScheduleIndex { get; } public int GetScheduleColumnScheduleIndex(int index) => ScheduleColumnScheduleIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumScheduleColumn => ScheduleColumnEntityTable?.NumRows ?? 0; - public IArray ScheduleColumnList { get; } + public ScheduleColumn[] ScheduleColumnList { get; } public ScheduleColumn GetScheduleColumn(int n) { if (n < 0) return null; @@ -3530,14 +3531,14 @@ public ScheduleColumn GetScheduleColumn(int n) public EntityTable ScheduleCellEntityTable { get; } - public IArray ScheduleCellValue { get; } + public String[] ScheduleCellValue { get; } public String GetScheduleCellValue(int index, String defaultValue = "") => ScheduleCellValue?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ScheduleCellRowIndex { get; } + public Int32[] ScheduleCellRowIndex { get; } public Int32 GetScheduleCellRowIndex(int index, Int32 defaultValue = default) => ScheduleCellRowIndex?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray ScheduleCellScheduleColumnIndex { get; } + public int[] ScheduleCellScheduleColumnIndex { get; } public int GetScheduleCellScheduleColumnIndex(int index) => ScheduleCellScheduleColumnIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumScheduleCell => ScheduleCellEntityTable?.NumRows ?? 0; - public IArray ScheduleCellList { get; } + public ScheduleCell[] ScheduleCellList { get; } public ScheduleCell GetScheduleCell(int n) { if (n < 0) return null; @@ -3555,10 +3556,10 @@ public ScheduleCell GetScheduleCell(int n) public EntityTable ViewSheetSetEntityTable { get; } - public IArray ViewSheetSetElementIndex { get; } + public int[] ViewSheetSetElementIndex { get; } public int GetViewSheetSetElementIndex(int index) => ViewSheetSetElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumViewSheetSet => ViewSheetSetEntityTable?.NumRows ?? 0; - public IArray ViewSheetSetList { get; } + public ViewSheetSet[] ViewSheetSetList { get; } public ViewSheetSet GetViewSheetSet(int n) { if (n < 0) return null; @@ -3574,12 +3575,12 @@ public ViewSheetSet GetViewSheetSet(int n) public EntityTable ViewSheetEntityTable { get; } - public IArray ViewSheetFamilyTypeIndex { get; } + public int[] ViewSheetFamilyTypeIndex { get; } public int GetViewSheetFamilyTypeIndex(int index) => ViewSheetFamilyTypeIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ViewSheetElementIndex { get; } + public int[] ViewSheetElementIndex { get; } public int GetViewSheetElementIndex(int index) => ViewSheetElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumViewSheet => ViewSheetEntityTable?.NumRows ?? 0; - public IArray ViewSheetList { get; } + public ViewSheet[] ViewSheetList { get; } public ViewSheet GetViewSheet(int n) { if (n < 0) return null; @@ -3596,12 +3597,12 @@ public ViewSheet GetViewSheet(int n) public EntityTable ViewSheetInViewSheetSetEntityTable { get; } - public IArray ViewSheetInViewSheetSetViewSheetIndex { get; } + public int[] ViewSheetInViewSheetSetViewSheetIndex { get; } public int GetViewSheetInViewSheetSetViewSheetIndex(int index) => ViewSheetInViewSheetSetViewSheetIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ViewSheetInViewSheetSetViewSheetSetIndex { get; } + public int[] ViewSheetInViewSheetSetViewSheetSetIndex { get; } public int GetViewSheetInViewSheetSetViewSheetSetIndex(int index) => ViewSheetInViewSheetSetViewSheetSetIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumViewSheetInViewSheetSet => ViewSheetInViewSheetSetEntityTable?.NumRows ?? 0; - public IArray ViewSheetInViewSheetSetList { get; } + public ViewSheetInViewSheetSet[] ViewSheetInViewSheetSetList { get; } public ViewSheetInViewSheetSet GetViewSheetInViewSheetSet(int n) { if (n < 0) return null; @@ -3618,12 +3619,12 @@ public ViewSheetInViewSheetSet GetViewSheetInViewSheetSet(int n) public EntityTable ViewInViewSheetSetEntityTable { get; } - public IArray ViewInViewSheetSetViewIndex { get; } + public int[] ViewInViewSheetSetViewIndex { get; } public int GetViewInViewSheetSetViewIndex(int index) => ViewInViewSheetSetViewIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ViewInViewSheetSetViewSheetSetIndex { get; } + public int[] ViewInViewSheetSetViewSheetSetIndex { get; } public int GetViewInViewSheetSetViewSheetSetIndex(int index) => ViewInViewSheetSetViewSheetSetIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumViewInViewSheetSet => ViewInViewSheetSetEntityTable?.NumRows ?? 0; - public IArray ViewInViewSheetSetList { get; } + public ViewInViewSheetSet[] ViewInViewSheetSetList { get; } public ViewInViewSheetSet GetViewInViewSheetSet(int n) { if (n < 0) return null; @@ -3640,12 +3641,12 @@ public ViewInViewSheetSet GetViewInViewSheetSet(int n) public EntityTable ViewInViewSheetEntityTable { get; } - public IArray ViewInViewSheetViewIndex { get; } + public int[] ViewInViewSheetViewIndex { get; } public int GetViewInViewSheetViewIndex(int index) => ViewInViewSheetViewIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray ViewInViewSheetViewSheetIndex { get; } + public int[] ViewInViewSheetViewSheetIndex { get; } public int GetViewInViewSheetViewSheetIndex(int index) => ViewInViewSheetViewSheetIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumViewInViewSheet => ViewInViewSheetEntityTable?.NumRows ?? 0; - public IArray ViewInViewSheetList { get; } + public ViewInViewSheet[] ViewInViewSheetList { get; } public ViewInViewSheet GetViewInViewSheet(int n) { if (n < 0) return null; @@ -3662,20 +3663,20 @@ public ViewInViewSheet GetViewInViewSheet(int n) public EntityTable SiteEntityTable { get; } - public IArray SiteLatitude { get; } + public Double[] SiteLatitude { get; } public Double GetSiteLatitude(int index, Double defaultValue = default) => SiteLatitude?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray SiteLongitude { get; } + public Double[] SiteLongitude { get; } public Double GetSiteLongitude(int index, Double defaultValue = default) => SiteLongitude?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray SiteAddress { get; } + public String[] SiteAddress { get; } public String GetSiteAddress(int index, String defaultValue = "") => SiteAddress?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray SiteElevation { get; } + public Double[] SiteElevation { get; } public Double GetSiteElevation(int index, Double defaultValue = default) => SiteElevation?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray SiteNumber { get; } + public String[] SiteNumber { get; } public String GetSiteNumber(int index, String defaultValue = "") => SiteNumber?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray SiteElementIndex { get; } + public int[] SiteElementIndex { get; } public int GetSiteElementIndex(int index) => SiteElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumSite => SiteEntityTable?.NumRows ?? 0; - public IArray SiteList { get; } + public Site[] SiteList { get; } public Site GetSite(int n) { if (n < 0) return null; @@ -3696,18 +3697,18 @@ public Site GetSite(int n) public EntityTable BuildingEntityTable { get; } - public IArray BuildingElevation { get; } + public Double[] BuildingElevation { get; } public Double GetBuildingElevation(int index, Double defaultValue = default) => BuildingElevation?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BuildingTerrainElevation { get; } + public Double[] BuildingTerrainElevation { get; } public Double GetBuildingTerrainElevation(int index, Double defaultValue = default) => BuildingTerrainElevation?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BuildingAddress { get; } + public String[] BuildingAddress { get; } public String GetBuildingAddress(int index, String defaultValue = "") => BuildingAddress?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; - public IArray BuildingSiteIndex { get; } + public int[] BuildingSiteIndex { get; } public int GetBuildingSiteIndex(int index) => BuildingSiteIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; - public IArray BuildingElementIndex { get; } + public int[] BuildingElementIndex { get; } public int GetBuildingElementIndex(int index) => BuildingElementIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public int NumBuilding => BuildingEntityTable?.NumRows ?? 0; - public IArray BuildingList { get; } + public Building[] BuildingList { get; } public Building GetBuilding(int n) { if (n < 0) return null; @@ -3724,60 +3725,60 @@ public Building GetBuilding(int n) // All entity collections public Dictionary> AllEntities => new Dictionary>() { - {"Vim.Asset", AssetList.ToEnumerable()}, - {"Vim.DisplayUnit", DisplayUnitList.ToEnumerable()}, - {"Vim.ParameterDescriptor", ParameterDescriptorList.ToEnumerable()}, - {"Vim.Parameter", ParameterList.ToEnumerable()}, - {"Vim.Element", ElementList.ToEnumerable()}, - {"Vim.Workset", WorksetList.ToEnumerable()}, - {"Vim.AssemblyInstance", AssemblyInstanceList.ToEnumerable()}, - {"Vim.Group", GroupList.ToEnumerable()}, - {"Vim.DesignOption", DesignOptionList.ToEnumerable()}, - {"Vim.Level", LevelList.ToEnumerable()}, - {"Vim.Phase", PhaseList.ToEnumerable()}, - {"Vim.Room", RoomList.ToEnumerable()}, - {"Vim.BimDocument", BimDocumentList.ToEnumerable()}, - {"Vim.DisplayUnitInBimDocument", DisplayUnitInBimDocumentList.ToEnumerable()}, - {"Vim.PhaseOrderInBimDocument", PhaseOrderInBimDocumentList.ToEnumerable()}, - {"Vim.Category", CategoryList.ToEnumerable()}, - {"Vim.Family", FamilyList.ToEnumerable()}, - {"Vim.FamilyType", FamilyTypeList.ToEnumerable()}, - {"Vim.FamilyInstance", FamilyInstanceList.ToEnumerable()}, - {"Vim.View", ViewList.ToEnumerable()}, - {"Vim.ElementInView", ElementInViewList.ToEnumerable()}, - {"Vim.ShapeInView", ShapeInViewList.ToEnumerable()}, - {"Vim.AssetInView", AssetInViewList.ToEnumerable()}, - {"Vim.AssetInViewSheet", AssetInViewSheetList.ToEnumerable()}, - {"Vim.LevelInView", LevelInViewList.ToEnumerable()}, - {"Vim.Camera", CameraList.ToEnumerable()}, - {"Vim.Material", MaterialList.ToEnumerable()}, - {"Vim.MaterialInElement", MaterialInElementList.ToEnumerable()}, - {"Vim.CompoundStructureLayer", CompoundStructureLayerList.ToEnumerable()}, - {"Vim.CompoundStructure", CompoundStructureList.ToEnumerable()}, - {"Vim.Node", NodeList.ToEnumerable()}, - {"Vim.Geometry", GeometryList.ToEnumerable()}, - {"Vim.Shape", ShapeList.ToEnumerable()}, - {"Vim.ShapeCollection", ShapeCollectionList.ToEnumerable()}, - {"Vim.ShapeInShapeCollection", ShapeInShapeCollectionList.ToEnumerable()}, - {"Vim.System", SystemList.ToEnumerable()}, - {"Vim.ElementInSystem", ElementInSystemList.ToEnumerable()}, - {"Vim.Warning", WarningList.ToEnumerable()}, - {"Vim.ElementInWarning", ElementInWarningList.ToEnumerable()}, - {"Vim.BasePoint", BasePointList.ToEnumerable()}, - {"Vim.PhaseFilter", PhaseFilterList.ToEnumerable()}, - {"Vim.Grid", GridList.ToEnumerable()}, - {"Vim.Area", AreaList.ToEnumerable()}, - {"Vim.AreaScheme", AreaSchemeList.ToEnumerable()}, - {"Vim.Schedule", ScheduleList.ToEnumerable()}, - {"Vim.ScheduleColumn", ScheduleColumnList.ToEnumerable()}, - {"Vim.ScheduleCell", ScheduleCellList.ToEnumerable()}, - {"Vim.ViewSheetSet", ViewSheetSetList.ToEnumerable()}, - {"Vim.ViewSheet", ViewSheetList.ToEnumerable()}, - {"Vim.ViewSheetInViewSheetSet", ViewSheetInViewSheetSetList.ToEnumerable()}, - {"Vim.ViewInViewSheetSet", ViewInViewSheetSetList.ToEnumerable()}, - {"Vim.ViewInViewSheet", ViewInViewSheetList.ToEnumerable()}, - {"Vim.Site", SiteList.ToEnumerable()}, - {"Vim.Building", BuildingList.ToEnumerable()}, + {"Vim.Asset", AssetList}, + {"Vim.DisplayUnit", DisplayUnitList}, + {"Vim.ParameterDescriptor", ParameterDescriptorList}, + {"Vim.Parameter", ParameterList}, + {"Vim.Element", ElementList}, + {"Vim.Workset", WorksetList}, + {"Vim.AssemblyInstance", AssemblyInstanceList}, + {"Vim.Group", GroupList}, + {"Vim.DesignOption", DesignOptionList}, + {"Vim.Level", LevelList}, + {"Vim.Phase", PhaseList}, + {"Vim.Room", RoomList}, + {"Vim.BimDocument", BimDocumentList}, + {"Vim.DisplayUnitInBimDocument", DisplayUnitInBimDocumentList}, + {"Vim.PhaseOrderInBimDocument", PhaseOrderInBimDocumentList}, + {"Vim.Category", CategoryList}, + {"Vim.Family", FamilyList}, + {"Vim.FamilyType", FamilyTypeList}, + {"Vim.FamilyInstance", FamilyInstanceList}, + {"Vim.View", ViewList}, + {"Vim.ElementInView", ElementInViewList}, + {"Vim.ShapeInView", ShapeInViewList}, + {"Vim.AssetInView", AssetInViewList}, + {"Vim.AssetInViewSheet", AssetInViewSheetList}, + {"Vim.LevelInView", LevelInViewList}, + {"Vim.Camera", CameraList}, + {"Vim.Material", MaterialList}, + {"Vim.MaterialInElement", MaterialInElementList}, + {"Vim.CompoundStructureLayer", CompoundStructureLayerList}, + {"Vim.CompoundStructure", CompoundStructureList}, + {"Vim.Node", NodeList}, + {"Vim.Geometry", GeometryList}, + {"Vim.Shape", ShapeList}, + {"Vim.ShapeCollection", ShapeCollectionList}, + {"Vim.ShapeInShapeCollection", ShapeInShapeCollectionList}, + {"Vim.System", SystemList}, + {"Vim.ElementInSystem", ElementInSystemList}, + {"Vim.Warning", WarningList}, + {"Vim.ElementInWarning", ElementInWarningList}, + {"Vim.BasePoint", BasePointList}, + {"Vim.PhaseFilter", PhaseFilterList}, + {"Vim.Grid", GridList}, + {"Vim.Area", AreaList}, + {"Vim.AreaScheme", AreaSchemeList}, + {"Vim.Schedule", ScheduleList}, + {"Vim.ScheduleColumn", ScheduleColumnList}, + {"Vim.ScheduleCell", ScheduleCellList}, + {"Vim.ViewSheetSet", ViewSheetSetList}, + {"Vim.ViewSheet", ViewSheetList}, + {"Vim.ViewSheetInViewSheetSet", ViewSheetInViewSheetSetList}, + {"Vim.ViewInViewSheetSet", ViewInViewSheetSetList}, + {"Vim.ViewInViewSheet", ViewInViewSheetList}, + {"Vim.Site", SiteList}, + {"Vim.Building", BuildingList}, }; // Entity types from table names @@ -3898,389 +3899,389 @@ public DocumentModel(Document d, bool inParallel = true) BuildingEntityTable = Document.GetTable("Vim.Building"); // Initialize entity arrays - AssetBufferName = AssetEntityTable?.GetStringColumnValues("string:BufferName") ?? Array.Empty().ToIArray(); - DisplayUnitSpec = DisplayUnitEntityTable?.GetStringColumnValues("string:Spec") ?? Array.Empty().ToIArray(); - DisplayUnitType = DisplayUnitEntityTable?.GetStringColumnValues("string:Type") ?? Array.Empty().ToIArray(); - DisplayUnitLabel = DisplayUnitEntityTable?.GetStringColumnValues("string:Label") ?? Array.Empty().ToIArray(); - ParameterDescriptorName = ParameterDescriptorEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty().ToIArray(); - ParameterDescriptorGroup = ParameterDescriptorEntityTable?.GetStringColumnValues("string:Group") ?? Array.Empty().ToIArray(); - ParameterDescriptorParameterType = ParameterDescriptorEntityTable?.GetStringColumnValues("string:ParameterType") ?? Array.Empty().ToIArray(); - ParameterDescriptorIsInstance = ParameterDescriptorEntityTable?.GetDataColumnValues("byte:IsInstance") ?? Array.Empty().ToIArray(); - ParameterDescriptorIsShared = ParameterDescriptorEntityTable?.GetDataColumnValues("byte:IsShared") ?? Array.Empty().ToIArray(); - ParameterDescriptorIsReadOnly = ParameterDescriptorEntityTable?.GetDataColumnValues("byte:IsReadOnly") ?? Array.Empty().ToIArray(); - ParameterDescriptorFlags = ParameterDescriptorEntityTable?.GetDataColumnValues("int:Flags") ?? Array.Empty().ToIArray(); - ParameterDescriptorGuid = ParameterDescriptorEntityTable?.GetStringColumnValues("string:Guid") ?? Array.Empty().ToIArray(); - ParameterValue = ParameterEntityTable?.GetStringColumnValues("string:Value") ?? Array.Empty().ToIArray(); - ElementId = (ElementEntityTable?.GetDataColumnValues("long:Id") ?? ElementEntityTable?.GetDataColumnValues("int:Id")?.Select(v => (Int64) v)) ?? Array.Empty().ToIArray(); - ElementType = ElementEntityTable?.GetStringColumnValues("string:Type") ?? Array.Empty().ToIArray(); - ElementName = ElementEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty().ToIArray(); - ElementUniqueId = ElementEntityTable?.GetStringColumnValues("string:UniqueId") ?? Array.Empty().ToIArray(); - ElementLocation_X = ElementEntityTable?.GetDataColumnValues("float:Location.X") ?? Array.Empty().ToIArray(); - ElementLocation_Y = ElementEntityTable?.GetDataColumnValues("float:Location.Y") ?? Array.Empty().ToIArray(); - ElementLocation_Z = ElementEntityTable?.GetDataColumnValues("float:Location.Z") ?? Array.Empty().ToIArray(); - ElementFamilyName = ElementEntityTable?.GetStringColumnValues("string:FamilyName") ?? Array.Empty().ToIArray(); - ElementIsPinned = ElementEntityTable?.GetDataColumnValues("byte:IsPinned") ?? Array.Empty().ToIArray(); - WorksetId = WorksetEntityTable?.GetDataColumnValues("int:Id") ?? Array.Empty().ToIArray(); - WorksetName = WorksetEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty().ToIArray(); - WorksetKind = WorksetEntityTable?.GetStringColumnValues("string:Kind") ?? Array.Empty().ToIArray(); - WorksetIsOpen = WorksetEntityTable?.GetDataColumnValues("byte:IsOpen") ?? Array.Empty().ToIArray(); - WorksetIsEditable = WorksetEntityTable?.GetDataColumnValues("byte:IsEditable") ?? Array.Empty().ToIArray(); - WorksetOwner = WorksetEntityTable?.GetStringColumnValues("string:Owner") ?? Array.Empty().ToIArray(); - WorksetUniqueId = WorksetEntityTable?.GetStringColumnValues("string:UniqueId") ?? Array.Empty().ToIArray(); - AssemblyInstanceAssemblyTypeName = AssemblyInstanceEntityTable?.GetStringColumnValues("string:AssemblyTypeName") ?? Array.Empty().ToIArray(); - AssemblyInstancePosition_X = AssemblyInstanceEntityTable?.GetDataColumnValues("float:Position.X") ?? Array.Empty().ToIArray(); - AssemblyInstancePosition_Y = AssemblyInstanceEntityTable?.GetDataColumnValues("float:Position.Y") ?? Array.Empty().ToIArray(); - AssemblyInstancePosition_Z = AssemblyInstanceEntityTable?.GetDataColumnValues("float:Position.Z") ?? Array.Empty().ToIArray(); - GroupGroupType = GroupEntityTable?.GetStringColumnValues("string:GroupType") ?? Array.Empty().ToIArray(); - GroupPosition_X = GroupEntityTable?.GetDataColumnValues("float:Position.X") ?? Array.Empty().ToIArray(); - GroupPosition_Y = GroupEntityTable?.GetDataColumnValues("float:Position.Y") ?? Array.Empty().ToIArray(); - GroupPosition_Z = GroupEntityTable?.GetDataColumnValues("float:Position.Z") ?? Array.Empty().ToIArray(); - DesignOptionIsPrimary = DesignOptionEntityTable?.GetDataColumnValues("byte:IsPrimary") ?? Array.Empty().ToIArray(); - LevelElevation = LevelEntityTable?.GetDataColumnValues("double:Elevation") ?? Array.Empty().ToIArray(); - RoomBaseOffset = RoomEntityTable?.GetDataColumnValues("double:BaseOffset") ?? Array.Empty().ToIArray(); - RoomLimitOffset = RoomEntityTable?.GetDataColumnValues("double:LimitOffset") ?? Array.Empty().ToIArray(); - RoomUnboundedHeight = RoomEntityTable?.GetDataColumnValues("double:UnboundedHeight") ?? Array.Empty().ToIArray(); - RoomVolume = RoomEntityTable?.GetDataColumnValues("double:Volume") ?? Array.Empty().ToIArray(); - RoomPerimeter = RoomEntityTable?.GetDataColumnValues("double:Perimeter") ?? Array.Empty().ToIArray(); - RoomArea = RoomEntityTable?.GetDataColumnValues("double:Area") ?? Array.Empty().ToIArray(); - RoomNumber = RoomEntityTable?.GetStringColumnValues("string:Number") ?? Array.Empty().ToIArray(); - BimDocumentTitle = BimDocumentEntityTable?.GetStringColumnValues("string:Title") ?? Array.Empty().ToIArray(); - BimDocumentIsMetric = BimDocumentEntityTable?.GetDataColumnValues("byte:IsMetric") ?? Array.Empty().ToIArray(); - BimDocumentGuid = BimDocumentEntityTable?.GetStringColumnValues("string:Guid") ?? Array.Empty().ToIArray(); - BimDocumentNumSaves = BimDocumentEntityTable?.GetDataColumnValues("int:NumSaves") ?? Array.Empty().ToIArray(); - BimDocumentIsLinked = BimDocumentEntityTable?.GetDataColumnValues("byte:IsLinked") ?? Array.Empty().ToIArray(); - BimDocumentIsDetached = BimDocumentEntityTable?.GetDataColumnValues("byte:IsDetached") ?? Array.Empty().ToIArray(); - BimDocumentIsWorkshared = BimDocumentEntityTable?.GetDataColumnValues("byte:IsWorkshared") ?? Array.Empty().ToIArray(); - BimDocumentPathName = BimDocumentEntityTable?.GetStringColumnValues("string:PathName") ?? Array.Empty().ToIArray(); - BimDocumentLatitude = BimDocumentEntityTable?.GetDataColumnValues("double:Latitude") ?? Array.Empty().ToIArray(); - BimDocumentLongitude = BimDocumentEntityTable?.GetDataColumnValues("double:Longitude") ?? Array.Empty().ToIArray(); - BimDocumentTimeZone = BimDocumentEntityTable?.GetDataColumnValues("double:TimeZone") ?? Array.Empty().ToIArray(); - BimDocumentPlaceName = BimDocumentEntityTable?.GetStringColumnValues("string:PlaceName") ?? Array.Empty().ToIArray(); - BimDocumentWeatherStationName = BimDocumentEntityTable?.GetStringColumnValues("string:WeatherStationName") ?? Array.Empty().ToIArray(); - BimDocumentElevation = BimDocumentEntityTable?.GetDataColumnValues("double:Elevation") ?? Array.Empty().ToIArray(); - BimDocumentProjectLocation = BimDocumentEntityTable?.GetStringColumnValues("string:ProjectLocation") ?? Array.Empty().ToIArray(); - BimDocumentIssueDate = BimDocumentEntityTable?.GetStringColumnValues("string:IssueDate") ?? Array.Empty().ToIArray(); - BimDocumentStatus = BimDocumentEntityTable?.GetStringColumnValues("string:Status") ?? Array.Empty().ToIArray(); - BimDocumentClientName = BimDocumentEntityTable?.GetStringColumnValues("string:ClientName") ?? Array.Empty().ToIArray(); - BimDocumentAddress = BimDocumentEntityTable?.GetStringColumnValues("string:Address") ?? Array.Empty().ToIArray(); - BimDocumentName = BimDocumentEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty().ToIArray(); - BimDocumentNumber = BimDocumentEntityTable?.GetStringColumnValues("string:Number") ?? Array.Empty().ToIArray(); - BimDocumentAuthor = BimDocumentEntityTable?.GetStringColumnValues("string:Author") ?? Array.Empty().ToIArray(); - BimDocumentBuildingName = BimDocumentEntityTable?.GetStringColumnValues("string:BuildingName") ?? Array.Empty().ToIArray(); - BimDocumentOrganizationName = BimDocumentEntityTable?.GetStringColumnValues("string:OrganizationName") ?? Array.Empty().ToIArray(); - BimDocumentOrganizationDescription = BimDocumentEntityTable?.GetStringColumnValues("string:OrganizationDescription") ?? Array.Empty().ToIArray(); - BimDocumentProduct = BimDocumentEntityTable?.GetStringColumnValues("string:Product") ?? Array.Empty().ToIArray(); - BimDocumentVersion = BimDocumentEntityTable?.GetStringColumnValues("string:Version") ?? Array.Empty().ToIArray(); - BimDocumentUser = BimDocumentEntityTable?.GetStringColumnValues("string:User") ?? Array.Empty().ToIArray(); - PhaseOrderInBimDocumentOrderIndex = PhaseOrderInBimDocumentEntityTable?.GetDataColumnValues("int:OrderIndex") ?? Array.Empty().ToIArray(); - CategoryName = CategoryEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty().ToIArray(); - CategoryId = (CategoryEntityTable?.GetDataColumnValues("long:Id") ?? CategoryEntityTable?.GetDataColumnValues("int:Id")?.Select(v => (Int64) v)) ?? Array.Empty().ToIArray(); - CategoryCategoryType = CategoryEntityTable?.GetStringColumnValues("string:CategoryType") ?? Array.Empty().ToIArray(); - CategoryLineColor_X = CategoryEntityTable?.GetDataColumnValues("double:LineColor.X") ?? Array.Empty().ToIArray(); - CategoryLineColor_Y = CategoryEntityTable?.GetDataColumnValues("double:LineColor.Y") ?? Array.Empty().ToIArray(); - CategoryLineColor_Z = CategoryEntityTable?.GetDataColumnValues("double:LineColor.Z") ?? Array.Empty().ToIArray(); - CategoryBuiltInCategory = CategoryEntityTable?.GetStringColumnValues("string:BuiltInCategory") ?? Array.Empty().ToIArray(); - FamilyStructuralMaterialType = FamilyEntityTable?.GetStringColumnValues("string:StructuralMaterialType") ?? Array.Empty().ToIArray(); - FamilyStructuralSectionShape = FamilyEntityTable?.GetStringColumnValues("string:StructuralSectionShape") ?? Array.Empty().ToIArray(); - FamilyIsSystemFamily = FamilyEntityTable?.GetDataColumnValues("byte:IsSystemFamily") ?? Array.Empty().ToIArray(); - FamilyIsInPlace = FamilyEntityTable?.GetDataColumnValues("byte:IsInPlace") ?? Array.Empty().ToIArray(); - FamilyTypeIsSystemFamilyType = FamilyTypeEntityTable?.GetDataColumnValues("byte:IsSystemFamilyType") ?? Array.Empty().ToIArray(); - FamilyInstanceFacingFlipped = FamilyInstanceEntityTable?.GetDataColumnValues("byte:FacingFlipped") ?? Array.Empty().ToIArray(); - FamilyInstanceFacingOrientation_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:FacingOrientation.X") ?? Array.Empty().ToIArray(); - FamilyInstanceFacingOrientation_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:FacingOrientation.Y") ?? Array.Empty().ToIArray(); - FamilyInstanceFacingOrientation_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:FacingOrientation.Z") ?? Array.Empty().ToIArray(); - FamilyInstanceHandFlipped = FamilyInstanceEntityTable?.GetDataColumnValues("byte:HandFlipped") ?? Array.Empty().ToIArray(); - FamilyInstanceMirrored = FamilyInstanceEntityTable?.GetDataColumnValues("byte:Mirrored") ?? Array.Empty().ToIArray(); - FamilyInstanceHasModifiedGeometry = FamilyInstanceEntityTable?.GetDataColumnValues("byte:HasModifiedGeometry") ?? Array.Empty().ToIArray(); - FamilyInstanceScale = FamilyInstanceEntityTable?.GetDataColumnValues("float:Scale") ?? Array.Empty().ToIArray(); - FamilyInstanceBasisX_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisX.X") ?? Array.Empty().ToIArray(); - FamilyInstanceBasisX_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisX.Y") ?? Array.Empty().ToIArray(); - FamilyInstanceBasisX_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisX.Z") ?? Array.Empty().ToIArray(); - FamilyInstanceBasisY_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisY.X") ?? Array.Empty().ToIArray(); - FamilyInstanceBasisY_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisY.Y") ?? Array.Empty().ToIArray(); - FamilyInstanceBasisY_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisY.Z") ?? Array.Empty().ToIArray(); - FamilyInstanceBasisZ_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisZ.X") ?? Array.Empty().ToIArray(); - FamilyInstanceBasisZ_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisZ.Y") ?? Array.Empty().ToIArray(); - FamilyInstanceBasisZ_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisZ.Z") ?? Array.Empty().ToIArray(); - FamilyInstanceTranslation_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:Translation.X") ?? Array.Empty().ToIArray(); - FamilyInstanceTranslation_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:Translation.Y") ?? Array.Empty().ToIArray(); - FamilyInstanceTranslation_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:Translation.Z") ?? Array.Empty().ToIArray(); - FamilyInstanceHandOrientation_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:HandOrientation.X") ?? Array.Empty().ToIArray(); - FamilyInstanceHandOrientation_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:HandOrientation.Y") ?? Array.Empty().ToIArray(); - FamilyInstanceHandOrientation_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:HandOrientation.Z") ?? Array.Empty().ToIArray(); - ViewTitle = ViewEntityTable?.GetStringColumnValues("string:Title") ?? Array.Empty().ToIArray(); - ViewViewType = ViewEntityTable?.GetStringColumnValues("string:ViewType") ?? Array.Empty().ToIArray(); - ViewUp_X = ViewEntityTable?.GetDataColumnValues("double:Up.X") ?? Array.Empty().ToIArray(); - ViewUp_Y = ViewEntityTable?.GetDataColumnValues("double:Up.Y") ?? Array.Empty().ToIArray(); - ViewUp_Z = ViewEntityTable?.GetDataColumnValues("double:Up.Z") ?? Array.Empty().ToIArray(); - ViewRight_X = ViewEntityTable?.GetDataColumnValues("double:Right.X") ?? Array.Empty().ToIArray(); - ViewRight_Y = ViewEntityTable?.GetDataColumnValues("double:Right.Y") ?? Array.Empty().ToIArray(); - ViewRight_Z = ViewEntityTable?.GetDataColumnValues("double:Right.Z") ?? Array.Empty().ToIArray(); - ViewOrigin_X = ViewEntityTable?.GetDataColumnValues("double:Origin.X") ?? Array.Empty().ToIArray(); - ViewOrigin_Y = ViewEntityTable?.GetDataColumnValues("double:Origin.Y") ?? Array.Empty().ToIArray(); - ViewOrigin_Z = ViewEntityTable?.GetDataColumnValues("double:Origin.Z") ?? Array.Empty().ToIArray(); - ViewViewDirection_X = ViewEntityTable?.GetDataColumnValues("double:ViewDirection.X") ?? Array.Empty().ToIArray(); - ViewViewDirection_Y = ViewEntityTable?.GetDataColumnValues("double:ViewDirection.Y") ?? Array.Empty().ToIArray(); - ViewViewDirection_Z = ViewEntityTable?.GetDataColumnValues("double:ViewDirection.Z") ?? Array.Empty().ToIArray(); - ViewViewPosition_X = ViewEntityTable?.GetDataColumnValues("double:ViewPosition.X") ?? Array.Empty().ToIArray(); - ViewViewPosition_Y = ViewEntityTable?.GetDataColumnValues("double:ViewPosition.Y") ?? Array.Empty().ToIArray(); - ViewViewPosition_Z = ViewEntityTable?.GetDataColumnValues("double:ViewPosition.Z") ?? Array.Empty().ToIArray(); - ViewScale = ViewEntityTable?.GetDataColumnValues("double:Scale") ?? Array.Empty().ToIArray(); - ViewOutline_Min_X = ViewEntityTable?.GetDataColumnValues("double:Outline.Min.X") ?? Array.Empty().ToIArray(); - ViewOutline_Min_Y = ViewEntityTable?.GetDataColumnValues("double:Outline.Min.Y") ?? Array.Empty().ToIArray(); - ViewOutline_Max_X = ViewEntityTable?.GetDataColumnValues("double:Outline.Max.X") ?? Array.Empty().ToIArray(); - ViewOutline_Max_Y = ViewEntityTable?.GetDataColumnValues("double:Outline.Max.Y") ?? Array.Empty().ToIArray(); - ViewDetailLevel = ViewEntityTable?.GetDataColumnValues("int:DetailLevel") ?? Array.Empty().ToIArray(); - LevelInViewExtents_Min_X = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Min.X") ?? Array.Empty().ToIArray(); - LevelInViewExtents_Min_Y = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Min.Y") ?? Array.Empty().ToIArray(); - LevelInViewExtents_Min_Z = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Min.Z") ?? Array.Empty().ToIArray(); - LevelInViewExtents_Max_X = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Max.X") ?? Array.Empty().ToIArray(); - LevelInViewExtents_Max_Y = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Max.Y") ?? Array.Empty().ToIArray(); - LevelInViewExtents_Max_Z = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Max.Z") ?? Array.Empty().ToIArray(); - CameraId = CameraEntityTable?.GetDataColumnValues("int:Id") ?? Array.Empty().ToIArray(); - CameraIsPerspective = CameraEntityTable?.GetDataColumnValues("int:IsPerspective") ?? Array.Empty().ToIArray(); - CameraVerticalExtent = CameraEntityTable?.GetDataColumnValues("double:VerticalExtent") ?? Array.Empty().ToIArray(); - CameraHorizontalExtent = CameraEntityTable?.GetDataColumnValues("double:HorizontalExtent") ?? Array.Empty().ToIArray(); - CameraFarDistance = CameraEntityTable?.GetDataColumnValues("double:FarDistance") ?? Array.Empty().ToIArray(); - CameraNearDistance = CameraEntityTable?.GetDataColumnValues("double:NearDistance") ?? Array.Empty().ToIArray(); - CameraTargetDistance = CameraEntityTable?.GetDataColumnValues("double:TargetDistance") ?? Array.Empty().ToIArray(); - CameraRightOffset = CameraEntityTable?.GetDataColumnValues("double:RightOffset") ?? Array.Empty().ToIArray(); - CameraUpOffset = CameraEntityTable?.GetDataColumnValues("double:UpOffset") ?? Array.Empty().ToIArray(); - MaterialName = MaterialEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty().ToIArray(); - MaterialMaterialCategory = MaterialEntityTable?.GetStringColumnValues("string:MaterialCategory") ?? Array.Empty().ToIArray(); - MaterialColor_X = MaterialEntityTable?.GetDataColumnValues("double:Color.X") ?? Array.Empty().ToIArray(); - MaterialColor_Y = MaterialEntityTable?.GetDataColumnValues("double:Color.Y") ?? Array.Empty().ToIArray(); - MaterialColor_Z = MaterialEntityTable?.GetDataColumnValues("double:Color.Z") ?? Array.Empty().ToIArray(); - MaterialColorUvScaling_X = MaterialEntityTable?.GetDataColumnValues("double:ColorUvScaling.X") ?? Array.Empty().ToIArray(); - MaterialColorUvScaling_Y = MaterialEntityTable?.GetDataColumnValues("double:ColorUvScaling.Y") ?? Array.Empty().ToIArray(); - MaterialColorUvOffset_X = MaterialEntityTable?.GetDataColumnValues("double:ColorUvOffset.X") ?? Array.Empty().ToIArray(); - MaterialColorUvOffset_Y = MaterialEntityTable?.GetDataColumnValues("double:ColorUvOffset.Y") ?? Array.Empty().ToIArray(); - MaterialNormalUvScaling_X = MaterialEntityTable?.GetDataColumnValues("double:NormalUvScaling.X") ?? Array.Empty().ToIArray(); - MaterialNormalUvScaling_Y = MaterialEntityTable?.GetDataColumnValues("double:NormalUvScaling.Y") ?? Array.Empty().ToIArray(); - MaterialNormalUvOffset_X = MaterialEntityTable?.GetDataColumnValues("double:NormalUvOffset.X") ?? Array.Empty().ToIArray(); - MaterialNormalUvOffset_Y = MaterialEntityTable?.GetDataColumnValues("double:NormalUvOffset.Y") ?? Array.Empty().ToIArray(); - MaterialNormalAmount = MaterialEntityTable?.GetDataColumnValues("double:NormalAmount") ?? Array.Empty().ToIArray(); - MaterialGlossiness = MaterialEntityTable?.GetDataColumnValues("double:Glossiness") ?? Array.Empty().ToIArray(); - MaterialSmoothness = MaterialEntityTable?.GetDataColumnValues("double:Smoothness") ?? Array.Empty().ToIArray(); - MaterialTransparency = MaterialEntityTable?.GetDataColumnValues("double:Transparency") ?? Array.Empty().ToIArray(); - MaterialInElementArea = MaterialInElementEntityTable?.GetDataColumnValues("double:Area") ?? Array.Empty().ToIArray(); - MaterialInElementVolume = MaterialInElementEntityTable?.GetDataColumnValues("double:Volume") ?? Array.Empty().ToIArray(); - MaterialInElementIsPaint = MaterialInElementEntityTable?.GetDataColumnValues("byte:IsPaint") ?? Array.Empty().ToIArray(); - CompoundStructureLayerOrderIndex = CompoundStructureLayerEntityTable?.GetDataColumnValues("int:OrderIndex") ?? Array.Empty().ToIArray(); - CompoundStructureLayerWidth = CompoundStructureLayerEntityTable?.GetDataColumnValues("double:Width") ?? Array.Empty().ToIArray(); - CompoundStructureLayerMaterialFunctionAssignment = CompoundStructureLayerEntityTable?.GetStringColumnValues("string:MaterialFunctionAssignment") ?? Array.Empty().ToIArray(); - CompoundStructureWidth = CompoundStructureEntityTable?.GetDataColumnValues("double:Width") ?? Array.Empty().ToIArray(); - GeometryBox_Min_X = GeometryEntityTable?.GetDataColumnValues("float:Box.Min.X") ?? Array.Empty().ToIArray(); - GeometryBox_Min_Y = GeometryEntityTable?.GetDataColumnValues("float:Box.Min.Y") ?? Array.Empty().ToIArray(); - GeometryBox_Min_Z = GeometryEntityTable?.GetDataColumnValues("float:Box.Min.Z") ?? Array.Empty().ToIArray(); - GeometryBox_Max_X = GeometryEntityTable?.GetDataColumnValues("float:Box.Max.X") ?? Array.Empty().ToIArray(); - GeometryBox_Max_Y = GeometryEntityTable?.GetDataColumnValues("float:Box.Max.Y") ?? Array.Empty().ToIArray(); - GeometryBox_Max_Z = GeometryEntityTable?.GetDataColumnValues("float:Box.Max.Z") ?? Array.Empty().ToIArray(); - GeometryVertexCount = GeometryEntityTable?.GetDataColumnValues("int:VertexCount") ?? Array.Empty().ToIArray(); - GeometryFaceCount = GeometryEntityTable?.GetDataColumnValues("int:FaceCount") ?? Array.Empty().ToIArray(); - SystemSystemType = SystemEntityTable?.GetDataColumnValues("int:SystemType") ?? Array.Empty().ToIArray(); - ElementInSystemRoles = ElementInSystemEntityTable?.GetDataColumnValues("int:Roles") ?? Array.Empty().ToIArray(); - WarningGuid = WarningEntityTable?.GetStringColumnValues("string:Guid") ?? Array.Empty().ToIArray(); - WarningSeverity = WarningEntityTable?.GetStringColumnValues("string:Severity") ?? Array.Empty().ToIArray(); - WarningDescription = WarningEntityTable?.GetStringColumnValues("string:Description") ?? Array.Empty().ToIArray(); - BasePointIsSurveyPoint = BasePointEntityTable?.GetDataColumnValues("byte:IsSurveyPoint") ?? Array.Empty().ToIArray(); - BasePointPosition_X = BasePointEntityTable?.GetDataColumnValues("double:Position.X") ?? Array.Empty().ToIArray(); - BasePointPosition_Y = BasePointEntityTable?.GetDataColumnValues("double:Position.Y") ?? Array.Empty().ToIArray(); - BasePointPosition_Z = BasePointEntityTable?.GetDataColumnValues("double:Position.Z") ?? Array.Empty().ToIArray(); - BasePointSharedPosition_X = BasePointEntityTable?.GetDataColumnValues("double:SharedPosition.X") ?? Array.Empty().ToIArray(); - BasePointSharedPosition_Y = BasePointEntityTable?.GetDataColumnValues("double:SharedPosition.Y") ?? Array.Empty().ToIArray(); - BasePointSharedPosition_Z = BasePointEntityTable?.GetDataColumnValues("double:SharedPosition.Z") ?? Array.Empty().ToIArray(); - PhaseFilterNew = PhaseFilterEntityTable?.GetDataColumnValues("int:New") ?? Array.Empty().ToIArray(); - PhaseFilterExisting = PhaseFilterEntityTable?.GetDataColumnValues("int:Existing") ?? Array.Empty().ToIArray(); - PhaseFilterDemolished = PhaseFilterEntityTable?.GetDataColumnValues("int:Demolished") ?? Array.Empty().ToIArray(); - PhaseFilterTemporary = PhaseFilterEntityTable?.GetDataColumnValues("int:Temporary") ?? Array.Empty().ToIArray(); - GridStartPoint_X = GridEntityTable?.GetDataColumnValues("double:StartPoint.X") ?? Array.Empty().ToIArray(); - GridStartPoint_Y = GridEntityTable?.GetDataColumnValues("double:StartPoint.Y") ?? Array.Empty().ToIArray(); - GridStartPoint_Z = GridEntityTable?.GetDataColumnValues("double:StartPoint.Z") ?? Array.Empty().ToIArray(); - GridEndPoint_X = GridEntityTable?.GetDataColumnValues("double:EndPoint.X") ?? Array.Empty().ToIArray(); - GridEndPoint_Y = GridEntityTable?.GetDataColumnValues("double:EndPoint.Y") ?? Array.Empty().ToIArray(); - GridEndPoint_Z = GridEntityTable?.GetDataColumnValues("double:EndPoint.Z") ?? Array.Empty().ToIArray(); - GridIsCurved = GridEntityTable?.GetDataColumnValues("byte:IsCurved") ?? Array.Empty().ToIArray(); - GridExtents_Min_X = GridEntityTable?.GetDataColumnValues("double:Extents.Min.X") ?? Array.Empty().ToIArray(); - GridExtents_Min_Y = GridEntityTable?.GetDataColumnValues("double:Extents.Min.Y") ?? Array.Empty().ToIArray(); - GridExtents_Min_Z = GridEntityTable?.GetDataColumnValues("double:Extents.Min.Z") ?? Array.Empty().ToIArray(); - GridExtents_Max_X = GridEntityTable?.GetDataColumnValues("double:Extents.Max.X") ?? Array.Empty().ToIArray(); - GridExtents_Max_Y = GridEntityTable?.GetDataColumnValues("double:Extents.Max.Y") ?? Array.Empty().ToIArray(); - GridExtents_Max_Z = GridEntityTable?.GetDataColumnValues("double:Extents.Max.Z") ?? Array.Empty().ToIArray(); - AreaValue = AreaEntityTable?.GetDataColumnValues("double:Value") ?? Array.Empty().ToIArray(); - AreaPerimeter = AreaEntityTable?.GetDataColumnValues("double:Perimeter") ?? Array.Empty().ToIArray(); - AreaNumber = AreaEntityTable?.GetStringColumnValues("string:Number") ?? Array.Empty().ToIArray(); - AreaIsGrossInterior = AreaEntityTable?.GetDataColumnValues("byte:IsGrossInterior") ?? Array.Empty().ToIArray(); - AreaSchemeIsGrossBuildingArea = AreaSchemeEntityTable?.GetDataColumnValues("byte:IsGrossBuildingArea") ?? Array.Empty().ToIArray(); - ScheduleColumnName = ScheduleColumnEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty().ToIArray(); - ScheduleColumnColumnIndex = ScheduleColumnEntityTable?.GetDataColumnValues("int:ColumnIndex") ?? Array.Empty().ToIArray(); - ScheduleCellValue = ScheduleCellEntityTable?.GetStringColumnValues("string:Value") ?? Array.Empty().ToIArray(); - ScheduleCellRowIndex = ScheduleCellEntityTable?.GetDataColumnValues("int:RowIndex") ?? Array.Empty().ToIArray(); - SiteLatitude = SiteEntityTable?.GetDataColumnValues("double:Latitude") ?? Array.Empty().ToIArray(); - SiteLongitude = SiteEntityTable?.GetDataColumnValues("double:Longitude") ?? Array.Empty().ToIArray(); - SiteAddress = SiteEntityTable?.GetStringColumnValues("string:Address") ?? Array.Empty().ToIArray(); - SiteElevation = SiteEntityTable?.GetDataColumnValues("double:Elevation") ?? Array.Empty().ToIArray(); - SiteNumber = SiteEntityTable?.GetStringColumnValues("string:Number") ?? Array.Empty().ToIArray(); - BuildingElevation = BuildingEntityTable?.GetDataColumnValues("double:Elevation") ?? Array.Empty().ToIArray(); - BuildingTerrainElevation = BuildingEntityTable?.GetDataColumnValues("double:TerrainElevation") ?? Array.Empty().ToIArray(); - BuildingAddress = BuildingEntityTable?.GetStringColumnValues("string:Address") ?? Array.Empty().ToIArray(); + AssetBufferName = AssetEntityTable?.GetStringColumnValues("string:BufferName") ?? Array.Empty(); + DisplayUnitSpec = DisplayUnitEntityTable?.GetStringColumnValues("string:Spec") ?? Array.Empty(); + DisplayUnitType = DisplayUnitEntityTable?.GetStringColumnValues("string:Type") ?? Array.Empty(); + DisplayUnitLabel = DisplayUnitEntityTable?.GetStringColumnValues("string:Label") ?? Array.Empty(); + ParameterDescriptorName = ParameterDescriptorEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty(); + ParameterDescriptorGroup = ParameterDescriptorEntityTable?.GetStringColumnValues("string:Group") ?? Array.Empty(); + ParameterDescriptorParameterType = ParameterDescriptorEntityTable?.GetStringColumnValues("string:ParameterType") ?? Array.Empty(); + ParameterDescriptorIsInstance = ParameterDescriptorEntityTable?.GetDataColumnValues("byte:IsInstance") ?? Array.Empty(); + ParameterDescriptorIsShared = ParameterDescriptorEntityTable?.GetDataColumnValues("byte:IsShared") ?? Array.Empty(); + ParameterDescriptorIsReadOnly = ParameterDescriptorEntityTable?.GetDataColumnValues("byte:IsReadOnly") ?? Array.Empty(); + ParameterDescriptorFlags = ParameterDescriptorEntityTable?.GetDataColumnValues("int:Flags") ?? Array.Empty(); + ParameterDescriptorGuid = ParameterDescriptorEntityTable?.GetStringColumnValues("string:Guid") ?? Array.Empty(); + ParameterValue = ParameterEntityTable?.GetStringColumnValues("string:Value") ?? Array.Empty(); + ElementId = (ElementEntityTable?.GetDataColumnValues("long:Id") ?? ElementEntityTable?.GetDataColumnValues("int:Id")?.Select(v => (Int64) v).ToArray()) ?? Array.Empty(); + ElementType = ElementEntityTable?.GetStringColumnValues("string:Type") ?? Array.Empty(); + ElementName = ElementEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty(); + ElementUniqueId = ElementEntityTable?.GetStringColumnValues("string:UniqueId") ?? Array.Empty(); + ElementLocation_X = ElementEntityTable?.GetDataColumnValues("float:Location.X") ?? Array.Empty(); + ElementLocation_Y = ElementEntityTable?.GetDataColumnValues("float:Location.Y") ?? Array.Empty(); + ElementLocation_Z = ElementEntityTable?.GetDataColumnValues("float:Location.Z") ?? Array.Empty(); + ElementFamilyName = ElementEntityTable?.GetStringColumnValues("string:FamilyName") ?? Array.Empty(); + ElementIsPinned = ElementEntityTable?.GetDataColumnValues("byte:IsPinned") ?? Array.Empty(); + WorksetId = WorksetEntityTable?.GetDataColumnValues("int:Id") ?? Array.Empty(); + WorksetName = WorksetEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty(); + WorksetKind = WorksetEntityTable?.GetStringColumnValues("string:Kind") ?? Array.Empty(); + WorksetIsOpen = WorksetEntityTable?.GetDataColumnValues("byte:IsOpen") ?? Array.Empty(); + WorksetIsEditable = WorksetEntityTable?.GetDataColumnValues("byte:IsEditable") ?? Array.Empty(); + WorksetOwner = WorksetEntityTable?.GetStringColumnValues("string:Owner") ?? Array.Empty(); + WorksetUniqueId = WorksetEntityTable?.GetStringColumnValues("string:UniqueId") ?? Array.Empty(); + AssemblyInstanceAssemblyTypeName = AssemblyInstanceEntityTable?.GetStringColumnValues("string:AssemblyTypeName") ?? Array.Empty(); + AssemblyInstancePosition_X = AssemblyInstanceEntityTable?.GetDataColumnValues("float:Position.X") ?? Array.Empty(); + AssemblyInstancePosition_Y = AssemblyInstanceEntityTable?.GetDataColumnValues("float:Position.Y") ?? Array.Empty(); + AssemblyInstancePosition_Z = AssemblyInstanceEntityTable?.GetDataColumnValues("float:Position.Z") ?? Array.Empty(); + GroupGroupType = GroupEntityTable?.GetStringColumnValues("string:GroupType") ?? Array.Empty(); + GroupPosition_X = GroupEntityTable?.GetDataColumnValues("float:Position.X") ?? Array.Empty(); + GroupPosition_Y = GroupEntityTable?.GetDataColumnValues("float:Position.Y") ?? Array.Empty(); + GroupPosition_Z = GroupEntityTable?.GetDataColumnValues("float:Position.Z") ?? Array.Empty(); + DesignOptionIsPrimary = DesignOptionEntityTable?.GetDataColumnValues("byte:IsPrimary") ?? Array.Empty(); + LevelElevation = LevelEntityTable?.GetDataColumnValues("double:Elevation") ?? Array.Empty(); + RoomBaseOffset = RoomEntityTable?.GetDataColumnValues("double:BaseOffset") ?? Array.Empty(); + RoomLimitOffset = RoomEntityTable?.GetDataColumnValues("double:LimitOffset") ?? Array.Empty(); + RoomUnboundedHeight = RoomEntityTable?.GetDataColumnValues("double:UnboundedHeight") ?? Array.Empty(); + RoomVolume = RoomEntityTable?.GetDataColumnValues("double:Volume") ?? Array.Empty(); + RoomPerimeter = RoomEntityTable?.GetDataColumnValues("double:Perimeter") ?? Array.Empty(); + RoomArea = RoomEntityTable?.GetDataColumnValues("double:Area") ?? Array.Empty(); + RoomNumber = RoomEntityTable?.GetStringColumnValues("string:Number") ?? Array.Empty(); + BimDocumentTitle = BimDocumentEntityTable?.GetStringColumnValues("string:Title") ?? Array.Empty(); + BimDocumentIsMetric = BimDocumentEntityTable?.GetDataColumnValues("byte:IsMetric") ?? Array.Empty(); + BimDocumentGuid = BimDocumentEntityTable?.GetStringColumnValues("string:Guid") ?? Array.Empty(); + BimDocumentNumSaves = BimDocumentEntityTable?.GetDataColumnValues("int:NumSaves") ?? Array.Empty(); + BimDocumentIsLinked = BimDocumentEntityTable?.GetDataColumnValues("byte:IsLinked") ?? Array.Empty(); + BimDocumentIsDetached = BimDocumentEntityTable?.GetDataColumnValues("byte:IsDetached") ?? Array.Empty(); + BimDocumentIsWorkshared = BimDocumentEntityTable?.GetDataColumnValues("byte:IsWorkshared") ?? Array.Empty(); + BimDocumentPathName = BimDocumentEntityTable?.GetStringColumnValues("string:PathName") ?? Array.Empty(); + BimDocumentLatitude = BimDocumentEntityTable?.GetDataColumnValues("double:Latitude") ?? Array.Empty(); + BimDocumentLongitude = BimDocumentEntityTable?.GetDataColumnValues("double:Longitude") ?? Array.Empty(); + BimDocumentTimeZone = BimDocumentEntityTable?.GetDataColumnValues("double:TimeZone") ?? Array.Empty(); + BimDocumentPlaceName = BimDocumentEntityTable?.GetStringColumnValues("string:PlaceName") ?? Array.Empty(); + BimDocumentWeatherStationName = BimDocumentEntityTable?.GetStringColumnValues("string:WeatherStationName") ?? Array.Empty(); + BimDocumentElevation = BimDocumentEntityTable?.GetDataColumnValues("double:Elevation") ?? Array.Empty(); + BimDocumentProjectLocation = BimDocumentEntityTable?.GetStringColumnValues("string:ProjectLocation") ?? Array.Empty(); + BimDocumentIssueDate = BimDocumentEntityTable?.GetStringColumnValues("string:IssueDate") ?? Array.Empty(); + BimDocumentStatus = BimDocumentEntityTable?.GetStringColumnValues("string:Status") ?? Array.Empty(); + BimDocumentClientName = BimDocumentEntityTable?.GetStringColumnValues("string:ClientName") ?? Array.Empty(); + BimDocumentAddress = BimDocumentEntityTable?.GetStringColumnValues("string:Address") ?? Array.Empty(); + BimDocumentName = BimDocumentEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty(); + BimDocumentNumber = BimDocumentEntityTable?.GetStringColumnValues("string:Number") ?? Array.Empty(); + BimDocumentAuthor = BimDocumentEntityTable?.GetStringColumnValues("string:Author") ?? Array.Empty(); + BimDocumentBuildingName = BimDocumentEntityTable?.GetStringColumnValues("string:BuildingName") ?? Array.Empty(); + BimDocumentOrganizationName = BimDocumentEntityTable?.GetStringColumnValues("string:OrganizationName") ?? Array.Empty(); + BimDocumentOrganizationDescription = BimDocumentEntityTable?.GetStringColumnValues("string:OrganizationDescription") ?? Array.Empty(); + BimDocumentProduct = BimDocumentEntityTable?.GetStringColumnValues("string:Product") ?? Array.Empty(); + BimDocumentVersion = BimDocumentEntityTable?.GetStringColumnValues("string:Version") ?? Array.Empty(); + BimDocumentUser = BimDocumentEntityTable?.GetStringColumnValues("string:User") ?? Array.Empty(); + PhaseOrderInBimDocumentOrderIndex = PhaseOrderInBimDocumentEntityTable?.GetDataColumnValues("int:OrderIndex") ?? Array.Empty(); + CategoryName = CategoryEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty(); + CategoryId = (CategoryEntityTable?.GetDataColumnValues("long:Id") ?? CategoryEntityTable?.GetDataColumnValues("int:Id")?.Select(v => (Int64) v).ToArray()) ?? Array.Empty(); + CategoryCategoryType = CategoryEntityTable?.GetStringColumnValues("string:CategoryType") ?? Array.Empty(); + CategoryLineColor_X = CategoryEntityTable?.GetDataColumnValues("double:LineColor.X") ?? Array.Empty(); + CategoryLineColor_Y = CategoryEntityTable?.GetDataColumnValues("double:LineColor.Y") ?? Array.Empty(); + CategoryLineColor_Z = CategoryEntityTable?.GetDataColumnValues("double:LineColor.Z") ?? Array.Empty(); + CategoryBuiltInCategory = CategoryEntityTable?.GetStringColumnValues("string:BuiltInCategory") ?? Array.Empty(); + FamilyStructuralMaterialType = FamilyEntityTable?.GetStringColumnValues("string:StructuralMaterialType") ?? Array.Empty(); + FamilyStructuralSectionShape = FamilyEntityTable?.GetStringColumnValues("string:StructuralSectionShape") ?? Array.Empty(); + FamilyIsSystemFamily = FamilyEntityTable?.GetDataColumnValues("byte:IsSystemFamily") ?? Array.Empty(); + FamilyIsInPlace = FamilyEntityTable?.GetDataColumnValues("byte:IsInPlace") ?? Array.Empty(); + FamilyTypeIsSystemFamilyType = FamilyTypeEntityTable?.GetDataColumnValues("byte:IsSystemFamilyType") ?? Array.Empty(); + FamilyInstanceFacingFlipped = FamilyInstanceEntityTable?.GetDataColumnValues("byte:FacingFlipped") ?? Array.Empty(); + FamilyInstanceFacingOrientation_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:FacingOrientation.X") ?? Array.Empty(); + FamilyInstanceFacingOrientation_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:FacingOrientation.Y") ?? Array.Empty(); + FamilyInstanceFacingOrientation_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:FacingOrientation.Z") ?? Array.Empty(); + FamilyInstanceHandFlipped = FamilyInstanceEntityTable?.GetDataColumnValues("byte:HandFlipped") ?? Array.Empty(); + FamilyInstanceMirrored = FamilyInstanceEntityTable?.GetDataColumnValues("byte:Mirrored") ?? Array.Empty(); + FamilyInstanceHasModifiedGeometry = FamilyInstanceEntityTable?.GetDataColumnValues("byte:HasModifiedGeometry") ?? Array.Empty(); + FamilyInstanceScale = FamilyInstanceEntityTable?.GetDataColumnValues("float:Scale") ?? Array.Empty(); + FamilyInstanceBasisX_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisX.X") ?? Array.Empty(); + FamilyInstanceBasisX_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisX.Y") ?? Array.Empty(); + FamilyInstanceBasisX_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisX.Z") ?? Array.Empty(); + FamilyInstanceBasisY_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisY.X") ?? Array.Empty(); + FamilyInstanceBasisY_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisY.Y") ?? Array.Empty(); + FamilyInstanceBasisY_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisY.Z") ?? Array.Empty(); + FamilyInstanceBasisZ_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisZ.X") ?? Array.Empty(); + FamilyInstanceBasisZ_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisZ.Y") ?? Array.Empty(); + FamilyInstanceBasisZ_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:BasisZ.Z") ?? Array.Empty(); + FamilyInstanceTranslation_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:Translation.X") ?? Array.Empty(); + FamilyInstanceTranslation_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:Translation.Y") ?? Array.Empty(); + FamilyInstanceTranslation_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:Translation.Z") ?? Array.Empty(); + FamilyInstanceHandOrientation_X = FamilyInstanceEntityTable?.GetDataColumnValues("float:HandOrientation.X") ?? Array.Empty(); + FamilyInstanceHandOrientation_Y = FamilyInstanceEntityTable?.GetDataColumnValues("float:HandOrientation.Y") ?? Array.Empty(); + FamilyInstanceHandOrientation_Z = FamilyInstanceEntityTable?.GetDataColumnValues("float:HandOrientation.Z") ?? Array.Empty(); + ViewTitle = ViewEntityTable?.GetStringColumnValues("string:Title") ?? Array.Empty(); + ViewViewType = ViewEntityTable?.GetStringColumnValues("string:ViewType") ?? Array.Empty(); + ViewUp_X = ViewEntityTable?.GetDataColumnValues("double:Up.X") ?? Array.Empty(); + ViewUp_Y = ViewEntityTable?.GetDataColumnValues("double:Up.Y") ?? Array.Empty(); + ViewUp_Z = ViewEntityTable?.GetDataColumnValues("double:Up.Z") ?? Array.Empty(); + ViewRight_X = ViewEntityTable?.GetDataColumnValues("double:Right.X") ?? Array.Empty(); + ViewRight_Y = ViewEntityTable?.GetDataColumnValues("double:Right.Y") ?? Array.Empty(); + ViewRight_Z = ViewEntityTable?.GetDataColumnValues("double:Right.Z") ?? Array.Empty(); + ViewOrigin_X = ViewEntityTable?.GetDataColumnValues("double:Origin.X") ?? Array.Empty(); + ViewOrigin_Y = ViewEntityTable?.GetDataColumnValues("double:Origin.Y") ?? Array.Empty(); + ViewOrigin_Z = ViewEntityTable?.GetDataColumnValues("double:Origin.Z") ?? Array.Empty(); + ViewViewDirection_X = ViewEntityTable?.GetDataColumnValues("double:ViewDirection.X") ?? Array.Empty(); + ViewViewDirection_Y = ViewEntityTable?.GetDataColumnValues("double:ViewDirection.Y") ?? Array.Empty(); + ViewViewDirection_Z = ViewEntityTable?.GetDataColumnValues("double:ViewDirection.Z") ?? Array.Empty(); + ViewViewPosition_X = ViewEntityTable?.GetDataColumnValues("double:ViewPosition.X") ?? Array.Empty(); + ViewViewPosition_Y = ViewEntityTable?.GetDataColumnValues("double:ViewPosition.Y") ?? Array.Empty(); + ViewViewPosition_Z = ViewEntityTable?.GetDataColumnValues("double:ViewPosition.Z") ?? Array.Empty(); + ViewScale = ViewEntityTable?.GetDataColumnValues("double:Scale") ?? Array.Empty(); + ViewOutline_Min_X = ViewEntityTable?.GetDataColumnValues("double:Outline.Min.X") ?? Array.Empty(); + ViewOutline_Min_Y = ViewEntityTable?.GetDataColumnValues("double:Outline.Min.Y") ?? Array.Empty(); + ViewOutline_Max_X = ViewEntityTable?.GetDataColumnValues("double:Outline.Max.X") ?? Array.Empty(); + ViewOutline_Max_Y = ViewEntityTable?.GetDataColumnValues("double:Outline.Max.Y") ?? Array.Empty(); + ViewDetailLevel = ViewEntityTable?.GetDataColumnValues("int:DetailLevel") ?? Array.Empty(); + LevelInViewExtents_Min_X = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Min.X") ?? Array.Empty(); + LevelInViewExtents_Min_Y = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Min.Y") ?? Array.Empty(); + LevelInViewExtents_Min_Z = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Min.Z") ?? Array.Empty(); + LevelInViewExtents_Max_X = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Max.X") ?? Array.Empty(); + LevelInViewExtents_Max_Y = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Max.Y") ?? Array.Empty(); + LevelInViewExtents_Max_Z = LevelInViewEntityTable?.GetDataColumnValues("double:Extents.Max.Z") ?? Array.Empty(); + CameraId = CameraEntityTable?.GetDataColumnValues("int:Id") ?? Array.Empty(); + CameraIsPerspective = CameraEntityTable?.GetDataColumnValues("int:IsPerspective") ?? Array.Empty(); + CameraVerticalExtent = CameraEntityTable?.GetDataColumnValues("double:VerticalExtent") ?? Array.Empty(); + CameraHorizontalExtent = CameraEntityTable?.GetDataColumnValues("double:HorizontalExtent") ?? Array.Empty(); + CameraFarDistance = CameraEntityTable?.GetDataColumnValues("double:FarDistance") ?? Array.Empty(); + CameraNearDistance = CameraEntityTable?.GetDataColumnValues("double:NearDistance") ?? Array.Empty(); + CameraTargetDistance = CameraEntityTable?.GetDataColumnValues("double:TargetDistance") ?? Array.Empty(); + CameraRightOffset = CameraEntityTable?.GetDataColumnValues("double:RightOffset") ?? Array.Empty(); + CameraUpOffset = CameraEntityTable?.GetDataColumnValues("double:UpOffset") ?? Array.Empty(); + MaterialName = MaterialEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty(); + MaterialMaterialCategory = MaterialEntityTable?.GetStringColumnValues("string:MaterialCategory") ?? Array.Empty(); + MaterialColor_X = MaterialEntityTable?.GetDataColumnValues("double:Color.X") ?? Array.Empty(); + MaterialColor_Y = MaterialEntityTable?.GetDataColumnValues("double:Color.Y") ?? Array.Empty(); + MaterialColor_Z = MaterialEntityTable?.GetDataColumnValues("double:Color.Z") ?? Array.Empty(); + MaterialColorUvScaling_X = MaterialEntityTable?.GetDataColumnValues("double:ColorUvScaling.X") ?? Array.Empty(); + MaterialColorUvScaling_Y = MaterialEntityTable?.GetDataColumnValues("double:ColorUvScaling.Y") ?? Array.Empty(); + MaterialColorUvOffset_X = MaterialEntityTable?.GetDataColumnValues("double:ColorUvOffset.X") ?? Array.Empty(); + MaterialColorUvOffset_Y = MaterialEntityTable?.GetDataColumnValues("double:ColorUvOffset.Y") ?? Array.Empty(); + MaterialNormalUvScaling_X = MaterialEntityTable?.GetDataColumnValues("double:NormalUvScaling.X") ?? Array.Empty(); + MaterialNormalUvScaling_Y = MaterialEntityTable?.GetDataColumnValues("double:NormalUvScaling.Y") ?? Array.Empty(); + MaterialNormalUvOffset_X = MaterialEntityTable?.GetDataColumnValues("double:NormalUvOffset.X") ?? Array.Empty(); + MaterialNormalUvOffset_Y = MaterialEntityTable?.GetDataColumnValues("double:NormalUvOffset.Y") ?? Array.Empty(); + MaterialNormalAmount = MaterialEntityTable?.GetDataColumnValues("double:NormalAmount") ?? Array.Empty(); + MaterialGlossiness = MaterialEntityTable?.GetDataColumnValues("double:Glossiness") ?? Array.Empty(); + MaterialSmoothness = MaterialEntityTable?.GetDataColumnValues("double:Smoothness") ?? Array.Empty(); + MaterialTransparency = MaterialEntityTable?.GetDataColumnValues("double:Transparency") ?? Array.Empty(); + MaterialInElementArea = MaterialInElementEntityTable?.GetDataColumnValues("double:Area") ?? Array.Empty(); + MaterialInElementVolume = MaterialInElementEntityTable?.GetDataColumnValues("double:Volume") ?? Array.Empty(); + MaterialInElementIsPaint = MaterialInElementEntityTable?.GetDataColumnValues("byte:IsPaint") ?? Array.Empty(); + CompoundStructureLayerOrderIndex = CompoundStructureLayerEntityTable?.GetDataColumnValues("int:OrderIndex") ?? Array.Empty(); + CompoundStructureLayerWidth = CompoundStructureLayerEntityTable?.GetDataColumnValues("double:Width") ?? Array.Empty(); + CompoundStructureLayerMaterialFunctionAssignment = CompoundStructureLayerEntityTable?.GetStringColumnValues("string:MaterialFunctionAssignment") ?? Array.Empty(); + CompoundStructureWidth = CompoundStructureEntityTable?.GetDataColumnValues("double:Width") ?? Array.Empty(); + GeometryBox_Min_X = GeometryEntityTable?.GetDataColumnValues("float:Box.Min.X") ?? Array.Empty(); + GeometryBox_Min_Y = GeometryEntityTable?.GetDataColumnValues("float:Box.Min.Y") ?? Array.Empty(); + GeometryBox_Min_Z = GeometryEntityTable?.GetDataColumnValues("float:Box.Min.Z") ?? Array.Empty(); + GeometryBox_Max_X = GeometryEntityTable?.GetDataColumnValues("float:Box.Max.X") ?? Array.Empty(); + GeometryBox_Max_Y = GeometryEntityTable?.GetDataColumnValues("float:Box.Max.Y") ?? Array.Empty(); + GeometryBox_Max_Z = GeometryEntityTable?.GetDataColumnValues("float:Box.Max.Z") ?? Array.Empty(); + GeometryVertexCount = GeometryEntityTable?.GetDataColumnValues("int:VertexCount") ?? Array.Empty(); + GeometryFaceCount = GeometryEntityTable?.GetDataColumnValues("int:FaceCount") ?? Array.Empty(); + SystemSystemType = SystemEntityTable?.GetDataColumnValues("int:SystemType") ?? Array.Empty(); + ElementInSystemRoles = ElementInSystemEntityTable?.GetDataColumnValues("int:Roles") ?? Array.Empty(); + WarningGuid = WarningEntityTable?.GetStringColumnValues("string:Guid") ?? Array.Empty(); + WarningSeverity = WarningEntityTable?.GetStringColumnValues("string:Severity") ?? Array.Empty(); + WarningDescription = WarningEntityTable?.GetStringColumnValues("string:Description") ?? Array.Empty(); + BasePointIsSurveyPoint = BasePointEntityTable?.GetDataColumnValues("byte:IsSurveyPoint") ?? Array.Empty(); + BasePointPosition_X = BasePointEntityTable?.GetDataColumnValues("double:Position.X") ?? Array.Empty(); + BasePointPosition_Y = BasePointEntityTable?.GetDataColumnValues("double:Position.Y") ?? Array.Empty(); + BasePointPosition_Z = BasePointEntityTable?.GetDataColumnValues("double:Position.Z") ?? Array.Empty(); + BasePointSharedPosition_X = BasePointEntityTable?.GetDataColumnValues("double:SharedPosition.X") ?? Array.Empty(); + BasePointSharedPosition_Y = BasePointEntityTable?.GetDataColumnValues("double:SharedPosition.Y") ?? Array.Empty(); + BasePointSharedPosition_Z = BasePointEntityTable?.GetDataColumnValues("double:SharedPosition.Z") ?? Array.Empty(); + PhaseFilterNew = PhaseFilterEntityTable?.GetDataColumnValues("int:New") ?? Array.Empty(); + PhaseFilterExisting = PhaseFilterEntityTable?.GetDataColumnValues("int:Existing") ?? Array.Empty(); + PhaseFilterDemolished = PhaseFilterEntityTable?.GetDataColumnValues("int:Demolished") ?? Array.Empty(); + PhaseFilterTemporary = PhaseFilterEntityTable?.GetDataColumnValues("int:Temporary") ?? Array.Empty(); + GridStartPoint_X = GridEntityTable?.GetDataColumnValues("double:StartPoint.X") ?? Array.Empty(); + GridStartPoint_Y = GridEntityTable?.GetDataColumnValues("double:StartPoint.Y") ?? Array.Empty(); + GridStartPoint_Z = GridEntityTable?.GetDataColumnValues("double:StartPoint.Z") ?? Array.Empty(); + GridEndPoint_X = GridEntityTable?.GetDataColumnValues("double:EndPoint.X") ?? Array.Empty(); + GridEndPoint_Y = GridEntityTable?.GetDataColumnValues("double:EndPoint.Y") ?? Array.Empty(); + GridEndPoint_Z = GridEntityTable?.GetDataColumnValues("double:EndPoint.Z") ?? Array.Empty(); + GridIsCurved = GridEntityTable?.GetDataColumnValues("byte:IsCurved") ?? Array.Empty(); + GridExtents_Min_X = GridEntityTable?.GetDataColumnValues("double:Extents.Min.X") ?? Array.Empty(); + GridExtents_Min_Y = GridEntityTable?.GetDataColumnValues("double:Extents.Min.Y") ?? Array.Empty(); + GridExtents_Min_Z = GridEntityTable?.GetDataColumnValues("double:Extents.Min.Z") ?? Array.Empty(); + GridExtents_Max_X = GridEntityTable?.GetDataColumnValues("double:Extents.Max.X") ?? Array.Empty(); + GridExtents_Max_Y = GridEntityTable?.GetDataColumnValues("double:Extents.Max.Y") ?? Array.Empty(); + GridExtents_Max_Z = GridEntityTable?.GetDataColumnValues("double:Extents.Max.Z") ?? Array.Empty(); + AreaValue = AreaEntityTable?.GetDataColumnValues("double:Value") ?? Array.Empty(); + AreaPerimeter = AreaEntityTable?.GetDataColumnValues("double:Perimeter") ?? Array.Empty(); + AreaNumber = AreaEntityTable?.GetStringColumnValues("string:Number") ?? Array.Empty(); + AreaIsGrossInterior = AreaEntityTable?.GetDataColumnValues("byte:IsGrossInterior") ?? Array.Empty(); + AreaSchemeIsGrossBuildingArea = AreaSchemeEntityTable?.GetDataColumnValues("byte:IsGrossBuildingArea") ?? Array.Empty(); + ScheduleColumnName = ScheduleColumnEntityTable?.GetStringColumnValues("string:Name") ?? Array.Empty(); + ScheduleColumnColumnIndex = ScheduleColumnEntityTable?.GetDataColumnValues("int:ColumnIndex") ?? Array.Empty(); + ScheduleCellValue = ScheduleCellEntityTable?.GetStringColumnValues("string:Value") ?? Array.Empty(); + ScheduleCellRowIndex = ScheduleCellEntityTable?.GetDataColumnValues("int:RowIndex") ?? Array.Empty(); + SiteLatitude = SiteEntityTable?.GetDataColumnValues("double:Latitude") ?? Array.Empty(); + SiteLongitude = SiteEntityTable?.GetDataColumnValues("double:Longitude") ?? Array.Empty(); + SiteAddress = SiteEntityTable?.GetStringColumnValues("string:Address") ?? Array.Empty(); + SiteElevation = SiteEntityTable?.GetDataColumnValues("double:Elevation") ?? Array.Empty(); + SiteNumber = SiteEntityTable?.GetStringColumnValues("string:Number") ?? Array.Empty(); + BuildingElevation = BuildingEntityTable?.GetDataColumnValues("double:Elevation") ?? Array.Empty(); + BuildingTerrainElevation = BuildingEntityTable?.GetDataColumnValues("double:TerrainElevation") ?? Array.Empty(); + BuildingAddress = BuildingEntityTable?.GetStringColumnValues("string:Address") ?? Array.Empty(); // Initialize entity relational columns - ParameterDescriptorDisplayUnitIndex = ParameterDescriptorEntityTable?.GetIndexColumnValues("index:Vim.DisplayUnit:DisplayUnit") ?? Array.Empty().ToIArray(); - ParameterParameterDescriptorIndex = ParameterEntityTable?.GetIndexColumnValues("index:Vim.ParameterDescriptor:ParameterDescriptor") ?? Array.Empty().ToIArray(); - ParameterElementIndex = ParameterEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ElementLevelIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Level:Level") ?? Array.Empty().ToIArray(); - ElementPhaseCreatedIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Phase:PhaseCreated") ?? Array.Empty().ToIArray(); - ElementPhaseDemolishedIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Phase:PhaseDemolished") ?? Array.Empty().ToIArray(); - ElementCategoryIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Category:Category") ?? Array.Empty().ToIArray(); - ElementWorksetIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Workset:Workset") ?? Array.Empty().ToIArray(); - ElementDesignOptionIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.DesignOption:DesignOption") ?? Array.Empty().ToIArray(); - ElementOwnerViewIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.View:OwnerView") ?? Array.Empty().ToIArray(); - ElementGroupIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Group:Group") ?? Array.Empty().ToIArray(); - ElementAssemblyInstanceIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.AssemblyInstance:AssemblyInstance") ?? Array.Empty().ToIArray(); - ElementBimDocumentIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty().ToIArray(); - ElementRoomIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Room:Room") ?? Array.Empty().ToIArray(); - WorksetBimDocumentIndex = WorksetEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty().ToIArray(); - AssemblyInstanceElementIndex = AssemblyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - GroupElementIndex = GroupEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - DesignOptionElementIndex = DesignOptionEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - LevelFamilyTypeIndex = LevelEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty().ToIArray(); - LevelBuildingIndex = LevelEntityTable?.GetIndexColumnValues("index:Vim.Building:Building") ?? Array.Empty().ToIArray(); - LevelElementIndex = LevelEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - PhaseElementIndex = PhaseEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - RoomUpperLimitIndex = RoomEntityTable?.GetIndexColumnValues("index:Vim.Level:UpperLimit") ?? Array.Empty().ToIArray(); - RoomElementIndex = RoomEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - BimDocumentActiveViewIndex = BimDocumentEntityTable?.GetIndexColumnValues("index:Vim.View:ActiveView") ?? Array.Empty().ToIArray(); - BimDocumentOwnerFamilyIndex = BimDocumentEntityTable?.GetIndexColumnValues("index:Vim.Family:OwnerFamily") ?? Array.Empty().ToIArray(); - BimDocumentParentIndex = BimDocumentEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:Parent") ?? Array.Empty().ToIArray(); - BimDocumentElementIndex = BimDocumentEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - DisplayUnitInBimDocumentDisplayUnitIndex = DisplayUnitInBimDocumentEntityTable?.GetIndexColumnValues("index:Vim.DisplayUnit:DisplayUnit") ?? Array.Empty().ToIArray(); - DisplayUnitInBimDocumentBimDocumentIndex = DisplayUnitInBimDocumentEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty().ToIArray(); - PhaseOrderInBimDocumentPhaseIndex = PhaseOrderInBimDocumentEntityTable?.GetIndexColumnValues("index:Vim.Phase:Phase") ?? Array.Empty().ToIArray(); - PhaseOrderInBimDocumentBimDocumentIndex = PhaseOrderInBimDocumentEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty().ToIArray(); - CategoryParentIndex = CategoryEntityTable?.GetIndexColumnValues("index:Vim.Category:Parent") ?? Array.Empty().ToIArray(); - CategoryMaterialIndex = CategoryEntityTable?.GetIndexColumnValues("index:Vim.Material:Material") ?? Array.Empty().ToIArray(); - FamilyFamilyCategoryIndex = FamilyEntityTable?.GetIndexColumnValues("index:Vim.Category:FamilyCategory") ?? Array.Empty().ToIArray(); - FamilyElementIndex = FamilyEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - FamilyTypeFamilyIndex = FamilyTypeEntityTable?.GetIndexColumnValues("index:Vim.Family:Family") ?? Array.Empty().ToIArray(); - FamilyTypeCompoundStructureIndex = FamilyTypeEntityTable?.GetIndexColumnValues("index:Vim.CompoundStructure:CompoundStructure") ?? Array.Empty().ToIArray(); - FamilyTypeElementIndex = FamilyTypeEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - FamilyInstanceFamilyTypeIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty().ToIArray(); - FamilyInstanceHostIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Element:Host") ?? Array.Empty().ToIArray(); - FamilyInstanceFromRoomIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Room:FromRoom") ?? Array.Empty().ToIArray(); - FamilyInstanceToRoomIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Room:ToRoom") ?? Array.Empty().ToIArray(); - FamilyInstanceElementIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ViewCameraIndex = ViewEntityTable?.GetIndexColumnValues("index:Vim.Camera:Camera") ?? Array.Empty().ToIArray(); - ViewFamilyTypeIndex = ViewEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty().ToIArray(); - ViewElementIndex = ViewEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ElementInViewViewIndex = ElementInViewEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty().ToIArray(); - ElementInViewElementIndex = ElementInViewEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ShapeInViewShapeIndex = ShapeInViewEntityTable?.GetIndexColumnValues("index:Vim.Shape:Shape") ?? Array.Empty().ToIArray(); - ShapeInViewViewIndex = ShapeInViewEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty().ToIArray(); - AssetInViewAssetIndex = AssetInViewEntityTable?.GetIndexColumnValues("index:Vim.Asset:Asset") ?? Array.Empty().ToIArray(); - AssetInViewViewIndex = AssetInViewEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty().ToIArray(); - AssetInViewSheetAssetIndex = AssetInViewSheetEntityTable?.GetIndexColumnValues("index:Vim.Asset:Asset") ?? Array.Empty().ToIArray(); - AssetInViewSheetViewSheetIndex = AssetInViewSheetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheet:ViewSheet") ?? Array.Empty().ToIArray(); - LevelInViewLevelIndex = LevelInViewEntityTable?.GetIndexColumnValues("index:Vim.Level:Level") ?? Array.Empty().ToIArray(); - LevelInViewViewIndex = LevelInViewEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty().ToIArray(); - MaterialColorTextureFileIndex = MaterialEntityTable?.GetIndexColumnValues("index:Vim.Asset:ColorTextureFile") ?? Array.Empty().ToIArray(); - MaterialNormalTextureFileIndex = MaterialEntityTable?.GetIndexColumnValues("index:Vim.Asset:NormalTextureFile") ?? Array.Empty().ToIArray(); - MaterialElementIndex = MaterialEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - MaterialInElementMaterialIndex = MaterialInElementEntityTable?.GetIndexColumnValues("index:Vim.Material:Material") ?? Array.Empty().ToIArray(); - MaterialInElementElementIndex = MaterialInElementEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - CompoundStructureLayerMaterialIndex = CompoundStructureLayerEntityTable?.GetIndexColumnValues("index:Vim.Material:Material") ?? Array.Empty().ToIArray(); - CompoundStructureLayerCompoundStructureIndex = CompoundStructureLayerEntityTable?.GetIndexColumnValues("index:Vim.CompoundStructure:CompoundStructure") ?? Array.Empty().ToIArray(); - CompoundStructureStructuralLayerIndex = CompoundStructureEntityTable?.GetIndexColumnValues("index:Vim.CompoundStructureLayer:StructuralLayer") ?? Array.Empty().ToIArray(); - NodeElementIndex = NodeEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ShapeElementIndex = ShapeEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ShapeCollectionElementIndex = ShapeCollectionEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ShapeInShapeCollectionShapeIndex = ShapeInShapeCollectionEntityTable?.GetIndexColumnValues("index:Vim.Shape:Shape") ?? Array.Empty().ToIArray(); - ShapeInShapeCollectionShapeCollectionIndex = ShapeInShapeCollectionEntityTable?.GetIndexColumnValues("index:Vim.ShapeCollection:ShapeCollection") ?? Array.Empty().ToIArray(); - SystemFamilyTypeIndex = SystemEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty().ToIArray(); - SystemElementIndex = SystemEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ElementInSystemSystemIndex = ElementInSystemEntityTable?.GetIndexColumnValues("index:Vim.System:System") ?? Array.Empty().ToIArray(); - ElementInSystemElementIndex = ElementInSystemEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - WarningBimDocumentIndex = WarningEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty().ToIArray(); - ElementInWarningWarningIndex = ElementInWarningEntityTable?.GetIndexColumnValues("index:Vim.Warning:Warning") ?? Array.Empty().ToIArray(); - ElementInWarningElementIndex = ElementInWarningEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - BasePointElementIndex = BasePointEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - PhaseFilterElementIndex = PhaseFilterEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - GridFamilyTypeIndex = GridEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty().ToIArray(); - GridElementIndex = GridEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - AreaAreaSchemeIndex = AreaEntityTable?.GetIndexColumnValues("index:Vim.AreaScheme:AreaScheme") ?? Array.Empty().ToIArray(); - AreaElementIndex = AreaEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - AreaSchemeElementIndex = AreaSchemeEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ScheduleElementIndex = ScheduleEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ScheduleColumnScheduleIndex = ScheduleColumnEntityTable?.GetIndexColumnValues("index:Vim.Schedule:Schedule") ?? Array.Empty().ToIArray(); - ScheduleCellScheduleColumnIndex = ScheduleCellEntityTable?.GetIndexColumnValues("index:Vim.ScheduleColumn:ScheduleColumn") ?? Array.Empty().ToIArray(); - ViewSheetSetElementIndex = ViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ViewSheetFamilyTypeIndex = ViewSheetEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty().ToIArray(); - ViewSheetElementIndex = ViewSheetEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - ViewSheetInViewSheetSetViewSheetIndex = ViewSheetInViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheet:ViewSheet") ?? Array.Empty().ToIArray(); - ViewSheetInViewSheetSetViewSheetSetIndex = ViewSheetInViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheetSet:ViewSheetSet") ?? Array.Empty().ToIArray(); - ViewInViewSheetSetViewIndex = ViewInViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty().ToIArray(); - ViewInViewSheetSetViewSheetSetIndex = ViewInViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheetSet:ViewSheetSet") ?? Array.Empty().ToIArray(); - ViewInViewSheetViewIndex = ViewInViewSheetEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty().ToIArray(); - ViewInViewSheetViewSheetIndex = ViewInViewSheetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheet:ViewSheet") ?? Array.Empty().ToIArray(); - SiteElementIndex = SiteEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); - BuildingSiteIndex = BuildingEntityTable?.GetIndexColumnValues("index:Vim.Site:Site") ?? Array.Empty().ToIArray(); - BuildingElementIndex = BuildingEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty().ToIArray(); + ParameterDescriptorDisplayUnitIndex = ParameterDescriptorEntityTable?.GetIndexColumnValues("index:Vim.DisplayUnit:DisplayUnit") ?? Array.Empty(); + ParameterParameterDescriptorIndex = ParameterEntityTable?.GetIndexColumnValues("index:Vim.ParameterDescriptor:ParameterDescriptor") ?? Array.Empty(); + ParameterElementIndex = ParameterEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ElementLevelIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Level:Level") ?? Array.Empty(); + ElementPhaseCreatedIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Phase:PhaseCreated") ?? Array.Empty(); + ElementPhaseDemolishedIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Phase:PhaseDemolished") ?? Array.Empty(); + ElementCategoryIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Category:Category") ?? Array.Empty(); + ElementWorksetIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Workset:Workset") ?? Array.Empty(); + ElementDesignOptionIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.DesignOption:DesignOption") ?? Array.Empty(); + ElementOwnerViewIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.View:OwnerView") ?? Array.Empty(); + ElementGroupIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Group:Group") ?? Array.Empty(); + ElementAssemblyInstanceIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.AssemblyInstance:AssemblyInstance") ?? Array.Empty(); + ElementBimDocumentIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty(); + ElementRoomIndex = ElementEntityTable?.GetIndexColumnValues("index:Vim.Room:Room") ?? Array.Empty(); + WorksetBimDocumentIndex = WorksetEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty(); + AssemblyInstanceElementIndex = AssemblyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + GroupElementIndex = GroupEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + DesignOptionElementIndex = DesignOptionEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + LevelFamilyTypeIndex = LevelEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty(); + LevelBuildingIndex = LevelEntityTable?.GetIndexColumnValues("index:Vim.Building:Building") ?? Array.Empty(); + LevelElementIndex = LevelEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + PhaseElementIndex = PhaseEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + RoomUpperLimitIndex = RoomEntityTable?.GetIndexColumnValues("index:Vim.Level:UpperLimit") ?? Array.Empty(); + RoomElementIndex = RoomEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + BimDocumentActiveViewIndex = BimDocumentEntityTable?.GetIndexColumnValues("index:Vim.View:ActiveView") ?? Array.Empty(); + BimDocumentOwnerFamilyIndex = BimDocumentEntityTable?.GetIndexColumnValues("index:Vim.Family:OwnerFamily") ?? Array.Empty(); + BimDocumentParentIndex = BimDocumentEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:Parent") ?? Array.Empty(); + BimDocumentElementIndex = BimDocumentEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + DisplayUnitInBimDocumentDisplayUnitIndex = DisplayUnitInBimDocumentEntityTable?.GetIndexColumnValues("index:Vim.DisplayUnit:DisplayUnit") ?? Array.Empty(); + DisplayUnitInBimDocumentBimDocumentIndex = DisplayUnitInBimDocumentEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty(); + PhaseOrderInBimDocumentPhaseIndex = PhaseOrderInBimDocumentEntityTable?.GetIndexColumnValues("index:Vim.Phase:Phase") ?? Array.Empty(); + PhaseOrderInBimDocumentBimDocumentIndex = PhaseOrderInBimDocumentEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty(); + CategoryParentIndex = CategoryEntityTable?.GetIndexColumnValues("index:Vim.Category:Parent") ?? Array.Empty(); + CategoryMaterialIndex = CategoryEntityTable?.GetIndexColumnValues("index:Vim.Material:Material") ?? Array.Empty(); + FamilyFamilyCategoryIndex = FamilyEntityTable?.GetIndexColumnValues("index:Vim.Category:FamilyCategory") ?? Array.Empty(); + FamilyElementIndex = FamilyEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + FamilyTypeFamilyIndex = FamilyTypeEntityTable?.GetIndexColumnValues("index:Vim.Family:Family") ?? Array.Empty(); + FamilyTypeCompoundStructureIndex = FamilyTypeEntityTable?.GetIndexColumnValues("index:Vim.CompoundStructure:CompoundStructure") ?? Array.Empty(); + FamilyTypeElementIndex = FamilyTypeEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + FamilyInstanceFamilyTypeIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty(); + FamilyInstanceHostIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Element:Host") ?? Array.Empty(); + FamilyInstanceFromRoomIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Room:FromRoom") ?? Array.Empty(); + FamilyInstanceToRoomIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Room:ToRoom") ?? Array.Empty(); + FamilyInstanceElementIndex = FamilyInstanceEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ViewCameraIndex = ViewEntityTable?.GetIndexColumnValues("index:Vim.Camera:Camera") ?? Array.Empty(); + ViewFamilyTypeIndex = ViewEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty(); + ViewElementIndex = ViewEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ElementInViewViewIndex = ElementInViewEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty(); + ElementInViewElementIndex = ElementInViewEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ShapeInViewShapeIndex = ShapeInViewEntityTable?.GetIndexColumnValues("index:Vim.Shape:Shape") ?? Array.Empty(); + ShapeInViewViewIndex = ShapeInViewEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty(); + AssetInViewAssetIndex = AssetInViewEntityTable?.GetIndexColumnValues("index:Vim.Asset:Asset") ?? Array.Empty(); + AssetInViewViewIndex = AssetInViewEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty(); + AssetInViewSheetAssetIndex = AssetInViewSheetEntityTable?.GetIndexColumnValues("index:Vim.Asset:Asset") ?? Array.Empty(); + AssetInViewSheetViewSheetIndex = AssetInViewSheetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheet:ViewSheet") ?? Array.Empty(); + LevelInViewLevelIndex = LevelInViewEntityTable?.GetIndexColumnValues("index:Vim.Level:Level") ?? Array.Empty(); + LevelInViewViewIndex = LevelInViewEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty(); + MaterialColorTextureFileIndex = MaterialEntityTable?.GetIndexColumnValues("index:Vim.Asset:ColorTextureFile") ?? Array.Empty(); + MaterialNormalTextureFileIndex = MaterialEntityTable?.GetIndexColumnValues("index:Vim.Asset:NormalTextureFile") ?? Array.Empty(); + MaterialElementIndex = MaterialEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + MaterialInElementMaterialIndex = MaterialInElementEntityTable?.GetIndexColumnValues("index:Vim.Material:Material") ?? Array.Empty(); + MaterialInElementElementIndex = MaterialInElementEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + CompoundStructureLayerMaterialIndex = CompoundStructureLayerEntityTable?.GetIndexColumnValues("index:Vim.Material:Material") ?? Array.Empty(); + CompoundStructureLayerCompoundStructureIndex = CompoundStructureLayerEntityTable?.GetIndexColumnValues("index:Vim.CompoundStructure:CompoundStructure") ?? Array.Empty(); + CompoundStructureStructuralLayerIndex = CompoundStructureEntityTable?.GetIndexColumnValues("index:Vim.CompoundStructureLayer:StructuralLayer") ?? Array.Empty(); + NodeElementIndex = NodeEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ShapeElementIndex = ShapeEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ShapeCollectionElementIndex = ShapeCollectionEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ShapeInShapeCollectionShapeIndex = ShapeInShapeCollectionEntityTable?.GetIndexColumnValues("index:Vim.Shape:Shape") ?? Array.Empty(); + ShapeInShapeCollectionShapeCollectionIndex = ShapeInShapeCollectionEntityTable?.GetIndexColumnValues("index:Vim.ShapeCollection:ShapeCollection") ?? Array.Empty(); + SystemFamilyTypeIndex = SystemEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty(); + SystemElementIndex = SystemEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ElementInSystemSystemIndex = ElementInSystemEntityTable?.GetIndexColumnValues("index:Vim.System:System") ?? Array.Empty(); + ElementInSystemElementIndex = ElementInSystemEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + WarningBimDocumentIndex = WarningEntityTable?.GetIndexColumnValues("index:Vim.BimDocument:BimDocument") ?? Array.Empty(); + ElementInWarningWarningIndex = ElementInWarningEntityTable?.GetIndexColumnValues("index:Vim.Warning:Warning") ?? Array.Empty(); + ElementInWarningElementIndex = ElementInWarningEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + BasePointElementIndex = BasePointEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + PhaseFilterElementIndex = PhaseFilterEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + GridFamilyTypeIndex = GridEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty(); + GridElementIndex = GridEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + AreaAreaSchemeIndex = AreaEntityTable?.GetIndexColumnValues("index:Vim.AreaScheme:AreaScheme") ?? Array.Empty(); + AreaElementIndex = AreaEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + AreaSchemeElementIndex = AreaSchemeEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ScheduleElementIndex = ScheduleEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ScheduleColumnScheduleIndex = ScheduleColumnEntityTable?.GetIndexColumnValues("index:Vim.Schedule:Schedule") ?? Array.Empty(); + ScheduleCellScheduleColumnIndex = ScheduleCellEntityTable?.GetIndexColumnValues("index:Vim.ScheduleColumn:ScheduleColumn") ?? Array.Empty(); + ViewSheetSetElementIndex = ViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ViewSheetFamilyTypeIndex = ViewSheetEntityTable?.GetIndexColumnValues("index:Vim.FamilyType:FamilyType") ?? Array.Empty(); + ViewSheetElementIndex = ViewSheetEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + ViewSheetInViewSheetSetViewSheetIndex = ViewSheetInViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheet:ViewSheet") ?? Array.Empty(); + ViewSheetInViewSheetSetViewSheetSetIndex = ViewSheetInViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheetSet:ViewSheetSet") ?? Array.Empty(); + ViewInViewSheetSetViewIndex = ViewInViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty(); + ViewInViewSheetSetViewSheetSetIndex = ViewInViewSheetSetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheetSet:ViewSheetSet") ?? Array.Empty(); + ViewInViewSheetViewIndex = ViewInViewSheetEntityTable?.GetIndexColumnValues("index:Vim.View:View") ?? Array.Empty(); + ViewInViewSheetViewSheetIndex = ViewInViewSheetEntityTable?.GetIndexColumnValues("index:Vim.ViewSheet:ViewSheet") ?? Array.Empty(); + SiteElementIndex = SiteEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); + BuildingSiteIndex = BuildingEntityTable?.GetIndexColumnValues("index:Vim.Site:Site") ?? Array.Empty(); + BuildingElementIndex = BuildingEntityTable?.GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); // Initialize entity collections - AssetList = NumAsset.Select(i => GetAsset(i)); - DisplayUnitList = NumDisplayUnit.Select(i => GetDisplayUnit(i)); - ParameterDescriptorList = NumParameterDescriptor.Select(i => GetParameterDescriptor(i)); - ParameterList = NumParameter.Select(i => GetParameter(i)); - ElementList = NumElement.Select(i => GetElement(i)); - WorksetList = NumWorkset.Select(i => GetWorkset(i)); - AssemblyInstanceList = NumAssemblyInstance.Select(i => GetAssemblyInstance(i)); - GroupList = NumGroup.Select(i => GetGroup(i)); - DesignOptionList = NumDesignOption.Select(i => GetDesignOption(i)); - LevelList = NumLevel.Select(i => GetLevel(i)); - PhaseList = NumPhase.Select(i => GetPhase(i)); - RoomList = NumRoom.Select(i => GetRoom(i)); - BimDocumentList = NumBimDocument.Select(i => GetBimDocument(i)); - DisplayUnitInBimDocumentList = NumDisplayUnitInBimDocument.Select(i => GetDisplayUnitInBimDocument(i)); - PhaseOrderInBimDocumentList = NumPhaseOrderInBimDocument.Select(i => GetPhaseOrderInBimDocument(i)); - CategoryList = NumCategory.Select(i => GetCategory(i)); - FamilyList = NumFamily.Select(i => GetFamily(i)); - FamilyTypeList = NumFamilyType.Select(i => GetFamilyType(i)); - FamilyInstanceList = NumFamilyInstance.Select(i => GetFamilyInstance(i)); - ViewList = NumView.Select(i => GetView(i)); - ElementInViewList = NumElementInView.Select(i => GetElementInView(i)); - ShapeInViewList = NumShapeInView.Select(i => GetShapeInView(i)); - AssetInViewList = NumAssetInView.Select(i => GetAssetInView(i)); - AssetInViewSheetList = NumAssetInViewSheet.Select(i => GetAssetInViewSheet(i)); - LevelInViewList = NumLevelInView.Select(i => GetLevelInView(i)); - CameraList = NumCamera.Select(i => GetCamera(i)); - MaterialList = NumMaterial.Select(i => GetMaterial(i)); - MaterialInElementList = NumMaterialInElement.Select(i => GetMaterialInElement(i)); - CompoundStructureLayerList = NumCompoundStructureLayer.Select(i => GetCompoundStructureLayer(i)); - CompoundStructureList = NumCompoundStructure.Select(i => GetCompoundStructure(i)); - NodeList = NumNode.Select(i => GetNode(i)); - GeometryList = NumGeometry.Select(i => GetGeometry(i)); - ShapeList = NumShape.Select(i => GetShape(i)); - ShapeCollectionList = NumShapeCollection.Select(i => GetShapeCollection(i)); - ShapeInShapeCollectionList = NumShapeInShapeCollection.Select(i => GetShapeInShapeCollection(i)); - SystemList = NumSystem.Select(i => GetSystem(i)); - ElementInSystemList = NumElementInSystem.Select(i => GetElementInSystem(i)); - WarningList = NumWarning.Select(i => GetWarning(i)); - ElementInWarningList = NumElementInWarning.Select(i => GetElementInWarning(i)); - BasePointList = NumBasePoint.Select(i => GetBasePoint(i)); - PhaseFilterList = NumPhaseFilter.Select(i => GetPhaseFilter(i)); - GridList = NumGrid.Select(i => GetGrid(i)); - AreaList = NumArea.Select(i => GetArea(i)); - AreaSchemeList = NumAreaScheme.Select(i => GetAreaScheme(i)); - ScheduleList = NumSchedule.Select(i => GetSchedule(i)); - ScheduleColumnList = NumScheduleColumn.Select(i => GetScheduleColumn(i)); - ScheduleCellList = NumScheduleCell.Select(i => GetScheduleCell(i)); - ViewSheetSetList = NumViewSheetSet.Select(i => GetViewSheetSet(i)); - ViewSheetList = NumViewSheet.Select(i => GetViewSheet(i)); - ViewSheetInViewSheetSetList = NumViewSheetInViewSheetSet.Select(i => GetViewSheetInViewSheetSet(i)); - ViewInViewSheetSetList = NumViewInViewSheetSet.Select(i => GetViewInViewSheetSet(i)); - ViewInViewSheetList = NumViewInViewSheet.Select(i => GetViewInViewSheet(i)); - SiteList = NumSite.Select(i => GetSite(i)); - BuildingList = NumBuilding.Select(i => GetBuilding(i)); + AssetList = Enumerable.Range(0, NumAsset).Select(i => GetAsset(i)).ToArray(); + DisplayUnitList = Enumerable.Range(0, NumDisplayUnit).Select(i => GetDisplayUnit(i)).ToArray(); + ParameterDescriptorList = Enumerable.Range(0, NumParameterDescriptor).Select(i => GetParameterDescriptor(i)).ToArray(); + ParameterList = Enumerable.Range(0, NumParameter).Select(i => GetParameter(i)).ToArray(); + ElementList = Enumerable.Range(0, NumElement).Select(i => GetElement(i)).ToArray(); + WorksetList = Enumerable.Range(0, NumWorkset).Select(i => GetWorkset(i)).ToArray(); + AssemblyInstanceList = Enumerable.Range(0, NumAssemblyInstance).Select(i => GetAssemblyInstance(i)).ToArray(); + GroupList = Enumerable.Range(0, NumGroup).Select(i => GetGroup(i)).ToArray(); + DesignOptionList = Enumerable.Range(0, NumDesignOption).Select(i => GetDesignOption(i)).ToArray(); + LevelList = Enumerable.Range(0, NumLevel).Select(i => GetLevel(i)).ToArray(); + PhaseList = Enumerable.Range(0, NumPhase).Select(i => GetPhase(i)).ToArray(); + RoomList = Enumerable.Range(0, NumRoom).Select(i => GetRoom(i)).ToArray(); + BimDocumentList = Enumerable.Range(0, NumBimDocument).Select(i => GetBimDocument(i)).ToArray(); + DisplayUnitInBimDocumentList = Enumerable.Range(0, NumDisplayUnitInBimDocument).Select(i => GetDisplayUnitInBimDocument(i)).ToArray(); + PhaseOrderInBimDocumentList = Enumerable.Range(0, NumPhaseOrderInBimDocument).Select(i => GetPhaseOrderInBimDocument(i)).ToArray(); + CategoryList = Enumerable.Range(0, NumCategory).Select(i => GetCategory(i)).ToArray(); + FamilyList = Enumerable.Range(0, NumFamily).Select(i => GetFamily(i)).ToArray(); + FamilyTypeList = Enumerable.Range(0, NumFamilyType).Select(i => GetFamilyType(i)).ToArray(); + FamilyInstanceList = Enumerable.Range(0, NumFamilyInstance).Select(i => GetFamilyInstance(i)).ToArray(); + ViewList = Enumerable.Range(0, NumView).Select(i => GetView(i)).ToArray(); + ElementInViewList = Enumerable.Range(0, NumElementInView).Select(i => GetElementInView(i)).ToArray(); + ShapeInViewList = Enumerable.Range(0, NumShapeInView).Select(i => GetShapeInView(i)).ToArray(); + AssetInViewList = Enumerable.Range(0, NumAssetInView).Select(i => GetAssetInView(i)).ToArray(); + AssetInViewSheetList = Enumerable.Range(0, NumAssetInViewSheet).Select(i => GetAssetInViewSheet(i)).ToArray(); + LevelInViewList = Enumerable.Range(0, NumLevelInView).Select(i => GetLevelInView(i)).ToArray(); + CameraList = Enumerable.Range(0, NumCamera).Select(i => GetCamera(i)).ToArray(); + MaterialList = Enumerable.Range(0, NumMaterial).Select(i => GetMaterial(i)).ToArray(); + MaterialInElementList = Enumerable.Range(0, NumMaterialInElement).Select(i => GetMaterialInElement(i)).ToArray(); + CompoundStructureLayerList = Enumerable.Range(0, NumCompoundStructureLayer).Select(i => GetCompoundStructureLayer(i)).ToArray(); + CompoundStructureList = Enumerable.Range(0, NumCompoundStructure).Select(i => GetCompoundStructure(i)).ToArray(); + NodeList = Enumerable.Range(0, NumNode).Select(i => GetNode(i)).ToArray(); + GeometryList = Enumerable.Range(0, NumGeometry).Select(i => GetGeometry(i)).ToArray(); + ShapeList = Enumerable.Range(0, NumShape).Select(i => GetShape(i)).ToArray(); + ShapeCollectionList = Enumerable.Range(0, NumShapeCollection).Select(i => GetShapeCollection(i)).ToArray(); + ShapeInShapeCollectionList = Enumerable.Range(0, NumShapeInShapeCollection).Select(i => GetShapeInShapeCollection(i)).ToArray(); + SystemList = Enumerable.Range(0, NumSystem).Select(i => GetSystem(i)).ToArray(); + ElementInSystemList = Enumerable.Range(0, NumElementInSystem).Select(i => GetElementInSystem(i)).ToArray(); + WarningList = Enumerable.Range(0, NumWarning).Select(i => GetWarning(i)).ToArray(); + ElementInWarningList = Enumerable.Range(0, NumElementInWarning).Select(i => GetElementInWarning(i)).ToArray(); + BasePointList = Enumerable.Range(0, NumBasePoint).Select(i => GetBasePoint(i)).ToArray(); + PhaseFilterList = Enumerable.Range(0, NumPhaseFilter).Select(i => GetPhaseFilter(i)).ToArray(); + GridList = Enumerable.Range(0, NumGrid).Select(i => GetGrid(i)).ToArray(); + AreaList = Enumerable.Range(0, NumArea).Select(i => GetArea(i)).ToArray(); + AreaSchemeList = Enumerable.Range(0, NumAreaScheme).Select(i => GetAreaScheme(i)).ToArray(); + ScheduleList = Enumerable.Range(0, NumSchedule).Select(i => GetSchedule(i)).ToArray(); + ScheduleColumnList = Enumerable.Range(0, NumScheduleColumn).Select(i => GetScheduleColumn(i)).ToArray(); + ScheduleCellList = Enumerable.Range(0, NumScheduleCell).Select(i => GetScheduleCell(i)).ToArray(); + ViewSheetSetList = Enumerable.Range(0, NumViewSheetSet).Select(i => GetViewSheetSet(i)).ToArray(); + ViewSheetList = Enumerable.Range(0, NumViewSheet).Select(i => GetViewSheet(i)).ToArray(); + ViewSheetInViewSheetSetList = Enumerable.Range(0, NumViewSheetInViewSheetSet).Select(i => GetViewSheetInViewSheetSet(i)).ToArray(); + ViewInViewSheetSetList = Enumerable.Range(0, NumViewInViewSheetSet).Select(i => GetViewInViewSheetSet(i)).ToArray(); + ViewInViewSheetList = Enumerable.Range(0, NumViewInViewSheet).Select(i => GetViewInViewSheet(i)).ToArray(); + SiteList = Enumerable.Range(0, NumSite).Select(i => GetSite(i)).ToArray(); + BuildingList = Enumerable.Range(0, NumBuilding).Select(i => GetBuilding(i)).ToArray(); // Initialize element index maps ElementIndexMaps = new ElementIndexMaps(this, inParallel); diff --git a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs index 1e6167da..7869186e 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Vim.LinqArray; using Vim.Math3d; +using Vim.Util; namespace Vim.Format.ObjectModel { @@ -58,7 +59,7 @@ public static void ValidateBimDocument(this DocumentModel dm, ObjectModelValidat if (dm.NumBimDocument == 0 && validationOptions.BimDocumentMustExist) throw new ObjectModelValidationException($"No {nameof(BimDocument)} found."); - foreach (var bd in dm.BimDocumentList.ToEnumerable()) + foreach (var bd in dm.BimDocumentList) { var bdElement = bd.Element; if (bdElement == null) @@ -150,7 +151,7 @@ public static void ValidateAssets(this DocumentModel dm) public static void ValidateParameters(this DocumentModel dm) { - Parallel.ForEach(dm.ParameterList.ToEnumerable(), p => + Parallel.ForEach(dm.ParameterList, p => { // Each parameter must be associated to an element. if (p._Element.Index == EntityRelation.None) @@ -162,7 +163,7 @@ public static void ValidateParameters(this DocumentModel dm) }); // Validate the parameter descriptors. - foreach (var pd in dm.ParameterDescriptorList.ToEnumerable()) + foreach (var pd in dm.ParameterDescriptorList) { if (pd.DisplayUnit == null) throw new ObjectModelValidationException($"{nameof(DisplayUnit)} is null for {nameof(ParameterDescriptor)} {pd.Index}"); @@ -198,7 +199,7 @@ public static void ValidatePhases(this DocumentModel dm) } // Validate that the phase order information covers the set of phases. - var phaseIndexSet = new HashSet(dm.PhaseList.Select(p => p.Index).ToEnumerable()); + var phaseIndexSet = new HashSet(dm.PhaseList.Select(p => p.Index)); phaseIndexSet.ExceptWith(poArray.Select(po => po.Index)); if (phaseIndexSet.Count != 0) throw new ObjectModelValidationException($"{nameof(Phase)} index coverage is incomplete among {nameof(PhaseOrderInBimDocument)}"); @@ -253,7 +254,7 @@ void ValidateDVector3Domain(string label, DVector3 value, DVector3 lowerInclusiv } } - foreach (var material in dm.MaterialList.ToEnumerable()) + foreach (var material in dm.MaterialList) { var index = material.Index; ValidateDVector3Domain(nameof(material.Color), material.Color, DVector3.Zero, DVector3.One, index); @@ -278,7 +279,7 @@ public static void ValidateShapesInView(this DocumentModel dm) var viewToElementsMap = dm.ElementInViewList.ToArray().GetViewToElementsMap(); // Validate that the shapes in view have an element which is also in the same view. - foreach (var item in dm.ShapeInViewList.ToEnumerable()) + foreach (var item in dm.ShapeInViewList) { var viewIndex = item._View.Index; var shape = item.Shape; @@ -302,7 +303,7 @@ public static void ValidateEntitiesWithElement(this DocumentModel dm) Parallel.ForEach(entityWithElementTypes, entityWithElementType => { - var elementIndices = ((IArray)dm.GetPropertyValue(entityWithElementType.Name + "ElementIndex")).ToArray(); + var elementIndices = ((int[])dm.GetPropertyValue(entityWithElementType.Name + "ElementIndex")).ToArray(); for (var i = 0; i < elementIndices.Length; ++i) { var elementIndex = elementIndices[i]; @@ -316,7 +317,7 @@ public static void ValidateEntitiesWithElement(this DocumentModel dm) public static void ValidateElementInSystem(this DocumentModel dm) { - foreach (var eis in dm.ElementInSystemList.ToEnumerable()) + foreach (var eis in dm.ElementInSystemList) { if (eis.System == null) throw new ObjectModelValidationException($"{nameof(ElementInSystem)} @ {eis.Index} has a null {nameof(ElementInSystem.System)}"); diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs index 025a2c6c..cf7ed5cc 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs @@ -156,7 +156,7 @@ public static Vector4 GetDiffuseColor(this Material m) public static Vector4 ToDiffuseColor(this DVector3 v, double transparency) => new Vector4((float)v.X, (float)v.Y, (float)v.Z, 1.0f - (float)transparency); - public static IArray MaterialColors(this VimScene scene) => scene.DocumentModel.MaterialList.Select(GetDiffuseColor); + public static Vector4[] MaterialColors(this VimScene scene) => scene.DocumentModel.MaterialList.Select(GetDiffuseColor).ToArray(); public static Vector4 DefaultColor = new Vector4(0.5f, 0.5f, 0.5f, 1); From 5bfe828deb5efde9d0f245429e73b9bc28f52449 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 08:50:58 -0400 Subject: [PATCH 068/104] lookup with enumerables --- src/cs/linqarray/Vim.LinqArray/ILookup.cs | 22 ++++++++----------- .../DocumentBuilderExtensions.cs | 9 ++++---- .../vim/Vim.Format.Core/DocumentExtensions.cs | 10 +++++---- src/cs/vim/Vim.Format.Core/EntityTable.cs | 8 +++---- .../Vim.Format.Core/Geometry/Validation.cs | 14 ++++++------ src/cs/vim/Vim.Format.Core/Validation.cs | 14 ++++++------ .../vim/Vim.Format/SceneBuilder/Validation.cs | 2 +- 7 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/cs/linqarray/Vim.LinqArray/ILookup.cs b/src/cs/linqarray/Vim.LinqArray/ILookup.cs index 4bf6dc81..a4eb5b8b 100644 --- a/src/cs/linqarray/Vim.LinqArray/ILookup.cs +++ b/src/cs/linqarray/Vim.LinqArray/ILookup.cs @@ -13,16 +13,16 @@ namespace Vim.LinqArray /// public interface ILookup { - IArray Keys { get; } - IArray Values { get; } + IEnumerable Keys { get; } + IEnumerable Values { get; } bool Contains(TKey key); TValue this[TKey key] { get; } } public class EmptyLookup : ILookup { - public IArray Keys => LinqArray.Empty(); - public IArray Values => LinqArray.Empty(); + public IEnumerable Keys => Enumerable.Empty(); + public IEnumerable Values => Enumerable.Empty(); public bool Contains(TKey key) => false; public TValue this[TKey key] => default; } @@ -37,12 +37,10 @@ public LookupFromDictionary(IDictionary d = null, TValue defaultVa Dictionary = d ?? new Dictionary(); // TODO: sort? _default = defaultValue; - Keys = d.Keys.ToIArray(); - Values = d.Values.ToIArray(); } - public IArray Keys { get; } - public IArray Values { get; } + public IEnumerable Keys => Dictionary.Keys; + public IEnumerable Values => Dictionary.Values; public TValue this[TKey key] => Contains(key) ? Dictionary[key] : _default; public bool Contains(TKey key) => Dictionary.ContainsKey(key); } @@ -54,12 +52,10 @@ public class LookupFromArray : ILookup public LookupFromArray(IArray xs) { array = xs; - Keys = array.Indices(); - Values = array; } - public IArray Keys { get; } - public IArray Values { get; } + public IEnumerable Keys => array.Indices().ToEnumerable(); + public IEnumerable Values => array.ToEnumerable(); public TValue this[int key] => array[key]; public bool Contains(int key) => key >= 0 && key <= array.Count; } @@ -73,6 +69,6 @@ public static TValue GetOrDefault(this ILookup looku => lookup.Contains(key) ? lookup[key] : default; public static IEnumerable GetValues(this ILookup lookup) - => lookup.Keys.ToEnumerable().Select(k => lookup[k]); + => lookup.Keys.Select(k => lookup[k]); } } diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index a8bf6e51..a73fe17b 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -3,6 +3,7 @@ using Vim.BFastLib; using Vim.Format.Geometry; using Vim.LinqArray; +using Vim.Util; using static Vim.Format.DocumentBuilder; namespace Vim.Format @@ -21,17 +22,17 @@ public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, Entity var name = table.Name; var tb = db.CreateTableBuilder(name); - foreach (var col in table.IndexColumns.Values.ToEnumerable()) + foreach (var col in table.IndexColumns.Values) { tb.AddIndexColumn(col.Name, col.GetTypedData().RemapData(nodeIndexRemapping)); } - foreach (var col in table.DataColumns.Values.ToEnumerable()) + foreach (var col in table.DataColumns.Values) { tb.AddDataColumn(col.Name, col.CopyDataColumn(nodeIndexRemapping)); } - foreach (var col in table.StringColumns.Values.ToEnumerable()) + foreach (var col in table.StringColumns.Values) { var strings = col.GetTypedData().Select(i => table.Document.StringTable.ElementAtOrDefault(i, null)); tb.AddStringColumn(col.Name, strings.ToArray().RemapData(nodeIndexRemapping)); @@ -42,7 +43,7 @@ public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, Entity public static DocumentBuilder CopyTablesFrom(this DocumentBuilder db, Document doc, List nodeIndexRemapping = null) { - foreach (var table in doc.EntityTables.Values.ToEnumerable()) + foreach (var table in doc.EntityTables.Values) { var name = table.Name; diff --git a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs index 3ab52296..3ed5c589 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs @@ -2,6 +2,8 @@ using System.Text.RegularExpressions; using Vim.LinqArray; using Vim.BFastLib; +using System.Collections.Generic; +using System.Linq; namespace Vim.Format { @@ -13,14 +15,14 @@ public static Document ToDocument(this SerializableDocument document) public static EntityTable ToEntityTable(this SerializableEntityTable entityTable, Document document) => new EntityTable(document, entityTable); - public static string[] GetColumnNames(this EntityTable table) - => table.Columns.Select(b => b.Name).ToArray(); + public static IEnumerable GetColumnNames(this EntityTable table) + => table.Columns.Select(c => c.Name); public static void ValidateRelations(this Document doc) { - foreach (var et in doc.EntityTables.Values.ToEnumerable()) + foreach (var et in doc.EntityTables.Values) { - foreach (var ic in et.IndexColumns.Values.ToEnumerable()) + foreach (var ic in et.IndexColumns.Values) { var relatedTable = ic.GetRelatedTable(doc); var maxValue = relatedTable.NumRows; diff --git a/src/cs/vim/Vim.Format.Core/EntityTable.cs b/src/cs/vim/Vim.Format.Core/EntityTable.cs index 51551e09..42c7b967 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTable.cs @@ -2,6 +2,7 @@ using Vim.LinqArray; using Vim.BFastLib; using System.Linq; +using System.Collections.Generic; namespace Vim.Format { @@ -28,11 +29,10 @@ public EntityTable(Document document, SerializableEntityTable entityTable) public LinqArray.ILookup DataColumns { get; } public LinqArray.ILookup> StringColumns { get; } public LinqArray.ILookup> IndexColumns { get; } - public INamedBuffer[] Columns + public IEnumerable Columns => DataColumns.Values - .Concatenate(IndexColumns.Values.Select(x => (INamedBuffer)x)) - .Concatenate(StringColumns.Values.Select(x => (INamedBuffer)x)) - .ToArray(); + .Concat(IndexColumns.Values.Select(x => (INamedBuffer)x)) + .Concat(StringColumns.Values.Select(x => (INamedBuffer)x)); public int[] GetIndexColumnValues(string columnName) => IndexColumns.GetOrDefault(columnName)?.GetColumnValues(); diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index e987282a..474b340a 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -8,21 +8,21 @@ public static class Validation { public static void ValidateTableRows(this Document doc) { - foreach (var et in doc.EntityTables.Values.ToArray()) + foreach (var et in doc.EntityTables.Values) { - foreach (var c in et.IndexColumns.Values.ToArray()) + foreach (var c in et.IndexColumns.Values) { if (c.Array.Length != et.NumRows) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.DataColumns.Values.ToArray()) + foreach (var c in et.DataColumns.Values) { if (c.NumElements() != et.NumRows) throw new Exception($"Expected array length {c.NumElements()} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.StringColumns.Values.ToArray()) + foreach (var c in et.StringColumns.Values) { if (c.Array.Length != et.NumRows) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); @@ -32,9 +32,9 @@ public static void ValidateTableRows(this Document doc) public static void ValidateIndexColumns(this Document doc) { - foreach (var et in doc.EntityTables.Values.ToArray()) + foreach (var et in doc.EntityTables.Values) { - foreach (var ic in et.IndexColumns.Values.ToEnumerable()) + foreach (var ic in et.IndexColumns.Values) { var table = ic.GetRelatedTable(doc); if (table == null) @@ -45,7 +45,7 @@ public static void ValidateIndexColumns(this Document doc) public static void ValidateAssets(this Document doc) { - foreach (var asset in doc.Assets.Values.ToEnumerable()) + foreach (var asset in doc.Assets.Values) AssetInfo.Parse(asset.Name); // This will throw if it fails to parse. } diff --git a/src/cs/vim/Vim.Format.Core/Validation.cs b/src/cs/vim/Vim.Format.Core/Validation.cs index e44b2d1c..6d596db8 100644 --- a/src/cs/vim/Vim.Format.Core/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Validation.cs @@ -9,21 +9,21 @@ public static class Validation { public static void ValidateTableRows(this Document doc) { - foreach (var et in doc.EntityTables.Values.ToArray()) + foreach (var et in doc.EntityTables.Values) { - foreach (var c in et.IndexColumns.Values.ToArray()) + foreach (var c in et.IndexColumns.Values) { if (c.Array.Length != et.NumRows) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.DataColumns.Values.ToArray()) + foreach (var c in et.DataColumns.Values) { if (c.NumElements() != et.NumRows) throw new Exception($"Expected array length {c.NumElements()} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.StringColumns.Values.ToArray()) + foreach (var c in et.StringColumns.Values) { if (c.Array.Length != et.NumRows) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); @@ -33,9 +33,9 @@ public static void ValidateTableRows(this Document doc) public static void ValidateIndexColumns(this Document doc) { - foreach (var et in doc.EntityTables.Values.ToArray()) + foreach (var et in doc.EntityTables.Values) { - foreach (var ic in et.IndexColumns.Values.ToEnumerable()) + foreach (var ic in et.IndexColumns.Values) { var table = ic.GetRelatedTable(doc); if (table == null) @@ -46,7 +46,7 @@ public static void ValidateIndexColumns(this Document doc) public static void ValidateAssets(this Document doc) { - foreach (var asset in doc.Assets.Values.ToEnumerable()) + foreach (var asset in doc.Assets.Values) AssetInfo.Parse(asset.Name); // This will throw if it fails to parse. } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index ceb34e38..0f7f2107 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -143,7 +143,7 @@ public static void ValidateEquality(this DocumentBuilder db, VimScene vim) // Test the entity tables. var tableNames = new HashSet(db.Tables.Values.Select(t => t.Name)); - foreach (var et in vim.Document.EntityTables.Keys.ToEnumerable()) + foreach (var et in vim.Document.EntityTables.Keys) { if (!tableNames.Contains(et)) throw new VimValidationException($"{nameof(DocumentBuilder)} does not contain table name {et} from {nameof(VimScene)}"); From ec747ebea11ebb7def0947239c7fe570c62e568e Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 09:01:52 -0400 Subject: [PATCH 069/104] iarray -> array --- src/cs/vim/Vim.Format.Core/AssetInfo.cs | 3 ++- src/cs/vim/Vim.Format.Core/VimSchema.cs | 4 ++-- src/cs/vim/Vim.Format.Tests/FormatTests.cs | 24 +++++++++---------- .../Vim.Format.Vimx.Conversion/Ordering.cs | 6 ++--- .../VimxConverter.cs | 13 +++++----- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/AssetInfo.cs b/src/cs/vim/Vim.Format.Core/AssetInfo.cs index 009d7d37..53c3ef73 100644 --- a/src/cs/vim/Vim.Format.Core/AssetInfo.cs +++ b/src/cs/vim/Vim.Format.Core/AssetInfo.cs @@ -4,6 +4,7 @@ using Vim.Util; using Vim.LinqArray; using Vim.BFastLib; +using System.Linq; namespace Vim.Format { @@ -123,7 +124,7 @@ public static FileInfo ExtractAsset(this Document doc, string assetBufferName, F public static IEnumerable<(string assetBufferName, FileInfo assetFileInfo)> ExtractAssets(this Document doc, DirectoryInfo directoryInfo) { var result = new List<(string assetBufferName, FileInfo assetFileInfo)>(); - foreach (var assetBuffer in doc.Assets.Values.ToEnumerable()) + foreach (var assetBuffer in doc.Assets.Values) { var assetBufferName = assetBuffer.Name; var assetFilePath = assetBuffer.ExtractAsset(directoryInfo); diff --git a/src/cs/vim/Vim.Format.Core/VimSchema.cs b/src/cs/vim/Vim.Format.Core/VimSchema.cs index 70b9e025..8195c39a 100644 --- a/src/cs/vim/Vim.Format.Core/VimSchema.cs +++ b/src/cs/vim/Vim.Format.Core/VimSchema.cs @@ -53,12 +53,12 @@ public static VimSchema Create(SerializableDocument doc) private static VimSchema Create(Document doc) { var vimSchema = new VimSchema(doc.Header); - foreach (var entityTable in doc.EntityTables.Values.ToEnumerable()) + foreach (var entityTable in doc.EntityTables.Values) { var ets = vimSchema.AddEntityTableSchema(entityTable.Name); // Collect all the column names in the entity table and sort them alphabetically. - foreach (var columnName in entityTable.Columns.Select(nb => nb.Name).ToEnumerable().OrderBy(n => n)) + foreach (var columnName in entityTable.Columns.Select(nb => nb.Name).OrderBy(n => n)) ets.AddColumn(columnName); } return vimSchema; diff --git a/src/cs/vim/Vim.Format.Tests/FormatTests.cs b/src/cs/vim/Vim.Format.Tests/FormatTests.cs index 544469ff..b243c570 100644 --- a/src/cs/vim/Vim.Format.Tests/FormatTests.cs +++ b/src/cs/vim/Vim.Format.Tests/FormatTests.cs @@ -68,12 +68,12 @@ public static void AssertEquals(SerializableDocument d1, SerializableDocument d2 public static void AssertEquals(EntityTable et1, EntityTable et2) { Assert.AreEqual(et1.Name, et2.Name); - Assert.AreEqual(et1.DataColumns.Keys.ToEnumerable().OrderBy(n => n).ToArray(), et2.DataColumns.Keys.ToEnumerable().OrderBy(n => n).ToArray()); - Assert.AreEqual(et1.IndexColumns.Keys.ToEnumerable().OrderBy(n => n).ToArray(), et2.IndexColumns.Keys.ToEnumerable().OrderBy(n => n).ToArray()); - Assert.AreEqual(et1.StringColumns.Keys.ToEnumerable().OrderBy(n => n).ToArray(), et2.StringColumns.Keys.ToEnumerable().OrderBy(n => n).ToArray()); + Assert.AreEqual(et1.DataColumns.Keys.OrderBy(n => n).ToArray(), et2.DataColumns.Keys.OrderBy(n => n).ToArray()); + Assert.AreEqual(et1.IndexColumns.Keys.OrderBy(n => n).ToArray(), et2.IndexColumns.Keys.OrderBy(n => n).ToArray()); + Assert.AreEqual(et1.StringColumns.Keys.OrderBy(n => n).ToArray(), et2.StringColumns.Keys.OrderBy(n => n).ToArray()); - var columns1 = et1.Columns.ToEnumerable().OrderBy(c => c.Name).ToArray(); - var columns2 = et2.Columns.ToEnumerable().OrderBy(c => c.Name).ToArray(); + var columns1 = et1.Columns.OrderBy(c => c.Name).ToArray(); + var columns2 = et2.Columns.OrderBy(c => c.Name).ToArray(); Assert.AreEqual( columns1.Select(ec => ec.Name).ToArray(), @@ -104,9 +104,9 @@ public static bool IsSupersetOf(IEnumerable a, IEnumerable b) public static void AssertIsSupersetOf(EntityTable et1, EntityTable et2) { Assert.AreEqual(et1.Name, et2.Name); - Assert.IsTrue(IsSupersetOf(et1.DataColumns.Keys.ToEnumerable(), et2.DataColumns.Keys.ToEnumerable())); - Assert.IsTrue(IsSupersetOf(et1.IndexColumns.Keys.ToEnumerable(), et2.IndexColumns.Keys.ToEnumerable())); - Assert.IsTrue(IsSupersetOf(et1.StringColumns.Keys.ToEnumerable(), et2.StringColumns.Keys.ToEnumerable())); + Assert.IsTrue(IsSupersetOf(et1.DataColumns.Keys, et2.DataColumns.Keys)); + Assert.IsTrue(IsSupersetOf(et1.IndexColumns.Keys, et2.IndexColumns.Keys)); + Assert.IsTrue(IsSupersetOf(et1.StringColumns.Keys, et2.StringColumns.Keys)); var columns1 = et1.Columns.ToArray(); var columns2 = et2.Columns.ToArray(); @@ -137,9 +137,9 @@ public static void AssertIsSuperSetOf(Document d1, Document d2, bool skipGeometr var etKeys1 = d1.EntityTables.Keys; var etKeys2 = d2.EntityTables.Keys; - Assert.IsTrue(IsSupersetOf(etKeys1.ToEnumerable(), etKeys2.ToEnumerable())); + Assert.IsTrue(IsSupersetOf(etKeys1, etKeys2)); - foreach (var key in etKeys2.ToEnumerable()) + foreach (var key in etKeys2) { if (skipGeometryAndNodes && key.ToLowerInvariant().Contains("geometry")) continue; @@ -158,8 +158,8 @@ public static void AssertEquals(Document d1, Document d2, bool skipGeometryAndNo var schema2 = VimSchema.Create(d2._Document); Assert.IsTrue(VimSchema.IsSame(schema1, schema2)); - var entityTables1 = d1.EntityTables.Keys.ToEnumerable().OrderBy(n => n).ToArray(); - var entityTables2 = d2.EntityTables.Keys.ToEnumerable().OrderBy(n => n).ToArray(); + var entityTables1 = d1.EntityTables.Keys.OrderBy(n => n).ToArray(); + var entityTables2 = d2.EntityTables.Keys.OrderBy(n => n).ToArray(); Assert.AreEqual(entityTables1, entityTables2); foreach (var k in entityTables1) diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/Ordering.cs b/src/cs/vim/Vim.Format.Vimx.Conversion/Ordering.cs index d079bf0b..2424185b 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/Ordering.cs +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/Ordering.cs @@ -40,13 +40,13 @@ static string GetMeshName(G3dVim g3d, DocumentModel bim, int mesh) { var node = g3d.GetMeshInstances(mesh)[0]; - if (node < 0 || node >= bim.NodeElementIndex.Count) return ""; + if (node < 0 || node >= bim.NodeElementIndex.Length) return ""; var element = bim.NodeElementIndex[node]; - if (element < 0 || element >= bim.ElementCategoryIndex.Count) return ""; + if (element < 0 || element >= bim.ElementCategoryIndex.Length) return ""; var category = bim.ElementCategoryIndex[element]; - if (category < 0 || category >= bim.CategoryName.Count) return ""; + if (category < 0 || category >= bim.CategoryName.Length) return ""; var name = bim.CategoryName[category]; return name; diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs b/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs index 31d3e45f..804635ae 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs @@ -1,13 +1,12 @@ -using System.Linq; -using Vim.LinqArray; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using Vim.BFastLib; -using Vim.G3dNext; using Vim.Format.ObjectModel; using Vim.G3dNext; -using System.Collections.Generic; +using Vim.LinqArray; using Vim.Math3d; -using System.Diagnostics; -using System; +using Vim.Util; namespace Vim.Format.VimxLib.Conversion { @@ -106,7 +105,7 @@ public static G3dScene CreateScene(VimChunks chunks, DocumentModel bim) // bim instanceNodes[instance] = node; instanceGroups[instance] = element; - instanceTags[instance] = bim.ElementId.SafeGet(element, -1); + instanceTags[instance] = bim.ElementId.ElementAtOrDefault(element, -1); instance++; } From 90e3a2f8c2be79e1a63a2bf61c044bdcc0f2f4c3 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 09:50:09 -0400 Subject: [PATCH 070/104] addind missing functions --- src/cs/util/Vim.Util/LinqExtensions.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/cs/util/Vim.Util/LinqExtensions.cs b/src/cs/util/Vim.Util/LinqExtensions.cs index 56800bb0..ac6b9410 100644 --- a/src/cs/util/Vim.Util/LinqExtensions.cs +++ b/src/cs/util/Vim.Util/LinqExtensions.cs @@ -8,6 +8,32 @@ namespace Vim.Util { public static class LinqExtensions { + /// + /// Returns the index of the first element matching the given item. + /// + public static int IndexOf(this IList self, Func predicate) + { + for (var i = 0; i < self.Count; ++i) + { + if (predicate(self[i])) + return i; + } + return -1; + } + + /// + /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. + /// An IArray is not created automatically because it is an expensive operation that is potentially unneeded. + /// + public static IEnumerable IndicesWhere(this IList self, Func predicate) + { + for (var i = 0; i < self.Count; ++i) + { + if (predicate(self[i])) + yield return i; + } + } + /// /// Returns the top of a stack, or the default T value if none is present. /// From deb6a22fd94cd8710ddb81fb7560ccf94e6b561e Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 09:54:09 -0400 Subject: [PATCH 071/104] more extensions --- src/cs/util/Vim.Util/LinqExtensions.cs | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/cs/util/Vim.Util/LinqExtensions.cs b/src/cs/util/Vim.Util/LinqExtensions.cs index ac6b9410..8a6c0b0a 100644 --- a/src/cs/util/Vim.Util/LinqExtensions.cs +++ b/src/cs/util/Vim.Util/LinqExtensions.cs @@ -9,7 +9,7 @@ namespace Vim.Util public static class LinqExtensions { /// - /// Returns the index of the first element matching the given item. + /// Returns the index of the first element matching the given predicate. /// public static int IndexOf(this IList self, Func predicate) { @@ -21,9 +21,21 @@ public static int IndexOf(this IList self, Func predicate) return -1; } + /// + /// Returns the index of the first element matching the given item. + /// + public static int IndexOf(this IList self, T value) where T:IEquatable + { + for (var i = 0; i < self.Count; ++i) + { + if (self[i].Equals(value)) + return i; + } + return -1; + } + /// /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. - /// An IArray is not created automatically because it is an expensive operation that is potentially unneeded. /// public static IEnumerable IndicesWhere(this IList self, Func predicate) { @@ -34,6 +46,18 @@ public static IEnumerable IndicesWhere(this IList self, Func } } + /// + /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. + /// + public static IEnumerable IndicesWhere(this IList self, Func predicate) + { + for (var i = 0; i < self.Count; ++i) + { + if (predicate(self[i], i)) + yield return i; + } + } + /// /// Returns the top of a stack, or the default T value if none is present. /// From 5a1f66600877ee100232240aa2b7108ade721825 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 09:57:38 -0400 Subject: [PATCH 072/104] removed conflicting method --- src/cs/util/Vim.Util/LinqExtensions.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/cs/util/Vim.Util/LinqExtensions.cs b/src/cs/util/Vim.Util/LinqExtensions.cs index 8a6c0b0a..0f82d4a9 100644 --- a/src/cs/util/Vim.Util/LinqExtensions.cs +++ b/src/cs/util/Vim.Util/LinqExtensions.cs @@ -77,12 +77,6 @@ public static T OneOrDefault(this IEnumerable values) return items?.Count == 1 ? items[0] : default; } - /// - /// A helper function for append one or more items to an IEnumerable. - /// - public static IEnumerable Append(this IEnumerable xs, params T[] x) - => xs.Concat(x); - public static T ElementAtOrDefault(this IReadOnlyList items, int index, T @default = default(T)) => index < 0 || index >= items.Count ? @default : items[index]; From 298324d0a1d30fe73b5161ad7e4335bcd25f497d Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 14:17:29 -0400 Subject: [PATCH 073/104] added array methods --- src/cs/util/Vim.Util/LinqExtensions.cs | 15 ++++++++++++++- src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cs/util/Vim.Util/LinqExtensions.cs b/src/cs/util/Vim.Util/LinqExtensions.cs index 0f82d4a9..775fc40e 100644 --- a/src/cs/util/Vim.Util/LinqExtensions.cs +++ b/src/cs/util/Vim.Util/LinqExtensions.cs @@ -24,7 +24,7 @@ public static int IndexOf(this IList self, Func predicate) /// /// Returns the index of the first element matching the given item. /// - public static int IndexOf(this IList self, T value) where T:IEquatable + public static int IndexOf(this IList self, T value) where T : IEquatable { for (var i = 0; i < self.Count; ++i) { @@ -34,6 +34,19 @@ public static int IndexOf(this IList self, T value) where T:IEquatable return -1; } + /// + /// [a, b, c ..] => [0, a, a+b, a+b+c ...] + /// + public static int[] OffsetsFromCounts(this IList self) + { + var result = new int[self.Count]; + for (var i = 1; i < self.Count; ++i) + { + result[i] = result[i - 1] + self[i-1]; + } + return result; + } + /// /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. /// diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index 0f1989a3..a199e5a4 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -259,7 +259,7 @@ public static VimMesh Merge2(this VimMesh mesh, params VimMesh[] others) { var meshes = Enumerable.Empty() .Append(mesh) - .Append(others) + .Concat(others) .ToArray(); return meshes.Merge(); From df716a3eec45fc2740f3354f7b531012f47d84f1 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 14:35:46 -0400 Subject: [PATCH 074/104] Remove array ops --- .../vim/Vim.Format.Core/Geometry/ArrayOps.cs | 259 ------------------ .../vim/Vim.Format.Core/Geometry/ArrayOps.tt | 96 ------- .../Vim.Format.Core/Vim.Format.Core.csproj | 15 - 3 files changed, 370 deletions(-) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.tt diff --git a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs b/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs deleted file mode 100644 index d77a7f5a..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs +++ /dev/null @@ -1,259 +0,0 @@ - -// AUTOGENERATED FILE: DO NOT EDIT -// This file is generated from ArrayOps.tt - - -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - public static class ArrayOps - { - public static IArray< int > Add(this IArray< int > self, IArray< int > other) => self.Zip(other, MathOps.Add); - public static IArray< int > Add(this IArray< int > self, int scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< int > Add(this int self, IArray< int > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< int > Multiply(this IArray< int > self, IArray< int > other) => self.Zip(other, MathOps.Multiply); - public static IArray< int > Multiply(this IArray< int > self, int scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< int > Multiply(this int self, IArray< int > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< int > Subtract(this IArray< int > self, IArray< int > other) => self.Zip(other, MathOps.Subtract); - public static IArray< int > Subtract(this IArray< int > self, int scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< int > Subtract(this int self, IArray< int > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< int > Divide(this IArray< int > self, IArray< int > other) => self.Zip(other, MathOps.Divide); - public static IArray< int > Divide(this IArray< int > self, int scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< int > Divide(this int self, IArray< int > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< long > Add(this IArray< long > self, IArray< long > other) => self.Zip(other, MathOps.Add); - public static IArray< long > Add(this IArray< long > self, long scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< long > Add(this long self, IArray< long > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< long > Multiply(this IArray< long > self, IArray< long > other) => self.Zip(other, MathOps.Multiply); - public static IArray< long > Multiply(this IArray< long > self, long scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< long > Multiply(this long self, IArray< long > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< long > Subtract(this IArray< long > self, IArray< long > other) => self.Zip(other, MathOps.Subtract); - public static IArray< long > Subtract(this IArray< long > self, long scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< long > Subtract(this long self, IArray< long > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< long > Divide(this IArray< long > self, IArray< long > other) => self.Zip(other, MathOps.Divide); - public static IArray< long > Divide(this IArray< long > self, long scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< long > Divide(this long self, IArray< long > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< float > Add(this IArray< float > self, IArray< float > other) => self.Zip(other, MathOps.Add); - public static IArray< float > Add(this IArray< float > self, float scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< float > Add(this float self, IArray< float > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< float > Multiply(this IArray< float > self, IArray< float > other) => self.Zip(other, MathOps.Multiply); - public static IArray< float > Multiply(this IArray< float > self, float scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< float > Multiply(this float self, IArray< float > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< float > Subtract(this IArray< float > self, IArray< float > other) => self.Zip(other, MathOps.Subtract); - public static IArray< float > Subtract(this IArray< float > self, float scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< float > Subtract(this float self, IArray< float > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< float > Divide(this IArray< float > self, IArray< float > other) => self.Zip(other, MathOps.Divide); - public static IArray< float > Divide(this IArray< float > self, float scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< float > Divide(this float self, IArray< float > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< double > Add(this IArray< double > self, IArray< double > other) => self.Zip(other, MathOps.Add); - public static IArray< double > Add(this IArray< double > self, double scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< double > Add(this double self, IArray< double > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< double > Multiply(this IArray< double > self, IArray< double > other) => self.Zip(other, MathOps.Multiply); - public static IArray< double > Multiply(this IArray< double > self, double scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< double > Multiply(this double self, IArray< double > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< double > Subtract(this IArray< double > self, IArray< double > other) => self.Zip(other, MathOps.Subtract); - public static IArray< double > Subtract(this IArray< double > self, double scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< double > Subtract(this double self, IArray< double > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< double > Divide(this IArray< double > self, IArray< double > other) => self.Zip(other, MathOps.Divide); - public static IArray< double > Divide(this IArray< double > self, double scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< double > Divide(this double self, IArray< double > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< Vector2 > Add(this IArray< Vector2 > self, IArray< Vector2 > other) => self.Zip(other, MathOps.Add); - public static IArray< Vector2 > Add(this IArray< Vector2 > self, Vector2 scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< Vector2 > Add(this Vector2 self, IArray< Vector2 > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< Vector2 > Multiply(this IArray< Vector2 > self, IArray< Vector2 > other) => self.Zip(other, MathOps.Multiply); - public static IArray< Vector2 > Multiply(this IArray< Vector2 > self, Vector2 scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< Vector2 > Multiply(this Vector2 self, IArray< Vector2 > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< Vector2 > Subtract(this IArray< Vector2 > self, IArray< Vector2 > other) => self.Zip(other, MathOps.Subtract); - public static IArray< Vector2 > Subtract(this IArray< Vector2 > self, Vector2 scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< Vector2 > Subtract(this Vector2 self, IArray< Vector2 > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< Vector2 > Divide(this IArray< Vector2 > self, IArray< Vector2 > other) => self.Zip(other, MathOps.Divide); - public static IArray< Vector2 > Divide(this IArray< Vector2 > self, Vector2 scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< Vector2 > Divide(this Vector2 self, IArray< Vector2 > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< Vector3 > Add(this IArray< Vector3 > self, IArray< Vector3 > other) => self.Zip(other, MathOps.Add); - public static IArray< Vector3 > Add(this IArray< Vector3 > self, Vector3 scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< Vector3 > Add(this Vector3 self, IArray< Vector3 > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< Vector3 > Multiply(this IArray< Vector3 > self, IArray< Vector3 > other) => self.Zip(other, MathOps.Multiply); - public static IArray< Vector3 > Multiply(this IArray< Vector3 > self, Vector3 scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< Vector3 > Multiply(this Vector3 self, IArray< Vector3 > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< Vector3 > Subtract(this IArray< Vector3 > self, IArray< Vector3 > other) => self.Zip(other, MathOps.Subtract); - public static IArray< Vector3 > Subtract(this IArray< Vector3 > self, Vector3 scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< Vector3 > Subtract(this Vector3 self, IArray< Vector3 > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< Vector3 > Divide(this IArray< Vector3 > self, IArray< Vector3 > other) => self.Zip(other, MathOps.Divide); - public static IArray< Vector3 > Divide(this IArray< Vector3 > self, Vector3 scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< Vector3 > Divide(this Vector3 self, IArray< Vector3 > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< Vector4 > Add(this IArray< Vector4 > self, IArray< Vector4 > other) => self.Zip(other, MathOps.Add); - public static IArray< Vector4 > Add(this IArray< Vector4 > self, Vector4 scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< Vector4 > Add(this Vector4 self, IArray< Vector4 > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< Vector4 > Multiply(this IArray< Vector4 > self, IArray< Vector4 > other) => self.Zip(other, MathOps.Multiply); - public static IArray< Vector4 > Multiply(this IArray< Vector4 > self, Vector4 scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< Vector4 > Multiply(this Vector4 self, IArray< Vector4 > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< Vector4 > Subtract(this IArray< Vector4 > self, IArray< Vector4 > other) => self.Zip(other, MathOps.Subtract); - public static IArray< Vector4 > Subtract(this IArray< Vector4 > self, Vector4 scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< Vector4 > Subtract(this Vector4 self, IArray< Vector4 > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< Vector4 > Divide(this IArray< Vector4 > self, IArray< Vector4 > other) => self.Zip(other, MathOps.Divide); - public static IArray< Vector4 > Divide(this IArray< Vector4 > self, Vector4 scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< Vector4 > Divide(this Vector4 self, IArray< Vector4 > vector) => vector.Select(x => MathOps.Divide(self, x)); - - public static IArray Abs (this IArray< double > self) => self.Select(MathOps.Abs); - public static IArray Abs (this IArray< float > self) => self.Select(MathOps.Abs); - public static IArray Abs (this IArray< Vector2 > self) => self.Select(MathOps.Abs); - public static IArray Abs (this IArray< Vector3 > self) => self.Select(MathOps.Abs); - public static IArray Abs (this IArray< Vector4 > self) => self.Select(MathOps.Abs); - - public static IArray Acos (this IArray< double > self) => self.Select(MathOps.Acos); - public static IArray Acos (this IArray< float > self) => self.Select(MathOps.Acos); - public static IArray Acos (this IArray< Vector2 > self) => self.Select(MathOps.Acos); - public static IArray Acos (this IArray< Vector3 > self) => self.Select(MathOps.Acos); - public static IArray Acos (this IArray< Vector4 > self) => self.Select(MathOps.Acos); - - public static IArray Asin (this IArray< double > self) => self.Select(MathOps.Asin); - public static IArray Asin (this IArray< float > self) => self.Select(MathOps.Asin); - public static IArray Asin (this IArray< Vector2 > self) => self.Select(MathOps.Asin); - public static IArray Asin (this IArray< Vector3 > self) => self.Select(MathOps.Asin); - public static IArray Asin (this IArray< Vector4 > self) => self.Select(MathOps.Asin); - - public static IArray Atan (this IArray< double > self) => self.Select(MathOps.Atan); - public static IArray Atan (this IArray< float > self) => self.Select(MathOps.Atan); - public static IArray Atan (this IArray< Vector2 > self) => self.Select(MathOps.Atan); - public static IArray Atan (this IArray< Vector3 > self) => self.Select(MathOps.Atan); - public static IArray Atan (this IArray< Vector4 > self) => self.Select(MathOps.Atan); - - public static IArray Cos (this IArray< double > self) => self.Select(MathOps.Cos); - public static IArray Cos (this IArray< float > self) => self.Select(MathOps.Cos); - public static IArray Cos (this IArray< Vector2 > self) => self.Select(MathOps.Cos); - public static IArray Cos (this IArray< Vector3 > self) => self.Select(MathOps.Cos); - public static IArray Cos (this IArray< Vector4 > self) => self.Select(MathOps.Cos); - - public static IArray Cosh (this IArray< double > self) => self.Select(MathOps.Cosh); - public static IArray Cosh (this IArray< float > self) => self.Select(MathOps.Cosh); - public static IArray Cosh (this IArray< Vector2 > self) => self.Select(MathOps.Cosh); - public static IArray Cosh (this IArray< Vector3 > self) => self.Select(MathOps.Cosh); - public static IArray Cosh (this IArray< Vector4 > self) => self.Select(MathOps.Cosh); - - public static IArray Exp (this IArray< double > self) => self.Select(MathOps.Exp); - public static IArray Exp (this IArray< float > self) => self.Select(MathOps.Exp); - public static IArray Exp (this IArray< Vector2 > self) => self.Select(MathOps.Exp); - public static IArray Exp (this IArray< Vector3 > self) => self.Select(MathOps.Exp); - public static IArray Exp (this IArray< Vector4 > self) => self.Select(MathOps.Exp); - - public static IArray Log (this IArray< double > self) => self.Select(MathOps.Log); - public static IArray Log (this IArray< float > self) => self.Select(MathOps.Log); - public static IArray Log (this IArray< Vector2 > self) => self.Select(MathOps.Log); - public static IArray Log (this IArray< Vector3 > self) => self.Select(MathOps.Log); - public static IArray Log (this IArray< Vector4 > self) => self.Select(MathOps.Log); - - public static IArray Log10 (this IArray< double > self) => self.Select(MathOps.Log10); - public static IArray Log10 (this IArray< float > self) => self.Select(MathOps.Log10); - public static IArray Log10 (this IArray< Vector2 > self) => self.Select(MathOps.Log10); - public static IArray Log10 (this IArray< Vector3 > self) => self.Select(MathOps.Log10); - public static IArray Log10 (this IArray< Vector4 > self) => self.Select(MathOps.Log10); - - public static IArray Sin (this IArray< double > self) => self.Select(MathOps.Sin); - public static IArray Sin (this IArray< float > self) => self.Select(MathOps.Sin); - public static IArray Sin (this IArray< Vector2 > self) => self.Select(MathOps.Sin); - public static IArray Sin (this IArray< Vector3 > self) => self.Select(MathOps.Sin); - public static IArray Sin (this IArray< Vector4 > self) => self.Select(MathOps.Sin); - - public static IArray Sinh (this IArray< double > self) => self.Select(MathOps.Sinh); - public static IArray Sinh (this IArray< float > self) => self.Select(MathOps.Sinh); - public static IArray Sinh (this IArray< Vector2 > self) => self.Select(MathOps.Sinh); - public static IArray Sinh (this IArray< Vector3 > self) => self.Select(MathOps.Sinh); - public static IArray Sinh (this IArray< Vector4 > self) => self.Select(MathOps.Sinh); - - public static IArray Sqrt (this IArray< double > self) => self.Select(MathOps.Sqrt); - public static IArray Sqrt (this IArray< float > self) => self.Select(MathOps.Sqrt); - public static IArray Sqrt (this IArray< Vector2 > self) => self.Select(MathOps.Sqrt); - public static IArray Sqrt (this IArray< Vector3 > self) => self.Select(MathOps.Sqrt); - public static IArray Sqrt (this IArray< Vector4 > self) => self.Select(MathOps.Sqrt); - - public static IArray Tan (this IArray< double > self) => self.Select(MathOps.Tan); - public static IArray Tan (this IArray< float > self) => self.Select(MathOps.Tan); - public static IArray Tan (this IArray< Vector2 > self) => self.Select(MathOps.Tan); - public static IArray Tan (this IArray< Vector3 > self) => self.Select(MathOps.Tan); - public static IArray Tan (this IArray< Vector4 > self) => self.Select(MathOps.Tan); - - public static IArray Tanh (this IArray< double > self) => self.Select(MathOps.Tanh); - public static IArray Tanh (this IArray< float > self) => self.Select(MathOps.Tanh); - public static IArray Tanh (this IArray< Vector2 > self) => self.Select(MathOps.Tanh); - public static IArray Tanh (this IArray< Vector3 > self) => self.Select(MathOps.Tanh); - public static IArray Tanh (this IArray< Vector4 > self) => self.Select(MathOps.Tanh); - - public static IArray Sqr (this IArray< double > self) => self.Select(MathOps.Sqr); - public static IArray Sqr (this IArray< float > self) => self.Select(MathOps.Sqr); - public static IArray Sqr (this IArray< Vector2 > self) => self.Select(MathOps.Sqr); - public static IArray Sqr (this IArray< Vector3 > self) => self.Select(MathOps.Sqr); - public static IArray Sqr (this IArray< Vector4 > self) => self.Select(MathOps.Sqr); - - public static IArray Inverse (this IArray< double > self) => self.Select(MathOps.Inverse); - public static IArray Inverse (this IArray< float > self) => self.Select(MathOps.Inverse); - public static IArray Inverse (this IArray< Vector2 > self) => self.Select(MathOps.Inverse); - public static IArray Inverse (this IArray< Vector3 > self) => self.Select(MathOps.Inverse); - public static IArray Inverse (this IArray< Vector4 > self) => self.Select(MathOps.Inverse); - - public static IArray Ceiling (this IArray< double > self) => self.Select(MathOps.Ceiling); - public static IArray Ceiling (this IArray< float > self) => self.Select(MathOps.Ceiling); - public static IArray Ceiling (this IArray< Vector2 > self) => self.Select(MathOps.Ceiling); - public static IArray Ceiling (this IArray< Vector3 > self) => self.Select(MathOps.Ceiling); - public static IArray Ceiling (this IArray< Vector4 > self) => self.Select(MathOps.Ceiling); - - public static IArray Floor (this IArray< double > self) => self.Select(MathOps.Floor); - public static IArray Floor (this IArray< float > self) => self.Select(MathOps.Floor); - public static IArray Floor (this IArray< Vector2 > self) => self.Select(MathOps.Floor); - public static IArray Floor (this IArray< Vector3 > self) => self.Select(MathOps.Floor); - public static IArray Floor (this IArray< Vector4 > self) => self.Select(MathOps.Floor); - - public static IArray Round (this IArray< double > self) => self.Select(MathOps.Round); - public static IArray Round (this IArray< float > self) => self.Select(MathOps.Round); - public static IArray Round (this IArray< Vector2 > self) => self.Select(MathOps.Round); - public static IArray Round (this IArray< Vector3 > self) => self.Select(MathOps.Round); - public static IArray Round (this IArray< Vector4 > self) => self.Select(MathOps.Round); - - public static IArray Truncate (this IArray< double > self) => self.Select(MathOps.Truncate); - public static IArray Truncate (this IArray< float > self) => self.Select(MathOps.Truncate); - public static IArray Truncate (this IArray< Vector2 > self) => self.Select(MathOps.Truncate); - public static IArray Truncate (this IArray< Vector3 > self) => self.Select(MathOps.Truncate); - public static IArray Truncate (this IArray< Vector4 > self) => self.Select(MathOps.Truncate); - // TODO: do this over all over the numerical types - public static long Sum(this IArray self) => self.Aggregate(0L, (x, y) => x + y); - public static long Sum(this IArray self) => self.Aggregate(0L, (x, y) => x + y); - public static double Sum(this IArray self) => self.Aggregate(0.0, (x, y) => x + y); - public static double Sum(this IArray self) => self.Aggregate(0.0, (x, y) => x + y); - public static Vector2 Sum(this IArray self) => self.Aggregate(Vector2.Zero, (x, y) => x + y); - public static Vector3 Sum(this IArray self) => self.Aggregate(Vector3.Zero, (x, y) => x + y); - public static Vector4 Sum(this IArray self) => self.Aggregate(Vector4.Zero, (x, y) => x + y); - - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static Vector2 Average(this IArray self) => self.Sum() / self.Count; - public static Vector3 Average(this IArray self) => self.Sum() / self.Count; - public static Vector4 Average(this IArray self) => self.Sum() / self.Count; - - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector2 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector3 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector4 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector2 StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector3 StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector4 StdDev(this IArray self) => self.Variance().Sqrt(); - - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - - } -} diff --git a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.tt b/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.tt deleted file mode 100644 index 2858a417..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.tt +++ /dev/null @@ -1,96 +0,0 @@ -<#@ template language="C#" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System" #> -<#@ import namespace="System.IO" #> -<#@ import namespace="System.Diagnostics" #> -<#@ import namespace="System.Linq" #> - -// AUTOGENERATED FILE: DO NOT EDIT -// This file is generated from ArrayOps.tt - -<# -var nonVectorTypes = new[] { "int", "long", "float", "double" }; -var vectorTypes = new[] { "Vector2", "Vector3", "Vector4" }; -var types = nonVectorTypes.Concat(vectorTypes); -var intTypes = new[] { "int", "long" }; -var araBinaryOps = new[] { "Add", "Sub", "Mul", "Div" }; -var araCompOps = new[] { "Gt", "Lt", "GtEq", "LtEq", "Eq", "NEq" }; -var sysUnaryOps = new[] { "Abs", "Acos", "Asin", "Atan", "Cos", "Cosh", "Exp", "Log", "Log10", "Sin", "Sinh", "Sqrt", "Tan", "Tanh" }; -var araUnaryOps = new[] { "Sqr", "Inverse", "Ceiling", "Floor", "Round", "Truncate" }; -var allUnaryOps = sysUnaryOps.Concat(araUnaryOps); -#> - -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - public static class ArrayOps - { - -<# -foreach (var t in types) { -foreach (var op in new[] { "Add", "Multiply", "Subtract", "Divide" }) -{ -#> - public static IArray< <#= t #> > <#= op #>(this IArray< <#= t #> > self, IArray< <#= t #> > other) => self.Zip(other, MathOps.<#= op #>); - public static IArray< <#= t #> > <#= op #>(this IArray< <#= t #> > self, <#= t #> scalar) => self.Select(x => MathOps.<#= op #>(x, scalar)); - public static IArray< <#= t #> > <#= op #>(this <#= t #> self, IArray< <#= t #> > vector) => vector.Select(x => MathOps.<#= op #>(self, x)); -<# -} -} -foreach (var op in allUnaryOps) { -#> - - public static IArray <#= op #> (this IArray< double > self) => self.Select(MathOps.<#= op #>); - public static IArray <#= op #> (this IArray< float > self) => self.Select(MathOps.<#= op #>); - public static IArray <#= op #> (this IArray< Vector2 > self) => self.Select(MathOps.<#= op #>); - public static IArray <#= op #> (this IArray< Vector3 > self) => self.Select(MathOps.<#= op #>); - public static IArray <#= op #> (this IArray< Vector4 > self) => self.Select(MathOps.<#= op #>); -<# -} -#> - // TODO: do this over all over the numerical types - public static long Sum(this IArray self) => self.Aggregate(0L, (x, y) => x + y); - public static long Sum(this IArray self) => self.Aggregate(0L, (x, y) => x + y); - public static double Sum(this IArray self) => self.Aggregate(0.0, (x, y) => x + y); - public static double Sum(this IArray self) => self.Aggregate(0.0, (x, y) => x + y); - public static Vector2 Sum(this IArray self) => self.Aggregate(Vector2.Zero, (x, y) => x + y); - public static Vector3 Sum(this IArray self) => self.Aggregate(Vector3.Zero, (x, y) => x + y); - public static Vector4 Sum(this IArray self) => self.Aggregate(Vector4.Zero, (x, y) => x + y); - - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static Vector2 Average(this IArray self) => self.Sum() / self.Count; - public static Vector3 Average(this IArray self) => self.Sum() / self.Count; - public static Vector4 Average(this IArray self) => self.Sum() / self.Count; - - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector2 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector3 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector4 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector2 StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector3 StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector4 StdDev(this IArray self) => self.Variance().Sqrt(); - - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - - } -} diff --git a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj index 00b498be..f2908353 100644 --- a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj +++ b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj @@ -23,21 +23,6 @@ - - - - TextTemplatingFileGenerator - ArrayOps.cs - - - - - - True - True - ArrayOps.tt - - True From 6422ca555270117e8c9c649bf27f7be7f3d7bc2a Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 14:37:25 -0400 Subject: [PATCH 075/104] removed array ops renamed linqextensions ->collectionextensions --- ...qExtensions.cs => CollectionExtensions.cs} | 43 +-- .../vim/Vim.Format.Core/Geometry/ArrayOps.cs | 259 ------------------ .../vim/Vim.Format.Core/Geometry/ArrayOps.tt | 96 ------- .../SerializableDocumentTests.cs | 1 + 4 files changed, 3 insertions(+), 396 deletions(-) rename src/cs/util/Vim.Util/{LinqExtensions.cs => CollectionExtensions.cs} (85%) delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs delete mode 100644 src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.tt diff --git a/src/cs/util/Vim.Util/LinqExtensions.cs b/src/cs/util/Vim.Util/CollectionExtensions.cs similarity index 85% rename from src/cs/util/Vim.Util/LinqExtensions.cs rename to src/cs/util/Vim.Util/CollectionExtensions.cs index 775fc40e..cadcfa54 100644 --- a/src/cs/util/Vim.Util/LinqExtensions.cs +++ b/src/cs/util/Vim.Util/CollectionExtensions.cs @@ -2,51 +2,12 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Vim.Util { - public static class LinqExtensions + public static class CollectionExtensions { - /// - /// Returns the index of the first element matching the given predicate. - /// - public static int IndexOf(this IList self, Func predicate) - { - for (var i = 0; i < self.Count; ++i) - { - if (predicate(self[i])) - return i; - } - return -1; - } - - /// - /// Returns the index of the first element matching the given item. - /// - public static int IndexOf(this IList self, T value) where T : IEquatable - { - for (var i = 0; i < self.Count; ++i) - { - if (self[i].Equals(value)) - return i; - } - return -1; - } - - /// - /// [a, b, c ..] => [0, a, a+b, a+b+c ...] - /// - public static int[] OffsetsFromCounts(this IList self) - { - var result = new int[self.Count]; - for (var i = 1; i < self.Count; ++i) - { - result[i] = result[i - 1] + self[i-1]; - } - return result; - } - + /// /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. /// diff --git a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs b/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs deleted file mode 100644 index d77a7f5a..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.cs +++ /dev/null @@ -1,259 +0,0 @@ - -// AUTOGENERATED FILE: DO NOT EDIT -// This file is generated from ArrayOps.tt - - -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - public static class ArrayOps - { - public static IArray< int > Add(this IArray< int > self, IArray< int > other) => self.Zip(other, MathOps.Add); - public static IArray< int > Add(this IArray< int > self, int scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< int > Add(this int self, IArray< int > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< int > Multiply(this IArray< int > self, IArray< int > other) => self.Zip(other, MathOps.Multiply); - public static IArray< int > Multiply(this IArray< int > self, int scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< int > Multiply(this int self, IArray< int > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< int > Subtract(this IArray< int > self, IArray< int > other) => self.Zip(other, MathOps.Subtract); - public static IArray< int > Subtract(this IArray< int > self, int scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< int > Subtract(this int self, IArray< int > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< int > Divide(this IArray< int > self, IArray< int > other) => self.Zip(other, MathOps.Divide); - public static IArray< int > Divide(this IArray< int > self, int scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< int > Divide(this int self, IArray< int > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< long > Add(this IArray< long > self, IArray< long > other) => self.Zip(other, MathOps.Add); - public static IArray< long > Add(this IArray< long > self, long scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< long > Add(this long self, IArray< long > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< long > Multiply(this IArray< long > self, IArray< long > other) => self.Zip(other, MathOps.Multiply); - public static IArray< long > Multiply(this IArray< long > self, long scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< long > Multiply(this long self, IArray< long > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< long > Subtract(this IArray< long > self, IArray< long > other) => self.Zip(other, MathOps.Subtract); - public static IArray< long > Subtract(this IArray< long > self, long scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< long > Subtract(this long self, IArray< long > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< long > Divide(this IArray< long > self, IArray< long > other) => self.Zip(other, MathOps.Divide); - public static IArray< long > Divide(this IArray< long > self, long scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< long > Divide(this long self, IArray< long > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< float > Add(this IArray< float > self, IArray< float > other) => self.Zip(other, MathOps.Add); - public static IArray< float > Add(this IArray< float > self, float scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< float > Add(this float self, IArray< float > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< float > Multiply(this IArray< float > self, IArray< float > other) => self.Zip(other, MathOps.Multiply); - public static IArray< float > Multiply(this IArray< float > self, float scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< float > Multiply(this float self, IArray< float > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< float > Subtract(this IArray< float > self, IArray< float > other) => self.Zip(other, MathOps.Subtract); - public static IArray< float > Subtract(this IArray< float > self, float scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< float > Subtract(this float self, IArray< float > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< float > Divide(this IArray< float > self, IArray< float > other) => self.Zip(other, MathOps.Divide); - public static IArray< float > Divide(this IArray< float > self, float scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< float > Divide(this float self, IArray< float > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< double > Add(this IArray< double > self, IArray< double > other) => self.Zip(other, MathOps.Add); - public static IArray< double > Add(this IArray< double > self, double scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< double > Add(this double self, IArray< double > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< double > Multiply(this IArray< double > self, IArray< double > other) => self.Zip(other, MathOps.Multiply); - public static IArray< double > Multiply(this IArray< double > self, double scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< double > Multiply(this double self, IArray< double > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< double > Subtract(this IArray< double > self, IArray< double > other) => self.Zip(other, MathOps.Subtract); - public static IArray< double > Subtract(this IArray< double > self, double scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< double > Subtract(this double self, IArray< double > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< double > Divide(this IArray< double > self, IArray< double > other) => self.Zip(other, MathOps.Divide); - public static IArray< double > Divide(this IArray< double > self, double scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< double > Divide(this double self, IArray< double > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< Vector2 > Add(this IArray< Vector2 > self, IArray< Vector2 > other) => self.Zip(other, MathOps.Add); - public static IArray< Vector2 > Add(this IArray< Vector2 > self, Vector2 scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< Vector2 > Add(this Vector2 self, IArray< Vector2 > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< Vector2 > Multiply(this IArray< Vector2 > self, IArray< Vector2 > other) => self.Zip(other, MathOps.Multiply); - public static IArray< Vector2 > Multiply(this IArray< Vector2 > self, Vector2 scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< Vector2 > Multiply(this Vector2 self, IArray< Vector2 > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< Vector2 > Subtract(this IArray< Vector2 > self, IArray< Vector2 > other) => self.Zip(other, MathOps.Subtract); - public static IArray< Vector2 > Subtract(this IArray< Vector2 > self, Vector2 scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< Vector2 > Subtract(this Vector2 self, IArray< Vector2 > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< Vector2 > Divide(this IArray< Vector2 > self, IArray< Vector2 > other) => self.Zip(other, MathOps.Divide); - public static IArray< Vector2 > Divide(this IArray< Vector2 > self, Vector2 scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< Vector2 > Divide(this Vector2 self, IArray< Vector2 > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< Vector3 > Add(this IArray< Vector3 > self, IArray< Vector3 > other) => self.Zip(other, MathOps.Add); - public static IArray< Vector3 > Add(this IArray< Vector3 > self, Vector3 scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< Vector3 > Add(this Vector3 self, IArray< Vector3 > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< Vector3 > Multiply(this IArray< Vector3 > self, IArray< Vector3 > other) => self.Zip(other, MathOps.Multiply); - public static IArray< Vector3 > Multiply(this IArray< Vector3 > self, Vector3 scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< Vector3 > Multiply(this Vector3 self, IArray< Vector3 > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< Vector3 > Subtract(this IArray< Vector3 > self, IArray< Vector3 > other) => self.Zip(other, MathOps.Subtract); - public static IArray< Vector3 > Subtract(this IArray< Vector3 > self, Vector3 scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< Vector3 > Subtract(this Vector3 self, IArray< Vector3 > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< Vector3 > Divide(this IArray< Vector3 > self, IArray< Vector3 > other) => self.Zip(other, MathOps.Divide); - public static IArray< Vector3 > Divide(this IArray< Vector3 > self, Vector3 scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< Vector3 > Divide(this Vector3 self, IArray< Vector3 > vector) => vector.Select(x => MathOps.Divide(self, x)); - public static IArray< Vector4 > Add(this IArray< Vector4 > self, IArray< Vector4 > other) => self.Zip(other, MathOps.Add); - public static IArray< Vector4 > Add(this IArray< Vector4 > self, Vector4 scalar) => self.Select(x => MathOps.Add(x, scalar)); - public static IArray< Vector4 > Add(this Vector4 self, IArray< Vector4 > vector) => vector.Select(x => MathOps.Add(self, x)); - public static IArray< Vector4 > Multiply(this IArray< Vector4 > self, IArray< Vector4 > other) => self.Zip(other, MathOps.Multiply); - public static IArray< Vector4 > Multiply(this IArray< Vector4 > self, Vector4 scalar) => self.Select(x => MathOps.Multiply(x, scalar)); - public static IArray< Vector4 > Multiply(this Vector4 self, IArray< Vector4 > vector) => vector.Select(x => MathOps.Multiply(self, x)); - public static IArray< Vector4 > Subtract(this IArray< Vector4 > self, IArray< Vector4 > other) => self.Zip(other, MathOps.Subtract); - public static IArray< Vector4 > Subtract(this IArray< Vector4 > self, Vector4 scalar) => self.Select(x => MathOps.Subtract(x, scalar)); - public static IArray< Vector4 > Subtract(this Vector4 self, IArray< Vector4 > vector) => vector.Select(x => MathOps.Subtract(self, x)); - public static IArray< Vector4 > Divide(this IArray< Vector4 > self, IArray< Vector4 > other) => self.Zip(other, MathOps.Divide); - public static IArray< Vector4 > Divide(this IArray< Vector4 > self, Vector4 scalar) => self.Select(x => MathOps.Divide(x, scalar)); - public static IArray< Vector4 > Divide(this Vector4 self, IArray< Vector4 > vector) => vector.Select(x => MathOps.Divide(self, x)); - - public static IArray Abs (this IArray< double > self) => self.Select(MathOps.Abs); - public static IArray Abs (this IArray< float > self) => self.Select(MathOps.Abs); - public static IArray Abs (this IArray< Vector2 > self) => self.Select(MathOps.Abs); - public static IArray Abs (this IArray< Vector3 > self) => self.Select(MathOps.Abs); - public static IArray Abs (this IArray< Vector4 > self) => self.Select(MathOps.Abs); - - public static IArray Acos (this IArray< double > self) => self.Select(MathOps.Acos); - public static IArray Acos (this IArray< float > self) => self.Select(MathOps.Acos); - public static IArray Acos (this IArray< Vector2 > self) => self.Select(MathOps.Acos); - public static IArray Acos (this IArray< Vector3 > self) => self.Select(MathOps.Acos); - public static IArray Acos (this IArray< Vector4 > self) => self.Select(MathOps.Acos); - - public static IArray Asin (this IArray< double > self) => self.Select(MathOps.Asin); - public static IArray Asin (this IArray< float > self) => self.Select(MathOps.Asin); - public static IArray Asin (this IArray< Vector2 > self) => self.Select(MathOps.Asin); - public static IArray Asin (this IArray< Vector3 > self) => self.Select(MathOps.Asin); - public static IArray Asin (this IArray< Vector4 > self) => self.Select(MathOps.Asin); - - public static IArray Atan (this IArray< double > self) => self.Select(MathOps.Atan); - public static IArray Atan (this IArray< float > self) => self.Select(MathOps.Atan); - public static IArray Atan (this IArray< Vector2 > self) => self.Select(MathOps.Atan); - public static IArray Atan (this IArray< Vector3 > self) => self.Select(MathOps.Atan); - public static IArray Atan (this IArray< Vector4 > self) => self.Select(MathOps.Atan); - - public static IArray Cos (this IArray< double > self) => self.Select(MathOps.Cos); - public static IArray Cos (this IArray< float > self) => self.Select(MathOps.Cos); - public static IArray Cos (this IArray< Vector2 > self) => self.Select(MathOps.Cos); - public static IArray Cos (this IArray< Vector3 > self) => self.Select(MathOps.Cos); - public static IArray Cos (this IArray< Vector4 > self) => self.Select(MathOps.Cos); - - public static IArray Cosh (this IArray< double > self) => self.Select(MathOps.Cosh); - public static IArray Cosh (this IArray< float > self) => self.Select(MathOps.Cosh); - public static IArray Cosh (this IArray< Vector2 > self) => self.Select(MathOps.Cosh); - public static IArray Cosh (this IArray< Vector3 > self) => self.Select(MathOps.Cosh); - public static IArray Cosh (this IArray< Vector4 > self) => self.Select(MathOps.Cosh); - - public static IArray Exp (this IArray< double > self) => self.Select(MathOps.Exp); - public static IArray Exp (this IArray< float > self) => self.Select(MathOps.Exp); - public static IArray Exp (this IArray< Vector2 > self) => self.Select(MathOps.Exp); - public static IArray Exp (this IArray< Vector3 > self) => self.Select(MathOps.Exp); - public static IArray Exp (this IArray< Vector4 > self) => self.Select(MathOps.Exp); - - public static IArray Log (this IArray< double > self) => self.Select(MathOps.Log); - public static IArray Log (this IArray< float > self) => self.Select(MathOps.Log); - public static IArray Log (this IArray< Vector2 > self) => self.Select(MathOps.Log); - public static IArray Log (this IArray< Vector3 > self) => self.Select(MathOps.Log); - public static IArray Log (this IArray< Vector4 > self) => self.Select(MathOps.Log); - - public static IArray Log10 (this IArray< double > self) => self.Select(MathOps.Log10); - public static IArray Log10 (this IArray< float > self) => self.Select(MathOps.Log10); - public static IArray Log10 (this IArray< Vector2 > self) => self.Select(MathOps.Log10); - public static IArray Log10 (this IArray< Vector3 > self) => self.Select(MathOps.Log10); - public static IArray Log10 (this IArray< Vector4 > self) => self.Select(MathOps.Log10); - - public static IArray Sin (this IArray< double > self) => self.Select(MathOps.Sin); - public static IArray Sin (this IArray< float > self) => self.Select(MathOps.Sin); - public static IArray Sin (this IArray< Vector2 > self) => self.Select(MathOps.Sin); - public static IArray Sin (this IArray< Vector3 > self) => self.Select(MathOps.Sin); - public static IArray Sin (this IArray< Vector4 > self) => self.Select(MathOps.Sin); - - public static IArray Sinh (this IArray< double > self) => self.Select(MathOps.Sinh); - public static IArray Sinh (this IArray< float > self) => self.Select(MathOps.Sinh); - public static IArray Sinh (this IArray< Vector2 > self) => self.Select(MathOps.Sinh); - public static IArray Sinh (this IArray< Vector3 > self) => self.Select(MathOps.Sinh); - public static IArray Sinh (this IArray< Vector4 > self) => self.Select(MathOps.Sinh); - - public static IArray Sqrt (this IArray< double > self) => self.Select(MathOps.Sqrt); - public static IArray Sqrt (this IArray< float > self) => self.Select(MathOps.Sqrt); - public static IArray Sqrt (this IArray< Vector2 > self) => self.Select(MathOps.Sqrt); - public static IArray Sqrt (this IArray< Vector3 > self) => self.Select(MathOps.Sqrt); - public static IArray Sqrt (this IArray< Vector4 > self) => self.Select(MathOps.Sqrt); - - public static IArray Tan (this IArray< double > self) => self.Select(MathOps.Tan); - public static IArray Tan (this IArray< float > self) => self.Select(MathOps.Tan); - public static IArray Tan (this IArray< Vector2 > self) => self.Select(MathOps.Tan); - public static IArray Tan (this IArray< Vector3 > self) => self.Select(MathOps.Tan); - public static IArray Tan (this IArray< Vector4 > self) => self.Select(MathOps.Tan); - - public static IArray Tanh (this IArray< double > self) => self.Select(MathOps.Tanh); - public static IArray Tanh (this IArray< float > self) => self.Select(MathOps.Tanh); - public static IArray Tanh (this IArray< Vector2 > self) => self.Select(MathOps.Tanh); - public static IArray Tanh (this IArray< Vector3 > self) => self.Select(MathOps.Tanh); - public static IArray Tanh (this IArray< Vector4 > self) => self.Select(MathOps.Tanh); - - public static IArray Sqr (this IArray< double > self) => self.Select(MathOps.Sqr); - public static IArray Sqr (this IArray< float > self) => self.Select(MathOps.Sqr); - public static IArray Sqr (this IArray< Vector2 > self) => self.Select(MathOps.Sqr); - public static IArray Sqr (this IArray< Vector3 > self) => self.Select(MathOps.Sqr); - public static IArray Sqr (this IArray< Vector4 > self) => self.Select(MathOps.Sqr); - - public static IArray Inverse (this IArray< double > self) => self.Select(MathOps.Inverse); - public static IArray Inverse (this IArray< float > self) => self.Select(MathOps.Inverse); - public static IArray Inverse (this IArray< Vector2 > self) => self.Select(MathOps.Inverse); - public static IArray Inverse (this IArray< Vector3 > self) => self.Select(MathOps.Inverse); - public static IArray Inverse (this IArray< Vector4 > self) => self.Select(MathOps.Inverse); - - public static IArray Ceiling (this IArray< double > self) => self.Select(MathOps.Ceiling); - public static IArray Ceiling (this IArray< float > self) => self.Select(MathOps.Ceiling); - public static IArray Ceiling (this IArray< Vector2 > self) => self.Select(MathOps.Ceiling); - public static IArray Ceiling (this IArray< Vector3 > self) => self.Select(MathOps.Ceiling); - public static IArray Ceiling (this IArray< Vector4 > self) => self.Select(MathOps.Ceiling); - - public static IArray Floor (this IArray< double > self) => self.Select(MathOps.Floor); - public static IArray Floor (this IArray< float > self) => self.Select(MathOps.Floor); - public static IArray Floor (this IArray< Vector2 > self) => self.Select(MathOps.Floor); - public static IArray Floor (this IArray< Vector3 > self) => self.Select(MathOps.Floor); - public static IArray Floor (this IArray< Vector4 > self) => self.Select(MathOps.Floor); - - public static IArray Round (this IArray< double > self) => self.Select(MathOps.Round); - public static IArray Round (this IArray< float > self) => self.Select(MathOps.Round); - public static IArray Round (this IArray< Vector2 > self) => self.Select(MathOps.Round); - public static IArray Round (this IArray< Vector3 > self) => self.Select(MathOps.Round); - public static IArray Round (this IArray< Vector4 > self) => self.Select(MathOps.Round); - - public static IArray Truncate (this IArray< double > self) => self.Select(MathOps.Truncate); - public static IArray Truncate (this IArray< float > self) => self.Select(MathOps.Truncate); - public static IArray Truncate (this IArray< Vector2 > self) => self.Select(MathOps.Truncate); - public static IArray Truncate (this IArray< Vector3 > self) => self.Select(MathOps.Truncate); - public static IArray Truncate (this IArray< Vector4 > self) => self.Select(MathOps.Truncate); - // TODO: do this over all over the numerical types - public static long Sum(this IArray self) => self.Aggregate(0L, (x, y) => x + y); - public static long Sum(this IArray self) => self.Aggregate(0L, (x, y) => x + y); - public static double Sum(this IArray self) => self.Aggregate(0.0, (x, y) => x + y); - public static double Sum(this IArray self) => self.Aggregate(0.0, (x, y) => x + y); - public static Vector2 Sum(this IArray self) => self.Aggregate(Vector2.Zero, (x, y) => x + y); - public static Vector3 Sum(this IArray self) => self.Aggregate(Vector3.Zero, (x, y) => x + y); - public static Vector4 Sum(this IArray self) => self.Aggregate(Vector4.Zero, (x, y) => x + y); - - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static Vector2 Average(this IArray self) => self.Sum() / self.Count; - public static Vector3 Average(this IArray self) => self.Sum() / self.Count; - public static Vector4 Average(this IArray self) => self.Sum() / self.Count; - - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector2 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector3 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector4 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector2 StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector3 StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector4 StdDev(this IArray self) => self.Variance().Sqrt(); - - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - - } -} diff --git a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.tt b/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.tt deleted file mode 100644 index 2858a417..00000000 --- a/src/cs/vim/Vim.Format.Core/Geometry/ArrayOps.tt +++ /dev/null @@ -1,96 +0,0 @@ -<#@ template language="C#" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System" #> -<#@ import namespace="System.IO" #> -<#@ import namespace="System.Diagnostics" #> -<#@ import namespace="System.Linq" #> - -// AUTOGENERATED FILE: DO NOT EDIT -// This file is generated from ArrayOps.tt - -<# -var nonVectorTypes = new[] { "int", "long", "float", "double" }; -var vectorTypes = new[] { "Vector2", "Vector3", "Vector4" }; -var types = nonVectorTypes.Concat(vectorTypes); -var intTypes = new[] { "int", "long" }; -var araBinaryOps = new[] { "Add", "Sub", "Mul", "Div" }; -var araCompOps = new[] { "Gt", "Lt", "GtEq", "LtEq", "Eq", "NEq" }; -var sysUnaryOps = new[] { "Abs", "Acos", "Asin", "Atan", "Cos", "Cosh", "Exp", "Log", "Log10", "Sin", "Sinh", "Sqrt", "Tan", "Tanh" }; -var araUnaryOps = new[] { "Sqr", "Inverse", "Ceiling", "Floor", "Round", "Truncate" }; -var allUnaryOps = sysUnaryOps.Concat(araUnaryOps); -#> - -using Vim.LinqArray; -using Vim.Math3d; - -namespace Vim.Format.Geometry -{ - public static class ArrayOps - { - -<# -foreach (var t in types) { -foreach (var op in new[] { "Add", "Multiply", "Subtract", "Divide" }) -{ -#> - public static IArray< <#= t #> > <#= op #>(this IArray< <#= t #> > self, IArray< <#= t #> > other) => self.Zip(other, MathOps.<#= op #>); - public static IArray< <#= t #> > <#= op #>(this IArray< <#= t #> > self, <#= t #> scalar) => self.Select(x => MathOps.<#= op #>(x, scalar)); - public static IArray< <#= t #> > <#= op #>(this <#= t #> self, IArray< <#= t #> > vector) => vector.Select(x => MathOps.<#= op #>(self, x)); -<# -} -} -foreach (var op in allUnaryOps) { -#> - - public static IArray <#= op #> (this IArray< double > self) => self.Select(MathOps.<#= op #>); - public static IArray <#= op #> (this IArray< float > self) => self.Select(MathOps.<#= op #>); - public static IArray <#= op #> (this IArray< Vector2 > self) => self.Select(MathOps.<#= op #>); - public static IArray <#= op #> (this IArray< Vector3 > self) => self.Select(MathOps.<#= op #>); - public static IArray <#= op #> (this IArray< Vector4 > self) => self.Select(MathOps.<#= op #>); -<# -} -#> - // TODO: do this over all over the numerical types - public static long Sum(this IArray self) => self.Aggregate(0L, (x, y) => x + y); - public static long Sum(this IArray self) => self.Aggregate(0L, (x, y) => x + y); - public static double Sum(this IArray self) => self.Aggregate(0.0, (x, y) => x + y); - public static double Sum(this IArray self) => self.Aggregate(0.0, (x, y) => x + y); - public static Vector2 Sum(this IArray self) => self.Aggregate(Vector2.Zero, (x, y) => x + y); - public static Vector3 Sum(this IArray self) => self.Aggregate(Vector3.Zero, (x, y) => x + y); - public static Vector4 Sum(this IArray self) => self.Aggregate(Vector4.Zero, (x, y) => x + y); - - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static double Average(this IArray self) => self.Sum() / self.Count; - public static Vector2 Average(this IArray self) => self.Sum() / self.Count; - public static Vector3 Average(this IArray self) => self.Sum() / self.Count; - public static Vector4 Average(this IArray self) => self.Sum() / self.Count; - - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static double Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector2 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector3 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - public static Vector4 Variance(this IArray self) { var mean = self.Average(); return self.Select(x => MathOps.Sqr(x - mean)).Average(); } - - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static double StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector2 StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector3 StdDev(this IArray self) => self.Variance().Sqrt(); - public static Vector4 StdDev(this IArray self) => self.Variance().Sqrt(); - - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - public static IArray PartialSums(this IArray self) => self.PostAccumulate((x, y) => x + y); - - } -} diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index 409323e5..acf01b1b 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -5,6 +5,7 @@ using Vim.Format.SceneBuilder; using Vim.LinqArray; using Vim.Util.Tests; +using Vim.Util; namespace Vim.Format.Tests; From 181976bbc209f2824824627b298c3b55feeac5f5 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 15:37:55 -0400 Subject: [PATCH 076/104] removing linq array --- src/cs/linqarray/Vim.LinqArray/LinqArray.cs | 6 ++---- src/cs/util/Vim.Util/CollectionExtensions.cs | 11 ++++++++++- .../Vim.LinqArray => util/Vim.Util}/ILookup.cs | 12 ++++++------ .../vim/Vim.Format.CodeGen/ObjectModelGenerator.cs | 1 - src/cs/vim/Vim.Format.Core/AssetInfo.cs | 1 - .../vim/Vim.Format.Core/ColumnExtensions.Buffer.cs | 3 +-- src/cs/vim/Vim.Format.Core/Document.cs | 7 +++---- .../Vim.Format.Core/DocumentBuilderExtensions.cs | 1 - src/cs/vim/Vim.Format.Core/DocumentExtensions.cs | 2 +- src/cs/vim/Vim.Format.Core/EntityTable.cs | 14 +++++++------- .../Vim.Format.Core/Geometry/MeshOptimization.cs | 1 - .../Geometry/PerimeterProjection.cs | 1 - src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs | 3 +-- src/cs/vim/Vim.Format.Core/Geometry/Validation.cs | 1 - src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs | 2 -- src/cs/vim/Vim.Format.Core/Validation.cs | 2 -- src/cs/vim/Vim.Format.Core/VimSchema.cs | 1 - src/cs/vim/Vim.Format.Tests/FormatTests.cs | 13 +------------ .../vim/Vim.Format.Tests/Geometry/GeometryTests.cs | 1 - .../Vim.Format.Tests/SerializableDocumentTests.cs | 4 ---- src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs | 1 - .../Vim.Format.Vimx.Conversion/VimxConverter.cs | 1 - src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs | 1 - .../ObjectModel/ObjectModelExtensions.cs | 3 +-- .../Vim.Format/ObjectModel/ObjectModelGenerated.cs | 1 - src/cs/vim/Vim.Format/ObjectModel/Validation.cs | 1 - src/cs/vim/Vim.Format/SceneBuilder/Validation.cs | 5 ++--- src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs | 1 - .../vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs | 1 - src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs | 1 - 30 files changed, 35 insertions(+), 68 deletions(-) rename src/cs/{linqarray/Vim.LinqArray => util/Vim.Util}/ILookup.cs (90%) diff --git a/src/cs/linqarray/Vim.LinqArray/LinqArray.cs b/src/cs/linqarray/Vim.LinqArray/LinqArray.cs index cf646593..3e392e0e 100644 --- a/src/cs/linqarray/Vim.LinqArray/LinqArray.cs +++ b/src/cs/linqarray/Vim.LinqArray/LinqArray.cs @@ -943,14 +943,12 @@ public static IArray Cast(this IArray xs) where T : U public static bool Contains(this IArray xs, T value) => xs.Any(x => x.Equals(value)); - public static ILookup ToLookup(this IEnumerable input, Func keyFunc, Func valueFunc) - => input.ToDictionary(keyFunc, valueFunc).ToLookup(); + + public static ILookup ToLookup(this IArray input, Func keyFunc, Func valueFunc) => input.ToEnumerable().ToLookup(keyFunc, valueFunc); - public static ILookup ToLookup(this IEnumerable input, Func keyFunc) - => input.ToDictionary(keyFunc, x => x).ToLookup(); public static ILookup ToLookup(this IArray input, Func keyFunc) => input.ToEnumerable().ToLookup(keyFunc, x => x); diff --git a/src/cs/util/Vim.Util/CollectionExtensions.cs b/src/cs/util/Vim.Util/CollectionExtensions.cs index cadcfa54..9982620a 100644 --- a/src/cs/util/Vim.Util/CollectionExtensions.cs +++ b/src/cs/util/Vim.Util/CollectionExtensions.cs @@ -7,7 +7,16 @@ namespace Vim.Util { public static class CollectionExtensions { - + public static TValue GetOrDefault(this ILookup lookup, TKey key, TValue @default = default(TValue)) + => lookup.Contains(key) ? lookup[key] : @default; + + public static ILookup ToVimLookup(this IEnumerable input, Func keyFunc, Func valueFunc) + => input.ToDictionary(keyFunc, valueFunc).ToLookup(); + + public static ILookup ToVimLookup(this IEnumerable input, Func keyFunc) + => input.ToDictionary(keyFunc, x => x).ToLookup(); + + /// /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. /// diff --git a/src/cs/linqarray/Vim.LinqArray/ILookup.cs b/src/cs/util/Vim.Util/ILookup.cs similarity index 90% rename from src/cs/linqarray/Vim.LinqArray/ILookup.cs rename to src/cs/util/Vim.Util/ILookup.cs index a4eb5b8b..b1c8257f 100644 --- a/src/cs/linqarray/Vim.LinqArray/ILookup.cs +++ b/src/cs/util/Vim.Util/ILookup.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; -namespace Vim.LinqArray +namespace Vim.Util { /// /// Lookup table: mapping from a key to some value. @@ -47,17 +47,17 @@ public LookupFromDictionary(IDictionary d = null, TValue defaultVa public class LookupFromArray : ILookup { - private IArray array; + private TValue[] array; - public LookupFromArray(IArray xs) + public LookupFromArray(TValue[] xs) { array = xs; } - public IEnumerable Keys => array.Indices().ToEnumerable(); - public IEnumerable Values => array.ToEnumerable(); + public IEnumerable Keys => Enumerable.Range(0, array.Length); + public IEnumerable Values => array; public TValue this[int key] => array[key]; - public bool Contains(int key) => key >= 0 && key <= array.Count; + public bool Contains(int key) => key >= 0 && key <= array.Length; } public static class LookupExtensions diff --git a/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs b/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs index 49ce077a..6b6fcbba 100644 --- a/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs +++ b/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs @@ -350,7 +350,6 @@ public static void WriteDocument(string file) cb.AppendLine("using System.Collections.Generic;"); cb.AppendLine("using System.Linq;"); cb.AppendLine("using Vim.Math3d;"); - cb.AppendLine("using Vim.LinqArray;"); cb.AppendLine("using Vim.Format.ObjectModel;"); cb.AppendLine("using Vim.Util;"); diff --git a/src/cs/vim/Vim.Format.Core/AssetInfo.cs b/src/cs/vim/Vim.Format.Core/AssetInfo.cs index 53c3ef73..dd3329e7 100644 --- a/src/cs/vim/Vim.Format.Core/AssetInfo.cs +++ b/src/cs/vim/Vim.Format.Core/AssetInfo.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using Vim.Util; -using Vim.LinqArray; using Vim.BFastLib; using System.Linq; diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs index 69133ef5..e1246fe2 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Vim.LinqArray; using Vim.BFastLib; namespace Vim.Format @@ -206,7 +205,7 @@ public static IEnumerable> NoneIndexColumnRelations( this IEnumerable> indexColumns, params string[] indexColumnNames) => indexColumns.Select(ic => indexColumnNames.Contains(ic.Name) - ? new NamedBuffer(VimConstants.NoEntityRelation.Repeat(ic.Data.Length).ToArray(), ic.Name) + ? new NamedBuffer(Enumerable.Repeat(VimConstants.NoEntityRelation, ic.Data.Length).ToArray(), ic.Name) : ic); /// diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index 9a529d6e..4257d38d 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -1,5 +1,4 @@ -using Vim.LinqArray; -using Vim.BFastLib; +using Vim.BFastLib; using Vim.G3dNext; using Vim.Util; @@ -14,10 +13,10 @@ public Document(SerializableDocument document) Header = _Document.Header; GeometryNext = _Document.GeometryNext; StringTable = _Document.StringTable; - EntityTables = _Document.EntityTables.ToLookup( + EntityTables = _Document.EntityTables.ToVimLookup( et => et.Name, et => et.ToEntityTable(this)); - Assets = _Document.Assets.ToLookup(et => et.Name, et => et); + Assets = _Document.Assets.ToVimLookup(et => et.Name, et => et); } public string FileName => _Document.FileName; diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index a73fe17b..c5b4e636 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -2,7 +2,6 @@ using System.Linq; using Vim.BFastLib; using Vim.Format.Geometry; -using Vim.LinqArray; using Vim.Util; using static Vim.Format.DocumentBuilder; diff --git a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs index 3ed5c589..366cf46b 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs @@ -1,9 +1,9 @@ using System; using System.Text.RegularExpressions; -using Vim.LinqArray; using Vim.BFastLib; using System.Collections.Generic; using System.Linq; +using Vim.Util; namespace Vim.Format { diff --git a/src/cs/vim/Vim.Format.Core/EntityTable.cs b/src/cs/vim/Vim.Format.Core/EntityTable.cs index 42c7b967..e4b317e4 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTable.cs @@ -1,8 +1,8 @@ using System; -using Vim.LinqArray; using Vim.BFastLib; using System.Linq; using System.Collections.Generic; +using Vim.Util; namespace Vim.Format { @@ -14,9 +14,9 @@ public EntityTable(Document document, SerializableEntityTable entityTable) _EntityTable = entityTable; Name = _EntityTable.Name; - DataColumns = LinqArray.LinqArray.ToLookup(_EntityTable.DataColumns, c => c.Name, c => c); - IndexColumns = LinqArray.LinqArray.ToLookup(_EntityTable.IndexColumns, c => c.Name, c => c); - StringColumns = LinqArray.LinqArray.ToLookup(_EntityTable.StringColumns, c => c.Name, c => c); + DataColumns = _EntityTable.DataColumns.ToVimLookup( c => c.Name, c => c); + IndexColumns = _EntityTable.IndexColumns.ToVimLookup(c => c.Name, c => c); + StringColumns = _EntityTable.StringColumns.ToVimLookup(c => c.Name, c => c); NumRows = Columns.FirstOrDefault()?.NumElements() ?? 0; Columns.ValidateColumnRowsAreAligned(); @@ -26,9 +26,9 @@ public EntityTable(Document document, SerializableEntityTable entityTable) public Document Document { get; } public string Name { get; } public int NumRows { get; } - public LinqArray.ILookup DataColumns { get; } - public LinqArray.ILookup> StringColumns { get; } - public LinqArray.ILookup> IndexColumns { get; } + public Vim.Util.ILookup DataColumns { get; } + public Vim.Util.ILookup> StringColumns { get; } + public Vim.Util.ILookup> IndexColumns { get; } public IEnumerable Columns => DataColumns.Values .Concat(IndexColumns.Values.Select(x => (INamedBuffer)x)) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs index 94dc91fc..e0a7199b 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Geometry diff --git a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs index e502b3f8..6acbe6b1 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Geometry diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index efd44cd3..ae24622f 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Geometry @@ -111,7 +110,7 @@ public static Vector2[] CirclePoints(float radius, int numPoints) => CirclePoints(numPoints).Select(x => x * radius).ToArray(); public static Vector2[] CirclePoints(int numPoints) - => numPoints.Select(i => CirclePoint(i, numPoints)).ToArray(); + => Enumerable.Range(0, numPoints).Select(i => CirclePoint(i, numPoints)).ToArray(); public static Vector2 CirclePoint(int i, int numPoints) => new Vector2((i * (Math3d.Constants.TwoPi / numPoints)).Cos(), (i * (Math3d.Constants.TwoPi / numPoints)).Sin()); diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index 474b340a..897ba16d 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -1,5 +1,4 @@ using System; -using Vim.LinqArray; using Vim.BFastLib; namespace Vim.Format.Geometry diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index a199e5a4..e5cffc94 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; -using Vim.Util; namespace Vim.Format.Geometry { diff --git a/src/cs/vim/Vim.Format.Core/Validation.cs b/src/cs/vim/Vim.Format.Core/Validation.cs index 6d596db8..6275bf17 100644 --- a/src/cs/vim/Vim.Format.Core/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Validation.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using Vim.BFastLib; -using Vim.LinqArray; namespace Vim.Format { diff --git a/src/cs/vim/Vim.Format.Core/VimSchema.cs b/src/cs/vim/Vim.Format.Core/VimSchema.cs index 8195c39a..cc262a08 100644 --- a/src/cs/vim/Vim.Format.Core/VimSchema.cs +++ b/src/cs/vim/Vim.Format.Core/VimSchema.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using Vim.Util; -using Vim.LinqArray; namespace Vim.Format { diff --git a/src/cs/vim/Vim.Format.Tests/FormatTests.cs b/src/cs/vim/Vim.Format.Tests/FormatTests.cs index b243c570..2ea981a3 100644 --- a/src/cs/vim/Vim.Format.Tests/FormatTests.cs +++ b/src/cs/vim/Vim.Format.Tests/FormatTests.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; -using Vim.LinqArray; using Vim.BFastLib; +using Vim.Util; namespace Vim.Format.Tests { @@ -29,17 +29,6 @@ public static void AssertNameAndSizesAreEqual(SerializableEntityTable t1, Serial Assert.AreEqual(t1.StringColumns.Count, t2.StringColumns.Count); for (var i = 0; i < t1.StringColumns.Count; ++i) AssertNameAndSizesAreEqual(t1.StringColumns[i], t2.StringColumns[i]); - - /* Can't expect the numerical values to be precise, because of non-determinism of parallelism when generating string table. - for (var i=0; i < t1.Properties.Length; ++i) - { - var p1 = t1.Properties[i]; - var p2 = t2.Properties[i]; - Assert.AreEqual(p1.EntityId, p2.EntityId); - Assert.AreEqual(p1.Name, p2.Name); - Assert.AreEqual(p1.Value, p2.Value); - } - */ } public static void AssertEquals(SerializableDocument d1, SerializableDocument d2, bool compareStringTables = true) diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 3850be40..6218cd8f 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -3,7 +3,6 @@ using System.Linq; using Vim.Format.Geometry; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Tests.Geometry diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index acf01b1b..cf8fe183 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -1,11 +1,7 @@ using NUnit.Framework; -using System; -using System.Linq; using Vim.Format.Geometry; using Vim.Format.SceneBuilder; -using Vim.LinqArray; using Vim.Util.Tests; -using Vim.Util; namespace Vim.Format.Tests; diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs b/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs index 2e42bc8d..0318eb23 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Vim.LinqArray; using Vim.Math3d; using Vim.G3dNext; diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs b/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs index 804635ae..77749be7 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs @@ -4,7 +4,6 @@ using Vim.BFastLib; using Vim.Format.ObjectModel; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; using Vim.Util; diff --git a/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs b/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs index df7755cb..cc896bb6 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Vim.LinqArray; namespace Vim.Format.ObjectModel { diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs index 6174db7f..7b45e3ff 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using Vim.Util; -using Vim.LinqArray; namespace Vim.Format.ObjectModel { @@ -153,7 +152,7 @@ public static DataTable GetScheduleAsDataTable(this DocumentModel dm, int schedu var columnSet = new HashSet(columns.Select(c => c.Index)); - var cellRecords = dm.ScheduleCellScheduleColumnIndex.ToIArray() + var cellRecords = dm.ScheduleCellScheduleColumnIndex .IndicesWhere((colIndex, _) => columnSet.Contains(colIndex)) .Select(cellIndex => new CellData( dm.GetScheduleCellValue(cellIndex), diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs index 6a5a980d..23c723df 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using Vim.Math3d; -using Vim.LinqArray; using Vim.Format.ObjectModel; using Vim.Util; diff --git a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs index 7869186e..fd795670 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; -using Vim.LinqArray; using Vim.Math3d; using Vim.Util; diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index 0f7f2107..8cc998e4 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -6,7 +6,6 @@ using Vim.BFastLib; using Vim.Format.Geometry; using Vim.Format.ObjectModel; -using Vim.LinqArray; using Vim.Math3d; using Vim.Util; @@ -44,9 +43,9 @@ public static void ValidateDocumentModelToG3dInvariantsNext(this VimScene vim) { var (type, attrs) = tuple; var propertyName = type.Name + "List"; - if (dm.GetPropertyValue(propertyName) is IArray arr) + if (dm.GetPropertyValue(propertyName) is Array arr) { - var numEntities = arr.Count; + var numEntities = arr.Length; foreach (var attr in attrs) { diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 005ea2d6..48a652d2 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -8,7 +8,6 @@ using Vim.Format.Geometry; using Vim.Format.ObjectModel; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; using Vim.Util; using IVimSceneProgress = System.IProgress<(string, double)>; diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs index cf7ed5cc..962916a6 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs @@ -4,7 +4,6 @@ using Vim.Format; using Vim.Format.ObjectModel; using Vim.Util; -using Vim.LinqArray; using Vim.Math3d; namespace Vim diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 76c0e3f4..9e7c5425 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -4,7 +4,6 @@ using Vim.Format.Geometry; using Vim.Format.ObjectModel; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; namespace Vim From 3fae7ec78a2ef96174fddb0120c6c9ff7d309243 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 15:37:55 -0400 Subject: [PATCH 077/104] removing linq array --- src/cs/linqarray/Vim.LinqArray/LinqArray.cs | 6 ++---- src/cs/util/Vim.Util/CollectionExtensions.cs | 11 ++++++++++- .../Vim.LinqArray => util/Vim.Util}/ILookup.cs | 12 ++++++------ .../vim/Vim.Format.CodeGen/ObjectModelGenerator.cs | 1 - src/cs/vim/Vim.Format.Core/AssetInfo.cs | 1 - .../vim/Vim.Format.Core/ColumnExtensions.Buffer.cs | 3 +-- src/cs/vim/Vim.Format.Core/Document.cs | 7 +++---- .../Vim.Format.Core/DocumentBuilderExtensions.cs | 1 - src/cs/vim/Vim.Format.Core/DocumentExtensions.cs | 2 +- src/cs/vim/Vim.Format.Core/EntityTable.cs | 14 +++++++------- .../Vim.Format.Core/Geometry/MeshOptimization.cs | 1 - .../Geometry/PerimeterProjection.cs | 1 - src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs | 3 +-- src/cs/vim/Vim.Format.Core/Geometry/Validation.cs | 1 - src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs | 2 -- src/cs/vim/Vim.Format.Core/Validation.cs | 2 -- src/cs/vim/Vim.Format.Core/VimSchema.cs | 1 - src/cs/vim/Vim.Format.Tests/FormatTests.cs | 13 +------------ .../vim/Vim.Format.Tests/Geometry/GeometryTests.cs | 1 - .../Vim.Format.Tests/SerializableDocumentTests.cs | 4 ---- src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs | 1 - .../Vim.Format.Vimx.Conversion/VimxConverter.cs | 1 - src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs | 1 - .../ObjectModel/ObjectModelExtensions.cs | 3 +-- .../Vim.Format/ObjectModel/ObjectModelGenerated.cs | 1 - src/cs/vim/Vim.Format/ObjectModel/Validation.cs | 1 - src/cs/vim/Vim.Format/SceneBuilder/Validation.cs | 5 ++--- src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs | 1 - .../vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs | 1 - src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs | 1 - 30 files changed, 35 insertions(+), 68 deletions(-) rename src/cs/{linqarray/Vim.LinqArray => util/Vim.Util}/ILookup.cs (90%) diff --git a/src/cs/linqarray/Vim.LinqArray/LinqArray.cs b/src/cs/linqarray/Vim.LinqArray/LinqArray.cs index cf646593..3e392e0e 100644 --- a/src/cs/linqarray/Vim.LinqArray/LinqArray.cs +++ b/src/cs/linqarray/Vim.LinqArray/LinqArray.cs @@ -943,14 +943,12 @@ public static IArray Cast(this IArray xs) where T : U public static bool Contains(this IArray xs, T value) => xs.Any(x => x.Equals(value)); - public static ILookup ToLookup(this IEnumerable input, Func keyFunc, Func valueFunc) - => input.ToDictionary(keyFunc, valueFunc).ToLookup(); + + public static ILookup ToLookup(this IArray input, Func keyFunc, Func valueFunc) => input.ToEnumerable().ToLookup(keyFunc, valueFunc); - public static ILookup ToLookup(this IEnumerable input, Func keyFunc) - => input.ToDictionary(keyFunc, x => x).ToLookup(); public static ILookup ToLookup(this IArray input, Func keyFunc) => input.ToEnumerable().ToLookup(keyFunc, x => x); diff --git a/src/cs/util/Vim.Util/CollectionExtensions.cs b/src/cs/util/Vim.Util/CollectionExtensions.cs index cadcfa54..9982620a 100644 --- a/src/cs/util/Vim.Util/CollectionExtensions.cs +++ b/src/cs/util/Vim.Util/CollectionExtensions.cs @@ -7,7 +7,16 @@ namespace Vim.Util { public static class CollectionExtensions { - + public static TValue GetOrDefault(this ILookup lookup, TKey key, TValue @default = default(TValue)) + => lookup.Contains(key) ? lookup[key] : @default; + + public static ILookup ToVimLookup(this IEnumerable input, Func keyFunc, Func valueFunc) + => input.ToDictionary(keyFunc, valueFunc).ToLookup(); + + public static ILookup ToVimLookup(this IEnumerable input, Func keyFunc) + => input.ToDictionary(keyFunc, x => x).ToLookup(); + + /// /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. /// diff --git a/src/cs/linqarray/Vim.LinqArray/ILookup.cs b/src/cs/util/Vim.Util/ILookup.cs similarity index 90% rename from src/cs/linqarray/Vim.LinqArray/ILookup.cs rename to src/cs/util/Vim.Util/ILookup.cs index a4eb5b8b..b1c8257f 100644 --- a/src/cs/linqarray/Vim.LinqArray/ILookup.cs +++ b/src/cs/util/Vim.Util/ILookup.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; -namespace Vim.LinqArray +namespace Vim.Util { /// /// Lookup table: mapping from a key to some value. @@ -47,17 +47,17 @@ public LookupFromDictionary(IDictionary d = null, TValue defaultVa public class LookupFromArray : ILookup { - private IArray array; + private TValue[] array; - public LookupFromArray(IArray xs) + public LookupFromArray(TValue[] xs) { array = xs; } - public IEnumerable Keys => array.Indices().ToEnumerable(); - public IEnumerable Values => array.ToEnumerable(); + public IEnumerable Keys => Enumerable.Range(0, array.Length); + public IEnumerable Values => array; public TValue this[int key] => array[key]; - public bool Contains(int key) => key >= 0 && key <= array.Count; + public bool Contains(int key) => key >= 0 && key <= array.Length; } public static class LookupExtensions diff --git a/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs b/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs index 49ce077a..6b6fcbba 100644 --- a/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs +++ b/src/cs/vim/Vim.Format.CodeGen/ObjectModelGenerator.cs @@ -350,7 +350,6 @@ public static void WriteDocument(string file) cb.AppendLine("using System.Collections.Generic;"); cb.AppendLine("using System.Linq;"); cb.AppendLine("using Vim.Math3d;"); - cb.AppendLine("using Vim.LinqArray;"); cb.AppendLine("using Vim.Format.ObjectModel;"); cb.AppendLine("using Vim.Util;"); diff --git a/src/cs/vim/Vim.Format.Core/AssetInfo.cs b/src/cs/vim/Vim.Format.Core/AssetInfo.cs index 53c3ef73..dd3329e7 100644 --- a/src/cs/vim/Vim.Format.Core/AssetInfo.cs +++ b/src/cs/vim/Vim.Format.Core/AssetInfo.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using Vim.Util; -using Vim.LinqArray; using Vim.BFastLib; using System.Linq; diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs index 69133ef5..e1246fe2 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Vim.LinqArray; using Vim.BFastLib; namespace Vim.Format @@ -206,7 +205,7 @@ public static IEnumerable> NoneIndexColumnRelations( this IEnumerable> indexColumns, params string[] indexColumnNames) => indexColumns.Select(ic => indexColumnNames.Contains(ic.Name) - ? new NamedBuffer(VimConstants.NoEntityRelation.Repeat(ic.Data.Length).ToArray(), ic.Name) + ? new NamedBuffer(Enumerable.Repeat(VimConstants.NoEntityRelation, ic.Data.Length).ToArray(), ic.Name) : ic); /// diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index 9a529d6e..4257d38d 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -1,5 +1,4 @@ -using Vim.LinqArray; -using Vim.BFastLib; +using Vim.BFastLib; using Vim.G3dNext; using Vim.Util; @@ -14,10 +13,10 @@ public Document(SerializableDocument document) Header = _Document.Header; GeometryNext = _Document.GeometryNext; StringTable = _Document.StringTable; - EntityTables = _Document.EntityTables.ToLookup( + EntityTables = _Document.EntityTables.ToVimLookup( et => et.Name, et => et.ToEntityTable(this)); - Assets = _Document.Assets.ToLookup(et => et.Name, et => et); + Assets = _Document.Assets.ToVimLookup(et => et.Name, et => et); } public string FileName => _Document.FileName; diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index a73fe17b..c5b4e636 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -2,7 +2,6 @@ using System.Linq; using Vim.BFastLib; using Vim.Format.Geometry; -using Vim.LinqArray; using Vim.Util; using static Vim.Format.DocumentBuilder; diff --git a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs index 3ed5c589..366cf46b 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs @@ -1,9 +1,9 @@ using System; using System.Text.RegularExpressions; -using Vim.LinqArray; using Vim.BFastLib; using System.Collections.Generic; using System.Linq; +using Vim.Util; namespace Vim.Format { diff --git a/src/cs/vim/Vim.Format.Core/EntityTable.cs b/src/cs/vim/Vim.Format.Core/EntityTable.cs index 42c7b967..e4b317e4 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTable.cs @@ -1,8 +1,8 @@ using System; -using Vim.LinqArray; using Vim.BFastLib; using System.Linq; using System.Collections.Generic; +using Vim.Util; namespace Vim.Format { @@ -14,9 +14,9 @@ public EntityTable(Document document, SerializableEntityTable entityTable) _EntityTable = entityTable; Name = _EntityTable.Name; - DataColumns = LinqArray.LinqArray.ToLookup(_EntityTable.DataColumns, c => c.Name, c => c); - IndexColumns = LinqArray.LinqArray.ToLookup(_EntityTable.IndexColumns, c => c.Name, c => c); - StringColumns = LinqArray.LinqArray.ToLookup(_EntityTable.StringColumns, c => c.Name, c => c); + DataColumns = _EntityTable.DataColumns.ToVimLookup( c => c.Name, c => c); + IndexColumns = _EntityTable.IndexColumns.ToVimLookup(c => c.Name, c => c); + StringColumns = _EntityTable.StringColumns.ToVimLookup(c => c.Name, c => c); NumRows = Columns.FirstOrDefault()?.NumElements() ?? 0; Columns.ValidateColumnRowsAreAligned(); @@ -26,9 +26,9 @@ public EntityTable(Document document, SerializableEntityTable entityTable) public Document Document { get; } public string Name { get; } public int NumRows { get; } - public LinqArray.ILookup DataColumns { get; } - public LinqArray.ILookup> StringColumns { get; } - public LinqArray.ILookup> IndexColumns { get; } + public Vim.Util.ILookup DataColumns { get; } + public Vim.Util.ILookup> StringColumns { get; } + public Vim.Util.ILookup> IndexColumns { get; } public IEnumerable Columns => DataColumns.Values .Concat(IndexColumns.Values.Select(x => (INamedBuffer)x)) diff --git a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs index 94dc91fc..e0a7199b 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/MeshOptimization.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Geometry diff --git a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs index e502b3f8..6acbe6b1 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/PerimeterProjection.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Geometry diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs index efd44cd3..ae24622f 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Primitives.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Geometry @@ -111,7 +110,7 @@ public static Vector2[] CirclePoints(float radius, int numPoints) => CirclePoints(numPoints).Select(x => x * radius).ToArray(); public static Vector2[] CirclePoints(int numPoints) - => numPoints.Select(i => CirclePoint(i, numPoints)).ToArray(); + => Enumerable.Range(0, numPoints).Select(i => CirclePoint(i, numPoints)).ToArray(); public static Vector2 CirclePoint(int i, int numPoints) => new Vector2((i * (Math3d.Constants.TwoPi / numPoints)).Cos(), (i * (Math3d.Constants.TwoPi / numPoints)).Sin()); diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index 474b340a..897ba16d 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -1,5 +1,4 @@ using System; -using Vim.LinqArray; using Vim.BFastLib; namespace Vim.Format.Geometry diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index a199e5a4..e5cffc94 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; -using Vim.Util; namespace Vim.Format.Geometry { diff --git a/src/cs/vim/Vim.Format.Core/Validation.cs b/src/cs/vim/Vim.Format.Core/Validation.cs index 6d596db8..6275bf17 100644 --- a/src/cs/vim/Vim.Format.Core/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Validation.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using Vim.BFastLib; -using Vim.LinqArray; namespace Vim.Format { diff --git a/src/cs/vim/Vim.Format.Core/VimSchema.cs b/src/cs/vim/Vim.Format.Core/VimSchema.cs index 8195c39a..cc262a08 100644 --- a/src/cs/vim/Vim.Format.Core/VimSchema.cs +++ b/src/cs/vim/Vim.Format.Core/VimSchema.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using Vim.Util; -using Vim.LinqArray; namespace Vim.Format { diff --git a/src/cs/vim/Vim.Format.Tests/FormatTests.cs b/src/cs/vim/Vim.Format.Tests/FormatTests.cs index b243c570..2ea981a3 100644 --- a/src/cs/vim/Vim.Format.Tests/FormatTests.cs +++ b/src/cs/vim/Vim.Format.Tests/FormatTests.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; -using Vim.LinqArray; using Vim.BFastLib; +using Vim.Util; namespace Vim.Format.Tests { @@ -29,17 +29,6 @@ public static void AssertNameAndSizesAreEqual(SerializableEntityTable t1, Serial Assert.AreEqual(t1.StringColumns.Count, t2.StringColumns.Count); for (var i = 0; i < t1.StringColumns.Count; ++i) AssertNameAndSizesAreEqual(t1.StringColumns[i], t2.StringColumns[i]); - - /* Can't expect the numerical values to be precise, because of non-determinism of parallelism when generating string table. - for (var i=0; i < t1.Properties.Length; ++i) - { - var p1 = t1.Properties[i]; - var p2 = t2.Properties[i]; - Assert.AreEqual(p1.EntityId, p2.EntityId); - Assert.AreEqual(p1.Name, p2.Name); - Assert.AreEqual(p1.Value, p2.Value); - } - */ } public static void AssertEquals(SerializableDocument d1, SerializableDocument d2, bool compareStringTables = true) diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 3850be40..6218cd8f 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -3,7 +3,6 @@ using System.Linq; using Vim.Format.Geometry; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; namespace Vim.Format.Tests.Geometry diff --git a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs index acf01b1b..cf8fe183 100644 --- a/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs +++ b/src/cs/vim/Vim.Format.Tests/SerializableDocumentTests.cs @@ -1,11 +1,7 @@ using NUnit.Framework; -using System; -using System.Linq; using Vim.Format.Geometry; using Vim.Format.SceneBuilder; -using Vim.LinqArray; using Vim.Util.Tests; -using Vim.Util; namespace Vim.Format.Tests; diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs b/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs index 2e42bc8d..0318eb23 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Vim.LinqArray; using Vim.Math3d; using Vim.G3dNext; diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs b/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs index 804635ae..77749be7 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs @@ -4,7 +4,6 @@ using Vim.BFastLib; using Vim.Format.ObjectModel; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; using Vim.Util; diff --git a/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs b/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs index df7755cb..cc896bb6 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ElementInfo.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Vim.LinqArray; namespace Vim.Format.ObjectModel { diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs index 6174db7f..7b45e3ff 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelExtensions.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using Vim.Util; -using Vim.LinqArray; namespace Vim.Format.ObjectModel { @@ -153,7 +152,7 @@ public static DataTable GetScheduleAsDataTable(this DocumentModel dm, int schedu var columnSet = new HashSet(columns.Select(c => c.Index)); - var cellRecords = dm.ScheduleCellScheduleColumnIndex.ToIArray() + var cellRecords = dm.ScheduleCellScheduleColumnIndex .IndicesWhere((colIndex, _) => columnSet.Contains(colIndex)) .Select(cellIndex => new CellData( dm.GetScheduleCellValue(cellIndex), diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs index 6a5a980d..23c723df 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using Vim.Math3d; -using Vim.LinqArray; using Vim.Format.ObjectModel; using Vim.Util; diff --git a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs index 7869186e..fd795670 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; -using Vim.LinqArray; using Vim.Math3d; using Vim.Util; diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index 0f7f2107..8cc998e4 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -6,7 +6,6 @@ using Vim.BFastLib; using Vim.Format.Geometry; using Vim.Format.ObjectModel; -using Vim.LinqArray; using Vim.Math3d; using Vim.Util; @@ -44,9 +43,9 @@ public static void ValidateDocumentModelToG3dInvariantsNext(this VimScene vim) { var (type, attrs) = tuple; var propertyName = type.Name + "List"; - if (dm.GetPropertyValue(propertyName) is IArray arr) + if (dm.GetPropertyValue(propertyName) is Array arr) { - var numEntities = arr.Count; + var numEntities = arr.Length; foreach (var attr in attrs) { diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 005ea2d6..48a652d2 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -8,7 +8,6 @@ using Vim.Format.Geometry; using Vim.Format.ObjectModel; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; using Vim.Util; using IVimSceneProgress = System.IProgress<(string, double)>; diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs index cf7ed5cc..962916a6 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneHelpers.cs @@ -4,7 +4,6 @@ using Vim.Format; using Vim.Format.ObjectModel; using Vim.Util; -using Vim.LinqArray; using Vim.Math3d; namespace Vim diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 76c0e3f4..9e7c5425 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -4,7 +4,6 @@ using Vim.Format.Geometry; using Vim.Format.ObjectModel; using Vim.G3dNext; -using Vim.LinqArray; using Vim.Math3d; namespace Vim From 43cb01fa7209d0f349a8f62912916a99da90c9d1 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 15:44:27 -0400 Subject: [PATCH 078/104] restored method --- src/cs/util/Vim.Util/CollectionExtensions.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cs/util/Vim.Util/CollectionExtensions.cs b/src/cs/util/Vim.Util/CollectionExtensions.cs index 9982620a..79712ba0 100644 --- a/src/cs/util/Vim.Util/CollectionExtensions.cs +++ b/src/cs/util/Vim.Util/CollectionExtensions.cs @@ -41,6 +41,19 @@ public static IEnumerable IndicesWhere(this IList self, Func + /// [a, b, c ..] => [0, a, a+b, a+b+c ...] + /// + public static int[] OffsetsFromCounts(this IList self) + { + var result = new int[self.Count]; + for (var i = 1; i < self.Count; ++i) + { + result[i] = result[i - 1] + self[i - 1]; + } + return result; + } + /// /// Returns the top of a stack, or the default T value if none is present. /// From 463a07af4aac1892d97892eec40702608c93164f Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 16:00:49 -0400 Subject: [PATCH 079/104] index of methods --- src/cs/util/Vim.Util/CollectionExtensions.cs | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/cs/util/Vim.Util/CollectionExtensions.cs b/src/cs/util/Vim.Util/CollectionExtensions.cs index 79712ba0..87339b07 100644 --- a/src/cs/util/Vim.Util/CollectionExtensions.cs +++ b/src/cs/util/Vim.Util/CollectionExtensions.cs @@ -17,6 +17,28 @@ public static ILookup ToVimLookup(this IEnumerable => input.ToDictionary(keyFunc, x => x).ToLookup(); + /// + /// Returns the index of the first element matching the given item. + /// + public static int IndexOf(this IArray self, T item) where T : IEquatable + => self.IndexOf(x => x.Equals(item)); + + /// + /// Returns the index of the first element matching the given item. + /// + public static int IndexOf(this IArray self, Func predicate) + { + for (var i = 0; i < self.Count; ++i) + { + if (predicate(self[i])) + return i; + } + + return -1; + } + + + /// /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. /// From d6db1d9564ca4c248310fefd4ac5822b28cc4082 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 16:02:27 -0400 Subject: [PATCH 080/104] fix --- src/cs/util/Vim.Util/CollectionExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cs/util/Vim.Util/CollectionExtensions.cs b/src/cs/util/Vim.Util/CollectionExtensions.cs index 87339b07..92404f98 100644 --- a/src/cs/util/Vim.Util/CollectionExtensions.cs +++ b/src/cs/util/Vim.Util/CollectionExtensions.cs @@ -20,15 +20,15 @@ public static ILookup ToVimLookup(this IEnumerable /// /// Returns the index of the first element matching the given item. /// - public static int IndexOf(this IArray self, T item) where T : IEquatable + public static int IndexOf(this T[] self, T item) where T : IEquatable => self.IndexOf(x => x.Equals(item)); /// /// Returns the index of the first element matching the given item. /// - public static int IndexOf(this IArray self, Func predicate) + public static int IndexOf(this T[] self, Func predicate) { - for (var i = 0; i < self.Count; ++i) + for (var i = 0; i < self.Length; ++i) { if (predicate(self[i])) return i; From a5a9b43032a174a23f7da54a9e6b82125f4a7752 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 17 Apr 2024 07:58:31 -0400 Subject: [PATCH 081/104] removed linqarray --- .../Vim.LinqArray.Tests/LinqArrayTests.cs | 72 -- src/cs/linqarray/Vim.LinqArray/LinqArray.cs | 1021 ----------------- .../Vim.Math3D/{LinqUtil.cs => AABoxUtil.cs} | 6 +- src/cs/vim-format.sln | 16 - .../Vim.Format.Core/Vim.Format.Core.csproj | 1 - .../Vim.Format.Vimx.Conversion.csproj | 3 +- src/cs/vim/Vim.Format/Vim.Format.csproj | 1 - 7 files changed, 3 insertions(+), 1117 deletions(-) delete mode 100644 src/cs/linqarray/Vim.LinqArray.Tests/LinqArrayTests.cs delete mode 100644 src/cs/linqarray/Vim.LinqArray/LinqArray.cs rename src/cs/math3d/Vim.Math3D/{LinqUtil.cs => AABoxUtil.cs} (57%) diff --git a/src/cs/linqarray/Vim.LinqArray.Tests/LinqArrayTests.cs b/src/cs/linqarray/Vim.LinqArray.Tests/LinqArrayTests.cs deleted file mode 100644 index 4f85ca04..00000000 --- a/src/cs/linqarray/Vim.LinqArray.Tests/LinqArrayTests.cs +++ /dev/null @@ -1,72 +0,0 @@ -using NUnit.Framework; -using System; - -namespace Vim.LinqArray.Tests -{ - public class LinqArrayTests - { - public static int[] ArrayToTen = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - public static IArray RangeToTen = 10.Range(); - public static IArray BuildToTen = LinqArray.Build(0, x => x + 1, x => x < 10); - - public static object[] TensData = { ArrayToTen.ToIArray(), RangeToTen, BuildToTen }; - - [TestCaseSource(nameof(TensData))] - public void CheckTens(IArray tens) - { - Assert.IsTrue(tens.SequenceEquals(ArrayToTen.ToIArray())); - Assert.AreEqual(0, tens.First()); - Assert.AreEqual(9, tens.Last()); - Assert.AreEqual(45, tens.Aggregate(0, (a, b) => a + b)); - Assert.AreEqual(10, tens.Count); - Assert.AreEqual(5, tens[5]); - Assert.AreEqual(5, tens.ElementAt(5)); - - var ones = 1.Repeat(9); - var diffs = tens.ZipEachWithNext((x, y) => y - x); - Assert.IsTrue(ones.SequenceEquals(diffs)); - Assert.IsFalse(ones.SequenceEquals(tens)); - - var indices = tens.Indices(); - Assert.IsTrue(tens.SequenceEquals(indices)); - Assert.IsTrue(tens.SequenceEquals(tens.SelectByIndex(indices))); - Assert.IsTrue(tens.Reverse().SequenceEquals(tens.SelectByIndex(indices.Reverse()))); - - var sum = 0; - foreach (var x in tens.ToEnumerable()) - { - sum += x; - } - foreach (var x in tens.ToEnumerable()) - { - Console.WriteLine(x.ToString()); - } - Assert.AreEqual(45, sum); - Assert.AreEqual(0, tens.First()); - Assert.True(tens.All(x => x < 10)); - Assert.True(tens.Any(x => x < 5)); - Assert.AreEqual(5, tens.CountWhere(x => x % 2 == 0)); - Assert.AreEqual(0, tens.Reverse().Last()); - Assert.AreEqual(0, tens.Reverse().Reverse().First()); - var split = tens.Split(LinqArray.Create(3, 6)); - Assert.AreEqual(3, split.Count); - - var batch = tens.SubArrays(3); - Assert.AreEqual(4, batch.Count); - Assert.True(batch[0].SequenceEquals(LinqArray.Create(0, 1, 2))); - Assert.True(batch[3].SequenceEquals(LinqArray.Create(9))); - - var batch2 = tens.Take(9).SubArrays(3); - Assert.AreEqual(3, batch2.Count); - - var counts = split.Select(x => x.Count); - Assert.True(counts.SequenceEquals(LinqArray.Create(3, 3, 4))); - var indices2 = counts.Accumulate((x, y) => x + y); - Assert.True(indices2.SequenceEquals(LinqArray.Create(3, 6, 10))); - var indices3 = counts.PostAccumulate((x, y) => x + y); - Assert.True(indices3.SequenceEquals(LinqArray.Create(0, 3, 6, 10))); - var flattened = split.Flatten(); - Assert.True(flattened.SequenceEquals(tens)); - } - } -} diff --git a/src/cs/linqarray/Vim.LinqArray/LinqArray.cs b/src/cs/linqarray/Vim.LinqArray/LinqArray.cs deleted file mode 100644 index 3e392e0e..00000000 --- a/src/cs/linqarray/Vim.LinqArray/LinqArray.cs +++ /dev/null @@ -1,1021 +0,0 @@ -// MIT License - Copyright 2019 (C) VIMaec, LLC. -// MIT License - Copyright (C) Ara 3D, Inc. -// This file is subject to the terms and conditions defined in -// file 'LICENSE.txt', which is part of this source code package. -// -// LinqArray.cs -// A library for working with pure functional arrays, using LINQ style extension functions. -// Based on code that originally appeared in https://www.codeproject.com/Articles/140138/Immutable-Array-for-NET - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Vim.LinqArray -{ - /// - /// Represents an immutable array with expected O(1) complexity when - /// retrieving the number of items. - /// - public interface IArray - { - int Count { get; } - } - - /// - /// Represents an immutable array with expected O(1) complexity when - /// retrieving the number of items and random element access. - /// - public interface IArray : IArray - { - T this[int n] { get; } - } - - /// - /// Implements an IArray via a function and a count. - /// - public class FunctionalArray : IArray - { - public readonly Func Function; - - public int Count - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } - - public T this[int n] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => Function(n); - } - public FunctionalArray(int count, Func function) - => (Count, Function) = (count, function); - } - - /// - /// Implements an IArray from a System.Array. - /// - public class ArrayAdapter : IArray - { - public readonly T[] Array; - - public int Count - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get; - } - - public T this[int n] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => Array[n]; - } - public ArrayAdapter(T[] xs) { Count = xs.Length; Array = xs; } - } - - /// - /// Extension functions for working on any object implementing IArray. This overrides - /// many of the Linq functions providing better performance. - /// - public static class LinqArray - { - /// - /// Helper function for creating an IArray from the arguments. - /// - public static IArray Create(params T[] self) - => self.ToIArray(); - - /// - /// A helper function to enable IArray to support IEnumerable - /// - public static IEnumerable ToEnumerable(this IArray self) - => Enumerable.Range(0, self.Count).Select(self.ElementAt); - - public static IArray ForEach(this IArray xs, Action f) - { - for (var i = 0; i < xs.Count; ++i) - f(xs[i]); - return xs; - } - - /// - /// Creates an IArray with the given number of items, - /// and uses the function to return items. - /// - public static IArray Select(this int count, Func f) - => new FunctionalArray(count, f); - - /// - /// Converts any implementation of IList (e.g. Array/List) to an IArray. - /// - public static IArray ToIArray(this IList self) - => self.Count.Select(i => self[i]); - - /// - /// Converts any implementation of IList (e.g. Array/List) to an IArray. - /// - public static IArray ToIArray(this T[] self) - => new ArrayAdapter(self); - - /// - /// Converts any implementation of IEnumerable to an IArray - /// - public static IArray ToIArray(this IEnumerable self) - => self is IList xs ? xs.ToIArray() : self.ToArray().ToIArray(); - - /// - /// Creates an IArray by repeating the given item a number of times. - /// - public static IArray Repeat(this T self, int count) - => Select(count, i => self); - - /// - /// Creates an IArray by repeating each item in the source a number of times. - /// - public static IArray RepeatElements(this IArray self, int count) - => Select(count, i => self[i / count]); - - /// - /// Creates an IArray starting with a seed value, and applying a function - /// to each individual member of the array. This is eagerly evaluated. - /// - public static IArray Generate(this T init, int count, Func f) - { - var r = new T[count]; - for (var i = 0; i < count; ++i) - { - r[i] = init; - init = f(init); - } - return r.ToIArray(); - } - - /// - /// Creates an IArray of integers from zero up to one less than the given number. - /// - public static IArray Range(this int self) - => Select(self, i => i); - - /// - /// Returns the first item in the array. - /// - public static T First(this IArray self, T @default = default) - => self.IsEmpty() ? @default : self[0]; - - /// - /// Returns the last item in the array - /// - public static T Last(this IArray self, T @default = default) - => self.IsEmpty() ? @default : self[self.Count - 1]; - - /// - /// Returns true if and only if the argument is a valid index into the array. - /// - public static bool InRange(this IArray self, int n) - => n >= 0 && n < self.Count; - - /// - /// A mnemonic for "Any()" that returns false if the count is greater than zero - /// - public static bool IsEmpty(this IArray self) - => !self.Any(); - - /// - /// Returns true if there are any elements in the array. - /// - public static bool Any(this IArray self) - => self.Count != 0; - - /// - /// Converts the IArray into a system array. - /// - public static T[] ToArray(this IArray self) - => self.CopyTo(new T[self.Count]); - - /// - /// Converts the IArray into a system List. - /// - public static List ToList(this IArray self) - => self.ToEnumerable().ToList(); - - /// - /// Converts the array into a function that returns values from an integer, returning a default value if out of range. - /// - public static Func ToFunction(this IArray self, T def = default) - => i => self.InRange(i) ? self[i] : def; - - /// - /// Converts the array into a predicate (a function that returns true or false) based on the truth of the given value. - /// - public static Func ToPredicate(this IArray self) - => self.ToFunction(); - - /// - /// Adds all elements of the array to the target collection. - /// - public static U AddTo(this IArray self, U other) where U : ICollection - { - self.ForEach(other.Add); - return other; - } - - /// - /// Copies all elements of the array to the target list or array, starting at the provided index. - /// - public static U CopyTo(this IArray self, U other, int destIndex = 0) where U : IList - { - for (var i = 0; i < self.Count; ++i) - other[i + destIndex] = self[i]; - return other; - } - - /// - /// Returns an array generated by applying a function to each element. - /// - public static IArray Select(this IArray self, Func f) - => Select(self.Count, i => f(self[i])); - - /// - /// Returns an array generated by applying a function to each element. - /// - public static IArray Select(this IArray self, Func f) - => Select(self.Count, i => f(self[i], i)); - - /// - /// Returns an array generated by applying a function to each element. - /// - public static IArray SelectIndices(this IArray self, Func f) - => self.Count.Select(f); - - /// - /// Converts an array of array into a flattened array. Each array is assumed to be of size n. - /// - public static IArray Flatten(this IArray> self, int n) - => Select(self.Count * n, i => self[i / n][i % n]); - - /// - /// Converts an array of array into a flattened array. - /// - public static IArray Flatten(this IArray> self) - { - var counts = self.Select(x => x.Count).PostAccumulate((x, y) => x + y); - var r = new T[counts.Last()]; - var i = 0; - foreach (var xs in self.ToEnumerable()) - xs.CopyTo(r, counts[i++]); - return r.ToIArray(); - } - - /// - /// Returns an array of tuple where each element of the initial array is paired with its index. - /// - public static IArray<(T value, int index)> ZipWithIndex(this IArray self) - => self.Select((v, i) => (v, i)); - - /// - /// Returns an array from an array of arrays, where the number of sub-elements is the same for reach array and is known. - /// - public static IArray SelectMany(this IArray> self, int count) - => Select(self.Count, i => self[i / count][i % count]); - - /// - /// Returns an array given a function that generates an IArray from each member. Eager evaluation. - /// - public static IArray SelectMany(this IArray self, Func> func) - { - var xs = new List(); - for (var i = 0; i < self.Count; ++i) - func(self[i]).AddTo(xs); - return xs.ToIArray(); - } - - /// - /// Returns an array given a function that generates an IArray from each member. Eager evaluation. - /// - public static IArray SelectMany(this IArray self, Func> func) - { - var xs = new List(); - for (var i = 0; i < self.Count; ++i) - func(self[i], i).AddTo(xs); - return xs.ToIArray(); - } - - /// - /// Returns an array given a function that generates a tuple from each member. Eager evaluation. - /// - public static IArray SelectMany(this IArray self, Func> func) - { - var r = new U[self.Count * 2]; - for (var i = 0; i < self.Count; ++i) - { - var tmp = func(self[i]); - r[i * 2] = tmp.Item1; - r[i * 2 + 1] = tmp.Item2; - } - - return r.ToIArray(); - } - - /// - /// Returns an array given a function that generates a tuple from each member. Eager evaluation. - /// - public static IArray SelectMany(this IArray self, Func> func) - { - var r = new U[self.Count * 3]; - for (var i = 0; i < self.Count; ++i) - { - var tmp = func(self[i]); - r[i * 3] = tmp.Item1; - r[i * 3 + 1] = tmp.Item2; - r[i * 3 + 2] = tmp.Item3; - } - return r.ToIArray(); - } - - /// - /// Returns an array given a function that generates a tuple from each member. Eager evaluation. - /// - public static IArray SelectMany(this IArray self, Func> func) - { - var r = new U[self.Count * 4]; - for (var i = 0; i < self.Count; ++i) - { - var tmp = func(self[i]); - r[i * 4] = tmp.Item1; - r[i * 4 + 1] = tmp.Item2; - r[i * 4 + 2] = tmp.Item3; - r[i * 4 + 3] = tmp.Item4; - } - return r.ToIArray(); - } - - /// - /// Returns an array generated by applying a function to corresponding pairs of elements in both arrays. - /// - public static IArray Zip(this IArray self, IArray other, Func f) - => Select(Math.Min(self.Count, other.Count), i => f(self[i], other[i])); - - /// - /// Returns an array generated by applying a function to corresponding pairs of elements in both arrays. - /// - public static IArray Zip(this IArray self, IArray other, Func f) - => Select(Math.Min(self.Count, other.Count), i => f(self[i], other[i], i)); - - /// - /// Returns an array generated by applying a function to corresponding pairs of elements in both arrays. - /// - public static IArray Zip(this IArray self, IArray other, IArray other2, Func f) - => Select(Math.Min(Math.Min(self.Count, other.Count), other2.Count), i => f(self[i], other[i], other2[i])); - - /// - /// Returns an array generated by applying a function to corresponding pairs of elements in both arrays. - /// - public static IArray Zip(this IArray self, IArray other, IArray other2, Func f) - => Select(Math.Min(Math.Min(self.Count, other.Count), other2.Count), i => f(self[i], other[i], other2[i], i)); - - /// - /// Returns an array generated by applying a function to corresponding pairs of elements in both arrays. - /// - public static IArray Zip(this IArray self, IArray other, IArray other2, IArray other3, Func f) - => Select(Math.Min(Math.Min(self.Count, other.Count), Math.Min(other2.Count, other3.Count)), i => f(self[i], other[i], other2[i], other3[i])); - - /// - /// Returns an array generated by applying a function to corresponding pairs of elements in both arrays. - /// - public static IArray Zip(this IArray self, IArray other, IArray other2, IArray other3, Func f) - => Select(Math.Min(Math.Min(self.Count, other.Count), Math.Min(other2.Count, other3.Count)), i => f(self[i], other[i], other2[i], other3[i], i)); - - /// - /// Applies a function to each element in the list paired with the next one. - /// Used to implement adjacent differences for example. - /// - public static IArray ZipEachWithNext(this IArray self, Func f) - => self.Zip(self.Skip(), f); - - /// - /// Returns an IEnumerable containing only elements of the array for which the function returns true on the index. - /// An IArray is not created automatically because it is an expensive operation that is potentially unneeded. - /// - public static IEnumerable WhereIndices(this IArray self, Func f) - => self.Where((x, i) => f(i)); - - /// - /// Returns an IEnumerable containing only elements of the array for which the corresponding mask is true. - /// An IArray is not created automatically because it is an expensive operation that is potentially unneeded. - /// - public static IEnumerable Where(this IArray self, IArray mask) - => self.WhereIndices(mask.ToPredicate()); - - /// - /// Returns an IEnumerable containing only elements of the array for which the corresponding predicate is true. - /// - public static IEnumerable Where(this IArray self, Func predicate) - => self.ToEnumerable().Where(predicate); - - /// - /// Returns an IEnumerable containing only elements of the array for which the corresponding predicate is true. - /// - public static IEnumerable Where(this IArray self, Func predicate) - => self.ToEnumerable().Where(predicate); - - /// - /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. - /// An IArray is not created automatically because it is an expensive operation that is potentially unneeded. - /// - public static IEnumerable IndicesWhere(this IArray self, Func f) - => self.Indices().Where(i => f(self[i])); - - /// - /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. - /// An IArray is not created automatically because it is an expensive operation that is potentially unneeded. - /// - public static IEnumerable IndicesWhere(this IArray self, Func f) - => self.IndicesWhere(i => f(self[i], i)); - - /// - /// Returns an IEnumerable containing only indices of the array for which the function satisfies a specific predicate. - /// An IArray is not created automatically because it is an expensive operation that is potentially unneeded. - /// - public static IEnumerable IndicesWhere(this IArray self, Func f) - => self.Indices().Where(i => f(i)); - - /// - /// Returns an IEnumerable containing only indices of the array for which booleans in the mask are true. - /// An IArray is not created automatically because it is an expensive operation that is potentially unneeded. - /// - public static IEnumerable IndicesWhere(this IArray self, IArray mask) - => self.IndicesWhere(mask.ToPredicate()); - - /// - /// Shortcut for ToEnumerable.Aggregate() - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static U Aggregate(this IArray self, U init, Func func) - { - for (var i = 0; i < self.Count; ++i) - init = func(init, self[i]); - return init; - } - - /// - /// Shortcut for ToEnumerable.Aggregate() - /// - public static U Aggregate(this IArray self, Func func) - => Aggregate(self, default, func); - - /// - /// Shortcut for ToEnumerable.Aggregate() - /// - public static U Aggregate(this IArray self, U init, Func func) - { - for (var i = 0; i < self.Count; ++i) - init = func(init, self[i], i); - return init; - } - - /// - /// Shortcut for ToEnumerable.Aggregate() - /// - public static U Aggregate(this IArray self, Func func) - => Aggregate(self, default, func); - - /// - /// Returns a new array containing the elements in the range of from to to. - /// - public static IArray Slice(this IArray self, int from, int to) - => Select(to - from, i => self[i + from]); - - /// - /// Returns an array of SubArrays of size "size" - /// the last items that cannot fill an arrat if size "size" will be ignored - /// - public static IArray> SubArraysFixed(this IArray self, int size) - => (self.Count / size).Select(i => self.SubArray(i, size)); - - - /// Returns an array of SubArrays of size "size" plus extras - /// The extra array is of size count % size if present - public static IArray> SubArrays(this IArray self, int size) - => self.Count % size == 0 - ? self.SubArraysFixed(size) - : self.SubArraysFixed(size).Append(self.TakeLast(self.Count % size)); - - /// - /// Returns n elements of the list starting from a given index. - /// - public static IArray SubArray(this IArray self, int from, int count) - => self.Slice(from, count + from); - - /// - /// Returns elements of the array between from and skipping every stride element. - /// - public static IArray Slice(this IArray self, int from, int to, int stride) - => Select(to - from / stride, i => self[i * stride + from]); - - /// - /// Returns a new array containing the elements by taking every nth item. - /// - public static IArray Stride(this IArray self, int n) - => Select(self.Count / n, i => self[i * n % self.Count]); - - /// - /// Returns a new array containing just the first n items. - /// - public static IArray Take(this IArray self, int n) - => self.Slice(0, n); - - /// - /// Returns a new array containing just at most n items. - /// - public static IArray TakeAtMost(this IArray self, int n) - => self.Count > n ? self.Slice(0, n) : self; - - /// - /// Returns a new array containing the elements after the first n elements. - /// - public static IArray Skip(this IArray self, int n = 1) - => self.Slice(n, self.Count); - - /// - /// Returns a new array containing the last n elements. - /// - public static IArray TakeLast(this IArray self, int n = 1) - => self.Skip(self.Count - n); - - /// - /// Returns a new array containing all elements excluding the last n elements. - /// - public static IArray DropLast(this IArray self, int n = 1) - => self.Count > n ? self.Take(self.Count - n) : self.Empty(); - - /// - /// Returns a new array by remapping indices - /// - public static IArray MapIndices(this IArray self, Func f) - => self.Count.Select(i => self[f(i)]); - - /// - /// Returns a new array that reverses the order of elements - /// - public static IArray Reverse(this IArray self) - => self.MapIndices(i => self.Count - 1 - i); - - /// - /// Uses the provided indices to select elements from the array. - /// - public static IArray SelectByIndex(this IArray self, IArray indices) - => indices.Select(i => self[i]); - - /// - /// Uses the array as indices to select elements from the other array. - /// - public static IArray Choose(this IArray indices, IArray values) - => values.SelectByIndex(indices); - - /// - /// Given indices of sub-arrays groups, this will convert it to arrays of indices (e.g. [0, 2] with a group size of 3 becomes [0, 1, 2, 6, 7, 8]) - /// - public static IArray GroupIndicesToIndices(this IArray indices, int groupSize) - => groupSize == 1 - ? indices : (indices.Count * groupSize).Select(i => indices[i / groupSize] * groupSize + i % groupSize); - - /// - /// Return the array separated into a series of groups (similar to DictionaryOfLists) - /// based on keys created by the given keySelector - /// - public static IEnumerable> GroupBy(this IArray self, Func keySelector) - => self.ToEnumerable().GroupBy(keySelector); - - /// - /// Return the array separated into a series of groups (similar to DictionaryOfLists) - /// based on keys created by the given keySelector and elements chosen by the element selector - /// - public static IEnumerable> GroupBy(this IArray self, Func keySelector, Func elementSelector) - => self.ToEnumerable().GroupBy(keySelector, elementSelector); - - /// - /// Uses the provided indices to select groups of contiguous elements from the array. - /// This is equivalent to self.SubArrays(groupSize).SelectByIndex(indices).SelectMany(); - /// - public static IArray SelectGroupsByIndex(this IArray self, int groupSize, IArray indices) - => self.SelectByIndex(indices.GroupIndicesToIndices(groupSize)); - - /// - /// Similar to take, if count is less than the number of items in the array, otherwise uses a modulo operation. - /// - public static IArray Resize(this IArray self, int count) - => Select(count, i => self[i % self.Count]); - - /// - /// Returns an array of the same type with no elements. - /// - public static IArray Empty(this IArray self) - => self.Take(0); - - /// - /// Returns an array of the same type with no elements. - /// - public static IArray Empty() - => default(T).Repeat(0); - - /// - /// Returns a sequence of integers from 0 to 1 less than the number of items in the array, representing indicies of the array. - /// - public static IArray Indices(this IArray self) - => self.Count.Range(); - - /// - /// Converts an array of elements into a string representation - /// - public static string Join(this IArray self, string sep = " ") - => self.Aggregate(new StringBuilder(), (sb, x) => sb.Append(x).Append(sep)).ToString(); - - /// - /// Concatenates the contents of one array with another. - /// - public static IArray Concatenate(this IArray self, IArray other) - => Select(self.Count + other.Count, i => i < self.Count ? self[i] : other[i - self.Count]); - - /// - /// Returns the index of the first element matching the given item. - /// - public static int IndexOf(this IArray self, T item) where T : IEquatable - => self.IndexOf(x => x.Equals(item)); - - /// - /// Returns the index of the first element matching the given item. - /// - public static int IndexOf(this IArray self, Func predicate) - { - for (var i = 0; i < self.Count; ++i) - { - if (predicate(self[i])) - return i; - } - - return -1; - } - - /// - /// Returns the index of the last element matching the given item. - /// - public static int LastIndexOf(this IArray self, T item) where T : IEquatable - { - var n = self.Reverse().IndexOf(item); - return n < 0 ? n : self.Count - 1 - n; - } - - /// - /// Returns an array that is one element shorter that subtracts each element from its previous one. - /// - public static IArray AdjacentDifferences(this IArray self) - => self.ZipEachWithNext((a, b) => b - a); - - /// - /// Creates a new array that concatenates a unit item list of one item after it. - /// Repeatedly calling Append would result in significant performance degradation. - /// - public static IArray Append(this IArray self, T x) - => (self.Count + 1).Select(i => i < self.Count ? self[i] : x); - - /// - /// Creates a new array that concatenates the given items to itself. - /// - public static IArray Append(this IArray self, params T[] x) - => self.Concatenate(x.ToIArray()); - - /// - /// Creates a new array that concatenates a unit item list of one item before it - /// Repeatedly calling Prepend would result in significant performance degradation. - /// - public static IArray Prepend(this IArray self, T x) - => (self.Count + 1).Select(i => i == 0 ? x : self[i - 1]); - - /// - /// Returns the element at the nth position, where n is modulo the number of items in the arrays. - /// - public static T ElementAt(this IArray self, int n) - => self[n]; - - /// - /// Returns the element at the nth position, where n is modulo the number of items in the arrays. - /// - public static T ElementAtModulo(this IArray self, int n) - => self.ElementAt(n % self.Count); - - /// - /// Returns the Nth element of the array, or a default value if out of range/ - /// - public static T ElementAtOrDefault(this IArray xs, int n, T defaultValue = default) - => xs != null && n >= 0 && n < xs.Count ? xs[n] : defaultValue; - - /// - /// Counts all elements in an array that satisfy a predicate - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountWhere(this IArray self, Func p) - => self.Aggregate(0, (n, x) => n + (p(x) ? 1 : 0)); - - /// - /// Counts all elements in an array that are equal to true - /// - public static int CountWhere(this IArray self) - => self.CountWhere(x => x); - - /// - /// Counts all elements in an array that are equal to a value - /// - public static int CountWhere(this IArray self, T val) where T : IEquatable - => self.CountWhere(x => x.Equals(val)); - - /// - /// Returns the minimum element in the list - /// - public static T Min(this IArray self) where T : IComparable - { - if (self.Count == 0) throw new ArgumentOutOfRangeException(); - return self.Aggregate(self[0], (a, b) => a.CompareTo(b) < 0 ? a : b); - } - - /// - /// Returns the maximum element in the list - /// - public static T Max(this IArray self) where T : IComparable - { - if (self.Count == 0) throw new ArgumentOutOfRangeException(); - return self.Aggregate(self[0], (a, b) => a.CompareTo(b) > 0 ? a : b); - } - - /// - /// Applies a function (like "+") to each element in the series to create an effect similar to partial sums. - /// - public static IArray Accumulate(this IArray self, Func f) - { - var n = self.Count; - var r = new T[n]; - if (n == 0) return r.ToIArray(); - var prev = r[0] = self[0]; - for (var i = 1; i < n; ++i) - { - prev = r[i] = f(prev, self[i]); - } - return r.ToIArray(); - } - - /// - /// Applies a function (like "+") to each element in the series to create an effect similar to partial sums. - /// The first value in the array will be zero. - /// - public static IArray PostAccumulate(this IArray self, Func f, T init = default) - { - var n = self.Count; - var r = new T[n + 1]; - var prev = r[0] = init; - if (n == 0) return r.ToIArray(); - for (var i = 0; i < n; ++i) - { - prev = r[i + 1] = f(prev, self[i]); - } - return r.ToIArray(); - } - - /// - /// Returns true if the two lists are the same length, and the elements are the same. - /// - public static bool SequenceEquals(this IArray self, IArray other) where T : IEquatable - => self == other || (self.Count == other.Count && self.Zip(other, (x, y) => x?.Equals(y) ?? y == null).All(x => x)); - - /// - /// Creates a readonly array from a seed value, by applying a function - /// - public static IArray Build(T init, Func next, Func hasNext) - { - var r = new List(); - while (hasNext(init)) - { - r.Add(init); - init = next(init); - } - return r.ToIArray(); - } - - /// - /// Creates a readonly array from a seed value, by applying a function - /// - public static IArray Build(T init, Func next, Func hasNext) - { - var i = 0; - var r = new List(); - while (hasNext(init, i)) - { - r.Add(init); - init = next(init, ++i); - } - return r.ToIArray(); - } - - /// - /// Creates an array of arrays, split at the given indices - /// - public static IArray> Split(this IArray self, IArray indices) - => indices.Prepend(0).Zip(indices.Append(self.Count), (x, y) => self.Slice(x, y)); - - /// - /// Creates an array of arrays, split at the given index. - /// - public static IArray> Split(this IArray self, int index) - => Create(self.Take(index), self.Skip(index)); - - /// - /// Splits an array of tuples into a tuple of array - /// - public static (IArray, IArray) Unzip(this IArray<(T1, T2)> self) - => (self.Select(pair => pair.Item1), self.Select(pair => pair.Item2)); - - - /// - /// Returns true if the predicate is true for all of the elements in the array - /// - public static bool All(this IArray self, Func predicate) - => self.ToEnumerable().All(predicate); - - /// - /// Returns true if the predicate is true for any of the elements in the array - /// - public static bool Any(this IArray self, Func predicate) - => self.ToEnumerable().Any(predicate); - - /// - /// Sums items in an array using a selector function that returns integers. - /// - public static long Sum(this IArray self, Func func) - => self.Aggregate(0L, (init, x) => init + func(x)); - - /// - /// Sums items in an array using a selector function that returns doubles. - /// - public static double Sum(this IArray self, Func func) - => self.Aggregate(0.0, (init, x) => init + func(x)); - - /// - /// Forces evaluation (aka reification) of the array by creating a copy in memory. - /// This is useful as a performance optimization, or to force the objects to exist permanently. - /// - public static IArray Evaluate(this IArray x) - => (x is ArrayAdapter) ? x : x.ToArray().ToIArray(); - - /// - /// Forces evaluation (aka reification) of the array in parallel. - /// - public static IArray EvaluateInParallel(this IArray x) - => (x is ArrayAdapter) ? x : x.ToArrayInParallel().ToIArray(); - - /// - /// Converts to a regular array in paralle; - /// - /// - /// - /// - public static T[] ToArrayInParallel(this IArray xs) - { - if (xs.Count == 0) - return Array.Empty(); - - if (xs.Count < Environment.ProcessorCount) - return xs.ToArray(); - - var r = new T[xs.Count]; - var partitioner = Partitioner.Create(0, xs.Count, xs.Count / Environment.ProcessorCount); - - Parallel.ForEach(partitioner, (range, state) => - { - for (var i = range.Item1; i < range.Item2; ++i) - r[i] = xs[i]; - }); - return r; - } - - /// - /// Maps pairs of elements to a new array. - /// - public static IArray SelectPairs(this IArray xs, Func f) - => (xs.Count / 2).Select(i => f(xs[i * 2], xs[i * 2 + 1])); - - /// - /// Maps every 3 elements to a new array. - /// - public static IArray SelectTriplets(this IArray xs, Func f) - => (xs.Count / 3).Select(i => f(xs[i * 3], xs[i * 3 + 1], xs[i * 3 + 2])); - - /// - /// Maps every 4 elements to a new array. - /// - public static IArray SelectQuartets(this IArray xs, Func f) - => (xs.Count / 4).Select(i => f(xs[i * 4], xs[i * 4 + 1], xs[i * 4 + 2], xs[i * 4 + 3])); - - /// - /// Returns the number of unique instances of elements in the array. - /// - public static int CountUnique(this IArray xs) - => xs.ToEnumerable().Distinct().Count(); - - /// - /// Returns elements in order. - /// - public static IArray Sort(this IArray xs) where T : IComparable - => xs.ToEnumerable().OrderBy(x => x).ToIArray(); - - /// - /// Given an array of elements of type T casts them to a U - /// - public static IArray Cast(this IArray xs) where T : U - => xs.Select(x => (U)x); - - /// - /// Returns true if the value is present in the array. - /// - public static bool Contains(this IArray xs, T value) - => xs.Any(x => x.Equals(value)); - - - - - public static ILookup ToLookup(this IArray input, Func keyFunc, Func valueFunc) - => input.ToEnumerable().ToLookup(keyFunc, valueFunc); - - - public static ILookup ToLookup(this IArray input, Func keyFunc) - => input.ToEnumerable().ToLookup(keyFunc, x => x); - - public static T FirstOrDefault(this IArray xs) - => xs.Count > 0 ? xs[0] : default; - - public static T FirstOrDefault(this IArray xs, T @default) - => xs.Count > 0 ? xs[0] : @default; - - public static T FirstOrDefault(this IArray xs, Func predicate) - => xs.Where(predicate).FirstOrDefault(); - - public static IArray ToLongs(this IArray xs) - => xs.Select(x => (long)x); - - public static IArray PrefixSums(this IArray self) - => self.ToLongs().PrefixSums(); - - public static IArray PrefixSums(this IArray self) - => self.Scan(0f, (a, b) => a + b); - - public static IArray PrefixSums(this IArray self) - => self.Scan(0.0, (a, b) => a + b); - - public static IArray Scan(this IArray self, U init, Func scanFunc) - { - if (self.Count == 0) - return Empty(); - var r = new U[self.Count]; - for (var i = 0; i < self.Count; ++i) - init = r[i] = scanFunc(init, self[i]); - return r.ToIArray(); - } - - public static IArray PrefixSums(this IArray counts) - => counts.Scan(0L, (a, b) => a + b); - - // Similar to prefix sums, but starts at zero. - // r[i] = Sum(count[0 to i]) - public static IArray CountsToOffsets(this IArray counts) - { - var r = new int[counts.Count]; - for (var i = 1; i < counts.Count; ++i) - r[i] = r[i - 1] + counts[i - 1]; - return r.ToIArray(); - } - - public static IArray OffsetsToCounts(this IArray offsets, int last) - => offsets.Indices().Select(i => i < offsets.Count - 1 ? offsets[i + 1] - offsets[i] : last - offsets[i]); - - public static IArray SetElementAt(this IArray self, int index, T value) - => self.SelectIndices(i => i == index ? value : self[i]); - - public static IArray SetFirstElementWhere(this IArray self, Func predicate, T value) - { - var index = self.IndexOf(predicate); - if (index < 0) - return self; - return self.SetElementAt(index, value); - } - - public static T SafeGet(this IArray self, int index, T defaultValue) - { - if(index < 0) return defaultValue; - if(index >= self.Count) return defaultValue; - return self[index]; - } - } -} diff --git a/src/cs/math3d/Vim.Math3D/LinqUtil.cs b/src/cs/math3d/Vim.Math3D/AABoxUtil.cs similarity index 57% rename from src/cs/math3d/Vim.Math3D/LinqUtil.cs rename to src/cs/math3d/Vim.Math3D/AABoxUtil.cs index c105f6e4..e5d3b854 100644 --- a/src/cs/math3d/Vim.Math3D/LinqUtil.cs +++ b/src/cs/math3d/Vim.Math3D/AABoxUtil.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace Vim.Math3d { - public static class LinqUtil + public static class AABoxUtil { public static AABox ToAABox(this IEnumerable self) => AABox.Create(self); diff --git a/src/cs/vim-format.sln b/src/cs/vim-format.sln index 6939a1f3..97edf442 100644 --- a/src/cs/vim-format.sln +++ b/src/cs/vim-format.sln @@ -5,12 +5,6 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "bfast", "bfast", "{F3260C54-834F-4C74-A3B7-EAB622AFA492}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "linqarray", "linqarray", "{CF54EDFD-51AB-4B0D-B084-2DF42918BA51}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.LinqArray", "linqarray\Vim.LinqArray\Vim.LinqArray.csproj", "{07CA1F46-21DA-4C22-A8CB-52D526D51C94}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.LinqArray.Tests", "linqarray\Vim.LinqArray.Tests\Vim.LinqArray.Tests.csproj", "{461788B0-072C-485F-82C0-F83CCC86F95D}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "math3d", "math3d", "{9BD3CC85-97FD-4093-AA11-58FE405B0F65}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Math3D", "math3d\Vim.Math3D\Vim.Math3D.csproj", "{1086F24E-32C8-4261-9B06-A364EEE71DEF}" @@ -59,14 +53,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {07CA1F46-21DA-4C22-A8CB-52D526D51C94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {07CA1F46-21DA-4C22-A8CB-52D526D51C94}.Debug|Any CPU.Build.0 = Debug|Any CPU - {07CA1F46-21DA-4C22-A8CB-52D526D51C94}.Release|Any CPU.ActiveCfg = Release|Any CPU - {07CA1F46-21DA-4C22-A8CB-52D526D51C94}.Release|Any CPU.Build.0 = Release|Any CPU - {461788B0-072C-485F-82C0-F83CCC86F95D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {461788B0-072C-485F-82C0-F83CCC86F95D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {461788B0-072C-485F-82C0-F83CCC86F95D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {461788B0-072C-485F-82C0-F83CCC86F95D}.Release|Any CPU.Build.0 = Release|Any CPU {1086F24E-32C8-4261-9B06-A364EEE71DEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1086F24E-32C8-4261-9B06-A364EEE71DEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {1086F24E-32C8-4261-9B06-A364EEE71DEF}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -140,8 +126,6 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {07CA1F46-21DA-4C22-A8CB-52D526D51C94} = {CF54EDFD-51AB-4B0D-B084-2DF42918BA51} - {461788B0-072C-485F-82C0-F83CCC86F95D} = {CF54EDFD-51AB-4B0D-B084-2DF42918BA51} {1086F24E-32C8-4261-9B06-A364EEE71DEF} = {9BD3CC85-97FD-4093-AA11-58FE405B0F65} {1CC20AA4-11F1-4548-9285-FD24D42190FB} = {9BD3CC85-97FD-4093-AA11-58FE405B0F65} {22278D91-27D7-4A84-8170-5FFB77A70C1F} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} diff --git a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj index f2908353..951143a3 100644 --- a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj +++ b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj @@ -8,7 +8,6 @@ - diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/Vim.Format.Vimx.Conversion.csproj b/src/cs/vim/Vim.Format.Vimx.Conversion/Vim.Format.Vimx.Conversion.csproj index 4e1f53c1..05a0161b 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/Vim.Format.Vimx.Conversion.csproj +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/Vim.Format.Vimx.Conversion.csproj @@ -1,11 +1,10 @@ - + netstandard2.0 - diff --git a/src/cs/vim/Vim.Format/Vim.Format.csproj b/src/cs/vim/Vim.Format/Vim.Format.csproj index a3ae53d8..5f433ac3 100644 --- a/src/cs/vim/Vim.Format/Vim.Format.csproj +++ b/src/cs/vim/Vim.Format/Vim.Format.csproj @@ -18,7 +18,6 @@ - From 68fa5e73dbda577c86384955d61491e7328a5beb Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 16 Apr 2024 16:02:27 -0400 Subject: [PATCH 082/104] fix --- src/cs/util/Vim.Util/CollectionExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cs/util/Vim.Util/CollectionExtensions.cs b/src/cs/util/Vim.Util/CollectionExtensions.cs index 87339b07..92404f98 100644 --- a/src/cs/util/Vim.Util/CollectionExtensions.cs +++ b/src/cs/util/Vim.Util/CollectionExtensions.cs @@ -20,15 +20,15 @@ public static ILookup ToVimLookup(this IEnumerable /// /// Returns the index of the first element matching the given item. /// - public static int IndexOf(this IArray self, T item) where T : IEquatable + public static int IndexOf(this T[] self, T item) where T : IEquatable => self.IndexOf(x => x.Equals(item)); /// /// Returns the index of the first element matching the given item. /// - public static int IndexOf(this IArray self, Func predicate) + public static int IndexOf(this T[] self, Func predicate) { - for (var i = 0; i < self.Count; ++i) + for (var i = 0; i < self.Length; ++i) { if (predicate(self[i])) return i; From c9af93b18551e36adbde6e2d6c5d3615ae4499fb Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 17 Apr 2024 08:25:37 -0400 Subject: [PATCH 083/104] renamed g3dnext -> g3d --- src/cs/Vim.G3dNext.Tests/{G3dNextTestUtils.cs => G3dTestUtils.cs} | 0 src/cs/Vim.G3dNext.Tests/{VimG3dNextTests.cs => G3dTests.cs} | 0 .../{Vim.G3dNext.Tests.csproj => Vim.G3d.Tests.csproj} | 0 src/cs/g3d/Vim.G3dNext/{Vim.G3dNext.csproj => Vim.G3d.csproj} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/cs/Vim.G3dNext.Tests/{G3dNextTestUtils.cs => G3dTestUtils.cs} (100%) rename src/cs/Vim.G3dNext.Tests/{VimG3dNextTests.cs => G3dTests.cs} (100%) rename src/cs/Vim.G3dNext.Tests/{Vim.G3dNext.Tests.csproj => Vim.G3d.Tests.csproj} (100%) rename src/cs/g3d/Vim.G3dNext/{Vim.G3dNext.csproj => Vim.G3d.csproj} (100%) diff --git a/src/cs/Vim.G3dNext.Tests/G3dNextTestUtils.cs b/src/cs/Vim.G3dNext.Tests/G3dTestUtils.cs similarity index 100% rename from src/cs/Vim.G3dNext.Tests/G3dNextTestUtils.cs rename to src/cs/Vim.G3dNext.Tests/G3dTestUtils.cs diff --git a/src/cs/Vim.G3dNext.Tests/VimG3dNextTests.cs b/src/cs/Vim.G3dNext.Tests/G3dTests.cs similarity index 100% rename from src/cs/Vim.G3dNext.Tests/VimG3dNextTests.cs rename to src/cs/Vim.G3dNext.Tests/G3dTests.cs diff --git a/src/cs/Vim.G3dNext.Tests/Vim.G3dNext.Tests.csproj b/src/cs/Vim.G3dNext.Tests/Vim.G3d.Tests.csproj similarity index 100% rename from src/cs/Vim.G3dNext.Tests/Vim.G3dNext.Tests.csproj rename to src/cs/Vim.G3dNext.Tests/Vim.G3d.Tests.csproj diff --git a/src/cs/g3d/Vim.G3dNext/Vim.G3dNext.csproj b/src/cs/g3d/Vim.G3dNext/Vim.G3d.csproj similarity index 100% rename from src/cs/g3d/Vim.G3dNext/Vim.G3dNext.csproj rename to src/cs/g3d/Vim.G3dNext/Vim.G3d.csproj From c5277817b998a6eea80ce69adb834c40e4a3bd21 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 17 Apr 2024 08:28:39 -0400 Subject: [PATCH 084/104] rename --- .../{Vim.G3dNext.CodeGen.csproj => Vim.G3d.CodeGen.csproj} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/cs/g3d/Vim.G3dNext.CodeGen/{Vim.G3dNext.CodeGen.csproj => Vim.G3d.CodeGen.csproj} (100%) diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/Vim.G3dNext.CodeGen.csproj b/src/cs/g3d/Vim.G3dNext.CodeGen/Vim.G3d.CodeGen.csproj similarity index 100% rename from src/cs/g3d/Vim.G3dNext.CodeGen/Vim.G3dNext.CodeGen.csproj rename to src/cs/g3d/Vim.G3dNext.CodeGen/Vim.G3d.CodeGen.csproj From ba112a440c67d944ab3c3832662deea191414fce Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 17 Apr 2024 08:51:09 -0400 Subject: [PATCH 085/104] g3dnext -> g3d --- .../CodeBuilder.cs | 2 +- .../Definitions.cs | 2 +- .../G3dBuffer.cs | 2 +- .../G3dCodeGen.cs | 4 +- .../G3dEntity.cs | 2 +- .../Program.cs | 2 +- .../Vim.G3d.CodeGen.csproj | 4 +- .../Vim.G3d.Tests}/G3dTestUtils.cs | 2 +- .../Vim.G3d.Tests}/G3dTests.cs | 2 +- .../Vim.G3d.Tests}/Vim.G3d.Tests.csproj | 7 +- .../{Vim.G3dNext => Vim.G3d}/BufferMethods.cs | 2 +- .../g3d/{Vim.G3dNext => Vim.G3d}/Constants.cs | 2 +- .../g3d/{Vim.G3dNext => Vim.G3d}/G3dChunk.cs | 2 +- .../G3dGenerated.g.cs | 2 +- .../{Vim.G3dNext => Vim.G3d}/G3dMaterials.cs | 2 +- .../g3d/{Vim.G3dNext => Vim.G3d}/G3dScene.cs | 2 +- src/cs/g3d/{Vim.G3dNext => Vim.G3d}/G3dVim.cs | 2 +- .../{Vim.G3dNext => Vim.G3d}/MetaHeader.cs | 2 +- src/cs/g3d/Vim.G3d/README.md | 109 ------------------ src/cs/g3d/Vim.G3d/Vim.G3d.csproj | 49 ++------ .../Vim.G3dNext.Tests.csproj | 37 ------ src/cs/g3d/Vim.G3dNext/Vim.G3d.csproj | 22 ---- src/cs/vim-format.sln | 40 +++---- src/cs/vim/Vim.Format.Core/Document.cs | 2 +- .../Vim.Format.Core/DocumentBuilderTypes.cs | 2 +- src/cs/vim/Vim.Format.Core/G3dBuilder.cs | 2 +- .../Geometry/VimMaterialNext.cs | 2 +- .../vim/Vim.Format.Core/Geometry/VimMesh.cs | 2 +- .../Vim.Format.Core/Geometry/VimShapeNext.cs | 2 +- .../Vim.Format.Core/SerializableDocument.cs | 2 +- .../Vim.Format.Core/Vim.Format.Core.csproj | 2 +- .../Geometry/GeometryTests.cs | 2 +- .../Vim.Format.Vimx.Conversion/Chunking.cs | 2 +- .../Vim.Format.Vimx.Conversion/Ordering.cs | 2 +- .../VimxConverter.cs | 2 +- .../Vim.Format.Vimx/Vim.Format.Vimx.csproj | 1 - src/cs/vim/Vim.Format.Vimx/Vimx.cs | 2 +- .../vim/Vim.Format/SceneBuilder/VimScene.cs | 2 +- .../Vim.Format/SceneBuilder/VimSceneNode.cs | 4 +- src/cs/vim/Vim.Format/Vim.Format.csproj | 1 - 40 files changed, 65 insertions(+), 271 deletions(-) rename src/cs/g3d/{Vim.G3dNext.CodeGen => Vim.G3d.CodeGen}/CodeBuilder.cs (98%) rename src/cs/g3d/{Vim.G3dNext.CodeGen => Vim.G3d.CodeGen}/Definitions.cs (99%) rename src/cs/g3d/{Vim.G3dNext.CodeGen => Vim.G3d.CodeGen}/G3dBuffer.cs (97%) rename src/cs/g3d/{Vim.G3dNext.CodeGen => Vim.G3d.CodeGen}/G3dCodeGen.cs (98%) rename src/cs/g3d/{Vim.G3dNext.CodeGen => Vim.G3d.CodeGen}/G3dEntity.cs (96%) rename src/cs/g3d/{Vim.G3dNext.CodeGen => Vim.G3d.CodeGen}/Program.cs (85%) rename src/cs/g3d/{Vim.G3dNext.CodeGen => Vim.G3d.CodeGen}/Vim.G3d.CodeGen.csproj (79%) rename src/cs/{Vim.G3dNext.Tests => g3d/Vim.G3d.Tests}/G3dTestUtils.cs (97%) rename src/cs/{Vim.G3dNext.Tests => g3d/Vim.G3d.Tests}/G3dTests.cs (99%) rename src/cs/{Vim.G3dNext.Tests => g3d/Vim.G3d.Tests}/Vim.G3d.Tests.csproj (71%) rename src/cs/g3d/{Vim.G3dNext => Vim.G3d}/BufferMethods.cs (98%) rename src/cs/g3d/{Vim.G3dNext => Vim.G3d}/Constants.cs (99%) rename src/cs/g3d/{Vim.G3dNext => Vim.G3d}/G3dChunk.cs (99%) rename src/cs/g3d/{Vim.G3dNext => Vim.G3d}/G3dGenerated.g.cs (99%) rename src/cs/g3d/{Vim.G3dNext => Vim.G3d}/G3dMaterials.cs (94%) rename src/cs/g3d/{Vim.G3dNext => Vim.G3d}/G3dScene.cs (90%) rename src/cs/g3d/{Vim.G3dNext => Vim.G3d}/G3dVim.cs (99%) rename src/cs/g3d/{Vim.G3dNext => Vim.G3d}/MetaHeader.cs (99%) delete mode 100644 src/cs/g3d/Vim.G3d/README.md delete mode 100644 src/cs/g3d/Vim.G3dNext.Tests/Vim.G3dNext.Tests.csproj delete mode 100644 src/cs/g3d/Vim.G3dNext/Vim.G3d.csproj diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/CodeBuilder.cs b/src/cs/g3d/Vim.G3d.CodeGen/CodeBuilder.cs similarity index 98% rename from src/cs/g3d/Vim.G3dNext.CodeGen/CodeBuilder.cs rename to src/cs/g3d/Vim.G3d.CodeGen/CodeBuilder.cs index 8dd3283a..41013d8f 100644 --- a/src/cs/g3d/Vim.G3dNext.CodeGen/CodeBuilder.cs +++ b/src/cs/g3d/Vim.G3d.CodeGen/CodeBuilder.cs @@ -2,7 +2,7 @@ using System.Linq; using System.Text; -namespace Vim.G3dNext.CodeGen +namespace Vim.G3d.CodeGen { public class CodeBuilder { diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/Definitions.cs b/src/cs/g3d/Vim.G3d.CodeGen/Definitions.cs similarity index 99% rename from src/cs/g3d/Vim.G3dNext.CodeGen/Definitions.cs rename to src/cs/g3d/Vim.G3d.CodeGen/Definitions.cs index 9eb47307..8d53e40b 100644 --- a/src/cs/g3d/Vim.G3dNext.CodeGen/Definitions.cs +++ b/src/cs/g3d/Vim.G3d.CodeGen/Definitions.cs @@ -1,6 +1,6 @@ using Vim.Math3d; -namespace Vim.G3dNext.CodeGen +namespace Vim.G3d.CodeGen { internal class Definitions { diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dBuffer.cs b/src/cs/g3d/Vim.G3d.CodeGen/G3dBuffer.cs similarity index 97% rename from src/cs/g3d/Vim.G3dNext.CodeGen/G3dBuffer.cs rename to src/cs/g3d/Vim.G3d.CodeGen/G3dBuffer.cs index 97cf4ce1..e3763042 100644 --- a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dBuffer.cs +++ b/src/cs/g3d/Vim.G3d.CodeGen/G3dBuffer.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; -namespace Vim.G3dNext.CodeGen +namespace Vim.G3d.CodeGen { public enum BufferType { diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs b/src/cs/g3d/Vim.G3d.CodeGen/G3dCodeGen.cs similarity index 98% rename from src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs rename to src/cs/g3d/Vim.G3d.CodeGen/G3dCodeGen.cs index 7d04fec4..773342cc 100644 --- a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dCodeGen.cs +++ b/src/cs/g3d/Vim.G3d.CodeGen/G3dCodeGen.cs @@ -2,7 +2,7 @@ using System.IO; using System.Linq; -namespace Vim.G3dNext.CodeGen +namespace Vim.G3d.CodeGen { public static class G3dCodeGen { @@ -16,7 +16,7 @@ public static void WriteDocument(string filePath) cb.AppendLine("// ReSharper disable All"); cb.AppendLine("using Vim.BFastLib;"); cb.AppendLine(); - cb.AppendLine("namespace Vim.G3dNext"); + cb.AppendLine("namespace Vim.G3d"); cb.AppendLine("{"); WriteEntities(cb); cb.AppendLine("}"); diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dEntity.cs b/src/cs/g3d/Vim.G3d.CodeGen/G3dEntity.cs similarity index 96% rename from src/cs/g3d/Vim.G3dNext.CodeGen/G3dEntity.cs rename to src/cs/g3d/Vim.G3d.CodeGen/G3dEntity.cs index 2be5f9e7..5c224c31 100644 --- a/src/cs/g3d/Vim.G3dNext.CodeGen/G3dEntity.cs +++ b/src/cs/g3d/Vim.G3d.CodeGen/G3dEntity.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Vim.G3dNext.CodeGen +namespace Vim.G3d.CodeGen { /// /// Holds the data to generate the code for a g3d entity. diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/Program.cs b/src/cs/g3d/Vim.G3d.CodeGen/Program.cs similarity index 85% rename from src/cs/g3d/Vim.G3dNext.CodeGen/Program.cs rename to src/cs/g3d/Vim.G3d.CodeGen/Program.cs index 5470fb2f..6bf7d644 100644 --- a/src/cs/g3d/Vim.G3dNext.CodeGen/Program.cs +++ b/src/cs/g3d/Vim.G3d.CodeGen/Program.cs @@ -1,4 +1,4 @@ -namespace Vim.G3dNext.CodeGen +namespace Vim.G3d.CodeGen { public static class Program { diff --git a/src/cs/g3d/Vim.G3dNext.CodeGen/Vim.G3d.CodeGen.csproj b/src/cs/g3d/Vim.G3d.CodeGen/Vim.G3d.CodeGen.csproj similarity index 79% rename from src/cs/g3d/Vim.G3dNext.CodeGen/Vim.G3d.CodeGen.csproj rename to src/cs/g3d/Vim.G3d.CodeGen/Vim.G3d.CodeGen.csproj index 41239fb1..74a5126c 100644 --- a/src/cs/g3d/Vim.G3dNext.CodeGen/Vim.G3d.CodeGen.csproj +++ b/src/cs/g3d/Vim.G3d.CodeGen/Vim.G3d.CodeGen.csproj @@ -7,7 +7,7 @@ Exe - Vim.G3dNext.CodeGen.Program + Vim.G3d.CodeGen.Program @@ -15,7 +15,7 @@ - + diff --git a/src/cs/Vim.G3dNext.Tests/G3dTestUtils.cs b/src/cs/g3d/Vim.G3d.Tests/G3dTestUtils.cs similarity index 97% rename from src/cs/Vim.G3dNext.Tests/G3dTestUtils.cs rename to src/cs/g3d/Vim.G3d.Tests/G3dTestUtils.cs index 118167fb..d179edd9 100644 --- a/src/cs/Vim.G3dNext.Tests/G3dTestUtils.cs +++ b/src/cs/g3d/Vim.G3d.Tests/G3dTestUtils.cs @@ -1,6 +1,6 @@ using Vim.Math3d; -namespace Vim.G3dNext.Tests +namespace Vim.G3d.Tests { public static class G3dNextTestUtils { diff --git a/src/cs/Vim.G3dNext.Tests/G3dTests.cs b/src/cs/g3d/Vim.G3d.Tests/G3dTests.cs similarity index 99% rename from src/cs/Vim.G3dNext.Tests/G3dTests.cs rename to src/cs/g3d/Vim.G3d.Tests/G3dTests.cs index a8505b66..1539c1f1 100644 --- a/src/cs/Vim.G3dNext.Tests/G3dTests.cs +++ b/src/cs/g3d/Vim.G3d.Tests/G3dTests.cs @@ -3,7 +3,7 @@ using Vim.BFastLib; using Vim.Util.Tests; -namespace Vim.G3dNext.Tests +namespace Vim.G3d.Tests { [TestFixture] public static class VimG3dNextTests diff --git a/src/cs/Vim.G3dNext.Tests/Vim.G3d.Tests.csproj b/src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj similarity index 71% rename from src/cs/Vim.G3dNext.Tests/Vim.G3d.Tests.csproj rename to src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj index 032e77f2..e56190a6 100644 --- a/src/cs/Vim.G3dNext.Tests/Vim.G3d.Tests.csproj +++ b/src/cs/g3d/Vim.G3d.Tests/Vim.G3d.Tests.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -16,9 +16,8 @@ - - - + + diff --git a/src/cs/g3d/Vim.G3dNext/BufferMethods.cs b/src/cs/g3d/Vim.G3d/BufferMethods.cs similarity index 98% rename from src/cs/g3d/Vim.G3dNext/BufferMethods.cs rename to src/cs/g3d/Vim.G3d/BufferMethods.cs index e4f74d70..c7330f7e 100644 --- a/src/cs/g3d/Vim.G3dNext/BufferMethods.cs +++ b/src/cs/g3d/Vim.G3d/BufferMethods.cs @@ -2,7 +2,7 @@ using System.IO; using System.Linq; -namespace Vim.G3dNext +namespace Vim.G3d { public static class BufferMethods { diff --git a/src/cs/g3d/Vim.G3dNext/Constants.cs b/src/cs/g3d/Vim.G3d/Constants.cs similarity index 99% rename from src/cs/g3d/Vim.G3dNext/Constants.cs rename to src/cs/g3d/Vim.G3d/Constants.cs index 047a6081..d22e623b 100644 --- a/src/cs/g3d/Vim.G3dNext/Constants.cs +++ b/src/cs/g3d/Vim.G3d/Constants.cs @@ -1,4 +1,4 @@ -namespace Vim.G3dNext +namespace Vim.G3d { /// /// Defines method for additionnal setup after constructors in generated G3d classes. diff --git a/src/cs/g3d/Vim.G3dNext/G3dChunk.cs b/src/cs/g3d/Vim.G3d/G3dChunk.cs similarity index 99% rename from src/cs/g3d/Vim.G3dNext/G3dChunk.cs rename to src/cs/g3d/Vim.G3d/G3dChunk.cs index b89414dd..c85d9bc9 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dChunk.cs +++ b/src/cs/g3d/Vim.G3d/G3dChunk.cs @@ -2,7 +2,7 @@ using System.Linq; using Vim.Math3d; -namespace Vim.G3dNext +namespace Vim.G3d { diff --git a/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs b/src/cs/g3d/Vim.G3d/G3dGenerated.g.cs similarity index 99% rename from src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs rename to src/cs/g3d/Vim.G3d/G3dGenerated.g.cs index 1a822426..21c085f8 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dGenerated.g.cs +++ b/src/cs/g3d/Vim.G3d/G3dGenerated.g.cs @@ -2,7 +2,7 @@ // ReSharper disable All using Vim.BFastLib; -namespace Vim.G3dNext +namespace Vim.G3d { // Please provide an explicit implementation in another partial class file. public partial class G3dVim : ISetup diff --git a/src/cs/g3d/Vim.G3dNext/G3dMaterials.cs b/src/cs/g3d/Vim.G3d/G3dMaterials.cs similarity index 94% rename from src/cs/g3d/Vim.G3dNext/G3dMaterials.cs rename to src/cs/g3d/Vim.G3d/G3dMaterials.cs index 18c3138a..28888a7e 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dMaterials.cs +++ b/src/cs/g3d/Vim.G3d/G3dMaterials.cs @@ -1,5 +1,5 @@  -namespace Vim.G3dNext +namespace Vim.G3d { public partial class G3dMaterials { diff --git a/src/cs/g3d/Vim.G3dNext/G3dScene.cs b/src/cs/g3d/Vim.G3d/G3dScene.cs similarity index 90% rename from src/cs/g3d/Vim.G3dNext/G3dScene.cs rename to src/cs/g3d/Vim.G3d/G3dScene.cs index 4d6adb03..1fe8d9e2 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dScene.cs +++ b/src/cs/g3d/Vim.G3d/G3dScene.cs @@ -1,4 +1,4 @@ -namespace Vim.G3dNext +namespace Vim.G3d { public partial class G3dScene { diff --git a/src/cs/g3d/Vim.G3dNext/G3dVim.cs b/src/cs/g3d/Vim.G3d/G3dVim.cs similarity index 99% rename from src/cs/g3d/Vim.G3dNext/G3dVim.cs rename to src/cs/g3d/Vim.G3d/G3dVim.cs index b21fed00..78ab447b 100644 --- a/src/cs/g3d/Vim.G3dNext/G3dVim.cs +++ b/src/cs/g3d/Vim.G3d/G3dVim.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Vim.BFastLib; -namespace Vim.G3dNext +namespace Vim.G3d { [Flags] public enum InstanceFlags diff --git a/src/cs/g3d/Vim.G3dNext/MetaHeader.cs b/src/cs/g3d/Vim.G3d/MetaHeader.cs similarity index 99% rename from src/cs/g3d/Vim.G3dNext/MetaHeader.cs rename to src/cs/g3d/Vim.G3d/MetaHeader.cs index a58a3a6f..b79db7ea 100644 --- a/src/cs/g3d/Vim.G3dNext/MetaHeader.cs +++ b/src/cs/g3d/Vim.G3d/MetaHeader.cs @@ -1,7 +1,7 @@ using System; using System.Text; -namespace Vim.G3dNext +namespace Vim.G3d { // http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/index.html?url=files/GUID-CC93340E-C4A1-49EE-B048-E898F856CFBF.htm,topicNumber=d30e8478 // https://twitter.com/FreyaHolmer/status/644881436982575104 diff --git a/src/cs/g3d/Vim.G3d/README.md b/src/cs/g3d/Vim.G3d/README.md deleted file mode 100644 index fd8f0ebe..00000000 --- a/src/cs/g3d/Vim.G3d/README.md +++ /dev/null @@ -1,109 +0,0 @@ -# G3D - -[](https://www.nuget.org/packages/Vim.G3d) - -G3D is a simple, efficient, generic binary format for storing and transmitting geometry. The G3D format -is designed to be used either as a serialization format or as an in-memory data structure. - -G3D can represent triangular meshes, quadrilateral meshes, polygonal meshes, point clouds, and line segments. -It can be easily and efficiently deserialized and rendered in different languages and on different platforms. - -The G3D format can contain a superset of geometry attributes found in most common geometry formats, -including formats such as FBX, glTF, OBJ, PLY, and in memory data structures used in popular 3D APIs, like -Unity, Three.JS, Assimp, and 3dsMax. - -BFAST is maintained by [VIMaec LLC](https://vimaec.com) and is licensed under the terms of the MIT License. - -# Format - -## BFAST Container - -The underlying binary layout of a G3D file conforms to the [BFAST serialization format](https://github.com/vimaec/bfast), which is a simple and efficient binary format for serializing -collections of byte arrays. BFAST provides an interface that allows named arrays of binary data to be serialized and deserialized quickly and easily. - -The first named buffer in the BFAST container is reserved for meta-information about the file encoded in JSON format. It has the name "meta". -Each subsequent buffer uses the attribute descriptor string as a name. - -## Meta-Information - -The first buffer of a G3D file is named "meta" and is represented by the G3D - -## Attributes - -G3D is organized as a collection of attribute buffers. Each attributes describe what part of the incoming geometry they are associated with: - -* point // vertex data -* corner // face-vertex data -* face // per polygon data -* edge // per half-edge data -* group // face group. Face groups are identified by a face data buffer -* SubGeometry // a contiguous section of the vertex-buffer, and index-buffer -* material // data associated with a material, materials are usually associated with groups, a -* instance // instance data, usually an instance has an index to a SubGeometry -* all // whole object data - for example face-size of 4 with whole object indicates a quad mesh -* none // no association - -Attributes also have a "semantic" which is used to identify what role the attribute has when parsing. These map roughly to FBX layer elements, or Three.JS buffer attributes. -There are a number of predefined semantic values with reserved names, but applications are free to define custom semantic values. The only required semantic in a G3D file is -"position". Here is a list of some of the predefined semantics: - -* unknown, // no known attribute type -* position, // vertex buffer -* index, // index buffer -* indexoffset, // an offset into the index buffer (used with Subgeometries) -* vertexoffset, // the offset into the vertex buffer (used only with Subgeometries) -* normal, // computed normal information (per face, group, corner, or vertex) -* binormal, // computed binormal information -* tangent, // computed tangent information -* material, // material index -* visibility, // visibility data (e.g. -* size, // number of indices per face or group -* uv, // UV (sometimes more than 1, e.g. Unity supports up to 8) -* color, // usually vertex color, but could be edge color as well -* smoothing, // identifies smoothing groups (e.g. ala 3ds Max and OBJ files) -* weight, // in 3ds Max this is called selection -* mapchannel, // 3ds Max map channel (assoc of none => map verts, assoc of corner => map faces) -* id, // used to identify what object each face part came from -* joint, // used to identify what a joint a skin is associated with -* boxes, // used to identify bounding boxes -* spheres, // used to identify bounding spheres -* user, // identifies user specific data (in 3ds Max this could be "per-vertex-data") - -Attributes are stored in 512-byte aligned data-buffers arranged as arrays of scalars or fixed width vectors. The individual data values can be integers, or floating point values of various widths from 1 to 8 bytes. The data-types are: - -* int8 -* int16 -* int32 -* int64 -* float32 -* float64 - -The number of primitives per data element is called the "arity" and can be any integer value greater than zero. For example UV might have an arity of 2, while position data -frequently has an arity of 3. - -## Encoding Strings - -While there is no explicit string type, one could encode string data by using a data-type uint8 with an arity of a fixed value (say 255) to store short strings. - -## Attribute Descriptor String - -Every attribute descriptor has a one to one mapping to a string representation similar to a URN: - - `g3d::::` - -This attribute descriptor string is the name of the buffer. - -# Recommended reading: - -* [VIM AEC blog post about using G3D with Unity](https://www.vimaec.com/the-g3d-geometry-exchange-format/) -* [Hackernoon article about BFast](https://hackernoon.com/bfast-a-data-format-for-serializing-named-binary-buffers-243p130uw) -* http://assimp.sourceforge.net/lib_html/structai_mesh.html -* http://help.autodesk.com/view/FBX/2017/ENU/?guid=__files_GUID_5EDC0280_E000_4B0B_88DF_5D215A589D5E_htm -* https://help.autodesk.com/cloudhelp/2017/ENU/Max-SDK/cpp_ref/class_mesh.html -* https://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_CBBA20AD_F7D5_46BC_9F5E_5EDA109F9CF4_htm -* http://paulbourke.net/dataformats/ -* http://paulbourke.net/dataformats/obj/ -* http://paulbourke.net/dataformats/ply/ -* http://paulbourke.net/dataformats/3ds/ -* https://github.com/KhronosGroup/gltf -* http://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_class_fbx_layer_element_html diff --git a/src/cs/g3d/Vim.G3d/Vim.G3d.csproj b/src/cs/g3d/Vim.G3d/Vim.G3d.csproj index f3bb78c2..b0086596 100644 --- a/src/cs/g3d/Vim.G3d/Vim.G3d.csproj +++ b/src/cs/g3d/Vim.G3d/Vim.G3d.csproj @@ -1,57 +1,22 @@  - - netstandard2.0 - true - G3D is a simple, efficient, generic binary format for storing and transmitting geometry. The G3D format is designed to be used either as a serialization format or as an in-memory data structure. G3D can represent triangular meshes, quadrilateral meshes, polygonal meshes, point clouds, and line segments. -It can be easily and efficiently deserialized and rendered in different languages and on different platforms. - true - true - snupkg - - - - true - - - - true + netstandard2.0 - - - True - - - - + - - - - - - CommonAttributes.tt - True - True - + + - - - CommonAttributes.cs - TextTemplatingFileGenerator + + True + - - - - - - diff --git a/src/cs/g3d/Vim.G3dNext.Tests/Vim.G3dNext.Tests.csproj b/src/cs/g3d/Vim.G3dNext.Tests/Vim.G3dNext.Tests.csproj deleted file mode 100644 index 158c815b..00000000 --- a/src/cs/g3d/Vim.G3dNext.Tests/Vim.G3dNext.Tests.csproj +++ /dev/null @@ -1,37 +0,0 @@ - - - netstandard2.0 - false - - - - - - - - - - - - - - - - - True - True - Resources.resx - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - - - diff --git a/src/cs/g3d/Vim.G3dNext/Vim.G3d.csproj b/src/cs/g3d/Vim.G3dNext/Vim.G3d.csproj deleted file mode 100644 index b0086596..00000000 --- a/src/cs/g3d/Vim.G3dNext/Vim.G3d.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - netstandard2.0 - - - - - - - - - - - - - - True - - - - - diff --git a/src/cs/vim-format.sln b/src/cs/vim-format.sln index 97edf442..dca052d8 100644 --- a/src/cs/vim-format.sln +++ b/src/cs/vim-format.sln @@ -31,10 +31,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "util", "util", "{A279C2F9-3 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Util.Logging.Serilog", "util\Vim.Util.Logging.Serilog\Vim.Util.Logging.Serilog.csproj", "{6B9E6432-A7BB-4487-905A-0C3117398140}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3dNext", "g3d\Vim.G3dNext\Vim.G3dNext.csproj", "{7A3255D6-444D-46B7-8BBD-ABED88C99009}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3dNext.CodeGen", "g3d\Vim.G3dNext.CodeGen\Vim.G3dNext.CodeGen.csproj", "{F0FFC990-6358-4B17-B878-C6CA087CDF3F}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Format.Vimx", "vim\Vim.Format.Vimx\Vim.Format.Vimx.csproj", "{B5C8E733-8D3F-45BD-BBBE-09A9F1965545}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Format.Vimx.Test", "vim\Vim.Vimx.Test\Vim.Format.Vimx.Test.csproj", "{BBF94CBD-CD39-49F5-979A-5C9E52C29330}" @@ -45,7 +41,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.BFast.Tests", "bfast\Vi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Format.Vimx.Conversion", "vim\Vim.Format.Vimx.Conversion\Vim.Format.Vimx.Conversion.csproj", "{4C4F9826-0DEF-4A39-BFC8-A834522694A0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3dNext.Tests", "Vim.G3dNext.Tests\Vim.G3dNext.Tests.csproj", "{AD1A2A9F-18E9-4430-A192-3CD1A17DDA0D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3d", "g3d\Vim.G3d\Vim.G3d.csproj", "{4D3789CE-5C2F-4B4E-8E9F-EC0D171E520E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3d.CodeGen", "g3d\Vim.G3d.CodeGen\Vim.G3d.CodeGen.csproj", "{DC267698-FA79-40E2-9322-14F346ABAD85}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.G3d.Tests", "g3d\Vim.G3d.Tests\Vim.G3d.Tests.csproj", "{059CAAF3-0B7C-46B0-A939-BF96DC6DB394}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -89,14 +89,6 @@ Global {6B9E6432-A7BB-4487-905A-0C3117398140}.Debug|Any CPU.Build.0 = Debug|Any CPU {6B9E6432-A7BB-4487-905A-0C3117398140}.Release|Any CPU.ActiveCfg = Release|Any CPU {6B9E6432-A7BB-4487-905A-0C3117398140}.Release|Any CPU.Build.0 = Release|Any CPU - {7A3255D6-444D-46B7-8BBD-ABED88C99009}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7A3255D6-444D-46B7-8BBD-ABED88C99009}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7A3255D6-444D-46B7-8BBD-ABED88C99009}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7A3255D6-444D-46B7-8BBD-ABED88C99009}.Release|Any CPU.Build.0 = Release|Any CPU - {F0FFC990-6358-4B17-B878-C6CA087CDF3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F0FFC990-6358-4B17-B878-C6CA087CDF3F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F0FFC990-6358-4B17-B878-C6CA087CDF3F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F0FFC990-6358-4B17-B878-C6CA087CDF3F}.Release|Any CPU.Build.0 = Release|Any CPU {B5C8E733-8D3F-45BD-BBBE-09A9F1965545}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B5C8E733-8D3F-45BD-BBBE-09A9F1965545}.Debug|Any CPU.Build.0 = Debug|Any CPU {B5C8E733-8D3F-45BD-BBBE-09A9F1965545}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -117,10 +109,18 @@ Global {4C4F9826-0DEF-4A39-BFC8-A834522694A0}.Debug|Any CPU.Build.0 = Debug|Any CPU {4C4F9826-0DEF-4A39-BFC8-A834522694A0}.Release|Any CPU.ActiveCfg = Release|Any CPU {4C4F9826-0DEF-4A39-BFC8-A834522694A0}.Release|Any CPU.Build.0 = Release|Any CPU - {AD1A2A9F-18E9-4430-A192-3CD1A17DDA0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AD1A2A9F-18E9-4430-A192-3CD1A17DDA0D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AD1A2A9F-18E9-4430-A192-3CD1A17DDA0D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AD1A2A9F-18E9-4430-A192-3CD1A17DDA0D}.Release|Any CPU.Build.0 = Release|Any CPU + {4D3789CE-5C2F-4B4E-8E9F-EC0D171E520E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D3789CE-5C2F-4B4E-8E9F-EC0D171E520E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D3789CE-5C2F-4B4E-8E9F-EC0D171E520E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D3789CE-5C2F-4B4E-8E9F-EC0D171E520E}.Release|Any CPU.Build.0 = Release|Any CPU + {DC267698-FA79-40E2-9322-14F346ABAD85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DC267698-FA79-40E2-9322-14F346ABAD85}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DC267698-FA79-40E2-9322-14F346ABAD85}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DC267698-FA79-40E2-9322-14F346ABAD85}.Release|Any CPU.Build.0 = Release|Any CPU + {059CAAF3-0B7C-46B0-A939-BF96DC6DB394}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {059CAAF3-0B7C-46B0-A939-BF96DC6DB394}.Debug|Any CPU.Build.0 = Debug|Any CPU + {059CAAF3-0B7C-46B0-A939-BF96DC6DB394}.Release|Any CPU.ActiveCfg = Release|Any CPU + {059CAAF3-0B7C-46B0-A939-BF96DC6DB394}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -135,14 +135,14 @@ Global {EC00B2EC-3CF0-43C3-A071-320AD3C355CF} = {A279C2F9-3418-484B-A36E-D1D1C67A0B2D} {F7091670-1059-4F4F-AC3A-0B1DE4A724B5} = {A279C2F9-3418-484B-A36E-D1D1C67A0B2D} {6B9E6432-A7BB-4487-905A-0C3117398140} = {A279C2F9-3418-484B-A36E-D1D1C67A0B2D} - {7A3255D6-444D-46B7-8BBD-ABED88C99009} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} - {F0FFC990-6358-4B17-B878-C6CA087CDF3F} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} {B5C8E733-8D3F-45BD-BBBE-09A9F1965545} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} {BBF94CBD-CD39-49F5-979A-5C9E52C29330} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} {408884EA-3CE5-4A34-97F6-1F2D64A0E745} = {F3260C54-834F-4C74-A3B7-EAB622AFA492} {FD149D64-5905-4F7D-97A8-9F7DA18A257D} = {F3260C54-834F-4C74-A3B7-EAB622AFA492} {4C4F9826-0DEF-4A39-BFC8-A834522694A0} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} - {AD1A2A9F-18E9-4430-A192-3CD1A17DDA0D} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} + {4D3789CE-5C2F-4B4E-8E9F-EC0D171E520E} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} + {DC267698-FA79-40E2-9322-14F346ABAD85} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} + {059CAAF3-0B7C-46B0-A939-BF96DC6DB394} = {705B8FB2-D707-4527-91FC-0AADEDBA4D80} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7D1BF641-26E8-4809-B638-029241C51BE2} diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index 4257d38d..6532197f 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -1,5 +1,5 @@ using Vim.BFastLib; -using Vim.G3dNext; +using Vim.G3d; using Vim.Util; namespace Vim.Format diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs index 7d48f289..3d4b276f 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using Vim.Format.Geometry; -using Vim.G3dNext; +using Vim.G3d; using Vim.Math3d; namespace Vim.Format diff --git a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs index f2cd62d4..8cbdbd45 100644 --- a/src/cs/vim/Vim.Format.Core/G3dBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/G3dBuilder.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Linq; -using Vim.G3dNext; +using Vim.G3d; using Vim.BFastLib; using static Vim.Format.DocumentBuilder; using Vim.Math3d; diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs index 0d0a1740..07ee1f2e 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMaterialNext.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Vim.G3dNext; +using Vim.G3d; using Vim.Math3d; namespace Vim.Format.Geometry diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs index e5cffc94..b80c1a0f 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimMesh.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Vim.G3dNext; +using Vim.G3d; using Vim.Math3d; namespace Vim.Format.Geometry diff --git a/src/cs/vim/Vim.Format.Core/Geometry/VimShapeNext.cs b/src/cs/vim/Vim.Format.Core/Geometry/VimShapeNext.cs index 10dcf2f3..7c63bdd1 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/VimShapeNext.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/VimShapeNext.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Vim.G3dNext; +using Vim.G3d; using Vim.Math3d; namespace Vim.Format.Geometry diff --git a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs index 013ce98f..6acaa935 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableDocument.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableDocument.cs @@ -4,7 +4,7 @@ using System.Text; using Vim.BFastLib; using Vim.BFastLib.Core; -using Vim.G3dNext; +using Vim.G3d; namespace Vim.Format { diff --git a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj index 951143a3..a291acd7 100644 --- a/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj +++ b/src/cs/vim/Vim.Format.Core/Vim.Format.Core.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs index 6218cd8f..13fde2f6 100644 --- a/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs +++ b/src/cs/vim/Vim.Format.Tests/Geometry/GeometryTests.cs @@ -2,7 +2,7 @@ using System; using System.Linq; using Vim.Format.Geometry; -using Vim.G3dNext; +using Vim.G3d; using Vim.Math3d; namespace Vim.Format.Tests.Geometry diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs b/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs index 0318eb23..8ddf6187 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/Chunking.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using Vim.Math3d; -using Vim.G3dNext; +using Vim.G3d; namespace Vim.Format.VimxLib.Conversion { diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/Ordering.cs b/src/cs/vim/Vim.Format.Vimx.Conversion/Ordering.cs index 2424185b..587bac7e 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/Ordering.cs +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/Ordering.cs @@ -1,6 +1,6 @@ using System; using Vim.Format.ObjectModel; -using Vim.G3dNext; +using Vim.G3d; namespace Vim.Format.VimxLib.Conversion { diff --git a/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs b/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs index 77749be7..62663db9 100644 --- a/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs +++ b/src/cs/vim/Vim.Format.Vimx.Conversion/VimxConverter.cs @@ -3,7 +3,7 @@ using System.Linq; using Vim.BFastLib; using Vim.Format.ObjectModel; -using Vim.G3dNext; +using Vim.G3d; using Vim.Math3d; using Vim.Util; diff --git a/src/cs/vim/Vim.Format.Vimx/Vim.Format.Vimx.csproj b/src/cs/vim/Vim.Format.Vimx/Vim.Format.Vimx.csproj index 78fe3dbf..b9896ad8 100644 --- a/src/cs/vim/Vim.Format.Vimx/Vim.Format.Vimx.csproj +++ b/src/cs/vim/Vim.Format.Vimx/Vim.Format.Vimx.csproj @@ -10,7 +10,6 @@ - diff --git a/src/cs/vim/Vim.Format.Vimx/Vimx.cs b/src/cs/vim/Vim.Format.Vimx/Vimx.cs index db973d04..31c3c20e 100644 --- a/src/cs/vim/Vim.Format.Vimx/Vimx.cs +++ b/src/cs/vim/Vim.Format.Vimx/Vimx.cs @@ -1,6 +1,6 @@ using System.Linq; using Vim.BFastLib; -using Vim.G3dNext; +using Vim.G3d; namespace Vim.Format.VimxLib { diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs index 48a652d2..ce5a7cbb 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimScene.cs @@ -7,7 +7,7 @@ using Vim.Format; using Vim.Format.Geometry; using Vim.Format.ObjectModel; -using Vim.G3dNext; +using Vim.G3d; using Vim.Math3d; using Vim.Util; using IVimSceneProgress = System.IProgress<(string, double)>; diff --git a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs index 9e7c5425..488f1adb 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/VimSceneNode.cs @@ -3,7 +3,7 @@ using System.Linq; using Vim.Format.Geometry; using Vim.Format.ObjectModel; -using Vim.G3dNext; +using Vim.G3d; using Vim.Math3d; namespace Vim @@ -26,7 +26,7 @@ public VimSceneNode(VimScene scene, int nodeIndex, int geometryIndex, Matrix4x4 public Matrix4x4 Transform { get; } public bool HideByDefault - => Scene.Document.GeometryNext.InstanceHasFlag(NodeIndex, G3dNext.InstanceFlags.Hidden); + => Scene.Document.GeometryNext.InstanceHasFlag(NodeIndex, InstanceFlags.Hidden); public int VimIndex { get; } = -1; public int NodeIndex { get; } = -1; diff --git a/src/cs/vim/Vim.Format/Vim.Format.csproj b/src/cs/vim/Vim.Format/Vim.Format.csproj index 5f433ac3..db3e19f8 100644 --- a/src/cs/vim/Vim.Format/Vim.Format.csproj +++ b/src/cs/vim/Vim.Format/Vim.Format.csproj @@ -33,7 +33,6 @@ true true - From faab3f8d732154fe65458c31336f608a4a79ce86 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 17 Apr 2024 09:00:59 -0400 Subject: [PATCH 086/104] g3dnext -> g3d --- src/cs/g3d/Vim.G3d.Tests/G3dTestUtils.cs | 2 +- src/cs/g3d/Vim.G3d.Tests/G3dTests.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cs/g3d/Vim.G3d.Tests/G3dTestUtils.cs b/src/cs/g3d/Vim.G3d.Tests/G3dTestUtils.cs index d179edd9..9bd3b033 100644 --- a/src/cs/g3d/Vim.G3d.Tests/G3dTestUtils.cs +++ b/src/cs/g3d/Vim.G3d.Tests/G3dTestUtils.cs @@ -2,7 +2,7 @@ namespace Vim.G3d.Tests { - public static class G3dNextTestUtils + public static class G3dTestUtils { public static G3dVim CreateTestG3d() { diff --git a/src/cs/g3d/Vim.G3d.Tests/G3dTests.cs b/src/cs/g3d/Vim.G3d.Tests/G3dTests.cs index 1539c1f1..c23b45e0 100644 --- a/src/cs/g3d/Vim.G3d.Tests/G3dTests.cs +++ b/src/cs/g3d/Vim.G3d.Tests/G3dTests.cs @@ -6,7 +6,7 @@ namespace Vim.G3d.Tests { [TestFixture] - public static class VimG3dNextTests + public static class VimG3dTests { [Test] public static void Can_Read_G3d_From_Vim() @@ -23,7 +23,7 @@ public static void Can_Ignore_Extra_Attributes() // We create a g3dMaterial from the bytes of a g3dVim // Shows that extra attributes are ignored as they should. - var g3d = G3dNextTestUtils.CreateTestG3d(); + var g3d = G3dTestUtils.CreateTestG3d(); var g3dMats = new G3dMaterials(g3d.ToBFast()); Assert.IsNotNull(g3dMats); @@ -35,7 +35,7 @@ public static void Can_Ignore_Extra_Attributes() [Test] public static void Can_Write_And_Read() { - var expected = G3dNextTestUtils.CreateTestG3d(); + var expected = G3dTestUtils.CreateTestG3d(); var g3d = new G3dVim(expected.ToBFast()); Assert.IsTrue(g3d.Equals(expected)); } @@ -45,7 +45,7 @@ public static void Can_Write_And_Read() [Test] public static void Can_Merge_two_g3d() { - var g3d = G3dNextTestUtils.CreateTestG3d(); + var g3d = G3dTestUtils.CreateTestG3d(); var merged = g3d.Merge(g3d); var expected = new G3dVim( @@ -73,7 +73,7 @@ public static void Can_Merge_two_g3d() [Test] public static void Clone_IsEqual() { - var g3d = G3dNextTestUtils.CreateTestG3d(); + var g3d = G3dTestUtils.CreateTestG3d(); Assert.IsTrue(g3d.Equals(g3d.Clone())); } } From 9affe332523cd6e70696654d1482db6c795ab7bd Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 17 Apr 2024 10:43:30 -0400 Subject: [PATCH 087/104] extracting loading code --- .../Vim.Format/SceneBuilder/ILoadingStep.cs | 21 ++++++++++++++++ .../SceneBuilder/LoadingProgress.cs | 22 +++++++++++++++++ .../SceneBuilder/LoadingSequence.cs | 22 +++++++++++++++++ .../Vim.Format/SceneBuilder/LoadingStep.cs | 24 +++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 src/cs/vim/Vim.Format/SceneBuilder/ILoadingStep.cs create mode 100644 src/cs/vim/Vim.Format/SceneBuilder/LoadingProgress.cs create mode 100644 src/cs/vim/Vim.Format/SceneBuilder/LoadingSequence.cs create mode 100644 src/cs/vim/Vim.Format/SceneBuilder/LoadingStep.cs diff --git a/src/cs/vim/Vim.Format/SceneBuilder/ILoadingStep.cs b/src/cs/vim/Vim.Format/SceneBuilder/ILoadingStep.cs new file mode 100644 index 00000000..6fd58731 --- /dev/null +++ b/src/cs/vim/Vim.Format/SceneBuilder/ILoadingStep.cs @@ -0,0 +1,21 @@ +namespace Vim.Format.SceneBuilder +{ + using System; + + public class LoadingProgress: Progress<(string, double)>, ILoadingProgress + { + public LoadingProgress(Action<(string, double)> handler) : base(handler) + { + } + } + + public interface ILoadingProgress : IProgress<(string, double)> + { + } + + public interface ILoadingStep + { + void Run(ILoadingProgress progress); + float Effort { get; } + } +} diff --git a/src/cs/vim/Vim.Format/SceneBuilder/LoadingProgress.cs b/src/cs/vim/Vim.Format/SceneBuilder/LoadingProgress.cs new file mode 100644 index 00000000..f5847bd6 --- /dev/null +++ b/src/cs/vim/Vim.Format/SceneBuilder/LoadingProgress.cs @@ -0,0 +1,22 @@ +namespace Vim.Format.SceneBuilder +{ + public class CumulativeProgressDecorator : ILoadingProgress + { + private readonly double _total; + private double _current; + + private readonly ILoadingProgress _progress; + + private CumulativeProgressDecorator(ILoadingProgress progress, float total) + => (_progress, _total) = (progress, total); + + public static CumulativeProgressDecorator Decorate(ILoadingProgress logger, float total) + => logger != null ? new CumulativeProgressDecorator(logger, total) : null; + + public void Report((string, double) value) + { + _current += value.Item2; + _progress.Report((value.Item1, _current / _total)); + } + } +} diff --git a/src/cs/vim/Vim.Format/SceneBuilder/LoadingSequence.cs b/src/cs/vim/Vim.Format/SceneBuilder/LoadingSequence.cs new file mode 100644 index 00000000..d864c8f3 --- /dev/null +++ b/src/cs/vim/Vim.Format/SceneBuilder/LoadingSequence.cs @@ -0,0 +1,22 @@ +using System.Linq; + +namespace Vim.Format.SceneBuilder +{ + public class LoadingSequence : ILoadingStep + { + private readonly LoadingStep[] _steps; + public float Effort { get; } + + public LoadingSequence(params LoadingStep[] steps) + { + _steps = steps; + Effort = _steps.Sum(s => s.Effort); + } + + public void Run(ILoadingProgress progress) + { + foreach (var step in _steps) + step.Run(progress); + } + } +} diff --git a/src/cs/vim/Vim.Format/SceneBuilder/LoadingStep.cs b/src/cs/vim/Vim.Format/SceneBuilder/LoadingStep.cs new file mode 100644 index 00000000..d8bbe47d --- /dev/null +++ b/src/cs/vim/Vim.Format/SceneBuilder/LoadingStep.cs @@ -0,0 +1,24 @@ +using System; + +namespace Vim.Format.SceneBuilder +{ + public class LoadingStep : ILoadingStep + { + private readonly Action _action; + private readonly string _name; + public float Effort { get; } + + public LoadingStep(Action action, string name, float effort = 1f) + { + _action = action; + _name = name; + Effort = effort; + } + + public void Run(ILoadingProgress progress) + { + progress?.Report((_name, Effort)); + _action(); + } + } +} From c80823a5f131d5982c6d418d5fd00c62d07fc644 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 17 Apr 2024 10:48:12 -0400 Subject: [PATCH 088/104] ilookup -> dictionnary --- src/cs/vim/Vim.Format.Core/Document.cs | 12 +++++++----- src/cs/vim/Vim.Format.Core/EntityTable.cs | 12 ++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index 6532197f..b83ae7ee 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -1,4 +1,6 @@ -using Vim.BFastLib; +using System.Collections.Generic; +using System.Linq; +using Vim.BFastLib; using Vim.G3d; using Vim.Util; @@ -13,17 +15,17 @@ public Document(SerializableDocument document) Header = _Document.Header; GeometryNext = _Document.GeometryNext; StringTable = _Document.StringTable; - EntityTables = _Document.EntityTables.ToVimLookup( + EntityTables = _Document.EntityTables.ToDictionary( et => et.Name, et => et.ToEntityTable(this)); - Assets = _Document.Assets.ToVimLookup(et => et.Name, et => et); + Assets = _Document.Assets.ToDictionary(et => et.Name, et => et); } public string FileName => _Document.FileName; public SerializableDocument _Document { get; } public SerializableHeader Header { get; } - public ILookup EntityTables { get; } - public ILookup Assets { get; } + public Dictionary EntityTables { get; } + public Dictionary Assets { get; } public string[] StringTable { get; } public string GetString(int index) => StringTable.ElementAtOrDefault(index); public G3dVim GeometryNext { get; } diff --git a/src/cs/vim/Vim.Format.Core/EntityTable.cs b/src/cs/vim/Vim.Format.Core/EntityTable.cs index e4b317e4..edc40e26 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTable.cs @@ -14,9 +14,9 @@ public EntityTable(Document document, SerializableEntityTable entityTable) _EntityTable = entityTable; Name = _EntityTable.Name; - DataColumns = _EntityTable.DataColumns.ToVimLookup( c => c.Name, c => c); - IndexColumns = _EntityTable.IndexColumns.ToVimLookup(c => c.Name, c => c); - StringColumns = _EntityTable.StringColumns.ToVimLookup(c => c.Name, c => c); + DataColumns = _EntityTable.DataColumns.ToDictionary( c => c.Name, c => c); + IndexColumns = _EntityTable.IndexColumns.ToDictionary(c => c.Name, c => c); + StringColumns = _EntityTable.StringColumns.ToDictionary(c => c.Name, c => c); NumRows = Columns.FirstOrDefault()?.NumElements() ?? 0; Columns.ValidateColumnRowsAreAligned(); @@ -26,9 +26,9 @@ public EntityTable(Document document, SerializableEntityTable entityTable) public Document Document { get; } public string Name { get; } public int NumRows { get; } - public Vim.Util.ILookup DataColumns { get; } - public Vim.Util.ILookup> StringColumns { get; } - public Vim.Util.ILookup> IndexColumns { get; } + public Dictionary DataColumns { get; } + public Dictionary> StringColumns { get; } + public Dictionary> IndexColumns { get; } public IEnumerable Columns => DataColumns.Values .Concat(IndexColumns.Values.Select(x => (INamedBuffer)x)) From 1b6042d6a065337166090c8f20d57101d8e3a60a Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 17 Apr 2024 10:52:17 -0400 Subject: [PATCH 089/104] removed ilookup --- src/cs/util/Vim.Util/CollectionExtensions.cs | 10 --- src/cs/util/Vim.Util/ILookup.cs | 74 ------------------- .../vim/Vim.Format/ObjectModel/Validation.cs | 2 +- 3 files changed, 1 insertion(+), 85 deletions(-) delete mode 100644 src/cs/util/Vim.Util/ILookup.cs diff --git a/src/cs/util/Vim.Util/CollectionExtensions.cs b/src/cs/util/Vim.Util/CollectionExtensions.cs index 92404f98..7039b7de 100644 --- a/src/cs/util/Vim.Util/CollectionExtensions.cs +++ b/src/cs/util/Vim.Util/CollectionExtensions.cs @@ -7,16 +7,6 @@ namespace Vim.Util { public static class CollectionExtensions { - public static TValue GetOrDefault(this ILookup lookup, TKey key, TValue @default = default(TValue)) - => lookup.Contains(key) ? lookup[key] : @default; - - public static ILookup ToVimLookup(this IEnumerable input, Func keyFunc, Func valueFunc) - => input.ToDictionary(keyFunc, valueFunc).ToLookup(); - - public static ILookup ToVimLookup(this IEnumerable input, Func keyFunc) - => input.ToDictionary(keyFunc, x => x).ToLookup(); - - /// /// Returns the index of the first element matching the given item. /// diff --git a/src/cs/util/Vim.Util/ILookup.cs b/src/cs/util/Vim.Util/ILookup.cs deleted file mode 100644 index b1c8257f..00000000 --- a/src/cs/util/Vim.Util/ILookup.cs +++ /dev/null @@ -1,74 +0,0 @@ -// MIT License - Copyright 2019 (C) VIMaec, LLC. -// MIT License - Copyright 2018 (C) Ara 3D, Inc. -// This file is subject to the terms and conditions defined in -// file 'LICENSE.txt', which is part of this source code package. - -using System.Collections.Generic; -using System.Linq; - -namespace Vim.Util -{ - /// - /// Lookup table: mapping from a key to some value. - /// - public interface ILookup - { - IEnumerable Keys { get; } - IEnumerable Values { get; } - bool Contains(TKey key); - TValue this[TKey key] { get; } - } - - public class EmptyLookup : ILookup - { - public IEnumerable Keys => Enumerable.Empty(); - public IEnumerable Values => Enumerable.Empty(); - public bool Contains(TKey key) => false; - public TValue this[TKey key] => default; - } - - public class LookupFromDictionary : ILookup - { - public IDictionary Dictionary; - private TValue _default; - - public LookupFromDictionary(IDictionary d = null, TValue defaultValue = default) - { - Dictionary = d ?? new Dictionary(); - // TODO: sort? - _default = defaultValue; - } - - public IEnumerable Keys => Dictionary.Keys; - public IEnumerable Values => Dictionary.Values; - public TValue this[TKey key] => Contains(key) ? Dictionary[key] : _default; - public bool Contains(TKey key) => Dictionary.ContainsKey(key); - } - - public class LookupFromArray : ILookup - { - private TValue[] array; - - public LookupFromArray(TValue[] xs) - { - array = xs; - } - - public IEnumerable Keys => Enumerable.Range(0, array.Length); - public IEnumerable Values => array; - public TValue this[int key] => array[key]; - public bool Contains(int key) => key >= 0 && key <= array.Length; - } - - public static class LookupExtensions - { - public static ILookup ToLookup(this IDictionary d, TValue defaultValue = default) - => new LookupFromDictionary(d, defaultValue); - - public static TValue GetOrDefault(this ILookup lookup, TKey key) - => lookup.Contains(key) ? lookup[key] : default; - - public static IEnumerable GetValues(this ILookup lookup) - => lookup.Keys.Select(k => lookup[k]); - } -} diff --git a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs index fd795670..14d5d24c 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs @@ -143,7 +143,7 @@ public static void ValidateAssets(this DocumentModel dm) var assetEntities = dm.AssetList.ToArray(); foreach (var asset in assetEntities) { - if (!assetBuffers.Contains(asset.BufferName)) + if (!assetBuffers.ContainsKey(asset.BufferName)) throw new ObjectModelValidationException($"No matching asset buffer found for asset entity {asset.Index} with {nameof(asset.BufferName)} '{asset.BufferName}'"); } } From ac1a599c6739586d0052888e80277bd984d205cc Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 09:45:28 -0400 Subject: [PATCH 090/104] removed unused code --- .../ColumnExtensions.Buffer.cs | 12 ------ .../ColumnExtensions.Reflection.cs | 3 -- .../vim/Vim.Format.Core/ColumnExtensions.cs | 3 -- .../DocumentBuilderExtensions.cs | 7 ---- .../vim/Vim.Format.Core/DocumentExtensions.cs | 37 +------------------ 5 files changed, 1 insertion(+), 61 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs index e1246fe2..4522b7d0 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs @@ -183,18 +183,6 @@ public static List> ConcatIntColumns(this IReadOnlyList thisColumnList.ConcatColumns(otherColumnList, (a, b) => new NamedBuffer(a.GetTypedData().Concat(b.GetTypedData()).ToArray(), a.Name)); - /// - /// Returns a concatenated SerializableEntityTable based on the column names of thisTable. - /// - public static SerializableEntityTable Concat(this SerializableEntityTable thisTable, SerializableEntityTable otherTable) - => new SerializableEntityTable - { - Name = thisTable.Name, - IndexColumns = thisTable.IndexColumns.ConcatIntColumns(otherTable.IndexColumns), - StringColumns = thisTable.StringColumns.ConcatIntColumns(otherTable.StringColumns), - DataColumns = thisTable.DataColumns.ConcatDataColumns(otherTable.DataColumns), - }.ValidateColumnRowsAreAligned(); - public static T[] GetColumnValues(this INamedBuffer nb) where T : unmanaged => nb.AsArray(); diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Reflection.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Reflection.cs index d7cedece..81f3efe3 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Reflection.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Reflection.cs @@ -60,9 +60,6 @@ public static string GetSerializedValueColumnName(this FieldInfo fieldInfo) return $"{typePrefix}{fieldInfo.GetSerializedValueName()}"; } - public static string GetSerializedIndexName(this FieldInfo fieldInfo) - => fieldInfo.Name.Trim('_'); - public static bool IsRelationType(this Type t) => t.Name == "Relation`1"; diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.cs index 0d826c14..531e3619 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.cs @@ -19,9 +19,6 @@ public static readonly IReadOnlyCollection AllColumnInfos new ColumnInfo(ColumnType.DataColumn, VimConstants.FloatColumnNameTypePrefix, typeof(float)), }; - public static readonly IReadOnlyDictionary TypePrefixToColumnTypeMap - = AllColumnInfos.ToDictionary(t => t.TypePrefix, t => t.ColumnType); - public static readonly IReadOnlyDictionary DataColumnTypeToPrefixMap = AllColumnInfos .Where(t => t.ColumnType == ColumnType.DataColumn) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index c5b4e636..da62d335 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -9,13 +9,6 @@ namespace Vim.Format { public static class DocumentBuilderExtensions { - public static SubdividedMesh ToDocumentBuilderSubdividedMesh(this VimMesh m) - => new SubdividedMesh( - m.indices, - m.vertices, - m.submeshIndexOffsets, - m.submeshMaterials); - public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, EntityTable table, List nodeIndexRemapping = null) { var name = table.Name; diff --git a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs index 366cf46b..dfa6a02d 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs @@ -15,30 +15,6 @@ public static Document ToDocument(this SerializableDocument document) public static EntityTable ToEntityTable(this SerializableEntityTable entityTable, Document document) => new EntityTable(document, entityTable); - public static IEnumerable GetColumnNames(this EntityTable table) - => table.Columns.Select(c => c.Name); - - public static void ValidateRelations(this Document doc) - { - foreach (var et in doc.EntityTables.Values) - { - foreach (var ic in et.IndexColumns.Values) - { - var relatedTable = ic.GetRelatedTable(doc); - var maxValue = relatedTable.NumRows; - var data = ic.GetTypedData(); - for (var i = 0; i < data.Length; ++i) - { - var v = data[i]; - if (v < -1 || v > maxValue) - { - throw new Exception($"Invalid relation {v} out of range of -1 to {maxValue}"); - } - } - } - } - } - public static readonly Regex IndexColumnNameComponentsRegex = new Regex(@"(\w+:)((?:\w|\.)+):(.+)"); public class IndexColumnNameComponents @@ -65,12 +41,6 @@ public static IndexColumnNameComponents SplitIndexColumnName(string name) public static string GetRelatedTableNameFromColumnName(string name) => SplitIndexColumnName(name).TableName; - public static string GetFieldNameFromColumnName(string name) - => SplitIndexColumnName(name).FieldName; - - public static string GetFieldName(this INamedBuffer ic) - => GetFieldNameFromColumnName(ic.Name); - public static string GetRelatedTableName(this INamedBuffer ic) => GetRelatedTableNameFromColumnName(ic.Name); @@ -79,11 +49,6 @@ public static EntityTable GetRelatedTable(this INamedBuffer ic, Document do public static EntityTable GetTable(this Document doc, string name) => doc.EntityTables.GetOrDefault(name); - - public static SerializableDocument SetFileName(this SerializableDocument doc, string fileName) - { - doc.FileName = fileName; - return doc; - } + } } From 90858edbeddfefd84ed44fa683a02f7df69ea327 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 10:29:04 -0400 Subject: [PATCH 091/104] removed uneeded extender --- src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs index 4522b7d0..333323fd 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs @@ -8,9 +8,6 @@ namespace Vim.Format { public static partial class ColumnExtensions { - public static IEnumerable GetAllColumns(this SerializableEntityTable et) - => et.DataColumns.Concat(et.IndexColumns).Concat(et.StringColumns).ToList(); - public static void ValidateColumnRowsAreAligned(this IEnumerable columns) { var numRows = columns.FirstOrDefault()?.NumElements() ?? 0; @@ -28,7 +25,7 @@ public static void ValidateColumnRowsAreAligned(this IEnumerable c public static SerializableEntityTable ValidateColumnRowsAreAligned(this SerializableEntityTable et) { - et.GetAllColumns().ValidateColumnRowsAreAligned(); + et.AllColumns.ValidateColumnRowsAreAligned(); return et; } From fb616d8dc15d1cab8ba10d63c1235d01a75bc4d0 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 10:29:22 -0400 Subject: [PATCH 092/104] added dictionaries --- .../SerializableEntityTable.cs | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs index 4b86268c..79814de4 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs @@ -22,16 +22,37 @@ public class SerializableEntityTable /// Relation to another entity table. For example surface to element. /// public List> IndexColumns = new List>(); + public Dictionary> IndexColumnsMap = new Dictionary>(); /// /// Data encoded as strings in the global string table /// public List> StringColumns = new List>(); + public Dictionary> StringColumnsMap = new Dictionary>(); /// /// Numeric data encoded as byte, int, float, or doubles /// public List DataColumns = new List(); + public Dictionary DataColumnsMap = new Dictionary(); + + public void AddDataColumn(INamedBuffer buffer) + { + DataColumns.Add(buffer); + DataColumnsMap.Add(buffer.Name, buffer); + } + + public void AddIndexColumn(NamedBuffer buffer) + { + IndexColumns.Add(buffer); + IndexColumnsMap.Add(buffer.Name, buffer); + } + + public void AddStringColumn(NamedBuffer buffer) + { + StringColumns.Add(buffer); + StringColumnsMap.Add(buffer.Name, buffer); + } public IEnumerable ColumnNames => IndexColumns.Select(c => c.Name) @@ -70,43 +91,43 @@ bool schemaOnly { //TODO: replace named buffer with arrays var col = schemaOnly ? new int[0] : bfast.GetArray(entry); - et.IndexColumns.Add(col.ToNamedBuffer(entry)); + et.AddIndexColumn(col.ToNamedBuffer(entry)); break; } case VimConstants.StringColumnNameTypePrefix: { var col = schemaOnly ? new int[0] : bfast.GetArray(entry); - et.StringColumns.Add(col.ToNamedBuffer(entry)); + et.AddStringColumn(col.ToNamedBuffer(entry)); break; } case VimConstants.IntColumnNameTypePrefix: { var col = schemaOnly ? new int[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); + et.AddDataColumn(col.ToNamedBuffer(entry)); break; } case VimConstants.LongColumnNameTypePrefix: { var col = schemaOnly ? new long[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); + et.AddDataColumn(col.ToNamedBuffer(entry)); break; } case VimConstants.DoubleColumnNameTypePrefix: { var col = schemaOnly ? new double[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); + et.AddDataColumn(col.ToNamedBuffer(entry)); break; } case VimConstants.FloatColumnNameTypePrefix: { var col = schemaOnly ? new float[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); + et.AddDataColumn(col.ToNamedBuffer(entry)); break; } case VimConstants.ByteColumnNameTypePrefix: { var col = schemaOnly ? new byte[0] : bfast.GetArray(entry); - et.DataColumns.Add(col.ToNamedBuffer(entry)); + et.AddDataColumn(col.ToNamedBuffer(entry)); break; } // For flexibility, we ignore the columns which do not contain a recognized prefix. From a60e207a95abde7e977f71b9bf8db02a76c5e0b0 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 10:50:28 -0400 Subject: [PATCH 093/104] replaced extenders with method --- .../Vim.BFast/Buffers/BufferExtensions.cs | 10 ++++++++ .../ColumnExtensions.Buffer.cs | 23 ------------------- .../SerializableEntityTable.cs | 7 ++++++ 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/cs/bfast/Vim.BFast/Buffers/BufferExtensions.cs b/src/cs/bfast/Vim.BFast/Buffers/BufferExtensions.cs index 6260c22b..91fd57c4 100644 --- a/src/cs/bfast/Vim.BFast/Buffers/BufferExtensions.cs +++ b/src/cs/bfast/Vim.BFast/Buffers/BufferExtensions.cs @@ -86,5 +86,15 @@ public static Buffer ReadBuffer(this Stream stream, int numBytes) public static void Write(this Stream stream, IBuffer buffer) => buffer.Write(stream); + + public static NamedBuffer Fill(this NamedBuffer buffer, T value) where T : unmanaged + { + var array = new T[buffer.Data.Length]; + for (var i = 0; i < array.Length; i++) + { + array[i] = value; + } + return array.ToNamedBuffer(buffer.Name); + } } } diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs index 333323fd..8c8becd4 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs @@ -183,29 +183,6 @@ public static List> ConcatIntColumns(this IReadOnlyList(this INamedBuffer nb) where T : unmanaged => nb.AsArray(); - /// - /// Returns a new collection of index columns in which the designated column names have repeated values of VimConstants.NoEntityRelation. - /// - public static IEnumerable> NoneIndexColumnRelations( - this IEnumerable> indexColumns, - params string[] indexColumnNames) - => indexColumns.Select(ic => indexColumnNames.Contains(ic.Name) - ? new NamedBuffer(Enumerable.Repeat(VimConstants.NoEntityRelation, ic.Data.Length).ToArray(), ic.Name) - : ic); - - /// - /// Replaces the designated index columns of the entity table with repeated values of VimConstants.NoEntityRelation. - /// - public static void NoneIndexColumnRelations( - this SerializableEntityTable et, - params string[] indexColumnNames) - { - if (et == null) - return; - - et.IndexColumns = et.IndexColumns.NoneIndexColumnRelations(indexColumnNames).ToList(); - } - /// /// Replaces the entity table contained in the document with the given entity table if it is not null. /// diff --git a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs index 79814de4..7983a221 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs @@ -36,6 +36,13 @@ public class SerializableEntityTable public List DataColumns = new List(); public Dictionary DataColumnsMap = new Dictionary(); + public void BreakIndices(params string[] columns) + { + var set = new HashSet(columns); + IndexColumns = IndexColumns.Select(c => set.Contains(c.Name) ? c.Fill(VimConstants.NoEntityRelation) : c).ToList(); + IndexColumnsMap = IndexColumns.ToDictionary(c => c.Name, c => c); + } + public void AddDataColumn(INamedBuffer buffer) { DataColumns.Add(buffer); From a589f832e0f941724bc073831efa7ef60eef1976 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 10:50:28 -0400 Subject: [PATCH 094/104] replaced extenders with method --- .../Vim.BFast/Buffers/BufferExtensions.cs | 10 ++++++++ .../ColumnExtensions.Buffer.cs | 23 ------------------- .../SerializableEntityTable.cs | 7 ++++++ 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/cs/bfast/Vim.BFast/Buffers/BufferExtensions.cs b/src/cs/bfast/Vim.BFast/Buffers/BufferExtensions.cs index 6260c22b..91fd57c4 100644 --- a/src/cs/bfast/Vim.BFast/Buffers/BufferExtensions.cs +++ b/src/cs/bfast/Vim.BFast/Buffers/BufferExtensions.cs @@ -86,5 +86,15 @@ public static Buffer ReadBuffer(this Stream stream, int numBytes) public static void Write(this Stream stream, IBuffer buffer) => buffer.Write(stream); + + public static NamedBuffer Fill(this NamedBuffer buffer, T value) where T : unmanaged + { + var array = new T[buffer.Data.Length]; + for (var i = 0; i < array.Length; i++) + { + array[i] = value; + } + return array.ToNamedBuffer(buffer.Name); + } } } diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs index 333323fd..8c8becd4 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs @@ -183,29 +183,6 @@ public static List> ConcatIntColumns(this IReadOnlyList(this INamedBuffer nb) where T : unmanaged => nb.AsArray(); - /// - /// Returns a new collection of index columns in which the designated column names have repeated values of VimConstants.NoEntityRelation. - /// - public static IEnumerable> NoneIndexColumnRelations( - this IEnumerable> indexColumns, - params string[] indexColumnNames) - => indexColumns.Select(ic => indexColumnNames.Contains(ic.Name) - ? new NamedBuffer(Enumerable.Repeat(VimConstants.NoEntityRelation, ic.Data.Length).ToArray(), ic.Name) - : ic); - - /// - /// Replaces the designated index columns of the entity table with repeated values of VimConstants.NoEntityRelation. - /// - public static void NoneIndexColumnRelations( - this SerializableEntityTable et, - params string[] indexColumnNames) - { - if (et == null) - return; - - et.IndexColumns = et.IndexColumns.NoneIndexColumnRelations(indexColumnNames).ToList(); - } - /// /// Replaces the entity table contained in the document with the given entity table if it is not null. /// diff --git a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs index 79814de4..7983a221 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs @@ -36,6 +36,13 @@ public class SerializableEntityTable public List DataColumns = new List(); public Dictionary DataColumnsMap = new Dictionary(); + public void BreakIndices(params string[] columns) + { + var set = new HashSet(columns); + IndexColumns = IndexColumns.Select(c => set.Contains(c.Name) ? c.Fill(VimConstants.NoEntityRelation) : c).ToList(); + IndexColumnsMap = IndexColumns.ToDictionary(c => c.Name, c => c); + } + public void AddDataColumn(INamedBuffer buffer) { DataColumns.Add(buffer); From 53db27754d043f269d6d0f97834ccd8aa439dbc4 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 11:42:32 -0400 Subject: [PATCH 095/104] use tobyte instead --- src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs index 7983a221..d4211270 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableEntityTable.cs @@ -36,6 +36,7 @@ public class SerializableEntityTable public List DataColumns = new List(); public Dictionary DataColumnsMap = new Dictionary(); + public void BreakIndices(params string[] columns) { var set = new HashSet(columns); @@ -149,7 +150,7 @@ public BFast ToBFast() var bfast = new BFast(); foreach (var col in AllColumns) { - bfast.SetArray(col.Name, col.AsArray()); + bfast.SetArray(col.Name, col.ToBytes()); } return bfast; } From 8f67e67d35a9cdb4c2962f7386a8aab0fa1554c1 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 11:43:05 -0400 Subject: [PATCH 096/104] extension to method --- .../DocumentBuilderExtensions.cs | 28 +------------------ .../vim/Vim.Format.Core/EntityTableBuilder.cs | 27 ++++++++++++++++++ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index da62d335..82bd81f3 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -49,32 +49,6 @@ public static DocumentBuilder CopyTablesFrom(this DocumentBuilder db, Document d return db; } - public static SerializableEntityTable ToSerializableEntityTable(this EntityTableBuilder tb, - IReadOnlyDictionary stringLookup) - { - var table = new SerializableEntityTable - { - // Set the table name - Name = tb.Name, - - // Convert the columns to named buffers - IndexColumns = tb.IndexColumns - .Select(kv => kv.Value.ToNamedBuffer(kv.Key)) - .ToList(), - DataColumns = tb.DataColumns - .Select(kv => kv.Value.ToNamedBuffer(kv.Key) as INamedBuffer) - .ToList(), - StringColumns = tb.StringColumns - .Select(kv => kv.Value - .Select(s => stringLookup[s ?? string.Empty]) - .ToArray() - .ToNamedBuffer(kv.Key)) - .ToList(), - }; - - table.ValidateColumnRowsAreAligned(); - - return table; - } + } } diff --git a/src/cs/vim/Vim.Format.Core/EntityTableBuilder.cs b/src/cs/vim/Vim.Format.Core/EntityTableBuilder.cs index 08582b99..2205500a 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTableBuilder.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTableBuilder.cs @@ -97,6 +97,33 @@ public IEnumerable GetAllStrings() => StringColumns.Values.SelectMany(sc => sc) .Where(x => x != null); + public SerializableEntityTable ToSerializableEntityTable(IReadOnlyDictionary stringLookup) + { + var table = new SerializableEntityTable + { + // Set the table name + Name = Name, + + // Convert the columns to named buffers + IndexColumns = IndexColumns + .Select(kv => kv.Value.ToNamedBuffer(kv.Key)) + .ToList(), + DataColumns = DataColumns + .Select(kv => kv.Value.ToNamedBuffer(kv.Key) as INamedBuffer) + .ToList(), + StringColumns = StringColumns + .Select(kv => kv.Value + .Select(s => stringLookup[s ?? string.Empty]) + .ToArray() + .ToNamedBuffer(kv.Key)) + .ToList(), + }; + + table.ValidateColumnRowsAreAligned(); + + return table; + } + public void Clear() { NumRows = 0; From 9c41872ea1d2a56aecf18fd927517c68054fe1cb Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 15:04:49 -0400 Subject: [PATCH 097/104] removing _Document usages --- src/cs/vim/Vim.Format.Core/Document.cs | 2 ++ src/cs/vim/Vim.Format.Tests/FormatTests.cs | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index b83ae7ee..9911081b 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -21,6 +21,8 @@ public Document(SerializableDocument document) Assets = _Document.Assets.ToDictionary(et => et.Name, et => et); } + public VimSchema GetSchema() => VimSchema.Create(_Document); + public string FileName => _Document.FileName; public SerializableDocument _Document { get; } public SerializableHeader Header { get; } diff --git a/src/cs/vim/Vim.Format.Tests/FormatTests.cs b/src/cs/vim/Vim.Format.Tests/FormatTests.cs index 2ea981a3..c529a421 100644 --- a/src/cs/vim/Vim.Format.Tests/FormatTests.cs +++ b/src/cs/vim/Vim.Format.Tests/FormatTests.cs @@ -120,8 +120,8 @@ public static void AssertIsSupersetOf(EntityTable et1, EntityTable et2) /// public static void AssertIsSuperSetOf(Document d1, Document d2, bool skipGeometryAndNodes = true) { - var schema1 = VimSchema.Create(d1._Document); - var schema2 = VimSchema.Create(d2._Document); + var schema1 = d1.GetSchema(); + var schema2 = d2.GetSchema(); Assert.IsTrue(VimSchema.IsSuperSetOf(schema1, schema2)); var etKeys1 = d1.EntityTables.Keys; @@ -143,8 +143,8 @@ public static void AssertIsSuperSetOf(Document d1, Document d2, bool skipGeometr public static void AssertEquals(Document d1, Document d2, bool skipGeometryAndNodes = false) { - var schema1 = VimSchema.Create(d1._Document); - var schema2 = VimSchema.Create(d2._Document); + var schema1 = d1.GetSchema(); + var schema2 = d2.GetSchema(); Assert.IsTrue(VimSchema.IsSame(schema1, schema2)); var entityTables1 = d1.EntityTables.Keys.OrderBy(n => n).ToArray(); From d96d4fd9fc158f914fe670c1902a684956c588d0 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 15:47:33 -0400 Subject: [PATCH 098/104] removing direct reference to EntityTables --- src/cs/vim/Vim.Format.Core/Document.cs | 8 +++++++- .../Vim.Format.Core/DocumentBuilderExtensions.cs | 2 +- src/cs/vim/Vim.Format.Core/DocumentExtensions.cs | 4 ---- src/cs/vim/Vim.Format.Core/Geometry/Validation.cs | 4 ++-- src/cs/vim/Vim.Format.Core/Validation.cs | 4 ++-- src/cs/vim/Vim.Format.Core/VimSchema.cs | 2 +- src/cs/vim/Vim.Format.Tests/FormatTests.cs | 14 +++++++------- src/cs/vim/Vim.Format/SceneBuilder/Validation.cs | 2 +- 8 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index 9911081b..aca47fc4 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections; +using System.Collections.Generic; using System.Linq; using Vim.BFastLib; using Vim.G3d; @@ -21,6 +22,11 @@ public Document(SerializableDocument document) Assets = _Document.Assets.ToDictionary(et => et.Name, et => et); } + public EntityTable GetTable(string name) + => EntityTables.GetOrDefault(name); + + public IEnumerable TableNames => _Document.EntityTables.Select(e => e.Name); + public IEnumerable Tables => EntityTables.Values; public VimSchema GetSchema() => VimSchema.Create(_Document); public string FileName => _Document.FileName; diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index 82bd81f3..c568b4fe 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -35,7 +35,7 @@ public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, Entity public static DocumentBuilder CopyTablesFrom(this DocumentBuilder db, Document doc, List nodeIndexRemapping = null) { - foreach (var table in doc.EntityTables.Values) + foreach (var table in doc.Tables) { var name = table.Name; diff --git a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs index dfa6a02d..26da6f7a 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentExtensions.cs @@ -46,9 +46,5 @@ public static string GetRelatedTableName(this INamedBuffer ic) public static EntityTable GetRelatedTable(this INamedBuffer ic, Document doc) => doc.GetTable(ic.GetRelatedTableName()); - - public static EntityTable GetTable(this Document doc, string name) - => doc.EntityTables.GetOrDefault(name); - } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index 897ba16d..a9a368ab 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -7,7 +7,7 @@ public static class Validation { public static void ValidateTableRows(this Document doc) { - foreach (var et in doc.EntityTables.Values) + foreach (var et in doc.Tables) { foreach (var c in et.IndexColumns.Values) { @@ -31,7 +31,7 @@ public static void ValidateTableRows(this Document doc) public static void ValidateIndexColumns(this Document doc) { - foreach (var et in doc.EntityTables.Values) + foreach (var et in doc.Tables) { foreach (var ic in et.IndexColumns.Values) { diff --git a/src/cs/vim/Vim.Format.Core/Validation.cs b/src/cs/vim/Vim.Format.Core/Validation.cs index 6275bf17..ca81d04f 100644 --- a/src/cs/vim/Vim.Format.Core/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Validation.cs @@ -7,7 +7,7 @@ public static class Validation { public static void ValidateTableRows(this Document doc) { - foreach (var et in doc.EntityTables.Values) + foreach (var et in doc.Tables) { foreach (var c in et.IndexColumns.Values) { @@ -31,7 +31,7 @@ public static void ValidateTableRows(this Document doc) public static void ValidateIndexColumns(this Document doc) { - foreach (var et in doc.EntityTables.Values) + foreach (var et in doc.Tables) { foreach (var ic in et.IndexColumns.Values) { diff --git a/src/cs/vim/Vim.Format.Core/VimSchema.cs b/src/cs/vim/Vim.Format.Core/VimSchema.cs index cc262a08..453747b2 100644 --- a/src/cs/vim/Vim.Format.Core/VimSchema.cs +++ b/src/cs/vim/Vim.Format.Core/VimSchema.cs @@ -52,7 +52,7 @@ public static VimSchema Create(SerializableDocument doc) private static VimSchema Create(Document doc) { var vimSchema = new VimSchema(doc.Header); - foreach (var entityTable in doc.EntityTables.Values) + foreach (var entityTable in doc.Tables) { var ets = vimSchema.AddEntityTableSchema(entityTable.Name); diff --git a/src/cs/vim/Vim.Format.Tests/FormatTests.cs b/src/cs/vim/Vim.Format.Tests/FormatTests.cs index c529a421..14a94be6 100644 --- a/src/cs/vim/Vim.Format.Tests/FormatTests.cs +++ b/src/cs/vim/Vim.Format.Tests/FormatTests.cs @@ -124,8 +124,8 @@ public static void AssertIsSuperSetOf(Document d1, Document d2, bool skipGeometr var schema2 = d2.GetSchema(); Assert.IsTrue(VimSchema.IsSuperSetOf(schema1, schema2)); - var etKeys1 = d1.EntityTables.Keys; - var etKeys2 = d2.EntityTables.Keys; + var etKeys1 = d1.TableNames; + var etKeys2 = d2.TableNames; Assert.IsTrue(IsSupersetOf(etKeys1, etKeys2)); foreach (var key in etKeys2) @@ -133,8 +133,8 @@ public static void AssertIsSuperSetOf(Document d1, Document d2, bool skipGeometr if (skipGeometryAndNodes && key.ToLowerInvariant().Contains("geometry")) continue; - var et2 = d2.EntityTables[key]; - var et1 = d1.EntityTables.GetOrDefault(key); + var et2 = d2.GetTable(key); + var et1 = d1.GetTable(key); if (et1 == null) Assert.Fail($"No matching entity table found: {key}"); AssertIsSupersetOf(et1, et2); @@ -147,15 +147,15 @@ public static void AssertEquals(Document d1, Document d2, bool skipGeometryAndNo var schema2 = d2.GetSchema(); Assert.IsTrue(VimSchema.IsSame(schema1, schema2)); - var entityTables1 = d1.EntityTables.Keys.OrderBy(n => n).ToArray(); - var entityTables2 = d2.EntityTables.Keys.OrderBy(n => n).ToArray(); + var entityTables1 = d1.TableNames.OrderBy(n => n).ToArray(); + var entityTables2 = d2.TableNames.OrderBy(n => n).ToArray(); Assert.AreEqual(entityTables1, entityTables2); foreach (var k in entityTables1) { if (skipGeometryAndNodes && k.ToLowerInvariant().Contains("geometry")) continue; - AssertEquals(d1.EntityTables[k], d2.EntityTables[k]); + AssertEquals(d1.GetTable(k), d2.GetTable(k)); } } } diff --git a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs index 8cc998e4..c817e6e4 100644 --- a/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs +++ b/src/cs/vim/Vim.Format/SceneBuilder/Validation.cs @@ -142,7 +142,7 @@ public static void ValidateEquality(this DocumentBuilder db, VimScene vim) // Test the entity tables. var tableNames = new HashSet(db.Tables.Values.Select(t => t.Name)); - foreach (var et in vim.Document.EntityTables.Keys) + foreach (var et in vim.Document.TableNames) { if (!tableNames.Contains(et)) throw new VimValidationException($"{nameof(DocumentBuilder)} does not contain table name {et} from {nameof(VimScene)}"); From 4618bd48e41ace9a963bd608d5ab7afb365ff064 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 15:58:13 -0400 Subject: [PATCH 099/104] table count --- src/cs/vim/Vim.Format.Core/Document.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index aca47fc4..75c1fa44 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -22,6 +22,8 @@ public Document(SerializableDocument document) Assets = _Document.Assets.ToDictionary(et => et.Name, et => et); } + public int TableCount => Tables.Count(); + public EntityTable GetTable(string name) => EntityTables.GetOrDefault(name); From 7cd1e6804494a38173b551bc19152af4830559fe Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 16:12:32 -0400 Subject: [PATCH 100/104] removed ref to Strings and introduced Bim object --- src/cs/vim/Vim.Format.Core/Document.cs | 42 +++++++++++++++++-- .../DocumentBuilderExtensions.cs | 2 +- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/Document.cs b/src/cs/vim/Vim.Format.Core/Document.cs index 75c1fa44..3ecd41c7 100644 --- a/src/cs/vim/Vim.Format.Core/Document.cs +++ b/src/cs/vim/Vim.Format.Core/Document.cs @@ -1,7 +1,9 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Xml.Linq; using Vim.BFastLib; +using Vim.Format; using Vim.G3d; using Vim.Util; @@ -16,19 +18,30 @@ public Document(SerializableDocument document) Header = _Document.Header; GeometryNext = _Document.GeometryNext; StringTable = _Document.StringTable; + EntityTables = _Document.EntityTables.ToDictionary( et => et.Name, et => et.ToEntityTable(this)); + + + Assets = _Document.Assets.ToDictionary(et => et.Name, et => et); + + var tables = document.EntityTables.ToDictionary( + et => et.Name, + et => et.ToEntityTable(this)); + _bim = new Bim(tables, _Document.StringTable); } - public int TableCount => Tables.Count(); + Bim _bim; + + public int TableCount => _bim.TableCount; public EntityTable GetTable(string name) - => EntityTables.GetOrDefault(name); + => _bim.GetTable(name); - public IEnumerable TableNames => _Document.EntityTables.Select(e => e.Name); - public IEnumerable Tables => EntityTables.Values; + public IEnumerable TableNames => _bim.TableNames; + public IEnumerable Tables => _bim.Tables; public VimSchema GetSchema() => VimSchema.Create(_Document); public string FileName => _Document.FileName; @@ -41,3 +54,24 @@ public EntityTable GetTable(string name) public G3dVim GeometryNext { get; } } } + +public class Bim +{ + private string[] _strings; + private Dictionary _tables { get; } + + public Bim(Dictionary tables, string[] strings) + { + _tables = tables; + _strings = strings; + } + + public int TableCount => Tables.Count(); + + public EntityTable GetTable(string name) + => _tables.GetOrDefault(name); + + public IEnumerable Tables => _tables.Values; + public IEnumerable TableNames => Tables.Select(e => e.Name); + +} diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index c568b4fe..8f2fa5f4 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -26,7 +26,7 @@ public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, Entity foreach (var col in table.StringColumns.Values) { - var strings = col.GetTypedData().Select(i => table.Document.StringTable.ElementAtOrDefault(i, null)); + var strings = col.GetTypedData().Select(i => table.Document.GetString(i)); tb.AddStringColumn(col.Name, strings.ToArray().RemapData(nodeIndexRemapping)); } From e33d91cd7153d42e22c38f3fcb582303ae224f7e Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 16:54:54 -0400 Subject: [PATCH 101/104] private data columns --- .../DocumentBuilderExtensions.cs | 2 +- src/cs/vim/Vim.Format.Core/EntityTable.cs | 17 ++++++++++------- .../vim/Vim.Format.Core/Geometry/Validation.cs | 2 +- src/cs/vim/Vim.Format.Core/Validation.cs | 2 +- src/cs/vim/Vim.Format.Tests/FormatTests.cs | 4 ++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index 8f2fa5f4..eb12efdd 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -19,7 +19,7 @@ public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, Entity tb.AddIndexColumn(col.Name, col.GetTypedData().RemapData(nodeIndexRemapping)); } - foreach (var col in table.DataColumns.Values) + foreach (var col in table.AllDataColumns) { tb.AddDataColumn(col.Name, col.CopyDataColumn(nodeIndexRemapping)); } diff --git a/src/cs/vim/Vim.Format.Core/EntityTable.cs b/src/cs/vim/Vim.Format.Core/EntityTable.cs index edc40e26..2caa0d54 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTable.cs @@ -14,7 +14,7 @@ public EntityTable(Document document, SerializableEntityTable entityTable) _EntityTable = entityTable; Name = _EntityTable.Name; - DataColumns = _EntityTable.DataColumns.ToDictionary( c => c.Name, c => c); + _dataColumns = _EntityTable.DataColumns.ToDictionary( c => c.Name, c => c); IndexColumns = _EntityTable.IndexColumns.ToDictionary(c => c.Name, c => c); StringColumns = _EntityTable.StringColumns.ToDictionary(c => c.Name, c => c); NumRows = Columns.FirstOrDefault()?.NumElements() ?? 0; @@ -26,11 +26,14 @@ public EntityTable(Document document, SerializableEntityTable entityTable) public Document Document { get; } public string Name { get; } public int NumRows { get; } - public Dictionary DataColumns { get; } + private Dictionary _dataColumns { get; } public Dictionary> StringColumns { get; } public Dictionary> IndexColumns { get; } + + public IEnumerable AllDataColumns => _dataColumns.Values; + public IEnumerable Columns - => DataColumns.Values + => AllDataColumns .Concat(IndexColumns.Values.Select(x => (INamedBuffer)x)) .Concat(StringColumns.Values.Select(x => (INamedBuffer)x)); @@ -49,16 +52,16 @@ public T[] GetDataColumnValues(string columnName) where T : unmanaged if (!ColumnExtensions.DataColumnTypes.Contains(type)) throw new Exception($"{nameof(GetDataColumnValues)} error - unsupported data column type {type}"); - var namedBuffer = DataColumns.GetOrDefault(columnName); + var namedBuffer = _dataColumns.GetOrDefault(columnName); if (namedBuffer == null) return null; if (type == typeof(short)) - return namedBuffer.GetColumnValues().Select(i => (short)i) as T[]; + return namedBuffer.AsArray().Select(i => (short)i) as T[]; if (type == typeof(bool)) - return namedBuffer.GetColumnValues().Select(b => b != 0) as T[]; - return namedBuffer.GetColumnValues(); + return namedBuffer.AsArray().Select(b => b != 0) as T[]; + return namedBuffer.AsArray(); } } } diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index a9a368ab..adf5d7ca 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -15,7 +15,7 @@ public static void ValidateTableRows(this Document doc) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.DataColumns.Values) + foreach (var c in et.AllDataColumns) { if (c.NumElements() != et.NumRows) throw new Exception($"Expected array length {c.NumElements()} of column {c.Name} to be the same as number of rows {et.NumRows}"); diff --git a/src/cs/vim/Vim.Format.Core/Validation.cs b/src/cs/vim/Vim.Format.Core/Validation.cs index ca81d04f..f728ffeb 100644 --- a/src/cs/vim/Vim.Format.Core/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Validation.cs @@ -15,7 +15,7 @@ public static void ValidateTableRows(this Document doc) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.DataColumns.Values) + foreach (var c in et.AllDataColumns) { if (c.NumElements() != et.NumRows) throw new Exception($"Expected array length {c.NumElements()} of column {c.Name} to be the same as number of rows {et.NumRows}"); diff --git a/src/cs/vim/Vim.Format.Tests/FormatTests.cs b/src/cs/vim/Vim.Format.Tests/FormatTests.cs index 14a94be6..dd231ddf 100644 --- a/src/cs/vim/Vim.Format.Tests/FormatTests.cs +++ b/src/cs/vim/Vim.Format.Tests/FormatTests.cs @@ -57,7 +57,7 @@ public static void AssertEquals(SerializableDocument d1, SerializableDocument d2 public static void AssertEquals(EntityTable et1, EntityTable et2) { Assert.AreEqual(et1.Name, et2.Name); - Assert.AreEqual(et1.DataColumns.Keys.OrderBy(n => n).ToArray(), et2.DataColumns.Keys.OrderBy(n => n).ToArray()); + Assert.AreEqual(et1.AllDataColumns.OrderBy(n => n).ToArray(), et2.AllDataColumns.OrderBy(n => n).ToArray()); Assert.AreEqual(et1.IndexColumns.Keys.OrderBy(n => n).ToArray(), et2.IndexColumns.Keys.OrderBy(n => n).ToArray()); Assert.AreEqual(et1.StringColumns.Keys.OrderBy(n => n).ToArray(), et2.StringColumns.Keys.OrderBy(n => n).ToArray()); @@ -93,7 +93,7 @@ public static bool IsSupersetOf(IEnumerable a, IEnumerable b) public static void AssertIsSupersetOf(EntityTable et1, EntityTable et2) { Assert.AreEqual(et1.Name, et2.Name); - Assert.IsTrue(IsSupersetOf(et1.DataColumns.Keys, et2.DataColumns.Keys)); + Assert.IsTrue(IsSupersetOf(et1.AllDataColumns, et2.AllDataColumns)); Assert.IsTrue(IsSupersetOf(et1.IndexColumns.Keys, et2.IndexColumns.Keys)); Assert.IsTrue(IsSupersetOf(et1.StringColumns.Keys, et2.StringColumns.Keys)); From 829a87294ae68d8047249ae7b91b802b8a5ac076 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 16:57:53 -0400 Subject: [PATCH 102/104] added has method --- src/cs/vim/Vim.Format.Core/EntityTable.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cs/vim/Vim.Format.Core/EntityTable.cs b/src/cs/vim/Vim.Format.Core/EntityTable.cs index 2caa0d54..a85e5a25 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTable.cs @@ -30,6 +30,8 @@ public EntityTable(Document document, SerializableEntityTable entityTable) public Dictionary> StringColumns { get; } public Dictionary> IndexColumns { get; } + + public bool HasDataColumns(string name) => _dataColumns.ContainsKey(name); public IEnumerable AllDataColumns => _dataColumns.Values; public IEnumerable Columns @@ -61,6 +63,7 @@ public T[] GetDataColumnValues(string columnName) where T : unmanaged if (type == typeof(bool)) return namedBuffer.AsArray().Select(b => b != 0) as T[]; + return namedBuffer.AsArray(); } } From a1ad1d77b8ec21ef1ea59b1a483cd3e87d8c01a4 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 17:15:36 -0400 Subject: [PATCH 103/104] private strings --- .../DocumentBuilderExtensions.cs | 7 ++----- src/cs/vim/Vim.Format.Core/EntityTable.cs | 18 ++++++++++++------ .../vim/Vim.Format.Core/Geometry/Validation.cs | 4 ++-- src/cs/vim/Vim.Format.Core/Validation.cs | 4 ++-- src/cs/vim/Vim.Format.Tests/FormatTests.cs | 8 ++++---- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index eb12efdd..d3a01f9f 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -1,9 +1,6 @@ using System.Collections.Generic; using System.Linq; using Vim.BFastLib; -using Vim.Format.Geometry; -using Vim.Util; -using static Vim.Format.DocumentBuilder; namespace Vim.Format { @@ -19,12 +16,12 @@ public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, Entity tb.AddIndexColumn(col.Name, col.GetTypedData().RemapData(nodeIndexRemapping)); } - foreach (var col in table.AllDataColumns) + foreach (var col in table.DataColumns) { tb.AddDataColumn(col.Name, col.CopyDataColumn(nodeIndexRemapping)); } - foreach (var col in table.StringColumns.Values) + foreach (var col in table.StringColumns) { var strings = col.GetTypedData().Select(i => table.Document.GetString(i)); tb.AddStringColumn(col.Name, strings.ToArray().RemapData(nodeIndexRemapping)); diff --git a/src/cs/vim/Vim.Format.Core/EntityTable.cs b/src/cs/vim/Vim.Format.Core/EntityTable.cs index a85e5a25..13d0df05 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTable.cs @@ -16,7 +16,7 @@ public EntityTable(Document document, SerializableEntityTable entityTable) _dataColumns = _EntityTable.DataColumns.ToDictionary( c => c.Name, c => c); IndexColumns = _EntityTable.IndexColumns.ToDictionary(c => c.Name, c => c); - StringColumns = _EntityTable.StringColumns.ToDictionary(c => c.Name, c => c); + _stringColumns = _EntityTable.StringColumns.ToDictionary(c => c.Name, c => c); NumRows = Columns.FirstOrDefault()?.NumElements() ?? 0; Columns.ValidateColumnRowsAreAligned(); @@ -27,23 +27,29 @@ public EntityTable(Document document, SerializableEntityTable entityTable) public string Name { get; } public int NumRows { get; } private Dictionary _dataColumns { get; } - public Dictionary> StringColumns { get; } + private Dictionary> _stringColumns { get; } public Dictionary> IndexColumns { get; } public bool HasDataColumns(string name) => _dataColumns.ContainsKey(name); - public IEnumerable AllDataColumns => _dataColumns.Values; + public IEnumerable DataColumns => _dataColumns.Values; + public IEnumerable DataColumnNames => _dataColumns.Keys; + + public IEnumerable> StringColumns => _stringColumns.Values; + public bool HasStringColumn(string name) => _stringColumns.ContainsKey(name); + public NamedBuffer GetStringColumn(string name) => _stringColumns.GetOrDefault(name); + public IEnumerable StringColumnNames => _stringColumns.Keys; public IEnumerable Columns - => AllDataColumns + => DataColumns .Concat(IndexColumns.Values.Select(x => (INamedBuffer)x)) - .Concat(StringColumns.Values.Select(x => (INamedBuffer)x)); + .Concat(_stringColumns.Values.Select(x => (INamedBuffer)x)); public int[] GetIndexColumnValues(string columnName) => IndexColumns.GetOrDefault(columnName)?.GetColumnValues(); public string[] GetStringColumnValues(string columnName) - => StringColumns.GetOrDefault(columnName) + => _stringColumns.GetOrDefault(columnName) ?.GetColumnValues() ?.Select(Document.GetString).ToArray(); diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index adf5d7ca..3331681d 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -15,13 +15,13 @@ public static void ValidateTableRows(this Document doc) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.AllDataColumns) + foreach (var c in et.DataColumns) { if (c.NumElements() != et.NumRows) throw new Exception($"Expected array length {c.NumElements()} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.StringColumns.Values) + foreach (var c in et.StringColumns) { if (c.Array.Length != et.NumRows) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); diff --git a/src/cs/vim/Vim.Format.Core/Validation.cs b/src/cs/vim/Vim.Format.Core/Validation.cs index f728ffeb..47d15840 100644 --- a/src/cs/vim/Vim.Format.Core/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Validation.cs @@ -15,13 +15,13 @@ public static void ValidateTableRows(this Document doc) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.AllDataColumns) + foreach (var c in et.DataColumns) { if (c.NumElements() != et.NumRows) throw new Exception($"Expected array length {c.NumElements()} of column {c.Name} to be the same as number of rows {et.NumRows}"); } - foreach (var c in et.StringColumns.Values) + foreach (var c in et.StringColumns) { if (c.Array.Length != et.NumRows) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); diff --git a/src/cs/vim/Vim.Format.Tests/FormatTests.cs b/src/cs/vim/Vim.Format.Tests/FormatTests.cs index dd231ddf..9eb2b8e6 100644 --- a/src/cs/vim/Vim.Format.Tests/FormatTests.cs +++ b/src/cs/vim/Vim.Format.Tests/FormatTests.cs @@ -57,9 +57,9 @@ public static void AssertEquals(SerializableDocument d1, SerializableDocument d2 public static void AssertEquals(EntityTable et1, EntityTable et2) { Assert.AreEqual(et1.Name, et2.Name); - Assert.AreEqual(et1.AllDataColumns.OrderBy(n => n).ToArray(), et2.AllDataColumns.OrderBy(n => n).ToArray()); + Assert.AreEqual(et1.DataColumnNames.OrderBy(n => n).ToArray(), et2.DataColumnNames.OrderBy(n => n).ToArray()); Assert.AreEqual(et1.IndexColumns.Keys.OrderBy(n => n).ToArray(), et2.IndexColumns.Keys.OrderBy(n => n).ToArray()); - Assert.AreEqual(et1.StringColumns.Keys.OrderBy(n => n).ToArray(), et2.StringColumns.Keys.OrderBy(n => n).ToArray()); + Assert.AreEqual(et1.StringColumnNames.OrderBy(n => n).ToArray(), et2.StringColumnNames.OrderBy(n => n).ToArray()); var columns1 = et1.Columns.OrderBy(c => c.Name).ToArray(); var columns2 = et2.Columns.OrderBy(c => c.Name).ToArray(); @@ -93,9 +93,9 @@ public static bool IsSupersetOf(IEnumerable a, IEnumerable b) public static void AssertIsSupersetOf(EntityTable et1, EntityTable et2) { Assert.AreEqual(et1.Name, et2.Name); - Assert.IsTrue(IsSupersetOf(et1.AllDataColumns, et2.AllDataColumns)); + Assert.IsTrue(IsSupersetOf(et1.DataColumnNames, et2.DataColumnNames)); Assert.IsTrue(IsSupersetOf(et1.IndexColumns.Keys, et2.IndexColumns.Keys)); - Assert.IsTrue(IsSupersetOf(et1.StringColumns.Keys, et2.StringColumns.Keys)); + Assert.IsTrue(IsSupersetOf(et1.StringColumnNames, et2.StringColumnNames)); var columns1 = et1.Columns.ToArray(); var columns2 = et2.Columns.ToArray(); From 37773597c1b3981a68dbc21750257d1f5819b483 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Apr 2024 17:27:25 -0400 Subject: [PATCH 104/104] private index columns --- .../ColumnExtensions.Buffer.cs | 3 --- .../DocumentBuilderExtensions.cs | 2 +- src/cs/vim/Vim.Format.Core/EntityTable.cs | 21 +++++++++++++------ .../Vim.Format.Core/Geometry/Validation.cs | 4 ++-- src/cs/vim/Vim.Format.Core/Validation.cs | 4 ++-- src/cs/vim/Vim.Format.Tests/FormatTests.cs | 4 ++-- .../ObjectModel/ElementIndexMaps.cs | 4 ++-- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs index 8c8becd4..0d84b5d9 100644 --- a/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs +++ b/src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs @@ -180,9 +180,6 @@ public static List> ConcatIntColumns(this IReadOnlyList thisColumnList.ConcatColumns(otherColumnList, (a, b) => new NamedBuffer(a.GetTypedData().Concat(b.GetTypedData()).ToArray(), a.Name)); - public static T[] GetColumnValues(this INamedBuffer nb) where T : unmanaged - => nb.AsArray(); - /// /// Replaces the entity table contained in the document with the given entity table if it is not null. /// diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs index d3a01f9f..aa425c18 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs @@ -11,7 +11,7 @@ public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, Entity var name = table.Name; var tb = db.CreateTableBuilder(name); - foreach (var col in table.IndexColumns.Values) + foreach (var col in table.IndexColumns) { tb.AddIndexColumn(col.Name, col.GetTypedData().RemapData(nodeIndexRemapping)); } diff --git a/src/cs/vim/Vim.Format.Core/EntityTable.cs b/src/cs/vim/Vim.Format.Core/EntityTable.cs index 13d0df05..fe58b5b7 100644 --- a/src/cs/vim/Vim.Format.Core/EntityTable.cs +++ b/src/cs/vim/Vim.Format.Core/EntityTable.cs @@ -15,7 +15,7 @@ public EntityTable(Document document, SerializableEntityTable entityTable) Name = _EntityTable.Name; _dataColumns = _EntityTable.DataColumns.ToDictionary( c => c.Name, c => c); - IndexColumns = _EntityTable.IndexColumns.ToDictionary(c => c.Name, c => c); + _indexColumns = _EntityTable.IndexColumns.ToDictionary(c => c.Name, c => c); _stringColumns = _EntityTable.StringColumns.ToDictionary(c => c.Name, c => c); NumRows = Columns.FirstOrDefault()?.NumElements() ?? 0; @@ -28,29 +28,38 @@ public EntityTable(Document document, SerializableEntityTable entityTable) public int NumRows { get; } private Dictionary _dataColumns { get; } private Dictionary> _stringColumns { get; } - public Dictionary> IndexColumns { get; } + private Dictionary> _indexColumns { get; } + // Data public bool HasDataColumns(string name) => _dataColumns.ContainsKey(name); public IEnumerable DataColumns => _dataColumns.Values; public IEnumerable DataColumnNames => _dataColumns.Keys; + // Strings public IEnumerable> StringColumns => _stringColumns.Values; public bool HasStringColumn(string name) => _stringColumns.ContainsKey(name); public NamedBuffer GetStringColumn(string name) => _stringColumns.GetOrDefault(name); public IEnumerable StringColumnNames => _stringColumns.Keys; + //Data + public IEnumerable> IndexColumns => _indexColumns.Values; + public IEnumerable IndexColumnNames => _indexColumns.Keys; + public bool HasIndexColumn(string name) => _indexColumns.ContainsKey(name); + public NamedBuffer GetIndexColumn(string name) => _indexColumns.GetOrDefault(name); + + public IEnumerable Columns => DataColumns - .Concat(IndexColumns.Values.Select(x => (INamedBuffer)x)) - .Concat(_stringColumns.Values.Select(x => (INamedBuffer)x)); + .Concat(IndexColumns.Select(x => (INamedBuffer)x)) + .Concat(StringColumns.Select(x => (INamedBuffer)x)); public int[] GetIndexColumnValues(string columnName) - => IndexColumns.GetOrDefault(columnName)?.GetColumnValues(); + => GetIndexColumn(columnName)?.AsArray(); public string[] GetStringColumnValues(string columnName) => _stringColumns.GetOrDefault(columnName) - ?.GetColumnValues() + ?.AsArray() ?.Select(Document.GetString).ToArray(); public T[] GetDataColumnValues(string columnName) where T : unmanaged diff --git a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs index 3331681d..f61d3bbe 100644 --- a/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Geometry/Validation.cs @@ -9,7 +9,7 @@ public static void ValidateTableRows(this Document doc) { foreach (var et in doc.Tables) { - foreach (var c in et.IndexColumns.Values) + foreach (var c in et.IndexColumns) { if (c.Array.Length != et.NumRows) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); @@ -33,7 +33,7 @@ public static void ValidateIndexColumns(this Document doc) { foreach (var et in doc.Tables) { - foreach (var ic in et.IndexColumns.Values) + foreach (var ic in et.IndexColumns) { var table = ic.GetRelatedTable(doc); if (table == null) diff --git a/src/cs/vim/Vim.Format.Core/Validation.cs b/src/cs/vim/Vim.Format.Core/Validation.cs index 47d15840..d0d8b366 100644 --- a/src/cs/vim/Vim.Format.Core/Validation.cs +++ b/src/cs/vim/Vim.Format.Core/Validation.cs @@ -9,7 +9,7 @@ public static void ValidateTableRows(this Document doc) { foreach (var et in doc.Tables) { - foreach (var c in et.IndexColumns.Values) + foreach (var c in et.IndexColumns) { if (c.Array.Length != et.NumRows) throw new Exception($"Expected array length {c.Array.Length} of column {c.Name} to be the same as number of rows {et.NumRows}"); @@ -33,7 +33,7 @@ public static void ValidateIndexColumns(this Document doc) { foreach (var et in doc.Tables) { - foreach (var ic in et.IndexColumns.Values) + foreach (var ic in et.IndexColumns) { var table = ic.GetRelatedTable(doc); if (table == null) diff --git a/src/cs/vim/Vim.Format.Tests/FormatTests.cs b/src/cs/vim/Vim.Format.Tests/FormatTests.cs index 9eb2b8e6..00bffff6 100644 --- a/src/cs/vim/Vim.Format.Tests/FormatTests.cs +++ b/src/cs/vim/Vim.Format.Tests/FormatTests.cs @@ -58,7 +58,7 @@ public static void AssertEquals(EntityTable et1, EntityTable et2) { Assert.AreEqual(et1.Name, et2.Name); Assert.AreEqual(et1.DataColumnNames.OrderBy(n => n).ToArray(), et2.DataColumnNames.OrderBy(n => n).ToArray()); - Assert.AreEqual(et1.IndexColumns.Keys.OrderBy(n => n).ToArray(), et2.IndexColumns.Keys.OrderBy(n => n).ToArray()); + Assert.AreEqual(et1.IndexColumnNames.OrderBy(n => n).ToArray(), et2.IndexColumnNames.OrderBy(n => n).ToArray()); Assert.AreEqual(et1.StringColumnNames.OrderBy(n => n).ToArray(), et2.StringColumnNames.OrderBy(n => n).ToArray()); var columns1 = et1.Columns.OrderBy(c => c.Name).ToArray(); @@ -94,7 +94,7 @@ public static void AssertIsSupersetOf(EntityTable et1, EntityTable et2) { Assert.AreEqual(et1.Name, et2.Name); Assert.IsTrue(IsSupersetOf(et1.DataColumnNames, et2.DataColumnNames)); - Assert.IsTrue(IsSupersetOf(et1.IndexColumns.Keys, et2.IndexColumns.Keys)); + Assert.IsTrue(IsSupersetOf(et1.IndexColumnNames, et2.IndexColumnNames)); Assert.IsTrue(IsSupersetOf(et1.StringColumnNames, et2.StringColumnNames)); var columns1 = et1.Columns.ToArray(); diff --git a/src/cs/vim/Vim.Format/ObjectModel/ElementIndexMaps.cs b/src/cs/vim/Vim.Format/ObjectModel/ElementIndexMaps.cs index 94730a1d..60af877a 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ElementIndexMaps.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ElementIndexMaps.cs @@ -62,7 +62,7 @@ public ElementIndexMaps(DocumentModel documentModel, bool inParallel = true) public static DictionaryOfLists GetElementIndicesMap(EntityTable et) { var indicesMap = new DictionaryOfLists(); - var elementIndices = et?.IndexColumns[ElementIndexColumnName]?.GetTypedData(); + var elementIndices = et?.GetIndexColumn(ElementIndexColumnName)?.GetTypedData(); if (elementIndices == null) return indicesMap; for (var i = 0; i < elementIndices.Length; ++i) @@ -73,7 +73,7 @@ public static DictionaryOfLists GetElementIndicesMap(EntityTable et) public static IndexMap GetElementIndexMap(EntityTable et) { var indexMap = new IndexMap(); - var elementIndices = et?.IndexColumns[ElementIndexColumnName]?.GetTypedData(); + var elementIndices = et?.GetIndexColumn(ElementIndexColumnName)?.GetTypedData(); if (elementIndices == null) return indexMap; for (var i = 0; i < elementIndices.Length; ++i)