mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-21 13:16:49 +01:00
Removed the gdscript version of MMMaterial, MMNode, and the universal property.
This commit is contained in:
parent
d5966526aa
commit
5562524cc8
@ -1,117 +0,0 @@
|
||||
tool
|
||||
#class_name MMMaterial
|
||||
extends Resource
|
||||
|
||||
#threads are implemented using my thread pool engine module.
|
||||
#if you want to use this without that module in your engine set this to false,
|
||||
#and comment out the lines that give errors
|
||||
const USE_THREADS = true
|
||||
|
||||
export(Vector2) var image_size : Vector2 = Vector2(128, 128)
|
||||
export(Array) var nodes : Array
|
||||
|
||||
var initialized : bool = false
|
||||
var rendering : bool = false
|
||||
var queued_render : bool = false
|
||||
var job : ThreadPoolExecuteJob = ThreadPoolExecuteJob.new()
|
||||
|
||||
func initialize():
|
||||
if !initialized:
|
||||
initialized = true
|
||||
|
||||
job.setup(self, "_thread_func")
|
||||
|
||||
for n in nodes:
|
||||
n.init_properties()
|
||||
n.connect("changed", self, "on_node_changed")
|
||||
|
||||
func add_node(node : MMNode) -> void:
|
||||
nodes.append(node)
|
||||
|
||||
node.connect("changed", self, "on_node_changed")
|
||||
|
||||
emit_changed()
|
||||
|
||||
func remove_node(node : MMNode) -> void:
|
||||
if !node:
|
||||
return
|
||||
|
||||
for op in node.output_properties:
|
||||
for n in nodes:
|
||||
if n:
|
||||
for ip in n.input_properties:
|
||||
if ip.input_property == op:
|
||||
ip.set_input_property(null)
|
||||
|
||||
nodes.erase(node)
|
||||
|
||||
node.disconnect("changed", self, "on_node_changed")
|
||||
|
||||
emit_changed()
|
||||
|
||||
func render() -> void:
|
||||
initialize()
|
||||
|
||||
if rendering:
|
||||
queued_render = true
|
||||
return
|
||||
|
||||
if USE_THREADS:
|
||||
render_threaded()
|
||||
else:
|
||||
render_non_threaded()
|
||||
|
||||
func render_non_threaded() -> void:
|
||||
var did_render : bool = true
|
||||
|
||||
while did_render:
|
||||
did_render = false
|
||||
|
||||
for n in nodes:
|
||||
if n && n.render(self):
|
||||
did_render = true
|
||||
|
||||
func render_threaded() -> void:
|
||||
job.cancelled = false
|
||||
|
||||
if !ThreadPool.has_job(job):
|
||||
ThreadPool.add_job(job)
|
||||
|
||||
func _thread_func() -> void:
|
||||
if job.cancelled:
|
||||
rendering = false
|
||||
return
|
||||
|
||||
rendering = true
|
||||
job.cancelled = false
|
||||
|
||||
var did_render : bool = true
|
||||
|
||||
while did_render:
|
||||
did_render = false
|
||||
|
||||
for n in nodes:
|
||||
if n && n.render(self):
|
||||
did_render = true
|
||||
|
||||
if job.cancelled:
|
||||
rendering = false
|
||||
return
|
||||
|
||||
rendering = false
|
||||
|
||||
if queued_render:
|
||||
queued_render = false
|
||||
_thread_func()
|
||||
|
||||
func cancel_render_and_wait() -> void:
|
||||
if rendering:
|
||||
ThreadPool.cancel_job_wait(job)
|
||||
|
||||
job.cancelled = false
|
||||
|
||||
pass
|
||||
|
||||
func on_node_changed() -> void:
|
||||
emit_changed()
|
||||
call_deferred("render")
|
@ -1,138 +0,0 @@
|
||||
tool
|
||||
#class_name MMNode
|
||||
extends Resource
|
||||
|
||||
export(Vector2) var graph_position : Vector2 = Vector2()
|
||||
|
||||
var input_properties : Array
|
||||
var output_properties : Array
|
||||
|
||||
var properties_initialized : bool = false
|
||||
|
||||
var dirty : bool = true
|
||||
|
||||
#MMMaterial
|
||||
func render(material) -> bool:
|
||||
if !dirty:
|
||||
return false
|
||||
|
||||
for p in input_properties:
|
||||
if p.input_property && p.input_property.owner.dirty:
|
||||
return false
|
||||
|
||||
_render(material)
|
||||
|
||||
dirty = false
|
||||
|
||||
return true
|
||||
|
||||
#MMMaterial
|
||||
func _render(material) -> void:
|
||||
pass
|
||||
|
||||
func _render_image(material) -> Image:
|
||||
var image : Image = Image.new()
|
||||
image.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
|
||||
|
||||
image.lock()
|
||||
|
||||
var w : float = image.get_width()
|
||||
var h : float = image.get_height()
|
||||
|
||||
var pseed : float = randf() + randi()
|
||||
|
||||
# for x in range(image.get_width()):
|
||||
# for y in range(image.get_height()):
|
||||
# var v : Vector2 = Vector2(x / w, y / h)
|
||||
#
|
||||
# var col : Color = get_value_for(v, pseed)
|
||||
#
|
||||
# image.set_pixel(x, y, col)
|
||||
|
||||
image.unlock()
|
||||
|
||||
return image
|
||||
|
||||
func _get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||
return Color()
|
||||
|
||||
func init_properties() -> void:
|
||||
if !properties_initialized:
|
||||
properties_initialized = true
|
||||
|
||||
_init_properties()
|
||||
|
||||
func _init_properties() -> void:
|
||||
pass
|
||||
|
||||
func register_methods(mm_graph_node) -> void:
|
||||
init_properties()
|
||||
_register_methods(mm_graph_node)
|
||||
|
||||
func _register_methods(mm_graph_node) -> void:
|
||||
pass
|
||||
|
||||
func get_graph_position() -> Vector2:
|
||||
return graph_position
|
||||
|
||||
func set_graph_position(pos : Vector2) -> void:
|
||||
graph_position = pos
|
||||
|
||||
emit_changed()
|
||||
|
||||
func register_input_property(prop : MMNodeUniversalProperty) -> void:
|
||||
#prop.owner = self
|
||||
|
||||
if !prop.is_connected("changed", self, "on_input_property_changed"):
|
||||
prop.connect("changed", self, "on_input_property_changed")
|
||||
|
||||
input_properties.append(prop)
|
||||
|
||||
func unregister_input_property(prop : MMNodeUniversalProperty) -> void:
|
||||
#if prop.owner == self:
|
||||
# prop.owner = null
|
||||
|
||||
if prop.is_connected("changed", self, "on_input_property_changed"):
|
||||
prop.disconnect("changed", self, "on_input_property_changed")
|
||||
|
||||
input_properties.erase(prop)
|
||||
|
||||
func register_output_property(prop : MMNodeUniversalProperty) -> void:
|
||||
#prop.owner = self
|
||||
|
||||
output_properties.append(prop)
|
||||
|
||||
func unregister_output_property(prop : MMNodeUniversalProperty) -> void:
|
||||
if prop.owner == self:
|
||||
prop.owner = null
|
||||
|
||||
output_properties.erase(prop)
|
||||
|
||||
func set_dirty(val : bool) -> void:
|
||||
var changed : bool = val != dirty
|
||||
|
||||
dirty = val
|
||||
|
||||
if changed:
|
||||
emit_changed()
|
||||
|
||||
func on_input_property_changed() -> void:
|
||||
set_dirty(true)
|
||||
emit_changed()
|
||||
|
||||
# Add it to the MMAlgos bing class instead.
|
||||
# Not a perfect fit, but a better fit.
|
||||
|
||||
#func editor_register_node_class(category : String, cls : String)
|
||||
# -> c++ method, adds node to the editor gui (add button)
|
||||
# in gdscript a plugin should instance an MMNode and call it to populate the add menu
|
||||
# with MMNodes
|
||||
# in c++ it should have a static counterpart.
|
||||
# register_types should populate c++ types with this
|
||||
|
||||
#func editor_unregister_node_class(category : String, cls : String)
|
||||
|
||||
#func editor_register_node_script(category : String, script_path : String)
|
||||
# same as the above, but for scripts
|
||||
|
||||
#func editor_unregister_node_script(category : String, cls : String)
|
@ -1,321 +0,0 @@
|
||||
tool
|
||||
#class_name MMNodeUniversalProperty
|
||||
extends Resource
|
||||
|
||||
enum SlotTypes {
|
||||
SLOT_TYPE_NONE = -1,
|
||||
SLOT_TYPE_IMAGE = 0,
|
||||
SLOT_TYPE_INT = 1,
|
||||
SLOT_TYPE_FLOAT = 2,
|
||||
SLOT_TYPE_VECTOR2 = 3,
|
||||
SLOT_TYPE_VECTOR3 = 4,
|
||||
SLOT_TYPE_COLOR = 5,
|
||||
SLOT_TYPE_UNIVERSAL = 6,
|
||||
}
|
||||
|
||||
enum MMNodeUniversalPropertyDefaultType {
|
||||
DEFAULT_TYPE_INT = 0,
|
||||
DEFAULT_TYPE_FLOAT = 1,
|
||||
DEFAULT_TYPE_VECTOR2 = 2,
|
||||
DEFAULT_TYPE_VECTOR3 = 3,
|
||||
DEFAULT_TYPE_COLOR = 4,
|
||||
DEFAULT_TYPE_IMAGE = 5,
|
||||
}
|
||||
|
||||
export(int, "Int,Float,Vector2,Vector3,Color,Image") var default_type : int
|
||||
|
||||
export(int) var default_int : int
|
||||
export(float) var default_float : float
|
||||
export(Vector2) var default_vector2 : Vector2
|
||||
export(Vector3) var default_vector3 : Vector3
|
||||
export(Color) var default_color : Color
|
||||
export(Image) var default_image : Image
|
||||
|
||||
var get_value_from_owner : bool = false
|
||||
var force_override : bool = false
|
||||
#This is not exported on purpose!
|
||||
var override_image : Image
|
||||
|
||||
#Should be a MMNodeUniversalProperty, but can't set it up like that
|
||||
export(Resource) var input_property : Resource
|
||||
|
||||
var input_slot_type : int = SlotTypes.SLOT_TYPE_NONE
|
||||
var output_slot_type : int = SlotTypes.SLOT_TYPE_NONE
|
||||
var slot_name : String
|
||||
var value_step : float = 0.1
|
||||
var value_range : Vector2 = Vector2(-1000, 1000)
|
||||
|
||||
#MMNode
|
||||
var owner
|
||||
|
||||
func _init():
|
||||
if input_property:
|
||||
input_property.connect("changed", self, "on_input_property_changed")
|
||||
|
||||
func get_value(uv : Vector2, skip_owner_val : bool = false):
|
||||
if get_value_from_owner && !skip_owner_val:
|
||||
return get_owner_value(uv)
|
||||
|
||||
if !input_property:
|
||||
return get_default_value(uv)
|
||||
|
||||
if default_type == input_property.default_type:
|
||||
return input_property.get_value(uv)
|
||||
|
||||
if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT:
|
||||
return to_int(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT:
|
||||
return to_float(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2:
|
||||
return to_vector2(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3:
|
||||
return to_vector3(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR:
|
||||
return to_color(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE:
|
||||
return to_color(input_property.get_value(uv))
|
||||
|
||||
return input_property.get_value(uv)
|
||||
|
||||
func get_owner_value(uv : Vector2):
|
||||
if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT:
|
||||
return to_int(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT:
|
||||
return to_float(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2:
|
||||
return to_vector2(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3:
|
||||
return to_vector3(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR:
|
||||
return to_color(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE:
|
||||
return to_color(owner.get_property_value(uv))
|
||||
|
||||
func get_value_or_zero(uv : Vector2, skip_owner_val : bool = false):
|
||||
if get_value_from_owner && !skip_owner_val:
|
||||
return get_owner_value(uv)
|
||||
|
||||
if !input_property:
|
||||
return get_zero_value()
|
||||
|
||||
if default_type == input_property.default_type:
|
||||
return input_property.get_value(uv)
|
||||
|
||||
if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT:
|
||||
return to_int(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT:
|
||||
return to_float(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2:
|
||||
return to_vector2(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3:
|
||||
return to_vector3(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR:
|
||||
return to_color(input_property.get_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE:
|
||||
return to_color(input_property.get_value(uv))
|
||||
|
||||
return input_property.get_value(uv)
|
||||
|
||||
func get_value_sdf3d(uv3 : Vector3, skip_owner_val : bool = false) -> Vector2:
|
||||
if get_value_from_owner && !skip_owner_val:
|
||||
return owner.get_property_value_sdf3d(uv3)
|
||||
|
||||
if !input_property:
|
||||
return default_vector2
|
||||
|
||||
return input_property.get_value_sdf3d(uv3)
|
||||
|
||||
func to_int(val) -> int:
|
||||
if val is int:
|
||||
return val
|
||||
|
||||
if val is float:
|
||||
return int(val)
|
||||
|
||||
if val is Vector2:
|
||||
return int(val.x)
|
||||
|
||||
if val is Vector3:
|
||||
return int(val.x)
|
||||
|
||||
if val is Color:
|
||||
return int(val.r)
|
||||
|
||||
return 0
|
||||
|
||||
func to_float(val) -> float:
|
||||
if val is float:
|
||||
return val
|
||||
|
||||
if val is int:
|
||||
return float(val)
|
||||
|
||||
if val is Vector2:
|
||||
return float(val.x)
|
||||
|
||||
if val is Vector3:
|
||||
return float(val.x)
|
||||
|
||||
if val is Color:
|
||||
return float(val.r)
|
||||
|
||||
return 0.0
|
||||
|
||||
func to_vector2(val) -> Vector2:
|
||||
if val is Vector2:
|
||||
return val
|
||||
|
||||
if val is int:
|
||||
return Vector2(val, val)
|
||||
|
||||
if val is float:
|
||||
return Vector2(val, val)
|
||||
|
||||
if val is Vector3:
|
||||
return Vector2(val.x, val.y)
|
||||
|
||||
if val is Color:
|
||||
return Vector2(val.r, val.g)
|
||||
|
||||
return Vector2()
|
||||
|
||||
func to_vector3(val) -> Vector3:
|
||||
if val is Vector3:
|
||||
return val
|
||||
|
||||
if val is int:
|
||||
return Vector3(val, val, val)
|
||||
|
||||
if val is float:
|
||||
return Vector3(val, val, val)
|
||||
|
||||
if val is Vector2:
|
||||
return Vector3(val.x, val.y, 0)
|
||||
|
||||
if val is Color:
|
||||
return Vector3(val.r, val.g, val.b)
|
||||
|
||||
return Vector3()
|
||||
|
||||
func to_color(val) -> Color:
|
||||
if val is Color:
|
||||
return val
|
||||
|
||||
if val is int:
|
||||
return Color(val, val, val, 1)
|
||||
|
||||
if val is float:
|
||||
return Color(val, val, val, 1)
|
||||
|
||||
if val is Vector2:
|
||||
return Color(val.x, val.y, 0, 1)
|
||||
|
||||
if val is Vector3:
|
||||
return Color(val.x, val.y, val.z, 1)
|
||||
|
||||
return Color()
|
||||
|
||||
func set_value(val):
|
||||
if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE:
|
||||
override_image = val
|
||||
emit_changed()
|
||||
return
|
||||
|
||||
set_default_value(val)
|
||||
|
||||
func get_zero_value():
|
||||
if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT:
|
||||
return 0
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT:
|
||||
return 0.0
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2:
|
||||
return Vector2()
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3:
|
||||
return Vector3()
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR:
|
||||
return Color()
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE:
|
||||
return Color()
|
||||
|
||||
return null
|
||||
|
||||
func get_default_value(uv : Vector2 = Vector2()):
|
||||
if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT:
|
||||
return default_int
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT:
|
||||
return default_float
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2:
|
||||
return default_vector2
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3:
|
||||
return default_vector3
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR:
|
||||
return default_color
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE:
|
||||
var image : Image = default_image
|
||||
|
||||
if override_image:
|
||||
image = override_image
|
||||
|
||||
if !image:
|
||||
return default_color
|
||||
|
||||
image.lock()
|
||||
var x : int = uv.x * image.get_width()
|
||||
var y : int = uv.y * image.get_height()
|
||||
|
||||
x = clamp(x, 0, image.get_width() - 1)
|
||||
y = clamp(y, 0, image.get_width() - 1)
|
||||
|
||||
var c : Color = image.get_pixel(x, y)
|
||||
image.unlock()
|
||||
|
||||
return c
|
||||
|
||||
return null
|
||||
|
||||
func set_default_value(val):
|
||||
if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT:
|
||||
default_int = val
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT:
|
||||
default_float = val
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2:
|
||||
default_vector2 = val
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3:
|
||||
default_vector3 = val
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR:
|
||||
default_color = val
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE:
|
||||
default_image = val
|
||||
|
||||
emit_changed()
|
||||
|
||||
func get_active_image() -> Image:
|
||||
if !force_override && input_property:
|
||||
return input_property.get_active_image()
|
||||
|
||||
if override_image:
|
||||
return override_image
|
||||
|
||||
return default_image
|
||||
|
||||
func set_input_property(val : MMNodeUniversalProperty) -> void:
|
||||
if input_property == val:
|
||||
return
|
||||
|
||||
if input_property:
|
||||
input_property.disconnect("changed", self, "on_input_property_changed")
|
||||
|
||||
input_property = val
|
||||
|
||||
if input_property:
|
||||
input_property.connect("changed", self, "on_input_property_changed")
|
||||
|
||||
emit_changed()
|
||||
|
||||
# Because in UndiRedo if you pass null as the only argument it will look
|
||||
# for a method with no arguments
|
||||
func unset_input_property() -> void:
|
||||
set_input_property(null)
|
||||
|
||||
func on_input_property_changed() -> void:
|
||||
emit_changed()
|
Loading…
Reference in New Issue
Block a user