public LODMeshObject(LODMeshObject parent, QuadTreeNode quadTreeNode, AxisAlignedRectangle bounds, int depth) { Invalid = true; Parent = parent; QuadNode = quadTreeNode; Bounds = bounds; Depth = depth; TotalDepth = QuadNode.Depth + Depth; Children = new LODMeshObject[4]; CornerReference = new bool[5]; Center = FindOrCreateCorner(Bounds.Position, true); Vector2 halfSize = Bounds.Size / 2; Corner = new Corner[8]; Corner[0] = FindOrCreateCorner(Bounds.Position + new Vector2(-halfSize.x, -halfSize.y), Parent == null); // bottom left Corner[1] = FindOrCreateCorner(Bounds.Position + new Vector2(-halfSize.x, 0), true); // left Corner[2] = FindOrCreateCorner(Bounds.Position + new Vector2(-halfSize.x, halfSize.y), Parent == null); // top left Corner[3] = FindOrCreateCorner(Bounds.Position + new Vector2(0, halfSize.y), true); // top Corner[4] = FindOrCreateCorner(Bounds.Position + new Vector2(halfSize.x, halfSize.y), Parent == null); // top right Corner[5] = FindOrCreateCorner(Bounds.Position + new Vector2(halfSize.x, 0), true); // right Corner[6] = FindOrCreateCorner(Bounds.Position + new Vector2(halfSize.x, -halfSize.y), Parent == null); // bottom right Corner[7] = FindOrCreateCorner(Bounds.Position + new Vector2(0, -halfSize.y), true); // bottom }
public QuadTreeNode(QuadTree quadTree, QuadTreeNode parent, Vector2 position, float length, float minSize, int depth) { Active = true; Parent = parent; QuadTree = quadTree; Position = position; SideLength = length; MinSize = minSize; Depth = depth; AAR = new AxisAlignedRectangle(Position, SideLength * 2); MeshObject = new LODMeshObject(null, this, AAR, 0); CreateGameobject(); }
private void Split() { Invalidate(); for (int i = 0; i < Children.Length; i++) { if (Children[i] != null) continue; Children[i] = new LODMeshObject(this, QuadNode, Bounds.Split((Quadrant)i), Depth + 1); } }
public void SetChildren(LODMeshObject southWest, LODMeshObject northWest, LODMeshObject southEast, LODMeshObject northEast) { Children[0] = southWest; Children[1] = northWest; Children[2] = southEast; Children[3] = northEast; ApplyValues(); }
public void ImportLODMesh(LODMeshObject lodMesh) { lodMesh.Children.CopyTo(Children, 0); lodMesh.Children[0] = null; lodMesh.Children[1] = null; lodMesh.Children[2] = null; lodMesh.Children[3] = null; ApplyValues(); }
private int GetDepth(LODMeshObject meshObject) { int depth = meshObject.Depth; for (int i = 0; i < meshObject.Children.Length; i++) { if (meshObject.Children[i] == null) continue; depth = Mathf.Max(depth, GetDepth(meshObject.Children[i])); } return depth; }
public void UseLODMesh(LODMeshObject lodMesh) { MeshObject.ImportLODMesh(lodMesh); }