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


C# Point3DCollection.ElementAtOrDefault方法代码示例

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


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

示例1: BuildMeshesWireframes

        private void BuildMeshesWireframes(OptFile opt)
        {
            this.meshesWireframes = null;

            if (opt == null)
            {
                return;
            }

            this.meshesWireframes = opt.Meshes
                .AsParallel()
                .AsOrdered()
                .Select(mesh =>
                {
                    var positions = new Point3DCollection(
                        mesh.Vertices
                        .Select(t => new Point3D(-t.Y, -t.X, t.Z)));

                    var wireframes = new IList<Point3D>[mesh.Lods.Count];

                    for (int lodIndex = 0; lodIndex < mesh.Lods.Count; lodIndex++)
                    {
                        var lod = mesh.Lods[lodIndex];

                        var lines = new List<Tuple<int, int>>(lod.TrianglesCount * 3);

                        var addLine = new Action<int, int>((a, b) =>
                        {
                            if (a < b)
                            {
                                lines.Add(new Tuple<int, int>(a, b));
                            }
                            else
                            {
                                lines.Add(new Tuple<int, int>(b, a));
                            }
                        });

                        for (int faceGroupIndex = 0; faceGroupIndex < lod.FaceGroups.Count; faceGroupIndex++)
                        {
                            var faceGroup = lod.FaceGroups[faceGroupIndex];

                            for (int faceIndex = 0; faceIndex < faceGroup.Faces.Count; faceIndex++)
                            {
                                var face = faceGroup.Faces[faceIndex];

                                Index positionsIndex = face.VerticesIndex;

                                addLine(positionsIndex.A, positionsIndex.B);
                                addLine(positionsIndex.B, positionsIndex.C);

                                if (positionsIndex.D < 0)
                                {
                                    addLine(positionsIndex.C, positionsIndex.A);
                                }
                                else
                                {
                                    addLine(positionsIndex.C, positionsIndex.D);
                                    addLine(positionsIndex.D, positionsIndex.A);
                                }
                            }
                        }

                        var points = lines
                            .Distinct()
                            .SelectMany(t => new List<Point3D>
                        {
                            positions.ElementAtOrDefault(t.Item1),
                            positions.ElementAtOrDefault(t.Item2)
                        })
                            .ToList();

                        wireframes[lodIndex] = points;
                    }

                    return wireframes;
                })
                .ToArray();
        }
开发者ID:JeremyAnsel,项目名称:XwaOptEditor,代码行数:79,代码来源:OptCache.cs

示例2: BuildMeshes

        private void BuildMeshes(OptFile opt)
        {
            this.meshes = null;

            if (opt == null)
            {
                return;
            }

            this.meshes = new MeshGeometry3D[opt.Meshes.Count][][][];

            for (int meshIndex = 0; meshIndex < opt.Meshes.Count; meshIndex++)
            {
                var mesh = opt.Meshes[meshIndex];

                var positions = new Point3DCollection(
                    mesh.Vertices
                    .Select(t => new Point3D(-t.Y, -t.X, t.Z)));

                var normals = new Vector3DCollection(
                    mesh.VertexNormals
                    .Select(t => new Vector3D(-t.Y, -t.X, t.Z)));

                var textureCoordinates = new PointCollection(
                    mesh.TextureCoordinates
                    .Select(t => new Point(t.U, t.V)));

                this.meshes[meshIndex] = new MeshGeometry3D[mesh.Lods.Count][][];

                for (int lodIndex = 0; lodIndex < mesh.Lods.Count; lodIndex++)
                {
                    var lod = mesh.Lods[lodIndex];

                    this.meshes[meshIndex][lodIndex] = new MeshGeometry3D[lod.FaceGroups.Count][];

                    for (int faceGroupIndex = 0; faceGroupIndex < lod.FaceGroups.Count; faceGroupIndex++)
                    {
                        var faceGroup = lod.FaceGroups[faceGroupIndex];

                        MeshGeometry3D[] geometries = new MeshGeometry3D[faceGroup.Faces.Count + 1];

                        for (int faceIndex = 0; faceIndex < faceGroup.Faces.Count; faceIndex++)
                        {
                            var face = faceGroup.Faces[faceIndex];

                            MeshGeometry3D geometry = new MeshGeometry3D();
                            int index = 0;

                            Index positionsIndex = face.VerticesIndex;
                            Index normalsIndex = face.VertexNormalsIndex;
                            Index textureCoordinatesIndex = face.TextureCoordinatesIndex;

                            geometry.Positions.Add(positions.ElementAtOrDefault(positionsIndex.A));
                            geometry.Normals.Add(normals.ElementAtOrDefault(normalsIndex.A));
                            geometry.TextureCoordinates.Add(textureCoordinates.ElementAtOrDefault(textureCoordinatesIndex.A));
                            geometry.TriangleIndices.Add(index);
                            index++;

                            geometry.Positions.Add(positions.ElementAtOrDefault(positionsIndex.B));
                            geometry.Normals.Add(normals.ElementAtOrDefault(normalsIndex.B));
                            geometry.TextureCoordinates.Add(textureCoordinates.ElementAtOrDefault(textureCoordinatesIndex.B));
                            geometry.TriangleIndices.Add(index);
                            index++;

                            geometry.Positions.Add(positions.ElementAtOrDefault(positionsIndex.C));
                            geometry.Normals.Add(normals.ElementAtOrDefault(normalsIndex.C));
                            geometry.TextureCoordinates.Add(textureCoordinates.ElementAtOrDefault(textureCoordinatesIndex.C));
                            geometry.TriangleIndices.Add(index);
                            index++;

                            if (positionsIndex.D >= 0)
                            {
                                geometry.TriangleIndices.Add(index - 3);
                                geometry.TriangleIndices.Add(index - 1);

                                geometry.Positions.Add(positions.ElementAtOrDefault(positionsIndex.D));
                                geometry.Normals.Add(normals.ElementAtOrDefault(normalsIndex.D));
                                geometry.TextureCoordinates.Add(textureCoordinates.ElementAtOrDefault(textureCoordinatesIndex.D));
                                geometry.TriangleIndices.Add(index);
                                index++;
                            }

                            geometry.Freeze();
                            geometries[1 + faceIndex] = geometry;
                        }

                        MeshGeometry3D geometryGroup = new MeshGeometry3D();

                        for (int i = 1; i < geometries.Length; i++)
                        {
                            MergeGeometry(geometryGroup, geometries[i]);
                        }

                        geometryGroup.Freeze();
                        geometries[0] = geometryGroup;

                        this.meshes[meshIndex][lodIndex][faceGroupIndex] = geometries;
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:JeremyAnsel,项目名称:XwaOptEditor,代码行数:101,代码来源:OptCache.cs


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