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,32 @@
# 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 Resource
class_name BlockData
@export var points:PackedVector3Array #Per vertex
@export var uvs:PackedVector2Array #Per face corner uv info
@export var face_vertex_indices:PackedInt32Array #Vertex index per face
@export var face_vertex_count:PackedInt32Array #Number of verts in each face
@export var face_material_indices:PackedInt32Array #Material index for each face

View file

@ -0,0 +1,137 @@
# 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 Resource
class_name ConvexBlockData
@export var selected:bool = false
@export var active:bool = false
@export var collision:bool = true
@export_flags_3d_physics var physics_layer:int
@export_flags_3d_physics var physics_mask:int
@export var vertex_points:PackedVector3Array #Per vertex
@export var vertex_selected:PackedByteArray #Per vertex
@export var edge_selected:PackedByteArray
@export var face_material_indices:PackedInt32Array #Material index for each face
@export var face_uv_transform:Array[Transform2D]
@export var face_visible:PackedByteArray
@export var face_color:PackedColorArray
@export var face_selected:PackedByteArray #Per face
@export var face_vertex_face_index:PackedInt32Array #Face index of this face-vertex
@export var face_vertex_vertex_index:PackedInt32Array #Vertex index of this face-vertex
@export var face_vertex_normal:PackedVector3Array #Per face-vertex
@export var face_vertex_color:PackedColorArray #Per face-vertex
@export var edge_vertex_indices:PackedInt32Array
@export var edge_face_indices:PackedInt32Array
@export var face_vertex_count:PackedInt32Array #Number of verts in each face
@export var face_vertex_indices:PackedInt32Array #Vertex indices encountered as you iterate over mesh one face at a time and each vertex per face
@export var active_vertex:int
@export var active_edge:int
@export var active_face:int
@export var active_face_vertex:int
#Validate arrays to make sure they're the right size
#@deprecated
func validate_arrays():
#print("deprecated validate_arrays")
var num_faces:int = face_vertex_count.size()
if face_visible.size() < num_faces:
var arr:PackedByteArray
arr.resize(num_faces - face_visible.size())
arr.fill(true)
face_visible.append_array(arr)
if face_color.size() < num_faces:
var arr:PackedColorArray
arr.resize(num_faces - face_color.size())
arr.fill(Color.WHITE)
face_color.append_array(arr)
func init_from_mesh_vector_data(mvd:MeshVectorData):
active_vertex = mvd.active_vertex
active_edge = mvd.active_edge
active_face = mvd.active_face
active_face_vertex = mvd.active_face_vertex
#selected = mvd.selected
#active = mvd.active
#collision = mvd.collision
#physics_layer = mvd.physics_layer
#physics_mask = mvd.physics_mask
var v_pos:DataVectorFloat = mvd.get_vertex_data(MeshVectorData.V_POSITION)
vertex_points = v_pos.to_vec3_array()
var v_sel:DataVectorByte = mvd.get_vertex_data(MeshVectorData.V_SELECTED)
vertex_selected = v_sel.data
var e_sel:DataVectorByte = mvd.get_edge_data(MeshVectorData.E_SELECTED)
edge_selected = e_sel.data
var f_mat:DataVectorInt = mvd.get_face_data(MeshVectorData.F_MATERIAL_INDEX)
face_material_indices = f_mat.data
# print("+build convex_block_data")
var f_uv_xform:DataVectorFloat = mvd.get_face_data(MeshVectorData.F_UV_XFORM)
face_uv_transform = f_uv_xform.to_transform2d_array()
# print("-build convex_block_data")
var f_vis:DataVectorByte = mvd.get_face_data(MeshVectorData.F_VISIBLE)
face_visible = f_vis.data
var f_col:DataVectorFloat = mvd.get_face_data(MeshVectorData.F_COLOR)
face_color = f_col.to_color_array()
var f_sel:DataVectorByte = mvd.get_face_data(MeshVectorData.F_SELECTED)
face_selected = f_sel.data
var fv_fidx:DataVectorInt = mvd.get_face_vertex_data(MeshVectorData.FV_FACE_INDEX)
face_vertex_face_index = fv_fidx.data
var fv_vidx:DataVectorInt = mvd.get_face_vertex_data(MeshVectorData.FV_VERTEX_INDEX)
face_vertex_vertex_index = fv_vidx.data
var fv_norm:DataVectorFloat = mvd.get_face_vertex_data(MeshVectorData.FV_NORMAL)
face_vertex_normal = fv_norm.to_vec3_array()
var fv_col:DataVectorFloat = mvd.get_face_vertex_data(MeshVectorData.FV_COLOR)
face_vertex_color = fv_col.to_color_array()
edge_vertex_indices = mvd.edge_vertex_indices
edge_face_indices = mvd.edge_face_indices
face_vertex_count = mvd.face_vertex_count
face_vertex_indices = mvd.face_vertex_indices

View file

@ -0,0 +1,30 @@
# 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 Resource
class_name CyclopsConfig
@export var tool_tags:Array[ToolTag]
@export var snapping_tags:Array[SnappingTag]

View file

@ -0,0 +1,84 @@
# 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 Resource
class_name DataVector
enum DataFormatType { BYTE, INT32, FLOAT32, STRING }
enum DataType { BOOL, INT, FLOAT, STRING, COLOR, VECTOR2, VECTOR3, VECTOR4, TRANSFORM_2D, TRANSFORM_3D }
@export var name:StringName
@export var category:String #uv, color, weights, etc.
@export var data_type:DataType
@export var stride:int = 1
func get_data_format_type()->DataFormatType:
return DataFormatType.BYTE
func size()->int:
return 0
func num_components()->int:
return size() / stride
func get_buffer_byte_data()->PackedByteArray:
return []
#func to_dictionary(buffer_ar:BufferArchive)->Dictionary:
#var result:Dictionary
#
#result["name"] = name
#result["data_type"] = DataType.values()[data_type]
#if stride != 1:
#result["stride"] = stride
#if !category.is_empty():
#result["category"] = category
#
#return result
static func data_type_num_components(type:DataType)->int:
match type:
DataType.BOOL:
return 1
DataType.INT:
return 1
DataType.FLOAT:
return 1
DataType.STRING:
return 1
DataType.COLOR:
return 4
DataType.VECTOR2:
return 2
DataType.VECTOR3:
return 3
DataType.VECTOR4:
return 4
DataType.TRANSFORM_2D:
return 6
DataType.TRANSFORM_3D:
return 12
_:
push_error("Invalid data type")
return 1

View file

@ -0,0 +1,62 @@
# 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 DataVector
class_name DataVectorByte
@export var data:PackedByteArray
func _init(name:StringName = "", data:PackedByteArray = [], data_type:DataType = DataType.BOOL):
self.name = name
self.data = data
self.data_type = data_type
self.stride = data_type_num_components(data_type)
func get_buffer_byte_data()->PackedByteArray:
return data
#func to_dictionary(buffer_ar:BufferArchive)->Dictionary:
#var result:Dictionary = super(buffer_ar)
#var region:BufferArchive.BufferRegion = buffer_ar.store_buffer(data)
#
## result["data"] = Marshalls.raw_to_base64(data.compress())
#result["data_buffer"] = region.index
#
#return result
func get_data_format_type()->DataFormatType:
return DataFormatType.BYTE
func size()->int:
return data.size()
func resize(size:int):
data.resize(size * stride)
func get_value(index:int)->int:
return data[index]
func set_value(value:int, index:int):
data[index] = value

View file

@ -0,0 +1,140 @@
# 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 DataVector
class_name DataVectorFloat
@export var data:PackedFloat32Array
func _init(name:StringName = "", data:PackedFloat32Array = [], data_type:DataType = DataType.FLOAT):
self.name = name
self.data = data
self.data_type = data_type
self.stride = data_type_num_components(data_type)
func get_data_format_type()->DataFormatType:
return DataFormatType.FLOAT32
func size()->int:
return data.size()
func resize(size:int):
data.resize(size * stride)
func get_value(index:int)->float:
return data[index]
func to_vec2_array()->PackedVector2Array:
var result:PackedVector2Array
for i in num_components():
result.append(get_value_vec2(i))
return result
func to_vec3_array()->PackedVector3Array:
var result:PackedVector3Array
for i in num_components():
result.append(get_value_vec3(i))
return result
func to_vec4_array()->Array[Vector4]:
var result:Array[Vector4]
for i in num_components():
result.append(get_value_vec4(i))
return result
func to_color_array()->PackedColorArray:
var result:PackedColorArray
for i in num_components():
result.append(get_value_color(i))
return result
func to_transform2d_array()->Array[Transform2D]:
#print("to_transform2d_array num_components() ", num_components())
var result:Array[Transform2D]
for i in num_components():
result.append(get_value_transform2d(i))
return result
func get_value_vec2(index:int)->Vector2:
return Vector2(data[index * stride], data[index * stride + 1])
func get_value_vec3(index:int)->Vector3:
return Vector3(data[index * stride], data[index * stride + 1], data[index * stride + 2])
func get_value_vec4(index:int)->Vector4:
return Vector4(data[index * stride], data[index * stride + 1], data[index * stride + 2], data[index * stride + 3])
func get_value_color(index:int)->Color:
return Color(data[index * stride], data[index * stride + 1], data[index * stride + 2], data[index * stride + 3])
func get_value_transform2d(index:int)->Transform2D:
return Transform2D(
Vector2(data[index * stride], data[index * stride + 1]),
Vector2(data[index * stride + 2], data[index * stride + 3]),
Vector2(data[index * stride + 4], data[index * stride + 5])
)
func get_value_transform3d(index:int)->Transform3D:
return Transform3D(
Vector3(data[index * stride], data[index * stride + 1], data[index * stride + 2]),
Vector3(data[index * stride + 3], data[index * stride + 4], data[index * stride + 5]),
Vector3(data[index * stride + 6], data[index * stride + 7], data[index * stride + 8]),
Vector3(data[index * stride + 9], data[index * stride + 10], data[index * stride + 11])
)
func set_value(value:int, index:int):
data[index] = value
func set_value_vec2(value:Vector2, index:int):
data[index * stride] = value.x
data[index * stride + 1] = value.y
func set_value_vec3(value:Vector3, index:int):
data[index * stride] = value.x
data[index * stride + 1] = value.y
data[index * stride + 2] = value.z
func set_value_vec4(value:Vector4, index:int):
data[index * stride] = value.x
data[index * stride + 1] = value.y
data[index * stride + 2] = value.z
data[index * stride + 3] = value.w
func set_value_color(value:Color, index:int):
data[index * stride] = value.r
data[index * stride + 1] = value.g
data[index * stride + 2] = value.b
data[index * stride + 3] = value.a
func get_buffer_byte_data()->PackedByteArray:
return data.to_byte_array()
#func to_dictionary(buffer_ar:BufferArchive)->Dictionary:
#var result:Dictionary = super(buffer_ar)
#var region:BufferArchive.BufferRegion = buffer_ar.store_buffer(data.to_byte_array())
#
#result["data_buffer"] = region.index
#
#return result

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 DataVector
class_name DataVectorInt
@export var data:PackedInt32Array
func _init(name:StringName = "", data:PackedInt32Array = [], data_type:DataType = DataType.INT):
self.name = name
self.data = data
self.data_type = data_type
self.stride = data_type_num_components(data_type)
func get_data_format_type()->DataFormatType:
return DataFormatType.INT32
func size()->int:
return data.size()
func resize(size:int):
data.resize(size * stride)
func get_value(index:int)->int:
return data[index]
func get_value_ivec2(index:int)->Vector2i:
return Vector2i(data[index * stride], data[index * stride + 1])
func get_value_ivec3(index:int)->Vector3i:
return Vector3i(data[index * stride], data[index * stride + 1], data[index * stride + 2])
func get_value_ivec4(index:int)->Vector4i:
return Vector4i(data[index * stride], data[index * stride + 1], data[index * stride + 2], data[index * stride + 3])
func set_value(value:int, index:int):
data[index] = value
func set_value_ivec2(value:Vector2i, index:int):
data[index * stride] = value.x
data[index * stride + 1] = value.y
func set_value_ivec3(value:Vector3i, index:int):
data[index * stride] = value.x
data[index * stride + 1] = value.y
data[index * stride + 2] = value.z
func set_value_ivec4(value:Vector4i, index:int):
data[index * stride] = value.x
data[index * stride + 1] = value.y
data[index * stride + 2] = value.z
data[index * stride + 3] = value.w
func get_buffer_byte_data()->PackedByteArray:
return data.to_byte_array()
#func to_dictionary(buffer_ar:BufferArchive)->Dictionary:
#var result:Dictionary = super(buffer_ar)
#var region:BufferArchive.BufferRegion = buffer_ar.store_buffer(data.to_byte_array())
#
#result["data_buffer"] = region.index
#
#return result

View file

@ -0,0 +1,61 @@
# 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 DataVector
class_name DataVectorString
@export var data:PackedStringArray
func _init(name:StringName = "", data:PackedStringArray = [], data_type:DataType = DataType.STRING):
self.name = name
self.data = data
self.data_type = data_type
self.stride = data_type_num_components(data_type)
func get_data_format_type()->DataFormatType:
return DataFormatType.STRING
func size()->int:
return data.size()
func resize(size:int):
data.resize(size * stride)
func get_value(index:int)->String:
return data[index]
func set_value(value:String, index:int):
data[index] = value
func get_buffer_byte_data()->PackedByteArray:
return var_to_bytes(data)
# return data.to_byte_array()
#func to_dictionary(buffer_ar:BufferArchive)->Dictionary:
#var result:Dictionary = super(buffer_ar)
#var region:BufferArchive.BufferRegion = buffer_ar.store_buffer(data.to_byte_array())
#
#result["data_buffer"] = region.index
#
#return result

View file

@ -0,0 +1,369 @@
# 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 Resource
class_name MeshVectorData
#@export var selected:bool = false
#@export var active:bool = false
#@export var collision:bool = true
#@export_flags_3d_physics var physics_layer:int
#@export_flags_3d_physics var physics_mask:int
@export var num_vertices:int
@export var num_edges:int
@export var num_faces:int
@export var num_face_vertices:int
@export var active_vertex:int
@export var active_edge:int
@export var active_face:int
@export var active_face_vertex:int
@export var edge_vertex_indices:PackedInt32Array
@export var edge_face_indices:PackedInt32Array
@export var face_vertex_count:PackedInt32Array #Number of verts in each face
@export var face_vertex_indices:PackedInt32Array #Vertex index per face
@export var vertex_data:Dictionary
@export var edge_data:Dictionary
@export var face_data:Dictionary
@export var face_vertex_data:Dictionary
const V_POSITION: StringName = "position"
const V_SELECTED: StringName = "selected"
const V_COLOR: StringName = "color"
const E_SELECTED: StringName = "selected"
const F_MATERIAL_INDEX: StringName = "material_index"
const F_UV_XFORM: StringName = "uv_transform"
const F_VISIBLE: StringName = "visible"
const F_COLOR: StringName = "color"
const F_SELECTED: StringName = "selected"
const FV_VERTEX_INDEX: StringName = "vertex_index"
const FV_FACE_INDEX: StringName = "face_index"
const FV_VERTEX_LOCAL_INDEX: StringName = "vertex_local_index"
const FV_SELECTED: StringName = "selected"
const FV_COLOR: StringName = "color"
const FV_NORMAL: StringName = "normal"
const FV_UV1: StringName = "uv1"
const FV_UV2: StringName = "uv2"
func create_from_convex_block(block_data:ConvexBlockData):
#selected = block_data.selected
#active = block_data.active
#collision = block_data.collision
#physics_layer = block_data.physics_layer
#physics_mask = block_data.physics_mask
active_vertex = block_data.active_vertex
active_edge = block_data.active_edge
active_face = block_data.active_face
active_face_vertex = block_data.active_face_vertex
num_vertices = block_data.vertex_points.size()
num_edges = block_data.edge_vertex_indices.size() / 2
num_faces = block_data.face_vertex_count.size()
set_vertex_data(DataVectorFloat.new(V_POSITION,
block_data.vertex_points.to_byte_array().to_float32_array(),
DataVector.DataType.VECTOR3))
set_vertex_data(DataVectorByte.new(V_SELECTED,
block_data.vertex_selected,
DataVector.DataType.BOOL))
set_edge_data(DataVectorByte.new(E_SELECTED,
block_data.edge_selected,
DataVector.DataType.BOOL))
set_face_data(DataVectorInt.new(F_MATERIAL_INDEX,
block_data.face_material_indices,
DataVector.DataType.INT))
set_face_data(DataVectorByte.new(F_VISIBLE,
block_data.face_visible,
DataVector.DataType.BOOL))
set_face_data(DataVectorFloat.new(F_COLOR,
block_data.face_color.to_byte_array().to_float32_array(),
DataVector.DataType.COLOR))
var f_uv_xform:PackedFloat32Array
for t in block_data.face_uv_transform:
f_uv_xform.append_array([t.x.x, t.x.y, t.y.x, t.y.y, t.origin.x, t.origin.y])
set_face_data(DataVectorFloat.new(F_UV_XFORM,
f_uv_xform,
DataVector.DataType.TRANSFORM_2D))
set_face_data(DataVectorByte.new(F_SELECTED,
block_data.face_selected,
DataVector.DataType.BOOL))
set_face_data(DataVectorFloat.new(F_COLOR,
block_data.face_color.to_byte_array().to_float32_array(),
DataVector.DataType.COLOR))
#Create face-vertex data
edge_vertex_indices = block_data.edge_vertex_indices
edge_face_indices = block_data.edge_face_indices
face_vertex_count = block_data.face_vertex_count
face_vertex_indices = block_data.face_vertex_indices
num_face_vertices = 0
for n in block_data.face_vertex_count:
num_face_vertices += n
var fv_array_offset:int = 0
var next_fv_idx:int = 0
var face_indices:PackedInt32Array
var vert_indices:PackedInt32Array
for f_idx in block_data.face_vertex_count.size():
var num_verts_in_face:int = block_data.face_vertex_count[f_idx]
for fv_local_idx in num_verts_in_face:
var v_idx:int = block_data.face_vertex_indices[fv_array_offset + fv_local_idx]
face_indices.append(f_idx)
vert_indices.append(v_idx)
fv_array_offset += num_verts_in_face
set_face_vertex_data(DataVectorInt.new(FV_FACE_INDEX,
face_indices,
DataVector.DataType.INT))
set_face_vertex_data(DataVectorInt.new(FV_VERTEX_INDEX,
vert_indices,
DataVector.DataType.INT))
#set_face_vertex_data(DataVectorInt.new(FV_VERTEX_LOCAL_INDEX,
#fv_local_indices,
#DataVector.DataType.INT))
if block_data.face_vertex_color.is_empty():
#Construct face vertex colors from old face colors system
var col_fv_data:PackedColorArray
for fv_idx in num_face_vertices:
var f_idx:int = face_indices[fv_idx]
var v_idx:int = vert_indices[fv_idx]
col_fv_data.append(block_data.face_color[f_idx])
set_face_vertex_data(DataVectorFloat.new(FV_COLOR,
col_fv_data.to_byte_array().to_float32_array(),
DataVector.DataType.COLOR))
else:
#Copy face vertex colors
set_face_vertex_data(DataVectorFloat.new(FV_COLOR,
block_data.face_vertex_color.to_byte_array().to_float32_array(),
DataVector.DataType.COLOR))
set_face_vertex_data(DataVectorFloat.new(FV_NORMAL,
block_data.face_vertex_normal.to_byte_array().to_float32_array(),
DataVector.DataType.VECTOR3))
func get_vertex_data(vector_name:String)->DataVector:
return vertex_data[vector_name]
func get_edge_data(vector_name:String)->DataVector:
return edge_data[vector_name]
func get_face_data(vector_name:String)->DataVector:
return face_data[vector_name]
func get_face_vertex_data(vector_name:String)->DataVector:
return face_vertex_data[vector_name]
func set_vertex_data(data_vector:DataVector):
vertex_data[data_vector.name] = data_vector
func set_edge_data(data_vector:DataVector):
edge_data[data_vector.name] = data_vector
func set_face_data(data_vector:DataVector):
face_data[data_vector.name] = data_vector
func set_face_vertex_data(data_vector:DataVector):
face_vertex_data[data_vector.name] = data_vector
func validate()->bool:
return true
func create_vector_xml_node(name:String, type:String, value:String)->XMLElement:
var evi_ele:XMLElement = XMLElement.new("vector")
evi_ele.set_attribute("name", name)
evi_ele.set_attribute("type", type)
evi_ele.set_attribute("value", value)
return evi_ele
func section_to_xml(type:String, vertex_data:Dictionary)->XMLElement:
var sec_vertex_ele:XMLElement = XMLElement.new("section")
sec_vertex_ele.set_attribute("type", type)
for vec_name in vertex_data.keys():
var v:DataVector = vertex_data[vec_name]
match v.data_type:
DataVector.DataType.BOOL:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "bool", var_to_str(v.data)))
DataVector.DataType.INT:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "int", var_to_str(v.data)))
DataVector.DataType.FLOAT:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "float", var_to_str(v.data)))
DataVector.DataType.STRING:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "string", var_to_str(v.data)))
DataVector.DataType.COLOR:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "color", var_to_str(v.data)))
DataVector.DataType.VECTOR2:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "vector2", var_to_str(v.data)))
DataVector.DataType.VECTOR3:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "vector3", var_to_str(v.data)))
DataVector.DataType.VECTOR4:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "vector4", var_to_str(v.data)))
DataVector.DataType.TRANSFORM_2D:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "transform2D", var_to_str(v.data)))
DataVector.DataType.TRANSFORM_3D:
sec_vertex_ele.add_child(create_vector_xml_node(v.name, "transform3D", var_to_str(v.data)))
return sec_vertex_ele
func to_xml()->XMLElement:
var rec_ele:XMLElement = XMLElement.new("record")
rec_ele.set_attribute("type", "mesh")
#rec_ele.set_attribute("selected", str(selected))
#rec_ele.set_attribute("active", str(active))
#rec_ele.set_attribute("collision", str(collision))
#rec_ele.set_attribute("physics_layer", str(physics_layer))
#rec_ele.set_attribute("physics_mask", str(physics_mask))
rec_ele.set_attribute("num_vertices", str(num_vertices))
rec_ele.set_attribute("num_edges", str(num_edges))
rec_ele.set_attribute("num_faces", str(num_faces))
rec_ele.set_attribute("num_face_vertices", str(num_face_vertices))
rec_ele.add_child(create_vector_xml_node("edge_vertex_indices", "int", var_to_str(edge_vertex_indices)))
rec_ele.add_child(create_vector_xml_node("edge_face_indices", "int", var_to_str(edge_face_indices)))
rec_ele.add_child(create_vector_xml_node("face_vertex_count", "int", var_to_str(face_vertex_count)))
rec_ele.add_child(create_vector_xml_node("face_vertex_indices", "int", var_to_str(face_vertex_indices)))
rec_ele.set_attribute("active_vertex", str(active_vertex))
rec_ele.set_attribute("active_edge", str(active_edge))
rec_ele.set_attribute("active_face", str(active_face))
rec_ele.set_attribute("active_face_vertex", str(active_face_vertex))
var sec_vertex_ele:XMLElement = XMLElement.new("data")
sec_vertex_ele.set_attribute("type", "vertex")
rec_ele.add_child(sec_vertex_ele)
rec_ele.add_child(section_to_xml("vertex", vertex_data))
rec_ele.add_child(section_to_xml("edge", edge_data))
rec_ele.add_child(section_to_xml("face", face_data))
rec_ele.add_child(section_to_xml("faceVertex", face_vertex_data))
return rec_ele
func to_dictionary(file_builder:CyclopsFileBuilder)->Dictionary:
var result:Dictionary
result["num_vertices"] = num_vertices
result["num_edges"] = num_edges
result["num_faces"] = num_faces
result["num_face_vertices"] = num_face_vertices
result["active_vertex"] = active_vertex
result["active_edge"] = active_edge
result["active_face"] = active_face
result["active_face_vertex"] = active_face_vertex
# vectors["face_vertices"].append(file_builder.export_vector(data_vec))
result["edge_vertex_index_buffer"] = file_builder.export_byte_array(edge_vertex_indices.to_byte_array())
result["edge_face_index_buffer"] = file_builder.export_byte_array(edge_face_indices.to_byte_array())
result["face_vertex_count_buffer"] = file_builder.export_byte_array(face_vertex_count.to_byte_array())
result["face_vertex_index_buffer"] = file_builder.export_byte_array(face_vertex_indices.to_byte_array())
#result["edge_vertex_indices"] = edge_vertex_indices
#result["edge_face_indices"] = edge_face_indices
#
#result["face_vertex_count"] = face_vertex_count
#result["face_vertex_indices"] = face_vertex_indices
var vectors:Dictionary = {
"vertices": [],
"edges": [],
"faces": [],
"face_vertices": []
}
result["vectors"] = vectors
for key in vertex_data.keys():
var data_vec:DataVector = vertex_data[key]
# vectors["vertices"].append(data_vec.to_dictionary(buf_ar))
vectors["vertices"].append(file_builder.export_vector(data_vec))
for key in edge_data.keys():
var data_vec:DataVector = edge_data[key]
# vectors["edges"].append(data_vec.to_dictionary(buf_ar))
vectors["edges"].append(file_builder.export_vector(data_vec))
for key in face_data.keys():
var data_vec:DataVector = face_data[key]
# vectors["faces"].append(data_vec.to_dictionary(buf_ar))
vectors["faces"].append(file_builder.export_vector(data_vec))
for key in face_vertex_data.keys():
var data_vec:DataVector = face_vertex_data[key]
# vectors["face_vertices"].append(data_vec.to_dictionary(buf_ar))
vectors["face_vertices"].append(file_builder.export_vector(data_vec))
return result
#func export_vector(vec:DataVector, file_builder:CyclopsFileBuilder)->Dictionary:
#var result:Dictionary
#
#result["name"] = vec.name
#result["data_type"] = DataVector.DataType.values()[vec.data_type]
#if vec.stride != 1:
#result["stride"] = vec.stride
#if !vec.category.is_empty():
#result["category"] = vec.category
#
#var region:BufferArchive.BufferRegion = file_builder.buf_ar.store_buffer(vec.get_buffer_byte_data())
#result["data_buffer"] = region.index
#
#return result

View file

@ -0,0 +1,50 @@
# 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 Resource
class_name ToolTag
@export var id:String
@export var name:String
@export var input_events: Array[InputEvent] = []
@export var input_events_override := false
@export_multiline var tooltip:String
@export var icon:Texture2D
@export var tool_script:Script
var tool:CyclopsTool
func _activate(plugin:CyclopsLevelBuilder):
if !tool_script:
return
if !tool:
tool = tool_script.new()
# print("Activating %s" % tool_script.resource_path)
# print("tool id %s" % tool._get_tool_id())
# print("Activating %s" % name)
plugin.switch_to_tool(tool)