public bool BakeGeometry(RhinoDoc doc, ObjectAttributes att, out Guid obj_guid)
        {
            obj_guid = Guid.Empty;

            if (att == null)
            {
                att = doc.CreateDefaultAttributes();
            }

            string id    = Guid.NewGuid().ToString();
            int    idxGr = doc.Groups.Add("IG-" + id);
            int    idxLy = doc.Layers.Add("IG-" + id, Color.Aqua);

            ObjectAttributes att1 = att.Duplicate();

            att1.AddToGroup(idxGr);
            att1.LayerIndex = idxLy;

            Line        ln;
            List <long> edgesID = new List <long>();
            long        data1, data2;
            Point3d     p1, p2;
            int         next, count;

            int[] hf;

            foreach (int elementID in ElementsKeys)
            {
                IElement e = GetElementWithKey(elementID);

                for (int halfFacetID = 1; halfFacetID <= e.HalfFacetsCount; halfFacetID++)
                {
                    e.GetHalfFacet(halfFacetID, out hf);

                    count = 1;
                    if (e.TopologicDimension == 3)
                    {
                        count = hf.Length;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        next = i + 1;
                        if (i == count - 1)
                        {
                            if (count > 1)
                            {
                                next = 0;
                            }
                            else
                            {
                                next = 1;
                            }
                        }
                        data1 = (Int64)hf[i] << 32 | (Int64)hf[next];
                        data2 = (Int64)hf[next] << 32 | (Int64)hf[i];
                        if (!edgesID.Contains(data1) && !edgesID.Contains(data2))
                        {
                            p1 = GetVertexWithKey(hf[i]).RhinoPoint;
                            p2 = GetVertexWithKey(hf[next]).RhinoPoint;
                            ln = new Line(p1, p2);
                            doc.Objects.AddLine(ln, att1);
                            edgesID.Add(data1);
                        }
                    }
                }
            }
            return(true);
        }
예제 #2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var vertices = new Point3d[8];

            vertices[0] = new Point3d(10.0, 10.0, 10.0);
            vertices[1] = new Point3d(10.0, 10.0, -10.0);
            vertices[2] = new Point3d(10.0, -10.0, 10.0);
            vertices[3] = new Point3d(10.0, -10.0, -10.0);
            vertices[4] = new Point3d(-10.0, 10.0, 10.0);
            vertices[5] = new Point3d(-10.0, 10.0, -10.0);
            vertices[6] = new Point3d(-10.0, -10.0, 10.0);
            vertices[7] = new Point3d(-10.0, -10.0, -10.0);

            var indices = new int[, ]
            {
                { 0, 1, 5, 4 },
                { 0, 4, 6, 2 },
                { 0, 2, 3, 1 },
                { 7, 3, 2, 6 },
                { 7, 6, 4, 5 },
                { 7, 5, 1, 3 }
            };

            var meshes = new Mesh[6];

            for (var mi = 0; mi < 6; mi++)
            {
                var mesh = new Mesh();
                for (var vi = 0; vi < 4; vi++)
                {
                    mesh.Vertices.Add(vertices[indices[mi, vi]]);
                }
                mesh.Faces.AddFace(0, 1, 2, 3);
                mesh.FaceNormals.ComputeFaceNormals();
                mesh.Normals.ComputeNormals();
                mesh.Compact();
                meshes[mi] = mesh;
            }

            var colors = new Color[]
            {
                Color.Red,
                Color.Orange,
                Color.Yellow,
                Color.Green,
                Color.Blue,
                Color.Purple
            };

            var gi = doc.Groups.Add();

            var atts = new ObjectAttributes {
                ColorSource = ObjectColorSource.ColorFromObject
            };

            atts.AddToGroup(gi);

            for (var mi = 0; mi < 6; mi++)
            {
                atts.ObjectColor = colors[mi];
                doc.Objects.AddMesh(meshes[mi], atts);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }