Beispiel #1
0
        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)
                {
                    WireframeHelper(group, matrixStack);
                    return;
                }

                GeometryModel3D geometry = model as GeometryModel3D;

                if (geometry != null)
                {
                    WireframeHelper(geometry, matrixStack);
                    return;
                }
            }
            finally
            {
                if (transform != null && transform != Transform3D.Identity)
                {
                    matrixStack.Pop();
                }
            }
        }
Beispiel #2
0
 private void WireframeHelper(Model3DGroup group, Matrix3DStack matrixStack)
 {
     foreach (Model3D child in group.Children)
     {
         WireframeHelper(child, matrixStack);
     }
 }
Beispiel #3
0
        public void MakeWireframe(Model3D model)
        {
            this.Points.Clear();

            if (model == null)
            {
                return;
            }

            Matrix3DStack transform = new Matrix3DStack();

            transform.Push(Matrix3D.Identity);

            WireframeHelper(model, transform);
        }
Beispiel #4
0
        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);
                    }
                }
            }
        }