Example #1
0
        public void InsertNode(SceneNode node, PartitionCategories category)
        {
            switch (category)
            {
            case PartitionCategories.Dynamic:
                mDynamicRoot.AddChild(node);
                break;

            case PartitionCategories.Static:
                ImplicitBoundingBoxNode boxNode = node as ImplicitBoundingBoxNode;
                if (boxNode == null)
                {
                    boxNode = new ImplicitBoundingBoxNode(true);
                    boxNode.AddChild(node);
                    boxNode.RecalculateBound();
                }

                if (mStaticTreeRoot == null)
                {
                    mStaticTreeRoot = boxNode;
                }
                else
                {
                    mStaticTreeRoot.InsertNodeIntoBVH(boxNode);
                }
                break;

            case PartitionCategories.Skybox:
                mSkyboxRoot.AddChild(node);
                break;
            }
        }
Example #2
0
        private SceneNode PartitionSectorGrid(int xMinIndex, int xCount, int zMinIndex, int zCount)
        {
            if (xCount == 1 && zCount == 1)
            {
                return(CreateSectorNode(xMinIndex, zMinIndex));
            }

            SceneNode child1 = null;
            SceneNode child2 = null;

            if (xCount > zCount)
            {
                child1 = PartitionSectorGrid(
                    xMinIndex,
                    xCount / 2,
                    zMinIndex,
                    zCount);
                child2 = PartitionSectorGrid(
                    xMinIndex + xCount / 2,
                    xCount - xCount / 2,
                    zMinIndex,
                    zCount);
            }
            else
            {
                child1 = PartitionSectorGrid(
                    xMinIndex,
                    xCount,
                    zMinIndex,
                    zCount / 2);
                child2 = PartitionSectorGrid(
                    xMinIndex,
                    xCount,
                    zMinIndex + zCount / 2,
                    zCount - zCount / 2);
            }

            ImplicitBoundingBoxNode implicitChild1 = child1 as ImplicitBoundingBoxNode;
            ImplicitBoundingBoxNode implicitChild2 = child2 as ImplicitBoundingBoxNode;
            // If either child is not an implicit node, then this node must be marked as a 'leaf' node so the BVH insertion will work correctly.
            ImplicitBoundingBoxNode parentPartition = new ImplicitBoundingBoxNode(implicitChild1 == null || implicitChild2 == null);

            parentPartition.AddChild(child1);
            parentPartition.AddChild(child2);

            return(parentPartition);
        }
        private SceneNode PartitionSectorGrid(int xMinIndex, int xCount, int zMinIndex, int zCount)
        {
            if (xCount == 1 && zCount == 1)
                return CreateSectorNode(xMinIndex, zMinIndex);

            SceneNode child1 = null;
            SceneNode child2 = null;

            if (xCount > zCount)
            {
                child1 = PartitionSectorGrid(
                    xMinIndex,
                    xCount / 2,
                    zMinIndex,
                    zCount);
                child2 = PartitionSectorGrid(
                    xMinIndex + xCount / 2,
                    xCount - xCount / 2,
                    zMinIndex,
                    zCount);
            }
            else
            {
                child1 = PartitionSectorGrid(
                    xMinIndex,
                    xCount,
                    zMinIndex,
                    zCount / 2);
                child2 = PartitionSectorGrid(
                    xMinIndex,
                    xCount,
                    zMinIndex + zCount / 2,
                    zCount - zCount / 2);
            }

            ImplicitBoundingBoxNode implicitChild1 = child1 as ImplicitBoundingBoxNode;
            ImplicitBoundingBoxNode implicitChild2 = child2 as ImplicitBoundingBoxNode;
            // If either child is not an implicit node, then this node must be marked as a 'leaf' node so the BVH insertion will work correctly.
            ImplicitBoundingBoxNode parentPartition = new ImplicitBoundingBoxNode(implicitChild1 == null || implicitChild2 == null);
            parentPartition.AddChild(child1);
            parentPartition.AddChild(child2);

            return parentPartition;
        }
Example #4
0
        public void InsertNode(SceneNode node, PartitionCategories category)
        {
            switch (category)
            {
                case PartitionCategories.Dynamic:
                    mDynamicRoot.AddChild(node);
                    break;
                case PartitionCategories.Static:
                    ImplicitBoundingBoxNode boxNode = node as ImplicitBoundingBoxNode;
                    if (boxNode == null)
                    {
                        boxNode = new ImplicitBoundingBoxNode(true);
                        boxNode.AddChild(node);
                        boxNode.RecalculateBound();
                    }

                    if (mStaticTreeRoot == null)
                    {
                        mStaticTreeRoot = boxNode;
                    }
                    else
                    {
                        mStaticTreeRoot.InsertNodeIntoBVH(boxNode);
                    }
                    break;
                case PartitionCategories.Skybox:
                    mSkyboxRoot.AddChild(node);
                    break;
            }
        }