Beispiel #1
0
        // Token: 0x06000017 RID: 23 RVA: 0x000023B0 File Offset: 0x000005B0
        public FacetedBRep Build(double epsilon)
        {
            KdTree3 kdTree = new KdTree3(epsilon);
            Dictionary <int, int[][]> dictionary = new Dictionary <int, int[][]>();
            List <int[]> list = new List <int[]>();

            foreach (FacetedBRepBuilder.FacetedBrepOuterWire facetedBrepOuterWire in this.outerWires)
            {
                List <int> list2 = new List <int>();
                foreach (Vector3 value in facetedBrepOuterWire.Vertices)
                {
                    list2.Add(kdTree.Insert(value));
                }
                int count = list.Count;
                list.Add(list2.ToArray());
                if (facetedBrepOuterWire.InnerWires.Count != 0)
                {
                    List <int[]> list3 = new List <int[]>();
                    foreach (FacetedBRepBuilder.FacetedBrepOuterWire facetedBrepOuterWire2 in facetedBrepOuterWire.InnerWires)
                    {
                        list2.Clear();
                        foreach (Vector3 value2 in facetedBrepOuterWire2.Vertices)
                        {
                            list2.Add(kdTree.Insert(value2));
                        }
                        list3.Add(list2.ToArray());
                    }
                    dictionary.Add(count, list3.ToArray());
                }
            }
            return(new FacetedBRep(kdTree.Vertices, list.ToArray(), dictionary));
        }
Beispiel #2
0
        // Token: 0x06000077 RID: 119 RVA: 0x00003894 File Offset: 0x00001A94
        public BRep(IEnumerable <Solid> solids)
        {
            Dictionary <ISurface, int>         dictionary  = new Dictionary <ISurface, int>();
            Dictionary <BRep.IndexedEdge, int> dictionary2 = new Dictionary <BRep.IndexedEdge, int>();
            Dictionary <ICurve3, int>          dictionary3 = new Dictionary <ICurve3, int>();
            Dictionary <ICurve2, int>          dictionary4 = new Dictionary <ICurve2, int>();
            List <BRep.IndexedSolid>           list        = new List <BRep.IndexedSolid>();
            List <BRep.IndexedShell>           list2       = new List <BRep.IndexedShell>();
            List <BRep.IndexedFace>            list3       = new List <BRep.IndexedFace>();
            List <ISurface>                 list4          = new List <ISurface>();
            List <BRep.IndexedWire>         list5          = new List <BRep.IndexedWire>();
            List <BRep.IndexedOrientedEdge> list6          = new List <BRep.IndexedOrientedEdge>();
            List <BRep.IndexedEdge>         list7          = new List <BRep.IndexedEdge>();
            List <ICurve3> list8  = new List <ICurve3>();
            List <ICurve2> list9  = new List <ICurve2>();
            KdTree3        kdTree = new KdTree3(1E-06);

            foreach (Solid solid in solids)
            {
                BRep.IndexedSolid item = new BRep.IndexedSolid
                {
                    ShellIndices = new int[solid.Shells.Count]
                };
                int num = 0;
                foreach (Shell shell in solid.Shells)
                {
                    int count = list2.Count;
                    item.ShellIndices[num++] = count;
                    BRep.IndexedShell item2 = new BRep.IndexedShell
                    {
                        FaceIndices = new int[shell.Faces.Count]
                    };
                    int num2 = 0;
                    foreach (Face face in shell.Faces)
                    {
                        int count2 = list3.Count;
                        item2.FaceIndices[num2++] = count2;
                        if (!dictionary.ContainsKey(face.Surface))
                        {
                            dictionary[face.Surface] = list4.Count;
                            list4.Add(face.Surface);
                        }
                        BRep.IndexedFace item3 = new BRep.IndexedFace
                        {
                            Orientation  = face.Orientation,
                            SurfaceIndex = dictionary[face.Surface],
                            WireIndices  = new int[face.Wires.Count]
                        };
                        Dictionary <int, int> dictionary5 = new Dictionary <int, int>();
                        int num3 = 0;
                        foreach (Wire3 wire in face.Wires)
                        {
                            int count3 = list5.Count;
                            item3.WireIndices[num3++] = count3;
                            BRep.IndexedWire item4 = new BRep.IndexedWire
                            {
                                Orientation         = wire.Orientation,
                                OrientedEdgeIndices = new int[wire.Edges.Count]
                            };
                            int num4 = 0;
                            foreach (Edge3 edge in wire.Edges)
                            {
                                int count4 = list6.Count;
                                item4.OrientedEdgeIndices[num4++] = count4;
                                if (!dictionary3.ContainsKey(edge.Curve))
                                {
                                    dictionary3[edge.Curve] = list8.Count;
                                    list8.Add(edge.Curve);
                                }
                                if (edge.CurveOnSurface != null && !dictionary4.ContainsKey(edge.CurveOnSurface))
                                {
                                    dictionary4[edge.CurveOnSurface] = list9.Count;
                                    list9.Add(edge.CurveOnSurface);
                                }
                                int startVertexIndex         = kdTree.Insert(edge.StartVertex);
                                int endVertexIndex           = kdTree.Insert(edge.EndVertex);
                                BRep.IndexedEdge indexedEdge = new BRep.IndexedEdge
                                {
                                    CurveIndex       = dictionary3[edge.Curve],
                                    StartParameter   = edge.StartParameter,
                                    EndParameter     = edge.EndParameter,
                                    StartVertexIndex = startVertexIndex,
                                    EndVertexIndex   = endVertexIndex
                                };
                                if (!dictionary2.ContainsKey(indexedEdge))
                                {
                                    dictionary2[indexedEdge] = list7.Count;
                                    list7.Add(indexedEdge);
                                }
                                int curveOnSurfaceIndex  = (edge.CurveOnSurface != null) ? dictionary4[edge.CurveOnSurface] : -1;
                                int curveOnSurfaceIndex2 = -1;
                                int num5 = dictionary2[indexedEdge];
                                if (dictionary5.ContainsKey(num5))
                                {
                                    int index = dictionary5[num5];
                                    curveOnSurfaceIndex2 = list6[index].CurveOnSurfaceIndex;
                                }
                                BRep.IndexedOrientedEdge item5 = new BRep.IndexedOrientedEdge
                                {
                                    Orientation          = edge.Orientation,
                                    CurveOnSurfaceIndex  = curveOnSurfaceIndex,
                                    CurveOnSurfaceIndex2 = curveOnSurfaceIndex2,
                                    EdgeIndex            = num5
                                };
                                list6.Add(item5);
                                if (dictionary5.ContainsKey(num5))
                                {
                                    int index2 = dictionary5[num5];
                                    BRep.IndexedOrientedEdge value = list6[index2];
                                    value.CurveOnSurfaceIndex2 = item5.CurveOnSurfaceIndex;
                                    list6[index2] = value;
                                }
                                else
                                {
                                    dictionary5[num5] = count4;
                                }
                            }
                            list5.Add(item4);
                        }
                        list3.Add(item3);
                    }
                    list2.Add(item2);
                }
                list.Add(item);
            }
            this.IndexedSolids        = list.AsReadOnly();
            this.IndexedShells        = list2.AsReadOnly();
            this.IndexedFaces         = list3.AsReadOnly();
            this.Surfaces             = list4.AsReadOnly();
            this.IndexedWires         = list5.AsReadOnly();
            this.IndexedOrientedEdges = list6.AsReadOnly();
            this.IndexedEdges         = list7.AsReadOnly();
            this.Curves          = list8.AsReadOnly();
            this.CurvesOnSurface = list9.AsReadOnly();
            this.Vertices        = new List <Vector3>(kdTree.Vertices).AsReadOnly();
        }
Beispiel #3
0
        // Token: 0x0600001A RID: 26 RVA: 0x00002F7C File Offset: 0x0000117C
        public static TriangleMesh CreateTriangleMesh(this FacetedBRep facetedBRep)
        {
            List <TriangleMesh.EdgeLine>      edgeLines      = new List <TriangleMesh.EdgeLine>();
            List <TriangleMesh.SurfaceLine>   surfaceLines   = new List <TriangleMesh.SurfaceLine>();
            List <TriangleMesh.Line>          lines          = new List <TriangleMesh.Line>();
            List <TriangleMesh.Triangle>      list           = new List <TriangleMesh.Triangle>();
            List <TriangleMesh.ReferenceLine> referenceLines = new List <TriangleMesh.ReferenceLine>();
            double referenceLineRadius = 0.0;
            Dictionary <Tuple <int, int>, int> dictionary = new Dictionary <Tuple <int, int>, int>();
            int     num    = 0;
            KdTree3 kdTree = new KdTree3(1E-05);
            Vector3 vector = facetedBRep.Vertices[0];
            List <TriangleMesh.Vertex> list2 = new List <TriangleMesh.Vertex>(facetedBRep.Vertices.Count);

            foreach (Vector3 left in facetedBRep.Vertices)
            {
                Vector3 vector2 = left - vector;
                list2.Add(new TriangleMesh.Vertex((float)vector2.X, (float)vector2.Y, (float)vector2.Z));
            }
            foreach (int[] array in facetedBRep.OuterWires)
            {
                Tess        tess    = new Tess();
                Vector3     left2   = facetedBRep.Vertices[array[0]];
                Vector3     right   = facetedBRep.Vertices[array[1]];
                Vector3     left3   = facetedBRep.Vertices[array[2]];
                Vector3     vector3 = left2 - right;
                Vector3     vector4 = left3 - right;
                UnitVector3 unitZ;
                if (!vector3.TryGetUnitCross(vector4, out unitZ))
                {
                    unitZ = UnitVector3.UnitZ;
                }
                int normalIndex            = kdTree.Insert((Vector3)unitZ);
                List <ContourVertex> list3 = new List <ContourVertex>();
                foreach (int num2 in array)
                {
                    Vector3 vector5 = facetedBRep.Vertices[num2];
                    Vec3    vec     = default(Vec3);
                    vec.X = (float)(vector5.X - vector.X);
                    vec.Y = (float)(vector5.Y - vector.Y);
                    vec.Z = (float)(vector5.Z - vector.Z);
                    Vec3          position      = vec;
                    ContourVertex contourVertex = default(ContourVertex);
                    contourVertex.Position = position;
                    contourVertex.Data     = num2;
                    ContourVertex item = contourVertex;
                    list3.Add(item);
                }
                tess.AddContour(list3.ToArray());
                tess.Tessellate(0, 0, 3);
                for (int k = 0; k < tess.ElementCount; k++)
                {
                    int num3        = tess.Elements[k * 3 + 0];
                    int num4        = tess.Elements[k * 3 + 1];
                    int num5        = tess.Elements[k * 3 + 2];
                    int pointIndex  = (int)tess.Vertices[num3].Data;
                    int pointIndex2 = (int)tess.Vertices[num4].Data;
                    int pointIndex3 = (int)tess.Vertices[num5].Data;
                    int corner      = FacetedBRepTesselationExtensions.GetCorner(normalIndex, pointIndex, dictionary, ref num);
                    int corner2     = FacetedBRepTesselationExtensions.GetCorner(normalIndex, pointIndex2, dictionary, ref num);
                    int corner3     = FacetedBRepTesselationExtensions.GetCorner(normalIndex, pointIndex3, dictionary, ref num);
                    list.Add(new TriangleMesh.Triangle((ushort)corner, (ushort)corner2, (ushort)corner3));
                }
            }
            TriangleMesh.Corner[] array3 = new TriangleMesh.Corner[dictionary.Count];
            foreach (KeyValuePair <Tuple <int, int>, int> keyValuePair in dictionary)
            {
                int value = keyValuePair.Value;
                array3[value] = new TriangleMesh.Corner((ushort)keyValuePair.Key.Item1, (ushort)keyValuePair.Key.Item2);
            }
            List <TriangleMesh.Normal> list4 = new List <TriangleMesh.Normal>();

            foreach (Vector3 vector6 in kdTree.Vertices)
            {
                list4.Add(new TriangleMesh.Normal((float)vector6.X, (float)vector6.Y, (float)vector6.Z));
            }
            return(new TriangleMesh(vector, list4, list2, edgeLines, surfaceLines, lines, array3, list, referenceLines, referenceLineRadius));
        }