コード例 #1
0
    public override bool Inspector()
    {
        MegaMultiVolSelect mod = (MegaMultiVolSelect)target;

#if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019
        EditorGUIUtility.LookLikeControls();
#endif
        mod.Label      = EditorGUILayout.TextField("Label", mod.Label);
        mod.MaxLOD     = EditorGUILayout.IntField("MaxLOD", mod.MaxLOD);
        mod.ModEnabled = EditorGUILayout.Toggle("Enabled", mod.ModEnabled);
        int order = EditorGUILayout.IntField("Order", mod.Order);
        if (order != mod.Order)
        {
            mod.Order = order;

            MegaModifiers context = mod.GetComponent <MegaModifiers>();

            if (context != null)
            {
                context.BuildList();
            }
        }

        mod.freezeSelection = EditorGUILayout.Toggle("Freeze Selection", mod.freezeSelection);
        mod.useCurrentVerts = EditorGUILayout.Toggle("Use Stack Verts", mod.useCurrentVerts);

        mod.displayWeights = EditorGUILayout.Toggle("Show Weights", mod.displayWeights);
        mod.gizCol         = EditorGUILayout.ColorField("Gizmo Col", mod.gizCol);
        mod.gizSize        = EditorGUILayout.FloatField("Gizmo Size", mod.gizSize);

        if (GUILayout.Button("Add Volume"))
        {
            mod.volumes.Add(MegaVolume.Create());
            EditorUtility.SetDirty(target);
        }

        for (int v = 0; v < mod.volumes.Count; v++)
        {
            MegaVolume vol = mod.volumes[v];

            vol.enabled = EditorGUILayout.BeginToggleGroup("Enabled", vol.enabled);
            vol.volType = (MegaVolumeType)EditorGUILayout.EnumPopup("Type", vol.volType);

            if (vol.volType == MegaVolumeType.Sphere)
            {
                vol.radius = EditorGUILayout.FloatField("Radius", vol.radius);
            }
            else
            {
                vol.boxsize = EditorGUILayout.Vector3Field("Size", vol.boxsize);
            }

            vol.weight  = EditorGUILayout.Slider("Weight", vol.weight, 0.0f, 1.0f);
            vol.falloff = EditorGUILayout.FloatField("Falloff", vol.falloff);
            vol.origin  = EditorGUILayout.Vector3Field("Origin", vol.origin);
            vol.target  = (Transform)EditorGUILayout.ObjectField("Target", vol.target, typeof(Transform), true);
            vol.inverse = EditorGUILayout.Toggle("Inverse", vol.inverse);

            EditorGUILayout.EndToggleGroup();

            if (GUILayout.Button("Delete Volume"))
            {
                mod.volumes.RemoveAt(v);
                v--;
                EditorUtility.SetDirty(target);
            }
        }

        return(false);
    }
コード例 #2
0
    // option to use base verts or current stack verts for distance calc
    // flag to display weights
    // size of weights and color of gizmo

    public override void DrawSceneGUI()
    {
        MegaMultiVolSelect mod = (MegaMultiVolSelect)target;

        if (!mod.ModEnabled)
        {
            return;
        }

        MegaModifiers mc = mod.gameObject.GetComponent <MegaModifiers>();

        float[] sel = mod.GetSel();

        if (mc != null && sel != null)
        {
            //Color col = Color.black;

            Matrix4x4 tm = mod.gameObject.transform.localToWorldMatrix;
            Handles.matrix = tm;                //Matrix4x4.identity;

            if (mod.displayWeights)
            {
                for (int i = 0; i < sel.Length; i++)
                {
                    float w = sel[i];
                    if (w > 0.001f)
                    {
                        if (w > 0.5f)
                        {
                            Handles.color = Color.Lerp(Color.green, Color.red, (w - 0.5f) * 2.0f);
                        }
                        else
                        {
                            Handles.color = Color.Lerp(Color.blue, Color.green, w * 2.0f);
                        }

                        MegaHandles.DotCap(i, mc.sverts[i], Quaternion.identity, mod.gizSize);
                    }
                }
            }

            Vector3 origin = Vector3.zero;

            for (int v = 0; v < mod.volumes.Count; v++)
            {
                MegaVolume vol = mod.volumes[v];

                if (vol.enabled)
                {
                    Handles.color = mod.gizCol;                         //new Color(0.5f, 0.5f, 0.5f, 0.2f);

                    // Draw box if box type
                    if (vol.volType == MegaVolumeType.Sphere)
                    {
                        //Handles.SphereCap(0, tm.MultiplyPoint(vol.origin), Quaternion.identity, vol.radius * 2.0f);
                        MegaHandles.SphereCap(0, vol.origin, Quaternion.identity, vol.radius * 2.0f);
                    }
                    //else
                    //	Handles.CubeCap(.DrawCube(0, tm.MultiplyPoint(vol.origin), Quaternion.identity, vol.radius * 2.0f);

                    //Handles.matrix = tm;
                    if (vol.target == null)
                    {
                        origin = Handles.PositionHandle(vol.origin, Quaternion.identity);

                        if (origin != vol.origin)
                        {
                            vol.origin = origin;
                            EditorUtility.SetDirty(target);
                        }
                    }
                }
            }

            Handles.matrix = Matrix4x4.identity;
        }
    }
コード例 #3
0
    float GetDistBox(MegaVolume vol, Vector3 p)
    {
        // Work in the box's coordinate system.
        Vector3 diff = p - vol.origin;

        // Compute squared distance and closest point on box.
        float sqrDistance = 0.0f;
        float delta;

        Vector3 closest = diff;

        //closest.x = diff.x;	//Vector3.Dot(diff, Vector3.right);

        if (closest.x < -vol.boxsize.x)
        {
            delta        = closest.x + vol.boxsize.x;
            sqrDistance += delta * delta;
            closest.x    = -vol.boxsize.x;
        }
        else
        {
            if (closest.x > vol.boxsize.x)
            {
                delta        = closest.x - vol.boxsize.x;
                sqrDistance += delta * delta;
                closest.x    = vol.boxsize.x;
            }
        }

        //closest.x = diff.x;	//Vector3.Dot(diff, Vector3.right);

        if (closest.y < -vol.boxsize.y)
        {
            delta        = closest.y + vol.boxsize.y;
            sqrDistance += delta * delta;
            closest.y    = -vol.boxsize.y;
        }
        else
        {
            if (closest.y > vol.boxsize.y)
            {
                delta        = closest.y - vol.boxsize.y;
                sqrDistance += delta * delta;
                closest.y    = vol.boxsize.y;
            }
        }

        //closest.x = diff.x;	//Vector3.Dot(diff, Vector3.right);

        if (closest.z < -vol.boxsize.z)
        {
            delta        = closest.z + vol.boxsize.z;
            sqrDistance += delta * delta;
            closest.z    = -vol.boxsize.z;
        }
        else
        {
            if (closest.z > vol.boxsize.z)
            {
                delta        = closest.z - vol.boxsize.z;
                sqrDistance += delta * delta;
                closest.z    = vol.boxsize.z;
            }
        }

        return(Mathf.Sqrt(sqrDistance));        // * 0.5f;
    }
コード例 #4
0
    static public MegaVolume Create()
    {
        MegaVolume vol = new MegaVolume();

        return(vol);
    }
コード例 #5
0
    public override void GetSelection(MegaModifiers mc)
    {
        if (modselection == null || modselection.Length != mc.verts.Length)
        {
            modselection = new float[mc.verts.Length];
        }

        int volcount = 0;

        if (!freezeSelection)
        {
            if (volumes != null && volumes.Count > 0)
            {
                for (int v = 0; v < volumes.Count; v++)
                {
                    MegaVolume vol = volumes[v];

                    if (vol.enabled)
                    {
                        Vector3 origin = Vector3.zero;

                        if (vol.target)
                        {
                            origin = transform.worldToLocalMatrix.MultiplyPoint(vol.target.position);
                        }
                        else
                        {
                            origin = vol.origin;
                        }

                        vol.origin = origin;

                        if (volcount == 0)
                        {
                            if (vol.volType == MegaVolumeType.Sphere)
                            {
                                if (useCurrentVerts)
                                {
                                    for (int i = 0; i < verts.Length; i++)
                                    {
                                        float d = Vector3.Distance(origin, verts[i]) - vol.radius;

                                        if (d < 0.0f)
                                        {
                                            modselection[i] = vol.weight;
                                        }
                                        else
                                        {
                                            float w = Mathf.Exp(-vol.falloff * Mathf.Abs(d));
                                            modselection[i] = w * vol.weight;                                                   //mc.cols[i][c];
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < verts.Length; i++)
                                    {
                                        float d = Vector3.Distance(origin, verts[i]) - vol.radius;

                                        if (d < 0.0f)
                                        {
                                            modselection[i] = vol.weight;
                                        }
                                        else
                                        {
                                            float w = Mathf.Exp(-vol.falloff * Mathf.Abs(d));
                                            modselection[i] = w * vol.weight;                                                   //mc.cols[i][c];
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (useCurrentVerts)
                                {
                                    for (int i = 0; i < verts.Length; i++)
                                    {
                                        float d = GetDistBox(vol, verts[i]);

                                        if (d < 0.0f)
                                        {
                                            modselection[i] = vol.weight;
                                        }
                                        else
                                        {
                                            float w = Mathf.Exp(-vol.falloff * Mathf.Abs(d));
                                            if (w > 1.0f)
                                            {
                                                w = 1.0f;
                                            }
                                            modselection[i] = w * vol.weight;                                                   //mc.cols[i][c];
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < verts.Length; i++)
                                    {
                                        float d = GetDistBox(vol, verts[i]);

                                        //float wg = modselection[i];

                                        if (d < 0.0f)
                                        {
                                            modselection[i] = vol.weight;
                                        }
                                        else
                                        {
                                            float w = Mathf.Exp(-vol.falloff * Mathf.Abs(d));
                                            if (w > 1.0f)
                                            {
                                                w = 1.0f;
                                            }
                                            modselection[i] = w * vol.weight;                                                   //mc.cols[i][c];
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (vol.volType == MegaVolumeType.Box)
                            {
                                if (useCurrentVerts)
                                {
                                    for (int i = 0; i < verts.Length; i++)
                                    {
                                        float d = GetDistBox(vol, verts[i]);

                                        float wg = modselection[i];
                                        if (d < 0.0f)
                                        {
                                            wg += vol.weight;
                                        }
                                        else
                                        {
                                            float w = Mathf.Exp(-vol.falloff * Mathf.Abs(d));
                                            wg += w * vol.weight;                                               //mc.cols[i][c];
                                        }

                                        if (wg > 1.0f)
                                        {
                                            modselection[i] = 1.0f;
                                        }
                                        else
                                        {
                                            modselection[i] = wg;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < verts.Length; i++)
                                    {
                                        float d = GetDistBox(vol, verts[i]);

                                        float wg = modselection[i];

                                        if (d < 0.0f)
                                        {
                                            wg += vol.weight;
                                        }
                                        else
                                        {
                                            float w = Mathf.Exp(-vol.falloff * Mathf.Abs(d));
                                            wg += w * vol.weight;                                               //mc.cols[i][c];
                                        }

                                        if (wg > 1.0f)
                                        {
                                            modselection[i] = 1.0f;
                                        }
                                        else
                                        {
                                            modselection[i] = wg;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (useCurrentVerts)
                                {
                                    for (int i = 0; i < verts.Length; i++)
                                    {
                                        float d = Vector3.Distance(origin, verts[i]) - vol.radius;

                                        float wg = modselection[i];
                                        if (d < 0.0f)
                                        {
                                            wg += vol.weight;
                                        }
                                        else
                                        {
                                            float w = Mathf.Exp(-vol.falloff * Mathf.Abs(d));
                                            wg += w * vol.weight;                                               //mc.cols[i][c];
                                        }

                                        if (wg > 1.0f)
                                        {
                                            modselection[i] = 1.0f;
                                        }
                                        else
                                        {
                                            modselection[i] = wg;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < verts.Length; i++)
                                    {
                                        float d = Vector3.Distance(origin, verts[i]) - vol.radius;

                                        float wg = modselection[i];

                                        if (d < 0.0f)
                                        {
                                            wg += vol.weight;
                                        }
                                        else
                                        {
                                            float w = Mathf.Exp(-vol.falloff * Mathf.Abs(d));
                                            wg += w * vol.weight;                                               //mc.cols[i][c];
                                        }

                                        if (wg > 1.0f)
                                        {
                                            modselection[i] = 1.0f;
                                        }
                                        else
                                        {
                                            modselection[i] = wg;
                                        }
                                    }
                                }
                            }
                        }

                        volcount++;
                    }
                }
            }

            if (volcount == 0)
            {
                for (int i = 0; i < verts.Length; i++)
                {
                    modselection[i] = 0.0f;
                }
            }
        }

        if ((mc.dirtyChannels & MegaModChannel.Verts) == 0)
        {
            mc.InitVertSource();
        }

        mc.selection = modselection;
    }
コード例 #6
0
 public static MegaVolume Create()
 {
     MegaVolume vol = new MegaVolume();
     return vol;
 }
コード例 #7
0
    float GetDistBox(MegaVolume vol, Vector3 p)
    {
        // Work in the box's coordinate system.
        Vector3 diff = p - vol.origin;

        // Compute squared distance and closest point on box.
        float sqrDistance = 0.0f;
        float delta;

        Vector3 closest = diff;
        //closest.x = diff.x;	//Vector3.Dot(diff, Vector3.right);

        if ( closest.x < -vol.boxsize.x )
        {
            delta = closest.x + vol.boxsize.x;
            sqrDistance += delta * delta;
            closest.x = -vol.boxsize.x;
        }
        else
        {
            if ( closest.x > vol.boxsize.x )
            {
                delta = closest.x - vol.boxsize.x;
                sqrDistance += delta * delta;
                closest.x = vol.boxsize.x;
            }
        }

        //closest.x = diff.x;	//Vector3.Dot(diff, Vector3.right);

        if ( closest.y < -vol.boxsize.y )
        {
            delta = closest.y + vol.boxsize.y;
            sqrDistance += delta * delta;
            closest.y = -vol.boxsize.y;
        }
        else
        {
            if ( closest.y > vol.boxsize.y )
            {
                delta = closest.y - vol.boxsize.y;
                sqrDistance += delta * delta;
                closest.y = vol.boxsize.y;
            }
        }

        //closest.x = diff.x;	//Vector3.Dot(diff, Vector3.right);

        if ( closest.z < -vol.boxsize.z )
        {
            delta = closest.z + vol.boxsize.z;
            sqrDistance += delta * delta;
            closest.z = -vol.boxsize.z;
        }
        else
        {
            if ( closest.z > vol.boxsize.z )
            {
                delta = closest.z - vol.boxsize.z;
                sqrDistance += delta * delta;
                closest.z = vol.boxsize.z;
            }
        }

        return Mathf.Sqrt(sqrDistance);	// * 0.5f;
    }