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


C# MeshBuilder.AddTriangle方法代码示例

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


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

示例1: buildTri

 private static object buildTri()
 {
     var mb = new MeshBuilder(true, false);
     var p0 = new Point3D(0, 0, 0);
     var p1 = new Point3D(1, 0, 0);
     var p2 = new Point3D(1, 1, 0);
     mb.AddTriangle(p0, p1, p2);
     mb.Normals.ToList().ForEach(x => System.Diagnostics.Trace.WriteLine(x.ToString()));
     return mb.ToMesh();
 }
开发者ID:JeremyAnsel,项目名称:helix-toolkit,代码行数:10,代码来源:MainWindow.xaml.cs

示例2: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            var material = MaterialHelper.CreateMaterial(Colors.Aqua);

            var builder = new MeshBuilder();
            builder.AddTriangle(new Point3D(0, 0, 0), new Point3D(0, 10, 100), new Point3D(100, 0, 0));
            var mesh = builder.ToMesh();
            var geo = new GeometryModel3D { Geometry = mesh, Material = material , Transform = null};
            var model = new ModelVisual3D { Content = geo, Transform = null };
            _visual.Children.Add(model);
        }
开发者ID:0x53A,项目名称:helix-crash,代码行数:13,代码来源:MainWindow.xaml.cs

示例3: PartMesh

        public PartMesh(string filename)
        {
            var meshBuilder = new MeshBuilder(false, false);

            var min = new Point3D(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity);
            var max = new Point3D(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity);

            using (var stream = modelAssembly.GetManifestResourceStream("Hexenstein.Models." + filename))
            using (var reader = new BinaryReader(stream))
            {
                var header = reader.ReadBytes(80);

                var num = reader.ReadUInt32();

                for (int i = 0; i < num; i++)
                {
                    var normal = ReadPoint(reader);
                    var v1 = ReadPoint(reader);
                    var v2 = ReadPoint(reader);
                    var v3 = ReadPoint(reader);
                    var extra = reader.ReadInt16();

                    meshBuilder.AddTriangle(v1, v2, v3);

                    min = new Point3D(
                        Math.Min(Math.Min(Math.Min(min.X, v1.X), v2.X), v3.X),
                        Math.Min(Math.Min(Math.Min(min.Y, v1.Y), v2.Y), v3.Y),
                        Math.Min(Math.Min(Math.Min(min.Z, v1.Z), v2.Z), v3.Z));

                    max = new Point3D(
                        Math.Max(Math.Max(Math.Max(max.X, v1.X), v2.X), v3.X),
                        Math.Max(Math.Max(Math.Max(max.Y, v1.Y), v2.Y), v3.Y),
                        Math.Max(Math.Max(Math.Max(max.Z, v1.Z), v2.Z), v3.Z));
                }
            }

            Centre = ((max - min) / 2 + min);
            Mesh = meshBuilder.ToMesh(true);
        }
开发者ID:bgbock,项目名称:Hexenstein,代码行数:39,代码来源:PartMesh.cs

示例4: Button_Click

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();
            ofd.FileOk += (_, __) =>
            {
                var file = ofd.FileName;
                Result r;
                using (var fs = File.OpenRead(file))
                    r = ProtoBuf.Serializer.Deserialize<Result>(fs);

                _model.Children.Clear();

                var nLines = r.Elements.SelectMany(x => x.Geometries).Select(g => r.Geometries[g.GeometryIndex]).Select(x => ((TriangulatedGeometryData)x).Lines.Length).Sum();
                var nTriangles = r.Elements.SelectMany(x => x.Geometries).Select(g => r.Geometries[g.GeometryIndex]).Select(x => ((TriangulatedGeometryData)x).Triangles.Length).Sum();

                Debug.WriteLine($"Model contains {nLines} Lines and {nTriangles} Triangles");

                var material = MaterialHelper.CreateMaterial(Colors.Red, 1);

                foreach (var ele in r.Elements)
                {
                    foreach (var geoRef in ele.Geometries)
                    {
                        var geo = r.Geometries[geoRef.GeometryIndex];
                        var triangulated = geo as TriangulatedGeometryData;
                        if (triangulated != null)
                        {
                            var builder = new MeshBuilder(true, false);
                            foreach (var t in triangulated.Triangles)
                            {
                                var a = r.PointsAndVectors[t.A].ToWpfPoint();
                                var b = r.PointsAndVectors[t.B].ToWpfPoint();
                                var c = r.PointsAndVectors[t.C].ToWpfPoint();
                                builder.AddTriangle(a, c, b);
                            }
                            var mesh = builder.ToMesh(true);
                            var geoModel = new GeometryModel3D { Geometry = mesh, Material = material };

                            Transform3D matrix = null;
                            if (geoRef.Transform != null)
                            {
                                matrix = new MatrixTransform3D(MatrixHelper.FromArray(geoRef.Transform.Matrix));
                                geoModel.Transform = matrix;
                            }
                            var modelVisual = new ModelVisual3D { Content = geoModel };

                            if (_lines.IsChecked == true)
                            {
                                foreach (var l in triangulated.Lines)
                                {
                                    var a = r.PointsAndVectors[l.A].ToWpfPoint();
                                    var b = r.PointsAndVectors[l.B].ToWpfPoint();
                                    var lineGeo = new LinesVisual3D { Color = Colors.Green, Points = new[] { a, b } };
                                    if (matrix != null)
                                        lineGeo.Transform = matrix;

                                    modelVisual.Children.Add(lineGeo);
                                }
                            }

                            _model.Children.Add(modelVisual);
                        }
                        else
                        {
                            throw new Exception("unknown geo data: " + geo.GetType());
                        }
                    }
                }
                _viewPort.ZoomExtents(500);
            };
            ofd.ShowDialog();
        }
开发者ID:0x53A,项目名称:mTIM-Viewer,代码行数:72,代码来源:MainWindow.xaml.cs

示例5: VisualizeBimPlusDataAsGenericElements

        public List<MeshIdandGeometry> VisualizeBimPlusDataAsGenericElements(List<GenericElement> baseElements, object sender)
        {
            if (InputPorts[0].Data == null)
                return null;

            var max = baseElements.Count;
            var m_i = 1;

            // Init some lists and containers
            var container = new ContainerUIElement3D();
            var geometry = new List<MeshIdandGeometry>();

            // Init the MeshBuilde
            var meshBuilder = new MeshBuilder(false, false);

            // Loop the items of each list
            foreach (var item in baseElements)
            {
                // Get the geometric data from the AttributeGroups
                var points = item.AttributeGroups["geometry"].Attributes["threejspoints"] as IList<Point3D>;
                var triangleindices = item.AttributeGroups["geometry"].Attributes["geometryindices"];
                var indices =
                    (from index in triangleindices as IList<uint> select Convert.ToInt32(index)).ToList();

                for (var i = 0; i < indices.Count; i++)
                {
                    if (indices[i] == 0)
                    {
                        meshBuilder.AddTriangle(points[indices[i + 1]], points[indices[i + 2]],
                            points[indices[i + 3]]);

                        i = i + 3;
                    }
                    else if (indices[i] == 1)
                    {
                        meshBuilder.AddQuad(points[indices[i + 1]], points[indices[i + 2]],
                            points[indices[i + 3]],
                            points[indices[i + 4]]);
                        i = i + 4;
                    }
                }

                // Get the color of each representation group
                var color = Convert.ToInt64(item.AttributeGroups["geometry"].Attributes["color"]);
                var tempcolor = Color.FromArgb((int)color);

                var col = new System.Windows.Media.Color
                {
                    A = tempcolor.A,
                    G = tempcolor.G,
                    R = tempcolor.R,
                    B = tempcolor.B
                };

                var myGeometryModel = new GeometryModel3D
                {
                    Material = new DiffuseMaterial(new SolidColorBrush(col)),
                    BackMaterial = new DiffuseMaterial(new SolidColorBrush(col)),
                    Geometry = meshBuilder.ToMesh(true),
                    Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90))
                };

                myGeometryModel.Freeze();

                var meshAndId = new MeshIdandGeometry
                {
                    Id = item.Id,
                    Model3D = myGeometryModel,
                    Material = myGeometryModel.Material
                };

                geometry.Add(meshAndId);

                // Save the parsed information in the elements attribute group
                item.AttributeGroups["geometry"].Attributes["parsedGeometry"] = meshAndId;

                // Refresh the builder so that we do not duplicate the meshes 
                meshBuilder = new MeshBuilder(false, false);

                m_i++;
                var progressPercentage = Convert.ToInt32(((double)m_i / max) * 100);
                var backgroundWorker = sender as BackgroundWorker;
                backgroundWorker?.ReportProgress(progressPercentage, item.Id);
            }

            container.Children.Clear();
            return geometry;
        }
开发者ID:Dessix,项目名称:TUM.CMS.VPLControl,代码行数:88,代码来源:BimPlusWatch3DNode.cs

示例6: MeshObject

        public MeshGeometry3D MeshObject(DtObject item, MeshBuilder meshBuilder)
        {
            var points = item.AttributeGroups["geometry"].GetProperty("threejspoints") as List<Point3D>;
            var indices = item.AttributeGroups["geometry"].GetProperty("geometryindices") as List<uint>;

            if (indices == null)
                return null;

            for (var i = 0; i < indices.Count; i++)
            {
                switch (indices[i])
                {
                    case 0:
                        meshBuilder.AddTriangle(points[(int)indices[i + 1]], points[(int)indices[i + 2]],
                            points[(int)indices[i + 3]]);

                        i = i + 3;
                        break;
                    case 1:
                        meshBuilder.AddQuad(points[(int)indices[i + 1]], points[(int)indices[i + 2]],
                            points[(int)indices[i + 3]],
                            points[(int)indices[i + 4]]);
                        i = i + 4;
                        break;
                }
            }
            return meshBuilder.ToMesh(true);
        }
开发者ID:corneliuspreidel,项目名称:TUM.CMS.VPLControl,代码行数:28,代码来源:BimPlusWatch3DNode.cs

示例7: Cut

        /// <summary>
        /// Cuts the mesh with the specified plane.
        /// </summary>
        /// <param name="mesh">
        /// The mesh.
        /// </param>
        /// <param name="p">
        /// The plane origin.
        /// </param>
        /// <param name="n">
        /// The plane normal.
        /// </param>
        /// <returns>
        /// The <see cref="MeshGeometry3D"/>.
        /// </returns>
        public static MeshGeometry3D Cut(MeshGeometry3D mesh, Point3D p, Vector3D n)
        {
            var ch = new ContourHelper(p, n);
            var mb = new MeshBuilder(false, false);
            //foreach (var pos in mesh.Positions)
            //{
                //mb.Positions.Add(pos);
            //}

            int j = mb.Positions.Count;
            for (int i = 0; i < mesh.TriangleIndices.Count; i += 3)
            {
                int i0 = mesh.TriangleIndices[i];
                int i1 = mesh.TriangleIndices[i + 1];
                int i2 = mesh.TriangleIndices[i + 2];
                var p0 = mesh.Positions[i0];
                var p1 = mesh.Positions[i1];
                var p2 = mesh.Positions[i2];
                Point3D s0, s1;
                int r = ch.ContourFacet(p0, p1, p2, out s0, out s1);
                switch (r)
                {
                    case -1:
                        //mb.TriangleIndices.Add(i0);
                        //mb.TriangleIndices.Add(i1);
                        //mb.TriangleIndices.Add(i2);
                        
                        mb.AddTriangle(p0, p1, p2);
                        break;
                    case 0:
                        //mb.Positions.Add(s1);
                        //mb.Positions.Add(s0);
                        //mb.TriangleIndices.Add(i0);
                        //mb.TriangleIndices.Add(j++);
                        //mb.TriangleIndices.Add(j++);
                        
                        mb.AddTriangle(p0, s1, s0);
                        break;
                    case 1:
                        //mb.Positions.Add(s0);
                        //mb.Positions.Add(s1);
                        //mb.TriangleIndices.Add(i1);
                        //mb.TriangleIndices.Add(j++);
                        //mb.TriangleIndices.Add(j++);
                        
                        mb.AddTriangle(p1, s0, s1);
                        break;
                    case 2:
                        //mb.Positions.Add(s0);
                        //mb.Positions.Add(s1);
                        //mb.TriangleIndices.Add(i2);
                        //mb.TriangleIndices.Add(j++);
                        //mb.TriangleIndices.Add(j++);
                         
                        mb.AddTriangle(p2, s0, s1);
                        break;
                    case 10:
                        //mb.Positions.Add(s0);
                        //mb.Positions.Add(s1);
                        //mb.TriangleIndices.Add(i1);
                        //mb.TriangleIndices.Add(i2);
                        //mb.TriangleIndices.Add(j);
                        //mb.TriangleIndices.Add(j++);
                        //mb.TriangleIndices.Add(j++);
                        //mb.TriangleIndices.Add(i1);
                        
                        mb.AddTriangle(p1, p2, s0);
                        mb.AddTriangle(s0, s1, p1);
                        break;
                    case 11:
                        //mb.Positions.Add(s1);
                        //mb.Positions.Add(s0);
                        //mb.TriangleIndices.Add(i2);
                        //mb.TriangleIndices.Add(i0);
                        //mb.TriangleIndices.Add(j);
                        //mb.TriangleIndices.Add(j++);
                        //mb.TriangleIndices.Add(j++);
                        //mb.TriangleIndices.Add(i2);
                        
                        mb.AddTriangle(p2, p0, s1);
                        mb.AddTriangle(s1, s0, p2);
                        break;
                    case 12:
                        //mb.Positions.Add(s1);
                        //mb.Positions.Add(s0);
//.........这里部分代码省略.........
开发者ID:sivarajankumar,项目名称:dentalsmile,代码行数:101,代码来源:MeshGeometryHelper.cs


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