// #### PUBLIC METHODS #### /// <summary> /// Add an object. /// </summary> /// <param name="obj">Object to add.</param> /// <param name="objBounds">3D bounding box around the object.</param> public BoundsOctreeNode <T> Add(T obj, Bounds objBounds) { var node = rootNode.Add(obj, objBounds); if (node != null) { Count++; return(node); } return(null); }
// #### PUBLIC METHODS #### /// <summary> /// Add an object. /// </summary> /// <param name="obj">Object to add.</param> /// <param name="objBounds">3D bounding box around the object.</param> public void Add(T obj, Bounds objBounds) { // Add object or expand the octree until it can be added int count = 0; // Safety check against infinite/excessive growth while (!rootNode.Add(obj, objBounds)) { rootNode.Add(obj, objBounds); Grow(objBounds.center - rootNode.Center); if (++count > 100) { //Console.Error.WriteLine("Aborted Add operation as it seemed to be going on forever (" + (count - 1) + // ") attempts at growing the octree."); throw new Exception("Aborted Add operation as it seemed to be going on forever (" + (count - 1) + ") attempts at growing the octree."); return; } } Count++; }
// #### PUBLIC METHODS #### /// <summary> /// Add an object. /// </summary> /// <param name="obj">Object to add.</param> /// <param name="objBounds">3D bounding box around the object.</param> // 添加物体 // 如果加不上,扩展八叉树范围 public void Add(T obj, Bounds objBounds) { // Add object or expand the octree until it can be added int count = 0; // Safety check against infinite/excessive growth // 查实根节点中,加入物体 while (!rootNode.Add(obj, objBounds)) { // 如果没有加上 // 尝试扩展八叉树大小 // 扩展八叉树的范围,原来的范围*2 // 会创建7个新的节点,同旧的根节点,一个8个节点 // 作为新的根节点的孩子 Grow(objBounds.center - rootNode.Center); if (++count > 20) { Debug.LogError("Aborted Add operation as it seemed to be going on forever (" + (count - 1) + ") attempts at growing the octree."); return; } } Count++; }