Added pointed cube wireframe

master
Marc Gilleron 2017-03-26 20:57:50 +02:00
parent 7cf17fc425
commit 2799ff67a3
4 changed files with 147 additions and 42 deletions

View File

@ -0,0 +1,89 @@
extends Node
export(NodePath) var terrain_path = null
export(Material) var cursor_material = null
var _terrain = null
var _cursor = null
onready var _head = get_parent().get_node("Camera")
func _ready():
_terrain = get_node(terrain_path)
_cursor = _make_cursor()
_terrain.add_child(_cursor)
func _fixed_process(delta):
if _terrain == null:
return
var origin = _head.get_global_transform().origin
var forward = -_head.get_transform().basis.z.normalized()
var hit = _terrain.raycast(origin, forward, 10)
var label = get_parent().get_node("debug_label")
if hit != null:
label.text = str(hit.position)
_cursor.show()
_cursor.set_translation(hit.position + Vector3(1,1,1)*0.5)
else:
label.text = "---"
_cursor.hide()
func _make_cursor():
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_LINES)
_add_wireframe_cube(st, -Vector3(1,1,1)*0.5, 1, Color(0,0,0))
var mesh = st.commit()
var mesh_instance = MeshInstance.new()
mesh_instance.mesh = mesh
if cursor_material != null:
mesh_instance.material_override = cursor_material
mesh_instance.set_scale(Vector3(1,1,1)*1.01)
return mesh_instance
static func _add_wireframe_cube(st, pos, step, color):
st.add_color(color)
st.add_vertex(pos)
st.add_vertex(pos + Vector3(step, 0, 0))
st.add_vertex(pos + Vector3(step, 0, 0))
st.add_vertex(pos + Vector3(step, 0, step))
st.add_vertex(pos + Vector3(step, 0, step))
st.add_vertex(pos + Vector3(0, 0, step))
st.add_vertex(pos + Vector3(0, 0, step))
st.add_vertex(pos)
st.add_vertex(pos + Vector3(0, step, 0))
st.add_vertex(pos + Vector3(step, step, 0))
st.add_vertex(pos + Vector3(step, step, 0))
st.add_vertex(pos + Vector3(step, step, step))
st.add_vertex(pos + Vector3(step, step, step))
st.add_vertex(pos + Vector3(0, step, step))
st.add_vertex(pos + Vector3(0, step, step))
st.add_vertex(pos + Vector3(0, step, 0))
st.add_vertex(pos)
st.add_vertex(pos + Vector3(0, step, 0))
st.add_vertex(pos + Vector3(step, 0, 0))
st.add_vertex(pos + Vector3(step, step, 0))
st.add_vertex(pos + Vector3(step, 0, step))
st.add_vertex(pos + Vector3(step, step, step))
st.add_vertex(pos + Vector3(0, 0, step))
st.add_vertex(pos + Vector3(0, step, step))

View File

@ -1,13 +1,48 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://character_controller.gd" type="Script" id=1]
[ext_resource path="res://mouse_look.gd" type="Script" id=2]
[ext_resource path="res://avatar_interaction.gd" type="Script" id=3]
[sub_resource type="CapsuleShape" id=1]
radius = 0.4
height = 0.85
[sub_resource type="FixedSpatialMaterial" id=2]
flags_transparent = false
flags_unshaded = false
flags_on_top = false
flags_use_point_size = false
vertex_color_use_as_albedo = true
vertex_color_is_srgb = false
params_diffuse_mode = 0
params_blend_mode = 0
params_cull_mode = 0
params_depth_draw_mode = 0
params_line_width = 2.0
params_point_size = 1.0
albedo_color = Color( 1, 1, 1, 1 )
specular_mode = 0
specular_color = Color( 0.1, 0.1, 0.1, 1 )
specular_metalness = 0.1
specular_roughness = 0.0
emission_enabled = false
normal_enabled = false
rim_enabled = false
clearcoat_enabled = false
anisotropy_enabled = false
ao_enabled = false
height_enabled = false
subsurf_scatter_enabled = false
refraction_enabled = false
detail_enabled = false
uv1_scale = Vector2( 1, 1 )
uv1_offset = Vector2( 0, 0 )
uv2_scale = Vector2( 1, 1 )
uv2_offset = Vector2( 0, 0 )
[node name="CharacterAvatar" type="KinematicBody"]
_import_transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
@ -58,4 +93,21 @@ min_angle = -90
max_angle = 90
capture_mouse = true
[node name="interaction" type="Node" parent="."]
script = ExtResource( 3 )
terrain_path = null
cursor_material = SubResource( 2 )
[node name="debug_label" type="Label" parent="."]
margin_right = 137.0
margin_bottom = 14.0
rect_clip_content = false
mouse_filter = 2
size_flags_vertical = 0
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1

View File

@ -33,44 +33,3 @@ func _ready():
mesh = st.commit()
#set_mesh(mesh)
#func _add_wireframe_cube(st, pos):
#
# st.add_vertex(pos)
# st.add_vertex(pos + Vector3(step, 0, 0))
#
# st.add_vertex(pos + Vector3(step, 0, 0))
# st.add_vertex(pos + Vector3(step, 0, step))
#
# st.add_vertex(pos + Vector3(step, 0, step))
# st.add_vertex(pos + Vector3(0, 0, step))
#
# st.add_vertex(pos + Vector3(0, 0, step))
# st.add_vertex(pos)
#
#
# st.add_vertex(pos + Vector3(0, step, 0))
# st.add_vertex(pos + Vector3(step, step, 0))
#
# st.add_vertex(pos + Vector3(step, step, 0))
# st.add_vertex(pos + Vector3(step, step, step))
#
# st.add_vertex(pos + Vector3(step, step, step))
# st.add_vertex(pos + Vector3(0, step, step))
#
# st.add_vertex(pos + Vector3(0, step, step))
# st.add_vertex(pos + Vector3(0, step, 0))
#
#
# st.add_vertex(pos)
# st.add_vertex(pos + Vector3(0, step, 0))
#
# st.add_vertex(pos + Vector3(step, 0, 0))
# st.add_vertex(pos + Vector3(step, step, 0))
#
# st.add_vertex(pos + Vector3(step, 0, step))
# st.add_vertex(pos + Vector3(step, step, step))
#
# st.add_vertex(pos + Vector3(0, 0, step))
# st.add_vertex(pos + Vector3(0, step, step))

View File

@ -281,4 +281,9 @@ speed = 4.0
gravity = 30.0
jump_force = 10.0
[node name="interaction" parent="CharacterAvatar"]
terrain_path = NodePath("../../VoxelTerrain")
[editable path="CharacterAvatar"]