// Called when the game starts or when spawned void AGridV1::BeginPlay() { Super::BeginPlay(); int32 HalfX = GridSize.X / 2; int32 HalfY = GridSize.Y / 2; int32 HalfZ = GridSize.Z / 2; FActorSpawnParameters param; param.Owner = this; for (int32 x = -HalfX; x < HalfX; x++) { for (int32 y = -HalfY; y < HalfY; y++) { for (int32 z = -HalfZ; z < HalfZ; z++) { ACellV1* cell = GetWorld()->SpawnActor<ACellV1>(FVector(x, y, z) * VoxelSize * CellSize, FRotator(), param); cell->GridPosition = FInt3(x, y, z); cell->Grid = this; cell->FutureData = Async<TMap<FInt3, uint16>>(EAsyncExecution::ThreadPool, []() { TMap<FInt3, uint16> ret; for (int32 i = 0; i < 32; i++) for (int32 j = 0; j < 32; j++) for (int32 k = 0; k < 32; k++) ret.Add(FInt3(i, j, k), 1); return ret; }); cell->OngoingLoading = true; cell->Mesh->SetMaterial(0, Material); Data.Add(FInt3(x, y, z), cell); } } } }
return (FInt3::Scalar(BrickVertexIndex) >> FInt3(2,1,0)) & FInt3::Scalar(1); } // Maps face index and face vertex index to brick corner indices. static const uint8 FaceVertices[6][4] = { { 2, 3, 1, 0 }, // -X { 4, 5, 7, 6 }, // +X { 0, 1, 5, 4 }, // -Y { 6, 7, 3, 2 }, // +Y { 4, 6, 2, 0 }, // -Z { 1, 3, 7, 5 } // +Z }; // Maps face index to normal. static const FInt3 FaceNormals[6] = { FInt3(-1, 0, 0), FInt3(+1, 0, 0), FInt3(0, -1, 0), FInt3(0, +1, 0), FInt3(0, 0, -1), FInt3(0, 0, +1) }; /** An element of the vertex buffer given to the GPU by the CPU brick tessellator. 8-bit coordinates are used for efficiency. */ struct FBrickVertex { uint8 X; uint8 Y; uint8 Z; uint8 AmbientOcclusionFactor;