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

Use separate resource files for each region #374

Merged
merged 19 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions Terrain3D.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<ClInclude Include="src\logger.h" />
<ClInclude Include="src\terrain_3d_instancer.h" />
<ClInclude Include="src\terrain_3d_mesh_asset.h" />
<ClInclude Include="src\terrain_3d_region.h" />
<ClInclude Include="src\terrain_3d_texture_asset.h" />
<ClInclude Include="src\terrain_3d_util.h" />
<ClInclude Include="src\terrain_3d_material.h" />
Expand All @@ -164,6 +165,7 @@
<ClCompile Include="src\terrain_3d_instancer.cpp" />
<ClCompile Include="src\terrain_3d_material.cpp" />
<ClCompile Include="src\terrain_3d_mesh_asset.cpp" />
<ClCompile Include="src\terrain_3d_region.cpp" />
<ClCompile Include="src\terrain_3d_storage.cpp" />
<ClCompile Include="src\terrain_3d_texture_asset.cpp" />
<ClCompile Include="src\terrain_3d_assets.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions Terrain3D.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<ClInclude Include="src\terrain_3d_asset_resource.h">
<Filter>4. Headers</Filter>
</ClInclude>
<ClInclude Include="src\terrain_3d_region.h">
<Filter>4. Headers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\geoclipmap.cpp">
Expand Down Expand Up @@ -107,6 +110,9 @@
<ClCompile Include="src\terrain_3d_mesh_asset.cpp">
<Filter>5. C++</Filter>
</ClCompile>
<ClCompile Include="src\terrain_3d_region.cpp">
<Filter>5. C++</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include=".github\actions\windows-deps\action.yml">
Expand Down
11 changes: 5 additions & 6 deletions project/addons/terrain_3d/editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ func _edit(p_object: Object) -> void:
ui.set_visible(true)
terrain.set_meta("_edit_lock_", true)

# Get alerted when a new asset list is loaded
# Get alerted when a new asset list is loaded
if not terrain.assets_changed.is_connected(asset_dock.update_assets):
terrain.assets_changed.connect(asset_dock.update_assets)
asset_dock.update_assets()
# Get alerted when the region map changes
# Get alerted when the region map changes
if not terrain.get_storage().region_map_changed.is_connected(update_region_grid):
terrain.get_storage().region_map_changed.connect(update_region_grid)
update_region_grid()
Expand Down Expand Up @@ -180,9 +180,8 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
ui.update_decal()

## Update region highlight
var region_size = terrain.get_storage().get_region_size()
var region_position: Vector2 = ( Vector2(mouse_global_position.x, mouse_global_position.z) \
/ (region_size * terrain.get_mesh_vertex_spacing()) ).floor()
/ (terrain.get_region_size() * terrain.get_mesh_vertex_spacing()) ).floor()
if current_region_position != region_position:
current_region_position = region_position
update_region_grid()
Expand Down Expand Up @@ -213,7 +212,7 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
# If adjusting regions
if editor.get_tool() == Terrain3DEditor.REGION:
# Skip regions that already exist or don't
var has_region: bool = terrain.get_storage().has_region(mouse_global_position)
var has_region: bool = terrain.get_storage().has_regionp(mouse_global_position)
var op: int = editor.get_operation()
if ( has_region and op == Terrain3DEditor.ADD) or \
( not has_region and op == Terrain3DEditor.SUBTRACT ):
Expand Down Expand Up @@ -246,7 +245,7 @@ func update_region_grid() -> void:
region_gizmo.show_rect = editor.get_tool() == Terrain3DEditor.REGION
region_gizmo.use_secondary_color = editor.get_operation() == Terrain3DEditor.SUBTRACT
region_gizmo.region_position = current_region_position
region_gizmo.region_size = terrain.get_storage().get_region_size() * terrain.get_mesh_vertex_spacing()
region_gizmo.region_size = terrain.get_region_size() * terrain.get_mesh_vertex_spacing()
region_gizmo.grid = terrain.get_storage().get_region_locations()

terrain.update_gizmos()
Expand Down
4 changes: 2 additions & 2 deletions project/addons/terrain_3d/src/ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ func pick(p_global_position: Vector3) -> void:
var color: Color
match picking:
Terrain3DEditor.HEIGHT:
color = plugin.terrain.get_storage().get_pixel(Terrain3DStorage.TYPE_HEIGHT, p_global_position)
color = plugin.terrain.get_storage().get_pixel(Terrain3DRegion.TYPE_HEIGHT, p_global_position)
Terrain3DEditor.ROUGHNESS:
color = plugin.terrain.get_storage().get_pixel(Terrain3DStorage.TYPE_COLOR, p_global_position)
color = plugin.terrain.get_storage().get_pixel(Terrain3DRegion.TYPE_COLOR, p_global_position)
Terrain3DEditor.COLOR:
color = plugin.terrain.get_storage().get_color(p_global_position)
Terrain3DEditor.ANGLE:
Expand Down
8 changes: 4 additions & 4 deletions project/addons/terrain_3d/tools/importer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ func start_import(p_value: bool) -> void:
storage = Terrain3DStorage.new()

var imported_images: Array[Image]
imported_images.resize(Terrain3DStorage.TYPE_MAX)
imported_images.resize(Terrain3DRegion.TYPE_MAX)
var min_max := Vector2(0, 1)
var img: Image
if height_file_name:
img = Terrain3DUtil.load_image(height_file_name, ResourceLoader.CACHE_MODE_IGNORE, r16_range, r16_size)
min_max = Terrain3DUtil.get_min_max(img)
imported_images[Terrain3DStorage.TYPE_HEIGHT] = img
imported_images[Terrain3DRegion.TYPE_HEIGHT] = img
if control_file_name:
img = Terrain3DUtil.load_image(control_file_name, ResourceLoader.CACHE_MODE_IGNORE)
imported_images[Terrain3DStorage.TYPE_CONTROL] = img
imported_images[Terrain3DRegion.TYPE_CONTROL] = img
if color_file_name:
img = Terrain3DUtil.load_image(color_file_name, ResourceLoader.CACHE_MODE_IGNORE)
imported_images[Terrain3DStorage.TYPE_COLOR] = img
imported_images[Terrain3DRegion.TYPE_COLOR] = img
if assets.get_texture_count() == 0:
material.show_checkered = false
material.show_colormap = true
Expand Down
28 changes: 17 additions & 11 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ using namespace godot;
#define COLOR_NORMAL Color(0.5f, 0.5f, 1.0f, 1.0f)
#define COLOR_CONTROL Color(as_float(enc_auto(true)), 0.f, 0.f, 1.0f)

// For consistency between msvc, gcc, clang

#ifndef __FLT_MAX__
#define __FLT_MAX__ FLT_MAX
#ifndef FLT_MAX
// For consistency between MSVC, gcc, clang
#define FLT_MAX __FLT_MAX__
#endif

#define V2_ZERO Vector2(0.f, 0.f)
#define V2_MAX Vector2(FLT_MAX, FLT_MAX)
#define V3_ZERO Vector3(0.f, 0.f, 0.f)
#define V3_MAX Vector3(FLT_MAX, FLT_MAX, FLT_MAX)
#define V2I_ZERO Vector2i(0, 0)
#define V2I_MAX Vector2i(INT32_MAX, INT32_MAX)

// Set class name for logger.h

#define CLASS_NAME() const String __class__ = get_class_static() + \
Expand Down Expand Up @@ -68,15 +74,15 @@ using namespace godot;
return ret; \
}

#define IS_STORAGE_INIT(ret) \
if (_terrain == nullptr || _terrain->get_storage().is_null()) { \
return ret; \
#define IS_STORAGE_INIT(ret) \
if (_terrain == nullptr || _terrain->get_storage() == nullptr) { \
return ret; \
}

#define IS_STORAGE_INIT_MESG(mesg, ret) \
if (_terrain == nullptr || _terrain->get_storage().is_null()) { \
LOG(ERROR, mesg); \
return ret; \
#define IS_STORAGE_INIT_MESG(mesg, ret) \
if (_terrain == nullptr || _terrain->get_storage() == nullptr) { \
LOG(ERROR, mesg); \
return ret; \
}

#endif // CONSTANTS_CLASS_H
2 changes: 1 addition & 1 deletion src/geoclipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Vector<RID> GeoClipMap::generate(const int p_size, const int p_levels) {
}
}

aabb = AABB(Vector3(0.f, 0.f, 0.f), Vector3(PATCH_VERT_RESOLUTION, 0.1f, PATCH_VERT_RESOLUTION));
aabb = AABB(V3_ZERO, Vector3(PATCH_VERT_RESOLUTION, 0.1f, PATCH_VERT_RESOLUTION));
tile_mesh = _create_mesh(vertices, indices, aabb);
}

Expand Down
1 change: 1 addition & 0 deletions src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void initialize_terrain_3d(ModuleInitializationLevel p_level) {
ClassDB::register_class<Terrain3DMaterial>();
ClassDB::register_class<Terrain3DMeshAsset>();
ClassDB::register_class<Terrain3DStorage>();
ClassDB::register_class<Terrain3DRegion>();
ClassDB::register_class<Terrain3DTextureAsset>();
ClassDB::register_class<Terrain3DUtil>();
ClassDB::register_class<Terrain3DTexture>(); // Deprecated 0.9.2 - Remove 0.9.3+
Expand Down
Loading