public override void Run(RenderControl renderer) { var ellipse = SketchBuilder.MakeEllipse(GP.Origin(), 10, 5, GP.DX(), GP.DZ()); renderer.ShowShape(ellipse, Vector3.Blue); ParametricCurve pc = new ParametricCurve(ellipse); var paramsList = pc.SplitByUniformLength(1, 0.01); uint itemCount = (uint)paramsList.Count; var points = new ParticleSceneNode(itemCount, Vector3.Green, 5.0f); var lines = new SegmentsSceneNode(itemCount, Vector3.Red, 2); Random random = new Random(); for (int ii = 0; ii < paramsList.Count; ++ii) { var value = pc.D1(paramsList[ii]); var pos = value.GetPoint(); var dir = value.GetVectors()[0]; var end = new GPnt(pos.XYZ().Added(dir.XYZ())); lines.SetPositions((uint)ii, Vector3.From(pos), Vector3.From(end)); lines.SetColors((uint)ii, Vector3.Red, Vector3.From(random.NextDouble(), random.NextDouble(), random.NextDouble())); points.SetPosition((uint)ii, Vector3.From(pos)); } renderer.ShowSceneNode(points); renderer.ShowSceneNode(lines); }
GroupSceneNode CreateFrames(double width, double height, double deep, double radius) { var baseSketch = CreateSketch(radius, deep); //TopLeft var s11 = Project(baseSketch, new GPnt(0, 0, height), new GDir(-1, 0, -1), GP.DZ()); //BottomLeft var s20 = Project(baseSketch, GP.Origin(), new GDir(-1, 0, 1), GP.DZ()); //BottomRight var s12 = Project(s20, new GPnt(width, 0, 0), new GDir(1, 0, 1), GP.DX()); //TopRight var s21 = Project(s11, new GPnt(width, 0, height), new GDir(-1, 0, 1), GP.DX()); var frame1 = FeatureTool.Loft(s11, s20, false); var frame2 = FeatureTool.Loft(s20, s12, false); var frame3 = FeatureTool.Loft(s12, s21, false); var frame4 = FeatureTool.Loft(s21, s11, false); var frameMaterial = MeshStandardMaterial.Create("window-frame"); frameMaterial.SetColor(Vector3.LightGray); frameMaterial.SetMetalness(0.5f); frameMaterial.SetFaceSide(EnumFaceSide.DoubleSide); var group = new GroupSceneNode(); group.AddNode(BrepSceneNode.Create(frame1, frameMaterial, null)); group.AddNode(BrepSceneNode.Create(frame2, frameMaterial, null)); group.AddNode(BrepSceneNode.Create(frame3, frameMaterial, null)); group.AddNode(BrepSceneNode.Create(frame4, frameMaterial, null)); return(group); }
public override void Run(RenderControl renderer) { string fileName = GetResourcePath("Holes.stp"); var shape = StepIO.Open(fileName); if (shape == null) { return; } renderer.ShowShape(shape, Vector3.LightGray); var bbox = shape.GetBBox(); var shape2 = ShapeBuilder.MakeBox(new GAx2(bbox.CornerMax(), GP.DZ()), 100, 100, 10); renderer.ShowShape(shape2, Vector3.LightGray); ExtremaShapeShape ess = new ExtremaShapeShape(); if (!ess.Initialize(shape, shape2, 0.001)) { return; } var pt1 = ess.GetPointOnShape1(0); var pt2 = ess.GetPointOnShape2(0); var line = SketchBuilder.MakeLine(pt1, pt2); renderer.ShowShape(line, Vector3.Red); }
public override void Run(RenderControl render) { var sketch = SketchBuilder.MakeEllipse(GP.Origin(), 5, 3, GP.DX(), GP.DZ()); // 1. Sweep { GPntList points = new GPntList { GP.Origin(), new GPnt(20, 10, 30), new GPnt(50, 50, 50), }; var path = SketchBuilder.MakeBSpline(points); render.ShowShape(path, Vector3.Green); var feature = FeatureTool.Sweep(sketch, path, EnumGeomFillTrihedron.ConstantNormal); render.ShowShape(feature, Vector3.Blue); } // 2. Revol { var feature = FeatureTool.Revol(sketch, new GAx1(new GPnt(-20, 0, 0), GP.DY()), 90); render.ShowShape(feature, Vector3.Green); } // 3. Loft { var baseWire = SketchBuilder.MakeRectangle(new GAx2(new GPnt(50, -50, 0), GP.DZ()), 20, 20, 5, false); var topWire = SketchBuilder.MakeCircle(new GPnt(60, -40, 40), 5, GP.DZ()); var loft = FeatureTool.Loft(baseWire, topWire, true); render.ShowShape(loft, Vector3.Red); } }
public override void Run(RenderControl render) { var material = MeshStandardMaterial.Create("workpiece"); material.SetColor(new Vector3(0.9f)); material.SetFaceSide(EnumFaceSide.DoubleSide); var shape = ShapeBuilder.MakeCylinder(GP.YOZ(), 5, 50, 0); mWorkpiece = BrepSceneNode.Create(shape, material, null); render.ShowSceneNode(mWorkpiece); var coord = new GAx2(new GPnt(0, 0, 5), GP.DZ()); var toolShape = ShapeBuilder.MakeCone(coord, 0, 2, 5, 0); var toolNode = render.ShowShape(toolShape, ColorTable.Blue); render.ShowSceneNode(mMotionTrail); // Initialize Animation mAnimation = new RigidAnimation(); var rotation = Matrix4.makeRotationAxis(new Vector3(1, 0, 0), (float)Math.PI); var trf = Matrix4.makeTranslation(-50, 0, 0) * rotation; mAnimation.Add(new MatrixAnimationClip(mWorkpiece, mWorkpiece.GetTransform(), trf, 0, 10)); mAnimation.Add(new MatrixAnimationClip(toolNode, toolNode.GetTransform(), trf, 10, 15)); mAnimation.Add(new RotateAnimationClip(toolNode, Vector3.UNIT_Z, (float)Math.PI * 4, 16, 20)); }
public override void Run(RenderControl render) { // 1. Make face with a hole. var c1 = SketchBuilder.MakeCircle(GP.Origin(), 30, GP.DZ()); var c2 = SketchBuilder.MakeCircle(GP.Origin(), 100, GP.DZ()); var face = SketchBuilder.MakePlanarFace(c2); var face2 = SketchBuilder.MakePlanarFace(c1); var shape = BooleanTool.Cut(face, face2); //render.ShowShape(shape, ColorTable.Blue); var faces = shape.GetChildren(EnumTopoShapeType.Topo_FACE); // 2. Hatch the face. foreach (var item in faces) { HatchHatcher hh = new HatchHatcher(item); hh.Build(); var material = BasicMaterial.Create("line"); material.SetColor(new Vector3(0.5f, 0.5f, 1.0f)); var node = hh.Create(material); // 3. Show the hatching lines. render.ShowSceneNode(node); } }
public override void Run(RenderControl render) { RedMaterial = MeshPhongMaterial.Create("phong.color"); RedMaterial.SetColor(Vector3.Red); GrayMaterial = MeshPhongMaterial.Create("phong.color"); GrayMaterial.SetColor(Vector3.LightGray); GrayMaterial.SetTransparent(true); GrayMaterial.SetOpacity(0.5f); var tube = ShapeBuilder.MakeTube(new GPnt(0, 0, 5), GP.DZ(), 10, 2, 50); TubeNode = BrepSceneNode.Create(tube, RedMaterial, null); var cylinder = ShapeBuilder.MakeCylinder(GP.XOY(), 10, 60, 0); CylinderNode = BrepSceneNode.Create(cylinder, GrayMaterial, null); render.ShowSceneNode(TubeNode); render.ShowSceneNode(CylinderNode); var cone = ShapeBuilder.MakeCone(GP.YOZ(), 5, 0, 10, 0); var bs = new BufferShape(cone, RedMaterial, null, 0.1); bs.Build(); ConeNode1 = new BrepSceneNode(bs); ConeNode2 = new BrepSceneNode(bs); render.ShowSceneNode(ConeNode1); render.ShowSceneNode(ConeNode2); }
public override void Run(RenderControl render) { var material = MeshStandardMaterial.Create("workpiece"); material.SetColor(new Vector3(0.9f)); material.SetFaceSide(EnumFaceSide.DoubleSide); var shape = ShapeBuilder.MakeCylinder(GP.YOZ(), 5, 50, 0); mWorkpiece = BrepSceneNode.Create(shape, material, null); render.ShowSceneNode(mWorkpiece); { var coord = new GAx2(new GPnt(0, 0, 5), GP.DZ()); var toolShape = ShapeBuilder.MakeCone(coord, 0, 2, 5, 0); render.ShowShape(toolShape, Vector3.Blue); } render.ShowSceneNode(mMotionTrail); mLength = 0; mTheta = 0; }
public override void Run(RenderControl render) { var rect1 = SketchBuilder.MakeRectangle(GP.XOY(), 10, 5, 1, true); var rect2 = SketchBuilder.MakeRectangle(new GAx2(new GPnt(1, 1, 0), GP.DZ(), GP.DX()), 8, 3, 1, true); var cut = BooleanTool.Cut(rect1, rect2); var extrude = FeatureTool.Extrude(cut, 100, GP.DZ()); render.ShowShape(extrude, Vector3.Blue); }
public override void Run(RenderControl render) { var deep = 8.0f; var radius = 6; var width = 100; var frameNode = CreateFrames(width, 50, deep, 6); render.ShowSceneNode(frameNode); var ax = new GAx2(new GPnt(radius, (deep - 2) / 2, radius), GP.DZ()); var glass = CreateGlass(ax, width - radius * 2, 50 - radius * 2, 2); render.ShowSceneNode(glass); var dim = new AlignedDimensionNode(new Vector3(0, deep * 0.5f, 0), new Vector3(width, deep * 0.5f, 0), -10, new Vector3(0, -1, 0), "100"); dim.Update(); render.ShowSceneNode(dim); }
public override void Run(RenderControl render) { var line = SketchBuilder.MakeLine(new GPnt(10, 10, 10), new GPnt(-10, -10, -10)); render.ShowShape(line, new Vector3(1, 1, 0)); var ellips = SketchBuilder.MakeEllipse(GP.Origin(), 10, 5, GP.DX(), GP.DZ()); render.ShowShape(ellips, Vector3.Blue); var circle = SketchBuilder.MakeCircle(GP.Origin(), 4, new GDir(0, 1, 0)); render.ShowShape(circle, Vector3.Green); var arc = SketchBuilder.MakeArcOfCircle(GP.Origin(), new GPnt(50, 0, 50), new GPnt(20, 0, 40)); render.ShowShape(arc, Vector3.Red); var rect = SketchBuilder.MakeRectangle(GP.XOY(), 30, 40, 5, false); render.ShowShape(rect, Vector3.Green); }
public override void Run(RenderControl render) { string filepathp = GetResourcePath(@"data\blade_p.dat"); // p侧字符型数据 string[] data_p = File.ReadAllLines(filepathp, Encoding.Default); // 1行 2401列, string filepaths = GetResourcePath(@"data\blade_s.dat"); // s侧字符型数据 string[] data_s = File.ReadAllLines(filepaths, Encoding.Default); // // p侧的曲线 double[,] curvee = new double[(data_p.GetUpperBound(data_p.Rank - 1) + 1), 3]; //建立数组,n行3列, for (int i = 0; i < (data_p.GetUpperBound(data_p.Rank - 1) + 1); i++) // { data_p[i].Split(); string[] split = data_p[i].Split(new Char[] { ' ' }); curvee[i, 0] = double.Parse(split[0]); curvee[i, 1] = double.Parse(split[1]); curvee[i, 2] = double.Parse(split[2]); } // // s侧的曲线, double[,] curvee1 = new double[(data_p.GetUpperBound(data_p.Rank - 1) + 1), 3]; //建立数组,n行3列, for (int i = 0; i < (data_p.GetUpperBound(data_p.Rank - 1) + 1); i++) // { data_s[i].Split(); string[] split = data_s[i].Split(new Char[] { ' ' }); curvee1[i, 0] = double.Parse(split[0]); curvee1[i, 1] = double.Parse(split[1]); curvee1[i, 2] = double.Parse(split[2]); } int n_jie = (int)curvee1[0, 1]; // 截面数 int n_points = (int)curvee1[0, 0]; // 点数 // topolist TopoShapeList spline = new TopoShapeList(); //进行拓扑list的生成, for (int nn = 0; nn < n_jie; nn++) // 循环截面数, { //int nn = 0; GPntList points = new GPntList(); // s侧 for (int mm = nn * n_points + 1; mm < (nn + 1) * n_points; mm++) // 循环截面所对应的点数范围, { GPnt P0 = new GPnt(curvee[mm, 0], curvee[mm, 1], curvee[mm, 2]); // 需要进行添加的点, points.Add(P0); } // p侧 for (int mm = (nn + 1) * n_points; mm > nn * n_points + 1; mm--) // 循环截面所对应的点数范围, { GPnt P0 = new GPnt(curvee1[mm, 0], curvee1[mm, 1], curvee1[mm, 2]); // 需要进行添加的点, points.Add(P0); } // var quxian = SketchBuilder.MakePolygon(points, true); //生成拓扑, var quxian = SketchBuilder.MakeBSpline(points, true); //mRenderView.ShowShape(quxian, Vector3.Red); spline.Add(quxian); } var shape = FeatureTool.Loft(spline, true, false); //创建一个体进行布尔运算 GPntList points_shroud = new GPntList(); GPnt P10 = new GPnt(170, 0, 0); GPnt P11 = new GPnt(170, 0, 200); GPnt P12 = new GPnt(250, 0, 200); GPnt P13 = new GPnt(250, 0, 0); points_shroud.Add(P10); points_shroud.Add(P11); points_shroud.Add(P12); points_shroud.Add(P13); var quxian1 = SketchBuilder.MakePolygon(points_shroud, true); var face = SketchBuilder.MakePlanarFace(quxian1); var feature = FeatureTool.Revol(face, new GAx1(new GPnt(0, 0, 0), GP.DZ()), 0); var cut = BooleanTool.Cut(shape, feature); // 求差 保留前面的一个 if (cut != null) { render.ShowShape(cut, Vector3.Green); } //var cut2 = BooleanTool.Cut(feature, shape); //if (cut2 != null) // render.ShowShape(cut2, Vector3.Blue); }
public override void Run(RenderControl render) { var baseSketch = SketchBuilder.MakeRectangle(GP.XOY(), 10, 20, 2, false); // project to plane var topSketch = ProjectionTool.ProjectOnPlane(baseSketch, new GPnt(0, 0, 30), new GDir(0, -0.5, 0.5), GP.DZ()); // make loft var shape = FeatureTool.Loft(baseSketch, topSketch, true); render.ShowShape(shape, ColorTable.Green); }
public override void Run(RenderControl render) { var path = SketchBuilder.MakeArcOfCircle(new GPnt(0, 0, 0), new GPnt(10, 0, 10), new GPnt(5, 0, 8)); var baseSketch = SketchBuilder.MakeRectangle(new GAx2(new GPnt(-5, -10, 0), GP.DZ(), GP.DX()), 10, 20, 2, false); var topSketch = SketchBuilder.MakeCircle(new GPnt(10, 0, 10), 5, GP.DX()); var shapeList = new TopoShapeList(); shapeList.Add(baseSketch); shapeList.Add(topSketch); var shape = FeatureTool.SweepByFrenet2(shapeList, path, EnumSweepTransitionMode.RoundCorner, true); render.ShowShape(shape, ColorTable.Beige); }
public override void Run(RenderControl render) { var material = MeshStandardMaterial.Create("my-material"); material.SetRoughness(0.75f); material.SetMetalness(0.1f); material.SetColor(ColorTable.Hex(0xFFC107)); for (uint ii = 0; ii < 10; ++ii) { TopoShape shape = ShapeBuilder.MakePyramid(new GAx2(new GPnt(ii * 11, 0, 0), GP.DZ()), ii + 3, 5, 5 + ii); var node = BrepSceneNode.Create(shape, material, null); render.ShowSceneNode(node); } //var bottom = SketchBuilder.MakeRectangle(GP.XOY(), 10, 20, 2, false); //var shape2 = FeatureTool.Loft(bottom, new GPnt(5, 10, 10)); //render.ShowShape(shape2, ColorTable.Blue); //var shape3 = ShapeBuilder.MakeCone(GP.XOY(), 10, 0, 10, 0); //render.ShowShape(shape3, ColorTable.Blue); }