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,293 @@
# 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 CyclopsBlock
signal mesh_changed
var mesh_instance:MeshInstance3D
var mesh_wire:MeshInstance3D
var collision_body:PhysicsBody3D
var collision_shape:CollisionShape3D
var active:bool
var dirty:bool = true
var control_mesh:ConvexVolume
@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)
#Convert to mesh vector data
var mvd:MeshVectorData = MeshVectorData.new()
mvd.create_from_convex_block(block_data)
mesh_vector_data = mvd
#dirty = true
#mesh_changed.emit()
@export var mesh_vector_data:MeshVectorData:
set(value):
if mesh_vector_data != value:
mesh_vector_data = value
control_mesh = ConvexVolume.new()
control_mesh.init_from_mesh_vector_data(mesh_vector_data)
dirty = true
mesh_changed.emit()
@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.MATERIAL
@export var collision_type:Collision.Type = Collision.Type.STATIC:
get:
return collision_type
set(value):
collision_type = value
update_physics_body()
@export_flags_3d_physics var collision_layer:int = 1:
get:
return collision_layer
set(value):
collision_layer = value
if collision_body:
collision_body.collision_layer = collision_layer
@export_flags_3d_physics var collision_mask:int = 1:
get:
return collision_mask
set(value):
collision_mask = value
if collision_body:
collision_body.collision_mask = collision_mask
# 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
#print("block owner path %s" % owner.get_path())
if Engine.is_editor_hint():
mesh_wire = MeshInstance3D.new()
add_child(mesh_wire)
collision_shape = CollisionShape3D.new()
#occluder = OccluderInstance3D.new()
#add_child(occluder)
build_from_block()
update_physics_body()
func update_physics_body():
if collision_body:
collision_body.remove_child(collision_shape)
collision_body.queue_free()
collision_body = null
match 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 = collision_layer
collision_body.collision_mask = collision_mask
add_child(collision_body)
collision_body.add_child(collision_shape)
func build_from_block():
#print("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
if !mesh_vector_data:
return
# print("got block data")
var vol:ConvexVolume = ConvexVolume.new()
vol.init_from_mesh_vector_data(mesh_vector_data)
#vol.init_from_convex_block_data(block_data)
#print("volume %s" % vol)
var mesh:ArrayMesh
if Engine.is_editor_hint():
var global_scene = get_node("/root/CyclopsAutoload")
mesh_wire.mesh = vol.create_mesh_wire(global_scene.outline_material)
#print ("added wireframe")
#print("rebuilding mesh")
if display_mode == DisplayMode.Type.MATERIAL:
mesh = vol.create_mesh(materials, default_material)
if display_mode == DisplayMode.Type.MESH:
mesh = vol.create_mesh(materials, default_material, true)
#print ("added faces")
else:
mesh = vol.create_mesh(materials, default_material)
mesh_instance.mesh = 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
func draw_unit_labels(viewport_camera:Camera3D, local_to_world:Transform3D):
var global_scene:CyclopsGlobalScene = get_node("/root/CyclopsAutoload")
var font:Font = global_scene.units_font
var font_size:float = global_scene.units_font_size
var descent:float = font.get_descent(font_size)
var text_offset:Vector2 = Vector2(0, -global_scene.vertex_radius - descent)
if control_mesh:
for e_idx in control_mesh.edges.size():
var e:ConvexVolume.EdgeInfo = control_mesh.edges[e_idx]
var focus:Vector3 = local_to_world * e.get_midpoint()
if !viewport_camera.is_position_behind(focus):
var focus_2d:Vector2 = viewport_camera.unproject_position(focus)
var v0:ConvexVolume.VertexInfo = control_mesh.vertices[e.start_index]
var v1:ConvexVolume.VertexInfo = control_mesh.vertices[e.end_index]
var distance:Vector3 = v1.point - v0.point
global_scene.draw_text("%.3f" % distance.length(), focus_2d, font, font_size)
func append_mesh_outline(mesh:ImmediateMesh, viewport_camera:Camera3D, local_to_world:Transform3D, mat:Material):
#var global_scene:CyclopsGlobalScene = get_node("/root/CyclopsAutoload")
if control_mesh:
control_mesh.append_mesh_outline(mesh, viewport_camera, local_to_world, mat)
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 intersect_ray_closest(origin:Vector3, dir:Vector3)->IntersectResults:
if !mesh_vector_data:
return null
var xform:Transform3D = global_transform.affine_inverse()
var origin_local:Vector3 = xform * origin
var dir_local:Vector3 = xform.basis * dir
var result:IntersectResults = control_mesh.intersect_ray_closest(origin_local, dir_local)
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 export_to_cyclops_file(file_builder:CyclopsFileBuilder)->Dictionary:
var result:Dictionary
result["collision_type"] = Collision.Type.keys()[collision_type]
result["collision_layer"] = collision_layer
result["collision_mask"] = collision_mask
var mat_res_paths:PackedStringArray
for mat in materials:
if mat:
mat_res_paths.append(mat.resource_path)
else:
mat_res_paths.append("")
result["materials"] = mat_res_paths
if mesh_vector_data:
result["mesh"] = mesh_vector_data.to_dictionary(file_builder)
#build_mesh["mesh"] = cur_node.mesh_vector_data.to_dictionary(self)
return result

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 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
func intersect_frustum_all(frustum:Array[Plane])->Array[CyclopsConvexBlock]:
var result:Array[CyclopsConvexBlock] = []
for child in get_children():
if child is CyclopsConvexBlock:
var block:CyclopsConvexBlock = child
var vol:ConvexVolume = block.control_mesh
if vol.intersects_frustum(frustum):
result.append(block)
return 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,124 @@
# 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
result.object = null
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,142 @@
# 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.MATERIAL
# 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)
if display_mode == DisplayMode.Type.MATERIAL:
mesh = vol.create_mesh(materials, default_material)
elif display_mode == DisplayMode.Type.MESH:
mesh = vol.create_mesh(materials, default_material, true)
#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 Node3D
class_name CyclopsScene
# 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,44 @@
# 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:CyclopsBlock
#var face_id:int
var face_index:int
var position:Vector3 #local space of block
var normal:Vector3
var distance_squared:float
func get_world_position()->Vector3:
return object.global_transform * position
func get_world_normal()->Vector3:
var basis:Basis = object.global_transform.basis
var basis_normals:Basis = basis.inverse().transposed()
return basis_normals * normal
func _to_string():
return "object:%s face_idx:%s pos:%s norm:%s dist_sq:%s" % [object, face_index, position, normal, distance_squared]