Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/Classes/Cel3D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/Classes/Project.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down