当前位置: 首页>>代码示例>>C#>>正文


C# MeshBuilder.Append方法代码示例

本文整理汇总了C#中HelixToolkit.Wpf.MeshBuilder.Append方法的典型用法代码示例。如果您正苦于以下问题:C# MeshBuilder.Append方法的具体用法?C# MeshBuilder.Append怎么用?C# MeshBuilder.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HelixToolkit.Wpf.MeshBuilder的用法示例。


在下文中一共展示了MeshBuilder.Append方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawLibGGraphicItem


//.........这里部分代码省略.........
                    //draw a label at the start of the curve
                    if (node.DisplayLabels && i == 0)
                    {
                        rd.Text.Add(new BillboardTextItem { Text = tag, Position = start });
                    }

                    if (selected)
                    {
                        rd.SelectedLines.Add(start);
                        rd.SelectedLines.Add(end);
                    }
                    else
                    {
                        rd.Lines.Add(start);
                        rd.Lines.Add(end);
                    }
                }

                #endregion

                #region draw surface

                //var sw = new Stopwatch();
                //sw.Start();

                var builder = new MeshBuilder();
                var points = new Point3DCollection();
                var tex = new PointCollection();
                var norms = new Vector3DCollection();
                var tris = new List<int>();

                FloatList triangle_vertices = g.triangle_vertices_threadsafe();
                FloatList triangle_normals = g.triangle_normals_threadsafe();

                for (int i = 0; i < triangle_vertices.Count; i+=3)
                {
                    var new_point = new Point3D(triangle_vertices[i],
                                                triangle_vertices[i + 1],
                                                triangle_vertices[i + 2]);

                    var normal = new Vector3D(triangle_normals[i],
                                                triangle_normals[i + 1],
                                                triangle_normals[i + 2]);

                    //find a matching point
                    //compare the angle between the normals
                    //to discern a 'break' angle for adjacent faces
                    //int foundIndex = -1;
                    //for (int j = 0; j < points.Count; j++)
                    //{
                    //    var testPt = points[j];
                    //    var testNorm = norms[j];
                    //    var ang = Vector3D.AngleBetween(normal, testNorm);

                    //    if (new_point.X == testPt.X &&
                    //        new_point.Y == testPt.Y &&
                    //        new_point.Z == testPt.Z &&
                    //        ang > 90.0000)
                    //    {
                    //        foundIndex = j;
                    //        break;
                    //    }
                    //}

                    //if (foundIndex != -1)
                    //{
                    //    tris.Add(foundIndex);
                    //    continue;
                    //}

                    tris.Add(points.Count);
                    points.Add(new_point);
                    norms.Add(normal);
                    tex.Add(new System.Windows.Point(0,0));

                    octree.AddNode(new_point.X, new_point.Y, new_point.Z, node.GUID.ToString());
                }

                //builder.AddTriangles(points, norms, tex);
                builder.Append(points, tris, norms, tex);

                //sw.Stop();
                //Debug.WriteLine(string.Format("{0} elapsed for drawing geometry.", sw.Elapsed));

                //don't add empty meshes
                if (builder.Positions.Count > 0)
                {
                    if (selected)
                    {
                        rd.SelectedMeshes.Add(builder.ToMesh(true));
                    }
                    else
                    {
                        rd.Meshes.Add(builder.ToMesh(true));
                    }
                }

                #endregion
            }
        }
开发者ID:riteshchandawar,项目名称:Dynamo,代码行数:101,代码来源:VisualizationManagerASM.cs

示例2: RevitMeshToHelixMesh

        /// <summary>
        /// Convert a Revit mesh to a Helix mesh for visualization.
        /// In order to merge mesh vertices, this method uses a dictionary with a string key formed as x:y:z of the point.
        /// This assumes that where vertices are the "same" in the Revit mesh, they will have the same coordinates. This
        /// is NOT a safe strategy to use in other mesh-processing contexts where vertices might have small discrepancies.
        /// </summary>
        /// <param name="rmesh"></param>
        /// <param name="octree"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        private static MeshGeometry3D RevitMeshToHelixMesh(Mesh rmesh, Octree.OctreeSearch.Octree octree, NodeModel node)
        {
            var builder = new MeshBuilder();
            var points = new Point3DCollection();
            var tex = new PointCollection();
            var norms = new Vector3DCollection();
            var tris = new List<int>();

            //A dictionary which will contain a point, a normal, and an index
            //keyed on the location of the point as a hash
            var pointDict = new Dictionary<string, PointData>();
            for (int i = 0; i < rmesh.NumTriangles; ++i)
            {
                var tri = rmesh.get_Triangle(i);
                //calculate the face normal by
                //getting the cross product of two edges
                var a = tri.get_Vertex(0);
                var b = tri.get_Vertex(1);
                var c = tri.get_Vertex(2);
                var e1 = b - a;
                var e2 = c - a;
                var normXYZ = e1.CrossProduct(e2).Normalize();
                var normal = new Vector3D(normXYZ.X, normXYZ.Y, normXYZ.Z);

                for (int j = 0; j < 3; j++)
                {
                    var pt = RevitPointToWindowsPoint(tri.get_Vertex(j));
                    var key = pt.X + ":" + pt.Y + ":" + pt.Z;
                    if (!pointDict.ContainsKey(key))
                    {
                        //if the dictionary doesn't contain the key
                        var pd = new PointData(pt.X,pt.Y,pt.Z);
                        pd.Normals.Add(normal);
                        pd.Index = pointDict.Count;
                        pointDict.Add(key, pd);
                        tris.Add(pd.Index);
                    }
                    else
                    {
                        //add an index to our tris array
                        //add a normal to our internal collection
                        //for post processing
                        var data = pointDict[key];
                        tris.Add(data.Index);
                        data.Normals.Add(normal);
                    }
                }
            }

            var lst = pointDict.ToList();
            lst.ForEach(x => points.Add(x.Value.Position));
            lst.ForEach(x=>octree.AddNode(x.Value.Position.X, x.Value.Position.Y, x.Value.Position.Z, node.GUID.ToString()));
            lst.ForEach(x=>tex.Add(x.Value.Tex));

            //merge the normals
            foreach (var pd in lst)
            {
                var avg = new Vector3D();
                var nList = pd.Value.Normals;
                foreach (var n in nList)
                {
                    avg.X += n.X;
                    avg.Y += n.Y;
                    avg.Z += n.Z;
                }
                avg.X = avg.X / nList.Count;
                avg.Y = avg.Y / nList.Count;
                avg.Z = avg.Z / nList.Count;
                norms.Add(avg);
            }

            builder.Append(points, tris, norms, tex);
            Debug.WriteLine(string.Format("Mesh had {0} faces coming in and {1} faces going out.", rmesh.NumTriangles, builder.TriangleIndices.Count / 3));

            return builder.ToMesh(true);
        }
开发者ID:riteshchandawar,项目名称:Dynamo,代码行数:86,代码来源:VisualizationManagerRevit.cs

示例3: ApplyCuttingPlanesToModel

        /// <summary>
        /// Applies the cutting planes to the model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="transform">The transform.</param>
        /// <param name="updateRequired">An update is required if set to <c>true</c>.</param>
        /// <exception cref="System.InvalidOperationException">No inverse transform.</exception>
        /// <exception cref="System.NotImplementedException"></exception>
        private void ApplyCuttingPlanesToModel(GeometryModel3D model, Transform3D transform, bool updateRequired)
        {
            if (model.Geometry == null)
            {
                return;
            }

            if (!this.IsEnabled)
            {
                updateRequired = true;
            }

            Geometry3D cutGeometry;
            if (this.cutGeometries.TryGetValue(model, out cutGeometry))
            {
                // ReSharper disable once RedundantNameQualifier
                if (object.ReferenceEquals(cutGeometry, model.Geometry))
                {
                    updateRequired = true;
                }
            }

            Geometry3D originalGeometry;
            if (!this.originalGeometries.TryGetValue(model, out originalGeometry))
            {
                originalGeometry = model.Geometry;
                updateRequired = true;
            }

            this.newOriginalGeometries.Add(model, originalGeometry);

            if (!updateRequired)
            {
                return;
            }

            var newGeometry = originalGeometry;
            var originalMeshGeometry = originalGeometry as MeshGeometry3D;

            if (this.IsEnabled && originalMeshGeometry != null)
            {
                var inverseTransform = transform.Inverse;
                if (inverseTransform == null)
                {
                    throw new InvalidOperationException("No inverse transform.");
                }

                switch (this.Operation)
                {
                    case CuttingOperation.Intersect:

                        var intersectedGeometry = originalMeshGeometry;

                        // Calculate the intersection of all the intersections
                        foreach (var cp in this.CuttingPlanes)
                        {
                            intersectedGeometry = this.Intersect(intersectedGeometry, inverseTransform, cp, false);
                        }

                        newGeometry = intersectedGeometry;
                        break;
                    case CuttingOperation.Subtract:
                        var builder = new MeshBuilder(originalMeshGeometry.Normals.Any(), originalMeshGeometry.TextureCoordinates.Any());

                        // Calculate the union of all complement intersections
                        foreach (var cp in this.CuttingPlanes)
                        {
                            var cg = this.Intersect(originalMeshGeometry, inverseTransform, cp, true);
                            builder.Append(cg);
                        }

                        newGeometry = builder.ToMesh(true);
                        break;
                }
            }

            model.Geometry = newGeometry;
            this.newCutGeometries.Add(model, originalMeshGeometry);
        }
开发者ID:ondrej11,项目名称:o106,代码行数:87,代码来源:CuttingPlaneGroup.cs

示例4: DrawFacet

        private void DrawFacet(NodeModel node, object obj, string tag, RenderDescription rd,
            Octree.OctreeSearch.Octree octree)
        {
            var facet = obj as Facet;
            if (facet == null)
                return;

            var builder = new MeshBuilder();
            var points = new Point3DCollection();
            var tex = new PointCollection();
            var norms = new Vector3DCollection();
            var tris = new List<int>();

            var a = facet.Points[0];
            var b = facet.Points[1];
            var c = facet.Points[2];

            var side1 = (b - a).Normalize();
            var side2 = (c - a).Normalize();
            var norm = side1.CrossProduct(side2);

            int count = 0;
            foreach (var pt in facet.Points)
            {
                points.Add(new Point3D(pt.X,pt.Y,pt.Z));
                tex.Add(new System.Windows.Point(0,0));
                tris.Add(count);
                norms.Add(new Vector3D(norm.X,norm.Y,norm.Z));
                count++;
            }

            builder.Append(points, tris, norms, tex);

            if (node.IsSelected)
            {
                rd.SelectedMeshes.Add(builder.ToMesh(true));
            }
            else
            {
                rd.Meshes.Add(builder.ToMesh(true));
            }

            if (node.DisplayLabels)
            {
                var cp = (a + b + c)/3;
                rd.Text.Add(new BillboardTextItem { Text = tag, Position = new Point3D(cp.X,cp.Y,cp.Z)});
            }
        }
开发者ID:riteshchandawar,项目名称:Dynamo,代码行数:48,代码来源:VisualizationManagerRevit.cs


注:本文中的HelixToolkit.Wpf.MeshBuilder.Append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。