private RectangleHitTestResultTreeNode HitTestGeometry(System.Windows.Media.Geometry geometry)
        {
            RectangleGeometry rectangleGeometry = geometry as RectangleGeometry;
            Rect rect = rectangleGeometry != null ? rectangleGeometry.Rect : geometry.GetFlattenedPathGeometry().Bounds;
            RectangleHitTestResultTreeNode parent = new RectangleHitTestResultTreeNode((RectangleHitTestResultTreeNode)null, (DependencyObject)null);

            for (int index = 0; index < this.viewports.Count; ++index)
            {
                List <Point> frustumOutline = new List <Point>();
                Point        point1         = this.viewports[index].Transform.Transform(rect.TopLeft);
                Point        point2         = this.viewports[index].Transform.Transform(rect.TopRight);
                Point        point3         = this.viewports[index].Transform.Transform(rect.BottomRight);
                Point        point4         = this.viewports[index].Transform.Transform(rect.BottomLeft);
                frustumOutline.Add(point1);
                frustumOutline.Add(point2);
                frustumOutline.Add(point3);
                frustumOutline.Add(point4);
                this.frustum = this.BuildFrustumFromViewport(this.viewports[index], frustumOutline);
                RectangleHitTestResultTreeNode testResultTreeNode = new RectangleHitTestResultTreeNode(parent, (DependencyObject)null);
                if (this.WalkVisual3DChildren(this.viewports[index].Children, Matrix3D.Identity, testResultTreeNode))
                {
                    parent.AddChild(testResultTreeNode);
                }
            }
            return(parent);
        }
        private bool WalkModelTree(Model3D model3D, Matrix3D currentTransform, RectangleHitTestResultTreeNode node)
        {
            Model3DGroup model3Dgroup = model3D as Model3DGroup;

            if (model3Dgroup != null)
            {
                if (model3Dgroup.Children == null || !this.TestSphereEnclosingBoundingBoxAgainstFrustum(model3Dgroup.Bounds, currentTransform))
                {
                    return(false);
                }
                if (model3Dgroup.Transform != null)
                {
                    currentTransform.Prepend(model3Dgroup.Transform.Value);
                }
                RectangleHitTestResultTreeNode testResultTreeNode = new RectangleHitTestResultTreeNode(node, (DependencyObject)model3Dgroup);
                bool flag = false;
                foreach (Model3D model3D1 in model3Dgroup.Children)
                {
                    if (this.WalkModelTree(model3D1, currentTransform, testResultTreeNode))
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    node.AddChild(testResultTreeNode);
                }
                return(flag);
            }
            GeometryModel3D geometryModel3D;

            if ((geometryModel3D = model3D as GeometryModel3D) != null)
            {
                return(this.HitTestAgainstGeometry((DependencyObject)geometryModel3D, geometryModel3D.Bounds, geometryModel3D.Transform, geometryModel3D.Geometry as MeshGeometry3D, currentTransform, geometryModel3D.Material, geometryModel3D.BackMaterial, node));
            }
            return(false);
        }
        private bool WalkVisual3DChildren(Visual3DCollection visual3DCollection, Matrix3D currentTransform, RectangleHitTestResultTreeNode node)
        {
            bool flag1 = false;

            if (visual3DCollection == null)
            {
                return(false);
            }
            foreach (Visual3D reference in visual3DCollection)
            {
                Matrix3D currentTransform1 = currentTransform;
                if (reference.Transform != null)
                {
                    currentTransform1.Prepend(reference.Transform.Value);
                }
                if (this.TestSphereEnclosingBoundingBoxAgainstFrustum(VisualTreeHelper.GetContentBounds(reference), currentTransform1))
                {
                    RectangleHitTestResultTreeNode testResultTreeNode = new RectangleHitTestResultTreeNode(node, (DependencyObject)reference);
                    bool                 flag2                = false;
                    ModelVisual3D        modelVisual3D        = reference as ModelVisual3D;
                    ModelUIElement3D     modelUiElement3D     = reference as ModelUIElement3D;
                    ContainerUIElement3D containerUiElement3D = reference as ContainerUIElement3D;
                    Viewport2DVisual3D   viewport2Dvisual3D   = reference as Viewport2DVisual3D;
                    if (modelVisual3D != null)
                    {
                        if (this.WalkModelTree(modelVisual3D.Content, currentTransform1, testResultTreeNode))
                        {
                            flag1 = true;
                        }
                        if (this.WalkVisual3DChildren(modelVisual3D.Children, currentTransform1, testResultTreeNode))
                        {
                            flag1 = true;
                        }
                    }
                    else if (modelUiElement3D != null)
                    {
                        if (this.WalkModelTree(modelUiElement3D.Model, currentTransform1, testResultTreeNode))
                        {
                            flag1 = true;
                        }
                    }
                    else if (containerUiElement3D != null)
                    {
                        if (this.WalkVisual3DChildren(containerUiElement3D.Children, currentTransform1, testResultTreeNode))
                        {
                            flag1 = true;
                        }
                    }
                    else if (viewport2Dvisual3D != null && viewport2Dvisual3D.Geometry != null)
                    {
                        flag2 = this.HitTestAgainstGeometry((DependencyObject)viewport2Dvisual3D, viewport2Dvisual3D.Geometry.Bounds, viewport2Dvisual3D.Transform, viewport2Dvisual3D.Geometry as MeshGeometry3D, currentTransform, viewport2Dvisual3D.Material, (Material)null, node);
                    }
                    if (flag1)
                    {
                        node.AddChild(testResultTreeNode);
                    }
                    if (flag2)
                    {
                        flag1 = true;
                    }
                }
            }
            return(flag1);
        }