public void DifferenceWhichSplitsVolumeSucceeds() { this.Name = nameof(DifferenceWhichSplitsVolumeSucceeds); var s1 = new Extrude(Polygon.Rectangle(2, 2), 2, Vector3.ZAxis, false); var s2 = new Extrude(Polygon.Rectangle(0.5, 4), 6, Vector3.ZAxis, false); var result1 = Solid.Difference(s1.Solid, new Transform(new Vector3(0, 0, -1)), s2.Solid, new Transform(new Vector3(0, 0, -3))); var s3 = new Extrude(Polygon.Rectangle(4, 0.5), 3, Vector3.ZAxis, false); result1 = Solid.Difference(result1, null, s3.Solid, new Transform(new Vector3(0, 0, -3.25))); var rep = new Representation(new List <SolidOperation>() { new ConstructedSolid(result1) }); var solidElement = new GeometricElement(representation: rep); this.Model.AddElement(solidElement); this.Model.AddElements(DrawEdges(result1, null)); Assert.Equal(20, result1.Faces.Count); Assert.Equal(32, result1.Vertices.Count); Assert.Equal(48, result1.Edges.Count); }
/// <summary> /// Construct a new position placement rule from scratch. /// </summary> /// <param name="name">The name of the rule.</param> /// <param name="anchorIndex">The index of the anchor this element moves with.</param> /// <param name="definition">The element that this rule places.</param> /// <param name="anchorOffset">An optional transform for this element relative to its anchor.</param> public PositionPlacementRule(string name, int anchorIndex, GeometricElement definition, Transform anchorOffset = null) { Name = name; AnchorIndex = anchorIndex; AnchorTransform = anchorOffset ?? new Transform(); Definition = definition; }
public void SolidPlaneIntersectionTests(string name, string path) { this.Name = name; var r = new Random(); var di = JsonConvert.DeserializeObject <DebugInfo>(File.ReadAllText(path), new[] { new SolidConverter() }); foreach (var solid in di.Solid) { Assert.True(di.Plane.Normal.IsUnitized()); Assert.True(solid.Intersects(di.Plane, out var results)); foreach (var p in results) { this.Model.AddElement(new Panel(p, r.NextMaterial())); } var rep = new Representation(new List <SolidOperation>() { new ConstructedSolid(solid, false) }); var solidElement = new GeometricElement(representation: rep, material: BuiltInMaterials.Mass); this.Model.AddElement(solidElement); } }
/// <summary> /// Does this ray intersect with the provided GeometricElement? Only GeometricElements with Solid Representations are currently supported, and voids will be ignored. /// </summary> /// <param name="element">The element to intersect with.</param> /// <param name="result">The list of intersection results.</param> /// <returns></returns> public bool Intersects(GeometricElement element, out List <Vector3> result) { List <Vector3> resultsOut = new List <Vector3>(); var transformFromElement = new Transform(element.Transform); transformFromElement.Invert(); var transformToElement = new Transform(element.Transform); var transformMinusTranslation = new Transform(transformFromElement); // This transform ignores position so it can be used to transform the ray direction vector transformMinusTranslation.Move(transformMinusTranslation.Origin.Negate()); var transformedRay = new Ray(transformFromElement.OfPoint(Origin), transformMinusTranslation.OfVector(Direction)); //TODO: extend to handle voids when void solids in Representations are supported generally var intersects = false; foreach (var solidOp in element.Representation.SolidOperations.Where(e => !e.IsVoid)) { if (transformedRay.Intersects(solidOp, out List <Vector3> tempResults)) { intersects = true; resultsOut.AddRange(tempResults.Select(t => transformToElement.OfPoint(t))); } ; } result = resultsOut; return(intersects); }
public void SolidIntersectsPlaneAtFaceReturningFaceLoop() { this.Name = nameof(SolidIntersectsPlaneAtFaceReturningFaceLoop); var r = new Random(); var profile = Polygon.Rectangle(5, 5); var extrude = new Extrude(profile, 5, Vector3.ZAxis, false); var plane = new Plane(new Vector3(0, -2.5, 2.5), Vector3.YAxis.Negate()); Assert.True(extrude.Solid.Intersects(plane, out List <Polygon> result)); Assert.Single(result); var p = result[0]; Assert.Equal(4, p.Vertices.Count); this.Model.AddElement(new Panel(p, r.NextMaterial())); var rep = new Representation(new List <SolidOperation>() { extrude }); var solidElement = new GeometricElement(representation: rep, material: BuiltInMaterials.Mass); this.Model.AddElement(solidElement); }
public void SolidIntersectPlaneTwice() { this.Name = nameof(SolidIntersectPlaneTwice); var r = new Random(); var l = Polygon.L(5, 5, 1); var profile = new Profile(l, l.Offset(-0.1).Reversed()); var arc = new Arc(Vector3.Origin, 5, 0, 180); var sweep = new Sweep(profile, arc, 0, 0, 0, false); var plane = new Plane(Vector3.Origin, Vector3.YAxis.Negate()); Assert.True(sweep.Solid.Intersects(plane, out List <Polygon> result)); Assert.Equal(4, result.Count); foreach (var p in result) { Assert.Equal(6, p.Vertices.Count); this.Model.AddElement(new Panel(p, r.NextMaterial())); } var rep = new Representation(new List <SolidOperation>() { sweep }); var solidElement = new GeometricElement(representation: rep, material: BuiltInMaterials.Mass); this.Model.AddElement(solidElement); }
public void TessellatorProducesCorrectVertexNormals() { Name = nameof(TessellatorProducesCorrectVertexNormals); var shape = new Polygon((4.96243, 50.58403), (5.78472, 50.58403), (5.78472, 65.83403), (-7.05727, 65.83403), (-7.05727, 50.57403), (4.96243, 50.57403)); var geoElem = new GeometricElement(representation: new Extrude(shape, 1, Vector3.ZAxis, false)); Model.AddElement(geoElem); var solid = geoElem.GetFinalCsgFromSolids(); var mgb = new MockGraphicsBuffer(); var arrows = new ModelArrows(); Tessellation.Tessellate(new Csg.Solid[] { solid }.Select(s => new CsgTessellationTargetProvider(solid)), mgb); for (int i = 0; i < mgb.Indices.Count; i += 3) { var a = mgb.Indices[i]; var b = mgb.Indices[i + 1]; var c = mgb.Indices[i + 2]; var verts = new[] { mgb.Vertices[a], mgb.Vertices[b], mgb.Vertices[c] }; verts.ToList().ForEach((v) => { arrows.Vectors.Add((v.position, v.normal, 0.2, Colors.Blue)); }); var triangle = new Polygon(verts.Select(v => v.position).ToList()); var normal = verts[0].normal; Assert.True(triangle.Normal().Dot(normal.Unitized()) > 0, "The vertex normals are pointing in the opposite direction as their triangles' winding should suggest"); Model.AddElement(triangle.TransformedPolygon(new Transform(normal * 0.2))); } Model.AddElement(arrows); }
public void AllBooleans() { this.Name = nameof(AllBooleans); CreateTestSolids(out GeometricElement a, out GeometricElement b); var t1 = new Transform(new Vector3(10, 0)); var t2 = new Transform(new Vector3(15, 0)); var s1 = Solid.Union(a.Representation.SolidOperations[0], b.Representation.SolidOperations[0]); var s2 = Solid.Difference(a.Representation.SolidOperations[0], b.Representation.SolidOperations[0]); var s3 = Solid.Intersection(a.Representation.SolidOperations[0], b.Representation.SolidOperations[0]); var i1 = new GeometricElement(null, BuiltInMaterials.Steel, new Representation(new List <SolidOperation> { new ConstructedSolid(s1) })); var i2 = new GeometricElement(t1, BuiltInMaterials.Steel, new Representation(new List <SolidOperation> { new ConstructedSolid(s2) })); var i3 = new GeometricElement(t2, BuiltInMaterials.Steel, new Representation(new List <SolidOperation> { new ConstructedSolid(s3) })); this.Model.AddElements(DrawEdges(s1, null)); this.Model.AddElements(DrawEdges(s2, t1)); this.Model.AddElements(DrawEdges(s3, t2)); this.Model.AddElements(i1, i2, i3); }
public void ConstructedSolid() { Name = nameof(ConstructedSolid); var solid = new Solid(); var A = new Vector3(0, 0, 0); var B = new Vector3(1, 0, 0); var C = new Vector3(1, 1, 0); var D = new Vector3(0, 1, 0); var E = new Vector3(0, 0, 1); var F = new Vector3(1, 0, 1); var G = new Vector3(1, 1, 1); var H = new Vector3(0, 1, 1); solid.AddFace(new Polygon(new[] { A, B, C, D })); solid.AddFace(new Polygon(new[] { E, F, G, H })); solid.AddFace(new Polygon(new[] { A, B, F, E })); solid.AddFace(new Polygon(new[] { B, C, G, F })); solid.AddFace(new Polygon(new[] { C, D, H, G })); solid.AddFace(new Polygon(new[] { D, A, E, H })); var emptySolid = new ConstructedSolid(new Solid(), false); var import = new ConstructedSolid(solid, false); var representation = new Representation(new[] { import }); var emptyRep = new Representation(new[] { emptySolid }); var userElement = new GeometricElement(new Transform(), BuiltInMaterials.Default, representation, false, Guid.NewGuid(), "Import"); var userElementWithEmptySolid = new GeometricElement(new Transform(), BuiltInMaterials.Default, emptyRep, false, Guid.NewGuid(), "Import"); Model.AddElement(userElement); Model.AddElement(userElementWithEmptySolid); }
/// <summary> /// Does this ray intersect with the provided GeometricElement? Only GeometricElements with Solid Representations are currently supported, and voids will be ignored. /// </summary> /// <param name="element">The element to intersect with.</param> /// <param name="result">The list of intersection results.</param> /// <returns></returns> public bool Intersects(GeometricElement element, out List <Vector3> result) { if (element.Representation == null || element.Representation.SolidOperations == null || element.Representation.SolidOperations.Count == 0) { element.UpdateRepresentations(); } List <Vector3> resultsOut = new List <Vector3>(); var transformFromElement = new Transform(element.Transform); transformFromElement.Invert(); var transformToElement = new Transform(element.Transform); var transformedRay = new Ray(transformFromElement.OfPoint(Origin), transformFromElement.OfVector(Direction)); //TODO: extend to handle voids when void solids in Representations are supported generally var intersects = false; foreach (var solidOp in element.Representation.SolidOperations.Where(e => !e.IsVoid)) { if (transformedRay.Intersects(solidOp, out List <Vector3> tempResults)) { intersects = true; resultsOut.AddRange(tempResults.Select(t => transformToElement.OfPoint(t))); } ; } result = resultsOut; return(intersects); }
private static IfcProduct ConvertElementToIfcProduct(Guid id, GeometricElement element, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { try { IfcProduct e = null; if (element is Beam) { e = ((Beam)element).ToIfc(id, localPlacement, shape); } if (element is Brace) { e = ((Brace)element).ToIfc(id, localPlacement, shape); } else if (element is Column) { e = ((Column)element).ToIfc(id, localPlacement, shape); } else if (element is StandardWall) { e = ((StandardWall)element).ToIfc(id, localPlacement, shape); } else if (element is Wall) { e = ((Wall)element).ToIfc(id, localPlacement, shape); } else if (element is Floor) { e = ((Floor)element).ToIfc(id, localPlacement, shape); } else if (element is Space) { e = ((Space)element).ToIfc(id, localPlacement, shape); } else if (element is Panel) { e = ((Panel)element).ToIfc(id, localPlacement, shape); } else if (element is Mass) { e = ((Mass)element).ToIfc(id, localPlacement, shape); } else if (element is Opening) { e = ((Opening)element).ToIfc(id, localPlacement, shape); } else { e = element.ToIfc(id, localPlacement, shape); } return(e); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine($"{element.GetType()} cannot be serialized to IFC."); } return(null); }
/// <summary> /// Construct a new array placement rule from scratch. /// </summary> /// <param name="definition">The element to array.</param> /// <param name="arrayPath">The path along which to array.</param> /// <param name="spacingRule">The configuration for the spacing.</param> /// <param name="anchorIndices">For each vertex, the index of the corresponding anchor.</param> /// <param name="anchorDisplacements">For each vertex, the displacement from its anchor.</param> /// <param name="name">The name.</param> public ArrayPlacementRule(GeometricElement definition, Polyline arrayPath, SpacingConfiguration spacingRule, IList <int> anchorIndices, IList <Vector3> anchorDisplacements, string name) { Curve = arrayPath; AnchorIndices = anchorIndices; AnchorDisplacements = anchorDisplacements; Name = name; IsClosed = arrayPath is Polygon; SpacingRule = spacingRule; ElementDefinition = definition; }
/// <summary> /// Get DXF entities from the Representation of a GeometricElement. /// </summary> /// <param name="element"></param> /// <returns></returns> public static List <DxfEntity> GetEntitiesFromRepresentation(this GeometricElement element) { var list = new List <DxfEntity>(); foreach (var solidOp in element.Representation.SolidOperations) { list.AddRange(solidOp.ToDxfEntities(element.Transform)); } return(list); }
public void ThrowsExceptionWhenCreatingMeshFromElementWithNoRepresentation() { var empty = new GeometricElement(new Transform(), BuiltInMaterials.Default, null, false, System.Guid.NewGuid(), ""); Assert.Throws <ArgumentNullException>(() => empty.ToMesh()); }
public bool BakeElement ( IDictionary <DB.ElementId, Guid> idMap, bool overwrite, RhinoDoc doc, ObjectAttributes att, out Guid guid ) { // 1. Check if is already cloned if (idMap.TryGetValue(Id, out guid)) { return(true); } // 3. Update if necessary if (Value is DB.FamilySymbol element) { using (var options = new DB.Options() { DetailLevel = DB.ViewDetailLevel.Fine }) { using (var context = GeometryDecoder.Context.Push()) { context.Element = element; context.GraphicsStyleId = element.Category?.GetGraphicsStyle(DB.GraphicsStyleType.Projection)?.Id ?? DB.ElementId.InvalidElementId; context.MaterialId = element.Category?.Material?.Id ?? DB.ElementId.InvalidElementId; using (var geometry = element.GetGeometry(options)) { if (geometry is DB.GeometryElement geometryElement) { if (GeometricElement.BakeGeometryElement(idMap, overwrite, doc, att, Transform.Identity, element, geometry, out var idefIndex)) { guid = doc.InstanceDefinitions[idefIndex].Id; } } if (guid != Guid.Empty) { idMap.Add(Id, guid); return(true); } } } } } return(false); }
private static IfcBuildingElementProxy ToIfc(this GeometricElement element, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var proxy = new IfcBuildingElementProxy(IfcGuid.ToIfcGuid(id), null, null, null, null, localPlacement, shape, null, IfcBuildingElementProxyTypeEnum.ELEMENT); return(proxy); }
private static IfcBuildingElementProxy ToIfc(this GeometricElement element, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var proxy = new IfcBuildingElementProxy(IfcGuid.ToIfcGuid(id), null, element.Name, $"A {element.GetType().Name} created in Hypar.", $"{element.GetType().FullName}", localPlacement, shape, null, IfcBuildingElementProxyTypeEnum.ELEMENT); return(proxy); }
public void CreateLaminaWithHoles() { Name = nameof(CreateLaminaWithHoles); var profile = new Profile(Polygon.Rectangle(15, 15), Polygon.Star(7, 4, 5)); var geoElem = new GeometricElement( new Transform(), BuiltInMaterials.XAxis, new Representation(new[] { new Lamina(profile) }), false, Guid.NewGuid(), "Planar Shape Test"); Model.AddElement(geoElem); }
/// <summary> /// Construct an ArrayPlacementRule from closest points using a set of reference anchors. Each polyline vertex will be associated with its closest anchor. /// </summary> /// <param name="element">The element to array.</param> /// <param name="polyline">The array path.</param> /// <param name="spacingRule">The spacing configuration.</param> /// <param name="Anchors">The reference anchors from which to calculate the associations.</param> /// <param name="name">The rule name.</param> public static ArrayPlacementRule FromClosestPoints(GeometricElement element, Polyline polyline, SpacingConfiguration spacingRule, IList <Vector3> Anchors, string name) { var anchorIndices = new List <int>(); var anchorDisplacements = new List <Vector3>(); foreach (var v in polyline.Vertices) { var closestAnchorIndex = Enumerable.Range(0, Anchors.Count).OrderBy(a => Anchors[a].DistanceTo(v)).First(); anchorIndices.Add(closestAnchorIndex); var closestAnchor = Anchors[closestAnchorIndex]; anchorDisplacements.Add(v - closestAnchor); } return(new ArrayPlacementRule(element, polyline, spacingRule, anchorIndices, anchorDisplacements, name)); }
public void Difference() { this.Name = nameof(Difference); CreateTestSolids(out GeometricElement a, out GeometricElement b); var s = Solid.Difference(a.Representation.SolidOperations[0], b.Representation.SolidOperations[0]); Assert.Equal(15, s.Faces.Count); var i = new GeometricElement(null, BuiltInMaterials.Steel, new Representation(new List <SolidOperation> { new ConstructedSolid(s) })); this.Model.AddElement(i); }
private static void CreateTestSolids(out GeometricElement a, out GeometricElement b) { var r = new Transform(); r.Move(2.5, 2.5, 2.5); a = new Mass(Polygon.Rectangle(5, 5), 5); b = new Mass(new Circle(2.5).ToPolygon(19).TransformedPolygon(r), 5); a.UpdateRepresentations(); b.UpdateRepresentations(); var rotate = new Transform(); rotate.Rotate(Vector3.XAxis, 15); b.Representation.SolidOperations[0].LocalTransform = rotate; }
public void SolidIntersectsWithPlane() { this.Name = nameof(SolidIntersectsWithPlane); var n = 4; var outer = Polygon.Ngon(n, 2); var inner = Polygon.Ngon(n, 1.75).Reversed(); var profile = new Profile(outer, new[] { inner }); var sweep = new Extrude(profile, 5, Vector3.ZAxis, false); var plane1 = new Plane(new Vector3(0, 0, 1), new Vector3(0.5, 0.5, 0.5)); var plane2 = new Plane(new Vector3(0, 0, 2), new Vector3(0.1, 0, 1)); var plane3 = new Plane(new Vector3(0, 0, 5), Vector3.ZAxis); Plane[] planes = new Plane[] { plane1, plane2, plane3 }; var r = new Random(); foreach (var plane in planes) { if (sweep.Solid.Intersects(plane, out List <Polygon> result)) { if (result.Count > 1) { Assert.Equal(2, result.Count); var cutProfile = new Profile(result[0], result.Skip(1).ToArray()); var lam = new Lamina(cutProfile, false); var cutRep = new Representation(new List <SolidOperation>() { lam }); this.Model.AddElement(new GeometricElement(representation: cutRep, material: r.NextMaterial())); } else { Assert.Single(result); this.Model.AddElement(new Panel(result[0], r.NextMaterial())); } } } var rep = new Representation(new List <SolidOperation>() { sweep }); var solidElement = new GeometricElement(representation: rep, material: BuiltInMaterials.Mass); this.Model.AddElement(solidElement); }
public void CoplanarSolidFacesUnionCorrectly() { this.Name = nameof(CoplanarSolidFacesUnionCorrectly); var s1 = new Extrude(Polygon.Rectangle(2, 2), 2, Vector3.ZAxis, false); var s2 = new Extrude(Polygon.Rectangle(2, 2).TransformedPolygon(new Transform(new Vector3(1, 1))), 2, Vector3.ZAxis, false); var result = Solid.Union(s1._solid, null, s2._solid, null); var rep = new Representation(new List <SolidOperation>() { new ConstructedSolid(result) }); var solidElement = new GeometricElement(representation: rep); this.Model.AddElement(solidElement); this.Model.AddElements(DrawEdges(result, null)); Assert.Equal(10, result.Faces.Count); var t = new Transform(new Vector3(5, 0)); var result1 = Solid.Difference(s1._solid, t, s2._solid, t); var rep1 = new Representation(new List <SolidOperation>() { new ConstructedSolid(result1) }); var solidElement1 = new GeometricElement(representation: rep1); this.Model.AddElement(solidElement1); this.Model.AddElements(DrawEdges(result1, null)); Assert.Equal(8, result1.Faces.Count); var t1 = new Transform(new Vector3(10, 0)); var result2 = Solid.Intersection(s1._solid, t1, s2._solid, t1); var rep2 = new Representation(new List <SolidOperation>() { new ConstructedSolid(result2) }); var solidElement2 = new GeometricElement(representation: rep2); this.Model.AddElement(solidElement2); this.Model.AddElements(DrawEdges(result2, null)); Assert.Equal(6, result2.Faces.Count); }
public void CreateProfilesFromPolygons() { Name = nameof(CreateProfilesFromPolygons); var polygons = new List <Polygon> { Polygon.Rectangle(10, 10), Polygon.Star(4, 2, 5), Polygon.Ngon(3, 1), Polygon.Rectangle(new Vector3(6, -5), new Vector3(11, 0)) }; var profiles = Elements.Geometry.Profile.CreateFromPolygons(polygons); Assert.True(profiles.Count == 3, $"There were {profiles.Count} profiles, 3 expected."); var extrudes = profiles.Select(p => new Geometry.Solids.Extrude(p, 1, Vector3.ZAxis, false)); var rep = new Representation(new List <Geometry.Solids.SolidOperation>(extrudes)); var geoElem = new GeometricElement(new Transform(), BuiltInMaterials.Mass, rep, false, Guid.NewGuid(), null); Model.AddElement(geoElem); }
public void ImplicitRepresentationOperator() { Name = nameof(ImplicitRepresentationOperator); // implicitly convert single solid operation to a representation var element = new GeometricElement(new Transform(), BuiltInMaterials.ZAxis, new Extrude(Polygon.Rectangle(5, 5), 1, Vector3.ZAxis, false), false, Guid.NewGuid(), null); // params constructor for Representation var element2 = new GeometricElement( new Transform(), BuiltInMaterials.XAxis, new Representation( new Extrude(Polygon.Rectangle(7, 7), 1, Vector3.ZAxis, false), new Extrude(Polygon.Rectangle(6, 6), 2, Vector3.ZAxis, true) ), false, Guid.NewGuid(), null); Model.AddElements(element, element2); }
public void Csg() { this.Name = "Elements_Geometry_Csg"; var s1 = new Extrude(Polygon.Rectangle(Vector3.Origin, new Vector3(30, 30)), 50, Vector3.ZAxis, false); var s2 = new Extrude(Polygon.Rectangle(30, 30), 30, Vector3.ZAxis, true); var s3 = new Sweep(Polygon.Rectangle(Vector3.Origin, new Vector3(5, 5)), new Line(new Vector3(0, 0, 45), new Vector3(30, 0, 45)), 0, 0, 0, false); var poly = new Polygon(new List <Vector3>() { new Vector3(0, 0, 0), new Vector3(20, 50, 0), new Vector3(0, 50, 0) }); var s4 = new Sweep(poly, new Line(new Vector3(0, 30, 0), new Vector3(30, 30, 0)), 0, 0, 0, true); var geom = new GeometricElement(new Transform(), new Material("Mod", Colors.White, 0.0, 0.0, "./Textures/UV.jpg"), new Representation(new List <SolidOperation>() { s1, s2, s3, s4 }), false, Guid.NewGuid(), null); this.Model.AddElement(geom); }
public void ConstructedSolid() { GenerateIfc = false; Name = nameof(ConstructedSolid); var solid = new Solid(); var A = new Vector3(0, 0, 0); var B = new Vector3(1, 0, 0); var C = new Vector3(1, 1, 0); var D = new Vector3(0, 1, 0); var E = new Vector3(0, 0, 1); var F = new Vector3(1, 0, 1); var G = new Vector3(1, 1, 1); var H = new Vector3(0, 1, 1); solid.AddFace(new Polygon(new[] { A, B, C, D }), mergeVerticesAndEdges: true); solid.AddFace(new Polygon(new[] { E, F, G, H }), mergeVerticesAndEdges: true); solid.AddFace(new Polygon(new[] { A, B, F, E }), mergeVerticesAndEdges: true); solid.AddFace(new Polygon(new[] { B, C, G, F }), mergeVerticesAndEdges: true); solid.AddFace(new Polygon(new[] { C, D, H, G }), mergeVerticesAndEdges: true); solid.AddFace(new Polygon(new[] { D, A, E, H }), mergeVerticesAndEdges: true); var emptySolid = new ConstructedSolid(new Solid(), false); var import = new ConstructedSolid(solid, false); var representation = new Representation(new[] { import }); var emptyRep = new Representation(new[] { emptySolid }); var userElement = new GeometricElement(new Transform(), BuiltInMaterials.Default, representation, false, Guid.NewGuid(), "Import"); var userElementWithEmptySolid = new GeometricElement(new Transform(), BuiltInMaterials.Default, emptyRep, false, Guid.NewGuid(), "Import Empty"); Model.AddElement(userElement); Model.AddElement(userElementWithEmptySolid); // ensure serialized solid var modelJson = Model.ToJson(); var deserializedModel = Model.FromJson(modelJson); var userElemDeserialized = deserializedModel.GetElementByName <GeometricElement>("Import"); var opDeserialized = userElemDeserialized.Representation.SolidOperations.First(); var solidDeserialized = opDeserialized?.Solid; Assert.NotNull(solidDeserialized); }
public void TwoHoles() { this.Name = nameof(TwoHoles); var s1 = new Extrude(Polygon.Rectangle(2, 2), 2, Vector3.ZAxis, false); var s2 = new Extrude(Polygon.Rectangle(0.25, 0.25).TransformedPolygon(new Transform(new Vector3(0, 0.5))), 2.5, Vector3.ZAxis, false); var s3 = new Extrude(Polygon.Rectangle(0.25, 0.25).TransformedPolygon(new Transform(new Vector3(0, -0.5))), 2.5, Vector3.ZAxis, false); var result = Solid.Union(s2.Solid, null, s3.Solid, null); result = Solid.Difference(s1.Solid, null, result, null); var rep = new Representation(new List <SolidOperation>() { new ConstructedSolid(result) }); var solidElement = new GeometricElement(representation: rep); this.Model.AddElement(solidElement); this.Model.AddElements(DrawEdges(result, null)); Assert.Equal(14, result.Faces.Count); }
public void ConstructedSolidProducesValidGlb() { Name = nameof(ConstructedSolidProducesValidGlb); var allPolygons = JsonConvert.DeserializeObject <List <(Polygon outerLoop, List <Polygon> innerLoops)> >(File.ReadAllText("../../../models/Geometry/ExampleConstructedSolidPolygons.json")); var solid = new Solid(); foreach (var face in allPolygons) { solid.AddFace(face.outerLoop, face.innerLoops, true); } var solidOp = new Elements.Geometry.Solids.ConstructedSolid(solid, false); solidOp.LocalTransform = new Transform(); var geoElem = new GeometricElement(new Transform(), BuiltInMaterials.Concrete, new Representation(new[] { solidOp }), false, Guid.NewGuid(), null); var model = new Model(); model.AddElement(geoElem); var bytes = model.ToGlTF(); Assert.True(bytes != null && bytes.Length > 3000); Model.AddElement(geoElem); }
public void PassingHoleWithEqualFaces() { // The bottom face of a blind hole is inside the main solid, // but does not intersect with any of the faces of the main solid. // Ensure that the bottom face is not excluded. this.Name = nameof(PassingHoleWithEqualFaces); var s1 = new Extrude(Polygon.Rectangle(2, 2), 2, Vector3.ZAxis, false); var s2 = new Extrude(Polygon.Rectangle(0.5, 0.5).TransformedPolygon(new Transform(new Vector3(0, 0.8))), 2, Vector3.ZAxis, false); var result = Solid.Difference(s1.Solid, null, s2.Solid, null); var rep = new Representation(new List <SolidOperation>() { new ConstructedSolid(result) }); var solidElement = new GeometricElement(representation: rep); this.Model.AddElement(solidElement); this.Model.AddElements(DrawEdges(result, null)); Assert.Equal(10, result.Faces.Count); }