Esempio n. 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            try {
                Mesh mesh = null;
                DA.GetData(0, ref mesh);

                if (mesh != null)
                {
                    Polyline[] plines = mesh.GetPolylines();
                    for (int i = 0; i < plines.Length; i++)
                    {
                        plines[i] = new Polyline(plines[i].Flip());
                    }

                    Mesh meshReversed = MeshCreate.MeshFromPolylines(plines, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                    Mesh meshFlipped  = mesh.DuplicateMesh();
                    meshFlipped.Flip(true, true, true);

                    DA.SetData(0, meshReversed);

                    PreparePreview(meshReversed, DA.Iteration);
                    DA.SetData(1, meshFlipped);
                }
            }catch (Exception e) {
                Rhino.RhinoApp.WriteLine(e.ToString());
            }
        }
Esempio n. 2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);

            double angle = 10;
            double dist  = 0.2;
            double width = 0.1;

            DA.GetData(1, ref angle);
            DA.GetData(2, ref dist);
            DA.GetData(3, ref width);

            if (mesh.IsValid)
            {
                if (mesh.Ngons.Count == 0)
                {
                    mesh = MeshCreate.MeshFromPolylines(mesh.GetFacePolylines(), Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                }

                var dt = mesh.ReciprocalFrame(angle, dist, width);
                this.PreparePreview(mesh, DA.Iteration, dt.AllData(), false);
                DA.SetDataTree(0, dt);
            }
        }
Esempio n. 3
0
    void Created_2D()
    {
        ve.ResetOverride("PositionBuffer");
        ve.ResetOverride("GrassCount");


        int buffSize = terrain.terrainData.treeInstanceCount;

        float r = Mathf.Sqrt(buffSize);
        int   w = (int)Mathf.Ceil(r);
        int   h = w;

        Debug.Log("W" + w + "H" + h + "Buff" + buffSize);

        Color[]   posBuffer = new Color[w * h];
        Vector3[] vertexs   = new Vector3[buffSize];

        for (int i = 0; i < buffSize; i++)
        {
            TreeInstance ti = terrain.terrainData.GetTreeInstance(i);

            //var t = ti.GetType();
            //t.Name
            Vector3 pos = Vector3.Scale(ti.position, terrain.terrainData.size) + Terrain.activeTerrain.transform.position;

            posBuffer[i] = new Color(pos.x, pos.y - 0.3f, pos.z);
            vertexs[i]   = pos + (Vector3.up * 0.0001f);
        }

        texture            = new Texture2D(w, h, TextureFormat.RGBAFloat, false);
        texture.filterMode = FilterMode.Point;
        texture.wrapMode   = TextureWrapMode.Clamp;

        texture.SetPixels(posBuffer);
        texture.Apply();



        //地面メッシュ生成
        GrassDust gd = MeshCreate.Create(vertexs, false, null).AddComponent <GrassDust>();

        gd.effect = ve_GrassDust;
        gd.gameObject.AddComponent <Rigidbody>().isKinematic = true;
        gd.gameObject.layer = LayerMask.NameToLayer("FootEvent");
        gd.gameObject.tag   = "Hide";
        //草エフェクト開始
        ve.SetTexture("PositionBuffer", texture);
        ve.SetFloat("GrassCount", posBuffer.Length * 2f);
        terrain.drawTreesAndFoliage = false;
        //        ve.Play();
        //        ve.gameObject.SetActive(true);


        ve.SendEvent("Emit");
        //ve.gameObject.SetActive(true);
        //ve.enabled = true;
//        Destroy(gameObject);
    }
Esempio n. 4
0
 void UpdateWall(WallInfo wallinfo)
 {
     wallInfo = wallinfo;
     if (wallInfo.EMeshFilter == null)
     {
         wallInfo.EMeshFilter = GetComponent <MeshFilter>();
     }
     if (wallInfo.EMeshFilter.mesh != null)
     {
         DestroyImmediate(wallInfo.EMeshFilter.mesh);
     }
     wallInfo.EMeshFilter.mesh = MeshCreate.CreateQuadMesh();
 }
Esempio n. 5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            try {
                List <Curve> curves = new List <Curve>();
                bool         flag   = DA.GetDataList(0, curves);

                //double weld = -1;
                //DA.GetData(1, ref weld);

                //IEnumerable<Polyline> p = curves.ToPolylines();
                IEnumerable <Polyline> p = curves.ToPolylinesFromCP(Math.Max(0.00001, 0.0001));


                Mesh mesh = MeshCreate.MeshFromPolylines(p, -1, Convert.ToInt32(!foo));

                this.PreparePreview(mesh, DA.Iteration);

                DA.SetData(0, mesh);
            } catch (Exception e) {
                Rhino.RhinoApp.WriteLine(e.ToString());
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData <Mesh>(0, ref mesh);
            double num  = 10;
            double num1 = 0.2;
            double num2 = 0.1;

            DA.GetData <double>(1, ref num);
            DA.GetData <double>(2, ref num1);
            DA.GetData <double>(3, ref num2);
            if (mesh.IsValid)
            {
                if (mesh.Ngons.Count == 0)
                {
                    mesh = MeshCreate.MeshFromPolylines(mesh.GetFacePolylines(), RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                }
                DataTree <Polyline> dataTree = mesh.ReciprocalFrame(num, num1, num2);
                //this.PreparePreview(mesh, DA.Iteration, dataTree.AllData(), false, null, null, 255, 0, 0, null, 255, 255, 255, 1);
                DA.SetDataTree(0, dataTree);
            }
        }
Esempio n. 7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            try {
                double U = 10;
                int    V = 10;
                double a = 0;
                DA.GetData(1, ref U);
                bool flag2 = DA.GetData(2, ref V);
                DA.GetData(3, ref a);

                Brep brep = new Brep();



                int  T = 0;
                int  r = -1;
                bool q = true;

                bool swap = true;


                DA.GetData(4, ref T);
                DA.GetData(5, ref swap);
                DA.GetData(6, ref r);
                DA.GetData(7, ref q);


                bool f = false;

                if (T == 0 || T == 1)
                {
                    f = true;
                }


                if (T != 0 && T != 1)
                {
                    T = 0;
                }

                if (DA.GetData(0, ref brep))
                {
                    if (brep.Faces.Count == 1 && !brep.Faces[0].IsClosed(0) && !brep.Faces[0].IsClosed(1))
                    {
                        Surface S = brep.Faces[0].ToNurbsSurface();



                        Surface tempS = S;

                        if (swap)
                        {
                            S = tempS.Transpose(true);
                        }
                        else
                        {
                            S = tempS.Reverse(0, true);
                        }

                        if (r > 0)
                        {
                            S = S.Rebuild(3, 3, r, r);
                        }


                        if (U <= 0)
                        {
                            U = 1;
                        }

                        if (V <= 0)
                        {
                            V = 1;
                        }

                        S.SetDomain(0, new Interval(0, 1));
                        S.SetDomain(1, new Interval(0, 1));

                        List <double> distanceA = new List <double>();
                        List <double> distanceB = new List <double>();



                        Mesh mesh = MeshCreate.HexMesh(S, (int)MathUtil.Constrain(U, 2, 100), (int)MathUtil.Constrain(V, 2, 100), a, T, ref distanceA, ref distanceB, f, q);

                        base.Message = (String.Format("Min {0} {1} \n Max {2} {3} \n Av {4} {5} \n Total {6}",
                                                      Math.Round(distanceA.Min(), 2),
                                                      Math.Round(distanceB.Min(), 2),
                                                      Math.Round(distanceA.Max(), 2),
                                                      Math.Round(distanceB.Max(), 2),
                                                      Math.Round(distanceA.Average(), 2),
                                                      Math.Round(distanceB.Average(), 2),
                                                      mesh.Ngons.Count

                                                      ));


                        mesh.Compact();
                        mesh.Vertices.CombineIdentical(true, true);
                        mesh.Vertices.CullUnused();

                        if (mesh.Ngons.Count > 0)
                        {
                            mesh.UnifyNormalsNGons();
                        }
                        else
                        {
                            mesh.UnifyNormals();
                        }


                        mesh.Weld(3.14159265358979);
                        mesh.FaceNormals.ComputeFaceNormals();
                        mesh.Normals.ComputeNormals();

                        if (mesh.SolidOrientation() == -1)
                        {
                            mesh.Flip(true, true, true);
                        }

                        DA.SetData(0, mesh);
                        this.PreparePreview(mesh, DA.Iteration);
                        DA.SetDataList(1, distanceA);
                        DA.SetDataList(2, distanceB);
                        this.Message = "Division UV ";
                    }
                    else
                    {
                        if (!explode)   //&& !flag2
                        {
                            int[][] feDivisions = null;
                            if (U == 0)
                            {
                                U = 1000;
                            }

                            if (!flag2 && foo)
                            {
                                int[] edgeDivisions = brep.EdgeDivisions(U, ref feDivisions);
                                this.Message = "Division U Dist";
                                //Rhino.RhinoApp.WriteLine("Hi");
                            }
                            else
                            {
                                this.Message = "Division UV Explode";
                            }

                            List <Polyline> plinesClothed = new List <Polyline>();
                            List <Polyline> plinesNaked   = new List <Polyline>();
                            MeshCreate.HexOrDiamondGrid(brep, (int)MathUtil.Constrain(U, 2, 100), (int)MathUtil.Constrain(V, 2, 100), ref plinesClothed, ref plinesNaked, a, true, feDivisions);
                            plinesClothed.AddRange(plinesNaked);
                            Mesh mesh = MeshCreate.MeshFromPolylines(plinesClothed, 0);
                            this.PreparePreview(mesh, DA.Iteration);
                            DA.SetData(0, mesh);
                        }
                        else
                        {
                            Mesh mesh = new Mesh();
                            for (int i = 0; i < brep.Faces.Count; i++)
                            {
                                //Reparametricize
                                Surface S = brep.Faces[i].ToNurbsSurface();
                                S.SetDomain(0, new Interval(0, 1));
                                S.SetDomain(1, new Interval(0, 1));
                                List <double> distanceA = new List <double>();
                                List <double> distanceB = new List <double>();
                                Mesh          m         = MeshCreate.HexMesh(S, (int)MathUtil.Constrain(U, 2, 100), (int)MathUtil.Constrain(V, 2, 100), a, T, ref distanceA, ref distanceB, f, q);

                                mesh.Append(m);
                            }
                            mesh.Compact();
                            mesh.Vertices.CombineIdentical(true, true);
                            mesh.Vertices.CullUnused();

                            if (mesh.Ngons.Count > 0)
                            {
                                mesh.UnifyNormalsNGons();
                            }
                            else
                            {
                                mesh.UnifyNormals();
                            }


                            mesh.Weld(3.14159265358979);
                            mesh.FaceNormals.ComputeFaceNormals();
                            mesh.Normals.ComputeNormals();

                            if (mesh.SolidOrientation() == -1)
                            {
                                mesh.Flip(true, true, true);
                            }

                            this.PreparePreview(mesh, DA.Iteration);
                            DA.SetData(0, mesh);
                            this.Message = "Division UV Explode";
                        }
                    }
                }
            }catch (Exception e) {
                Rhino.RhinoApp.WriteLine(e.ToString());
            }
        }
Esempio n. 8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Surface S = null;

            DA.GetData(0, ref S);

            int    U = 10;
            int    V = 10;
            int    T = 0;
            double a = 0;
            int    r = 9;
            bool   q = true;

            bool swap = true;

            DA.GetData(1, ref U);
            DA.GetData(2, ref V);
            DA.GetData(3, ref a);

            DA.GetData(4, ref swap);
            DA.GetData(5, ref r);


            Surface tempS = S;

            if (swap)
            {
                S = tempS.Transpose(true);
            }
            else
            {
                S = tempS.Reverse(0, true);
            }

            if (r > 0)
            {
                S = S.Rebuild(3, 3, r, r);
            }


            if (U <= 0)
            {
                U = 1;
            }

            if (V <= 0)
            {
                V = 1;
            }

            S.SetDomain(0, new Interval(0, 1));
            S.SetDomain(1, new Interval(0, 1));


            bool f = false;

            if (T == 0 || T == 1)
            {
                f = true;
            }


            if (T != 0 && T != 1)
            {
                T = 0;
            }



            Mesh mesh = MeshCreate.HexMesh2(S, U, V, a);


            DA.SetData(0, mesh);
            this.PreparePreview(mesh, DA.Iteration);
        }
Esempio n. 9
0
        public static Mesh Dual(this Mesh mesh, int type = 0, Surface surface = null, List <Point3d> pts = null)
        {
            Mesh x = mesh.DuplicateMesh();

            bool hasOnlyTriangleQuadNgons = true;

            for (int i = 0; i < x.Ngons.Count; i++)
            {
                if (x.Ngons[i].BoundaryVertexCount > 4)
                {
                    hasOnlyTriangleQuadNgons = false;
                    break;
                }
            }
            if (hasOnlyTriangleQuadNgons)
            {
                x.Ngons.Clear();
            }


            int Type = Math.Abs(type);


            Mesh dual = new Mesh();

            if (surface != null)
            {
                Surface s = surface;
                s.SetDomain(0, new Interval(0, 1));
                s.SetDomain(1, new Interval(0, 1));
            }

            if (x.Ngons.Count == 0)
            {
                //Get face center
                int count = 0;
                foreach (MeshFace mf in x.Faces)
                {
                    Point3d barycenter = Point3d.Origin;

                    if (pts != null)
                    {
                        if (pts.Count == x.Faces.Count)
                        {
                            Type = 2;
                        }
                    }

                    switch (Type)
                    {
                    case (2):
                        barycenter = pts[count];
                        break;

                    case (1):
                        if (mf.IsQuad)
                        {
                            barycenter = new Polyline(new Point3d[] { x.Vertices[mf.A], x.Vertices[mf.B], x.Vertices[mf.C], x.Vertices[mf.D], x.Vertices[mf.A] }).CenterPoint();
                        }
                        else
                        {
                            barycenter = new Polyline(new Point3d[] { x.Vertices[mf.A], x.Vertices[mf.B], x.Vertices[mf.C], x.Vertices[mf.A] }).CenterPoint();
                        }
                        break;

                    default:

                        barycenter += (x.Vertices[mf.A]);
                        barycenter += (x.Vertices[mf.B]);
                        barycenter += (x.Vertices[mf.C]);

                        if (mf.IsQuad)
                        {
                            barycenter += (x.Vertices[mf.D]);
                            barycenter /= 4;
                        }
                        else
                        {
                            barycenter /= 3;
                        }
                        break;
                    }



                    dual.Vertices.Add(barycenter);
                    count++;
                }


                //Apply dual
                List <Polyline> polylines = new List <Polyline>();
                bool[]          nakedv    = x.GetNakedEdgePointStatus();
                Point3d[]       midPoints = MeshUtilSimple.EdgeMidPoints(x);
                dual.Vertices.AddVertices(midPoints);

                //int[] edges = x.TopologyVertices.ConnectedEdges(vID);
                //foreach (int edgeID in edges) {
                //    int[] edgeFaces = x.TopologyEdges.GetConnectedFaces(edgeID);
                //    if (edgeFaces.Length == 1) {
                //        nakedFaces.Add(edgeFaces[0]);
                //        nakedEdges.Add(edgeID);
                //        nakedEdgesP.Add(midPoints[edgeID]);
                //        // nakedEdgesPDistToLastP.Add(lastPoint.DistanceToSquared(midPoints[edgeID]));
                //    }
                //}

                for (int i = 0; i < x.Vertices.Count; i++)
                {
                    if (nakedv[i] && type < 0)
                    {
                        continue;
                    }

                    int   vID = x.TopologyVertices.TopologyVertexIndex(i);
                    int[] vf  = x.TopologyVertices.ConnectedFaces(vID);


                    int[] sortedFaces = SortFacesConnectedToTopologyVertex(x, vf);

                    //You can select vertices from dual mesh
                    //Or if you calculate barycenter here, then you will have duplicate points

                    if (vf.Length > 0)  //2

                    {
                        Polyline   polyline = new Polyline();
                        List <int> id       = new List <int>();

                        for (int j = 0; j < sortedFaces.Length; j++)
                        {
                            polyline.Add(dual.Vertices[sortedFaces[j]]);
                            id.Add(sortedFaces[j]);
                        }



                        if (nakedv[i])
                        {
                            Point3d        lastPoint              = polyline.Last();
                            List <int>     nakedEdges             = new List <int>();
                            List <Point3d> nakedEdgesP            = new List <Point3d>();
                            List <double>  nakedEdgesPDistToLastP = new List <double>();
                            List <int>     nakedFaces             = new List <int>();

                            int[] edges          = x.TopologyVertices.ConnectedEdges(vID);
                            int   numberOfNakedV = 0;
                            foreach (int edgeID in edges)
                            {
                                int[] edgeFaces = x.TopologyEdges.GetConnectedFaces(edgeID);
                                if (edgeFaces.Length == 1)
                                {
                                    numberOfNakedV++;
                                    nakedFaces.Add(edgeFaces[0]);
                                    nakedEdges.Add(edgeID);
                                    nakedEdgesP.Add(midPoints[edgeID]);
                                    // nakedEdgesPDistToLastP.Add(lastPoint.DistanceToSquared(midPoints[edgeID]));
                                }
                            }

                            if (nakedFaces.Count == 2)
                            {
                                if (id.Last() == nakedFaces[0])
                                {
                                    polyline.Add(nakedEdgesP[0]);

                                    if (vf.Length <= 10)
                                    {
                                        polyline.Add(x.Vertices[vID]);
                                    }

                                    polyline.Add(nakedEdgesP[1]);

                                    //id.Add(nakedFaces[0]);
                                    //id.Add(nakedFaces[1]);
                                }
                                else
                                {
                                    polyline.Add(nakedEdgesP[1]);
                                    if (vf.Length <= 10)
                                    {
                                        polyline.Add(x.Vertices[vID]);
                                    }

                                    polyline.Add(nakedEdgesP[0]);
                                    //id.Add(nakedFaces[1]);
                                    //id.Add(nakedFaces[0]);
                                }
                            }
                        }


                        polyline.Add(polyline[0]);
                        polylines.Add(polyline);


                        //MeshFace[] faces = polyline.TriangulateClosedPolyline();
                        //if (faces != null) {

                        //    int f = dual.Faces.Count;//current dual faces
                        //    int[] faceId = new int[faces.Length];//triangulate polyline faces


                        //    for (int j = 0; j < faces.Length; j++) {
                        //        //id - face id
                        //        dual.Faces.AddFace(id[faces[j].A], id[faces[j].B], id[faces[j].C]);
                        //        faceId[j] = f++;
                        //    }

                        //    dual.Ngons.AddNgon(MeshNgon.Create(id, faceId));

                        //}
                    }
                }
                dual = MeshCreate.MeshFromPolylines(polylines, 0);
            }
            else
            {
                if (pts != null)
                {
                    if (pts.Count == x.Ngons.Count)
                    {
                        Type = 2;
                    }
                }


                int[][]         tv        = x.GetNGonsTopoBoundaries();
                HashSet <int>   allV      = x.GetAllNGonsVertices();
                List <Polyline> polylines = new List <Polyline>();
                int[][]         vf        = x.GetNGonsConnectedToNGonVertices(allV);
                int[][]         vf_       = new int[vf.Length][];
                List <int>[]    ff        = x.GetNgonFaceAdjacencyOrdered();
                bool[]          naked     = x.GetNakedNGonPointStatus(allV);

                for (int i = 0; i < vf.Length; i++)
                {
                    if (naked[i])
                    {
                        continue;
                    }

                    vf_[i] = new int[vf[i].Length];
                    HashSet <int> tempHash = new HashSet <int>();
                    Polyline      outline  = new Polyline();


                    for (int j = 0; j < vf[i].Length; j++)
                    {
                        if (j == 0)
                        {
                            vf_[i][j] = vf[i][0];
                            tempHash.Add(vf[i][0]);


                            switch (Type)
                            {
                            case (2):
                                outline.Add(pts[vf[i][0]]);
                                break;

                            case (1):
                                outline.Add(x.GetNgonCenter(vf[i][0]));
                                break;

                            default:
                                outline.Add(x.Ngons.GetNgonCenter(vf[i][0]));
                                break;
                            }
                        }
                        else
                        {
                            List <int> ffLocal = ff[vf_[i][j - 1]];
                            List <int> neiF    = ffLocal.Intersect(vf[i]).ToList();

                            foreach (int nf in neiF)
                            {
                                if (tempHash.Add(nf))
                                {
                                    vf_[i][j] = nf;


                                    switch (Type)
                                    {
                                    case (2):
                                        outline.Add(pts[nf]);
                                        break;

                                    case (1):
                                        outline.Add(x.GetNgonCenter(nf));
                                        break;

                                    default:
                                        outline.Add(x.Ngons.GetNgonCenter(nf));
                                        break;
                                    }


                                    break;
                                } //if
                            }
                        }         //if
                    }             //for j

                    outline.Close();
                    polylines.Add(outline);
                    //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(outline);
                }//for i

                dual = MeshCreate.MeshFromPolylines(polylines, 0.01);
            }//if ngon



            dual.Clean();

            //var bfs = NGonsCore.Graphs.UndirectedGraphBfsRhino.MeshBFS(dual, "0");
            //dual = NGonsCore.MeshCreate.MeshFromPolylines(dual.UnifyWinding(bfs.Item2[0].ToArray()), 0.01);

            return(dual);
        }