Skip to content

Commit

Permalink
Added post-processing to stretch-robot initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
elimvb committed Jul 16, 2024
1 parent c87dcc0 commit 76e0203
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ MonoBehaviour:
- {fileID: 114156960648436490}
- {fileID: 114125738884031076}
- {fileID: 114774809263292024}
- {fileID: 8332371402478750980}
--- !u!114 &114125738884031076
MonoBehaviour:
m_ObjectHideFlags: 3
Expand Down Expand Up @@ -75,7 +76,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c1cb7e9e120078f43bce4f0b1be547a7, type: 3}
m_Name: AmbientOcclusion
m_EditorClassIdentifier:
active: 0
active: 1
enabled:
overrideState: 1
value: 1
Expand Down Expand Up @@ -1423,3 +1424,37 @@ MonoBehaviour:
- 0.5
- 0.5
- 0.5
--- !u!114 &8332371402478750980
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9b77c5407dc277943b591ade9e6b18c5, type: 3}
m_Name: LensDistortion
m_EditorClassIdentifier:
active: 0
enabled:
overrideState: 1
value: 1
intensity:
overrideState: 1
value: 35
intensityX:
overrideState: 0
value: 1
intensityY:
overrideState: 0
value: 1
centerX:
overrideState: 0
value: 0
centerY:
overrideState: 0
value: 0
scale:
overrideState: 1
value: 1.03
25 changes: 23 additions & 2 deletions unity/Assets/Scripts/StretchAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public partial class StretchAgentController : ArmAgentController {
);
private Vector3 defaultSecondaryCameraLocalRotation = new Vector3(50f, 90f, 0);
private float defaultSecondaryCameraFieldOfView = 59f;
private bool distortLens = true;

public StretchAgentController(
BaseAgentComponent baseAgentComponent,
Expand Down Expand Up @@ -57,8 +58,6 @@ public override ActionFinished InitializeBody(ServerAction initializeAction) {
cc.center = m_CharacterController.center;
cc.radius = m_CharacterController.radius;
cc.height = m_CharacterController.height;
m_Camera.GetComponent<PostProcessVolume>().enabled = true;
m_Camera.GetComponent<PostProcessLayer>().enabled = true;

// set camera stand/crouch local positions for Tall mode
standingLocalCameraPosition = m_Camera.transform.localPosition;
Expand Down Expand Up @@ -92,6 +91,12 @@ public override ActionFinished InitializeBody(ServerAction initializeAction) {
fp_camera_2.transform.localEulerAngles = defaultSecondaryCameraLocalRotation;
fp_camera_2.fieldOfView = defaultSecondaryCameraFieldOfView;

// set up lens distortion for stretch bot cameras
if (distortLens == true) {
enableLensDistortion(m_Camera);
enableLensDistortion(fp_camera_2);
}

// limit camera from looking too far down/up
if (Mathf.Approximately(initializeAction.maxUpwardLookAngle, 0.0f)) {
this.maxUpwardLookAngle = 25f;
Expand Down Expand Up @@ -133,6 +138,22 @@ out secondaryCameraParams
return ActionFinished.Success;
}

public void enableLensDistortion(Camera camera) {
// "enableLensDistortion" - Set this up as an external function that takes a camera, then run it for both!!!
// don't forget to emulate this logic for LocoBot, but only if you think it's worth standardizing, and not one-offing like here...
PostProcessVolume cameraPPVolume = camera.GetComponent<PostProcessVolume>();
cameraPPVolume.enabled = true;

PostProcessLayer cameraPPLayer = camera.GetComponent<PostProcessLayer>();
cameraPPLayer.enabled = true;

PostProcessProfile cameraPPProfile = cameraPPVolume.profile;

if (cameraPPProfile.TryGetSettings(out LensDistortion lensDistortion)) {
lensDistortion.active = true; // Toggle Lens Distortion on based on some condition
}
}

private ArmController getArmImplementation() {
Stretch_Robot_Arm_Controller arm =
GetComponentInChildren<Stretch_Robot_Arm_Controller>();
Expand Down

0 comments on commit 76e0203

Please sign in to comment.