Exemplo n.º 1
0
        private static IBody2[] RoundTrip(IBody2 cutBody)
        {
            var faces  = cutBody.GetFaces().CastArray <IFace2>();
            var sheets = faces.Select(face => BSplineFace.Create(face).ToSheetBody()).ToArray();

            //foreach (var sheet in sheets)
            //{
            //    yielder(sheet.DisplayUndoable(modelDoc));
            //}


            var error = (int)swSheetSewingError_e.swSewingOk;
            var body  = Modeler
                        .CreateBodiesFromSheets2(sheets, (int)swSheetSewingOption_e.swSewToSolid, 1e-5, ref error)
                        .CastArray <IBody2>();

            return(body);
        }
Exemplo n.º 2
0
        private static bool IsOpenGeometry(IBody2 body)
        {
            object[] faces = body.GetFaces() as object[];

            if (faces != null)
            {
                foreach (IFace2 face in faces)
                {
                    FaceShellType_e shellType = (FaceShellType_e)face.GetShellType();

                    if (shellType == FaceShellType_e.Open)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        private IFace2 FindLargestPlanarFace(IBody2 body)
        {
            var faces = body.GetFaces() as object[];

            if (faces == null)
            {
                throw new NullReferenceException("Body doesn't contain faces");
            }

            var face = faces.Cast <IFace2>()
                       .Where(f => f.IGetSurface().IsPlane())
                       .OrderBy(f => f.GetArea()).LastOrDefault();

            if (face == null)
            {
                throw new NullReferenceException("There are no planar faces in this body");
            }

            return(face);
        }
Exemplo n.º 4
0
        public static bool GetDistance(this IBody2 body0, IBody2 body1, out double[] p0, out double [] p1)
        {
            var faces0    = body0.GetFaces().CastArray <IFace2>();
            var faces1    = body1.GetFaces().CastArray <IFace2>();
            var distances = GetDistances(faces0, faces1);

            p0 = null;
            p1 = null;


            var shortest = distances.MinBy(t => MathPointExtensions.Distance(t.Item1, t.Item2));

            if (shortest.Count == 0)
            {
                return(false);
            }

            p0 = shortest[0].Item1;
            p1 = shortest[0].Item2;

            return(true);
        }
        private static IBody2[] RoundTrip(IBody2 cutBody)
        {
            var faces = cutBody.GetFaces().CastArray<IFace2>();
            var sheets = faces
                .Select(face => BSplineFace.Create(face).ToSheetBody())
                .AssertAllSome()
                .ToArray();

            //foreach (var sheet in sheets)
            //{
            //    yielder(sheet.DisplayUndoable(modelDoc));
            //}


            var error = (int) swSheetSewingError_e.swSewingOk;
            var body = Modeler
                .CreateBodiesFromSheets2(sheets, (int) swSheetSewingOption_e.swSewToSolid, 1e-5, ref error)
                .CastArray<IBody2>();
            return body;
        }
Exemplo n.º 6
0
        private static BodyTessellation GetBodyMesh(IBody2 body, IPartDoc partDoc, ITessellation tessellation, long?overrideColor)
        {
            var bodyTessellation = new BodyTessellation();

            if (overrideColor.HasValue)
            {
                bodyTessellation.FaceColors.Add(overrideColor.Value);
            }
            else
            {
                double[] bodyColorArray = null;
                var      features       = (object[])body.GetFeatures();
                if (features != null)
                {
                    foreach (IFeature feature in features.Reverse())
                    {
                        bodyColorArray =
                            (double[])feature.GetMaterialPropertyValues2(
                                (int)swInConfigurationOpts_e.swThisConfiguration, null);
                        if (bodyColorArray[0] == -1
                            ) // All -1s are returned by features that don't assign color.
                        {
                            bodyColorArray = null;
                        }

                        if (bodyColorArray != null)
                        {
                            break;
                        }
                    }
                }

                if (bodyColorArray == null)
                {
                    bodyColorArray = (double[])body.MaterialPropertyValues2;
                }

                if (bodyColorArray == null)
                {
                    bodyColorArray = (double[])partDoc.MaterialPropertyValues;
                }

                var bodyColor = ColorArrayToColor(bodyColorArray);

                bodyTessellation.FaceColors.Add(bodyColor);
            }

            var coloredFaces = new Dictionary <IFace2, long>();
            var faceCount    = 0;

            foreach (IFace2 face in (object[])body.GetFaces())
            {
                faceCount++;
                var colorArray = (double[])face.MaterialPropertyValues;
                if (colorArray != null)
                {
                    coloredFaces[face] = ColorArrayToColor(colorArray);
                }
            }

            if (coloredFaces.Count < faceCount)
            {
                for (var i = 0; i < tessellation.GetVertexCount(); i++)
                {
                    bodyTessellation.VertexPositions.Add((double[])tessellation.GetVertexPoint(i));
                    bodyTessellation.VertexNormals.Add((double[])tessellation.GetVertexNormal(i));
                }

                foreach (IFace2 face in (object[])body.GetFaces())
                {
                    if (coloredFaces.ContainsKey(face))
                    {
                        continue;
                    }

                    foreach (var facet in (int[])tessellation.GetFaceFacets(face))
                    {
                        var vertexIndices = new List <int>();
                        foreach (var fin in (int[])tessellation.GetFacetFins(facet))
                        {
                            vertexIndices.Add(((int[])tessellation.GetFinVertices(fin))[0]);
                        }

                        bodyTessellation.Faces.Add(new FaceStruct {
                            Color   = 0,
                            Vertex1 = vertexIndices[0],
                            Vertex2 = vertexIndices[1],
                            Vertex3 = vertexIndices[2],
                        });
                    }
                }
            }

            foreach (var pair in coloredFaces)
            {
                var colorIndex = bodyTessellation.FaceColors.IndexOf(pair.Value);
                if (colorIndex == -1)
                {
                    bodyTessellation.FaceColors.Add(pair.Value);
                    colorIndex = bodyTessellation.FaceColors.Count - 1;
                }

                foreach (var facet in (int[])tessellation.GetFaceFacets(pair.Key))
                {
                    var vertexIndices = new List <int>();
                    foreach (var fin in (int[])tessellation.GetFacetFins(facet))
                    {
                        vertexIndices.Add(((int[])tessellation.GetFinVertices(fin))[0]);
                    }

                    bodyTessellation.Faces.Add(
                        new FaceStruct {
                        Color   = colorIndex,
                        Vertex1 = bodyTessellation.VertexPositions.Count,
                        Vertex2 = bodyTessellation.VertexPositions.Count + 1,
                        Vertex3 = bodyTessellation.VertexPositions.Count + 2
                    });

                    bodyTessellation.VertexPositions.Add(
                        (double[])tessellation.GetVertexPoint(vertexIndices[0]));
                    bodyTessellation.VertexPositions.Add(
                        (double[])tessellation.GetVertexPoint(vertexIndices[1]));
                    bodyTessellation.VertexPositions.Add(
                        (double[])tessellation.GetVertexPoint(vertexIndices[2]));

                    bodyTessellation.VertexNormals.Add(
                        (double[])tessellation.GetVertexNormal(vertexIndices[0]));
                    bodyTessellation.VertexNormals.Add(
                        (double[])tessellation.GetVertexNormal(vertexIndices[1]));
                    bodyTessellation.VertexNormals.Add(
                        (double[])tessellation.GetVertexNormal(vertexIndices[2]));
                }
            }
            return(bodyTessellation);
        }