initial commit

This commit is contained in:
2023-05-24 00:27:34 +03:00
commit 11ee2c7949
174 changed files with 13452 additions and 0 deletions

View File

@ -0,0 +1,143 @@
# 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 Node3D
class_name CyclopsBlocks
signal blocks_changed
@export var occluder_vertex_offset:float = 0:
get:
return occluder_vertex_offset
set(value):
occluder_vertex_offset = value
dirty = true
var dirty:bool = true
var block_bodies:Node3D
# Called when the node enters the scene tree for the first time.
func _ready():
child_entered_tree.connect(on_child_entered_tree)
child_exiting_tree.connect(on_child_exiting_tree)
block_bodies = Node3D.new()
block_bodies.name = "block_bodies"
add_child(block_bodies)
for node in get_children():
if node is CyclopsConvexBlock:
var block:CyclopsConvexBlock = node
block.mesh_changed.connect(on_child_mesh_changed)
func on_child_mesh_changed():
dirty = true
blocks_changed.emit()
func on_child_entered_tree(node:Node):
if node is CyclopsConvexBlock:
var block:CyclopsConvexBlock = node
block.mesh_changed.connect(on_child_mesh_changed)
# print("on_child_entered_tree %s" % node.name)
dirty = true
func on_child_exiting_tree(node:Node):
if node is CyclopsConvexBlock:
var block:CyclopsConvexBlock = node
block.mesh_changed.disconnect(on_child_mesh_changed)
# print("on_child_exited_tree %s" % node.name)
dirty = true
func has_selected_blocks()->bool:
for child in get_children():
if child is CyclopsConvexBlock and child.selected:
return true
return false
func rebuild_mesh():
for child in block_bodies.get_children():
child.queue_free()
for child in get_children():
if child is CyclopsConvexBlock:
var block:CyclopsConvexBlock = child
# var block_body:CyclopsConvexBlockBody = preload("res://addons/cyclops_level_builder/nodes/cyclops_convex_block_body.gd").instantiate()
var block_body:CyclopsConvexBlockBody = CyclopsConvexBlockBody.new()
block_body.materials = block.materials
block_body.block_data = block.block_data
block_bodies.add_child(block_body)
dirty = false
func get_active_block()->CyclopsConvexBlock:
for child in get_children():
if child is CyclopsConvexBlock:
var block:CyclopsConvexBlock = child
if block.active:
return block
return null
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if dirty:
rebuild_mesh()
func _input(event):
if Engine.is_editor_hint():
pass
#print(event.as_text())
pass
func intersect_ray_closest(origin:Vector3, dir:Vector3)->IntersectResults:
return intersect_ray_closest_filtered(origin, dir, func(block:CyclopsConvexBlock): return true)
func intersect_ray_closest_selected_only(origin:Vector3, dir:Vector3)->IntersectResults:
return intersect_ray_closest_filtered(origin, dir, func(block:CyclopsConvexBlock): return block.selected)
func intersect_ray_closest_filtered(origin:Vector3, dir:Vector3, filter:Callable)->IntersectResults:
var best_result:IntersectResults
for child in get_children():
if child is CyclopsConvexBlock:
var result:IntersectResults = child.intersect_ray_closest(origin, dir)
if result:
if !filter.call(result.object):
continue
if !best_result or result.distance_squared < best_result.distance_squared:
best_result = result
return best_result

Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bdmaqfi82aq41"
path="res://.godot/imported/cyclops_blocks_icon.png-24c4441d9ebe4c1c02b0cf9fcbf537f3.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/cyclops_level_builder/nodes/cyclops_blocks_icon.png"
dest_files=["res://.godot/imported/cyclops_blocks_icon.png-24c4441d9ebe4c1c02b0cf9fcbf537f3.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="16"
height="16"
viewBox="0 0 16 16"
version="1.1"
id="svg5"
sodipodi:docname="cyclops_blocks_icon.svg"
inkscape:version="1.2.2 (732a01da63, 2022-12-09)"
inkscape:export-filename="cyclops_blocks_icon.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#111111"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="1"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
showgrid="false"
inkscape:zoom="18.495262"
inkscape:cx="6.8125556"
inkscape:cy="15.625623"
inkscape:window-width="1920"
inkscape:window-height="1017"
inkscape:window-x="1912"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs2" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:none;stroke:#ff8080;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
d="M 1.2454232,11.434424 V 6.9691417 L 10.05946,1.5087391 14.812743,6.0760853 V 10.592399 L 6.5338449,14.70046 Z"
id="path122"
sodipodi:nodetypes="ccccccc" />
<path
style="fill:none;stroke:#ff8080;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
d="M 1.3083806,6.9691417 6.5653235,10.005533 14.718308,6.1526332"
id="path124"
sodipodi:nodetypes="ccc" />
<path
style="fill:none;stroke:#ff8080;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
d="M 10.027981,1.6363186 6.5653235,9.9289853"
id="path126"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#ff8080;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
d="m 6.5653235,10.056566 v 4.490798"
id="path860"
sodipodi:nodetypes="cc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://chuwp6awho53q"
path="res://.godot/imported/cyclops_blocks_icon.svg-5e216ef2489ff1d30c472c6b8748fdf1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/cyclops_level_builder/nodes/cyclops_blocks_icon.svg"
dest_files=["res://.godot/imported/cyclops_blocks_icon.svg-5e216ef2489ff1d30c472c6b8748fdf1.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View File

@ -0,0 +1,123 @@
# 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 Node
class_name CyclopsConvexBlock
signal mesh_changed
@export var materials:Array[Material]
var control_mesh:ConvexVolume
var selected:bool = false:
get:
return selected
set(value):
if value == selected:
return
selected = value
mesh_changed.emit()
var active:bool:
get:
return active
set(value):
if value == active:
return
active = value
mesh_changed.emit()
var default_material:Material = preload("res://addons/cyclops_level_builder/materials/grid.tres")
@export var block_data:ConvexBlockData:
get:
return block_data
set(value):
if block_data != value:
block_data = value
control_mesh = ConvexVolume.new()
control_mesh.init_from_convex_block_data(block_data)
mesh_changed.emit()
func intersect_ray_closest(origin:Vector3, dir:Vector3)->IntersectResults:
if !block_data:
return null
var result:IntersectResults = control_mesh.intersect_ray_closest(origin, dir)
if result:
result.object = self
return result
func select_face(face_idx:int, select_type:Selection.Type = Selection.Type.REPLACE):
if select_type == Selection.Type.REPLACE:
for f in control_mesh.faces:
f.selected = f.index == face_idx
elif select_type == Selection.Type.ADD:
control_mesh.faces[face_idx].selected = true
elif select_type == Selection.Type.SUBTRACT:
control_mesh.faces[face_idx].selected = true
elif select_type == Selection.Type.TOGGLE:
control_mesh.faces[face_idx].selected = !control_mesh.faces[face_idx].selected
mesh_changed.emit()
func append_mesh(mesh:ImmediateMesh):
# print("adding block mesh %s" % name)
#var global_scene:CyclopsGlobalScene = get_node("/root/CyclopsAutoload")
control_mesh.append_mesh(mesh, materials, default_material)
func append_mesh_wire(mesh:ImmediateMesh):
var global_scene:CyclopsGlobalScene = get_node("/root/CyclopsAutoload")
var mat:Material = global_scene.outline_material
control_mesh.append_mesh_wire(mesh, mat)
func append_mesh_backfacing(mesh:ImmediateMesh):
var global_scene:CyclopsGlobalScene = get_node("/root/CyclopsAutoload")
var mat:Material = global_scene.tool_object_selected_material
control_mesh.append_mesh_backfacing(mesh, mat)
func append_mesh_outline(mesh:ImmediateMesh, viewport_camera:Camera3D, local_to_world:Transform3D):
var global_scene:CyclopsGlobalScene = get_node("/root/CyclopsAutoload")
var mat:Material = global_scene.tool_object_active_material if active else global_scene.tool_object_selected_material
control_mesh.append_mesh_outline(mesh, viewport_camera, local_to_world, mat)
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

View File

@ -0,0 +1,141 @@
# 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 Node3D
class_name CyclopsConvexBlockBody
var mesh_instance:MeshInstance3D
var mesh_wire:MeshInstance3D
var collision_body:StaticBody3D
var collision_shape:CollisionShape3D
var occluder:OccluderInstance3D
var dirty:bool = true
@export var block_data:ConvexBlockData:
get:
return block_data
set(value):
block_data = value
dirty = true
@export var materials:Array[Material]
var default_material:Material = preload("res://addons/cyclops_level_builder/materials/grid.tres")
var display_mode:DisplayMode.Type = DisplayMode.Type.TEXTURED
# Called when the node enters the scene tree for the first time.
func _ready():
mesh_instance = MeshInstance3D.new()
add_child(mesh_instance)
mesh_instance.gi_mode = GeometryInstance3D.GI_MODE_STATIC
if Engine.is_editor_hint():
mesh_wire = MeshInstance3D.new()
add_child(mesh_wire)
collision_body = StaticBody3D.new()
add_child(collision_body)
collision_shape = CollisionShape3D.new()
collision_body.add_child(collision_shape)
occluder = OccluderInstance3D.new()
add_child(occluder)
build_from_block()
func build_from_block():
dirty = false
mesh_instance.mesh = null
collision_shape.shape = null
if Engine.is_editor_hint():
# var global_scene:CyclopsGlobalScene = get_node("/root/CyclopsAutoload")
var global_scene = get_node("/root/CyclopsAutoload")
display_mode = global_scene.builder.display_mode
# print("block_data %s" % block_data)
# print("vert points %s" % block_data.vertex_points)
if !block_data:
return
# print("got block data")
var vol:ConvexVolume = ConvexVolume.new()
vol.init_from_convex_block_data(block_data)
#print("volume %s" % vol)
# var mesh:ImmediateMesh = ImmediateMesh.new()
var mesh:ArrayMesh
if Engine.is_editor_hint():
# var global_scene:CyclopsGlobalScene = get_node("/root/CyclopsAutoload")
var global_scene = get_node("/root/CyclopsAutoload")
mesh_wire.mesh = vol.create_mesh_wire(global_scene.outline_material)
#print ("added wireframe")
if display_mode == DisplayMode.Type.TEXTURED:
mesh = vol.create_mesh(materials, default_material)
#print ("added faces")
else:
mesh = vol.create_mesh(materials, default_material)
# vol.append_mesh(mesh, materials, default_material)
mesh_instance.mesh = mesh
# print("===============")
# GeneralUtil.dump_properties(mesh_instance)
# print("---------------")
# GeneralUtil.dump_properties(mesh_instance.mesh)
var shape:ConvexPolygonShape3D = ConvexPolygonShape3D.new()
shape.points = vol.get_points()
collision_shape.shape = shape
if !Engine.is_editor_hint():
#Disabling this in the editor for now since this is causing slowdown
var occluder_object:ArrayOccluder3D = ArrayOccluder3D.new()
occluder_object.vertices = vol.get_points()
occluder_object.indices = vol.get_trimesh_indices()
occluder.occluder = occluder_object
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if dirty:
build_from_block()
if Engine.is_editor_hint():
# var global_scene:CyclopsGlobalScene = get_node("/root/CyclopsAutoload")
var global_scene = get_node("/root/CyclopsAutoload")
if display_mode != global_scene.builder.display_mode:
dirty = true
return

View File

@ -0,0 +1,35 @@
# 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 RefCounted
class_name IntersectResults
var object:CyclopsConvexBlock
var face_id:int
var position:Vector3
var normal:Vector3
var distance_squared:float
func _to_string():
return "object:%s face_id:%s pos:%s norm:%s dist_sq:%s" % [object, face_id, position, normal, distance_squared]