Skip to content

Commit

Permalink
Fixes for issue #4 and #5
Browse files Browse the repository at this point in the history
  • Loading branch information
markeel committed May 22, 2023
1 parent 3dfae5e commit 4936aa6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 12 deletions.
17 changes: 17 additions & 0 deletions addons/vizpath/resources/viz_head.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ class_name VizHead
length_factor = l
emit_changed()

## The get_offset function will be called to shift the end of the last
## segment to accomodate the head mesh
##
## This class can be overridden to provide a custom head to the path
## by defining a resource that has an apply method with the following
## definition:
##
## The [code]left[/code] and [code]right[/code] positions at the end of the path, where the
## V texture coordinate is 0.0 for [code]left[/code] and 1.0 for [code]right[/code].
## The [code]normal[/code] and the [code]direction[/code] define the position of the face and the
## direction that the path is going.
func get_offset(left : Vector3, right : Vector3, normal : Vector3, direction : Vector3) -> float:
var segment := right - left
var segment_len := segment.length()
var arrow_point_len := segment_len * length_factor
return arrow_point_len

## The apply function will be called when the path
## mesh is created.
##
Expand Down
14 changes: 14 additions & 0 deletions addons/vizpath/resources/viz_tail.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ class_name VizTail
num_segs = s
emit_changed()

## The get_offset function will be called to shift the beginning of the first
## segment to accomodate the tail mesh
##
## This class can be overridden to provide a custom head to the path
## by defining a resource that has an apply method with the following
## definition:
##
## The [code]left[/code] and [code]right[/code] positions at the start of the path, where the
## V texture coordinate is 0.0 for [code]left[/code] and 1.0 for [code]right[/code].
## The [code]normal[/code] and the [code]direction[/code] define the position of the face and the
## direction that the path is going.
func get_offset(left : Vector3, right : Vector3, normal : Vector3, direction : Vector3) -> float:
return 0.0

## The apply function will be called when the path
## mesh is created.
##
Expand Down
3 changes: 0 additions & 3 deletions addons/vizpath/utilities/viz_simple_leg.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ var _width : float
var _bend_lip : float
var _bend : VizBend

var tri_mat : Material = load("res://example/common/materials/white.tres")
var bend_mat : Material = load("res://example/common/materials/red.tres")

const MIN_SEGMENT_LENGTH=0.01
const EPSILON=0.00001

Expand Down
32 changes: 25 additions & 7 deletions addons/vizpath/visualized_path.gd
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ signal changed_layout
path_tail.changed.connect(_rebuild)
_rebuild()

@export var suppress_warnings := false :
set(s):
suppress_warnings = s
_rebuild()

var _mesh_instance : MeshInstance3D
var _errors : Array[String]

Expand All @@ -121,7 +126,9 @@ func _ready():
_rebuild()

func _get_configuration_warnings():
return PackedStringArray(_errors)
if not suppress_warnings:
return PackedStringArray(_errors)
return PackedStringArray()

func get_errors() -> Array[String]:
return _errors
Expand Down Expand Up @@ -149,15 +156,17 @@ func _rebuild():
if segments[idx-1].is_invalid():
_errors.push_back(segments[idx-1].get_error())
break
if idx == 1:
u = _add_tail(segments[idx-1], u)
u = segments[idx-1].update_mesh(_mesh_instance, u, bend_segs, bend_sharpness, path_mat)
u = midpoint.update_mesh(_mesh_instance, u, num_curve_segs, path_mat)
if _errors.size() == 0:
if segments[segments.size()-1].is_invalid():
_errors.push_back(segments[segments.size()-1].get_error())
else:
u = segments[segments.size()-1].update_mesh(_mesh_instance, u, bend_segs, bend_sharpness, path_mat)
if segments.size() == 1:
u = _add_tail(segments[0], u)
_add_head(segments[segments.size()-1], u)
_add_tail(segments[0], 0.0)
update_configuration_warnings()
changed_layout.emit()

Expand All @@ -169,14 +178,23 @@ func _add_head(head : VizSegment, u : float):
var right := end + binormal * path_width / 2.0
var normal := head.get_end().normal
var direction := head.get_end_ray()
path_head.apply(_mesh_instance, u, left, right, normal, direction, path_mat)

func _add_tail(tail : VizSegment, u : float):
var offset := path_head.get_offset(left, right, normal, direction)
head.adjust_end(offset)
u = head.update_mesh(_mesh_instance, u, bend_segs, bend_sharpness, path_mat)
path_head.apply(_mesh_instance, u, left - direction * offset, right - direction * offset, normal, direction, path_mat)
else:
head.update_mesh(_mesh_instance, u, bend_segs, bend_sharpness, path_mat)

func _add_tail(tail : VizSegment, u : float) -> float:
if path_tail != null:
var begin := tail.get_begin().point
var binormal := tail.get_begin_binormal()
var left := begin - binormal * path_width / 2.0
var right := begin + binormal * path_width / 2.0
var normal := tail.get_begin().normal
var direction := tail.get_begin_ray()
path_tail.apply(_mesh_instance, u, left, right, normal, direction, path_mat)
var offset := path_tail.get_offset(left, right, normal, direction)
tail.adjust_begin(offset)
path_tail.apply(_mesh_instance, u, left - direction * offset, right - direction * offset, normal, direction, path_mat)
return u + offset
return u
4 changes: 2 additions & 2 deletions example/vizpath/two_bend/two_bend.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[ext_resource type="Script" path="res://addons/vizpath/visualized_path.gd" id="1_3gjiw"]
[ext_resource type="Script" path="res://example/two_bend/two_bend.gd" id="1_avpar"]
[ext_resource type="Script" path="res://addons/vizpath/resources/spot.gd" id="2_xhjfb"]
[ext_resource type="Material" uid="uid://bb6vecpbvsco2" path="res://example/common/materials/green.tres" id="4_dnqvd"]
[ext_resource type="Material" uid="uid://c4qytbc7juuoa" path="res://example/common/materials/move.tres" id="5_cr2c7"]
[ext_resource type="Material" uid="uid://bb6vecpbvsco2" path="res://example/vizpath/common/materials/green.tres" id="4_dnqvd"]
[ext_resource type="Material" uid="uid://c4qytbc7juuoa" path="res://example/vizpath/common/materials/move.tres" id="5_cr2c7"]

[sub_resource type="Resource" id="Resource_m5l7s"]
script = ExtResource("2_xhjfb")
Expand Down
Binary file modified source/vizpath/ladder.blend
Binary file not shown.

0 comments on commit 4936aa6

Please sign in to comment.