From 1f48d44a5fe36b12d7f3cc82510d3b5ce3f19012 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 20 Jan 2022 00:21:23 +0100 Subject: [PATCH] Now the uv preview will show the mesh data instance's active texture as a background. --- game/addons/mesh_data_resource_editor/MDIEd.gd | 14 +++++++++----- game/addons/mesh_data_resource_editor/MDIEd.tscn | 2 +- game/addons/mesh_data_resource_editor/UVEditor.gd | 12 +++++++++++- game/addons/mesh_data_resource_editor/plugin.gd | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/game/addons/mesh_data_resource_editor/MDIEd.gd b/game/addons/mesh_data_resource_editor/MDIEd.gd index da269a0d..fa281849 100644 --- a/game/addons/mesh_data_resource_editor/MDIEd.gd +++ b/game/addons/mesh_data_resource_editor/MDIEd.gd @@ -3,16 +3,20 @@ extends Control var plugin : EditorPlugin -export var uv_editor_path : NodePath +export var uv_preview_path : NodePath -var uv_editor : Node +var uv_preview : Node func _enter_tree(): - uv_editor = get_node(uv_editor_path) + uv_preview = get_node(uv_preview_path) func set_mesh_data_resource(a : MeshDataResource) -> void: - if uv_editor: - uv_editor.set_mesh_data_resource(a) + if uv_preview: + uv_preview.set_mesh_data_resource(a) + +func set_mesh_data_instance(a : MeshDataInstance) -> void: + if uv_preview: + uv_preview.set_mesh_data_instance(a) func _unhandled_key_input(event : InputEventKey) -> void: if event.echo: diff --git a/game/addons/mesh_data_resource_editor/MDIEd.tscn b/game/addons/mesh_data_resource_editor/MDIEd.tscn index 5fadd24b..2804b8c2 100644 --- a/game/addons/mesh_data_resource_editor/MDIEd.tscn +++ b/game/addons/mesh_data_resource_editor/MDIEd.tscn @@ -12,7 +12,7 @@ script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } -uv_editor_path = NodePath("VBoxContainer/ScrollContainer/VBoxContainer2/Operations/Operations/UVDisplay") +uv_preview_path = NodePath("VBoxContainer/ScrollContainer/VBoxContainer2/Operations/Operations/UVDisplay") [node name="VBoxContainer" type="VBoxContainer" parent="."] margin_left = 7.0 diff --git a/game/addons/mesh_data_resource_editor/UVEditor.gd b/game/addons/mesh_data_resource_editor/UVEditor.gd index 7b6e566a..b04cef43 100644 --- a/game/addons/mesh_data_resource_editor/UVEditor.gd +++ b/game/addons/mesh_data_resource_editor/UVEditor.gd @@ -2,6 +2,7 @@ tool extends Control var mesh_data_resource : MeshDataResource = null setget set_mesh_data_resource +var background_texture : Texture = null func set_mesh_data_resource(a : MeshDataResource): if mesh_data_resource: @@ -13,17 +14,26 @@ func set_mesh_data_resource(a : MeshDataResource): mesh_data_resource.connect("changed", self, "on_mdr_changed") update() + +func set_mesh_data_instance(a : MeshDataInstance): + if !a: + background_texture = null + + background_texture = a.texture func on_mdr_changed(): update() func _draw(): + if background_texture: + draw_texture_rect_region(background_texture, Rect2(Vector2(), get_size()), Rect2(Vector2(), background_texture.get_size())) + if !mesh_data_resource: return if mesh_data_resource.array.size() != ArrayMesh.ARRAY_MAX: return - + var uvs : PoolVector2Array = mesh_data_resource.array[ArrayMesh.ARRAY_TEX_UV] var indices : PoolIntArray = mesh_data_resource.array[ArrayMesh.ARRAY_INDEX] diff --git a/game/addons/mesh_data_resource_editor/plugin.gd b/game/addons/mesh_data_resource_editor/plugin.gd index 3f0aa1e1..98f4fecb 100644 --- a/game/addons/mesh_data_resource_editor/plugin.gd +++ b/game/addons/mesh_data_resource_editor/plugin.gd @@ -63,6 +63,7 @@ func edit(object): if mdi: mdi_ed_gui.set_mesh_data_resource(mdi.mesh_data) + mdi_ed_gui.set_mesh_data_instance(mdi) func make_visible(visible): #print("make_visible")