Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instancer storage rework #523

Merged
merged 28 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0998494
Fix undo - call stop_operating
TokisanGames Oct 24, 2024
caf9fd2
Fix crash on close
TokisanGames Oct 19, 2024
8e16a54
Replace TypedArray<Color> with PackedColorArray
TokisanGames Oct 12, 2024
1825f5c
Add instancer grid debug view
Xtarsia Oct 16, 2024
4ac78fa
Fix set-get_pixel error condition on deleted regions
Xtarsia Oct 16, 2024
9a48a6b
Renames, updates, force_update_mmis in Data on region add/remove not …
TokisanGames Oct 12, 2024
56bb1ad
Store MMIs under region containers
TokisanGames Oct 12, 2024
8b77430
Add region data dict; Setup initial upgrade infrastructure
TokisanGames Oct 12, 2024
c6d1a94
Store transforms in region space w/ embedded vertex spacing
Xtarsia Oct 10, 2024
70e731e
Add _get_cell()
TokisanGames Oct 12, 2024
12869b9
Change data structure (partially working, lots not)
TokisanGames Oct 12, 2024
50d72cf
Refactor remove instances
Xtarsia Oct 12, 2024
5f8c759
Refactor update_transforms modify maps_edited signal
Xtarsia Oct 14, 2024
3675bcd
Renames. Reduce logging. Improve cleanup
TokisanGames Oct 15, 2024
8d4b9ad
Region size change implementation
Xtarsia Oct 15, 2024
8d51bcf
Remove update xforms vertex spacing correction
Xtarsia Oct 16, 2024
a7145a1
Rename mesh_dict -> mesh_inst_dict, etc
TokisanGames Oct 17, 2024
e84220f
Consolidate all MMI deletion. Switch MMI storage to unordered_map.
TokisanGames Oct 17, 2024
7a1f731
Expose mesh asset visibility range
TokisanGames Oct 17, 2024
9620c34
Convert region mmi node container to std::unordered_map
TokisanGames Oct 18, 2024
8cd7bbb
Fix crash - iterate over keys when removing elements. Fix clearing da…
TokisanGames Oct 18, 2024
fefb3b0
Fix crash via incorrect mesh index
Xtarsia Oct 18, 2024
38b4967
Refactor swap_ids. Remove instancer::get_multimeshes()
TokisanGames Oct 18, 2024
27bf67e
Remove clear option from append funcs, add update
TokisanGames Oct 20, 2024
064ac91
Reorder code; remove comments, messages
TokisanGames Oct 24, 2024
8f11f6f
Backup sooner; Fix Update_transforms height offset; Remove instances …
TokisanGames Oct 24, 2024
11c9ea4
Upgrade instancer data from 0.9.2 or 0.9.3-dev
TokisanGames Oct 20, 2024
3d28a6d
Update demo
TokisanGames Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions project/addons/terrain_3d/editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func _edit(p_object: Object) -> void:
return
terrain = p_object
_last_terrain = terrain
terrain.set_plugin(self)
terrain.set_editor(editor)
editor.set_terrain(terrain)
region_gizmo.set_node_3d(terrain)
terrain.add_gizmo(region_gizmo)
terrain.set_plugin(self)
terrain.set_editor(editor)
ui.set_visible(true)
terrain.set_meta("_edit_lock_", true)

Expand Down Expand Up @@ -243,7 +243,12 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->

func _read_input(p_event: InputEvent = null) -> void:
## Determine if user is moving camera or applying
_input_mode = 1 if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) else 0
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) or \
p_event is InputEventMouseButton and p_event.is_released() and \
p_event.get_button_index() == MOUSE_BUTTON_LEFT:
_input_mode = 1
else:
_input_mode = 0

match get_setting("editors/3d/navigation/navigation_scheme", 0):
2, 1: # Modo, Maya
Expand Down
2 changes: 1 addition & 1 deletion project/addons/terrain_3d/src/ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func update_decal() -> void:

decal.position = plugin.mouse_global_position
decal.visible = true
decal.size = Vector3.ONE * brush_data["size"]
decal.size = Vector3.ONE * maxf(brush_data["size"], .5)
if brush_data["align_to_view"]:
var cam: Camera3D = plugin.terrain.get_camera();
if (cam):
Expand Down
49 changes: 47 additions & 2 deletions project/demo/components/UI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,53 @@ script = ExtResource("1_why5e")
[node name="Label" type="Label" parent="."]
unique_name_in_owner = true
layout_mode = 1
offset_right = 40.0
offset_bottom = 23.0
offset_left = 5.0
offset_top = 5.0
offset_right = 275.0
offset_bottom = 340.0
theme_override_colors/font_shadow_color = Color(0, 0, 0, 0.662745)
theme_override_constants/shadow_offset_x = 1
theme_override_constants/shadow_offset_y = 1
text = "FPS: 100
Position: (100, 100, 100)
Move Speed: 10

Player
Move: WASDEQ,Space,Mouse
Move speed: Wheel,+/-,Shift
Camera view: V
Gravity toggle: G
Collision toggle: C

Window
Quit: F8
UI toggle: F9
Render mode: F10
Full screen: F11
Mouse toggle: Escape
"

[node name="Panel" type="Panel" parent="Label"]
modulate = Color(1, 1, 1, 0.392157)
show_behind_parent = true
layout_mode = 0
offset_left = -5.0
offset_top = -5.0
offset_right = 248.0
offset_bottom = 444.0

[node name="HSeparator" type="HSeparator" parent="Label/Panel"]
top_level = true
layout_mode = 0
offset_left = 6.0
offset_top = 129.0
offset_right = 246.0
offset_bottom = 138.0

[node name="HSeparator2" type="HSeparator" parent="Label/Panel"]
top_level = true
layout_mode = 0
offset_left = 6.0
offset_top = 310.0
offset_right = 246.0
offset_bottom = 319.0
12 changes: 8 additions & 4 deletions project/demo/data/assets.tres
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
[ext_resource type="Texture2D" uid="uid://ddprscrpsofah" path="res://demo/assets/textures/ground037_alb_ht.png" id="3_g8f2m"]
[ext_resource type="Texture2D" uid="uid://c1ots7w6i0i1q" path="res://demo/assets/textures/ground037_nrm_rgh.png" id="4_aw5y1"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_6fvgb"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_aubfq"]
transparency = 4
cull_mode = 2
vertex_color_use_as_albedo = true
backlight_enabled = true
backlight = Color(0.5, 0.5, 0.5, 1)
distance_fade_mode = 1
distance_fade_min_distance = 960.0
distance_fade_max_distance = 480.0

[sub_resource type="Terrain3DMeshAsset" id="Terrain3DMeshAsset_xqljq"]
[sub_resource type="Terrain3DMeshAsset" id="Terrain3DMeshAsset_dw1mh"]
height_offset = 0.5
density = 10.0
material_override = SubResource("StandardMaterial3D_6fvgb")
material_override = SubResource("StandardMaterial3D_aubfq")
generated_type = 1

[sub_resource type="Terrain3DTextureAsset" id="Terrain3DTextureAsset_mup2f"]
Expand All @@ -31,5 +35,5 @@ albedo_texture = ExtResource("3_g8f2m")
normal_texture = ExtResource("4_aw5y1")

[resource]
mesh_list = Array[Terrain3DMeshAsset]([SubResource("Terrain3DMeshAsset_xqljq")])
mesh_list = Array[Terrain3DMeshAsset]([SubResource("Terrain3DMeshAsset_dw1mh")])
texture_list = Array[Terrain3DTextureAsset]([SubResource("Terrain3DTextureAsset_mup2f"), SubResource("Terrain3DTextureAsset_od0q7")])
36 changes: 23 additions & 13 deletions project/demo/src/UI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends Control


var player: Node
var visible_mode: int = 1


func _init() -> void:
Expand All @@ -10,26 +11,35 @@ func _init() -> void:

func _process(p_delta) -> void:
$Label.text = "FPS: %s\n" % str(Engine.get_frames_per_second())
$Label.text += "Move Speed: %.1f\n" % player.MOVE_SPEED if player else ""
$Label.text += "Position: %.1v\n" % player.global_position if player else ""
$Label.text += "Move: WASDEQ/Space/Shift/Mouse\n"
$Label.text += "Move speed: Wheel,+/-\n"
$Label.text += "Camera View: V\n"
$Label.text += "Gravity toggle: G\n"
$Label.text += "Collision toggle: C\n"
$Label.text += "Hide UI: H\n"
$Label.text += "Full screen: F11\n"
$Label.text += "Mouse toggle: Escape\n"
$Label.text += "Quit: F8\n"
if(visible_mode == 1):
$Label.text += "Move Speed: %.1f\n" % player.MOVE_SPEED if player else ""
$Label.text += "Position: %.1v\n" % player.global_position if player else ""
$Label.text += """
Player
Move: WASDEQ,Space,Mouse
Move speed: Wheel,+/-,Shift
Camera View: V
Gravity toggle: G
Collision toggle: C

Window
Quit: F8
UI toggle: F9
Render mode: F10
Full screen: F11
Mouse toggle: Escape
"""


func _unhandled_key_input(p_event: InputEvent) -> void:
if p_event is InputEventKey and p_event.pressed:
match p_event.keycode:
KEY_H:
visible = ! visible
KEY_F8:
get_tree().quit()
KEY_F9:
visible_mode = (visible_mode + 1 ) % 3
$Label/Panel.visible = (visible_mode == 1)
visible = visible_mode > 0
KEY_F10:
var vp = get_viewport()
vp.debug_draw = (vp.debug_draw + 1 ) % 6
Expand Down
19 changes: 19 additions & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,23 @@ using namespace godot;
return ret; \
}

// Global Types

struct Vector2iHash {
std::size_t operator()(const Vector2i &v) const {
std::size_t h1 = std::hash<int>()(v.x);
std::size_t h2 = std::hash<int>()(v.y);
return h1 ^ (h2 << 1);
}
};

struct Vector3Hash {
std::size_t operator()(const Vector3 &v) const {
std::size_t h1 = std::hash<float>()(v.x);
std::size_t h2 = std::hash<float>()(v.y);
std::size_t h3 = std::hash<float>()(v.z);
return h1 ^ (h2 << 1) ^ (h3 << 2);
}
};

#endif // CONSTANTS_CLASS_H
11 changes: 0 additions & 11 deletions src/geoclipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@

// Half each triangle, have to check for longest side.
void GeoClipMap::_subdivide_half(PackedVector3Array &vertices, PackedInt32Array &indices) {

// Hash for map for quick vertex search, for loop was very very slow!
struct Vector3Hash {
std::size_t operator()(const Vector3 &v) const {
std::size_t h1 = std::hash<float>()(v.x);
std::size_t h2 = std::hash<float>()(v.y);
std::size_t h3 = std::hash<float>()(v.z);
return h1 ^ (h2 << 1) ^ (h3 << 2);
}
};

PackedVector3Array new_vertices;
PackedInt32Array new_indices;

Expand Down
6 changes: 3 additions & 3 deletions src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ void initialize_terrain_3d(ModuleInitializationLevel p_level) {
ClassDB::register_class<Terrain3DInstancer>();
ClassDB::register_class<Terrain3DMaterial>();
ClassDB::register_class<Terrain3DMeshAsset>();
ClassDB::register_class<Terrain3DStorage>(); // Deprecated 0.9.3 - Remove 0.9.4+
ClassDB::register_class<Terrain3DStorage>(); // Deprecated 0.9.3 - Remove 1.0
ClassDB::register_class<Terrain3DRegion>();
ClassDB::register_class<Terrain3DTextureAsset>();
ClassDB::register_class<Terrain3DUtil>();
ClassDB::register_class<Terrain3DTexture>(); // Deprecated 0.9.2 - Remove 0.9.3+
ClassDB::register_class<Terrain3DTextureList>(); // Deprecated 0.9.2 - Remove 0.9.3+
ClassDB::register_class<Terrain3DTexture>(); // Deprecated 0.9.2 - Remove 1.0
ClassDB::register_class<Terrain3DTextureList>(); // Deprecated 0.9.2 - Remove 1.0
}

void uninitialize_terrain_3d(ModuleInitializationLevel p_level) {
Expand Down
15 changes: 13 additions & 2 deletions src/shaders/debug_views.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ R"(
//INSERT: DEBUG_REGION_GRID
// Show region grid
vec3 __pixel_pos1 = (INV_VIEW_MATRIX * vec4(VERTEX,1.0)).xyz;
float __region_line = 0.5; // Region line thickness
__region_line = .1*sqrt(length(v_camera_pos - __pixel_pos1));
float __region_line = 1.0; // Region line thickness
__region_line *= .1*sqrt(length(v_camera_pos - __pixel_pos1));
if (mod(__pixel_pos1.x * _vertex_density + __region_line*.5, _region_size) <= __region_line ||
mod(__pixel_pos1.z * _vertex_density + __region_line*.5, _region_size) <= __region_line ) {
ALBEDO = vec3(1.);
Expand Down Expand Up @@ -162,4 +162,15 @@ R"(
}
ALBEDO = fma(ALBEDO, 1.-__vertex_mul, __vertex_add);

//INSERT: DEBUG_INSTANCER_GRID
// Show region grid
vec3 __pixel_pos3 = (INV_VIEW_MATRIX * vec4(VERTEX,1.0)).xyz;
float __cell_line = 0.5; // Cell line thickness
__cell_line *= .1*sqrt(length(v_camera_pos - __pixel_pos3));
#define CELL_SIZE 32
if (mod(__pixel_pos3.x * _vertex_density + __cell_line*.5, CELL_SIZE) <= __cell_line ||
mod(__pixel_pos3.z * _vertex_density + __cell_line*.5, CELL_SIZE) <= __cell_line ) {
ALBEDO = vec3(.033);
}

)"
Loading