Skip to content

Commit

Permalink
CMCL-0000: fix upgrader and legacy streaming bugs found in the Enemie…
Browse files Browse the repository at this point in the history
…s demo project. (#911)

* initial wip

* Regression fix: Legacy Lens settings had lost their ability to be animated

* Various bugs in upgrader

* Update CHANGELOG.md

* add missing API doc

* API doc again

* Fix broken legacy streaming

* CmCamera inspector tweaks

* more broken Legacy Upgrade
  • Loading branch information
glabute authored Nov 25, 2023
1 parent e7ec0e4 commit 18082a5
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 428 deletions.
4 changes: 3 additions & 1 deletion com.unity.cinemachine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Bugfix: Divide-by-zero error in InputAxis.CancelDeltaTime if deltaTime is zero.
- Regression fix: CinemachineCamera inspector Solo functionality was not updating correctly.
-
- Regression fix: Legacy Lens settings had lost their ability to be animated.
- Bugfix: Upgrader was not correctly upgrading animation bindings in some cases.

### Added
- Added CinemachineVirtualCameraBase.CancelDamping() convenience method to snap camera to its target position.
- Added CinemachineOrbitalFollow.TargetOffset to reposition orbit center.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public override VisualElement CreateInspectorGUI()
this.AddCameraStatus(ux);
this.AddTransitionsSection(ux, new () { serializedObject.FindProperty(() => Target.BlendHint) });
ux.Add(new PropertyField(serializedObject.FindProperty(() => Target.Lens)));
ux.Add(new PropertyField(serializedObject.FindProperty(() => Target.Target)));

ux.AddHeader("Global Settings");
this.AddGlobalControls(ux);

var defaultTargetLabel = new Label() { style = { alignSelf = Align.FlexEnd, opacity = 0.5f }};
var row = ux.AddChild(new InspectorUtility.LabeledRow("<b>Set Procedural Components</b>", "", defaultTargetLabel));
var row = ux.AddChild(new InspectorUtility.LabeledRow("<b>Procedural Components</b>", "", defaultTargetLabel));
row.focusable = false;
row.style.paddingTop = InspectorUtility.SingleLineHeight / 2;
row.style.paddingBottom = EditorGUIUtility.standardVerticalSpacing;

ux.Add(new PropertyField(serializedObject.FindProperty(() => Target.Target)));
this.AddPipelineDropdowns(ux);

ux.AddSpace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void GetExcludedPropertiesInInspector(List<string> excluded)
base.GetExcludedPropertiesInInspector(excluded);
excluded.Add(FieldPath(x => x.m_Orbits));
if (!Target.m_CommonLens)
excluded.Add(FieldPath(x => x.Lens));
excluded.Add(FieldPath(x => x.m_Lens));
if (Target.m_BindingMode == TargetTracking.BindingMode.LazyFollow)
{
excluded.Add(FieldPath(x => x.m_Heading));
Expand Down Expand Up @@ -80,7 +80,7 @@ public override void OnInspectorGUI()
DrawTargetsInInspector(serializedObject.FindProperty(() => Target.m_Follow), serializedObject.FindProperty(() => Target.m_LookAt));
DrawPropertyInInspector(serializedObject.FindProperty(() => Target.StandbyUpdate));
DrawPropertyInInspector(serializedObject.FindProperty(() => Target.m_CommonLens));
DrawPropertyInInspector(serializedObject.FindProperty(() => Target.Lens));
DrawPropertyInInspector(serializedObject.FindProperty(() => Target.m_Lens));
DrawRemainingPropertiesInInspector();

// Orbits
Expand Down Expand Up @@ -135,13 +135,13 @@ void OnSceneGUI()
if (freelook.m_CommonLens && CinemachineSceneToolUtility.IsToolActive(typeof(FoVTool)))
{
CinemachineSceneToolHelpers.FovToolHandle(freelook,
new SerializedObject(freelook).FindProperty(() => freelook.Lens),
freelook.Lens, IsHorizontalFOVUsed());
new SerializedObject(freelook).FindProperty(() => freelook.m_Lens),
freelook.m_Lens.ToLensSettings(), IsHorizontalFOVUsed());
}
else if (freelook.m_CommonLens && CinemachineSceneToolUtility.IsToolActive(typeof(FarNearClipTool)))
{
CinemachineSceneToolHelpers.NearFarClipHandle(freelook,
new SerializedObject(freelook).FindProperty(() => freelook.Lens));
new SerializedObject(freelook).FindProperty(() => freelook.m_Lens));
}
else if (freelook.Follow != null && CinemachineSceneToolUtility.IsToolActive(typeof(FollowOffsetTool)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void AdoptGameViewCameraSettings(MenuCommand command)
var brain = CinemachineCore.FindPotentialTargetBrain(vcam);
if (brain != null)
{
vcam.Lens = brain.State.Lens;
vcam.m_Lens.SetFromLensSettings(brain.State.Lens);
vcam.transform.SetPositionAndRotation(brain.transform.position, brain.transform.rotation);
}
}
Expand All @@ -31,7 +31,7 @@ static void AdoptGameViewCameraSettings(MenuCommand command)
static void AdoptSceneViewCameraSettings(MenuCommand command)
{
var vcam = command.context as CinemachineVirtualCamera;
vcam.Lens = CinemachineMenu.MatchSceneViewCamera(vcam.transform);
vcam.m_Lens.SetFromLensSettings(CinemachineMenu.MatchSceneViewCamera(vcam.transform));
}

/// <summary>Get the property names to exclude in the inspector.
Expand Down Expand Up @@ -125,13 +125,13 @@ void OnSceneGUI()
if (CinemachineSceneToolUtility.IsToolActive(typeof(FoVTool)))
{
CinemachineSceneToolHelpers.FovToolHandle(vcam,
new SerializedObject(vcam).FindProperty(() => vcam.Lens),
vcam.Lens, IsHorizontalFOVUsed());
new SerializedObject(vcam).FindProperty(() => vcam.m_Lens),
vcam.m_Lens.ToLensSettings(), IsHorizontalFOVUsed());
}
else if (CinemachineSceneToolUtility.IsToolActive(typeof(FarNearClipTool)))
{
CinemachineSceneToolHelpers.NearFarClipHandle(vcam,
new SerializedObject(vcam).FindProperty(() => vcam.Lens));
new SerializedObject(vcam).FindProperty(() => vcam.m_Lens));
}
Handles.color = originalColor;
}
Expand All @@ -153,7 +153,7 @@ public override void OnInspectorGUI()
DrawPropertyInInspector(serializedObject.FindProperty(() => Target.OutputChannel));
DrawTargetsInInspector(serializedObject.FindProperty(() => Target.m_Follow), serializedObject.FindProperty(() => Target.m_LookAt));
DrawPropertyInInspector(serializedObject.FindProperty(() => Target.StandbyUpdate));
DrawPropertyInInspector(serializedObject.FindProperty(() => Target.Lens));
DrawPropertyInInspector(serializedObject.FindProperty(() => Target.m_Lens));
DrawRemainingPropertiesInInspector();
m_PipelineSet.OnInspectorGUI(!IsPropertyExcluded("Header"));
DrawNonExcludedExtensionsWidgetInInspector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,211 +466,5 @@ void WritePhysicalSettings(in LensSettings.PhysicalSettings s)
p.FindPropertyRelative(() => s_Def.PhysicalProperties.Anamorphism).floatValue = s.Anamorphism;
}
}

#if true
///===========================================================================
/// IMGUI IMPLEMENTATION (to be removed)
///===========================================================================

static readonly GUIContent HFOVLabel = new ("Horizontal FOV", "Horizontal Field of View");
static readonly GUIContent VFOVLabel = new ("Vertical FOV", "Vertical Field of View");
static readonly GUIContent FocalLengthLabel = new ("Focal Length", "The length of the lens (in mm)");
static readonly GUIContent OrthoSizeLabel = new ("Ortho Size", "When using an orthographic camera, "
+ "this defines the half-height, in world coordinates, of the camera view.");
static readonly GUIContent AdvancedLabel = new ("Advanced");
static readonly string AdvancedHelpboxMessage = "Lens Mode Override must be enabled in the Cinemachine Brain for Mode Override to take effect";

static bool s_AdvancedLensExpanded;

struct Snapshot
{
public bool IsOrtho;
public bool IsPhysical;
public float Aspect;
public bool UseHorizontalFOV;
}
Snapshot m_Snapshot;

const float vSpace= 2;

void SnapshotCameraShadowValues(SerializedProperty property)
{
// Assume lens is up-to-date
m_Snapshot.UseHorizontalFOV = UseHorizontalFOV(property);
m_Snapshot.IsOrtho = IsOrtho(property);
m_Snapshot.IsPhysical = IsPhysical(property);
m_Snapshot.Aspect = Aspect(property);
}

GUIContent GetFOVLabel()
{
if (m_Snapshot.IsOrtho) return OrthoSizeLabel;
if (m_Snapshot.IsPhysical) return FocalLengthLabel;
return m_Snapshot.UseHorizontalFOV ? HFOVLabel : VFOVLabel;
}

void DrawFOVControl(Rect rect, SerializedProperty property, GUIContent label)
{
if (m_Snapshot.IsOrtho)
EditorGUI.PropertyField(
rect, property.FindPropertyRelative(() => s_Def.OrthographicSize), label);
else if (m_Snapshot.IsPhysical)
DrawFocalLengthControl(rect, property, label);
else
{
var FOVProperty = property.FindPropertyRelative(() => s_Def.FieldOfView);
float aspect = m_Snapshot.Aspect;
float f = FOVProperty.floatValue;
if (m_Snapshot.UseHorizontalFOV)
f = Camera.VerticalToHorizontalFieldOfView(f, aspect);
EditorGUI.BeginProperty(rect, label, FOVProperty);
f = EditorGUI.FloatField(rect, label, f);
if (m_Snapshot.UseHorizontalFOV)
f = Camera.HorizontalToVerticalFieldOfView(Mathf.Clamp(f, 1, 179), aspect);
if (!Mathf.Approximately(FOVProperty.floatValue, f))
FOVProperty.floatValue = Mathf.Clamp(f, 1, 179);
EditorGUI.EndProperty();
}
}

void DrawFocalLengthControl(Rect rect, SerializedProperty property, GUIContent label)
{
var FOVProperty = property.FindPropertyRelative(() => s_Def.FieldOfView);
var physicalProp = property.FindPropertyRelative(() => s_Def.PhysicalProperties);
var sensorSizeProp = physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.SensorSize);

float f = Camera.FieldOfViewToFocalLength(FOVProperty.floatValue, sensorSizeProp.vector2Value.y);
EditorGUI.BeginProperty(rect, label, FOVProperty);
f = EditorGUI.FloatField(rect, label, f);
f = Camera.FocalLengthToFieldOfView(Mathf.Max(0.01f, f), sensorSizeProp.vector2Value.y);
if (!Mathf.Approximately(FOVProperty.floatValue, f))
FOVProperty.floatValue = Mathf.Clamp(f, 1, 179);
EditorGUI.EndProperty();
}

public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
{
rect.height = EditorGUIUtility.singleLineHeight; // draw one line at a time

var fovLabel = GetFOVLabel();
var fovLabelWidth = GUI.skin.label.CalcSize(fovLabel).x;

property.isExpanded = EditorGUI.Foldout(
new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth - fovLabelWidth, rect.height),
property.isExpanded, label, true);

if (!property.isExpanded)
{
// Put the FOV on the same line
var oldIndent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
var oldLabelWidth = EditorGUIUtility.labelWidth;
var delta = EditorGUIUtility.labelWidth - fovLabelWidth;
EditorGUIUtility.labelWidth = fovLabelWidth;
DrawFOVControl(
new Rect(rect.x + delta, rect.y, rect.width - delta, rect.height),
property, fovLabel);
EditorGUIUtility.labelWidth = oldLabelWidth;
EditorGUI.indentLevel = oldIndent;
}
else
{
++EditorGUI.indentLevel;

rect.y += rect.height + vSpace;
DrawFOVControl(rect, property, fovLabel);

rect.y += rect.height + vSpace;
var nearClip = property.FindPropertyRelative(() => s_Def.NearClipPlane);
EditorGUI.PropertyField(rect, nearClip);
if (!m_Snapshot.IsOrtho && nearClip.floatValue < 0.01f)
{
nearClip.floatValue = 0.01f;
property.serializedObject.ApplyModifiedPropertiesWithoutUndo();
}
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => s_Def.FarClipPlane));

rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => s_Def.Dutch));

if (m_Snapshot.IsPhysical)
{
var physicalProp = property.FindPropertyRelative(() => s_Def.PhysicalProperties);
rect.y += rect.height + vSpace;
physicalProp.isExpanded = EditorGUI.Foldout(rect, physicalProp.isExpanded, physicalProp.displayName, true);
if (physicalProp.isExpanded)
{
++EditorGUI.indentLevel;
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.GateFit));
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.SensorSize));
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.LensShift));
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.Iso));
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.ShutterSpeed));
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.Aperture));
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.BladeCount));
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.Curvature));
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.BarrelClipping));
rect.y += rect.height + vSpace;
EditorGUI.PropertyField(rect, physicalProp.FindPropertyRelative(() => s_Def.PhysicalProperties.Anamorphism));
--EditorGUI.indentLevel;
}
}
if (!HideModeOverride)
{
rect.y += rect.height + vSpace;
s_AdvancedLensExpanded = EditorGUI.Foldout(rect, s_AdvancedLensExpanded, AdvancedLabel);
if (s_AdvancedLensExpanded)
{
++EditorGUI.indentLevel;
rect.y += rect.height + vSpace;
var r = EditorGUI.IndentedRect(rect); r.height *= 2;
EditorGUI.HelpBox(r, AdvancedHelpboxMessage, MessageType.Info);

rect.y += r.height + vSpace;
EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => s_Def.ModeOverride));
--EditorGUI.indentLevel;
}
}
--EditorGUI.indentLevel;
}
property.serializedObject.ApplyModifiedProperties();
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
SnapshotCameraShadowValues(property);

var lineHeight = EditorGUIUtility.singleLineHeight;
if (!property.isExpanded)
return lineHeight;

int numLines = 4;
if (m_Snapshot.IsPhysical)
{
numLines += 1;
var physicalProp = property.FindPropertyRelative(() => s_Def.PhysicalProperties);
if (physicalProp.isExpanded)
numLines += 10;
}
if (!HideModeOverride)
{
// Advanced section
numLines += 1;
if (s_AdvancedLensExpanded)
numLines += 3; // not correct but try to make it big enough to hold the help box
}
return lineHeight + numLines * (lineHeight + vSpace);
}
#endif
}
}
Loading

0 comments on commit 18082a5

Please sign in to comment.