Zinnia.Unity icon indicating copy to clipboard operation
Zinnia.Unity copied to clipboard

Would PinchScaler.cs support MinimumMultiplier/MaximumMultiplier or MinimumScale/MaximumScale and Only change Scale X/Y/Z?

Open BelieveXiaoShuai opened this issue 6 years ago • 3 comments

Environment

  1. VRTK.Prefab 1.1.4
  2. Unity 2019.2.1f1
  3. Hardware used (Oculus Rift)
  4. SDK used (Oculus Intergation)

Expected behavior

I expect the intention of the set up is Secondary_Scale to support the limit of minimum/maximum scale and only change Scale X/Y/Z.

Current behavior

The source feature has very limited use.

The solution I'd like

I rewrite PinchScaler.cs to support. may be humble:

    public float MinMultiple = 0.2f;
    public float MaxMultiple = 4.0f;
    private bool m_Flag;

    public override void Process()
    {
        if (Target == null)
        {
            m_Flag = false;
            return;
        }

        if (Target != null)
        {
            if (!m_Flag)
            {
                originalScale = GetTargetScale();
            }

            m_Flag = true;
            var curLocalScale = GetTargetScale();
            var minLocalScale = originalScale * MinMultiple;
            var maxLocalScale = originalScale * MaxMultiple;
            previousDistance = previousDistance ?? GetDistance();
            var distanceDelta = GetDistance() - (float) previousDistance;
            var scale = distanceDelta * Multiplier;
            if (curLocalScale.x <= minLocalScale.x)
            {
                if (scale <= 0)
                {
                    return;
                }
            }

            if (curLocalScale.x >= maxLocalScale.x)
            {
                if (scale > 0)
                {
                    return;
                }
            }
        }

        base.Process();
    }

BelieveXiaoShuai avatar Nov 07 '19 12:11 BelieveXiaoShuai

Is it true that it can be coupled with a Vector3Restrictor

fight4dream avatar Nov 13 '19 11:11 fight4dream

The component right now does the scaling so you wouldn't be able to pass the data out to a 3rd party component via events. but some sort of a restrictor, or clamper that you can optionally inject into scripts could work.

thestonefox avatar Nov 14 '19 13:11 thestonefox

So yeah I think some sort of data clampers would work in this instance.

So you could have

  • int clamper
  • float clamper
  • vector2 clamper
  • vector3 clamper

And you call Clamp passing the input type and it emits the clamped value.

Then in this regard because PinchScaler is a process, you could do:

TransformScaleExtractor.Extract -> Vector3Clamper -> TransformScaleMutator.SetGlobal/Local

thestonefox avatar Nov 24 '19 18:11 thestonefox

PR https://github.com/ExtendRealityLtd/Zinnia.Unity/pull/587

thestonefox avatar May 01 '23 19:05 thestonefox