Skip to content

Hd/fix pivot size ratio percistency through 0 #3600

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

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
2 changes: 1 addition & 1 deletion com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed issue with compositor custom pass hooks added/removed repeatedly (case 1315971).
- Fixed: SSR with transparent (case 1311088)
- Fixed decals in material debug display.

- Fixed WouldFitInAtlas that would previously return wrong results if any one face of a point light would fit (it used to return true even though the light in entirety wouldn't fit).
- Fixed loss of persistency of ratio between pivot position and size when sliding by 0 in DecalProjector inspector (case 1308338)

### Changed
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ private void OnEnable()
};
m_FadeFactor = serializedObject.FindProperty("m_FadeFactor");
m_DecalLayerMask = serializedObject.FindProperty("m_DecalLayerMask");

ReinitSavedRatioSizePivotPosition();
}

private void OnDisable()
Expand Down Expand Up @@ -336,6 +338,8 @@ void DrawPivotHandles(DecalProjector decalProjector)

decalProjector.pivot += Quaternion.Inverse(decalProjector.transform.rotation) * (decalProjector.transform.position - newPosition);
decalProjector.transform.position = newPosition;

ReinitSavedRatioSizePivotPosition();
}
}
}
Expand Down Expand Up @@ -452,11 +456,66 @@ static Func<Bounds> GetBoundsGetter(DecalProjector decalProjector)
};
}

void UpdateSize(int axe, float newSize, float oldSize)
// Temporarilly save ratio beetwin size and pivot position while editing in inspector.
// null or NaN is used to say that there is no saved ratio.
// Aim is to keep propotion while sliding the value to 0 in Inspector and then go back to something else.
// Current solution only work for the life of this editor, but is enough in most case.
// Wich means if you go to there, selection something else and go back on it, pivot position is thus null.
Dictionary<DecalProjector, Vector3> ratioSizePivotPositionSaved = null;

void ReinitSavedRatioSizePivotPosition()
{
m_SizeValues[axe].floatValue = newSize;
if (oldSize > Mathf.Epsilon)
m_OffsetValues[axe].floatValue *= newSize / oldSize;
ratioSizePivotPositionSaved = null;
}

void UpdateSize(int axe, float newSize)
{
void UpdateSizeOfOneTarget(DecalProjector currentTarget)
{
//lazy init on demand as targets array cannot be accessed from OnSceneGUI so in edit mode.
if (ratioSizePivotPositionSaved == null)
{
ratioSizePivotPositionSaved = new Dictionary<DecalProjector, Vector3>();
foreach (DecalProjector projector in targets)
ratioSizePivotPositionSaved[projector] = new Vector3(float.NaN, float.NaN, float.NaN);
}

// Save old ratio if not registered
// Either or are NaN or no one, check only first
Vector3 saved = ratioSizePivotPositionSaved[currentTarget];
if (float.IsNaN(saved[axe]))
{
float oldSize = currentTarget.m_Size[axe];
saved[axe] = Mathf.Abs(oldSize) <= Mathf.Epsilon ? 0f : currentTarget.m_Offset[axe] / oldSize;
ratioSizePivotPositionSaved[currentTarget] = saved;
}

currentTarget.m_Size[axe] = newSize;
currentTarget.m_Offset[axe] = saved[axe] * newSize;

// refresh DecalProjector to update projection
currentTarget.OnValidate();
}

// Manually register Undo as we work directly on the target
Undo.RecordObjects(targets, "Change DecalProjector Size or Depth");

// Apply any change on target first
serializedObject.ApplyModifiedProperties();

// update each target
foreach (DecalProjector decalProjector in targets)
UpdateSizeOfOneTarget(decalProjector);

// update again serialize object to register change in targets
serializedObject.Update();

// change was not tracked by SerializeReference so force repaint the scene views and game views
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();

// strange: we need to force it throu serialization to update multiple differente value state (value are right but still detected as different)
if (m_SizeValues[axe].hasMultipleDifferentValues)
m_SizeValues[axe].floatValue = newSize;
}

public override void OnInspectorGUI()
Expand All @@ -483,26 +542,31 @@ public override void OnInspectorGUI()
Rect rect = EditorGUILayout.GetControlRect(true, EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector2, k_SizeContent));
EditorGUI.BeginProperty(rect, k_SizeSubContent[0], m_SizeValues[0]);
EditorGUI.BeginProperty(rect, k_SizeSubContent[1], m_SizeValues[1]);
bool savedHasMultipleDifferentValue = EditorGUI.showMixedValue;
EditorGUI.showMixedValue = m_SizeValues[0].hasMultipleDifferentValues || m_SizeValues[1].hasMultipleDifferentValues;
float[] size = new float[2] { m_SizeValues[0].floatValue, m_SizeValues[1].floatValue };
EditorGUI.BeginChangeCheck();
EditorGUI.MultiFloatField(rect, k_SizeContent, k_SizeSubContent, size);
if (EditorGUI.EndChangeCheck())
{
for (int i = 0; i < 2; ++i)
UpdateSize(i, Mathf.Max(0, size[i]), m_SizeValues[i].floatValue);
UpdateSize(i, Mathf.Max(0, size[i]));
}
EditorGUI.showMixedValue = savedHasMultipleDifferentValue;
EditorGUI.EndProperty();
EditorGUI.EndProperty();

EditorGUI.BeginProperty(rect, k_ProjectionDepthContent, m_SizeValues[2]);
EditorGUI.BeginChangeCheck();
float oldSizeZ = m_SizeValues[2].floatValue;
EditorGUILayout.PropertyField(m_SizeValues[2], k_ProjectionDepthContent);
float newSizeZ = EditorGUILayout.FloatField(k_ProjectionDepthContent, m_SizeValues[2].floatValue);
if (EditorGUI.EndChangeCheck())
{
UpdateSize(2, Mathf.Max(0, m_SizeValues[2].floatValue), oldSizeZ);
}
UpdateSize(2, Mathf.Max(0, newSizeZ));

EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_Offset, k_Offset);
if (EditorGUI.EndChangeCheck())
ReinitSavedRatioSizePivotPosition();
EditorGUI.EndProperty();

EditorGUILayout.PropertyField(m_MaterialProperty, k_MaterialContent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public DecalLayerEnum decalLayerMask
}

[SerializeField]
private Vector3 m_Offset = new Vector3(0, 0, 0.5f);
internal Vector3 m_Offset = new Vector3(0, 0, 0);
/// <summary>
/// Change the pivot position.
/// It is an offset between the center of the projection and the transform position.
Expand All @@ -199,7 +199,7 @@ public Vector3 pivot
}

[SerializeField]
Vector3 m_Size = new Vector3(1, 1, 1);
internal Vector3 m_Size = new Vector3(1, 1, 1);
/// <summary>
/// The size of the projection volume.
/// See also <seealso cref="ResizeAroundPivot"/> to rescale relatively to the pivot position.
Expand Down