Skip to content

Commit

Permalink
Made plugin compatible with asset lib
Browse files Browse the repository at this point in the history
Made plugin compatible with asset lib

Made compatible with asset lib

Made compatible with asset lib

Update README.md
  • Loading branch information
addmix committed Feb 7, 2024
1 parent 4ceecd6 commit 469ddd9
Show file tree
Hide file tree
Showing 19 changed files with 797 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.import
export.cfg
export_presets.cfg
.godot/

# Mono-specific ignores
.mono/
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
4. Enable plugin in project settings `Project > Project Settings > Plugins`
5. Reload project (if necessary).

# Dependencies
[Godot Utils v0.3.1](https://github.com/addmix/godot_utils/releases/tag/v0.3.1)

# Usage
Tutorial available [here](https://youtu.be/iI8SXQdaqDQ)
1. Add an `AeroBody` to your scene, and add one or more `AeroSurface` derived classes as children, adjust settings to change the characteristics.
Expand Down
3 changes: 3 additions & 0 deletions core/aero_body_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ var inclination := 0.0


#debug
const Vector3D = preload("../utils/vector_3d/vector_3d.gd")
const Point3D = preload("../utils/point_3d/point_3d.gd")

var linear_velocity_vector : Vector3D
var angular_velocity_vector : Vector3D

Expand Down
1 change: 1 addition & 0 deletions core/aero_influencer_3d/aero_influencer_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var dynamic_pressure : float = 0.0
var _current_force : Vector3 = Vector3.ZERO
var _current_torque : Vector3 = Vector3.ZERO

const Vector3D = preload("../../utils/vector_3d/vector_3d.gd")
var force_debug_vector : Vector3D
var torque_debug_vector : Vector3D

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
extends Resource
class_name ManualAeroSurfaceConfig

@export var min_lift_coefficient : float = -1.5
@export var max_lift_coefficient : float = 1.5
@export var min_lift_coefficient : float = -1.0
@export var max_lift_coefficient : float = 1.0
@export var lift_aoa_curve : Curve
@export var min_drag_coefficient : float = 0.001
@export var max_drag_coefficient : float = 0.5

@export var min_drag_coefficient : float = 0.0
@export var max_drag_coefficient : float = 1.0
@export var drag_aoa_curve : Curve

const MathUtils = preload("../../../../utils/math_utils.gd")

func _init(_lift_aoa_curve : Curve = preload("../../../resources/default_lift_aoa_curve.tres").duplicate(), _drag_aoa_curve : Curve = preload("../../../resources/default_drag_aoa_curve.tres").duplicate()) -> void:
lift_aoa_curve = _lift_aoa_curve
drag_aoa_curve = _drag_aoa_curve
Expand Down
10 changes: 7 additions & 3 deletions core/singletons/aero_units.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@tool
extends Node

const NodeUtils = preload("../../utils/node_utils.gd")

#air is 1.402
@export var ratio_of_specific_heat : float = 1.402

Expand All @@ -24,10 +26,12 @@ extends Node
@export var min_altitude : float = 0.0
@export var max_altitude : float = 80000.0
func get_altitude(node : Node) -> float:
var floating_origin = NodeUtils.get_first_parent_of_type(node, FloatingOrigin)
if floating_origin is FloatingOrigin:
# Need to find a better way to check for floating origin

var floating_origin = NodeUtils.get_first_parent_of_type_with_string(node, "FloatingOrigin")
if floating_origin:
return node.global_position.y + (float(floating_origin.current_offset.y) * floating_origin.shift_threshold)
return node.global_position.y
return node.position.y

@export var min_mach : float = 0.0
@export var max_mach : float = 10.0
Expand Down
8 changes: 8 additions & 0 deletions demo/aero_body_3d.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@tool
extends AeroBody3D

func _physics_process(delta):
super._physics_process(delta)
$Elevator.rotation.x = Input.get_axis("ui_down", "ui_up") * 0.4
$WingL.rotation.x = Input.get_axis("ui_left", "ui_right") * 0.1
$WingR.rotation.x = -Input.get_axis("ui_left", "ui_right") * 0.1
153 changes: 153 additions & 0 deletions demo/demo_plane.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
[gd_scene load_steps=18 format=3 uid="uid://dx0v1i14fyw8c"]

[ext_resource type="Script" path="res://addons/godot_aerodynamic_physics/core/aero_influencer_3d/aero_surface_3d/manual_aero_surface_3d/manual_aero_surface_3d.gd" id="2_ygpq6"]
[ext_resource type="Script" path="res://addons/godot_aerodynamic_physics/core/aero_influencer_3d/aero_surface_3d/manual_aero_surface_3d/manual_aero_surface_config.gd" id="3_dhflf"]
[ext_resource type="Script" path="res://addons/godot_aerodynamic_physics/core/aero_influencer_3d/aero_surface_3d/aero_surface_config.gd" id="4_ht3i8"]
[ext_resource type="Script" path="res://demo/thruster.gd" id="5_50cgi"]
[ext_resource type="Script" path="res://demo/aero_body_3d.gd" id="5_208xj"]

[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_swshj"]
friction = 0.0

[sub_resource type="BoxShape3D" id="BoxShape3D_nchkm"]
size = Vector3(5.34473, 0.454224, 5.40618)

[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_6onr1"]
radius = 0.248054

[sub_resource type="Curve" id="Curve_v5kpe"]
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.25, 1), 0.0, 0.0, 0, 0, Vector2(0.5, 0), 0.0, 0.0, 0, 0, Vector2(0.75, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 5

[sub_resource type="Curve" id="Curve_cmcrd"]
min_value = -1.0
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.25, -0.571), 0.0, 0.0, 0, 0, Vector2(0.375, -0.4), 0.0, 0.0, 0, 0, Vector2(0.403, -1), 0.0, 0.0, 0, 0, Vector2(0.597, 1), 0.0, 0.0, 0, 0, Vector2(0.625, 0.4), 0.0, 0.0, 0, 0, Vector2(0.75, 0.571), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 8

[sub_resource type="Resource" id="Resource_raxm3"]
script = ExtResource("3_dhflf")
min_lift_coefficient = -1.5
max_lift_coefficient = 1.5
lift_aoa_curve = SubResource("Curve_cmcrd")
min_drag_coefficient = 0.001
max_drag_coefficient = 0.5
drag_aoa_curve = SubResource("Curve_v5kpe")

[sub_resource type="Curve" id="Curve_8vcck"]

[sub_resource type="Curve" id="Curve_26y5e"]
min_value = 1.0
max_value = 1.69
_data = [Vector2(0.07, 1), 0.0, 0.0, 0, 0, Vector2(0.088, 1.519), 0.0, 0.0, 0, 0, Vector2(0.119, 1), 0.0, 0.0, 0, 0]
point_count = 3

[sub_resource type="Curve" id="Curve_u1ll1"]
_data = [Vector2(0, 1), 0.0, -2.09824, 0, 0, Vector2(0.406542, 0.490909), -0.666575, -0.666575, 0, 0, Vector2(1, 0.290909), 0.0, 0.0, 0, 0]
point_count = 3

[sub_resource type="Resource" id="Resource_b87jk"]
script = ExtResource("4_ht3i8")
chord = 1.0
span = 2.0
skin_friction = 0.001
auto_aspect_ratio = true
aspect_ratio = 2.0
zero_lift_aoa = 0.0
flap_fraction = 0.0
is_control_surface = false
sweep_drag_multiplier_curve = SubResource("Curve_u1ll1")
drag_at_mach_multiplier_curve = SubResource("Curve_26y5e")
buffet_aoa_curve = SubResource("Curve_8vcck")

[sub_resource type="Resource" id="Resource_7jeqs"]
script = ExtResource("4_ht3i8")
chord = 1.0
span = 1.4
skin_friction = 0.001
auto_aspect_ratio = true
aspect_ratio = 1.4
zero_lift_aoa = 0.0
flap_fraction = 0.0
is_control_surface = false
sweep_drag_multiplier_curve = SubResource("Curve_u1ll1")
drag_at_mach_multiplier_curve = SubResource("Curve_26y5e")
buffet_aoa_curve = SubResource("Curve_8vcck")

[sub_resource type="Resource" id="Resource_658jb"]
script = ExtResource("4_ht3i8")
chord = 1.0
span = 3.55
skin_friction = 0.001
auto_aspect_ratio = true
aspect_ratio = 3.55
zero_lift_aoa = 0.0
flap_fraction = 0.0
is_control_surface = false
sweep_drag_multiplier_curve = SubResource("Curve_u1ll1")
drag_at_mach_multiplier_curve = SubResource("Curve_26y5e")
buffet_aoa_curve = SubResource("Curve_8vcck")

[node name="AeroBody3D" type="VehicleBody3D"]
mass = 1000.0
physics_material_override = SubResource("PhysicsMaterial_swshj")
center_of_mass_mode = 1
linear_damp_mode = 1
angular_damp_mode = 1
script = ExtResource("5_208xj")
show_debug = true
update_debug = true

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0840454, 1.49654)
shape = SubResource("BoxShape3D_nchkm")

[node name="CollisionShape3D2" type="CollisionShape3D" parent="."]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0, -0.282653, -0.4323)
shape = SubResource("CapsuleShape3D_6onr1")

[node name="Elevator" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.57628e-07, 3.05994)
script = ExtResource("2_ygpq6")
manual_config = SubResource("Resource_raxm3")
wing_config = SubResource("Resource_b87jk")
show_debug = true

[node name="Rudder" type="Node3D" parent="."]
transform = Transform3D(-4.37114e-08, -1, 0, 0.835693, -3.65293e-08, -0.549198, 0.549198, -2.40062e-08, 0.835693, -2.96035e-17, 0.742918, 3.32475)
script = ExtResource("2_ygpq6")
manual_config = SubResource("Resource_raxm3")
wing_config = SubResource("Resource_7jeqs")
show_debug = true

[node name="WingL" type="Node3D" parent="."]
transform = Transform3D(1, 0, -5.96046e-08, 0, 1, 0, 5.96046e-08, 0, 1, -1.90776, 0, -0.473555)
script = ExtResource("2_ygpq6")
manual_config = SubResource("Resource_raxm3")
wing_config = SubResource("Resource_658jb")
show_debug = true

[node name="WingR" type="Node3D" parent="."]
transform = Transform3D(1, 0, 5.96046e-08, 0, 1, 0, -5.96046e-08, 0, 1, 1.908, 0, -0.473945)
script = ExtResource("2_ygpq6")
manual_config = SubResource("Resource_raxm3")
wing_config = SubResource("Resource_658jb")
show_debug = true

[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.55771, 9.0562)

[node name="CSGBox3D" type="CSGBox3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.20421)
size = Vector3(7.34863, 0.113525, 1.14014)

[node name="CSGBox3D2" type="CSGBox3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.35488)
size = Vector3(2.0332, 0.113525, 1.14014)

[node name="CSGBox3D3" type="CSGBox3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.822998, -0.568045, 0, 0.568045, 0.822998, 0, 0.623825, 3.53358)
size = Vector3(0.141602, 1.41797, 1.14014)

[node name="Marker3D" type="Marker3D" parent="."]
script = ExtResource("5_50cgi")
force = 600.0
37 changes: 37 additions & 0 deletions demo/demo_scene.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[gd_scene load_steps=6 format=3 uid="uid://cpbp7en0cerjl"]

[ext_resource type="PackedScene" uid="uid://dx0v1i14fyw8c" path="res://demo/demo_plane.tscn" id="1_bbdyo"]

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_lajrc"]
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)

[sub_resource type="Sky" id="Sky_dsdc3"]
sky_material = SubResource("ProceduralSkyMaterial_lajrc")

[sub_resource type="Environment" id="Environment_bkiet"]
background_mode = 2
sky = SubResource("Sky_dsdc3")
tonemap_mode = 2
glow_enabled = true

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_1sawy"]
albedo_color = Color(0, 0.490196, 0.0823529, 1)

[node name="Main" type="Node3D"]

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 0, 0)
shadow_enabled = true

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_bkiet")

[node name="AeroBody3D" parent="." instance=ExtResource("1_bbdyo")]
linear_velocity = Vector3(0, 0, -100)

[node name="CSGBox3D" type="CSGBox3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4.12099, -190.455)
use_collision = true
size = Vector3(10000, 1, 10000)
material = SubResource("StandardMaterial3D_1sawy")
8 changes: 8 additions & 0 deletions demo/thruster.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends Marker3D

@export var enabled : bool = true
@export var force : float = 100.0

func _physics_process(delta : float) -> void:
if enabled:
get_parent().apply_force(-global_transform.basis.z * force, global_transform.basis * position)
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion plugin.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@tool
extends EditorPlugin

const PluginUtils = preload("./utils/plugin_utils.gd")

var path := PluginUtils.get_plugin_path("Godot Aerodynamic Physics")

#icons
Expand Down Expand Up @@ -28,7 +30,7 @@ const manual_aero_surface_config = preload("./core/aero_influencer_3d/aero_surfa
#const procedural_aero_surface_config = preload("./core/aero_influencer_3d/aero_surface_3d/procedural_aero_surface_3d/procedural_aero_surface_config.gd")

func _enter_tree():
SettingsUtils.ifndef("physics/3d/aerodynamics/substeps", 1)
ifndef("physics/3d/aerodynamics/substeps", 1)
add_autoload_singleton("AeroUnits", path + "/core/singletons/aero_units.gd")
add_node_3d_gizmo_plugin(gizmo_plugin_instance)

Expand Down Expand Up @@ -57,3 +59,11 @@ func _exit_tree():

remove_autoload_singleton("AeroUnits")
remove_node_3d_gizmo_plugin(gizmo_plugin_instance)

static func ifndef(setting : String, default_value : Variant) -> Variant:
if not ProjectSettings.has_setting(setting):
ProjectSettings.set_setting(setting, default_value)
if not default_value == null:
ProjectSettings.set_initial_value(setting, default_value)

return ProjectSettings.get_setting(setting)
Loading

0 comments on commit 469ddd9

Please sign in to comment.