From 3e2cf691f3529e6035411a660a1e5a2918278e4d Mon Sep 17 00:00:00 2001 From: Rendo Date: Tue, 15 Jul 2025 21:47:33 +0500 Subject: [PATCH] Editor rotational sprite, 2d calculations --- base/assets/test_enemy/0001.png.import | 13 ++++++------ base/assets/test_enemy/0002.png.import | 13 ++++++------ base/assets/test_enemy/0003.png.import | 13 ++++++------ base/assets/test_enemy/0004.png.import | 13 ++++++------ base/assets/test_enemy/0005.png.import | 13 ++++++------ base/assets/test_enemy/0006.png.import | 13 ++++++------ base/assets/test_enemy/0007.png.import | 13 ++++++------ base/scenes/enemies/test_enemy.tscn | 21 +++----------------- base/scripts/enemies/directional_sprite3d.gd | 10 +++++++--- 9 files changed, 59 insertions(+), 63 deletions(-) diff --git a/base/assets/test_enemy/0001.png.import b/base/assets/test_enemy/0001.png.import index 7821615..c00daad 100644 --- a/base/assets/test_enemy/0001.png.import +++ b/base/assets/test_enemy/0001.png.import @@ -3,25 +3,26 @@ importer="texture" type="CompressedTexture2D" uid="uid://bp7iec52kc0ko" -path="res://.godot/imported/0001.png-b37bf2a8d5a87496e9149209ad9d9645.ctex" +path.s3tc="res://.godot/imported/0001.png-b37bf2a8d5a87496e9149209ad9d9645.s3tc.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc"], +"vram_texture": true } [deps] source_file="res://base/assets/test_enemy/0001.png" -dest_files=["res://.godot/imported/0001.png-b37bf2a8d5a87496e9149209ad9d9645.ctex"] +dest_files=["res://.godot/imported/0001.png-b37bf2a8d5a87496e9149209ad9d9645.s3tc.ctex"] [params] -compress/mode=0 +compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 -mipmaps/generate=false +mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" @@ -31,4 +32,4 @@ process/normal_map_invert_y=false process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 -detect_3d/compress_to=1 +detect_3d/compress_to=0 diff --git a/base/assets/test_enemy/0002.png.import b/base/assets/test_enemy/0002.png.import index 9f94d9b..999c6a6 100644 --- a/base/assets/test_enemy/0002.png.import +++ b/base/assets/test_enemy/0002.png.import @@ -3,25 +3,26 @@ importer="texture" type="CompressedTexture2D" uid="uid://bmjanur1y65ut" -path="res://.godot/imported/0002.png-9b12b65d0c4a70fdde18f69d2bbccc91.ctex" +path.s3tc="res://.godot/imported/0002.png-9b12b65d0c4a70fdde18f69d2bbccc91.s3tc.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc"], +"vram_texture": true } [deps] source_file="res://base/assets/test_enemy/0002.png" -dest_files=["res://.godot/imported/0002.png-9b12b65d0c4a70fdde18f69d2bbccc91.ctex"] +dest_files=["res://.godot/imported/0002.png-9b12b65d0c4a70fdde18f69d2bbccc91.s3tc.ctex"] [params] -compress/mode=0 +compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 -mipmaps/generate=false +mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" @@ -31,4 +32,4 @@ process/normal_map_invert_y=false process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 -detect_3d/compress_to=1 +detect_3d/compress_to=0 diff --git a/base/assets/test_enemy/0003.png.import b/base/assets/test_enemy/0003.png.import index af2bf0a..5e17830 100644 --- a/base/assets/test_enemy/0003.png.import +++ b/base/assets/test_enemy/0003.png.import @@ -3,25 +3,26 @@ importer="texture" type="CompressedTexture2D" uid="uid://csyoosmr6c251" -path="res://.godot/imported/0003.png-1f669fd5f649d54756b5d5cbb6d54ede.ctex" +path.s3tc="res://.godot/imported/0003.png-1f669fd5f649d54756b5d5cbb6d54ede.s3tc.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc"], +"vram_texture": true } [deps] source_file="res://base/assets/test_enemy/0003.png" -dest_files=["res://.godot/imported/0003.png-1f669fd5f649d54756b5d5cbb6d54ede.ctex"] +dest_files=["res://.godot/imported/0003.png-1f669fd5f649d54756b5d5cbb6d54ede.s3tc.ctex"] [params] -compress/mode=0 +compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 -mipmaps/generate=false +mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" @@ -31,4 +32,4 @@ process/normal_map_invert_y=false process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 -detect_3d/compress_to=1 +detect_3d/compress_to=0 diff --git a/base/assets/test_enemy/0004.png.import b/base/assets/test_enemy/0004.png.import index f1e2020..2f8abf1 100644 --- a/base/assets/test_enemy/0004.png.import +++ b/base/assets/test_enemy/0004.png.import @@ -3,25 +3,26 @@ importer="texture" type="CompressedTexture2D" uid="uid://8ijiv8ly74jg" -path="res://.godot/imported/0004.png-2fc0af59b10bb4de39b70e455e5a56ba.ctex" +path.s3tc="res://.godot/imported/0004.png-2fc0af59b10bb4de39b70e455e5a56ba.s3tc.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc"], +"vram_texture": true } [deps] source_file="res://base/assets/test_enemy/0004.png" -dest_files=["res://.godot/imported/0004.png-2fc0af59b10bb4de39b70e455e5a56ba.ctex"] +dest_files=["res://.godot/imported/0004.png-2fc0af59b10bb4de39b70e455e5a56ba.s3tc.ctex"] [params] -compress/mode=0 +compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 -mipmaps/generate=false +mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" @@ -31,4 +32,4 @@ process/normal_map_invert_y=false process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 -detect_3d/compress_to=1 +detect_3d/compress_to=0 diff --git a/base/assets/test_enemy/0005.png.import b/base/assets/test_enemy/0005.png.import index cd3d2cc..9473853 100644 --- a/base/assets/test_enemy/0005.png.import +++ b/base/assets/test_enemy/0005.png.import @@ -3,25 +3,26 @@ importer="texture" type="CompressedTexture2D" uid="uid://lbo6ygri22or" -path="res://.godot/imported/0005.png-ea4e5800e69dcb3db9c74e0d36f7dada.ctex" +path.s3tc="res://.godot/imported/0005.png-ea4e5800e69dcb3db9c74e0d36f7dada.s3tc.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc"], +"vram_texture": true } [deps] source_file="res://base/assets/test_enemy/0005.png" -dest_files=["res://.godot/imported/0005.png-ea4e5800e69dcb3db9c74e0d36f7dada.ctex"] +dest_files=["res://.godot/imported/0005.png-ea4e5800e69dcb3db9c74e0d36f7dada.s3tc.ctex"] [params] -compress/mode=0 +compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 -mipmaps/generate=false +mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" @@ -31,4 +32,4 @@ process/normal_map_invert_y=false process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 -detect_3d/compress_to=1 +detect_3d/compress_to=0 diff --git a/base/assets/test_enemy/0006.png.import b/base/assets/test_enemy/0006.png.import index 86a3a56..5cc4ffc 100644 --- a/base/assets/test_enemy/0006.png.import +++ b/base/assets/test_enemy/0006.png.import @@ -3,25 +3,26 @@ importer="texture" type="CompressedTexture2D" uid="uid://bu54h8g5r50qp" -path="res://.godot/imported/0006.png-5ea93347fb4075fdeb67e91f967d8081.ctex" +path.s3tc="res://.godot/imported/0006.png-5ea93347fb4075fdeb67e91f967d8081.s3tc.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc"], +"vram_texture": true } [deps] source_file="res://base/assets/test_enemy/0006.png" -dest_files=["res://.godot/imported/0006.png-5ea93347fb4075fdeb67e91f967d8081.ctex"] +dest_files=["res://.godot/imported/0006.png-5ea93347fb4075fdeb67e91f967d8081.s3tc.ctex"] [params] -compress/mode=0 +compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 -mipmaps/generate=false +mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" @@ -31,4 +32,4 @@ process/normal_map_invert_y=false process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 -detect_3d/compress_to=1 +detect_3d/compress_to=0 diff --git a/base/assets/test_enemy/0007.png.import b/base/assets/test_enemy/0007.png.import index ee32c91..10e9944 100644 --- a/base/assets/test_enemy/0007.png.import +++ b/base/assets/test_enemy/0007.png.import @@ -3,25 +3,26 @@ importer="texture" type="CompressedTexture2D" uid="uid://c57drlhnuicu5" -path="res://.godot/imported/0007.png-c700fd2bc75a43d8fec1237ad0c34562.ctex" +path.s3tc="res://.godot/imported/0007.png-c700fd2bc75a43d8fec1237ad0c34562.s3tc.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc"], +"vram_texture": true } [deps] source_file="res://base/assets/test_enemy/0007.png" -dest_files=["res://.godot/imported/0007.png-c700fd2bc75a43d8fec1237ad0c34562.ctex"] +dest_files=["res://.godot/imported/0007.png-c700fd2bc75a43d8fec1237ad0c34562.s3tc.ctex"] [params] -compress/mode=0 +compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 -mipmaps/generate=false +mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" @@ -31,4 +32,4 @@ process/normal_map_invert_y=false process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 -detect_3d/compress_to=1 +detect_3d/compress_to=0 diff --git a/base/scenes/enemies/test_enemy.tscn b/base/scenes/enemies/test_enemy.tscn index 757ab89..50d7454 100644 --- a/base/scenes/enemies/test_enemy.tscn +++ b/base/scenes/enemies/test_enemy.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://twqkevpn0q1a"] +[gd_scene load_steps=10 format=3 uid="uid://twqkevpn0q1a"] [ext_resource type="Texture2D" uid="uid://b0gyyb6xwfjex" path="res://base/assets/test_enemy/0000.png" id="1_7qny8"] [ext_resource type="Script" uid="uid://j0w37fjl13ox" path="res://base/scripts/enemies/directional_sprite3d.gd" id="2_hmq60"] @@ -10,16 +10,6 @@ [ext_resource type="Texture2D" uid="uid://bu54h8g5r50qp" path="res://base/assets/test_enemy/0006.png" id="8_snoby"] [ext_resource type="Texture2D" uid="uid://c57drlhnuicu5" path="res://base/assets/test_enemy/0007.png" id="9_83myg"] -[sub_resource type="GDScript" id="GDScript_hmq60"] -resource_name = "temp_script" -script/source = "extends Node3D - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - rotate_y(TAU*delta) -" - [node name="TestEnemy" type="Node3D"] [node name="RotationalSprite" type="Sprite3D" parent="."] @@ -35,11 +25,6 @@ rotations = Dictionary[float, Texture2D]({ 3.14159: ExtResource("1_7qny8"), 3.92699: ExtResource("3_rvsun"), 4.71239: ExtResource("4_ajcop"), -5.49779: ExtResource("5_xto1v") +5.49779: ExtResource("5_xto1v"), +6.28319: ExtResource("6_d1vpv") }) - -[node name="Node3D" type="Node3D" parent="."] -script = SubResource("GDScript_hmq60") - -[node name="Camera3D" type="Camera3D" parent="Node3D"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2.19268) diff --git a/base/scripts/enemies/directional_sprite3d.gd b/base/scripts/enemies/directional_sprite3d.gd index cbfc869..0ea3170 100644 --- a/base/scripts/enemies/directional_sprite3d.gd +++ b/base/scripts/enemies/directional_sprite3d.gd @@ -5,9 +5,10 @@ extends Sprite3D @export var rotations : Dictionary[float,Texture2D] func _process(delta: float) -> void: - if Engine.is_editor_hint(): return var camera = get_viewport().get_camera_3d() - var rotation_to_camera = global_transform.basis.z.signed_angle_to(camera.global_position,Vector3.UP) + PI + if Engine.is_editor_hint(): + camera = EditorInterface.get_editor_viewport_3d().get_camera_3d() + var rotation_to_camera = -vec3_to_vec2(global_transform.basis.z).angle_to(vec3_to_vec2(camera.global_position)) + PI var chosen_index = 0 for i in rotations.keys(): if abs(rotation_to_camera-i) < abs(rotation_to_camera-chosen_index): @@ -19,5 +20,8 @@ func _process(delta: float) -> void: func entry_generator(): rotations.clear() - for i in range(rotation_count): + for i in range(rotation_count+1): rotations[TAU/rotation_count*i] = Texture2D.new() + +func vec3_to_vec2(vector : Vector3) -> Vector2: + return Vector2(vector.x,vector.z).normalized()