public override void Run(RenderControl renderer) { var shape = ShapeBuilder.MakeSphere(new GPnt(), 1); var bufferShape = new BufferShape(shape, null, null, 0.1); bufferShape.Build(); float distance = 3.0f; int halfCount = 5; var scene = renderer.GetScene(); for (int ii = -halfCount; ii < halfCount; ++ii) { for (int jj = -halfCount; jj < halfCount; ++jj) { for (int kk = -halfCount; kk < halfCount; ++kk) { var node = new BrepSceneNode(bufferShape); node.SetTransform(Matrix4.makeTranslation(ii * distance, jj * distance, kk * distance)); scene.AddNode(node); } } } renderer.ZoomAll(); Matrix4 m1 = new Matrix4(1); Matrix4 m2 = new Matrix4(1); Matrix4 x = m1 * m2; }
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 renderer) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "IGES (*.igs;*.iges)|*.igs;*.iges|STEP (*.stp;*.step)|*.stp;*.step|Brep (*.brep)|*.brep"; if (dialog.ShowDialog() != DialogResult.OK) { return; } var shape = ShapeIO.Open(dialog.FileName); if (shape == null) { return; } var bs = new BufferShape(shape, null, null, 0); bs.Build(); // 1. Compute var holeExp = new HoleExplor(); if (!holeExp.Initialize(bs)) { return; } var dir = holeExp.ComputeDirection(); holeExp.Compute(dir); var defaultMaterial = MeshPhongMaterial.Create("face-x"); defaultMaterial.SetFaceSide(EnumFaceSide.DoubleSide); bs.SetFaceMaterial(defaultMaterial); // 2. Set hole faces with red color var material = BasicMaterial.Create("hole-face"); material.SetFaceSide(EnumFaceSide.DoubleSide); material.SetColor(new Vector3(0.5f, 0, 0)); var holeNumber = holeExp.GetHoleCount(); for (uint ii = 0; ii < holeNumber; ++ii) { var faceIDs = holeExp.GetHoleFaces(ii); foreach (var faceIdx in faceIDs) { bs.SetFaceMaterial(faceIdx, material); } } // 2. Show the faces var shapeNode = new BrepSceneNode(bs); renderer.ShowSceneNode(shapeNode); }
public override void Run(RenderControl render) { var material = MeshStandardMaterial.Create("metal-double"); material.SetColor(new Vector3(1.0f, 0.8f, 0.0f)); material.SetMetalness(0.8f); material.SetRoughness(0.5f); material.SetFaceSide(EnumFaceSide.DoubleSide); var startPt = new GVec(0, 100, 0); var points = new GPntList(); points.Add(new GPnt(startPt.XYZ())); points.Add(new GPnt(startPt.Added(new GVec(0, 0, 150)).XYZ())); points.Add(new GPnt(startPt.Added(new GVec(0, 100, 150)).XYZ())); points.Add(new GPnt(startPt.Added(new GVec(-100, 100, 150)).XYZ())); points.Add(new GPnt(startPt.Added(new GVec(-100, 300, 150)).XYZ())); points.Add(new GPnt(startPt.Added(new GVec(100, 300, 150)).XYZ())); TopoShape path = SketchBuilder.MakePolygon(points, false); var sectionList = new TopoShapeList(); GAx2 coord1 = new GAx2(new GPnt(startPt.Added(new GVec(-25, -25, 0)).XYZ()), GP.DY()); TopoShape section1 = SketchBuilder.MakeRectangle(coord1, 50, 50, 10, false); render.ShowShape(section1, ColorTable.Red); render.ShowShape(path, ColorTable.Green); TopoShape pipe = FeatureTool.SweepByFrenet(section1, path, EnumSweepTransitionMode.RoundCorner, false); BufferShape bs = new BufferShape(pipe, material, null, 0.1f); bs.Build(); var node = new BrepSceneNode(bs); render.ShowSceneNode(node); }
public override void Run(RenderControl render) { //1. Create Shape TopoShapeList tg = new TopoShapeList(); GPntList points = new GPntList(); using (var sr = new StreamReader(GetResourcePath("data/Stage4_Rotor4_Profile.curve"))) { string line; while ((line = sr.ReadLine()) != null) { if (line.StartsWith("# Profile")) { if (points.Count > 0) { var temp2 = SketchBuilder.MakeBSpline(points); if (temp2 != null) { tg.Add(temp2); } } points = new GPntList(); } else { var temp = line.Split('\t'); points.Add(new GPnt(double.Parse(temp[0]), double.Parse(temp[1]), double.Parse(temp[2]))); } } } var shape = FeatureTool.Loft(tg, true, true); //2. Compute Curvature var material = BasicMaterial.Create("vertex-color"); material.SetVertexColors(true); material.SetFaceSide(EnumFaceSide.DoubleSide); var bs = new BufferShape(shape, material, null, 0.01f); bs.Build(); ColorLookupTable clt = new ColorLookupTable(); clt.SetColorMap(ColorMapKeyword.Create(EnumSystemColorMap.Rainbow)); float scale = 100; clt.SetMinValue(-0.2f * scale); clt.SetMaxValue(scale); for (uint ii = 0; ii < bs.GetFaceCount(); ++ii) { var sc = new SurfaceCurvature(bs); if (sc.Compute(ii, EnumCurvatureType.MeanCurvature)) { Console.WriteLine("{0}, {1}", sc.GetMinValue(), sc.GetMaxValue()); var colorBuffer = sc.ComputeColors(clt, scale); bs.SetVertexColors(ii, colorBuffer); } } // 3. Show it! var node = new BrepSceneNode(bs); render.ShowSceneNode(node); }