Ejemplo n.º 1
0
        void InvalidateDueVisibilityChange(IntVector3 cameraChunkPos)
        {
            var min = IntVector3.Min(cameraChunkPos, m_cameraChunkPos);
            var max = IntVector3.Max(cameraChunkPos, m_cameraChunkPos);

            var diff = max - min;

            if (diff.X != 0)
            {
                for (int x = Math.Max(min.X, 0); x <= Math.Min(max.X, this.Size.Width - 1); ++x)
                {
                    InvalidateYZPlane(x);
                }
            }

            if (diff.Y != 0)
            {
                for (int y = Math.Max(min.Y, 0); y <= Math.Min(max.Y, this.Size.Height - 1); ++y)
                {
                    InvalidateXZPlane(y);
                }
            }

            if (diff.Z != 0)
            {
                for (int z = Math.Max(min.Z, 0); z <= Math.Min(max.Z, this.Size.Depth - 1); ++z)
                {
                    InvalidateXYPlane(z);
                }
            }
        }
Ejemplo n.º 2
0
    // Returns whether the node is changed.
    private bool RemoveInternal(IntBox area, OctreeNode <T> node, int level, IntVector3 corner)
    {
        IntBox nodeArea = new IntBox(corner, corner + ((1 << level) - 1) * IntVector3.one);

        if (area.Contains(nodeArea))
        {
            if (!node.isEmpty)
            {
                node.obj      = default(T);
                node.objCount = 0;
                node.RemoveChildren();
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else if (!node.obj.Equals(default(T)))
        {
            node.Split();
        }

        int        childSize     = 1 << (level - 1);
        IntVector3 childIndexMin = IntVector3.Max((area.min - corner) / childSize, IntVector3.zero);
        IntVector3 childIndexMax = IntVector3.Min((area.max - corner) / childSize, IntVector3.one);
        bool       changed       = false;

        for (int x = childIndexMin.x; x <= childIndexMax.x; x++)
        {
            for (int y = childIndexMin.y; y <= childIndexMax.y; y++)
            {
                for (int z = childIndexMin.z; z <= childIndexMax.z; z++)
                {
                    IntVector3 childIndex = new IntVector3(x, y, z);
                    var        childNode  = node.GetChild(childIndex);
                    if (childNode != null)
                    {
                        long oldChildObjCount = childNode.objCount;
                        bool childChanged     = RemoveInternal(area, childNode, level - 1, corner + childIndex * childSize);
                        if (childChanged)
                        {
                            changed        = true;
                            node.objCount += childNode.objCount - oldChildObjCount;
                            if (childNode.isEmpty)
                            {
                                node.RemoveChild(childIndex);
                            }
                        }
                    }
                }
            }
        }
        return(changed);
    }
Ejemplo n.º 3
0
    // Returns whether the node is changed.
    private bool SetInternal(IntBox area, T obj, OctreeNode <T> node, int level, IntVector3 corner)
    {
        IntBox nodeArea = new IntBox(corner, corner + ((1 << level) - 1) * IntVector3.one);

        if (node.obj.Equals(obj))
        {
            return(false);
        }
        else if (area.Contains(nodeArea))
        {
            node.obj      = obj;
            node.objCount = 1 << level;
            node.RemoveChildren();
            return(true);
        }
        else if (node.isFilled)
        {
            node.Split();
        }

        int        childSize     = 1 << (level - 1);
        IntVector3 childIndexMin = IntVector3.Max((area.min - corner) / childSize, IntVector3.zero);
        IntVector3 childIndexMax = IntVector3.Min((area.max - corner) / childSize, IntVector3.one);
        bool       changed       = false;

        for (int x = childIndexMin.x; x <= childIndexMax.x; x++)
        {
            for (int y = childIndexMin.y; y <= childIndexMax.y; y++)
            {
                for (int z = childIndexMin.z; z <= childIndexMax.z; z++)
                {
                    IntVector3 childIndex = new IntVector3(x, y, z);
                    var        childNode  = node.GetChild(childIndex);
                    if (childNode == null)
                    {
                        childNode = node.CreateChild(childIndex);
                    }

                    long oldChildObjCount = childNode.objCount;
                    bool childChanged     = SetInternal(area, obj, childNode, level - 1, corner + childIndex * childSize);
                    if (childChanged)
                    {
                        changed        = true;
                        node.objCount += childNode.objCount - oldChildObjCount;
                        if (childNode.isFilled)
                        {
                            node.MergeIfPossible(obj);
                        }
                    }
                }
            }
        }
        return(changed);
    }
Ejemplo n.º 4
0
 public static IntBox OuterBound(IntBox b1, IntBox b2)
 {
     if (b1.isEmpty)
     {
         return(b2);
     }
     if (b2.isEmpty)
     {
         return(b1);
     }
     return(new IntBox(IntVector3.Min(b1.min, b2.min), IntVector3.Max(b1.max, b2.max)));
 }
Ejemplo n.º 5
0
 public static IntBox Intersection(IntBox b1, IntBox b2)
 {
     return(new IntBox(IntVector3.Max(b1.min, b2.min), IntVector3.Min(b1.max, b2.max)));
 }
Ejemplo n.º 6
0
 protected override void ExtendBounds(IntVector3 index)
 {
     _bounds.min = IntVector3.Min(_bounds.min, index);
     _bounds.max = IntVector3.Max(_bounds.max, index);
 }