Now the uv preview will show the mesh data instance's active texture as a background.

This commit is contained in:
Relintai 2022-01-20 00:21:23 +01:00
parent b2e6c037f4
commit 1f48d44a5f
4 changed files with 22 additions and 7 deletions

View File

@ -3,16 +3,20 @@ extends Control
var plugin : EditorPlugin 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(): 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: func set_mesh_data_resource(a : MeshDataResource) -> void:
if uv_editor: if uv_preview:
uv_editor.set_mesh_data_resource(a) 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: func _unhandled_key_input(event : InputEventKey) -> void:
if event.echo: if event.echo:

View File

@ -12,7 +12,7 @@ script = ExtResource( 1 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_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="."] [node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 7.0 margin_left = 7.0

View File

@ -2,6 +2,7 @@ tool
extends Control extends Control
var mesh_data_resource : MeshDataResource = null setget set_mesh_data_resource var mesh_data_resource : MeshDataResource = null setget set_mesh_data_resource
var background_texture : Texture = null
func set_mesh_data_resource(a : MeshDataResource): func set_mesh_data_resource(a : MeshDataResource):
if mesh_data_resource: if mesh_data_resource:
@ -13,17 +14,26 @@ func set_mesh_data_resource(a : MeshDataResource):
mesh_data_resource.connect("changed", self, "on_mdr_changed") mesh_data_resource.connect("changed", self, "on_mdr_changed")
update() update()
func set_mesh_data_instance(a : MeshDataInstance):
if !a:
background_texture = null
background_texture = a.texture
func on_mdr_changed(): func on_mdr_changed():
update() update()
func _draw(): 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: if !mesh_data_resource:
return return
if mesh_data_resource.array.size() != ArrayMesh.ARRAY_MAX: if mesh_data_resource.array.size() != ArrayMesh.ARRAY_MAX:
return return
var uvs : PoolVector2Array = mesh_data_resource.array[ArrayMesh.ARRAY_TEX_UV] var uvs : PoolVector2Array = mesh_data_resource.array[ArrayMesh.ARRAY_TEX_UV]
var indices : PoolIntArray = mesh_data_resource.array[ArrayMesh.ARRAY_INDEX] var indices : PoolIntArray = mesh_data_resource.array[ArrayMesh.ARRAY_INDEX]

View File

@ -63,6 +63,7 @@ func edit(object):
if mdi: if mdi:
mdi_ed_gui.set_mesh_data_resource(mdi.mesh_data) mdi_ed_gui.set_mesh_data_resource(mdi.mesh_data)
mdi_ed_gui.set_mesh_data_instance(mdi)
func make_visible(visible): func make_visible(visible):
#print("make_visible") #print("make_visible")