From 0455cbf6599fd2759f514b6174f2122162363607 Mon Sep 17 00:00:00 2001 From: Samuel Arsenault-Brassard Date: Wed, 21 Oct 2026 21:18:22 -0400 Subject: [PATCH 1/2] Texture coordinates per vertex in the geometry buffers (opt-in, written only when the exporter sends them) Co-Authored-By: Claude Opus 5.5 --- src/cs/vim/Vim.Format.Core/BigG3dWriter.cs | 16 ++++++++++++++++ .../vim/Vim.Format.Core/DocumentBuilderTypes.cs | 16 ++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/cs/vim/Vim.Format.Core/BigG3dWriter.cs b/src/cs/vim/Vim.Format.Core/BigG3dWriter.cs index e70ac297..7f019403 100644 --- a/src/cs/vim/Vim.Format.Core/BigG3dWriter.cs +++ b/src/cs/vim/Vim.Format.Core/BigG3dWriter.cs @@ -28,6 +28,7 @@ public class BigG3dWriter : IBFastComponent public int[] MeshSubmeshOffset { get; } public int[] SubmeshIndexOffsets { get; } public int[] ShapeVertexOffsets { get; } + public bool HasVertexUvs { get; } public BigG3dWriter(List meshes, List instances, List shapes, List materials, G3dHeader? header = null, bool useColors = false) { @@ -113,6 +114,14 @@ public BigG3dWriter(List meshes, List instances, List< writers.Add(AttributeSizeAndName(CommonAttributes.VertexColor, totalVertices)); } + // Texture coordinates: written only when at least one mesh carries them (the exporter's experimental + // "Textures" option). The buffer always spans every vertex; meshes without UVs get (0, 0). + HasVertexUvs = meshes.Any(m => m.UVs != null); + if (HasVertexUvs) + { + writers.Add(AttributeSizeAndName(CommonAttributes.VertexUv, totalVertices)); + } + Names = writers.Select(w => w.attribute).ToArray(); Sizes = writers.Select(w => w.size).ToArray(); Header = BFast.BFast.CreateBFastHeader(Sizes, Names); @@ -139,6 +148,13 @@ public void Write(Stream stream) Meshes.ForEach(g => stream.Write(g.Vertices.ToArray())); break; + // Texture coordinates (one per vertex, zeros for meshes without UVs) + case CommonAttributes.VertexUv: + Meshes.ForEach(g => stream.Write(g.UVs != null + ? g.UVs.ToArray() + : new Math3d.Vector2[g.Vertices.Count])); + break; + // Indices case CommonAttributes.Index: for (var i = 0; i < Meshes.Count; ++i) diff --git a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs index d3a71764..46e68393 100644 --- a/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs +++ b/src/cs/vim/Vim.Format.Core/DocumentBuilderTypes.cs @@ -110,6 +110,12 @@ public class SubdividedMesh public IReadOnlyList SubmeshesIndexOffset { get; } public IReadOnlyList SubmeshMaterials { get; } + /// + /// The per-vertex texture coordinates, or null when the mesh has none. + /// When present, UVs.Count == Vertices.Count (a mesh whose UV count does not match its vertex count gets none). + /// + public IReadOnlyList UVs { get; } + public SubdividedMesh(Mesh mesh) { if (mesh.Indices.Any(i => i < 0 && i >= mesh.Vertices.Count)) @@ -140,26 +146,32 @@ public SubdividedMesh(Mesh mesh) SubmeshesIndexOffset = submeshIndexOffset; Vertices = mesh.Vertices; + UVs = mesh.UVs != null && mesh.UVs.Count > 0 && mesh.UVs.Count == mesh.Vertices.Count + ? mesh.UVs + : null; } public SubdividedMesh( IReadOnlyList indices, IReadOnlyList vertices, IReadOnlyList submeshesIndexOffset, - IReadOnlyList submeshMaterials + IReadOnlyList submeshMaterials, + IReadOnlyList uvs = null ) { Indices = indices; Vertices = vertices; SubmeshesIndexOffset = submeshesIndexOffset; SubmeshMaterials = submeshMaterials; + UVs = uvs != null && uvs.Count > 0 && uvs.Count == vertices.Count ? uvs : null; } public bool IsEquivalentTo(SubdividedMesh other) => Vertices.SequenceEqual(other.Vertices) && Indices.SequenceEqual(other.Indices) && SubmeshesIndexOffset.SequenceEqual(other.SubmeshesIndexOffset) - && SubmeshMaterials.SequenceEqual(other.SubmeshMaterials); + && SubmeshMaterials.SequenceEqual(other.SubmeshMaterials) + && (UVs == null ? other.UVs == null : other.UVs != null && UVs.SequenceEqual(other.UVs)); public static SubdividedMesh CreateFromWorldSpaceBox(IReadOnlyList points, int materialIndex) { From e91cf0843ea0da002df548f5c5b5c90d61c35e7d Mon Sep 17 00:00:00 2001 From: Samuel Arsenault-Brassard Date: Mon, 26 Oct 2026 11:05:39 -0400 Subject: [PATCH 2/2] Realistic materials: Material AppearanceColor, Metalness, Reflectivity (schema 5.8.0); optional header value materials=realistic | realistic+textures; header values through ObjectModelStore.ToDocumentBuilder Co-Authored-By: Claude Opus 5.5 --- src/cpp/vim/object-model.h | 195 ++++++++++++++++++ .../vim/Vim.Format.Core/SerializableHeader.cs | 11 + .../vim/Vim.Format/ObjectModel/ObjectModel.cs | 33 ++- .../ObjectModel/ObjectModelBuilder.cs | 7 +- .../ObjectModel/ObjectModelGenerated.cs | 70 +++++++ .../ObjectModel/ObjectModelStore.cs | 8 +- .../vim/Vim.Format/ObjectModel/Validation.cs | 3 + src/ts/src/objectModel.ts | 80 +++++++ 8 files changed, 404 insertions(+), 3 deletions(-) diff --git a/src/cpp/vim/object-model.h b/src/cpp/vim/object-model.h index 674f8b73..a612b173 100644 --- a/src/cpp/vim/object-model.h +++ b/src/cpp/vim/object-model.h @@ -8654,6 +8654,11 @@ namespace Vim double mGlossiness; double mSmoothness; double mTransparency; + double mAppearanceColor_X; + double mAppearanceColor_Y; + double mAppearanceColor_Z; + double mMetalness; + double mReflectivity; int mColorTextureFileIndex; Asset* mColorTextureFile; @@ -8699,6 +8704,11 @@ namespace Vim material->mGlossiness = GetGlossiness(materialIndex); material->mSmoothness = GetSmoothness(materialIndex); material->mTransparency = GetTransparency(materialIndex); + material->mAppearanceColor_X = GetAppearanceColor_X(materialIndex); + material->mAppearanceColor_Y = GetAppearanceColor_Y(materialIndex); + material->mAppearanceColor_Z = GetAppearanceColor_Z(materialIndex); + material->mMetalness = GetMetalness(materialIndex); + material->mReflectivity = GetReflectivity(materialIndex); material->mColorTextureFileIndex = GetColorTextureFileIndex(materialIndex); material->mNormalTextureFileIndex = GetNormalTextureFileIndex(materialIndex); material->mElementIndex = GetElementIndex(materialIndex); @@ -8724,6 +8734,11 @@ namespace Vim bool existsGlossiness = mEntityTable.column_exists("double:Glossiness"); bool existsSmoothness = mEntityTable.column_exists("double:Smoothness"); bool existsTransparency = mEntityTable.column_exists("double:Transparency"); + bool existsAppearanceColor_X = mEntityTable.column_exists("double:AppearanceColor.X"); + bool existsAppearanceColor_Y = mEntityTable.column_exists("double:AppearanceColor.Y"); + bool existsAppearanceColor_Z = mEntityTable.column_exists("double:AppearanceColor.Z"); + bool existsMetalness = mEntityTable.column_exists("double:Metalness"); + bool existsReflectivity = mEntityTable.column_exists("double:Reflectivity"); bool existsColorTextureFile = mEntityTable.column_exists("index:Vim.Asset:ColorTextureFile"); bool existsNormalTextureFile = mEntityTable.column_exists("index:Vim.Asset:NormalTextureFile"); bool existsElement = mEntityTable.column_exists("index:Vim.Element:Element"); @@ -8812,6 +8827,31 @@ namespace Vim memcpy(transparencyData, mEntityTable.mDataColumns["double:Transparency"].begin(), count * sizeof(double)); } + double* appearanceColor_XData = new double[count]; + if (mEntityTable.column_exists("double:AppearanceColor.X")) { + memcpy(appearanceColor_XData, mEntityTable.mDataColumns["double:AppearanceColor.X"].begin(), count * sizeof(double)); + } + + double* appearanceColor_YData = new double[count]; + if (mEntityTable.column_exists("double:AppearanceColor.Y")) { + memcpy(appearanceColor_YData, mEntityTable.mDataColumns["double:AppearanceColor.Y"].begin(), count * sizeof(double)); + } + + double* appearanceColor_ZData = new double[count]; + if (mEntityTable.column_exists("double:AppearanceColor.Z")) { + memcpy(appearanceColor_ZData, mEntityTable.mDataColumns["double:AppearanceColor.Z"].begin(), count * sizeof(double)); + } + + double* metalnessData = new double[count]; + if (mEntityTable.column_exists("double:Metalness")) { + memcpy(metalnessData, mEntityTable.mDataColumns["double:Metalness"].begin(), count * sizeof(double)); + } + + double* reflectivityData = new double[count]; + if (mEntityTable.column_exists("double:Reflectivity")) { + memcpy(reflectivityData, mEntityTable.mDataColumns["double:Reflectivity"].begin(), count * sizeof(double)); + } + const std::vector& colorTextureFileData = mEntityTable.column_exists("index:Vim.Asset:ColorTextureFile") ? mEntityTable.mIndexColumns["index:Vim.Asset:ColorTextureFile"] : std::vector(); const std::vector& normalTextureFileData = mEntityTable.column_exists("index:Vim.Asset:NormalTextureFile") ? mEntityTable.mIndexColumns["index:Vim.Asset:NormalTextureFile"] : std::vector(); const std::vector& elementData = mEntityTable.column_exists("index:Vim.Element:Element") ? mEntityTable.mIndexColumns["index:Vim.Element:Element"] : std::vector(); @@ -8854,6 +8894,16 @@ namespace Vim entity.mSmoothness = smoothnessData[i]; if (existsTransparency) entity.mTransparency = transparencyData[i]; + if (existsAppearanceColor_X) + entity.mAppearanceColor_X = appearanceColor_XData[i]; + if (existsAppearanceColor_Y) + entity.mAppearanceColor_Y = appearanceColor_YData[i]; + if (existsAppearanceColor_Z) + entity.mAppearanceColor_Z = appearanceColor_ZData[i]; + if (existsMetalness) + entity.mMetalness = metalnessData[i]; + if (existsReflectivity) + entity.mReflectivity = reflectivityData[i]; entity.mColorTextureFileIndex = existsColorTextureFile ? colorTextureFileData[i] : -1; entity.mNormalTextureFileIndex = existsNormalTextureFile ? normalTextureFileData[i] : -1; entity.mElementIndex = existsElement ? elementData[i] : -1; @@ -8875,6 +8925,11 @@ namespace Vim delete[] glossinessData; delete[] smoothnessData; delete[] transparencyData; + delete[] appearanceColor_XData; + delete[] appearanceColor_YData; + delete[] appearanceColor_ZData; + delete[] metalnessData; + delete[] reflectivityData; return material; } @@ -9357,6 +9412,146 @@ namespace Vim return result; } + double GetAppearanceColor_X(int materialIndex) + { + if (materialIndex < 0 || materialIndex >= GetCount()) + return {}; + + if (mEntityTable.column_exists("double:AppearanceColor.X")) { + return *reinterpret_cast(const_cast(mEntityTable.mDataColumns["double:AppearanceColor.X"].begin() + materialIndex * sizeof(double))); + } + + return {}; + } + + std::vector* GetAllAppearanceColor_X() + { + const auto count = GetCount(); + + double* appearanceColor_XData = new double[count]; + if (mEntityTable.column_exists("double:AppearanceColor.X")) { + memcpy(appearanceColor_XData, mEntityTable.mDataColumns["double:AppearanceColor.X"].begin(), count * sizeof(double)); + } + + std::vector* result = new std::vector(appearanceColor_XData, appearanceColor_XData + count); + + delete[] appearanceColor_XData; + + return result; + } + + double GetAppearanceColor_Y(int materialIndex) + { + if (materialIndex < 0 || materialIndex >= GetCount()) + return {}; + + if (mEntityTable.column_exists("double:AppearanceColor.Y")) { + return *reinterpret_cast(const_cast(mEntityTable.mDataColumns["double:AppearanceColor.Y"].begin() + materialIndex * sizeof(double))); + } + + return {}; + } + + std::vector* GetAllAppearanceColor_Y() + { + const auto count = GetCount(); + + double* appearanceColor_YData = new double[count]; + if (mEntityTable.column_exists("double:AppearanceColor.Y")) { + memcpy(appearanceColor_YData, mEntityTable.mDataColumns["double:AppearanceColor.Y"].begin(), count * sizeof(double)); + } + + std::vector* result = new std::vector(appearanceColor_YData, appearanceColor_YData + count); + + delete[] appearanceColor_YData; + + return result; + } + + double GetAppearanceColor_Z(int materialIndex) + { + if (materialIndex < 0 || materialIndex >= GetCount()) + return {}; + + if (mEntityTable.column_exists("double:AppearanceColor.Z")) { + return *reinterpret_cast(const_cast(mEntityTable.mDataColumns["double:AppearanceColor.Z"].begin() + materialIndex * sizeof(double))); + } + + return {}; + } + + std::vector* GetAllAppearanceColor_Z() + { + const auto count = GetCount(); + + double* appearanceColor_ZData = new double[count]; + if (mEntityTable.column_exists("double:AppearanceColor.Z")) { + memcpy(appearanceColor_ZData, mEntityTable.mDataColumns["double:AppearanceColor.Z"].begin(), count * sizeof(double)); + } + + std::vector* result = new std::vector(appearanceColor_ZData, appearanceColor_ZData + count); + + delete[] appearanceColor_ZData; + + return result; + } + + double GetMetalness(int materialIndex) + { + if (materialIndex < 0 || materialIndex >= GetCount()) + return {}; + + if (mEntityTable.column_exists("double:Metalness")) { + return *reinterpret_cast(const_cast(mEntityTable.mDataColumns["double:Metalness"].begin() + materialIndex * sizeof(double))); + } + + return {}; + } + + std::vector* GetAllMetalness() + { + const auto count = GetCount(); + + double* metalnessData = new double[count]; + if (mEntityTable.column_exists("double:Metalness")) { + memcpy(metalnessData, mEntityTable.mDataColumns["double:Metalness"].begin(), count * sizeof(double)); + } + + std::vector* result = new std::vector(metalnessData, metalnessData + count); + + delete[] metalnessData; + + return result; + } + + double GetReflectivity(int materialIndex) + { + if (materialIndex < 0 || materialIndex >= GetCount()) + return {}; + + if (mEntityTable.column_exists("double:Reflectivity")) { + return *reinterpret_cast(const_cast(mEntityTable.mDataColumns["double:Reflectivity"].begin() + materialIndex * sizeof(double))); + } + + return {}; + } + + std::vector* GetAllReflectivity() + { + const auto count = GetCount(); + + double* reflectivityData = new double[count]; + if (mEntityTable.column_exists("double:Reflectivity")) { + memcpy(reflectivityData, mEntityTable.mDataColumns["double:Reflectivity"].begin(), count * sizeof(double)); + } + + std::vector* result = new std::vector(reflectivityData, reflectivityData + count); + + delete[] reflectivityData; + + return result; + } + int GetColorTextureFileIndex(int materialIndex) { if (!mEntityTable.column_exists("index:Vim.Asset:ColorTextureFile")) { diff --git a/src/cs/vim/Vim.Format.Core/SerializableHeader.cs b/src/cs/vim/Vim.Format.Core/SerializableHeader.cs index c1c3a97c..47c53dbd 100644 --- a/src/cs/vim/Vim.Format.Core/SerializableHeader.cs +++ b/src/cs/vim/Vim.Format.Core/SerializableHeader.cs @@ -18,6 +18,17 @@ public class SerializableHeader public const string SchemaField = "schema"; public const string BuildField = "build"; // optional + /// + /// Optional: how the materials were exported. Absent = the default (Revit's Graphics / shaded colours). + /// "realistic" = the Material table also carries each material's render appearance (AppearanceColor, Metalness, + /// Reflectivity, Glossiness and Transparency from the appearance). + /// "realistic+textures" = as "realistic", plus the texture images in the assets and one texture coordinate per + /// vertex (g3d:vertex:uv) with the texture's size, offset and rotation already applied (image coordinates). + /// + public const string MaterialsField = "materials"; + public const string MaterialsRealistic = "realistic"; + public const string MaterialsRealisticWithTextures = "realistic+textures"; + public const char Separator = '='; public const char EndOfLineChar = '\n'; public const string EndOfLineString = "\n"; diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModel.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModel.cs index ddcf8846..1fad61b8 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModel.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModel.cs @@ -14,6 +14,14 @@ public static class SchemaVersion // ReSharper disable MemberHidesStaticFromOuterClass public static class History { + // Schema additions (realistic materials; filled only by exports with the header value materials=realistic*) + // Vim.Material__double:AppearanceColor.X + // Vim.Material__double:AppearanceColor.Y + // Vim.Material__double:AppearanceColor.Z + // Vim.Material__double:Metalness + // Vim.Material__double:Reflectivity + public const string v5_8_0 = "5.8.0"; + // Schema additions // Vim.Element__string:Creator // Vim.Element__string:LastChangedBy @@ -186,7 +194,8 @@ public static class History // ReSharper enable MemberHidesStaticFromOuterClass // [MAINTAIN] Add more object model SerializableVersions below and update the current one. - public static SerializableVersion Current => v5_7_0; + public static SerializableVersion Current => v5_8_0; + public static SerializableVersion v5_8_0 => SerializableVersion.Parse(History.v5_8_0); public static SerializableVersion v5_7_0 => SerializableVersion.Parse(History.v5_7_0); public static SerializableVersion v5_6_0 => SerializableVersion.Parse(History.v5_6_0); public static SerializableVersion v5_5_0 => SerializableVersion.Parse(History.v5_5_0); @@ -1451,6 +1460,28 @@ public DVector2 NormalUvOffset /// The transparency, defined in the domain [0..1] public double Transparency; + + // Realistic materials (schema 5.8.0). Filled only when the file header says materials=realistic or + // materials=realistic+textures; then Glossiness and Transparency also come from the render appearance. + + /// + /// The render appearance's base colour (Revit: Appearance > Color, tint applied), in [0..1]. + /// Color keeps the Graphics / shaded colour. + /// + public double AppearanceColor_X; + public double AppearanceColor_Y; + public double AppearanceColor_Z; + public DVector3 AppearanceColor + { + get => new DVector3(AppearanceColor_X, AppearanceColor_Y, AppearanceColor_Z); + set => (AppearanceColor_X, AppearanceColor_Y, AppearanceColor_Z) = value; + } + + /// The metalness, in [0..1] (Revit: Highlights = Metallic, or a metal appearance). + public double Metalness; + + /// The reflectivity facing the viewer (F0), in [0..1] (Revit: Reflectivity > Direct, or the F0 value). 0 when the appearance gives none. + public double Reflectivity; } /// diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelBuilder.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelBuilder.cs index ad2952d4..48ea7c33 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelBuilder.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelBuilder.cs @@ -1,4 +1,6 @@ -namespace Vim.Format.ObjectModel +using System.Collections.Generic; + +namespace Vim.Format.ObjectModel { /// /// This class makes it easy to fill out the entity tables of a VIM, by allowing the user to specify a mapping @@ -10,5 +12,8 @@ public partial class ObjectModelBuilder { public DocumentBuilder ToDocumentBuilder(string generator, string versionString) => AddEntityTableSets(new DocumentBuilder(generator, SchemaVersion.Current, versionString)); + + public DocumentBuilder ToDocumentBuilder(string generator, string versionString, IReadOnlyDictionary optionalHeaderValues) + => AddEntityTableSets(new DocumentBuilder(generator, SchemaVersion.Current, versionString, optionalHeaderValues)); } } diff --git a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs index 8df50365..60c7eb55 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/ObjectModelGenerated.cs @@ -1084,6 +1084,11 @@ public override bool FieldsAreEqual(object obj) (Glossiness == other.Glossiness) && (Smoothness == other.Smoothness) && (Transparency == other.Transparency) && + (AppearanceColor_X == other.AppearanceColor_X) && + (AppearanceColor_Y == other.AppearanceColor_Y) && + (AppearanceColor_Z == other.AppearanceColor_Z) && + (Metalness == other.Metalness) && + (Reflectivity == other.Reflectivity) && (_ColorTextureFile?.Index == other._ColorTextureFile?.Index) && (_NormalTextureFile?.Index == other._NormalTextureFile?.Index) && (_Element?.Index == other._Element?.Index); @@ -3090,6 +3095,16 @@ public Camera GetCamera(int n) public Double GetMaterialSmoothness(int index, Double defaultValue = default) => MaterialSmoothness?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; public IArray MaterialTransparency { get; } public Double GetMaterialTransparency(int index, Double defaultValue = default) => MaterialTransparency?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; + public IArray MaterialAppearanceColor_X { get; } + public Double GetMaterialAppearanceColor_X(int index, Double defaultValue = default) => MaterialAppearanceColor_X?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; + public IArray MaterialAppearanceColor_Y { get; } + public Double GetMaterialAppearanceColor_Y(int index, Double defaultValue = default) => MaterialAppearanceColor_Y?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; + public IArray MaterialAppearanceColor_Z { get; } + public Double GetMaterialAppearanceColor_Z(int index, Double defaultValue = default) => MaterialAppearanceColor_Z?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; + public IArray MaterialMetalness { get; } + public Double GetMaterialMetalness(int index, Double defaultValue = default) => MaterialMetalness?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; + public IArray MaterialReflectivity { get; } + public Double GetMaterialReflectivity(int index, Double defaultValue = default) => MaterialReflectivity?.ElementAtOrDefault(index, defaultValue) ?? defaultValue; public IArray MaterialColorTextureFileIndex { get; } public int GetMaterialColorTextureFileIndex(int index) => MaterialColorTextureFileIndex?.ElementAtOrDefault(index, EntityRelation.None) ?? EntityRelation.None; public IArray MaterialNormalTextureFileIndex { get; } @@ -3121,6 +3136,11 @@ public Material GetMaterial(int n) r.Glossiness = MaterialGlossiness.ElementAtOrDefault(n); r.Smoothness = MaterialSmoothness.ElementAtOrDefault(n); r.Transparency = MaterialTransparency.ElementAtOrDefault(n); + r.AppearanceColor_X = MaterialAppearanceColor_X.ElementAtOrDefault(n); + r.AppearanceColor_Y = MaterialAppearanceColor_Y.ElementAtOrDefault(n); + r.AppearanceColor_Z = MaterialAppearanceColor_Z.ElementAtOrDefault(n); + r.Metalness = MaterialMetalness.ElementAtOrDefault(n); + r.Reflectivity = MaterialReflectivity.ElementAtOrDefault(n); r._ColorTextureFile = new Relation(GetMaterialColorTextureFileIndex(n), GetAsset); r._NormalTextureFile = new Relation(GetMaterialNormalTextureFileIndex(n), GetAsset); r._Element = new Relation(GetMaterialElementIndex(n), GetElement); @@ -4221,6 +4241,11 @@ public DocumentModel(Document d, bool inParallel = true) MaterialGlossiness = MaterialEntityTable?.GetDataColumnValues("double:Glossiness") ?? Array.Empty().ToIArray(); MaterialSmoothness = MaterialEntityTable?.GetDataColumnValues("double:Smoothness") ?? Array.Empty().ToIArray(); MaterialTransparency = MaterialEntityTable?.GetDataColumnValues("double:Transparency") ?? Array.Empty().ToIArray(); + MaterialAppearanceColor_X = MaterialEntityTable?.GetDataColumnValues("double:AppearanceColor.X") ?? Array.Empty().ToIArray(); + MaterialAppearanceColor_Y = MaterialEntityTable?.GetDataColumnValues("double:AppearanceColor.Y") ?? Array.Empty().ToIArray(); + MaterialAppearanceColor_Z = MaterialEntityTable?.GetDataColumnValues("double:AppearanceColor.Z") ?? Array.Empty().ToIArray(); + MaterialMetalness = MaterialEntityTable?.GetDataColumnValues("double:Metalness") ?? Array.Empty().ToIArray(); + MaterialReflectivity = MaterialEntityTable?.GetDataColumnValues("double:Reflectivity") ?? 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(); @@ -6751,6 +6776,11 @@ public MaterialTable(SerializableEntityTable rawTable, string[] stringTable, Ent Column_Glossiness = GetDataColumnValues("double:Glossiness") ?? Array.Empty(); Column_Smoothness = GetDataColumnValues("double:Smoothness") ?? Array.Empty(); Column_Transparency = GetDataColumnValues("double:Transparency") ?? Array.Empty(); + Column_AppearanceColor_X = GetDataColumnValues("double:AppearanceColor.X") ?? Array.Empty(); + Column_AppearanceColor_Y = GetDataColumnValues("double:AppearanceColor.Y") ?? Array.Empty(); + Column_AppearanceColor_Z = GetDataColumnValues("double:AppearanceColor.Z") ?? Array.Empty(); + Column_Metalness = GetDataColumnValues("double:Metalness") ?? Array.Empty(); + Column_Reflectivity = GetDataColumnValues("double:Reflectivity") ?? Array.Empty(); Column_ColorTextureFileIndex = GetIndexColumnValues("index:Vim.Asset:ColorTextureFile") ?? Array.Empty(); Column_NormalTextureFileIndex = GetIndexColumnValues("index:Vim.Asset:NormalTextureFile") ?? Array.Empty(); Column_ElementIndex = GetIndexColumnValues("index:Vim.Element:Element") ?? Array.Empty(); @@ -6790,6 +6820,16 @@ public MaterialTable(SerializableEntityTable rawTable, string[] stringTable, Ent public Double GetSmoothness(int index, Double @default = default) => Column_Smoothness.ElementAtOrDefault(index, @default); public Double[] Column_Transparency { get; } public Double GetTransparency(int index, Double @default = default) => Column_Transparency.ElementAtOrDefault(index, @default); + public Double[] Column_AppearanceColor_X { get; } + public Double GetAppearanceColor_X(int index, Double @default = default) => Column_AppearanceColor_X.ElementAtOrDefault(index, @default); + public Double[] Column_AppearanceColor_Y { get; } + public Double GetAppearanceColor_Y(int index, Double @default = default) => Column_AppearanceColor_Y.ElementAtOrDefault(index, @default); + public Double[] Column_AppearanceColor_Z { get; } + public Double GetAppearanceColor_Z(int index, Double @default = default) => Column_AppearanceColor_Z.ElementAtOrDefault(index, @default); + public Double[] Column_Metalness { get; } + public Double GetMetalness(int index, Double @default = default) => Column_Metalness.ElementAtOrDefault(index, @default); + public Double[] Column_Reflectivity { get; } + public Double GetReflectivity(int index, Double @default = default) => Column_Reflectivity.ElementAtOrDefault(index, @default); public int[] Column_ColorTextureFileIndex { get; } public int GetColorTextureFileIndex(int index) => Column_ColorTextureFileIndex.ElementAtOrDefault(index, EntityRelation.None); public Asset GetColorTextureFile(int index) => _GetReferencedColorTextureFile(GetColorTextureFileIndex(index)); @@ -6825,6 +6865,11 @@ public Material Get(int index) r.Glossiness = GetGlossiness(index); r.Smoothness = GetSmoothness(index); r.Transparency = GetTransparency(index); + r.AppearanceColor_X = GetAppearanceColor_X(index); + r.AppearanceColor_Y = GetAppearanceColor_Y(index); + r.AppearanceColor_Z = GetAppearanceColor_Z(index); + r.Metalness = GetMetalness(index); + r.Reflectivity = GetReflectivity(index); r._ColorTextureFile = new Relation(GetColorTextureFileIndex(index), _GetReferencedColorTextureFile); r._NormalTextureFile = new Relation(GetNormalTextureFileIndex(index), _GetReferencedNormalTextureFile); r._Element = new Relation(GetElementIndex(index), _GetReferencedElement); @@ -9454,6 +9499,31 @@ public static EntityTableBuilder ToMaterialTableBuilder(this EntitySetBuilder Shapes { get; } = new List(); public DocumentBuilder ToDocumentBuilder(string generator, string versionString) + => ToDocumentBuilder(generator, versionString, null); + + /// + /// The optional header values (for example SerializableHeader.MaterialsField) are written into the VIM header. + /// + public DocumentBuilder ToDocumentBuilder(string generator, string versionString, IReadOnlyDictionary optionalHeaderValues) { - return ObjectModelBuilder.ToDocumentBuilder(generator, versionString) + return ObjectModelBuilder.ToDocumentBuilder(generator, versionString, optionalHeaderValues) .AddMeshes(Meshes.Select(g => g.Subdivide())) .AddInstances(Instances) .AddShapes(Shapes) diff --git a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs index 24fb6399..42e3054f 100644 --- a/src/cs/vim/Vim.Format/ObjectModel/Validation.cs +++ b/src/cs/vim/Vim.Format/ObjectModel/Validation.cs @@ -261,6 +261,9 @@ void ValidateDVector3Domain(string label, DVector3 value, DVector3 lowerInclusiv ValidateDomain(nameof(material.Smoothness), material.Smoothness, 0d, 1d, index); ValidateDomain(nameof(material.Transparency), material.Transparency, 0d, 1d, index); ValidateDomain(nameof(material.NormalAmount), material.NormalAmount, 0d, 1d, index); + ValidateDVector3Domain(nameof(material.AppearanceColor), material.AppearanceColor, DVector3.Zero, DVector3.One, index); + ValidateDomain(nameof(material.Metalness), material.Metalness, 0d, 1d, index); + ValidateDomain(nameof(material.Reflectivity), material.Reflectivity, 0d, 1d, index); } } diff --git a/src/ts/src/objectModel.ts b/src/ts/src/objectModel.ts index c0a5ea4f..c6891069 100644 --- a/src/ts/src/objectModel.ts +++ b/src/ts/src/objectModel.ts @@ -6102,6 +6102,11 @@ export interface IMaterial { glossiness?: number smoothness?: number transparency?: number + appearanceColor_X?: number + appearanceColor_Y?: number + appearanceColor_Z?: number + metalness?: number + reflectivity?: number colorTextureFileIndex?: number colorTextureFile?: IAsset @@ -6150,6 +6155,16 @@ export interface IMaterialTable { getAllSmoothness(): Promise getTransparency(materialIndex: number): Promise getAllTransparency(): Promise + getAppearanceColor_X(materialIndex: number): Promise + getAllAppearanceColor_X(): Promise + getAppearanceColor_Y(materialIndex: number): Promise + getAllAppearanceColor_Y(): Promise + getAppearanceColor_Z(materialIndex: number): Promise + getAllAppearanceColor_Z(): Promise + getMetalness(materialIndex: number): Promise + getAllMetalness(): Promise + getReflectivity(materialIndex: number): Promise + getAllReflectivity(): Promise getColorTextureFileIndex(materialIndex: number): Promise getAllColorTextureFileIndex(): Promise @@ -6181,6 +6196,11 @@ export class Material implements IMaterial { glossiness?: number smoothness?: number transparency?: number + appearanceColor_X?: number + appearanceColor_Y?: number + appearanceColor_Z?: number + metalness?: number + reflectivity?: number colorTextureFileIndex?: number colorTextureFile?: IAsset @@ -6211,6 +6231,11 @@ export class Material implements IMaterial { table.getGlossiness(index).then(v => result.glossiness = v), table.getSmoothness(index).then(v => result.smoothness = v), table.getTransparency(index).then(v => result.transparency = v), + table.getAppearanceColor_X(index).then(v => result.appearanceColor_X = v), + table.getAppearanceColor_Y(index).then(v => result.appearanceColor_Y = v), + table.getAppearanceColor_Z(index).then(v => result.appearanceColor_Z = v), + table.getMetalness(index).then(v => result.metalness = v), + table.getReflectivity(index).then(v => result.reflectivity = v), table.getColorTextureFileIndex(index).then(v => result.colorTextureFileIndex = v), table.getNormalTextureFileIndex(index).then(v => result.normalTextureFileIndex = v), table.getElementIndex(index).then(v => result.elementIndex = v), @@ -6266,6 +6291,11 @@ export class MaterialTable implements IMaterialTable { let glossiness: number[] | undefined let smoothness: number[] | undefined let transparency: number[] | undefined + let appearanceColor_X: number[] | undefined + let appearanceColor_Y: number[] | undefined + let appearanceColor_Z: number[] | undefined + let metalness: number[] | undefined + let reflectivity: number[] | undefined let colorTextureFileIndex: number[] | undefined let normalTextureFileIndex: number[] | undefined let elementIndex: number[] | undefined @@ -6288,6 +6318,11 @@ export class MaterialTable implements IMaterialTable { (async () => { glossiness = (await localTable.getNumberArray("double:Glossiness")) })(), (async () => { smoothness = (await localTable.getNumberArray("double:Smoothness")) })(), (async () => { transparency = (await localTable.getNumberArray("double:Transparency")) })(), + (async () => { appearanceColor_X = (await localTable.getNumberArray("double:AppearanceColor.X")) })(), + (async () => { appearanceColor_Y = (await localTable.getNumberArray("double:AppearanceColor.Y")) })(), + (async () => { appearanceColor_Z = (await localTable.getNumberArray("double:AppearanceColor.Z")) })(), + (async () => { metalness = (await localTable.getNumberArray("double:Metalness")) })(), + (async () => { reflectivity = (await localTable.getNumberArray("double:Reflectivity")) })(), (async () => { colorTextureFileIndex = (await localTable.getNumberArray("index:Vim.Asset:ColorTextureFile")) })(), (async () => { normalTextureFileIndex = (await localTable.getNumberArray("index:Vim.Asset:NormalTextureFile")) })(), (async () => { elementIndex = (await localTable.getNumberArray("index:Vim.Element:Element")) })(), @@ -6316,6 +6351,11 @@ export class MaterialTable implements IMaterialTable { glossiness: glossiness ? glossiness[i] : undefined, smoothness: smoothness ? smoothness[i] : undefined, transparency: transparency ? transparency[i] : undefined, + appearanceColor_X: appearanceColor_X ? appearanceColor_X[i] : undefined, + appearanceColor_Y: appearanceColor_Y ? appearanceColor_Y[i] : undefined, + appearanceColor_Z: appearanceColor_Z ? appearanceColor_Z[i] : undefined, + metalness: metalness ? metalness[i] : undefined, + reflectivity: reflectivity ? reflectivity[i] : undefined, colorTextureFileIndex: colorTextureFileIndex ? colorTextureFileIndex[i] : undefined, normalTextureFileIndex: normalTextureFileIndex ? normalTextureFileIndex[i] : undefined, elementIndex: elementIndex ? elementIndex[i] : undefined @@ -6461,6 +6501,46 @@ export class MaterialTable implements IMaterialTable { return (await this.entityTable.getNumberArray("double:Transparency")) } + async getAppearanceColor_X(materialIndex: number): Promise { + return (await this.entityTable.getNumber(materialIndex, "double:AppearanceColor.X")) + } + + async getAllAppearanceColor_X(): Promise { + return (await this.entityTable.getNumberArray("double:AppearanceColor.X")) + } + + async getAppearanceColor_Y(materialIndex: number): Promise { + return (await this.entityTable.getNumber(materialIndex, "double:AppearanceColor.Y")) + } + + async getAllAppearanceColor_Y(): Promise { + return (await this.entityTable.getNumberArray("double:AppearanceColor.Y")) + } + + async getAppearanceColor_Z(materialIndex: number): Promise { + return (await this.entityTable.getNumber(materialIndex, "double:AppearanceColor.Z")) + } + + async getAllAppearanceColor_Z(): Promise { + return (await this.entityTable.getNumberArray("double:AppearanceColor.Z")) + } + + async getMetalness(materialIndex: number): Promise { + return (await this.entityTable.getNumber(materialIndex, "double:Metalness")) + } + + async getAllMetalness(): Promise { + return (await this.entityTable.getNumberArray("double:Metalness")) + } + + async getReflectivity(materialIndex: number): Promise { + return (await this.entityTable.getNumber(materialIndex, "double:Reflectivity")) + } + + async getAllReflectivity(): Promise { + return (await this.entityTable.getNumberArray("double:Reflectivity")) + } + async getColorTextureFileIndex(materialIndex: number): Promise { return await this.entityTable.getNumber(materialIndex, "index:Vim.Asset:ColorTextureFile") }