GeometryModel3D.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Core / CSharp / System / Windows / Media3D / GeometryModel3D.cs / 1 / GeometryModel3D.cs

                            //---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved.
//  
//
// 
// Description: 3D geometry primitive implementation. 
//
//              See spec at http://avalon/medialayer/Specifications/Avalon3D%20API%20Spec.mht 
//
// History:
//  06/10/2004 : [....] - Created from MeshPrimitive3D.cs (deprecated)
// 
//---------------------------------------------------------------------------
 
using MS.Internal; 
using MS.Internal.Media3D;
using System; 
using System.Collections;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Windows.Media; 
using System.Windows.Media.Composition;
using System.Windows.Media.Media3D; 
using System.Windows.Markup; 

namespace System.Windows.Media.Media3D 
{
    /// 
    ///     GeometryModel3D is for modeling with a Geometry3D and a Material.
    ///  
    public sealed partial class GeometryModel3D : Model3D
    { 
        //----------------------------------------------------- 
        //
        //  Constructors 
        //
        //-----------------------------------------------------

        ///  
        ///     Builds a GeometryModel3D with empty Geometry3D and Material.
        ///  
        public GeometryModel3D() {} 

        ///  
        ///     Constructor.
        /// 
        /// Geometry of the new mesh primitive.
        /// Material of the new mesh primitive. 
        public GeometryModel3D(Geometry3D geometry, Material material)
        { 
            Geometry = geometry; 
            Material = material;
        } 

        //------------------------------------------------------
        //
        //  Public Methods 
        //
        //----------------------------------------------------- 
 
        //------------------------------------------------------
        // 
        //  Internal Methods
        //
        //------------------------------------------------------
 
        #region Internal Methods
 
        internal override Rect3D CalculateSubgraphBoundsInnerSpace() 
        {
            Geometry3D geometry = Geometry; 

            if (geometry == null)
            {
                return Rect3D.Empty; 
            }
 
            return geometry.Bounds; 
        }
 
        internal override void RayHitTestCore(RayHitTestParameters rayParams)
        {
            Geometry3D geometry = Geometry;
 
            if (geometry != null)
            { 
                // If our Geometry3D hit test intersects anything we should return "this" Model3D 
                // as the HitTestResult.ModelHit.
                rayParams.CurrentModel = this; 

                FaceType facesToHit = FaceType.None;

                if (Material != null) 
                {
                    facesToHit |= FaceType.Front; 
                } 

                if (BackMaterial != null) 
                {
                    facesToHit |= FaceType.Back;
                }
 
                if (facesToHit != FaceType.None)
                { 
                    geometry.RayHitTest(rayParams, facesToHit); 
                }
            } 
        }

        internal void MaterialPropertyChangedHook(DependencyPropertyChangedEventArgs e)
        { 
            // Override of OnChanged on Model3DGroup will propagate this up
            _flags[DirtyForPreComputeFlag] = true; 
        } 

        internal void BackMaterialPropertyChangedHook(DependencyPropertyChangedEventArgs e) 
        {
            MaterialPropertyChangedHook(e);
        }
 
        internal override void PreCompute()
        { 
            Debug.Assert(_flags[DirtyForPreComputeFlag]); 

            bool requiresRealization = false; 

            Material material = Material;
            if (material != null)
            { 
                requiresRealization |= material.PreCompute();
            } 
 
            Material backMaterial = BackMaterial;
            if (backMaterial != null) 
            {
                requiresRealization |= backMaterial.PreCompute();
            }
 
            _flags[RequiresRealizationFlag] = requiresRealization;
            _flags[DirtyForPreComputeFlag] = false; 
        } 

        ///  
        /// Realization support
        /// 
        internal override void MarkVisibleRealizations(
            RealizationContext rc) 
        {
            Debug.Assert(_flags[RequiresRealizationFlag]); 
 
            MeshGeometry3D geometry = Geometry as MeshGeometry3D;
            Material material = Material; 
            Material backMaterial = BackMaterial;

            if (geometry != null && (material != null || backMaterial != null))
            { 
                Rect textureCoordinateBounds = geometry.GetTextureCoordinateBounds();
 
                // 
                // If the texture coordinate bounds are empty, we skip realizing this
                // material. 

                if (textureCoordinateBounds.IsEmpty)
                {
                    return; 
                }
 
                Transform3D transform = Transform; 
                Matrix3DStack stack3D = rc.Transform3DStack;
                if (transform != null) 
                {
                    stack3D.Push(transform.Value);
                }
 
                Rect3D mesh3DBox = geometry.Bounds;
 
                // 
                // Extend the 2D world transform to a 3D matrix and calculate the
                // full 3d device transform. 
                MatrixStack stack2D = rc.TransformStack;
                Matrix deviceTransform2D = stack2D.Peek();
                Matrix3D deviceTransform3D = new Matrix3D(
                    deviceTransform2D.M11    ,     deviceTransform2D.M12, 0, 0, 
                    deviceTransform2D.M21    ,     deviceTransform2D.M22, 0, 0,
                                            0,                         0, 1, 0, 
                    deviceTransform2D.OffsetX, deviceTransform2D.OffsetY, 0, 1); 
                deviceTransform3D.Prepend(stack3D.Top);
 
                //
                // Calculate the material to texture sample space transform.

                Matrix textureSpaceTransform2D; 

                MILUtilities.CalcMesh3DBrushAndSampleSpace( 
                    ref deviceTransform3D, 
                    ref mesh3DBox,
                    ref textureCoordinateBounds, 
                    out textureSpaceTransform2D);

                //
                // The textureSpaceTransform is bascially our new 2D device transform. 

                stack2D.Push(ref textureSpaceTransform2D, false); 
 
                if (material != null && material.RequiresRealization)
                { 
                    material.UpdateRealizations(rc, ref textureCoordinateBounds);
                }

                if (backMaterial != null && backMaterial.RequiresRealization) 
                {
                    backMaterial.UpdateRealizations(rc, ref textureCoordinateBounds); 
                } 

                stack2D.Pop(); 

                if (transform != null)
                {
                    stack3D.Pop(); 
                }
            } 
        } 

        #endregion Internal Methods 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved.
//  
//
// 
// Description: 3D geometry primitive implementation. 
//
//              See spec at http://avalon/medialayer/Specifications/Avalon3D%20API%20Spec.mht 
//
// History:
//  06/10/2004 : [....] - Created from MeshPrimitive3D.cs (deprecated)
// 
//---------------------------------------------------------------------------
 
using MS.Internal; 
using MS.Internal.Media3D;
using System; 
using System.Collections;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Windows.Media; 
using System.Windows.Media.Composition;
using System.Windows.Media.Media3D; 
using System.Windows.Markup; 

namespace System.Windows.Media.Media3D 
{
    /// 
    ///     GeometryModel3D is for modeling with a Geometry3D and a Material.
    ///  
    public sealed partial class GeometryModel3D : Model3D
    { 
        //----------------------------------------------------- 
        //
        //  Constructors 
        //
        //-----------------------------------------------------

        ///  
        ///     Builds a GeometryModel3D with empty Geometry3D and Material.
        ///  
        public GeometryModel3D() {} 

        ///  
        ///     Constructor.
        /// 
        /// Geometry of the new mesh primitive.
        /// Material of the new mesh primitive. 
        public GeometryModel3D(Geometry3D geometry, Material material)
        { 
            Geometry = geometry; 
            Material = material;
        } 

        //------------------------------------------------------
        //
        //  Public Methods 
        //
        //----------------------------------------------------- 
 
        //------------------------------------------------------
        // 
        //  Internal Methods
        //
        //------------------------------------------------------
 
        #region Internal Methods
 
        internal override Rect3D CalculateSubgraphBoundsInnerSpace() 
        {
            Geometry3D geometry = Geometry; 

            if (geometry == null)
            {
                return Rect3D.Empty; 
            }
 
            return geometry.Bounds; 
        }
 
        internal override void RayHitTestCore(RayHitTestParameters rayParams)
        {
            Geometry3D geometry = Geometry;
 
            if (geometry != null)
            { 
                // If our Geometry3D hit test intersects anything we should return "this" Model3D 
                // as the HitTestResult.ModelHit.
                rayParams.CurrentModel = this; 

                FaceType facesToHit = FaceType.None;

                if (Material != null) 
                {
                    facesToHit |= FaceType.Front; 
                } 

                if (BackMaterial != null) 
                {
                    facesToHit |= FaceType.Back;
                }
 
                if (facesToHit != FaceType.None)
                { 
                    geometry.RayHitTest(rayParams, facesToHit); 
                }
            } 
        }

        internal void MaterialPropertyChangedHook(DependencyPropertyChangedEventArgs e)
        { 
            // Override of OnChanged on Model3DGroup will propagate this up
            _flags[DirtyForPreComputeFlag] = true; 
        } 

        internal void BackMaterialPropertyChangedHook(DependencyPropertyChangedEventArgs e) 
        {
            MaterialPropertyChangedHook(e);
        }
 
        internal override void PreCompute()
        { 
            Debug.Assert(_flags[DirtyForPreComputeFlag]); 

            bool requiresRealization = false; 

            Material material = Material;
            if (material != null)
            { 
                requiresRealization |= material.PreCompute();
            } 
 
            Material backMaterial = BackMaterial;
            if (backMaterial != null) 
            {
                requiresRealization |= backMaterial.PreCompute();
            }
 
            _flags[RequiresRealizationFlag] = requiresRealization;
            _flags[DirtyForPreComputeFlag] = false; 
        } 

        ///  
        /// Realization support
        /// 
        internal override void MarkVisibleRealizations(
            RealizationContext rc) 
        {
            Debug.Assert(_flags[RequiresRealizationFlag]); 
 
            MeshGeometry3D geometry = Geometry as MeshGeometry3D;
            Material material = Material; 
            Material backMaterial = BackMaterial;

            if (geometry != null && (material != null || backMaterial != null))
            { 
                Rect textureCoordinateBounds = geometry.GetTextureCoordinateBounds();
 
                // 
                // If the texture coordinate bounds are empty, we skip realizing this
                // material. 

                if (textureCoordinateBounds.IsEmpty)
                {
                    return; 
                }
 
                Transform3D transform = Transform; 
                Matrix3DStack stack3D = rc.Transform3DStack;
                if (transform != null) 
                {
                    stack3D.Push(transform.Value);
                }
 
                Rect3D mesh3DBox = geometry.Bounds;
 
                // 
                // Extend the 2D world transform to a 3D matrix and calculate the
                // full 3d device transform. 
                MatrixStack stack2D = rc.TransformStack;
                Matrix deviceTransform2D = stack2D.Peek();
                Matrix3D deviceTransform3D = new Matrix3D(
                    deviceTransform2D.M11    ,     deviceTransform2D.M12, 0, 0, 
                    deviceTransform2D.M21    ,     deviceTransform2D.M22, 0, 0,
                                            0,                         0, 1, 0, 
                    deviceTransform2D.OffsetX, deviceTransform2D.OffsetY, 0, 1); 
                deviceTransform3D.Prepend(stack3D.Top);
 
                //
                // Calculate the material to texture sample space transform.

                Matrix textureSpaceTransform2D; 

                MILUtilities.CalcMesh3DBrushAndSampleSpace( 
                    ref deviceTransform3D, 
                    ref mesh3DBox,
                    ref textureCoordinateBounds, 
                    out textureSpaceTransform2D);

                //
                // The textureSpaceTransform is bascially our new 2D device transform. 

                stack2D.Push(ref textureSpaceTransform2D, false); 
 
                if (material != null && material.RequiresRealization)
                { 
                    material.UpdateRealizations(rc, ref textureCoordinateBounds);
                }

                if (backMaterial != null && backMaterial.RequiresRealization) 
                {
                    backMaterial.UpdateRealizations(rc, ref textureCoordinateBounds); 
                } 

                stack2D.Pop(); 

                if (transform != null)
                {
                    stack3D.Pop(); 
                }
            } 
        } 

        #endregion Internal Methods 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK