Reduced gunk mask resolution

This commit is contained in:
Rob Kelly 2025-03-02 13:16:40 -07:00
parent 37b377fac0
commit 3230afe301
7 changed files with 38 additions and 8 deletions

View File

@ -180,7 +180,7 @@ shape = SubResource("ConcavePolygonShape3D_hvf6a")
[node name="Cube" parent="Geometry" instance=ExtResource("1_a67lu")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8, 4, 0)
mask_dim = 4096
mask_dim = 1024
[node name="MeshInstance3D" type="MeshInstance3D" parent="Geometry/Cube"]
mesh = ExtResource("6_4kku3")
@ -191,7 +191,7 @@ shape = SubResource("ConcavePolygonShape3D_0qjrr")
[node name="Cylinder" parent="Geometry" instance=ExtResource("1_a67lu")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.33738, 6, -7.18125)
mask_dim = 4096
mask_dim = 1024
[node name="MeshInstance3D" type="MeshInstance3D" parent="Geometry/Cylinder"]
mesh = ExtResource("7_gn6k6")

View File

@ -1,7 +1,7 @@
class_name PointSpray extends Spray
## Simple single-point spraygun
@export var spray_scale := 16.0
@export var spray_scale := 3.0
@onready var raycast: RayCast3D = %RayCast3D
@onready var spray_effect: MeshInstance3D = %SprayEffect

View File

@ -3,7 +3,7 @@ class_name WideSpray extends Spray
const SPRAYCAST_GROUP := "SprayCast"
@export var spray_scale := 16.0
@export var spray_scale := 3.0
@onready var spray_casts: Node3D = %SprayCasts
@onready var spray_effect: MeshInstance3D = %SprayEffect

View File

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://src/player/player.gd" id="1_npueo"]
[ext_resource type="Script" path="res://src/player/camera_controller.gd" id="2_veeqv"]
[ext_resource type="PackedScene" uid="uid://cc102xko0u6yj" path="res://src/equipment/point_spray/point_spray.tscn" id="3_8n2h0"]
[ext_resource type="PackedScene" uid="uid://d2hnxr5l6w2x4" path="res://src/equipment/wide_spray/wide_spray.tscn" id="3_ibq07"]
[sub_resource type="BoxMesh" id="BoxMesh_ua7a2"]
size = Vector3(0.05, 0.05, 0.3)
@ -30,7 +30,7 @@ mesh = SubResource("BoxMesh_ua7a2")
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 0.997564, -0.0697565, 0, 0.0697565, 0.997564, 0, 0, -0.15)
[node name="PointSpray" parent="CameraPivot/SprayNozzle/SprayMuzzle" instance=ExtResource("3_8n2h0")]
[node name="WideSpray" parent="CameraPivot/SprayNozzle/SprayMuzzle" instance=ExtResource("3_ibq07")]
[node name="Camera3D" type="Camera3D" parent="CameraPivot"]
current = true

View File

@ -1,8 +1,11 @@
class_name DrawController extends Control
## Emitted the frame after at least one paint operation was done.
signal painted
var _draw_queue: Array[Callable] = []
var _dirty := true
var _dirty := false
func queue_draw(op: Callable) -> void:
@ -20,3 +23,4 @@ func _process(_delta: float) -> void:
if _dirty:
queue_redraw()
_dirty = false
painted.emit()

View File

@ -6,7 +6,7 @@ const BUFFER_LIMIT := 3
const FACE_EPSILON := 0.4
const MASK_COLOR := Color.RED
@export var mask_dim := 1024
@export var mask_dim := 256
var meshtool := MeshDataTool.new()
@ -16,6 +16,9 @@ var _continued_paint_this_frame := false
var _multiline_buffer := PackedVector2Array()
var _multiline_width := 1.0
var _clear_total := 0.0
var _clear_total_dirty := true
@onready var mesh_instance: MeshInstance3D = $MeshInstance3D
@onready var mesh: ArrayMesh = mesh_instance.mesh
@onready var gunk_mat: ShaderMaterial = mesh_instance.get_surface_override_material(0).next_pass
@ -30,6 +33,23 @@ func _ready() -> void:
meshtool.create_from_surface(mesh, 0)
## Get the precise number of gunk pixels cleared from this image.
##
## This will use a cached result unless the mask has been painted since the last calculation.
## Be aware that cache misses are potentially quite expensive.
func get_clear_total() -> float:
if _clear_total_dirty:
var mask_img := mask_viewport.get_texture().get_image()
mask_img.convert(Image.FORMAT_R8)
var px_data := mask_img.get_data()
var px_sum := 0
for px in px_data:
px_sum += px
_clear_total = px_sum / 255.0
_clear_total_dirty = false
return _clear_total
## Transform cartesian coordinates to barycentric wrt the given triangle.
func _barycentric(p: Vector3, a: Vector3, b: Vector3, c: Vector3) -> Vector3:
var v0 := b - a
@ -156,3 +176,7 @@ func _process(_delta: float) -> void:
func() -> void: mask_control.draw_multiline(points, MASK_COLOR, width, true)
)
_multiline_buffer = PackedVector2Array()
func _on_mask_painted() -> void:
_clear_total_dirty = true

View File

@ -25,3 +25,5 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("2_kkcjw")
[connection signal="painted" from="MaskViewport/MaskControl" to="." method="_on_mask_painted"]