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


C# MeshBuilder.ToMesh方法代码示例

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


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

示例1: MainViewModel

        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            // Create a model group
            var modelGroup = new Model3DGroup();

            // Create a mesh builder and add a box to it
            var meshBuilder = new MeshBuilder(false, false);
            meshBuilder.AddBox(new Point3D(0, 0, 1), 1, 2, 0.5);
            meshBuilder.AddBox(new Rect3D(0, 0, 1.2, 0.5, 1, 0.4));

            // Create a mesh from the builder (and freeze it)
            var mesh = meshBuilder.ToMesh(true);

            // Create some materials
            var greenMaterial = MaterialHelper.CreateMaterial(Colors.Green);
            var redMaterial = MaterialHelper.CreateMaterial(Colors.Red);
            var blueMaterial = MaterialHelper.CreateMaterial(Colors.Blue);
            var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);

            // Add 3 models to the group (using the same mesh, that's why we had to freeze it)
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Material = greenMaterial, BackMaterial = insideMaterial });
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(-2, 0, 0), Material = redMaterial, BackMaterial = insideMaterial });
            modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(2, 0, 0), Material = blueMaterial, BackMaterial = insideMaterial });

            // Set the property, which will be bound to the Content property of the ModelVisual3D (see MainWindow.xaml)
            this.Model = modelGroup;
        }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:30,代码来源:MainViewModel.cs

示例2: 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:chantsunman,项目名称:helix-toolkit,代码行数:10,代码来源:MainWindow.xaml.cs

示例3: DemoElement3D

        public DemoElement3D()
        {
            var gm = new GeometryModel3D();
            var mb = new MeshBuilder();
            mb.AddSphere(new Point3D(0, 0, 0), 2, 100, 50);
            gm.Geometry = mb.ToMesh();
            gm.Material = Materials.Blue;

            Visual3DModel = gm;
        }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:10,代码来源:DemoElement3D.cs

示例4: CreateDice

        private ModelVisual3D CreateDice()
        {
            var diceMesh = new MeshBuilder();
            diceMesh.AddBox(new Point3D(0, 0, 0), 1, 1, 1);
            for (int i = 0; i < 2; i++)
                for (int j = 0; j < 2; j++)
                    for (int k = 0; k < 2; k++)
                    {
                        var points = new List<Point3D>();
                        diceMesh.ChamferCorner(new Point3D(i - 0.5, j - 0.5, k - 0.5), 0.1, 1e-6, points);
                        //foreach (var p in points)
                        //    b.ChamferCorner(p, 0.03);
                    }

            return new ModelVisual3D { Content = new GeometryModel3D { Geometry = diceMesh.ToMesh(), Material = Materials.White } };
        }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:16,代码来源:MainWindow.xaml.cs

示例5: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            var container = new ContainerUIElement3D();
            var element = new ModelUIElement3D();
            var geometry = new GeometryModel3D();
            var meshBuilder = new MeshBuilder();
            meshBuilder.AddSphere(new Point3D(0, 0, 0), 2, 100, 50);
            geometry.Geometry = meshBuilder.ToMesh();
            geometry.Material = Materials.Green;
            element.Model = geometry;
            element.Transform = new TranslateTransform3D(5, 0, 0);
            element.MouseDown += this.ContainerElementMouseDown;
            container.Children.Add(element);
            view1.Children.Add(container);
        }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:17,代码来源:MainWindow.xaml.cs

示例6: Generate

        public override GeometryModel3D Generate()
        {
            var mesh = new MeshBuilder();

            AddBranch(mesh, new Point3D(0,0,0), UpVector, 0);

            var mv = new GeometryModel3D
            {
                Geometry = mesh.ToMesh(),
                Material = mat,
                BackMaterial = mat
            };

            TriangleCount = mesh.TriangleIndices.Count / 3;

            return mv;
        }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:17,代码来源:Plant.cs

示例7: GetDefaultGeometry

 private static Geometry3D GetDefaultGeometry()
 {
     // The default geometry is a box
     var mb = new MeshBuilder(false, false);
     mb.AddBox(new Point3D(0, 0, 0.5), 0.8, 0.8, 1);
     return mb.ToMesh();
 }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:7,代码来源:SpectrumAnalyser.cs

示例8: MeshBuild

 private void MeshBuild()
 {
     //build the box for the nodes
     MeshBuilder builder = new MeshBuilder();
     builder.AddBox(new Point3D(0, 0, 0), 2, 2, 2);
     _nodeModel = new GeometryModel3D(builder.ToMesh(), Materials.Green);
 }
开发者ID:Unchated,项目名称:pogee-3d-editor,代码行数:7,代码来源:PathDisplay3D.cs

示例9: CreateInitialMesh

        private void CreateInitialMesh()
        {
            var pts = new Point3D[n, m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                {
                    pts[i, j] = new Point3D(-Length * j / (m - 1), 0, PoleHeight - Height * i / (n - 1));
                }

            var mb = new MeshBuilder(false, true);
            mb.AddRectangularMesh(pts, null, false, false);
            Mesh = mb.ToMesh();
        }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:13,代码来源:Flag.cs

示例10: UpdateGeometry

 /// <summary>
 /// Updates the geometry.
 /// </summary>
 protected override void UpdateGeometry()
 {
     var mb = new MeshBuilder(false, false);
     var p0 = new Point3D(0, 0, 0);
     var d = this.Direction;
     d.Normalize();
     var p1 = p0 + (d * this.Length);
     mb.AddArrow(p0, p1, this.Diameter);
     this.Model.Geometry = mb.ToMesh();
 }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:13,代码来源:TranslateManipulator.cs

示例11: ToMeshGeometry3D

        /// <summary>
        /// Converts the mesh to a MeshGeometry3D.
        /// </summary>
        /// <param name="sharedVertices">
        /// Allow shared vertices (smooth shading) if set to <c>true</c> .
        /// </param>
        /// <param name="shrinkFactor">
        /// The shrink factor.
        /// </param>
        /// <param name="faceIndices">
        /// The face indices.
        /// </param>
        /// <returns>
        /// A mesh geometry.
        /// </returns>
        public MeshGeometry3D ToMeshGeometry3D(
            bool sharedVertices = true, double shrinkFactor = 0.0, List<int> faceIndices = null)
        {
            bool shrink = Math.Abs(shrinkFactor) > double.Epsilon;

            if (!sharedVertices || shrink)
            {
                // not shared vertices - flat shading
                var tm = new MeshBuilder(false, this.TextureCoordinates != null);
                int faceIndex = 0;
                foreach (var face in this.Faces)
                {
                    var vertices = new int[face.Length];
                    int j = 0;

                    var centroid = this.FindCentroid(faceIndex);

                    // var n = GetFaceNormal(faceIndex);
                    // for (int i = 0; i < face.Length; i++)
                    // tm.Normals.Add(n);
                    foreach (int v in face)
                    {
                        vertices[j++] = tm.Positions.Count;
                        var vertex = this.Vertices[v];
                        if (shrink)
                        {
                            vertex = vertex + (shrinkFactor * (centroid - vertex));
                        }

                        tm.Positions.Add(vertex);
                        if (tm.CreateTextureCoordinates)
                        {
                            tm.TextureCoordinates.Add(this.TextureCoordinates[v]);
                        }
                    }

                    tm.AddTriangleFan(vertices);
                    if (faceIndices != null)
                    {
                        int numberOfTriangles = vertices.Length - 2;
                        for (int i = 0; i < numberOfTriangles; i++)
                        {
                            faceIndices.Add(faceIndex);
                        }
                    }

                    faceIndex++;
                }

                return tm.ToMesh();
            }
            else
            {
                // shared vertices - smooth shading
                var tm = new MeshBuilder(false, this.TextureCoordinates != null);
                foreach (var v in this.Vertices)
                {
                    tm.Positions.Add(v);
                }

                if (this.TextureCoordinates != null)
                {
                    foreach (var uv in this.TextureCoordinates)
                    {
                        tm.TextureCoordinates.Add(uv);
                    }
                }

                int faceIndex = 0;
                foreach (var face in this.Faces)
                {
                    tm.AddTriangleFan(face);
                    if (faceIndices != null)
                    {
                        int numberOfTriangles = face.Length - 2;
                        for (int i = 0; i < numberOfTriangles; i++)
                        {
                            faceIndices.Add(faceIndex);
                        }
                    }

                    faceIndex++;
                }

                return tm.ToMesh();
//.........这里部分代码省略.........
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:101,代码来源:Mesh3D.cs

示例12: AppearanceChanged

        private void AppearanceChanged()
        {
            var builder = new MeshBuilder(false, false);
            foreach (var p1 in DistributePoles(this.Positions, this.PoleDistance))
            {
                var p2 = p1 + new Vector3D(0, 0, this.Height);
                builder.AddCylinder(p1, p2, this.Diameter, 36);
            }

            this.postsModel.Geometry = builder.ToMesh();

            var fenceBuilder = new MeshBuilder(false, true);
            var w0 = 0d;
            for (int i = 0; i + 1 < this.Positions.Count; i++)
            {
                var p0 = this.Positions[i];
                var p1 = this.Positions[i + 1];
                var p2 = this.Positions[i + 1] + new Vector3D(0, 0, this.Height);
                var p3 = this.Positions[i] + new Vector3D(0, 0, this.Height);
                var h = this.Height / this.MeshSize;
                var dw = p0.DistanceTo(p1) / this.MeshSize;
                fenceBuilder.AddQuad(
                    p0,
                    p1,
                    p2,
                    p3,
                    new Point(w0, h),
                    new Point(w0 + dw, h),
                    new Point(w0 + dw, 0),
                    new Point(w0, 0));
                w0 += dw;
            }

            this.fenceModel.Geometry = fenceBuilder.ToMesh();
        }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:35,代码来源:FenceVisual3D.cs

示例13: CreateVoxelModel3D

 private static GeometryModel3D CreateVoxelModel3D(Voxel v)
 {
     const double size = 0.98;
     var m = new GeometryModel3D();
     var mb = new MeshBuilder();
     mb.AddBox(new Point3D(0, 0, 0), size, size, size);
     m.Geometry = mb.ToMesh();
     m.Material = MaterialHelper.CreateMaterial(v.Colour);
     m.Transform = new TranslateTransform3D(v.Position.X, v.Position.Y, v.Position.Z);
     return m;
 }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:11,代码来源:MainViewModel.cs

示例14: Tessellate

        /// <summary>
        /// Do the tessellation and return the <see cref="MeshGeometry3D"/>.
        /// </summary>
        /// <returns>The mesh geometry.</returns>
        protected override MeshGeometry3D Tessellate()
        {
            var b = new MeshBuilder(false, true);
            b.AddCubeFace(
                this.Center, new Vector3D(-1, 0, 0), new Vector3D(0, 0, 1), this.Length, this.Width, this.Height);
            b.AddCubeFace(
                this.Center, new Vector3D(1, 0, 0), new Vector3D(0, 0, -1), this.Length, this.Width, this.Height);
            b.AddCubeFace(
                this.Center, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), this.Width, this.Length, this.Height);
            b.AddCubeFace(
                this.Center, new Vector3D(0, 1, 0), new Vector3D(0, 0, -1), this.Width, this.Length, this.Height);
            if (this.TopFace)
            {
                b.AddCubeFace(
                    this.Center, new Vector3D(0, 0, 1), new Vector3D(0, -1, 0), this.Height, this.Length, this.Width);
            }

            if (this.BottomFace)
            {
                b.AddCubeFace(
                    this.Center, new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), this.Height, this.Length, this.Width);
            }

            return b.ToMesh();
        }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:29,代码来源:BoxVisual3D.cs

示例15: RenderObjects

        public void RenderObjects()
        {
            if (_renderObjects == null) return;
            Model3DGroup group = Model as Model3DGroup;

            #region Texturing
            /*
            Dictionary<BitmapImage, List<PolygonRender> > polysByTexture = new Dictionary<BitmapImage, List<PolygonRender> >();

            foreach (var obj in _renderObjects)
            {
                foreach (var p in obj.Polygons)
                {
                    if (p.Image == null) continue;

                    if (!polysByTexture.ContainsKey(p.Image))
                    {
                        polysByTexture[p.Image] = new List<PolygonRender>();
                    }
                    polysByTexture[p.Image].Add(obj);
                }
            }

            var rotate = new RotateTransform3D();
            rotate.Rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90);
            var builder = new MeshBuilder();
            Material mat = Materials.Gold;
            foreach (var obj in polysByTexture)
            {
                foreach (var pr in obj.Value)
                {
                    var transforms = pr.Location.GetTransforms();
                    float scaleY = pr.Location.ScaleY;
                    float scaleX = pr.Location.ScaleX;
                    float scaleZ = pr.Location.ScaleZ;

                    foreach(var poly in pr.Polygons.Where( x => x.Image == obj.Key ) )
                    {
                        Point3D p1 = new Point3D(poly.V1.X * scaleX, poly.V1.Y * scaleY, poly.V1.Z * scaleZ);
                        Point3D p2 = new Point3D(poly.V2.X * scaleX, poly.V2.Y * scaleY, poly.V2.Z * scaleZ);
                        Point3D p3 = new Point3D(poly.V3.X * scaleX, poly.V3.Y * scaleY, poly.V3.Z * scaleZ);

                        foreach (var t in transforms)
                        {
                            p1 = t.Transform(p1);
                            p2 = t.Transform(p2);
                            p3 = t.Transform(p3);
                        }

                        p1 = rotate.Transform(p1);
                        p2 = rotate.Transform(p2);
                        p3 = rotate.Transform(p3);

                        if (!Clipping.DrawPoint(p1) || !Clipping.DrawPoint(p2) || !Clipping.DrawPoint(p3))
                        {
                            continue;
                        }

                        //v coordinate - negate it to convert from opengl coordinates to directx
                        //var t1 = new System.Windows.Point(poly.V1.U, 1 - poly.V1.V);
                        //var t2 = new System.Windows.Point(poly.V2.U, 1 - poly.V2.V);
                        //var t3 = new System.Windows.Point(poly.V3.U, 1 - poly.V3.V);

                        //var t1 = new System.Windows.Point(0.0, 0.0);
                        //var t2 = new System.Windows.Point(2.0, 0.0);
                        //var t3 = new System.Windows.Point(0.0, 2.0);
                        //builder.AddTriangle(p3, p2, p1, t3, t2, t1);
                        //builder.AddTriangle(p3, p2, p1, t3, t2, t1);
                        builder.AddTriangle(p3, p2, p1);

                    }
                }
            }
            group.Children.Add(new GeometryModel3D(builder.ToMesh(), mat));
            */
            #endregion

            Material mat = Materials.DarkGray;
            var builder = new MeshBuilder();
            var rotate = new RotateTransform3D();
            rotate.Rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90);
            foreach (var obj in _renderObjects)
            {
                var transforms = obj.Location.GetTransforms();

                float scaleY = obj.Location.ScaleY;
                float scaleX = obj.Location.ScaleX;
                float scaleZ = obj.Location.ScaleZ;

                foreach (var poly in obj.Polygons)
                {
                    Point3D p1 = new Point3D(poly.V1.X * scaleX, poly.V1.Y * scaleY, poly.V1.Z * scaleZ);
                    Point3D p2 = new Point3D(poly.V2.X * scaleX, poly.V2.Y * scaleY, poly.V2.Z * scaleZ);
                    Point3D p3 = new Point3D(poly.V3.X * scaleX, poly.V3.Y * scaleY, poly.V3.Z * scaleZ);

                    foreach (var t in transforms)
                    {
                        p1 = t.Transform(p1);
                        p2 = t.Transform(p2);
                        p3 = t.Transform(p3);
//.........这里部分代码省略.........
开发者ID:Unchated,项目名称:pogee-3d-editor,代码行数:101,代码来源:WldDisplay3D.cs


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