private static void DeriveExtents(BoundsItem[] items, int imin, int imax, ref ChunkyTriMeshNode node) { node.xmin = items[imin].xmin; node.zmin = items[imin].zmin; node.xmax = items[imin].xmax; node.zmax = items[imin].zmax; for (int i = imin + 1; i < imax; ++i) { if (items[i].xmin < node.xmin) { node.xmin = items[i].xmin; } if (items[i].zmin < node.zmin) { node.zmin = items[i].zmin; } if (items[i].xmax > node.xmax) { node.xmax = items[i].xmax; } if (items[i].zmax > node.zmax) { node.zmax = items[i].zmax; } } }
/// <summary> /// Gets all nodes overlapped by the specified bounds. /// </summary> /// <param name="xmin">The minimum x-bounds.</param> /// <param name="zmin">The minimum z-bounds.</param> /// <param name="xmax">The maximum x-bounds.</param> /// <param name="zmax">The maximum z-bounds.</param> /// <param name="resultNodes">The list to append the result to.</param> /// <returns>The number of result nodes appended to the result list.</returns> public int GetChunks(float xmin, float zmin, float xmax, float zmax , List <ChunkyTriMeshNode> resultNodes) { if (tris == IntPtr.Zero || resultNodes == null) { return(0); } int result = 0; int i = 0; while (i < mNodeCount) { ChunkyTriMeshNode node = mNodes[i]; bool overlap = node.Overlaps(xmin, zmin, xmax, zmax); bool isLeafNode = node.i >= 0; if (isLeafNode && overlap) { resultNodes.Add(node); result += node.count; } if (overlap || isLeafNode) { i++; } else { int escapeIndex = -node.i; i += escapeIndex; } } return(result); }
internal ChunkyTriMesh(Vector3[] verts , int vertCount , int[] tris , byte[] areas , int triCount , ChunkyTriMeshNode[] nodes , int nodeCount) { int size = sizeof(float) * vertCount * 3; this.verts = UtilEx.GetBuffer(size, false); float[] fverts = Vector3Util.Flatten(verts, vertCount); // Bleh. Marshal.Copy(fverts, 0, this.verts, vertCount * 3); size = sizeof(int) * tris.Length; this.tris = UtilEx.GetBuffer(size, false); Marshal.Copy(tris, 0, this.tris, tris.Length); size = sizeof(byte) * areas.Length; this.areas = UtilEx.GetBuffer(size, false); Marshal.Copy(areas, 0, this.areas, areas.Length); mTriCount = triCount; mVertCount = vertCount; mNodes = nodes; mNodeCount = nodeCount; }