private void NormalsHelper(GeometryModel3D model, Matrix3DStack matrixStack) { Geometry3D geometry = model.Geometry; MeshGeometry3D mesh = geometry as MeshGeometry3D; if (mesh != null) { Point3D[] positions = new Point3D[mesh.Positions.Count]; mesh.Positions.CopyTo(positions, 0); //matrixStack.Peek().Transform(positions); Vector3D[] normals = new Vector3D[mesh.Normals.Count]; mesh.Normals.CopyTo(normals, 0); new ScaleTransform3D(0.1, 0.1, 0.1).Transform(normals); for (int i = 0; i < mesh.Positions.Count; i++) { Point3D p1 = matrixStack.Peek().Transform(positions[i]); Point3D p2 = matrixStack.Peek().Transform(new Point3D(positions[i].X + normals[i].X, positions[i].Y + normals[i].Y, positions[i].Z + normals[i].Z)); Points.Add(p1); Points.Add(p2); } } }
private void WireframeHelper(GeometryModel3D model, Matrix3DStack matrixStack) { Geometry3D geometry = model.Geometry; MeshGeometry3D mesh = geometry as MeshGeometry3D; if (mesh != null) { Point3D[] positions = new Point3D[mesh.Positions.Count]; mesh.Positions.CopyTo(positions, 0); matrixStack.Peek().Transform(positions); Int32Collection indices = mesh.TriangleIndices; if (indices.Count > 0) { int limit = positions.Length - 1; for (int i = 2, count = indices.Count; i < count; i += 3) { int i0 = indices[i - 2]; int i1 = indices[i - 1]; int i2 = indices[i]; // WPF halts rendering on the first deformed triangle. We should // do the same. if ((0 > i0 || i0 > limit) || (0 > i1 || i1 > limit) || (0 > i2 || i2 > limit)) { break; } AddTriangle(positions, i0, i1, i2); } } else { for (int i = 2, count = positions.Length; i < count; i += 3) { int i0 = i - 2; int i1 = i - 1; int i2 = i; AddTriangle(positions, i0, i1, i2); } } } }