Esempio n. 1
0
        /// <summary>
        /// Tries to set the visibility of this object on the given view.
        /// This method can be used to force rendering on the next frame after adding
        /// an object to the scene.
        /// </summary>
        /// <param name="viewInfo">The view on which to set the visibility.</param>
        /// <param name="isVisible">The visibility state to set.</param>
        public bool TrySetInitialVisibility(ViewInformation viewInfo, bool isVisible)
        {
            if (viewInfo.ViewIndex < 0)
            {
                return(false);
            }

            VisibilityCheckData checkData = this.GetVisibilityCheckData(viewInfo);

            if (checkData.IsVisible)
            {
                return(true);
            }

            if ((checkData.IsVisible != isVisible) &&
                (checkData.FilterStageData.Count == 0))
            {
                checkData.IsVisible = isVisible;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the data object used for visibility checking.
        /// </summary>
        /// <param name="viewInfo">The VisibilityCheckData for this object for the given view.</param>
        internal VisibilityCheckData GetVisibilityCheckData(ViewInformation viewInfo)
        {
            VisibilityCheckData checkData = m_visibilityData[viewInfo.ViewIndex];

            if (checkData == null)
            {
                checkData = m_visibilityData.AddObject(
                    new VisibilityCheckData(),
                    viewInfo.ViewIndex);
            }
            return(checkData);
        }
Esempio n. 3
0
        /// <summary>
        /// Is this object visible in the given view?
        /// </summary>
        /// <param name="viewInfo">The view info to check.</param>
        public bool IsVisible(ViewInformation viewInfo)
        {
            if (viewInfo.ViewIndex < 0)
            {
                throw new SeeingSharpGraphicsException("Given ViewInformation object is not assoziated to any view!");
            }
            if (viewInfo.Scene == null)
            {
                throw new SeeingSharpGraphicsException("Given ViewInformation object is not attached to any scene!");
            }
            if (viewInfo.Scene != this.Scene)
            {
                throw new SeeingSharpGraphicsException("Given ViewInformation object is not attached to this scene!");
            }

            VisibilityCheckData checkData = m_visibilityData[viewInfo.ViewIndex];

            if (checkData == null)
            {
                return(false);
            }

            return(checkData.IsVisible);
        }
Esempio n. 4
0
        /// <summary>
        /// Main method for object filtering. This method checks whether an object is visible or not.
        /// </summary>
        /// <param name="actObject">The object to be tested.</param>
        /// <param name="filters">All currently active filters.</param>
        /// <param name="refreshStaticObjects">A flag inicating whether we have to update all objects.</param>
        private void PerformViewboxCulling(SceneObject actObject, List <SceneObjectFilter> filters, bool refreshStaticObjects)
        {
            if (!actObject.IsLayerViewSubsetRegistered(this.ViewIndex))
            {
                return;
            }
            if (m_invalidObjects.ContainsKey(actObject))
            {
                return;
            }

            // Get visiblity check data about current object
            VisibilityCheckData checkData = actObject.GetVisibilityCheckData(m_viewInformation);

            if (checkData == null)
            {
                return;
            }

            // Execute all filters in configured order step by step
            int  filterCount            = filters.Count;
            bool previousFilterExecuted = false;
            bool previousFilterResult   = true;
            VisibilityCheckFilterStageData lastFilterStageData = null;

            for (int actFilterIndex = 0; actFilterIndex < filterCount; actFilterIndex++)
            {
                SceneObjectFilter actFilter = filters[actFilterIndex];

                // Get data about current filter stage
                VisibilityCheckFilterStageData filterStageData = checkData.FilterStageData[actFilterIndex];
                if (filterStageData == null)
                {
                    filterStageData = checkData.FilterStageData.AddObject(
                        new VisibilityCheckFilterStageData(),
                        actFilterIndex);
                }

                // Remember last filter stage data
                lastFilterStageData = filterStageData;

                // Execute filter if needed
                if ((!filterStageData.HasExecuted) ||   // <-- Execute the filter if it was not executed for this object before
                    (actFilter.ConfigurationChanged) || // <-- Execute the filter if its configuraiton has changed
                    previousFilterExecuted ||           // <-- Execute the filter if one of the previous was executed
                    actFilter.UpdateEachFrame)          // <-- Execute the filter if it requests it on each frame (e. g. clipping filter)
                {
                    if (previousFilterResult)
                    {
                        // Re-Filter this object because any above condition has passed and
                        // this object successfully past the previous filter
                        bool isObjectVisible = actFilter.IsObjectVisible(actObject, m_viewInformation);

                        filterStageData.HasExecuted = true;
                        filterStageData.HasPassed   = isObjectVisible;

                        previousFilterResult   = isObjectVisible;
                        previousFilterExecuted = true;
                    }
                    else
                    {
                        // Set this object to unvisible because previous filter has thrown out
                        // this object
                        filterStageData.HasExecuted = true;
                        filterStageData.HasPassed   = false;
                    }
                }
                else
                {
                    previousFilterResult   = filterStageData.HasPassed;
                    previousFilterExecuted = false;
                }
            }

            // Handle changed visibility of the object
            bool oldVisible = checkData.IsVisible;
            bool newVisible = lastFilterStageData != null ? lastFilterStageData.HasPassed : true;

            if (oldVisible != newVisible)
            {
                checkData.IsVisible = newVisible;
                m_tmpChangedVisibilities.Add(Tuple.Create(actObject, oldVisible, newVisible));
            }
        }