1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 01:29:49 +00:00

[0.x] Fix cel3d compatibility when transferring project from 1.0 to 0.x (#928)

* make cel3d backwards compatible

* further changes

* fix capsule shape

* formatting
This commit is contained in:
Variable 2023-10-26 18:10:47 +05:00 committed by GitHub
parent 6fa4056cd4
commit 5fcffece4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 0 deletions

View file

@ -177,6 +177,9 @@ func serialize() -> Dictionary:
func deserialize(dict: Dictionary) -> void:
if dict.has("pxo_version"):
if dict["pxo_version"] == 3: # It's a 1.x project convert it to 0.x format
convert_1x_to_0x(dict)
.deserialize(dict)
scene_properties = dict["scene_properties"]
var objects_copy = dict["object_properties"]
@ -195,6 +198,70 @@ func deserialize(dict: Dictionary) -> void:
_add_object_node(object)
## Used to convert 3d cels found in projects exported from a 0.x version to 1.x
func convert_1x_to_0x(dict: Dictionary) -> void:
# Converting the scene dictionary
var scene_dict: Dictionary = dict["scene_properties"]
scene_dict["camera_transform"] = str2var(
scene_dict["camera_transform"].replace("Transform3D", "Transform")
)
scene_dict["camera_projection"] = str2var(scene_dict["camera_projection"])
scene_dict["camera_fov"] = str2var(scene_dict["camera_fov"])
scene_dict["camera_size"] = str2var(scene_dict["camera_size"])
scene_dict["ambient_light_color"] = str2var(scene_dict["ambient_light_color"])
scene_dict["ambient_light_energy"] = str2var(scene_dict["ambient_light_energy"])
# Converting the objects dictionary
var objects_copy: Dictionary = dict["object_properties"]
for object_id_as_str in objects_copy.keys():
objects_copy[object_id_as_str] = str2var(
objects_copy[object_id_as_str].replace("Transform3D", "Transform")
)
# we are using a separate variable to make it easy to write
var object_info: Dictionary = objects_copy[object_id_as_str]
# Special operations to adjust gizmo
# take note of origin
var origin = object_info["transform"].origin
match object_info["type"]:
0: # BOX
object_info["transform"] = object_info["transform"].scaled(Vector3.ONE / 2)
object_info["transform"].origin = origin
object_info["mesh_size"] *= 2
1: # SPHERE
object_info["transform"] = object_info["transform"].scaled(Vector3.ONE / 2)
object_info["transform"].origin = origin
object_info["mesh_radius"] *= 2
object_info["mesh_height"] *= 2
2: # CAPSULE
object_info["transform"] = object_info["transform"].scaled(-(Vector3.ONE / 2))
var basis = object_info["transform"].basis
var new_transform: Transform = Transform(basis.x, -basis.z, -basis.y, origin)
object_info["transform"] = new_transform
object_info["transform"].origin = origin
object_info["mesh_radius"] *= 2
object_info["mesh_mid_height"] = (
object_info["mesh_height"]
- (object_info["mesh_radius"] / 2)
)
3: # CYLINDER
object_info["transform"] = object_info["transform"].scaled(Vector3.ONE / 2)
object_info["transform"].origin = origin
object_info["mesh_height"] *= 2
object_info["mesh_bottom_radius"] *= 2
object_info["mesh_top_radius"] *= 2
4: # PRISM
object_info["transform"] = object_info["transform"].scaled(Vector3.ONE / 2)
object_info["transform"].origin = origin
object_info["mesh_size"] *= 2
6: # PLANE
object_info["transform"] = object_info["transform"].scaled(Vector3.ONE / 2)
object_info["transform"].origin = origin
object_info["mesh_sizev2"] *= 2
_:
if not "shadow_color" in object_info.keys():
object_info["shadow_color"] = Color.black
objects_copy[object_id_as_str] = objects_copy[object_id_as_str]
func on_remove() -> void:
if is_instance_valid(viewport):
viewport.queue_free()

View file

@ -380,6 +380,8 @@ func deserialize(dict: Dictionary) -> void:
cels.append(GroupCel.new())
Global.LayerTypes.THREE_D:
cels.append(Cel3D.new(size, true))
if dict.has("pxo_version"):
cel["pxo_version"] = dict["pxo_version"]
cels[cel_i].deserialize(cel)
_deserialize_metadata(cels[cel_i], cel)
cel_i += 1