コード例 #1
0
ファイル: BlockType.cs プロジェクト: JonRurka/VoxelTerrain
 public void SetScaledIndices(int length)
 {
     for (int i = 0; i < textureIndex.Length; i++)
     {
         ScaledIndex[i] = VoxelConversions.Scale(textureIndex[i], 0, length, 0, 1);
     }
 }
コード例 #2
0
    // Start is called before the first frame update
    void Start()
    {
        uint val = 0;

        uint loc     = 52428;
        uint type_P2 = 255 << 16;
        uint iso_p2  = (uint)VoxelConversions.Scale(Mathf.Clamp(2, -2, 2), -2, 2, byte.MinValue, byte.MaxValue) << 24;

        val  = loc;
        val |= type_P2;
        val |= iso_p2;



        byte[] us_b = System.BitConverter.GetBytes(val);

        Debug.Log(System.BitConverter.ToString(us_b));
    }
コード例 #3
0
    public void MarkSurfaceBlocks(GridPoint p1, GridPoint p2)
    {
        byte[] loc_bytes;

        if (p1.type == byte.MaxValue || p2.type == byte.MaxValue)
        {
            return;
        }

        ushort loc_p1 = (ushort)Get_Flat_Index(p1.OriginLocal.x, p1.OriginLocal.y, p1.OriginLocal.z);

        if (IsInBounds(p1.OriginLocal.x, p1.OriginLocal.y, p1.OriginLocal.z) && !Result.blocks_surface[loc_p1])
        {
            //Vector3 org =
            Vector3 other = new Vector3(p2.x, p2.y, p2.z);
            //UnityEngine.Debug.DrawLine(new Vector3(p1.x, p1.y, p1.z), other, UnityEngine.Color.red, 50000);
            byte type_P1 = (byte)p1.type;
            byte iso_p1  = (byte)VoxelConversions.Scale(Mathf.Clamp(p1.iso, -2, 2), -2, 2, byte.MinValue, byte.MaxValue);
            loc_bytes = BitConverter.GetBytes(loc_p1);
            Result.surfaceBlocks[Result.surfaceBlocksCount] = (BitConverter.ToUInt32(new byte[] { loc_bytes[0], loc_bytes[1], type_P1, iso_p1 }, 0));
            Result.blocks_surface[loc_p1] = true;
            Result.surfaceBlocksCount++;
        }



        ushort loc_p2 = (ushort)Get_Flat_Index(p2.OriginLocal.x, p2.OriginLocal.y, p2.OriginLocal.z);

        if (IsInBounds(p2.OriginLocal.x, p2.OriginLocal.y, p2.OriginLocal.z) && !Result.blocks_surface[loc_p2])
        {
            Vector3 other = new Vector3(p1.x, p1.y, p1.z);
            //UnityEngine.Debug.DrawLine(new Vector3(p2.x, p2.y, p2.z), other, UnityEngine.Color.red, 50000);
            byte type_P2 = (byte)p2.type;
            byte iso_p2  = (byte)VoxelConversions.Scale(Mathf.Clamp(p2.iso, -2, 2), -2, 2, byte.MinValue, byte.MaxValue);
            loc_bytes = BitConverter.GetBytes(loc_p2);
            Result.surfaceBlocks[Result.surfaceBlocksCount] = (BitConverter.ToUInt32(new byte[] { loc_bytes[0], loc_bytes[1], type_P2, iso_p2 }, 0));
            Result.blocks_surface[loc_p2] = true;
            Result.surfaceBlocksCount++;
        }
    }
コード例 #4
0
    public Vector3Int[][] GetChunkLocationsAroundPoint(int threads, int radius, Vector3Int center)
    {
        Vector3Int[][] result = new Vector3Int[0][];
        try
        {
            List <List <Vector3Int> > chunksInSphere = new List <List <Vector3Int> >();
            if (radius > 0)
            {
                List <Vector3Int> counted = new List <Vector3Int>();
                for (int i = 0; i < threads; i++)
                {
                    chunksInSphere.Add(new List <Vector3Int>());
                }
                int threadIndex   = 0;
                int circumference = (int)((2 * Mathf.PI * radius) + 1) / 2;
                for (int i = 0; i <= circumference; i++)
                {
                    float angle = VoxelConversions.Scale(i, 0, circumference, 0, 360);
                    int   x     = (int)(center.x + radius * Mathf.Cos(angle * (Mathf.PI / 180)));
                    int   z     = (int)(center.z + radius * Mathf.Sin(angle * (Mathf.PI / 180)));

                    for (int y = -SmoothVoxelSettings.maxChunksY / 2; y < SmoothVoxelSettings.maxChunksY / 2; y++)
                    {
                        Vector3Int[] positions = new Vector3Int[] {
                            new Vector3Int(x, y, z),
                            new Vector3Int(x + 1, y, z),
                            new Vector3Int(x - 1, y, z),
                            new Vector3Int(x, y, z + 1),
                            new Vector3Int(x, y, z - 1),
                            new Vector3Int(x - 1, y, z - 1),
                            new Vector3Int(x + 1, y, z - 1),
                            new Vector3Int(x + 1, y, z + 1),
                            new Vector3Int(x - 1, y, z + 1),
                        };
                        if (threadIndex >= threads)
                        {
                            threadIndex = 0;
                        }
                        for (int posIndex = 0; posIndex < positions.Length; posIndex++)
                        {
                            if (!BuilderExists(positions[posIndex].x, positions[posIndex].y, positions[posIndex].z) && !counted.Contains(positions[posIndex]))
                            {
                                chunksInSphere[threadIndex].Add(positions[posIndex]);
                                counted.Add(positions[posIndex]);
                            }
                        }
                        threadIndex++;
                    }
                }
            }
            else
            {
                chunksInSphere.Add(new List <Vector3Int>());
                chunksInSphere[0].Add(center);
            }

            result = new Vector3Int[chunksInSphere.Count][];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = chunksInSphere[i].ToArray();
            }
        }
        catch (Exception e)
        {
            SafeDebug.LogError(string.Format("{0}", e.Message));
        }
        return(result);
    }