JBone
I'm wanting to get something basic playable over the network. My plan is to have a small section of a voxel farm world as a playable space, blocking access beyond the boundaries. For the server to run the physics of all the players, I would like to have the whole section be at the fullest LOD. Either that or I will need the server to have a clipmap view for each player, but since I plan to have many dynamic objects in the game world, as well as fast movement/teleporting, the first option is probably better for me.

Would this be done using a custom clipmap, or is there a way to just request a cell at a specific LOD? Could this be done without source code? Any elaboration on this issue would be helpful, thanks!
0 0
voxelfarmtorres
The ClipmapView object has properties that will allow you to set a single LOD. First, you need to set the start LOD, which you can do by setting CClipmapView::baseLOD to the desired number. Note that LODs start at 2 (LOD_0). To set the maximum LOD, use CClipmapView::maxCellLodToProcess.

You do not need the engine code for this, as these parameters can be set to the clipmap view instance.
0 0
JBone
Excellent thanks for the help. I also needed to increase the radiusLOD0 of the clipmap to cover the whole area. Is it correct that I would need the engine code to change CELL_SIZE? I should be able to get by without that, just by increasing the world scale. I don't think I will need such a small voxel size.
0 0
voxelfarmtorres
That is correct, radiusLOD0 will determine the number of first LOD cells around the focus point. I can also confirm increasing the world scale will have the same effect as rebuilding with a different CELL_SIZE, so you are OK without the full source code.
0 0
JBone
I'm currently using the toon world example for my tests. Is there any way to scale down the whole world in Voxel Studio, so that it can keep it's relative scale in Unity? Or will I have to build a new terrain with the new world scale in mind.
0 0
voxelfarmtorres
Unfortunately there is no way to scale the content inside Voxel Studio. You need to mind the conversion factor between the coordinate systems.
0 0
JBone
Hi. Another quick question: How would I get the CellId from world coordinate. I'm trying to edit voxels without moving the clipmap view position.
0 0
voxelfarmtorres
That can be accomplished by some simple math.

The first thing is to realize that due to LODs, there are multiple cells that will contain a given x,y,z point. So LOD is also an input here.

The first step is to compute the cell size for the desired LOD:

double cellSize = (1 << lod)*CELL_SIZE;

Next, you need to find out the integer coordinates of the cell:

int xi = (int)(x / cellSize);
int yi = (int)(y / cellSize);
int zi = (int)(z / cellSize);

And last, you may call the packCellId function, which will produce the cell ID you look for:

CellId cell = packCellId(lod, xi, yi, zi);
0 0
JBone
Thanks, I'm still having trouble getting this working. I also need to convert from Unity's coordinates to voxelfarm's. 

I noticed that the z axis is reversed between Unity and Voxel Studio when looking at the position in the Render tab. I had to reverse the coordinate before making the edit.

I have made a function in the plugin called add_block_at_location that edits voxels in a cube at a location. There are a few problems I'm still having. 

1. The very first time I make an edit, it is always in the same location (far away from the actual edit, and it creates a "staircase" form edit, not a cube).
2. After the first edit, the edit's appear in a consistent location relative to the actual edit location, but it is still off. I'm trying to figure out exactly what I need to offset.
3. These edits create the correct shape, but the new gameobject for the cell that was modified is not active, leaving a void in the surface. I can manually enable the inactive cell to see the edit.

In Unity, I have this:


 Vector3 editLocation = edit.Center / voxelfarm.constants.scale;
            voxelfarm.dll.build.add_block_at_location(cellInfo.LOD,
                editLocation.x + voxelfarm_client.Current.bundle.originX,
                editLocation.y + voxelfarm_client.Current.bundle.originY,
                -editLocation.z + voxelfarm_client.Current.bundle.originZ,
                5, 0);


And here is cpp the function in the plugin.


void VOXELFARM_API add_block_at_location(int lod, double xW, double yW, double zW, double size, int materialId)
{
  CClipmapView* cv = vfImpl->vf->clipmapView();
  double cellSize = (1 << lod) * CELL_SIZE;
  TSet<CellId> changedCells;
  // loop through world coordinates of block
  for (int x = xW; x < xW + size; x++)
  {
    for (int y = yW; y < yW + size; y++)
    {
      for (int z = zW; z < zW + size; z++)
      {
        // cell coordinates
        int xC = (int)(x / cellSize);
        int yC = (int)(y / cellSize);
        int zC = (int)(z / cellSize);
        CellId currentCellId = packCellId(lod, xC, yC, zC);
        // inner cell offset
        int xI = x - xC * cellSize;
        int yI = y - yC * cellSize;
        int zI = z - zC * cellSize;
        BlockVoxelData* data = cv->blockData->fetchData(currentCellId, true);
        data->setMaterial(BlockVoxelData::Index(xI, yI, zI), materialId);
        data->setVector(BlockVoxelData::Index(xI, yI, zI), 0.5, 0.5, 0.5);
        changedCells.insert(currentCellId);
      }
    }
  }
  cv->processModifiedCells(changedCells, false, NULL); // , false);
}


Is there anything obviously wrong? The edits are appearing about 5 Unity units below the actual location. I tried adjusting for the clipmap's view position, but that did not help. Thanks for any time you can spend on this.
0 0
JBone
I'm closer to getting this working, but still have the problem of cells not always activating after being edited. I have a few more basic questions:

1. When I call fetchData on a cell, is that data only at the LOD of that cell? Does this mean there are multiple LOD's for the voxel data itself? I assumed the higher LOD's just downsampled the base voxel data.

2. I have a test that sets a single voxel at (20, 20, 20) in a LOD 2 cell as solid with vector values of 0.5. It's creating a perfect cube on a few cells, but on most the cube has one corner pushed up a bit. Why is there an inconsistency between cells?

3. Why is the default lowest LOD set to 2? Am I not losing voxel resolution that way?
0 0
voxelfarmtorres
1) There is data at each LOD, sampled at different resolutions. Higher LODs contain downsampled data, this is necessary because producing this downsampled version of the data is time-consuming, and may involve a massive amount of data. For instance, consider a LOD10 cell will contain a very large number of LOD0 cells. If you had to load all this on-demand to produce the downsampled LOD10 cell, it would just take too long.

2) There is no inconsistency between cells. You can watch our Minecraft or MagicaVoxel videos to see perfect cubes. To have a cube you need to set vectors on 8 voxels, not just one. Setting just one voxel leaves 7 of the other cube corners to chance.

3) You do not loose voxel resolution due to this. Voxel resolution is more a matter of what world size you assign to the first LOD that appears in your scenes. LOD_0 is set to 2 to make today Voxel Farm applications future proof. We could introduce a method that increases detail by storing data at actual LOD 0 and LOD 1, and any of the data created by your application would benefit from this without having to remap your cell key space.
0 0
JBone
Thanks. That helped me understand things much better. A few more questions: 

1. How should I disable the movingSolids system? I would like to have the floating pieces just remain editable voxels for now.

2. How complex is voxelfarm's block_add code? I am having trouble figuring out how to get mine to work correctly when placing a block that is intersecting a surface that is not aligned to the voxel grid or sloped. I don't have a grasp on what to set the voxel vectors to.

3. You mentioned in another thread that the team is working on transforming a mesh before placing it. Will this be available in an upcoming release? This could be an easier solution to some of my problems.

4. Would you prefer that I keep adding future questions to this thread, start a new thread for new topics, or would email be better? I don't want to start spamming the forum if I have too many questions.
0 0