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

Map icons #47

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
15 changes: 3 additions & 12 deletions Icon.gd
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
extends Sprite3D

const Utils = preload("utils.gd")

var texture_path
func set_icon_image(texture_path: String):
self.texture_path = texture_path

var texture_file = File.new()
var image = Image.new()
texture_file.open(texture_path, File.READ)
image.load_png_from_buffer(texture_file.get_buffer(texture_file.get_len()))
texture_file.close()
image.lock()

var texture = ImageTexture.new()
texture.create_from_image(image) #, 6)


var texture = Utils.new().generate_texture(texture_path)
self.texture = texture
self.material_override.set_shader_param("texture_albedo", texture)
10 changes: 10 additions & 0 deletions Icon2D.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Sprite

const Utils = preload("utils.gd")

func set_icon_image(texture_path: String):
var texture = Utils.new().generate_texture(texture_path)
self.texture = texture
# TODO: Figure out a better heuristic. Why 0.2?
var scaling_factor = 0.1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the complexity that prevented me from doing this in the previous version. Maybe look at what taco or blish hud does for this? I do not know what the right answer is.

self.apply_scale(Vector2(scaling_factor, scaling_factor))
29 changes: 29 additions & 0 deletions Icon2D.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Icon2D.gd" type="Script" id=1]

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

uniform vec2 minimap_corner;
uniform vec2 minimap_corner2;

void fragment() {
COLOR = vec4(0,0,0,0);
vec2 screen_pixel_size = vec2(textureSize(SCREEN_TEXTURE, 0));
vec2 screen_pixel = SCREEN_UV * screen_pixel_size;
if (screen_pixel.x > minimap_corner.x && screen_pixel.x < minimap_corner2.x
&& screen_pixel.y > minimap_corner.y && screen_pixel.y < minimap_corner2.y) {
COLOR = texture(TEXTURE, vec2(UV.y, -UV.x));
}
}"

[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
shader_param/minimap_corner = Vector2( 0, 0 )
shader_param/minimap_corner2 = Vector2( 0, 0 )

[node name="Icon2D" type="Sprite"]
material = SubResource( 2 )
script = ExtResource( 1 )
11 changes: 9 additions & 2 deletions Spatial.gd
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ func reset_minimap_masks():
compass_corner2 = compass_corner1 + Vector2(compass_width, compass_height)

for minimap_path in $Control/MiniMap.get_children():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename. It's not just minimap_path now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the non minimap I have the two types split into different parent nodes.

Burrito/Spatial.gd

Lines 410 to 417 in 55fff1e

for path in paths.get_children():
path.queue_free()
for path2d in minimap.get_children():
path2d.queue_free()
for icon in icons.get_children():
icon.queue_free()

Maybe it makes sense to also do that for the minimap now that it will have icons.

minimap_path.material.set_shader_param("minimap_corner", compass_corner1)
minimap_path.material.set_shader_param("minimap_corner2", compass_corner2)
if minimap_path.material != null:
minimap_path.material.set_shader_param("minimap_corner", compass_corner1)
minimap_path.material.set_shader_param("minimap_corner2", compass_corner2)

var markerdata = {}
var marker_file_path = ""
Expand Down Expand Up @@ -329,6 +330,7 @@ var route_scene = load("res://Route.tscn")
var icon_scene = load("res://Icon.tscn")
var path2d_scene = load("res://Route2D.tscn")
var gizmo_scene = load("res://Gizmo/PointEdit.tscn")
var icon2d_scene = load("res://Icon2D.tscn")

##########Gizmo Stuff###########
# How long the ray to search for 3D clickable object should be.
Expand Down Expand Up @@ -501,6 +503,11 @@ func gen_new_icon(position: Vector3, texture_path: String):
#icon_markers.append(new_icon)
icons.add_child(new_icon)

var minimap_icon = icon2d_scene.instance()
minimap_icon.set_position(Vector2(position[0], position[2]))
minimap_icon.set_icon_image(texture_path)
minimap.add_child(minimap_icon)

# This function take all of the currently rendered objects and converts it into
# the data format that is saved/loaded from.
func data_from_renderview():
Expand Down
18 changes: 11 additions & 7 deletions Spatial.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=2]
[gd_scene load_steps=18 format=2]

[ext_resource path="res://Spatial.gd" type="Script" id=1]
[ext_resource path="res://shaders/range_indicators.shader" type="Shader" id=2]
Expand All @@ -12,6 +12,7 @@
[ext_resource path="res://icon_new_path.png" type="Texture" id=10]
[ext_resource path="res://icon_new_point.png" type="Texture" id=11]
[ext_resource path="res://SettingsDialog.gd" type="Script" id=12]
[ext_resource path="res://Icon2D.gd" type="Script" id=13]

[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
Expand Down Expand Up @@ -70,6 +71,9 @@ scale = Vector2( 2, 2 )

[node name="Line2D" parent="Control/MiniMap" instance=ExtResource( 4 )]

[node name="Icon2D" type="Sprite" parent="Control/MiniMap"]
script = ExtResource( 13 )

[node name="GlobalMenuButton" type="Control" parent="Control"]
margin_left = 287.348
margin_right = 314.348
Expand Down Expand Up @@ -185,9 +189,9 @@ margin_bottom = 672.0
window_title = "Open a File"
mode = 0
access = 2
current_dir = "."
current_dir = "/home/jl/Projects/Burrito"
current_file = "."
current_path = "."
current_path = "/home/jl/Projects/Burrito/."
__meta__ = {
"_edit_use_anchors_": false
}
Expand Down Expand Up @@ -483,9 +487,9 @@ window_title = "Open a File"
mode = 0
access = 2
filters = PoolStringArray( "*.png" )
current_dir = "."
current_dir = "/home/jl/Projects/Burrito"
current_file = "."
current_path = "."
current_path = "/home/jl/Projects/Burrito/."
__meta__ = {
"_edit_use_anchors_": false
}
Expand All @@ -498,9 +502,9 @@ margin_bottom = 624.833
window_title = "Save Path"
resizable = true
access = 2
current_dir = "."
current_dir = "/home/jl/Projects/Burrito"
current_file = "."
current_path = "."
current_path = "/home/jl/Projects/Burrito/."
__meta__ = {
"_edit_use_anchors_": false
}
Expand Down
6 changes: 6 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ _global_script_classes=[ {
"language": "NativeScript",
"path": "res://tacoparser.gdns"
}, {
"base": "Reference",
"class": "Utils",
"language": "GDScript",
"path": "res://utils.gd"
}, {
"base": "",
"class": "X11_FG",
"language": "NativeScript",
"path": "res://Spatial.gdns"
} ]
_global_script_class_icons={
"TacoParser": "",
"Utils": "",
"X11_FG": ""
}

Expand Down
16 changes: 16 additions & 0 deletions utils.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class_name Utils

func load_image_from_path(path: String):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance I can convince you to use the same texture loaders for both the icon textures and the path textures? It would be a nice decrease in complexity. Also take a look at #19 to make sure that your solution is compatible with that eventual goal, otherwise the texture loading might need to be rewritten again at a later date.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, have attempted to reuse the util function for both paths and icons. Also accept another parameter, RGB vs sRGB and added 2d and 3d textures for paths.

var file = File.new()
var image = Image.new()
file.open(path, File.READ)
image.load_png_from_buffer(file.get_buffer(file.get_len()))
file.close()
image.lock()
return image

func generate_texture(texture_path: String):
var image = load_image_from_path(texture_path)
var texture = ImageTexture.new()
texture.create_from_image(image)
return texture