private void DrawSpot(out Entity drawnLight, out LeaderAndText lightName) { double distance, kl, kc, kq; kl = Light.LinearAttenuation; kc = Light.ConstantAttenuation; kq = Light.QuadraticAttenuation; // sets distance considering attenuation values of the light if (kq.CompareTo(0.0) != 0) { distance = (-kl + Math.Sqrt(kl * kl - 4 * kq * kc)) / (2 * kq); } else { distance = ((1 / 0.6) - kc) / kl; } // draws spot light like a cone drawnLight = Mesh.CreateCone(Math.Tan(Light.SpotHalfAngle) * distance, 0, distance, 10); drawnLight.ColorMethod = colorMethodType.byEntity; // Aligns the direction of spot to the light direction Transformation t = new Align3D(Plane.XY, new Plane(Light.Direction * -1)); drawnLight.Translate(0, 0, -distance); drawnLight.TransformBy(t); // translates the light spot to choosen position drawnLight.Translate(Light.Position.X, Light.Position.Y, Light.Position.Z); // draws name label lightName = new LeaderAndText(Light.Position, "Light " + NumLight, new Font("Tahoma", 8.25f), Color.White, new Vector2D(0, 15)); }
public static Transformation getPlacementTransformtion(IfcObjectPlacement obPL) { if (obPL is IfcLocalPlacement) { IfcLocalPlacement locPl = (IfcLocalPlacement)obPL; Plane pln = Conversion.getPlaneFromPosition((IfcPlacement)locPl.RelativePlacement); Align3D align = new Align3D(Plane.XY, pln); if (locPl.PlacementRelTo == null) { return(align); } else { return(getPlacementTransformtion(locPl.PlacementRelTo) * align); } } else if (obPL is IfcGridPlacement) { throw new Exception("IfcGridPlacement"); } return(null); }
public void Draw(Model model) { Point3D origin; Vector3D camX, camY, camZ; Camera.GetFrame(out origin, out camX, out camY, out camZ); if (origin != null) { // Draws the View Volume Point3D[] pts = new Point3D[24]; int count = 0; for (int i = 0; i < 4; i++) { pts[count++] = pNear[i]; pts[count++] = pNear[(i + 1) % 4]; pts[count++] = pFar[(i + 1) % 4]; pts[count++] = pFar[i]; pts[count++] = origin; pts[count++] = pNear[(i + 1) % 4]; } LinearPath lp1 = new LinearPath(pts); lp1.Color = Color.Gray; lp1.ColorMethod = colorMethodType.byEntity; model.Entities.Add(lp1, LayerName); //Draws the Camera const double widthB = 3, heightB = 5, depthB = 3, heightC = widthB / 2, radiusC = 1.5; Mesh cone = Mesh.CreateCone(radiusC, radiusC / 2, heightC, 10); cone.ColorMethod = colorMethodType.byEntity; cone.Color = Color.GreenYellow; Mesh box = Mesh.CreateBox(widthB, depthB, heightB); box.ColorMethod = colorMethodType.byEntity; box.Color = Color.GreenYellow; // centers the box to the world origin box.Translate(-widthB / 2, -depthB / 2, +heightC); // Aligns the Camera to the Camera view Transformation t = new Align3D(Plane.XY, new Plane(origin, camX, camY)); box.TransformBy(t); cone.TransformBy(t); model.Entities.Add(cone, LayerName); model.Entities.Add(box, LayerName); } }
public static Entity getEntityFromIfcRepresentationItem(IfcRepresentationItem reprItem, ViewportLayout viewportLayout1 = null, Transformation entityTrs = null) { Entity result = null; if (reprItem is IfcBooleanClippingResult) { IfcBooleanClippingResult bcr = (IfcBooleanClippingResult)reprItem; result = getSolidFromIfcBooleanClippingResult(bcr); } else if (reprItem is IfcCurve) { result = (Entity)getICurveFromIfcCurve((IfcCurve)reprItem, viewportLayout1, entityTrs); } else if (reprItem is IfcExtrudedAreaSolid) { IfcExtrudedAreaSolid extrAreaSolid = (IfcExtrudedAreaSolid)reprItem; // if (!viewportLayout1.Blocks.ContainsKey(extrAreaSolid.Index.ToString())) { Plane pln = Conversion.getPlaneFromPosition(extrAreaSolid.Position); Align3D align = new Align3D(Plane.XY, pln); IfcDirection dir = extrAreaSolid.ExtrudedDirection; Vector3D extDir = new Vector3D(dir.DirectionRatioX, dir.DirectionRatioY, dir.DirectionRatioZ); //extDir.TransformBy(trs * align2); extDir.TransformBy(align); devDept.Eyeshot.Entities.Region region = getRegionFromIfcProfileDef(extrAreaSolid.SweptArea, viewportLayout1); if (region != null) { //region.TransformBy(trs * align2); region.TransformBy(align); result = region.ExtrudeAsMesh(extDir * extrAreaSolid.Depth, 0.1, Mesh.natureType.Plain); // 0.1 tolerance must be computed according to object size //viewportLayout1.Entities.Add(result, 1); //Block b = new Block(); //b.Entities.Add(m); //viewportLayout1.Blocks.Add(extrAreaSolid.Index.ToString(), b); } } // BlockReference br = new IfcBlockReference(trs, extrAreaSolid.Index.ToString()); // viewportLayout1.Entities.Add(br, 0, Color.Gray); } else if (reprItem is IfcFaceBasedSurfaceModel) { IfcFaceBasedSurfaceModel fbs = (IfcFaceBasedSurfaceModel)reprItem; result = new Mesh(0, 0, Mesh.natureType.Plain); foreach (IfcConnectedFaceSet cfs in fbs.FbsmFaces) { Mesh global = new Mesh(0, 0, Mesh.natureType.Plain); foreach (IfcFace face in cfs.CfsFaces) { Point3D[] outerPoints = null; List <Point3D[]> innerPointsList = new List <Point3D[]>(); foreach (IfcFaceBound fb in face.Bounds) // al massimo 2 ? profilo esterno e interno { // bool sense = ifb.mOrientation; if (fb is IfcFaceOuterBound) { IfcFaceOuterBound ifob = (IfcFaceOuterBound)fb; IfcPolyloop pl = (IfcPolyloop)fb.Bound; List <Point3D> pLIst = new List <Point3D>(); for (int i = 0; i < pl.Polygon.Count; i++) { Point3D p = getPoint3DFromIfcCartesianPoint(pl.Polygon[i]); if (!pLIst.Contains(p)) // non copio punti uguali !! { pLIst.Add(p); } } outerPoints = pLIst.ToArray(); if (!outerPoints[0].Equals(outerPoints[outerPoints.Length - 1])) { Array.Resize(ref outerPoints, outerPoints.Length + 1); outerPoints[outerPoints.Length - 1] = (Point3D)outerPoints[0].Clone(); } Array.Reverse(outerPoints); } else { IfcFaceBound ifb = (IfcFaceBound)fb; IfcPolyloop inPl = (IfcPolyloop)ifb.Bound; List <Point3D> pLIst = new List <Point3D>(); for (int i = 0; i < inPl.Polygon.Count; i++) { Point3D p = getPoint3DFromIfcCartesianPoint(inPl.Polygon[i]); if (!pLIst.Contains(p)) // non copio punti uguali !! { pLIst.Add(p); } } Point3D[] innerPoints = pLIst.ToArray(); if (!innerPoints[0].Equals(innerPoints[innerPoints.Length - 1])) { Array.Resize(ref innerPoints, innerPoints.Length + 1); innerPoints[innerPoints.Length - 1] = (Point3D)innerPoints[0].Clone(); } Array.Reverse(innerPoints); innerPointsList.Add(innerPoints); } } if (outerPoints.Length > 3) { Mesh local; List <LinearPath> boundLp = new List <LinearPath>(); boundLp.Add(new LinearPath(outerPoints)); foreach (Point3D[] innerPoints in innerPointsList) { boundLp.Add(new LinearPath(innerPoints)); } local = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()).ConvertToMesh(0, Mesh.natureType.Plain); global.MergeWith(local, true); // fonde i vertici, sarebbe meglio farla una volta sola alla fine } } ((Mesh)result).MergeWith(global, true); } } else if (reprItem is IfcFacetedBrep) //controllare { IfcFacetedBrep facBrep = (IfcFacetedBrep)reprItem; IfcClosedShell cs = facBrep.Outer; Mesh global = new Mesh(0, 0, Mesh.natureType.Plain); foreach (IfcFace face in cs.CfsFaces) { Point3D[] outerPoints = null; List <Point3D[]> innerPointsList = new List <Point3D[]>(); foreach (IfcFaceBound fb in face.Bounds) { // bool sense = ifb.mOrientation; if (fb is IfcFaceOuterBound) { IfcFaceOuterBound ifob = (IfcFaceOuterBound)fb; IfcPolyloop pl = (IfcPolyloop)fb.Bound; List <Point3D> pLIst = new List <Point3D>(); for (int i = 0; i < pl.Polygon.Count; i++) { Point3D p = getPoint3DFromIfcCartesianPoint(pl.Polygon[i]); if (!pLIst.Contains(p)) // non copio punti uguali !! { pLIst.Add(p); } } outerPoints = pLIst.ToArray(); if (!outerPoints[0].Equals(outerPoints[outerPoints.Length - 1])) { Array.Resize(ref outerPoints, outerPoints.Length + 1); outerPoints[outerPoints.Length - 1] = (Point3D)outerPoints[0].Clone(); } Array.Reverse(outerPoints); } else { IfcFaceBound ifb = (IfcFaceBound)fb; IfcPolyloop inPl = (IfcPolyloop)ifb.Bound; List <Point3D> pLIst = new List <Point3D>(); for (int i = 0; i < inPl.Polygon.Count; i++) { Point3D p = getPoint3DFromIfcCartesianPoint(inPl.Polygon[i]); if (!pLIst.Contains(p)) // non copio punti uguali !! { pLIst.Add(p); } } Point3D[] innerPoints = pLIst.ToArray(); if (!innerPoints[0].Equals(innerPoints[innerPoints.Length - 1])) { Array.Resize(ref innerPoints, innerPoints.Length + 1); innerPoints[innerPoints.Length - 1] = (Point3D)innerPoints[0].Clone(); } Array.Reverse(innerPoints); innerPointsList.Add(innerPoints); } } if (outerPoints.Length > 3) { Mesh local; List <LinearPath> boundLp = new List <LinearPath>(); boundLp.Add(new LinearPath(outerPoints)); foreach (Point3D[] innerPoints in innerPointsList) { boundLp.Add(new LinearPath(innerPoints)); } local = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()).ConvertToMesh(0, Mesh.natureType.Plain); global.MergeWith(local, true); // fonde i vertici, sarebbe meglio farla una volta sola alla fine } } result = global; } //else if (repItem is IfcBoundingBox) //{ // IfcBoundingBox bBox = (IfcBoundingBox)iRep.Items[0]; // m = Mesh.CreateBox(bBox.XDim, bBox.YDim, bBox.ZDim); // m.Translate(bBox.Corner.Coordinates.Item1, bBox.Corner.Coordinates.Item1, bBox.Corner.Coordinates.Item1); //} else if (reprItem is IfcMappedItem) { IfcMappedItem mapItem = (IfcMappedItem)reprItem; if (!viewportLayout1.Blocks.ContainsKey("MappingSource " + mapItem.MappingSource.Index.ToString())) { IfcRepresentationMap reprMapSource = mapItem.MappingSource; Entity mapSource = getEntityFromIfcRepresentation(reprMapSource.MappedRepresentation, viewportLayout1, entityTrs); Block b = new Block(); if (mapSource != null) { Plane pln = getPlaneFromPosition((IfcPlacement)reprMapSource.MappingOrigin); Align3D algn = new Align3D(Plane.XY, pln); mapSource.TransformBy(algn); b.Entities.Add(mapSource); } viewportLayout1.Blocks.Add("MappingSource " + mapItem.MappingSource.Index.ToString(), b); } IfcCartesianTransformationOperator3D iTrs = (IfcCartesianTransformationOperator3D)mapItem.MappingTarget; Point3D org = new Point3D(iTrs.LocalOrigin.Coordinates.Item1, iTrs.LocalOrigin.Coordinates.Item2, iTrs.LocalOrigin.Coordinates.Item3); Vector3D vectorX; if (iTrs.Axis1 != null) { vectorX = new Vector3D(iTrs.Axis1.DirectionRatioX, iTrs.Axis1.DirectionRatioY, iTrs.Axis1.DirectionRatioZ); } else { vectorX = new Vector3D(1, 0, 0); } vectorX = vectorX * iTrs.Scale; Vector3D vectorY; if (iTrs.Axis2 != null) { vectorY = new Vector3D(iTrs.Axis2.DirectionRatioX, iTrs.Axis2.DirectionRatioY, iTrs.Axis2.DirectionRatioZ); } else { vectorY = new Vector3D(0, 1, 0); } Vector3D vectorZ; if (iTrs.Axis1 != null) { vectorZ = new Vector3D(iTrs.Axis3.DirectionRatioX, iTrs.Axis3.DirectionRatioY, iTrs.Axis3.DirectionRatioZ); } else { vectorZ = new Vector3D(0, 0, 1); } if (iTrs is IfcCartesianTransformationOperator3DnonUniform) { IfcCartesianTransformationOperator3DnonUniform nut = (IfcCartesianTransformationOperator3DnonUniform)iTrs; vectorY = vectorY * nut.Scale2; vectorZ = vectorZ * nut.Scale3; } Transformation targetTrs = new Transformation(org, vectorX, vectorY, vectorZ); result = new IfcBlockReference(targetTrs, "MappingSource " + mapItem.MappingSource.Index.ToString()); } else if (reprItem is IfcShellBasedSurfaceModel) { IfcShellBasedSurfaceModel sbs = (IfcShellBasedSurfaceModel)reprItem; result = new Mesh(0, 0, Mesh.natureType.Plain); foreach (IfcShell cfs in sbs.SbsmBoundary) { Mesh global = new Mesh(0, 0, Mesh.natureType.Plain); foreach (IfcFace face in cfs.CfsFaces) { Point3D[] outerPoints = null; List <Point3D[]> innerPointsList = new List <Point3D[]>(); foreach (IfcFaceBound fb in face.Bounds) // al massimo 2 ? profilo esterno e interno { // bool sense = ifb.mOrientation; if (fb is IfcFaceOuterBound) { IfcFaceOuterBound ifob = (IfcFaceOuterBound)fb; IfcPolyloop pl = (IfcPolyloop)fb.Bound; List <Point3D> pLIst = new List <Point3D>(); for (int i = 0; i < pl.Polygon.Count; i++) { Point3D p = getPoint3DFromIfcCartesianPoint(pl.Polygon[i]); if (!pLIst.Contains(p)) // non copio punti uguali !! { pLIst.Add(p); } } outerPoints = pLIst.ToArray(); if (!outerPoints[0].Equals(outerPoints[outerPoints.Length - 1])) { Array.Resize(ref outerPoints, outerPoints.Length + 1); outerPoints[outerPoints.Length - 1] = (Point3D)outerPoints[0].Clone(); } Array.Reverse(outerPoints); } else { IfcFaceBound ifb = (IfcFaceBound)fb; IfcPolyloop inPl = (IfcPolyloop)ifb.Bound; List <Point3D> pLIst = new List <Point3D>(); for (int i = 0; i < inPl.Polygon.Count; i++) { Point3D p = getPoint3DFromIfcCartesianPoint(inPl.Polygon[i]); if (!pLIst.Contains(p)) // non copio punti uguali !! { pLIst.Add(p); } } Point3D[] innerPoints = pLIst.ToArray(); if (!innerPoints[0].Equals(innerPoints[innerPoints.Length - 1])) { Array.Resize(ref innerPoints, innerPoints.Length + 1); innerPoints[innerPoints.Length - 1] = (Point3D)innerPoints[0].Clone(); } Array.Reverse(innerPoints); innerPointsList.Add(innerPoints); } } if (outerPoints.Length > 3) { Mesh local; List <LinearPath> boundLp = new List <LinearPath>(); boundLp.Add(new LinearPath(outerPoints)); foreach (Point3D[] innerPoints in innerPointsList) { boundLp.Add(new LinearPath(innerPoints)); } //devDept.Eyeshot.Entities.Region localRegion = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()); //localRegion.TransformBy(entityTrs); //viewportLayout1.Entities.Add(localRegion, 1); local = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()).ConvertToMesh(0, Mesh.natureType.Plain); global.MergeWith(local, true); // fonde i vertici, sarebbe meglio farla una volta sola alla fine } } ((Mesh)result).MergeWith(global, true); } } else { if (!debug.Contains("IfcRepresentationItem not supported: " + reprItem.KeyWord)) { debug += "IfcRepresentationItem not supported: " + reprItem.KeyWord + "\n"; } } if (result != null) { Color color; if (tryGetColorFromIfcRepresentationItem(reprItem, out color)) { result.ColorMethod = colorMethodType.byEntity; result.Color = color; } else { result.ColorMethod = colorMethodType.byParent; } } return(result); }
public static devDept.Eyeshot.Entities.Region getRegionFromIfcProfileDef(IfcProfileDef ipd, ViewportLayout viewportLayout1) { devDept.Eyeshot.Entities.Region region = null; if (ipd is IfcCircleProfileDef) { IfcCircleProfileDef crProfDef = (IfcCircleProfileDef)ipd; region = new CircularRegion(crProfDef.Radius); } else if (ipd is IfcIShapeProfileDef) // IfcIShapeProfileDef and all derived from { IfcIShapeProfileDef shProfDef = (IfcIShapeProfileDef)ipd; double halfWidth = shProfDef.OverallWidth / 2; double halfDepth = shProfDef.OverallDepth / 2; LinearPath lp = new LinearPath(Plane.XY, new Point2D(-halfWidth, -halfDepth), new Point2D(halfWidth, -halfDepth), new Point2D(halfWidth, -halfDepth + shProfDef.FlangeThickness), new Point2D(shProfDef.WebThickness / 2, -halfDepth + shProfDef.FlangeThickness), new Point2D(shProfDef.WebThickness / 2, +halfDepth - shProfDef.FlangeThickness), new Point2D(halfWidth, +halfDepth - shProfDef.FlangeThickness), new Point2D(halfWidth, halfDepth), new Point2D(-halfWidth, halfDepth), new Point2D(-halfWidth, halfDepth - shProfDef.FlangeThickness), new Point2D(-shProfDef.WebThickness / 2, halfDepth - shProfDef.FlangeThickness), new Point2D(-shProfDef.WebThickness / 2, -halfDepth + shProfDef.FlangeThickness), new Point2D(-halfWidth, -halfDepth + shProfDef.FlangeThickness), new Point2D(-halfWidth, -halfDepth) ); region = new devDept.Eyeshot.Entities.Region(lp); } else if (ipd is IfcRectangleProfileDef) { IfcRectangleProfileDef recProfDef = (IfcRectangleProfileDef)ipd; region = new RectangularRegion(recProfDef.XDim, recProfDef.YDim, true); } else if (ipd is IfcArbitraryClosedProfileDef) { IfcArbitraryClosedProfileDef arProfDef = (IfcArbitraryClosedProfileDef)ipd; ICurve cc = getICurveFromIfcCurve(arProfDef.OuterCurve); if (cc != null) { //foreach(Entity xx in cc.CurveList) // viewportLayout1.Entities.Add((Entity)xx.Clone(), 1); //viewportLayout1.Entities.Add((Entity)cc.Clone(), 2); region = new devDept.Eyeshot.Entities.Region(cc); } } else { if (!debug.Contains("IfcProfileDef not supported: " + ipd.KeyWord)) { debug += "IfcProfileDef not supported: " + ipd.KeyWord + "\n"; } } if (ipd is IfcParameterizedProfileDef) { IfcParameterizedProfileDef parProfDef = (IfcParameterizedProfileDef)ipd; if (parProfDef.Position != null && region != null) { Plane plane = getPlaneFromPosition(parProfDef.Position); Align3D algn = new Align3D(Plane.XY, plane); region.TransformBy(algn); //region.Translate(parProfDef.Position.Location.Coordinates.Item1, parProfDef.Position.Location.Coordinates.Item2, parProfDef.Position.Location.Coordinates.Item3); } } return(region); }
private static Solid getSolidFromIfcBooleanClippingResult(IfcBooleanClippingResult bcr) { Solid op1 = null, op2 = null; Solid mmm = null; Entity e; if (bcr.FirstOperand is IfcBooleanClippingResult) { op1 = getSolidFromIfcBooleanClippingResult((IfcBooleanClippingResult)bcr.FirstOperand); } else { e = getEntityFromIfcRepresentationItem((IfcRepresentationItem)bcr.FirstOperand); if (e != null)// && (e is Solid || e is Mesh)) { if (e is Mesh) { op1 = ((Mesh)e).ConvertToSolid(); } else { op1 = (Solid)e; } } } //m = getMeshFromIfcRepresentationItem((IfcRepresentationItem)bcr.SecondOperand); //if (m != null) // op2 = m.ConvertToSolid(); if (bcr.SecondOperand is IfcPolygonalBoundedHalfSpace) { IfcPolygonalBoundedHalfSpace polB = (IfcPolygonalBoundedHalfSpace)bcr.SecondOperand; IfcPlane baseSurface = (IfcPlane)polB.BaseSurface; Plane cutPln = Conversion.getPlaneFromPosition(baseSurface.Position); devDept.Eyeshot.Entities.Region r = new RectangularRegion(cutPln, 100, 100, true); mmm = r.ExtrudeAsSolid(cutPln.AxisZ * 0.1, 0.1); Plane boundaryPlane = Conversion.getPlaneFromPosition(polB.Position); Align3D align = new Align3D(Plane.XY, boundaryPlane); ICurve boundary = getICurveFromIfcCurve(polB.PolygonalBoundary); if (boundary != null) { devDept.Eyeshot.Entities.Region region = new devDept.Eyeshot.Entities.Region(boundary); region.TransformBy(align); Vector3D extDir = boundaryPlane.AxisZ; op2 = region.ExtrudeAsSolid(extDir * 20, 0.1); // 0.1 tolerance must be computed according to object size if (!polB.AgreementFlag) { cutPln.Flip(); } op2.CutBy(cutPln); } } else if (bcr.SecondOperand is IfcHalfSpaceSolid) { IfcHalfSpaceSolid hs = (IfcHalfSpaceSolid)bcr.SecondOperand; IfcPlane ip = (IfcPlane)hs.BaseSurface; Plane pln = Conversion.getPlaneFromPosition(ip.Position); if (!hs.AgreementFlag) { pln.Flip(); } if (op1 != null) { op1.CutBy(pln); } return(op1); } if (op1 == null || op2 == null) { return(null); } //op1.TransformBy(trs); //op2.TransformBy(trs); //viewportLayout1.Entities.Add(op1, testLayer, Color.Red); //viewportLayout1.Entities.Add(op2, testLayer, Color.Blue); //return null; Solid[] result; double tolerance = 0.01; switch (bcr.Operator) { case IfcBooleanOperator.DIFFERENCE: result = Solid.Difference(op1, op2, tolerance); //su dll nuova e' possibile inserire parametro di tolleranza break; case IfcBooleanOperator.UNION: result = Solid.Union(op1, op2, tolerance); break; case IfcBooleanOperator.INTERSECTION: result = Solid.Intersection(op1, op2, tolerance); break; default: return(null); } //WriteSTL ws = new WriteSTL(new Entity[] { op1, op2, mmm }, new Layer[] { new Layer("Default") }, new Dictionary<string, Block>(), @"c:\devdept\booleanError\gino" + count + ".stl", 0.01, true); //count++; //ws.DoWork(); if (result != null) { return(result[0]); } else { WriteSTL ws = new WriteSTL(new Entity[] { op1, op2 }, new Layer[] { new Layer("Default") }, new Dictionary <string, Block>(), @"c:\devdept\booleanError\gino" + bcr.Index + ".stl", 0.01, true); count++; ws.DoWork(); debug += "Error in boolean operation\n"; return(op1); } }