示例#1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            hostPresenter = GetTemplateChild(ViewportPartNames.PART_HostPresenter) as ContentPresenter;
            if (hostPresenter != null)
            {
                hostPresenter.Content = new SwapChainRenderHost(EnableDeferredRendering);
                renderHostInternal    = (hostPresenter.Content as SwapChainRenderHost).RenderHost;
                if (renderHostInternal != null)
                {
                    renderHostInternal.Viewport            = this;
                    renderHostInternal.IsRendering         = Visibility == Visibility.Visible;
                    renderHostInternal.EffectsManager      = this.EffectsManager;
                    renderHostInternal.RenderTechnique     = this.RenderTechnique;
                    renderHostInternal.ClearColor          = this.BackgroundColor.ToColor4();
                    renderHostInternal.EnableRenderFrustum = this.EnableRenderFrustum;
                    renderHostInternal.IsShadowMapEnabled  = this.IsShadowMappingEnabled;
#if MSAA
                    renderHostInternal.MSAA = this.MSAA;
#endif
                    renderHostInternal.RenderConfiguration.AutoUpdateOctree = this.EnableAutoOctreeUpdate;
                    renderHostInternal.ExceptionOccurred += RenderHostInternal_ExceptionOccurred;
                }
            }
            if (viewCube == null)
            {
                viewCube = GetTemplateChild(ViewportPartNames.PART_ViewCube) as ViewBoxModel3D;
                if (viewCube != null)
                {
                    viewCube.ViewBoxClickedEvent += ViewCube_ViewBoxClickedEvent;
                }
            }

            if (viewCube == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_ViewCube);
            }
            else
            {
                viewCube.RelativeScreenLocationX = ViewCubeHorizontalPosition;
                viewCube.RelativeScreenLocationY = ViewCubeVerticalPosition;
                viewCube.UpDirection             = ModelUpDirection;
            }

            if (coordinateSystem == null)
            {
                coordinateSystem = GetTemplateChild(ViewportPartNames.PART_CoordinateView) as CoordinateSystemModel3D;
            }
            if (coordinateSystem == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_CoordinateView);
            }
            else
            {
                coordinateSystem.RelativeScreenLocationX = CoordinateSystemHorizontalPosition;
                coordinateSystem.RelativeScreenLocationY = CoordinateSystemVerticalPosition;
            }
        }
示例#2
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            if (IsInDesignMode && !EnableDesignModeRendering)
            {
                return;
            }
            itemsContainer = GetTemplateChild(ViewportPartNames.PART_ItemsContainer) as ItemsControl;
            if (itemsContainer == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_ItemsContainer);
            }
            else
            {
                itemsContainer.Items.Clear();
                foreach (var item in Items)
                {
                    itemsContainer.Items.Add(item);
                }
            }
            hostPresenter = GetTemplateChild(ViewportPartNames.PART_HostPresenter) as ContentPresenter;
            if (hostPresenter != null)
            {
                hostPresenter.Content = new SwapChainRenderHost(EnableDeferredRendering);
                renderHostInternal    = (hostPresenter.Content as SwapChainRenderHost).RenderHost;
                if (renderHostInternal != null)
                {
                    renderHostInternal.Viewport               = this;
                    renderHostInternal.IsRendering            = Visibility == Visibility.Visible;
                    renderHostInternal.EffectsManager         = this.EffectsManager;
                    renderHostInternal.RenderTechnique        = this.RenderTechnique;
                    renderHostInternal.ClearColor             = this.BackgroundColor.ToColor4();
                    renderHostInternal.EnableRenderFrustum    = this.EnableRenderFrustum;
                    renderHostInternal.IsShadowMapEnabled     = this.IsShadowMappingEnabled;
                    renderHostInternal.SharedModelContainer   = this.SharedModelContainer;
                    renderHostInternal.EnableSharingModelMode = this.EnableSharedModelMode;
#if MSAA
                    renderHostInternal.MSAA = this.MSAA;
#endif
                    renderHostInternal.RenderConfiguration.AutoUpdateOctree    = this.EnableAutoOctreeUpdate;
                    renderHostInternal.RenderConfiguration.EnableOITRendering  = EnableOITRendering;
                    renderHostInternal.RenderConfiguration.OITWeightPower      = (float)OITWeightPower;
                    renderHostInternal.RenderConfiguration.OITWeightDepthSlope = (float)OITWeightDepthSlope;
                    renderHostInternal.RenderConfiguration.OITWeightMode       = OITWeightMode;
                    renderHostInternal.RenderConfiguration.FXAALevel           = FXAALevel;
                    renderHostInternal.OnRendered        -= this.OnRendered;
                    renderHostInternal.OnRendered        += this.OnRendered;
                    renderHostInternal.ExceptionOccurred -= RenderHostInternal_ExceptionOccurred;
                    renderHostInternal.ExceptionOccurred += RenderHostInternal_ExceptionOccurred;
                }
            }
            if (viewCube == null)
            {
                viewCube = GetTemplateChild(ViewportPartNames.PART_ViewCube) as ViewBoxModel3D;
                if (viewCube != null)
                {
                    viewCube.ViewBoxClickedEvent += ViewCube_ViewBoxClickedEvent;
                }
            }

            if (viewCube == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_ViewCube);
            }

            if (coordinateSystem == null)
            {
                coordinateSystem = GetTemplateChild(ViewportPartNames.PART_CoordinateView) as CoordinateSystemModel3D;
            }
            if (coordinateSystem == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_CoordinateView);
            }
        }
示例#3
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            if (IsInDesignMode && !EnableDesignModeRendering)
            {
                return;
            }
            itemsContainer = GetTemplateChild(ViewportPartNames.PART_ItemsContainer) as ItemsControl;
            if (itemsContainer == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_ItemsContainer);
            }
            else
            {
                itemsContainer.Items.Clear();
                foreach (var item in Items)
                {
                    itemsContainer.Items.Add(item);
                }
            }

            if (hostPresenter != null)
            {
                renderHostInternal.Rendered          -= this.RaiseRenderHostRendered;
                renderHostInternal.ExceptionOccurred -= RenderHostInternal_ExceptionOccurred;
            }
            hostPresenter = GetTemplateChild(ViewportPartNames.PART_HostPresenter) as ContentPresenter;
            if (hostPresenter != null)
            {
                hostPresenter.Content = new SwapChainRenderHost(EnableDeferredRendering);
                renderHostInternal    = (hostPresenter.Content as SwapChainRenderHost).RenderHost;
                if (renderHostInternal != null)
                {
                    renderHostInternal.RenderConfiguration.RenderD2D = false;
                    renderHostInternal.Viewport               = this;
                    renderHostInternal.IsRendering            = Visibility == Visibility.Visible;
                    renderHostInternal.EffectsManager         = this.EffectsManager;
                    renderHostInternal.ClearColor             = this.BackgroundColor.ToColor4();
                    renderHostInternal.EnableRenderFrustum    = this.EnableRenderFrustum;
                    renderHostInternal.IsShadowMapEnabled     = this.IsShadowMappingEnabled;
                    renderHostInternal.SharedModelContainer   = this.SharedModelContainer;
                    renderHostInternal.EnableSharingModelMode = this.EnableSharedModelMode;
#if MSAA
                    renderHostInternal.MSAA = this.MSAA;
#endif
                    renderHostInternal.RenderConfiguration.AutoUpdateOctree    = this.EnableAutoOctreeUpdate;
                    renderHostInternal.RenderConfiguration.EnableOITRendering  = EnableOITRendering;
                    renderHostInternal.RenderConfiguration.OITWeightPower      = (float)OITWeightPower;
                    renderHostInternal.RenderConfiguration.OITWeightDepthSlope = (float)OITWeightDepthSlope;
                    renderHostInternal.RenderConfiguration.OITWeightMode       = OITWeightMode;
                    renderHostInternal.RenderConfiguration.FXAALevel           = FXAALevel;
                    renderHostInternal.RenderConfiguration.EnableRenderOrder   = EnableRenderOrder;
                    renderHostInternal.RenderConfiguration.EnableSSAO          = EnableSSAO;
                    renderHostInternal.RenderConfiguration.SSAORadius          = (float)SSAOSamplingRadius;
                    renderHostInternal.RenderConfiguration.SSAOIntensity       = (float)SSAOIntensity;
                    renderHostInternal.RenderConfiguration.SSAOQuality         = SSAOQuality;
                    renderHostInternal.RenderConfiguration.MinimumUpdateCount  = (uint)Math.Max(0, MinimumUpdateCount);
                    renderHostInternal.Rendered          += this.RaiseRenderHostRendered;
                    renderHostInternal.ExceptionOccurred += RenderHostInternal_ExceptionOccurred;

                    if (ShowFrameRate)
                    {
                        this.renderHostInternal.ShowRenderDetail |= RenderDetail.FPS;
                    }
                    else
                    {
                        this.renderHostInternal.ShowRenderDetail &= ~RenderDetail.FPS;
                    }
                    if (ShowFrameDetails)
                    {
                        this.renderHostInternal.ShowRenderDetail |= RenderDetail.Statistics;
                    }
                    else
                    {
                        this.renderHostInternal.ShowRenderDetail &= ~RenderDetail.Statistics;
                    }
                    if (ShowTriangleCountInfo)
                    {
                        this.renderHostInternal.ShowRenderDetail |= RenderDetail.TriangleInfo;
                    }
                    else
                    {
                        this.renderHostInternal.ShowRenderDetail &= ~RenderDetail.TriangleInfo;
                    }
                    if (ShowCameraInfo)
                    {
                        this.renderHostInternal.ShowRenderDetail |= RenderDetail.Camera;
                    }
                    else
                    {
                        this.renderHostInternal.ShowRenderDetail &= ~RenderDetail.Camera;
                    }
                }
            }
            if (viewCube == null)
            {
                viewCube = GetTemplateChild(ViewportPartNames.PART_ViewCube) as ViewBoxModel3D;
            }

            if (viewCube == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_ViewCube);
            }

            if (coordinateSystem == null)
            {
                coordinateSystem = GetTemplateChild(ViewportPartNames.PART_CoordinateView) as CoordinateSystemModel3D;
            }
            if (coordinateSystem == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_CoordinateView);
            }
        }