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;
editLocation.x + voxelfarm_client.Current.bundle.originX,
editLocation.y + voxelfarm_client.Current.bundle.originY,
-editLocation.z + voxelfarm_client.Current.bundle.originZ,
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;
// 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);
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.