Skip to content

Commit

Permalink
using new lighter paths for faster editing
Browse files Browse the repository at this point in the history
  • Loading branch information
AsherGlick committed Jul 28, 2021
1 parent bd38691 commit 4faec5b
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 135 deletions.
31 changes: 13 additions & 18 deletions Gizmo/PointEdit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ extends Spatial
var camera: Camera
signal selected(selected_object)
signal deselected(selected_object)

var last_translation
var selected: bool = false


func clear_selection():
self.selected = false
$Node/CollisionShape.disabled = false
Expand All @@ -15,6 +16,7 @@ func clear_selection():
$Pillar/CollisionShape.disabled = true
emit_signal("deselected", self)


func select(camera, event):
self.selected = true
self.camera = camera
Expand All @@ -30,6 +32,7 @@ var object_2d_link = null
var object_index:int = 0
var point_type: String


func link_point(point_type: String, object_link, object_2d_link = null, object_index = 0):
self.point_type = point_type
self.object_link = object_link
Expand All @@ -39,24 +42,16 @@ func link_point(point_type: String, object_link, object_2d_link = null, object_i
if point_type == "icon":
pass


func update_point():
if point_type == "path" || point_type == "area":
# Regeneration of 3d paths can take a while and will cause lag if we
# try to update it every frame. Instead we only update it if the mouse
# is not pressed (dragging a node) and if the position is different
# from what is used to be. There may be a better way to generate paths
# in the future that is less resource intensive but the original
# solution was chosen for its implementation speed instead of its
# generation speed.
if (
self.object_link.curve.get_point_position(self.object_index) != self.translation
and not Input.is_mouse_button_pressed( 1 )
):
self.object_link.curve.set_point_position(self.object_index, self.translation)

self.object_2d_link.points[self.object_index] = Vector2(self.translation.x, self.translation.z)
if point_type == "icon":
self.object_link.translation = self.translation
if self.translation != self.last_translation:
if point_type == "path" || point_type == "area":
self.object_link.set_point_position(self.object_index, self.translation)
self.object_2d_link.points[self.object_index] = Vector2(self.translation.x, self.translation.z)
if point_type == "icon":
self.object_link.translation = self.translation
print("update")
self.last_translation = self.translation


################################################################################
Expand Down
56 changes: 3 additions & 53 deletions Path.tscn
Original file line number Diff line number Diff line change
@@ -1,58 +1,8 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=3 format=2]

[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Route.tres" type="Material" id=1]
[ext_resource path="res://Path.gd" type="Script" id=2]

[sub_resource type="Shader" id=1]
code = "shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
//render_mode unshaded, blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;

uniform sampler2D texture_albedo : hint_albedo; // TODO: Make instance uniform sampler2D when 4.0 is released
uniform vec2 map_size;
uniform bool map_flipped;
uniform float map_bottom_offset = 36.0;

uniform float interval = 1.0;

void vertex() {}




void fragment() {
if (SCREEN_UV.x * VIEWPORT_SIZE.x > VIEWPORT_SIZE.x - map_size.x) {
if (map_flipped && SCREEN_UV.y * VIEWPORT_SIZE.y > VIEWPORT_SIZE.y - map_size.y) {
return;
}
if (!map_flipped && SCREEN_UV.y * VIEWPORT_SIZE.y < map_size.y + map_bottom_offset) {
return;
}
}




vec2 base_uv = vec2(UV.y, -UV.x * interval);
vec4 albedo_tex = texture(texture_albedo,base_uv);
ALBEDO = albedo_tex.rgb;
ALPHA = albedo_tex.a;
EMISSION = albedo_tex.rgb;
METALLIC = 0.0;
ROUGHNESS = 1.0;
SPECULAR = 0.0;
}
"

[sub_resource type="ShaderMaterial" id=2]
resource_local_to_scene = true
shader = SubResource( 1 )
shader_param/map_size = Vector2( 0, 0 )
shader_param/map_flipped = null
shader_param/map_bottom_offset = 36.0
shader_param/interval = 1.0
shader_param/texture_albedo = ExtResource( 1 )

[node name="Path" type="Path"]
curve = null
script = ExtResource( 2 )
Expand All @@ -69,4 +19,4 @@ path_local = false
path_continuous_u = false
path_joined = false
smooth_faces = true
material = SubResource( 2 )
material = ExtResource( 1 )
82 changes: 82 additions & 0 deletions Route.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
extends Spatial

var texture_path

var color = Color(0.9, 0.1, 0.1)

var point_list := PoolVector3Array()

func create_mesh(point_list: PoolVector3Array):
self.point_list = point_list
refresh_mesh()

func refresh_mesh():
var tmpMesh = Mesh.new()
var i = 0
var last_uv: float = 0.0
for point_index in range(len(point_list)-1):
var point:Vector3 = point_list[point_index]
var next_point:Vector3 = point_list[point_index+1]

var distance: float = point.distance_to(next_point)
var normal: Vector3 = (next_point - point).normalized()
#print(normal)
var horizontal_tangent:Vector3 = Vector3(normal.z, 0, -normal.x).normalized()

normal = Vector3(0,0,0)

var point1: Vector3 = point + normal/2 - horizontal_tangent/2
var point2: Vector3 = point + normal/2 + horizontal_tangent/2
var point3: Vector3 = next_point - normal/2 + horizontal_tangent/2
var point4: Vector3 = next_point - normal/2 - horizontal_tangent/2

var vertices = PoolVector3Array()
var UVs = PoolVector2Array()

vertices.push_back(point1)
vertices.push_back(point2)
vertices.push_back(point3)
vertices.push_back(point4)

var next_uv = last_uv + distance

UVs.push_back(Vector2(1,last_uv))
UVs.push_back(Vector2(0,last_uv))
UVs.push_back(Vector2(0,next_uv))
UVs.push_back(Vector2(1,next_uv))

last_uv = next_uv
if last_uv > 100:
last_uv = last_uv-100

var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLE_FAN)

for v in vertices.size():
st.add_color(color)
st.add_uv(UVs[v])
st.add_vertex(vertices[v])
st.commit(tmpMesh)
$MeshInstance.mesh = tmpMesh


func update_point_vertical(index, y_value):
pass

func reverse():
self.point_list.invert()
refresh_mesh()

func get_point_count():
return len(self.point_list)

func get_point_position(index: int):
return self.point_list[index]

func set_point_position(index: int, position: Vector3):
self.point_list[index] = position
create_mesh(self.point_list)

func set_texture(texture):
$MeshInstance.material_override.set_shader_param("texture_albedo", texture)

51 changes: 51 additions & 0 deletions Route.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[gd_resource type="ShaderMaterial" load_steps=3 format=2]

[ext_resource path="res://icon.png" type="Texture" id=1]

[sub_resource type="Shader" id=1]
code = "shader_type spatial;
//render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
render_mode unshaded, blend_mix, depth_draw_opaque, cull_disabled, diffuse_burley, specular_schlick_ggx;

uniform sampler2D texture_albedo : hint_albedo; // TODO: Make instance uniform sampler2D when 4.0 is released
uniform vec2 map_size;
uniform bool map_flipped;
uniform float map_bottom_offset = 36.0;

uniform float interval = 1.0;

void vertex() {}




void fragment() {
if (SCREEN_UV.x * VIEWPORT_SIZE.x > VIEWPORT_SIZE.x - map_size.x) {
if (map_flipped && SCREEN_UV.y * VIEWPORT_SIZE.y > VIEWPORT_SIZE.y - map_size.y) {
return;
}
if (!map_flipped && SCREEN_UV.y * VIEWPORT_SIZE.y < map_size.y + map_bottom_offset) {
return;
}
}

vec2 base_uv = vec2(UV.y, -UV.x * interval);
base_uv = vec2(UV.x, -UV.y);
vec4 albedo_tex = texture(texture_albedo,base_uv);
ALBEDO = albedo_tex.rgb;
ALPHA = albedo_tex.a;
//EMISSION = albedo_tex.rgb;
//METALLIC = 0.0;
//ROUGHNESS = 1.0;
//SPECULAR = 0.0;
}
"

[resource]
resource_local_to_scene = true
shader = SubResource( 1 )
shader_param/map_size = Vector2( 0, 0 )
shader_param/map_flipped = null
shader_param/map_bottom_offset = 36.0
shader_param/interval = 1.0
shader_param/texture_albedo = ExtResource( 1 )
10 changes: 10 additions & 0 deletions Route.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://Route.gd" type="Script" id=1]
[ext_resource path="res://Route.tres" type="Material" id=2]

[node name="Path" type="Spatial"]
script = ExtResource( 1 )

[node name="MeshInstance" type="MeshInstance" parent="."]
material_override = ExtResource( 2 )
2 changes: 1 addition & 1 deletion Path2D.tscn → Route2D.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
render_mode blend_mix;
render_mode unshaded,blend_mix;

uniform vec2 minimap_corner;
uniform vec2 minimap_corner2;
Expand Down
Loading

0 comments on commit 4faec5b

Please sign in to comment.