Beispiel #1
0
    public void Initialize(World world, int chunkSize, Vector3Int position)
    {
        this.chunkSize = chunkSize;
        this.position  = position;
        _isolevel      = world.isolevel;

        _densityGenerator = world.densityGenerator;

        int worldPosX = position.x;
        int worldPosY = position.y - 300;
        int worldPosZ = position.z;

        points = new Point[chunkSize + 1, chunkSize + 1, chunkSize + 1];

        _seed          = world.seed;
        _marchingCubes = new MarchingCubes(points, _isolevel, _seed);

        for (int x = 0; x < points.GetLength(0); x++)
        {
            for (int y = 0; y < points.GetLength(1); y++)
            {
                for (int z = 0; z < points.GetLength(2); z++)
                {
                    points[x, y, z] = new Point(
                        new Vector3Int(x, y, z),
                        _densityGenerator.CalculateDensity(x + worldPosX, y + worldPosY, z + worldPosZ)
                        );
                }
            }
        }
    }
    DensityGenerator CreateChunk(Vector3Int newPosition)
    {
        GameObject       newObject = Instantiate(prefab) as GameObject;
        DensityGenerator chunk     = newObject.GetComponent <DensityGenerator>();

        chunk.Seed          = Seed;
        chunk.Surface       = Surface;
        chunk.ChunkSize     = ChunkSize;
        chunk.ChunkPosition = newPosition;
        return(chunk);
    }
Beispiel #3
0
    private void Start()
    {
        boundaryLength = asteroidGeneration.worldLength * chunkSize;
        boundaryWidth  = asteroidGeneration.worldWidth * chunkSize;
        boundaryHeight = asteroidGeneration.worldHeight * chunkSize;

        asteroidData = asteroidGeneration.GenerateAsteroidData(asteroidTypeID, boundaryLength, boundaryWidth, boundaryHeight);

        thisAsteroid = new GameObject("Asteroid " + asteroidGeneration.seed.ToString());

        densityGenerator = new DensityGenerator(asteroidGeneration.seed);

        worldBounds = new Bounds();
        UpdateBounds();

        chunks = new Dictionary <Vector3Int, Chunk>(asteroidGeneration.worldWidth * asteroidGeneration.worldHeight * asteroidGeneration.worldLength);
        CreateChunks();

        PassVoxelsToShader();
    }
Beispiel #4
0
 private void Awake()
 {
     densityGenerator = new DensityGenerator(seed);
 }
Beispiel #5
0
    public override void _Ready()
    {
        GD.Print("Ready to create world!");

        if (densityGeneratorPath == null)
        {
            GD.PushError("VoxelTerrain must have a Density Generator.");
            return;
        }

        densityGenerator = GetNode <DensityGenerator>(densityGeneratorPath);
        if (densityGenerator == null)
        {
            GD.PushError("VoxelTerrain could not locate the supplied Density Generator.");
            return;
        }

        if (observerPath == null)
        {
            GD.PushError("VoxelTerrain must have an observer.");
            return;
        }

        observer = GetNode <Spatial>(observerPath);
        if (observer == null)
        {
            GD.PushError("VoxelTerrain could not locate the supplied observer.");
            return;
        }

        if (!(observer is Camera))
        {
            observer = (Camera)observer.FindNode("Camera");
        }

        if (debugLabelPath != null)
        {
            debugLabel = GetNode <Label>(debugLabelPath);
        }

        for (int y = -5; y < 5; y++)
        {
            for (int z = -5; z <= 5; z++)
            {
                for (int x = -5; x <= 5; x++)
                {
                    var at    = new ChunkPosition(x, y, z);
                    var chunk = new Chunk(at);
                    AddChunk(chunk);

                    var instance = new ChunkInstance(chunk)
                    {
                        MaterialOverride = material
                    };

                    chunk.InitDensity(densityGenerator.GetDensity);
                    AddChild(instance);
                }
            }
        }

        var origoChunk = chunks[new ChunkPosition(0, 0, 0)];

        origoChunk.GetLuminance().Init();
        origoChunk.ForEachChunk(chunk => chunk.TriangulateChunk());

        SetPhysicsProcess(true);
    }
Beispiel #6
0
    public void Initialize(World world, int chunkSize, Vector3Int position)
    {
        asteroidGeneration = world.gameObject.GetComponent <AsteroidGeneration>();

        this.chunkSize = chunkSize;
        this.position  = position;
        _isolevel      = world.isolevel;

        _densityGenerator = world.densityGenerator;

        int worldPosX = position.x;
        int worldPosY = position.y;
        int worldPosZ = position.z;

        midLength = chunkSize * asteroidGeneration.worldLength / 2;
        midWidth  = chunkSize * asteroidGeneration.worldWidth / 2;
        midHeight = chunkSize * asteroidGeneration.worldHeight / 2;

        points = new VoxelPoint[chunkSize + 1, chunkSize + 1, chunkSize + 1];

        asteroidGeneration = world.asteroidGeneration;
        _seed          = asteroidGeneration.seed;
        _marchingCubes = new MarchingCubes(points, _isolevel, _seed);

        var asteroidLength = asteroidGeneration.radius * 2;
        var asteroidWidth  = asteroidGeneration.radius * 2;
        var asteroidHeight = asteroidGeneration.radius * 2;

        // Fill array with density and material ID of 0
        for (int x = 0; x < points.GetLength(0); x++)
        {
            for (int y = 0; y < points.GetLength(1); y++)
            {
                for (int z = 0; z < points.GetLength(2); z++)
                {
                    points[x, y, z] = new VoxelPoint(
                        new Vector3Int(x, y, z),
                        0.0f,
                        0
                        );
                }
            }
        }

        for (int x = 0; x < points.GetLength(0); x++)
        {
            for (int y = 0; y < points.GetLength(1); y++)
            {
                for (int z = 0; z < points.GetLength(2); z++)
                {
                    int currX = x + worldPosX;
                    int currY = y + worldPosY;
                    int currZ = z + worldPosZ;

                    float density = GetVoxelDensity(world.asteroidData, currX, currY, currZ);
                    SetDensity(density, x, y, z);

                    int material = GetVoxelMaterial(world.asteroidData, currX, currY, currZ);
                    SetMaterial(material, x, y, z);
                }
            }
        }
    }
Beispiel #7
0
 public void UpdateAfterReload(World world)
 {
     _densityGenerator = world.densityGenerator;
     _marchingCubes    = new MarchingCubes(world, points, world.seed);
 }
Beispiel #8
0
 public void OnEnable()
 {
     CSTarget = (DensityGenerator)target;
 }