Giter Site home page Giter Site logo

autolevel's Introduction

Auto-Level

Free procural level generator based on WFC algorithm for unity.

The target of this package is to create a procural level generator that is controllable, easy to use, and fast to some extent by leveraging the power of the WFC. WFC is a powerful algorithm in terms of procural generation. However, it does not give the user control over the generation process.

Features

  • Runtime WFC solver
  • Editor tools, build level inside the editor
  • Set the weight for individual Blocks or Block Group
  • Control the generation process, and constrain volume to groups of Blocks
  • Constrain boundary to a single group or another builder boundary
  • Ability to rebuild a given section of the level
  • Block variants and Block group variants
  • Big block support
  • Mesh builder that supports multiple materials input, with the ability to subdivide the level into chunks
  • fbx export
  • Child objects export

Complete C# source code is provided.

Usage

  • Create the Blocks Repo by clicking 'GameObject/AutoLevel/Blocks Repo'
  • Place Blocks under the Blocks Repo in the hierarchy. Make sure that the mesh is read/write enabled in the import settings, and the Blocks are in the range (0,0,0) (1,1,1), and their pivot is in the bottom back left corner.
  • Add the Block Asset component to the Blocks
  • Select a Block and start making connections in the scene view. Remember to change the editing mode to connection. After the connections are made, the Blocks Repo is ready to use

  • Create a Level Builder by clicking 'GameObject/AutoLevel/Builder'
  • Assign the Blocks Repo to the builder
  • Use the selection handle to set block groups over the level. The level inspector provides a toggle to switch between controlling the level or selection bounds. Bounds can be controlled via inspector or by using scene handles. Toggle between the different handles using w,r,t
  • Hit the rebuild button
  • Hit Export Mesh to export the result to fbx file

Keep in mind that the Building performance depends on two factors the size of the builder and the number of blocks produced by the repo. You can get better performance by only building where needed using multiple builders. Also, using constraints can reduce the building time significantly.

Runtime Example

using UnityEngine;
using AutoLevel;

public class RuntimeExample : MonoBehaviour
{
    [SerializeField]
    public BlocksRepo repo;
    [SerializeField]
    public BoundsInt bounds;

    private BlocksRepo.Runtime runtimeRepo;
    private LevelMeshBuilder meshBuilder;
    private LevelData levelData;
    private LevelSolver solver;

    private void OnEnable()
    {
        //generate blocks connections, variants and other configuration
        BlocksRepo.Runtime runtimeRepo = repo.CreateRuntime();

        //a container for the solver result
        levelData = new LevelData(bounds);
        meshBuilder = new LevelMeshBuilder(levelData, runtimeRepo);

        solver = new LevelSolver(bounds.size);
        solver.SetRepo(runtimeRepo);
        solver.SetlevelData(levelData);

        //set the bottom boundary
        solver.SetBoundary(
            new GroupsBoundary(runtimeRepo.GetGroupIndex(BlocksRepo.SOLID_GROUP)), Direction.Down);
    }

    private void OnDisable()
    {
        runtimeRepo.Dispose();
        meshBuilder.Dispose();
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
            Rebuild(bounds);
    }

    void Rebuild(BoundsInt bounds)
    {
        //run the solver, this will return the number of iteration it took,
        //0 means the solver has failed
        var iterations = solver.Solve(bounds);
        if (iterations > 0)
        {
            //rebuild the mesh if the solver success
            meshBuilder.Rebuild(bounds);
        }
    }
}

FILLING

When selecting a Block Asset, there is an option called filling in the scene view context menu dropdown. This will show handles to edit the block filling, red for empty and green for fill, similar to the marching cubes algorithm.

The filling has two roles. First, the connections will only be made to blocks with similar side patterns. Second, Level Builder can use that information to define the level rooms. The builder contains two built-in groups, the 'Empty' and 'Solid' groups, and you can use them to define the rooms and walls.

PERFORMACE

  • Regarding memory, reducing memory usage can be done by switching to a dictionary instead of arrays. This also helped with performance.
  • There is a considerable cost when using a block group. This cost has been reduced significantly by creating a lookup table for group interaction.

WHAT NEXT

  • Fine Block connection control
  • Multithredead solving

autolevel's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.