mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
More parameters UI in 2D preview
This commit is contained in:
parent
5207b8093e
commit
1b377a7b05
@ -535,5 +535,10 @@
|
|||||||
d="m 6.5259032,281.28721 v 5.18946 H 1.3344969 v 2.96679 h 5.1914063 v 5.19141 h 2.9648437 v -5.19141 h 5.1914061 v -2.96679 H 9.4907469 v -5.18946 z"
|
d="m 6.5259032,281.28721 v 5.18946 H 1.3344969 v 2.96679 h 5.1914063 v 5.19141 h 2.9648437 v -5.19141 h 5.1914061 v -2.96679 H 9.4907469 v -5.18946 z"
|
||||||
id="rect1173"
|
id="rect1173"
|
||||||
inkscape:connector-curvature="0" />
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.80881888;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="M 23.974609 64.923828 A 6.9700141 6.9700141 0 0 0 17.003906 71.894531 A 6.9700141 6.9700141 0 0 0 23.974609 78.863281 A 6.9700141 6.9700141 0 0 0 30.945312 71.894531 A 6.9700141 6.9700141 0 0 0 23.974609 64.923828 z M 23.974609 67.494141 A 4.4003119 4.4003119 0 0 1 28.375 71.894531 A 4.4003119 4.4003119 0 0 1 23.974609 76.294922 A 4.4003119 4.4003119 0 0 1 19.574219 71.894531 A 4.4003119 4.4003119 0 0 1 23.974609 67.494141 z "
|
||||||
|
transform="translate(0,216.06665)"
|
||||||
|
id="path897" />
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 36 KiB |
@ -5,17 +5,17 @@
|
|||||||
"y": 0
|
"y": 0
|
||||||
},
|
},
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"a1": 0,
|
"a1": 135,
|
||||||
"a2": -50,
|
"a2": 45,
|
||||||
"cx": 0,
|
"cx": 0,
|
||||||
"cy": 0,
|
"cy": 0,
|
||||||
"r": 0.4,
|
"r": 0.4,
|
||||||
"r1": 0.29021,
|
"r1": 0.3,
|
||||||
"r2": 0.075098
|
"r2": 0.1
|
||||||
},
|
},
|
||||||
"shader_model": {
|
"shader_model": {
|
||||||
"code": "",
|
"code": "",
|
||||||
"global": "float sdArc(vec2 p, vec2 sca, vec2 scb, float ra, float rb) {\n p *= mat2(vec2(sca.x,sca.y),vec2(-sca.y,sca.x));\n p.x = abs(p.x);\n float k = (scb.y*p.x>scb.x*p.y) ? dot(p.xy,scb) : length(p.xy);\n return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb;\n}",
|
"global": "float sdArc(vec2 p, float a1, float a2, float ra, float rb) {\n\tfloat amid = 0.5*(a1+a2)+1.6+3.14*step(a1, a2);\n\tfloat alength = 0.5*(a1-a2)-1.6+3.14*step(a1, a2);\n\tvec2 sca = vec2(cos(amid), sin(amid));\n\tvec2 scb = vec2(cos(alength), sin(alength));\n p *= mat2(vec2(sca.x,sca.y),vec2(-sca.y,sca.x));\n p.x = abs(p.x);\n float k = (scb.y*p.x>scb.x*p.y) ? dot(p.xy,scb) : length(p.xy);\n return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb;\n}\n",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
|
|
||||||
],
|
],
|
||||||
@ -23,13 +23,13 @@
|
|||||||
"name": "sdArc",
|
"name": "sdArc",
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"sdf2d": "sdArc($uv-vec2(0.5), vec2(cos($a1*0.01745329251), sin($a1*0.01745329251)), vec2(cos($a2*0.01745329251), sin($a2*0.01745329251)), $r1, $r2)",
|
"sdf2d": "sdArc($uv-vec2(0.5), mod($a1, 360.0)*0.01745329251, mod($a2, 360.0)*0.01745329251, $r1, $r2)",
|
||||||
"type": "sdf2d"
|
"type": "sdf2d"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"control": "None",
|
"control": "Angle1.a",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"label": "Angle 1",
|
"label": "Angle 1",
|
||||||
"max": 180,
|
"max": 180,
|
||||||
@ -39,7 +39,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"control": "None",
|
"control": "Angle2.a",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"label": "Angle 2",
|
"label": "Angle 2",
|
||||||
"max": 180,
|
"max": 180,
|
||||||
@ -49,7 +49,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"control": "Radius1.x",
|
"control": "Radius1.r",
|
||||||
"default": 0.5,
|
"default": 0.5,
|
||||||
"label": "Radius 1",
|
"label": "Radius 1",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
@ -59,7 +59,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"control": "Radius11.x",
|
"control": "Radius11.r",
|
||||||
"default": 0.1,
|
"default": 0.1,
|
||||||
"label": "Radius 2",
|
"label": "Radius 2",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
"y": 0
|
"y": 0
|
||||||
},
|
},
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"r": 0.01,
|
"r": 0.05,
|
||||||
"sx": 0.25,
|
"sx": 0.3,
|
||||||
"sy": 0.25,
|
"sy": 0.25,
|
||||||
"sz": 0.5
|
"sz": 0.25
|
||||||
},
|
},
|
||||||
"shader_model": {
|
"shader_model": {
|
||||||
"code": "vec3 $(name_uv)_q = abs($uv) - vec3($sx, $sy, $sz);\n",
|
"code": "vec3 $(name_uv)_q = abs($uv) - vec3($sx, $sy, $sz);\n",
|
||||||
@ -26,6 +26,7 @@
|
|||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
"control": "Rect1.x",
|
||||||
"default": 0.5,
|
"default": 0.5,
|
||||||
"label": "Size X",
|
"label": "Size X",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
@ -35,6 +36,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "Rect1.y",
|
||||||
"default": 0.5,
|
"default": 0.5,
|
||||||
"label": "Size Y",
|
"label": "Size Y",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
@ -44,6 +46,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "None",
|
||||||
"default": 0.5,
|
"default": 0.5,
|
||||||
"label": "Size Z",
|
"label": "Size Z",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
@ -53,6 +56,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "None",
|
||||||
"default": 0.5,
|
"default": 0.5,
|
||||||
"label": "Radius",
|
"label": "Radius",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
"y": 0
|
"y": 0
|
||||||
},
|
},
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"l": 0.25,
|
"l": 0.3,
|
||||||
"r": 0.1,
|
"r": 0.15,
|
||||||
"sx": 0.25,
|
"sx": 0.25,
|
||||||
"sy": 0.25,
|
"sy": 0.25,
|
||||||
"sz": 0.5
|
"sz": 0.5
|
||||||
},
|
},
|
||||||
"shader_model": {
|
"shader_model": {
|
||||||
"code": "vec3 $(name_uv)_p = $uv;\n$(name_uv)_p.y -= clamp($(name_uv)_p.y, -0.5*$l, 0.5*$l);\n",
|
"code": "vec3 $(name_uv)_p = $uv;\n$(name_uv)_p.y -= clamp($(name_uv)_p.y, -$l, $l);\n",
|
||||||
"global": "",
|
"global": "",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
|
|
||||||
@ -27,7 +27,8 @@
|
|||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"default": 0.5,
|
"control": "Rect1.y",
|
||||||
|
"default": 0.25,
|
||||||
"label": "Length",
|
"label": "Length",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
"min": 0,
|
"min": 0,
|
||||||
@ -36,6 +37,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "Rect1.x",
|
||||||
"default": 0.2,
|
"default": 0.2,
|
||||||
"label": "Radius",
|
"label": "Radius",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
"y": 0
|
"y": 0
|
||||||
},
|
},
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"l": 0.25,
|
"l": 0.4,
|
||||||
"r": 0.1,
|
"r": 0.2,
|
||||||
"sx": 0.25,
|
"sx": 0.25,
|
||||||
"sy": 0.25,
|
"sy": 0.25,
|
||||||
"sz": 0.5
|
"sz": 0.5
|
||||||
@ -27,6 +27,7 @@
|
|||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
"control": "Rect1.y",
|
||||||
"default": 0.5,
|
"default": 0.5,
|
||||||
"label": "Length",
|
"label": "Length",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
@ -36,6 +37,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "Rect1.x",
|
||||||
"default": 0.2,
|
"default": 0.2,
|
||||||
"label": "Radius",
|
"label": "Radius",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
"control": "Scale1.x",
|
||||||
"default": 1,
|
"default": 1,
|
||||||
"label": "",
|
"label": "",
|
||||||
"max": 5,
|
"max": 5,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"y": 0
|
"y": 0
|
||||||
},
|
},
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"r": 0.5
|
"r": 0.4
|
||||||
},
|
},
|
||||||
"shader_model": {
|
"shader_model": {
|
||||||
"code": "",
|
"code": "",
|
||||||
@ -23,6 +23,7 @@
|
|||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
"control": "Radius1.r",
|
||||||
"default": 0.5,
|
"default": 0.5,
|
||||||
"label": "",
|
"label": "",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"y": 0
|
"y": 0
|
||||||
},
|
},
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"R": 0.25,
|
"R": 0.3,
|
||||||
"r": 0.1,
|
"r": 0.1,
|
||||||
"sx": 0.1,
|
"sx": 0.1,
|
||||||
"sy": 0.1,
|
"sy": 0.1,
|
||||||
@ -27,6 +27,7 @@
|
|||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
"control": "Radius1.r",
|
||||||
"default": 0.5,
|
"default": 0.5,
|
||||||
"label": "R",
|
"label": "R",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
@ -36,6 +37,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "Radius11.r",
|
||||||
"default": 0.1,
|
"default": 0.1,
|
||||||
"label": "r",
|
"label": "r",
|
||||||
"max": 0.5,
|
"max": 0.5,
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
"control": "P1.x",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"label": "X",
|
"label": "X",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
@ -39,6 +40,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "P1.y",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"label": "Y",
|
"label": "Y",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
@ -48,6 +50,7 @@
|
|||||||
"type": "float"
|
"type": "float"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "None",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"label": "Z",
|
"label": "Z",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
"control": "Radius1.a",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"label": "",
|
"label": "",
|
||||||
"max": 180,
|
"max": 180,
|
||||||
|
@ -63,54 +63,54 @@
|
|||||||
],
|
],
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
"control": "P1.x",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"label": "2:Translate X:",
|
"label": "2:Translate X:",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
"min": -1,
|
"min": -1,
|
||||||
"name": "translate_x",
|
"name": "translate_x",
|
||||||
"step": 0.005,
|
"step": 0.005,
|
||||||
"type": "float",
|
"type": "float"
|
||||||
"widget": "spinbox"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "P1.y",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"label": "Translate Y:",
|
"label": "Translate Y:",
|
||||||
"max": 1,
|
"max": 1,
|
||||||
"min": -1,
|
"min": -1,
|
||||||
"name": "translate_y",
|
"name": "translate_y",
|
||||||
"step": 0.005,
|
"step": 0.005,
|
||||||
"type": "float",
|
"type": "float"
|
||||||
"widget": "spinbox"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "Radius1.a",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"label": "Rotate:",
|
"label": "Rotate:",
|
||||||
"max": 720,
|
"max": 720,
|
||||||
"min": -720,
|
"min": -720,
|
||||||
"name": "rotate",
|
"name": "rotate",
|
||||||
"step": 0.005,
|
"step": 0.005,
|
||||||
"type": "float",
|
"type": "float"
|
||||||
"widget": "spinbox"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "Scale1.x",
|
||||||
"default": 1,
|
"default": 1,
|
||||||
"label": "Scale X:",
|
"label": "Scale X:",
|
||||||
"max": 50,
|
"max": 50,
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"name": "scale_x",
|
"name": "scale_x",
|
||||||
"step": 0.005,
|
"step": 0.005,
|
||||||
"type": "float",
|
"type": "float"
|
||||||
"widget": "spinbox"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"control": "Scale1.y",
|
||||||
"default": 1,
|
"default": 1,
|
||||||
"label": "Scale Y:",
|
"label": "Scale Y:",
|
||||||
"max": 50,
|
"max": 50,
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"name": "scale_y",
|
"name": "scale_y",
|
||||||
"step": 0.005,
|
"step": 0.005,
|
||||||
"type": "float",
|
"type": "float"
|
||||||
"widget": "spinbox"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": false,
|
"default": false,
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
extends TextureRect
|
extends TextureRect
|
||||||
|
|
||||||
export var parent_control : String = ""
|
export var parent_control : String = ""
|
||||||
export(int, "Simple", "Rect", "Radius", "Scale", "ScaleXY" ) var control_type : int = 0
|
export(int, "Simple", "Rect", "Radius", "Scale" ) var control_type : int = 0
|
||||||
|
|
||||||
var generator : MMGenBase = null
|
var generator : MMGenBase = null
|
||||||
var parameter_x : String = ""
|
var parameter_x : String = ""
|
||||||
var parameter_y : String = ""
|
var parameter_y : String = ""
|
||||||
var dragging = false
|
var parameter_r : String = ""
|
||||||
|
var parameter_a : String = ""
|
||||||
|
var is_xy : bool = false
|
||||||
|
|
||||||
|
var dragging : bool = false
|
||||||
|
|
||||||
var parent_control_node = null
|
var parent_control_node = null
|
||||||
var children_control_nodes = []
|
var children_control_nodes = []
|
||||||
@ -23,11 +27,18 @@ func _draw() -> void:
|
|||||||
var ppos = parent_control_node.rect_position+0.5*parent_control_node.rect_size
|
var ppos = parent_control_node.rect_position+0.5*parent_control_node.rect_size
|
||||||
draw_rect(Rect2(0.5*rect_size, 2.0*(ppos-(rect_position+0.5*rect_size))), modulate, false)
|
draw_rect(Rect2(0.5*rect_size, 2.0*(ppos-(rect_position+0.5*rect_size))), modulate, false)
|
||||||
2: # Radius
|
2: # Radius
|
||||||
draw_line(0.5*rect_size, 0.5*rect_size-get_parent().value_to_offset(get_value()), modulate)
|
var ppos
|
||||||
|
if parent_control_node == null:
|
||||||
|
ppos = get_parent().value_to_pos(Vector2(0, 0))
|
||||||
|
else:
|
||||||
|
ppos = parent_control_node.rect_position+0.5*parent_control_node.rect_size
|
||||||
|
draw_line(0.5*rect_size, ppos-rect_position, modulate)
|
||||||
3: # Scale
|
3: # Scale
|
||||||
draw_line(0.5*rect_size, 0.5*rect_size-get_parent().value_to_offset(0.25*get_value()), modulate)
|
var ppos
|
||||||
4: # ScaleXY
|
if parent_control_node == null:
|
||||||
var ppos = parent_control_node.rect_position+0.5*parent_control_node.rect_size
|
ppos = get_parent().value_to_pos(Vector2(0, 0))
|
||||||
|
else:
|
||||||
|
ppos = parent_control_node.rect_position+0.5*parent_control_node.rect_size
|
||||||
draw_rect(Rect2(0.5*rect_size, ppos-(rect_position+0.5*rect_size)), modulate, false)
|
draw_rect(Rect2(0.5*rect_size, ppos-(rect_position+0.5*rect_size)), modulate, false)
|
||||||
|
|
||||||
func setup_control(g : MMGenBase, param_defs : Array) -> void:
|
func setup_control(g : MMGenBase, param_defs : Array) -> void:
|
||||||
@ -37,6 +48,8 @@ func setup_control(g : MMGenBase, param_defs : Array) -> void:
|
|||||||
generator = g
|
generator = g
|
||||||
parameter_x = ""
|
parameter_x = ""
|
||||||
parameter_y = ""
|
parameter_y = ""
|
||||||
|
parameter_r = ""
|
||||||
|
parameter_a = ""
|
||||||
for p in param_defs:
|
for p in param_defs:
|
||||||
if p.has("control"):
|
if p.has("control"):
|
||||||
if p.control == name+".x":
|
if p.control == name+".x":
|
||||||
@ -45,6 +58,13 @@ func setup_control(g : MMGenBase, param_defs : Array) -> void:
|
|||||||
elif p.control == name+".y":
|
elif p.control == name+".y":
|
||||||
show()
|
show()
|
||||||
parameter_y = p.name
|
parameter_y = p.name
|
||||||
|
elif p.control == name+".r":
|
||||||
|
show()
|
||||||
|
parameter_r = p.name
|
||||||
|
elif p.control == name+".a":
|
||||||
|
show()
|
||||||
|
parameter_a = p.name
|
||||||
|
is_xy = parameter_x != "" or parameter_y != ""
|
||||||
if visible:
|
if visible:
|
||||||
generator.connect("parameter_changed", self, "on_parameter_changed")
|
generator.connect("parameter_changed", self, "on_parameter_changed")
|
||||||
update_position(get_value())
|
update_position(get_value())
|
||||||
@ -55,32 +75,52 @@ func setup_control(g : MMGenBase, param_defs : Array) -> void:
|
|||||||
func get_value() -> Vector2:
|
func get_value() -> Vector2:
|
||||||
var pos : Vector2 = Vector2(0, 0)
|
var pos : Vector2 = Vector2(0, 0)
|
||||||
if is_instance_valid(generator):
|
if is_instance_valid(generator):
|
||||||
if parameter_x != "":
|
if is_xy:
|
||||||
pos.x = generator.get_parameter(parameter_x)
|
if parameter_x != "":
|
||||||
if parameter_y != "":
|
pos.x = generator.get_parameter(parameter_x)
|
||||||
pos.y = generator.get_parameter(parameter_y)
|
if parameter_y != "":
|
||||||
|
pos.y = generator.get_parameter(parameter_y)
|
||||||
|
else:
|
||||||
|
var r = 0.25
|
||||||
|
var a = 0
|
||||||
|
if parameter_r != "":
|
||||||
|
r = generator.get_parameter(parameter_r)
|
||||||
|
if parameter_a != "":
|
||||||
|
a = generator.get_parameter(parameter_a)*0.01745329251
|
||||||
|
pos.x = r*cos(a)
|
||||||
|
pos.y = r*sin(a)
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
|
func get_parent_value() -> Vector2:
|
||||||
|
var parent_value = Vector2(0, 0)
|
||||||
|
var p = parent_control_node
|
||||||
|
while p != null:
|
||||||
|
parent_value += p.get_value()
|
||||||
|
p = p.parent_control_node
|
||||||
|
return parent_value
|
||||||
|
|
||||||
func on_parameter_changed(p, v) -> void:
|
func on_parameter_changed(p, v) -> void:
|
||||||
if !dragging and (p == parameter_x or p == parameter_y):
|
if !dragging and (p == parameter_x or p == parameter_y or p == parameter_r or p == parameter_a):
|
||||||
update_position(get_value())
|
update_position(get_value())
|
||||||
update()
|
update()
|
||||||
|
|
||||||
func update_parameters(pos : Vector2) -> void:
|
func update_parameters(value : Vector2) -> void:
|
||||||
if !is_instance_valid(generator):
|
if !is_instance_valid(generator):
|
||||||
return
|
return
|
||||||
if parent_control_node != null:
|
|
||||||
pos -= parent_control_node.get_value()
|
|
||||||
match control_type:
|
match control_type:
|
||||||
1: # Rect
|
1: # Rect
|
||||||
pos.x = abs(pos.x)
|
value.x = abs(value.x)
|
||||||
pos.y = abs(pos.y)
|
value.y = abs(value.y)
|
||||||
3: # Scale
|
3: # Scale
|
||||||
pos.x = 4.0*pos.x
|
value = 4.0*value
|
||||||
if parameter_x != "":
|
if parameter_x != "":
|
||||||
generator.set_parameter(parameter_x, pos.x)
|
generator.set_parameter(parameter_x, value.x)
|
||||||
if parameter_y != "":
|
if parameter_y != "":
|
||||||
generator.set_parameter(parameter_y, pos.y)
|
generator.set_parameter(parameter_y, value.y)
|
||||||
|
if parameter_r != "":
|
||||||
|
generator.set_parameter(parameter_r, value.length())
|
||||||
|
if parameter_a != "":
|
||||||
|
generator.set_parameter(parameter_a, atan2(value.y, value.x)*57.2957795131)
|
||||||
|
|
||||||
func update_position(pos : Vector2) -> void:
|
func update_position(pos : Vector2) -> void:
|
||||||
match control_type:
|
match control_type:
|
||||||
@ -88,24 +128,28 @@ func update_position(pos : Vector2) -> void:
|
|||||||
pos *= 0.25
|
pos *= 0.25
|
||||||
if parent_control_node != null:
|
if parent_control_node != null:
|
||||||
pos += parent_control_node.get_value()
|
pos += parent_control_node.get_value()
|
||||||
rect_position = get_parent().value_to_pos(pos+Vector2(0.5, 0.5))-0.5*rect_size
|
rect_position = get_parent().value_to_pos(pos)-0.5*rect_size
|
||||||
for c in children_control_nodes:
|
for c in children_control_nodes:
|
||||||
c.update_position(c.get_value())
|
c.update_position(c.get_value())
|
||||||
update()
|
update()
|
||||||
|
|
||||||
func _on_Point_gui_input(event : InputEvent):
|
func _on_Point_gui_input(event : InputEvent):
|
||||||
if event is InputEventMouseMotion and event.button_mask == BUTTON_MASK_LEFT:
|
if event is InputEventMouseMotion and event.button_mask == BUTTON_MASK_LEFT:
|
||||||
rect_position += event.relative
|
var parent_value = get_parent_value()
|
||||||
match control_type:
|
var value = get_parent().pos_to_value(rect_position+0.5*rect_size+event.relative)-parent_value
|
||||||
2: # Radius
|
if is_xy:
|
||||||
rect_position.x = max(rect_position.x, parent_control_node.rect_position.x+0.5*(parent_control_node.rect_size.x-rect_size.x))
|
if parameter_x == "":
|
||||||
rect_position.y = parent_control_node.rect_position.y+0.5*(parent_control_node.rect_size.y-rect_size.y)
|
value.x = 0
|
||||||
3: # Scale
|
if parameter_y == "":
|
||||||
rect_position.x = max(rect_position.x, parent_control_node.rect_position.x+0.5*(parent_control_node.rect_size.x-rect_size.x))
|
value.y = 0
|
||||||
rect_position.y = parent_control_node.rect_position.y+0.5*(parent_control_node.rect_size.y-rect_size.y)
|
else:
|
||||||
var pos = get_parent().pos_to_value(rect_position+0.5*rect_size)-Vector2(0.5, 0.5)
|
if parameter_r == "":
|
||||||
|
value = 0.25*value/value.length()
|
||||||
|
if parameter_a == "":
|
||||||
|
value = Vector2(value.length(), 0.0)
|
||||||
|
rect_position = get_parent().value_to_pos(value+parent_value)-0.5*rect_size
|
||||||
dragging = true
|
dragging = true
|
||||||
update_parameters(pos)
|
update_parameters(value)
|
||||||
update()
|
update()
|
||||||
dragging = false
|
dragging = false
|
||||||
for c in children_control_nodes:
|
for c in children_control_nodes:
|
||||||
|
@ -22,10 +22,10 @@ func setup_controls(g : MMGenBase) -> void:
|
|||||||
c.setup_control(generator, [])
|
c.setup_control(generator, [])
|
||||||
|
|
||||||
func value_to_pos(value : Vector2) -> Vector2:
|
func value_to_pos(value : Vector2) -> Vector2:
|
||||||
return rect_size*0.5+(value-Vector2(0.5, 0.5))*min(rect_size.x, rect_size.y)/1.2
|
return rect_size*0.5+value*min(rect_size.x, rect_size.y)/1.2
|
||||||
|
|
||||||
func value_to_offset(value : Vector2) -> Vector2:
|
func value_to_offset(value : Vector2) -> Vector2:
|
||||||
return value*min(rect_size.x, rect_size.y)/1.2
|
return value*min(rect_size.x, rect_size.y)/1.2
|
||||||
|
|
||||||
func pos_to_value(pos : Vector2) -> Vector2:
|
func pos_to_value(pos : Vector2) -> Vector2:
|
||||||
return (pos - rect_size*0.5)*1.2/min(rect_size.x, rect_size.y)+Vector2(0.5, 0.5)
|
return (pos - rect_size*0.5)*1.2/min(rect_size.x, rect_size.y)
|
||||||
|
@ -29,7 +29,7 @@ region = Rect2( 64, 48, 32, 32 )
|
|||||||
[sub_resource type="AtlasTexture" id=4]
|
[sub_resource type="AtlasTexture" id=4]
|
||||||
flags = 4
|
flags = 4
|
||||||
atlas = ExtResource( 3 )
|
atlas = ExtResource( 3 )
|
||||||
region = Rect2( 0, 64, 16, 16 )
|
region = Rect2( 16, 64, 16, 16 )
|
||||||
|
|
||||||
[node name="Preview2D" type="ColorRect"]
|
[node name="Preview2D" type="ColorRect"]
|
||||||
material = SubResource( 2 )
|
material = SubResource( 2 )
|
||||||
@ -92,4 +92,24 @@ mouse_default_cursor_shape = 10
|
|||||||
texture = SubResource( 4 )
|
texture = SubResource( 4 )
|
||||||
parent_control = "P1"
|
parent_control = "P1"
|
||||||
control_type = 3
|
control_type = 3
|
||||||
|
|
||||||
|
[node name="Angle1" parent="." instance=ExtResource( 2 )]
|
||||||
|
visible = false
|
||||||
|
self_modulate = Color( 1, 0.631373, 0, 1 )
|
||||||
|
margin_right = 16.0
|
||||||
|
margin_bottom = 16.0
|
||||||
|
mouse_default_cursor_shape = 10
|
||||||
|
texture = SubResource( 4 )
|
||||||
|
parent_control = "P1"
|
||||||
|
control_type = 2
|
||||||
|
|
||||||
|
[node name="Angle2" parent="." instance=ExtResource( 2 )]
|
||||||
|
visible = false
|
||||||
|
self_modulate = Color( 1, 0.631373, 0, 1 )
|
||||||
|
margin_right = 16.0
|
||||||
|
margin_bottom = 16.0
|
||||||
|
mouse_default_cursor_shape = 10
|
||||||
|
texture = SubResource( 4 )
|
||||||
|
parent_control = "P1"
|
||||||
|
control_type = 2
|
||||||
[connection signal="resized" from="." to="." method="on_resized"]
|
[connection signal="resized" from="." to="." method="on_resized"]
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
tool
|
tool
|
||||||
extends HBoxContainer
|
extends HBoxContainer
|
||||||
|
|
||||||
|
const CONTROLS = [ "None", "P1.x", "P1.y", "P1.a", "P1.r", "P2.x", "P2.y", "P2.a", "P2.r", "Rect1.x", "Rect1.y", "Radius1.r", "Radius1.a", "Radius11.r", "Radius11.a", "Scale1.x", "Scale1.y", "Angle1.a", "Angle2.a" ]
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
$Control.clear()
|
||||||
|
for c in CONTROLS:
|
||||||
|
$Control.add_item(c)
|
||||||
|
|
||||||
func get_model_data() -> Dictionary:
|
func get_model_data() -> Dictionary:
|
||||||
var data = {
|
var data = {
|
||||||
min = $Min.value,
|
min = $Min.value,
|
||||||
|
@ -94,7 +94,6 @@ margin_left = 458.0
|
|||||||
margin_right = 533.0
|
margin_right = 533.0
|
||||||
margin_bottom = 24.0
|
margin_bottom = 24.0
|
||||||
text = "None"
|
text = "None"
|
||||||
items = [ "None", null, false, 0, null, "P1.x", null, false, 1, null, "P1.y", null, false, 2, null, "P2.x", null, false, 3, null, "P2.y", null, false, 4, null, "Rect1.x", null, false, 5, null, "Rect1.y", null, false, 6, null, "Radius1.x", null, false, 7, null, "Radius11.x", null, false, 8, null, "Scale1.x", null, false, 9, null ]
|
|
||||||
selected = 0
|
selected = 0
|
||||||
[connection signal="value_changed" from="Min" to="." method="_on_Min_value_changed"]
|
[connection signal="value_changed" from="Min" to="." method="_on_Min_value_changed"]
|
||||||
[connection signal="value_changed" from="Max" to="." method="_on_Max_value_changed"]
|
[connection signal="value_changed" from="Max" to="." method="_on_Max_value_changed"]
|
||||||
|
Loading…
Reference in New Issue
Block a user