From 422361b278584e9af7f406723d9374dff5965898 Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 11 Jan 2023 11:37:49 +0000 Subject: [PATCH] Fix TerrainInstance size limits --- editor.scn | 4 ++-- project.godot | 9 +++++++++ terrain_instance_3d.gd | 17 +++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/editor.scn b/editor.scn index 0226e59..a239f0b 100644 --- a/editor.scn +++ b/editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4d2a991052e7d0bfb3cb39dbcc6b609a97c192e36c4aa916602edba30e8bcbef -size 5163 +oid sha256:02382b8b2ed646e3bd9a8d0a88db4b36a31ff1c0fa4a865a83d00d676cf80032 +size 5157 diff --git a/project.godot b/project.godot index a9234d7..7e196d1 100644 --- a/project.godot +++ b/project.godot @@ -53,6 +53,15 @@ window/size/viewport_height=800 window/stretch/mode="canvas_items" window/stretch/aspect="keep_height" +[editor] + +version_control/plugin_name="GitPlugin" +version_control/autoload_on_startup=true + +[editor_plugins] + +enabled=PackedStringArray() + [input] player_controller_left={ diff --git a/terrain_instance_3d.gd b/terrain_instance_3d.gd index 9680b6f..4cc1949 100644 --- a/terrain_instance_3d.gd +++ b/terrain_instance_3d.gd @@ -1,6 +1,8 @@ @tool class_name TerrainInstance3D extends GeometryInstance3D +const _TERRAIN_MAX := 1024 + var _mesh := PlaneMesh.new() var _material := ShaderMaterial.new() @@ -14,18 +16,22 @@ var size: Vector2i = Vector2i.ZERO: return size set(value): - var width := value.x - var height := value.y + var width := clampi(value.x, 0, _TERRAIN_MAX) + var height := clampi(value.y, 0, _TERRAIN_MAX) - if (width != 0) and (height != 0): - if (width != size.x) or (height != size.y): + if (width != size.x) or (height != size.y): + if (width == 0) and (height == 0): + RenderingServer.instance_set_base(self.get_instance(), RID()) + + else: self._mesh.subdivide_width = width self._mesh.subdivide_depth = height self._mesh.size = value self._material.set_shader_parameter("SIZE", Vector2(value)) + RenderingServer.instance_set_base(self.get_instance(), self._mesh) - size = value + size = Vector2i(width, height) ## ## @@ -161,4 +167,3 @@ func _init() -> void: self._material.shader = preload("res://terrain_shader.gdshader") self._mesh.surface_set_material(0, self._material) - RenderingServer.instance_set_base(self.get_instance(), self._mesh)