-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1044 from hypar-io/content_representation
Added ContentRepresentation
- Loading branch information
Showing
6 changed files
with
163 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System.Collections.Generic; | ||
using Elements.Geometry; | ||
using Elements.Geometry.Solids; | ||
using Elements.Serialization.glTF; | ||
using Elements.Utilities; | ||
using glTFLoader.Schema; | ||
|
||
namespace Elements | ||
{ | ||
/// <summary> | ||
/// Represents an element as a reference to a GLB file location within the content catalog. | ||
/// </summary> | ||
public class ContentRepresentation : ElementRepresentation | ||
{ | ||
/// <summary>The URI of the glb for this element.</summary> | ||
public string GlbLocation { get; set; } | ||
|
||
/// <summary>The bounding box of the content.</summary> | ||
public BBox3 BoundingBox { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of ContentRepresentation class | ||
/// </summary> | ||
/// <param name="glbLocation">The URI of the glb for this element.</param> | ||
/// <param name="boundingBox">The bounding box of the content.</param> | ||
public ContentRepresentation(string glbLocation, BBox3 boundingBox) | ||
{ | ||
GlbLocation = glbLocation; | ||
BoundingBox = boundingBox; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of ContentRepresentation class | ||
/// </summary> | ||
/// <param name="glbLocation">The URI of the glb for this element.</param> | ||
public ContentRepresentation(string glbLocation) : this(glbLocation, default) { } | ||
|
||
/// <inheritdoc/> | ||
public override bool TryToGraphicsBuffers(GeometricElement element, out List<GraphicsBuffers> graphicsBuffers, out string id, out MeshPrimitive.ModeEnum? mode) | ||
{ | ||
id = element.Id + "_mesh"; | ||
|
||
graphicsBuffers = new List<GraphicsBuffers>(); | ||
mode = MeshPrimitive.ModeEnum.TRIANGLES; | ||
|
||
if (!BoundingBox.IsValid() || BoundingBox.IsDegenerate()) | ||
{ | ||
return true; | ||
} | ||
|
||
var bottomProfile = new Geometry.Polygon(new List<Vector3>{ | ||
new Vector3(BoundingBox.Min.X, BoundingBox.Min.Y, BoundingBox.Min.Z), | ||
new Vector3(BoundingBox.Min.X, BoundingBox.Max.Y, BoundingBox.Min.Z), | ||
new Vector3(BoundingBox.Max.X, BoundingBox.Max.Y, BoundingBox.Min.Z), | ||
new Vector3(BoundingBox.Max.X, BoundingBox.Min.Y, BoundingBox.Min.Z), | ||
}); | ||
|
||
var height = BoundingBox.Max.Z - BoundingBox.Min.Z; | ||
var boxSolid = new Extrude(bottomProfile, height, Vector3.ZAxis, false); | ||
|
||
var csg = SolidOperationUtils.GetFinalCsgFromSolids(new List<SolidOperation>() { boxSolid }, element, false); | ||
|
||
if (csg == null) | ||
{ | ||
return false; | ||
} | ||
|
||
GraphicsBuffers buffers = null; | ||
buffers = csg.Tessellate(); | ||
|
||
if (buffers.Vertices.Count == 0) | ||
{ | ||
return false; | ||
} | ||
|
||
graphicsBuffers.Add(buffers); | ||
return true; | ||
} | ||
|
||
internal override List<NodeExtension> GetNodeExtensions(GeometricElement element) | ||
{ | ||
var extensions = base.GetNodeExtensions(element); | ||
extensions.Add(new NodeExtension("HYPAR_referenced_content", "contentUrl", GlbLocation)); | ||
return extensions; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Elements.Serialization.glTF | ||
{ | ||
internal class NodeExtension | ||
{ | ||
public NodeExtension(string name, Dictionary<string, object> attributes) | ||
{ | ||
Name = name; | ||
Attributes = attributes; | ||
} | ||
|
||
public NodeExtension(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public NodeExtension(string name, string attributeName, object attributeValue) | ||
{ | ||
Name = name; | ||
Attributes.Add(attributeName, attributeValue); | ||
} | ||
|
||
public string Name { get; set; } | ||
|
||
public Dictionary<string, object> Attributes { get; } = new Dictionary<string, object>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters