diff --git a/src/components/controls/LoopControls.gd b/src/components/controls/LoopControls.gd index b4b7471..bc6e576 100644 --- a/src/components/controls/LoopControls.gd +++ b/src/components/controls/LoopControls.gd @@ -104,6 +104,7 @@ func _process(delta: float) -> void: else: handle_free_spin_input(delta) +# TODO make statc func handle_free_spin_input(delta: float): var rotation: Quaternion var rs := ROTATION_SPEED / 10. * delta diff --git a/src/components/utils/Op.gd b/src/components/utils/Op.gd index d210830..636c5e3 100644 --- a/src/components/utils/Op.gd +++ b/src/components/utils/Op.gd @@ -6,4 +6,4 @@ static func xor(arg1: bool, arg2: bool) -> bool: return arg1 != arg2 static func v3(arr: Array) -> Vector3: - return Vector3(arr[0], arr[3], arr[2]) + return Vector3(arr[0], arr[1], arr[2]) diff --git a/src/components/utils/ShaderUtils.gd b/src/components/utils/ShaderUtils.gd index 0c4cc2e..3b22d4e 100644 --- a/src/components/utils/ShaderUtils.gd +++ b/src/components/utils/ShaderUtils.gd @@ -3,6 +3,8 @@ class_name ShaderUtils static func set_shader_param(node: MeshInstance3D, _name: String, value: Variant, idx: int = 0): var m = node.get_active_material(0) as ShaderMaterial + if not m: + return if idx == 0: m.set_shader_parameter(_name, value) elif idx == 1 and m.next_pass: @@ -18,8 +20,16 @@ static func create_shader_material(_shader: Shader) -> ShaderMaterial: sm.shader = _shader return sm -static func apply_shaders(_shaders: Array[Shader], node: MeshInstance3D) -> MeshInstance3D: +static func apply_shaders(_shaders: Array, node: MeshInstance3D) -> MeshInstance3D: for i in _shaders.size(): var m := create_shader_material(_shaders[i]) - node.set("material_override" + "/next_pass".repeat(i), m) +# TODO: figure out how to do it w/ set and property path + #node.set("material_override" + ":next_pass".repeat(i), m) + match i: + 0: node.material_override = m + 1: node.material_override.next_pass = m + 2: node.material_override.next_pass.next_pass = m + 3: node.material_override.next_pass.next_pass.next_pass = m + 4: node.material_override.next_pass.next_pass.next_pass.next_pass = m + 5: node.material_override.next_pass.next_pass.next_pass.next_pass.next_pass = m return node diff --git a/src/globals.gd b/src/globals.gd index c1c47d2..285881f 100644 --- a/src/globals.gd +++ b/src/globals.gd @@ -8,7 +8,9 @@ var D = { init_pos = Quaternion(0, 0.707, 0, 0.707).normalized(), } var data := {} -var settings := {} +var settings := { + SCALE_FACTOR = DafaultConfig.settings.game_settings.SCALE_FACTOR, +} # global signals enum FontType {HEX, EMOJI} diff --git a/src/models/icosahedron/Icosahedron.tscn b/src/models/icosahedron/Icosahedron.tscn index 00ef0ce..7df0023 100644 --- a/src/models/icosahedron/Icosahedron.tscn +++ b/src/models/icosahedron/Icosahedron.tscn @@ -54,7 +54,6 @@ shader = ExtResource("5_s1usq") shader_parameter/pulse_enabled = false shader_parameter/colorflow_enbled = false shader_parameter/cutplate_visible = true -shader_parameter/use_web_colors = false shader_parameter/cutplane = Vector4(-0.577, -0.577, 0.577, 0.794) shader_parameter/color = Vector3(0, 1, 0) diff --git a/src/models/icosahedron/components/Icosahedron.gd b/src/models/icosahedron/components/Icosahedron.gd index 839c9e9..a13da23 100644 --- a/src/models/icosahedron/components/Icosahedron.gd +++ b/src/models/icosahedron/components/Icosahedron.gd @@ -13,7 +13,8 @@ const EDGE_NOISE = preload('res://src/models/icosahedron/resources/edge_noise.re @export var shader_type: int = 0: set(val): shader_type = val - set_shader_type(val) + #set_shader_type(val) +var show_face_numbers: bool @export var inital_transfrm := Quaternion() @onready var cut_plane: CutPlane = $CutPlane @onready var mesh_icosahedron: MeshIcosahedron = $MeshIcosahedron @@ -22,77 +23,82 @@ var cutplane_vector := Vector3(1,1,1).normalized() var scale_timer: ScaleTimer var sf: float -func set_shader_type(_type: int): - var variant = IcosahedronVarints.figure_variants[_type] - if variant.get("cutplane"): - set_cutplane(variant.cutplane) - set_color(G.theme.figure_variants.get(variant.name, G.theme.base_color)) - -func init(shader_args: Dictionary, transform_args: Dictionary = {}) -> Icosahedron: - scale_factor = G.settings.SCALE_FACTOR - scaling_enabled = G.settings.get("SCALING_ENABLED", true) - DEBUG_VISUAL = G.settings.get("DEBUG_VISUAL", false) - shader_type = shader_args.get("type", 0) - inital_transfrm = transform_args.get("quat", Quaternion()) - scale_timer = transform_args.get("scale_timer") - +func with_type(type: int): + shader_type = type return self -func set_cutplane(v: Vector4): - Utils.set_shader_param(mesh_icosahedron, "cutplane", v) - Utils.set_shader_param(mesh_icosahedron, "cutplane", v, 1) - Utils.set_shader_param(mesh_icosahedron, "cutplane", v, 3) - Utils.set_shader_param(mesh_icosahedron, "noise_pattern", EDGE_NOISE, 3) - - cutplane_vector = Vector3(v.x, v.y, v.z).normalized() - if DEBUG_VISUAL: - var ray = RayCast3D.new() - ray.target_position = $Collider.get_cutplane_vector() - mesh_icosahedron.add_child(ray) - -func set_color(arr: Array): - var c = Vector3(arr[0], arr[1], arr[2]) - Utils.set_shader_param(mesh_icosahedron, "color", c) - Utils.set_shader_param(mesh_icosahedron, "color", c, 1) - Utils.set_shader_param(mesh_icosahedron, "color", c, 3) +func with_face_numbers(show: bool): + show_face_numbers = show + return self +# +#func set_shader_type(_type: int): + #var variant = IcosahedronVarints.figure_variants[_type] + #if variant.get("cutplane"): + #set_cutplane(variant.cutplane) + #set_color(G.theme.figure_variants.get(variant.name, G.theme.base_color)) +# +#func init(shader_args: Dictionary, transform_args: Dictionary = {}) -> Icosahedron: + #scale_factor = G.settings.SCALE_FACTOR + #scaling_enabled = G.settings.get("SCALING_ENABLED", true) + #DEBUG_VISUAL = G.settings.get("DEBUG_VISUAL", false) + #shader_type = shader_args.get("type", 0) + #inital_transfrm = transform_args.get("quat", Quaternion()) + #scale_timer = transform_args.get("scale_timer") +# + #return self +# +#func set_cutplane(v: Vector4): + #Utils.set_shader_param(mesh_icosahedron, "cutplane", v) + #Utils.set_shader_param(mesh_icosahedron, "cutplane", v, 1) + #Utils.set_shader_param(mesh_icosahedron, "cutplane", v, 3) + #Utils.set_shader_param(mesh_icosahedron, "noise_pattern", EDGE_NOISE, 3) +# + #cutplane_vector = Vector3(v.x, v.y, v.z).normalized() + #if DEBUG_VISUAL: + #var ray = RayCast3D.new() + #ray.target_position = $Collider.get_cutplane_vector() + #mesh_icosahedron.add_child(ray) + +#func set_color(arr: Array): + #var c = Vector3(arr[0], arr[1], arr[2]) + #Utils.set_shader_param(mesh_icosahedron, "color", c) + #Utils.set_shader_param(mesh_icosahedron, "color", c, 1) + #Utils.set_shader_param(mesh_icosahedron, "color", c, 3) const dst := IcosahedronVarints.dst +var inital_transform := Quaternion(0, 0.707, 0, 0.707).normalized() # Called when the node enters the scene tree for the first time. func _ready() -> void: + transform.basis = Basis(inital_transform).orthonormalized() if not DEBUG_VISUAL: cut_plane.hide() if scale_timer: scale_timer.timeout.connect(_on_scale_tick) if scale_factor: sf = (scale_factor + 1000.) / 1000. - var variant = IcosahedronVarints.figure_variants[shader_type] - var sm = ShaderMaterial.new() - sm.shader = ICOSAHEDRON_SHADER_V_1 - var sm2 = ShaderMaterial.new() - sm2.shader = CUTPLANE_EFFECT_V_2 - var sm3 = ShaderMaterial.new() - sm3.shader = OUTLINE_V_1 - var sm4 = ShaderMaterial.new() - sm4.shader = EDGE_HIGHLIGHT_V_1 - mesh_icosahedron.material_override = sm - mesh_icosahedron.material_override.next_pass = sm2 - mesh_icosahedron.material_override.next_pass.next_pass = sm3 - mesh_icosahedron.material_override.next_pass.next_pass.next_pass = sm4 - if variant.get("cutplane"): - set_cutplane(variant.cutplane) - else: - Utils.set_shader_param(mesh_icosahedron, "cutplate_visible", false) - Utils.set_shader_param(mesh_icosahedron, "enable", false, 1) - Utils.set_shader_param(mesh_icosahedron, "enable", false, 2) - Utils.set_shader_param(mesh_icosahedron, "enable", false, 3) - - set_color(G.theme.figure_variants.get(variant.name, G.theme.base_color)) - - if inital_transfrm: - transform.basis = Basis(inital_transfrm).orthonormalized() - - pass + #var variant = IcosahedronVarints.figure_variants[shader_type] + #var sm = ShaderMaterial.new() + #sm.shader = ICOSAHEDRON_SHADER_V_1 + #var sm2 = ShaderMaterial.new() + #sm2.shader = CUTPLANE_EFFECT_V_2 + #var sm3 = ShaderMaterial.new() + #sm3.shader = OUTLINE_V_1 + #var sm4 = ShaderMaterial.new() + #sm4.shader = EDGE_HIGHLIGHT_V_1 + #mesh_icosahedron.material_override = sm + #mesh_icosahedron.material_override.next_pass = sm2 + #mesh_icosahedron.material_override.next_pass.next_pass = sm3 + #mesh_icosahedron.material_override.next_pass.next_pass.next_pass = sm4 + #if variant.get("cutplane"): + #set_cutplane(variant.cutplane) + #else: + #Utils.set_shader_param(mesh_icosahedron, "cutplate_visible", false) + #Utils.set_shader_param(mesh_icosahedron, "enable", false, 1) + #Utils.set_shader_param(mesh_icosahedron, "enable", false, 2) + #Utils.set_shader_param(mesh_icosahedron, "enable", false, 3) +# + #set_color(G.theme.figure_variants.get(variant.name, G.theme.base_color)) # Called every frame. 'delta' is the elapsed time since the previous frame. func _on_scale_tick() -> void: diff --git a/src/models/icosahedron/components/MeshIcosahedron.gd b/src/models/icosahedron/components/MeshIcosahedron.gd index 4ee0e71..4cfe6a7 100644 --- a/src/models/icosahedron/components/MeshIcosahedron.gd +++ b/src/models/icosahedron/components/MeshIcosahedron.gd @@ -7,6 +7,8 @@ const OUTLINE_V_1 = preload('res://src/models/icosahedron/shaders/outline_v1.gds const EDGE_HIGHLIGHT_V_1 = preload('res://src/models/icosahedron/shaders/edge_highlight_v1.gdshader') const EDGE_NOISE = preload('res://src/models/icosahedron/resources/edge_noise.res') +const MATERIAL_002 = preload('res://src/models/icosahedron/test/Material.face_index.tres') + @export var applied_shaders := [ ICOSAHEDRON_SHADER_V_1, CUTPLANE_EFFECT_V_2, @@ -14,39 +16,45 @@ const EDGE_NOISE = preload('res://src/models/icosahedron/resources/edge_noise.re EDGE_HIGHLIGHT_V_1, ] -@onready var icosahedron: Icosahedron = $'..' +@onready var icosahedron: Icosahedron = $".." @onready var collider: Collider = $'../Collider' var angle_good := false var is_alt := false var is_rotating := false -var currnt_type := -1 - - +@export var currnt_type := -1 +var show_face_numbers := false # Called when the node enters the scene tree for the first time. func _ready() -> void: + currnt_type = icosahedron.shader_type + show_face_numbers = icosahedron.show_face_numbers + set_type(currnt_type) if Utils.main_scene(self) in ['MainScene', 'LoopScene', 'MenuScene']: # wierd trick to not get errors when scaling and rotating mesh when its mounted in runtime transform.basis = Basis(icosahedron.transform.basis.get_rotation_quaternion()) func set_controlled(state: bool): - Utils.set_shader_param(self, "enable", state, 2) + ShaderUtils.set_shader_param(self, "enable", state, 2) collider.set_collision_mask_value(1, state) collider.set_collision_layer_value(1, state) func set_cutplane(v: Vector4): for i in applied_shaders.size(): - Utils.set_shader_param(self, "cutplane", v, i) - Utils.set_shader_param(self, "noise_pattern", EDGE_NOISE, 3) + ShaderUtils.set_shader_param(self, "cutplane", v, i) + ShaderUtils.set_shader_param(self, "noise_pattern", EDGE_NOISE, i) func set_color(c: Vector3): for i in applied_shaders.size(): - Utils.set_shader_param(self, "color", c, i) + ShaderUtils.set_shader_param(self, "color", c, i) func set_type(type: int): currnt_type = type var variant: Vector4 = IcosahedronVarints.figure_variants_v2[type] - ShaderUtils.apply_shaders(applied_shaders, self) + if show_face_numbers: + self.material_override = MATERIAL_002 + else: + ShaderUtils.apply_shaders(applied_shaders, self) + set_cutplane(variant) - var variant_color: Array = TwTheme.figure_variants_v2[variant] + var variant_color: Array = TwTheme.figure_variants_v2[type] set_color(Op.v3(variant_color)) diff --git a/src/models/icosahedron/components/Variants.gd b/src/models/icosahedron/components/Variants.gd index 56942c8..0f0a31b 100644 --- a/src/models/icosahedron/components/Variants.gd +++ b/src/models/icosahedron/components/Variants.gd @@ -45,7 +45,7 @@ const figure_variants = { # TDOO: make in sync w/ UV map from discrete_control.tscn static var figure_variants_v2 := { - 0: Quaternion(), - 1: FaceLock.left_q.normalized(), + 0: Vector4( -0.577, 0.577, 0.577, dst), + 1: Vector4( -0.577, 0.577, -0.577, dst), # ... } diff --git a/src/models/icosahedron/test/Material.face_index.tres b/src/models/icosahedron/test/Material.face_index.tres index 2561aa9..2a69fed 100644 --- a/src/models/icosahedron/test/Material.face_index.tres +++ b/src/models/icosahedron/test/Material.face_index.tres @@ -1,18 +1,8 @@ -[gd_resource type="StandardMaterial3D" load_steps=4 format=3 uid="uid://b6aokpwbpsi2l"] +[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://b6aokpwbpsi2l"] [ext_resource type="Texture2D" uid="uid://dplxjdemisp4h" path="res://src/models/icosahedron/test/UV_face_index.png" id="1_w4ekc"] -[ext_resource type="Shader" path="res://src/models/icosahedron/shaders/cutplane_effect_v3.gdshader" id="2_x1gid"] - -[sub_resource type="ShaderMaterial" id="ShaderMaterial_2ft62"] -render_priority = 0 -shader = ExtResource("2_x1gid") -shader_parameter/cutplane = Vector4(0.358, 0, 0.934, 0.794) -shader_parameter/color = Color(0, 1, 0, 1) -shader_parameter/enable = true -shader_parameter/outline_thickness = 0.0 [resource] resource_name = "Material.002" -next_pass = SubResource("ShaderMaterial_2ft62") albedo_texture = ExtResource("1_w4ekc") roughness = 0.5 diff --git a/src/models/icosahedron/test/variant_test.gd b/src/models/icosahedron/test/variant_test.gd index 1fde196..3d582d9 100644 --- a/src/models/icosahedron/test/variant_test.gd +++ b/src/models/icosahedron/test/variant_test.gd @@ -1,40 +1,39 @@ -@tool extends Node3D const IcosahedronScene = preload('res://src/models/icosahedron/Icosahedron.tscn') -var G: Globals = Globals.new() -@onready var icosahedron: Icosahedron = $Icosahedron - -@export var a := false: - set(val): - var new_figure = IcosahedronScene.instantiate() - new_figure.shader_type = 1 - self.add_child(new_figure) - new_figure.owner = get_tree().edited_scene_root - print_debug(new_figure.shader_type) - -@export var b := false: - set(val): - for i in self.get_children(): - remove_child(i) - -@export var c := 0: - set(val): - c = val - var a : Icosahedron = get_child(0) - print_debug(a) - a.shader_type = val - +var controlledNode +# TODO get from defaults +var ROTATION_SPEED := 12 +@export var show_face_numbers: bool = false # Called when the node enters the scene tree for the first time. func _ready() -> void: - #if not get_tree().edited_scene_root.get_node_or_null('./globals'): - #var globals = Globals.new() - #globals.set_name('globals') - #get_tree().edited_scene_root.call_deferred('add_child', globals) - #G = get_tree().edited_scene_root.get_node('./globals') - pass # Replace with function body. + var new_figure = IcosahedronScene.instantiate().with_type(1).with_face_numbers(show_face_numbers) + add_child(new_figure) + controlledNode = new_figure.mesh_icosahedron # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: + if not controlledNode: + return + if Input.is_action_just_pressed('ui_accept'): + controlledNode.transform.basis = Basis(Quaternion()).orthonormalized() + handle_free_spin_input(delta) pass + +func handle_free_spin_input(delta: float): + var _rotation: Quaternion + var rs := ROTATION_SPEED / 10. * delta + var is_inverted = false + + if Input.is_action_pressed("ui_up"): + _rotation = _rotation * Quaternion(0, 0, -rs, 1, ) + if Input.is_action_pressed("ui_down"): + _rotation = _rotation * Quaternion(0, 0, rs, 1, ) + if Op.xor(is_inverted, Input.is_action_pressed("ui_right")): + _rotation = _rotation * Quaternion(0, rs, 0, 1, ) + if Op.xor(is_inverted, Input.is_action_pressed("ui_left")): + _rotation = _rotation * Quaternion(0, -rs, 0, 1, ) + if controlledNode and _rotation: + var t = _rotation.normalized() * controlledNode.quaternion + controlledNode.transform.basis = Basis(t).orthonormalized() diff --git a/src/models/icosahedron/test/variant_test.tscn b/src/models/icosahedron/test/variant_test.tscn index 402b16a..be7de18 100644 --- a/src/models/icosahedron/test/variant_test.tscn +++ b/src/models/icosahedron/test/variant_test.tscn @@ -1,12 +1,45 @@ -[gd_scene load_steps=4 format=3 uid="uid://cd21bp42ng8gy"] +[gd_scene load_steps=10 format=3 uid="uid://cd21bp42ng8gy"] [ext_resource type="Script" path="res://src/models/icosahedron/test/variant_test.gd" id="1_4av47"] -[ext_resource type="PackedScene" uid="uid://c28nbcejwepp8" path="res://src/models/icosahedron/Icosahedron.tscn" id="2_d25gj"] -[ext_resource type="Script" path="res://src/models/icosahedron/components/Icosahedron.gd" id="3_bof8s"] +[ext_resource type="Shader" path="res://src/shaders/LoopSceneSky.gdshader" id="2_78ays"] +[ext_resource type="Shader" path="res://src/shaders/MenuSceneSky_v2.gdshader" id="3_ty025"] +[ext_resource type="ArrayMesh" uid="uid://o7rlauuvnfp6" path="res://assets/build/skybox/icosahedron_Solid_Sky.res" id="4_ayq7c"] +[ext_resource type="Script" path="res://src/components/sky/SkyIcosahedron.gd" id="5_pg1rd"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_tb2j1"] +shader = ExtResource("2_78ays") +shader_parameter/bg_color = Vector3(0.729, 0.902, 0.992) + +[sub_resource type="Sky" id="Sky_puicm"] +sky_material = SubResource("ShaderMaterial_tb2j1") + +[sub_resource type="Environment" id="Environment_37xli"] +background_mode = 2 +sky = SubResource("Sky_puicm") + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_0smox"] +render_priority = 0 +shader = ExtResource("3_ty025") +shader_parameter/bg_color = Color(0.729, 0.902, 0.992, 1) [node name="VariantTest" type="Node3D"] script = ExtResource("1_4av47") +show_face_numbers = true + +[node name="Environment" type="Node3D" parent="."] + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="Environment"] +transform = Transform3D(-0.0409792, 0.660641, -0.749583, -0.599842, 0.583709, 0.547242, 0.799069, 0.472056, 0.37236, 0.155482, 0.644891, 0.176892) + +[node name="WorldEnvironment" type="WorldEnvironment" parent="Environment"] +environment = SubResource("Environment_37xli") + +[node name="Camera3D" type="Camera3D" parent="Environment"] +transform = Transform3D(1, 0, 0, 0, 0.907777, 0.419452, 0, -0.419452, 0.907777, 0, 1.5894, 2.81957) -[node name="Icosahedron" type="MeshInstance3D" parent="." instance=ExtResource("2_d25gj")] -script = ExtResource("3_bof8s") -shader_type = 1 +[node name="SkyMeshIcosahedron" type="MeshInstance3D" parent="Environment"] +transform = Transform3D(42.78, 0, 0, 0, 42.78, 0, 0, 0, 42.78, 0, 0, 0) +material_override = SubResource("ShaderMaterial_0smox") +mesh = ExtResource("4_ayq7c") +skeleton = NodePath("../..") +script = ExtResource("5_pg1rd")