Jump to content
  • Advertisement
Sign in to follow this  
Ovicior

Unity How Does One Program A Voxel Editor?

This topic is 1003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,

Interested in learning a bit more coding, specifically on voxels. How does one program a voxel editor? One that is capable of placing voxels in a 3D space, changing the colors of the voxels, and later exporting the models? This is a really basic editor, but I'd like to learn a bit more past Unity. Has anyone done this before in C# ? How did you do it? Any guides you're aware of?

Thanks,

Ovi

Share this post


Link to post
Share on other sites
Advertisement


How does one program a voxel editor?

It is data. Creating an editor for your data is going to be whatever it means to you.

 

Minecraft could be thought of as a giant voxel editor, for appropriate data.

 

Text editors could be a voxel editor, for appropriate data.

 

A movie editor could be a voxel editor, for appropriate data.

 

A collection of stacked images edited with your favorite image editor could be a voxel editor, for appropriate data.

 

 

 

Without knowing a lot more details about your project and your data it is going to be difficult to come up with a good answer.  If you can edit the data in a way that works for you, that is the thing.

Share this post


Link to post
Share on other sites

You may want to start in 2D, eg making a rectangle editor at a plain canvas in a GUI toolkit.

Many GUI programming tutorials have a "draw simple geometry stuff at a window and interact with the mouse" at some point.

 

The standard pattern is the MVC (model view controller) pattern, but that is fairly abstract.

Share this post


Link to post
Share on other sites
It really depends on how you intend to use voxels.

If you plan to use them as model parts like in C&C tiberian sun, that's different (due to the sheer number of voxels involved) to programmatically generating voxel landscape a la minecraft.

In either form I would consider a voxel model to be a simple sparse three dimensional array of simple six sided cubes. In the case of tiberian sun these cubes were all single colour but could be affected by simple 2d lighting effects and sometimes modified by explosions and damage.

hvabuilder21.png

Rendering these can be expensive unless you use instancing and other graphical tricks (these weren't available back when TS was created).

Let me know if this helps at all!

Share this post


Link to post
Share on other sites

It should be noted that voxel animations can be kind of flaky if you expect to do lots of animation. Usually models that require animation are done as 3d models, even if they appear similar to voxels.

Share this post


Link to post
Share on other sites


How does one program a voxel editor?

 

1. You'll need to get familiar with one of spatial partitioning structures - bsp/octree/kd-tree/etc.

2. You'll need box-ray intersection function.

With that you already can edit something, drawing all voxels/boxes without further checks.

Then you'll need:

3. Box-frustum test to quickly select parts of scene that is visible.

 

Start with that bare minimum.

Share this post


Link to post
Share on other sites

I'm interested in creating something like MagicaVoxel, for the sole purpose of learning more about voxels.

I'm not sure what spatial partitioning structures are.

I also have not created a voxel renderer, or any renderer at all.

This is overwhelming o_O

Share this post


Link to post
Share on other sites
Create the voxel renderer first. That'll help you learn more about voxels. The editor will be essentially your renderer plus a bunch of UI and UX related stuff that has very, very little to do with actual voxels. After writing the voxel renderer, you may find that another voxel editor suits your purposes well, thus saving you the actual effort of writing your own editor.

Share this post


Link to post
Share on other sites

I'm interested in creating something like MagicaVoxel, for the sole purpose of learning more about voxels.
I'm not sure what spatial partitioning structures are.
I also have not created a voxel renderer, or any renderer at all.
This is overwhelming o_O

Looking up octrees would give you a good idea of what spatial partitioning is, all the examples listed basically all go down to the same thing, they're a data format for dividing up logical objects in a 3d space in order to work with them more efficiently and avoid comparisons, sort of like putting information about them into big grouped bins.

A renderer is just something that takes vertices(and other data) and draws things, a voxel renderer is just a renderer that is working with voxels on the back end. If I want to draw a line of five voxels that are supposed to be a model for a game(ignoring optimization) you're basically just going to have some representation of those five cubes in memory, and use that to render 5 boxes. When you export the data you'd just be exporting the data structure that represents the boxes. You know the voxels are uniform size and shape so you don't need to keep information about each one and their position relative to each other in vertices or anything, you could just represent one spot being filled at a voxel, then a spot adjacent to it, or whatever. Basically you don't need all that fancy information like what triangles form each cube and all that stuff, since you can figure it out mathematically.

Using minecraft as an example, they implemented a model format now I believe, so you'd write code that can import and export that data, and have some kind of representation in memory, then set up your UI and rendering to let you view the placed voxels and to work with them. It isn't fundamentally different from a model editor, just less detail required. Edited by Satharis

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!