Skip to content

Commit a80214e

Browse files
committed
removed .zosim serialization
1 parent c507a9d commit a80214e

21 files changed

+31
-1886
lines changed

Runtime/Scripts/Document/ZOSimDocumentRoot.cs

Lines changed: 0 additions & 400 deletions
Large diffs are not rendered by default.

Runtime/Scripts/Document/ZOSimOccurrence.cs

Lines changed: 1 addition & 904 deletions
Large diffs are not rendered by default.

Runtime/Scripts/Document/ZOURDFSerializationInterface.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

Runtime/Scripts/Document/ZOURDFSerializationInterface.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Runtime/Scripts/Physics/ZOFixedJoint.cs

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace ZO.Physics {
2121
/// constrains the joint angle.
2222
/// </summary>
2323
[ExecuteAlways]
24-
public class ZOFixedJoint : MonoBehaviour, ZOSerializationInterface, ZOJointInterface {
24+
public class ZOFixedJoint : MonoBehaviour, ZOJointInterface {
2525

2626
[SerializeField] public UnityEngine.FixedJoint _fixedJoint;
2727

@@ -155,79 +155,6 @@ public JObject JSON {
155155
}
156156

157157

158-
/// <summary>
159-
/// Serializes the ZOFixedJoint to ZOSim JSON.
160-
/// </summary>
161-
/// <param name="documentRoot"></param>
162-
/// <param name="parent"></param>
163-
/// <returns></returns>
164-
public JObject Serialize(ZOSimDocumentRoot documentRoot, UnityEngine.Object parent = null) {
165-
// calculate the world anchor positions relative to the document root transform
166-
// BUGBUG: maybe from the base of the joint chain which is not necessarily the document root?
167-
Vector3 worldAnchor = this.transform.TransformPoint(UnityFixedJoint.anchor);
168-
worldAnchor = documentRoot.transform.InverseTransformPoint(worldAnchor);
169-
170-
Vector3 worldConnectedAnchor = this.transform.TransformPoint(UnityFixedJoint.connectedAnchor);
171-
worldConnectedAnchor = documentRoot.transform.InverseTransformPoint(worldConnectedAnchor);
172-
173-
174-
JObject json = new JObject(
175-
new JProperty("name", Name),
176-
new JProperty("type", Type),
177-
new JProperty("anchor", ZOSimDocumentRoot.ToJSON(UnityFixedJoint.anchor)),
178-
new JProperty("world_anchor", ZOSimDocumentRoot.ToJSON(worldAnchor)),
179-
new JProperty("connected_anchor", ZOSimDocumentRoot.ToJSON(UnityFixedJoint.connectedAnchor)),
180-
new JProperty("world_connected_anchor", ZOSimDocumentRoot.ToJSON(worldConnectedAnchor))
181-
);
182-
183-
if (UnityFixedJoint.connectedBody) {
184-
ZOSimOccurrence connected_occurrence = UnityFixedJoint.connectedBody.gameObject.GetComponent<ZOSimOccurrence>();
185-
186-
if (connected_occurrence) {
187-
json["connected_occurrence"] = connected_occurrence.Name;
188-
} else {
189-
Debug.LogWarning("WARNING: Could not get connected occurrence for ZOFixedJoint: " + Name + "\nPerhaps there is a missing ZOSimOccurrence?");
190-
}
191-
} else {
192-
Debug.LogWarning("WARNING: Could not get connected occurrence for ZOFixedJoint: " + Name);
193-
}
194-
195-
ZOSimOccurrence parent_occurrence = GetComponent<ZOSimOccurrence>();
196-
if (parent_occurrence) {
197-
json["parent_occurrence"] = parent_occurrence.Name;
198-
}
199-
200-
_json = json;
201-
202-
return json;
203-
}
204-
205-
206-
public void Deserialize(ZOSimDocumentRoot documentRoot, JObject json) {
207-
// Assert.Equals(json["type"].Value<string>() == Type);
208-
209-
_json = json;
210-
Name = json.ValueOrDefault("name", Name);
211-
UnityFixedJoint.anchor = json.ToVector3OrDefault("anchor", UnityFixedJoint.anchor);
212-
UnityFixedJoint.connectedAnchor = json.ToVector3OrDefault("connected_anchor", UnityFixedJoint.connectedAnchor);
213-
214-
215-
216-
// find connected body. this likely will need to be done post LoadFromJSON as it may
217-
// not be created yet.
218-
documentRoot.OnPostDeserializationNotification((docRoot) => {
219-
if (JSON.ContainsKey("connected_occurrence")) {
220-
ZOSimOccurrence connectedOccurrence = docRoot.GetOccurrence(JSON["connected_occurrence"].Value<string>());
221-
if (connectedOccurrence) {
222-
UnityFixedJoint.connectedBody = connectedOccurrence.GetComponent<Rigidbody>();
223-
} else {
224-
Debug.LogWarning("WARNING: ZOFixedJoint failed to find connected occurrence: " + JSON["connected_occurrence"].Value<string>());
225-
}
226-
227-
}
228-
});
229-
230-
}
231158
#endregion
232159

233160
}

Runtime/Scripts/Physics/ZOHingeJoint.cs

Lines changed: 1 addition & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace ZO.Physics {
2222
/// constrains the joint angle.
2323
/// </summary>
2424
[ExecuteAlways]
25-
public class ZOHingeJoint : MonoBehaviour, ZOSerializationInterface, ZOJointInterface {
25+
public class ZOHingeJoint : MonoBehaviour, ZOJointInterface {
2626

2727
public Rigidbody _connectedBody;
2828
public Vector3 _anchor = Vector3.zero;
@@ -338,136 +338,6 @@ public JObject JSON {
338338
}
339339

340340

341-
/// <summary>
342-
/// Serializes the ZOHingeJoint to ZOSim JSON.
343-
/// </summary>
344-
/// <param name="documentRoot"></param>
345-
/// <param name="parent"></param>
346-
/// <returns></returns>
347-
public JObject Serialize(ZOSimDocumentRoot documentRoot, UnityEngine.Object parent = null) {
348-
// calculate the world anchor positions relative to the document root transform
349-
// BUGBUG: maybe from the base of the joint chain which is not necessarily the document root?
350-
Vector3 worldAnchor = this.transform.TransformPoint(UnityHingeJoint.anchor);
351-
worldAnchor = documentRoot.transform.InverseTransformPoint(worldAnchor);
352-
353-
Vector3 worldConnectedAnchor = this.transform.TransformPoint(UnityHingeJoint.connectedAnchor);
354-
worldConnectedAnchor = documentRoot.transform.InverseTransformPoint(worldConnectedAnchor);
355-
356-
Vector3 worldAxis = this.transform.rotation * UnityHingeJoint.axis;
357-
worldAxis = documentRoot.transform.InverseTransformDirection(worldAxis);
358-
359-
JObject json = new JObject(
360-
new JProperty("name", Name),
361-
new JProperty("type", Type),
362-
new JProperty("anchor", ZOSimDocumentRoot.ToJSON(UnityHingeJoint.anchor)),
363-
new JProperty("world_anchor", ZOSimDocumentRoot.ToJSON(worldAnchor)),
364-
new JProperty("axis", ZOSimDocumentRoot.ToJSON(UnityHingeJoint.axis)),
365-
new JProperty("world_axis", ZOSimDocumentRoot.ToJSON(worldAxis)),
366-
new JProperty("connected_anchor", ZOSimDocumentRoot.ToJSON(UnityHingeJoint.connectedAnchor)),
367-
new JProperty("world_connected_anchor", ZOSimDocumentRoot.ToJSON(worldConnectedAnchor)),
368-
new JProperty("use_spring", UnityHingeJoint.useSpring),
369-
new JProperty("spring", new JObject(
370-
new JProperty("spring", UnityHingeJoint.spring.spring),
371-
new JProperty("damper", UnityHingeJoint.spring.damper),
372-
new JProperty("target_position", UnityHingeJoint.spring.targetPosition)
373-
)),
374-
new JProperty("use_motor", UnityHingeJoint.useMotor),
375-
new JProperty("motor", new JObject(
376-
new JProperty("target_velocity", UnityHingeJoint.motor.targetVelocity),
377-
new JProperty("force", UnityHingeJoint.motor.force),
378-
new JProperty("free_spin", UnityHingeJoint.motor.freeSpin)
379-
)),
380-
new JProperty("use_limits", UnityHingeJoint.useLimits),
381-
new JProperty("limits", new JObject(
382-
new JProperty("min", UnityHingeJoint.limits.min),
383-
new JProperty("max", UnityHingeJoint.limits.max),
384-
new JProperty("bounciness", UnityHingeJoint.limits.bounciness),
385-
new JProperty("bounce_min_velocity", UnityHingeJoint.limits.bounceMinVelocity),
386-
new JProperty("contact_distance", UnityHingeJoint.limits.contactDistance)
387-
))
388-
);
389-
390-
if (UnityHingeJoint.connectedBody) {
391-
ZOSimOccurrence connected_occurrence = UnityHingeJoint.connectedBody.gameObject.GetComponent<ZOSimOccurrence>();
392-
393-
if (connected_occurrence) {
394-
json["connected_occurrence"] = connected_occurrence.Name;
395-
} else {
396-
Debug.LogWarning("WARNING: Could not get connected occurrence for ZOHingeJoint: " + Name + "\nPerhaps there is a missing ZOSimOccurrence?");
397-
}
398-
} else {
399-
Debug.LogWarning("WARNING: Could not get connected occurrence for ZOHingeJoint: " + Name);
400-
}
401-
402-
ZOSimOccurrence parent_occurrence = GetComponent<ZOSimOccurrence>();
403-
if (parent_occurrence) {
404-
json["parent_occurrence"] = parent_occurrence.Name;
405-
}
406-
407-
_json = json;
408-
409-
return json;
410-
}
411-
412-
413-
public void Deserialize(ZOSimDocumentRoot documentRoot, JObject json) {
414-
// Assert.Equals(json["type"].Value<string>() == Type);
415-
416-
_json = json;
417-
Name = json.ValueOrDefault("name", Name);
418-
UnityHingeJoint.anchor = json.ToVector3OrDefault("anchor", UnityHingeJoint.anchor);
419-
UnityHingeJoint.axis = json.ToVector3OrDefault("axis", UnityHingeJoint.axis);
420-
UnityHingeJoint.connectedAnchor = json.ToVector3OrDefault("connected_anchor", UnityHingeJoint.connectedAnchor);
421-
UnityHingeJoint.useSpring = json.ValueOrDefault<bool>("use_spring", UnityHingeJoint.useSpring);
422-
423-
424-
if (json.ContainsKey("spring")) {
425-
JObject springJSON = json["spring"].Value<JObject>();
426-
JointSpring spring = UnityHingeJoint.spring;
427-
spring.spring = springJSON.ValueOrDefault<float>("spring", spring.spring);
428-
spring.damper = springJSON.ValueOrDefault<float>("damper", spring.damper);
429-
spring.targetPosition = springJSON.ValueOrDefault<float>("target_position", spring.targetPosition);
430-
UnityHingeJoint.spring = spring;
431-
432-
}
433-
434-
UnityHingeJoint.useMotor = json.ValueOrDefault<bool>("use_motor", UnityHingeJoint.useMotor);
435-
if (json.ContainsKey("use_motor")) {
436-
JObject motorJSON = json["motor"].Value<JObject>();
437-
JointMotor motor = UnityHingeJoint.motor;
438-
motor.targetVelocity = motorJSON.ValueOrDefault<float>("target_velocity", motor.targetVelocity);
439-
motor.force = motorJSON.ValueOrDefault<float>("force", motor.force);
440-
motor.freeSpin = motorJSON.ValueOrDefault<bool>("free_spin", motor.freeSpin);
441-
UnityHingeJoint.motor = motor;
442-
}
443-
444-
UnityHingeJoint.useLimits = json.ValueOrDefault<bool>("use_limits", UnityHingeJoint.useLimits);
445-
if (json.ContainsKey("limits")) {
446-
JObject limitsJSON = json["limits"].Value<JObject>();
447-
JointLimits limits = UnityHingeJoint.limits;
448-
limits.min = limitsJSON.ValueOrDefault<float>("min", limits.min);
449-
limits.max = limitsJSON.ValueOrDefault<float>("max", limits.max);
450-
limits.bounciness = limitsJSON.ValueOrDefault<float>("bounciness", limits.bounciness);
451-
limits.bounceMinVelocity = limitsJSON.ValueOrDefault<float>("bounce_min_velocity", UnityHingeJoint.limits.bounceMinVelocity);
452-
limits.contactDistance = limitsJSON.ValueOrDefault<float>("contact_distance", limits.contactDistance);
453-
UnityHingeJoint.limits = limits;
454-
}
455-
456-
// find connected body. this likely will need to be done post LoadFromJSON as it may
457-
// not be created yet.
458-
documentRoot.OnPostDeserializationNotification((docRoot) => {
459-
if (JSON.ContainsKey("connected_occurrence")) {
460-
ZOSimOccurrence connectedOccurrence = docRoot.GetOccurrence(JSON["connected_occurrence"].Value<string>());
461-
if (connectedOccurrence) {
462-
UnityHingeJoint.connectedBody = connectedOccurrence.GetComponent<Rigidbody>();
463-
} else {
464-
Debug.LogWarning("WARNING: ZOHingeJoint failed to find connected occurrence: " + JSON["connected_occurrence"].Value<string>());
465-
}
466-
467-
}
468-
});
469-
470-
}
471341
#endregion
472342

473343
}

Runtime/Scripts/ROS/Unity/Controllers/ZOArmController.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -666,20 +666,6 @@ public override string Type {
666666
get => "controller.arm_controller";
667667
}
668668

669-
public override JObject Serialize(ZOSimDocumentRoot documentRoot, UnityEngine.Object parent = null) {
670-
JObject json = new JObject(
671-
new JProperty("name", Name),
672-
new JProperty("type", Type),
673-
new JProperty("update_rate_hz", UpdateRateHz)
674-
);
675-
JSON = json;
676-
return json;
677-
}
678-
679-
public override void Deserialize(ZOSimDocumentRoot documentRoot, JObject json) {
680-
Name = json["name"].Value<string>();
681-
UpdateRateHz = json["update_rate_hz"].Value<float>();
682-
}
683669

684670
#endregion // ZOSerializationInterface
685671

Runtime/Scripts/ROS/Unity/Controllers/ZODifferentialDriveController.cs

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace ZO.ROS.Controllers {
3232
/// See: https://github.com/ros-controls/ros_controllers/blob/indigo-devel/diff_drive_controller/include/diff_drive_controller/diff_drive_controller.h
3333
/// </reference>
3434
/// TODO: Make this a ZOROSUnityGameObjectBase and a controller interface
35-
public class ZODifferentialDriveController : ZOGameObjectBase, ZOSerializationInterface {
35+
public class ZODifferentialDriveController : ZOGameObjectBase {
3636

3737
public String _name;
3838
public string Name {
@@ -386,50 +386,5 @@ public Task OnROSTwistMessageReceived(ZOROSBridgeConnection rosBridgeConnection,
386386
}
387387

388388

389-
public JObject Serialize(ZOSimDocumentRoot documentRoot, UnityEngine.Object parent = null) {
390-
JObject json = new JObject(
391-
new JProperty("name", Name),
392-
new JProperty("type", Type),
393-
new JProperty("connected_body", _connectedBody.Name),
394-
new JProperty("right_wheel_motor", new JObject(
395-
new JProperty("occurrence_name", _rightWheelMotor.GetComponent<ZOSimOccurrence>().Name),
396-
new JProperty("hinge_joint_name", _rightWheelMotor.Name)
397-
)),
398-
new JProperty("left_wheel_motor", new JObject(
399-
new JProperty("occurrence_name", _leftWheelMotor.GetComponent<ZOSimOccurrence>().Name),
400-
new JProperty("hinge_joint_name", _leftWheelMotor.Name)
401-
)),
402-
new JProperty("wheel_radius", _wheelRadius),
403-
new JProperty("wheel_seperation", _wheelSeperation),
404-
new JProperty("update_rate_hz", UpdateRateHz)
405-
);
406-
JSON = json;
407-
return json;
408-
}
409-
410-
public void Deserialize(ZOSimDocumentRoot documentRoot, JObject json) {
411-
JSON = json;
412-
Name = json["name"].Value<string>();
413-
_wheelRadius = json["wheel_radius"].Value<float>();
414-
_wheelSeperation = json["wheel_seperation"].Value<float>();
415-
UpdateRateHz = json["update_rate_hz"].Value<float>();
416-
417-
documentRoot.OnPostDeserializationNotification((docRoot) => {
418-
419-
// find and hook up the motors
420-
if (JSON.ContainsKey("connected_body")) {
421-
_connectedBody = docRoot.GetOccurrence(JSON["connected_body"].Value<string>());
422-
ZOSimOccurrence rightWheelOccurrence = docRoot.GetOccurrence(JSON["right_wheel_motor"]["occurrence_name"].Value<string>());
423-
ZOSimOccurrence leftWheelOccurrence = docRoot.GetOccurrence(JSON["left_wheel_motor"]["occurrence_name"].Value<string>());
424-
425-
_rightWheelMotor = rightWheelOccurrence.GetHingeJointNamed(JSON["right_wheel_motor"]["hinge_joint_name"].Value<string>());
426-
_leftWheelMotor = leftWheelOccurrence.GetHingeJointNamed(JSON["left_wheel_motor"]["hinge_joint_name"].Value<string>());
427-
428-
429-
}
430-
});
431-
432-
}
433389
}
434-
435390
}

0 commit comments

Comments
 (0)