I know this is a pretty old question and was probably solved. I am currently doing something similar, creating dots in an empty map. My solution was the next one:
static func get_event_spatial_position(mousePos:Vector2, viewport:Viewport, obj:Spatial)->Vector3:
var vSize = viewport.get_size()
var obj_rotation = obj.transform.basis.inverse()
var camera_pos = viewport.get_camera().transform.origin
var initial_correction = 720 / vSize.y #Viewport always streches keeping the 720 (1080/720)
var last_correction = 465
camera_pos -= Vector3(0,0,1)
camera_pos = camera_pos * 1.1
camera_pos = obj_rotation * camera_pos
#Vector2 Mouse Position
mousePos -= vSize/2
mousePos *= Vector2(1,-1)
mousePos *= initial_correction
#Vector3 Spatial Position
var spatialPos = Vector3(mousePos.x, mousePos.y, 0)
spatialPos = obj_rotation * spatialPos
spatialPos /= last_correction
spatialPos += camera_pos
The thing I couldn't figure out was the last correction. That one was a constant value i made by trial an error that made the dot go where it should.
Also, this code makes it always apear in position 0 of what would be the axis when rotating the camara (if z is depth that will be 0, if x is depth that would be 0). To change this you would need to change the starting z parameter in spatialPos.
Lastly, I do camera_pos -= Vector3(0,0,1) because that is its starting position.