Coder Social home page Coder Social logo

voxelfactory's Introduction

Voxel Factory ๐Ÿ“ฆ ๐Ÿญ

Voxel Factory is a simple Godot C# library that allows you to create voxel mesh easily using cubes. It handles the meshing for you and optimize it.

Usage

VoxelFactory can be used for anything in your project that needs procedural meshing. If you have a way to feed it some data. Then it will create the mesh no problem. You could use the library to create some voxel Items like in minecraft from pngs. You could feed it some chunk data so it will create the chunk mesh for you. If you want to create a procedural landscape using this library, you will need to handle the generation and multi-threading yourself.

Installation

Just import the source VoxelFactory.cs class to your project. Nuget package and dll coming soon. GDscript version coming soon.

Exemples

If you have an image that you would like to extrude in voxels, all you need is the path to your image.

 var VoxelFactory = new VoxelFactory();
 Mesh = VoxelFactory.CreateMeshFromIMG("res://New Piskel.png");

You can also add voxels manually like so:

var VoxelFactory = new VoxelFactory();

VoxelFactory.AddVoxel(0, 0, 0, new Color(1, 0, 0));
VoxelFactory.AddVoxel(0, 1, 0, new Color(0, 1, 0));
Mesh = VoxelFactory.CreateMesh();

If you have a sprite node that has a texture that you want to extrude.

 var VoxelFactory = new VoxelFactory();
 var mySpriteNode = (Sprite)GetNode("mySpriteNode");
 Mesh = VoxelFactory.CreateMeshFromSprite(mySpriteNode);

Documentation

Propreties

Type Name
Material DefaultMaterial
float VoxelSize

Methods

Return type Name
Mesh CreateMeshFromIMG
Mesh CreateMeshFromSprite
Mesh CreateMesh
void AddVoxel
void AddVoxels
void ClearVoxels

Propreties Descriptions

  • Default Material

The default material used on the mesh. By default, only the VertexColorUseAsAlbedois enabled. You can override this before create a mesh to use a custom material.

  • VoxelSize

The size of a voxel. Default is 1 unit.

Methods Descriptions

  • Mesh CreateMeshFromIMG(string path)

This will create a mesh from an image specified as path. For each pixel in the image, a voxel with the same color will be created. If the pixel is fully transparent, no voxel will be created.

  • Mesh CreateMeshFromSprite(Sprite node)

This will create a mesh from a Sprite node. It will use the sprite texture as an image.

  • void CreateMesh()

Create a Mesh from the current data in the VoxelFactory. Use this if you are adding Voxels manually.

  • void AddVoxel(int x, int y , int z, Color color, [bool overwrite = false])
  • void AddVoxel(Vector3 position, Color color)

Add a voxel at a specified position with a color to the VoxelFactory dataset. You can either use a Vector3 for the position or specify them one by one. You can specify if you want to overwrite if a voxel already exists at the position specified

  • void AddVoxels(Dictionary<Vector3, Color>, [bool overwrite = false])

Add a bunch of voxels all at once that are in a Dictionary with the position as the key, and the color as the value. You can specify if you want to overwrite if a voxel already exists at the position specified

  • void ClearVoxels()

Clears the dataset in the VoxelFactory

voxelfactory's People

Contributors

antopilo avatar

Watchers

 avatar

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.