Ejemplo n.º 1
0
 private void WireframeHelper(Model3DGroup group, Matrix3DStack matrixStack)
 {
     foreach (Model3D child in group.Children)
     {
         WireframeHelper(child, matrixStack);
     }
 }
Ejemplo n.º 2
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);
                    }
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
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();
                }
            }
        }
Ejemplo n.º 5
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);
                WireframeHelper(positions, mesh.TriangleIndices);
            }
        }
Ejemplo n.º 6
0
        public void MakeWireframe(IList<Point3D> points)
        {
            this.Points.Clear();

            if ((points != null) && (points.Count > 0))
            {
                Matrix3DStack transform = new Matrix3DStack();
                transform.Push(Matrix3D.Identity);

                WireframeHelper(points, null);
            }
        }
Ejemplo n.º 7
0
        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);
                }
            }
        }
Ejemplo n.º 8
0
 private void NormalsHelper(Model3DGroup group, Matrix3DStack matrixStack)
 {
     foreach (Model3D child in group.Children)
     {
         NormalsHelper(child, matrixStack);
     }
 }
Ejemplo n.º 9
0
        public void MakeNormals(Model3D model)
        {
            Points.Clear();
            Thickness = 1;
            Color = Colors.SlateBlue;

            if (model == null)
            {
                return;
            }

            Matrix3DStack transform = new Matrix3DStack();
            transform.Push(Matrix3D.Identity);

            NormalsHelper(model, transform);
        }