Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ModifyTerrain.instance.AddBlockCursor(1);
- prevVo = hit.collider.GetComponentInParent<Volume>();
- pvo = prevVo;
- //Get the frame from the volume
- frame = pvo.GetCurrentFrame();
- // Start iterating from the hit point along the ray until we hit a voxel
- Vector3 checkPoint = hit.point + (ray.direction * hitpointNudgeAmount);
- Vector3 backOneStep = hit.point + (ray.direction * -hitpointNudgeAmount);
- //Initialize the Editing Voxels array
- Voxel? v = pvo.GetVoxelAtWorldPosition(checkPoint);
- if (v.HasValue)
- {
- PicaVoxelPoint point = pvo.GetVoxelArrayPosition(backOneStep);
- pvo.GetVoxelAtArrayPosition(point.X, point.Y, point.Z);
- Debug.Log("Hit voxel (init): " + pvo.name + " " + point.X + "," + point.Y + "," + point.Z);
- frame.EditingVoxels = new Voxel[pvo.XSize * pvo.YSize * pvo.ZSize];
- frame.Voxels.CopyTo(frame.EditingVoxels, 0);
- frame.EditingVoxels[point.X + pvo.XSize * (point.Y + pvo.YSize * point.Z)]
- = new Voxel()
- {
- State = VoxelState.Active,
- Color = color,
- Value = 128
- };
- }
- // pvo.UpdateChunks(true);
- // pvo.UpdateAllChunksNextFrame();
- // Once the mouse/finger is released(or if the raycast changes volumes), Update the final Frame to save the changes to the model
- if (frame && frame.EditingVoxels != null)
- {
- //for (int i = 0; i < frame.EditingVoxels.Length; i++)
- //{
- // frame.EditingVoxels[i].Color = color;
- //}
- //Debug.Log("Ending edit: " + frame.ParentVolume.name);
- frame.EditingVoxels.CopyTo(frame.Voxels, 0);
- frame.EditingVoxels = null;
- // pvo.UpdateChunks(true);
- pvo.UpdateAllChunksNextFrame();
- }
Add Comment
Please, Sign In to add comment