本文整理汇总了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();
}
示例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;
}
}
}
//.........这里部分代码省略.........