private void WireframeHelper(Model3D model, Matrix3DStack matrixStack) { Transform3D transform = model.Transform; if (transform != null && transform != Transform3D.Identity) { matrixStack.Prepend(model.Transform.Value); } try { Model3DGroup group = model as Model3DGroup; if (group != null) { this.WireframeHelper(group, matrixStack); return; } GeometryModel3D geometry = model as GeometryModel3D; if (geometry != null) { this.WireframeHelper(geometry, matrixStack); return; } } finally { if (transform != null && transform != Transform3D.Identity) { matrixStack.Pop(); } } }
private void WireframeHelper(Model3DGroup group, Matrix3DStack matrixStack) { foreach (Model3D child in group.Children) { this.WireframeHelper(child, matrixStack); } }
public void MakeWireframe(Model3D model) { this.Points.Clear(); if (model == null) { return; } Matrix3DStack transform = new Matrix3DStack(); transform.Push(Matrix3D.Identity); this.WireframeHelper(model, transform); }
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); } } } }