Ejemplo n.º 1
0
 public MeshJobData(int3 dimensions,
                    bool includeLighting,
                    NativeArray <VoxelTypeID> voxels,
                    NativeArray <RotatedVoxelEntry> rotatedVoxels,
                    NativeArray <LightValue> lights,
                    NeighbourData neighbourData,
                    NativeMeshDatabase meshDatabase,
                    NativeVoxelTypeDatabase voxelTypeDatabase,
                    Allocator allocator)
 {
     this.dimensions        = dimensions;
     this.includeLighting   = includeLighting;
     this.voxels            = voxels;
     this.rotatedVoxels     = rotatedVoxels;
     this.lights            = lights;
     this.neighbourData     = neighbourData;
     this.meshDatabase      = meshDatabase;
     this.voxelTypeDatabase = voxelTypeDatabase;
     vertices           = new NativeList <Vector3>(allocator);
     vertexColours      = new NativeList <Color>(allocator);
     uvs                = new NativeList <Vector3>(allocator);
     normals            = new NativeList <Vector3>(allocator);
     allTriangleIndices = new NativeList <int>(allocator);
     materialRuns       = new NativeList <MaterialRun>(allocator);
     collisionSubmesh   = new CollisionSubmeshDescriptor(allocator);
 }
Ejemplo n.º 2
0
        public static NeighbourData CacheNeighbourData(Vector3Int chunkId, IChunkManager chunkManager)
        {
            UnityEngine.Profiling.Profiler.BeginSample("CacheNeighbourData");

            NeighbourData neighbourData = new NeighbourData();

            for (int i = 0; i < DirectionExtensions.numDirections; i++)
            {
                var neighbourID = chunkId + DirectionExtensions.Vectors[i];
                try
                {
                    var neighbour   = chunkManager.GetReadOnlyChunkData(neighbourID);
                    var oppositeDir = DirectionExtensions.Opposite[i];
                    neighbourData.Add((Direction)i, neighbour.BorderToNative(oppositeDir));
                    neighbourData.Add((Direction)i, neighbour.BorderToNativeLight(oppositeDir));
                }
                catch (Exception e)
                {
                    var(managerHad, pipelinehad) = chunkManager.ContainsChunkID(chunkId);
                    string minStage = "";
                    string maxStage = "";
                    if (pipelinehad)
                    {
                        minStage = chunkManager.GetMinPipelineStageOfChunkByName(chunkId);
                        maxStage = chunkManager.GetMaxPipelineStageOfChunkByName(chunkId);
                    }
                    throw new Exception($"Failed to get neighbour data for chunk {chunkId}." +
                                        $"Manager had this chunk = {managerHad}, pipeline had it = {pipelinehad}." +
                                        $" Min pipeline stage {minStage}, max {maxStage} ." +
                                        $"Cause: {e.Message}", e);
                }
            }

            UnityEngine.Profiling.Profiler.EndSample();
            return(neighbourData);
        }
Ejemplo n.º 3
0
        public static LightValue GetLightValue(int3 pos, NativeArray <LightValue> lights, int3 dimensions, NeighbourData neighbourData)
        {
            neighbourData.AdjustLocalPos(ref pos, out var InChunk, out var DirectionOfNeighbour, dimensions);
            if (InChunk)
            {
                return(lights[Utils.Helpers.MultiIndexToFlat(pos.x, pos.y, pos.z, dimensions)]);
            }
            else
            {
                var localIndexInNeighbour = neighbourData.IndicesInNeighbour(DirectionOfNeighbour, pos);
                var neighbourDimensions   = neighbourData.IndicesInNeighbour(DirectionOfNeighbour, dimensions);

                var flattenedIndex = Utils.Helpers.MultiIndexToFlat(localIndexInNeighbour.x, localIndexInNeighbour.y, neighbourDimensions);

                var neighbourLightData = neighbourData.GetLightValues(DirectionOfNeighbour);
                return(neighbourLightData[flattenedIndex]);
            }
        }
Ejemplo n.º 4
0
        public static VoxelTypeID GetVoxel(int3 pos, NativeArray <VoxelTypeID> voxels, int3 dimensions, NeighbourData neighbourData)
        {
            neighbourData.AdjustLocalPos(ref pos, out var InChunk, out var DirectionOfNeighbour, dimensions);
            if (InChunk)
            {
                return(voxels[Utils.Helpers.MultiIndexToFlat(pos.x, pos.y, pos.z, dimensions)]);
            }
            else
            {
                var localIndexInNeighbour = neighbourData.IndicesInNeighbour(DirectionOfNeighbour, pos);
                var neighbourDimensions   = neighbourData.IndicesInNeighbour(DirectionOfNeighbour, dimensions);

                var flattenedIndex = Utils.Helpers.MultiIndexToFlat(localIndexInNeighbour.x, localIndexInNeighbour.y, neighbourDimensions);

                var neighbourVoxelData = neighbourData.GetVoxels(DirectionOfNeighbour);
                return(neighbourVoxelData[flattenedIndex]);
            }
        }