Esempio n. 1
0
        /// <summary>
        /// Sets the specified cull value to the object at results index
        /// </summary>
        /// <param name="value">Value</param>
        /// <param name="index">Results index</param>
        /// <param name="item">Object</param>
        private void SetCullValue(CullData value, int index, ICullable item, bool force)
        {
            if (!this.Objects.ContainsKey(item))
            {
                this.Objects.Add(item, new List <CullData>(index + 1));
            }

            var values = this.Objects[item];

            if (values.Count <= index)
            {
                var valuesToAdd = new CullData[index - values.Count + 1];

                values.AddRange(valuesToAdd);
            }

            if (force)
            {
                // Culled values stay untouched
                if (values[index].Culled)
                {
                    values[index] = value;
                }
            }
            else
            {
                values[index] = value;
            }
        }
        public void AddCullable(ICullable cullable)
        {
            if (cullables.Contains(cullable))
            {
                throw new InvalidOperationException();
            }
            cullables.Add(cullable);
            var item = new CullableItem {
                Cullable = cullable, Index = cullablesLookup.Count
            };

            cullablesLookup.Add(item);
            cullableItemMap[cullable] = item;


            CullNode node = RootNode.FindContainingNode(cullable);

            cullableContainingNodes[cullable] = node;

            if (node == null)
            {
                node = RootNode;
            }
            node.PlaceCullable(item);


            if (viewCullablesBufferSize <= cullablesLookup.Count)
            {
                expandCullablesBuffer();
            }
        }
Esempio n. 3
0
 public RenderItem(
     EffectMaterial material,
     Buffer vertexBuffer0,
     Buffer vertexBuffer1,
     CullFlags cullFlags,
     ICullable cullable,
     in Matrix4x4 world,
        /// <summary>
        /// TODO: test this, i think this doesnt work correctly. Objects seem to remain in the tree
        /// </summary>
        /// <param name="cullable"></param>
        public void RemoveCullable(ICullable cullable)
        {
            cullables.Remove(cullable);

            CullNode node = cullableContainingNodes[cullable];

            node.RemoveCullable(cullableItemMap[cullable]);
        }
 public bool isCompletelyInFrustum(ICullable target)
 {
     return(EventHorizonBlazorInterop.Func <bool>(
                new object[]
     {
         new string[] { this.___guid, "isCompletelyInFrustum" }, target
     }
                ));
 }
 public bool isInFrustum(ICullable target, System.Nullable <bool> checkRigCameras = null)
 {
     return(EventHorizonBlazorInterop.Func <bool>(
                new object[]
     {
         new string[] { this.___guid, "isInFrustum" }, target, checkRigCameras
     }
                ));
 }
Esempio n. 7
0
 public void Update(ICullable item)
 {
     if (Scene != null)
     {
         if (item.BoundingSphere.Radius > 0)
         {
             _items.Remove((Frame)item);
             item.CullRegion = Scene.GetCullRegion((Frame)item);
         }
     }
 }
            public CullNode FindEncapsulatingNodeUpwards(ICullable cullable)
            {
                if (nodeData.BoundingBox.xna().Contains(cullable.BoundingBox.xna()) == Microsoft.Xna.Framework.ContainmentType.Contains)
                {
                    return(this);
                }

                if (nodeData.Parent == null)
                {
                    return(this);
                }
                return(nodeData.Parent.FindEncapsulatingNodeUpwards(cullable));
            }
Esempio n. 9
0
        /// <summary>
        /// Gets the specified object cull data in the results index
        /// </summary>
        /// <param name="index">Results index</param>
        /// <param name="item">Object</param>
        /// <returns>Returns the cull data item for the specified object and index. If not exists, returns the Empty cull data object</returns>
        public CullData GetCullValue(int index, ICullable item)
        {
            if (this.Objects.ContainsKey(item))
            {
                var values = this.Objects[item];

                if (index < values.Count)
                {
                    return(values[index]);
                }
            }

            return(CullData.Empty);
        }
Esempio n. 10
0
            public void Remove(ICullable item)
            {
                bool foundInChild = false;

                for (int i = 0; i < Children.Count; i++)
                {
                    if (Children[i].Bounds.Contains(item.Bounds) == ContainmentType.Contains)
                    {
                        Children[i].Remove(item);
                        foundInChild = true;
                        break;
                    }
                }

                if (!foundInChild)
                {
                    Items.Remove(item);
                }
            }
Esempio n. 11
0
        public void Add(ICullable item)
        {
            var bounds = item.Bounds;
            if (root.Bounds.Contains(bounds) != ContainmentType.Contains)
            {
                BoundingBox newWorld = root.Bounds;
                do
                {
                    var extents = new Vector3(bounds.Radius + 1);
                    var newItemBounds = new BoundingBox(bounds.Center - extents, bounds.Center + extents);
                    newWorld = BoundingBox.CreateMerged(newWorld, newItemBounds);
                } while (newWorld.Contains(bounds) != ContainmentType.Contains);

                var newRoot = nodePool.Get();
                newRoot.Bounds = newWorld;
                root.Transfer(newRoot);
                root = newRoot;
            }

            root.Add(item);
        }
            public CullNode FindContainingNode(ICullable cullable)
            {
                if (nodeData.BoundingBox.xna().Contains(cullable.BoundingBox.xna()) != Microsoft.Xna.Framework.ContainmentType.Contains)
                {
                    return(null);
                }

                if (QuadTree.IsLeafNode(this))
                {
                    return(this);
                }

                CullNode node;

                node = (nodeData.LowerLeft as CullNode).FindContainingNode(cullable);
                if (node != null)
                {
                    return(node);
                }

                node = (nodeData.LowerRight as CullNode).FindContainingNode(cullable);
                if (node != null)
                {
                    return(node);
                }

                node = (nodeData.UpperLeft as CullNode).FindContainingNode(cullable);
                if (node != null)
                {
                    return(node);
                }

                node = (nodeData.UpperRight as CullNode).FindContainingNode(cullable);
                if (node != null)
                {
                    return(node);
                }

                return(this);
            }
Esempio n. 13
0
        public void Add(ICullable item)
        {
            var bounds = item.Bounds;

            if (root.Bounds.Contains(bounds) != ContainmentType.Contains)
            {
                BoundingBox newWorld = root.Bounds;
                do
                {
                    var extents       = new Vector3(bounds.Radius + 1);
                    var newItemBounds = new BoundingBox(bounds.Center - extents, bounds.Center + extents);
                    newWorld = BoundingBox.CreateMerged(newWorld, newItemBounds);
                } while (newWorld.Contains(bounds) != ContainmentType.Contains);

                var newRoot = nodePool.Get();
                newRoot.Bounds = newWorld;
                root.Transfer(newRoot);
                root = newRoot;
            }

            root.Add(item);
        }
        public void UpdateCullable(ICullable cullable)
        {
            CullNode oldNode = cullableContainingNodes[cullable];
            CullNode newNode;

            //This check is cheatfix and this bug should be fixed
            if (oldNode == null)
            {
                newNode = null;
            }
            else
            {
                newNode = oldNode.FindEncapsulatingNodeUpwards(cullable);
                newNode = newNode.FindContainingNode(cullable);
            }

            if (newNode == null)
            {
                newNode = RootNode;
            }

            if (newNode == oldNode)
            {
                return;
            }

            cullableContainingNodes[cullable] = newNode;

            var item = cullableItemMap[cullable];

            //This check is cheatfix and this bug should be fixed
            if (oldNode != null)
            {
                oldNode.RemoveCullable(item);
            }
            newNode.PlaceCullable(item);
        }
 public void RemoveCullable(ICullable cullable)
 {
     culler.RemoveCullable(cullable);
 }
Esempio n. 16
0
 public bool Remove(ICullable item)
 {
     return(_items.Remove((Frame)item));
 }
Esempio n. 17
0
 public bool Add(ICullable item)
 {
     _items.Add((Frame)item);
     return(true);
 }
Esempio n. 18
0
 public void UpdateCullable(ICullable cullable)
 {
 }
Esempio n. 19
0
 public void RemoveCullable(ICullable cullable)
 {
     cullable.VisibleReferenceCount--;
 }
Esempio n. 20
0
            public void Add(ICullable item)
            {
                //var bounds = item.BoundingBox.AxisAlignedBounds;

                bool insertedIntoChild = false;

                for (int i = 0; i < Children.Count; i++)
                {
                    if (Children[i].Bounds.Contains(item.Bounds) == ContainmentType.Contains)
                    {
                        Children[i].Add(item);
                        insertedIntoChild = true;
                        break;
                    }
                }

                if (!insertedIntoChild)
                {
                    Items.Add(item);
                }

                if (Children.Count == 0 && Items.Count > SPLIT_THRESHOLD)
                {
                    //var min = -Vector3.One;//Bounds.Min;
                    //var max = Vector3.One;//Bounds.Max;
                    //var centre = (min + max) / 2;
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(min.X, min.Y, min.Z), new Vector3(centre.X, centre.Y, centre.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(min.X, centre.Y, min.Z), new Vector3(centre.X, max.Y, centre.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(centre.X, centre.Y, min.Z), new Vector3(max.X, max.Y, centre.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(centre.X, min.Y, min.Z), new Vector3(max.X, centre.Y, centre.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(min.X, min.Y, centre.Z), new Vector3(centre.X, centre.Y, max.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(min.X, centre.Y, centre.Z), new Vector3(centre.X, max.Y, max.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(centre.X, centre.Y, centre.Z), new Vector3(max.X, max.Y, max.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(centre.X, min.Y, centre.Z), new Vector3(max.X, centre.Y, max.Z)) });

                    var min  = Bounds.Min;
                    var size = (Bounds.Max - Bounds.Min) / 2;
                    for (int x = 0; x < 2; x++)
                    {
                        for (int y = 0; y < 2; y++)
                        {
                            for (int z = 0; z < 2; z++)
                            {
                                var positionOffset = size * new Vector3(x, y, z);
                                Children.Add(new Node()
                                {
                                    Bounds = new BoundingBox(min + positionOffset, min + size + positionOffset)
                                });
                            }
                        }
                    }


                    var items = new List <ICullable>(Items);
                    Items.Clear();
                    foreach (var i in items)
                    {
                        Add(i);
                    }
                }
            }
Esempio n. 21
0
 bool ICullRegion.Add(ICullable item)
 {
     Add((T)item);
     return(true);
 }
 public void AddCullable(ICullable cullable)
 {
     culler.AddCullable(cullable);
 }
Esempio n. 23
0
            public void Remove(ICullable item)
            {
                bool foundInChild = false;
                for (int i = 0; i < Children.Count; i++)
                {
                    if (Children[i].Bounds.Contains(item.Bounds) == ContainmentType.Contains)
                    {
                        Children[i].Remove(item);
                        foundInChild = true;
                        break;
                    }
                }

                if (!foundInChild)
                    Items.Remove(item);
            }
Esempio n. 24
0
            public void Add(ICullable item)
            {
                //var bounds = item.BoundingBox.AxisAlignedBounds;

                bool insertedIntoChild = false;
                for (int i = 0; i < Children.Count; i++)
                {
                    if (Children[i].Bounds.Contains(item.Bounds) == ContainmentType.Contains)
                    {
                        Children[i].Add(item);
                        insertedIntoChild = true;
                        break;
                    }
                }

                if (!insertedIntoChild)
                    Items.Add(item);

                if (Children.Count == 0 && Items.Count > SPLIT_THRESHOLD)
                {
                    //var min = -Vector3.One;//Bounds.Min;
                    //var max = Vector3.One;//Bounds.Max;
                    //var centre = (min + max) / 2;
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(min.X, min.Y, min.Z), new Vector3(centre.X, centre.Y, centre.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(min.X, centre.Y, min.Z), new Vector3(centre.X, max.Y, centre.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(centre.X, centre.Y, min.Z), new Vector3(max.X, max.Y, centre.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(centre.X, min.Y, min.Z), new Vector3(max.X, centre.Y, centre.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(min.X, min.Y, centre.Z), new Vector3(centre.X, centre.Y, max.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(min.X, centre.Y, centre.Z), new Vector3(centre.X, max.Y, max.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(centre.X, centre.Y, centre.Z), new Vector3(max.X, max.Y, max.Z)) });
                    //Children.Add(new Node() { Bounds = new BoundingBox(new Vector3(centre.X, min.Y, centre.Z), new Vector3(max.X, centre.Y, max.Z)) });

                    var min = Bounds.Min;
                    var size = (Bounds.Max - Bounds.Min) / 2;
                    for (int x = 0; x < 2; x++)
                    {
                        for (int y = 0; y < 2; y++)
                        {
                            for (int z = 0; z < 2; z++)
                            {
                                var positionOffset = size * new Vector3(x, y, z);
                                Children.Add(new Node() { Bounds = new BoundingBox(min + positionOffset, min + size + positionOffset) });
                            }
                        }
                    }

                    var items = new List<ICullable>(Items);
                    Items.Clear();
                    foreach (var i in items)
                    {
                        Add(i);
                    }
                }
            }
Esempio n. 25
0
 public void Remove(ICullable item)
 {
     root.Remove(item);
 }
Esempio n. 26
0
 public void Remove(ICullable item)
 {
     root.Remove(item);
 }
Esempio n. 27
0
 void ICullRegion.Update(ICullable item)
 {
 }
Esempio n. 28
0
 bool ICullRegion.Add(ICullable item)
 {
     return(Add((T)item));
 }
Esempio n. 29
0
 bool ICullRegion.Remove(ICullable item)
 {
     return(Remove((T)item));
 }
 public void UpdateCullable(ICullable cullable)
 {
     culler.UpdateCullable(cullable);
 }
Esempio n. 31
0
 void ICullRegion.Update(ICullable item)
 {
     Update((T)item);
 }
Esempio n. 32
0
 public void AddCullable(ICullable cullable)
 {
     cullable.VisibleReferenceCount++;
 }