Ejemplo n.º 1
0
        DiffuseMaterial GetMaterial()
        {
            DiffuseMaterial mat = new DiffuseMaterial(Brushes.Red);

            mat.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, true);
            return(mat);
        }
Ejemplo n.º 2
0
        private FrameworkElement CreateVisualChild()
        {
            var simpleQuad = new MeshGeometry3D
            {
                Positions          = new Point3DCollection(Mesh),
                TextureCoordinates = new PointCollection(TexCoords),
                TriangleIndices    = new Int32Collection(Indices)
            };

            // Front material is interactive, back material is not.
            Material frontMaterial = new DiffuseMaterial(Brushes.White);

            frontMaterial.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, true);

            var vb = new VisualBrush(_logicalChild);

            SetCachingForObject(vb);  // big perf wins by caching!!
            Material backMaterial = new DiffuseMaterial(vb);

            _rotationTransform.Rotation = _quaternionRotation;
            var xfGroup = new Transform3DGroup {
                Children = { _scaleTransform, _rotationTransform }
            };

            var backModel = new GeometryModel3D {
                Geometry = simpleQuad, Transform = xfGroup, BackMaterial = backMaterial
            };
            var m3DGroup = new Model3DGroup
            {
                Children = { new DirectionalLight(Colors.White, new Vector3D(0,      0, -1)),
                             new DirectionalLight(Colors.White, new Vector3D(0.1, -0.1,  1)),
                             backModel }
            };

            // Non-interactive Visual3D consisting of the backside, and two lights.
            var mv3D = new ModelVisual3D {
                Content = m3DGroup
            };

            // Interactive frontside Visual3D
            var frontModel = new Viewport2DVisual3D {
                Geometry = simpleQuad, Visual = _logicalChild, Material = frontMaterial, Transform = xfGroup
            };

            // Cache the brush in the VP2V3 by setting caching on it.  Big perf wins.
            SetCachingForObject(frontModel);

            // Scene consists of both the above Visual3D's.
            _viewport3D = new Viewport3D {
                ClipToBounds = false, Children = { mv3D, frontModel }
            };

            UpdateRotation();

            return(_viewport3D);
        }
Ejemplo n.º 3
0
        private FrameworkElement CreateVisualChild()
        {
            MeshGeometry3D meshGeometry3D = new MeshGeometry3D()
            {
                Positions          = new Point3DCollection(Planerator.Mesh),
                TextureCoordinates = new PointCollection(Planerator.TexCoords),
                TriangleIndices    = new Int32Collection(Planerator.Indices)
            };
            Material diffuseMaterial = new DiffuseMaterial(Brushes.White);

            diffuseMaterial.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, (object)true);
            VisualBrush visualBrush = new VisualBrush(this._logicalChild);

            this.SetCachingForObject(visualBrush);
            Material material = new DiffuseMaterial(visualBrush);

            this._rotationTransform.Rotation = this._quaternionRotation;
            Transform3DGroup transform3DGroup = new Transform3DGroup();

            transform3DGroup.Children.Add(this._scaleTransform);
            transform3DGroup.Children.Add(this._rotationTransform);
            Transform3DGroup transform3DGroup1 = transform3DGroup;
            GeometryModel3D  geometryModel3D   = new GeometryModel3D()
            {
                Geometry     = meshGeometry3D,
                Transform    = transform3DGroup1,
                BackMaterial = material
            };
            Model3DGroup model3DGroup = new Model3DGroup();

            model3DGroup.Children.Add(new DirectionalLight(Colors.White, new Vector3D(0, 0, -1)));
            model3DGroup.Children.Add(new DirectionalLight(Colors.White, new Vector3D(0.1, -0.1, 1)));
            model3DGroup.Children.Add(geometryModel3D);
            ModelVisual3D modelVisual3D = new ModelVisual3D()
            {
                Content = model3DGroup
            };

            if (this._frontModel != null)
            {
                this._frontModel.Visual = null;
            }
            this._frontModel = new Viewport2DVisual3D()
            {
                Geometry  = meshGeometry3D,
                Visual    = this._logicalChild,
                Material  = diffuseMaterial,
                Transform = transform3DGroup1
            };
            this.SetCachingForObject(this._frontModel);
            Viewport3D viewport3D = new Viewport3D()
            {
                ClipToBounds = false
            };

            viewport3D.Children.Add(modelVisual3D);
            viewport3D.Children.Add(this._frontModel);
            this._viewport3D = viewport3D;
            this.UpdateRotation();
            return(this._viewport3D);
        }
Ejemplo n.º 4
0
        public Transition3D()
            : base(new Viewport3D())
        {
            // camera to ue
            WrappedElement.Camera = new PerspectiveCamera();

            // the model visual 3D
            ModelVisual3D mv3D = new ModelVisual3D();

            mv3D.Content = new PointLight(Colors.White, new Point3D(0, 0, 0));

            WrappedElement.Children.Add(mv3D);

            MeshGeometry3D    plane     = new MeshGeometry3D();
            Point3DCollection positions = new Point3DCollection();

            positions.Add(new Point3D(-1, -1, 0));
            positions.Add(new Point3D(-1, 1, 0));
            positions.Add(new Point3D(1, 1, 0));
            positions.Add(new Point3D(1, -1, 0));
            positions.Freeze();
            plane.Positions = positions;

            PointCollection textureCoords = new PointCollection();

            textureCoords.Add(new Point(0, 1));
            textureCoords.Add(new Point(0, 0));
            textureCoords.Add(new Point(1, 0));
            textureCoords.Add(new Point(1, 1));
            textureCoords.Freeze();
            plane.TextureCoordinates = textureCoords;

            Int32Collection indices = new Int32Collection();

            indices.Add(0);
            indices.Add(3);
            indices.Add(1);
            indices.Add(1);
            indices.Add(3);
            indices.Add(2);
            indices.Freeze();
            plane.TriangleIndices = indices;

            Material planeMaterial = new DiffuseMaterial(Brushes.Blue);

            planeMaterial.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, true);

            m_visual3D          = new Viewport2DVisual3D();
            m_visual3D.Geometry = plane;
            m_visual3D.Material = planeMaterial;

            Transform3DGroup transform = new Transform3DGroup();

            m_rotation    = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 35);
            m_scale       = new ScaleTransform3D(0, 0, 0);
            m_translation = new TranslateTransform3D(-2.5, 0, -10);

            transform.Children.Add(m_scale);
            transform.Children.Add(new RotateTransform3D(m_rotation));
            transform.Children.Add(m_translation);

            m_visual3D.Transform = transform;

            WrappedElement.Children.Add(m_visual3D);
        }