public void Create(RenderControl render)
        {
            // 随便构造些点
            float offset = 10.0f;

            for (int ii = 0; ii < 10; ++ii)
            {
                for (int jj = 0; jj < ii; ++jj)
                {
                    mPoints.Add(new Vector3(jj * offset, 100, ii * offset));
                }
            }


            mMotionTrail = new ParticleSceneNode((uint)mPoints.Count, ColorTable.Green, 3.0f);

            mCurrentIdx = 0;

            render.ShowSceneNode(mMotionTrail);

            var lineMaterial = BasicMaterial.Create("myline");

            lineMaterial.SetColor(ColorTable.Hex(0xFF0000));
            var line = GeometryBuilder.CreateLine(Vector3.Zero, new Vector3(1, 0, 0));

            mLineNode = new PrimitiveSceneNode(line, lineMaterial);
            mLineNode.SetTransform(MakeTransform(mStart, mPoints[0]));
            mLineNode.RequstUpdate();
            render.ShowSceneNode(mLineNode);
        }
Ejemplo n.º 2
0
        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 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 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);
        }
        public override void Run(RenderControl render)
        {
            if (!ReadData())
            {
                return;
            }

            var material = BasicMaterial.Create("point-material");

            material.GetTemplate().SetVertexColors(true);

            var geometry = GeometryBuilder.CreatePoints(new Float32Array(mPositions), new Float32Array(mColors));

            var node = new PrimitiveSceneNode(geometry, material);

            //node.SetPickable(false);

            render.ShowSceneNode(node);
        }
Ejemplo n.º 6
0
        public override void Run(RenderControl render)
        {
            mGeometry = GeometryBuilder.CreatePlane(20000, 20000, worldWidth - 1, worldDepth - 1);
            var position = mGeometry.GetGeometry().GetAttribute(0);

            position.SetDataUsage(EnumBufferDataUsage.DYNAMIC_DRAW);
            var mPosition = new Float32Array(position.GetData());

            for (uint i = 0; i < position.GetCount() / 3; i++)
            {
                float z = (float)(35 * Math.Sin(i / 2));
                mPosition.SetValue(i * 3 + 2, z);
            }

            var material = BasicMaterial.Create("basic-water");
            var img      = FileImage.Create(GetResourcePath("textures/water.png"));
            var texture  = new ImageTexture2D();

            texture.SetSource(img);
            var desc = texture.GetDesc();

            desc.SetWrapS(EnumTextureWrappingType.REPEAT);
            desc.SetWrapT(EnumTextureWrappingType.REPEAT);
            texture.SetRepeat(new Vector2(5, 5));

            material.AddTexture("map", texture);
            var color = Vector3.ColorFromHex(0x0044ff);

            material.SetUniform("diffuse", Uniform.Create(color));


            var node = new PrimitiveSceneNode(mGeometry, material);

            node.SetPickable(false);
            node.SetCulling(false);

            render.ShowSceneNode(node);
        }
Ejemplo n.º 7
0
        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);
        }