Skip to content

Commit

Permalink
Add max_slope to Project on Terrain3D modifier for Proton Scatter
Browse files Browse the repository at this point in the history
  • Loading branch information
DissonantVoid authored and TokisanGames committed Jan 7, 2025
1 parent 4a04728 commit 21df330
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions project/addons/terrain_3d/extras/project_on_terrain3d.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# Copyright © 2024 Cory Petkovsek, Roope Palmroos, and Contributors.
# Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
# This script is an addon for HungryProton's Scatter https://github.com/HungryProton/scatter
# It provides a `Project on Terrain3D` modifier, which allows Scatter
# to detect the terrain height from Terrain3D without using collision.
# Copy this file into /addons/proton_scatter/src/modifiers
# Then uncomment everything below
# In the editor, add this modifier to Scatter, then set your Terrain3D node

# This script is an addon for HungryProton's Scatter https://github.com/HungryProton/scatter
# It allows Scatter to detect the terrain height from Terrain3D
#
# Copy this file into /addons/proton_scatter/src/modifiers
# Then uncomment everything below (select, press CTRL+K)
# In the editor, add this modifier, then set your Terrain3D node
# In the editor, add this modifier to Scatter, then set your Terrain3D node

#@tool
#extends "base_modifier.gd"
Expand All @@ -21,6 +16,7 @@
#
#@export var terrain_node : NodePath
#@export var align_with_collision_normal := false
#@export_range(0.0, 90.0, 0.1) var max_slope = 90.0
#
#var _terrain: Terrain3D
#
Expand Down Expand Up @@ -69,20 +65,29 @@
## Get global transform
#var gt: Transform3D = domain.get_global_transform()
#var gt_inverse := gt.affine_inverse()
#var new_transforms_array: Array[Transform3D] = []
#var remapped_max_slope: float = remap(max_slope, 0.0, 90.0, 0.0, 1.0)
#for i in transforms.list.size():
#var location: Vector3 = (gt * transforms.list[i]).origin
#var t: Transform3D = transforms.list[i]
#
#var location: Vector3 = (gt * t).origin
#var height: float = _terrain.data.get_height(location)
#var normal: Vector3 = _terrain.data.get_normal(location)
#
#if align_with_collision_normal and not is_nan(normal.x):
#transforms.list[i].basis.y = normal
#transforms.list[i].basis.x = -transforms.list[i].basis.z.cross(normal)
#transforms.list[i].basis = transforms.list[i].basis.orthonormalized()
#t.basis.y = normal
#t.basis.x = -t.basis.z.cross(normal)
#t.basis = t.basis.orthonormalized()
#
#if abs(Vector3.UP.dot(normal)) >= (1.0 - remapped_max_slope):
#t.origin.y = gt.origin.y if is_nan(height) else height - gt.origin.y
#new_transforms_array.push_back(t)
#
#transforms.list[i].origin.y = gt.origin.y if is_nan(height) else height - gt.origin.y
#transforms.list.clear()
#transforms.list.append_array(new_transforms_array)
#
#if transforms.is_empty():
#warning += """Every point has been removed. Possible reasons include: \n
#warning += """All transforms have been removed. Possible reasons include: \n
#+ No collider is close enough to the shapes.
#+ Ray length is too short.
#+ Ray direction is incorrect.
Expand Down

0 comments on commit 21df330

Please sign in to comment.