From 615c33063fb6b717c4ece301f538abc51dfafb72 Mon Sep 17 00:00:00 2001 From: katehryhorenko Date: Mon, 9 Oct 2023 10:48:25 -0300 Subject: [PATCH 1/2] Multiple representations, gltf serialization: element is a parent node, all representations - are its children --- .../src/Serialization/glTF/GltfExtensions.cs | 7 +++++-- .../src/Serialization/glTF/NodeUtilities.cs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Elements/src/Serialization/glTF/GltfExtensions.cs b/Elements/src/Serialization/glTF/GltfExtensions.cs index fee6995db..d112caf90 100644 --- a/Elements/src/Serialization/glTF/GltfExtensions.cs +++ b/Elements/src/Serialization/glTF/GltfExtensions.cs @@ -1289,6 +1289,7 @@ private static void GetRenderDataForElement(Element e, if (element.RepresentationInstances != null && element.RepresentationInstances.Any()) { + var elementNodeId = NodeUtilities.AddInstanceNode(nodes, element.Transform, element.Id); foreach (var representation in element.RepresentationInstances) { // get the unique id that contains representation Id and opening Ids @@ -1296,10 +1297,11 @@ private static void GetRenderDataForElement(Element e, if (representationsMap.TryGetValue(combinedId, out var mesh)) { - var addedNodes = NodeUtilities.AddInstanceNode(nodes, mesh, element.Transform, e.Id); + var addedNodes = NodeUtilities.AddNodes(nodes, mesh, elementNodeId); foreach (var index in addedNodes) { NodeUtilities.SetRepresentationInfo(nodes[index], representation); + NodeUtilities.SetElementInfo(nodes[index], element.Id); } } else if (representation.Representation.TryToGraphicsBuffers(geometricElement, out var graphicsBuffers, @@ -1320,10 +1322,11 @@ private static void GetRenderDataForElement(Element e, { var meshIdList = new List { meshId }; representationsMap.Add(combinedId, meshIdList); - var addedNodes = NodeUtilities.AddInstanceNode(nodes, meshIdList, element.Transform, e.Id); + var addedNodes = NodeUtilities.AddNodes(nodes, meshIdList, elementNodeId); foreach (var index in addedNodes) { NodeUtilities.SetRepresentationInfo(nodes[index], representation); + NodeUtilities.SetElementInfo(nodes[index], element.Id); } } } diff --git a/Elements/src/Serialization/glTF/NodeUtilities.cs b/Elements/src/Serialization/glTF/NodeUtilities.cs index b64c8382d..7059a7348 100644 --- a/Elements/src/Serialization/glTF/NodeUtilities.cs +++ b/Elements/src/Serialization/glTF/NodeUtilities.cs @@ -39,6 +39,16 @@ internal static int[] AddNodes(List nodes, IEnumerable newNodes, int return newIds; } + internal static int[] AddNodes(List nodes, List meshIds, int? parentId) + { + var newNodes = meshIds.Select(meshId => + { + return new Node() { Mesh = meshId }; + }); + + return AddNodes(nodes, newNodes, parentId); + } + internal static int AddNode(List nodes, Node newNode, int? parentId) { return NodeUtilities.AddNodes(nodes, new[] { newNode }, parentId).First(); @@ -138,6 +148,14 @@ private static int RecursivelyCopyNode(List nodes, ProtoNode nodeToCopy) return nodeIndex; } + internal static int AddInstanceNode(List nodes, Transform transform, Guid elementId) + { + float[] matrix = TransformToMatrix(transform); + var newNode = new Node() { Matrix = matrix, Name = elementId.ToString() }; + newNode.SetElementInfo(elementId); + return AddNode(nodes, newNode, 0); + } + internal static int[] AddInstanceNode( List nodes, List meshIds, From 5e9dacb7296ab107feb1de7d90a234298d92f4ec Mon Sep 17 00:00:00 2001 From: katehryhorenko Date: Tue, 10 Oct 2023 15:14:55 -0300 Subject: [PATCH 2/2] Change log --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 005eb7821..7a810a9ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,10 +61,8 @@ ### Changed - `GltfExtensions.UseReferencedContentExtension` is now true by default. - -### Changed - -- `GeometricElement.Intersects` method now supports multiple representations +- `GeometricElement.Intersects` method now supports multiple representations. +- `GltfExtensions.ToGlTF` creates parent node for element and child nodes for representation instances. ## 2.0.0