Tonmy
I'm trying to Stamp a Mesh with no luck. The game feature is to create an explosion which will explode part of the terrain. I could achieve this just by stamping a sphere in the terrain, pretty much like the unity demo.

But the demo uses the hitInfo of the ClipmapView, and I would like to input an arbitrary world position.

The scale factors from unity to voxelfarm seems to be right as I can sucessfully carve the explosion if I use this awful workaround: Change LineofSight to explosion position, StampMesh with the demo code, Change back the LineOfSight to the camera position.
I also tried different combinations for the offset position  "double hitPos[3]  = ...     vfImpl->vf->originY() - z }" with no luck.

How could I get this rights? 

My code is currently like this

Code in unity script on the voxelfarm_client.cs:

 

public void stampAssetMeshInPosition(Vector3 worldPosition,bool remove, float meshScaleFactor = 50.0f)

{
// make a mesh triangle array
float[] vertices = new float[meshToStamp.triangles.Length*3];

int vert_i = 0;

for (int i = 0; i < meshToStamp.triangles.Length; i += 3)
{
Vector3 p1 = meshToStamp.vertices[meshToStamp.triangles[i + 0]];
Vector3 p2 = meshToStamp.vertices[meshToStamp.triangles[i + 1]];
Vector3 p3 = meshToStamp.vertices[meshToStamp.triangles[i + 2]];

vertices[vert_i++] = p1.x * meshScaleFactor;
vertices[vert_i++] = p1.y * meshScaleFactor;
vertices[vert_i++] = p1.z * meshScaleFactor;

vertices[vert_i++] = p2.x * meshScaleFactor;
vertices[vert_i++] = p2.y * meshScaleFactor;
vertices[vert_i++] = p2.z * meshScaleFactor;

vertices[vert_i++] = p3.x * meshScaleFactor;
vertices[vert_i++] = p3.y * meshScaleFactor;
vertices[vert_i++] = p3.z * meshScaleFactor;
}

// voxelize the mesh

// voxelize the mesh
voxelfarm.dll.build.stamp_passed_meshInPosition((worldPosition.x- voxelfarm.Scene.instance.root.transform.position.x) /voxelfarm.constants.scale
, (worldPosition.y- voxelfarm.Scene.instance.root.transform.position.y) / voxelfarm.constants.scale
,( worldPosition.z - voxelfarm.Scene.instance.root.transform.position.z) / voxelfarm.constants.scale
, vert_i, vertices, remove);

/* The "voxelfarm.Scene.instance.root.transform.position" is currently set to (0,0,0) so it doesn't influence in anything.
*/

}




On voxelfarm.cpp, in the project to compile de DLL, my code is the following:

void VOXELFARM_API stamp_passed_meshInPosition(double x, double y, double z,int vertCount, float* vertices, bool remove)
{
  if (vfImpl->vf->clipmapView()->scene == 0) return;
  CRawMesh mesh(vertCount / 3 / 3, vertices);
  Algebra::Matrix transform = Algebra::Matrix_identity();
  // -----------------------------------------------------------------------
  vfImpl->vf->clipmapView()->enterCriticalSection();
  //if (!vfImpl->vf->clipmapView()->hitInfo.valid || vfImpl->vf->clipmapView()->hitInfo.cell == 0)
  {
    //vfImpl->vf->clipmapView()->leaveCriticalSection();
    //return;
  }

  // Begin tracking changes for UNDO
  vfImpl->vf->clipmapView()->blockData->beginChanges();
  // -----------------------------------------------------------------------
  /*
  int hlevel, hxc, hyc, hzc;
  unpackCellId(vfImpl->vf->clipmapView()->hitInfo.cell, hlevel, hxc, hyc, hzc);
  double hscale = CELL_SIZE*(1 << hlevel);
  double blockSize = hscale / BLOCK_DIMENSION;
  const double Size[3] = { 1.0, 1.0, 1.0 };
  */
  /*double hitPos[3] = {
    hscale*(hxc + (double)vfImpl->vf->clipmapView()->hitInfo.voxel[0] / VoxelFarm::BLOCK_DIMENSION) + Size[0] / 2.0,
    hscale*(hyc + (double)vfImpl->vf->clipmapView()->hitInfo.voxel[1] / VoxelFarm::BLOCK_DIMENSION) + Size[1] / 2.0,
    hscale*(hzc + (double)vfImpl->vf->clipmapView()->hitInfo.voxel[2] / VoxelFarm::BLOCK_DIMENSION) + Size[2] / 2.0
  };*/
  double hitPos[3] = {
    vfImpl->vf->originX() + x,
    vfImpl->vf->originY() + y,
    vfImpl->vf->originY() - z
  };
  std::set<CellId> changedCells;
  static CAirStampMeshMaterials airMat;
  CAirStampMeshMaterials* mat = (remove) ? &airMat : NULL;
  stampMeshQEF(vfImpl->vf->clipmapView()->blockData, &mesh, mat, hitPos, transform, &changedCells);

  vfImpl->vf->clipmapView()->processModifiedCells(changedCells);
  // -----------------------------------------------------------------------
  // Track end of changes for UNDO
  vfImpl->vf->clipmapView()->blockData->endChanges();
  vfImpl->vf->clipmapView()->leaveCriticalSection();

  // -----------------------------------------------------------------------
  // track that a cell has been modified by the user
  for (std::set<CellId>::const_iterator iter = changedCells.begin(); iter != changedCells.end(); ++iter)
    addToUserChangedCells(*iter);
  // -----------------------------------------------------------------------
  //vfImpl->vf->setUserRemovedBlock();
}


Thanks

 

0 0
voxelfarmtorres
We have dispatched your question to our devs, please hold for an answer.
0 0
voxelfarmtorres
The code appears to be ok on a first glance. There is one small typo which could be causing the unwanted behaviour. In you cpp file, the hitPos is being computed like so:
 
 double hitPos[3] = {
    vfImpl->vf->originX() + x,
    vfImpl->vf->originY() + y,
    vfImpl->vf->originY() - z
  };
 
there the originY() is used instead of originZ()
 
Please see if correcting that will fix the issue.
0 0
Tonmy
That was exactly it. Sorry for taking you time. I've rewritten (erased and wrote again) that function a few times, when I got it right, made that mistake.

Thanks very much for the help, I wouldn't have caught the typo, and sorry again for taking time with that kind of mistake.
0 0
voxelfarmtorres
No worries, that is why we are here [smile]
0 0