ashkan.saeedi.1989

The AddBlock/Removeblock operaitons are automatically snapped to a grid.

What should i do to snap StampMesh to a grid? What i tried to do was i first did GetStampMeshHitInfo and then modified the position and called GetStampInfo to fix the position i modified with an actual stamp info but the results are not good and takes time to stabilize whenever i move the mouse.

 

The code is like this

ray = Camera.ScreenPointToRay(mousePosition);

var hitInfo = GetStampMeshHitInfo(ray);

hitInfo.position = Snapped(hitInfo.position);

hitInfo2 = GetStampMeshInfo(hitInfo);

StampMesh(ConvertToUnityPosition(hitInfo2.position),mesh,material,pos,rotation,size);

 

The reulst is not good and whenever i move the mouse and a new ray is cast , the final position 

moves for some time and then stabilizes at a position which doesn't feel right. What is a better way to do this and in general what exactly GetStampInfo does exactly different compared to GetStampMeshHitInfo ?

0 0
Ericool
Hi ashkan.saeedi.1989,
Have you tried to use GetFillBlockHitInfo instead and using your mesh bounds size converted to voxel size?

As for StampMesh, as for now it takes directly the position from a hit info as it is in Voxel Farm Coordinates, have you try without converting hitInfo2.position ? 
0 0
ashkan.saeedi.1989

@Ericool

Wow Thanks Eric! It worked like a charm. The snap size doesn't exactly behave like add block however. 

Actually a related question is, I successfully use GetPlaceMeshInfo to find out where the mesh will be based on my ray and put a visual indicator (exact shape of the mesh) there to guide the user but when i tried to put a block there for cubes (getting the position using GetFillBock and GetCarveBlock) i could not find out how to calculate where to put the cube. If you let me know how should i calculate that (i guess it is based on normal as well) then this part of my game would be fully done.

 

P.S I'm going to write a blog post for the fellow devs this week describing how to show visual indicators, snap stamped meshes and ... and am more than willing to help updating the docs. I can write an advanced StampMesh page now. And hopefully my game would soon be more than that house of marble.

0 0
Ericool
@ashkan.saeedi.1989

This still needs to be tested in depth with different rotations and scales but you can obtain the add block behaviour in that way for stamp mesh,
and this does not include taking the hitinfo normal into account for the rotation.

in client_subscriber you can add : 

  protected void StampMeshToGrid(Ray lineOfSight, ushort materialUid, Mesh mesh)
{
   if (client != null)
   {
      if (mesh != null)
      {
         Vector3 meshSize = mesh.bounds.size;
         uint sizeX = (uint)Mathf.FloorToInt(meshSize.x / .3f);
         uint sizeY = (uint)Mathf.FloorToInt(meshSize.y / .3f);
         uint sizeZ = (uint)Mathf.FloorToInt(meshSize.z / .3f);
         HitInfo hitInfo = client.GetFillBlockHitInfo(lineOfSight, sizeX, sizeY, sizeZ);

         meshSize.x = .3f * sizeX;
         meshSize.y = .3f * sizeY;
         meshSize.z = .3f * sizeZ;

         Vector3 meshPosition = ( meshSize + new Vector3(0.3f, 0.3f, 0.3f)) / 2;
         meshPosition.z *= -1.0f;

         client.StampMesh(hitInfo.positionX, hitInfo.positionY, hitInfo.positionZ, mesh, materialUid, meshPosition, constants.Vector3Zero, meshSize);
      }
   }
}
This will work for meshes where the origin is the center of mass such as Unity cube,sphere,etc.

At last, I did not tested it with different scales and rotations or position offset.
0 0
ashkan.saeedi.1989

@Ericool 

Thanks but this was what i already had. What i want is to find out what place center of the cube for AddBlock would be which needs the normal, I guess formula is finding the position of GetFillBlock and then move away from it in the direction of the HitInfo.normal and in length of half of the size so i can show the user where their AddBlock will be done. 

 

Thanks for it anyways and I'll follow up with my post soon. 

0 0
ashkan.saeedi.1989

I posted once but i guess it wasn't sent successfully. 

 

Thanks @Ericool This is what i already have but what is needed for knowing where AddBlock cube's center will be, is the normal i gues. I need to move away half of the length of the size from GetFillBlockInfo in direction of the hitInfo normal so should do it myself or wait for the next release

0 0
Ericool
@ashkan.saeedi.1989

The translation is done during StampBlock to center the block , although it will be moved to GetFillBlock or GetCarveBlock for the next release. So that it can be used for StampMesh as well. For fill or carve we dont adjust the center with the hit normal; but with the outside direction which is aligned with the voxel grid. This is done during GetFillBlock or GetCarveBlock.
0 0
ashkan.saeedi.1989
@Ericool As you guessed it doesn't work for different rotations and scales so please try to find out how the landmark guys did it. Since I need infor from voxels to calculate this. For example how can I know which side of a voxel my ray hits and other info from the voxel which might be useful? We already talked about the normal but say position of the plane/surface we hit and ...
0 0
Ericool
At the moment, if you want to fill or carve either a block or a mesh you wont be able to apply any rotation in Unity.
Nonetheless, you can still obtain the desired behaviour by implementing it in the dll.
When applying an edition such as fill,carve,etc. if you provide a ray, we are going to compute a potential hit. PlaceMesh will use the hit position on the plane/surface. Where as fill or carve will use some voxel info to calculate a position on the grid.
Among the voxel info we use a non-normalized vector called outsideDirection in the hit info structure. Each component is either -1,0,1. This is what you need if you want to know which side. Know that you will need to convert the vector for Unity. For example a front side in VoxelFarm could be the back side in Unity.
0 0
Ericool
We are going to reexpose the hit info structure in the upcoming plugin release. We simply had to hide it temporary to avoid conflicts with the way we process editions. 
0 0