mirror of
https://github.com/FOSS-Supremacy/OpenLiberty.git
synced 2025-04-28 11:57:58 +03:00
Merge pull request #26 from FOSS-Supremacy/coords-fix
Fix coordinates system
This commit is contained in:
commit
f34f6df3ec
6 changed files with 48 additions and 29 deletions
|
@ -32,11 +32,12 @@ func _init(file: FileAccess):
|
|||
|
||||
class TBase:
|
||||
func read_vector3(file: FileAccess) -> Vector3:
|
||||
var result := Vector3()
|
||||
result.x = file.get_float()
|
||||
result.y = file.get_float()
|
||||
result.z = file.get_float()
|
||||
return result
|
||||
# GTA3 uses a different coordinate system, so we need to convert
|
||||
# the coordinates to Godot's coordinate system.
|
||||
var x := file.get_float()
|
||||
var y := file.get_float()
|
||||
var z := file.get_float()
|
||||
return Vector3(x, z, -y)
|
||||
|
||||
class TBounds extends TBase:
|
||||
var radius: float
|
||||
|
|
|
@ -57,10 +57,11 @@ func _read_ide_line(section: String, tokens: Array[String]):
|
|||
items[id] = item
|
||||
"2dfx":
|
||||
var parent := tokens[0].to_int()
|
||||
# Convert GTA to Godot coordinate system
|
||||
var position := Vector3(
|
||||
tokens[1].to_float(),
|
||||
tokens[2].to_float(),
|
||||
tokens[3].to_float() )
|
||||
tokens[3].to_float(),
|
||||
-tokens[2].to_float() )
|
||||
var color := Color(
|
||||
tokens[4].to_float() / 255,
|
||||
tokens[5].to_float() / 255,
|
||||
|
@ -84,18 +85,21 @@ func _read_ipl_line(section: String, tokens: Array[String]):
|
|||
var placement := ItemPlacement.new()
|
||||
placement.id = tokens[0].to_int()
|
||||
placement.model_name = tokens[1].to_lower()
|
||||
# Convert GTA to Godot coordinate system
|
||||
placement.position = Vector3(
|
||||
tokens[2].to_float(),
|
||||
tokens[3].to_float(),
|
||||
tokens[4].to_float(), )
|
||||
tokens[4].to_float(),
|
||||
-tokens[3].to_float(), )
|
||||
# Scale conversion follows the same pattern
|
||||
placement.scale = Vector3(
|
||||
tokens[5].to_float(),
|
||||
tokens[6].to_float(),
|
||||
tokens[7].to_float(), )
|
||||
tokens[7].to_float(),
|
||||
tokens[6].to_float(), )
|
||||
# Quaternion conversion requires negating components
|
||||
placement.rotation = Quaternion(
|
||||
-tokens[8].to_float(),
|
||||
-tokens[9].to_float(),
|
||||
-tokens[10].to_float(),
|
||||
-tokens[9].to_float(),
|
||||
tokens[11].to_float(), )
|
||||
placements.append(placement)
|
||||
|
||||
|
@ -115,7 +119,6 @@ func _read_map_data(path: String, line_handler: Callable) -> void:
|
|||
|
||||
func clear_map() -> void:
|
||||
map = Node3D.new()
|
||||
map.rotation.x = deg_to_rad(-90.0)
|
||||
|
||||
func spawn_placement(ipl: ItemPlacement) -> Node3D:
|
||||
return spawn(ipl.id, ipl.model_name, ipl.position, ipl.scale, ipl.rotation)
|
||||
|
@ -147,13 +150,31 @@ func spawn(id: int, model_name: String, position: Vector3, scale: Vector3, rotat
|
|||
var colshape := CollisionShape3D.new()
|
||||
if collision is ColFile.TBox:
|
||||
var aabb := AABB()
|
||||
aabb.position = collision.min
|
||||
aabb.end = collision.max
|
||||
# Get min and max positions from collision box
|
||||
var min_pos := collision.min as Vector3
|
||||
var max_pos := collision.max as Vector3
|
||||
|
||||
# Ensure AABB has positive size by sorting min/max for each axis
|
||||
aabb.position = Vector3(
|
||||
min(min_pos.x, max_pos.x),
|
||||
min(min_pos.y, max_pos.y),
|
||||
min(min_pos.z, max_pos.z)
|
||||
)
|
||||
aabb.end = Vector3(
|
||||
max(min_pos.x, max_pos.x),
|
||||
max(min_pos.y, max_pos.y),
|
||||
max(min_pos.z, max_pos.z)
|
||||
)
|
||||
|
||||
# Only create the shape if size is valid
|
||||
if aabb.size.x > 0 and aabb.size.y > 0 and aabb.size.z > 0:
|
||||
var shape := BoxShape3D.new()
|
||||
shape.size = aabb.size
|
||||
colshape.shape = shape
|
||||
colshape.position = aabb.get_center()
|
||||
sb.add_child(colshape)
|
||||
else:
|
||||
sb.add_child(colshape)
|
||||
if item.colfile.vertices.size() > 0:
|
||||
var colshape := CollisionShape3D.new()
|
||||
var shape := ConcavePolygonShape3D.new()
|
||||
|
|
|
@ -4,7 +4,6 @@ extends Node
|
|||
var suzanne := preload("res://prefabs/suzanne.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
world.rotation.x = deg_to_rad(-90.0)
|
||||
var start := Time.get_ticks_msec()
|
||||
var target = MapBuilder.placements.size()
|
||||
var count := 0
|
||||
|
|
|
@ -9,7 +9,6 @@ func _ready() -> void:
|
|||
spinbox.rounded = true
|
||||
spinbox.max_value = 0
|
||||
misc = RWTextureDict.new(GameManager.open_file("models/misc.txd", FileAccess.READ))
|
||||
meshinstance.rotation.x = deg_to_rad(-90.0)
|
||||
|
||||
func _ld_dff() -> void:
|
||||
var dialog := FileDialog.new()
|
||||
|
|
|
@ -110,17 +110,17 @@ func _init(file: FileAccess):
|
|||
morph_t.has_normals = file.get_32() != 0
|
||||
if morph_t.has_vertices:
|
||||
for j in vert_count:
|
||||
var vert := Vector3()
|
||||
vert.x = file.get_float()
|
||||
vert.y = file.get_float()
|
||||
vert.z = file.get_float()
|
||||
morph_t.vertices.append(vert)
|
||||
# Convert GTA to Godot coordinate system
|
||||
var x := file.get_float()
|
||||
var y := file.get_float()
|
||||
var z := file.get_float()
|
||||
morph_t.vertices.append(Vector3(x, z, -y))
|
||||
if morph_t.has_normals:
|
||||
for j in vert_count:
|
||||
var normal := Vector3()
|
||||
normal.x = file.get_float()
|
||||
normal.y = file.get_float()
|
||||
normal.z = file.get_float()
|
||||
normal.y = file.get_float()
|
||||
morph_t.normals.append(normal)
|
||||
morph_targets.append(morph_t)
|
||||
material_list = RWMaterialList.new(file)
|
||||
|
|
|
@ -7,7 +7,6 @@ extends Node
|
|||
var car := preload("res://scenes/car.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
world.rotation.x = deg_to_rad(-90.0)
|
||||
var start := Time.get_ticks_msec()
|
||||
var target = MapBuilder.placements.size()
|
||||
var count := 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue