90 lines
2.0 KiB
GDScript
90 lines
2.0 KiB
GDScript
class_name CockpitMeshFactory
|
|
extends RefCounted
|
|
|
|
|
|
static func add_box(
|
|
node_name: String,
|
|
parent: Node3D,
|
|
position: Vector3,
|
|
size: Vector3,
|
|
material: Material,
|
|
rotation_degrees: Vector3 = Vector3.ZERO
|
|
) -> MeshInstance3D:
|
|
var instance := MeshInstance3D.new()
|
|
instance.name = node_name
|
|
var mesh := BoxMesh.new()
|
|
mesh.size = size
|
|
instance.mesh = mesh
|
|
instance.material_override = material
|
|
instance.position = position
|
|
instance.rotation_degrees = rotation_degrees
|
|
parent.add_child(instance)
|
|
return instance
|
|
|
|
|
|
static func add_cylinder(
|
|
node_name: String,
|
|
parent: Node3D,
|
|
position: Vector3,
|
|
radius: float,
|
|
height: float,
|
|
material: Material,
|
|
rotation_degrees: Vector3 = Vector3.ZERO
|
|
) -> MeshInstance3D:
|
|
var instance := MeshInstance3D.new()
|
|
instance.name = node_name
|
|
var mesh := CylinderMesh.new()
|
|
mesh.top_radius = radius
|
|
mesh.bottom_radius = radius
|
|
mesh.height = height
|
|
mesh.radial_segments = 16
|
|
instance.mesh = mesh
|
|
instance.material_override = material
|
|
instance.position = position
|
|
instance.rotation_degrees = rotation_degrees
|
|
parent.add_child(instance)
|
|
return instance
|
|
|
|
|
|
static func add_cylinder_between(
|
|
node_name: String,
|
|
parent: Node3D,
|
|
start: Vector3,
|
|
end: Vector3,
|
|
radius: float,
|
|
material: Material
|
|
) -> MeshInstance3D:
|
|
var direction := end - start
|
|
var instance := add_cylinder(
|
|
node_name,
|
|
parent,
|
|
(start + end) * 0.5,
|
|
radius,
|
|
direction.length(),
|
|
material
|
|
)
|
|
if not direction.is_zero_approx():
|
|
instance.quaternion = Quaternion(Vector3.UP, direction.normalized())
|
|
return instance
|
|
|
|
|
|
static func add_sphere(
|
|
node_name: String,
|
|
parent: Node3D,
|
|
position: Vector3,
|
|
radius: float,
|
|
material: Material
|
|
) -> MeshInstance3D:
|
|
var instance := MeshInstance3D.new()
|
|
instance.name = node_name
|
|
var mesh := SphereMesh.new()
|
|
mesh.radius = radius
|
|
mesh.height = radius * 2.0
|
|
mesh.radial_segments = 16
|
|
mesh.rings = 8
|
|
instance.mesh = mesh
|
|
instance.material_override = material
|
|
instance.position = position
|
|
parent.add_child(instance)
|
|
return instance
|