Converting between static and runtime mesh

0
sbat posted this 18 November 2015

In my project almost all voxel objects are static/non-animated. Besides most of them are square floor tiles, so they are highly optimizeable meshes.

But one (or only few) of them will be changed at runtime programmatically (gradually "evaporated" voxel by voxel, tile after tile as player "runs").

Do I understand right that in that case it is best to create two copies of the same volume:

  • Mesh-Only Copy volume
  • Normal volume

and dynamically replace static volume with dynamic one in a script, when time comes for evaporation?

Maybe there's built-in way to do that at runtime? Or - just maybe - such optimization already works automatically for all volumes (i.e. they are represented as optimized meshes, until I programmatically touch at least one voxel)?

3 Comments
Order By: Standard | Newest | Votes
1
GarethIW posted this 18 November 2015

The Mesh-Only conversion is one-way only - it simply generates a mesh from the voxel data, stores the mesh and then creates gameobjects that have ONLY the meshrenderer/meshfilter on them. You don't get any voxel data stored or any of the PicaVoxel scripts on them so you can't switch them back to being voxel objects.

In PicaVoxel's case, what I mean by "optimized" in the context of a mesh is that the mesh is generated using the Greedy algorithm. So the normal PicaVoxel objects already have optimized meshes. Converting them to Mesh-Only does not do any further mesh optimization. The main overhead of a PicaVoxel volume is the voxel data, so more RAM will be used.

Hope that helps!

0
sbat posted this 18 November 2015

In PicaVoxel's case, what I mean by "optimized" in the context of a mesh is that the mesh is generated using the Greedy algorithm.

This indeed helps, thx!

Just to double check:

  • If I programmatically change several voxels in a volume, greedy algorithm will run again on this frame and adjust the mesh? Will this run only once per frame, if I touched 20 voxels in a loop?
  • If I have 100 instances of prefab with the same Volume, they all 100 have a separate copy of Voxel data array? Or behind the scene they share voxel data, until voxel is touched?
  • If I instantiate 20 new Volumes on a given frame (creating new tiles for character to walk), will each of them require greedy algorithm run? Or initial mesh is created at design time?

Last edited 18 November 2015

0
GarethIW posted this 23 November 2015

Sorry for the late reply, I forgot to subscribe to the thread!

The mesh/data stuff (including the difference between prefab and copy/duplicate) is explained in the manual on page 14: http://picavoxel.com/files/picavoxel%20manual.pdf - but essentially at runtime all volumes have their own data whether they are an instantiated prefab or not.

I believe at edit-time there would only be one copy of the voxel data for all instances of that prefab (although I am not 100% sure on this - it's not always easy to know what's going on with Unity serialization).

Greedy is the default meshing algorithm. Unless you change the meshing algorithm to Culled, the greedy algorithm is used every time any destruction occurs. Note that the greedy algorithm is slower than culled, so you may have to trade off between triangles and mesh generation speed if you have a lot of destruction happening.

PicaVoxel keeps track of which chunks have had changes (destruction, addition, color, or value) to their voxels at runtime and every frame runs an update on only the chunks affected (and neighbouring chunks if applicable) since the last update. The mesh generation is threaded as much as it can be (within the limitations of Unity's mesh system)

Last edited 23 November 2015


Our 125 members have posted 459 times in 111 discussions