Exemple #1
0
        protected virtual void PropertyChanged(DependencyPropertyChangedEventArgs args)
        {
            Point3DCollection  vertices;
            Vector3DCollection normals;
            Int32Collection    indices;
            PointCollection    textures;

            if (!IsWireFrame || args.Property == IsWireFrameProperty && !(bool)args.OldValue)
            {
                // Obtain the MeshGeometry3D.
                MeshGeometry3D mesh = Geometry;

                // Get all four collectiona.
                vertices = mesh.Positions;
                normals  = mesh.Normals;
                indices  = mesh.TriangleIndices;
                textures = mesh.TextureCoordinates;

                // Set the MeshGeometry3D collections to null while updating.
                mesh.Positions          = null;
                mesh.Normals            = null;
                mesh.TriangleIndices    = null;
                mesh.TextureCoordinates = null;
            }

            else
            {
                // Get properties from WireFrame object
                vertices = wireframe.Positions;
                normals  = wireframe.Normals;
                indices  = wireframe.TriangleIndices;
                textures = wireframe.TextureCoordinates;

                wireframe.Positions          = null;
                wireframe.Normals            = null;
                wireframe.TriangleIndices    = null;
                wireframe.TextureCoordinates = null;
            }

            // If args.Property not IsWireFrame OR Algorithmic transforms
            if (args.Property != AlgorithmicTransformsProperty &&
                args.Property != IsWireFrameProperty)
            {
                // Call the abstract method to fill the collections.
                Triangulate(args, vertices, normals, indices, textures);

                // Transfer vertices and normals to internal collections.
                verticesPreTransform.Clear();
                normalsPreTransform.Clear();

                foreach (Point3D vertex in vertices)
                {
                    verticesPreTransform.Add(vertex);
                }

                foreach (Vector3D normal in normals)
                {
                    normalsPreTransform.Add(normal);
                }
            }

            if (args.Property == AlgorithmicTransformsProperty)
            {
                vertices.Clear();
                normals.Clear();
                normalsAsPoints.Clear();

                // Transfer saved vertices and normals.
                foreach (Point3D vertex in verticesPreTransform)
                {
                    vertices.Add(vertex);
                }

                foreach (Vector3D normal in normalsPreTransform)
                {
                    normalsAsPoints.Add((Point3D)normal);
                }
            }

            if (args.Property != IsWireFrameProperty)
            {
                foreach (AlgorithmicTransform xform in AlgorithmicTransforms)
                {
                    xform.Transform(vertices);
                    xform.Transform(normalsAsPoints);
                }

                foreach (Point3D point in normalsAsPoints)
                {
                    normals.Add((Vector3D)point);
                }
            }

            if (IsWireFrame)
            {
                // Set stuff to WireFrame object, and create it if necessary
                if (wireframe == null)
                {
                    wireframe = new WireFrame();
                    Children.Add(wireframe);                // do we want to remove it when it's no longer used?
                }

                wireframe.TextureCoordinates = textures;
                wireframe.TriangleIndices    = indices;
                wireframe.Normals            = normals;
                wireframe.Positions          = vertices;
            }
            else
            {
                // Obtain the MeshGeometry3D.
                MeshGeometry3D mesh = Geometry;

                // Set the updated collections to the MeshGeometry3D.
                mesh.TextureCoordinates = textures;
                mesh.TriangleIndices    = indices;
                mesh.Normals            = normals;
                mesh.Positions          = vertices;
            }
        }
        protected virtual void PropertyChanged(DependencyPropertyChangedEventArgs args)
        {
            Point3DCollection vertices;
            Vector3DCollection normals;
            Int32Collection indices;
            PointCollection textures;

            if (!IsWireFrame || args.Property == IsWireFrameProperty && !(bool)args.OldValue)
            {
                // Obtain the MeshGeometry3D.
                MeshGeometry3D mesh = Geometry;

                // Get all four collectiona.
                vertices = mesh.Positions;
                normals = mesh.Normals;
                indices = mesh.TriangleIndices;
                textures = mesh.TextureCoordinates;

                // Set the MeshGeometry3D collections to null while updating.
                mesh.Positions = null;
                mesh.Normals = null;
                mesh.TriangleIndices = null;
                mesh.TextureCoordinates = null;
            }

            else
            {
                // Get properties from WireFrame object
                vertices = wireframe.Positions;
                normals = wireframe.Normals;
                indices = wireframe.TriangleIndices;
                textures = wireframe.TextureCoordinates;

                wireframe.Positions = null;
                wireframe.Normals = null;
                wireframe.TriangleIndices = null;
                wireframe.TextureCoordinates = null;
            }

            // If args.Property not IsWireFrame OR Algorithmic transforms
            if (args.Property != AlgorithmicTransformsProperty &&
                args.Property != IsWireFrameProperty)
            {
                // Call the abstract method to fill the collections.
                Triangulate(args, vertices, normals, indices, textures);

                // Transfer vertices and normals to internal collections.
                verticesPreTransform.Clear();
                normalsPreTransform.Clear();

                foreach (Point3D vertex in vertices)
                    verticesPreTransform.Add(vertex);

                foreach (Vector3D normal in normals)
                    normalsPreTransform.Add(normal);
            }

            if (args.Property == AlgorithmicTransformsProperty)
            {
                vertices.Clear();
                normals.Clear();
                normalsAsPoints.Clear();

                // Transfer saved vertices and normals.
                foreach (Point3D vertex in verticesPreTransform)
                    vertices.Add(vertex);

                foreach (Vector3D normal in normalsPreTransform)
                    normalsAsPoints.Add((Point3D)normal);
            }

            if (args.Property != IsWireFrameProperty)
            {
                foreach (AlgorithmicTransform xform in AlgorithmicTransforms)
                {
                    xform.Transform(vertices);
                    xform.Transform(normalsAsPoints);
                }

                foreach (Point3D point in normalsAsPoints)
                    normals.Add((Vector3D)point);
            }

            if (IsWireFrame)
            {
                // Set stuff to WireFrame object, and create it if necessary
                if (wireframe == null)
                {
                    wireframe = new WireFrame();
                    Children.Add(wireframe);                // do we want to remove it when it's no longer used?
                }

                wireframe.TextureCoordinates = textures;
                wireframe.TriangleIndices = indices;
                wireframe.Normals = normals;
                wireframe.Positions = vertices;
            }
            else
            {
                // Obtain the MeshGeometry3D.
                MeshGeometry3D mesh = Geometry;

                // Set the updated collections to the MeshGeometry3D.
                mesh.TextureCoordinates = textures;
                mesh.TriangleIndices = indices;
                mesh.Normals = normals;
                mesh.Positions = vertices;
            }
        }