Exemplo n.º 1
0
        public Solid(TopoShape solid)
        {
            BoundingBox = solid.GetBBox();

            var faces = GlobalInstance.TopoExplor.ExplorFaces(solid);
            TopoShapeProperty prop           = new TopoShapeProperty();
            List <FaceInfo>   dictFaceByArea = new List <FaceInfo>();

            for (int ii = 0; ii < faces.Size(); ++ii)
            {
                var face = faces.GetAt(ii);
                prop.SetShape(face);
                double area = prop.SurfaceArea();

                var faceInfo = new FaceInfo(face, ii, area);
                dictFaceByArea.Add(faceInfo);

                Faces.Add(ii, faceInfo);
            }
            dictFaceByArea.Sort((a, b) =>
            {
                return((int)((b.Area - a.Area) * 1000));
            });

            var baseFace = dictFaceByArea[0];

            foreach (var item in baseFace.Edges)
            {
                EdgeGroup eg = new EdgeGroup(item.Value);
                EdgeGroups.Add(eg);
            }

            for (int ii = 2; ii < dictFaceByArea.Count; ++ii)
            {
                var faceInfo = dictFaceByArea[ii];
                if (AddLongFace(faceInfo))
                {
                    continue;
                }

                AddSideFace(faceInfo);
            }
        }
Exemplo n.º 2
0
        public override bool Run(FeatureContext context)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "STL (*.stl)|*.stl|IGES (*.igs;*.iges)|*.igs;*.iges|STEP (*.stp;*.step)|*.stp;*.step|BREP (*.brep)|*.brep|All Files(*.*)|*.*";

            if (DialogResult.OK != dlg.ShowDialog())
            {
                return(false);
            }

            context.RenderView.RenderTimer.Enabled = false;
            TopoShape shape = GlobalInstance.BrepTools.LoadFile(new AnyCAD.Platform.Path(dlg.FileName));

            context.RenderView.RenderTimer.Enabled = true;
            MessageBox.Show("loaded");
            if (shape != null)
            {
                //context.ShowGeometry(shape, new ElementId(100));
                //GlobalInstance.BrepTools.SaveFile(shape, new Path(dlg.FileName + ".brep"));

                AABox     bbox     = shape.GetBBox();
                Vector3   size     = bbox.Size();
                Vector3   start    = new Vector3(bbox.MinPt.X - 10, bbox.MinPt.Y + size.Y * 0.5f, bbox.MinPt.Z - 10);
                TopoShape boxShape = GlobalInstance.BrepTools.MakeBox(start, Vector3.UNIT_Z, new Vector3(size.X + 20, size.Y * 0.25f, size.Z + 20));

                shape = GlobalInstance.BrepTools.BooleanCut(shape, boxShape);

                MessageBox.Show("cut!");
                var groups = GlobalInstance.TopoExplor.ExplorSubShapes(shape);
                for (int ii = 0, len = groups.Size(); ii < len; ++ii)
                {
                    shape = groups.GetAt(ii);
                    var node = context.ShowGeometry(shape, new ElementId(100));
                    var fs   = new FaceStyle();
                    fs.SetColor(ii * 100, 0, ii + 200);
                    node.SetFaceStyle(fs);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        private void faceTriangulateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TopoShape circle = GlobalInstance.BrepTools.MakeCircle(Vector3.ZERO, 100, Vector3.UNIT_Z);
            TopoShape face   = GlobalInstance.BrepTools.MakeFace(circle);

            if (face.GetShapeType() == (int)EnShapeType.Topo_FACE)
            {
                MessageBox.Show("This is a face!");
            }

            FaceTriangulation ft = new FaceTriangulation();

            ft.SetTolerance(5);
            ft.Perform(face);
            float[] points     = ft.GetVertexBuffer();
            int     pointCount = points.Length / 3;

            uint[] indexBuffer = ft.GetIndexBuffer();
            int    faceCount   = indexBuffer.Length / 3;

            float[] normals = ft.GetNormalBuffer();

            MessageBox.Show(String.Format("Point Count: {0}\n Face Count: {1}", pointCount, faceCount));

            float[] colorBuffer = new float[pointCount * 4];

            Random num = new Random();

            for (int ii = 0; ii < pointCount; ++ii)
            {
                int idx = ii * 4;
                colorBuffer[idx]     = num.Next(0, 256) / 256.0f;
                colorBuffer[idx + 1] = num.Next(0, 256) / 256.0f;
                colorBuffer[idx + 2] = num.Next(0, 256) / 256.0f;
                colorBuffer[idx + 3] = 1;
            }

            RenderableEntity entity = GlobalInstance.TopoShapeConvert.CreateColoredFaceEntity(points, indexBuffer, normals, colorBuffer, face.GetBBox());

            EntitySceneNode node = new EntitySceneNode();

            node.SetEntity(entity);

            renderView.SceneManager.AddNode(node);
            renderView.RequestDraw();
            //////////////////////////////////////////////////////////////////////////
            // Code to get the mesh

            /*
             * for (int ii = 0; ii < faceCount; ++ii)
             * {
             *  int p0 = (int)indexBuffer[ii * 3];
             *  int p1 = (int)indexBuffer[ii * 3 + 1];
             *  int p2 = (int)indexBuffer[ii * 3 + 2];
             *
             *  Vector3 pt0 = new Vector3(points[p0 * 3], points[p0 * 3 + 1], points[p0 * 3 + 2]);
             *  Vector3 pt1 = new Vector3(points[p1 * 3], points[p1 * 3 + 1], points[p1 * 3 + 2]);
             *  Vector3 pt2 = new Vector3(points[p2 * 3], points[p2 * 3 + 1], points[p2 * 3 + 2]);
             *
             *  // ....
             *  // use the same way to get the normal data for each point.
             * }
             * */
            //////////////////////////////////////////////////////////////////////////
        }
        public override bool Run(FeatureContext context)
        {
            TopoShape circle = GlobalInstance.BrepTools.MakeCircle(Vector3.ZERO, 100, Vector3.UNIT_Z);
            TopoShape face   = GlobalInstance.BrepTools.MakeFace(circle);

            FaceTriangulation ft = new FaceTriangulation();

            ft.SetTolerance(5);
            ft.Perform(face);
            float[] points     = ft.GetVertexBuffer();
            int     pointCount = points.Length / 3;

            uint[] indexBuffer = ft.GetIndexBuffer();
            int    faceCount   = indexBuffer.Length / 3;

            float[] normals = ft.GetNormalBuffer();


            float[] colorBuffer = new float[pointCount * 4];

            Random num = new Random();

            for (int ii = 0; ii < pointCount; ++ii)
            {
                int idx = ii * 4;
                colorBuffer[idx]     = num.Next(0, 256) / 256.0f;
                colorBuffer[idx + 1] = num.Next(0, 256) / 256.0f;
                colorBuffer[idx + 2] = num.Next(0, 256) / 256.0f;
                colorBuffer[idx + 3] = 1;
            }

            RenderableEntity entity = GlobalInstance.TopoShapeConvert.CreateColoredFaceEntity(points, indexBuffer, normals, colorBuffer, face.GetBBox());

            EntitySceneNode node = new EntitySceneNode();

            node.SetEntity(entity);

            context.ShowSceneNode(node);

            //////////////////////////////////////////////////////////////////////////
            // Code to get the mesh

            /*
             * for (int ii = 0; ii < faceCount; ++ii)
             * {
             *  int p0 = (int)indexBuffer[ii * 3];
             *  int p1 = (int)indexBuffer[ii * 3 + 1];
             *  int p2 = (int)indexBuffer[ii * 3 + 2];
             *
             *  Vector3 pt0 = new Vector3(points[p0 * 3], points[p0 * 3 + 1], points[p0 * 3 + 2]);
             *  Vector3 pt1 = new Vector3(points[p1 * 3], points[p1 * 3 + 1], points[p1 * 3 + 2]);
             *  Vector3 pt2 = new Vector3(points[p2 * 3], points[p2 * 3 + 1], points[p2 * 3 + 2]);
             *
             *  // ....
             *  // use the same way to get the normal data for each point.
             * }
             * */


            return(true);
        }