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);
        }
Ejemplo n.º 2
0
        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 render)
        {
            var paramCurve = Sketch2dBuilder.MakeLine(new GPnt2d(0, 0), new GPnt2d(Math.PI * 20, 20));

            // curve one cone
            {
                var cone               = ShapeBuilder.MakeCone(GP.XOY(), 1, 10, 20, 0);
                var coneFace           = cone.FindChild(EnumTopoShapeType.Topo_FACE, 0);
                var curveOnConeSurface = SketchBuilder.MakeCurveOnSurface(paramCurve, coneFace);

                var material = LineDashedMaterial.Create("my.dashed.material");
                material.SetColor(ColorTable.Hex(0x0FFAA));
                var node = BrepSceneNode.Create(curveOnConeSurface, null, material);
                node.ComputeLineDistances(); // Enable dashed line style.

                render.ShowSceneNode(node);
            }
            // curve one cylinder
            {
                var cylinder     = ShapeBuilder.MakeCylinder(GP.XOY(), 2, 20, 0);
                var cylinderFace = cylinder.FindChild(EnumTopoShapeType.Topo_FACE, 0);

                var curveOnCylinderSurface = SketchBuilder.MakeCurveOnSurface(paramCurve, cylinderFace);

                var node2 = BrepSceneNode.Create(curveOnCylinderSurface, null, null);
                render.ShowSceneNode(node2);
            }
        }
Ejemplo n.º 4
0
        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)
        {
            PrepareMaterials();

            //1. Load part models of the robot.
            List <string> files = new List <string>();

            files.Add("Base.brep");
            files.Add("AXIS1.brep");
            files.Add("AXIS2.brep");
            files.Add("AXIS3.brep");
            files.Add("AXIS4.brep");
            files.Add("AXIS5.brep");
            files.Add("AXIS6.brep");

            var rootPath = GetResourcePath(@"models\6R\");

            List <BrepSceneNode> links = new List <BrepSceneNode>();

            for (int ii = 0; ii < files.Count; ++ii)
            {
                var shape = ShapeIO.Open(rootPath + files[ii]);
                if (shape == null)
                {
                    return;
                }

                links.Add(BrepSceneNode.Create(shape, mRobotMaterial, null, 0.1));
            }

            //2. Create the arm
            mRobot.AddJoint(EnumRobotJointType.Fixed, 0, 0, 200, 0);
            mRobot.AddJoint(EnumRobotJointType.Revolute, 0, 0, 130, 0);                               // Link1
            mRobot.AddJoint(EnumRobotJointType.Revolute, 90, 30, 0, 180, new RobotDH(90, 0, 480, 0)); // Link2
            mRobot.AddJoint(EnumRobotJointType.Revolute, 90, 0, 0, 270, new RobotDH(90, 0, 100, 0));  // Link3
            mRobot.AddJoint(EnumRobotJointType.Revolute, 0, 0, 380, 0);                               // Link4
            mRobot.AddJoint(EnumRobotJointType.Revolute, 270, 0, 0, 0);                               // Link5
            mRobot.AddJoint(EnumRobotJointType.Revolute, 90, 0, 100, 0);                              // Link6

            for (int ii = 0; ii < 7; ++ii)
            {
                mRobot.AddLink((uint)ii, links[ii]);
            }

            mRobot.ResetInitialState();

            //3. Show it.
            render.ShowSceneNode(mRobot);

            render.ShowSceneNode(mMotionTrail);

            // 4. Enable animation
            mRobotAnimation = new RobotAnimation(mRobot);
            mRobotAnimation.AddClip(new RobotAnimationClip(1, 0, 90, 0, 5));
            mRobotAnimation.AddClip(new RobotAnimationClip(2, 180, 270, 0, 5));
            mRobotAnimation.AddClip(new RobotAnimationClip(3, 270, 360, 0, 5));

            mRobotAnimation.AddClip(new RobotAnimationClip(2, 270, 90, 5, 15));
            mRobotAnimation.AddClip(new RobotAnimationClip(3, 360, 90, 5, 15));
        }
        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)
        {
            Random   rand   = new Random();
            GPntList points = new GPntList();

            for (int ii = 0; ii < 5; ++ii)
            {
                for (int jj = 0; jj < 5; ++jj)
                {
                    points.Add(new GPnt(ii, jj, rand.NextDouble()));
                }
            }

            var surf = SurfaceBuilder.PointsToBSplineSurface(points, 5);

            var material = MeshStandardMaterial.Create("plastic");

            material.SetRoughness(0.1f);
            material.SetMetalness(0.4f);
            material.SetColor(new Vector3(0.98f, 0.55f, 0.33f));
            material.SetFaceSide(EnumFaceSide.DoubleSide);
            var node = BrepSceneNode.Create(surf, material, null);

            render.ShowSceneNode(node);
        }
Ejemplo n.º 8
0
        public override void Run(RenderControl render)
        {
            var material = MeshPhongMaterial.Create("phong.bspline");

            material.SetUniform("diffuse", Uniform.Create(new Vector3(1, 0, 1)));

            var shape = CreateShape();
            var node  = BrepSceneNode.Create(shape, material, null);

            render.ShowSceneNode(node);
        }
        public override void Run(RenderControl renderer)
        {
            string fileName = GetResourcePath("Holes.stp");
            var    shape    = StepIO.Open(fileName);

            if (shape == null)
            {
                return;
            }


            var face    = shape.FindChild(EnumTopoShapeType.Topo_FACE, 148);
            var surface = new ParametricSurface(face);

            var wireExp = new WireExplor(face);
            var wires   = wireExp.GetInnerWires();

            foreach (var wire in wires)
            {
                // Show wire
                renderer.ShowShape(wire, Vector3.Red);

                var curve     = new ParametricCurve(wire);
                var paramList = curve.SplitByUniformLength(1, 0.01);

                var  lines = new SegmentsSceneNode((uint)paramList.Count, Vector3.Green, 2);
                uint idx   = 0;
                foreach (var p in paramList)
                {
                    var pt       = curve.Value(p);
                    var pointSur = new ExtremaPointSurface();
                    if (pointSur.Initialize(surface, pt, GP.Resolution(), GP.Resolution()))
                    {
                        var uv     = pointSur.GetParameter(0);
                        var normal = surface.GetNormal(uv.X(), uv.Y());

                        lines.SetPositions(idx++, Vector3.From(pt), Vector3.From(pt.XYZ().Added(normal.XYZ())));
                    }
                }
                lines.UpdateBoundingBox();
                renderer.ShowSceneNode(lines);
            }

            // Show face
            var faceMaterial = MeshStandardMaterial.Create("pbr.face");

            faceMaterial.SetColor(Vector3.LightGray);
            faceMaterial.SetFaceSide(EnumFaceSide.DoubleSide);
            var faceNode = BrepSceneNode.Create(face, faceMaterial, null);

            faceNode.SetDisplayFilter(EnumShapeFilter.Face);
            renderer.ShowSceneNode(faceNode);
        }
Ejemplo n.º 10
0
        BrepSceneNode CreateGlass(GAx2 ax, double width, double height, double thickness)
        {
            var shape = ShapeBuilder.MakeBox(ax, width, thickness, height);

            var frameMaterial = MeshStandardMaterial.Create("window-glass");

            frameMaterial.SetColor(ColorTable.Hex(0xAAAAAA));
            frameMaterial.SetFaceSide(EnumFaceSide.DoubleSide);
            frameMaterial.SetTransparent(true);
            frameMaterial.SetOpacity(0.5f);

            return(BrepSceneNode.Create(shape, frameMaterial, null));
        }
Ejemplo n.º 11
0
        public override void Run(RenderControl render)
        {
            var material = MeshStandardMaterial.Create("robot");

            material.SetColor(new Vector3(0.9f));
            material.SetFaceSide(EnumFaceSide.DoubleSide);
            material.SetOpacity(0.5f);
            material.SetTransparent(true);

            List <string> files = new List <string>();

            files.Add("Base.brep");
            files.Add("AXIS1.brep");
            files.Add("AXIS2.brep");
            files.Add("AXIS3.brep");
            files.Add("AXIS4.brep");
            files.Add("AXIS5.brep");
            files.Add("AXIS6.brep");

            var rootPath = GetResourcePath(@"models\6R\");

            double scale = 1;

            mRobot.AddJoint(EnumRobotJointType.Fixed, 0, 0, 200 * scale, 0);
            mRobot.AddJoint(EnumRobotJointType.Revolute, 0, 0, 130 * scale, 0);                               // Link1
            mRobot.AddJoint(EnumRobotJointType.Revolute, 90, 30, 0, 180, new RobotDH(90, 0, 480 * scale, 0)); // Link2
            mRobot.AddJoint(EnumRobotJointType.Revolute, 90, 0, 0, 270, new RobotDH(90, 0, 100 * scale, 0));  // Link3
            mRobot.AddJoint(EnumRobotJointType.Revolute, 0, 0, 380 * scale, 0);                               // Link4
            mRobot.AddJoint(EnumRobotJointType.Revolute, 270, 0, 0, 0);                                       // Link5
            mRobot.AddJoint(EnumRobotJointType.Revolute, 90, 0, 100 * scale, 0);                              // Link6

            mRobot.AddLink(0, BrepSceneNode.Create(BrepIO.Open(rootPath + files[0]), material, null, 0.1));
            //Link1
            mRobot.AddLink(1, BrepSceneNode.Create(BrepIO.Open(rootPath + files[1]), material, null, 0.1));
            //Link2
            mRobot.AddLink(2, BrepSceneNode.Create(BrepIO.Open(rootPath + files[2]), material, null, 0.1));
            ////Link3
            mRobot.AddLink(3, BrepSceneNode.Create(BrepIO.Open(rootPath + files[3]), material, null, 0.1));
            //Link4
            mRobot.AddLink(4, BrepSceneNode.Create(BrepIO.Open(rootPath + files[4]), material, null, 0.1));
            //Link5
            mRobot.AddLink(5, BrepSceneNode.Create(BrepIO.Open(rootPath + files[5]), material, null, 0.1));
            //Link6
            mRobot.AddLink(6, BrepSceneNode.Create(BrepIO.Open(rootPath + files[6]), material, null, 0.1));

            mRobot.ResetInitialState();

            render.ShowSceneNode(mRobot);

            render.ShowSceneNode(mMotionTrail);
        }
        public override void Run(RenderControl renderer)
        {
            var shape = ShapeIO.Open(GetResourcePath("hole/30-30.IGS"));

            if (shape == null)
            {
                return;
            }

            var edgeMaterial = BasicMaterial.Create("hole-edge");

            edgeMaterial.SetColor(ColorTable.Hex(0xFF0000));
            edgeMaterial.SetLineWidth(2);


            // 1. Find the exterial holes
            var holeExp = new HoleExplorLegacy();

            if (!holeExp.Initialize(shape))
            {
                return;
            }
            var holeNumber = holeExp.ComputeExteriorHoles();

            for (int ii = 0; ii < holeNumber; ++ii)
            {
                var wire     = holeExp.GetExteriorHoleWire(ii);
                var wireNode = BrepSceneNode.Create(wire, null, edgeMaterial);

                renderer.ShowSceneNode(wireNode);
            }

            // 2. Show the faces
            var material = MeshStandardMaterial.Create("hole-face");

            material.SetColor(ColorTable.Hex(0xBBAA33));
            material.SetRoughness(0.8f);
            material.SetFaceSide(EnumFaceSide.DoubleSide);

            var shapeNode = BrepSceneNode.Create(shape, material, null);

            shapeNode.SetDisplayFilter(EnumShapeFilter.Face);
            renderer.ShowSceneNode(shapeNode);
        }
Ejemplo n.º 13
0
        public override void Run(RenderControl render)
        {
            var arrowMaterial = MeshPhongMaterial.Create("arrow");

            arrowMaterial.SetColor(ColorTable.Red);
            mArrow = ArrowWidget.Create(2, 10, arrowMaterial);
            mArrow.SetPickable(false);
            render.ShowSceneNode(mArrow);


            var shape = ShapeBuilder.MakeBox(GP.XOY(), 10, 20, 30);
            var mat   = MeshStandardMaterial.Create("ss");

            mat.SetColor(Vector3.LightGray);

            var node = BrepSceneNode.Create(shape, mat, null);

            render.ShowSceneNode(node);
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            GlobalInstance.Initialize();

            WindowCanvas canvas = new WindowCanvas("AnyCAD", false);

            canvas.Initialize(0, 600, 400);


            var box   = ShapeBuilder.MakeBox(GP.XOY(), 10, 20, 30);
            var node  = BrepSceneNode.Create(box, null, null, 0.01);
            var scene = canvas.GetContext().GetScene();

            scene.AddNode(node);
            //canvas.Run();
            scene.UpdateWorld();
            canvas.ZoomToExtend();
            canvas.Redraw(0);
            canvas.CaptureScreenShot("image.bmp");
            canvas.Destroy();

            GlobalInstance.Destroy();
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        public override void Run(RenderControl render)
        {
            mMaterial1 = MeshPhongMaterial.Create("phong.texture");
            mMaterial1.SetColor(new Vector3(1, 0, 1));

            var texture = ImageTexture2D.Create(GetResourcePath("textures/bricks2.jpg"));

            texture.SetRepeat(new Vector2(2.0f, 2.0f));
            texture.UpdateTransform();

            mMaterial1.SetColorMap(texture);

            var shape = ShapeBuilder.MakeBox(GP.XOY(), 4, 4, 8);

            mNode = BrepSceneNode.Create(shape, mMaterial1, null);

            mMaterial2 = MeshPhongMaterial.Create("phong.texture");
            var texture2 = ImageTexture2D.Create(GetResourcePath("textures/water.png"));

            mMaterial2.SetColorMap(texture2);


            render.ShowSceneNode(mNode);
        }