Example #1
0
        internal Dyn.Mesh ToDynamoMesh(sMesh sm, out List <Color> vcols)
        {
            List <Dyn.Point>      pts    = new List <Autodesk.DesignScript.Geometry.Point>();
            List <Dyn.IndexGroup> indice = new List <Autodesk.DesignScript.Geometry.IndexGroup>();
            List <Color>          cols   = new List <Color>();

            for (int i = 0; i < sm.vertices.Count; ++i)
            {
                pts.Add(ToDynamoPoint(sm.vertices[i].location));
                if (sm.vertices[i].color != null)
                {
                    cols.Add(sm.vertices[i].color.ToWinColor());
                }
            }

            for (int i = 0; i < sm.faces.Count; ++i)
            {
                Dyn.IndexGroup faceIDs = Dyn.IndexGroup.ByIndices((uint)sm.faces[i].A, (uint)sm.faces[i].B, (uint)sm.faces[i].C);
                indice.Add(faceIDs);
            }

            vcols = cols;

            return(Dyn.Mesh.ByPointsFaceIndices(pts, indice));
        }
        private BoundingBox GetRhinoBoundingBox(List <IsObject> objs)
        {
            List <Point3d> pts = new List <Point3d>();

            foreach (IsObject so in objs)
            {
                if (so is sFrameSet)
                {
                    sFrameSet sb = so as sFrameSet;
                    Curve     rc = ToRhinoCurve(sb.parentCrv);
                    Point3d[] dpts;
                    rc.DivideByCount(3, true, out dpts);
                    for (int i = 0; i < dpts.Length; ++i)
                    {
                        pts.Add(dpts[i]);
                    }
                }
                if (so is sMesh)
                {
                    sMesh sm = so as sMesh;
                    foreach (sVertex sv in sm.vertices)
                    {
                        pts.Add(ToRhinoPoint3d(sv.location));
                    }
                }
            }
            return(new BoundingBox(pts));
        }
Example #3
0
        public static object AppendMesh(sSystem sghSystem, string meshName, List <double> verticeNineNumbers, int colorA, int colorR, int colorG, int colorB)
        {
            sDynamoConverter dycon = new sDynamoConverter("Feet", "Meters");

            List <string> meshNames = new List <string>();

            for (int i = 0; i < sghSystem.meshes.Count; ++i)
            {
                if (sghSystem.meshes[i].meshName == meshName)
                {
                    sghSystem.meshes.RemoveAt(i);
                }
            }

            sMesh sm = dycon.TosMesh(dycon.EnsureUnit(verticeNineNumbers), new sColor(colorA, colorR, colorG, colorB));

            sm.meshName = meshName;

            sghSystem.meshes.Add(sm);

            foreach (sMesh mm in sghSystem.meshes)
            {
                meshNames.Add(mm.meshName);
            }

            return(new Dictionary <string, object>
            {
                { "sSystem", sghSystem },
                { "AppendedMeshNames", meshNames }
            });
        }
        public sMesh TosMesh(Mesh rhm)
        {
            Mesh rm = EnsureTriangulated(rhm);

            rm.FaceNormals.ComputeFaceNormals();
            rm.Normals.ComputeNormals();

            sMesh sm = new sMesh();

            for (int i = 0; i < rm.Vertices.Count; ++i)
            {
                sm.SetVertex(i, new sXYZ(rm.Vertices[i].X, rm.Vertices[i].Y, rm.Vertices[i].Z));
                sm.vertices[i].normal = this.TosXYZ(rm.Normals[i]);
                if (rm.VertexColors[i] != null)
                {
                    sm.vertices[i].color = sColor.FromWinColor(rm.VertexColors[i]);
                }
            }

            for (int i = 0; i < rm.Faces.Count; ++i)
            {
                sm.SetFace(i, rm.Faces[i].A, rm.Faces[i].B, rm.Faces[i].C);
                sm.faces[i].normal = this.TosXYZ(rm.FaceNormals[i]);
            }

            return(sm);
        }
        public void ConstructBeamResultMesh(eColorMode colorMode, ref List <sMesh> meshes, out sRange dataRange, sRange threshold = null, double du = 0.0)
        {
            if (colorMode != eColorMode.NONE)
            {
                sRange resultRange = GetSystemBeamResultRange(colorMode);

                foreach (IFrameSet bs in this.frameSets)
                {
                    foreach (sFrame b in bs.frames)
                    {
                        sMesh sm = b.ConstructBeamColorMesh(resultRange, colorMode, threshold, du);
                        meshes.Add(sm);
                    }
                }

                dataRange = resultRange;
            }
            else
            {
                foreach (IFrameSet bs in this.frameSets)
                {
                    foreach (sFrame b in bs.frames)
                    {
                        sMesh sm = b.ConstructBeamColorMesh(new sRange(0.0, 0.0), colorMode, new sRange(0.0, 0.0), 0.0);
                        meshes.Add(sm);
                    }
                }
                dataRange = null;
            }
        }
Example #6
0
        internal sMesh TosMesh(Dyn.Mesh dym)
        {
            sMesh sm = new sMesh();

            for (int i = 0; i < dym.VertexPositions.Length; ++i)
            {
                sm.SetVertex(i, new sXYZ(dym.VertexPositions[i].X, dym.VertexPositions[i].Y, dym.VertexPositions[i].Z));
                // if (rm.VertexColors[i] != null)
                // {
                //     sm.vertices[i].color = sColor.FromWinColor(rm.VertexColors[i]);
                // }
            }

            for (int i = 0; i < dym.FaceIndices.Length; ++i)
            {
                sm.SetFace(i, (int)dym.FaceIndices[i].A, (int)dym.FaceIndices[i].B, (int)dym.FaceIndices[i].C);
            }

            return(sm);
        }
Example #7
0
        internal List <double> ToDynamoMeshTriVerticeInfo(sMesh sm)
        {
            List <double> vs = new List <double>();

            foreach (sFace sf in sm.faces)
            {
                vs.Add(sm.vertices[sf.A].location.X);
                vs.Add(sm.vertices[sf.A].location.Y);
                vs.Add(sm.vertices[sf.A].location.Z);

                vs.Add(sm.vertices[sf.B].location.X);
                vs.Add(sm.vertices[sf.B].location.Y);
                vs.Add(sm.vertices[sf.B].location.Z);

                vs.Add(sm.vertices[sf.C].location.X);
                vs.Add(sm.vertices[sf.C].location.Y);
                vs.Add(sm.vertices[sf.C].location.Z);
            }
            return(vs);
        }
Example #8
0
        internal void ToDynamoToolKitMeshData(sMesh sm, ref List <Dyn.Point> vpts, ref List <int> findice, ref List <int> rr, ref List <int> gg, ref List <int> bb)
        {
            for (int i = 0; i < sm.vertices.Count; ++i)
            {
                vpts.Add(ToDynamoPoint(sm.vertices[i].location));
                // if (sm.vertices[i].color != null)
                // {
                Color vc = sm.vertices[i].color.ToWinColor();
                rr.Add(vc.R);
                gg.Add(vc.G);
                bb.Add(vc.B);
                // }
            }

            for (int i = 0; i < sm.faces.Count; ++i)
            {
                findice.Add(sm.faces[i].A);
                findice.Add(sm.faces[i].B);
                findice.Add(sm.faces[i].C);
            }
        }
        public Mesh ToRhinoMesh(sMesh sm)
        {
            Mesh m = new Mesh();

            for (int i = 0; i < sm.vertices.Count; ++i)
            {
                m.Vertices.SetVertex(i, sm.vertices[i].location.X, sm.vertices[i].location.Y, sm.vertices[i].location.Z);
                if (sm.vertices[i].color != null)
                {
                    Color vcol = sm.vertices[i].color.ToWinColor();
                    m.VertexColors.SetColor(i, vcol);
                }
            }
            for (int i = 0; i < sm.faces.Count; ++i)
            {
                m.Faces.SetFace(i, sm.faces[i].A, sm.faces[i].B, sm.faces[i].C);
            }
            m.FaceNormals.ComputeFaceNormals();
            m.Normals.ComputeNormals();
            return(m);
        }
Example #10
0
        internal sMesh TosMesh(List <double> triVerticeInfo, sColor scol)
        {
            //nine conseq
            sMesh sm        = new sMesh();
            int   faceCount = (int)(triVerticeInfo.Count / 9);

            int verID  = 0;
            int infoID = 0;

            for (int i = 0; i < faceCount; ++i)
            {
                sm.SetVertex(verID + 0, new sXYZ(triVerticeInfo[infoID + 0], triVerticeInfo[infoID + 1], triVerticeInfo[infoID + 2]), scol);
                sm.SetVertex(verID + 1, new sXYZ(triVerticeInfo[infoID + 3], triVerticeInfo[infoID + 4], triVerticeInfo[infoID + 5]), scol);
                sm.SetVertex(verID + 2, new sXYZ(triVerticeInfo[infoID + 6], triVerticeInfo[infoID + 7], triVerticeInfo[infoID + 8]), scol);

                sm.SetFace(i, verID + 0, verID + 1, verID + 2);

                verID  += 3;
                infoID += 9;
            }
            sm.ComputeNormals();

            return(sm);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            sSystem     ssys     = null;
            string      meshName = "";
            List <Mesh> ms       = new List <Mesh>();

            System.Drawing.Color col = System.Drawing.Color.Empty;


            if (!DA.GetData(0, ref ssys))
            {
                return;
            }
            if (!DA.GetData(1, ref meshName))
            {
                return;
            }
            if (!DA.GetDataList(2, ms))
            {
                return;
            }
            if (!DA.GetData(3, ref col))
            {
                return;
            }


            string          modelUnit = Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem.ToString();
            sRhinoConverter rhcon     = new sRhinoConverter(modelUnit, "Meters");

            Mesh bm = new Mesh();

            foreach (Mesh m in ms)
            {
                Mesh ensuredM = rhcon.EnsureUnit(m) as Mesh;
                bm.Append(ensuredM);
            }
            bm.Vertices.CombineIdentical(false, false);

            for (int i = 0; i < bm.Vertices.Count; ++i)
            {
                bm.VertexColors.SetColor(i, col);
            }

            int           count     = 0;
            List <string> meshNames = new List <string>();

            foreach (sMesh sm in ssys.meshes)
            {
                if (sm.meshName == meshName)
                {
                    count++;
                }
                meshNames.Add(sm.meshName);
            }

            string mms = "Appended Meshes";

            if (count == 0)
            {
                sMesh sm = rhcon.TosMesh(bm);
                sm.opacity  = (double)(col.A) / (255.0);
                sm.meshName = meshName;

                ssys.meshes.Add(sm);
            }

            foreach (string mn in meshNames)
            {
                mms += "\n" + mn;
            }
            this.Message = mms;


            DA.SetData(0, ssys);
        }
Example #12
0
        public sMesh ConstructBeamColorMesh(sRange dataRange, eColorMode colorMode, sRange threshold, double du)
        {
            sMesh sm = new sMesh();

            int vertexID = 0;

            for (int i = 0; i < this.results.Count; ++i)
            {
                sFrameResult br = this.results[i];

                for (int j = 0; j < br.sectionResults.Count; ++j)
                {
                    sFrameSectionResult sr = br.sectionResults[j];
                    sColor vcol            = this.GetBeamResultColor(dataRange, colorMode, i, j, 255, threshold);
                    sXYZ   deflectionVec   = du * (sr.deflection_mm * 0.001);
                    sXYZ   deflectedPt     = sr.location + deflectionVec;
                    sm.SetVertex(vertexID, deflectedPt, vcol);
                    //or
                    //sm.SetVertex(vertexID, sr.point, vcol);

                    sr.ID = vertexID;

                    vertexID++;
                }
            }

            int vertexCountPerFace = this.results[0].sectionResults.Count;
            int faceIndex          = 0;

            for (int i = 0; i < this.results.Count - 1; ++i)
            {
                sFrameResult br_this = this.results[i];
                sFrameResult br_next = this.results[i + 1];

                for (int j = 0; j < br_this.sectionResults.Count; ++j)
                {
                    int id0 = 0;
                    int id1 = 0;
                    int id2 = 0;
                    int id3 = 0;
                    if (j < br_this.sectionResults.Count - 1)
                    {
                        id0 = br_this.sectionResults[j].ID;
                        id1 = br_next.sectionResults[j].ID;
                        id2 = br_next.sectionResults[j + 1].ID;
                        id3 = br_this.sectionResults[j + 1].ID;
                    }
                    else
                    {
                        id0 = br_this.sectionResults[j].ID;
                        id1 = br_next.sectionResults[j].ID;
                        id2 = br_next.sectionResults[0].ID;
                        id3 = br_this.sectionResults[0].ID;
                    }

                    sm.SetFace(faceIndex, faceIndex + 1, id0, id1, id2, id3);
                    faceIndex += 2;
                }
            }

            sm.ComputeNormals();
            return(sm);
        }