Пример #1
0
        static void Handle_OriginEditing(HDReflectionProbeUI s, SerializedHDReflectionProbe sp, Editor o)
        {
            var p = (ReflectionProbe)sp.so.targetObject;
            var transformPosition = p.transform.position;
            var size = p.size;

            EditorGUI.BeginChangeCheck();
            var newPostion = Handles.PositionHandle(transformPosition, HDReflectionProbeEditorUtility.GetLocalSpaceRotation(p));

            var changed = EditorGUI.EndChangeCheck();

            if (changed || s.oldLocalSpace != HDReflectionProbeEditorUtility.GetLocalSpace(p))
            {
                var localNewPosition = s.oldLocalSpace.inverse.MultiplyPoint3x4(newPostion);

                var b = new Bounds(p.center, size);
                localNewPosition = b.ClosestPoint(localNewPosition);

                Undo.RecordObject(p.transform, "Modified Reflection Probe Origin");
                p.transform.position = s.oldLocalSpace.MultiplyPoint3x4(localNewPosition);

                Undo.RecordObject(p, "Modified Reflection Probe Origin");
                p.center = HDReflectionProbeEditorUtility.GetLocalSpace(p).inverse.MultiplyPoint3x4(s.oldLocalSpace.MultiplyPoint3x4(p.center));

                EditorUtility.SetDirty(p);

                s.UpdateOldLocalSpace(p);
            }
        }
        static void Gizmos_Influence(ReflectionProbe p, HDAdditionalReflectionData a, HDReflectionProbeEditor e, bool isEdit)
        {
            var col = Gizmos.color;
            var mat = Gizmos.matrix;

            Gizmos.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(p);
            switch (a.influenceShape)
            {
            case ShapeType.Box:
            {
                Gizmos.color = k_GizmoThemeColorExtentFace;
                e.m_UIState.alternativeBoxInfluenceHandle.DrawHull(isEdit);
                break;
            }

            case ShapeType.Sphere:
            {
                Gizmos.color = k_GizmoThemeColorExtentFace;
                if (isEdit)
                {
                    Gizmos.DrawSphere(p.center, a.influenceSphereRadius);
                }
                else
                {
                    Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius);
                }
                break;
            }
            }

            Gizmos.matrix = mat;
            Gizmos.color  = col;
        }
Пример #3
0
        static void Gizmos_Influence(ReflectionProbe p, HDAdditionalReflectionData a, Editor e, bool isEdit)
        {
            var col = Gizmos.color;
            var mat = Gizmos.matrix;

            Gizmos.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(p);
            switch (a.influenceShape)
            {
            case ReflectionInfluenceShape.Box:
            {
                Gizmos.color = isEdit ? k_GizmoThemeColorExtentFace : k_GizmoThemeColorExtent;
                if (isEdit)
                {
                    Gizmos.DrawCube(p.center, p.size);
                }
                else
                {
                    Gizmos.DrawWireCube(p.center, p.size);
                }
                break;
            }

            case ReflectionInfluenceShape.Sphere:
            {
                Gizmos.color = k_GizmoThemeColorExtentFace;
                if (isEdit)
                {
                    Gizmos.DrawSphere(p.center, a.influenceSphereRadius);
                }
                else
                {
                    Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius);
                }
                break;
            }
            }

            Gizmos.matrix = mat;
            Gizmos.color  = col;
        }
Пример #4
0
        static void Handle_InfluenceFadeEditing(HDReflectionProbeUI s, SerializedHDReflectionProbe sp, Editor o, InfluenceType influenceType)
        {
            BoxBoundsHandle    blendBox;
            SphereBoundsHandle sphereHandle;
            Vector3            probeBlendDistancePositive, probeBlendDistanceNegative;
            Color color;

            switch (influenceType)
            {
            default:
            case InfluenceType.Standard:
            {
                blendBox     = s.boxBlendHandle;
                sphereHandle = s.sphereBlendHandle;
                probeBlendDistancePositive = sp.targetData.blendDistancePositive;
                probeBlendDistanceNegative = sp.targetData.blendDistanceNegative;
                color = k_GizmoThemeColorInfluenceBlend;
                break;
            }

            case InfluenceType.Normal:
            {
                blendBox     = s.boxBlendNormalHandle;
                sphereHandle = s.sphereBlendNormalHandle;
                probeBlendDistancePositive = sp.targetData.blendNormalDistancePositive;
                probeBlendDistanceNegative = sp.targetData.blendNormalDistanceNegative;
                color = k_GizmoThemeColorInfluenceNormalBlend;
                break;
            }
            }


            var mat = Handles.matrix;
            var col = Handles.color;

            Handles.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(sp.target);
            switch ((ReflectionInfluenceShape)sp.influenceShape.enumValueIndex)
            {
            case ReflectionInfluenceShape.Box:
            {
                blendBox.center = sp.target.center - (probeBlendDistancePositive - probeBlendDistanceNegative) * 0.5f;
                blendBox.size   = sp.target.size - probeBlendDistancePositive - probeBlendDistanceNegative;

                Handles.color = k_GizmoThemeColorExtent;
                EditorGUI.BeginChangeCheck();
                Handles.color = color;
                blendBox.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(sp.target, "Modified Reflection Probe Influence");
                    Undo.RecordObject(sp.targetData, "Modified Reflection Probe Influence");

                    var center        = sp.target.center;
                    var influenceSize = sp.target.size;

                    var diff     = 2 * (blendBox.center - center);
                    var sum      = influenceSize - blendBox.size;
                    var positive = (sum - diff) * 0.5f;
                    var negative = (sum + diff) * 0.5f;
                    var blendDistancePositive = Vector3.Max(Vector3.zero, Vector3.Min(positive, influenceSize));
                    var blendDistanceNegative = Vector3.Max(Vector3.zero, Vector3.Min(negative, influenceSize));

                    probeBlendDistancePositive = blendDistancePositive;
                    probeBlendDistanceNegative = blendDistanceNegative;

                    ApplyConstraintsOnTargets(s, sp, o);

                    EditorUtility.SetDirty(sp.target);
                    EditorUtility.SetDirty(sp.targetData);
                }
                break;
            }

            case ReflectionInfluenceShape.Sphere:
            {
                sphereHandle.center = sp.target.center;
                sphereHandle.radius = Mathf.Clamp(sp.targetData.influenceSphereRadius - probeBlendDistancePositive.x, 0, sp.targetData.influenceSphereRadius);

                Handles.color = k_GizmoThemeColorExtent;
                EditorGUI.BeginChangeCheck();
                Handles.color = color;
                sphereHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(sp.target, "Modified Reflection influence volume");
                    Undo.RecordObject(sp.targetData, "Modified Reflection influence volume");

                    var influenceRadius = sp.targetData.influenceSphereRadius;
                    var blendRadius     = sphereHandle.radius;

                    var blendDistance = Mathf.Clamp(influenceRadius - blendRadius, 0, influenceRadius);

                    probeBlendDistancePositive = Vector3.one * blendDistance;
                    probeBlendDistanceNegative = probeBlendDistancePositive;

                    ApplyConstraintsOnTargets(s, sp, o);

                    EditorUtility.SetDirty(sp.target);
                    EditorUtility.SetDirty(sp.targetData);
                }
                break;
            }
            }
            Handles.matrix = mat;
            Handles.color  = col;


            switch (influenceType)
            {
            default:
            case InfluenceType.Standard:
            {
                sp.targetData.blendDistancePositive = probeBlendDistancePositive;
                sp.targetData.blendDistanceNegative = probeBlendDistanceNegative;
                break;
            }

            case InfluenceType.Normal:
            {
                sp.targetData.blendNormalDistancePositive = probeBlendDistancePositive;
                sp.targetData.blendNormalDistanceNegative = probeBlendDistanceNegative;
                break;
            }
            }
        }
Пример #5
0
        static void Gizmos_InfluenceFade(ReflectionProbe p, HDAdditionalReflectionData a, Editor e, InfluenceType type, bool isEdit)
        {
            var col = Gizmos.color;
            var mat = Gizmos.matrix;

            Vector3 boxCenterOffset;
            Vector3 boxSizeOffset;
            float   sphereRadiusOffset;
            Color   color;

            switch (type)
            {
            default:
            case InfluenceType.Standard:
            {
                boxCenterOffset    = a.boxBlendCenterOffset;
                boxSizeOffset      = a.boxBlendSizeOffset;
                sphereRadiusOffset = a.sphereBlendRadiusOffset;
                color = isEdit ? k_GizmoThemeColorInfluenceBlendFace : k_GizmoThemeColorInfluenceBlend;
                break;
            }

            case InfluenceType.Normal:
            {
                boxCenterOffset    = a.boxBlendNormalCenterOffset;
                boxSizeOffset      = a.boxBlendNormalSizeOffset;
                sphereRadiusOffset = a.sphereBlendNormalRadiusOffset;
                color = isEdit ? k_GizmoThemeColorInfluenceNormalBlendFace : k_GizmoThemeColorInfluenceNormalBlend;
                break;
            }
            }

            Gizmos.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(p);
            switch (a.influenceShape)
            {
            case ReflectionInfluenceShape.Box:
            {
                Gizmos.color = color;
                if (isEdit)
                {
                    Gizmos.DrawCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
                }
                else
                {
                    Gizmos.DrawWireCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
                }
                break;
            }

            case ReflectionInfluenceShape.Sphere:
            {
                Gizmos.color = color;
                if (isEdit)
                {
                    Gizmos.DrawSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
                }
                else
                {
                    Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
                }
                break;
            }
            }

            Gizmos.matrix = mat;
            Gizmos.color  = col;
        }
Пример #6
0
        static void Handle_InfluenceEditing(HDReflectionProbeUI s, SerializedHDReflectionProbe sp, Editor o)
        {
            var mat = Handles.matrix;
            var col = Handles.color;

            Handles.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(sp.target);
            switch ((ReflectionInfluenceShape)sp.influenceShape.enumValueIndex)
            {
            case ReflectionInfluenceShape.Box:
            {
                s.boxInfluenceHandle.center = sp.target.center;
                s.boxInfluenceHandle.size   = sp.target.size;

                Handles.color = k_GizmoThemeColorExtent;
                EditorGUI.BeginChangeCheck();
                s.boxInfluenceHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(sp.target, "Modified Reflection Probe AABB");
                    Undo.RecordObject(sp.targetData, "Modified Reflection Probe AABB");

                    var center = s.boxInfluenceHandle.center;
                    var size   = s.boxInfluenceHandle.size;

                    HDReflectionProbeEditorUtility.ValidateAABB(sp.target, ref center, ref size);

                    sp.target.center = center;
                    sp.target.size   = size;

                    ApplyConstraintsOnTargets(s, sp, o);

                    EditorUtility.SetDirty(sp.target);
                    EditorUtility.SetDirty(sp.targetData);
                }
                break;
            }

            case ReflectionInfluenceShape.Sphere:
            {
                s.sphereInfluenceHandle.center = sp.target.center;
                s.sphereInfluenceHandle.radius = sp.targetData.influenceSphereRadius;

                Handles.color = k_GizmoThemeColorExtent;
                EditorGUI.BeginChangeCheck();
                s.sphereInfluenceHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(sp.target, "Modified Reflection Probe AABB");
                    Undo.RecordObject(sp.targetData, "Modified Reflection Probe AABB");

                    var center          = sp.target.center;
                    var influenceRadius = s.sphereInfluenceHandle.radius;
                    var radius          = Vector3.one * influenceRadius;

                    HDReflectionProbeEditorUtility.ValidateAABB(sp.target, ref center, ref radius);
                    influenceRadius = radius.x;

                    sp.targetData.influenceSphereRadius = influenceRadius;

                    ApplyConstraintsOnTargets(s, sp, o);

                    EditorUtility.SetDirty(sp.target);
                    EditorUtility.SetDirty(sp.targetData);
                }
                break;
            }
            }
            Handles.matrix = mat;
            Handles.color  = col;
        }
Пример #7
0
 internal void UpdateOldLocalSpace(ReflectionProbe target)
 {
     oldLocalSpace = HDReflectionProbeEditorUtility.GetLocalSpace(target);
 }
        static void Gizmos_InfluenceFade(ReflectionProbe p, HDAdditionalReflectionData a, HDReflectionProbeEditor e, InfluenceType type, bool isEdit)
        {
            var col = Gizmos.color;
            var mat = Gizmos.matrix;

            Gizmo6FacesBoxContained box;
            Vector3 boxCenterOffset;
            Vector3 boxSizeOffset;
            float   sphereRadiusOffset;
            Color   color;

            switch (type)
            {
            default:
            case InfluenceType.Standard:
            {
                box                = e != null ? e.m_UIState.alternativeBoxBlendHandle : null;
                boxCenterOffset    = a.boxBlendCenterOffset;
                boxSizeOffset      = a.boxBlendSizeOffset;
                sphereRadiusOffset = a.sphereBlendRadiusOffset;
                color              = isEdit ? k_GizmoThemeColorInfluenceBlendFace : k_GizmoThemeColorInfluenceBlend;
                break;
            }

            case InfluenceType.Normal:
            {
                box                = e != null ? e.m_UIState.alternativeBoxBlendNormalHandle : null;
                boxCenterOffset    = a.boxBlendNormalCenterOffset;
                boxSizeOffset      = a.boxBlendNormalSizeOffset;
                sphereRadiusOffset = a.sphereBlendNormalRadiusOffset;
                color              = isEdit ? k_GizmoThemeColorInfluenceNormalBlendFace : k_GizmoThemeColorInfluenceNormalBlend;
                break;
            }
            }

            Gizmos.matrix = HDReflectionProbeEditorUtility.GetLocalSpace(p);
            switch (a.influenceShape)
            {
            case ShapeType.Box:
            {
                Gizmos.color = color;
                if (e != null)        // e == null may occure when editor have still not been created at selection while the tool is not used for this part
                {
                    box.DrawHull(isEdit);
                }
                else
                {
                    if (isEdit)
                    {
                        Gizmos.DrawCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
                    }
                    else
                    {
                        Gizmos.DrawWireCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
                    }
                }
                break;
            }

            case ShapeType.Sphere:
            {
                Gizmos.color = color;
                if (isEdit)
                {
                    Gizmos.DrawSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
                }
                else
                {
                    Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
                }
                break;
            }
            }

            Gizmos.matrix = mat;
            Gizmos.color  = col;
        }