Guest User

Untitled

a guest
Jul 3rd, 2019
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. // ModifyTerrain.instance.AddBlockCursor(1);
  2. prevVo = hit.collider.GetComponentInParent<Volume>();
  3. pvo = prevVo;
  4. //Get the frame from the volume
  5. frame = pvo.GetCurrentFrame();
  6. // Start iterating from the hit point along the ray until we hit a voxel
  7. Vector3 checkPoint = hit.point + (ray.direction * hitpointNudgeAmount);
  8. Vector3 backOneStep = hit.point + (ray.direction * -hitpointNudgeAmount);
  9. //Initialize the Editing Voxels array
  10. Voxel? v = pvo.GetVoxelAtWorldPosition(checkPoint);
  11. if (v.HasValue)
  12. {
  13.  
  14. PicaVoxelPoint point = pvo.GetVoxelArrayPosition(backOneStep);
  15. pvo.GetVoxelAtArrayPosition(point.X, point.Y, point.Z);
  16. Debug.Log("Hit voxel (init): " + pvo.name + " " + point.X + "," + point.Y + "," + point.Z);
  17. frame.EditingVoxels = new Voxel[pvo.XSize * pvo.YSize * pvo.ZSize];
  18. frame.Voxels.CopyTo(frame.EditingVoxels, 0);
  19. frame.EditingVoxels[point.X + pvo.XSize * (point.Y + pvo.YSize * point.Z)]
  20. = new Voxel()
  21. {
  22. State = VoxelState.Active,
  23. Color = color,
  24. Value = 128
  25. };
  26.  
  27. }
  28. // pvo.UpdateChunks(true);
  29. // pvo.UpdateAllChunksNextFrame();
  30. // Once the mouse/finger is released(or if the raycast changes volumes), Update the final Frame to save the changes to the model
  31.  
  32. if (frame && frame.EditingVoxels != null)
  33. {
  34. //for (int i = 0; i < frame.EditingVoxels.Length; i++)
  35. //{
  36. // frame.EditingVoxels[i].Color = color;
  37. //}
  38. //Debug.Log("Ending edit: " + frame.ParentVolume.name);
  39. frame.EditingVoxels.CopyTo(frame.Voxels, 0);
  40. frame.EditingVoxels = null;
  41. // pvo.UpdateChunks(true);
  42. pvo.UpdateAllChunksNextFrame();
  43. }
Add Comment
Please, Sign In to add comment