void VisibleIn(int index) { var chunk = this.Chunks[index]; var chunkEntityCount = chunk.Count; var chunkVisibleCount = 0; var chunkLODs = chunk.GetNativeArray(this.MeshLODComponentType); var hasMeshLODComponentType = chunkLODs.Length > 0; float4x4 *dstPtr = this.GetVisibleOutputBuffer(chunk); float4x4 *srcPtr = this.GetLocalToWorldSourceBuffer(chunk); if (srcPtr == null) { return; } var chunkVisibleLocalToWorld = chunk.GetNativeArray(this.VisibleIndexType); if (!hasMeshLODComponentType) { for (int i = 0; i < chunkEntityCount; i++) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount + i, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount + i] = new VisibleIndex { Value = i }; } chunkVisibleCount = chunkEntityCount; } else { for (int i = 0; i < chunkEntityCount; i++) { var instanceLOD = chunkLODs[i]; var instanceLODValid = (this.ActiveLODGroupMask[instanceLOD.Group].LODMask & instanceLOD.LODMask) != 0; if (instanceLODValid) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount] = new VisibleIndex { Value = i }; chunkVisibleCount++; } } } this.ChunkVisibleCount[index] = chunkVisibleCount; }
void VisiblePartial(int index) { var chunk = this.Chunks[index]; var chunkEntityCount = chunk.Count; var chunkVisibleCount = 0; var chunkLODs = chunk.GetNativeArray(this.MeshLODComponentType); var chunkBounds = chunk.GetNativeArray(this.WorldRenderBoundsType); var hasMeshLODComponentType = chunkLODs.Length > 0; var hasWorldRenderBounds = chunkBounds.Length > 0; var chunkVisibleLocalToWorld = chunk.GetNativeArray(this.VisibleIndexType); float4x4 *dstPtr = this.GetVisibleOutputBuffer(chunk); float4x4 *srcPtr = this.GetLocalToWorldSourceBuffer(chunk); if (srcPtr == null) { return; } // 00 (-WorldRenderBounds -MeshLODComponentType) if ((!hasWorldRenderBounds) && (!hasMeshLODComponentType)) { for (int i = 0; i < chunkEntityCount; i++) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount + i, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount + i] = new VisibleIndex { Value = i }; } chunkVisibleCount = chunkEntityCount; } // 01 (-WorldRenderBounds +MeshLODComponentType) else if ((!hasWorldRenderBounds) && (hasMeshLODComponentType)) { for (int i = 0; i < chunkEntityCount; i++) { var instanceLOD = chunkLODs[i]; var instanceLODValid = (this.ActiveLODGroupMask[instanceLOD.Group].LODMask & instanceLOD.LODMask) != 0; if (instanceLODValid) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount] = new VisibleIndex { Value = i }; chunkVisibleCount++; } } } // 10 (+WorldRenderBounds -MeshLODComponentType) else if ((hasWorldRenderBounds) && (!hasMeshLODComponentType)) { for (int i = 0; i < chunkEntityCount; i++) { var instanceBounds = chunkBounds[i]; var instanceCullValid = (FrustumPlanes.Intersect(this.Planes, instanceBounds.Value) != FrustumPlanes.IntersectResult.Out); if (instanceCullValid) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount] = new VisibleIndex { Value = i }; chunkVisibleCount++; } } } // 11 (+WorldRenderBounds +MeshLODComponentType) else { for (int i = 0; i < chunkEntityCount; i++) { var instanceLOD = chunkLODs[i]; var instanceLODValid = (this.ActiveLODGroupMask[instanceLOD.Group].LODMask & instanceLOD.LODMask) != 0; if (instanceLODValid) { var instanceBounds = chunkBounds[i]; var instanceCullValid = (FrustumPlanes.Intersect(this.Planes, instanceBounds.Value) != FrustumPlanes.IntersectResult.Out); if (instanceCullValid) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount] = new VisibleIndex { Value = i }; chunkVisibleCount++; } } } } this.ChunkVisibleCount[index] = chunkVisibleCount; }