Search Unity

PicaVoxel

Discussion in 'Assets and Asset Store' started by GarethIW, Feb 19, 2015.

  1. UnbreakableOne

    UnbreakableOne

    Joined:
    Nov 16, 2013
    Posts:
    168
    Hi,

    How can I fill an empty Volume from code? As your SHMUP sample, I've made one Volume in the editor, deleted all it's voxels and passed it to my script:


    Code (csharp):
    1.  
    2.        void Start ()
    3.        {
    4.             //v = gameObject.AddComponent<Volume>();
    5.             //v.AddFrame(0);
    6.          
    7.             //v.MeshingMode = MeshingMode.Culled; // Apparently it's better for pcg
    8.  
    9.             //v.Frames[0].Voxels = new Voxel[100];
    10.  
    11.             //volume.Frames[0].Voxels = new Voxel[X_TILES * Y_TILES * Z_TILES];
    12.             volume.Frames[0].Voxels = new Voxel[volume.XSize * volume.YSize * volume.ZSize];
    13.  
    14.             for (int x = 0; x < volume.XSize; x++)
    15.             {
    16.                 for (int y = 0; y < volume.YSize; y++)
    17.                 {
    18.                     for (int z = 0; z < volume.ZSize; z++)
    19.                     {
    20.                         volume.Frames[0].Voxels[x + y + z] = new Voxel()
    21.                         {
    22.                             State = VoxelState.Active,
    23.                             Color = Color.green,
    24.                             Value = 1
    25.                         };
    26.                     }
    27.                 }
    28.                 //volume.UpdateAllChunks();
    29.             }
    30.  
    31.  
    32.  
    33.             volume.UpdateAllChunks();
    34.  
    35.          
    36.        }
    37.  
    But when I run this, only a couple of voxels are generated in the Volume and if I put break points to examine, it crashes and Unity says a mesh can not have more than 65k vertices. I think it has something to do with chunks (as they are a mean to overcome this, IIRC) but can't find out how.
     
  2. GarethIW

    GarethIW

    Joined:
    Jun 24, 2014
    Posts:
    50
    Hi, I believe you may have emailed me about this over the weekend and I replied to it (apologies if not - I received an email with this exact same question).

    First, either have a PicaVoxel volume already in the scene to generate into, or create a prefab from a Volume which you would then instantiate.

    Once you have a volume ready, you can then make it the correct size and add your voxels to it. Here is all the code you need:

    https://gist.github.com/GarethIW/2740ee670dc7085aa926fbd6f354dfd9
     
  3. UnbreakableOne

    UnbreakableOne

    Joined:
    Nov 16, 2013
    Posts:
    168
    Thanks. Reading the gist.

    1) In the edit mode of a volume, if I remove all voxels from a mesh, is there anyway to add one?

    2) Also in the edit mode of a volume, does new voxels you want to draw/add should be attached to a previous one? Like can you put one in the sky?

    3) How can I detect collision on my voxels?

    4) I find a couple methods that you call when you change or create a volume namely "CreateChunks", UpdateAllChunks, UpdateAllChunksNextFrame, SaveForSerialize, among others. What are their differences and where should we call each of them?

    5) Should I be concerned with chunks when making volumes procedurally?

    6) In the SHMUP sample, why did you create an array of volumes? Performance? Why not a big volume instead of a 2D array of small volumes? I thought point of voxels is to overcome doing these.

    7) Why traversing the inner array of a volume as [x + y + z] won't work and I have to do it as you do: "x + voxelVolume.XSize * (y + voxelVolume.YSize * z)" ? I suspect it's for inside mechanism of chunks but am interested to know why.

    (I have a couple more questions actually but I think asking them in "chunks" is better!)
     
  4. GarethIW

    GarethIW

    Joined:
    Jun 24, 2014
    Posts:
    50
    1) In the edit mode of a volume, if I remove all voxels from a mesh, is there anyway to add one?
    2) Also in the edit mode of a volume, does new voxels you want to draw/add should be attached to a previous one? Like can you put one in the sky?

    Answering these two at the same time. The PicaVoxel editing tools were based on MagicaVoxel's tools. When I first started PicaVoxel, Magica was very rudimentary but it quickly became an incredibly powerful voxel art creation tool that I could never hope to keep up with in terms of functionality. PicaVoxel has always been more about what you do with the voxels than it is about creating them, so now I always recommend that users create their models using Magica or Qubicle and import them with PicaVoxel. You can then use the PV editing tools for last-minute touches or game-specific edits.

    To answer the questions: 1) No, but you can create a Base-Only volume which only has the "bottom" layer of voxels filled. 2) Yes, you add voxels by attaching them to existing ones as opposed to painting directly into a grid.

    3) How can I detect collision on my voxels?

    This is a big topic. Firstly, there is nothing special about objects created by PicaVoxel - they are standard Unity GameObjects. That means you can use box / sphere colliders to detect collisions with and between entire objects. You can use MeshColliders (which PicaVoxel can attach for you if you choose), although you need to watch out for performance especially if you are altering the voxels at runtime.

    What I imagine you're wondering though is how you can do per-voxel collision. I include a CollisionDetector script to help with this. You can see an example of using it in the Invaders demo (look at the Bullet script). You can do it manually. There's an example of that in the RPG demo on the RPGCharacterController script.

    Collision detection would be entirely dependent on the game you are making though. It is often best to use a mixture of Unity physics and per-voxel collision (raycasting/collision events for gaemobject collision, then a per-voxel check on the resulting volume).

    4) I find a couple methods that you call when you change or create a volume namely "CreateChunks", UpdateAllChunks, UpdateAllChunksNextFrame, SaveForSerialize, among others. What are their differences and where should we call each of them?

    • CreateChunks(): Splits a volume up into chunks and creates the hierarchy of gameobjects needed to contain the volume. This should only be called if you are changing the size of a volume at runtime.
    • UpdateChunks(): Updates *only* chunks that have been changed since the last time this method was called (usually every frame).
    • UpdateAllChunks(): Immediately generate meshes for all chunks on a volume. Should only be called at runtime if you have added/removed/recolored voxels across the entire volume.
    • UpdateAllChunksNextFrame(): The same as above, but threaded. Will rebuild all of the chunks of a volume over subsequent frames.
    • SaveForSerialize(): Not really to do with generation; this serializes the voxel data into a byte array so Unity can store it. Not used at runtime.

    5) Should I be concerned with chunks when making volumes procedurally?

    No. PicaVoxel takes care of chunking for you.

    6) In the SHMUP sample, why did you create an array of volumes? Performance? Why not a big volume instead of a 2D array of small volumes? I thought point of voxels is to overcome doing these.

    Because the Shmup sample is essentially a tile engine as well as a procedural generation demo. The playfield is split up into tiles (one volume per tile) like a 2D tile engine, and when the tiles disappear off of the left of the playfield, they are moved to the right (all off-screen), and then the landscape is generated into those tiles by copying from a source volume (which acts as a tilesheet of sorts), and also by procedurally generating the cliffs at the top and bottom of the screen.

    Performance-wise, it is faster to generate smaller meshes. So breaking up the entire playfield into tiled volumes also helps in that way.

    7) Why traversing the inner array of a volume as [x + y + z] won't work and I have to do it as you do: "x + voxelVolume.XSize * (y + voxelVolume.YSize * z)" ? I suspect it's for inside mechanism of chunks but am interested to know why.

    A 3D array would normally be indexed as [x,y,z]. While syntactically nice, 3D arrays are (performace-wise) slower to access than 1D arrays. So we take the 3D array and lay it out into a 1D array. The algorithm above is how you address the 3D space contained in the 1D array. Simple.
     
  5. Icezman

    Icezman

    Joined:
    Mar 31, 2017
    Posts:
    7
    Hello!
    I've recently bought the PicaVoxel pack!
    Really great and i'm eagerly getting to know how it works!
    1 issue though! When playing around and when it collides or brakes blocks, almost always it suddenly turns off the lights? Is that only in the editor that it happens and is it normal.?
     
  6. Atomhax

    Atomhax

    Joined:
    Dec 31, 2014
    Posts:
    3
    Old thread but I'm really loving the Demos you included in this asset. I purchased this a few years ago on a whim and recently redownloaded it.
     
  7. GarethIW

    GarethIW

    Joined:
    Jun 24, 2014
    Posts:
    50
    After five fantastic years on the Asset Store and with great sadness, I've decided to deprecate PicaVoxel.

    PicaVoxel always included full source code, so if you've purchased any of the iterations of PicaVoxel over the years, you will still be able to download the asset and update/improve it yourself!

    Due to life commitments, I can no longer keep up with the cadence of updates on the Unity Editor. I recently discovered that my support for the new Prefab workflow (in 2019.1) isn't quite where it needs to be and probably needs a fair bit of work to get it there. I can no longer spare the kind of time needed. And quite frankly, I haven't used the new prefab workflow enough to even understand how it should work!

    There are also a lot of changes coming to unity (SRP, DOTS, ECS, completely new editor) that mean that PicaVoxel needs to become something else entirely really.

    It's been an absolute blast helping you folks make awesome games with PicaVoxel.

    I'm also considering making PicaVoxel available to all as open-source on a Github repo. I won't have the time to manage this myself, but if you're interested in managing an open-source version of PicaVoxel going forward please let me know (support@picavoxel.com)
     
    Last edited: Feb 11, 2020
    tcmeric likes this.
  8. StevenPicard

    StevenPicard

    Joined:
    Mar 7, 2016
    Posts:
    859
    Making the source code available on GitHub would be great. I'm sure many people could make great use of it.
     
  9. Arjun-Gupte

    Arjun-Gupte

    Joined:
    May 31, 2013
    Posts:
    54
    We are getting this error whenever we adding/deleting blocks in runtime , and that to happening on particular iPad version

    Mesh.colors is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array. PicaVoxel.Chunk:SetMesh() PicaVoxel.Chunk:Update()
    [11:17]
    Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array. PicaVoxel.Chunk:SetMesh() PicaVoxel.Chunk:Update()
    [11:18]
    Failed setting triangles. The number of supplied triangle indices must be a multiple of 3. PicaVoxel.Chunk:SetMesh() PicaVoxel.Chunk:Update()
     
    killer1171090 likes this.
  10. killer1171090

    killer1171090

    Joined:
    Feb 23, 2013
    Posts:
    145
    Same issue here, Happening in Windows
     
    Last edited: Aug 15, 2020
  11. Atomhax

    Atomhax

    Joined:
    Dec 31, 2014
    Posts:
    3
    I hope eventually you make a return. I'm so glad I bought this on a whim years ago.
     
  12. arcadian-taha

    arcadian-taha

    Joined:
    Oct 13, 2020
    Posts:
    1
    Hope we will see you back. It will be nice if we get Git Repo link.
     
  13. modgle

    modgle

    Joined:
    Sep 24, 2019
    Posts:
    3
    @GarethIW

    Agree! It's a shame that such an awesome asset is no longer available. However maybe there is a way to get the latest updated version? I can still pay for it since there is no repo on GitHub or anywhere else.
     
  14. Dr_D

    Dr_D

    Joined:
    Mar 21, 2014
    Posts:
    13
    Hey guys. I know this library is deprecated, but we're using an older version of Unity so we can use it in our project. I have a question about the MeshStore folder within Pica. Can I delete it? I'm creating a repository for our project, but as of this post, the project folder is 700 MB, and the vast majority of that is within the MeshStore folder. Thanks!
     
  15. GarethIW

    GarethIW

    Joined:
    Jun 24, 2014
    Posts:
    50
  16. GarethIW

    GarethIW

    Joined:
    Jun 24, 2014
    Posts:
    50
    You can delete MeshStore safely, but you will need to go through all of your scenes and prefabs and select each volume in turn so that it rebuilds its mesh.

    You could look into using runtime-only meshes as an alternative, but they have an generation overhead at runtime.
     
  17. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Thank you for open-sourcing this great plugin! If we use this plugin in our commercial projects, since the plugin is licensed under GPL-3.0, are we supposed to disclose the project's source code under GPL-3.0 license, as well? I think that would prevent majority of commercial projects from using the plugin.
     
  18. GarethIW

    GarethIW

    Joined:
    Jun 24, 2014
    Posts:
    50
    Sorry, I'm not very good at this. I've swapped GNU out for MIT, which seems far more permissive.
     
    yasirkula likes this.
  19. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,878
    Awesome, thank you very much! One suggestion: putting a few screenshots to the README would make the repository much more attractive to the visitors who haven't heard of PicaVoxel before.
     
    Last edited: Mar 10, 2021
  20. Mal_Duffin

    Mal_Duffin

    Joined:
    Jan 22, 2015
    Posts:
    71
    We are looking about to look at PicaVoxel as a potential tool to use in an upcoming prototype.

    Has anyone had any issues running it with the latest version of Unity? Not using URP etc, but that would be cool if someone did try that and got it working! I just tried it with Unity 2021.1, and some of the demos work better than others - - I'll go back to an older version of Unity during the week.

    What's the earliest version of Unity that someone has gone back to, where PicaVoxel works for their project?

    We're looking forward to getting time to checking out PicaVoxel and other solutions that allow us to have exploding voxels!
     
  21. Mal_Duffin

    Mal_Duffin

    Joined:
    Jan 22, 2015
    Posts:
    71
    For anyone using PicaVoxel with a recent version of Unity, and wanting to use URP rendering, you may have noticed duplicate items not showing up.

    Here is a quick fix - we didn't have time to dig into the root cause of why this was breaking it, but it might help you out of the same spot we were in. If you figure out a better solution, feel free to post to help everyone out!

    In Assets/PicaVoxel/PicaVoxel/Scripts, change Frame.cs to...

    upload_2021-6-14_15-9-0.png

    This is the twitter feed of the game we are currently working on, using PicaVoxel and URP. We are also using MagicaVoxel for creating the 3D models.

    https://twitter.com/voxelbrawler
     

    Attached Files: