1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
using System.Windows.Media.Media3D;
using System.Windows.Media;
namespace WpTransform3Dto2D
{
public class GeometryGenerator
{
public GeometryGenerator()
{
GeomMesh = CreateCubeModel();
}
public MeshGeometry3D GeomMesh { get; set; }
public static MeshGeometry3D CreateCubeModel()
{
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions.Add(new Point3D(-1, -1, 1));
mesh.Positions.Add(new Point3D(1, -1, 1));
mesh.Positions.Add(new Point3D(1, 1, 1));
mesh.Positions.Add(new Point3D(-1, 1, 1));
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(3);
mesh.Normals.Add(new Vector3D(0, 0, 1));
mesh.Normals.Add(new Vector3D(0, 0, 1));
mesh.Normals.Add(new Vector3D(0, 0, 1));
mesh.Normals.Add(new Vector3D(0, 0, 1));
mesh.Positions.Add(new Point3D(1, -1, 1));
mesh.Positions.Add(new Point3D(1, -1, -1));
mesh.Positions.Add(new Point3D(1, 1, -1));
mesh.Positions.Add(new Point3D(1, 1, 1));
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(7);
mesh.Normals.Add(new Vector3D(1, 0, 0));
mesh.Normals.Add(new Vector3D(1, 0, 0));
mesh.Normals.Add(new Vector3D(1, 0, 0));
mesh.Normals.Add(new Vector3D(1, 0, 0));
mesh.Positions.Add(new Point3D(1, -1, -1));
mesh.Positions.Add(new Point3D(-1, -1, -1));
mesh.Positions.Add(new Point3D(-1, 1, -1));
mesh.Positions.Add(new Point3D(1, 1, -1));
mesh.TriangleIndices.Add(8);
mesh.TriangleIndices.Add(9);
mesh.TriangleIndices.Add(10);
mesh.TriangleIndices.Add(8);
mesh.TriangleIndices.Add(10);
mesh.TriangleIndices.Add(11);
mesh.Normals.Add(new Vector3D(0, 0, -1));
mesh.Normals.Add(new Vector3D(0, 0, -1));
mesh.Normals.Add(new Vector3D(0, 0, -1));
mesh.Normals.Add(new Vector3D(0, 0, -1));
mesh.Positions.Add(new Point3D(-1, -1, -1));
mesh.Positions.Add(new Point3D(-1, -1, 1));
mesh.Positions.Add(new Point3D(-1, 1, 1));
mesh.Positions.Add(new Point3D(-1, 1, -1));
mesh.TriangleIndices.Add(12);
mesh.TriangleIndices.Add(13);
mesh.TriangleIndices.Add(14);
mesh.TriangleIndices.Add(12);
mesh.TriangleIndices.Add(14);
mesh.TriangleIndices.Add(15);
mesh.Normals.Add(new Vector3D(-1, 0, 0));
mesh.Normals.Add(new Vector3D(-1, 0, 0));
mesh.Normals.Add(new Vector3D(-1, 0, 0));
mesh.Normals.Add(new Vector3D(-1, 0, 0));
mesh.Positions.Add(new Point3D(-1, -1, 1));
mesh.Positions.Add(new Point3D(-1, -1, -1));
mesh.Positions.Add(new Point3D(1, -1, -1));
mesh.Positions.Add(new Point3D(1, -1, 1));
mesh.TriangleIndices.Add(16);
mesh.TriangleIndices.Add(17);
mesh.TriangleIndices.Add(18);
mesh.TriangleIndices.Add(16);
mesh.TriangleIndices.Add(18);
mesh.TriangleIndices.Add(19);
mesh.Normals.Add(new Vector3D(0, -1, 0));
mesh.Normals.Add(new Vector3D(0, -1, 0));
mesh.Normals.Add(new Vector3D(0, -1, 0));
mesh.Normals.Add(new Vector3D(0, -1, 0));
mesh.Positions.Add(new Point3D(-1, 1, 1));
mesh.Positions.Add(new Point3D(1, 1, 1));
mesh.Positions.Add(new Point3D(1, 1, -1));
mesh.Positions.Add(new Point3D(-1, 1, -1));
mesh.TriangleIndices.Add(20);
mesh.TriangleIndices.Add(21);
mesh.TriangleIndices.Add(22);
mesh.TriangleIndices.Add(20);
mesh.TriangleIndices.Add(22);
mesh.TriangleIndices.Add(23);
mesh.Normals.Add(new Vector3D(0, 1, 0));
mesh.Normals.Add(new Vector3D(0, 1, 0));
mesh.Normals.Add(new Vector3D(0, 1, 0));
mesh.Normals.Add(new Vector3D(0, 1, 0));
return mesh;
}
}
} |
Partager