Adds missing data

This commit is contained in:
Michel 2025-02-03 19:17:20 +01:00
parent e6391d9fdd
commit 53cdcc3433
620 changed files with 47293 additions and 151 deletions

View file

@ -0,0 +1,82 @@
# MIT License
#
# Copyright (c) 2023 Mark McKay
# https://github.com/blackears/cyclopsLevelBuilder
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
extends ResourceInspector
class_name BufferArchive
class BufferRegion extends Resource:
var builder:BufferArchive
#var index:int
var start_byte:int
var length:int
func get_buffer()->PackedByteArray:
return builder.buffer.slice(start_byte, start_byte + length)
var buffer:PackedByteArray
#var region_list:Array[BufferRegion]
func store_buffer(buf:PackedByteArray)->BufferRegion:
var region:BufferRegion = BufferRegion.new()
region.builder = self
#region.index = region_list.size()
region.start_byte = buffer.size()
region.length = buf.size()
buffer.append_array(buf)
# buffer.resize(buffer.size() + byte_len)
#region_list.append(region)
return region
#func allocate_buffer(byte_len:int)->BufferRegion:
#var region:BufferRegion = BufferRegion.new()
#
#region.builder = self
#region.index = region_list.size()
#region.start_byte = buffer.size()
#region.length = byte_len
#buffer.resize(buffer.size() + byte_len)
#
#region_list.append(region)
#
#return region
func to_dictionary()->Dictionary:
var result:Dictionary
#result["regions"] = []
#for region in region_list:
#result.region.append({
##"index": region.index,
#"start": region.start_byte,
#"length": region.length
#})
result["buffer"] = Marshalls.raw_to_base64(buffer.compress())
return result

View file

@ -0,0 +1,199 @@
# MIT License
#
# Copyright (c) 2023 Mark McKay
# https://github.com/blackears/cyclopsLevelBuilder
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
class_name CyclopsFileBuilder
extends RefCounted
var plugin:CyclopsLevelBuilder
var buffer_archive:BufferArchive = BufferArchive.new()
var document:Dictionary
var node_indexer:ItemIndexer = ItemIndexer.new()
var object_indexer:ItemIndexer = ItemIndexer.new()
var buffer_region_indexer:ItemIndexer = ItemIndexer.new()
var buffer_region_map:Dictionary
func _init(plugin:CyclopsLevelBuilder):
self.plugin = plugin
func should_include_branch(node:Node3D)->bool:
if node is CyclopsBlock:
return true
for child in node.get_children():
if child is Node3D && should_include_branch(child):
return true
return false
func build_file():
var root:Node = plugin.get_editor_interface().get_edited_scene_root()
document = {
"header": {
"exporter": "Cyclops Level Builder " + plugin.get_plugin_version(),
"version": "1.0.0"
},
"scenes": [],
"nodes": [],
"objects": [],
"buffer_regions": [],
"buffers": []
}
export_scene_recursive(root)
#var build_scene:Dictionary
#build_scene["root"] = root.name
document.scenes.append({
"id": 0,
"root": node_indexer.get_or_create_id(root)
})
for id in buffer_region_map.keys():
var region:BufferArchive.BufferRegion = buffer_region_map[id]
document.buffer_regions.append({
"id": id,
"start": region.start_byte,
"length": region.length,
"buffer_id": 0
})
document.buffers.append({
"id": 0,
"byte_length": buffer_archive.buffer.size(),
"data_buffer": Marshalls.raw_to_base64(buffer_archive.buffer.compress())
})
func export_scene_recursive(cur_node:Node3D):
#print(str(cur_node.get_path()) + "\n")
if !should_include_branch(cur_node):
return
var build_node:Dictionary
build_node["id"] = node_indexer.get_or_create_id(cur_node)
build_node["name"] = cur_node.name
document.nodes.append(build_node)
if !cur_node.visible:
build_node["visible"] = cur_node.visible
if !cur_node.position.is_equal_approx(Vector3.ZERO):
build_node["translate"] = [cur_node.position.x, cur_node.position.y, cur_node.position.z]
if !cur_node.transform.basis.is_equal_approx(Basis.IDENTITY):
build_node["basis"] = [
cur_node.basis.x.x, cur_node.basis.x.y, cur_node.basis.x.z,
cur_node.basis.y.x, cur_node.basis.y.y, cur_node.basis.y.z,
cur_node.basis.z.x, cur_node.basis.z.y, cur_node.basis.z.z
]
if cur_node is CyclopsBlock:
var obj_id:int = object_indexer.get_or_create_id(cur_node)
build_node["object"] = obj_id
var dict:Dictionary = cur_node.export_to_cyclops_file(self)
document.objects.append(
{
"id": obj_id,
"type": "convex_block",
"body": dict
}
)
#export_mesh_node(cur_node)
else:
# print("children of ", cur_node.name)
var child_ids:Array[int]
var exp_children:Array[Node3D]
for local_child in cur_node.get_children():
if local_child is Node3D && should_include_branch(local_child):
child_ids.append(node_indexer.get_or_create_id(local_child))
exp_children.append(local_child)
if !child_ids.is_empty():
build_node["children"] = child_ids
for local_child in exp_children:
export_scene_recursive(local_child)
func export_mesh_node(cur_node:CyclopsBlock):
if !cur_node.mesh_vector_data:
return
var build_mesh:Dictionary
document.objects.append(build_mesh)
build_mesh["id"] = object_indexer.get_or_create_id(cur_node)
build_mesh["collision_type"] = Collision.Type.keys()[cur_node.collision_type]
build_mesh["collision_layer"] = cur_node.collision_layer
build_mesh["collision_mask"] = cur_node.collision_mask
var mat_res_paths:PackedStringArray
for mat in cur_node.materials:
if mat:
mat_res_paths.append(mat.resource_path)
else:
mat_res_paths.append("")
build_mesh["materials"] = mat_res_paths
build_mesh["mesh"] = cur_node.mesh_vector_data.to_dictionary(self)
#build_mesh["mesh"] = cur_node.mesh_vector_data.to_dictionary(self)
func export_byte_array(byte_data:PackedByteArray)->int:
var result:Dictionary
var region:BufferArchive.BufferRegion = buffer_archive.store_buffer(byte_data)
var buf_id:int = buffer_region_indexer.get_or_create_id(region)
buffer_region_map[buf_id] = region
# result["data_buffer"] = region.index
return buf_id
func export_vector(vec:DataVector)->Dictionary:
var result:Dictionary
result["name"] = vec.name
result["data_type"] = DataVector.DataType.keys()[vec.data_type]
#if vec.stride != 1:
#result["stride"] = vec.stride
if !vec.category.is_empty():
result["category"] = vec.category
var region:BufferArchive.BufferRegion = buffer_archive.store_buffer(vec.get_buffer_byte_data())
var buf_id:int = buffer_region_indexer.get_or_create_id(region)
buffer_region_map[buf_id] = region
# result["data_buffer"] = region.index
result["data_buffer"] = buf_id
return result

View file

@ -0,0 +1,209 @@
# MIT License
#
# Copyright (c) 2023 Mark McKay
# https://github.com/blackears/cyclopsLevelBuilder
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
class_name CyclopsFileLoader
extends RefCounted
class BufferRegion:
var start:int
var length:int
var buffer_id:int
var buffer_archive:BufferArchive = BufferArchive.new()
var buffer_map:Dictionary
var buffer_region_map:Dictionary
var object_map:Dictionary
var node_map:Dictionary
var scene_map:Dictionary
var plugin:CyclopsLevelBuilder
func load(root:Dictionary):
for buf_dict in root["buffers"]:
var buf_id:int = buf_dict["id"]
var buf_size:int = buf_dict["byte_length"]
var text:String = buf_dict["data_buffer"]
var zip_buf:PackedByteArray = Marshalls.base64_to_raw(text)
var buf:PackedByteArray = zip_buf.decompress(buf_size)
var ba:BufferArchive = BufferArchive.new()
ba.buffer = buf
buffer_map[buf_id] = ba
for reg_dict in root["buffer_regions"]:
var reg:BufferRegion = BufferRegion.new()
var id:int = reg_dict["id"]
reg.start = reg_dict["start"]
reg.length = reg_dict["length"]
reg.buffer_id = reg_dict["buffer_id"]
buffer_region_map[id] = reg
for obj_dict in root["objects"]:
var id:int = obj_dict["id"]
var type:String = obj_dict["type"]
var body:Dictionary = obj_dict["body"]
var object_node
match type:
"convex_block":
object_node = load_convex_block(body)
if object_node:
object_map[id] = object_node
for node_dict in root["nodes"]:
var id:int = node_dict["id"]
var node:Node3D
if node_dict.has("object"):
var obj_id:int = node_dict["object"]
node = object_map[obj_id]
else:
node = Node3D.new()
node_map[id] = node
if node_dict.has("name"):
node.name = node_dict["name"]
if node_dict.has("visible"):
node.visible = node_dict["visible"]
if node_dict.has("basis"):
var a:Array = node_dict["basis"]
var basis:Basis = Basis(Vector3(a[0], a[1], a[2]), Vector3(a[3], a[4], a[5]), Vector3(a[6], a[7], a[8]))
node.basis = basis
if node_dict.has("translate"):
var a:Array = node_dict["translate"]
node.position = Vector3(a[0], a[1], a[2])
for node_dict in root["nodes"]:
var id:int = node_dict["id"]
var node:Node3D = node_map[id]
if node_dict.has("children"):
for child_idx in node_dict["children"]:
var child_node:Node3D = node_map[int(child_idx)]
node.add_child(child_node)
for scene_dict in root["scenes"]:
var id:int = scene_dict["id"]
var root_id:int = scene_dict["root"]
scene_map[id] = root_id
func load_convex_block(body_dict:Dictionary)->CyclopsBlock:
var block:CyclopsBlock = preload("res://addons/cyclops_level_builder/nodes/cyclops_block.gd").new()
#blocks_root.add_child(block)
#block.owner = builder.get_editor_interface().get_edited_scene_root()
#block.name = GeneralUtil.find_unique_name(blocks_root, block_name_prefix)
block.collision_type = Collision.Type.get(body_dict["collision_type"])
block.collision_layer = body_dict["collision_layer"]
block.collision_mask = body_dict["collision_mask"]
for mat_res_path in body_dict["materials"]:
var res = ResourceLoader.load(mat_res_path)
block.materials.append(res)
if body_dict.has("mesh"):
var mesh_dict:Dictionary = body_dict["mesh"]
var mesh:MeshVectorData = MeshVectorData.new()
mesh.num_vertices = mesh_dict["num_vertices"]
mesh.num_edges = mesh_dict["num_edges"]
mesh.num_faces = mesh_dict["num_faces"]
mesh.num_face_vertices = mesh_dict["num_face_vertices"]
mesh.active_vertex = mesh_dict["active_vertex"]
mesh.active_edge = mesh_dict["active_edge"]
mesh.active_face = mesh_dict["active_face"]
mesh.active_face_vertex = mesh_dict["active_face_vertex"]
mesh.edge_vertex_indices = load_buffer(mesh_dict["edge_vertex_index_buffer"]).to_int32_array()
mesh.edge_face_indices = load_buffer(mesh_dict["edge_face_index_buffer"]).to_int32_array()
mesh.face_vertex_count = load_buffer(mesh_dict["face_vertex_count_buffer"]).to_int32_array()
mesh.face_vertex_indices = load_buffer(mesh_dict["face_vertex_index_buffer"]).to_int32_array()
for vec_dict in mesh_dict["vectors"]["vertices"]:
var vec:DataVector = load_data_vector(vec_dict)
mesh.vertex_data[vec.name] = vec
for vec_dict in mesh_dict["vectors"]["edges"]:
var vec:DataVector = load_data_vector(vec_dict)
mesh.edge_data[vec.name] = vec
for vec_dict in mesh_dict["vectors"]["faces"]:
var vec:DataVector = load_data_vector(vec_dict)
mesh.face_data[vec.name] = vec
for vec_dict in mesh_dict["vectors"]["face_vertices"]:
var vec:DataVector = load_data_vector(vec_dict)
mesh.face_vertex_data[vec.name] = vec
block.mesh_vector_data = mesh
return block
#enum DataType { BOOL, INT, FLOAT, STRING, COLOR, VECTOR2, VECTOR3, VECTOR4, TRANSFORM_2D, TRANSFORM_3D }
func load_data_vector(vec_dict)->DataVector:
match vec_dict["data_type"]:
"BOOL":
var buf:PackedByteArray = load_buffer(vec_dict["data_buffer"])
return DataVectorByte.new(vec_dict["name"], buf, DataVector.DataType.BOOL)
"INT":
var buf:PackedInt32Array = load_buffer(vec_dict["data_buffer"]).to_int32_array()
return DataVectorInt.new(vec_dict["name"], buf, DataVector.DataType.INT)
"FLOAT":
var buf:PackedFloat32Array = load_buffer(vec_dict["data_buffer"]).to_float32_array()
return DataVectorFloat.new(vec_dict["name"], buf, DataVector.DataType.FLOAT)
"STRING":
var buf:PackedStringArray = bytes_to_var(load_buffer(vec_dict["data_buffer"]))
return DataVectorString.new(vec_dict["name"], buf, DataVector.DataType.STRING)
"COLOR":
var buf:PackedFloat32Array = load_buffer(vec_dict["data_buffer"]).to_float32_array()
return DataVectorFloat.new(vec_dict["name"], buf, DataVector.DataType.COLOR)
"TRANSFORM_2D":
var buf:PackedFloat32Array = load_buffer(vec_dict["data_buffer"]).to_float32_array()
return DataVectorFloat.new(vec_dict["name"], buf, DataVector.DataType.TRANSFORM_2D)
"TRANSFORM_3D":
var buf:PackedFloat32Array = load_buffer(vec_dict["data_buffer"]).to_float32_array()
return DataVectorFloat.new(vec_dict["name"], buf, DataVector.DataType.TRANSFORM_3D)
"VECTOR2":
var buf:PackedFloat32Array = load_buffer(vec_dict["data_buffer"]).to_float32_array()
return DataVectorFloat.new(vec_dict["name"], buf, DataVector.DataType.VECTOR2)
"VECTOR3":
var buf:PackedFloat32Array = load_buffer(vec_dict["data_buffer"]).to_float32_array()
return DataVectorFloat.new(vec_dict["name"], buf, DataVector.DataType.VECTOR3)
"VECTOR4":
var buf:PackedFloat32Array = load_buffer(vec_dict["data_buffer"]).to_float32_array()
return DataVectorFloat.new(vec_dict["name"], buf, DataVector.DataType.VECTOR4)
_:
return null
func load_buffer(buf_id:int)->PackedByteArray:
var buf_reg:BufferRegion = buffer_region_map[buf_id]
var buf_src:BufferArchive = buffer_map[buf_reg.buffer_id]
return buf_src.buffer.slice(buf_reg["start"], buf_reg["start"] + buf_reg["length"])

View file

@ -0,0 +1,36 @@
# MIT License
#
# Copyright (c) 2023 Mark McKay
# https://github.com/blackears/cyclopsLevelBuilder
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
class_name ItemIndexer
extends RefCounted
var dict:Dictionary
func get_or_create_id(node:Variant)->int:
if dict.has(node):
return dict[node]
var id:int = dict.size()
dict[node] = id
return id

View file

@ -0,0 +1,85 @@
# MIT License
#
# Copyright (c) 2023 Mark McKay
# https://github.com/blackears/cyclopsLevelBuilder
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
extends Window
class_name ExporterCyclopsWizard
var file_dialog:FileDialog
var save_path:String
var plugin:CyclopsLevelBuilder
# Called when the node enters the scene tree for the first time.
func _ready():
file_dialog = FileDialog.new()
add_child(file_dialog)
file_dialog.size = Vector2(600, 400)
file_dialog.file_mode = FileDialog.FILE_MODE_SAVE_FILE
file_dialog.set_access(FileDialog.ACCESS_RESOURCES)
file_dialog.title = "Save file..."
file_dialog.filters = PackedStringArray(["*.cyclops; Cyclops files"])
file_dialog.current_file = save_path
file_dialog.file_selected.connect(on_save_file)
%lineEdit_path.text = save_path
#_text_path = %lineEdit_path
#_text_path.text = save_path
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func on_save_file(path:String):
save_path = path
%lineEdit_path.text = path
func _on_bn_browse_pressed():
file_dialog.popup_centered()
func _on_bn_cancel_pressed():
hide()
func _on_close_requested():
hide()
func _on_bn_okay_pressed():
var path:String = save_path
if !save_path.to_lower().ends_with(".cyclops"):
path = save_path + ".cyclops"
var cyclops_file_builder:CyclopsFileBuilder = CyclopsFileBuilder.new(plugin)
cyclops_file_builder.build_file()
var text = JSON.stringify(cyclops_file_builder.document, " ", false)
var file:FileAccess = FileAccess.open(path, FileAccess.WRITE)
file.store_string(text)
hide()

View file

@ -0,0 +1,60 @@
[gd_scene load_steps=3 format=3 uid="uid://bxmmf4lvpqtvr"]
[ext_resource type="Script" path="res://addons/cyclops_level_builder/io/exporter/exporter_cyclops_wizard.gd" id="1_107gl"]
[sub_resource type="Theme" id="Theme_5yuos"]
MarginContainer/constants/margin_bottom = 10
MarginContainer/constants/margin_left = 10
MarginContainer/constants/margin_right = 10
MarginContainer/constants/margin_top = 10
[node name="Window" type="Window"]
position = Vector2i(0, 36)
size = Vector2i(600, 100)
script = ExtResource("1_107gl")
[node name="MarginContainer" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = SubResource("Theme_5yuos")
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Path
"
[node name="lineEdit_path" type="LineEdit" parent="MarginContainer/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
[node name="bn_browse" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
tooltip_text = "Browse"
text = "..."
[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
[node name="bn_okay" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Okay"
[node name="bn_cancel" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Cancel"
[connection signal="close_requested" from="." to="." method="_on_close_requested"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer/bn_browse" to="." method="_on_bn_browse_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/bn_okay" to="." method="_on_bn_okay_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/bn_cancel" to="." method="_on_bn_cancel_pressed"]

View file

@ -0,0 +1,167 @@
# MIT License
#
# Copyright (c) 2023 Mark McKay
# https://github.com/blackears/cyclopsLevelBuilder
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
extends Window
class_name ExporterGltfWizard
#@onready var _text_path:LineEdit = $VBoxContainer/HBoxContainer/text_path
#var _text_path:LineEdit
var file_dialog:FileDialog
var save_path:String
var plugin:CyclopsLevelBuilder
# Called when the node enters the scene tree for the first time.
func _ready():
file_dialog = FileDialog.new()
add_child(file_dialog)
file_dialog.size = Vector2(600, 400)
file_dialog.file_mode = FileDialog.FILE_MODE_SAVE_FILE
file_dialog.set_access(FileDialog.ACCESS_FILESYSTEM)
file_dialog.title = "Export scene..."
file_dialog.filters = PackedStringArray(["*.gltf; glTF files"])
file_dialog.current_file = save_path
file_dialog.file_selected.connect(on_save_file)
# _text_path = $VBoxContainer/HBoxContainer/lineEdit_path
#var hh = get_node("VBoxContainer")
#var children = get_children()
# _text_path = get_node("VBoxContainer/HBoxContainer/lineEdit_path")
%lineEdit_path.text = save_path
#_text_path = %lineEdit_path
#_text_path.text = save_path
func on_save_file(path:String):
save_path = path
%lineEdit_path.text = path
func _on_bn_browse_pressed():
file_dialog.popup_centered()
func branch_is_valid(node:Node)->bool:
if node is CyclopsBlock || (%check_markers.button_pressed && node is Marker3D):
return true
for child in node.get_children():
if child is Node3D and branch_is_valid(child):
return true
return false
func clean_branch(node:Node3D)->Node3D:
if node is CyclopsBlock:
var block:CyclopsBlock = node
var new_mesh_node:MeshInstance3D = block.mesh_instance.duplicate()
new_mesh_node.name = block.mesh_instance.name
var new_node:Node3D = Node3D.new()
new_node.name = node.name
new_node.transform = node.transform
new_node.add_child(new_mesh_node)
return new_node
elif node is Marker3D:
var new_node:Marker3D = node.duplicate()
return new_node
else:
var new_node:Node3D = Node3D.new()
new_node.transform = node.transform
new_node.name = node.name
for child in node.get_children():
if branch_is_valid(child):
new_node.add_child(clean_branch(child))
return new_node
func search_nodes_flat(node:Node, root:Node3D):
# print("searching %s" % node.name)
if node is CyclopsBlock:
#print("exporting block %s" % node.name)
var block:CyclopsBlock = node
var new_mesh_node:MeshInstance3D = block.mesh_instance.duplicate()
new_mesh_node.name = block.name
root.add_child(new_mesh_node)
new_mesh_node.global_transform = block.mesh_instance.global_transform
elif node is Marker3D:
if %check_markers.button_pressed:
var new_node:Marker3D = Marker3D.new()
new_node.name = node.name
root.add_child(new_node)
new_node.global_transform = node.global_transform
for child in node.get_children():
search_nodes_flat(child, root)
func clean_flat(node:Node3D)->Node3D:
#print("clean_flat")
var root:Node3D = Node3D.new()
root.name = "CyclopsScene"
for child in node.get_children():
#print("rpt chjild %s" % child.name)
search_nodes_flat(child, root)
return root
func _on_bn_okay_pressed():
var path:String = save_path
if !save_path.to_lower().ends_with(".gltf") && !save_path.to_lower().ends_with(".glb"):
path = save_path + ".gltf"
var doc:GLTFDocument = GLTFDocument.new()
var state:GLTFState = GLTFState.new()
var root:Node = plugin.get_editor_interface().get_edited_scene_root()
var root_clean:Node3D = clean_flat(root) if %check_flatten.button_pressed else clean_branch(root)
doc.append_from_scene(root_clean, state)
doc.write_to_filesystem(state, path)
hide()
func _on_bn_cancel_pressed():
hide()
func _on_close_requested():
hide()

View file

@ -0,0 +1,75 @@
[gd_scene load_steps=3 format=3 uid="uid://ct2mftn2hge7k"]
[ext_resource type="Script" path="res://addons/cyclops_level_builder/io/exporter/exporter_gltf_wizard.gd" id="1_asb2l"]
[sub_resource type="Theme" id="Theme_pvimd"]
MarginContainer/constants/margin_bottom = 10
MarginContainer/constants/margin_left = 10
MarginContainer/constants/margin_right = 10
MarginContainer/constants/margin_top = 10
[node name="Window" type="Window"]
title = "Gltf Wizard"
position = Vector2i(0, 36)
size = Vector2i(400, 150)
script = ExtResource("1_asb2l")
[node name="MarginContainer" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = SubResource("Theme_pvimd")
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="check_flatten" type="CheckBox" parent="MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
tooltip_text = "If unchecked, the scene heierarchy will be refelected in the exported nodes. Otherwise all nodes will be children of the root."
button_pressed = true
text = "Flatten"
[node name="check_markers" type="CheckBox" parent="MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
tooltip_text = "Include Marker3Ds in export."
button_pressed = true
text = "Markers"
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Path
"
[node name="lineEdit_path" type="LineEdit" parent="MarginContainer/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
[node name="bn_browse" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
tooltip_text = "Browse"
text = "..."
[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
[node name="bn_okay" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Okay"
[node name="bn_cancel" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Cancel"
[connection signal="close_requested" from="." to="." method="_on_close_requested"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer/bn_browse" to="." method="_on_bn_browse_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/bn_okay" to="." method="_on_bn_okay_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/bn_cancel" to="." method="_on_bn_cancel_pressed"]

View file

@ -0,0 +1,155 @@
# MIT License
#
# Copyright (c) 2023 Mark McKay
# https://github.com/blackears/cyclopsLevelBuilder
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
extends Window
class_name ExporterGodotSceneWizard
#var _text_path:LineEdit
var default_material:Material = preload("res://addons/cyclops_level_builder/materials/grid.tres")
var file_dialog:FileDialog
var save_path:String
var plugin:CyclopsLevelBuilder
# Called when the node enters the scene tree for the first time.
func _ready():
file_dialog = FileDialog.new()
add_child(file_dialog)
file_dialog.size = Vector2(600, 400)
file_dialog.file_mode = FileDialog.FILE_MODE_SAVE_FILE
file_dialog.set_access(FileDialog.ACCESS_RESOURCES)
file_dialog.title = "Export scene..."
file_dialog.filters = PackedStringArray(["*.tscn; tscn files"])
file_dialog.current_file = save_path
file_dialog.file_selected.connect(on_save_file)
%lineEdit_path.text = save_path
#_text_path = %lineEdit_path
#_text_path.text = save_path
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func on_save_file(path:String):
save_path = path
%lineEdit_path.text = path
func _on_bn_browse_pressed():
file_dialog.popup_centered()
func _on_bn_cancel_pressed():
hide()
func _on_close_requested():
hide()
func _on_bn_okay_pressed():
var path:String = save_path
if !save_path.to_lower().ends_with(".tscn") && !save_path.to_lower().ends_with(".tscn"):
path = save_path + ".tscn"
var root:Node = plugin.get_editor_interface().get_edited_scene_root()
#var dup_node:Node = copy_scene_recursive(root)
var dup_node:Node = root.duplicate()
await get_tree().process_frame
replace_blocks_recursive(dup_node, dup_node)
#dup_node.name = "aaaaaaa"
var dup_scene:PackedScene = PackedScene.new()
dup_scene.pack(dup_node)
ResourceSaver.save(dup_scene, path)
hide()
func replace_blocks_recursive(node:Node, root:Node):
for child in node.get_children():
#print("child.name ", child.name)
if child is CyclopsBlock:
var child_block:CyclopsBlock = child
var new_child:Node3D = Node3D.new()
child.add_sibling(new_child)
new_child.owner = root
new_child.transform = child_block.transform
new_child.set_display_folded(true)
#Mesh
var vol:ConvexVolume = ConvexVolume.new()
vol.init_from_mesh_vector_data(child_block.mesh_vector_data)
var mesh:ArrayMesh = vol.create_mesh(child_block.materials, default_material)
var mesh_instance:MeshInstance3D = MeshInstance3D.new()
new_child.add_child(mesh_instance)
mesh_instance.owner = root
mesh_instance.mesh = mesh
mesh_instance.name = "mesh_instance"
#Collision
var collision_body:PhysicsBody3D
match child_block.collision_type:
Collision.Type.STATIC:
collision_body = StaticBody3D.new()
Collision.Type.KINEMATIC:
collision_body = CharacterBody3D.new()
Collision.Type.RIGID:
collision_body = RigidBody3D.new()
if collision_body:
collision_body.collision_layer = child_block.collision_layer
collision_body.collision_mask = child_block.collision_mask
new_child.add_child(collision_body)
collision_body.owner = root
collision_body.name = "collision_body"
var collision_shape:CollisionShape3D = CollisionShape3D.new()
collision_body.add_child(collision_shape)
collision_shape.owner = root
var shape:ConvexPolygonShape3D = ConvexPolygonShape3D.new()
shape.points = vol.get_points()
collision_shape.shape = shape
collision_shape.name = "collision_shape"
var child_name:String = child.name
node.remove_child(child)
child.queue_free()
new_child.name = child_name
else:
replace_blocks_recursive(child, root)

View file

@ -0,0 +1,61 @@
[gd_scene load_steps=3 format=3 uid="uid://bqmvfbarjmc7c"]
[ext_resource type="Script" path="res://addons/cyclops_level_builder/io/exporter/exporter_godot_scene_wizard.gd" id="1_khuso"]
[sub_resource type="Theme" id="Theme_3em6s"]
MarginContainer/constants/margin_bottom = 10
MarginContainer/constants/margin_left = 10
MarginContainer/constants/margin_right = 10
MarginContainer/constants/margin_top = 10
[node name="Window" type="Window"]
title = "Export as Scene"
position = Vector2i(0, 36)
size = Vector2i(600, 100)
script = ExtResource("1_khuso")
[node name="MarginContainer" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = SubResource("Theme_3em6s")
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Path
"
[node name="lineEdit_path" type="LineEdit" parent="MarginContainer/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
[node name="bn_browse" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
tooltip_text = "Browse"
text = "..."
[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
[node name="bn_okay" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Okay"
[node name="bn_cancel" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Cancel"
[connection signal="close_requested" from="." to="." method="_on_close_requested"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer/bn_browse" to="." method="_on_bn_browse_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/bn_okay" to="." method="_on_bn_okay_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/bn_cancel" to="." method="_on_bn_cancel_pressed"]

View file

@ -0,0 +1,82 @@
# MIT License
#
# Copyright (c) 2023 Mark McKay
# https://github.com/blackears/cyclopsLevelBuilder
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
extends Window
class_name ImporterCyclopsFileWizard
#var _text_path:LineEdit
var default_material:Material = preload("res://addons/cyclops_level_builder/materials/grid.tres")
var file_dialog:FileDialog
var file_path:String
var plugin:CyclopsLevelBuilder
# Called when the node enters the scene tree for the first time.
func _ready():
file_dialog = FileDialog.new()
add_child(file_dialog)
file_dialog.size = Vector2(600, 400)
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
file_dialog.set_access(FileDialog.ACCESS_RESOURCES)
file_dialog.title = "Import scene..."
file_dialog.filters = PackedStringArray(["*.cyclops; Cyclops files"])
file_dialog.current_file = file_path
file_dialog.file_selected.connect(on_open_file)
%lineEdit_path.text = file_path
func on_open_file(path:String):
file_path = path
%lineEdit_path.text = path
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_bn_browse_pressed():
file_dialog.popup_centered()
func _on_close_requested():
hide()
func _on_bn_cancel_pressed():
hide()
func _on_bn_okay_pressed():
var editor_scene_root:Node = plugin.get_editor_interface().get_edited_scene_root()
var cmd:CommandImportCyclopsFile = CommandImportCyclopsFile.new()
cmd.builder = plugin
cmd.file_path = file_path
cmd.target_parent = editor_scene_root.get_path()
var undo:EditorUndoRedoManager = plugin.get_undo_redo()
cmd.add_to_undo_manager(undo)
hide()

View file

@ -0,0 +1,59 @@
[gd_scene load_steps=3 format=3 uid="uid://bl2ohfqvxwjke"]
[ext_resource type="Script" path="res://addons/cyclops_level_builder/io/importer/importer_cyclops_file_wizard.gd" id="1_sehb5"]
[sub_resource type="Theme" id="Theme_jvbwn"]
MarginContainer/constants/margin_bottom = 10
MarginContainer/constants/margin_left = 10
MarginContainer/constants/margin_right = 10
MarginContainer/constants/margin_top = 10
[node name="ImporterCyclopsFileWizard" type="Window"]
size = Vector2i(600, 100)
script = ExtResource("1_sehb5")
[node name="MarginContainer" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = SubResource("Theme_jvbwn")
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Path
"
[node name="lineEdit_path" type="LineEdit" parent="MarginContainer/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
[node name="bn_browse" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
tooltip_text = "Browse"
text = "..."
[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
[node name="bn_okay" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Okay"
[node name="bn_cancel" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Cancel"
[connection signal="close_requested" from="." to="." method="_on_close_requested"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer/bn_browse" to="." method="_on_bn_browse_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/bn_okay" to="." method="_on_bn_okay_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/bn_cancel" to="." method="_on_bn_cancel_pressed"]