示例#1
0
    // This needs to be optimized
    public void PopulateTerrainMap()
    {
        int xOffSet = width * managerIndex.x;
        int yOffSet = height * managerIndex.y;
        int zOffSet = depth * managerIndex.z;

        Vector3Int  managerPosInt  = new Vector3Int((int)manager.transform.position.x, (int)manager.transform.position.y, (int)manager.transform.position.z);
        Vector3Int  CenterOfChunk  = new Vector3Int(width / 2 + xOffSet, height / 2 + yOffSet, depth / 2 + zOffSet);
        Vector3     chunkScale     = new Vector3(width + 1, height + 1, depth + 1);
        List <aabb> collidingCubes = new List <aabb>();

        foreach (aabb cube in manager.fillSpots)
        {
            if (cube.checkCollision(CenterOfChunk + managerPosInt, chunkScale))
            {
                collidingCubes.Add(cube);
            }
        }

        if (collidingCubes.Count <= 0)
        {
            return;
        }

        for (int x = 0; x < width + 1; x++)
        {
            for (int y = 0; y < height + 1; y++)
            {
                for (int z = 0; z < depth + 1; z++)
                {
                    if (terrainMap[x, y, z] == null)
                    {
                        terrainMap[x, y, z] = new FloatMyGuy(0.0f);
                    }
                    else
                    {
                        terrainMap[x, y, z].value = 0.0f;
                    }

                    Vector3Int vertPos = new Vector3Int(x + xOffSet, y + yOffSet, z + zOffSet);

                    foreach (aabb cube in collidingCubes)
                    {
                        if (cube.checkCollision(vertPos + managerPosInt))
                        {
                            terrainMap[x, y, z].value = -1f + (UnityEngine.Random.value * 0.75f);
                            break;
                        }
                        else
                        {
                            terrainMap[x, y, z].value = 1.0f;
                        }
                    }
                }
            }
        }
    }
示例#2
0
    public void CreateMesh(TerrainMan newManager, Vector3Int index, Vector3Int meshSize)
    {
        managerIndex = index;
        manager      = newManager;
        SetWidth(meshSize.x);
        SetHeight(meshSize.y);
        SetDepth(meshSize.z);

        terrainMap = new FloatMyGuy[width + 1, height + 1, depth + 1];
        for (int x = 0; x < width + 1; x++)
        {
            for (int y = 0; y < height + 1; y++)
            {
                for (int z = 0; z < depth + 1; z++)
                {
                    terrainMap[x, y, z] = new FloatMyGuy(1.0f);
                }
            }
        }
    }