arcaneenergy/godot-multimesh-scatter

Angle constraints with custom normal

bikemurt opened this issue · 1 comments

The custom normal feature #10 which I added might be interacting badly with the "angle constraints" feature.

For example, when the custom normal is set to (0,1,0) all instance normal angles are set to this value. Constraining by angle then doesn't really do anything - it's either on or off (e.g. 0 degrees all instances disappear and > 1 degree, all re-appear). What we really want is to constrain by the original angle as determined by the hit, even though the actual placement angle is overriden.

I'm using this workaround for now by storing the original hit normal in terrain_normal:

var terrain_normal = hit.normal
if not custom_normal.is_zero_approx():
	hit.normal = custom_normal.normalized()

# Angle constraints check - use original hit angle
if use_angle:
	var off: float = rad_to_deg((abs(terrain_normal.x) + abs(terrain_normal.z)) / 2.0)
	if not off < angle_degrees:
		iteration_scale = Vector3.ZERO

In my example, I don't want trees appearing on these steep slopes, so using the original hit angle makes sense:
image

With angle constraint off, I sometimes get instances appearing on these steep faces:
image

Let me know if this makes sense or if another script parameter might need to be introduced

Sure. I have no plans updating this plugin. But the example code you provided seems to work well for these cases, so I can merge it with your changes (or you can create a pull request, doesn't really matter).